@aztec/simulator 0.62.0 → 0.63.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/acvm/acvm.d.ts +2 -16
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/acvm.js +2 -70
- package/dest/acvm/oracle/oracle.d.ts +4 -4
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +10 -11
- package/dest/acvm/oracle/typed_oracle.d.ts +5 -5
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +8 -8
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +2 -1
- package/dest/avm/avm_machine_state.d.ts +27 -8
- package/dest/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/avm/avm_machine_state.js +6 -10
- package/dest/avm/avm_memory_types.d.ts +8 -0
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +5 -1
- package/dest/avm/avm_simulator.d.ts +2 -19
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +12 -14
- package/dest/avm/avm_tree.d.ts +249 -0
- package/dest/avm/avm_tree.d.ts.map +1 -0
- package/dest/avm/avm_tree.js +637 -0
- package/dest/avm/errors.d.ts +4 -17
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/errors.js +21 -50
- package/dest/avm/fixtures/index.d.ts +7 -2
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +12 -12
- package/dest/avm/index.d.ts +1 -0
- package/dest/avm/index.d.ts.map +1 -1
- package/dest/avm/index.js +2 -1
- package/dest/avm/journal/journal.d.ts +43 -24
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +172 -39
- package/dest/avm/journal/nullifiers.d.ts +5 -4
- package/dest/avm/journal/nullifiers.d.ts.map +1 -1
- package/dest/avm/journal/nullifiers.js +2 -3
- package/dest/avm/journal/public_storage.d.ts +6 -5
- package/dest/avm/journal/public_storage.d.ts.map +1 -1
- package/dest/avm/journal/public_storage.js +1 -1
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +4 -10
- package/dest/avm/opcodes/arithmetic.d.ts +4 -1
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +18 -4
- package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/avm/opcodes/bitwise.js +1 -3
- package/dest/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/avm/opcodes/comparators.js +1 -2
- package/dest/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/avm/opcodes/contract.js +2 -3
- package/dest/avm/opcodes/control_flow.d.ts +4 -0
- package/dest/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/avm/opcodes/control_flow.js +21 -6
- package/dest/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/avm/opcodes/conversion.js +1 -2
- package/dest/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/avm/opcodes/ec_add.js +5 -11
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +1 -2
- package/dest/avm/opcodes/external_calls.d.ts +4 -2
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +38 -22
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +1 -4
- package/dest/avm/opcodes/instruction.d.ts +4 -0
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +7 -1
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +1 -7
- package/dest/avm/opcodes/misc.js +3 -3
- package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
- package/dest/avm/opcodes/multi_scalar_mul.js +6 -5
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +2 -4
- package/dest/avm/serialization/bytecode_serialization.d.ts +1 -6
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +24 -20
- package/dest/client/client_execution_context.d.ts +7 -11
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +18 -20
- package/dest/client/db_oracle.d.ts +17 -10
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/db_oracle.js +1 -1
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +5 -4
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +3 -2
- package/dest/client/view_data_oracle.d.ts +6 -12
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +10 -12
- package/dest/common/errors.d.ts +15 -2
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/common/errors.js +85 -4
- package/dest/mocks/fixtures.d.ts +9 -28
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +12 -57
- package/dest/public/dual_side_effect_trace.d.ts +34 -26
- package/dest/public/dual_side_effect_trace.d.ts.map +1 -1
- package/dest/public/dual_side_effect_trace.js +48 -36
- package/dest/public/enqueued_call_side_effect_trace.d.ts +96 -33
- package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -1
- package/dest/public/enqueued_call_side_effect_trace.js +212 -138
- package/dest/public/execution.d.ts +50 -17
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -29
- package/dest/public/executor.d.ts +28 -11
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +33 -33
- package/dest/public/index.d.ts +4 -5
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +4 -5
- package/dest/public/public_db_sources.d.ts +1 -0
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +12 -5
- package/dest/public/public_processor.d.ts +7 -11
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +60 -42
- 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/public_tx_context.d.ts +130 -0
- package/dest/public/public_tx_context.d.ts.map +1 -0
- package/dest/public/public_tx_context.js +293 -0
- package/dest/public/public_tx_simulator.d.ts +36 -0
- package/dest/public/public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator.js +148 -0
- package/dest/public/side_effect_trace.d.ts +30 -15
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +70 -16
- package/dest/public/side_effect_trace_interface.d.ts +43 -12
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/transitional_adapters.d.ts +9 -0
- package/dest/public/transitional_adapters.d.ts.map +1 -0
- package/dest/public/transitional_adapters.js +127 -0
- package/dest/public/utils.d.ts +5 -0
- package/dest/public/utils.d.ts.map +1 -0
- package/dest/public/utils.js +30 -0
- package/package.json +12 -9
- package/src/acvm/acvm.ts +3 -94
- package/src/acvm/oracle/oracle.ts +9 -14
- package/src/acvm/oracle/typed_oracle.ts +8 -8
- package/src/avm/avm_gas.ts +1 -0
- package/src/avm/avm_machine_state.ts +28 -12
- package/src/avm/avm_memory_types.ts +5 -0
- package/src/avm/avm_simulator.ts +13 -16
- package/src/avm/avm_tree.ts +785 -0
- package/src/avm/errors.ts +25 -48
- package/src/avm/fixtures/index.ts +16 -12
- package/src/avm/index.ts +1 -0
- package/src/avm/journal/journal.ts +291 -52
- package/src/avm/journal/nullifiers.ts +7 -7
- package/src/avm/journal/public_storage.ts +5 -5
- package/src/avm/opcodes/accrued_substate.ts +3 -9
- package/src/avm/opcodes/arithmetic.ts +26 -4
- package/src/avm/opcodes/bitwise.ts +0 -2
- package/src/avm/opcodes/comparators.ts +0 -1
- package/src/avm/opcodes/contract.ts +1 -2
- package/src/avm/opcodes/control_flow.ts +24 -5
- package/src/avm/opcodes/conversion.ts +0 -1
- package/src/avm/opcodes/ec_add.ts +6 -9
- package/src/avm/opcodes/environment_getters.ts +0 -1
- package/src/avm/opcodes/external_calls.ts +39 -21
- package/src/avm/opcodes/hashing.ts +0 -3
- package/src/avm/opcodes/instruction.ts +7 -0
- package/src/avm/opcodes/memory.ts +0 -6
- package/src/avm/opcodes/misc.ts +2 -2
- package/src/avm/opcodes/multi_scalar_mul.ts +5 -4
- package/src/avm/opcodes/storage.ts +1 -3
- package/src/avm/serialization/bytecode_serialization.ts +31 -22
- package/src/client/client_execution_context.ts +22 -23
- package/src/client/db_oracle.ts +22 -11
- package/src/client/private_execution.ts +5 -4
- package/src/client/unconstrained_execution.ts +2 -1
- package/src/client/view_data_oracle.ts +14 -13
- package/src/common/errors.ts +119 -3
- package/src/mocks/fixtures.ts +15 -106
- package/src/public/dual_side_effect_trace.ts +138 -50
- package/src/public/enqueued_call_side_effect_trace.ts +352 -212
- package/src/public/execution.ts +58 -42
- package/src/public/executor.ts +52 -67
- package/src/public/index.ts +7 -5
- package/src/public/public_db_sources.ts +12 -4
- package/src/public/public_processor.ts +111 -73
- package/src/public/public_processor_metrics.ts +3 -3
- package/src/public/public_tx_context.ts +411 -0
- package/src/public/public_tx_simulator.ts +232 -0
- package/src/public/side_effect_trace.ts +154 -28
- package/src/public/side_effect_trace_interface.ts +92 -14
- package/src/public/transitional_adapters.ts +347 -0
- package/src/public/utils.ts +32 -0
- package/dest/public/enqueued_call_simulator.d.ts +0 -43
- package/dest/public/enqueued_call_simulator.d.ts.map +0 -1
- package/dest/public/enqueued_call_simulator.js +0 -156
- package/dest/public/enqueued_calls_processor.d.ts +0 -43
- package/dest/public/enqueued_calls_processor.d.ts.map +0 -1
- package/dest/public/enqueued_calls_processor.js +0 -209
- package/dest/public/hints_builder.d.ts +0 -29
- package/dest/public/hints_builder.d.ts.map +0 -1
- package/dest/public/hints_builder.js +0 -75
- package/dest/public/public_kernel.d.ts +0 -30
- package/dest/public/public_kernel.d.ts.map +0 -1
- package/dest/public/public_kernel.js +0 -67
- package/dest/public/public_kernel_circuit_simulator.d.ts +0 -25
- package/dest/public/public_kernel_circuit_simulator.d.ts.map +0 -1
- package/dest/public/public_kernel_circuit_simulator.js +0 -2
- package/dest/public/public_kernel_tail_simulator.d.ts +0 -15
- package/dest/public/public_kernel_tail_simulator.d.ts.map +0 -1
- package/dest/public/public_kernel_tail_simulator.js +0 -39
- package/src/public/enqueued_call_simulator.ts +0 -360
- package/src/public/enqueued_calls_processor.ts +0 -372
- package/src/public/hints_builder.ts +0 -168
- package/src/public/public_kernel.ts +0 -100
- package/src/public/public_kernel_circuit_simulator.ts +0 -32
- package/src/public/public_kernel_tail_simulator.ts +0 -97
package/src/public/execution.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
NestedProcessReturnValues,
|
|
3
2
|
type PublicExecutionRequest,
|
|
4
3
|
type SimulationError,
|
|
5
4
|
type UnencryptedFunctionL2Logs,
|
|
@@ -15,17 +14,73 @@ import {
|
|
|
15
14
|
type NoteHash,
|
|
16
15
|
type Nullifier,
|
|
17
16
|
PublicCallStackItemCompressed,
|
|
17
|
+
type PublicDataUpdateRequest,
|
|
18
18
|
PublicInnerCallRequest,
|
|
19
19
|
type ReadRequest,
|
|
20
20
|
RevertCode,
|
|
21
|
+
type ScopedL2ToL1Message,
|
|
22
|
+
type ScopedLogHash,
|
|
23
|
+
type ScopedNoteHash,
|
|
21
24
|
type TreeLeafReadRequest,
|
|
22
25
|
} from '@aztec/circuits.js';
|
|
23
26
|
import { computeVarArgsHash } from '@aztec/circuits.js/hash';
|
|
24
27
|
|
|
28
|
+
export interface PublicSideEffects {
|
|
29
|
+
/** The contract storage update requests performed. */
|
|
30
|
+
publicDataWrites: PublicDataUpdateRequest[];
|
|
31
|
+
/** The new note hashes to be inserted into the note hashes tree. */
|
|
32
|
+
noteHashes: ScopedNoteHash[];
|
|
33
|
+
/** The new nullifiers to be inserted into the nullifier tree. */
|
|
34
|
+
nullifiers: Nullifier[];
|
|
35
|
+
/** The new l2 to l1 messages generated to be inserted into the messages tree. */
|
|
36
|
+
l2ToL1Messages: ScopedL2ToL1Message[];
|
|
37
|
+
/**
|
|
38
|
+
* The hashed logs with side effect counter.
|
|
39
|
+
* Note: required as we don't track the counter anywhere else.
|
|
40
|
+
*/
|
|
41
|
+
unencryptedLogsHashes: ScopedLogHash[];
|
|
42
|
+
/**
|
|
43
|
+
* Unencrypted logs emitted during execution.
|
|
44
|
+
* Note: These are preimages to `unencryptedLogsHashes`.
|
|
45
|
+
*/
|
|
46
|
+
unencryptedLogs: UnencryptedFunctionL2Logs;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface EnqueuedPublicCallExecutionResult {
|
|
50
|
+
/** How much gas was left after this public execution. */
|
|
51
|
+
endGasLeft: Gas;
|
|
52
|
+
/** The side effect counter after execution */
|
|
53
|
+
endSideEffectCounter: Fr;
|
|
54
|
+
|
|
55
|
+
/** The return values of the function. */
|
|
56
|
+
returnValues: Fr[];
|
|
57
|
+
/** Whether the execution reverted. */
|
|
58
|
+
reverted: boolean;
|
|
59
|
+
/** The revert reason if the execution reverted. */
|
|
60
|
+
revertReason?: SimulationError;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface EnqueuedPublicCallExecutionResultWithSideEffects {
|
|
64
|
+
/** How much gas was left after this public execution. */
|
|
65
|
+
endGasLeft: Gas;
|
|
66
|
+
/** The side effect counter after execution */
|
|
67
|
+
endSideEffectCounter: Fr;
|
|
68
|
+
|
|
69
|
+
/** The return values of the function. */
|
|
70
|
+
returnValues: Fr[];
|
|
71
|
+
/** Whether the execution reverted. */
|
|
72
|
+
reverted: boolean;
|
|
73
|
+
/** The revert reason if the execution reverted. */
|
|
74
|
+
revertReason?: SimulationError;
|
|
75
|
+
|
|
76
|
+
/** The public side effects of the function. */
|
|
77
|
+
sideEffects: PublicSideEffects;
|
|
78
|
+
}
|
|
79
|
+
|
|
25
80
|
/**
|
|
26
81
|
* The public function execution result.
|
|
27
82
|
*/
|
|
28
|
-
export interface
|
|
83
|
+
export interface PublicFunctionCallResult {
|
|
29
84
|
/** The execution request that triggered this result. */
|
|
30
85
|
executionRequest: PublicExecutionRequest;
|
|
31
86
|
|
|
@@ -97,46 +152,7 @@ export interface PublicExecutionResult {
|
|
|
97
152
|
functionName: string;
|
|
98
153
|
}
|
|
99
154
|
|
|
100
|
-
|
|
101
|
-
* Recursively accummulate the return values of a call result and its nested executions,
|
|
102
|
-
* so they can be retrieved in order.
|
|
103
|
-
* @param executionResult
|
|
104
|
-
* @returns
|
|
105
|
-
*/
|
|
106
|
-
export function accumulatePublicReturnValues(executionResult: PublicExecutionResult): NestedProcessReturnValues {
|
|
107
|
-
const acc = new NestedProcessReturnValues(executionResult.returnValues);
|
|
108
|
-
acc.nested = executionResult.nestedExecutions.map(nestedExecution => accumulatePublicReturnValues(nestedExecution));
|
|
109
|
-
return acc;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export function collectExecutionResults(result: PublicExecutionResult): PublicExecutionResult[] {
|
|
113
|
-
return [result, ...result.nestedExecutions.map(collectExecutionResults)].flat();
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Checks whether the child execution result is valid for a static call (no state modifications).
|
|
118
|
-
* @param executionResult - The execution result of a public function
|
|
119
|
-
*/
|
|
120
|
-
|
|
121
|
-
export function checkValidStaticCall(
|
|
122
|
-
noteHashes: NoteHash[],
|
|
123
|
-
nullifiers: Nullifier[],
|
|
124
|
-
contractStorageUpdateRequests: ContractStorageUpdateRequest[],
|
|
125
|
-
l2ToL1Messages: L2ToL1Message[],
|
|
126
|
-
unencryptedLogs: UnencryptedFunctionL2Logs,
|
|
127
|
-
) {
|
|
128
|
-
if (
|
|
129
|
-
contractStorageUpdateRequests.length > 0 ||
|
|
130
|
-
noteHashes.length > 0 ||
|
|
131
|
-
nullifiers.length > 0 ||
|
|
132
|
-
l2ToL1Messages.length > 0 ||
|
|
133
|
-
unencryptedLogs.logs.length > 0
|
|
134
|
-
) {
|
|
135
|
-
throw new Error('Static call cannot update the state, emit L2->L1 messages or generate logs');
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export function resultToPublicCallRequest(result: PublicExecutionResult) {
|
|
155
|
+
export function resultToPublicCallRequest(result: PublicFunctionCallResult) {
|
|
140
156
|
const request = result.executionRequest;
|
|
141
157
|
const item = new PublicCallStackItemCompressed(
|
|
142
158
|
request.callContext.contractAddress,
|
package/src/public/executor.ts
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import { type PublicExecutionRequest } from '@aztec/circuit-types';
|
|
2
2
|
import { type AvmSimulationStats } from '@aztec/circuit-types/stats';
|
|
3
|
-
import {
|
|
4
|
-
type CombinedConstantData,
|
|
5
|
-
Fr,
|
|
6
|
-
Gas,
|
|
7
|
-
type GlobalVariables,
|
|
8
|
-
type Nullifier,
|
|
9
|
-
PublicAccumulatedDataArrayLengths,
|
|
10
|
-
PublicValidationRequestArrayLengths,
|
|
11
|
-
type TxContext,
|
|
12
|
-
} from '@aztec/circuits.js';
|
|
3
|
+
import { Fr, Gas, type GlobalVariables } from '@aztec/circuits.js';
|
|
13
4
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
14
5
|
import { Timer } from '@aztec/foundation/timer';
|
|
15
6
|
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
@@ -22,7 +13,10 @@ import { AvmPersistableStateManager } from '../avm/journal/index.js';
|
|
|
22
13
|
import { getPublicFunctionDebugName } from '../common/debug_fn_name.js';
|
|
23
14
|
import { DualSideEffectTrace } from './dual_side_effect_trace.js';
|
|
24
15
|
import { PublicEnqueuedCallSideEffectTrace } from './enqueued_call_side_effect_trace.js';
|
|
25
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
type EnqueuedPublicCallExecutionResult,
|
|
18
|
+
type EnqueuedPublicCallExecutionResultWithSideEffects,
|
|
19
|
+
} from './execution.js';
|
|
26
20
|
import { ExecutorMetrics } from './executor_metrics.js';
|
|
27
21
|
import { type WorldStateDB } from './public_db_sources.js';
|
|
28
22
|
import { PublicSideEffectTrace } from './side_effect_trace.js';
|
|
@@ -40,29 +34,20 @@ export class PublicExecutor {
|
|
|
40
34
|
static readonly log = createDebugLogger('aztec:simulator:public_executor');
|
|
41
35
|
|
|
42
36
|
/**
|
|
43
|
-
*
|
|
37
|
+
* Simulate a public execution request.
|
|
44
38
|
* @param executionRequest - The execution to run.
|
|
45
|
-
* @param
|
|
39
|
+
* @param globalVariables - The global variables to use.
|
|
46
40
|
* @param allocatedGas - The gas available at the start of this enqueued call.
|
|
47
|
-
* @param txContext - Transaction context.
|
|
48
|
-
* @param pendingSiloedNullifiers - The pending nullifier set from earlier parts of this TX.
|
|
49
41
|
* @param transactionFee - Fee offered for this TX.
|
|
50
|
-
* @
|
|
51
|
-
* @param previousValidationRequestArrayLengths - Side effect array lengths from previous kernel
|
|
52
|
-
* @param previousAccumulatedDataArrayLengths - Side effect array lengths from previous kernel
|
|
53
|
-
* @returns The result of execution, including the results of all nested calls.
|
|
42
|
+
* @returns The result of execution.
|
|
54
43
|
*/
|
|
55
44
|
public async simulate(
|
|
45
|
+
stateManager: AvmPersistableStateManager,
|
|
56
46
|
executionRequest: PublicExecutionRequest,
|
|
57
|
-
|
|
47
|
+
globalVariables: GlobalVariables,
|
|
58
48
|
allocatedGas: Gas,
|
|
59
|
-
_txContext: TxContext,
|
|
60
|
-
pendingSiloedNullifiers: Nullifier[],
|
|
61
49
|
transactionFee: Fr = Fr.ZERO,
|
|
62
|
-
|
|
63
|
-
previousValidationRequestArrayLengths: PublicValidationRequestArrayLengths = PublicValidationRequestArrayLengths.empty(),
|
|
64
|
-
previousAccumulatedDataArrayLengths: PublicAccumulatedDataArrayLengths = PublicAccumulatedDataArrayLengths.empty(),
|
|
65
|
-
): Promise<PublicExecutionResult> {
|
|
50
|
+
): Promise<EnqueuedPublicCallExecutionResult> {
|
|
66
51
|
const address = executionRequest.callContext.contractAddress;
|
|
67
52
|
const selector = executionRequest.callContext.functionSelector;
|
|
68
53
|
const fnName = await getPublicFunctionDebugName(this.worldStateDB, address, selector, executionRequest.args);
|
|
@@ -72,36 +57,17 @@ export class PublicExecutor {
|
|
|
72
57
|
);
|
|
73
58
|
const timer = new Timer();
|
|
74
59
|
|
|
75
|
-
const
|
|
76
|
-
const enqueuedCallTrace = new PublicEnqueuedCallSideEffectTrace(
|
|
77
|
-
startSideEffectCounter,
|
|
78
|
-
previousValidationRequestArrayLengths,
|
|
79
|
-
previousAccumulatedDataArrayLengths,
|
|
80
|
-
);
|
|
81
|
-
const trace = new DualSideEffectTrace(innerCallTrace, enqueuedCallTrace);
|
|
82
|
-
const avmPersistableState = AvmPersistableStateManager.newWithPendingSiloedNullifiers(
|
|
83
|
-
this.worldStateDB,
|
|
84
|
-
trace,
|
|
85
|
-
pendingSiloedNullifiers.map(n => n.value),
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
const avmExecutionEnv = createAvmExecutionEnvironment(executionRequest, constants.globalVariables, transactionFee);
|
|
60
|
+
const avmExecutionEnv = createAvmExecutionEnvironment(executionRequest, globalVariables, transactionFee);
|
|
89
61
|
|
|
90
62
|
const avmMachineState = new AvmMachineState(allocatedGas);
|
|
91
|
-
const avmContext = new AvmContext(
|
|
63
|
+
const avmContext = new AvmContext(stateManager, avmExecutionEnv, avmMachineState);
|
|
92
64
|
const simulator = new AvmSimulator(avmContext);
|
|
93
|
-
const
|
|
65
|
+
const avmCallResult = await simulator.execute();
|
|
94
66
|
const bytecode = simulator.getBytecode()!;
|
|
95
67
|
|
|
96
|
-
// Commit the public storage state to the DBs since this is a top-level execution.
|
|
97
|
-
// Observe that this will write all the state changes to the DBs, not only the latest for each slot.
|
|
98
|
-
// However, the underlying DB keep a cache and will only write the latest state to disk.
|
|
99
|
-
// TODO(dbanks12): this should be unnecessary here or should be exposed by state manager
|
|
100
|
-
await avmContext.persistableState.publicStorage.commitToDB();
|
|
101
|
-
|
|
102
68
|
PublicExecutor.log.verbose(
|
|
103
|
-
`[AVM] ${fnName} returned, reverted: ${
|
|
104
|
-
|
|
69
|
+
`[AVM] ${fnName} returned, reverted: ${avmCallResult.reverted}${
|
|
70
|
+
avmCallResult.reverted ? ', reason: ' + avmCallResult.revertReason : ''
|
|
105
71
|
}.`,
|
|
106
72
|
{
|
|
107
73
|
eventName: 'avm-simulation',
|
|
@@ -111,37 +77,56 @@ export class PublicExecutor {
|
|
|
111
77
|
} satisfies AvmSimulationStats,
|
|
112
78
|
);
|
|
113
79
|
|
|
114
|
-
const publicExecutionResult = trace.
|
|
115
|
-
avmExecutionEnv,
|
|
116
|
-
/*startGasLeft=*/ allocatedGas,
|
|
80
|
+
const publicExecutionResult = stateManager.trace.toPublicEnqueuedCallExecutionResult(
|
|
117
81
|
/*endGasLeft=*/ Gas.from(avmContext.machineState.gasLeft),
|
|
118
|
-
|
|
119
|
-
avmResult,
|
|
120
|
-
fnName,
|
|
82
|
+
avmCallResult,
|
|
121
83
|
);
|
|
122
84
|
|
|
123
|
-
if (
|
|
85
|
+
if (avmCallResult.reverted) {
|
|
124
86
|
this.metrics.recordFunctionSimulationFailure();
|
|
125
87
|
} else {
|
|
126
88
|
this.metrics.recordFunctionSimulation(bytecode.length, timer.ms());
|
|
127
89
|
}
|
|
128
90
|
|
|
129
|
-
const _vmCircuitPublicInputs = enqueuedCallTrace.toVMCircuitPublicInputs(
|
|
130
|
-
constants,
|
|
131
|
-
avmExecutionEnv,
|
|
132
|
-
/*startGasLeft=*/ allocatedGas,
|
|
133
|
-
/*endGasLeft=*/ Gas.from(avmContext.machineState.gasLeft),
|
|
134
|
-
avmResult,
|
|
135
|
-
);
|
|
136
|
-
|
|
137
91
|
PublicExecutor.log.verbose(
|
|
138
|
-
`[AVM] ${fnName} simulation complete. Reverted=${
|
|
92
|
+
`[AVM] ${fnName} simulation complete. Reverted=${avmCallResult.reverted}. Consumed ${
|
|
139
93
|
allocatedGas.l2Gas - avmContext.machineState.gasLeft.l2Gas
|
|
140
94
|
} L2 gas, ending with ${avmContext.machineState.gasLeft.l2Gas} L2 gas left.`,
|
|
141
95
|
);
|
|
142
96
|
|
|
143
97
|
return publicExecutionResult;
|
|
144
98
|
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Simulate an enqueued call on its own, and include its side effects in its results.
|
|
102
|
+
* @param executionRequest - The execution to run.
|
|
103
|
+
* @param globalVariables - The global variables to use.
|
|
104
|
+
* @param allocatedGas - The gas available at the start of this enqueued call.
|
|
105
|
+
* @param transactionFee - Fee offered for this TX.
|
|
106
|
+
* @param startSideEffectCounter - The start counter to initialize the side effect trace with.
|
|
107
|
+
* @returns The result of execution including side effect vectors.
|
|
108
|
+
* FIXME: this function is only used by the TXE. Ideally we would not support this as an external interface.
|
|
109
|
+
* Avoid using this interface as it it shouldn't really exist in the first place.
|
|
110
|
+
*/
|
|
111
|
+
public async simulateIsolatedEnqueuedCall(
|
|
112
|
+
executionRequest: PublicExecutionRequest,
|
|
113
|
+
globalVariables: GlobalVariables,
|
|
114
|
+
allocatedGas: Gas,
|
|
115
|
+
transactionFee: Fr = Fr.ONE,
|
|
116
|
+
startSideEffectCounter: number = 0,
|
|
117
|
+
): Promise<EnqueuedPublicCallExecutionResultWithSideEffects> {
|
|
118
|
+
const innerCallTrace = new PublicSideEffectTrace(startSideEffectCounter);
|
|
119
|
+
const enqueuedCallTrace = new PublicEnqueuedCallSideEffectTrace(startSideEffectCounter);
|
|
120
|
+
const trace = new DualSideEffectTrace(innerCallTrace, enqueuedCallTrace);
|
|
121
|
+
const stateManager = new AvmPersistableStateManager(this.worldStateDB, trace);
|
|
122
|
+
return (await this.simulate(
|
|
123
|
+
stateManager,
|
|
124
|
+
executionRequest,
|
|
125
|
+
globalVariables,
|
|
126
|
+
allocatedGas,
|
|
127
|
+
transactionFee,
|
|
128
|
+
)) as EnqueuedPublicCallExecutionResultWithSideEffects;
|
|
129
|
+
}
|
|
145
130
|
}
|
|
146
131
|
|
|
147
132
|
/**
|
|
@@ -151,7 +136,7 @@ export class PublicExecutor {
|
|
|
151
136
|
* @param globalVariables
|
|
152
137
|
* @returns
|
|
153
138
|
*/
|
|
154
|
-
function createAvmExecutionEnvironment(
|
|
139
|
+
export function createAvmExecutionEnvironment(
|
|
155
140
|
executionRequest: PublicExecutionRequest,
|
|
156
141
|
globalVariables: GlobalVariables,
|
|
157
142
|
transactionFee: Fr,
|
package/src/public/index.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export * from './db_interfaces.js';
|
|
2
|
-
export * from './
|
|
3
|
-
export {
|
|
2
|
+
export * from './public_tx_simulator.js';
|
|
3
|
+
export {
|
|
4
|
+
type EnqueuedPublicCallExecutionResult as PublicExecutionResult,
|
|
5
|
+
type PublicFunctionCallResult,
|
|
6
|
+
} from './execution.js';
|
|
4
7
|
export { PublicExecutor } from './executor.js';
|
|
5
8
|
export * from './fee_payment.js';
|
|
6
|
-
export { HintsBuilder } from './hints_builder.js';
|
|
7
9
|
export * from './public_db_sources.js';
|
|
8
|
-
export * from './public_kernel.js';
|
|
9
|
-
export * from './public_kernel_circuit_simulator.js';
|
|
10
10
|
export { PublicProcessor, PublicProcessorFactory } from './public_processor.js';
|
|
11
11
|
export { PublicSideEffectTrace } from './side_effect_trace.js';
|
|
12
|
+
export { PublicEnqueuedCallSideEffectTrace } from './enqueued_call_side_effect_trace.js';
|
|
13
|
+
export { getExecutionRequestsByPhase } from './utils.js';
|
|
@@ -49,12 +49,14 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
|
|
|
49
49
|
*/
|
|
50
50
|
public addNewContracts(tx: Tx): Promise<void> {
|
|
51
51
|
// Extract contract class and instance data from logs and add to cache for this block
|
|
52
|
-
const logs = tx.
|
|
52
|
+
const logs = tx.contractClassLogs.unrollLogs();
|
|
53
53
|
ContractClassRegisteredEvent.fromLogs(logs, ProtocolContractAddress.ContractClassRegisterer).forEach(e => {
|
|
54
54
|
this.log.debug(`Adding class ${e.contractClassId.toString()} to public execution contract cache`);
|
|
55
55
|
this.classCache.set(e.contractClassId.toString(), e.toContractClassPublic());
|
|
56
56
|
});
|
|
57
|
-
|
|
57
|
+
// We store the contract instance deployed event log in enc logs, contract_instance_deployer_contract/src/main.nr
|
|
58
|
+
const encLogs = tx.encryptedLogs.unrollLogs();
|
|
59
|
+
ContractInstanceDeployedEvent.fromLogs(encLogs).forEach(e => {
|
|
58
60
|
this.log.debug(
|
|
59
61
|
`Adding instance ${e.address.toString()} with class ${e.contractClassId.toString()} to public execution contract cache`,
|
|
60
62
|
);
|
|
@@ -72,11 +74,13 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
|
|
|
72
74
|
// TODO(@spalladino): Can this inadvertently delete a valid contract added by another tx?
|
|
73
75
|
// Let's say we have two txs adding the same contract on the same block. If the 2nd one reverts,
|
|
74
76
|
// wouldn't that accidentally remove the contract added on the first one?
|
|
75
|
-
const logs = tx.
|
|
77
|
+
const logs = tx.contractClassLogs.unrollLogs();
|
|
76
78
|
ContractClassRegisteredEvent.fromLogs(logs, ProtocolContractAddress.ContractClassRegisterer).forEach(e =>
|
|
77
79
|
this.classCache.delete(e.contractClassId.toString()),
|
|
78
80
|
);
|
|
79
|
-
|
|
81
|
+
// We store the contract instance deployed event log in enc logs, contract_instance_deployer_contract/src/main.nr
|
|
82
|
+
const encLogs = tx.encryptedLogs.unrollLogs();
|
|
83
|
+
ContractInstanceDeployedEvent.fromLogs(encLogs).forEach(e => this.instanceCache.delete(e.address.toString()));
|
|
80
84
|
return Promise.resolve();
|
|
81
85
|
}
|
|
82
86
|
|
|
@@ -131,6 +135,10 @@ export class WorldStateDB extends ContractsDataSourcePublicDB implements PublicS
|
|
|
131
135
|
super(dataSource);
|
|
132
136
|
}
|
|
133
137
|
|
|
138
|
+
public getMerkleInterface(): MerkleTreeWriteOperations {
|
|
139
|
+
return this.db;
|
|
140
|
+
}
|
|
141
|
+
|
|
134
142
|
/**
|
|
135
143
|
* Reads a value from public storage, returning zero if none.
|
|
136
144
|
* @param contract - Owner of the storage.
|