@aztec/simulator 4.0.0-nightly.20250907 → 4.0.0-nightly.20260108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client.d.ts +1 -1
- package/dest/common/errors.d.ts +2 -8
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/common/index.d.ts +1 -1
- package/dest/common/stats/index.d.ts +1 -1
- package/dest/common/stats/stats.d.ts +1 -1
- package/dest/private/acvm/acvm.d.ts +1 -1
- package/dest/private/acvm/acvm_types.d.ts +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/index.d.ts +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/acvm_native.d.ts +2 -3
- package/dest/private/acvm_native.d.ts.map +1 -1
- package/dest/private/acvm_native.js +15 -13
- package/dest/private/acvm_wasm.d.ts +1 -1
- package/dest/private/acvm_wasm.d.ts.map +1 -1
- package/dest/private/acvm_wasm_with_blobs.d.ts +1 -1
- package/dest/private/acvm_wasm_with_blobs.d.ts.map +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/private/circuit_recording/file_circuit_recorder.d.ts +1 -1
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +1 -1
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +2 -2
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
- package/dest/private/circuit_simulator.d.ts +1 -1
- package/dest/private/factory.d.ts +1 -1
- package/dest/public/avm/avm_context.d.ts +2 -2
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts +2 -2
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.d.ts +5 -4
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.js +5 -5
- package/dest/public/avm/avm_gas.d.ts +2 -2
- package/dest/public/avm/avm_gas.d.ts.map +1 -1
- package/dest/public/avm/avm_gas.js +2 -2
- package/dest/public/avm/avm_machine_state.d.ts +2 -2
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.d.ts +20 -14
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.js +10 -3
- 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 +19 -25
- package/dest/public/avm/avm_simulator_interface.d.ts +1 -1
- package/dest/public/avm/errors.d.ts +13 -16
- package/dest/public/avm/errors.d.ts.map +1 -1
- package/dest/public/avm/errors.js +21 -22
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +3 -2
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +14 -6
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +4 -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 +23 -1
- package/dest/public/avm/fixtures/initializers.d.ts +2 -3
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.js +6 -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/index.d.ts +1 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts +3 -3
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +8 -8
- package/dest/public/avm/opcodes/addressing_mode.d.ts +1 -1
- package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/public/avm/opcodes/addressing_mode.js +4 -5
- 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 +11 -1
- package/dest/public/avm/opcodes/bitwise.d.ts +5 -5
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
- 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/contract.d.ts +1 -1
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/control_flow.d.ts +1 -1
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.d.ts +1 -1
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.js +3 -0
- package/dest/public/avm/opcodes/ec_add.d.ts +2 -2
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.js +6 -6
- package/dest/public/avm/opcodes/environment_getters.d.ts +3 -3
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/environment_getters.js +7 -9
- package/dest/public/avm/opcodes/external_calls.d.ts +1 -1
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +1 -1
- package/dest/public/avm/opcodes/hashing.d.ts +2 -2
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/public/avm/opcodes/hashing.js +9 -4
- package/dest/public/avm/opcodes/index.d.ts +1 -1
- package/dest/public/avm/opcodes/instruction.d.ts +2 -2
- package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/public/avm/opcodes/instruction.js +5 -6
- package/dest/public/avm/opcodes/instruction_impl.d.ts +1 -1
- package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.d.ts +2 -2
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +1 -1
- package/dest/public/avm/opcodes/misc.d.ts +3 -2
- package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/public/avm/opcodes/misc.js +28 -8
- package/dest/public/avm/opcodes/storage.d.ts +3 -3
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
- 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/buffer_cursor.d.ts +1 -1
- package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -1
- 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.d.ts +9 -1
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +11 -1
- package/dest/public/avm/test_utils.d.ts +4 -4
- package/dest/public/avm/test_utils.d.ts.map +1 -1
- package/dest/public/avm/test_utils.js +7 -10
- package/dest/public/contracts_db_checkpoint.d.ts +16 -0
- package/dest/public/contracts_db_checkpoint.d.ts.map +1 -0
- package/dest/public/contracts_db_checkpoint.js +30 -0
- package/dest/public/db_interfaces.d.ts +14 -2
- package/dest/public/db_interfaces.d.ts.map +1 -1
- package/dest/public/debug_fn_name.d.ts +15 -2
- package/dest/public/debug_fn_name.d.ts.map +1 -1
- package/dest/public/debug_fn_name.js +28 -2
- package/dest/public/executor_metrics.d.ts +3 -2
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +1 -1
- package/dest/public/executor_metrics_interface.d.ts +3 -2
- package/dest/public/executor_metrics_interface.d.ts.map +1 -1
- package/dest/public/fixtures/amm_test.d.ts +1 -1
- package/dest/public/fixtures/amm_test.js +2 -2
- package/dest/public/fixtures/bulk_test.d.ts +1 -1
- package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
- package/dest/public/fixtures/bulk_test.js +59 -177
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +34 -0
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -0
- package/dest/public/fixtures/custom_bytecode_tester.js +53 -0
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +12 -0
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -0
- package/dest/public/fixtures/custom_bytecode_tests.js +174 -0
- package/dest/public/fixtures/index.d.ts +5 -2
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +4 -1
- package/dest/public/fixtures/minimal_public_tx.d.ts +4 -9
- package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
- package/dest/public/fixtures/minimal_public_tx.js +8 -32
- 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 +1681 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +25 -5
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +63 -17
- 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 -12
- 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 +7 -6
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +46 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +139 -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 +100 -0
- package/dest/public/hinting_db_sources.d.ts +16 -4
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +74 -13
- package/dest/public/index.d.ts +3 -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 +24 -65
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +85 -132
- package/dest/public/public_errors.d.ts +12 -0
- package/dest/public/public_errors.d.ts.map +1 -0
- package/dest/public/public_errors.js +13 -0
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +6 -2
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
- package/dest/public/public_processor/guarded_merkle_tree.js +8 -0
- package/dest/public/public_processor/public_processor.d.ts +11 -13
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +477 -70
- 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_tx_simulator/contract_provider_for_cpp.d.ts +18 -0
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +98 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +53 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +131 -0
- 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 +6 -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 +16 -8
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +7 -8
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +9 -4
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +22 -10
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +22 -29
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +178 -127
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +32 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.js +1 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +4 -3
- 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 +396 -20
- package/dest/public/side_effect_errors.d.ts +42 -2
- package/dest/public/side_effect_errors.d.ts.map +1 -1
- package/dest/public/side_effect_errors.js +70 -1
- package/dest/public/side_effect_trace.d.ts +13 -7
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +36 -21
- package/dest/public/side_effect_trace_interface.d.ts +9 -4
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/state_manager/index.d.ts +1 -1
- package/dest/public/state_manager/nullifiers.d.ts +2 -5
- package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
- package/dest/public/state_manager/nullifiers.js +1 -6
- 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 +16 -13
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +64 -21
- package/dest/public/test_executor_metrics.d.ts +4 -3
- package/dest/public/test_executor_metrics.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.js +5 -4
- package/dest/public/unique_class_ids.d.ts +1 -1
- package/dest/public/unique_class_ids.d.ts.map +1 -1
- package/dest/public/utils.d.ts +1 -1
- package/dest/server.d.ts +1 -1
- package/dest/testing.d.ts +1 -1
- package/package.json +24 -19
- 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/acvm_native.ts +18 -11
- package/src/private/circuit_recording/circuit_recorder.ts +17 -16
- package/src/private/circuit_recording/simulator_recorder_wrapper.ts +1 -1
- package/src/public/avm/avm_context.ts +1 -1
- package/src/public/avm/avm_contract_call_result.ts +1 -1
- package/src/public/avm/avm_execution_environment.ts +4 -3
- package/src/public/avm/avm_gas.ts +5 -5
- package/src/public/avm/avm_machine_state.ts +1 -1
- package/src/public/avm/avm_memory_types.ts +12 -3
- package/src/public/avm/avm_simulator.ts +24 -33
- package/src/public/avm/errors.ts +24 -27
- package/src/public/avm/fixtures/avm_simulation_tester.ts +14 -4
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +33 -1
- package/src/public/avm/fixtures/initializers.ts +7 -8
- package/src/public/avm/fixtures/utils.ts +3 -2
- package/src/public/avm/opcodes/accrued_substate.ts +5 -5
- package/src/public/avm/opcodes/addressing_mode.ts +5 -5
- package/src/public/avm/opcodes/arithmetic.ts +13 -1
- package/src/public/avm/opcodes/conversion.ts +4 -0
- package/src/public/avm/opcodes/ec_add.ts +6 -6
- package/src/public/avm/opcodes/environment_getters.ts +10 -12
- package/src/public/avm/opcodes/external_calls.ts +1 -1
- package/src/public/avm/opcodes/hashing.ts +10 -4
- package/src/public/avm/opcodes/instruction.ts +8 -6
- package/src/public/avm/opcodes/memory.ts +1 -1
- package/src/public/avm/opcodes/misc.ts +41 -7
- 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 +13 -1
- package/src/public/avm/test_utils.ts +7 -15
- package/src/public/contracts_db_checkpoint.ts +41 -0
- package/src/public/db_interfaces.ts +16 -1
- package/src/public/debug_fn_name.ts +35 -3
- package/src/public/executor_metrics.ts +2 -1
- package/src/public/executor_metrics_interface.ts +2 -1
- package/src/public/fixtures/amm_test.ts +2 -2
- package/src/public/fixtures/bulk_test.ts +39 -26
- package/src/public/fixtures/custom_bytecode_tester.ts +83 -0
- package/src/public/fixtures/custom_bytecode_tests.ts +219 -0
- package/src/public/fixtures/index.ts +8 -1
- package/src/public/fixtures/minimal_public_tx.ts +9 -42
- package/src/public/fixtures/opcode_spammer.ts +1638 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +90 -22
- package/src/public/fixtures/simple_contract_data_source.ts +8 -9
- package/src/public/fixtures/token_test.ts +18 -10
- package/src/public/fixtures/utils.ts +5 -6
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +240 -0
- package/src/public/fuzzing/avm_simulator_bin.ts +140 -0
- package/src/public/hinting_db_sources.ts +117 -10
- package/src/public/index.ts +8 -1
- package/src/public/public_db_sources.ts +112 -175
- package/src/public/public_errors.ts +14 -0
- package/src/public/public_processor/guarded_merkle_tree.ts +10 -1
- package/src/public/public_processor/public_processor.ts +112 -79
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +121 -0
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +200 -0
- 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 +5 -0
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +13 -14
- package/src/public/public_tx_simulator/public_tx_context.ts +20 -7
- package/src/public/public_tx_simulator/public_tx_simulator.ts +265 -179
- package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +33 -0
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +4 -13
- package/src/public/side_effect_errors.ts +91 -1
- package/src/public/side_effect_trace.ts +49 -24
- package/src/public/side_effect_trace_interface.ts +7 -1
- package/src/public/state_manager/nullifiers.ts +2 -8
- package/src/public/state_manager/public_storage.ts +1 -1
- package/src/public/state_manager/state_manager.ts +87 -39
- package/src/public/test_executor_metrics.ts +7 -5
- package/dest/public/bytecode_errors.d.ts +0 -4
- package/dest/public/bytecode_errors.d.ts.map +0 -1
- package/dest/public/bytecode_errors.js +0 -6
- package/dest/public/tx_contract_cache.d.ts +0 -41
- package/dest/public/tx_contract_cache.d.ts.map +0 -1
- package/dest/public/tx_contract_cache.js +0 -49
- package/src/public/bytecode_errors.ts +0 -6
- package/src/public/tx_contract_cache.ts +0 -69
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { type Logger, createLogger, logLevel } from '@aztec/foundation/log';
|
|
2
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
3
|
+
import { type CancellationToken, avmSimulate, cancelSimulation, createCancellationToken } from '@aztec/native';
|
|
4
|
+
import { ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
5
|
+
import {
|
|
6
|
+
AvmFastSimulationInputs,
|
|
7
|
+
AvmTxHint,
|
|
8
|
+
type PublicSimulatorConfig,
|
|
9
|
+
PublicTxResult,
|
|
10
|
+
deserializeFromMessagePack,
|
|
11
|
+
} from '@aztec/stdlib/avm';
|
|
12
|
+
import { SimulationError } from '@aztec/stdlib/errors';
|
|
13
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
14
|
+
import type { GlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
15
|
+
import { WorldStateRevisionWithHandle } from '@aztec/stdlib/world-state';
|
|
16
|
+
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
17
|
+
|
|
18
|
+
import { strict as assert } from 'assert';
|
|
19
|
+
|
|
20
|
+
import { ExecutorMetrics } from '../executor_metrics.js';
|
|
21
|
+
import type { ExecutorMetricsInterface } from '../executor_metrics_interface.js';
|
|
22
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
23
|
+
import { ContractProviderForCpp } from './contract_provider_for_cpp.js';
|
|
24
|
+
import { PublicTxSimulator } from './public_tx_simulator.js';
|
|
25
|
+
import type {
|
|
26
|
+
MeasuredPublicTxSimulatorInterface,
|
|
27
|
+
PublicTxSimulatorInterface,
|
|
28
|
+
} from './public_tx_simulator_interface.js';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* C++ implementation of PublicTxSimulator using the C++ simulator.
|
|
32
|
+
* The C++ simulator accesses the world state directly/natively within C++.
|
|
33
|
+
* For contract DB accesses, it makes callbacks through NAPI back to the TS PublicContractsDB cache.
|
|
34
|
+
*/
|
|
35
|
+
export class CppPublicTxSimulator extends PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
36
|
+
protected override log: Logger;
|
|
37
|
+
/** Current cancellation token for in-flight simulation. */
|
|
38
|
+
private cancellationToken?: CancellationToken;
|
|
39
|
+
/** Current simulation promise, used to wait for completion after cancellation. */
|
|
40
|
+
private simulationPromise?: Promise<Buffer>;
|
|
41
|
+
|
|
42
|
+
constructor(
|
|
43
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
44
|
+
contractsDB: PublicContractsDB,
|
|
45
|
+
globalVariables: GlobalVariables,
|
|
46
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
47
|
+
) {
|
|
48
|
+
super(merkleTree, contractsDB, globalVariables, config);
|
|
49
|
+
this.log = createLogger(`simulator:cpp_public_tx_simulator`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Simulate a transaction's public portion using the C++ avvm simulator.
|
|
54
|
+
*
|
|
55
|
+
* @param tx - The transaction to simulate.
|
|
56
|
+
* @returns The result of the transaction's public execution.
|
|
57
|
+
*/
|
|
58
|
+
public override async simulate(tx: Tx): Promise<PublicTxResult> {
|
|
59
|
+
const txHash = this.computeTxHash(tx);
|
|
60
|
+
this.log.debug(`C++ simulation of ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, {
|
|
61
|
+
txHash,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Using the "as WorldStateRevisionWithHandle" is a bit of a "trust me bro", hence the assert.
|
|
65
|
+
let wsRevision = this.merkleTree.getRevision();
|
|
66
|
+
assert(
|
|
67
|
+
wsRevision instanceof WorldStateRevisionWithHandle,
|
|
68
|
+
'CppPublicTxSimulator a real NativeWorldStateInstance with a handle to the C++ WorldState object',
|
|
69
|
+
);
|
|
70
|
+
const wsCppHandle = (wsRevision as WorldStateRevisionWithHandle).handle;
|
|
71
|
+
wsRevision = wsRevision.toWorldStateRevision(); // for msgpack serialization, we don't include the handle in the type
|
|
72
|
+
|
|
73
|
+
this.log.trace(`Running C++ simulation with world state revision ${JSON.stringify(wsRevision)}`);
|
|
74
|
+
|
|
75
|
+
// Create the fast simulation inputs
|
|
76
|
+
const txHint = AvmTxHint.fromTx(tx, this.globalVariables.gasFees);
|
|
77
|
+
const protocolContracts = ProtocolContractsList;
|
|
78
|
+
const fastSimInputs = new AvmFastSimulationInputs(
|
|
79
|
+
wsRevision,
|
|
80
|
+
this.config,
|
|
81
|
+
txHint,
|
|
82
|
+
this.globalVariables,
|
|
83
|
+
protocolContracts,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
// Create contract provider for callbacks to TypeScript PublicContractsDB from C++
|
|
87
|
+
const contractProvider = new ContractProviderForCpp(this.contractsDB, this.globalVariables);
|
|
88
|
+
|
|
89
|
+
// Serialize to msgpack and call the C++ simulator
|
|
90
|
+
this.log.trace(`Serializing fast simulation inputs to msgpack...`);
|
|
91
|
+
const inputBuffer = fastSimInputs.serializeWithMessagePack();
|
|
92
|
+
|
|
93
|
+
// Create cancellation token for this simulation
|
|
94
|
+
this.cancellationToken = createCancellationToken();
|
|
95
|
+
|
|
96
|
+
// Store the promise so cancel() can wait for it
|
|
97
|
+
this.log.debug(`Calling C++ simulator for tx ${txHash}`);
|
|
98
|
+
this.simulationPromise = avmSimulate(inputBuffer, contractProvider, wsCppHandle, logLevel, this.cancellationToken);
|
|
99
|
+
|
|
100
|
+
let resultBuffer: Buffer;
|
|
101
|
+
try {
|
|
102
|
+
resultBuffer = await this.simulationPromise;
|
|
103
|
+
} catch (error: any) {
|
|
104
|
+
// Check if this was a cancellation
|
|
105
|
+
if (error.message?.includes('Simulation cancelled')) {
|
|
106
|
+
throw new SimulationError(`C++ simulation cancelled`, []);
|
|
107
|
+
}
|
|
108
|
+
throw new SimulationError(`C++ simulation failed: ${error.message}`, []);
|
|
109
|
+
} finally {
|
|
110
|
+
this.cancellationToken = undefined;
|
|
111
|
+
this.simulationPromise = undefined;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// If we've reached this point, C++ succeeded during simulation,
|
|
115
|
+
|
|
116
|
+
// Deserialize the msgpack result
|
|
117
|
+
this.log.trace(`Deserializing C++ from buffer (size: ${resultBuffer.length})...`);
|
|
118
|
+
const cppResultJSON: object = deserializeFromMessagePack(resultBuffer);
|
|
119
|
+
this.log.trace(`Deserializing C++ result to PublicTxResult...`);
|
|
120
|
+
const cppResult = PublicTxResult.fromPlainObject(cppResultJSON);
|
|
121
|
+
|
|
122
|
+
this.log.trace(`C++ simulation completed for tx ${txHash}`, {
|
|
123
|
+
txHash,
|
|
124
|
+
reverted: !cppResult.revertCode.isOK(),
|
|
125
|
+
cppGasUsed: cppResult.gasUsed.totalGas.l2Gas,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return cppResult;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Cancel the current simulation if one is in progress.
|
|
133
|
+
* This signals the C++ simulator to stop at the next opcode or before the next WorldState write.
|
|
134
|
+
* Safe to call even if no simulation is in progress.
|
|
135
|
+
*
|
|
136
|
+
* @param waitTimeoutMs - If provided, wait up to this many ms for the simulation to actually stop.
|
|
137
|
+
* This is important because C++ might be in the middle of a slow operation
|
|
138
|
+
* (e.g., pad_trees) and won't check the cancellation flag until it completes.
|
|
139
|
+
* Default timeout of 100ms after cancellation.
|
|
140
|
+
*/
|
|
141
|
+
public async cancel(waitTimeoutMs: number = 100): Promise<void> {
|
|
142
|
+
if (this.cancellationToken) {
|
|
143
|
+
this.log.debug('Cancelling C++ simulation');
|
|
144
|
+
cancelSimulation(this.cancellationToken);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Wait for the simulation to actually complete if not already done
|
|
148
|
+
if (this.simulationPromise) {
|
|
149
|
+
this.log.debug(`Waiting up to ${waitTimeoutMs}ms for C++ simulation to stop`);
|
|
150
|
+
await Promise.race([
|
|
151
|
+
this.simulationPromise.catch(() => {}), // Ignore rejection, just wait for completion
|
|
152
|
+
sleep(waitTimeoutMs),
|
|
153
|
+
]);
|
|
154
|
+
this.log.debug('C++ simulation stopped or wait timed out');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export class MeasuredCppPublicTxSimulator extends CppPublicTxSimulator implements MeasuredPublicTxSimulatorInterface {
|
|
160
|
+
constructor(
|
|
161
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
162
|
+
contractsDB: PublicContractsDB,
|
|
163
|
+
globalVariables: GlobalVariables,
|
|
164
|
+
protected readonly metrics: ExecutorMetricsInterface,
|
|
165
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
166
|
+
) {
|
|
167
|
+
super(merkleTree, contractsDB, globalVariables, config);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public override async simulate(tx: Tx, txLabel: string = 'unlabeledTx'): Promise<PublicTxResult> {
|
|
171
|
+
this.metrics.startRecordingTxSimulation(txLabel);
|
|
172
|
+
let result: PublicTxResult | undefined;
|
|
173
|
+
try {
|
|
174
|
+
result = await super.simulate(tx);
|
|
175
|
+
} finally {
|
|
176
|
+
this.metrics.stopRecordingTxSimulation(txLabel, result?.gasUsed, result?.revertCode);
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* A C++ public tx simulator that tracks runtime/production metrics with telemetry.
|
|
184
|
+
*/
|
|
185
|
+
export class TelemetryCppPublicTxSimulator extends MeasuredCppPublicTxSimulator {
|
|
186
|
+
/* tracer needed by trackSpans */
|
|
187
|
+
public readonly tracer: Tracer;
|
|
188
|
+
|
|
189
|
+
constructor(
|
|
190
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
191
|
+
contractsDB: PublicContractsDB,
|
|
192
|
+
globalVariables: GlobalVariables,
|
|
193
|
+
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
194
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
195
|
+
) {
|
|
196
|
+
const metrics = new ExecutorMetrics(telemetryClient, 'CppPublicTxSimulator');
|
|
197
|
+
super(merkleTree, contractsDB, globalVariables, metrics, config);
|
|
198
|
+
this.tracer = metrics.tracer;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { type Logger, createLogger, logLevel } from '@aztec/foundation/log';
|
|
2
|
+
import { avmSimulateWithHintedDbs } from '@aztec/native';
|
|
3
|
+
import {
|
|
4
|
+
AvmCircuitInputs,
|
|
5
|
+
type PublicSimulatorConfig,
|
|
6
|
+
PublicTxResult,
|
|
7
|
+
deserializeFromMessagePack,
|
|
8
|
+
} from '@aztec/stdlib/avm';
|
|
9
|
+
import { SimulationError } from '@aztec/stdlib/errors';
|
|
10
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
11
|
+
import type { GlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
12
|
+
|
|
13
|
+
import { strict as assert } from 'assert';
|
|
14
|
+
|
|
15
|
+
import type { ExecutorMetricsInterface } from '../executor_metrics_interface.js';
|
|
16
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
17
|
+
import { PublicTxSimulator } from './public_tx_simulator.js';
|
|
18
|
+
import type {
|
|
19
|
+
MeasuredPublicTxSimulatorInterface,
|
|
20
|
+
PublicTxSimulatorInterface,
|
|
21
|
+
} from './public_tx_simulator_interface.js';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* C++ implementation of PublicTxSimulator using pre-collected hints.
|
|
25
|
+
* This implementation runs TS simulation first to collect all hints,
|
|
26
|
+
* then passes the complete AvmCircuitInputs (hints + public inputs)
|
|
27
|
+
* to C++ to run hinted simulation.
|
|
28
|
+
*/
|
|
29
|
+
export class CppPublicTxSimulatorHintedDbs extends PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
30
|
+
protected override log: Logger;
|
|
31
|
+
|
|
32
|
+
constructor(
|
|
33
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
34
|
+
contractsDB: PublicContractsDB,
|
|
35
|
+
globalVariables: GlobalVariables,
|
|
36
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
37
|
+
) {
|
|
38
|
+
super(merkleTree, contractsDB, globalVariables, config);
|
|
39
|
+
this.log = createLogger(`simulator:cpp_public_tx_simulator_hinted_dbs`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Simulate a transaction's public portion using the C++ vm2 simulator with hinted DBs.
|
|
44
|
+
*
|
|
45
|
+
* This implementation:
|
|
46
|
+
* 1. Runs the full TypeScript simulation to generate AvmCircuitInputs (hints + public inputs)
|
|
47
|
+
* 2. Passes the complete AvmCircuitInputs to C++ to run hinted simulation
|
|
48
|
+
*
|
|
49
|
+
* @param tx - The transaction to simulate.
|
|
50
|
+
* @returns The result of the transaction's public execution.
|
|
51
|
+
*/
|
|
52
|
+
public override async simulate(tx: Tx): Promise<PublicTxResult> {
|
|
53
|
+
const txHash = this.computeTxHash(tx);
|
|
54
|
+
this.log.debug(`C++ hinted DB simulation of ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, {
|
|
55
|
+
txHash,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// First, run TS simulation to generate hints and public inputs
|
|
59
|
+
this.log.debug(`Running TS simulation for tx ${txHash}`);
|
|
60
|
+
|
|
61
|
+
// Run the full TypeScript simulation using the parent class
|
|
62
|
+
// This will modify the merkle tree with the transaction's state changes
|
|
63
|
+
const tsResult = await super.simulate(tx);
|
|
64
|
+
this.log.debug(`TS simulation succeeded for tx ${txHash}`);
|
|
65
|
+
|
|
66
|
+
// Extract the full AvmCircuitInputs from the TS result
|
|
67
|
+
const avmCircuitInputs = new AvmCircuitInputs(tsResult.hints!, tsResult.publicInputs!);
|
|
68
|
+
|
|
69
|
+
// Second, run C++ simulation with hinted DBs
|
|
70
|
+
this.log.debug(`Running C++ simulation with hinted DBs for tx ${txHash}`);
|
|
71
|
+
|
|
72
|
+
// Serialize to msgpack and call the C++ simulator
|
|
73
|
+
const inputBuffer = avmCircuitInputs.serializeWithMessagePack();
|
|
74
|
+
|
|
75
|
+
let resultBuffer: Buffer;
|
|
76
|
+
try {
|
|
77
|
+
resultBuffer = await avmSimulateWithHintedDbs(inputBuffer, logLevel);
|
|
78
|
+
} catch (error: any) {
|
|
79
|
+
throw new SimulationError(`C++ hinted simulation failed: ${error.message}`, []);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Deserialize the msgpack result
|
|
83
|
+
const cppResultJSON: object = deserializeFromMessagePack(resultBuffer);
|
|
84
|
+
const cppResult = PublicTxResult.fromPlainObject(cppResultJSON);
|
|
85
|
+
|
|
86
|
+
assert(cppResult.revertCode.equals(tsResult.revertCode));
|
|
87
|
+
assert(cppResult.gasUsed.totalGas.equals(tsResult.gasUsed.totalGas));
|
|
88
|
+
|
|
89
|
+
this.log.debug(`C++ hinted simulation completed for tx ${txHash}`, {
|
|
90
|
+
txHash,
|
|
91
|
+
reverted: !tsResult.revertCode.isOK(),
|
|
92
|
+
tsGasUsed: tsResult.gasUsed.totalGas.l2Gas,
|
|
93
|
+
cppGasUsed: tsResult.gasUsed.totalGas.l2Gas,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// TODO(fcarreiro): complete this.
|
|
97
|
+
return tsResult;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Class to record metrics for simulation.
|
|
103
|
+
*
|
|
104
|
+
* Note(dbanks12): We might not be able to collect all the same metrics in C++ as we do in TS!
|
|
105
|
+
* Unless we move some of the metrics collection to C++, we don't have inner functions exposed
|
|
106
|
+
* to TS for tracking.
|
|
107
|
+
*/
|
|
108
|
+
export class MeasuredCppPublicTxSimulatorHintedDbs
|
|
109
|
+
extends CppPublicTxSimulatorHintedDbs
|
|
110
|
+
implements MeasuredPublicTxSimulatorInterface
|
|
111
|
+
{
|
|
112
|
+
constructor(
|
|
113
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
114
|
+
contractsDB: PublicContractsDB,
|
|
115
|
+
globalVariables: GlobalVariables,
|
|
116
|
+
protected readonly metrics: ExecutorMetricsInterface,
|
|
117
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
118
|
+
) {
|
|
119
|
+
super(merkleTree, contractsDB, globalVariables, config);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public override async simulate(tx: Tx, txLabel: string = 'unlabeledTx'): Promise<PublicTxResult> {
|
|
123
|
+
this.metrics.startRecordingTxSimulation(txLabel);
|
|
124
|
+
let result: PublicTxResult | undefined;
|
|
125
|
+
try {
|
|
126
|
+
result = await super.simulate(tx);
|
|
127
|
+
} finally {
|
|
128
|
+
this.metrics.stopRecordingTxSimulation(txLabel, result?.gasUsed, result?.revertCode);
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -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
|
+
}
|