@aztec/pxe 4.0.0-devnet.1-patch.0 → 4.0.0-devnet.1-patch.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +51 -28
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +165 -57
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +34 -36
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +62 -17
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +28 -11
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +20 -22
- package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +9 -1
- package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +9 -1
- package/dest/entrypoints/server/utils.js +9 -1
- package/dest/pxe.d.ts +52 -21
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +31 -27
- package/package.json +16 -16
- package/src/contract_function_simulator/contract_function_simulator.ts +314 -117
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +81 -93
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +56 -19
- package/src/entrypoints/client/bundle/utils.ts +9 -1
- package/src/entrypoints/client/lazy/utils.ts +9 -1
- package/src/entrypoints/server/utils.ts +7 -7
- package/src/pxe.ts +84 -58
|
@@ -9,12 +9,17 @@ import {
|
|
|
9
9
|
FIXED_L2_GAS,
|
|
10
10
|
GeneratorIndex,
|
|
11
11
|
L2_GAS_PER_CONTRACT_CLASS_LOG,
|
|
12
|
+
L2_GAS_PER_L2_TO_L1_MSG,
|
|
13
|
+
L2_GAS_PER_NOTE_HASH,
|
|
14
|
+
L2_GAS_PER_NULLIFIER,
|
|
12
15
|
L2_GAS_PER_PRIVATE_LOG,
|
|
13
16
|
MAX_CONTRACT_CLASS_LOGS_PER_TX,
|
|
14
17
|
MAX_ENQUEUED_CALLS_PER_TX,
|
|
15
18
|
MAX_L2_TO_L1_MSGS_PER_TX,
|
|
16
19
|
MAX_NOTE_HASHES_PER_TX,
|
|
20
|
+
MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
|
|
17
21
|
MAX_NULLIFIERS_PER_TX,
|
|
22
|
+
MAX_NULLIFIER_READ_REQUESTS_PER_TX,
|
|
18
23
|
MAX_PRIVATE_LOGS_PER_TX,
|
|
19
24
|
} from '@aztec/constants';
|
|
20
25
|
import { arrayNonEmptyLength, padArrayEnd } from '@aztec/foundation/collection';
|
|
@@ -38,6 +43,7 @@ import type { FunctionCall } from '@aztec/stdlib/abi';
|
|
|
38
43
|
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
39
44
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
40
45
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
46
|
+
import type { BlockParameter } from '@aztec/stdlib/block';
|
|
41
47
|
import { Gas } from '@aztec/stdlib/gas';
|
|
42
48
|
import {
|
|
43
49
|
computeNoteHashNonce,
|
|
@@ -48,15 +54,24 @@ import {
|
|
|
48
54
|
} from '@aztec/stdlib/hash';
|
|
49
55
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
50
56
|
import {
|
|
57
|
+
ClaimedLengthArray,
|
|
51
58
|
PartialPrivateTailPublicInputsForPublic,
|
|
52
59
|
PartialPrivateTailPublicInputsForRollup,
|
|
53
60
|
type PrivateExecutionStep,
|
|
54
61
|
type PrivateKernelExecutionProofOutput,
|
|
55
62
|
PrivateKernelTailCircuitPublicInputs,
|
|
63
|
+
PrivateLogData,
|
|
56
64
|
PrivateToPublicAccumulatedData,
|
|
57
65
|
PrivateToRollupAccumulatedData,
|
|
58
66
|
PublicCallRequest,
|
|
67
|
+
ReadRequestActionEnum,
|
|
59
68
|
ScopedLogHash,
|
|
69
|
+
ScopedNoteHash,
|
|
70
|
+
ScopedNullifier,
|
|
71
|
+
ScopedReadRequest,
|
|
72
|
+
buildTransientDataHints,
|
|
73
|
+
getNoteHashReadRequestResetActions,
|
|
74
|
+
getNullifierReadRequestResetActions,
|
|
60
75
|
} from '@aztec/stdlib/kernel';
|
|
61
76
|
import { PrivateLog } from '@aztec/stdlib/logs';
|
|
62
77
|
import { ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
|
|
@@ -69,6 +84,7 @@ import {
|
|
|
69
84
|
TxConstantData,
|
|
70
85
|
TxExecutionRequest,
|
|
71
86
|
collectNested,
|
|
87
|
+
collectNoteHashNullifierCounterMap,
|
|
72
88
|
getFinalMinRevertibleSideEffectCounter,
|
|
73
89
|
} from '@aztec/stdlib/tx';
|
|
74
90
|
|
|
@@ -90,52 +106,89 @@ import { executePrivateFunction } from './oracle/private_execution.js';
|
|
|
90
106
|
import { PrivateExecutionOracle } from './oracle/private_execution_oracle.js';
|
|
91
107
|
import { UtilityExecutionOracle } from './oracle/utility_execution_oracle.js';
|
|
92
108
|
|
|
109
|
+
/** Options for ContractFunctionSimulator.run. */
|
|
110
|
+
export type ContractSimulatorRunOpts = {
|
|
111
|
+
/** The address of the contract (should match request.origin). */
|
|
112
|
+
contractAddress: AztecAddress;
|
|
113
|
+
/** The function selector of the entry point. */
|
|
114
|
+
selector: FunctionSelector;
|
|
115
|
+
/** The address calling the function. Can be replaced to simulate a call from another contract or account. */
|
|
116
|
+
msgSender?: AztecAddress;
|
|
117
|
+
/** The block header to use as base state for this run. */
|
|
118
|
+
anchorBlockHeader: BlockHeader;
|
|
119
|
+
/** The address used as a tagging sender when emitting private logs. */
|
|
120
|
+
senderForTags?: AztecAddress;
|
|
121
|
+
/** The accounts whose notes we can access in this call. Defaults to all. */
|
|
122
|
+
scopes?: AztecAddress[];
|
|
123
|
+
/** The job ID for staged writes. */
|
|
124
|
+
jobId: string;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/** Args for ContractFunctionSimulator constructor. */
|
|
128
|
+
export type ContractFunctionSimulatorArgs = {
|
|
129
|
+
contractStore: ContractStore;
|
|
130
|
+
noteStore: NoteStore;
|
|
131
|
+
keyStore: KeyStore;
|
|
132
|
+
addressStore: AddressStore;
|
|
133
|
+
aztecNode: AztecNode;
|
|
134
|
+
senderTaggingStore: SenderTaggingStore;
|
|
135
|
+
recipientTaggingStore: RecipientTaggingStore;
|
|
136
|
+
senderAddressBookStore: SenderAddressBookStore;
|
|
137
|
+
capsuleStore: CapsuleStore;
|
|
138
|
+
privateEventStore: PrivateEventStore;
|
|
139
|
+
simulator: CircuitSimulator;
|
|
140
|
+
contractSyncService: ContractSyncService;
|
|
141
|
+
};
|
|
142
|
+
|
|
93
143
|
/**
|
|
94
144
|
* The contract function simulator.
|
|
95
145
|
*/
|
|
96
146
|
export class ContractFunctionSimulator {
|
|
97
|
-
private log: Logger;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
147
|
+
private readonly log: Logger;
|
|
148
|
+
private readonly contractStore: ContractStore;
|
|
149
|
+
private readonly noteStore: NoteStore;
|
|
150
|
+
private readonly keyStore: KeyStore;
|
|
151
|
+
private readonly addressStore: AddressStore;
|
|
152
|
+
private readonly aztecNode: AztecNode;
|
|
153
|
+
private readonly senderTaggingStore: SenderTaggingStore;
|
|
154
|
+
private readonly recipientTaggingStore: RecipientTaggingStore;
|
|
155
|
+
private readonly senderAddressBookStore: SenderAddressBookStore;
|
|
156
|
+
private readonly capsuleStore: CapsuleStore;
|
|
157
|
+
private readonly privateEventStore: PrivateEventStore;
|
|
158
|
+
private readonly simulator: CircuitSimulator;
|
|
159
|
+
private readonly contractSyncService: ContractSyncService;
|
|
160
|
+
|
|
161
|
+
constructor(args: ContractFunctionSimulatorArgs) {
|
|
162
|
+
this.contractStore = args.contractStore;
|
|
163
|
+
this.noteStore = args.noteStore;
|
|
164
|
+
this.keyStore = args.keyStore;
|
|
165
|
+
this.addressStore = args.addressStore;
|
|
166
|
+
this.aztecNode = args.aztecNode;
|
|
167
|
+
this.senderTaggingStore = args.senderTaggingStore;
|
|
168
|
+
this.recipientTaggingStore = args.recipientTaggingStore;
|
|
169
|
+
this.senderAddressBookStore = args.senderAddressBookStore;
|
|
170
|
+
this.capsuleStore = args.capsuleStore;
|
|
171
|
+
this.privateEventStore = args.privateEventStore;
|
|
172
|
+
this.simulator = args.simulator;
|
|
173
|
+
this.contractSyncService = args.contractSyncService;
|
|
113
174
|
this.log = createLogger('simulator');
|
|
114
175
|
}
|
|
115
176
|
|
|
116
177
|
/**
|
|
117
178
|
* Runs a private function.
|
|
118
179
|
* @param request - The transaction request.
|
|
119
|
-
* @param entryPointArtifact - The artifact of the entry point function.
|
|
120
|
-
* @param contractAddress - The address of the contract (should match request.origin)
|
|
121
|
-
* @param msgSender - The address calling the function. This can be replaced to simulate a call from another contract
|
|
122
|
-
* or a specific account.
|
|
123
|
-
* @param anchorBlockHeader - The block header to use as base state for this run.
|
|
124
|
-
* @param senderForTags - The address that is used as a tagging sender when emitting private logs. Returned from
|
|
125
|
-
* the `privateGetSenderForTags` oracle.
|
|
126
|
-
* @param scopes - The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
127
|
-
* @param jobId - The job ID for staged writes.
|
|
128
|
-
* @returns The result of the execution.
|
|
129
180
|
*/
|
|
130
181
|
public async run(
|
|
131
182
|
request: TxExecutionRequest,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
183
|
+
{
|
|
184
|
+
contractAddress,
|
|
185
|
+
selector,
|
|
186
|
+
msgSender = AztecAddress.fromField(Fr.MAX_FIELD_VALUE),
|
|
187
|
+
anchorBlockHeader,
|
|
188
|
+
senderForTags,
|
|
189
|
+
scopes,
|
|
190
|
+
jobId,
|
|
191
|
+
}: ContractSimulatorRunOpts,
|
|
139
192
|
): Promise<PrivateExecutionResult> {
|
|
140
193
|
const simulatorSetupTimer = new Timer();
|
|
141
194
|
|
|
@@ -165,38 +218,37 @@ export class ContractFunctionSimulator {
|
|
|
165
218
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
166
219
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
167
220
|
|
|
168
|
-
const privateExecutionOracle = new PrivateExecutionOracle(
|
|
169
|
-
request.firstCallArgsHash,
|
|
170
|
-
request.txContext,
|
|
221
|
+
const privateExecutionOracle = new PrivateExecutionOracle({
|
|
222
|
+
argsHash: request.firstCallArgsHash,
|
|
223
|
+
txContext: request.txContext,
|
|
171
224
|
callContext,
|
|
172
225
|
anchorBlockHeader,
|
|
173
|
-
async call => {
|
|
226
|
+
utilityExecutor: async call => {
|
|
174
227
|
await this.runUtility(call, [], anchorBlockHeader, scopes, jobId);
|
|
175
228
|
},
|
|
176
|
-
request.authWitnesses,
|
|
177
|
-
request.capsules,
|
|
178
|
-
HashedValuesCache.create(request.argsOfCalls),
|
|
229
|
+
authWitnesses: request.authWitnesses,
|
|
230
|
+
capsules: request.capsules,
|
|
231
|
+
executionCache: HashedValuesCache.create(request.argsOfCalls),
|
|
179
232
|
noteCache,
|
|
180
233
|
taggingIndexCache,
|
|
181
|
-
this.contractStore,
|
|
182
|
-
this.noteStore,
|
|
183
|
-
this.keyStore,
|
|
184
|
-
this.addressStore,
|
|
185
|
-
this.aztecNode,
|
|
186
|
-
this.senderTaggingStore,
|
|
187
|
-
this.recipientTaggingStore,
|
|
188
|
-
this.senderAddressBookStore,
|
|
189
|
-
this.capsuleStore,
|
|
190
|
-
this.privateEventStore,
|
|
191
|
-
this.contractSyncService,
|
|
234
|
+
contractStore: this.contractStore,
|
|
235
|
+
noteStore: this.noteStore,
|
|
236
|
+
keyStore: this.keyStore,
|
|
237
|
+
addressStore: this.addressStore,
|
|
238
|
+
aztecNode: this.aztecNode,
|
|
239
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
240
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
241
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
242
|
+
capsuleStore: this.capsuleStore,
|
|
243
|
+
privateEventStore: this.privateEventStore,
|
|
244
|
+
contractSyncService: this.contractSyncService,
|
|
192
245
|
jobId,
|
|
193
|
-
0,
|
|
194
|
-
startSideEffectCounter,
|
|
195
|
-
undefined, // log
|
|
246
|
+
totalPublicCalldataCount: 0,
|
|
247
|
+
sideEffectCounter: startSideEffectCounter,
|
|
196
248
|
scopes,
|
|
197
249
|
senderForTags,
|
|
198
|
-
this.simulator,
|
|
199
|
-
);
|
|
250
|
+
simulator: this.simulator,
|
|
251
|
+
});
|
|
200
252
|
|
|
201
253
|
const setupTime = simulatorSetupTimer.ms();
|
|
202
254
|
|
|
@@ -269,24 +321,23 @@ export class ContractFunctionSimulator {
|
|
|
269
321
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
270
322
|
}
|
|
271
323
|
|
|
272
|
-
const oracle = new UtilityExecutionOracle(
|
|
273
|
-
call.to,
|
|
274
|
-
authwits,
|
|
275
|
-
[],
|
|
324
|
+
const oracle = new UtilityExecutionOracle({
|
|
325
|
+
contractAddress: call.to,
|
|
326
|
+
authWitnesses: authwits,
|
|
327
|
+
capsules: [],
|
|
276
328
|
anchorBlockHeader,
|
|
277
|
-
this.contractStore,
|
|
278
|
-
this.noteStore,
|
|
279
|
-
this.keyStore,
|
|
280
|
-
this.addressStore,
|
|
281
|
-
this.aztecNode,
|
|
282
|
-
this.recipientTaggingStore,
|
|
283
|
-
this.senderAddressBookStore,
|
|
284
|
-
this.capsuleStore,
|
|
285
|
-
this.privateEventStore,
|
|
329
|
+
contractStore: this.contractStore,
|
|
330
|
+
noteStore: this.noteStore,
|
|
331
|
+
keyStore: this.keyStore,
|
|
332
|
+
addressStore: this.addressStore,
|
|
333
|
+
aztecNode: this.aztecNode,
|
|
334
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
335
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
336
|
+
capsuleStore: this.capsuleStore,
|
|
337
|
+
privateEventStore: this.privateEventStore,
|
|
286
338
|
jobId,
|
|
287
|
-
undefined,
|
|
288
339
|
scopes,
|
|
289
|
-
);
|
|
340
|
+
});
|
|
290
341
|
|
|
291
342
|
try {
|
|
292
343
|
this.log.verbose(`Executing utility function ${entryPointArtifact.name}`, {
|
|
@@ -352,7 +403,8 @@ class OrderedSideEffect<T> {
|
|
|
352
403
|
* (allowing state overrides) and is much faster, while still generating a valid
|
|
353
404
|
* output that can be sent to the node for public simulation
|
|
354
405
|
* @param privateExecutionResult - The result of the private execution.
|
|
355
|
-
* @param
|
|
406
|
+
* @param debugFunctionNameGetter - A provider for contract data in order to get function names and debug info.
|
|
407
|
+
* @param node - AztecNode for verifying settled read requests against the note hash and nullifier trees.
|
|
356
408
|
* @param minRevertibleSideEffectCounterOverride - Optional override for the min revertible side effect counter.
|
|
357
409
|
* Used by TXE to simulate account contract behavior (setting the counter before app execution).
|
|
358
410
|
* @returns The simulated proving result.
|
|
@@ -360,16 +412,24 @@ class OrderedSideEffect<T> {
|
|
|
360
412
|
export async function generateSimulatedProvingResult(
|
|
361
413
|
privateExecutionResult: PrivateExecutionResult,
|
|
362
414
|
debugFunctionNameGetter: (contractAddress: AztecAddress, functionSelector: FunctionSelector) => Promise<string>,
|
|
415
|
+
node: AztecNode,
|
|
363
416
|
minRevertibleSideEffectCounterOverride?: number,
|
|
364
417
|
): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
365
|
-
const
|
|
366
|
-
const nullifiers: OrderedSideEffect<Fr>[] = [];
|
|
367
|
-
const taggedPrivateLogs: OrderedSideEffect<PrivateLog>[] = [];
|
|
418
|
+
const taggedPrivateLogs: OrderedSideEffect<PrivateLogData>[] = [];
|
|
368
419
|
const l2ToL1Messages: OrderedSideEffect<ScopedL2ToL1Message>[] = [];
|
|
369
420
|
const contractClassLogsHashes: OrderedSideEffect<ScopedLogHash>[] = [];
|
|
370
421
|
const publicCallRequests: OrderedSideEffect<PublicCallRequest>[] = [];
|
|
371
422
|
const executionSteps: PrivateExecutionStep[] = [];
|
|
372
423
|
|
|
424
|
+
// Unsiloed scoped arrays — used for squashing, read request verification,
|
|
425
|
+
// and siloed at the end only for the surviving items
|
|
426
|
+
const scopedNoteHashes: ScopedNoteHash[] = [];
|
|
427
|
+
const scopedNullifiers: ScopedNullifier[] = [];
|
|
428
|
+
|
|
429
|
+
// Read requests for verification
|
|
430
|
+
const noteHashReadRequests: ScopedReadRequest[] = [];
|
|
431
|
+
const nullifierReadRequests: ScopedReadRequest[] = [];
|
|
432
|
+
|
|
373
433
|
let publicTeardownCallRequest;
|
|
374
434
|
|
|
375
435
|
const executions = [privateExecutionResult.entrypoint];
|
|
@@ -380,38 +440,28 @@ export async function generateSimulatedProvingResult(
|
|
|
380
440
|
|
|
381
441
|
const { contractAddress } = execution.publicInputs.callContext;
|
|
382
442
|
|
|
383
|
-
|
|
384
|
-
execution.publicInputs.noteHashes
|
|
443
|
+
scopedNoteHashes.push(
|
|
444
|
+
...execution.publicInputs.noteHashes
|
|
385
445
|
.getActiveItems()
|
|
386
|
-
.filter(
|
|
387
|
-
.map(
|
|
388
|
-
async noteHash =>
|
|
389
|
-
new OrderedSideEffect(await siloNoteHash(contractAddress, noteHash.value), noteHash.counter),
|
|
390
|
-
),
|
|
446
|
+
.filter(nh => !nh.isEmpty())
|
|
447
|
+
.map(nh => nh.scope(contractAddress)),
|
|
391
448
|
);
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
.map(
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
metadata.log.fields[0] = await poseidon2HashWithSeparator(
|
|
405
|
-
[contractAddress, metadata.log.fields[0]],
|
|
406
|
-
GeneratorIndex.PRIVATE_LOG_FIRST_FIELD,
|
|
407
|
-
);
|
|
408
|
-
return new OrderedSideEffect(metadata.log, metadata.counter);
|
|
409
|
-
}),
|
|
449
|
+
scopedNullifiers.push(...execution.publicInputs.nullifiers.getActiveItems().map(n => n.scope(contractAddress)));
|
|
450
|
+
|
|
451
|
+
taggedPrivateLogs.push(
|
|
452
|
+
...(await Promise.all(
|
|
453
|
+
execution.publicInputs.privateLogs.getActiveItems().map(async metadata => {
|
|
454
|
+
metadata.log.fields[0] = await poseidon2HashWithSeparator(
|
|
455
|
+
[contractAddress, metadata.log.fields[0]],
|
|
456
|
+
GeneratorIndex.PRIVATE_LOG_FIRST_FIELD,
|
|
457
|
+
);
|
|
458
|
+
return new OrderedSideEffect(metadata, metadata.counter);
|
|
459
|
+
}),
|
|
460
|
+
)),
|
|
410
461
|
);
|
|
411
462
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
nullifiers.push(...nullifiersFromExecution);
|
|
463
|
+
noteHashReadRequests.push(...execution.publicInputs.noteHashReadRequests.getActiveItems());
|
|
464
|
+
nullifierReadRequests.push(...execution.publicInputs.nullifierReadRequests.getActiveItems());
|
|
415
465
|
l2ToL1Messages.push(
|
|
416
466
|
...execution.publicInputs.l2ToL1Msgs
|
|
417
467
|
.getActiveItems()
|
|
@@ -451,6 +501,47 @@ export async function generateSimulatedProvingResult(
|
|
|
451
501
|
});
|
|
452
502
|
}
|
|
453
503
|
|
|
504
|
+
const noteHashNullifierCounterMap = collectNoteHashNullifierCounterMap(privateExecutionResult);
|
|
505
|
+
const minRevertibleSideEffectCounter =
|
|
506
|
+
minRevertibleSideEffectCounterOverride ?? getFinalMinRevertibleSideEffectCounter(privateExecutionResult);
|
|
507
|
+
|
|
508
|
+
const scopedNoteHashesCLA = new ClaimedLengthArray<ScopedNoteHash, typeof MAX_NOTE_HASHES_PER_TX>(
|
|
509
|
+
padArrayEnd(scopedNoteHashes, ScopedNoteHash.empty(), MAX_NOTE_HASHES_PER_TX),
|
|
510
|
+
scopedNoteHashes.length,
|
|
511
|
+
);
|
|
512
|
+
const scopedNullifiersCLA = new ClaimedLengthArray<ScopedNullifier, typeof MAX_NULLIFIERS_PER_TX>(
|
|
513
|
+
padArrayEnd(scopedNullifiers, ScopedNullifier.empty(), MAX_NULLIFIERS_PER_TX),
|
|
514
|
+
scopedNullifiers.length,
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
const { filteredNoteHashes, filteredNullifiers, filteredPrivateLogs } = squashTransientSideEffects(
|
|
518
|
+
taggedPrivateLogs,
|
|
519
|
+
scopedNoteHashesCLA,
|
|
520
|
+
scopedNullifiersCLA,
|
|
521
|
+
noteHashNullifierCounterMap,
|
|
522
|
+
minRevertibleSideEffectCounter,
|
|
523
|
+
);
|
|
524
|
+
|
|
525
|
+
await verifyReadRequests(
|
|
526
|
+
node,
|
|
527
|
+
await privateExecutionResult.entrypoint.publicInputs.anchorBlockHeader.hash(),
|
|
528
|
+
noteHashReadRequests,
|
|
529
|
+
nullifierReadRequests,
|
|
530
|
+
scopedNoteHashesCLA,
|
|
531
|
+
scopedNullifiersCLA,
|
|
532
|
+
);
|
|
533
|
+
|
|
534
|
+
const siloedNoteHashes = await Promise.all(
|
|
535
|
+
filteredNoteHashes
|
|
536
|
+
.sort((a, b) => a.counter - b.counter)
|
|
537
|
+
.map(async nh => new OrderedSideEffect(await siloNoteHash(nh.contractAddress, nh.value), nh.counter)),
|
|
538
|
+
);
|
|
539
|
+
const siloedNullifiers = await Promise.all(
|
|
540
|
+
filteredNullifiers
|
|
541
|
+
.sort((a, b) => a.counter - b.counter)
|
|
542
|
+
.map(async n => new OrderedSideEffect(await siloNullifier(n.contractAddress, n.value), n.counter)),
|
|
543
|
+
);
|
|
544
|
+
|
|
454
545
|
const constantData = new TxConstantData(
|
|
455
546
|
privateExecutionResult.entrypoint.publicInputs.anchorBlockHeader,
|
|
456
547
|
privateExecutionResult.entrypoint.publicInputs.txContext,
|
|
@@ -467,11 +558,9 @@ export async function generateSimulatedProvingResult(
|
|
|
467
558
|
const getEffect = <T>(orderedSideEffect: OrderedSideEffect<T>) => orderedSideEffect.sideEffect;
|
|
468
559
|
|
|
469
560
|
const isPrivateOnlyTx = privateExecutionResult.publicFunctionCalldata.length === 0;
|
|
470
|
-
const minRevertibleSideEffectCounter =
|
|
471
|
-
minRevertibleSideEffectCounterOverride ?? getFinalMinRevertibleSideEffectCounter(privateExecutionResult);
|
|
472
561
|
|
|
473
562
|
const [nonRevertibleNullifiers, revertibleNullifiers] = splitOrderedSideEffects(
|
|
474
|
-
|
|
563
|
+
siloedNullifiers,
|
|
475
564
|
minRevertibleSideEffectCounter,
|
|
476
565
|
);
|
|
477
566
|
const nonceGenerator = privateExecutionResult.firstNullifier;
|
|
@@ -485,7 +574,7 @@ export async function generateSimulatedProvingResult(
|
|
|
485
574
|
// We must make the note hashes unique by using the
|
|
486
575
|
// nonce generator and their index in the tx.
|
|
487
576
|
const uniqueNoteHashes = await Promise.all(
|
|
488
|
-
siloedNoteHashes.
|
|
577
|
+
siloedNoteHashes.map(async (orderedSideEffect, i) => {
|
|
489
578
|
const siloedNoteHash = orderedSideEffect.sideEffect;
|
|
490
579
|
const nonce = await computeNoteHashNonce(nonceGenerator, i);
|
|
491
580
|
const uniqueNoteHash = await computeUniqueNoteHash(nonce, siloedNoteHash);
|
|
@@ -500,18 +589,18 @@ export async function generateSimulatedProvingResult(
|
|
|
500
589
|
ScopedL2ToL1Message.empty(),
|
|
501
590
|
MAX_L2_TO_L1_MSGS_PER_TX,
|
|
502
591
|
),
|
|
503
|
-
padArrayEnd(
|
|
592
|
+
padArrayEnd(filteredPrivateLogs.sort(sortByCounter).map(getEffect), PrivateLog.empty(), MAX_PRIVATE_LOGS_PER_TX),
|
|
504
593
|
padArrayEnd(
|
|
505
594
|
contractClassLogsHashes.sort(sortByCounter).map(getEffect),
|
|
506
595
|
ScopedLogHash.empty(),
|
|
507
596
|
MAX_CONTRACT_CLASS_LOGS_PER_TX,
|
|
508
597
|
),
|
|
509
598
|
);
|
|
510
|
-
gasUsed = meterGasUsed(accumulatedDataForRollup);
|
|
599
|
+
gasUsed = meterGasUsed(accumulatedDataForRollup, isPrivateOnlyTx);
|
|
511
600
|
inputsForRollup = new PartialPrivateTailPublicInputsForRollup(accumulatedDataForRollup);
|
|
512
601
|
} else {
|
|
513
602
|
const [nonRevertibleNoteHashes, revertibleNoteHashes] = splitOrderedSideEffects(
|
|
514
|
-
siloedNoteHashes
|
|
603
|
+
siloedNoteHashes,
|
|
515
604
|
minRevertibleSideEffectCounter,
|
|
516
605
|
);
|
|
517
606
|
const nonRevertibleUniqueNoteHashes = await Promise.all(
|
|
@@ -525,7 +614,7 @@ export async function generateSimulatedProvingResult(
|
|
|
525
614
|
minRevertibleSideEffectCounter,
|
|
526
615
|
);
|
|
527
616
|
const [nonRevertibleTaggedPrivateLogs, revertibleTaggedPrivateLogs] = splitOrderedSideEffects(
|
|
528
|
-
|
|
617
|
+
filteredPrivateLogs,
|
|
529
618
|
minRevertibleSideEffectCounter,
|
|
530
619
|
);
|
|
531
620
|
const [nonRevertibleContractClassLogHashes, revertibleContractClassLogHashes] = splitOrderedSideEffects(
|
|
@@ -554,9 +643,9 @@ export async function generateSimulatedProvingResult(
|
|
|
554
643
|
padArrayEnd(revertibleContractClassLogHashes, ScopedLogHash.empty(), MAX_CONTRACT_CLASS_LOGS_PER_TX),
|
|
555
644
|
padArrayEnd(revertiblePublicCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX),
|
|
556
645
|
);
|
|
557
|
-
gasUsed = meterGasUsed(revertibleData).add(meterGasUsed(nonRevertibleData));
|
|
646
|
+
gasUsed = meterGasUsed(revertibleData, isPrivateOnlyTx).add(meterGasUsed(nonRevertibleData, isPrivateOnlyTx));
|
|
558
647
|
if (publicTeardownCallRequest) {
|
|
559
|
-
gasUsed.add(privateExecutionResult.entrypoint.publicInputs.txContext.gasSettings.teardownGasLimits);
|
|
648
|
+
gasUsed = gasUsed.add(privateExecutionResult.entrypoint.publicInputs.txContext.gasSettings.teardownGasLimits);
|
|
560
649
|
}
|
|
561
650
|
|
|
562
651
|
inputsForPublic = new PartialPrivateTailPublicInputsForPublic(
|
|
@@ -582,6 +671,111 @@ export async function generateSimulatedProvingResult(
|
|
|
582
671
|
};
|
|
583
672
|
}
|
|
584
673
|
|
|
674
|
+
/**
|
|
675
|
+
* Squashes transient note hashes and nullifiers, mimicking the behavior
|
|
676
|
+
* of the reset kernels. Returns the filtered (surviving) scoped items and private logs.
|
|
677
|
+
*/
|
|
678
|
+
function squashTransientSideEffects(
|
|
679
|
+
taggedPrivateLogs: OrderedSideEffect<PrivateLogData>[],
|
|
680
|
+
scopedNoteHashesCLA: ClaimedLengthArray<ScopedNoteHash, typeof MAX_NOTE_HASHES_PER_TX>,
|
|
681
|
+
scopedNullifiersCLA: ClaimedLengthArray<ScopedNullifier, typeof MAX_NULLIFIERS_PER_TX>,
|
|
682
|
+
noteHashNullifierCounterMap: Map<number, number>,
|
|
683
|
+
minRevertibleSideEffectCounter: number,
|
|
684
|
+
) {
|
|
685
|
+
const { numTransientData, hints: transientDataHints } = buildTransientDataHints(
|
|
686
|
+
scopedNoteHashesCLA,
|
|
687
|
+
scopedNullifiersCLA,
|
|
688
|
+
/*futureNoteHashReads=*/ [],
|
|
689
|
+
/*futureNullifierReads=*/ [],
|
|
690
|
+
noteHashNullifierCounterMap,
|
|
691
|
+
minRevertibleSideEffectCounter,
|
|
692
|
+
);
|
|
693
|
+
|
|
694
|
+
const squashedNoteHashCounters = new Set<number>();
|
|
695
|
+
const squashedNullifierCounters = new Set<number>();
|
|
696
|
+
for (let i = 0; i < numTransientData; i++) {
|
|
697
|
+
const hint = transientDataHints[i];
|
|
698
|
+
squashedNoteHashCounters.add(scopedNoteHashesCLA.array[hint.noteHashIndex].counter);
|
|
699
|
+
squashedNullifierCounters.add(scopedNullifiersCLA.array[hint.nullifierIndex].counter);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
return {
|
|
703
|
+
filteredNoteHashes: scopedNoteHashesCLA.getActiveItems().filter(nh => !squashedNoteHashCounters.has(nh.counter)),
|
|
704
|
+
filteredNullifiers: scopedNullifiersCLA.getActiveItems().filter(n => !squashedNullifierCounters.has(n.counter)),
|
|
705
|
+
filteredPrivateLogs: taggedPrivateLogs
|
|
706
|
+
.filter(item => !squashedNoteHashCounters.has(item.sideEffect.noteHashCounter))
|
|
707
|
+
.map(item => new OrderedSideEffect(item.sideEffect.log, item.counter)),
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* Verifies settled read requests by checking membership in the note hash and nullifier trees
|
|
713
|
+
* at the tx's anchor block, mimicking the behavior of the kernels
|
|
714
|
+
*/
|
|
715
|
+
async function verifyReadRequests(
|
|
716
|
+
node: Pick<AztecNode, 'getNoteHashMembershipWitness' | 'getNullifierMembershipWitness'>,
|
|
717
|
+
anchorBlockHash: BlockParameter,
|
|
718
|
+
noteHashReadRequests: ScopedReadRequest[],
|
|
719
|
+
nullifierReadRequests: ScopedReadRequest[],
|
|
720
|
+
scopedNoteHashesCLA: ClaimedLengthArray<ScopedNoteHash, typeof MAX_NOTE_HASHES_PER_TX>,
|
|
721
|
+
scopedNullifiersCLA: ClaimedLengthArray<ScopedNullifier, typeof MAX_NULLIFIERS_PER_TX>,
|
|
722
|
+
) {
|
|
723
|
+
const noteHashReadRequestsCLA = new ClaimedLengthArray<ScopedReadRequest, typeof MAX_NOTE_HASH_READ_REQUESTS_PER_TX>(
|
|
724
|
+
padArrayEnd(noteHashReadRequests, ScopedReadRequest.empty(), MAX_NOTE_HASH_READ_REQUESTS_PER_TX),
|
|
725
|
+
noteHashReadRequests.length,
|
|
726
|
+
);
|
|
727
|
+
const nullifierReadRequestsCLA = new ClaimedLengthArray<ScopedReadRequest, typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX>(
|
|
728
|
+
padArrayEnd(nullifierReadRequests, ScopedReadRequest.empty(), MAX_NULLIFIER_READ_REQUESTS_PER_TX),
|
|
729
|
+
nullifierReadRequests.length,
|
|
730
|
+
);
|
|
731
|
+
|
|
732
|
+
const noteHashResetActions = getNoteHashReadRequestResetActions(
|
|
733
|
+
noteHashReadRequestsCLA,
|
|
734
|
+
scopedNoteHashesCLA,
|
|
735
|
+
/*futureNoteHashes=*/ [],
|
|
736
|
+
);
|
|
737
|
+
const nullifierResetActions = getNullifierReadRequestResetActions(
|
|
738
|
+
nullifierReadRequestsCLA,
|
|
739
|
+
scopedNullifiersCLA,
|
|
740
|
+
/*futureNullifiers=*/ [],
|
|
741
|
+
);
|
|
742
|
+
|
|
743
|
+
const settledNoteHashReads: { index: number; value: Fr }[] = [];
|
|
744
|
+
for (let i = 0; i < noteHashResetActions.actions.length; i++) {
|
|
745
|
+
if (noteHashResetActions.actions[i] === ReadRequestActionEnum.READ_AS_SETTLED) {
|
|
746
|
+
settledNoteHashReads.push({ index: i, value: noteHashReadRequests[i].value });
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
const settledNullifierReads: { index: number; value: Fr }[] = [];
|
|
751
|
+
for (let i = 0; i < nullifierResetActions.actions.length; i++) {
|
|
752
|
+
if (nullifierResetActions.actions[i] === ReadRequestActionEnum.READ_AS_SETTLED) {
|
|
753
|
+
settledNullifierReads.push({ index: i, value: nullifierReadRequests[i].value });
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
const [noteHashWitnesses, nullifierWitnesses] = await Promise.all([
|
|
758
|
+
Promise.all(settledNoteHashReads.map(({ value }) => node.getNoteHashMembershipWitness(anchorBlockHash, value))),
|
|
759
|
+
Promise.all(settledNullifierReads.map(({ value }) => node.getNullifierMembershipWitness(anchorBlockHash, value))),
|
|
760
|
+
]);
|
|
761
|
+
|
|
762
|
+
for (let i = 0; i < settledNoteHashReads.length; i++) {
|
|
763
|
+
if (!noteHashWitnesses[i]) {
|
|
764
|
+
throw new Error(
|
|
765
|
+
`Note hash read request at index ${settledNoteHashReads[i].index} is reading an unknown note hash: ${settledNoteHashReads[i].value}`,
|
|
766
|
+
);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
for (let i = 0; i < settledNullifierReads.length; i++) {
|
|
771
|
+
if (!nullifierWitnesses[i]) {
|
|
772
|
+
throw new Error(
|
|
773
|
+
`Nullifier read request at index ${settledNullifierReads[i].index} is reading an unknown nullifier: ${settledNullifierReads[i].value}`,
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
585
779
|
function splitOrderedSideEffects<T>(effects: OrderedSideEffect<T>[], minRevertibleSideEffectCounter: number) {
|
|
586
780
|
const revertibleSideEffects: T[] = [];
|
|
587
781
|
const nonRevertibleSideEffects: T[] = [];
|
|
@@ -595,21 +789,24 @@ function splitOrderedSideEffects<T>(effects: OrderedSideEffect<T>[], minRevertib
|
|
|
595
789
|
return [nonRevertibleSideEffects, revertibleSideEffects];
|
|
596
790
|
}
|
|
597
791
|
|
|
598
|
-
function meterGasUsed(data: PrivateToRollupAccumulatedData | PrivateToPublicAccumulatedData) {
|
|
792
|
+
function meterGasUsed(data: PrivateToRollupAccumulatedData | PrivateToPublicAccumulatedData, isPrivateOnlyTx: boolean) {
|
|
599
793
|
let meteredDAFields = 0;
|
|
600
794
|
let meteredL2Gas = 0;
|
|
601
795
|
|
|
602
796
|
const numNoteHashes = arrayNonEmptyLength(data.noteHashes, hash => hash.isEmpty());
|
|
603
797
|
meteredDAFields += numNoteHashes;
|
|
604
|
-
|
|
798
|
+
const noteHashBaseGas = isPrivateOnlyTx ? L2_GAS_PER_NOTE_HASH : AVM_EMITNOTEHASH_BASE_L2_GAS;
|
|
799
|
+
meteredL2Gas += numNoteHashes * noteHashBaseGas;
|
|
605
800
|
|
|
606
801
|
const numNullifiers = arrayNonEmptyLength(data.nullifiers, nullifier => nullifier.isEmpty());
|
|
607
802
|
meteredDAFields += numNullifiers;
|
|
608
|
-
|
|
803
|
+
const nullifierBaseGas = isPrivateOnlyTx ? L2_GAS_PER_NULLIFIER : AVM_EMITNULLIFIER_BASE_L2_GAS;
|
|
804
|
+
meteredL2Gas += numNullifiers * nullifierBaseGas;
|
|
609
805
|
|
|
610
806
|
const numL2toL1Messages = arrayNonEmptyLength(data.l2ToL1Msgs, msg => msg.isEmpty());
|
|
611
807
|
meteredDAFields += numL2toL1Messages;
|
|
612
|
-
|
|
808
|
+
const l2ToL1MessageBaseGas = isPrivateOnlyTx ? L2_GAS_PER_L2_TO_L1_MSG : AVM_SENDL2TOL1MSG_BASE_L2_GAS;
|
|
809
|
+
meteredL2Gas += numL2toL1Messages * l2ToL1MessageBaseGas;
|
|
613
810
|
|
|
614
811
|
const numPrivatelogs = arrayNonEmptyLength(data.privateLogs, log => log.isEmpty());
|
|
615
812
|
// Every private log emits its length as an additional field
|