Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Dec 12, 2023
1 parent 9537457 commit fe20b9b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 33 deletions.
35 changes: 31 additions & 4 deletions yarn-project/aztec-nr/aztec/src/history/note_inclusion.nr
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
use create::context::PrivateContext;
use crate::{

context::PrivateContext,

fn prove_note_commitment_inclusion(
pub fn prove_note_commitment_inclusion(
note_commitment: Fr,
block_number: Field, // The block at which we'll prove that the note exists
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 is included in the archive.
let block_header = context.get_block_header(block_number);

// 4) Get the membership witness of the note in the note hash tree
let note_hash_tree_id = 2; // TODO(#3443)
let witness: MembershipWitness<NOTE_HASH_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT + 1> =
get_membership_witness(block_number, note_hash_tree_id, note_commitment);

// 5) Prove that the commitment is in the note hash tree
assert(
block_header.note_hash_tree_root == compute_merkle_root(note_commitment, witness.index, witness.path),
"Proving note inclusion failed"
);

// --> Now we have traversed the trees all the way up to blocks tree root.
}

pub fn prove_note_inclusion<Note, N>(
note_interface: NoteInterface<Note, N>,
note_with_header: Note,
block_number: u32, // The block at which we'll prove that the note exists
context: PrivateContext
) {
let note_commitment = note_utils::compute_unique_siloed_note_hash(ValueNoteMethods, note_with_header)

prove_note_commitment_inclusion(note_commitment, block_number, context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,36 +101,19 @@ contract InclusionProofs {
block_number: u32, // The block at which we'll prove that the note exists
spare_commitment: Field, // This is only used when the note is not found --> used to test the failure case
) {
// 1) Get block header from oracle and ensure that the block hash is included in the current blocks tree
// root.
let block_header = context.get_block_header(block_number);

// 2) Get the note from PXE.
// 1) Get the note from PXE.
let private_values = storage.private_values.at(owner.address);
let options = NoteGetterOptions::new().select(1, owner.address).set_limit(1);
let notes = private_values.get_notes(options);
let maybe_note = notes[0];

// 3) Compute the commitment from the note
let note_commitment = if maybe_note.is_some() {
note_utils::compute_unique_siloed_note_hash(ValueNoteMethods, maybe_note.unwrap_unchecked())
// 2) Prove the note inclusion
if maybe_note.is_some() {
prove_note_inclusion(ValueNoteMethods, maybe_note.unwrap_unchecked(), block_number, context);
} else {
// Note was not found so we will use the spare commitment
spare_commitment
// Note was not found so we will prove inclusion of the spare commitment
prove_note_commitment_inclusion(spare_commitment, block_number, context);
};

// 4) Get the membership witness of the note in the note hash tree
let note_hash_tree_id = 2; // TODO(#3443)
let witness: MembershipWitness<NOTE_HASH_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT + 1> =
get_membership_witness(block_number, note_hash_tree_id, note_commitment);

// 5) Prove that the commitment is in the note hash tree
assert(
block_header.note_hash_tree_root == compute_merkle_root(note_commitment, witness.index, witness.path),
"Proving note inclusion failed"
);

// --> Now we have traversed the trees all the way up to blocks tree root.
}

// Proves that the note was not yet nullified at block `block_number`.
Expand All @@ -140,8 +123,7 @@ contract InclusionProofs {
block_number: u32, // The block at which we'll prove that the nullifier does not exists
spare_nullifier: Field, // This is only used when the note is not found --> used to test the failure case
) {
// 1) Get block header from oracle and ensure that the block hash is included in the current blocks tree
// root.
// 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 note from PXE
Expand Down Expand Up @@ -207,8 +189,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 current blocks tree
// root.
// 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
Expand All @@ -235,8 +216,7 @@ contract InclusionProofs {
public_value: Field,
block_number: u32, // The block at which we'll prove that the public value exists
) {
// 1) Get block header from oracle and ensure that the block hash is included in the current blocks tree
// root.
// 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) Compute the public value leaf index.
Expand Down

0 comments on commit fe20b9b

Please sign in to comment.