Skip to content

Commit 2113ba0

Browse files
author
sklppy88
committed
addressing more comments
1 parent a4a8851 commit 2113ba0

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
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

+25-21
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ 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+
8688
pub unconstrained fn setup() -> (&mut TestEnvironment, AztecAddress, AztecAddress) {
8789
// Setup env, generate keys
8890
let mut env = TestEnvironment::new();
@@ -92,6 +94,9 @@ pub unconstrained fn setup() -> (&mut TestEnvironment, AztecAddress, AztecAddres
9294
// 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.
9395
env.advance_block_by(1);
9496

97+
// We sanity check that we are building block 3, thus block 3 is where the contract will be deployed.
98+
assert_eq(env.pending_block_number(), CONTRACT_DEPLOYED_AT);
99+
95100
// Deploy contract and initialize
96101
let initializer = Test::interface().initialize();
97102
let test_contract = env.deploy_self("Test").with_private_initializer(initializer);
@@ -110,17 +115,20 @@ pub unconstrained fn setup() -> (&mut TestEnvironment, AztecAddress, AztecAddres
110115
unconstrained fn contract_historical_proofs_happy_path() {
111116
let (env, contract_address) = setup();
112117

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;
118+
let context_at_block_before_deployment = env.private_at(CONTRACT_DEPLOYED_AT - 1);
119+
let context_at_block_of_deployment = env.private_at(CONTRACT_DEPLOYED_AT);
116120

117121
// 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);
122+
context_at_block_before_deployment.historical_header.prove_contract_non_deployment(
123+
contract_address,
124+
);
125+
context_at_block_before_deployment.historical_header.prove_contract_non_initialization(
126+
contract_address,
127+
);
120128

121129
// 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);
130+
context_at_block_of_deployment.historical_header.prove_contract_deployment(contract_address);
131+
context_at_block_of_deployment.historical_header.prove_contract_initialization(contract_address);
124132
}
125133

126134
// In this test, we fail to prove contract deployment at the block before it was deployed. This checks for inclusion
@@ -129,10 +137,9 @@ unconstrained fn contract_historical_proofs_happy_path() {
129137
unconstrained fn proving_contract_deployment_fails() {
130138
let (env, contract_address) = setup();
131139

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

135-
header_at_block_before_deployment.prove_contract_deployment(contract_address);
142+
context.historical_header.prove_contract_deployment(contract_address);
136143
}
137144

138145
// In this test, we fail to prove contract initialization at the block before it was deployed. This checks for inclusion
@@ -141,30 +148,27 @@ unconstrained fn proving_contract_deployment_fails() {
141148
unconstrained fn proving_contract_initialization_fails() {
142149
let (env, contract_address) = setup();
143150

144-
let context = env.private();
145-
let header_at_block_before_deployment = context.get_block_header_at(2);
151+
let context = env.private_at(CONTRACT_DEPLOYED_AT - 1);
146152

147-
header_at_block_before_deployment.prove_contract_initialization(contract_address);
153+
context.historical_header.prove_contract_initialization(contract_address);
148154
}
149155

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

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

158-
current_header.prove_contract_non_deployment(contract_address);
163+
context.historical_header.prove_contract_non_deployment(contract_address);
159164
}
160165

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

166-
let context = env.private();
167-
let current_header = context.historical_header;
171+
let context = env.private_at(CONTRACT_DEPLOYED_AT);
168172

169-
current_header.prove_contract_non_initialization(contract_address);
173+
context.historical_header.prove_contract_non_initialization(contract_address);
170174
}

0 commit comments

Comments
 (0)