@aztec/simulator 0.34.0 → 0.35.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/acvm.d.ts +4 -1
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/acvm.js +5 -5
- package/dest/acvm/deserialize.d.ts +3 -5
- package/dest/acvm/deserialize.d.ts.map +1 -1
- package/dest/acvm/deserialize.js +6 -9
- package/dest/acvm/oracle/oracle.d.ts +2 -0
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +12 -4
- package/dest/acvm/oracle/typed_oracle.d.ts +2 -0
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +7 -1
- package/dest/avm/avm_execution_environment.d.ts +4 -2
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +7 -5
- package/dest/avm/avm_gas.js +2 -2
- 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 +24 -6
- package/dest/avm/avm_memory_types.js +2 -2
- package/dest/avm/avm_simulator.js +2 -2
- package/dest/avm/fixtures/index.d.ts +3 -0
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +11 -4
- package/dest/avm/journal/journal.d.ts +1 -0
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +12 -1
- package/dest/avm/opcodes/accrued_substate.d.ts +2 -1
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +13 -5
- package/dest/avm/opcodes/context_getters.js +2 -2
- package/dest/avm/opcodes/external_calls.d.ts +2 -2
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +7 -6
- package/dest/avm/opcodes/hashing.d.ts +8 -8
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +35 -43
- package/dest/avm/serialization/instruction_serialization.d.ts +1 -1
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +2 -2
- package/dest/client/client_execution_context.d.ts +13 -3
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +23 -8
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +8 -6
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +6 -5
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +5 -4
- package/dest/common/index.d.ts +1 -1
- package/dest/common/index.d.ts.map +1 -1
- package/dest/common/index.js +2 -2
- package/dest/common/packed_values_cache.d.ts +28 -0
- package/dest/common/packed_values_cache.d.ts.map +1 -0
- package/dest/common/packed_values_cache.js +50 -0
- package/dest/index.d.ts +1 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -1
- package/dest/mocks/fixtures.d.ts +42 -0
- package/dest/mocks/fixtures.d.ts.map +1 -0
- package/dest/mocks/fixtures.js +84 -0
- package/dest/mocks/index.d.ts +2 -0
- package/dest/mocks/index.d.ts.map +1 -0
- package/dest/mocks/index.js +2 -0
- package/dest/public/abstract_phase_manager.d.ts +82 -0
- package/dest/public/abstract_phase_manager.d.ts.map +1 -0
- package/dest/public/abstract_phase_manager.js +320 -0
- package/dest/public/app_logic_phase_manager.d.ts +29 -0
- package/dest/public/app_logic_phase_manager.d.ts.map +1 -0
- package/dest/public/app_logic_phase_manager.js +50 -0
- package/dest/public/execution.d.ts +3 -0
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -1
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +17 -13
- package/dest/public/hints_builder.d.ts +23 -0
- package/dest/public/hints_builder.d.ts.map +1 -0
- package/dest/public/hints_builder.js +62 -0
- package/dest/public/index.d.ts +5 -0
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +6 -1
- package/dest/public/phase_manager_factory.d.ts +18 -0
- package/dest/public/phase_manager_factory.d.ts.map +1 -0
- package/dest/public/phase_manager_factory.js +56 -0
- package/dest/public/public_execution_context.d.ts +15 -5
- package/dest/public/public_execution_context.d.ts.map +1 -1
- package/dest/public/public_execution_context.js +28 -12
- package/dest/public/public_executor.d.ts +79 -0
- package/dest/public/public_executor.d.ts.map +1 -0
- package/dest/public/public_executor.js +198 -0
- package/dest/public/public_kernel.d.ts +37 -0
- package/dest/public/public_kernel.d.ts.map +1 -0
- package/dest/public/public_kernel.js +97 -0
- package/dest/public/public_kernel_circuit_simulator.d.ts +31 -0
- package/dest/public/public_kernel_circuit_simulator.d.ts.map +1 -0
- package/dest/public/public_kernel_circuit_simulator.js +2 -0
- package/dest/public/public_processor.d.ts +53 -0
- package/dest/public/public_processor.d.ts.map +1 -0
- package/dest/public/public_processor.js +144 -0
- package/dest/public/setup_phase_manager.d.ts +30 -0
- package/dest/public/setup_phase_manager.d.ts.map +1 -0
- package/dest/public/setup_phase_manager.js +46 -0
- package/dest/public/tail_phase_manager.d.ts +30 -0
- package/dest/public/tail_phase_manager.d.ts.map +1 -0
- package/dest/public/tail_phase_manager.js +60 -0
- package/dest/public/teardown_phase_manager.d.ts +30 -0
- package/dest/public/teardown_phase_manager.d.ts.map +1 -0
- package/dest/public/teardown_phase_manager.js +46 -0
- package/dest/public/transitional_adaptors.d.ts +2 -1
- package/dest/public/transitional_adaptors.d.ts.map +1 -1
- package/dest/public/transitional_adaptors.js +11 -10
- package/dest/public/utils.d.ts +8 -0
- package/dest/public/utils.d.ts.map +1 -0
- package/dest/public/utils.js +29 -0
- package/dest/simulator/acvm_native.d.ts +19 -3
- package/dest/simulator/acvm_native.d.ts.map +1 -1
- package/dest/simulator/acvm_native.js +75 -48
- package/dest/simulator/acvm_wasm.d.ts.map +1 -1
- package/dest/simulator/acvm_wasm.js +3 -4
- package/package.json +8 -5
- package/src/acvm/acvm.ts +8 -5
- package/src/acvm/deserialize.ts +5 -9
- package/src/acvm/oracle/oracle.ts +13 -3
- package/src/acvm/oracle/typed_oracle.ts +8 -0
- package/src/avm/avm_execution_environment.ts +9 -1
- package/src/avm/avm_gas.ts +1 -1
- package/src/avm/avm_machine_state.ts +26 -5
- package/src/avm/avm_memory_types.ts +1 -1
- package/src/avm/avm_simulator.ts +1 -1
- package/src/avm/fixtures/index.ts +13 -1
- package/src/avm/journal/journal.ts +13 -0
- package/src/avm/opcodes/accrued_substate.ts +16 -4
- package/src/avm/opcodes/context_getters.ts +1 -1
- package/src/avm/opcodes/external_calls.ts +8 -5
- package/src/avm/opcodes/hashing.ts +38 -54
- package/src/avm/serialization/instruction_serialization.ts +1 -1
- package/src/client/client_execution_context.ts +25 -6
- package/src/client/private_execution.ts +7 -6
- package/src/client/simulator.ts +7 -3
- package/src/client/unconstrained_execution.ts +4 -3
- package/src/common/index.ts +1 -1
- package/src/common/packed_values_cache.ts +55 -0
- package/src/index.ts +1 -0
- package/src/mocks/fixtures.ts +169 -0
- package/src/mocks/index.ts +1 -0
- package/src/public/abstract_phase_manager.ts +571 -0
- package/src/public/app_logic_phase_manager.ts +76 -0
- package/src/public/execution.ts +4 -0
- package/src/public/executor.ts +18 -13
- package/src/public/hints_builder.ts +119 -0
- package/src/public/index.ts +5 -0
- package/src/public/phase_manager_factory.ts +126 -0
- package/src/public/public_execution_context.ts +29 -18
- package/src/public/public_executor.ts +267 -0
- package/src/public/public_kernel.ts +139 -0
- package/src/public/public_kernel_circuit_simulator.ts +36 -0
- package/src/public/public_processor.ts +212 -0
- package/src/public/setup_phase_manager.ts +66 -0
- package/src/public/tail_phase_manager.ts +120 -0
- package/src/public/teardown_phase_manager.ts +66 -0
- package/src/public/transitional_adaptors.ts +14 -5
- package/src/public/utils.ts +31 -0
- package/src/simulator/acvm_native.ts +94 -47
- package/src/simulator/acvm_wasm.ts +7 -3
- package/dest/common/packed_args_cache.d.ts +0 -28
- package/dest/common/packed_args_cache.d.ts.map +0 -1
- package/dest/common/packed_args_cache.js +0 -50
- package/src/common/packed_args_cache.ts +0 -55
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { type FunctionCall, type SimulationError, UnencryptedFunctionL2Logs } from '@aztec/circuit-types';
|
|
2
|
+
import {
|
|
3
|
+
ARGS_LENGTH,
|
|
4
|
+
type AztecAddress,
|
|
5
|
+
CallContext,
|
|
6
|
+
CallRequest,
|
|
7
|
+
type ContractStorageUpdateRequest,
|
|
8
|
+
EthAddress,
|
|
9
|
+
Fr,
|
|
10
|
+
FunctionData,
|
|
11
|
+
Gas,
|
|
12
|
+
GasSettings,
|
|
13
|
+
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
|
|
14
|
+
type PrivateKernelTailCircuitPublicInputs,
|
|
15
|
+
type PublicCallRequest,
|
|
16
|
+
} from '@aztec/circuits.js';
|
|
17
|
+
import { makeAztecAddress, makeSelector } from '@aztec/circuits.js/testing';
|
|
18
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
19
|
+
|
|
20
|
+
import { type PublicExecution, type PublicExecutionResult } from '../public/execution.js';
|
|
21
|
+
|
|
22
|
+
export class PublicExecutionResultBuilder {
|
|
23
|
+
private _execution: PublicExecution;
|
|
24
|
+
private _nestedExecutions: PublicExecutionResult[] = [];
|
|
25
|
+
private _contractStorageUpdateRequests: ContractStorageUpdateRequest[] = [];
|
|
26
|
+
private _returnValues: Fr[] = [];
|
|
27
|
+
private _reverted = false;
|
|
28
|
+
private _revertReason: SimulationError | undefined = undefined;
|
|
29
|
+
|
|
30
|
+
constructor(execution: PublicExecution) {
|
|
31
|
+
this._execution = execution;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static fromPublicCallRequest({
|
|
35
|
+
request,
|
|
36
|
+
returnValues = [new Fr(1n)],
|
|
37
|
+
nestedExecutions = [],
|
|
38
|
+
contractStorageUpdateRequests = [],
|
|
39
|
+
}: {
|
|
40
|
+
request: PublicCallRequest;
|
|
41
|
+
returnValues?: Fr[];
|
|
42
|
+
nestedExecutions?: PublicExecutionResult[];
|
|
43
|
+
contractStorageUpdateRequests?: ContractStorageUpdateRequest[];
|
|
44
|
+
}): PublicExecutionResultBuilder {
|
|
45
|
+
const builder = new PublicExecutionResultBuilder(request);
|
|
46
|
+
|
|
47
|
+
builder.withNestedExecutions(...nestedExecutions);
|
|
48
|
+
builder.withContractStorageUpdateRequest(...contractStorageUpdateRequests);
|
|
49
|
+
builder.withReturnValues(...returnValues);
|
|
50
|
+
|
|
51
|
+
return builder;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static fromFunctionCall({
|
|
55
|
+
from,
|
|
56
|
+
tx,
|
|
57
|
+
returnValues = [new Fr(1n)],
|
|
58
|
+
nestedExecutions = [],
|
|
59
|
+
contractStorageUpdateRequests = [],
|
|
60
|
+
revertReason,
|
|
61
|
+
}: {
|
|
62
|
+
from: AztecAddress;
|
|
63
|
+
tx: FunctionCall;
|
|
64
|
+
returnValues?: Fr[];
|
|
65
|
+
nestedExecutions?: PublicExecutionResult[];
|
|
66
|
+
contractStorageUpdateRequests?: ContractStorageUpdateRequest[];
|
|
67
|
+
revertReason?: SimulationError;
|
|
68
|
+
}) {
|
|
69
|
+
const builder = new PublicExecutionResultBuilder({
|
|
70
|
+
callContext: new CallContext(
|
|
71
|
+
from,
|
|
72
|
+
tx.to,
|
|
73
|
+
EthAddress.ZERO,
|
|
74
|
+
tx.functionData.selector,
|
|
75
|
+
Gas.test(),
|
|
76
|
+
false,
|
|
77
|
+
false,
|
|
78
|
+
0,
|
|
79
|
+
GasSettings.default(),
|
|
80
|
+
Fr.ZERO,
|
|
81
|
+
),
|
|
82
|
+
contractAddress: tx.to,
|
|
83
|
+
functionData: tx.functionData,
|
|
84
|
+
args: tx.args,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
builder.withNestedExecutions(...nestedExecutions);
|
|
88
|
+
builder.withContractStorageUpdateRequest(...contractStorageUpdateRequests);
|
|
89
|
+
builder.withReturnValues(...returnValues);
|
|
90
|
+
if (revertReason) {
|
|
91
|
+
builder.withReverted(revertReason);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return builder;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
withNestedExecutions(...nested: PublicExecutionResult[]): PublicExecutionResultBuilder {
|
|
98
|
+
this._nestedExecutions.push(...nested);
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
withContractStorageUpdateRequest(...request: ContractStorageUpdateRequest[]): PublicExecutionResultBuilder {
|
|
103
|
+
this._contractStorageUpdateRequests.push(...request);
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
withReturnValues(...values: Fr[]): PublicExecutionResultBuilder {
|
|
108
|
+
this._returnValues.push(...values);
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
withReverted(reason: SimulationError): PublicExecutionResultBuilder {
|
|
113
|
+
this._reverted = true;
|
|
114
|
+
this._revertReason = reason;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
build(): PublicExecutionResult {
|
|
119
|
+
return {
|
|
120
|
+
execution: this._execution,
|
|
121
|
+
nestedExecutions: this._nestedExecutions,
|
|
122
|
+
nullifierReadRequests: [],
|
|
123
|
+
nullifierNonExistentReadRequests: [],
|
|
124
|
+
contractStorageUpdateRequests: this._contractStorageUpdateRequests,
|
|
125
|
+
returnValues: padArrayEnd(this._returnValues, Fr.ZERO, 4), // TODO(#5450) Need to use the proper return values here
|
|
126
|
+
newNoteHashes: [],
|
|
127
|
+
newNullifiers: [],
|
|
128
|
+
newL2ToL1Messages: [],
|
|
129
|
+
contractStorageReads: [],
|
|
130
|
+
unencryptedLogs: UnencryptedFunctionL2Logs.empty(),
|
|
131
|
+
startSideEffectCounter: Fr.ZERO,
|
|
132
|
+
endSideEffectCounter: Fr.ZERO,
|
|
133
|
+
reverted: this._reverted,
|
|
134
|
+
revertReason: this._revertReason,
|
|
135
|
+
gasLeft: this._execution.callContext.gasLeft.mul(0.9),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export const makeFunctionCall = (
|
|
141
|
+
to = makeAztecAddress(30),
|
|
142
|
+
selector = makeSelector(5),
|
|
143
|
+
args = new Array(ARGS_LENGTH).fill(Fr.ZERO),
|
|
144
|
+
) => ({ to, functionData: new FunctionData(selector, false), args });
|
|
145
|
+
|
|
146
|
+
export function addKernelPublicCallStack(
|
|
147
|
+
kernelOutput: PrivateKernelTailCircuitPublicInputs,
|
|
148
|
+
calls: {
|
|
149
|
+
setupCalls: PublicCallRequest[];
|
|
150
|
+
appLogicCalls: PublicCallRequest[];
|
|
151
|
+
teardownCall: PublicCallRequest;
|
|
152
|
+
},
|
|
153
|
+
) {
|
|
154
|
+
// the first two calls are non-revertible
|
|
155
|
+
// the first is for setup, the second is for teardown
|
|
156
|
+
kernelOutput.forPublic!.endNonRevertibleData.publicCallStack = padArrayEnd(
|
|
157
|
+
// this is a stack, so the first item is the last call
|
|
158
|
+
// and callRequests is in the order of the calls
|
|
159
|
+
[calls.teardownCall.toCallRequest(), ...calls.setupCalls.map(c => c.toCallRequest())],
|
|
160
|
+
CallRequest.empty(),
|
|
161
|
+
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
kernelOutput.forPublic!.end.publicCallStack = padArrayEnd(
|
|
165
|
+
calls.appLogicCalls.map(c => c.toCallRequest()),
|
|
166
|
+
CallRequest.empty(),
|
|
167
|
+
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './fixtures.js';
|