-
Notifications
You must be signed in to change notification settings - Fork 599
feat: Extend Historical Access APIs #4179 #4375
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cf1ee1b
fix
76ed297
fix
442d5af
Merge branch 'master' into ek/fix/extend-historical-state
6957185
next
546cdc6
Merge branch 'master' into ek/fix/extend-historical-state
363abd4
Merge branch 'master' into ek/feat/extend-historical-state
df85ca2
address comments nr
c82cbc9
fix tests
a0c9b3d
format
67a94b2
fix format
ea998fc
Merge branch 'master' into ek/feat/extend-historical-state
sklppy88 65bc812
Merge branch 'master' into ek/feat/extend-historical-state
sklppy88 e6a8c67
Merge branch 'master' into ek/feat/extend-historical-state
sklppy88 b333747
Merge branch 'master' into ek/feat/extend-historical-state
c289e23
Addressing comments and fixing merge problems
efd125b
Merge branch 'master' into ek/feat/extend-historical-state
sklppy88 f134042
bump
f220fce
Revert "bump"
80f2ed7
fix ?
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||
sklppy88 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.