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

feat: libraryfying historic access #3658

Merged
merged 7 commits into from
Dec 13, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
nullifier inclusion libraryfied
benesjan committed Dec 12, 2023
commit 06ee4512cd49c69dd41124f04cd5382e33eecf31
1 change: 1 addition & 0 deletions yarn-project/aztec-nr/aztec/src/history.nr
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mod note_inclusion;
mod nullifier_inclusion;
mod nullifier_non_inclusion;
33 changes: 33 additions & 0 deletions yarn-project/aztec-nr/aztec/src/history/nullifier_inclusion.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use dep::std::merkle::compute_merkle_root;

use crate::{
context::PrivateContext,
oracle::get_nullifier_membership_witness::get_nullifier_membership_witness,
};

pub fn prove_nullifier_inclusion(
nullifier: Field,
block_number: u32, // The block at which we'll prove that the note exists
context: PrivateContext
) {
// 1) Get block header from oracle and ensure that the block hash is included in the archive.
let block_header = context.get_block_header(block_number);

// 2) Get the membership witness of the nullifier
let witness = get_nullifier_membership_witness(block_number, nullifier);

// 3) Check that the witness we obtained matches the nullifier
assert(witness.leaf_data.value == nullifier, "Nullifier does not match value in witness");

// 4) Compute the nullifier tree leaf
let nullifier_leaf = witness.leaf_data.hash();

// 5) Prove that the nullifier is in the nullifier tree
assert(
block_header.nullifier_tree_root == compute_merkle_root(nullifier_leaf, witness.index, witness.path),
"Proving nullifier inclusion failed"
);

// --> Now we have traversed the trees all the way up to archive root and verified that the nullifier
// was not yet included in the nullifier tree.
}
Original file line number Diff line number Diff line change
@@ -39,6 +39,9 @@ contract InclusionProofs {
prove_note_commitment_inclusion,
prove_note_inclusion,
},
nullifier_inclusion::{
prove_nullifier_inclusion,
},
nullifier_non_inclusion::{
prove_nullifier_non_inclusion,
prove_note_not_nullified,
@@ -158,26 +161,7 @@ contract InclusionProofs {
nullifier: Field,
block_number: u32, // The block at which we'll prove that the nullifier not exists in the tree
) {
// 1) Get block header from oracle and ensure that the block hash is included in the archive.
let block_header = context.get_block_header(block_number);

// 2) Get the membership witness of the nullifier
let witness = get_nullifier_membership_witness(block_number, nullifier);

// 3) Check that the witness we obtained matches the nullifier
assert(witness.leaf_data.value == nullifier, "Nullifier does not match value in witness");

// 4) Compute the nullifier tree leaf
let nullifier_leaf = witness.leaf_data.hash();

// 5) Prove that the nullifier is in the nullifier tree
assert(
block_header.nullifier_tree_root == compute_merkle_root(nullifier_leaf, witness.index, witness.path),
"Proving nullifier inclusion failed"
);

// --> Now we have traversed the trees all the way up to blocks tree root and verified that the nullifier
// was not yet included in the nullifier tree.
prove_nullifier_inclusion(nullifier, block_number, context);
}

#[aztec(private)]