Skip to content

Commit 3403877

Browse files
authored
feat: specific membership witness functions in aztec-nr (AztecProtocol#3674)
Fixes AztecProtocol#3663
1 parent fcb04a7 commit 3403877

File tree

5 files changed

+42
-29
lines changed

5 files changed

+42
-29
lines changed

yarn-project/aztec-nr/aztec/src/history/note_inclusion.nr

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use dep::protocol_types::constants::NOTE_HASH_TREE_HEIGHT;
21
use dep::std::merkle::compute_merkle_root;
32

43
use crate::{
@@ -8,10 +7,7 @@ use crate::{
87
note_header::NoteHeader,
98
note_interface::NoteInterface,
109
},
11-
oracle::get_membership_witness::{
12-
get_membership_witness,
13-
MembershipWitness,
14-
},
10+
oracle::get_membership_witness::get_note_hash_membership_witness,
1511
};
1612

1713
pub fn prove_note_commitment_inclusion(
@@ -23,9 +19,7 @@ pub fn prove_note_commitment_inclusion(
2319
let block_header = context.get_block_header(block_number);
2420

2521
// 2) Get the membership witness of the note in the note hash tree
26-
let note_hash_tree_id = 2; // TODO(#3443)
27-
let witness: MembershipWitness<NOTE_HASH_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT + 1> =
28-
get_membership_witness(block_number, note_hash_tree_id, note_commitment);
22+
let witness = get_note_hash_membership_witness(block_number, note_commitment);
2923

3024
// 3) Prove that the commitment is in the note hash tree
3125
assert(

yarn-project/aztec-nr/aztec/src/history/public_value_inclusion.nr

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
use dep::protocol_types::{
2-
constants::{
3-
PUBLIC_DATA_TREE_HEIGHT,
4-
GENERATOR_INDEX__PUBLIC_LEAF_INDEX,
5-
},
2+
constants::GENERATOR_INDEX__PUBLIC_LEAF_INDEX,
63
hash::pedersen_hash,
74
};
85
use dep::std::merkle::compute_merkle_root;
96

107
use crate::{
118
context::PrivateContext,
12-
oracle::get_sibling_path::get_sibling_path,
9+
oracle::get_sibling_path::get_public_data_sibling_path,
1310
};
1411

1512
pub fn prove_public_value_inclusion(
@@ -31,9 +28,7 @@ pub fn prove_public_value_inclusion(
3128
);
3229

3330
// 3) Get the sibling path of the value leaf index in the public data tree at block `block_number`.
34-
let public_data_tree_id = 3; // TODO(#3443)
35-
let path: [Field; PUBLIC_DATA_TREE_HEIGHT] =
36-
get_sibling_path(block_number, public_data_tree_id, value_leaf_index);
31+
let path = get_public_data_sibling_path(block_number, value_leaf_index);
3732

3833
// 4) Prove that the value provided on input is in the public data tree at the given storage slot.
3934
assert(

yarn-project/aztec-nr/aztec/src/oracle/get_block_header.nr

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
use dep::std::merkle::compute_merkle_root;
22
use dep::protocol_types::{
33
abis::block_header::BlockHeader,
4-
constants::{
5-
BLOCK_HEADER_LENGTH,
6-
ARCHIVE_HEIGHT,
7-
},
4+
constants::BLOCK_HEADER_LENGTH,
85
};
96

107
use crate::{
118
context::PrivateContext,
12-
oracle::get_membership_witness::{
13-
get_membership_witness,
14-
MembershipWitness,
15-
},
9+
oracle::get_membership_witness::get_archive_membership_witness,
1610
};
1711

1812
// TODO(#3564) - Nuke this oracle and Inject the number directly to context
@@ -47,8 +41,7 @@ pub fn get_block_header(block_number: u32, context: PrivateContext) -> BlockHead
4741
let block_hash = block_header.block_hash();
4842

4943
// 5) Get the membership witness of the block in the archive
50-
let archive_id = 5; // TODO(#3443)
51-
let witness: MembershipWitness<ARCHIVE_HEIGHT, ARCHIVE_HEIGHT + 1> = get_membership_witness(block_header_block_number, archive_id, block_hash);
44+
let witness = get_archive_membership_witness(block_header_block_number, block_hash);
5245

5346
// 6) Check that the block is in the archive (i.e. the witness is valid)
5447
assert(context.block_header.archive_root == compute_merkle_root(block_hash, witness.index, witness.path), "Proving membership of a block in archive failed");

yarn-project/aztec-nr/aztec/src/oracle/get_membership_witness.nr

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use dep::protocol_types::constants::NOTE_HASH_TREE_HEIGHT;
1+
use dep::protocol_types::constants::{
2+
ARCHIVE_HEIGHT,
3+
CONTRACT_TREE_HEIGHT,
4+
NOTE_HASH_TREE_HEIGHT,
5+
};
26
use crate::utils::arr_copy_slice;
37

48
// Note: We have M here because we need to somehow set it when calling get_membership_witness function and one way to
@@ -20,3 +24,23 @@ unconstrained pub fn get_membership_witness<N, M>(block_number: u32, tree_id: Fi
2024
let fields: [Field; M] = get_membership_witness_oracle(block_number, tree_id, leaf_value);
2125
MembershipWitness { index: fields[0], path: arr_copy_slice(fields, [0; N], 1) }
2226
}
27+
28+
unconstrained pub fn get_contract_membership_witness(block_number: u32, leaf_value: Field) -> MembershipWitness<CONTRACT_TREE_HEIGHT, CONTRACT_TREE_HEIGHT + 1> {
29+
let contract_tree_id = 0; // TODO(#3443)
30+
get_membership_witness(block_number, contract_tree_id, leaf_value)
31+
}
32+
33+
// Note: get_nullifier_membership_witness function is implemented in get_nullifier_membership_witness.nr
34+
35+
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> {
36+
let note_hash_tree_id = 2; // TODO(#3443)
37+
get_membership_witness(block_number, note_hash_tree_id, leaf_value)
38+
}
39+
40+
// There is no `get_public_data_membership_witness` function because it doesn't make sense to be getting a membership
41+
// witness for a value in the public data tree.
42+
43+
unconstrained pub fn get_archive_membership_witness(block_number: u32, leaf_value: Field) -> MembershipWitness<ARCHIVE_HEIGHT, ARCHIVE_HEIGHT + 1> {
44+
let archive_tree_id = 5; // TODO(#3443)
45+
get_membership_witness(block_number, archive_tree_id, leaf_value)
46+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use dep::protocol_types::constants::NOTE_HASH_TREE_HEIGHT;
2-
use crate::utils::arr_copy_slice;
1+
use dep::protocol_types::constants::PUBLIC_DATA_TREE_HEIGHT;
32

43
#[oracle(getSiblingPath)]
54
fn get_sibling_path_oracle<N>(_block_number: u32, _tree_id: Field, _leaf_index: Field) -> [Field; N] {}
@@ -8,3 +7,11 @@ unconstrained pub fn get_sibling_path<N>(block_number: u32, tree_id: Field, leaf
87
let value: [Field; N] = get_sibling_path_oracle(block_number, tree_id, leaf_index);
98
value
109
}
10+
11+
unconstrained pub fn get_public_data_sibling_path<N>(block_number: u32, leaf_index: Field) -> [Field; PUBLIC_DATA_TREE_HEIGHT] {
12+
let public_data_tree_id = 3; // TODO(#3443)
13+
get_sibling_path(block_number, public_data_tree_id, leaf_index)
14+
}
15+
16+
// We don't implement specific function for other trees than public data tree because for the rest it makes sense
17+
// to use get membership witness function instead.

0 commit comments

Comments
 (0)