Skip to content

feat(world-state): add blockHash verification to syncImmediate#21556

Open
spalladino wants to merge 1 commit intomerge-train/spartanfrom
palla/sync-immediate-block-hash-verification
Open

feat(world-state): add blockHash verification to syncImmediate#21556
spalladino wants to merge 1 commit intomerge-train/spartanfrom
palla/sync-immediate-block-hash-verification

Conversation

@spalladino
Copy link
Contributor

Motivation

syncImmediate syncs world state to a target block number but does not verify block identity. If a reorg occurred and the world state is at the same height but on a different fork, the method returns early without detecting the mismatch. Additionally, skipThrowIfTargetNotReached was dead code with no caller ever passing true.

Approach

Added an optional typed BlockHash parameter to syncImmediate. When at or past the target height, the implementation checks the hash via getL2BlockHash before returning early. On mismatch it falls through to trigger a resync. After syncing, if the hash still doesn't match, it throws a WorldStateSynchronizerError with reason block_hash_mismatch. Removed the unused skipThrowIfTargetNotReached parameter entirely.

Changes

  • stdlib: Updated WorldStateSynchronizer interface signature — replaced skipThrowIfTargetNotReached?: boolean with blockHash?: BlockHash
  • world-state: Implemented block hash verification in ServerWorldStateSynchronizer.syncImmediate with pre-sync and post-sync checks
  • p2p: Both tx pool v1 and v2 FeePayerBalanceEvictionRule now pass BlockHash from context.block.hash() on BLOCK_MINED events
  • prover-node: Passes last block's header hash when syncing world state before creating proving jobs
  • txe: Updated mock synchronizer parameter name and type
  • world-state (tests): Added tests for hash match (early return), hash mismatch (triggers resync), and hash mismatch after sync (throws)
  • p2p (tests): Updated mock expectations to verify blockHash is passed in BLOCK_MINED handlers

Adds an optional `BlockHash` parameter to `syncImmediate` for reorg detection.
When provided, verifies the block at the target number matches the expected hash.
On mismatch, triggers a resync; if still mismatched after sync, throws.
Also removes dead `skipThrowIfTargetNotReached` parameter (no caller passed `true`).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@spalladino spalladino added ci-no-fail-fast Sets NO_FAIL_FAST in the CI so the run is not aborted on the first failure backport-to-v4-next labels Mar 13, 2026
@spalladino spalladino enabled auto-merge (squash) March 13, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-v4-next ci-no-fail-fast Sets NO_FAIL_FAST in the CI so the run is not aborted on the first failure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant