@aztec/simulator 0.60.0 → 0.62.0
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/acvm/oracle/oracle.d.ts +3 -0
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +12 -1
- package/dest/acvm/oracle/typed_oracle.d.ts +4 -1
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +10 -1
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +8 -5
- package/dest/avm/avm_machine_state.d.ts +2 -0
- package/dest/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/avm/avm_machine_state.js +3 -1
- package/dest/avm/avm_simulator.d.ts +15 -0
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +45 -4
- package/dest/avm/fixtures/index.d.ts +1 -1
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +7 -7
- package/dest/avm/journal/journal.d.ts +5 -6
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +42 -17
- package/dest/avm/opcodes/contract.d.ts +8 -1
- package/dest/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/avm/opcodes/contract.js +41 -21
- package/dest/avm/opcodes/control_flow.js +5 -5
- package/dest/avm/opcodes/conversion.d.ts +1 -1
- package/dest/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/avm/opcodes/conversion.js +12 -9
- package/dest/avm/opcodes/environment_getters.d.ts +1 -1
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +5 -1
- package/dest/avm/opcodes/external_calls.d.ts +3 -6
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +23 -43
- package/dest/avm/opcodes/memory.d.ts +20 -0
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +59 -3
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +5 -3
- package/dest/avm/serialization/instruction_serialization.d.ts +36 -34
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +37 -35
- package/dest/avm/test_utils.d.ts +2 -1
- package/dest/avm/test_utils.d.ts.map +1 -1
- package/dest/avm/test_utils.js +4 -1
- package/dest/client/client_execution_context.d.ts +1 -8
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +4 -18
- package/dest/client/db_oracle.d.ts +24 -1
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/db_oracle.js +1 -1
- package/dest/client/view_data_oracle.d.ts +17 -1
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +21 -1
- package/dest/common/index.d.ts +0 -1
- package/dest/common/index.d.ts.map +1 -1
- package/dest/common/index.js +1 -2
- package/dest/public/dual_side_effect_trace.d.ts +3 -5
- package/dest/public/dual_side_effect_trace.d.ts.map +1 -1
- package/dest/public/dual_side_effect_trace.js +8 -4
- package/dest/public/enqueued_call_side_effect_trace.d.ts +4 -6
- package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -1
- package/dest/public/enqueued_call_side_effect_trace.js +19 -7
- package/dest/public/enqueued_call_simulator.d.ts +2 -2
- package/dest/public/enqueued_call_simulator.d.ts.map +1 -1
- package/dest/public/enqueued_call_simulator.js +21 -29
- package/dest/public/enqueued_calls_processor.d.ts +2 -3
- package/dest/public/enqueued_calls_processor.d.ts.map +1 -1
- package/dest/public/enqueued_calls_processor.js +18 -25
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +10 -15
- package/dest/public/public_kernel.d.ts +0 -1
- package/dest/public/public_kernel.d.ts.map +1 -1
- package/dest/public/public_kernel.js +5 -8
- package/dest/public/public_kernel_tail_simulator.d.ts +1 -5
- package/dest/public/public_kernel_tail_simulator.d.ts.map +1 -1
- package/dest/public/public_kernel_tail_simulator.js +6 -12
- package/dest/public/public_processor.js +4 -4
- package/dest/public/side_effect_trace.d.ts +4 -3
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +27 -16
- package/dest/public/side_effect_trace_interface.d.ts +3 -3
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/test/utils.d.ts +2 -2
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +4 -4
- package/package.json +9 -9
- package/src/acvm/oracle/oracle.ts +20 -0
- package/src/acvm/oracle/typed_oracle.ts +13 -0
- package/src/avm/avm_gas.ts +7 -4
- package/src/avm/avm_machine_state.ts +2 -0
- package/src/avm/avm_simulator.ts +69 -6
- package/src/avm/fixtures/index.ts +7 -7
- package/src/avm/journal/journal.ts +62 -19
- package/src/avm/opcodes/contract.ts +45 -21
- package/src/avm/opcodes/control_flow.ts +5 -5
- package/src/avm/opcodes/conversion.ts +9 -6
- package/src/avm/opcodes/environment_getters.ts +7 -2
- package/src/avm/opcodes/external_calls.ts +21 -45
- package/src/avm/opcodes/memory.ts +69 -2
- package/src/avm/serialization/bytecode_serialization.ts +6 -2
- package/src/avm/serialization/instruction_serialization.ts +5 -3
- package/src/avm/test_utils.ts +5 -1
- package/src/client/client_execution_context.ts +4 -27
- package/src/client/db_oracle.ts +38 -0
- package/src/client/view_data_oracle.ts +31 -1
- package/src/common/index.ts +0 -1
- package/src/public/dual_side_effect_trace.ts +20 -6
- package/src/public/enqueued_call_side_effect_trace.ts +46 -8
- package/src/public/enqueued_call_simulator.ts +42 -26
- package/src/public/enqueued_calls_processor.ts +26 -38
- package/src/public/public_db_sources.ts +10 -15
- package/src/public/public_kernel.ts +9 -12
- package/src/public/public_kernel_tail_simulator.ts +6 -15
- package/src/public/public_processor.ts +3 -3
- package/src/public/side_effect_trace.ts +54 -15
- package/src/public/side_effect_trace_interface.ts +9 -4
- package/src/test/utils.ts +9 -2
- package/dest/client/test_utils.d.ts +0 -9
- package/dest/client/test_utils.d.ts.map +0 -1
- package/dest/client/test_utils.js +0 -27
- package/dest/common/side_effect_counter.d.ts +0 -10
- package/dest/common/side_effect_counter.d.ts.map +0 -1
- package/dest/common/side_effect_counter.js +0 -18
- package/dest/rollup/index.d.ts +0 -2
- package/dest/rollup/index.d.ts.map +0 -1
- package/dest/rollup/index.js +0 -2
- package/dest/rollup/rollup.d.ts +0 -101
- package/dest/rollup/rollup.d.ts.map +0 -1
- package/dest/rollup/rollup.js +0 -100
- package/src/client/test_utils.ts +0 -57
- package/src/common/side_effect_counter.ts +0 -17
- package/src/rollup/index.ts +0 -1
- package/src/rollup/rollup.ts +0 -228
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AVM_REQUEST,
|
|
3
2
|
type AvmProvingRequest,
|
|
4
3
|
MerkleTreeId,
|
|
5
4
|
NestedProcessReturnValues,
|
|
6
5
|
ProvingRequestType,
|
|
7
6
|
type PublicExecutionRequest,
|
|
8
7
|
PublicKernelPhase,
|
|
9
|
-
type PublicProvingRequest,
|
|
10
8
|
type SimulationError,
|
|
11
9
|
type Tx,
|
|
12
10
|
UnencryptedFunctionL2Logs,
|
|
13
11
|
} from '@aztec/circuit-types';
|
|
14
12
|
import {
|
|
13
|
+
AvmCircuitInputs,
|
|
15
14
|
AztecAddress,
|
|
16
15
|
ContractStorageRead,
|
|
17
16
|
ContractStorageUpdateRequest,
|
|
@@ -52,6 +51,7 @@ import {
|
|
|
52
51
|
RevertCode,
|
|
53
52
|
TreeLeafReadRequest,
|
|
54
53
|
VMCircuitPublicInputs,
|
|
54
|
+
VerificationKeyData,
|
|
55
55
|
makeEmptyProof,
|
|
56
56
|
makeEmptyRecursiveProof,
|
|
57
57
|
} from '@aztec/circuits.js';
|
|
@@ -59,33 +59,22 @@ import { computeVarArgsHash } from '@aztec/circuits.js/hash';
|
|
|
59
59
|
import { makeTuple } from '@aztec/foundation/array';
|
|
60
60
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
61
61
|
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
62
|
-
import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types';
|
|
63
62
|
import { type MerkleTreeReadOperations } from '@aztec/world-state';
|
|
64
63
|
|
|
65
64
|
import { type PublicExecutionResult, accumulatePublicReturnValues, collectExecutionResults } from './execution.js';
|
|
66
65
|
import { type PublicExecutor } from './executor.js';
|
|
67
66
|
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
68
67
|
|
|
69
|
-
function makeAvmProvingRequest(
|
|
70
|
-
inputs: PublicKernelInnerCircuitPrivateInputs,
|
|
71
|
-
result: PublicExecutionResult,
|
|
72
|
-
): AvmProvingRequest {
|
|
68
|
+
function makeAvmProvingRequest(inputs: PublicCircuitPublicInputs, result: PublicExecutionResult): AvmProvingRequest {
|
|
73
69
|
return {
|
|
74
|
-
type:
|
|
75
|
-
|
|
76
|
-
calldata: result.calldata,
|
|
77
|
-
bytecode: result.bytecode!,
|
|
78
|
-
avmHints: result.avmCircuitHints,
|
|
79
|
-
kernelRequest: {
|
|
80
|
-
type: ProvingRequestType.PUBLIC_KERNEL_INNER,
|
|
81
|
-
inputs,
|
|
82
|
-
},
|
|
70
|
+
type: ProvingRequestType.PUBLIC_VM,
|
|
71
|
+
inputs: new AvmCircuitInputs(result.functionName, result.calldata, inputs, result.avmCircuitHints),
|
|
83
72
|
};
|
|
84
73
|
}
|
|
85
74
|
|
|
86
75
|
export type EnqueuedCallResult = {
|
|
87
76
|
/** Inputs to be used for proving */
|
|
88
|
-
|
|
77
|
+
avmProvingRequest: AvmProvingRequest;
|
|
89
78
|
/** The public kernel output at the end of the enqueued call */
|
|
90
79
|
kernelOutput: VMCircuitPublicInputs;
|
|
91
80
|
/** Unencrypted logs generated during the execution of this enqueued call */
|
|
@@ -186,7 +175,7 @@ export class EnqueuedCallSimulator {
|
|
|
186
175
|
): Promise<EnqueuedCallResult> {
|
|
187
176
|
const executionResults = collectExecutionResults(topResult);
|
|
188
177
|
|
|
189
|
-
|
|
178
|
+
let avmProvingRequest: AvmProvingRequest;
|
|
190
179
|
let gasUsed = Gas.empty();
|
|
191
180
|
let revertReason;
|
|
192
181
|
let kernelOutput = startVMCircuitOutput;
|
|
@@ -215,7 +204,7 @@ export class EnqueuedCallSimulator {
|
|
|
215
204
|
kernelOutput = output;
|
|
216
205
|
|
|
217
206
|
// Capture the inputs for later proving in the AVM and kernel.
|
|
218
|
-
|
|
207
|
+
avmProvingRequest = makeAvmProvingRequest(inputs.publicCall.publicInputs, result);
|
|
219
208
|
|
|
220
209
|
// Safely return the revert reason and the kernel output (which has had its revertible side effects dropped)
|
|
221
210
|
// TODO(@leila) we shouldn't drop everything when it reverts. The tail kernel needs the data to prove that it's reverted for the correct reason.
|
|
@@ -226,7 +215,7 @@ export class EnqueuedCallSimulator {
|
|
|
226
215
|
// TODO(@spalladino): Check gasUsed is correct. The AVM should take care of setting gasLeft to zero upon a revert.
|
|
227
216
|
|
|
228
217
|
return {
|
|
229
|
-
|
|
218
|
+
avmProvingRequest,
|
|
230
219
|
kernelOutput,
|
|
231
220
|
newUnencryptedLogs: UnencryptedFunctionL2Logs.empty(),
|
|
232
221
|
returnValues: NestedProcessReturnValues.empty(),
|
|
@@ -237,7 +226,7 @@ export class EnqueuedCallSimulator {
|
|
|
237
226
|
}
|
|
238
227
|
|
|
239
228
|
return {
|
|
240
|
-
|
|
229
|
+
avmProvingRequest: avmProvingRequest!,
|
|
241
230
|
kernelOutput,
|
|
242
231
|
newUnencryptedLogs: topResult.allUnencryptedLogs,
|
|
243
232
|
returnValues: accumulatePublicReturnValues(topResult),
|
|
@@ -257,7 +246,7 @@ export class EnqueuedCallSimulator {
|
|
|
257
246
|
): Promise<{ inputs: PublicKernelInnerCircuitPrivateInputs; output: VMCircuitPublicInputs }> {
|
|
258
247
|
// The proof is not used in simulation
|
|
259
248
|
const proof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH);
|
|
260
|
-
const vk =
|
|
249
|
+
const vk = VerificationKeyData.makeFakeHonk();
|
|
261
250
|
const previousKernel = new PublicKernelInnerData(previousOutput, proof, vk);
|
|
262
251
|
const inputs = new PublicKernelInnerCircuitPrivateInputs(previousKernel, callData);
|
|
263
252
|
return { inputs, output: await this.publicKernelSimulator.publicKernelCircuitInner(inputs) };
|
|
@@ -283,9 +272,24 @@ export class EnqueuedCallSimulator {
|
|
|
283
272
|
callContext: result.executionRequest.callContext,
|
|
284
273
|
proverAddress: AztecAddress.ZERO,
|
|
285
274
|
argsHash: computeVarArgsHash(result.executionRequest.args),
|
|
286
|
-
noteHashes: padArrayEnd(
|
|
287
|
-
|
|
288
|
-
|
|
275
|
+
noteHashes: padArrayEnd(
|
|
276
|
+
result.noteHashes,
|
|
277
|
+
NoteHash.empty(),
|
|
278
|
+
MAX_NOTE_HASHES_PER_CALL,
|
|
279
|
+
`Too many note hashes. Got ${result.noteHashes.length} with max being ${MAX_NOTE_HASHES_PER_CALL}`,
|
|
280
|
+
),
|
|
281
|
+
nullifiers: padArrayEnd(
|
|
282
|
+
result.nullifiers,
|
|
283
|
+
Nullifier.empty(),
|
|
284
|
+
MAX_NULLIFIERS_PER_CALL,
|
|
285
|
+
`Too many nullifiers. Got ${result.nullifiers.length} with max being ${MAX_NULLIFIERS_PER_CALL}`,
|
|
286
|
+
),
|
|
287
|
+
l2ToL1Msgs: padArrayEnd(
|
|
288
|
+
result.l2ToL1Messages,
|
|
289
|
+
L2ToL1Message.empty(),
|
|
290
|
+
MAX_L2_TO_L1_MSGS_PER_CALL,
|
|
291
|
+
`Too many L2 to L1 messages. Got ${result.l2ToL1Messages.length} with max being ${MAX_L2_TO_L1_MSGS_PER_CALL}`,
|
|
292
|
+
),
|
|
289
293
|
startSideEffectCounter: result.startSideEffectCounter,
|
|
290
294
|
endSideEffectCounter: result.endSideEffectCounter,
|
|
291
295
|
returnsHash: computeVarArgsHash(result.returnValues),
|
|
@@ -293,38 +297,50 @@ export class EnqueuedCallSimulator {
|
|
|
293
297
|
result.noteHashReadRequests,
|
|
294
298
|
TreeLeafReadRequest.empty(),
|
|
295
299
|
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
|
|
300
|
+
`Too many note hash read requests. Got ${result.noteHashReadRequests.length} with max being ${MAX_NOTE_HASH_READ_REQUESTS_PER_CALL}`,
|
|
296
301
|
),
|
|
297
302
|
nullifierReadRequests: padArrayEnd(
|
|
298
303
|
result.nullifierReadRequests,
|
|
299
304
|
ReadRequest.empty(),
|
|
300
305
|
MAX_NULLIFIER_READ_REQUESTS_PER_CALL,
|
|
306
|
+
`Too many nullifier read requests. Got ${result.nullifierReadRequests.length} with max being ${MAX_NULLIFIER_READ_REQUESTS_PER_CALL}`,
|
|
301
307
|
),
|
|
302
308
|
nullifierNonExistentReadRequests: padArrayEnd(
|
|
303
309
|
result.nullifierNonExistentReadRequests,
|
|
304
310
|
ReadRequest.empty(),
|
|
305
311
|
MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL,
|
|
312
|
+
`Too many nullifier non-existent read requests. Got ${result.nullifierNonExistentReadRequests.length} with max being ${MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL}`,
|
|
306
313
|
),
|
|
307
314
|
l1ToL2MsgReadRequests: padArrayEnd(
|
|
308
315
|
result.l1ToL2MsgReadRequests,
|
|
309
316
|
TreeLeafReadRequest.empty(),
|
|
310
317
|
MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL,
|
|
318
|
+
`Too many L1 to L2 message read requests. Got ${result.l1ToL2MsgReadRequests.length} with max being ${MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL}`,
|
|
311
319
|
),
|
|
312
320
|
contractStorageReads: padArrayEnd(
|
|
313
321
|
result.contractStorageReads,
|
|
314
322
|
ContractStorageRead.empty(),
|
|
315
323
|
MAX_PUBLIC_DATA_READS_PER_CALL,
|
|
324
|
+
`Too many public data reads. Got ${result.contractStorageReads.length} with max being ${MAX_PUBLIC_DATA_READS_PER_CALL}`,
|
|
316
325
|
),
|
|
317
326
|
contractStorageUpdateRequests: padArrayEnd(
|
|
318
327
|
result.contractStorageUpdateRequests,
|
|
319
328
|
ContractStorageUpdateRequest.empty(),
|
|
320
329
|
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
|
|
330
|
+
`Too many public data update requests. Got ${result.contractStorageUpdateRequests.length} with max being ${MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL}`,
|
|
321
331
|
),
|
|
322
332
|
publicCallRequests: padArrayEnd(
|
|
323
333
|
result.publicCallRequests,
|
|
324
334
|
PublicInnerCallRequest.empty(),
|
|
325
335
|
MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
|
|
336
|
+
`Too many public call requests. Got ${result.publicCallRequests.length} with max being ${MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL}`,
|
|
337
|
+
),
|
|
338
|
+
unencryptedLogsHashes: padArrayEnd(
|
|
339
|
+
result.unencryptedLogsHashes,
|
|
340
|
+
LogHash.empty(),
|
|
341
|
+
MAX_UNENCRYPTED_LOGS_PER_CALL,
|
|
342
|
+
`Too many unencrypted logs. Got ${result.unencryptedLogsHashes.length} with max being ${MAX_UNENCRYPTED_LOGS_PER_CALL}`,
|
|
326
343
|
),
|
|
327
|
-
unencryptedLogsHashes: padArrayEnd(result.unencryptedLogsHashes, LogHash.empty(), MAX_UNENCRYPTED_LOGS_PER_CALL),
|
|
328
344
|
historicalHeader: this.historicalHeader,
|
|
329
345
|
globalVariables: this.globalVariables,
|
|
330
346
|
startGasLeft: Gas.from(result.startGasLeft),
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
+
type AvmProvingRequest,
|
|
2
3
|
type MerkleTreeReadOperations,
|
|
3
4
|
type NestedProcessReturnValues,
|
|
4
5
|
type ProcessedTx,
|
|
5
|
-
ProvingRequestType,
|
|
6
6
|
type PublicExecutionRequest,
|
|
7
|
-
type PublicKernelMergeRequest,
|
|
8
7
|
PublicKernelPhase,
|
|
9
|
-
type PublicProvingRequest,
|
|
10
8
|
type SimulationError,
|
|
11
9
|
type Tx,
|
|
12
10
|
} from '@aztec/circuit-types';
|
|
@@ -23,12 +21,13 @@ import {
|
|
|
23
21
|
type PublicKernelCircuitPublicInputs,
|
|
24
22
|
PublicKernelData,
|
|
25
23
|
type VMCircuitPublicInputs,
|
|
24
|
+
VerificationKeyData,
|
|
26
25
|
makeEmptyProof,
|
|
27
26
|
makeEmptyRecursiveProof,
|
|
28
27
|
} from '@aztec/circuits.js';
|
|
29
28
|
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
30
29
|
import { Timer } from '@aztec/foundation/timer';
|
|
31
|
-
import {
|
|
30
|
+
import { getVKSiblingPath } from '@aztec/noir-protocol-circuits-types';
|
|
32
31
|
|
|
33
32
|
import { inspect } from 'util';
|
|
34
33
|
|
|
@@ -45,10 +44,9 @@ const PhaseIsRevertible: Record<PublicKernelPhase, boolean> = {
|
|
|
45
44
|
};
|
|
46
45
|
|
|
47
46
|
type PublicPhaseResult = {
|
|
47
|
+
avmProvingRequest: AvmProvingRequest;
|
|
48
48
|
/** The output of the public kernel circuit simulation for this phase */
|
|
49
49
|
publicKernelOutput: PublicKernelCircuitPublicInputs;
|
|
50
|
-
/** The collection of public proving requests */
|
|
51
|
-
provingRequests: PublicProvingRequest[];
|
|
52
50
|
/** Return values of simulating complete callstack */
|
|
53
51
|
returnValues: NestedProcessReturnValues[];
|
|
54
52
|
/** Gas used during the execution this phase */
|
|
@@ -66,8 +64,7 @@ export type ProcessedPhase = {
|
|
|
66
64
|
};
|
|
67
65
|
|
|
68
66
|
export type TxPublicCallsResult = {
|
|
69
|
-
|
|
70
|
-
provingRequests: PublicProvingRequest[];
|
|
67
|
+
avmProvingRequest: AvmProvingRequest;
|
|
71
68
|
/** The output of the public kernel tail circuit simulation for this tx */
|
|
72
69
|
tailKernelOutput: KernelCircuitPublicInputs;
|
|
73
70
|
/** Return values of simulating complete callstack */
|
|
@@ -158,8 +155,8 @@ export class EnqueuedCallsProcessor {
|
|
|
158
155
|
PublicKernelPhase.TEARDOWN,
|
|
159
156
|
];
|
|
160
157
|
const processedPhases: ProcessedPhase[] = [];
|
|
161
|
-
const provingRequests: PublicProvingRequest[] = [];
|
|
162
158
|
const gasUsed: ProcessedTx['gasUsed'] = {};
|
|
159
|
+
let avmProvingRequest: AvmProvingRequest;
|
|
163
160
|
let publicKernelOutput = tx.data.toPublicKernelCircuitPublicInputs();
|
|
164
161
|
let isFromPrivate = true;
|
|
165
162
|
let returnValues: NestedProcessReturnValues[] = [];
|
|
@@ -184,7 +181,9 @@ export class EnqueuedCallsProcessor {
|
|
|
184
181
|
publicKernelOutput = result.publicKernelOutput;
|
|
185
182
|
isFromPrivate = false;
|
|
186
183
|
|
|
187
|
-
|
|
184
|
+
// Propagate only one avmProvingRequest of a function call for now, so that we know it's still provable.
|
|
185
|
+
// Eventually this will be the proof for the entire public call stack.
|
|
186
|
+
avmProvingRequest = result.avmProvingRequest;
|
|
188
187
|
if (phase === PublicKernelPhase.APP_LOGIC) {
|
|
189
188
|
returnValues = result.returnValues;
|
|
190
189
|
}
|
|
@@ -201,19 +200,16 @@ export class EnqueuedCallsProcessor {
|
|
|
201
200
|
}
|
|
202
201
|
}
|
|
203
202
|
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
},
|
|
212
|
-
);
|
|
213
|
-
provingRequests.push(provingRequest);
|
|
203
|
+
const tailKernelOutput = await this.publicKernelTailSimulator.simulate(publicKernelOutput).catch(
|
|
204
|
+
// the abstract phase manager throws if simulation gives error in non-revertible phase
|
|
205
|
+
async err => {
|
|
206
|
+
await this.worldStateDB.rollbackToCommit();
|
|
207
|
+
throw err;
|
|
208
|
+
},
|
|
209
|
+
);
|
|
214
210
|
|
|
215
211
|
return {
|
|
216
|
-
|
|
212
|
+
avmProvingRequest: avmProvingRequest!,
|
|
217
213
|
tailKernelOutput,
|
|
218
214
|
returnValues,
|
|
219
215
|
gasUsed,
|
|
@@ -233,8 +229,8 @@ export class EnqueuedCallsProcessor {
|
|
|
233
229
|
this.log.debug(`Beginning processing in phase ${PublicKernelPhase[phase]} for tx ${tx.getTxHash()}`);
|
|
234
230
|
|
|
235
231
|
const phaseTimer = new Timer();
|
|
236
|
-
const provingRequests: PublicProvingRequest[] = [];
|
|
237
232
|
const returnValues: NestedProcessReturnValues[] = [];
|
|
233
|
+
let avmProvingRequest: AvmProvingRequest;
|
|
238
234
|
let publicKernelOutput = previousPublicKernelOutput;
|
|
239
235
|
let gasUsed = Gas.empty();
|
|
240
236
|
let revertReason: SimulationError | undefined;
|
|
@@ -270,7 +266,7 @@ export class EnqueuedCallsProcessor {
|
|
|
270
266
|
throw enqueuedCallResult.revertReason;
|
|
271
267
|
}
|
|
272
268
|
|
|
273
|
-
|
|
269
|
+
avmProvingRequest = enqueuedCallResult.avmProvingRequest;
|
|
274
270
|
returnValues.push(enqueuedCallResult.returnValues);
|
|
275
271
|
gasUsed = gasUsed.add(enqueuedCallResult.gasUsed);
|
|
276
272
|
revertReason ??= enqueuedCallResult.revertReason;
|
|
@@ -286,14 +282,13 @@ export class EnqueuedCallsProcessor {
|
|
|
286
282
|
tx.unencryptedLogs.addFunctionLogs([enqueuedCallResult.newUnencryptedLogs]);
|
|
287
283
|
}
|
|
288
284
|
|
|
289
|
-
const
|
|
285
|
+
const output = await this.runMergeKernelCircuit(
|
|
290
286
|
publicKernelOutput,
|
|
291
287
|
enqueuedCallResult.kernelOutput,
|
|
292
288
|
isFromPrivate,
|
|
293
289
|
);
|
|
294
290
|
publicKernelOutput = output;
|
|
295
291
|
isFromPrivate = false;
|
|
296
|
-
provingRequests.push(provingRequest);
|
|
297
292
|
}
|
|
298
293
|
|
|
299
294
|
if (phase === PublicKernelPhase.SETUP) {
|
|
@@ -301,8 +296,8 @@ export class EnqueuedCallsProcessor {
|
|
|
301
296
|
}
|
|
302
297
|
|
|
303
298
|
return {
|
|
299
|
+
avmProvingRequest: avmProvingRequest!,
|
|
304
300
|
publicKernelOutput,
|
|
305
|
-
provingRequests,
|
|
306
301
|
durationMs: phaseTimer.ms(),
|
|
307
302
|
gasUsed,
|
|
308
303
|
returnValues: revertReason ? [] : returnValues,
|
|
@@ -349,7 +344,7 @@ export class EnqueuedCallsProcessor {
|
|
|
349
344
|
previousOutput: PublicKernelCircuitPublicInputs,
|
|
350
345
|
enqueuedCallData: VMCircuitPublicInputs,
|
|
351
346
|
isFromPrivate: boolean,
|
|
352
|
-
): Promise<
|
|
347
|
+
): Promise<PublicKernelCircuitPublicInputs> {
|
|
353
348
|
const previousKernel = this.getPreviousKernelData(previousOutput, isFromPrivate);
|
|
354
349
|
|
|
355
350
|
// The proof is not used in simulation.
|
|
@@ -358,25 +353,18 @@ export class EnqueuedCallsProcessor {
|
|
|
358
353
|
|
|
359
354
|
const inputs = new PublicKernelCircuitPrivateInputs(previousKernel, callData);
|
|
360
355
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
const provingRequest: PublicKernelMergeRequest = {
|
|
364
|
-
type: ProvingRequestType.PUBLIC_KERNEL_MERGE,
|
|
365
|
-
inputs,
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
return { output, provingRequest };
|
|
356
|
+
return await this.publicKernelSimulator.publicKernelCircuitMerge(inputs);
|
|
369
357
|
}
|
|
370
358
|
|
|
371
359
|
private getPreviousKernelData(
|
|
372
360
|
previousOutput: PublicKernelCircuitPublicInputs,
|
|
373
|
-
|
|
361
|
+
_isFromPrivate: boolean,
|
|
374
362
|
): PublicKernelData {
|
|
375
363
|
// The proof is not used in simulation.
|
|
376
364
|
const proof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH);
|
|
377
365
|
|
|
378
|
-
const vk =
|
|
379
|
-
const vkIndex =
|
|
366
|
+
const vk = VerificationKeyData.makeFakeHonk();
|
|
367
|
+
const vkIndex = 0;
|
|
380
368
|
const siblingPath = getVKSiblingPath(vkIndex);
|
|
381
369
|
|
|
382
370
|
return new PublicKernelData(previousOutput, proof, vk, vkIndex, siblingPath);
|
|
@@ -203,24 +203,19 @@ export class WorldStateDB extends ContractsDataSourcePublicDB implements PublicS
|
|
|
203
203
|
messageHash: Fr,
|
|
204
204
|
secret: Fr,
|
|
205
205
|
): Promise<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>> {
|
|
206
|
-
let nullifierIndex: bigint | undefined;
|
|
207
|
-
let messageIndex: bigint | undefined;
|
|
208
|
-
let startIndex = 0n;
|
|
209
|
-
|
|
210
|
-
// We iterate over messages until we find one whose nullifier is not in the nullifier tree --> we need to check
|
|
211
|
-
// for nullifiers because messages can have duplicates.
|
|
212
206
|
const timer = new Timer();
|
|
213
|
-
do {
|
|
214
|
-
messageIndex = (await this.db.findLeafIndexAfter(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, messageHash, startIndex))!;
|
|
215
|
-
if (messageIndex === undefined) {
|
|
216
|
-
throw new Error(`No non-nullified L1 to L2 message found for message hash ${messageHash.toString()}`);
|
|
217
|
-
}
|
|
218
207
|
|
|
219
|
-
|
|
220
|
-
|
|
208
|
+
const messageIndex = await this.db.findLeafIndex(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, messageHash);
|
|
209
|
+
if (messageIndex === undefined) {
|
|
210
|
+
throw new Error(`No L1 to L2 message found for message hash ${messageHash.toString()}`);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const messageNullifier = computeL1ToL2MessageNullifier(contractAddress, messageHash, secret);
|
|
214
|
+
const nullifierIndex = await this.getNullifierIndex(messageNullifier);
|
|
221
215
|
|
|
222
|
-
|
|
223
|
-
|
|
216
|
+
if (nullifierIndex !== undefined) {
|
|
217
|
+
throw new Error(`No non-nullified L1 to L2 message found for message hash ${messageHash.toString()}`);
|
|
218
|
+
}
|
|
224
219
|
|
|
225
220
|
const siblingPath = await this.db.getSiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>(
|
|
226
221
|
MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type CircuitSimulationStats } from '@aztec/circuit-types/stats';
|
|
2
1
|
import {
|
|
3
2
|
type KernelCircuitPublicInputs,
|
|
4
3
|
type PublicKernelCircuitPrivateInputs,
|
|
@@ -10,7 +9,9 @@ import {
|
|
|
10
9
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
11
10
|
import { elapsed } from '@aztec/foundation/timer';
|
|
12
11
|
import {
|
|
13
|
-
|
|
12
|
+
SimulatedPublicKernelInnerArtifact,
|
|
13
|
+
SimulatedPublicKernelMergeArtifact,
|
|
14
|
+
SimulatedPublicKernelTailArtifact,
|
|
14
15
|
convertSimulatedPublicInnerInputsToWitnessMap,
|
|
15
16
|
convertSimulatedPublicInnerOutputFromWitnessMap,
|
|
16
17
|
convertSimulatedPublicMergeInputsToWitnessMap,
|
|
@@ -19,7 +20,6 @@ import {
|
|
|
19
20
|
convertSimulatedPublicTailOutputFromWitnessMap,
|
|
20
21
|
} from '@aztec/noir-protocol-circuits-types';
|
|
21
22
|
|
|
22
|
-
import { WASMSimulator } from '../providers/acvm_wasm.js';
|
|
23
23
|
import { type SimulationProvider } from '../providers/simulation_provider.js';
|
|
24
24
|
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
25
25
|
|
|
@@ -29,9 +29,6 @@ import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simul
|
|
|
29
29
|
export class RealPublicKernelCircuitSimulator implements PublicKernelCircuitSimulator {
|
|
30
30
|
private log = createDebugLogger('aztec:public-kernel-simulator');
|
|
31
31
|
|
|
32
|
-
// Some circuits are so small it is faster to use WASM
|
|
33
|
-
private wasmSimulator: WASMSimulator = new WASMSimulator();
|
|
34
|
-
|
|
35
32
|
constructor(private simulator: SimulationProvider) {}
|
|
36
33
|
|
|
37
34
|
/**
|
|
@@ -42,7 +39,7 @@ export class RealPublicKernelCircuitSimulator implements PublicKernelCircuitSimu
|
|
|
42
39
|
public async publicKernelCircuitInner(input: PublicKernelInnerCircuitPrivateInputs): Promise<VMCircuitPublicInputs> {
|
|
43
40
|
const inputWitness = convertSimulatedPublicInnerInputsToWitnessMap(input);
|
|
44
41
|
const [duration, witness] = await elapsed(() =>
|
|
45
|
-
this.
|
|
42
|
+
this.simulator.simulateCircuit(inputWitness, SimulatedPublicKernelInnerArtifact),
|
|
46
43
|
);
|
|
47
44
|
const result = convertSimulatedPublicInnerOutputFromWitnessMap(witness);
|
|
48
45
|
this.log.debug(`Simulated public kernel inner circuit`, {
|
|
@@ -51,7 +48,7 @@ export class RealPublicKernelCircuitSimulator implements PublicKernelCircuitSimu
|
|
|
51
48
|
duration,
|
|
52
49
|
inputSize: input.toBuffer().length,
|
|
53
50
|
outputSize: result.toBuffer().length,
|
|
54
|
-
}
|
|
51
|
+
});
|
|
55
52
|
return result;
|
|
56
53
|
}
|
|
57
54
|
|
|
@@ -65,7 +62,7 @@ export class RealPublicKernelCircuitSimulator implements PublicKernelCircuitSimu
|
|
|
65
62
|
): Promise<PublicKernelCircuitPublicInputs> {
|
|
66
63
|
const inputWitness = convertSimulatedPublicMergeInputsToWitnessMap(input);
|
|
67
64
|
const [duration, witness] = await elapsed(() =>
|
|
68
|
-
this.
|
|
65
|
+
this.simulator.simulateCircuit(inputWitness, SimulatedPublicKernelMergeArtifact),
|
|
69
66
|
);
|
|
70
67
|
const result = convertSimulatedPublicMergeOutputFromWitnessMap(witness);
|
|
71
68
|
this.log.debug(`Simulated public kernel merge circuit`, {
|
|
@@ -74,7 +71,7 @@ export class RealPublicKernelCircuitSimulator implements PublicKernelCircuitSimu
|
|
|
74
71
|
duration,
|
|
75
72
|
inputSize: input.toBuffer().length,
|
|
76
73
|
outputSize: result.toBuffer().length,
|
|
77
|
-
}
|
|
74
|
+
});
|
|
78
75
|
return result;
|
|
79
76
|
}
|
|
80
77
|
|
|
@@ -88,7 +85,7 @@ export class RealPublicKernelCircuitSimulator implements PublicKernelCircuitSimu
|
|
|
88
85
|
): Promise<KernelCircuitPublicInputs> {
|
|
89
86
|
const inputWitness = convertSimulatedPublicTailInputsToWitnessMap(input);
|
|
90
87
|
const [duration, witness] = await elapsed(() =>
|
|
91
|
-
this.
|
|
88
|
+
this.simulator.simulateCircuit(inputWitness, SimulatedPublicKernelTailArtifact),
|
|
92
89
|
);
|
|
93
90
|
const result = convertSimulatedPublicTailOutputFromWitnessMap(witness);
|
|
94
91
|
this.log.debug(`Simulated public kernel tail circuit`, {
|
|
@@ -97,7 +94,7 @@ export class RealPublicKernelCircuitSimulator implements PublicKernelCircuitSimu
|
|
|
97
94
|
duration,
|
|
98
95
|
inputSize: input.toBuffer().length,
|
|
99
96
|
outputSize: result.toBuffer().length,
|
|
100
|
-
}
|
|
97
|
+
});
|
|
101
98
|
return result;
|
|
102
99
|
}
|
|
103
100
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ProvingRequestType, type PublicKernelTailRequest } from '@aztec/circuit-types';
|
|
2
1
|
import {
|
|
3
2
|
type KernelCircuitPublicInputs,
|
|
4
3
|
MAX_NULLIFIERS_PER_TX,
|
|
@@ -7,10 +6,11 @@ import {
|
|
|
7
6
|
type PublicKernelCircuitPublicInputs,
|
|
8
7
|
PublicKernelData,
|
|
9
8
|
PublicKernelTailCircuitPrivateInputs,
|
|
9
|
+
VerificationKeyData,
|
|
10
10
|
makeEmptyRecursiveProof,
|
|
11
11
|
mergeAccumulatedData,
|
|
12
12
|
} from '@aztec/circuits.js';
|
|
13
|
-
import {
|
|
13
|
+
import { getVKSiblingPath } from '@aztec/noir-protocol-circuits-types';
|
|
14
14
|
import { type MerkleTreeReadOperations } from '@aztec/world-state';
|
|
15
15
|
|
|
16
16
|
import { HintsBuilder } from './hints_builder.js';
|
|
@@ -28,19 +28,10 @@ export class PublicKernelTailSimulator {
|
|
|
28
28
|
return new PublicKernelTailSimulator(db, publicKernelSimulator, hintsBuilder);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
async simulate(
|
|
32
|
-
previousOutput: PublicKernelCircuitPublicInputs,
|
|
33
|
-
): Promise<{ output: KernelCircuitPublicInputs; provingRequest: PublicKernelTailRequest }> {
|
|
31
|
+
async simulate(previousOutput: PublicKernelCircuitPublicInputs): Promise<KernelCircuitPublicInputs> {
|
|
34
32
|
const inputs = await this.buildPrivateInputs(previousOutput);
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const provingRequest: PublicKernelTailRequest = {
|
|
39
|
-
type: ProvingRequestType.PUBLIC_KERNEL_TAIL,
|
|
40
|
-
inputs,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return { output, provingRequest };
|
|
34
|
+
return await this.publicKernelSimulator.publicKernelCircuitTail(inputs);
|
|
44
35
|
}
|
|
45
36
|
|
|
46
37
|
private async buildPrivateInputs(previousOutput: PublicKernelCircuitPublicInputs) {
|
|
@@ -98,8 +89,8 @@ export class PublicKernelTailSimulator {
|
|
|
98
89
|
|
|
99
90
|
private getPreviousKernelData(previousOutput: PublicKernelCircuitPublicInputs): PublicKernelData {
|
|
100
91
|
const proof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH);
|
|
101
|
-
const vk =
|
|
102
|
-
const vkIndex =
|
|
92
|
+
const vk = VerificationKeyData.makeFakeHonk();
|
|
93
|
+
const vkIndex = 0;
|
|
103
94
|
const siblingPath = getVKSiblingPath(vkIndex);
|
|
104
95
|
return new PublicKernelData(previousOutput, proof, vk, vkIndex, siblingPath);
|
|
105
96
|
}
|
|
@@ -152,7 +152,7 @@ export class PublicProcessor {
|
|
|
152
152
|
}
|
|
153
153
|
try {
|
|
154
154
|
const [processedTx, returnValues] = !tx.hasPublicCalls()
|
|
155
|
-
? [makeProcessedTx(tx, tx.data.toKernelCircuitPublicInputs()
|
|
155
|
+
? [makeProcessedTx(tx, tx.data.toKernelCircuitPublicInputs())]
|
|
156
156
|
: await this.processTxWithPublicCalls(tx);
|
|
157
157
|
this.log.debug(`Processed tx`, {
|
|
158
158
|
txHash: processedTx.hash,
|
|
@@ -253,7 +253,7 @@ export class PublicProcessor {
|
|
|
253
253
|
private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, NestedProcessReturnValues[]]> {
|
|
254
254
|
const timer = new Timer();
|
|
255
255
|
|
|
256
|
-
const { tailKernelOutput, returnValues, revertReason,
|
|
256
|
+
const { avmProvingRequest, tailKernelOutput, returnValues, revertReason, gasUsed, processedPhases } =
|
|
257
257
|
await this.enqueuedCallsProcessor.process(tx);
|
|
258
258
|
|
|
259
259
|
if (!tailKernelOutput) {
|
|
@@ -279,7 +279,7 @@ export class PublicProcessor {
|
|
|
279
279
|
const phaseCount = processedPhases.length;
|
|
280
280
|
this.metrics.recordTx(phaseCount, timer.ms());
|
|
281
281
|
|
|
282
|
-
const processedTx = makeProcessedTx(tx, tailKernelOutput,
|
|
282
|
+
const processedTx = makeProcessedTx(tx, tailKernelOutput, { avmProvingRequest, revertReason, gasUsed });
|
|
283
283
|
return [processedTx, returnValues];
|
|
284
284
|
}
|
|
285
285
|
}
|