Skip to content

Commit

Permalink
feat: tree ids in noir (#3809)
Browse files Browse the repository at this point in the history
Fixes
[#3443](#3443)

Given that the tree ids are used only in 1 noir file I decided to tackle
the issue just by adding a comment to merkle_tree_id.ts and grouping the
constants next to each other.
  • Loading branch information
benesjan authored Jan 3, 2024
1 parent e9077cd commit ec2e36e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 7 additions & 6 deletions yarn-project/aztec-nr/aztec/src/oracle/get_membership_witness.nr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use dep::protocol_types::constants::{
};
use crate::utils::arr_copy_slice;

global CONTRACT_TREE_ID = 0;
global NOTE_HASH_TREE_ID = 2;
global ARCHIVE_TREE_ID = 5;

// Note: We have M here because we need to somehow set it when calling get_membership_witness function and one way to
// do it is to set M here and then set type of the return param, e.g.:
//
Expand All @@ -26,21 +30,18 @@ unconstrained pub fn get_membership_witness<N, M>(block_number: u32, tree_id: Fi
}

unconstrained pub fn get_contract_membership_witness(block_number: u32, leaf_value: Field) -> MembershipWitness<CONTRACT_TREE_HEIGHT, CONTRACT_TREE_HEIGHT + 1> {
let contract_tree_id = 0; // TODO(#3443)
get_membership_witness(block_number, contract_tree_id, leaf_value)
get_membership_witness(block_number, CONTRACT_TREE_ID, leaf_value)
}

// Note: get_nullifier_membership_witness function is implemented in get_nullifier_membership_witness.nr

unconstrained pub fn get_note_hash_membership_witness<N, M>(block_number: u32, leaf_value: Field) -> MembershipWitness<NOTE_HASH_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT + 1> {
let note_hash_tree_id = 2; // TODO(#3443)
get_membership_witness(block_number, note_hash_tree_id, leaf_value)
get_membership_witness(block_number, NOTE_HASH_TREE_ID, leaf_value)
}

// There is no `get_public_data_membership_witness` function because it doesn't make sense to be getting a membership
// witness for a value in the public data tree.

unconstrained pub fn get_archive_membership_witness(block_number: u32, leaf_value: Field) -> MembershipWitness<ARCHIVE_HEIGHT, ARCHIVE_HEIGHT + 1> {
let archive_tree_id = 5; // TODO(#3443)
get_membership_witness(block_number, archive_tree_id, leaf_value)
get_membership_witness(block_number, ARCHIVE_TREE_ID, leaf_value)
}
1 change: 1 addition & 0 deletions yarn-project/types/src/merkle_tree_id.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Defines the possible Merkle tree IDs.
* NOTE: If you change this, update get_membership_witness.nr as well.
*/
export enum MerkleTreeId {
CONTRACT_TREE = 0,
Expand Down

0 comments on commit ec2e36e

Please sign in to comment.