Skip to content

Commit 0522cb7

Browse files
author
sklppy88
committed
addressing more feedback
1 parent 976644b commit 0522cb7

File tree

14 files changed

+116
-79
lines changed

14 files changed

+116
-79
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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Retrieve the note from the user's PXE.
4545

4646
#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 storage_slot that is specified. We look for notes located in this storage_slot and return the ones matched by the getter options.
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

Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
use crate::history::{note_inclusion::ProveNoteInclusion, test};
22

3-
// In this test, we create a note and prove its inclusion in the block.
3+
// In this test, we create a note and prove its inclusion in the block of its creation.
44
#[test]
55
unconstrained fn note_inclusion() {
66
let (env, retrieved_note) = test::create_note();
77

8-
let context = &mut env.private();
8+
let context = &mut env.private_at(test::NOTE_CREATED_AT);
99

1010
// docs:start:prove_note_inclusion
11-
context.historical_header.prove_note_inclusion(retrieved_note, 15);
11+
context.historical_header.prove_note_inclusion(retrieved_note, test::NOTE_STORAGE_SLOT);
1212
// docs:end:prove_note_inclusion
1313
}
1414

15-
// In this test, we create a note and fail to prove its inclusion in a block before its creation.
15+
// In this test, we create a note and fail to prove its inclusion in the block before its creation.
1616
#[test(should_fail_with = "not found in NOTE_HASH_TREE at block 1")]
1717
unconstrained fn note_inclusion_fails() {
1818
let (env, retrieved_note) = test::create_note();
1919

20-
let context = &mut env.private_at(1);
21-
context.historical_header.prove_note_inclusion(retrieved_note, 15);
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);
2222
}

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,35 @@ use crate::history::test;
44
// In these tests, we create a note in one block and nullify it in the next.
55

66
// 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 specified.
7+
// non-inclusion of the note in the block before its creation.
88
#[test(should_fail_with = "not found in NOTE_HASH_TREE at block 1")]
99
unconstrained fn note_not_valid_due_to_non_inclusion() {
1010
let (env, retrieved_note) = test::create_note_and_nullify_it();
1111

12-
let context = &mut env.private_at(1);
12+
let context = &mut env.private_at(test::NOTE_CREATED_AT - 1);
1313

14-
context.historical_header.prove_note_validity(retrieved_note, 15, context);
14+
context.historical_header.prove_note_validity(retrieved_note, test::NOTE_STORAGE_SLOT, context);
1515
}
1616

17-
// In this test, we prove the note's validity in the block after its creation, and before its nullification. It succeeds
18-
// because it is included and not nullified at the block specified
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.
1919
#[test]
2020
unconstrained fn note_is_valid() {
2121
let (env, retrieved_note) = test::create_note_and_nullify_it();
2222

23-
let context = &mut env.private_at(2);
23+
let context = &mut env.private_at(test::NOTE_CREATED_AT);
2424

2525
// docs:start:prove_note_validity
26-
context.historical_header.prove_note_validity(retrieved_note, 15, context);
26+
context.historical_header.prove_note_validity(retrieved_note, test::NOTE_STORAGE_SLOT, context);
2727
// docs:end:prove_note_validity
2828
}
2929

30-
// In this test, we fail to prove the note's validity in the block after its nullification. It fails the validity check due to
31-
// its nullifier being included in the state at the block specified.
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.
3232
#[test(should_fail_with = "Proving nullifier non-inclusion failed")]
3333
unconstrained fn note_not_valid_due_to_nullification() {
3434
let (env, retrieved_note) = test::create_note_and_nullify_it();
3535

36-
let context = &mut env.private();
37-
context.historical_header.prove_note_validity(retrieved_note, 15, context);
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);
3838
}

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

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
11
use crate::history::{nullifier_inclusion::{ProveNoteIsNullified, ProveNullifierInclusion}, test};
22
use crate::oracle::random::random;
3+
use crate::test::helpers::test_environment::FIRST_NULLIFIER_EMITTED_IN_TXE;
34

45
// In these tests, we create a note in one block and nullify it in the next.
56

6-
// In this test, we prove the presence of the note's nullifier in state at the current block (the block after it was nullified).
7+
// In this test, we prove the presence of the note's nullifier in state at the block it was nullified in.
78
#[test]
89
unconstrained fn note_is_nullified() {
910
let (env, retrieved_note) = test::create_note_and_nullify_it();
1011

11-
let context = &mut env.private();
12+
let context = &mut env.private_at(test::NOTE_NULLIFIED_AT);
1213

13-
context.historical_header.prove_note_is_nullified(retrieved_note, 15, context);
14+
context.historical_header.prove_note_is_nullified(
15+
retrieved_note,
16+
test::NOTE_STORAGE_SLOT,
17+
context,
18+
);
1419
}
1520

1621
// In this test, we fail to prove the presence of the note's nullifier in state at the block before it was nullified.
1722
#[test(should_fail_with = "Nullifier membership witness not found at block 2.")]
1823
unconstrained fn note_is_not_nullified() {
1924
let (env, retrieved_note) = test::create_note_and_nullify_it();
2025

21-
let context = &mut env.private_at(2);
26+
let context = &mut env.private_at(test::NOTE_NULLIFIED_AT - 1);
2227

23-
context.historical_header.prove_note_is_nullified(retrieved_note, 15, context);
28+
context.historical_header.prove_note_is_nullified(
29+
retrieved_note,
30+
test::NOTE_STORAGE_SLOT,
31+
context,
32+
);
2433
}
2534

26-
// In this test, we prove the inclusion of an existing nullifier in state. We use 6969 + 1 because it is
27-
// the first nullifier created (the TXe creates deterministic first nullifiers if no side-effects are emitted)
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.
2837
#[test]
2938
unconstrained fn nullifier_inclusion() {
3039
let (env) = test::create_note_and_nullify_it();
3140

32-
let context = &mut env.private_at(2);
41+
let context = &mut env.private();
3342

3443
// docs:start:prove_nullifier_inclusion
35-
context.historical_header.prove_nullifier_inclusion(6969 + 1);
44+
context.historical_header.prove_nullifier_inclusion(FIRST_NULLIFIER_EMITTED_IN_TXE);
3645
// docs:end:prove_nullifier_inclusion
3746
}
3847

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

+19-10
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,54 @@ use crate::history::nullifier_non_inclusion::{ProveNoteNotNullified, ProveNullif
22
use crate::oracle::random::random;
33

44
use crate::history::test;
5+
use crate::test::helpers::test_environment::FIRST_NULLIFIER_EMITTED_IN_TXE;
56

67
// In these tests, we create a note in one block and nullify it in the next.
78

8-
// In this test, we prove the absence of the note's nullifier in state before the note was nullified.
9+
// In this test, we prove the absence of the note's nullifier in state at the block before it was nullified.
910
#[test]
1011
unconstrained fn note_not_nullified() {
1112
let (env, retrieved_note) = test::create_note_and_nullify_it();
1213

13-
let context = &mut env.private_at(2);
14+
let context = &mut env.private_at(test::NOTE_NULLIFIED_AT - 1);
1415

15-
context.historical_header.prove_note_not_nullified(retrieved_note, 15, context);
16+
context.historical_header.prove_note_not_nullified(
17+
retrieved_note,
18+
test::NOTE_STORAGE_SLOT,
19+
context,
20+
);
1621
}
1722

18-
// In this test, we fail to prove the absence of the note's nullifier in state at the current block (the block after it was nullified).
23+
// In this test, we fail prove the absence of the note's nullifier in state at the block it was nullified in.
1924
#[test(should_fail_with = "Proving nullifier non-inclusion failed")]
2025
unconstrained fn note_not_nullified_fails() {
2126
let (env, retrieved_note) = test::create_note_and_nullify_it();
2227

23-
let context = &mut env.private();
24-
context.historical_header.prove_note_not_nullified(retrieved_note, 15, context);
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+
);
2534
}
2635

2736
// In this test, we prove the absence of an arbitrary nullifier in state.
2837
#[test]
2938
unconstrained fn nullifier_non_inclusion() {
3039
let (env) = test::create_note_and_nullify_it();
3140

32-
let context = &mut env.private_at(2);
41+
let context = &mut env.private();
3342

3443
context.historical_header.prove_nullifier_non_inclusion(random());
3544
}
3645

37-
// In this test, we fail to prove the inclusion of an existing nullifier in state. We use 6969 + 1 because it is
38-
// the first nullifier created (the TXe creates deterministic first nullifiers if no side-effects are emitted)
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.
3948
#[test(should_fail_with = "Proving nullifier non-inclusion failed")]
4049
unconstrained fn nullifier_non_inclusion_fails() {
4150
let (env) = test::create_note_and_nullify_it();
4251

4352
let context = &mut env.private();
4453

45-
context.historical_header.prove_nullifier_non_inclusion(6969 + 1);
54+
context.historical_header.prove_nullifier_non_inclusion(FIRST_NULLIFIER_EMITTED_IN_TXE);
4655
}

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

+21-7
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@ use crate::{
33
test::helpers::test_environment::TestEnvironment,
44
};
55

6+
global STORAGE_SLOT: Field = 420;
7+
global VALUE: Field = 69;
8+
global WRITTEN_TO_STORAGE_AT: u32 = 2;
9+
global STORAGE_UNSET_VALUE: Field = 0;
10+
611
unconstrained fn setup() -> &mut TestEnvironment {
712
let mut env = TestEnvironment::new();
813
let context = &mut env.public();
914

10-
context.storage_write(15, 69);
15+
// We sanity check that we are building block 2, and thus block 2 is this storage write will occur.
16+
assert_eq(env.pending_block_number(), 2);
17+
18+
context.storage_write(STORAGE_SLOT, VALUE);
1119

1220
env.advance_block_by(1);
1321

@@ -19,11 +27,14 @@ unconstrained fn setup() -> &mut TestEnvironment {
1927
unconstrained fn public_storage_read() {
2028
let env = setup();
2129

22-
let context = &mut env.private();
30+
let context = &mut env.private_at(WRITTEN_TO_STORAGE_AT);
2331

2432
assert_eq(
25-
context.historical_header.public_storage_historical_read(15, get_contract_address()),
26-
69,
33+
context.historical_header.public_storage_historical_read(
34+
STORAGE_SLOT,
35+
get_contract_address(),
36+
),
37+
VALUE,
2738
);
2839
}
2940

@@ -32,10 +43,13 @@ unconstrained fn public_storage_read() {
3243
unconstrained fn public_storage_read_empty() {
3344
let env = setup();
3445

35-
let context = &mut env.private_at(1);
46+
let context = &mut env.private_at(WRITTEN_TO_STORAGE_AT - 1);
3647

3748
assert_eq(
38-
context.historical_header.public_storage_historical_read(15, get_contract_address()),
39-
0,
49+
context.historical_header.public_storage_historical_read(
50+
STORAGE_SLOT,
51+
get_contract_address(),
52+
),
53+
STORAGE_UNSET_VALUE,
4054
);
4155
}

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

+15-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@ use crate::{
88
use crate::note::retrieved_note::RetrievedNote;
99
use crate::test::{helpers::test_environment::TestEnvironment, mocks::mock_note::MockNote};
1010

11-
// We create a note at block 2 and nullify it in the next block. This helps us test our historical apis.
11+
pub(crate) global NOTE_STORAGE_SLOT: Field = 420;
12+
pub(crate) global NOTE_CREATED_AT: u32 = 2;
13+
pub(crate) global NOTE_NULLIFIED_AT: u32 = 3;
14+
15+
// We create a note in block 2.
1216
pub(crate) unconstrained fn create_note() -> (&mut TestEnvironment, RetrievedNote<MockNote>) {
1317
let mut env = TestEnvironment::new();
1418
let context = &mut env.private();
1519

20+
// We sanity check that we are building block 2, thus block 2 is where the note will be added.
21+
assert_eq(env.pending_block_number(), 2);
22+
1623
let contract_address = get_contract_address();
1724

1825
let retrieved_note = MockNote::new(69)
@@ -23,22 +30,25 @@ pub(crate) unconstrained fn create_note() -> (&mut TestEnvironment, RetrievedNot
2330
))
2431
.build_retrieved_note();
2532

26-
let _ = lifecycle_create_note(context, 15, retrieved_note.note);
33+
let _ = lifecycle_create_note(context, NOTE_STORAGE_SLOT, retrieved_note.note);
2734

28-
// #TODO (12226): FIX
35+
// TODO(#12226): FIX
2936
// context.push_note_hash(retrieved_note.note.compute_note_hash(15));
3037
env.advance_block_by(1);
3138

3239
(&mut env, retrieved_note)
3340
}
3441

35-
// We create a note at block 2 and nullify it in the next block. This helps us test our historical apis.
42+
// We create a note at block 2 and nullify it in the next block.
3643
pub(crate) unconstrained fn create_note_and_nullify_it() -> (&mut TestEnvironment, RetrievedNote<MockNote>) {
3744
let (env, retrieved_note) = create_note();
3845

3946
let context = &mut env.private();
4047

41-
destroy_note(context, retrieved_note, 15);
48+
// We sanity check that we are building block 3, thus block 3 is where the note will be nullified.
49+
assert_eq(env.pending_block_number(), 3);
50+
51+
destroy_note(context, retrieved_note, NOTE_STORAGE_SLOT);
4252

4353
env.advance_block_by(1);
4454

noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ use crate::oracle::{
1414
use protocol_types::constants::PUBLIC_DISPATCH_SELECTOR;
1515
use protocol_types::traits::Packable;
1616

17+
// This is the first nullifier emitted from the TXe. It is an arbitrary number assigned in the TXe that is
18+
// larger than the first prefilled subtree of the nullifier tree. We use know FIRST_NULLIFIER_EMITTED_IN_TXE exists
19+
// because the TXe creates deterministic first nullifiers if no side-effects are emitted.
20+
pub global FIRST_NULLIFIER_EMITTED_IN_TXE: Field = 6969 + 1;
21+
1722
pub struct TestEnvironment {}
1823

1924
impl TestEnvironment {

noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ impl MockNoteBuilder {
8686
RetrievedNote {
8787
note: MockNote { value: self.value },
8888
contract_address: self.contract_address.unwrap_or(AztecAddress::zero()),
89-
// This is invalid note metadata, which would result in the kernel failing to prove note existence. Because
90-
// our tests don't interact with the kernel this is not a problem.
89+
// If the option is `None` for self.note_metadata, we fill it with invalid note metadata, which would result in the kernel
90+
// failing to prove note existence. Because our tests don't interact with the kernel this is not a problem.
9191
metadata: self.note_metadata.unwrap_or(std::mem::zeroed()),
9292
}
9393
}

noir-projects/noir-contracts/contracts/docs_example_contract/src/main.nr

+7
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ pub contract DocsExample {
8888
}
8989
}
9090

91+
// DO NOT uncomment this and add an initializer in this contract. We specifically need this contract to not have an initializer
92+
// because of tests in 'yarn-project/end-to-end/src/e2e_deploy_contract/deploy_method.test.ts'
93+
// #[initializer]
94+
// #[private]
95+
// // We can name our initializer anything we want as long as it's marked as aztec(initializer)
96+
// fn initialize() {}
97+
9198
// docs:start:initialize_public_immutable
9299
#[public]
93100
fn initialize_public_immutable(points: u8) {

noir-projects/noir-contracts/contracts/test_contract/src/test.nr

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub unconstrained fn setup() -> (&mut TestEnvironment, AztecAddress, AztecAddres
8989
let owner = env.create_account(1);
9090
env.impersonate(owner);
9191

92-
// TODO: (12276) This is here because we are testing historical proofs, and we cannot get a block_header at 1 due to a bug in world state.
92+
// TODO(#12276): This is here because we are testing historical proofs, and we cannot get a valid block_header at 1 due to a bug in world state.
9393
env.advance_block_by(1);
9494

9595
// Deploy contract and initialize

0 commit comments

Comments
 (0)