From a5a3a40c70e8fc48e74015eb121874f09c67caf5 Mon Sep 17 00:00:00 2001 From: BGluth Date: Fri, 1 Mar 2024 10:41:25 -0700 Subject: [PATCH 1/2] Creating sub-tries now never hashes leaves - Plonky2 expects (not sure if it's always) leaves to never be hashed that it traverses down to, even if there isn't a read/write on the leaf itself. Note however that it is fine to hash any nodes above the leaf --- mpt_trie/src/trie_subsets.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/mpt_trie/src/trie_subsets.rs b/mpt_trie/src/trie_subsets.rs index 974b92afc..b125c0cf4 100644 --- a/mpt_trie/src/trie_subsets.rs +++ b/mpt_trie/src/trie_subsets.rs @@ -316,10 +316,7 @@ fn mark_nodes_that_are_needed( } } TrackedNodeIntern::Leaf => { - let (k, _) = trie.info.get_leaf_nibbles_and_value_expected(); - if k == curr_nibbles { - trie.info.touched = true; - } + trie.info.touched = true; } } From 132475ae467aeea54b6e4ece239392512b526504 Mon Sep 17 00:00:00 2001 From: BGluth Date: Fri, 1 Mar 2024 14:39:54 -0700 Subject: [PATCH 2/2] Fixed a failing test --- mpt_trie/src/trie_subsets.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mpt_trie/src/trie_subsets.rs b/mpt_trie/src/trie_subsets.rs index b125c0cf4..455d3685c 100644 --- a/mpt_trie/src/trie_subsets.rs +++ b/mpt_trie/src/trie_subsets.rs @@ -288,7 +288,7 @@ fn mark_nodes_that_are_needed( return Err(SubsetTrieError::UnexpectedKey( *curr_nibbles, format!("{:?}", trie), - )) + )); } true => { trie.info.touched = true; @@ -716,14 +716,14 @@ mod tests { } #[test] - fn sub_trie_for_non_existent_key_that_hits_branch_leaf_hashes_out_leaf() { + fn sub_trie_for_non_existent_key_that_hits_branch_leaf_does_not_hash_out_leaf() { common_setup(); let trie = create_trie_with_large_entry_nodes(&[0x1234, 0x1234589, 0x12346]); let partial_trie = create_trie_subset(&trie, [0x1234567]).unwrap(); // Note that `0x1234589` gets hashed at the branch slot at `0x12345`. - assert_nodes_are_hash_nodes(&partial_trie, [0x12345, 0x12346]); + assert_nodes_are_hash_nodes(&partial_trie, Vec::::default()); } #[test]