Skip to content

feat(trie): Proof Rewrite: Support partial proofs#20336

Merged
mediocregopher merged 63 commits into
mainfrom
mediocregopher/19516-proof-rewrite-partial-proofs
Dec 23, 2025
Merged

feat(trie): Proof Rewrite: Support partial proofs#20336
mediocregopher merged 63 commits into
mainfrom
mediocregopher/19516-proof-rewrite-partial-proofs

Conversation

@mediocregopher
Copy link
Copy Markdown
Member

The key change here is the addition of the Target type, which wraps a B256 key to hold also a min_len. When a node's path length is less than the min_len then we do not retain it for that target.

Given a set of Targets we then intelligently determine which sub-tries of the overall trie actually need to be computed, so we don't waste time computing portions of the trie which no target could possibly match anyway. The method for determining sub-tries is a bit complex, but is heavily documented in the code with examples; more docs/examples can be added if necessary.

The actual algorithms for building the trie from leaves+cached branches has not significantly changed, except to add boundary checks for the sub-tries.

Closes #19516

@github-actions github-actions Bot added the A-engine Related to the engine implementation label Dec 12, 2025
skip_all,
fields(prefix=?sub_trie_targets.prefix),
)]
fn proof_subtrie<'a>(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proof_subtrie has essentially replaced the previous proof_inner implementation; proof_inner previously drove the calculation of the trie for the entire trie, now proof_subtrie drives the calculation of a single sub-trie using roughly the same logic. proof_inner instead now loops over each sub-trie and calls on proof_subtrie on each.

@mediocregopher mediocregopher changed the title feat(trie): Proof Rewrite: Support partial proofs feat(trie): Proof Rewrite: Support partial proofs Dec 12, 2025
// forward to 0xabc2 (because all children will have been visited already). At this
// point the target for 0xabc2 will not match the branch due to its prefix, but any of
// the other targets would, so we need to check those as well.
if lower.key.starts_with(path) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see, with min_len this basically allows should_retain to filter which nodes is sent for proof output?

i.e which nodes are already cached and what nodes are needed

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we can use this to not retain nodes which are already known. In addition we are using min_len to not bother constructing portions of the trie which are already known (or not needed) in the first place.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh i see, its pretty neat that this is the core and its simple 💯

Comment thread crates/trie/trie/src/proof_v2/mod.rs
yongkangc

This comment was marked as outdated.

Comment thread crates/trie/trie/src/proof_v2/target.rs Outdated
Copy link
Copy Markdown
Contributor

@yongkangc yongkangc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! logic wise it makes sense to me and its quite minimal changes compared to what i would have expected

@github-project-automation github-project-automation Bot moved this from Backlog to In Progress in Reth Tracker Dec 15, 2025
Base automatically changed from mediocregopher/19513-proof-rewrite-cached-branches to main December 15, 2025 15:38
Comment thread crates/trie/trie/src/proof_v2/target.rs
@mediocregopher mediocregopher self-assigned this Dec 16, 2025
@mediocregopher mediocregopher marked this pull request as ready for review December 16, 2025 08:53
Copy link
Copy Markdown
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, all of this makes sense, even for me

@mediocregopher mediocregopher added this pull request to the merge queue Dec 23, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Dec 23, 2025
@mediocregopher mediocregopher added this pull request to the merge queue Dec 23, 2025
Merged via the queue into main with commit b79c58d Dec 23, 2025
44 checks passed
@mediocregopher mediocregopher deleted the mediocregopher/19516-proof-rewrite-partial-proofs branch December 23, 2025 12:50
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Reth Tracker Dec 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-engine Related to the engine implementation A-trie Related to Merkle Patricia Trie implementation C-perf A change motivated by improving speed, memory usage or disk footprint

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Proof Calc Rewrite: Partial Proofs

3 participants