Skip to content

op-reth: live test of index-versus-execute proofs store parity - #23442

Closed
einar-oplabs wants to merge 3 commits into
einar/23384-proofs-parent-statesfrom
einar/23388-proofs-index-execute-parity
Closed

einar-oplabs wants to merge 3 commits into
einar/23384-proofs-parent-statesfrom
einar/23388-proofs-index-execute-parity

Conversation

@einar-oplabs

@einar-oplabs einar-oplabs commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Builds one chain into four proofs stores, one indexed from reth's trie data, one re-executed by the engine and two initialized at the tip and backfilled, and asserts that they serve the same state at every block. The index and execute paths cross-check each other in the ExEx and nothing verified that they still agree on a self-destruct, a zeroed slot or an emptied account; this is the regression net for the storage-wipe removal (reth#26811) in the reth 2.6 bump (#23046).

What the test does

index_execute_and_backfill_stores_agree in rust/op-reth/crates/trie/tests/live/index_execute_parity.rs:

  1. Drives reth with SimulatedReth (lifted out of the parent-state test into tests/live/simulated_reth.rs), so every block has the ExecutedBlock trie data reth's engine tree holds.
  2. Feeds the indexed store through EngineHandle::index_block with that block's trie_updates and hashed_state, and the executed store through EngineHandle::execute_block.
  3. Persists the chain to reth's database, then builds two stores the way proofs init does: InitializationJob at the tip, then BackfillJob::run (history) and BackfillJob::run_with_snapshot back to genesis, in batches of three blocks so each backfill commits more than once.
  4. Compares every store with the indexed one at every block from genesis to the tip (tests/live/store_view.rs): the proof window; the account hashed cursor over the whole key space; the storage hashed cursor and the storage trie cursor of every account the store holds and of every address the chain can touch; the account trie cursor; and Proof::overlay_account_proof for every address the chain can touch with the slots its contracts write. A mismatch fails naming the store, block, table and key. The indexed store's proofs are also verified against the header's state root, so four stores agreeing on the wrong state still fail.
  5. Checks that the chain did what the case says (the slot writer kept its storage after the Cancun self-destruct, the EIP-6780 contract is gone with its storage, only the cousin slot survived the zeroing, and so on).

Matrix

Axis Values
state change (rstest cases) BLOCKHASH read; CREATE plus SELFDESTRUCT in one transaction; deploy then call; EIP-161 touch; SELFDESTRUCT of a pre-existing contract; SSTORE to zero
engine flush cadence (persistence, backpressure) every block (1, 2); every fifth block (5, 10)
store backend for the indexed and executed stores InMemoryProofsStorage, MdbxProofsStorage

24 cells, all run. The backfilled stores are always MDBX, the only backend that implements OpProofsBackfillStore.

Every chain is ten blocks: three empty blocks, the content, empty blocks to the end. The test asserts that ten is a multiple of the cadence's persistence threshold, so the final flush leaves nothing in the engine buffer, and multi-block content straddles the flush at block 5 under the slower cadence. The engine's buffer is not readable from outside the engine, so the cadence decides whether the execute path reads a block's parent from the buffer or from disk; the comparison runs over the persisted history once everything is flushed.

The chain is Cancun (the self-destruct cases need EIP-6780), with the EIP-4788 contract in genesis so every block also writes two slots of a pre-existing contract. create_block_from_spec now fills the Shanghai and Cancun header fields when the chain spec has those forks active, and gives every block a timestamp; the existing Paris tests only see the timestamps.

Trie depth

reth stores no branch node for a trie whose keys all differ in their first nibble, so the first draft of this test compared empty trie tables and had no removed node to corrupt. The slot writer's eight slots and the three EIP-161 genesis accounts are therefore chosen at runtime (colliding_keys) so that three keys share their first hashed nibble and two of those also the second: filling them stores a branch node, and zeroing the first of the pair (or EIP-161 removing the empty account) removes it.

Local verification

cargo test -p reth-optimism-trie --test live
test result: ok. 56 passed; 0 failed; 6 ignored; 0 measured; 0 filtered out; finished in 21.73s

The 24 new cases take about 10 s of that. just fmt-fix applied; cargo clippy -p reth-optimism-trie --all-targets reports only the three pre-existing warnings outside this diff. The rust-code-reviewer agent's findings are addressed in the second commit.

Corruption check (run locally with a temporary patch, not committed): dropping one removed trie node from the index side's TrieUpdatesSorted fails the run with

Error: the executed store differs from the indexed store at block 6 in StoragesTrie[0x630c…d45a] at key Nibbles(0xb): indexed Some(BranchNodeCompact { state_mask: TrieMask(0000100000000010), … }), executed None

for the SSTORE to zero case (MDBX, every-block cadence) and with

Error: the executed store differs from the indexed store at block 4 in AccountsTrie at key Nibbles(0xc): indexed Some(BranchNodeCompact { … }), executed None

for the EIP-161 case (in-memory, every-fifth-block cadence).

Notes on the issue text

  • "A transfer that creates and then empties an EIP-161 account" cannot be produced by real transactions after Spurious Dragon: an account only an incoming transfer created can only be emptied by a transaction it signs, which leaves its nonce at one. The case instead touches an empty account from the genesis allocation, which EIP-161 removes (the trie leaf and its branch go away), and touches an address that never had anything, which creates nothing.
  • The empty-account fix (reth#27252) is in reth's state-root task, which converts the EVM state rather than the bundle state. SimulatedReth hashes the bundle state, like reth's engine does below five cores, so this test does not reach that code path; it covers the store's own handling of what reth hands it.

Seams for later PRs

  • tests/live/simulated_reth.rs: SimulatedReth (now with spawn_engine, state_root and persist_all, and commit returning the ExecutedBlock), RethPersistence, Location, fixed_signer.
  • tests/live/store_view.rs: BlockView::read reads everything a store serves at one block; assert_same_view names the first differing table and key.
  • tests/live/contracts.rs: initcode_returning, the block-hash recorder, the slot writer (parameterized slots, self-destruct on empty calldata) and the create-and-self-destruct initcode.
  • live.rs: TxSpec::with_value, BlockSpec::empty, chain_spec_builder and funded for custom genesis allocations and forks, block_timestamp, PRUNE_INTERVAL_BLOCKS.

Stacked on #23441, #23437, #23434, #23429, #23428, #23421 and #23418.

Closes #23388

🤖 Generated with Claude Code

@opgitgovernance

Copy link
Copy Markdown
Contributor

This pr has been automatically marked as stale and will be closed in 5 days if no updates

@opgitgovernance opgitgovernance added the S-stale Status: Will be closed unless there is activity label Oct 31, 2026
@einar-oplabs einar-oplabs reopened this Nov 6, 2026
@einar-oplabs einar-oplabs removed the S-stale Status: Will be closed unless there is activity label Nov 6, 2026
einar-oplabs and others added 2 commits November 9, 2026 22:11
Builds one Cancun chain into three proofs stores, one indexed from reth's
trie data, one re-executed by the engine and one initialized at the tip
and backfilled, and compares the proof window, the hashed account and
storage cursors, the account and storage trie cursors and an account
proof per touched address at every block. Block content covers deploy
then call, SSTORE to zero, CREATE plus SELFDESTRUCT in one transaction,
SELFDESTRUCT of a pre-existing contract, an EIP-161 touch and a BLOCKHASH
read, over both engine flush cadences and both store backends.

Lifts SimulatedReth and the contract bytecode helpers out of the
parent-state test into shared modules of the live test crate.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 9503b72)
(cherry picked from commit 25e71cef99b5d49ad92de9bf5421b29faedc9c12)
Adds a snapshot-backfilled store so both backfill modes are compared,
backfills in batches of three so a backfill commits more than once, and
checks the chain length against the flush cadence instead of stating it.
Reads each store's own account set instead of a union across stores,
verifies proofs only on the reference store, and moves the store view
and its comparison into a module of their own. Reuses
RecoveredBlock::block_with_parent and TrieCursorIter, lets SimulatedReth
spawn the engine and report state roots, and flattens the search for
colliding keys.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit b561b8e)
(cherry picked from commit d78fb4ece0f34a998b976a47f39316dad6e678d2)
@einar-oplabs
einar-oplabs force-pushed the einar/23388-proofs-index-execute-parity branch from b561b8e to 37687f1 Compare November 9, 2026 22:30
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@einar-oplabs
einar-oplabs marked this pull request as ready for review November 13, 2026 11:44
@einar-oplabs
einar-oplabs requested a review from a team as a code owner November 13, 2026 11:44
@joshklop
joshklop added this pull request to stack #24332 November 21, 2026 22:26
@joshklop joshklop closed this Nov 21, 2026
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.

op-reth: live test of index-versus-execute proofs store parity over rich block content

3 participants