Skip to content

Commit

Permalink
Creating sub-tries now never hashes leaves (#76)
Browse files Browse the repository at this point in the history
* 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

* Fixed a failing test
  • Loading branch information
BGluth authored Mar 5, 2024
1 parent ac1998c commit ff4c767
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions mpt_trie/src/trie_subsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn mark_nodes_that_are_needed<N: PartialTrie>(
return Err(SubsetTrieError::UnexpectedKey(
*curr_nibbles,
format!("{:?}", trie),
))
));
}
true => {
trie.info.touched = true;
Expand Down Expand Up @@ -316,10 +316,7 @@ fn mark_nodes_that_are_needed<N: PartialTrie>(
}
}
TrackedNodeIntern::Leaf => {
let (k, _) = trie.info.get_leaf_nibbles_and_value_expected();
if k == curr_nibbles {
trie.info.touched = true;
}
trie.info.touched = true;
}
}

Expand Down Expand Up @@ -719,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::<Nibbles>::default());
}

#[test]
Expand Down

0 comments on commit ff4c767

Please sign in to comment.