@aztec/simulator 0.55.1 → 0.57.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 +2 -5
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +6 -37
- package/dest/acvm/oracle/typed_oracle.d.ts +3 -6
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +1 -10
- package/dest/avm/avm_execution_environment.d.ts +2 -11
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +3 -22
- package/dest/avm/avm_gas.d.ts +2 -2
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +31 -116
- package/dest/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/avm/avm_machine_state.js +6 -6
- package/dest/avm/avm_memory_types.d.ts +38 -9
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +27 -13
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +5 -6
- package/dest/avm/bytecode_utils.d.ts +1 -2
- package/dest/avm/bytecode_utils.d.ts.map +1 -1
- package/dest/avm/bytecode_utils.js +3 -17
- package/dest/avm/errors.d.ts +1 -1
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/errors.js +12 -3
- package/dest/avm/fixtures/index.d.ts +4 -16
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +11 -27
- package/dest/avm/journal/index.d.ts +0 -1
- package/dest/avm/journal/index.d.ts.map +1 -1
- package/dest/avm/journal/index.js +1 -2
- package/dest/avm/journal/journal.d.ts +6 -5
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +18 -16
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +37 -30
- package/dest/avm/opcodes/addressing_mode.d.ts +3 -2
- package/dest/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/avm/opcodes/addressing_mode.js +25 -21
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +6 -5
- package/dest/avm/opcodes/bitwise.d.ts +10 -4
- package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/avm/opcodes/bitwise.js +26 -18
- package/dest/avm/opcodes/commitment.d.ts.map +1 -1
- package/dest/avm/opcodes/commitment.js +6 -5
- package/dest/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/avm/opcodes/comparators.js +8 -7
- package/dest/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/avm/opcodes/contract.js +6 -5
- package/dest/avm/opcodes/control_flow.js +6 -6
- package/dest/avm/opcodes/conversion.d.ts +3 -2
- package/dest/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/avm/opcodes/conversion.js +21 -13
- package/dest/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/avm/opcodes/ec_add.js +8 -7
- package/dest/avm/opcodes/environment_getters.d.ts +27 -63
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +76 -80
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +27 -16
- package/dest/avm/opcodes/hashing.d.ts +5 -5
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +47 -40
- package/dest/avm/opcodes/index.d.ts +3 -0
- package/dest/avm/opcodes/index.d.ts.map +1 -1
- package/dest/avm/opcodes/index.js +4 -1
- package/dest/avm/opcodes/instruction.d.ts +2 -6
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +3 -9
- package/dest/avm/opcodes/instruction_impl.d.ts +0 -26
- package/dest/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction_impl.js +1 -51
- package/dest/avm/opcodes/memory.d.ts +5 -12
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +40 -53
- package/dest/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/avm/opcodes/misc.js +6 -5
- package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
- package/dest/avm/opcodes/multi_scalar_mul.js +17 -16
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +11 -9
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +5 -25
- package/dest/avm/serialization/instruction_serialization.d.ts +40 -54
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +41 -57
- package/dest/avm/test_utils.d.ts +8 -8
- package/dest/avm/test_utils.d.ts.map +1 -1
- package/dest/avm/test_utils.js +15 -15
- package/dest/client/client_execution_context.d.ts +6 -30
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +31 -53
- package/dest/client/index.d.ts +0 -1
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +1 -2
- package/dest/client/private_execution.d.ts +2 -2
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +5 -19
- package/dest/client/simulator.d.ts +3 -4
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +1 -1
- package/dest/client/test_utils.d.ts.map +1 -1
- package/dest/client/test_utils.js +12 -6
- package/dest/client/unconstrained_execution.d.ts +2 -2
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +3 -3
- package/dest/common/debug_fn_name.d.ts +4 -0
- package/dest/common/debug_fn_name.d.ts.map +1 -0
- package/dest/common/debug_fn_name.js +15 -0
- 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/enqueued_call_simulator.d.ts +43 -0
- package/dest/public/enqueued_call_simulator.d.ts.map +1 -0
- package/dest/public/enqueued_call_simulator.js +154 -0
- package/dest/public/enqueued_calls_processor.d.ts +44 -0
- package/dest/public/enqueued_calls_processor.d.ts.map +1 -0
- package/dest/public/enqueued_calls_processor.js +218 -0
- package/dest/public/execution.d.ts +10 -8
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +15 -8
- package/dest/public/executor.d.ts +4 -7
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +10 -14
- package/dest/public/hints_builder.d.ts +4 -3
- package/dest/public/hints_builder.d.ts.map +1 -1
- package/dest/public/hints_builder.js +5 -5
- package/dest/public/index.d.ts +3 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +3 -3
- package/dest/public/public_db_sources.d.ts +17 -24
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +58 -65
- package/dest/public/public_kernel.d.ts +3 -9
- package/dest/public/public_kernel.d.ts.map +1 -1
- package/dest/public/public_kernel.js +13 -40
- package/dest/public/public_kernel_circuit_simulator.d.ts +5 -11
- package/dest/public/public_kernel_circuit_simulator.d.ts.map +1 -1
- package/dest/public/public_kernel_tail_simulator.d.ts +19 -0
- package/dest/public/public_kernel_tail_simulator.d.ts.map +1 -0
- package/dest/public/public_kernel_tail_simulator.js +45 -0
- package/dest/public/public_processor.d.ts +9 -5
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +34 -48
- package/dest/public/public_processor_metrics.d.ts +3 -3
- package/dest/public/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor_metrics.js +1 -1
- package/dest/public/side_effect_errors.d.ts +4 -0
- package/dest/public/side_effect_errors.d.ts.map +1 -0
- package/dest/public/side_effect_errors.js +7 -0
- package/dest/public/side_effect_trace.d.ts +2 -2
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +56 -35
- package/dest/public/side_effect_trace_interface.d.ts +1 -1
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/package.json +12 -9
- package/src/acvm/oracle/oracle.ts +7 -85
- package/src/acvm/oracle/typed_oracle.ts +2 -31
- package/src/avm/avm_execution_environment.ts +2 -24
- package/src/avm/avm_gas.ts +30 -115
- package/src/avm/avm_machine_state.ts +5 -5
- package/src/avm/avm_memory_types.ts +41 -14
- package/src/avm/avm_simulator.ts +4 -5
- package/src/avm/bytecode_utils.ts +2 -17
- package/src/avm/errors.ts +11 -3
- package/src/avm/fixtures/index.ts +13 -46
- package/src/avm/journal/index.ts +0 -1
- package/src/avm/journal/journal.ts +22 -22
- package/src/avm/opcodes/accrued_substate.ts +36 -44
- package/src/avm/opcodes/addressing_mode.ts +27 -24
- package/src/avm/opcodes/arithmetic.ts +5 -7
- package/src/avm/opcodes/bitwise.ts +23 -20
- package/src/avm/opcodes/commitment.ts +6 -7
- package/src/avm/opcodes/comparators.ts +7 -9
- package/src/avm/opcodes/contract.ts +5 -7
- package/src/avm/opcodes/control_flow.ts +5 -5
- package/src/avm/opcodes/conversion.ts +19 -12
- package/src/avm/opcodes/ec_add.ts +14 -16
- package/src/avm/opcodes/environment_getters.ts +73 -99
- package/src/avm/opcodes/external_calls.ts +27 -20
- package/src/avm/opcodes/hashing.ts +52 -52
- package/src/avm/opcodes/index.ts +3 -0
- package/src/avm/opcodes/instruction.ts +3 -10
- package/src/avm/opcodes/instruction_impl.ts +0 -62
- package/src/avm/opcodes/memory.ts +37 -67
- package/src/avm/opcodes/misc.ts +5 -7
- package/src/avm/opcodes/multi_scalar_mul.ts +16 -19
- package/src/avm/opcodes/storage.ts +10 -8
- package/src/avm/serialization/bytecode_serialization.ts +11 -35
- package/src/avm/serialization/instruction_serialization.ts +3 -19
- package/src/avm/test_utils.ts +20 -16
- package/src/client/client_execution_context.ts +40 -96
- package/src/client/index.ts +0 -1
- package/src/client/private_execution.ts +9 -9
- package/src/client/simulator.ts +2 -3
- package/src/client/test_utils.ts +36 -9
- package/src/client/unconstrained_execution.ts +3 -8
- package/src/common/debug_fn_name.ts +22 -0
- package/src/common/index.ts +0 -1
- package/src/public/enqueued_call_simulator.ts +335 -0
- package/src/public/enqueued_calls_processor.ts +388 -0
- package/src/public/execution.ts +16 -12
- package/src/public/executor.ts +8 -22
- package/src/public/hints_builder.ts +21 -21
- package/src/public/index.ts +3 -2
- package/src/public/public_db_sources.ts +62 -67
- package/src/public/public_kernel.ts +15 -49
- package/src/public/public_kernel_circuit_simulator.ts +6 -10
- package/src/public/public_kernel_tail_simulator.ts +106 -0
- package/src/public/public_processor.ts +65 -86
- package/src/public/public_processor_metrics.ts +3 -3
- package/src/public/side_effect_errors.ts +6 -0
- package/src/public/side_effect_trace.ts +77 -39
- package/src/public/side_effect_trace_interface.ts +2 -2
- package/dest/avm/journal/host_storage.d.ts +0 -13
- package/dest/avm/journal/host_storage.d.ts.map +0 -1
- package/dest/avm/journal/host_storage.js +0 -13
- package/dest/avm/opcodes/context_getters.d.ts +0 -15
- package/dest/avm/opcodes/context_getters.d.ts.map +0 -1
- package/dest/avm/opcodes/context_getters.js +0 -19
- package/dest/client/execution_result.d.ts +0 -104
- package/dest/client/execution_result.d.ts.map +0 -1
- package/dest/client/execution_result.js +0 -136
- package/dest/common/return_values.d.ts +0 -11
- package/dest/common/return_values.d.ts.map +0 -1
- package/dest/common/return_values.js +0 -13
- package/dest/public/abstract_phase_manager.d.ts +0 -93
- package/dest/public/abstract_phase_manager.d.ts.map +0 -1
- package/dest/public/abstract_phase_manager.js +0 -285
- package/dest/public/app_logic_phase_manager.d.ts +0 -25
- package/dest/public/app_logic_phase_manager.d.ts.map +0 -1
- package/dest/public/app_logic_phase_manager.js +0 -52
- package/dest/public/phase_manager_factory.d.ts +0 -18
- package/dest/public/phase_manager_factory.d.ts.map +0 -1
- package/dest/public/phase_manager_factory.js +0 -56
- package/dest/public/setup_phase_manager.d.ts +0 -25
- package/dest/public/setup_phase_manager.d.ts.map +0 -1
- package/dest/public/setup_phase_manager.js +0 -39
- package/dest/public/tail_phase_manager.d.ts +0 -23
- package/dest/public/tail_phase_manager.d.ts.map +0 -1
- package/dest/public/tail_phase_manager.js +0 -50
- package/dest/public/teardown_phase_manager.d.ts +0 -27
- package/dest/public/teardown_phase_manager.d.ts.map +0 -1
- package/dest/public/teardown_phase_manager.js +0 -56
- package/src/avm/journal/host_storage.ts +0 -14
- package/src/avm/opcodes/context_getters.ts +0 -23
- package/src/client/execution_result.ts +0 -228
- package/src/common/return_values.ts +0 -18
- package/src/public/abstract_phase_manager.ts +0 -522
- package/src/public/app_logic_phase_manager.ts +0 -81
- package/src/public/phase_manager_factory.ts +0 -126
- package/src/public/setup_phase_manager.ts +0 -61
- package/src/public/tail_phase_manager.ts +0 -127
- package/src/public/teardown_phase_manager.ts +0 -86
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AVM_REQUEST,
|
|
3
|
+
type AvmProvingRequest,
|
|
4
|
+
MerkleTreeId,
|
|
5
|
+
NestedProcessReturnValues,
|
|
6
|
+
ProvingRequestType,
|
|
7
|
+
type PublicExecutionRequest,
|
|
8
|
+
PublicKernelPhase,
|
|
9
|
+
type PublicProvingRequest,
|
|
10
|
+
type SimulationError,
|
|
11
|
+
type Tx,
|
|
12
|
+
UnencryptedFunctionL2Logs,
|
|
13
|
+
} from '@aztec/circuit-types';
|
|
14
|
+
import {
|
|
15
|
+
AztecAddress,
|
|
16
|
+
ContractStorageRead,
|
|
17
|
+
ContractStorageUpdateRequest,
|
|
18
|
+
Fr,
|
|
19
|
+
FunctionData,
|
|
20
|
+
Gas,
|
|
21
|
+
type GlobalVariables,
|
|
22
|
+
type Header,
|
|
23
|
+
L2ToL1Message,
|
|
24
|
+
LogHash,
|
|
25
|
+
MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL,
|
|
26
|
+
MAX_L2_TO_L1_MSGS_PER_CALL,
|
|
27
|
+
MAX_NOTE_HASHES_PER_CALL,
|
|
28
|
+
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
|
|
29
|
+
MAX_NULLIFIERS_PER_CALL,
|
|
30
|
+
MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL,
|
|
31
|
+
MAX_NULLIFIER_READ_REQUESTS_PER_CALL,
|
|
32
|
+
MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
|
|
33
|
+
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
|
|
34
|
+
MAX_PUBLIC_DATA_READS_PER_CALL,
|
|
35
|
+
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
|
|
36
|
+
MAX_UNENCRYPTED_LOGS_PER_CALL,
|
|
37
|
+
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
38
|
+
NoteHash,
|
|
39
|
+
Nullifier,
|
|
40
|
+
PublicAccumulatedData,
|
|
41
|
+
PublicAccumulatedDataArrayLengths,
|
|
42
|
+
PublicCallData,
|
|
43
|
+
type PublicCallRequest,
|
|
44
|
+
PublicCallStackItem,
|
|
45
|
+
PublicCircuitPublicInputs,
|
|
46
|
+
PublicInnerCallRequest,
|
|
47
|
+
type PublicKernelCircuitPublicInputs,
|
|
48
|
+
PublicKernelInnerCircuitPrivateInputs,
|
|
49
|
+
PublicKernelInnerData,
|
|
50
|
+
PublicValidationRequestArrayLengths,
|
|
51
|
+
PublicValidationRequests,
|
|
52
|
+
ReadRequest,
|
|
53
|
+
RevertCode,
|
|
54
|
+
TreeLeafReadRequest,
|
|
55
|
+
VMCircuitPublicInputs,
|
|
56
|
+
makeEmptyProof,
|
|
57
|
+
makeEmptyRecursiveProof,
|
|
58
|
+
} from '@aztec/circuits.js';
|
|
59
|
+
import { computeVarArgsHash } from '@aztec/circuits.js/hash';
|
|
60
|
+
import { makeTuple } from '@aztec/foundation/array';
|
|
61
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
62
|
+
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
63
|
+
import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types';
|
|
64
|
+
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
65
|
+
|
|
66
|
+
import { type PublicExecutionResult, accumulatePublicReturnValues, collectExecutionResults } from './execution.js';
|
|
67
|
+
import { type PublicExecutor } from './executor.js';
|
|
68
|
+
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
69
|
+
|
|
70
|
+
function makeAvmProvingRequest(
|
|
71
|
+
inputs: PublicKernelInnerCircuitPrivateInputs,
|
|
72
|
+
result: PublicExecutionResult,
|
|
73
|
+
): AvmProvingRequest {
|
|
74
|
+
return {
|
|
75
|
+
type: AVM_REQUEST,
|
|
76
|
+
functionName: result.functionName,
|
|
77
|
+
calldata: result.calldata,
|
|
78
|
+
bytecode: result.bytecode!,
|
|
79
|
+
avmHints: result.avmCircuitHints,
|
|
80
|
+
kernelRequest: {
|
|
81
|
+
type: ProvingRequestType.PUBLIC_KERNEL_INNER,
|
|
82
|
+
inputs,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type EnqueuedCallResult = {
|
|
88
|
+
/** Inputs to be used for proving */
|
|
89
|
+
provingRequests: PublicProvingRequest[];
|
|
90
|
+
/** The public kernel output at the end of the enqueued call */
|
|
91
|
+
kernelOutput: VMCircuitPublicInputs;
|
|
92
|
+
/** Unencrypted logs generated during the execution of this enqueued call */
|
|
93
|
+
newUnencryptedLogs: UnencryptedFunctionL2Logs;
|
|
94
|
+
/** Return values of simulating complete callstack */
|
|
95
|
+
returnValues: NestedProcessReturnValues;
|
|
96
|
+
/** Gas used during the execution this enqueued call */
|
|
97
|
+
gasUsed: Gas;
|
|
98
|
+
/** Revert reason, if any */
|
|
99
|
+
revertReason?: SimulationError;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export class EnqueuedCallSimulator {
|
|
103
|
+
private log: DebugLogger;
|
|
104
|
+
constructor(
|
|
105
|
+
private db: MerkleTreeOperations,
|
|
106
|
+
private publicExecutor: PublicExecutor,
|
|
107
|
+
private publicKernelSimulator: PublicKernelCircuitSimulator,
|
|
108
|
+
private globalVariables: GlobalVariables,
|
|
109
|
+
private historicalHeader: Header,
|
|
110
|
+
) {
|
|
111
|
+
this.log = createDebugLogger(`aztec:sequencer`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async simulate(
|
|
115
|
+
callRequest: PublicCallRequest,
|
|
116
|
+
executionRequest: PublicExecutionRequest,
|
|
117
|
+
tx: Tx,
|
|
118
|
+
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
119
|
+
availableGas: Gas,
|
|
120
|
+
transactionFee: Fr,
|
|
121
|
+
phase: PublicKernelPhase,
|
|
122
|
+
): Promise<EnqueuedCallResult> {
|
|
123
|
+
const pendingNullifiers = this.getSiloedPendingNullifiers(previousPublicKernelOutput);
|
|
124
|
+
const startSideEffectCounter = previousPublicKernelOutput.endSideEffectCounter + 1;
|
|
125
|
+
const result = await this.publicExecutor.simulate(
|
|
126
|
+
executionRequest,
|
|
127
|
+
this.globalVariables,
|
|
128
|
+
availableGas,
|
|
129
|
+
tx.data.constants.txContext,
|
|
130
|
+
pendingNullifiers,
|
|
131
|
+
transactionFee,
|
|
132
|
+
startSideEffectCounter,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const callStack = makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, PublicInnerCallRequest.empty);
|
|
136
|
+
callStack[0].item.contractAddress = callRequest.contractAddress;
|
|
137
|
+
callStack[0].item.callContext = callRequest.callContext;
|
|
138
|
+
callStack[0].item.argsHash = callRequest.argsHash;
|
|
139
|
+
const prevAccumulatedData =
|
|
140
|
+
phase === PublicKernelPhase.SETUP
|
|
141
|
+
? previousPublicKernelOutput.endNonRevertibleData
|
|
142
|
+
: previousPublicKernelOutput.end;
|
|
143
|
+
const accumulatedData = PublicAccumulatedData.empty();
|
|
144
|
+
accumulatedData.publicCallStack[0] = callRequest;
|
|
145
|
+
const startVMCircuitOutput = new VMCircuitPublicInputs(
|
|
146
|
+
previousPublicKernelOutput.constants,
|
|
147
|
+
callRequest,
|
|
148
|
+
callStack,
|
|
149
|
+
PublicValidationRequestArrayLengths.new(previousPublicKernelOutput.validationRequests),
|
|
150
|
+
PublicValidationRequests.empty(),
|
|
151
|
+
PublicAccumulatedDataArrayLengths.new(prevAccumulatedData),
|
|
152
|
+
accumulatedData,
|
|
153
|
+
startSideEffectCounter,
|
|
154
|
+
startSideEffectCounter,
|
|
155
|
+
availableGas,
|
|
156
|
+
result.transactionFee,
|
|
157
|
+
result.reverted,
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
return await this.combineNestedExecutionResults(result, startVMCircuitOutput);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private async combineNestedExecutionResults(
|
|
164
|
+
topResult: PublicExecutionResult,
|
|
165
|
+
startVMCircuitOutput: VMCircuitPublicInputs,
|
|
166
|
+
): Promise<EnqueuedCallResult> {
|
|
167
|
+
const executionResults = collectExecutionResults(topResult);
|
|
168
|
+
|
|
169
|
+
const provingRequests: AvmProvingRequest[] = [];
|
|
170
|
+
let gasUsed = Gas.empty();
|
|
171
|
+
let revertReason;
|
|
172
|
+
let kernelOutput = startVMCircuitOutput;
|
|
173
|
+
|
|
174
|
+
for (const result of executionResults) {
|
|
175
|
+
// Accumulate gas used in this enqueued call.
|
|
176
|
+
gasUsed = gasUsed.add(Gas.from(result.startGasLeft).sub(Gas.from(result.endGasLeft)));
|
|
177
|
+
|
|
178
|
+
// Sanity check for a current upstream assumption.
|
|
179
|
+
// Consumers of the result seem to expect "reverted <=> revertReason !== undefined".
|
|
180
|
+
const functionSelector = result.executionRequest.callContext.functionSelector.toString();
|
|
181
|
+
if (result.reverted && !result.revertReason) {
|
|
182
|
+
throw new Error(
|
|
183
|
+
`Simulation of ${result.executionRequest.contractAddress.toString()}:${functionSelector}(${
|
|
184
|
+
result.functionName
|
|
185
|
+
}) reverted with no reason.`,
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Simulate the public kernel circuit.
|
|
190
|
+
this.log.debug(
|
|
191
|
+
`Running public kernel inner circuit for ${result.executionRequest.contractAddress.toString()}:${functionSelector}(${
|
|
192
|
+
result.functionName
|
|
193
|
+
})`,
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
const callData = await this.getPublicCallData(result);
|
|
197
|
+
const { inputs, output } = await this.runKernelCircuit(kernelOutput, callData);
|
|
198
|
+
kernelOutput = output;
|
|
199
|
+
|
|
200
|
+
// Capture the inputs for later proving in the AVM and kernel.
|
|
201
|
+
provingRequests.push(makeAvmProvingRequest(inputs, result));
|
|
202
|
+
|
|
203
|
+
// Safely return the revert reason and the kernel output (which has had its revertible side effects dropped)
|
|
204
|
+
// 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.
|
|
205
|
+
if (result.reverted) {
|
|
206
|
+
this.log.debug(
|
|
207
|
+
`Reverting on ${result.executionRequest.contractAddress.toString()}:${functionSelector}(${
|
|
208
|
+
result.functionName
|
|
209
|
+
}) with reason: ${result.revertReason}`,
|
|
210
|
+
);
|
|
211
|
+
// TODO(@spalladino): Check gasUsed is correct. The AVM should take care of setting gasLeft to zero upon a revert.
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
provingRequests,
|
|
215
|
+
kernelOutput,
|
|
216
|
+
newUnencryptedLogs: UnencryptedFunctionL2Logs.empty(),
|
|
217
|
+
returnValues: NestedProcessReturnValues.empty(),
|
|
218
|
+
gasUsed,
|
|
219
|
+
revertReason: result.revertReason,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return {
|
|
225
|
+
provingRequests,
|
|
226
|
+
kernelOutput,
|
|
227
|
+
newUnencryptedLogs: topResult.allUnencryptedLogs,
|
|
228
|
+
returnValues: accumulatePublicReturnValues(topResult),
|
|
229
|
+
gasUsed,
|
|
230
|
+
revertReason,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Returns all pending private and public nullifiers. */
|
|
235
|
+
private getSiloedPendingNullifiers(ko: PublicKernelCircuitPublicInputs) {
|
|
236
|
+
return [...ko.end.nullifiers, ...ko.endNonRevertibleData.nullifiers].filter(n => !n.isEmpty());
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
private async runKernelCircuit(
|
|
240
|
+
previousOutput: VMCircuitPublicInputs,
|
|
241
|
+
callData: PublicCallData,
|
|
242
|
+
): Promise<{ inputs: PublicKernelInnerCircuitPrivateInputs; output: VMCircuitPublicInputs }> {
|
|
243
|
+
// The proof is not used in simulation
|
|
244
|
+
const proof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH);
|
|
245
|
+
const vk = ProtocolCircuitVks.PublicKernelInnerArtifact;
|
|
246
|
+
const previousKernel = new PublicKernelInnerData(previousOutput, proof, vk);
|
|
247
|
+
const inputs = new PublicKernelInnerCircuitPrivateInputs(previousKernel, callData);
|
|
248
|
+
return { inputs, output: await this.publicKernelSimulator.publicKernelCircuitInner(inputs) };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Calculates the PublicCircuitOutput for this execution result along with its proof,
|
|
253
|
+
* and assembles a PublicCallData object from it.
|
|
254
|
+
* @param result - The execution result.
|
|
255
|
+
* @returns A corresponding PublicCallData object.
|
|
256
|
+
*/
|
|
257
|
+
private async getPublicCallData(result: PublicExecutionResult) {
|
|
258
|
+
const bytecodeHash = await this.getBytecodeHash(result);
|
|
259
|
+
const callStackItem = await this.getPublicCallStackItem(result);
|
|
260
|
+
return new PublicCallData(callStackItem, makeEmptyProof(), bytecodeHash);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
private async getPublicCallStackItem(result: PublicExecutionResult) {
|
|
264
|
+
const publicDataTreeInfo = await this.db.getTreeInfo(MerkleTreeId.PUBLIC_DATA_TREE);
|
|
265
|
+
this.historicalHeader.state.partial.publicDataTree.root = Fr.fromBuffer(publicDataTreeInfo.root);
|
|
266
|
+
|
|
267
|
+
const publicCircuitPublicInputs = PublicCircuitPublicInputs.from({
|
|
268
|
+
callContext: result.executionRequest.callContext,
|
|
269
|
+
proverAddress: AztecAddress.ZERO,
|
|
270
|
+
argsHash: computeVarArgsHash(result.executionRequest.args),
|
|
271
|
+
noteHashes: padArrayEnd(result.noteHashes, NoteHash.empty(), MAX_NOTE_HASHES_PER_CALL),
|
|
272
|
+
nullifiers: padArrayEnd(result.nullifiers, Nullifier.empty(), MAX_NULLIFIERS_PER_CALL),
|
|
273
|
+
l2ToL1Msgs: padArrayEnd(result.l2ToL1Messages, L2ToL1Message.empty(), MAX_L2_TO_L1_MSGS_PER_CALL),
|
|
274
|
+
startSideEffectCounter: result.startSideEffectCounter,
|
|
275
|
+
endSideEffectCounter: result.endSideEffectCounter,
|
|
276
|
+
returnsHash: computeVarArgsHash(result.returnValues),
|
|
277
|
+
noteHashReadRequests: padArrayEnd(
|
|
278
|
+
result.noteHashReadRequests,
|
|
279
|
+
TreeLeafReadRequest.empty(),
|
|
280
|
+
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
|
|
281
|
+
),
|
|
282
|
+
nullifierReadRequests: padArrayEnd(
|
|
283
|
+
result.nullifierReadRequests,
|
|
284
|
+
ReadRequest.empty(),
|
|
285
|
+
MAX_NULLIFIER_READ_REQUESTS_PER_CALL,
|
|
286
|
+
),
|
|
287
|
+
nullifierNonExistentReadRequests: padArrayEnd(
|
|
288
|
+
result.nullifierNonExistentReadRequests,
|
|
289
|
+
ReadRequest.empty(),
|
|
290
|
+
MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL,
|
|
291
|
+
),
|
|
292
|
+
l1ToL2MsgReadRequests: padArrayEnd(
|
|
293
|
+
result.l1ToL2MsgReadRequests,
|
|
294
|
+
TreeLeafReadRequest.empty(),
|
|
295
|
+
MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL,
|
|
296
|
+
),
|
|
297
|
+
contractStorageReads: padArrayEnd(
|
|
298
|
+
result.contractStorageReads,
|
|
299
|
+
ContractStorageRead.empty(),
|
|
300
|
+
MAX_PUBLIC_DATA_READS_PER_CALL,
|
|
301
|
+
),
|
|
302
|
+
contractStorageUpdateRequests: padArrayEnd(
|
|
303
|
+
result.contractStorageUpdateRequests,
|
|
304
|
+
ContractStorageUpdateRequest.empty(),
|
|
305
|
+
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
|
|
306
|
+
),
|
|
307
|
+
publicCallRequests: padArrayEnd(
|
|
308
|
+
result.publicCallRequests,
|
|
309
|
+
PublicInnerCallRequest.empty(),
|
|
310
|
+
MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
|
|
311
|
+
),
|
|
312
|
+
unencryptedLogsHashes: padArrayEnd(result.unencryptedLogsHashes, LogHash.empty(), MAX_UNENCRYPTED_LOGS_PER_CALL),
|
|
313
|
+
historicalHeader: this.historicalHeader,
|
|
314
|
+
globalVariables: this.globalVariables,
|
|
315
|
+
startGasLeft: Gas.from(result.startGasLeft),
|
|
316
|
+
endGasLeft: Gas.from(result.endGasLeft),
|
|
317
|
+
transactionFee: result.transactionFee,
|
|
318
|
+
// TODO(@just-mitch): need better mapping from simulator to revert code.
|
|
319
|
+
revertCode: result.reverted ? RevertCode.APP_LOGIC_REVERTED : RevertCode.OK,
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
return new PublicCallStackItem(
|
|
323
|
+
result.executionRequest.contractAddress,
|
|
324
|
+
new FunctionData(result.executionRequest.callContext.functionSelector, false),
|
|
325
|
+
publicCircuitPublicInputs,
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
private getBytecodeHash(_result: PublicExecutionResult) {
|
|
330
|
+
// TODO: Determine how to calculate bytecode hash. Circuits just check it isn't zero for now.
|
|
331
|
+
// See https://github.com/AztecProtocol/aztec3-packages/issues/378
|
|
332
|
+
const bytecodeHash = new Fr(1n);
|
|
333
|
+
return Promise.resolve(bytecodeHash);
|
|
334
|
+
}
|
|
335
|
+
}
|