-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
38 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
mod note_inclusion; | ||
mod nullifier_inclusion; | ||
mod nullifier_non_inclusion; |
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 |
---|---|---|
@@ -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. | ||
} |
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