From b824c597d8000fa86fc733ca4b2e4d6639a5927d Mon Sep 17 00:00:00 2001 From: BGluth Date: Wed, 10 Jan 2024 13:58:26 -0700 Subject: [PATCH] Fixed subtle bug with trie iterators - The iterator made the assumption that a hash node would never follow an extension node. This actually can happen in practice, and when it did, it would destroy part of the key. --- src/trie_ops.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/trie_ops.rs b/src/trie_ops.rs index 0de89d3..3743baf 100644 --- a/src/trie_ops.rs +++ b/src/trie_ops.rs @@ -179,8 +179,11 @@ impl PartialTrieIter { self.advance_iter_to_next_empty_leaf_or_hash_node(&children[0], curr_key) } Node::Extension { nibbles, child } => { + if TrieNodeType::from(child) != TrieNodeType::Hash { self.trie_stack .push(IterStackEntry::Extension(nibbles.count)); + } + curr_key = curr_key.merge_nibbles(nibbles); self.advance_iter_to_next_empty_leaf_or_hash_node(child, curr_key)