@aztec/simulator 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f
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/README.md +6 -4
- package/dest/common/errors.d.ts +7 -1
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/private/acvm/acvm.d.ts +4 -2
- package/dest/private/acvm/acvm.d.ts.map +1 -1
- package/dest/private/acvm/acvm.js +4 -3
- package/dest/private/acvm_native.d.ts +5 -3
- package/dest/private/acvm_native.d.ts.map +1 -1
- package/dest/private/acvm_native.js +8 -6
- package/dest/private/acvm_wasm.d.ts +4 -3
- package/dest/private/acvm_wasm.d.ts.map +1 -1
- package/dest/private/acvm_wasm.js +7 -5
- package/dest/private/circuit_recording/circuit_recorder.d.ts +4 -3
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.js +22 -19
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts +3 -2
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/file_circuit_recorder.js +2 -2
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
- package/dest/private/factory.d.ts +3 -3
- package/dest/private/factory.d.ts.map +1 -1
- package/dest/private/factory.js +7 -4
- package/dest/public/avm/avm_context.d.ts +3 -3
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts +6 -6
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.js +3 -3
- package/dest/public/avm/avm_execution_environment.d.ts +6 -5
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_gas.js +3 -3
- package/dest/public/avm/avm_machine_state.d.ts +6 -5
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.js +3 -2
- package/dest/public/avm/avm_memory_types.d.ts +1 -1
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.js +3 -0
- package/dest/public/avm/avm_simulator.d.ts +3 -2
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +6 -5
- package/dest/public/avm/calldata.d.ts +51 -0
- package/dest/public/avm/calldata.d.ts.map +1 -0
- package/dest/public/avm/calldata.js +64 -0
- package/dest/public/avm/fixtures/account_proof_fetcher.d.ts +2 -0
- package/dest/public/avm/fixtures/account_proof_fetcher.d.ts.map +1 -0
- package/dest/public/avm/fixtures/account_proof_fetcher.js +152 -0
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +3 -2
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +17 -2
- package/dest/public/avm/fixtures/initializers.d.ts +1 -1
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.js +2 -1
- package/dest/public/avm/fixtures/utils.d.ts +1 -1
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
- package/dest/public/avm/fixtures/utils.js +3 -0
- package/dest/public/avm/opcodes/accrued_substate.d.ts +17 -18
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +42 -43
- package/dest/public/avm/opcodes/arithmetic.d.ts +8 -8
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.js +1 -1
- package/dest/public/avm/opcodes/bitwise.d.ts +7 -7
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/public/avm/opcodes/bitwise.js +5 -5
- package/dest/public/avm/opcodes/comparators.d.ts +4 -4
- package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/public/avm/opcodes/comparators.js +1 -1
- package/dest/public/avm/opcodes/contract.d.ts +5 -4
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/contract.js +13 -9
- package/dest/public/avm/opcodes/control_flow.d.ts +3 -3
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/public/avm/opcodes/control_flow.js +4 -4
- package/dest/public/avm/opcodes/conversion.d.ts +3 -3
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.js +4 -4
- package/dest/public/avm/opcodes/ec_add.d.ts +4 -6
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.js +22 -27
- package/dest/public/avm/opcodes/environment_getters.d.ts +5 -5
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/environment_getters.js +6 -6
- package/dest/public/avm/opcodes/external_calls.d.ts +9 -9
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +23 -22
- package/dest/public/avm/opcodes/hashing.d.ts +8 -8
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/public/avm/opcodes/hashing.js +12 -12
- package/dest/public/avm/opcodes/instruction_impl.d.ts +4 -4
- package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/public/avm/opcodes/instruction_impl.js +4 -4
- package/dest/public/avm/opcodes/memory.d.ts +14 -14
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +25 -25
- package/dest/public/avm/opcodes/misc.d.ts +3 -3
- package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/public/avm/opcodes/misc.js +4 -4
- package/dest/public/avm/opcodes/storage.d.ts +16 -15
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/public/avm/opcodes/storage.js +34 -24
- package/dest/public/avm/serialization/bytecode_serialization.js +3 -3
- package/dest/public/avm/serialization/instruction_serialization.d.ts +2 -2
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +1 -1
- package/dest/public/contracts_db_checkpoint.d.ts +2 -2
- package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
- package/dest/public/contracts_db_checkpoint.js +1 -1
- package/dest/public/debug_fn_name.d.ts +4 -4
- package/dest/public/debug_fn_name.d.ts.map +1 -1
- package/dest/public/debug_fn_name.js +7 -5
- package/dest/public/executor_metrics.d.ts +1 -1
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +12 -33
- package/dest/public/fixtures/amm_test.js +2 -2
- package/dest/public/fixtures/bulk_test.d.ts +3 -3
- package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
- package/dest/public/fixtures/bulk_test.js +32 -21
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +13 -11
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tests.js +79 -19
- package/dest/public/fixtures/minimal_public_tx.js +2 -2
- package/dest/public/fixtures/opcode_spammer.d.ts +3 -4
- package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -1
- package/dest/public/fixtures/opcode_spammer.js +100 -136
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +6 -5
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +37 -10
- package/dest/public/fixtures/utils.d.ts +2 -2
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +19 -20
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +21 -7
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -1
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +42 -10
- package/dest/public/fuzzing/avm_simulator_bin.js +29 -11
- package/dest/public/hinting_db_sources.d.ts +5 -5
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +10 -7
- package/dest/public/public_db_sources.d.ts +9 -5
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +20 -14
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +5 -5
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
- package/dest/public/public_processor/guarded_merkle_tree.js +7 -5
- package/dest/public/public_processor/public_processor.d.ts +11 -6
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +511 -92
- package/dest/public/public_processor/public_processor_metrics.d.ts +5 -2
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor_metrics.js +36 -45
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +3 -2
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +5 -4
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +5 -5
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +10 -10
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +4 -4
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +7 -7
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +4 -4
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +6 -6
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +3 -2
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +2 -2
- package/dest/public/public_tx_simulator/factories.d.ts +3 -2
- package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/factories.js +4 -4
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +10 -5
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +16 -18
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +11 -5
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +26 -16
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +395 -19
- package/dest/public/side_effect_trace.d.ts +5 -4
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +3 -3
- package/dest/public/state_manager/state_manager.d.ts +10 -4
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +14 -7
- package/dest/public/test_executor_metrics.d.ts +8 -2
- package/dest/public/test_executor_metrics.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.js +24 -2
- package/package.json +17 -17
- package/src/private/acvm/acvm.ts +4 -3
- package/src/private/acvm_native.ts +11 -5
- package/src/private/acvm_wasm.ts +11 -4
- package/src/private/circuit_recording/circuit_recorder.ts +23 -20
- package/src/private/circuit_recording/file_circuit_recorder.ts +7 -2
- package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
- package/src/private/factory.ts +7 -4
- package/src/public/avm/avm_context.ts +2 -2
- package/src/public/avm/avm_contract_call_result.ts +8 -6
- package/src/public/avm/avm_execution_environment.ts +9 -4
- package/src/public/avm/avm_gas.ts +2 -2
- package/src/public/avm/avm_machine_state.ts +6 -5
- package/src/public/avm/avm_memory_types.ts +4 -0
- package/src/public/avm/avm_simulator.ts +9 -6
- package/src/public/avm/calldata.ts +101 -0
- package/src/public/avm/fixtures/account_proof.json +553 -0
- package/src/public/avm/fixtures/account_proof_fetcher.ts +166 -0
- package/src/public/avm/fixtures/avm_simulation_tester.ts +8 -2
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +22 -2
- package/src/public/avm/fixtures/initializers.ts +2 -1
- package/src/public/avm/fixtures/utils.ts +3 -0
- package/src/public/avm/opcodes/accrued_substate.ts +31 -34
- package/src/public/avm/opcodes/arithmetic.ts +1 -1
- package/src/public/avm/opcodes/bitwise.ts +3 -3
- package/src/public/avm/opcodes/comparators.ts +1 -1
- package/src/public/avm/opcodes/contract.ts +9 -8
- package/src/public/avm/opcodes/control_flow.ts +2 -2
- package/src/public/avm/opcodes/conversion.ts +3 -3
- package/src/public/avm/opcodes/ec_add.ts +21 -31
- package/src/public/avm/opcodes/environment_getters.ts +7 -7
- package/src/public/avm/opcodes/external_calls.ts +18 -16
- package/src/public/avm/opcodes/hashing.ts +6 -6
- package/src/public/avm/opcodes/instruction_impl.ts +2 -2
- package/src/public/avm/opcodes/memory.ts +19 -19
- package/src/public/avm/opcodes/misc.ts +2 -2
- package/src/public/avm/opcodes/storage.ts +30 -22
- package/src/public/avm/serialization/bytecode_serialization.ts +2 -2
- package/src/public/avm/serialization/instruction_serialization.ts +1 -1
- package/src/public/contracts_db_checkpoint.ts +1 -1
- package/src/public/debug_fn_name.ts +10 -8
- package/src/public/executor_metrics.ts +9 -33
- package/src/public/fixtures/amm_test.ts +2 -2
- package/src/public/fixtures/bulk_test.ts +31 -6
- package/src/public/fixtures/custom_bytecode_tests.ts +166 -19
- package/src/public/fixtures/minimal_public_tx.ts +2 -2
- package/src/public/fixtures/opcode_spammer.ts +200 -125
- package/src/public/fixtures/public_tx_simulation_tester.ts +47 -6
- package/src/public/fixtures/utils.ts +26 -22
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +61 -13
- package/src/public/fuzzing/avm_simulator_bin.ts +43 -8
- package/src/public/hinting_db_sources.ts +10 -7
- package/src/public/public_db_sources.ts +36 -19
- package/src/public/public_processor/guarded_merkle_tree.ts +6 -6
- package/src/public/public_processor/public_processor.ts +156 -93
- package/src/public/public_processor/public_processor_metrics.ts +28 -44
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +9 -5
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +17 -7
- package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +7 -5
- package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +7 -5
- package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +3 -1
- package/src/public/public_tx_simulator/factories.ts +6 -3
- package/src/public/public_tx_simulator/public_tx_context.ts +21 -16
- package/src/public/public_tx_simulator/public_tx_simulator.ts +32 -17
- package/src/public/side_effect_trace.ts +5 -2
- package/src/public/state_manager/state_manager.ts +29 -20
- package/src/public/test_executor_metrics.ts +27 -3
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PUBLIC_TX_L2_GAS_OVERHEAD, TX_DA_GAS_OVERHEAD } from '@aztec/constants';
|
|
2
2
|
import { asyncMap } from '@aztec/foundation/async-map';
|
|
3
3
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
4
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
5
|
import { type ContractArtifact, encodeArguments } from '@aztec/stdlib/abi';
|
|
6
6
|
import { PublicSimulatorConfig, type PublicTxResult } from '@aztec/stdlib/avm';
|
|
7
7
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
|
-
import { Gas, GasFees } from '@aztec/stdlib/gas';
|
|
8
|
+
import { FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT, Gas, GasFees } from '@aztec/stdlib/gas';
|
|
9
9
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
10
10
|
import { PublicCallRequest } from '@aztec/stdlib/kernel';
|
|
11
11
|
import { GlobalVariables, PublicCallRequestWithCalldata, type Tx } from '@aztec/stdlib/tx';
|
|
@@ -112,6 +112,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
112
112
|
feePayer: AztecAddress = sender,
|
|
113
113
|
/* need some unique first nullifier for note-nonce computations */
|
|
114
114
|
privateInsertions: TestPrivateInsertions = { nonRevertible: { nullifiers: [new Fr(420000 + this.txCount)] } },
|
|
115
|
+
gasLimits?: Gas,
|
|
115
116
|
): Promise<Tx> {
|
|
116
117
|
const setupCallRequests = await asyncMap(setupCalls, call =>
|
|
117
118
|
this.#createPubicCallRequestForCall(call, call.sender ?? sender),
|
|
@@ -131,9 +132,13 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
131
132
|
teardownCallRequest,
|
|
132
133
|
feePayer,
|
|
133
134
|
/*gasUsedByPrivate*/ teardownCall
|
|
134
|
-
? new Gas(
|
|
135
|
-
|
|
135
|
+
? new Gas(
|
|
136
|
+
FALLBACK_TEARDOWN_DA_GAS_LIMIT + TX_DA_GAS_OVERHEAD,
|
|
137
|
+
FALLBACK_TEARDOWN_L2_GAS_LIMIT + PUBLIC_TX_L2_GAS_OVERHEAD,
|
|
138
|
+
)
|
|
139
|
+
: new Gas(TX_DA_GAS_OVERHEAD, PUBLIC_TX_L2_GAS_OVERHEAD),
|
|
136
140
|
defaultGlobals(),
|
|
141
|
+
gasLimits,
|
|
137
142
|
);
|
|
138
143
|
}
|
|
139
144
|
|
|
@@ -146,8 +151,9 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
146
151
|
/* need some unique first nullifier for note-nonce computations */
|
|
147
152
|
privateInsertions?: TestPrivateInsertions,
|
|
148
153
|
txLabel: string = 'unlabeledTx',
|
|
154
|
+
gasLimits?: Gas,
|
|
149
155
|
): Promise<PublicTxResult> {
|
|
150
|
-
const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions);
|
|
156
|
+
const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions, gasLimits);
|
|
151
157
|
|
|
152
158
|
await this.setFeePayerBalance(feePayer);
|
|
153
159
|
|
|
@@ -161,6 +167,8 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
161
167
|
}
|
|
162
168
|
const avmResult = await this.simulator.simulate(tx, fullTxLabel);
|
|
163
169
|
|
|
170
|
+
await this.#recordBytecodeSizes(fullTxLabel, [...setupCalls, ...appCalls, ...(teardownCall ? [teardownCall] : [])]);
|
|
171
|
+
|
|
164
172
|
// Something like this is often useful for debugging:
|
|
165
173
|
//if (avmResult.revertReason) {
|
|
166
174
|
// // resolve / enrich revert reason
|
|
@@ -190,8 +198,18 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
190
198
|
teardownCall?: TestEnqueuedCall,
|
|
191
199
|
feePayer?: AztecAddress,
|
|
192
200
|
privateInsertions?: TestPrivateInsertions,
|
|
201
|
+
gasLimits?: Gas,
|
|
193
202
|
): Promise<PublicTxResult> {
|
|
194
|
-
return await this.simulateTx(
|
|
203
|
+
return await this.simulateTx(
|
|
204
|
+
sender,
|
|
205
|
+
setupCalls,
|
|
206
|
+
appCalls,
|
|
207
|
+
teardownCall,
|
|
208
|
+
feePayer,
|
|
209
|
+
privateInsertions,
|
|
210
|
+
txLabel,
|
|
211
|
+
gasLimits,
|
|
212
|
+
);
|
|
195
213
|
}
|
|
196
214
|
|
|
197
215
|
/**
|
|
@@ -209,6 +227,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
209
227
|
teardownCall?: TestEnqueuedCall,
|
|
210
228
|
feePayer?: AztecAddress,
|
|
211
229
|
privateInsertions?: TestPrivateInsertions,
|
|
230
|
+
gasLimits?: Gas,
|
|
212
231
|
): Promise<PublicTxResult> {
|
|
213
232
|
return await this.simulateTxWithLabel(
|
|
214
233
|
txLabel,
|
|
@@ -218,6 +237,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
218
237
|
teardownCall,
|
|
219
238
|
feePayer,
|
|
220
239
|
privateInsertions,
|
|
240
|
+
gasLimits,
|
|
221
241
|
);
|
|
222
242
|
}
|
|
223
243
|
|
|
@@ -277,6 +297,27 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
277
297
|
|
|
278
298
|
return new PublicCallRequestWithCalldata(request, calldata);
|
|
279
299
|
}
|
|
300
|
+
|
|
301
|
+
// WARNING: Deduplicates by artifact name, so two different artifacts with the same name
|
|
302
|
+
// in a single tx would only record the first one's bytecode size.
|
|
303
|
+
async #recordBytecodeSizes(txLabel: string, calls: TestEnqueuedCall[]) {
|
|
304
|
+
const seenArtifactNames = new Set<string>();
|
|
305
|
+
for (const call of calls) {
|
|
306
|
+
const artifact = await this.contractDataSource.getContractArtifact(call.address);
|
|
307
|
+
if (!artifact || seenArtifactNames.has(artifact.name)) {
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
seenArtifactNames.add(artifact.name);
|
|
311
|
+
const instance = await this.contractDataSource.getContract(call.address);
|
|
312
|
+
if (!instance) {
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
const contractClass = await this.contractDataSource.getContractClass(instance.currentContractClassId);
|
|
316
|
+
if (contractClass) {
|
|
317
|
+
this.metrics.recordBytecodeSize(txLabel, artifact.name, contractClass.packedBytecode.length);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
280
321
|
}
|
|
281
322
|
|
|
282
323
|
export function defaultGlobals() {
|
|
@@ -2,10 +2,8 @@ import {
|
|
|
2
2
|
CONTRACT_CLASS_PUBLISHED_MAGIC_VALUE,
|
|
3
3
|
CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS,
|
|
4
4
|
CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
DEFAULT_TEARDOWN_DA_GAS_LIMIT,
|
|
8
|
-
DEFAULT_TEARDOWN_L2_GAS_LIMIT,
|
|
5
|
+
MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT,
|
|
6
|
+
MAX_PROCESSABLE_L2_GAS,
|
|
9
7
|
PRIVATE_LOG_SIZE_IN_FIELDS,
|
|
10
8
|
} from '@aztec/constants';
|
|
11
9
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
@@ -14,7 +12,13 @@ import { CONTRACT_INSTANCE_PUBLISHED_EVENT_TAG } from '@aztec/protocol-contracts
|
|
|
14
12
|
import { bufferAsFields } from '@aztec/stdlib/abi';
|
|
15
13
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
16
14
|
import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
17
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
FALLBACK_TEARDOWN_DA_GAS_LIMIT,
|
|
17
|
+
FALLBACK_TEARDOWN_L2_GAS_LIMIT,
|
|
18
|
+
Gas,
|
|
19
|
+
GasFees,
|
|
20
|
+
GasSettings,
|
|
21
|
+
} from '@aztec/stdlib/gas';
|
|
18
22
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
19
23
|
import {
|
|
20
24
|
LogHash,
|
|
@@ -62,13 +66,14 @@ export async function createTxForPublicCalls(
|
|
|
62
66
|
feePayer = AztecAddress.zero(),
|
|
63
67
|
gasUsedByPrivate: Gas = Gas.empty(),
|
|
64
68
|
globals: GlobalVariables = GlobalVariables.empty(),
|
|
69
|
+
gasLimits?: Gas,
|
|
65
70
|
): Promise<Tx> {
|
|
66
71
|
assert(
|
|
67
72
|
setupCallRequests.length > 0 || appCallRequests.length > 0 || teardownCallRequest !== undefined,
|
|
68
73
|
"Can't create public tx with no enqueued calls",
|
|
69
74
|
);
|
|
70
75
|
// use max limits
|
|
71
|
-
|
|
76
|
+
gasLimits = gasLimits ?? new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
|
|
72
77
|
|
|
73
78
|
const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
|
|
74
79
|
|
|
@@ -128,19 +133,19 @@ export async function createTxForPublicCalls(
|
|
|
128
133
|
|
|
129
134
|
const maxFeesPerGas = feePayer.isZero() ? GasFees.empty() : new GasFees(10, 10);
|
|
130
135
|
const teardownGasLimits = teardownCallRequest
|
|
131
|
-
? new Gas(
|
|
136
|
+
? new Gas(FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT)
|
|
132
137
|
: Gas.empty();
|
|
133
138
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, maxFeesPerGas, GasFees.empty());
|
|
134
139
|
const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
|
|
135
140
|
const header = BlockHeader.empty({ globalVariables: globals });
|
|
136
141
|
const constantData = new TxConstantData(header, txContext, Fr.zero(), Fr.zero());
|
|
137
|
-
const
|
|
142
|
+
const expirationTimestamp = 0n; // Not used in the simulator.
|
|
138
143
|
|
|
139
144
|
const txData = new PrivateKernelTailCircuitPublicInputs(
|
|
140
145
|
constantData,
|
|
141
146
|
/*gasUsed=*/ gasUsedByPrivate,
|
|
142
147
|
feePayer,
|
|
143
|
-
|
|
148
|
+
expirationTimestamp,
|
|
144
149
|
forPublic,
|
|
145
150
|
);
|
|
146
151
|
|
|
@@ -163,7 +168,7 @@ export async function createTxForPrivateOnly(
|
|
|
163
168
|
gasUsedByPrivate: Gas = new Gas(10, 10),
|
|
164
169
|
): Promise<Tx> {
|
|
165
170
|
// use max limits
|
|
166
|
-
const gasLimits = new Gas(
|
|
171
|
+
const gasLimits = new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
|
|
167
172
|
|
|
168
173
|
const forRollup = PartialPrivateTailPublicInputsForRollup.empty();
|
|
169
174
|
|
|
@@ -171,13 +176,13 @@ export async function createTxForPrivateOnly(
|
|
|
171
176
|
const gasSettings = new GasSettings(gasLimits, Gas.empty(), maxFeesPerGas, GasFees.empty());
|
|
172
177
|
const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
|
|
173
178
|
const constantData = new TxConstantData(BlockHeader.empty(), txContext, Fr.zero(), Fr.zero());
|
|
174
|
-
const
|
|
179
|
+
const expirationTimestamp = 0n; // Not used in the simulator.
|
|
175
180
|
|
|
176
181
|
const txData = new PrivateKernelTailCircuitPublicInputs(
|
|
177
182
|
constantData,
|
|
178
183
|
/*gasUsed=*/ gasUsedByPrivate,
|
|
179
184
|
feePayer,
|
|
180
|
-
|
|
185
|
+
expirationTimestamp,
|
|
181
186
|
/*forPublic=*/ undefined,
|
|
182
187
|
forRollup,
|
|
183
188
|
);
|
|
@@ -228,17 +233,15 @@ export async function addNewContractInstanceToTx(
|
|
|
228
233
|
contractInstance: ContractInstanceWithAddress,
|
|
229
234
|
skipNullifierInsertion = false,
|
|
230
235
|
) {
|
|
231
|
-
//
|
|
232
|
-
// is not broadcast in such private logs
|
|
236
|
+
// Only ivpk_m is broadcast as a point (x, y); the other five keys are hashes.
|
|
233
237
|
const publicKeysAsFields = [
|
|
234
|
-
contractInstance.publicKeys.
|
|
235
|
-
contractInstance.publicKeys.
|
|
236
|
-
contractInstance.publicKeys.
|
|
237
|
-
contractInstance.publicKeys.
|
|
238
|
-
contractInstance.publicKeys.
|
|
239
|
-
contractInstance.publicKeys.
|
|
240
|
-
contractInstance.publicKeys.
|
|
241
|
-
contractInstance.publicKeys.masterTaggingPublicKey.y,
|
|
238
|
+
contractInstance.publicKeys.npkMHash,
|
|
239
|
+
contractInstance.publicKeys.ivpkM.x,
|
|
240
|
+
contractInstance.publicKeys.ivpkM.y,
|
|
241
|
+
contractInstance.publicKeys.ovpkMHash,
|
|
242
|
+
contractInstance.publicKeys.tpkMHash,
|
|
243
|
+
contractInstance.publicKeys.mspkMHash,
|
|
244
|
+
contractInstance.publicKeys.fbpkMHash,
|
|
242
245
|
];
|
|
243
246
|
const logFields = [
|
|
244
247
|
CONTRACT_INSTANCE_PUBLISHED_EVENT_TAG,
|
|
@@ -247,6 +250,7 @@ export async function addNewContractInstanceToTx(
|
|
|
247
250
|
new Fr(contractInstance.salt),
|
|
248
251
|
contractInstance.currentContractClassId,
|
|
249
252
|
contractInstance.initializationHash,
|
|
253
|
+
contractInstance.immutablesHash,
|
|
250
254
|
...publicKeysAsFields,
|
|
251
255
|
contractInstance.deployer.toField(),
|
|
252
256
|
];
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
MAX_NOTE_HASHES_PER_TX,
|
|
5
5
|
MAX_NULLIFIERS_PER_TX,
|
|
6
6
|
MAX_PRIVATE_LOGS_PER_TX,
|
|
7
|
+
MAX_PROTOCOL_CONTRACTS,
|
|
7
8
|
} from '@aztec/constants';
|
|
8
9
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
9
10
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
@@ -19,8 +20,17 @@ import {
|
|
|
19
20
|
import { PrivateLog } from '@aztec/stdlib/logs';
|
|
20
21
|
import { ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
|
|
21
22
|
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
22
|
-
import type
|
|
23
|
-
import {
|
|
23
|
+
import { MerkleTreeId, type MerkleTreeWriteOperations, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
24
|
+
import {
|
|
25
|
+
BlockHeader,
|
|
26
|
+
GlobalVariables,
|
|
27
|
+
HashedValues,
|
|
28
|
+
ProtocolContracts,
|
|
29
|
+
Tx,
|
|
30
|
+
TxConstantData,
|
|
31
|
+
TxContext,
|
|
32
|
+
TxHash,
|
|
33
|
+
} from '@aztec/stdlib/tx';
|
|
24
34
|
import type { NativeWorldStateService } from '@aztec/world-state';
|
|
25
35
|
|
|
26
36
|
import { BaseAvmSimulationTester } from '../avm/fixtures/base_avm_simulation_tester.js';
|
|
@@ -40,6 +50,9 @@ export class FuzzerSimulationRequest {
|
|
|
40
50
|
public readonly globals: GlobalVariables,
|
|
41
51
|
public readonly contractClasses: any[], // Raw, processed by addContractClassFromCpp
|
|
42
52
|
public readonly contractInstances: [any, any][], // Raw pairs [address, instance]
|
|
53
|
+
public readonly publicDataWrites: any[], // Raw public data tree writes to apply before simulation
|
|
54
|
+
public readonly noteHashes: any[], // Raw note hashes to apply before simulation
|
|
55
|
+
public readonly protocolContracts: ProtocolContracts, // Protocol contracts mapping from C++
|
|
43
56
|
) {}
|
|
44
57
|
|
|
45
58
|
static fromPlainObject(obj: any): FuzzerSimulationRequest {
|
|
@@ -53,6 +66,9 @@ export class FuzzerSimulationRequest {
|
|
|
53
66
|
GlobalVariables.fromPlainObject(obj.globals),
|
|
54
67
|
obj.contractClasses,
|
|
55
68
|
obj.contractInstances,
|
|
69
|
+
obj.publicDataWrites ?? [],
|
|
70
|
+
obj.noteHashes ?? [],
|
|
71
|
+
ProtocolContracts.fromPlainObject(obj.protocolContracts),
|
|
56
72
|
);
|
|
57
73
|
}
|
|
58
74
|
}
|
|
@@ -130,7 +146,7 @@ async function createTxFromHint(cppTx: AvmTxHint): Promise<Tx> {
|
|
|
130
146
|
constants,
|
|
131
147
|
cppTx.gasUsedByPrivate,
|
|
132
148
|
cppTx.feePayer,
|
|
133
|
-
0n, //
|
|
149
|
+
0n, // expirationTimestamp
|
|
134
150
|
forPublic,
|
|
135
151
|
undefined, // forRollup - not needed for public simulation
|
|
136
152
|
);
|
|
@@ -181,16 +197,23 @@ export class AvmFuzzerSimulator extends BaseAvmSimulationTester {
|
|
|
181
197
|
merkleTrees: MerkleTreeWriteOperations,
|
|
182
198
|
contractDataSource: SimpleContractDataSource,
|
|
183
199
|
globals: GlobalVariables,
|
|
200
|
+
protocolContracts: ProtocolContracts,
|
|
184
201
|
) {
|
|
185
202
|
super(contractDataSource, merkleTrees);
|
|
186
203
|
const contractsDb = new PublicContractsDB(contractDataSource);
|
|
187
|
-
this.simulator = new PublicTxSimulator(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
204
|
+
this.simulator = new PublicTxSimulator(
|
|
205
|
+
merkleTrees,
|
|
206
|
+
contractsDb,
|
|
207
|
+
globals,
|
|
208
|
+
{
|
|
209
|
+
skipFeeEnforcement: false,
|
|
210
|
+
collectDebugLogs: false,
|
|
211
|
+
collectHints: false,
|
|
212
|
+
collectStatistics: false,
|
|
213
|
+
collectCallMetadata: false,
|
|
214
|
+
},
|
|
215
|
+
protocolContracts,
|
|
216
|
+
);
|
|
194
217
|
}
|
|
195
218
|
|
|
196
219
|
/**
|
|
@@ -199,10 +222,11 @@ export class AvmFuzzerSimulator extends BaseAvmSimulationTester {
|
|
|
199
222
|
public static async create(
|
|
200
223
|
worldStateService: NativeWorldStateService,
|
|
201
224
|
globals: GlobalVariables,
|
|
225
|
+
protocolContracts: ProtocolContracts,
|
|
202
226
|
): Promise<AvmFuzzerSimulator> {
|
|
203
227
|
const contractDataSource = new SimpleContractDataSource();
|
|
204
228
|
const merkleTrees = await worldStateService.fork();
|
|
205
|
-
return new AvmFuzzerSimulator(merkleTrees, contractDataSource, globals);
|
|
229
|
+
return new AvmFuzzerSimulator(merkleTrees, contractDataSource, globals, protocolContracts);
|
|
206
230
|
}
|
|
207
231
|
|
|
208
232
|
/**
|
|
@@ -230,11 +254,35 @@ export class AvmFuzzerSimulator extends BaseAvmSimulationTester {
|
|
|
230
254
|
|
|
231
255
|
/**
|
|
232
256
|
* Add a contract instance from C++ raw msgpack data.
|
|
233
|
-
* This also inserts the contract address nullifier into the nullifier tree
|
|
257
|
+
* This also inserts the contract address nullifier into the nullifier tree,
|
|
258
|
+
* unless the address is a protocol canonical address (1-11).
|
|
234
259
|
*/
|
|
235
260
|
public async addContractInstanceFromCpp(rawAddress: any, rawInstance: any): Promise<void> {
|
|
236
261
|
const address = AztecAddress.fromPlainObject(rawAddress);
|
|
237
262
|
const instance = contractInstanceWithAddressFromPlainObject(address, rawInstance);
|
|
238
|
-
|
|
263
|
+
// Protocol canonical addresses (1-11) should not have nullifiers inserted
|
|
264
|
+
const isProtocolCanonicalAddress = address.toBigInt() <= MAX_PROTOCOL_CONTRACTS && address.toBigInt() >= 1n;
|
|
265
|
+
await this.addContractInstance(instance, /* skipNullifierInsertion */ isProtocolCanonicalAddress);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Apply public data tree writes from C++ raw msgpack data.
|
|
270
|
+
* This is used to pre-populate the public data tree before simulation (e.g., for bytecode upgrades).
|
|
271
|
+
*/
|
|
272
|
+
public async applyPublicDataWrites(rawWrites: any[]): Promise<void> {
|
|
273
|
+
for (const rawWrite of rawWrites) {
|
|
274
|
+
const leaf = PublicDataTreeLeaf.fromPlainObject(rawWrite);
|
|
275
|
+
await this.merkleTrees.sequentialInsert(MerkleTreeId.PUBLIC_DATA_TREE, [leaf.toBuffer()]);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Apply note hashes from C++ raw msgpack data.
|
|
281
|
+
* This is used to pre-populate the note hash tree before simulation.
|
|
282
|
+
*/
|
|
283
|
+
public async applyNoteHashes(rawNoteHashes: any[]): Promise<void> {
|
|
284
|
+
const paddingLeaves = MAX_NOTE_HASHES_PER_TX - (rawNoteHashes.length % MAX_NOTE_HASHES_PER_TX);
|
|
285
|
+
const paddedNoteHashes = [...rawNoteHashes, ...Array(paddingLeaves).fill(Fr.ZERO)];
|
|
286
|
+
await this.merkleTrees.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, paddedNoteHashes);
|
|
239
287
|
}
|
|
240
288
|
}
|
|
@@ -3,17 +3,30 @@ import { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
3
3
|
import {
|
|
4
4
|
AvmCircuitPublicInputs,
|
|
5
5
|
type AvmTxHint,
|
|
6
|
+
PublicTxEffect,
|
|
6
7
|
deserializeFromMessagePack,
|
|
7
8
|
serializeWithMessagePack,
|
|
8
9
|
} from '@aztec/stdlib/avm';
|
|
9
|
-
import { GlobalVariables, TreeSnapshots } from '@aztec/stdlib/tx';
|
|
10
|
+
import { GlobalVariables, ProtocolContracts, TreeSnapshots } from '@aztec/stdlib/tx';
|
|
10
11
|
import { NativeWorldStateService } from '@aztec/world-state';
|
|
11
12
|
|
|
12
|
-
import { writeSync } from 'fs';
|
|
13
13
|
import { createInterface } from 'readline';
|
|
14
14
|
|
|
15
15
|
import { AvmFuzzerSimulator, FuzzerSimulationRequest } from './avm_fuzzer_simulator.js';
|
|
16
16
|
|
|
17
|
+
/** Write data to stdout, letting Node handle buffering. */
|
|
18
|
+
function writeOutput(data: string): Promise<void> {
|
|
19
|
+
return new Promise<void>((resolve, reject) => {
|
|
20
|
+
process.stdout.write(data, err => {
|
|
21
|
+
if (err) {
|
|
22
|
+
reject(err);
|
|
23
|
+
} else {
|
|
24
|
+
resolve();
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
17
30
|
// This cache holds opened world states to avoid reopening them for each invocation.
|
|
18
31
|
// It's a map so that in the future we could support multiple world states (if we had multiple fuzzers).
|
|
19
32
|
const worldStateCache = new Map<string, NativeWorldStateService>();
|
|
@@ -43,12 +56,23 @@ async function simulateWithFuzzer(
|
|
|
43
56
|
globals: GlobalVariables,
|
|
44
57
|
rawContractClasses: any[], // Replace these when we are moving contract classes to TS
|
|
45
58
|
rawContractInstances: [any, any][], // Replace these when we are moving contract instances to TS
|
|
46
|
-
|
|
59
|
+
rawPublicDataWrites: any[], // Public data tree writes to apply before simulation
|
|
60
|
+
rawNoteHashes: any[], // Note hashes to apply before simulation
|
|
61
|
+
protocolContracts: ProtocolContracts, // Protocol contracts mapping from C++
|
|
62
|
+
): Promise<{
|
|
63
|
+
reverted: boolean;
|
|
64
|
+
output: Fr[];
|
|
65
|
+
revertReason?: string;
|
|
66
|
+
publicInputs: AvmCircuitPublicInputs;
|
|
67
|
+
publicTxEffect: PublicTxEffect;
|
|
68
|
+
}> {
|
|
47
69
|
const worldStateService = await openExistingWorldState(dataDir, mapSizeKb);
|
|
48
70
|
|
|
49
|
-
const simulator = await AvmFuzzerSimulator.create(worldStateService, globals);
|
|
71
|
+
const simulator = await AvmFuzzerSimulator.create(worldStateService, globals, protocolContracts);
|
|
72
|
+
|
|
73
|
+
await simulator.applyNoteHashes(rawNoteHashes);
|
|
50
74
|
|
|
51
|
-
// Register contract classes from C++
|
|
75
|
+
// Register contract classes from C++ (must happen before public data writes to match C++ order)
|
|
52
76
|
for (const rawClass of rawContractClasses) {
|
|
53
77
|
await simulator.addContractClassFromCpp(rawClass);
|
|
54
78
|
}
|
|
@@ -58,6 +82,10 @@ async function simulateWithFuzzer(
|
|
|
58
82
|
await simulator.addContractInstanceFromCpp(rawAddress, rawInstance);
|
|
59
83
|
}
|
|
60
84
|
|
|
85
|
+
// Apply public data writes after contract registration (e.g., for bytecode upgrades)
|
|
86
|
+
// This must happen last to match C++ setup_fuzzer_state ordering
|
|
87
|
+
await simulator.applyPublicDataWrites(rawPublicDataWrites);
|
|
88
|
+
|
|
61
89
|
const result = await simulator.simulate(txHint);
|
|
62
90
|
|
|
63
91
|
const output = result
|
|
@@ -69,6 +97,7 @@ async function simulateWithFuzzer(
|
|
|
69
97
|
output,
|
|
70
98
|
revertReason: result.findRevertReason()?.message,
|
|
71
99
|
publicInputs: result.publicInputs!,
|
|
100
|
+
publicTxEffect: result.publicTxEffect,
|
|
72
101
|
};
|
|
73
102
|
}
|
|
74
103
|
|
|
@@ -87,6 +116,9 @@ async function execute(base64Line: string): Promise<void> {
|
|
|
87
116
|
request.globals,
|
|
88
117
|
request.contractClasses,
|
|
89
118
|
request.contractInstances,
|
|
119
|
+
request.publicDataWrites,
|
|
120
|
+
request.noteHashes,
|
|
121
|
+
request.protocolContracts,
|
|
90
122
|
);
|
|
91
123
|
|
|
92
124
|
// Serialize the result to msgpack and encode it in base64 for output
|
|
@@ -95,17 +127,20 @@ async function execute(base64Line: string): Promise<void> {
|
|
|
95
127
|
output: result.output,
|
|
96
128
|
revertReason: result.revertReason ?? '',
|
|
97
129
|
endTreeSnapshots: result.publicInputs.endTreeSnapshots,
|
|
130
|
+
publicTxEffect: result.publicTxEffect,
|
|
98
131
|
});
|
|
99
|
-
|
|
132
|
+
const base64Response = resultBuffer.toString('base64') + '\n';
|
|
133
|
+
await writeOutput(base64Response);
|
|
100
134
|
} catch (error: any) {
|
|
101
135
|
// If we error, treat as reverted
|
|
102
136
|
const errorResult = serializeWithMessagePack({
|
|
103
137
|
reverted: true,
|
|
104
|
-
output: [] as
|
|
138
|
+
output: [] as Fr[],
|
|
105
139
|
revertReason: `Unexpected Error ${error.message}`,
|
|
106
140
|
endTreeSnapshots: TreeSnapshots.empty(),
|
|
141
|
+
publicTxEffect: PublicTxEffect.empty(),
|
|
107
142
|
});
|
|
108
|
-
|
|
143
|
+
await writeOutput(errorResult.toString('base64') + '\n');
|
|
109
144
|
}
|
|
110
145
|
}
|
|
111
146
|
|
|
@@ -83,6 +83,7 @@ export class HintingPublicContractsDB implements PublicContractsDBInterface {
|
|
|
83
83
|
instance.currentContractClassId,
|
|
84
84
|
instance.originalContractClassId,
|
|
85
85
|
instance.initializationHash,
|
|
86
|
+
instance.immutablesHash,
|
|
86
87
|
instance.publicKeys,
|
|
87
88
|
),
|
|
88
89
|
);
|
|
@@ -410,12 +411,12 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
|
|
|
410
411
|
}
|
|
411
412
|
}
|
|
412
413
|
|
|
413
|
-
public async createCheckpoint(): Promise<
|
|
414
|
+
public async createCheckpoint(): Promise<number> {
|
|
414
415
|
const actionCounter = this.checkpointActionCounter++;
|
|
415
416
|
const oldCheckpointId = this.getCurrentCheckpointId();
|
|
416
417
|
const treesStateHash = await this.getTreesStateHash();
|
|
417
418
|
|
|
418
|
-
await this.db.createCheckpoint();
|
|
419
|
+
const depth = await this.db.createCheckpoint();
|
|
419
420
|
this.checkpointStack.push(this.nextCheckpointId++);
|
|
420
421
|
const newCheckpointId = this.getCurrentCheckpointId();
|
|
421
422
|
|
|
@@ -424,14 +425,16 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
|
|
|
424
425
|
HintingMerkleWriteOperations.log.trace(
|
|
425
426
|
`[createCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
|
|
426
427
|
);
|
|
428
|
+
|
|
429
|
+
return depth;
|
|
427
430
|
}
|
|
428
431
|
|
|
429
|
-
public
|
|
430
|
-
throw new Error('
|
|
432
|
+
public commitAllCheckpointsTo(_depth: number): Promise<void> {
|
|
433
|
+
throw new Error('commitAllCheckpointsTo is not supported in HintingMerkleWriteOperations.');
|
|
431
434
|
}
|
|
432
435
|
|
|
433
|
-
public
|
|
434
|
-
throw new Error('
|
|
436
|
+
public revertAllCheckpointsTo(_depth: number): Promise<void> {
|
|
437
|
+
throw new Error('revertAllCheckpointsTo is not supported in HintingMerkleWriteOperations.');
|
|
435
438
|
}
|
|
436
439
|
|
|
437
440
|
public async commitCheckpoint(): Promise<void> {
|
|
@@ -572,7 +575,7 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
|
|
|
572
575
|
return await this.db.close();
|
|
573
576
|
}
|
|
574
577
|
|
|
575
|
-
async [Symbol.
|
|
578
|
+
async [Symbol.asyncDispose](): Promise<void> {
|
|
576
579
|
await this.close();
|
|
577
580
|
}
|
|
578
581
|
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
PUBLIC_DATA_SUBTREE_HEIGHT,
|
|
6
6
|
} from '@aztec/constants';
|
|
7
7
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
8
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
8
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
9
9
|
import { Timer } from '@aztec/foundation/timer';
|
|
10
10
|
import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
|
|
11
11
|
import { ContractInstancePublishedEvent } from '@aztec/protocol-contracts/instance-registry';
|
|
@@ -46,14 +46,20 @@ import { L1ToL2MessageIndexOutOfRangeError, NoteHashIndexOutOfRangeError } from
|
|
|
46
46
|
export class PublicContractsDB implements PublicContractsDBInterface {
|
|
47
47
|
private contractStateStack: ContractsDbCheckpoint[] = [new ContractsDbCheckpoint()];
|
|
48
48
|
|
|
49
|
-
private log
|
|
49
|
+
private log: Logger;
|
|
50
50
|
|
|
51
|
-
constructor(
|
|
51
|
+
constructor(
|
|
52
|
+
private dataSource: ContractDataSource,
|
|
53
|
+
bindings?: LoggerBindings,
|
|
54
|
+
) {
|
|
55
|
+
this.log = createLogger('simulator:contracts-data-source', bindings);
|
|
56
|
+
}
|
|
52
57
|
|
|
53
|
-
|
|
58
|
+
/** Parses raw log data from the C++/NAPI bridge and inserts the resulting contracts into the current checkpoint. */
|
|
59
|
+
public addContractsFromLogs(contractDeploymentData: ContractDeploymentData): void {
|
|
54
60
|
const currentState = this.getCurrentState();
|
|
55
61
|
|
|
56
|
-
|
|
62
|
+
this.addContractClassesFromEvents(
|
|
57
63
|
ContractClassPublishedEvent.extractContractClassEvents(contractDeploymentData.getContractClassLogs()),
|
|
58
64
|
currentState,
|
|
59
65
|
);
|
|
@@ -64,10 +70,18 @@ export class PublicContractsDB implements PublicContractsDBInterface {
|
|
|
64
70
|
);
|
|
65
71
|
}
|
|
66
72
|
|
|
67
|
-
public
|
|
73
|
+
public addNewContracts(tx: Tx): void {
|
|
68
74
|
const contractDeploymentData = AllContractDeploymentData.fromTx(tx);
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
this.addContractsFromLogs(contractDeploymentData.getNonRevertibleContractDeploymentData());
|
|
76
|
+
this.addContractsFromLogs(contractDeploymentData.getRevertibleContractDeploymentData());
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Inserts typed contract instances directly into the current checkpoint. */
|
|
80
|
+
public addContracts(contractInstances?: ContractInstanceWithAddress[]): void {
|
|
81
|
+
const currentState = this.getCurrentState();
|
|
82
|
+
for (const instance of contractInstances ?? []) {
|
|
83
|
+
currentState.addInstance(instance.address, instance);
|
|
84
|
+
}
|
|
71
85
|
}
|
|
72
86
|
|
|
73
87
|
/**
|
|
@@ -76,7 +90,7 @@ export class PublicContractsDB implements PublicContractsDBInterface {
|
|
|
76
90
|
*/
|
|
77
91
|
public createCheckpoint(): void {
|
|
78
92
|
const currentState = this.getCurrentState();
|
|
79
|
-
const newState = currentState.
|
|
93
|
+
const newState = currentState.fork();
|
|
80
94
|
this.contractStateStack.push(newState);
|
|
81
95
|
}
|
|
82
96
|
|
|
@@ -169,17 +183,15 @@ export class PublicContractsDB implements PublicContractsDBInterface {
|
|
|
169
183
|
return await this.dataSource.getDebugFunctionName(address, selector);
|
|
170
184
|
}
|
|
171
185
|
|
|
172
|
-
private
|
|
186
|
+
private addContractClassesFromEvents(
|
|
173
187
|
contractClassEvents: ContractClassPublishedEvent[],
|
|
174
188
|
state: ContractsDbCheckpoint,
|
|
175
189
|
) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}),
|
|
182
|
-
);
|
|
190
|
+
for (const event of contractClassEvents) {
|
|
191
|
+
this.log.debug(`Adding class ${event.contractClassId.toString()} to contract state`);
|
|
192
|
+
const contractClass = event.toContractClassPublic();
|
|
193
|
+
state.addClass(event.contractClassId, contractClass);
|
|
194
|
+
}
|
|
183
195
|
}
|
|
184
196
|
|
|
185
197
|
private addContractInstancesFromEvents(
|
|
@@ -208,9 +220,14 @@ export class PublicContractsDB implements PublicContractsDBInterface {
|
|
|
208
220
|
* to decide whether to use hints or not (same with tracing, etc).
|
|
209
221
|
*/
|
|
210
222
|
export class PublicTreesDB implements PublicStateDBInterface {
|
|
211
|
-
private logger
|
|
223
|
+
private logger: Logger;
|
|
212
224
|
|
|
213
|
-
constructor(
|
|
225
|
+
constructor(
|
|
226
|
+
private readonly db: MerkleTreeWriteOperations,
|
|
227
|
+
bindings?: LoggerBindings,
|
|
228
|
+
) {
|
|
229
|
+
this.logger = createLogger('simulator:public-trees-db', bindings);
|
|
230
|
+
}
|
|
214
231
|
|
|
215
232
|
public async storageRead(contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
216
233
|
const timer = new Timer();
|