Skip to content

Commit

Permalink
fixing bug in MT implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
signorecello committed Nov 26, 2024
1 parent 5084696 commit 64b7fa8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/merkle-trees/src/merkle/tests/pedersen.nr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn test_merkle_tree_membership() {

#[test]
fn test_merkle_tree_add() {
let old_root = 0x11e2d065876247ae83558524bb2e51d4547879fb968665e1c75352b3ea5ee1fb;
let old_root = 0x1c59022dba1d97f63021cc5a23e4fe80f019465e0ccb54de9aa91935495354a3;
let mut mt = MerkleTree::from(old_root, pedersen_hasher);

let leaf = 0x67635fc829435949ed0ced751d11f3f823087ec463ca6ee53e253fb7e390e74;
Expand All @@ -36,7 +36,7 @@ fn test_merkle_tree_delete() {

mt.delete(leaf, 0x01, paths);

assert(mt.root == 0x11e2d065876247ae83558524bb2e51d4547879fb968665e1c75352b3ea5ee1fb);
assert(mt.root == 0x1c59022dba1d97f63021cc5a23e4fe80f019465e0ccb54de9aa91935495354a3);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions packages/merkle-trees/src/merkle/tests/poseidon.nr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn test_merkle_tree_membership() {

#[test]
fn test_merkle_tree_add() {
let old_root = 0x15e321a84ad14e8182bad513f664bed0028594caa1485295a410fd09135654b9;
let old_root = 0x1910f234d14bea7c640841c9fd0d765e8599a4cd527285590e4159e66b912be1;
let mut mt = MerkleTree::from(old_root, poseidon_hasher);

let leaf = 0x26059ac500f935d65bf50b096f757fe1dcb3568822d4e4cb7a8dc95f7bbd24f7;
Expand All @@ -35,7 +35,7 @@ fn test_merkle_tree_delete() {
let paths = [0x1910f234d14bea7c640841c9fd0d765e8599a4cd527285590e4159e66b912be1];
mt.delete(leaf, 0x01, paths);

assert(mt.root == 0x15e321a84ad14e8182bad513f664bed0028594caa1485295a410fd09135654b9);
assert(mt.root == 0x1910f234d14bea7c640841c9fd0d765e8599a4cd527285590e4159e66b912be1);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions packages/merkle-trees/src/merkle/tests/poseidon2.nr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn test_merkle_tree_membership() {

#[test]
fn test_merkle_tree_add() {
let old_root = 0x21b9f42cdec1bff42a7b4231c6c506f2f6803ccc4bf5a2481a08e6d4e12e9897;
let old_root = 0x21447efbbddb57d6fc5ad24d906388492e82c44e5160425258dd4ea995e3a06e;
let mut mt = MerkleTree::from(old_root, poseidon2_hasher);

let leaf = 0x2bc00d90b885b09d12764e764410f7f693f514f7f3ca14d916741ff3968b3079;
Expand All @@ -36,7 +36,7 @@ fn test_merkle_tree_delete() {

mt.delete(leaf, 0x01, paths);

assert(mt.root == 0x21b9f42cdec1bff42a7b4231c6c506f2f6803ccc4bf5a2481a08e6d4e12e9897);
assert(mt.root == 0x21447efbbddb57d6fc5ad24d906388492e82c44e5160425258dd4ea995e3a06e);
}

#[test]
Expand Down
3 changes: 2 additions & 1 deletion packages/merkle-trees/src/merkle/tree.nr
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ impl Calculator<Field> for MerkleTree {
let mut root_with_leaf = leaf;
// root_without_leaf is a container for hashes to derive the root node for the tree that
// doesn't include the entry
let mut root_without_leaf: Field = 0;
let mut root_without_leaf: Field = hash_path[0];

// iterate over the levels of the tree from bottom to top
for i in 0..hash_path.len() {
let sibling = hash_path[i];
Expand Down

0 comments on commit 64b7fa8

Please sign in to comment.