fix(trie): subtrie root node too small to have hash#22114
Open
mediocregopher wants to merge 12 commits intomainfrom
Open
fix(trie): subtrie root node too small to have hash#22114mediocregopher wants to merge 12 commits intomainfrom
mediocregopher wants to merge 12 commits intomainfrom
Conversation
Contributor
✅ Changelog found on PR. |
klkvr
approved these changes
Feb 13, 2026
Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
We encountered a PST bug in one of the trie witness tests given the
following scenario:
In this scenario we have the following nodes:
The branch node is interesting because it is simultaneously the root of its lower subtrie, and its RLP encoding is <32 bytes and is therefore inlined into the parent extension rather than being hashed.
Our implementation of update_upper_subtrie_hashes was incorrectly assuming that the root node of lower subtries would always have its hash field populated, but that field only gets populated if the node is actually hashed.
Primary Solution
The solution is to refactor our sparse trie nodes to cache their RlpNode, rather than their Hash. This way in cases where the node encodes to a length smaller than 32 bytes we still cache the RlpNode, and have that available at the lower subtrie root.
Secondary Changes
Introduced a new enum SparseNodeState to track whether or not a trie node's cached data is valid. This is mostly for code clarity and to make reasoning about the logic easier.
Tests have been updated to always pass 32 byte keys into update/remove_leaf. Many tests were previously malformed and would pass smaller paths into those methods, creating tries which are technically possible from PST's perspective, but not supported in reality.