Skip to content

execution/commitment: materialize collapse-sibling branch in toWitnessTrie - #21892

Merged
awskii merged 2 commits into
mainfrom
awskii/witness-collapse-sibling
Jun 19, 2026
Merged

awskii merged 2 commits into
mainfrom
awskii/witness-collapse-sibling

Conversation

@awskii

@awskii awskii commented Jun 19, 2026 •

Copy link
Copy Markdown
Member

debug_executionWitness blinded the surviving sibling of a collapsing storage branch on a zero-value write (#21869). On a slot delete from a two-child branch, toWitnessTrie emitted the sibling extension but left the branch it points to a bare HashNode. reth's stateless verifier can't re-form the collapsed branch from a blinded node, so it returns BlindedNode and the post-state root diverges.

Repro: mainnet block 25335936, zero-write to slot 0x43cb…, sibling 0x43cd blinded → SparseTrieError(BlindedNode(Nibbles(0x43cd))).

Fix: in exclusion-proof (legacy) mode, materialize that branch via witnessMaterializeBranch with a subtrie-root check instead of a HashNode. Same hash, witness root unchanged; canonical mode stays minimal. The absent-slot path and this one now share witnessMaterializeBranchChild.

Test: Test_WitnessTrie_GenerateWitness/CollapseSiblingExtensionMustBeMaterialized — two-child storage branch, sibling is an extension over a sub-branch, delete the other child, assert the sub-branch is a FullNode not a HashNode. End-to-end: block 25335936 witness passes reth stateless (VALID; state nodes 16395 → 16396).

Fixes #21869

…n witness

debug_executionWitness left the surviving sibling of a collapsing storage branch
blinded on a zero-value write: the sibling extension was emitted but the branch it
points to stayed a bare HashNode, so a strict sparse-trie verifier (reth) could not
re-form the collapsing branch and the post-state root diverged (#21869).

In exclusion-proof (legacy) mode, materialize that branch via witnessMaterializeBranch
with a subtrie-root check, mirroring the absent-slot exclusion path; both materializing
sites now share witnessMaterializeBranchChild. Canonical mode stays minimal.
@awskii
awskii requested review from mh0lt and taratorio as code owners June 19, 2026 00:59
@awskii awskii changed the title execution/commitment: materialize collapse-sibling branch in execution witness execution/commitment: materialize collapse-sibling branch in toWitnessTrie Jun 19, 2026
@awskii
awskii requested review from canepat and lupin012 June 19, 2026 01:19
@AskAlexSharov
AskAlexSharov added this pull request to the merge queue Jun 19, 2026
The diverging-extension site half-built the ShortNode and left its Val to be
filled later in two separate pathDivergenceFound blocks (the FullNode and
AccountNode cases). Build the child in one place via witnessDivergedBranchChild
— the materialized branch in exclusion-proof mode, else its hash (computed when
the cell carries no hash-ref) — and drop both fill-in blocks.

No behavior change: the absent-account, absent-slot, and collapse-sibling witness
tests cover the diverged paths and the witness root stays equal to the commitment
root.
@awskii
awskii removed this pull request from the merge queue due to a manual request Jun 19, 2026
@awskii

awskii commented Jun 19, 2026 •

Copy link
Copy Markdown
Member Author

Comparing debug_executionWitness (legacy mode) output against reth on a mainnet archive node: erigon's state nodes are a strict subset of reth's (erigon_only=0), codes and keys identical, ~20–47 fewer state nodes per block. Characterizing one block's reth-only set:

What the reth-only nodes are

  • 20 branches + 12 leaves
  • 31 of 32 are NOT referenced by any erigon node — they live in subtrees erigon's witness never points into, i.e. they are not children erigon blinded on its own proof paths.
  • Only 1 is a node erigon hash-references but omits (a genuinely blinded child).
  • Leaf samples show the tell: the same key 20290decd9 appears twice with different value lengths (vlen=21 and vlen=2), and keys carry the 0x20 leaf prefix — i.e. pre- and post-state versions of modified slots. reth's witness carries touched/after-state nodes that erigon's minimal recompute witness doesn't.

Do we need them?

No. Three independent reasons:

  1. erigon's witness is VALID under reth's own stateless verifier — it re-executes the block and reproduces the post-state root without those 32 nodes. If any were required, re-execution would fail (BlindedNode or wrong root). It doesn't.
  2. 31/32 aren't even on erigon's proof paths — they're reth-side completeness (after-state / read-touched nodes), not data erigon dropped.
  3. Across every block checked, erigon_only=0, codes and keys identical — erigon never omits a node it references; it's strictly leaner, never short.

@awskii
awskii added this pull request to the merge queue Jun 19, 2026
Merged via the queue into main with commit 7d6c43f Jun 19, 2026
173 of 175 checks passed
@awskii
awskii deleted the awskii/witness-collapse-sibling branch June 19, 2026 07:53
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.

debug_executionWitness: post-state root mismatch due to missing sibling node

2 participants