Skip to content

Conversation

@yyhrnk
Copy link
Contributor

@yyhrnk yyhrnk commented Dec 10, 2025

WitnessStats.Add was indexing fixed-size depth arrays directly by len(path), where path is the trie node prefix in nibbles. For state and storage tries these prefixes can easily exceed 15, which makes the index out of range for the [16]int64 backing arrays and causes a panic when collecting witness statistics. This change clamps the computed depth to the last bucket (15+) so that all deeper leaves are still counted without risking an out-of-bounds access, while preserving the existing 0..15 metrics layout.

@yyhrnk yyhrnk requested a review from rjl493456442 as a code owner December 10, 2025 12:46
// The last path is always a leaf.
if i == len(paths)-1 || !strings.HasPrefix(paths[i+1], paths[i]) {
depth := len(path)
if depth >= len(s.accountTrieLeaves) {
Copy link
Member

Choose a reason for hiding this comment

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

pls cap the length according to the type, use accountTrieLeaves or storageTrieLeaves accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pls cap the length according to the type, use accountTrieLeaves or storageTrieLeaves accordingly

corrected, should I add a test?

@rjl493456442 rjl493456442 added this to the 1.16.8 milestone Dec 11, 2025
@rjl493456442 rjl493456442 merged commit 472e3a2 into ethereum:master Dec 11, 2025
7 of 8 checks passed
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