Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(stdlib)!: remove unnecessary merkle functions from stdlib #1424

Merged
merged 2 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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