From fe20b9bf724eb3342acabf028d8f38a029fefe77 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 12 Dec 2023 14:05:02 +0000 Subject: [PATCH] WIP --- .../aztec/src/history/note_inclusion.nr | 35 +++++++++++++++-- .../inclusion_proofs_contract/src/main.nr | 38 +++++-------------- 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/yarn-project/aztec-nr/aztec/src/history/note_inclusion.nr b/yarn-project/aztec-nr/aztec/src/history/note_inclusion.nr index 0e51d46e0365..92926927181a 100644 --- a/yarn-project/aztec-nr/aztec/src/history/note_inclusion.nr +++ b/yarn-project/aztec-nr/aztec/src/history/note_inclusion.nr @@ -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 = + 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_interface: NoteInterface, + 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); } \ No newline at end of file diff --git a/yarn-project/noir-contracts/src/contracts/inclusion_proofs_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/inclusion_proofs_contract/src/main.nr index a06c832cd500..7c9856e1c3d2 100644 --- a/yarn-project/noir-contracts/src/contracts/inclusion_proofs_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/inclusion_proofs_contract/src/main.nr @@ -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 = - 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`. @@ -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 @@ -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 @@ -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.