diff --git a/crates/nargo_cli/tests/test_data/merkle_insert/src/main.nr b/crates/nargo_cli/tests/test_data/merkle_insert/src/main.nr index f90bcac3efa..3de10520037 100644 --- a/crates/nargo_cli/tests/test_data/merkle_insert/src/main.nr +++ b/crates/nargo_cli/tests/test_data/merkle_insert/src/main.nr @@ -9,9 +9,8 @@ fn main( index: Field, mimc_input: [Field; 4], ) { - let old_leaf_exists = std::merkle::check_membership(old_root, old_leaf, index, old_hash_path); - assert(old_leaf_exists); - assert(old_root == std::merkle::compute_root_from_leaf(old_leaf, index, old_hash_path)); + assert(old_root == std::merkle::compute_merkle_root(old_leaf, index, old_hash_path)); + let calculated_root = std::merkle::compute_merkle_root(leaf, index, old_hash_path); assert(new_root == calculated_root); diff --git a/crates/nargo_cli/tests/test_data/simple_shield/src/main.nr b/crates/nargo_cli/tests/test_data/simple_shield/src/main.nr index 4b3eeae409a..18fccd862b5 100644 --- a/crates/nargo_cli/tests/test_data/simple_shield/src/main.nr +++ b/crates/nargo_cli/tests/test_data/simple_shield/src/main.nr @@ -29,8 +29,7 @@ fn main( let receiver_note_commitment = std::hash::pedersen([to_pubkey_x, to_pubkey_y]); // Check that the input note nullifier is in the root - let is_member = std::merkle::check_membership(note_root, note_commitment[0], index, note_hash_path); - assert(is_member); + assert(note_root == std::merkle::compute_merkle_root(note_commitment[0], index, note_hash_path)); [nullifier[0], receiver_note_commitment[0]] } diff --git a/noir_stdlib/src/merkle.nr b/noir_stdlib/src/merkle.nr index aa4aa8c40da..1a8f2ca3811 100644 --- a/noir_stdlib/src/merkle.nr +++ b/noir_stdlib/src/merkle.nr @@ -1,19 +1,9 @@ // Regular merkle tree means a append-only merkle tree (Explain why this is the only way to have privacy and alternatives if you don't want it) - -// Returns one if the leaf is in the tree -// and it is at the given index -// and the hashpath proves this // Currently we assume that it is a binary tree, so depth k implies a width of 2^k // XXX: In the future we can add an arity parameter -fn check_membership(_root : Field, _leaf : Field, _index : Field, _hash_path: [Field]) -> bool { - compute_merkle_root(_leaf, _index, _hash_path) == _root -} - -#[foreign(compute_merkle_root)] -fn compute_merkle_root(_leaf : Field, _index : Field, _hash_path: [Field]) -> Field {} -// Returns the root of the tree from the provided leaf and its hashpath, using pedersen hash -fn compute_root_from_leaf(leaf : Field, index : Field, hash_path: [Field]) -> Field { +// Returns the merkle root of the tree from the provided leaf, its hashpath, using a pedersen hash function. +fn compute_merkle_root(leaf: Field, index: Field, hash_path: [Field]) -> Field { let n = hash_path.len(); let index_bits = index.to_le_bits(n as u32); let mut current = leaf;