Skip to content

fix: backfill worker parent-hash validation#158

Open
jxom wants to merge 1 commit intomainfrom
fix/backfill-parent-hash
Open

fix: backfill worker parent-hash validation#158
jxom wants to merge 1 commit intomainfrom
fix/backfill-parent-hash

Conversation

@jxom
Copy link
Copy Markdown
Member

@jxom jxom commented Mar 31, 2026

Audit Finding Fix

Finding: Backfill-First Gap Worker Skips Parent-Hash Validation and Commits Forged Block Chains

The backfill/gap-fill standalone worker (sync_range_standalone) did not validate parent hashes when ingesting blocks. A malicious RPC could supply blocks with incorrect parent_hash linkage that would be written to the database without validation.

Changes

  • Extract validate_parent_hash_chain() as a standalone function that verifies consecutive blocks in a batch form a valid parent-hash chain
  • Call it from sync_range_standalone() (gap-fill/backfill path) before writing to DB
  • Refactor SyncEngine::validate_parent_chain() to reuse the same function for internal chain validation

Tests

5 unit tests covering:

  • Valid consecutive block chain passes
  • Mismatched parent_hash is detected and rejected
  • Single-block batches pass (no previous block to check)
  • Empty input passes
  • Mid-batch mismatch is caught at the correct block number

Extract validate_parent_hash_chain() as a standalone function that
verifies consecutive blocks form a valid parent-hash chain. Called from
both the realtime sync path (via SyncEngine::validate_parent_chain)
and the gap-fill/backfill standalone worker (sync_range_standalone).

Previously the backfill path skipped parent-hash checks entirely,
allowing a malicious RPC to supply blocks with incorrect parent_hash
linkage that would be written to the database without validation.

Tests cover: valid chain, mismatch detection, single-block batches,
empty input, and mid-batch mismatch detection.

Amp-Thread-ID: https://ampcode.com/threads/T-019d458d-01b9-76ca-9fb1-c2b64d30877e
Co-authored-by: Amp <amp@ampcode.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant