-
Notifications
You must be signed in to change notification settings - Fork 327
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
feat: add historical library tests and remove old inclusion proof contract / related tests #12215
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c724b3f
init
84e7350
addressing comments
f0be1ee
addressing more feedback
478c074
Update noir-projects/aztec-nr/aztec/src/history/public_storage/test.nr
sklppy88 9c29d3c
Update noir-projects/aztec-nr/aztec/src/history/public_storage/test.nr
sklppy88 ff619fc
Update noir-projects/aztec-nr/aztec/src/history/test.nr
sklppy88 68bd62a
Update noir-projects/aztec-nr/aztec/src/history/test.nr
sklppy88 a4a8851
Update noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr
sklppy88 53e8d21
addressing more comments
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,7 @@ | |
"Nargo", | ||
"nixpkgs", | ||
"nodebuffer", | ||
"noinitcheck", | ||
"noirc", | ||
"noirup", | ||
"nullifer", | ||
|
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
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,6 +1,7 @@ | ||
mod contract_inclusion; | ||
mod note_inclusion; | ||
mod note_validity; | ||
mod nullifier_inclusion; | ||
mod nullifier_non_inclusion; | ||
mod public_storage; | ||
pub mod contract_inclusion; | ||
pub mod note_inclusion; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exposing all these as well to remove warnings |
||
pub mod note_validity; | ||
pub mod nullifier_inclusion; | ||
pub mod nullifier_non_inclusion; | ||
pub mod public_storage; | ||
mod test; |
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
22 changes: 22 additions & 0 deletions
22
noir-projects/aztec-nr/aztec/src/history/note_inclusion/test.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use crate::history::{note_inclusion::ProveNoteInclusion, test}; | ||
|
||
// In this test, we create a note and prove its inclusion in the block of its creation. | ||
#[test] | ||
unconstrained fn note_inclusion() { | ||
let (env, retrieved_note) = test::create_note(); | ||
|
||
let context = &mut env.private_at(test::NOTE_CREATED_AT); | ||
|
||
// docs:start:prove_note_inclusion | ||
context.historical_header.prove_note_inclusion(retrieved_note, test::NOTE_STORAGE_SLOT); | ||
// docs:end:prove_note_inclusion | ||
} | ||
|
||
// In this test, we create a note and fail to prove its inclusion in the block before its creation. | ||
#[test(should_fail_with = "not found in NOTE_HASH_TREE at block 1")] | ||
unconstrained fn note_inclusion_fails() { | ||
benesjan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let (env, retrieved_note) = test::create_note(); | ||
|
||
let context = &mut env.private_at(test::NOTE_CREATED_AT - 1); | ||
context.historical_header.prove_note_inclusion(retrieved_note, test::NOTE_STORAGE_SLOT); | ||
} |
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
38 changes: 38 additions & 0 deletions
38
noir-projects/aztec-nr/aztec/src/history/note_validity/test.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::history::note_validity::ProveNoteValidity; | ||
use crate::history::test; | ||
|
||
// In these tests, we create a note in one block and nullify it in the next. | ||
|
||
// In this test, we fail to prove the note's validity in the block before its creation. It fails the validity check due to | ||
// non-inclusion of the note in the block before its creation. | ||
#[test(should_fail_with = "not found in NOTE_HASH_TREE at block 1")] | ||
unconstrained fn note_not_valid_due_to_non_inclusion() { | ||
let (env, retrieved_note) = test::create_note_and_nullify_it(); | ||
|
||
let context = &mut env.private_at(test::NOTE_CREATED_AT - 1); | ||
|
||
context.historical_header.prove_note_validity(retrieved_note, test::NOTE_STORAGE_SLOT, context); | ||
} | ||
|
||
// In this test, we prove the note's validity in the block at its creation, and before its nullification. It succeeds | ||
// because it is included and not nullified at the block specified. | ||
#[test] | ||
unconstrained fn note_is_valid() { | ||
let (env, retrieved_note) = test::create_note_and_nullify_it(); | ||
|
||
let context = &mut env.private_at(test::NOTE_CREATED_AT); | ||
|
||
// docs:start:prove_note_validity | ||
context.historical_header.prove_note_validity(retrieved_note, test::NOTE_STORAGE_SLOT, context); | ||
// docs:end:prove_note_validity | ||
} | ||
|
||
// In this test, we fail to prove the note's validity in the block at its nullification. It fails the validity check due to | ||
// its nullifier being included in the state at one block after it was created. | ||
#[test(should_fail_with = "Proving nullifier non-inclusion failed")] | ||
unconstrained fn note_not_valid_due_to_nullification() { | ||
let (env, retrieved_note) = test::create_note_and_nullify_it(); | ||
|
||
let context = &mut env.private_at(test::NOTE_NULLIFIED_AT); | ||
context.historical_header.prove_note_validity(retrieved_note, test::NOTE_STORAGE_SLOT, context); | ||
} |
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
55 changes: 55 additions & 0 deletions
55
noir-projects/aztec-nr/aztec/src/history/nullifier_inclusion/test.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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use crate::history::{nullifier_inclusion::{ProveNoteIsNullified, ProveNullifierInclusion}, test}; | ||
use crate::oracle::random::random; | ||
use crate::test::helpers::test_environment::FIRST_NULLIFIER_EMITTED_IN_TXE; | ||
|
||
// In these tests, we create a note in one block and nullify it in the next. | ||
|
||
// In this test, we prove the presence of the note's nullifier in state at the block it was nullified in. | ||
#[test] | ||
unconstrained fn note_is_nullified() { | ||
let (env, retrieved_note) = test::create_note_and_nullify_it(); | ||
|
||
let context = &mut env.private_at(test::NOTE_NULLIFIED_AT); | ||
|
||
context.historical_header.prove_note_is_nullified( | ||
retrieved_note, | ||
test::NOTE_STORAGE_SLOT, | ||
context, | ||
); | ||
} | ||
|
||
// In this test, we fail to prove the presence of the note's nullifier in state at the block before it was nullified. | ||
#[test(should_fail_with = "Nullifier membership witness not found at block 2.")] | ||
unconstrained fn note_is_not_nullified() { | ||
let (env, retrieved_note) = test::create_note_and_nullify_it(); | ||
|
||
let context = &mut env.private_at(test::NOTE_NULLIFIED_AT - 1); | ||
|
||
context.historical_header.prove_note_is_nullified( | ||
retrieved_note, | ||
test::NOTE_STORAGE_SLOT, | ||
context, | ||
); | ||
} | ||
|
||
// In this test, we prove the inclusion of an existing nullifier in state. We use know FIRST_NULLIFIER_EMITTED_IN_TXE exists | ||
// because the TXe creates deterministic first nullifiers if no side-effects are emitted. | ||
#[test] | ||
unconstrained fn nullifier_inclusion() { | ||
let (env) = test::create_note_and_nullify_it(); | ||
|
||
let context = &mut env.private(); | ||
|
||
// docs:start:prove_nullifier_inclusion | ||
context.historical_header.prove_nullifier_inclusion(FIRST_NULLIFIER_EMITTED_IN_TXE); | ||
// docs:end:prove_nullifier_inclusion | ||
} | ||
|
||
// In this test, we fail to prove the inclusion of an arbitrary nullifier in state. | ||
#[test(should_fail_with = "Nullifier membership witness not found")] | ||
unconstrained fn nullifier_inclusion_fails() { | ||
let (env) = test::create_note_and_nullify_it(); | ||
|
||
let context = &mut env.private(); | ||
context.historical_header.prove_nullifier_inclusion(random()); | ||
} |
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
55 changes: 55 additions & 0 deletions
55
noir-projects/aztec-nr/aztec/src/history/nullifier_non_inclusion/test.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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use crate::history::nullifier_non_inclusion::{ProveNoteNotNullified, ProveNullifierNonInclusion}; | ||
use crate::oracle::random::random; | ||
|
||
use crate::history::test; | ||
use crate::test::helpers::test_environment::FIRST_NULLIFIER_EMITTED_IN_TXE; | ||
|
||
// In these tests, we create a note in one block and nullify it in the next. | ||
|
||
// In this test, we prove the absence of the note's nullifier in state at the block before it was nullified. | ||
#[test] | ||
unconstrained fn note_not_nullified() { | ||
let (env, retrieved_note) = test::create_note_and_nullify_it(); | ||
|
||
let context = &mut env.private_at(test::NOTE_NULLIFIED_AT - 1); | ||
|
||
context.historical_header.prove_note_not_nullified( | ||
retrieved_note, | ||
test::NOTE_STORAGE_SLOT, | ||
context, | ||
); | ||
} | ||
|
||
// In this test, we fail prove the absence of the note's nullifier in state at the block it was nullified in. | ||
#[test(should_fail_with = "Proving nullifier non-inclusion failed")] | ||
unconstrained fn note_not_nullified_fails() { | ||
let (env, retrieved_note) = test::create_note_and_nullify_it(); | ||
|
||
let context = &mut env.private_at(test::NOTE_NULLIFIED_AT); | ||
context.historical_header.prove_note_not_nullified( | ||
retrieved_note, | ||
test::NOTE_STORAGE_SLOT, | ||
context, | ||
); | ||
} | ||
|
||
// In this test, we prove the absence of an arbitrary nullifier in state. | ||
#[test] | ||
unconstrained fn nullifier_non_inclusion() { | ||
let (env) = test::create_note_and_nullify_it(); | ||
|
||
let context = &mut env.private(); | ||
|
||
context.historical_header.prove_nullifier_non_inclusion(random()); | ||
} | ||
|
||
// In this test, we fail to prove the absence of an existing nullifier in state. We use know FIRST_NULLIFIER_EMITTED_IN_TXE exists | ||
// because the TXe creates deterministic first nullifiers if no side-effects are emitted. | ||
#[test(should_fail_with = "Proving nullifier non-inclusion failed")] | ||
unconstrained fn nullifier_non_inclusion_fails() { | ||
let (env) = test::create_note_and_nullify_it(); | ||
|
||
let context = &mut env.private(); | ||
|
||
context.historical_header.prove_nullifier_non_inclusion(FIRST_NULLIFIER_EMITTED_IN_TXE); | ||
} |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were exposed to be used in the counter-contracts due to not being able to test this in aztec-nr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They should be exposed anyway as the history library and the whole of Aztec.nr is to be consumed from contracts.