Skip to content

fix(validation): bind sections to the header's roots in apply_state - #23

Open
cafebedouin wants to merge 1 commit into
mwaddip:mainfrom
cafebedouin:ergo-logic/apply-root-binding
Open

cafebedouin wants to merge 1 commit into
mwaddip:mainfrom
cafebedouin:ergo-logic/apply-root-binding

Conversation

@cafebedouin

@cafebedouin cafebedouin commented Sep 16, 2026 •

Copy link
Copy Markdown

Branch: ergo-logic/apply-root-binding (from 5b8e6f3). Files: validation/Cargo.toml,
validation/src/{lib,sections,utxo,digest,test_support}.rs, validation/tests/block_version_gate.rs,
facts/validation.md, Cargo.lock.

Why

Both validators parse the transactions and extension sections without comparing them to
header.transaction_root / header.extension_root. The receive path binds peer deliveries at the
store write since v0.8.2, so today this is reachable by any route that bypasses that write: a store
populated before v0.8.2 (see the companion rebind PR, #24), a direct caller, and the conformance runners.
Executed through
SANTA's block tier on the captured testnet block 2666: three tampered extensions (a flipped value, a
65-byte value, a duplicate key) validate with the identical post-digest and cost; arkadianet/ergo
rejects all three from its own validator (ExtensionRootMismatch).

What

sections::check_section_roots(header, &parsed_txs, &parsed_ext) runs right after parsing in both
apply_state paths; roots come from enr_chain::transactions_root / extension_root (the single
workspace implementations, per v0.8.2's changelog). New errors TransactionsRootMismatch /
ExtensionRootMismatch, clean rejections. The transactions root is recomputed with header.version,
not the version the body declares about itself (ParsedBlockTransactions::block_version, read from
the body's own wire bytes): that flag decides whether witness leaves fold into the root, and the
header is the verified side of the comparison. validation gains a path-dep on enr-chain (no
cycle: chain depends on neither validation nor state).

Tests

Fixtures carried zero roots; they now bind them (test_support::bind_roots; block_version_gate.rs
binds per test so each still reaches the gate it targets). New: section_root_binding:: {honest_body_still_applies, reordered_transactions_are_rejected, tampered_extension_is_rejected}.
cargo test -p ergo-validation: 69 + 2 + 4 + 3 passed, 0 failed (re-run after the header.version change; workspace run on the prior revision: every crate green, 0 failures).

Contract

facts/validation.md § "Section-to-header binding at apply". Relation to facts/receive-path.md:
the store binds the network sink; this is the validation seam's own guarantee.

Changelog entry

Not in the patch (your repo instructions reserve CHANGELOG.md for the main session, and four PRs
inserting an Unreleased block at the same spot conflict with each other). Text, if useful:

#### `apply_state` binds sections to the header's roots

The validators parsed the transactions and extension sections without
comparing them to `header.transaction_root` / `header.extension_root`; a
body that reached validation by any route other than the (now bound)
receive path — a store written before v0.8.2, a direct caller — was
applied as-is. Both validators now recompute the roots
(`enr_chain::transactions_root` / `extension_root`) and reject mismatches.
Test fixtures that carried zero roots now bind them (`test_support::bind_roots`).

🤖 Generated with Claude Code

Both validators parsed the transactions and extension sections without
comparing them to header.transaction_root / header.extension_root. Any body
that reached validation by a route other than the bound receive path — a
store written before v0.8.2, a direct caller, the conformance runners —
was applied as-is. Recompute both roots via enr_chain (the workspace's
single implementations) and reject mismatches as TransactionsRootMismatch /
ExtensionRootMismatch (JVM bsCorrespondsToHeader).

Test fixtures carried zero roots; they now bind them (test_support::
bind_roots; block_version_gate.rs binds per test). New tests: honest body
applies, reordered transactions rejected, tampered extension rejected.
facts/validation.md gains the seam's contract; CHANGELOG under Unreleased.
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