fix(trie): pass down hash
function for hashing on trie copies
#2068
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.
Something I noticed here https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/trie/src/trie/secure.ts#L109 is that
hash: this.hash
seems to be missing. TheTrie
passes it down when it callscopy
butCheckpointTrie
andSecureTrie
don't. Is this intentional or an oversight?I assume this could result in corrupted data if you copy a
CheckpointTrie
orSecureTrie
that for example usessha256
but then it doesn't pass down the hash function and the copy works withkeccak256
hashes becauseconst _hash = opts?.hash ?? keccak256
will fall back to thekeccak256
function?I think the above reproduces the issue. If I then change to the following
copy
function forSecureTrie
it'll pass.The above test will fail because it will store
key1
hashed viasha256
andkey2
hashed viakeccak256
but then the copy of the trie will usekeccak256
again becausethis.hash
wasn't passed down which results in it looking upkey1
hashed viakeccak256
instead of thesha256
it was stored as.