forked from visoftsolutions/noir_rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Extend Historical Access APIs AztecProtocol#4179 (AztecProtocol…
…#4375) Resolves AztecProtocol#4179
- Loading branch information
Showing
9 changed files
with
349 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 15 additions & 17 deletions
32
yarn-project/aztec-nr/aztec/src/history/note_inclusion.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,38 @@ | ||
use dep::std::merkle::compute_merkle_root; | ||
use dep::protocol_types::header::Header; | ||
|
||
use crate::{ | ||
context::PrivateContext, | ||
note::{ | ||
utils::compute_note_hash_for_consumption, | ||
note_header::NoteHeader, | ||
note_interface::NoteInterface, | ||
}, | ||
oracle::get_membership_witness::get_note_hash_membership_witness, | ||
}; | ||
|
||
pub fn prove_note_commitment_inclusion( | ||
note_commitment: 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 is included in the archive. | ||
let header = context.get_header_at(block_number); | ||
fn _note_inclusion<Note, N>(note: Note, header: Header) where Note: NoteInterface<N> { | ||
// 1) Compute note_hash | ||
let note_hash = compute_note_hash_for_consumption(note); | ||
|
||
// 2) Get the membership witness of the note in the note hash tree | ||
let witness = get_note_hash_membership_witness(block_number, note_commitment); | ||
let witness = get_note_hash_membership_witness(header.global_variables.block_number as u32, note_hash); | ||
|
||
// 3) Prove that the commitment is in the note hash tree | ||
assert( | ||
header.state.partial.note_hash_tree.root | ||
== compute_merkle_root(note_commitment, witness.index, witness.path), "Proving note inclusion failed" | ||
assert_eq( | ||
header.state.partial.note_hash_tree.root, compute_merkle_root(note_hash, witness.index, witness.path), "Proving note inclusion failed" | ||
); | ||
// --> Now we have traversed the trees all the way up to archive root. | ||
} | ||
|
||
pub fn prove_note_inclusion<Note, N>( | ||
note_with_header: Note, | ||
pub fn prove_note_inclusion<Note, N>(note: Note, context: PrivateContext) where Note: NoteInterface<N> { | ||
_note_inclusion(note, context.historical_header); | ||
} | ||
|
||
pub fn prove_note_inclusion_at<Note, N>( | ||
note: Note, | ||
block_number: u32, // The block at which we'll prove that the note exists | ||
context: PrivateContext | ||
) where Note: NoteInterface<N> { | ||
let note_commitment = compute_note_hash_for_consumption(note_with_header); | ||
let header = context.get_header_at(block_number); | ||
|
||
prove_note_commitment_inclusion(note_commitment, block_number, context); | ||
_note_inclusion(note, header); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 45 additions & 13 deletions
58
yarn-project/aztec-nr/aztec/src/history/nullifier_inclusion.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,64 @@ | ||
use dep::std::merkle::compute_merkle_root; | ||
use dep::protocol_types::header::Header; | ||
|
||
use crate::{ | ||
context::PrivateContext, | ||
oracle::get_nullifier_membership_witness::get_nullifier_membership_witness, | ||
note::{ | ||
utils::compute_siloed_nullifier, | ||
note_interface::NoteInterface, | ||
}, | ||
}; | ||
|
||
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 header = context.get_header_at(block_number); | ||
|
||
// 2) Get the membership witness of the nullifier | ||
let witness = get_nullifier_membership_witness(block_number, nullifier); | ||
fn _nullifier_inclusion(nullifier: Field, header: Header) { | ||
// 1) Get the membership witness of the nullifier | ||
let witness = get_nullifier_membership_witness(header.global_variables.block_number as u32, nullifier); | ||
|
||
// 3) Check that the witness we obtained matches the nullifier | ||
// 2) Check that the witness we obtained matches the nullifier | ||
assert(witness.leaf_preimage.nullifier == nullifier, "Nullifier does not match value in witness"); | ||
|
||
// 4) Compute the nullifier tree leaf | ||
// 3) Compute the nullifier tree leaf | ||
let nullifier_leaf = witness.leaf_preimage.hash(); | ||
|
||
// 5) Prove that the nullifier is in the nullifier tree | ||
// 4) Prove that the nullifier is in the nullifier tree | ||
assert( | ||
header.state.partial.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. | ||
} | ||
|
||
pub fn prove_nullifier_inclusion(nullifier: Field, context: PrivateContext) { | ||
_nullifier_inclusion(nullifier, context.historical_header); | ||
} | ||
|
||
pub fn prove_nullifier_inclusion_at( | ||
nullifier: Field, | ||
block_number: u32, // The block at which we'll prove that the note exists | ||
context: PrivateContext | ||
) { | ||
let header = context.get_header_at(block_number); | ||
|
||
_nullifier_inclusion(nullifier, header); | ||
} | ||
|
||
pub fn prove_note_is_nullified<Note, N>( | ||
note: Note, | ||
context: &mut PrivateContext | ||
) where Note: NoteInterface<N> { | ||
let nullifier = compute_siloed_nullifier(note, context); | ||
|
||
_nullifier_inclusion(nullifier, context.historical_header); | ||
} | ||
|
||
pub fn prove_note_is_nullified_at<Note, N>( | ||
note: Note, | ||
block_number: u32, | ||
context: &mut PrivateContext | ||
) where Note: NoteInterface<N> { | ||
let nullifier = compute_siloed_nullifier(note, context); | ||
let header = context.get_header_at(block_number); | ||
|
||
_nullifier_inclusion(nullifier, header); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.