Skip to content

Trie: reject ROOT-keyed items in put_chunk#3762

Merged
jsdanielh merged 1 commit into
albatrossfrom
stefan/put-chunk-reject-root-keyed-item
May 6, 2026
Merged

Trie: reject ROOT-keyed items in put_chunk#3762
jsdanielh merged 1 commit into
albatrossfrom
stefan/put-chunk-reject-root-keyed-item

Conversation

@jsdanielh

Copy link
Copy Markdown
Member

What's in this pull request?

MerkleRadixTrie::put_chunk processes TrieChunk data from state-sync peers. It validates sorting, key range, and the Merkle proof but does not reject items whose key is KeyNibbles::ROOT (the empty-nibbles root key). When such an item reaches put_raw, the equal-key branch calls cur_node.put_value(value).unwrap() on the root node.

A malicious sync peer crafts a ResponseChunk::Chunk whose items[0].key == KeyNibbles::ROOT. ROOT is the lexicographically smallest key, so the sort check passes. The proof verifies because it is over the last item's Merkle path, not every item. The crash fires on the first chunk the node commits.

Fix

  1. Reject any item whose key is empty, inside the existing if !chunk.items.is_empty() { … } block, using the existing InvalidChunk error variant. items[0] is sufficient because the existing sort check guarantees strictly increasing keys and ROOT is the minimum.

Impact

  • Consensus / wire format / public API: none. InvalidChunk is already returned for other chunk validation failures; commit_chunks already aborts the txn, logs a warn, and triggers reset_chunk_request_chain() in the live-sync layer. Honest peers never construct ROOT-keyed items.

@jsdanielh jsdanielh force-pushed the stefan/put-chunk-reject-root-keyed-item branch from 8820a62 to 0fb8766 Compare May 6, 2026 22:29
@jsdanielh jsdanielh merged commit 0fb8766 into albatross May 6, 2026
6 of 8 checks passed
@jsdanielh jsdanielh deleted the stefan/put-chunk-reject-root-keyed-item branch May 6, 2026 22:29
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.

3 participants