-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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): reveal extension child in sparse trie when updating a leaf #13183
Conversation
crates/trie/sparse/src/trie.rs
Outdated
*key = current.slice(current.len() - key.len()..common); | ||
|
||
// Check if the extension node child is a hash that needs to be revealed | ||
if self.nodes.get(¤t).unwrap().is_hash() { |
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.
only if updates are enabled
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.
done
2d8c899
to
522273f
Compare
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.
lgtm
if self.updates.is_some() { | ||
// Check if the extension node child is a hash that needs to be revealed | ||
if self.nodes.get(¤t).unwrap().is_hash() { |
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.
surprised clippy does not complain
Consider the following scenario:
0x77853ecb3c80cc9dd0543d964574eefd6e89131a8e875c3606451dabd99ae6f4
0x77853ec
which is an extension nodeExtension(ExtensionNode { key: Nibbles("0d"), child: "a04d1721cf2c8ae2649fffbf4c5bc6e71ac1646e592ff4bfeb3054aa4d56b69456" })
0x77853ecb3c80cc9dd0543d964574eefd6e89131a8e875c3606451dabd99ae6f4
and turn the extension node into a branch node, setting the old nibbled
from the extension node in the state mask of the new branch node.The problem here is that the node under the nibble
d
may be a branch node that will need to appear in the hash mask of the newly created branch node, but we don't know if that's a branch node unless we reveal the extension node child.This PR reveals the original extension node child when we turn an extension node into a branch node with two children.