Skip to content

trie: Fix unit tests when trie refs are reset#19113

Merged
antonis19 merged 2 commits into
mainfrom
trie-reset-refs
Feb 11, 2026
Merged

trie: Fix unit tests when trie refs are reset#19113
antonis19 merged 2 commits into
mainfrom
trie-reset-refs

Conversation

@antonis19

@antonis19 antonis19 commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Some tests in Test_WitnessTrie_GenerateWitness incorrectly passed because the cached trie node hashes were cached, but when tr.Reset() was being called, the unit tests started failing which exposed issues in the trie structure.

Due to this, problems appeared with the witness of #18290 because proofs are requested even for storage keys that haven't been created yet for accounts with no storage, and there was no logic to prevent traversing further than the account. There was a handling introduced for that in #18988 but the fix there was insufficient and the caching hid that the problem wasn't fixed.

This PR fixes the unit tests correctly.

@antonis19

Copy link
Copy Markdown
Contributor Author

RPC eth_getProof test suite passes as well.

Comment on lines -1660 to -1681
// we need to check if we are dealing with the next node being an account node and we have a storage key,
// in that case start a new tree for the storage
if nextAccNode, ok := nextNode.(*trie.AccountNode); ok && len(hashedKey) > 64 {
// If the account has an empty storage root, stop traversal here.
// There's no storage trie to expand into, and continuing would incorporate
// garbage data from rows below the account into the proof.
if nextAccNode.Root == trie.EmptyRoot {
if hph.trace {
fmt.Printf("[witness] AccountNode (empty storage root, break) (%d, %0x, depth=%d) %s proof %+v\n", row, currentNibble, hph.depths[row], cellToExpand.FullString(), nextAccNode)
}
break
}
if cellToExpand.hashedExtLen > 0 {
extKey := common.Copy(cellToExpand.hashedExtension[:cellToExpand.hashedExtLen])
nextNode = &trie.ShortNode{Key: extKey}
} else {
nextNode = &trie.FullNode{}
}
nextAccNode.Storage = nextNode
if hph.trace {
fmt.Printf("[witness] AccountNode (+StorageTrie) (%d, %0x, depth=%d) %s [proof %+v\n", row, currentNibble, hph.depths[row], cellToExpand.FullString(), nextAccNode)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was dead code.

@antonis19 antonis19 merged commit 346253c into main Feb 11, 2026
19 of 20 checks passed
@antonis19 antonis19 deleted the trie-reset-refs branch February 11, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants