go-ethereum/trie/bintrie
CPerezz 169c545693
trie/bintrie: fix GetAccount/GetStorage non-membership — verify stem before returning values
BinaryTrie.GetAccount returned the wrong account data for non-existent
addresses when the trie root was a StemNode (single-account trie). The
StemNode branch directly returned r.Values without verifying that the
queried address's stem matched the node's stem. Similarly, GetStorage
panicked via StemNode.Get("this should not be called directly") when
the root was a StemNode.

Additionally, Empty.GetValuesAtStem returned a non-nil slice of 256
nil entries instead of nil, creating a semantic trap for callers that
check values != nil to determine membership.

Fix all four bug sites:

1. StemNode.Get: replace panic with proper stem verification and value
   lookup, matching InternalNode.Get's contract.

2. GetAccount StemNode branch: delegate to GetValuesAtStem (which
   already has the stem equality check) instead of accessing r.Values
   directly. This is consistent with the InternalNode branch.

3. Empty.GetValuesAtStem: return nil instead of 256 nil values.
   Callers (InternalNode.Get, GetAccount) already handle nil correctly.

4. GetAccount: add explicit nil-values guard before the decode logic
   as defense-in-depth, and simplify the now-redundant values != nil
   condition in the emptyAccount loop.
2026-04-09 14:40:32 +02:00
..
binary_node.go trie/bintrie: cache hashes of clean nodes so as not to rehash the whole tree (#33961) 2026-03-06 18:06:24 +01:00
binary_node_test.go cmd/evm/internal/t8ntool, trie: support for verkle-at-genesis, use UBT, and move the transition tree to its own package (#32445) 2025-11-14 15:25:30 +01:00
empty.go trie/bintrie: fix GetAccount/GetStorage non-membership — verify stem before returning values 2026-04-09 14:40:32 +02:00
empty_test.go trie/bintrie: fix GetAccount/GetStorage non-membership — verify stem before returning values 2026-04-09 14:40:32 +02:00
hashed_node.go trie/bintrie: cache hashes of clean nodes so as not to rehash the whole tree (#33961) 2026-03-06 18:06:24 +01:00
hashed_node_test.go cmd/evm/internal/t8ntool, trie: support for verkle-at-genesis, use UBT, and move the transition tree to its own package (#32445) 2025-11-14 15:25:30 +01:00
hasher.go trie/bintrie: use a sync.Pool when hashing binary tree nodes (#33989) 2026-03-12 10:20:12 +01:00
internal_node.go trie/bintrie: parallelize InternalNode.Hash at shallow tree depths (#34032) 2026-03-18 13:54:23 +01:00
internal_node_test.go trie/bintrie: cache hashes of clean nodes so as not to rehash the whole tree (#33961) 2026-03-06 18:06:24 +01:00
iterator.go trie/bintrie: fix NodeIterator Empty node handling and expose tree accessors (#34056) 2026-03-20 13:53:14 -04:00
iterator_test.go trie/bintrie: fix NodeIterator Empty node handling and expose tree accessors (#34056) 2026-03-20 13:53:14 -04:00
key_encoding.go trie/bintrie: use a sync.Pool when hashing binary tree nodes (#33989) 2026-03-12 10:20:12 +01:00
stem_node.go trie/bintrie: fix GetAccount/GetStorage non-membership — verify stem before returning values 2026-04-09 14:40:32 +02:00
stem_node_test.go trie/bintrie: fix GetAccount/GetStorage non-membership — verify stem before returning values 2026-04-09 14:40:32 +02:00
trie.go trie/bintrie: fix GetAccount/GetStorage non-membership — verify stem before returning values 2026-04-09 14:40:32 +02:00
trie_test.go trie/bintrie: fix GetAccount/GetStorage non-membership — verify stem before returning values 2026-04-09 14:40:32 +02:00