arnaucube
arnaucube/miden-cryptoPublic Self-hosted repository
fix: fix add_path func leaf determination
Andrey Khmuro andrey@polygon.technology
Sat, 03 Jun 2023 15:38:24 +0300
commit

55cc71dadfc5ce801b083e4f274196523cced61c

parent

ebf71c2dc7c1981bf1524aa11566c946136b586a

2 files changed, 8 insertions(+), 7 deletions(-)

jump to
M src/merkle/partial_mt/mod.rs → src/merkle/partial_mt/mod.rs

@@ -213,17 +213,15 @@ index_value.move_up();

// insert calculated node to the nodes map self.nodes.insert(index_value, node); + // if the calculated node was a leaf, remove it from leaves set. + if self.leaves.contains(&index_value) { + self.leaves.remove(&index_value); + } + let sibling_node = index_value.sibling(); // node became a leaf only if it is a new node (it wasn't in nodes map) if !self.nodes.contains_key(&sibling_node) { self.leaves.insert(sibling_node); - } - - // node stops being a leaf if the path contains a node which is a child of this leaf - let mut parent = index_value; - parent.move_up(); - if self.leaves.contains(&parent) { - self.leaves.remove(&parent); } // insert node from Merkle path to the nodes map
M src/merkle/partial_mt/tests.rs → src/merkle/partial_mt/tests.rs

@@ -133,6 +133,9 @@ assert_eq!(pmt.get_leaf_depth(6).unwrap(), 1);

assert_eq!(pmt.get_leaf_depth(7).unwrap(), 1); } +// TODO: add test for add_path function and check correctness of leaf determination (requires +// inner_nodes iter) + // HELPER FUNCTIONS // --------------------------------------------------------------------------------------------