Skip to content

Commit

Permalink
chore(stdlib)!: remove unnecessary merkle functions from stdlib (#1424)
Browse files Browse the repository at this point in the history
* chore(stdlib)!: remove unnecessary merkle functions from stdlib

* chore: whitespace change
  • Loading branch information
TomAFrench authored May 27, 2023
1 parent 2777348 commit 50fcb3c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
5 changes: 2 additions & 3 deletions crates/nargo_cli/tests/test_data/merkle_insert/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions crates/nargo_cli/tests/test_data/simple_shield/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
}
14 changes: 2 additions & 12 deletions noir_stdlib/src/merkle.nr
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 50fcb3c

Please sign in to comment.