-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(trie): do not reveal same node twice in sparse trie #14370
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rkrasiuk
reviewed
Feb 10, 2025
496c81d
to
557b344
Compare
557b344
to
50bd2cb
Compare
9fd7871
to
7f341a0
Compare
rkrasiuk
reviewed
Feb 10, 2025
Comment on lines
+29
to
+32
/// Collection of revealed account trie paths. | ||
revealed_account_paths: HashSet<Nibbles>, | ||
/// Collection of revealed storage trie paths, per account. | ||
revealed_storage_paths: B256HashMap<HashSet<Nibbles>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we keep these on trie level instead?
rkrasiuk
approved these changes
Feb 10, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The issue is that it's possible to reveal the same leaf twice if we request two proofs with two leaves that have the same prefix.
For example, in DB we have a leaf at path
0x0d07
. First, we request a proof for leaf0xd7b6990105719101dabeb77144f2a3385c8033acd3af97e9423a695e81ad1eb5
. Then, we request another proof for leaf0xd7999c7eedf8fe42767a51577f99fda631d84616191df1557bdaf61266d16a0f
.In both cases, the multiproof will have a leaf at path
0xd07
, and we will try to reveal it. Current prevention for not revealing it second time is this checkreth/crates/trie/sparse/src/trie.rs
Lines 314 to 317 in a7f895e
0xd7b6990105719101dabeb77144f2a3385c8033acd3af97e9423a695e81ad1eb5
was deleted after it was revealed, so we will reveal the leaf node agian.It's problematic because we could have already deleted a leaf node, and we should not insert it again on proof revealing.
Solution
Maintain a list of revealed paths per account trie and each of storage tries.