Skip to content

fix(trie): encode FlaggedStorage in StorageProof::verify#343

Open
ameya-deshmukh wants to merge 4 commits intoseismicfrom
ameya/flagged-storage-merkle-proof-test
Open

fix(trie): encode FlaggedStorage in StorageProof::verify#343
ameya-deshmukh wants to merge 4 commits intoseismicfrom
ameya/flagged-storage-merkle-proof-test

Conversation

@ameya-deshmukh
Copy link
Copy Markdown
Contributor

@ameya-deshmukh ameya-deshmukh commented Mar 19, 2026

Summary

  • Fix StorageProof::verify to encode values as FlaggedStorage (value + privacy flag byte) instead of raw U256, matching what the trie actually stores. This is a client-side utility function currently only used in tests — verify_proof in seismic-trie is already well-tested with privacy flags.
  • Add test_flagged_storage_proof integration test covering proof generation via Proof::from_tx with mixed public/private storage slots, all-private accounts, all-public accounts, and accounts with no storage.

Test plan

  • cargo nextest run -p reth-trie-db --test proof — all 5 tests pass (including new test_flagged_storage_proof)
  • Clippy clean on reth-trie-common (where the fix lives)

🤖 Generated with Claude Code

@ameya-deshmukh ameya-deshmukh requested a review from cdrappi as a code owner March 19, 2026 19:00
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 19, 2026

Fixes storage proof verification to encode FlaggedStorage with privacy flags, matching actual trie storage format.

LGTM

The change correctly addresses a semantic mismatch where StorageProof::verify() was encoding raw U256 values but the trie actually stores FlaggedStorage (value + privacy flag). The logic change from encode_fixed_size(&self.value) to encode_fixed_size(&FlaggedStorage::new(self.value, self.is_private)) aligns with how storage values are encoded in crates/trie/trie/src/test_utils.rs:104,128.

The updated zero-value handling is also correct - private zero values (value.is_zero() && is_private) need to be stored in the trie to preserve the privacy flag, while public zero values can be omitted entirely.

The test coverage is comprehensive and validates the fix across various scenarios.

ameya-deshmukh and others added 3 commits March 20, 2026 18:57
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
StorageProof::verify was encoding just the U256 value when comparing
against trie nodes, but the trie stores FlaggedStorage (value + privacy
flag byte). This caused proof verification to fail with ValueMismatch
for any non-zero storage value.

Also adds test_flagged_storage_proof covering mixed public/private
storage slots, all-private accounts, and all-public accounts.
@ameya-deshmukh ameya-deshmukh force-pushed the ameya/flagged-storage-merkle-proof-test branch from 878bd50 to b745af1 Compare March 20, 2026 13:28
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