Skip to content

Commit a301f72

Browse files
sklppy88benesjan
andauthored
feat: add historical library tests and remove old inclusion proof contract / related tests (#12215)
Adding txe tests to the historical apis, and removing inclusion proofs contract with corresponding (flaky) e2e test --------- Co-authored-by: Jan Beneš <janbenes1234@gmail.com>
1 parent ac5de42 commit a301f72

File tree

31 files changed

+511
-750
lines changed

31 files changed

+511
-750
lines changed

.test_patterns.yml

-23
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,6 @@ tests:
7878
owners:
7979
- "U04DT239VQU" # sean
8080

81-
# FAIL ./flakey_e2e_inclusion_proofs_contract.test.ts
82-
# ● e2e_inclusion_proofs_contract › contract inclusion › proves public deployment of a contract
83-
#
84-
# Undefined argument value of type field
85-
#
86-
# 41 | private encodeArgument(abiType: AbiType, arg: any, name?: string) {
87-
# 42 | if (arg === undefined || arg == null) {
88-
# > 43 | throw new Error(`Undefined argument ${name ?? 'unnamed'} of type ${abiType.kind}`);
89-
# | ^
90-
# 44 | }
91-
# 45 | switch (abiType.kind) {
92-
# 46 | case 'field':
93-
#
94-
# at ArgumentEncoder.encodeArgument (../../stdlib/src/abi/encoder.ts:43:13)
95-
# at ArgumentEncoder.encode (../../stdlib/src/abi/encoder.ts:137:12)
96-
# at encodeArguments (../../stdlib/src/abi/encoder.ts:150:41)
97-
# at computeInitializationHash (../../stdlib/src/contract/contract_address.ts:75:20)
98-
# at getContractInstanceFromDeployParams (../../stdlib/src/contract/contract_instance.ts:124:9)
99-
# at Object.getContractInstanceFromDeployParams (flakey_e2e_inclusion_proofs_contract.test.ts:275:24)
100-
- regex: "simple flakey_e2e_inclusion_proofs_contract"
101-
owners:
102-
- "UKUMA5J7K" # charlie
103-
10481
- regex: "simple e2e_fees/private_payments"
10582
owners:
10683
- "U02G4KAD57Y" # phil

cspell.json

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
"Nargo",
190190
"nixpkgs",
191191
"nodebuffer",
192+
"noinitcheck",
192193
"noirc",
193194
"noirup",
194195
"nullifer",

docs/docs/developers/guides/smart_contracts/writing_contracts/how_to_prove_history.md

+8-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sidebar_position: 4
44
tags: [contracts]
55
---
66

7-
The Aztec Protocol uses an append-only Merkle tree to store hashes of the headers of all previous blocks in the chain as its leaves. This is known as the Archive tree.
7+
The Aztec Protocol uses an append-only Merkle tree to store hashes of the headers of all previous blocks in the chain as its leaves. This is known as the Archive tree.
88

99
This page is a quick introductory guide to creating historical proofs proofs from the archive tree.
1010

@@ -37,33 +37,31 @@ Using this library, you can check that specific notes or nullifiers were part of
3737

3838
In general you will likely have the note you want to prove inclusion of. But if you are just experimenting you can create a note with a function like below:
3939

40-
#include_code create_note noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr rust
40+
#include_code create_note noir-projects/noir-contracts/contracts/test_contract/src/main.nr rust
4141

4242
## Get the note from the PXE
4343

4444
Retrieve the note from the user's PXE.
4545

46-
#include_code get_note_from_pxe noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr rust
46+
#include_code get_note_from_pxe noir-projects/noir-contracts/contracts/test_contract/src/main.nr rust
4747

48-
In this example, the user's notes are stored in a map called `private_values`. We retrieve this map, then select 1 note from it with the value of `1`.
48+
In this example, we fetch notes located in the storage slot that we pass in from the function parameters. The notes also must match the criteria specified by the getter options that we declare and are able to customize.
4949

5050
## Prove that a note was included in a specified block
5151

5252
To prove that a note existed in a specified block, call `prove_note_inclusion` on the `header` as shown in this example:
5353

54-
#include_code prove_note_inclusion noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr rust
55-
56-
Here, if `block_number` exists as an argument, it will prove inclusion in that block. Else, it will use the current block.
54+
#include_code prove_note_inclusion noir-projects/aztec-nr/aztec/src/history/note_inclusion/test.nr rust
5755

5856
This will only prove the note existed at the specific block number, not whether or not the note has been nullified. You can prove that a note existed and had not been nullified in a specified block by using `prove_note_validity` on the block header which takes the following arguments:
5957

60-
#include_code prove_note_validity noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr rust
58+
#include_code prove_note_validity noir-projects/aztec-nr/aztec/src/history/note_validity/test.nr rust
6159

6260
## Create a nullifier to prove inclusion of
6361

6462
You can easily nullify a note like so:
6563

66-
#include_code nullify_note noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr rust
64+
#include_code nullify_note noir-projects/noir-contracts/contracts/test_contract/src/main.nr rust
6765

6866
This function gets a note from the PXE and nullifies it with `remove()`.
6967

@@ -73,7 +71,7 @@ You can then compute this nullifier with `note.compute_nullifier(&mut context)`.
7371

7472
Call `prove_nullifier_inclusion` on a block header like so:
7573

76-
#include_code prove_nullifier_inclusion noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr rust
74+
#include_code prove_nullifier_inclusion noir-projects/aztec-nr/aztec/src/history/nullifier_inclusion/test.nr rust
7775

7876
It takes the nullifier as an argument.
7977

docs/docs/developers/reference/environment_reference/sandbox-reference.md

-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ EscrowContractArtifact
133133
FPCContractArtifact
134134
FeeJuiceContractArtifact
135135
ImportTestContractArtifact
136-
InclusionProofsContractArtifact
137136
LendingContractArtifact
138137
MultiCallEntrypointContractArtifact
139138
ParentContractArtifact

noir-projects/aztec-nr/aztec/src/history/contract_inclusion.nr

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use dep::protocol_types::{
33
hash::compute_siloed_nullifier,
44
};
55

6-
trait ProveContractDeployment {
6+
// This is tested in `noir-projects/noir-contracts/test_contract/src/test.nr because we cannot define a contract
7+
// from within aztec.nr (due to the contract macro).
8+
9+
pub trait ProveContractDeployment {
710
fn prove_contract_deployment(header: BlockHeader, contract_address: AztecAddress);
811
}
912

@@ -17,7 +20,7 @@ impl ProveContractDeployment for BlockHeader {
1720
}
1821
}
1922

20-
trait ProveContractNonDeployment {
23+
pub trait ProveContractNonDeployment {
2124
fn prove_contract_non_deployment(header: BlockHeader, contract_address: AztecAddress);
2225
}
2326

@@ -33,7 +36,7 @@ impl ProveContractNonDeployment for BlockHeader {
3336
}
3437
}
3538

36-
trait ProveContractInitialization {
39+
pub trait ProveContractInitialization {
3740
fn prove_contract_initialization(header: BlockHeader, contract_address: AztecAddress);
3841
}
3942

@@ -46,7 +49,7 @@ impl ProveContractInitialization for BlockHeader {
4649
}
4750
}
4851

49-
trait ProveContractNonInitialization {
52+
pub trait ProveContractNonInitialization {
5053
fn prove_contract_non_initialization(header: BlockHeader, contract_address: AztecAddress);
5154
}
5255

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
mod contract_inclusion;
2-
mod note_inclusion;
3-
mod note_validity;
4-
mod nullifier_inclusion;
5-
mod nullifier_non_inclusion;
6-
mod public_storage;
1+
pub mod contract_inclusion;
2+
pub mod note_inclusion;
3+
pub mod note_validity;
4+
pub mod nullifier_inclusion;
5+
pub mod nullifier_non_inclusion;
6+
pub mod public_storage;
7+
mod test;

noir-projects/aztec-nr/aztec/src/history/note_inclusion.nr

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use crate::{
99
oracle::get_membership_witness::get_note_hash_membership_witness,
1010
};
1111

12+
mod test;
13+
1214
trait ProveNoteInclusion {
1315
fn prove_note_inclusion<Note>(
1416
header: BlockHeader,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use crate::history::{note_inclusion::ProveNoteInclusion, test};
2+
3+
// In this test, we create a note and prove its inclusion in the block of its creation.
4+
#[test]
5+
unconstrained fn note_inclusion() {
6+
let (env, retrieved_note) = test::create_note();
7+
8+
let context = &mut env.private_at(test::NOTE_CREATED_AT);
9+
10+
// docs:start:prove_note_inclusion
11+
context.historical_header.prove_note_inclusion(retrieved_note, test::NOTE_STORAGE_SLOT);
12+
// docs:end:prove_note_inclusion
13+
}
14+
15+
// In this test, we create a note and fail to prove its inclusion in the block before its creation.
16+
#[test(should_fail_with = "not found in NOTE_HASH_TREE at block 1")]
17+
unconstrained fn note_inclusion_fails() {
18+
let (env, retrieved_note) = test::create_note();
19+
20+
let context = &mut env.private_at(test::NOTE_CREATED_AT - 1);
21+
context.historical_header.prove_note_inclusion(retrieved_note, test::NOTE_STORAGE_SLOT);
22+
}

noir-projects/aztec-nr/aztec/src/history/note_validity.nr

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use crate::{
55

66
use dep::protocol_types::block_header::BlockHeader;
77

8+
mod test;
9+
810
trait ProveNoteValidity {
911
fn prove_note_validity<Note>(
1012
header: BlockHeader,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use crate::history::note_validity::ProveNoteValidity;
2+
use crate::history::test;
3+
4+
// In these tests, we create a note in one block and nullify it in the next.
5+
6+
// In this test, we fail to prove the note's validity in the block before its creation. It fails the validity check due to
7+
// non-inclusion of the note in the block before its creation.
8+
#[test(should_fail_with = "not found in NOTE_HASH_TREE at block 1")]
9+
unconstrained fn note_not_valid_due_to_non_inclusion() {
10+
let (env, retrieved_note) = test::create_note_and_nullify_it();
11+
12+
let context = &mut env.private_at(test::NOTE_CREATED_AT - 1);
13+
14+
context.historical_header.prove_note_validity(retrieved_note, test::NOTE_STORAGE_SLOT, context);
15+
}
16+
17+
// In this test, we prove the note's validity in the block at its creation, and before its nullification. It succeeds
18+
// because it is included and not nullified at the block specified.
19+
#[test]
20+
unconstrained fn note_is_valid() {
21+
let (env, retrieved_note) = test::create_note_and_nullify_it();
22+
23+
let context = &mut env.private_at(test::NOTE_CREATED_AT);
24+
25+
// docs:start:prove_note_validity
26+
context.historical_header.prove_note_validity(retrieved_note, test::NOTE_STORAGE_SLOT, context);
27+
// docs:end:prove_note_validity
28+
}
29+
30+
// In this test, we fail to prove the note's validity in the block at its nullification. It fails the validity check due to
31+
// its nullifier being included in the state at one block after it was created.
32+
#[test(should_fail_with = "Proving nullifier non-inclusion failed")]
33+
unconstrained fn note_not_valid_due_to_nullification() {
34+
let (env, retrieved_note) = test::create_note_and_nullify_it();
35+
36+
let context = &mut env.private_at(test::NOTE_NULLIFIED_AT);
37+
context.historical_header.prove_note_validity(retrieved_note, test::NOTE_STORAGE_SLOT, context);
38+
}

noir-projects/aztec-nr/aztec/src/history/nullifier_inclusion.nr

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use crate::{
1010
oracle::get_nullifier_membership_witness::get_nullifier_membership_witness,
1111
};
1212

13+
mod test;
14+
1315
trait ProveNullifierInclusion {
1416
fn prove_nullifier_inclusion(header: BlockHeader, nullifier: Field);
1517
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use crate::history::{nullifier_inclusion::{ProveNoteIsNullified, ProveNullifierInclusion}, test};
2+
use crate::oracle::random::random;
3+
use crate::test::helpers::test_environment::FIRST_NULLIFIER_EMITTED_IN_TXE;
4+
5+
// In these tests, we create a note in one block and nullify it in the next.
6+
7+
// In this test, we prove the presence of the note's nullifier in state at the block it was nullified in.
8+
#[test]
9+
unconstrained fn note_is_nullified() {
10+
let (env, retrieved_note) = test::create_note_and_nullify_it();
11+
12+
let context = &mut env.private_at(test::NOTE_NULLIFIED_AT);
13+
14+
context.historical_header.prove_note_is_nullified(
15+
retrieved_note,
16+
test::NOTE_STORAGE_SLOT,
17+
context,
18+
);
19+
}
20+
21+
// In this test, we fail to prove the presence of the note's nullifier in state at the block before it was nullified.
22+
#[test(should_fail_with = "Nullifier membership witness not found at block 2.")]
23+
unconstrained fn note_is_not_nullified() {
24+
let (env, retrieved_note) = test::create_note_and_nullify_it();
25+
26+
let context = &mut env.private_at(test::NOTE_NULLIFIED_AT - 1);
27+
28+
context.historical_header.prove_note_is_nullified(
29+
retrieved_note,
30+
test::NOTE_STORAGE_SLOT,
31+
context,
32+
);
33+
}
34+
35+
// In this test, we prove the inclusion of an existing nullifier in state. We use know FIRST_NULLIFIER_EMITTED_IN_TXE exists
36+
// because the TXe creates deterministic first nullifiers if no side-effects are emitted.
37+
#[test]
38+
unconstrained fn nullifier_inclusion() {
39+
let (env) = test::create_note_and_nullify_it();
40+
41+
let context = &mut env.private();
42+
43+
// docs:start:prove_nullifier_inclusion
44+
context.historical_header.prove_nullifier_inclusion(FIRST_NULLIFIER_EMITTED_IN_TXE);
45+
// docs:end:prove_nullifier_inclusion
46+
}
47+
48+
// In this test, we fail to prove the inclusion of an arbitrary nullifier in state.
49+
#[test(should_fail_with = "Nullifier membership witness not found")]
50+
unconstrained fn nullifier_inclusion_fails() {
51+
let (env) = test::create_note_and_nullify_it();
52+
53+
let context = &mut env.private();
54+
context.historical_header.prove_nullifier_inclusion(random());
55+
}

noir-projects/aztec-nr/aztec/src/history/nullifier_non_inclusion.nr

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use dep::protocol_types::{
1212
};
1313
use dep::protocol_types::merkle_tree::root::root_from_sibling_path;
1414

15+
mod test;
16+
1517
trait ProveNullifierNonInclusion {
1618
fn prove_nullifier_non_inclusion(header: BlockHeader, nullifier: Field);
1719
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use crate::history::nullifier_non_inclusion::{ProveNoteNotNullified, ProveNullifierNonInclusion};
2+
use crate::oracle::random::random;
3+
4+
use crate::history::test;
5+
use crate::test::helpers::test_environment::FIRST_NULLIFIER_EMITTED_IN_TXE;
6+
7+
// In these tests, we create a note in one block and nullify it in the next.
8+
9+
// In this test, we prove the absence of the note's nullifier in state at the block before it was nullified.
10+
#[test]
11+
unconstrained fn note_not_nullified() {
12+
let (env, retrieved_note) = test::create_note_and_nullify_it();
13+
14+
let context = &mut env.private_at(test::NOTE_NULLIFIED_AT - 1);
15+
16+
context.historical_header.prove_note_not_nullified(
17+
retrieved_note,
18+
test::NOTE_STORAGE_SLOT,
19+
context,
20+
);
21+
}
22+
23+
// In this test, we fail prove the absence of the note's nullifier in state at the block it was nullified in.
24+
#[test(should_fail_with = "Proving nullifier non-inclusion failed")]
25+
unconstrained fn note_not_nullified_fails() {
26+
let (env, retrieved_note) = test::create_note_and_nullify_it();
27+
28+
let context = &mut env.private_at(test::NOTE_NULLIFIED_AT);
29+
context.historical_header.prove_note_not_nullified(
30+
retrieved_note,
31+
test::NOTE_STORAGE_SLOT,
32+
context,
33+
);
34+
}
35+
36+
// In this test, we prove the absence of an arbitrary nullifier in state.
37+
#[test]
38+
unconstrained fn nullifier_non_inclusion() {
39+
let (env) = test::create_note_and_nullify_it();
40+
41+
let context = &mut env.private();
42+
43+
context.historical_header.prove_nullifier_non_inclusion(random());
44+
}
45+
46+
// In this test, we fail to prove the absence of an existing nullifier in state. We use know FIRST_NULLIFIER_EMITTED_IN_TXE exists
47+
// because the TXe creates deterministic first nullifiers if no side-effects are emitted.
48+
#[test(should_fail_with = "Proving nullifier non-inclusion failed")]
49+
unconstrained fn nullifier_non_inclusion_fails() {
50+
let (env) = test::create_note_and_nullify_it();
51+
52+
let context = &mut env.private();
53+
54+
context.historical_header.prove_nullifier_non_inclusion(FIRST_NULLIFIER_EMITTED_IN_TXE);
55+
}

noir-projects/aztec-nr/aztec/src/history/public_storage.nr

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use dep::protocol_types::merkle_tree::root::root_from_sibling_path;
66

77
use crate::oracle::get_public_data_witness::get_public_data_witness;
88

9+
mod test;
10+
911
trait PublicStorageHistoricalRead {
1012
fn public_storage_historical_read(
1113
header: BlockHeader,

0 commit comments

Comments
 (0)