crosscheck

package
v1.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: Apache-2.0, MIT Imports: 8 Imported by: 0

Documentation

Overview

Package crosscheck implements the VM-bridge auditor (#98).

The VM bridge (vm/bridge) is normally a PRODUCTION dependency: it computes post-execution state roots for block production. This package turns the same connection into an AUDITOR for the read path: it periodically asks the operator's own Forest/Lotus node for the canonical tipset at a settled depth and compares it against Lantern's header-store view. A mismatch means Lantern's head path and the operator's full node disagree about the canonical chain - a state-root level attack, an eclipse, or a bug - and is worth a loud alarm.

Why this is honest trust-wise (TRUST-MODEL 4.x): the bridge is the operator's own node, already trusted for block production. Using it to CROSS-CHECK adds no new trust; the read path stays 100% local and is never answered by the bridge. The check is observe-only: a divergence alarms (log + counter + dashboard) but never blocks or rewrites Lantern's head. This delivers most of the practical security value of full re-execution (#89 Stage C) at ~zero cost, and doubles as the vector generator Stage C will need.

Sampling: checks run at a fixed interval (default 60s) against depth head-K (default 3 epochs) so legitimate near-tip reorgs don't produce false alarms. Null rounds are skipped (heights must match to compare).

Index

Constants

View Source
const DefaultDepth = 3

DefaultDepth is how many epochs behind head the check targets. 3 epochs (~90s) is deep enough that honest near-tip reorgs have settled, shallow enough that an attack alarms within ~2 minutes.

View Source
const DefaultInterval = 60 * time.Second

DefaultInterval is the default wall-clock spacing between checks.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

Checker periodically cross-checks the local canonical chain against the operator's bridge node. Observe-only: never mutates local state.

func New

func New(cfg Config) (*Checker, error)

New builds a Checker. Bridge and Source are required.

func (*Checker) CheckOnce

func (c *Checker) CheckOnce(ctx context.Context)

CheckOnce performs one cross-check. Exposed for tests and for a dashboard "check now" action.

func (*Checker) Start

func (c *Checker) Start(ctx context.Context)

Start launches the periodic check loop; returns immediately. The loop exits when ctx is cancelled.

func (*Checker) Stats

func (c *Checker) Stats() Stats

Stats returns a snapshot of counters.

type Config

type Config struct {
	Bridge   RPC
	Source   Source
	Interval time.Duration // 0 => DefaultInterval
	Depth    int           // 0 => DefaultDepth
	// OnDiverge, when set, fires on every confirmed divergence (after
	// the height-match guard). Wire alerts/notifications here.
	OnDiverge func(epoch abi.ChainEpoch, ours, theirs string)
}

Config wires a Checker.

type RPC

type RPC interface {
	RawJSONRPC(ctx context.Context, method string, params json.RawMessage) (json.RawMessage, error)
	Provenance() string
}

RPC is the bridge surface the checker needs. vm/bridge.ForestBridge (and the Bridge interface) satisfy it.

type Source

type Source interface {
	Head() *ltypes.TipSet
	GetTipSetByHeight(epoch abi.ChainEpoch) (*ltypes.TipSet, error)
}

Source is the local chain surface the checker audits. chain/header/store.Store satisfies it.

type Stats

type Stats struct {
	Checks           uint64
	Agrees           uint64
	Diverges         uint64
	Skipped          uint64 // bridge lag / null round / shallow chain / errors
	LastCheckedEpoch abi.ChainEpoch
	LastResult       string // "agree" | "DIVERGE" | "skip" | ""
	Provenance       string
}

Stats is a snapshot of checker counters.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL