@aztec/simulator 0.0.1-commit.5476d83 → 0.0.1-commit.59e663cd
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 +2 -0
- package/dest/common/errors.d.ts +8 -2
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.d.ts +2 -2
- package/dest/private/acvm/deserialize.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.js +1 -1
- package/dest/private/acvm/serialize.d.ts +2 -2
- package/dest/private/acvm/serialize.d.ts.map +1 -1
- package/dest/private/acvm/serialize.js +1 -1
- package/dest/private/circuit_recording/circuit_recorder.d.ts +1 -1
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.js +16 -15
- 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 +7 -6
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.js +1 -1
- package/dest/public/avm/avm_gas.d.ts +1 -1
- package/dest/public/avm/avm_gas.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.d.ts +7 -6
- 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 +2 -2
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.js +4 -1
- package/dest/public/avm/avm_simulator.d.ts +4 -3
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +11 -9
- 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 +63 -0
- package/dest/public/avm/errors.d.ts +8 -2
- package/dest/public/avm/errors.d.ts.map +1 -1
- package/dest/public/avm/errors.js +14 -2
- 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 +4 -3
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -2
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +1 -1
- package/dest/public/avm/fixtures/initializers.d.ts +2 -2
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.js +5 -4
- package/dest/public/avm/fixtures/utils.d.ts +4 -3
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
- package/dest/public/avm/fixtures/utils.js +3 -2
- package/dest/public/avm/opcodes/accrued_substate.d.ts +15 -15
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +33 -29
- package/dest/public/avm/opcodes/addressing_mode.js +2 -2
- package/dest/public/avm/opcodes/arithmetic.d.ts +10 -8
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.js +12 -2
- 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 +3 -3
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/contract.js +8 -8
- 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 -4
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.js +17 -8
- 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 +21 -16
- 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 +26 -26
- 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 +6 -6
- 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/revert_reason.d.ts +2 -2
- package/dest/public/avm/revert_reason.d.ts.map +1 -1
- package/dest/public/avm/revert_reason.js +3 -2
- package/dest/public/avm/serialization/bytecode_serialization.d.ts +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.js +9 -6
- package/dest/public/avm/serialization/instruction_serialization.js +1 -1
- package/dest/public/avm/test_utils.d.ts +2 -2
- package/dest/public/avm/test_utils.d.ts.map +1 -1
- package/dest/public/avm/test_utils.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/db_interfaces.d.ts +2 -2
- package/dest/public/db_interfaces.d.ts.map +1 -1
- package/dest/public/debug_fn_name.d.ts +16 -3
- package/dest/public/debug_fn_name.d.ts.map +1 -1
- package/dest/public/debug_fn_name.js +31 -3
- 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 +8 -34
- 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 +5 -69
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +28 -6
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tester.js +36 -12
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +11 -8
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tests.js +83 -18
- package/dest/public/fixtures/index.d.ts +4 -2
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +3 -1
- package/dest/public/fixtures/minimal_public_tx.d.ts +2 -7
- package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
- package/dest/public/fixtures/minimal_public_tx.js +4 -14
- package/dest/public/fixtures/opcode_spammer.d.ts +123 -0
- package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -0
- package/dest/public/fixtures/opcode_spammer.js +1693 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +22 -3
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +50 -13
- package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
- package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
- package/dest/public/fixtures/simple_contract_data_source.js +4 -4
- package/dest/public/fixtures/token_test.d.ts +6 -2
- package/dest/public/fixtures/token_test.d.ts.map +1 -1
- package/dest/public/fixtures/token_test.js +13 -11
- 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 +4 -3
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +60 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +171 -0
- package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
- package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_simulator_bin.js +118 -0
- package/dest/public/hinting_db_sources.d.ts +5 -3
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +7 -2
- package/dest/public/index.d.ts +2 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +1 -1
- package/dest/public/public_db_sources.d.ts +2 -2
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +1 -1
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +4 -2
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
- package/dest/public/public_processor/guarded_merkle_tree.js +5 -0
- package/dest/public/public_processor/public_processor.d.ts +6 -6
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +437 -43
- package/dest/public/public_processor/public_processor_metrics.d.ts +1 -1
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor_metrics.js +12 -45
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +1 -13
- 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 +18 -53
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +21 -34
- 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 +61 -139
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +42 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +86 -0
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +30 -0
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +171 -0
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +22 -0
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +52 -0
- package/dest/public/public_tx_simulator/factories.d.ts +13 -0
- package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/factories.js +28 -0
- package/dest/public/public_tx_simulator/index.d.ts +4 -1
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/index.js +3 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +3 -3
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +2 -2
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +6 -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 +20 -11
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +24 -1
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +2 -2
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +395 -19
- package/dest/public/side_effect_trace.d.ts +3 -2
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +1 -1
- package/dest/public/side_effect_trace_interface.d.ts +2 -2
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/state_manager/nullifiers.d.ts +2 -2
- package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
- package/dest/public/state_manager/public_storage.d.ts +2 -2
- package/dest/public/state_manager/public_storage.d.ts.map +1 -1
- package/dest/public/state_manager/public_storage.js +1 -1
- package/dest/public/state_manager/state_manager.d.ts +7 -2
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +7 -4
- package/package.json +20 -20
- package/src/common/errors.ts +1 -1
- package/src/private/acvm/deserialize.ts +1 -1
- package/src/private/acvm/serialize.ts +1 -1
- package/src/private/circuit_recording/circuit_recorder.ts +17 -16
- 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 +10 -5
- package/src/public/avm/avm_gas.ts +3 -3
- package/src/public/avm/avm_machine_state.ts +7 -6
- package/src/public/avm/avm_memory_types.ts +5 -1
- package/src/public/avm/avm_simulator.ts +16 -10
- package/src/public/avm/calldata.ts +100 -0
- package/src/public/avm/errors.ts +17 -3
- package/src/public/avm/fixtures/avm_simulation_tester.ts +9 -3
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
- package/src/public/avm/fixtures/initializers.ts +5 -4
- package/src/public/avm/fixtures/utils.ts +3 -2
- package/src/public/avm/opcodes/accrued_substate.ts +21 -15
- package/src/public/avm/opcodes/addressing_mode.ts +2 -2
- package/src/public/avm/opcodes/arithmetic.ts +14 -2
- 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 +4 -7
- 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 +15 -6
- package/src/public/avm/opcodes/environment_getters.ts +7 -7
- package/src/public/avm/opcodes/external_calls.ts +17 -15
- package/src/public/avm/opcodes/hashing.ts +16 -10
- package/src/public/avm/opcodes/instruction_impl.ts +2 -2
- package/src/public/avm/opcodes/memory.ts +20 -20
- package/src/public/avm/opcodes/misc.ts +4 -4
- package/src/public/avm/opcodes/storage.ts +30 -22
- package/src/public/avm/revert_reason.ts +6 -3
- package/src/public/avm/serialization/bytecode_serialization.ts +17 -6
- package/src/public/avm/serialization/instruction_serialization.ts +1 -1
- package/src/public/avm/test_utils.ts +1 -1
- package/src/public/contracts_db_checkpoint.ts +1 -1
- package/src/public/db_interfaces.ts +1 -1
- package/src/public/debug_fn_name.ts +39 -5
- package/src/public/executor_metrics.ts +7 -34
- package/src/public/fixtures/amm_test.ts +2 -2
- package/src/public/fixtures/bulk_test.ts +9 -9
- package/src/public/fixtures/custom_bytecode_tester.ts +53 -19
- package/src/public/fixtures/custom_bytecode_tests.ts +111 -18
- package/src/public/fixtures/index.ts +7 -1
- package/src/public/fixtures/minimal_public_tx.ts +6 -15
- package/src/public/fixtures/opcode_spammer.ts +1754 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +69 -13
- package/src/public/fixtures/simple_contract_data_source.ts +8 -9
- package/src/public/fixtures/token_test.ts +18 -9
- package/src/public/fixtures/utils.ts +2 -3
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +288 -0
- package/src/public/fuzzing/avm_simulator_bin.ts +175 -0
- package/src/public/hinting_db_sources.ts +8 -3
- package/src/public/index.ts +7 -1
- package/src/public/public_db_sources.ts +1 -1
- package/src/public/public_processor/guarded_merkle_tree.ts +6 -1
- package/src/public/public_processor/public_processor.ts +46 -29
- package/src/public/public_processor/public_processor_metrics.ts +11 -45
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +19 -60
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +76 -174
- package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +132 -0
- package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +237 -0
- package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +81 -0
- package/src/public/public_tx_simulator/factories.ts +41 -0
- package/src/public/public_tx_simulator/index.ts +3 -0
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +1 -1
- package/src/public/public_tx_simulator/public_tx_context.ts +1 -1
- package/src/public/public_tx_simulator/public_tx_simulator.ts +36 -14
- package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +23 -0
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +1 -1
- package/src/public/side_effect_trace.ts +1 -1
- package/src/public/side_effect_trace_interface.ts +1 -1
- package/src/public/state_manager/nullifiers.ts +1 -1
- package/src/public/state_manager/public_storage.ts +1 -1
- package/src/public/state_manager/state_manager.ts +12 -19
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { type Logger, createLogger, logLevel } from '@aztec/foundation/log';
|
|
2
|
+
import { avmSimulate } from '@aztec/native';
|
|
3
|
+
import { ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
4
|
+
import {
|
|
5
|
+
AvmFastSimulationInputs,
|
|
6
|
+
AvmTxHint,
|
|
7
|
+
type PublicSimulatorConfig,
|
|
8
|
+
PublicTxResult,
|
|
9
|
+
deserializeFromMessagePack,
|
|
10
|
+
} from '@aztec/stdlib/avm';
|
|
11
|
+
import { SimulationError } from '@aztec/stdlib/errors';
|
|
12
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
13
|
+
import type { GlobalVariables, StateReference, Tx } from '@aztec/stdlib/tx';
|
|
14
|
+
import { WorldStateRevisionWithHandle } from '@aztec/stdlib/world-state';
|
|
15
|
+
|
|
16
|
+
import { strict as assert } from 'assert';
|
|
17
|
+
|
|
18
|
+
import type { ExecutorMetricsInterface } from '../executor_metrics_interface.js';
|
|
19
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
20
|
+
import { ContractProviderForCpp } from './contract_provider_for_cpp.js';
|
|
21
|
+
import { PublicTxSimulator } from './public_tx_simulator.js';
|
|
22
|
+
import type {
|
|
23
|
+
MeasuredPublicTxSimulatorInterface,
|
|
24
|
+
PublicTxSimulatorInterface,
|
|
25
|
+
} from './public_tx_simulator_interface.js';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* An implementation of PublicTxSimulator that first simulates in C++, then TS, an compares the results.
|
|
29
|
+
* The C++ simulator accesses the world state directly/natively within C++.
|
|
30
|
+
* For contract DB accesses, it makes callbacks through NAPI back to the TS PublicContractsDB cache.
|
|
31
|
+
*/
|
|
32
|
+
export class CppVsTsPublicTxSimulator extends PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
33
|
+
protected override log: Logger;
|
|
34
|
+
|
|
35
|
+
constructor(
|
|
36
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
37
|
+
contractsDB: PublicContractsDB,
|
|
38
|
+
globalVariables: GlobalVariables,
|
|
39
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
40
|
+
) {
|
|
41
|
+
super(merkleTree, contractsDB, globalVariables, config);
|
|
42
|
+
this.log = createLogger(`simulator:cpp_vs_public_tx_simulator`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Simulate a transaction's public portion using the C++ avvm simulator.
|
|
47
|
+
*
|
|
48
|
+
* @param tx - The transaction to simulate.
|
|
49
|
+
* @returns The result of the transaction's public execution.
|
|
50
|
+
*/
|
|
51
|
+
public override async simulate(tx: Tx): Promise<PublicTxResult> {
|
|
52
|
+
const txHash = this.computeTxHash(tx);
|
|
53
|
+
this.log.debug(`C++ simulation of ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, {
|
|
54
|
+
txHash,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Run TS simulation to generate hints and public inputs
|
|
58
|
+
this.log.debug(`Running TS simulation for tx ${txHash}`);
|
|
59
|
+
|
|
60
|
+
// create checkpoint for ws
|
|
61
|
+
let tsResult: PublicTxResult | undefined;
|
|
62
|
+
let tsStateRef: StateReference | undefined;
|
|
63
|
+
await this.merkleTree.createCheckpoint();
|
|
64
|
+
this.contractsDB.createCheckpoint();
|
|
65
|
+
try {
|
|
66
|
+
// Run the full TypeScript simulation using the parent class
|
|
67
|
+
// This will modify the merkle tree with the transaction's state changes
|
|
68
|
+
tsResult = await super.simulate(tx);
|
|
69
|
+
this.log.debug(`TS simulation completed for tx ${txHash}`);
|
|
70
|
+
|
|
71
|
+
tsStateRef = await this.merkleTree.getStateReference(); // capture tree roots for later comparsion
|
|
72
|
+
} catch (error: any) {
|
|
73
|
+
this.log.warn(`TS simulation failed, but still continuing with C++ simulation: ${error.message} ${error.stack}`);
|
|
74
|
+
} finally {
|
|
75
|
+
// revert checkpoint for ws and clear contract db changes
|
|
76
|
+
// (cpp should reapply exactly the same changes if there are no bugs)
|
|
77
|
+
await this.merkleTree.revertCheckpoint();
|
|
78
|
+
this.contractsDB.revertCheckpoint();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
this.log.debug(`Running C++ simulation for tx ${txHash}`);
|
|
82
|
+
|
|
83
|
+
// Using the "as WorldStateRevisionWithHandle" is a bit of a "trust me bro", hence the assert.
|
|
84
|
+
let wsRevision = this.merkleTree.getRevision();
|
|
85
|
+
assert(
|
|
86
|
+
wsRevision instanceof WorldStateRevisionWithHandle,
|
|
87
|
+
'CppPublicTxSimulator a real NativeWorldStateInstance with a handle to the C++ WorldState object',
|
|
88
|
+
);
|
|
89
|
+
const wsCppHandle = (wsRevision as WorldStateRevisionWithHandle).handle;
|
|
90
|
+
wsRevision = wsRevision.toWorldStateRevision(); // for msgpack serialization, we don't include the handle in the type
|
|
91
|
+
|
|
92
|
+
this.log.debug(`Running C++ simulation with world state revision ${JSON.stringify(wsRevision)}`);
|
|
93
|
+
|
|
94
|
+
// Create the fast simulation inputs
|
|
95
|
+
const txHint = AvmTxHint.fromTx(tx, this.globalVariables.gasFees);
|
|
96
|
+
const protocolContracts = ProtocolContractsList;
|
|
97
|
+
const fastSimInputs = new AvmFastSimulationInputs(
|
|
98
|
+
wsRevision,
|
|
99
|
+
this.config,
|
|
100
|
+
txHint,
|
|
101
|
+
this.globalVariables,
|
|
102
|
+
protocolContracts,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
// Create contract provider for callbacks to TypeScript PublicContractsDB from C++
|
|
106
|
+
const contractProvider = new ContractProviderForCpp(this.contractsDB, this.globalVariables);
|
|
107
|
+
|
|
108
|
+
// Serialize to msgpack and call the C++ simulator
|
|
109
|
+
this.log.debug(`Serializing fast simulation inputs to msgpack...`);
|
|
110
|
+
const inputBuffer = fastSimInputs.serializeWithMessagePack();
|
|
111
|
+
|
|
112
|
+
let resultBuffer: Buffer;
|
|
113
|
+
try {
|
|
114
|
+
this.log.debug(`Calling C++ simulator for tx ${txHash}`);
|
|
115
|
+
resultBuffer = await avmSimulate(inputBuffer, contractProvider, wsCppHandle, logLevel);
|
|
116
|
+
} catch (error: any) {
|
|
117
|
+
throw new SimulationError(`C++ simulation failed: ${error.message}`, []);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// If we've reached this point, C++ succeeded during simulation,
|
|
121
|
+
// so we assert that TS also succeeded.
|
|
122
|
+
assert(tsResult !== undefined, 'TS simulation should have succeeded if C++ succeeded');
|
|
123
|
+
assert(tsStateRef !== undefined, 'TS state reference should have been captured if C++ succeeded');
|
|
124
|
+
|
|
125
|
+
// Deserialize the msgpack result
|
|
126
|
+
this.log.debug(`Deserializing C++ from buffer (size: ${resultBuffer.length})...`);
|
|
127
|
+
const cppResultJSON: object = deserializeFromMessagePack(resultBuffer);
|
|
128
|
+
this.log.debug(`Deserializing C++ result to PublicTxResult...`);
|
|
129
|
+
const cppResult = PublicTxResult.fromPlainObject(cppResultJSON);
|
|
130
|
+
this.log.debug(`Done.`);
|
|
131
|
+
assert(cppResult.revertCode.equals(tsResult.revertCode));
|
|
132
|
+
assert(cppResult.gasUsed.totalGas.equals(tsResult.gasUsed.totalGas));
|
|
133
|
+
assert(cppResult.gasUsed.publicGas.equals(tsResult.gasUsed.publicGas));
|
|
134
|
+
assert(cppResult.gasUsed.teardownGas.equals(tsResult.gasUsed.teardownGas));
|
|
135
|
+
assert(cppResult.gasUsed.billedGas.equals(tsResult.gasUsed.billedGas));
|
|
136
|
+
assert(cppResult.publicTxEffect.equals(tsResult.publicTxEffect));
|
|
137
|
+
if (cppResult.publicInputs !== undefined) {
|
|
138
|
+
assert(cppResult.publicInputs!.toBuffer().equals(tsResult.publicInputs!.toBuffer()));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// TODO(fcarreiro): complete this.
|
|
142
|
+
// Check that C++ hints are a strict subset of TS hints.
|
|
143
|
+
// Then enable for misc tests and validate hints.
|
|
144
|
+
//if (this.config?.collectHints) {
|
|
145
|
+
//}
|
|
146
|
+
|
|
147
|
+
if (this.config?.collectCallMetadata) {
|
|
148
|
+
assert(cppResult.getAppLogicReturnValues().length === tsResult.getAppLogicReturnValues().length);
|
|
149
|
+
for (let i = 0; i < cppResult.getAppLogicReturnValues().length; i++) {
|
|
150
|
+
assert(cppResult.getAppLogicReturnValues()[i].equals(tsResult.getAppLogicReturnValues()[i]));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Messages are still not ok for exceptional halts (they are not plumbed in C++).
|
|
154
|
+
const cppRevertReason = cppResult.findRevertReason() || {};
|
|
155
|
+
const tsRevertReason = tsResult.findRevertReason() || {};
|
|
156
|
+
const cppRevertReasonAsObject = JSON.parse(JSON.stringify(cppRevertReason));
|
|
157
|
+
const tsRevertReasonAsObject = JSON.parse(JSON.stringify(tsRevertReason));
|
|
158
|
+
if (JSON.stringify(cppRevertReasonAsObject) !== JSON.stringify(tsRevertReasonAsObject)) {
|
|
159
|
+
this.log.debug('cppResult.findRevertReason()', cppRevertReasonAsObject);
|
|
160
|
+
this.log.debug('tsResult.findRevertReason()', tsRevertReasonAsObject);
|
|
161
|
+
}
|
|
162
|
+
// TODO: dont compare the strings since this is not deterministic.
|
|
163
|
+
|
|
164
|
+
// Sometimes error messages are different between C++ and TS, so we omit in the default comparison
|
|
165
|
+
const cppRevertReasonWithoutMessage = { ...cppRevertReasonAsObject, originalMessage: undefined };
|
|
166
|
+
const tsRevertReasonWithoutMessage = { ...tsRevertReasonAsObject, originalMessage: undefined };
|
|
167
|
+
assert(JSON.stringify(cppRevertReasonWithoutMessage) === JSON.stringify(tsRevertReasonWithoutMessage));
|
|
168
|
+
|
|
169
|
+
const cppHasRevertMessage =
|
|
170
|
+
cppRevertReasonAsObject.originalMessage && cppRevertReasonAsObject.originalMessage.length > 0;
|
|
171
|
+
const tsHasRevertMessage =
|
|
172
|
+
tsRevertReasonAsObject.originalMessage && tsRevertReasonAsObject.originalMessage.length > 0;
|
|
173
|
+
// assert that if one of the error messages is non-empty, the other is
|
|
174
|
+
assert(
|
|
175
|
+
cppHasRevertMessage === tsHasRevertMessage,
|
|
176
|
+
'One of the AVM simulators (C++ or TS) produced a revert message, but the other did not',
|
|
177
|
+
);
|
|
178
|
+
// Ideally, we'd love to be able to compare full error messages, but without a lot of work
|
|
179
|
+
// the two simulators will always be able to produce some differing errors.
|
|
180
|
+
// Commenting out the code below will enforce that the error messages are at least
|
|
181
|
+
// similar (one contains the other). Even this is not something we can guarantee.
|
|
182
|
+
//if (cppHasRevertMessage) {
|
|
183
|
+
// const cppRevertMessageContainsTs = cppRevertReasonAsObject.originalMessage.includes(
|
|
184
|
+
// tsRevertReasonAsObject.originalMessage,
|
|
185
|
+
// );
|
|
186
|
+
// const tsRevertMessageContainsCpp = tsRevertReasonAsObject.originalMessage.includes(
|
|
187
|
+
// cppRevertReasonAsObject.originalMessage,
|
|
188
|
+
// );
|
|
189
|
+
// assert(
|
|
190
|
+
// cppRevertMessageContainsTs || tsRevertMessageContainsCpp,
|
|
191
|
+
// 'The AVM simulators (C++ and TS) produced different revert messages (neither was a substring of the other)',
|
|
192
|
+
// );
|
|
193
|
+
//}
|
|
194
|
+
|
|
195
|
+
// Confirm that tree roots match
|
|
196
|
+
const cppStateRef = await this.merkleTree.getStateReference();
|
|
197
|
+
assert(
|
|
198
|
+
cppStateRef.equals(tsStateRef),
|
|
199
|
+
`Tree roots mismatch between TS and C++ public simulations for tx ${txHash}`,
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
this.log.debug(`C++ simulation completed for tx ${txHash}`, {
|
|
203
|
+
txHash,
|
|
204
|
+
reverted: !cppResult.revertCode.isOK(),
|
|
205
|
+
cppGasUsed: cppResult.gasUsed.totalGas.l2Gas,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
// Return cpp result as it has more detailed metadata / revert reasons
|
|
209
|
+
return cppResult;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export class MeasuredCppVsTsPublicTxSimulator
|
|
214
|
+
extends CppVsTsPublicTxSimulator
|
|
215
|
+
implements MeasuredPublicTxSimulatorInterface
|
|
216
|
+
{
|
|
217
|
+
constructor(
|
|
218
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
219
|
+
contractsDB: PublicContractsDB,
|
|
220
|
+
globalVariables: GlobalVariables,
|
|
221
|
+
protected readonly metrics: ExecutorMetricsInterface,
|
|
222
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
223
|
+
) {
|
|
224
|
+
super(merkleTree, contractsDB, globalVariables, config);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
public override async simulate(tx: Tx, txLabel: string = 'unlabeledTx'): Promise<PublicTxResult> {
|
|
228
|
+
this.metrics.startRecordingTxSimulation(txLabel);
|
|
229
|
+
let result: PublicTxResult | undefined;
|
|
230
|
+
try {
|
|
231
|
+
result = await super.simulate(tx);
|
|
232
|
+
} finally {
|
|
233
|
+
this.metrics.stopRecordingTxSimulation(txLabel, result?.gasUsed, result?.revertCode);
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AvmCircuitInputs,
|
|
3
|
+
AvmCircuitPublicInputs,
|
|
4
|
+
AvmExecutionHints,
|
|
5
|
+
type PublicSimulatorConfig,
|
|
6
|
+
PublicTxResult,
|
|
7
|
+
serializeWithMessagePack,
|
|
8
|
+
} from '@aztec/stdlib/avm';
|
|
9
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
10
|
+
import type { GlobalVariables, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
11
|
+
|
|
12
|
+
import { strict as assert } from 'assert';
|
|
13
|
+
import { mkdirSync, writeFileSync } from 'fs';
|
|
14
|
+
import { join } from 'path';
|
|
15
|
+
|
|
16
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
17
|
+
import { CppPublicTxSimulator } from './cpp_public_tx_simulator.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A C++ public tx simulator that dumps AVM circuit inputs to disk after simulation.
|
|
21
|
+
* Used during nightly CI runs to collect circuit inputs for benchmarking.
|
|
22
|
+
*/
|
|
23
|
+
export class DumpingCppPublicTxSimulator extends CppPublicTxSimulator {
|
|
24
|
+
private readonly outputDir: string;
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
28
|
+
contractsDB: PublicContractsDB,
|
|
29
|
+
globalVariables: GlobalVariables,
|
|
30
|
+
config: Partial<PublicSimulatorConfig>,
|
|
31
|
+
outputDir: string,
|
|
32
|
+
) {
|
|
33
|
+
super(merkleTree, contractsDB, globalVariables, config);
|
|
34
|
+
assert(config.collectHints === true, 'collectHints must be enabled to dump AVM circuit inputs');
|
|
35
|
+
assert(config.collectPublicInputs === true, 'collectPublicInputs must be enabled to dump AVM circuit inputs');
|
|
36
|
+
this.outputDir = outputDir;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public override async simulate(tx: Tx): Promise<PublicTxResult> {
|
|
40
|
+
const result = await super.simulate(tx);
|
|
41
|
+
|
|
42
|
+
// Dump the circuit inputs after successful simulation
|
|
43
|
+
const txHash = this.computeTxHash(tx);
|
|
44
|
+
this.dumpAvmCircuitInputs(result, txHash);
|
|
45
|
+
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Dumps AVM circuit inputs to disk.
|
|
51
|
+
*
|
|
52
|
+
* @param result - The simulation result containing hints and public inputs
|
|
53
|
+
* @param txHash - The transaction hash to use in the filename
|
|
54
|
+
*/
|
|
55
|
+
private dumpAvmCircuitInputs(result: PublicTxResult, txHash: TxHash): void {
|
|
56
|
+
try {
|
|
57
|
+
// Ensure the output directory exists
|
|
58
|
+
mkdirSync(this.outputDir, { recursive: true });
|
|
59
|
+
|
|
60
|
+
// Generate filename using transaction hash
|
|
61
|
+
const filename = `avm-circuit-inputs-tx-${txHash.toString()}.bin`;
|
|
62
|
+
const filepath = join(this.outputDir, filename);
|
|
63
|
+
|
|
64
|
+
// Create circuit inputs from the result
|
|
65
|
+
const hints = result.hints ?? AvmExecutionHints.empty();
|
|
66
|
+
const publicInputs = result.publicInputs ?? AvmCircuitPublicInputs.empty();
|
|
67
|
+
const avmCircuitInputs = new AvmCircuitInputs(hints, publicInputs);
|
|
68
|
+
|
|
69
|
+
// Serialize the circuit inputs using MessagePack
|
|
70
|
+
const serialized = serializeWithMessagePack(avmCircuitInputs);
|
|
71
|
+
|
|
72
|
+
// Write to disk
|
|
73
|
+
writeFileSync(filepath, serialized);
|
|
74
|
+
|
|
75
|
+
this.log.debug(`Dumped AVM circuit inputs to ${filepath}`);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
// Non-blocking error handling - log but don't interrupt processing
|
|
78
|
+
this.log.warn(`Failed to dump AVM circuit inputs for tx ${txHash.toString()}: ${error}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
2
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
3
|
+
import type { GlobalVariables } from '@aztec/stdlib/tx';
|
|
4
|
+
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
5
|
+
|
|
6
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
7
|
+
import { TelemetryCppPublicTxSimulator } from './cpp_public_tx_simulator.js';
|
|
8
|
+
import { DumpingCppPublicTxSimulator } from './dumping_cpp_public_tx_simulator.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates a public tx simulator for block building.
|
|
12
|
+
* Uses DumpingCppPublicTxSimulator if DUMP_AVM_INPUTS_TO_DIR env var is set (for CI/testing avm circuit),
|
|
13
|
+
* otherwise uses TelemetryCppPublicTxSimulator (for production).
|
|
14
|
+
*/
|
|
15
|
+
export function createPublicTxSimulatorForBlockBuilding(
|
|
16
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
17
|
+
contractsDB: PublicContractsDB,
|
|
18
|
+
globalVariables: GlobalVariables,
|
|
19
|
+
telemetryClient: TelemetryClient,
|
|
20
|
+
) {
|
|
21
|
+
const config = PublicSimulatorConfig.from({
|
|
22
|
+
skipFeeEnforcement: false,
|
|
23
|
+
collectDebugLogs: false,
|
|
24
|
+
collectHints: false,
|
|
25
|
+
collectPublicInputs: false,
|
|
26
|
+
collectStatistics: false,
|
|
27
|
+
collectCallMetadata: false,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const dumpDir = process.env.DUMP_AVM_INPUTS_TO_DIR;
|
|
31
|
+
if (dumpDir) {
|
|
32
|
+
// must collect hints and PIs for dumping
|
|
33
|
+
const dumpingConfig = {
|
|
34
|
+
...config,
|
|
35
|
+
collectHints: true,
|
|
36
|
+
collectPublicInputs: true,
|
|
37
|
+
};
|
|
38
|
+
return new DumpingCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, dumpingConfig, dumpDir);
|
|
39
|
+
}
|
|
40
|
+
return new TelemetryCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, telemetryClient, config);
|
|
41
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export * from './public_tx_simulator.js';
|
|
2
|
+
export { CppPublicTxSimulator, TelemetryCppPublicTxSimulator } from './cpp_public_tx_simulator.js';
|
|
3
|
+
export { DumpingCppPublicTxSimulator } from './dumping_cpp_public_tx_simulator.js';
|
|
4
|
+
export { createPublicTxSimulatorForBlockBuilding } from './factories.js';
|
|
2
5
|
export type { PublicTxSimulatorInterface } from './public_tx_simulator_interface.js';
|
|
3
6
|
export { TelemetryPublicTxSimulator } from './telemetry_public_tx_simulator.js';
|
|
4
7
|
export type { PublicTxResult, PublicSimulatorConfig as PublicTxSimulatorConfig } from '@aztec/stdlib/avm';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { Timer } from '@aztec/foundation/timer';
|
|
3
3
|
import type { PublicSimulatorConfig, PublicTxResult } from '@aztec/stdlib/avm';
|
|
4
4
|
import type { Gas } from '@aztec/stdlib/gas';
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
7
7
|
} from '@aztec/constants';
|
|
8
8
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
9
|
-
import { Fr } from '@aztec/foundation/
|
|
9
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
10
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
11
11
|
import {
|
|
12
12
|
AvmAccumulatedData,
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { AVM_MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { ProtocolContractAddress, ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
5
5
|
import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
6
|
-
import { AvmExecutionHints, AvmTxHint, PublicSimulatorConfig, PublicTxResult } from '@aztec/stdlib/avm';
|
|
6
|
+
import { AvmExecutionHints, AvmTxHint, PublicSimulatorConfig, PublicTxEffect, PublicTxResult } from '@aztec/stdlib/avm';
|
|
7
7
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
8
|
-
import
|
|
8
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
9
9
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
10
10
|
import {
|
|
11
11
|
type GlobalVariables,
|
|
12
12
|
NestedProcessReturnValues,
|
|
13
|
+
ProtocolContracts,
|
|
13
14
|
PublicCallRequestWithCalldata,
|
|
14
15
|
Tx,
|
|
15
16
|
TxExecutionPhase,
|
|
@@ -18,6 +19,7 @@ import {
|
|
|
18
19
|
import { strict as assert } from 'assert';
|
|
19
20
|
|
|
20
21
|
import type { AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
|
|
22
|
+
import { CallDataArray } from '../avm/calldata.js';
|
|
21
23
|
import { AvmSimulator } from '../avm/index.js';
|
|
22
24
|
import { getPublicFunctionDebugName } from '../debug_fn_name.js';
|
|
23
25
|
import { HintingMerkleWriteOperations, HintingPublicContractsDB } from '../hinting_db_sources.js';
|
|
@@ -85,6 +87,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
85
87
|
protected contractsDB: PublicContractsDB,
|
|
86
88
|
protected globalVariables: GlobalVariables,
|
|
87
89
|
config?: Partial<PublicSimulatorConfig>,
|
|
90
|
+
protected protocolContracts: ProtocolContracts = ProtocolContractsList,
|
|
88
91
|
) {
|
|
89
92
|
this.config = PublicSimulatorConfig.from(config ?? {});
|
|
90
93
|
this.log = createLogger(`simulator:public_tx_simulator`);
|
|
@@ -103,7 +106,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
103
106
|
const hints = new AvmExecutionHints(
|
|
104
107
|
this.globalVariables,
|
|
105
108
|
AvmTxHint.fromTx(tx, this.globalVariables.gasFees),
|
|
106
|
-
|
|
109
|
+
this.protocolContracts,
|
|
107
110
|
);
|
|
108
111
|
const hintingMerkleTree = await HintingMerkleWriteOperations.create(this.merkleTree, hints);
|
|
109
112
|
const hintingTreesDB = new PublicTreesDB(hintingMerkleTree);
|
|
@@ -114,7 +117,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
114
117
|
hintingContractsDB,
|
|
115
118
|
tx,
|
|
116
119
|
this.globalVariables,
|
|
117
|
-
|
|
120
|
+
this.protocolContracts,
|
|
118
121
|
this.config.proverId,
|
|
119
122
|
);
|
|
120
123
|
|
|
@@ -129,7 +132,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
129
132
|
const setupResult = await this.simulatePhase(TxExecutionPhase.SETUP, context);
|
|
130
133
|
if (setupResult.reverted) {
|
|
131
134
|
throw new Error(
|
|
132
|
-
`
|
|
135
|
+
`[SETUP] UNRECOVERABLE ERROR! The transaction will be thrown out. ${setupResult.revertReason?.message}`,
|
|
133
136
|
);
|
|
134
137
|
}
|
|
135
138
|
processedPhases.push(setupResult);
|
|
@@ -200,10 +203,25 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
200
203
|
const publicInputs = await context.generateAvmCircuitPublicInputs();
|
|
201
204
|
const revertCode = context.getFinalRevertCode();
|
|
202
205
|
|
|
203
|
-
// We only return the app logic phase information.
|
|
204
|
-
const appLogicReturnValues =
|
|
206
|
+
// We only return the app logic phase information, and only 1 per phase.
|
|
207
|
+
const appLogicReturnValues: NestedProcessReturnValues[] =
|
|
205
208
|
processedPhases.find(({ phase }) => phase === TxExecutionPhase.APP_LOGIC)?.returnValues ?? [];
|
|
206
209
|
|
|
210
|
+
// TODO(fcarreiro): This is a temporary backwards compatibility layer until we migrate to the C++ simulator.
|
|
211
|
+
if (context.revertReason !== undefined) {
|
|
212
|
+
(appLogicReturnValues as any).revertReason = context.revertReason;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Create PublicTxEffect from PublicInputs.
|
|
216
|
+
const publicTxEffect = new PublicTxEffect(
|
|
217
|
+
publicInputs.transactionFee,
|
|
218
|
+
publicInputs.accumulatedData.noteHashes.filter(h => !h.isEmpty()),
|
|
219
|
+
publicInputs.accumulatedData.nullifiers.filter(n => !n.isEmpty()),
|
|
220
|
+
publicInputs.accumulatedData.l2ToL1Msgs.filter(m => !m.isEmpty()),
|
|
221
|
+
publicInputs.accumulatedData.publicLogs.toLogs(),
|
|
222
|
+
publicInputs.accumulatedData.publicDataWrites.filter(w => !w.isEmpty()),
|
|
223
|
+
);
|
|
224
|
+
|
|
207
225
|
return new PublicTxResult(
|
|
208
226
|
/*gasUsed=*/ {
|
|
209
227
|
totalGas: context.getActualGasUsed(),
|
|
@@ -212,8 +230,8 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
212
230
|
billedGas: context.getTotalGasUsed(),
|
|
213
231
|
},
|
|
214
232
|
/*revertCode=*/ revertCode,
|
|
215
|
-
/*
|
|
216
|
-
/*
|
|
233
|
+
/*publicTxEffect=*/ publicTxEffect,
|
|
234
|
+
/*callStackMetadata=*/ appLogicReturnValues,
|
|
217
235
|
/*logs=*/ context.state.getActiveStateManager().getLogs(),
|
|
218
236
|
/*hints=*/ hints,
|
|
219
237
|
/*publicInputs=*/ publicInputs,
|
|
@@ -250,7 +268,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
250
268
|
|
|
251
269
|
const enqueuedCallResult = await this.simulateEnqueuedCall(phase, context, callRequest);
|
|
252
270
|
|
|
253
|
-
returnValues.push(new NestedProcessReturnValues(enqueuedCallResult.output));
|
|
271
|
+
returnValues.push(new NestedProcessReturnValues(enqueuedCallResult.output.bestEffortReadAll()));
|
|
254
272
|
|
|
255
273
|
if (enqueuedCallResult.reverted) {
|
|
256
274
|
reverted = true;
|
|
@@ -280,7 +298,11 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
280
298
|
): Promise<AvmFinalizedCallResult> {
|
|
281
299
|
const stateManager = context.state.getActiveStateManager();
|
|
282
300
|
const contractAddress = callRequest.request.contractAddress;
|
|
283
|
-
const fnName = await getPublicFunctionDebugName(
|
|
301
|
+
const fnName = await getPublicFunctionDebugName(
|
|
302
|
+
this.contractsDB,
|
|
303
|
+
contractAddress,
|
|
304
|
+
new CallDataArray(callRequest.calldata),
|
|
305
|
+
);
|
|
284
306
|
|
|
285
307
|
const allocatedGas = context.getGasLeftAtPhase(phase);
|
|
286
308
|
|
|
@@ -299,7 +321,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
299
321
|
);
|
|
300
322
|
|
|
301
323
|
if (result.reverted) {
|
|
302
|
-
const culprit = `${contractAddress}:${
|
|
324
|
+
const culprit = `${contractAddress}:${fnName}`;
|
|
303
325
|
context.revert(phase, result.revertReason, culprit);
|
|
304
326
|
}
|
|
305
327
|
|
|
@@ -340,7 +362,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
340
362
|
transactionFee,
|
|
341
363
|
this.globalVariables,
|
|
342
364
|
request.isStaticCall,
|
|
343
|
-
calldata,
|
|
365
|
+
new CallDataArray(calldata),
|
|
344
366
|
allocatedGas,
|
|
345
367
|
this.config,
|
|
346
368
|
);
|
|
@@ -3,8 +3,31 @@ import type { Tx } from '@aztec/stdlib/tx';
|
|
|
3
3
|
|
|
4
4
|
export interface PublicTxSimulatorInterface {
|
|
5
5
|
simulate(tx: Tx): Promise<PublicTxResult>;
|
|
6
|
+
/**
|
|
7
|
+
* Cancel the current simulation if one is in progress.
|
|
8
|
+
* This signals the underlying simulator (e.g., C++) to stop at the next safe point.
|
|
9
|
+
* Safe to call even if no simulation is in progress.
|
|
10
|
+
* Optional - not all implementations support cancellation.
|
|
11
|
+
*
|
|
12
|
+
* @param waitTimeoutMs - If provided, wait up to this many ms for the simulation to actually stop.
|
|
13
|
+
* This is important because signaling cancellation doesn't immediately stop C++ -
|
|
14
|
+
* it only sets a flag that C++ checks at certain points. If C++ is in the middle
|
|
15
|
+
* of a slow operation (e.g., pad_trees), it won't stop until that completes.
|
|
16
|
+
* @returns Promise that resolves when cancellation is signaled (and optionally when simulation stops)
|
|
17
|
+
*/
|
|
18
|
+
cancel?(waitTimeoutMs?: number): Promise<void>;
|
|
6
19
|
}
|
|
7
20
|
|
|
8
21
|
export interface MeasuredPublicTxSimulatorInterface {
|
|
9
22
|
simulate(tx: Tx, txLabel: string): Promise<PublicTxResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Cancel the current simulation if one is in progress.
|
|
25
|
+
* This signals the underlying simulator (e.g., C++) to stop at the next safe point.
|
|
26
|
+
* Safe to call even if no simulation is in progress.
|
|
27
|
+
* Optional - not all implementations support cancellation.
|
|
28
|
+
*
|
|
29
|
+
* @param waitTimeoutMs - If provided, wait up to this many ms for the simulation to actually stop.
|
|
30
|
+
* @returns Promise that resolves when cancellation is signaled (and optionally when simulation stops)
|
|
31
|
+
*/
|
|
32
|
+
cancel?(waitTimeoutMs?: number): Promise<void>;
|
|
10
33
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
3
3
|
import type { Gas } from '@aztec/stdlib/gas';
|
|
4
4
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
8
8
|
PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
9
9
|
} from '@aztec/constants';
|
|
10
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
11
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
11
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
12
12
|
import { type LogLevel, createLogger } from '@aztec/foundation/log';
|
|
13
13
|
import { PublicDataUpdateRequest } from '@aztec/stdlib/avm';
|
|
14
14
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { LogLevel } from '@aztec/foundation/log';
|
|
3
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import type { DebugLog } from '@aztec/stdlib/logs';
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS,
|
|
5
|
-
FEE_JUICE_ADDRESS,
|
|
6
|
-
MULTI_CALL_ENTRYPOINT_ADDRESS,
|
|
7
|
-
ROUTER_ADDRESS,
|
|
8
|
-
} from '@aztec/constants';
|
|
9
|
-
import { poseidon2Hash } from '@aztec/foundation/crypto';
|
|
10
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
1
|
+
import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS, MAX_PROTOCOL_CONTRACTS } from '@aztec/constants';
|
|
2
|
+
import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
11
4
|
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
12
5
|
import { type LogLevel, createLogger } from '@aztec/foundation/log';
|
|
13
6
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
7
|
+
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
14
8
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
9
|
import type { ContractClassPublicWithCommitment, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
16
10
|
import { SerializableContractInstance } from '@aztec/stdlib/contract';
|
|
@@ -26,7 +20,7 @@ import { strict as assert } from 'assert';
|
|
|
26
20
|
|
|
27
21
|
import type { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
|
|
28
22
|
import type { PublicContractsDBInterface } from '../db_interfaces.js';
|
|
29
|
-
import { getPublicFunctionDebugName } from '../debug_fn_name.js';
|
|
23
|
+
import { getPublicFunctionDebugName, getPublicFunctionSelectorAndName } from '../debug_fn_name.js';
|
|
30
24
|
import type { PublicTreesDB } from '../public_db_sources.js';
|
|
31
25
|
import {
|
|
32
26
|
L1ToL2MessageIndexOutOfRangeError,
|
|
@@ -532,6 +526,12 @@ export class PublicPersistableStateManager {
|
|
|
532
526
|
return await getPublicFunctionDebugName(this.contractsDB, avmEnvironment.address, avmEnvironment.calldata);
|
|
533
527
|
}
|
|
534
528
|
|
|
529
|
+
public async getPublicFunctionSelectorAndName(
|
|
530
|
+
avmEnvironment: AvmExecutionEnvironment,
|
|
531
|
+
): Promise<{ functionSelector?: FunctionSelector; functionName?: string }> {
|
|
532
|
+
return await getPublicFunctionSelectorAndName(this.contractsDB, avmEnvironment.address, avmEnvironment.calldata);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
535
|
public async padTree(treeId: MerkleTreeId, leavesToInsert: number): Promise<void> {
|
|
536
536
|
await this.treesDB.padTree(treeId, leavesToInsert);
|
|
537
537
|
}
|
|
@@ -542,12 +542,5 @@ export class PublicPersistableStateManager {
|
|
|
542
542
|
}
|
|
543
543
|
|
|
544
544
|
function contractAddressIsCanonical(contractAddress: AztecAddress): boolean {
|
|
545
|
-
return (
|
|
546
|
-
contractAddress.equals(AztecAddress.fromNumber(CANONICAL_AUTH_REGISTRY_ADDRESS)) ||
|
|
547
|
-
contractAddress.equals(AztecAddress.fromNumber(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS)) ||
|
|
548
|
-
contractAddress.equals(AztecAddress.fromNumber(CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS)) ||
|
|
549
|
-
contractAddress.equals(AztecAddress.fromNumber(MULTI_CALL_ENTRYPOINT_ADDRESS)) ||
|
|
550
|
-
contractAddress.equals(AztecAddress.fromNumber(FEE_JUICE_ADDRESS)) ||
|
|
551
|
-
contractAddress.equals(AztecAddress.fromNumber(ROUTER_ADDRESS))
|
|
552
|
-
);
|
|
545
|
+
return contractAddress.toBigInt() >= 1 && contractAddress.toBigInt() <= MAX_PROTOCOL_CONTRACTS;
|
|
553
546
|
}
|