-
Notifications
You must be signed in to change notification settings - Fork 936
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
Remove leaf hashing in MerkleRoot function #1653
Conversation
See ethereum/consensus-specs#646 for clarification.
e66382b
to
fcf3168
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.
I would rather than not remove leaf hashing as we would still have to do it outside the function to generate the merkle root. Ex:
for i, v := range values {
hashedValue := Hash(v)
values[i] = hashedValue[:]
}
root := MerkleRoot(values)
I rather do the hashing in the function than outside the function and have to add boilerplate code whenever we have to calculate the merkle root.
The thing is, these leaves are not just hashed directly and not hashed immediately before being put into To get specific, the
The issue is less about whether or not to keep a MerkleRoot function that hashes the leaves, and more about this specific instance, where you most likely will need a function that returns a merkle root, but does not hash the leaves. |
@wemeetagain In that case it makes sense :) . Could you add a comment stating why we are not hashing the leaves in the function and are assuming that the leaves are pre-hashed |
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 , thanks for this !
Codecov Report
@@ Coverage Diff @@
## master #1653 +/- ##
==========================================
- Coverage 71.49% 70.85% -0.65%
==========================================
Files 98 97 -1
Lines 7010 6687 -323
==========================================
- Hits 5012 4738 -274
+ Misses 1553 1523 -30
+ Partials 445 426 -19 |
Description
Previously, the MerkleRoot function hashed the leaves provided as input.
This is in line with merkle hashing, generally speaking, however the spec's definition of the merkle_root function makes an optimization by assuming that the leaves are pre-hashed, and therefore not hashing the leaves.
This update removes the hashing of the leaf nodes from the MerkleRoot function and updates the MerkleRoot test.
See ethereum/consensus-specs#646 for clarification.