Skip to content

Commit 53e8d21

Browse files
author
sklppy88
committed
addressing more comments
1 parent a4a8851 commit 53e8d21

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

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

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

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+
69
pub trait ProveContractDeployment {
710
fn prove_contract_deployment(header: BlockHeader, contract_address: AztecAddress);
811
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ use protocol_types::traits::Packable;
1616

1717
// This is the first nullifier emitted from the TXe. It is an arbitrary number assigned in the TXe that is
1818
// larger than the first prefilled subtree of the nullifier tree. We know FIRST_NULLIFIER_EMITTED_IN_TXE exists
19-
// because the TXe creates deterministic first nullifiers if no side-effects are emitted.
19+
// because the TXe creates a deterministic first nullifier for each block if no side-effects are emitted in said block.
20+
// The TXe automatically builds an empty block upon initialization and therefore we know this nullifier is inserted.
21+
// TODO(#12226): REMOVE THIS
2022
pub global FIRST_NULLIFIER_EMITTED_IN_TXE: Field = 6969 + 1;
2123

2224
pub struct TestEnvironment {}

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

+34-22
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ fn get_shared_mutable_num_slots() -> Field {
8383
value_change_and_delay_change_packed_len + with_hash_additional_slots
8484
}
8585

86+
global CONTRACT_DEPLOYED_AT: u32 = 3;
87+
88+
// In env.deploy_self("Test").with_private_initializer(initializer); it first deploys the contract, then advances a block, then calls the initializer.
89+
global CONTRACT_INITIALIZED_AT: u32 = CONTRACT_DEPLOYED_AT + 1;
90+
8691
pub unconstrained fn setup() -> (&mut TestEnvironment, AztecAddress, AztecAddress) {
8792
// Setup env, generate keys
8893
let mut env = TestEnvironment::new();
@@ -92,6 +97,9 @@ pub unconstrained fn setup() -> (&mut TestEnvironment, AztecAddress, AztecAddres
9297
// 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.
9398
env.advance_block_by(1);
9499

100+
// We sanity check that we are building block 3, thus block 3 is where the contract will be deployed.
101+
assert_eq(env.pending_block_number(), CONTRACT_DEPLOYED_AT);
102+
95103
// Deploy contract and initialize
96104
let initializer = Test::interface().initialize();
97105
let test_contract = env.deploy_self("Test").with_private_initializer(initializer);
@@ -110,17 +118,25 @@ pub unconstrained fn setup() -> (&mut TestEnvironment, AztecAddress, AztecAddres
110118
unconstrained fn contract_historical_proofs_happy_path() {
111119
let (env, contract_address) = setup();
112120

113-
let context = env.private();
114-
let header_at_block_before_deployment = context.get_block_header_at(2);
115-
let current_header = context.historical_header;
121+
let context_at_block_before_deployment = env.private_at(CONTRACT_DEPLOYED_AT - 1);
122+
let context_at_block_of_deployment = env.private_at(CONTRACT_DEPLOYED_AT);
123+
124+
let context_at_block_before_initialization = env.private_at(CONTRACT_INITIALIZED_AT - 1);
125+
let context_at_block_of_initialization = env.private_at(CONTRACT_INITIALIZED_AT);
116126

117127
// We prove that the contract had not been deployed nor initialized at the block before deployment
118-
header_at_block_before_deployment.prove_contract_non_deployment(contract_address);
119-
header_at_block_before_deployment.prove_contract_non_initialization(contract_address);
128+
context_at_block_before_deployment.historical_header.prove_contract_non_deployment(
129+
contract_address,
130+
);
131+
context_at_block_before_initialization.historical_header.prove_contract_non_initialization(
132+
contract_address,
133+
);
120134

121135
// And we prove that the contract has been been deployed and initialized at the block after deployment
122-
current_header.prove_contract_deployment(contract_address);
123-
current_header.prove_contract_initialization(contract_address);
136+
context_at_block_of_deployment.historical_header.prove_contract_deployment(contract_address);
137+
context_at_block_of_initialization.historical_header.prove_contract_initialization(
138+
contract_address,
139+
);
124140
}
125141

126142
// In this test, we fail to prove contract deployment at the block before it was deployed. This checks for inclusion
@@ -129,42 +145,38 @@ unconstrained fn contract_historical_proofs_happy_path() {
129145
unconstrained fn proving_contract_deployment_fails() {
130146
let (env, contract_address) = setup();
131147

132-
let context = env.private();
133-
let header_at_block_before_deployment = context.get_block_header_at(2);
148+
let context = env.private_at(CONTRACT_DEPLOYED_AT - 1);
134149

135-
header_at_block_before_deployment.prove_contract_deployment(contract_address);
150+
context.historical_header.prove_contract_deployment(contract_address);
136151
}
137152

138153
// In this test, we fail to prove contract initialization at the block before it was deployed. This checks for inclusion
139154
// of the initialization nullifier in state.
140-
#[test(should_fail_with = "Nullifier membership witness not found at block 2.")]
155+
#[test(should_fail_with = "Nullifier membership witness not found at block 3.")]
141156
unconstrained fn proving_contract_initialization_fails() {
142157
let (env, contract_address) = setup();
143158

144-
let context = env.private();
145-
let header_at_block_before_deployment = context.get_block_header_at(2);
159+
let context = env.private_at(CONTRACT_INITIALIZED_AT - 1);
146160

147-
header_at_block_before_deployment.prove_contract_initialization(contract_address);
161+
context.historical_header.prove_contract_initialization(contract_address);
148162
}
149163

150-
// In this test, we fail to prove contract non-deployment at the block after it was deployed.
164+
// In this test, we fail to prove contract non-deployment at the block of its deployment.
151165
#[test(should_fail_with = "Proving nullifier non-inclusion failed")]
152166
unconstrained fn proving_contract_non_deployment_fails() {
153167
let (env, contract_address) = setup();
154168

155-
let context = env.private();
156-
let current_header = context.historical_header;
169+
let context = env.private_at(CONTRACT_DEPLOYED_AT);
157170

158-
current_header.prove_contract_non_deployment(contract_address);
171+
context.historical_header.prove_contract_non_deployment(contract_address);
159172
}
160173

161-
// In this test, we fail to prove contract non-initialization at the block after it was deployed.
174+
// In this test, we fail to prove contract non-initialization at the block of its deployment.
162175
#[test(should_fail_with = "Proving nullifier non-inclusion failed")]
163176
unconstrained fn proving_contract_non_initialization_fails() {
164177
let (env, contract_address) = setup();
165178

166-
let context = env.private();
167-
let current_header = context.historical_header;
179+
let context = env.private_at(CONTRACT_INITIALIZED_AT);
168180

169-
current_header.prove_contract_non_initialization(contract_address);
181+
context.historical_header.prove_contract_non_initialization(contract_address);
170182
}

0 commit comments

Comments
 (0)