go-ethereum/eth/protocols/snap
ozpool 3c5cca0906 eth/protocols/snap: validate trie node path length
A peer-supplied path in a GetTrieNodes request is fed straight to
accTrie.GetNode (or stTrie.GetNode), which calls compactToHex on
the path before traversing the trie. compactToHex allocates
2*len(path)+1 nibbles regardless of whether the path can possibly
match a node.

Trie keys in any Ethereum state trie are Keccak256 hashes (32 bytes
= 64 nibbles), so the longest valid compact-encoded path is 33 bytes
(64 nibbles + 1 prefix byte). Anything longer is structurally
invalid and cannot address a node.

Currently the handler accepts arbitrary-length paths up to the 10MB
message cap, performing a doomed trie traversal for each one. This
gives a peer a cheap way to amplify CPU/memory usage on the server
and silently makes geth a non-conforming reference for the devp2p
snap test suite (clients that reject long paths at the protocol
layer fail tests that pin geth's accept-and-empty-respond behavior).

Add a guard at both the account-path and storage-path branches of
ServiceGetTrieNodesQuery: if the path exceeds maxTrieNodePathLength
(33 bytes), append a nil placeholder and skip the trie walk. The
nil placeholder preserves positional alignment with the request and
matches the existing wire behavior for paths that resolve to a
non-existent node, so this is a pure CPU/allocation fix and not a
protocol change.

Adds unit tests in handler_test.go covering account paths just over
the limit and far over the limit. The storage-path branch shares the
same guard but exercising it requires a chain with existing accounts;
that coverage is left as a follow-up.

Refs #34853.
2026-04-30 15:44:48 +05:30
..
discovery.go core, eth: split eth package, implement snap protocol (#21482) 2020-12-14 10:27:15 +01:00
gentrie.go eth/protocols/snap: cleanup dangling account trie nodes due to incomplete storage (#30258) 2024-08-12 10:43:54 +02:00
gentrie_test.go common, eth: remove duplicate test cases (#32624) 2025-09-19 17:20:44 -06:00
handler.go eth/protocols/snap: validate trie node path length 2026-04-30 15:44:48 +05:30
handler_fuzzing_test.go core, eth/protocols/snap: Snap/2 Protocol + BAL Serving (#34083) 2026-04-03 14:10:32 +08:00
handler_test.go eth/protocols/snap: validate trie node path length 2026-04-30 15:44:48 +05:30
handlers.go eth/protocols/snap: validate trie node path length 2026-04-30 15:44:48 +05:30
metrics.go eth/protocols/snap: add healing and syncing metrics (#32258) 2025-07-24 16:43:04 +08:00
peer.go eth/protocols/eth, eth/protocols/snap: delayed p2p message decoding (#33835) 2026-02-15 21:21:16 +08:00
progress_test.go core, eth/protocols/snap, internal/ethapi: remove redundant types (#29841) 2024-05-27 14:39:39 +08:00
protocol.go eth/protocols/snap: fix block accessList encoding rule (#34644) 2026-04-07 20:13:19 +08:00
range.go eth/protocols/snap: optimize incHash (#32748) 2025-10-10 13:48:25 +08:00
range_test.go eth/protocols/snap: fix snap sync failure on empty storage range (#28306) 2023-10-13 09:08:26 +02:00
sort_test.go core, les, eth: port snap sync changes (#24898) 2022-07-15 14:55:51 +03:00
sync.go eth/protocols/snap: restore peers to idle pool on request revert (#33790) 2026-02-24 09:14:11 +08:00
sync_test.go eth/protocols/snap: fix data race on testPeer counters (#34802) 2026-04-24 13:37:34 +02:00