Skip to content

Commit 4f248b5

Browse files
alexghrjust-mitch
andauthored
feat: add meta_hwm to PrivateCircuitPublicInputs (#4341)
This PR adds `meta_hwm` to the context and exposes it through the private circuits so that in the last circuit the side effects created during private execution can be partitioned into reversible and irreversible effect sets Fix #4084 --------- Co-authored-by: Mitchell Tracy <mitchell@aztecprotocol.com>
1 parent c918d8d commit 4f248b5

37 files changed

Lines changed: 5460 additions & 3000 deletions

l1-contracts/src/core/libraries/ConstantsGen.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ library Constants {
3838
uint256 internal constant MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX = 4;
3939
uint256 internal constant NUM_ENCRYPTED_LOGS_HASHES_PER_TX = 1;
4040
uint256 internal constant NUM_UNENCRYPTED_LOGS_HASHES_PER_TX = 1;
41+
uint256 internal constant MAX_NEW_COMMITMENTS_PER_TX_META = 8;
42+
uint256 internal constant MAX_NEW_NULLIFIERS_PER_TX_META = 8;
43+
uint256 internal constant MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX_META = 2;
4144
uint256 internal constant NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16;
4245
uint256 internal constant VK_TREE_HEIGHT = 3;
4346
uint256 internal constant FUNCTION_TREE_HEIGHT = 5;
@@ -79,8 +82,8 @@ library Constants {
7982
uint256 internal constant HEADER_LENGTH = 18;
8083
uint256 internal constant FUNCTION_DATA_LENGTH = 4;
8184
uint256 internal constant CONTRACT_DEPLOYMENT_DATA_LENGTH = 6;
82-
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 204;
83-
uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = 209;
85+
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 205;
86+
uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = 210;
8487
uint256 internal constant CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH = 3;
8588
uint256 internal constant CONTRACT_STORAGE_READ_LENGTH = 2;
8689
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 201;

yarn-project/acir-simulator/src/client/client_execution_context.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,14 @@ export class ClientExecutionContext extends ViewDataOracle {
309309
* @param targetContractAddress - The address of the contract to call.
310310
* @param functionSelector - The function selector of the function to call.
311311
* @param argsHash - The packed arguments to pass to the function.
312-
* @param sideffectCounter - The side effect counter at the start of the call.
312+
* @param sideEffectCounter - The side effect counter at the start of the call.
313313
* @returns The execution result.
314314
*/
315315
async callPrivateFunction(
316316
targetContractAddress: AztecAddress,
317317
functionSelector: FunctionSelector,
318318
argsHash: Fr,
319-
sideffectCounter: number,
319+
sideEffectCounter: number,
320320
) {
321321
this.log(
322322
`Calling private function ${this.contractAddress}:${functionSelector} from ${this.callContext.storageContractAddress}`,
@@ -337,7 +337,7 @@ export class ClientExecutionContext extends ViewDataOracle {
337337
const derivedCallContext = await this.deriveCallContext(
338338
targetContractAddress,
339339
targetArtifact,
340-
sideffectCounter,
340+
sideEffectCounter,
341341
false,
342342
false,
343343
);

yarn-project/aztec-nr/aztec/src/context.nr

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ struct PrivateContext {
7272
inputs: PrivateContextInputs,
7373
side_effect_counter: u32,
7474

75+
meta_hwm: u32,
76+
7577
args_hash : Field,
7678
return_values : BoundedVec<Field, RETURN_VALUES_LENGTH>,
7779

@@ -101,6 +103,7 @@ impl PrivateContext {
101103
PrivateContext {
102104
inputs: inputs,
103105
side_effect_counter: inputs.call_context.start_side_effect_counter,
106+
meta_hwm: 0,
104107

105108
args_hash: args_hash,
106109
return_values: BoundedVec::new(0),
@@ -172,6 +175,7 @@ impl PrivateContext {
172175
call_context: self.inputs.call_context,
173176
args_hash: self.args_hash,
174177
return_values: self.return_values.storage,
178+
meta_hwm: self.meta_hwm,
175179
read_requests: self.read_requests.storage,
176180
nullifier_key_validation_requests: self.nullifier_key_validation_requests.storage,
177181
new_commitments: self.new_commitments.storage,
@@ -239,7 +243,7 @@ impl PrivateContext {
239243
}
240244

241245
// docs:start:context_message_portal
242-
pub fn message_portal(&mut self, content: Field)
246+
pub fn message_portal(&mut self, content: Field)
243247
// docs:end:context_message_portal
244248
{
245249
self.new_l2_to_l1_msgs.push(content);
@@ -254,7 +258,7 @@ impl PrivateContext {
254258
msg_key: Field,
255259
content: Field,
256260
secret: Field
257-
)
261+
)
258262
// docs:end:context_consume_l1_to_l2_message
259263
{
260264
let nullifier = process_l1_to_l2_message(self.historical_header.state.l1_to_l2_message_tree.root, self.this_address(), self.this_portal_address(), self.chain_id(), self.version(), msg_key, content, secret);
@@ -278,8 +282,8 @@ impl PrivateContext {
278282

279283
pub fn call_private_function<ARGS_COUNT>(
280284
&mut self,
281-
contract_address: AztecAddress,
282-
function_selector: FunctionSelector,
285+
contract_address: AztecAddress,
286+
function_selector: FunctionSelector,
283287
args: [Field; ARGS_COUNT]
284288
) -> [Field; RETURN_VALUES_LENGTH] {
285289
let args_hash = hash_args(args);
@@ -289,8 +293,8 @@ impl PrivateContext {
289293

290294
pub fn call_private_function_no_args(
291295
&mut self,
292-
contract_address: AztecAddress,
293-
function_selector: FunctionSelector,
296+
contract_address: AztecAddress,
297+
function_selector: FunctionSelector,
294298
) -> [Field; RETURN_VALUES_LENGTH] {
295299
self.call_private_function_with_packed_args(contract_address, function_selector, 0)
296300
}
@@ -303,14 +307,14 @@ impl PrivateContext {
303307
) -> [Field; RETURN_VALUES_LENGTH] {
304308
let item = call_private_function_internal(
305309
contract_address,
306-
function_selector,
310+
function_selector,
307311
args_hash,
308312
self.side_effect_counter,
309313
);
310314

311315
assert_eq(item.public_inputs.call_context.start_side_effect_counter, self.side_effect_counter);
312316
self.side_effect_counter = item.public_inputs.end_side_effect_counter + 1;
313-
317+
314318
assert(contract_address.eq(item.contract_address));
315319
assert(function_selector.eq(item.function_data.selector));
316320

@@ -333,8 +337,8 @@ impl PrivateContext {
333337

334338
pub fn call_public_function<ARGS_COUNT>(
335339
&mut self,
336-
contract_address: AztecAddress,
337-
function_selector: FunctionSelector,
340+
contract_address: AztecAddress,
341+
function_selector: FunctionSelector,
338342
args: [Field; ARGS_COUNT]
339343
) {
340344
let args_hash = hash_args(args);
@@ -344,7 +348,7 @@ impl PrivateContext {
344348

345349
pub fn call_public_function_no_args(
346350
&mut self,
347-
contract_address: AztecAddress,
351+
contract_address: AztecAddress,
348352
function_selector: FunctionSelector,
349353
) {
350354
self.call_public_function_with_packed_args(contract_address, function_selector, 0)
@@ -357,8 +361,8 @@ impl PrivateContext {
357361
args_hash: Field
358362
) {
359363
let fields = enqueue_public_function_call_internal(
360-
contract_address,
361-
function_selector,
364+
contract_address,
365+
function_selector,
362366
args_hash,
363367
self.side_effect_counter
364368
);
@@ -395,7 +399,7 @@ impl PrivateContext {
395399
assert_eq(item.public_inputs.call_context.start_side_effect_counter, self.side_effect_counter);
396400
// We increment the sideffect counter by one, to account for the call itself being a side effect.
397401
self.side_effect_counter = self.side_effect_counter + 1;
398-
402+
399403
assert(args_hash == item.public_inputs.args_hash);
400404

401405
// Assert that the call context of the enqueued call generated by the oracle matches our request.
@@ -457,7 +461,7 @@ impl PublicContext {
457461

458462
new_l2_to_l1_msgs: BoundedVec::new(0),
459463

460-
464+
461465
unencrypted_logs_hash: BoundedVec::new(0),
462466
unencrypted_logs_preimages_length: 0,
463467

@@ -574,27 +578,27 @@ impl PublicContext {
574578

575579
pub fn call_public_function<ARGS_COUNT>(
576580
_self: Self,
577-
contract_address: AztecAddress,
581+
contract_address: AztecAddress,
578582
function_selector: FunctionSelector,
579583
args: [Field; ARGS_COUNT],
580584
) -> [Field; RETURN_VALUES_LENGTH] {
581585
let args_hash = hash_args(args);
582586
assert(args_hash == arguments::pack_arguments(args));
583587
call_public_function_internal(
584-
contract_address,
585-
function_selector,
588+
contract_address,
589+
function_selector,
586590
args_hash,
587591
)
588592
}
589593

590594
pub fn call_public_function_no_args(
591595
_self: Self,
592-
contract_address: AztecAddress,
596+
contract_address: AztecAddress,
593597
function_selector: FunctionSelector,
594598
) -> [Field; RETURN_VALUES_LENGTH] {
595599
call_public_function_internal(
596-
contract_address,
597-
function_selector,
600+
contract_address,
601+
function_selector,
598602
0,
599603
)
600604
}

yarn-project/circuits.js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"clean": "rm -rf ./dest .tsbuildinfo",
2727
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
2828
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
29-
"remake-constants": "node --loader ts-node/esm src/scripts/constants.in.ts && prettier -w src/constants.gen.ts",
29+
"remake-constants": "node --loader ts-node/esm src/scripts/constants.in.ts && prettier -w src/constants.gen.ts && forge fmt --root ../../l1-contracts",
3030
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests"
3131
},
3232
"inherits": [

yarn-project/circuits.js/src/constants.gen.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export const MAX_READ_REQUESTS_PER_TX = 128;
2424
export const MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX = 4;
2525
export const NUM_ENCRYPTED_LOGS_HASHES_PER_TX = 1;
2626
export const NUM_UNENCRYPTED_LOGS_HASHES_PER_TX = 1;
27+
export const MAX_NEW_COMMITMENTS_PER_TX_META = 8;
28+
export const MAX_NEW_NULLIFIERS_PER_TX_META = 8;
29+
export const MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX_META = 2;
2730
export const NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16;
2831
export const VK_TREE_HEIGHT = 3;
2932
export const FUNCTION_TREE_HEIGHT = 5;
@@ -64,8 +67,8 @@ export const STATE_REFERENCE_LENGTH = 10;
6467
export const HEADER_LENGTH = 18;
6568
export const FUNCTION_DATA_LENGTH = 4;
6669
export const CONTRACT_DEPLOYMENT_DATA_LENGTH = 6;
67-
export const PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 204;
68-
export const PRIVATE_CALL_STACK_ITEM_LENGTH = 209;
70+
export const PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 205;
71+
export const PRIVATE_CALL_STACK_ITEM_LENGTH = 210;
6972
export const CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH = 3;
7073
export const CONTRACT_STORAGE_READ_LENGTH = 2;
7174
export const PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 201;

yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,41 @@
22

33
exports[`PrivateCallStackItem computes empty item hash 1`] = `
44
Fr {
5-
"asBigInt": 21230813221792739829032218511346459661622392006403997687170807299887246304465n,
5+
"asBigInt": 2538825319674219123846958071590111740225106671201233263868844578355336664781n,
66
"asBuffer": {
77
"data": [
8-
46,
9-
240,
10-
54,
8+
5,
9+
156,
10+
236,
11+
152,
12+
233,
13+
157,
14+
232,
15+
67,
16+
153,
1117
229,
12-
221,
1318
27,
14-
22,
19+
168,
20+
75,
21+
195,
22+
183,
23+
254,
24+
111,
25+
10,
26+
250,
27+
64,
28+
122,
29+
141,
30+
166,
31+
174,
32+
48,
33+
176,
34+
125,
35+
64,
1536
205,
16-
116,
17-
188,
37+
67,
38+
86,
1839
205,
19-
128,
20-
113,
21-
43,
22-
99,
23-
253,
24-
225,
25-
42,
26-
162,
27-
230,
28-
75,
29-
8,
30-
243,
31-
160,
32-
150,
33-
65,
34-
149,
35-
200,
36-
179,
37-
79,
38-
100,
39-
209,
4040
],
4141
"type": "Buffer",
4242
},
@@ -45,41 +45,41 @@ Fr {
4545

4646
exports[`PrivateCallStackItem computes hash 1`] = `
4747
Fr {
48-
"asBigInt": 14723811775539034985226914197401344473208275906441619992416957589322673569693n,
48+
"asBigInt": 14128890724092381488704229567615295219923311195211320351016242351826479641614n,
4949
"asBuffer": {
5050
"data": [
51-
32,
52-
141,
53-
97,
54-
211,
55-
254,
56-
114,
57-
95,
58-
205,
59-
151,
60-
179,
61-
64,
62-
109,
63-
121,
64-
32,
65-
239,
66-
244,
67-
117,
68-
162,
69-
13,
70-
12,
71-
74,
72-
168,
73-
124,
74-
126,
75-
12,
51+
31,
52+
60,
53+
171,
54+
51,
55+
195,
56+
14,
57+
113,
58+
231,
59+
119,
60+
201,
61+
1,
62+
173,
63+
160,
64+
14,
65+
186,
66+
38,
67+
104,
68+
235,
69+
90,
70+
76,
71+
0,
72+
233,
73+
167,
74+
78,
75+
217,
76+
88,
77+
247,
7678
59,
77-
146,
78-
221,
79-
124,
80-
42,
81-
63,
82-
157,
79+
171,
80+
156,
81+
116,
82+
14,
8383
],
8484
"type": "Buffer",
8585
},

0 commit comments

Comments
 (0)