@@ -83,6 +83,8 @@ fn get_shared_mutable_num_slots() -> Field {
83
83
value_change_and_delay_change_packed_len + with_hash_additional_slots
84
84
}
85
85
86
+ global CONTRACT_DEPLOYED_AT : u32 = 3 ;
87
+
86
88
pub unconstrained fn setup () -> (&mut TestEnvironment , AztecAddress , AztecAddress ) {
87
89
// Setup env, generate keys
88
90
let mut env = TestEnvironment ::new ();
@@ -92,6 +94,9 @@ pub unconstrained fn setup() -> (&mut TestEnvironment, AztecAddress, AztecAddres
92
94
// 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.
93
95
env .advance_block_by (1 );
94
96
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
+
95
100
// Deploy contract and initialize
96
101
let initializer = Test ::interface ().initialize ();
97
102
let test_contract = env .deploy_self ("Test" ).with_private_initializer (initializer );
@@ -110,17 +115,20 @@ pub unconstrained fn setup() -> (&mut TestEnvironment, AztecAddress, AztecAddres
110
115
unconstrained fn contract_historical_proofs_happy_path () {
111
116
let (env , contract_address ) = setup ();
112
117
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 );
116
120
117
121
// 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
+ );
120
128
121
129
// 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 );
124
132
}
125
133
126
134
// 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() {
129
137
unconstrained fn proving_contract_deployment_fails () {
130
138
let (env , contract_address ) = setup ();
131
139
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 );
134
141
135
- header_at_block_before_deployment .prove_contract_deployment (contract_address );
142
+ context . historical_header .prove_contract_deployment (contract_address );
136
143
}
137
144
138
145
// 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() {
141
148
unconstrained fn proving_contract_initialization_fails () {
142
149
let (env , contract_address ) = setup ();
143
150
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 );
146
152
147
- header_at_block_before_deployment .prove_contract_initialization (contract_address );
153
+ context . historical_header .prove_contract_initialization (contract_address );
148
154
}
149
155
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 .
151
157
#[test(should_fail_with = "Proving nullifier non-inclusion failed")]
152
158
unconstrained fn proving_contract_non_deployment_fails () {
153
159
let (env , contract_address ) = setup ();
154
160
155
- let context = env .private ();
156
- let current_header = context .historical_header ;
161
+ let context = env .private_at (CONTRACT_DEPLOYED_AT );
157
162
158
- current_header .prove_contract_non_deployment (contract_address );
163
+ context . historical_header .prove_contract_non_deployment (contract_address );
159
164
}
160
165
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 .
162
167
#[test(should_fail_with = "Proving nullifier non-inclusion failed")]
163
168
unconstrained fn proving_contract_non_initialization_fails () {
164
169
let (env , contract_address ) = setup ();
165
170
166
- let context = env .private ();
167
- let current_header = context .historical_header ;
171
+ let context = env .private_at (CONTRACT_DEPLOYED_AT );
168
172
169
- current_header .prove_contract_non_initialization (contract_address );
173
+ context . historical_header .prove_contract_non_initialization (contract_address );
170
174
}
0 commit comments