@aztec/simulator 0.0.1-commit.fce3e4f → 0.0.1-commit.ffe5b04ea
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/dest/common/errors.d.ts +8 -2
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/private/acvm/acvm.d.ts +4 -2
- package/dest/private/acvm/acvm.d.ts.map +1 -1
- package/dest/private/acvm/acvm.js +4 -3
- package/dest/private/acvm/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/acvm_native.d.ts +5 -3
- package/dest/private/acvm_native.d.ts.map +1 -1
- package/dest/private/acvm_native.js +8 -6
- package/dest/private/acvm_wasm.d.ts +4 -3
- package/dest/private/acvm_wasm.d.ts.map +1 -1
- package/dest/private/acvm_wasm.js +4 -4
- package/dest/private/circuit_recording/circuit_recorder.d.ts +4 -3
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.js +23 -20
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts +3 -2
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/file_circuit_recorder.js +2 -2
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
- package/dest/private/factory.d.ts +3 -3
- package/dest/private/factory.d.ts.map +1 -1
- package/dest/private/factory.js +7 -4
- package/dest/public/avm/avm_context.d.ts +3 -3
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts +6 -6
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.js +3 -3
- package/dest/public/avm/avm_execution_environment.d.ts +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_gas.js +3 -3
- 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/account_proof_fetcher.d.ts +2 -0
- package/dest/public/avm/fixtures/account_proof_fetcher.d.ts.map +1 -0
- package/dest/public/avm/fixtures/account_proof_fetcher.js +152 -0
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +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 +17 -18
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +42 -43
- package/dest/public/avm/opcodes/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 +12 -9
- package/dest/public/avm/serialization/instruction_serialization.d.ts +2 -2
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +2 -2
- 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 +12 -33
- package/dest/public/fixtures/amm_test.js +4 -4
- 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 +122 -0
- package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -0
- package/dest/public/fixtures/opcode_spammer.js +1653 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +27 -7
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +86 -22
- 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 +3 -3
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +10 -9
- 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 +5 -4
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +5 -5
- 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 +11 -7
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +483 -74
- package/dest/public/public_processor/public_processor_metrics.d.ts +2 -2
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor_metrics.js +28 -45
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +3 -14
- 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 +20 -55
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +24 -37
- 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 +65 -144
- 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 +23 -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 +14 -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 +5 -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 +9 -9
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +8 -6
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +25 -14
- 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 +6 -5
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +4 -4
- 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 +16 -5
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +19 -9
- package/dest/public/test_executor_metrics.d.ts +8 -2
- package/dest/public/test_executor_metrics.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.js +24 -2
- package/package.json +20 -20
- package/src/common/errors.ts +1 -1
- package/src/private/acvm/acvm.ts +4 -3
- package/src/private/acvm/deserialize.ts +1 -1
- package/src/private/acvm/serialize.ts +1 -1
- package/src/private/acvm_native.ts +11 -5
- package/src/private/acvm_wasm.ts +7 -3
- package/src/private/circuit_recording/circuit_recorder.ts +24 -21
- package/src/private/circuit_recording/file_circuit_recorder.ts +7 -2
- package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
- package/src/private/factory.ts +7 -4
- package/src/public/avm/avm_context.ts +2 -2
- package/src/public/avm/avm_contract_call_result.ts +8 -6
- package/src/public/avm/avm_execution_environment.ts +10 -5
- package/src/public/avm/avm_gas.ts +5 -5
- 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/account_proof.json +553 -0
- package/src/public/avm/fixtures/account_proof_fetcher.ts +166 -0
- package/src/public/avm/fixtures/avm_simulation_tester.ts +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 +31 -34
- 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 +19 -8
- package/src/public/avm/serialization/instruction_serialization.ts +2 -2
- 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 +9 -33
- package/src/public/fixtures/amm_test.ts +4 -4
- 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 +1717 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +120 -18
- 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 +8 -8
- 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 +16 -6
- package/src/public/public_processor/guarded_merkle_tree.ts +6 -1
- package/src/public/public_processor/public_processor.ts +116 -71
- package/src/public/public_processor/public_processor_metrics.ts +16 -44
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +25 -63
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +82 -178
- package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +134 -0
- package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +239 -0
- package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +83 -0
- package/src/public/public_tx_simulator/factories.ts +44 -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 +14 -7
- package/src/public/public_tx_simulator/public_tx_simulator.ts +45 -19
- 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 +6 -3
- 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 +39 -23
- package/src/public/test_executor_metrics.ts +27 -3
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { type Logger, type LoggerBindings, 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
|
+
bindings?: LoggerBindings,
|
|
41
|
+
) {
|
|
42
|
+
super(merkleTree, contractsDB, globalVariables, config, undefined, bindings);
|
|
43
|
+
this.log = createLogger(`simulator:cpp_vs_public_tx_simulator`, bindings);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Simulate a transaction's public portion using the C++ avvm simulator.
|
|
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++ simulation of ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, {
|
|
55
|
+
txHash,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Run TS simulation to generate hints and public inputs
|
|
59
|
+
this.log.debug(`Running TS simulation for tx ${txHash}`);
|
|
60
|
+
|
|
61
|
+
// create checkpoint for ws
|
|
62
|
+
let tsResult: PublicTxResult | undefined;
|
|
63
|
+
let tsStateRef: StateReference | undefined;
|
|
64
|
+
await this.merkleTree.createCheckpoint();
|
|
65
|
+
this.contractsDB.createCheckpoint();
|
|
66
|
+
try {
|
|
67
|
+
// Run the full TypeScript simulation using the parent class
|
|
68
|
+
// This will modify the merkle tree with the transaction's state changes
|
|
69
|
+
tsResult = await super.simulate(tx);
|
|
70
|
+
this.log.debug(`TS simulation completed for tx ${txHash}`);
|
|
71
|
+
|
|
72
|
+
tsStateRef = await this.merkleTree.getStateReference(); // capture tree roots for later comparsion
|
|
73
|
+
} catch (error: any) {
|
|
74
|
+
this.log.warn(`TS simulation failed, but still continuing with C++ simulation: ${error.message} ${error.stack}`);
|
|
75
|
+
} finally {
|
|
76
|
+
// revert checkpoint for ws and clear contract db changes
|
|
77
|
+
// (cpp should reapply exactly the same changes if there are no bugs)
|
|
78
|
+
await this.merkleTree.revertCheckpoint();
|
|
79
|
+
this.contractsDB.revertCheckpoint();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this.log.debug(`Running C++ simulation for tx ${txHash}`);
|
|
83
|
+
|
|
84
|
+
// Using the "as WorldStateRevisionWithHandle" is a bit of a "trust me bro", hence the assert.
|
|
85
|
+
let wsRevision = this.merkleTree.getRevision();
|
|
86
|
+
assert(
|
|
87
|
+
wsRevision instanceof WorldStateRevisionWithHandle,
|
|
88
|
+
'CppPublicTxSimulator a real NativeWorldStateInstance with a handle to the C++ WorldState object',
|
|
89
|
+
);
|
|
90
|
+
const wsCppHandle = (wsRevision as WorldStateRevisionWithHandle).handle;
|
|
91
|
+
wsRevision = wsRevision.toWorldStateRevision(); // for msgpack serialization, we don't include the handle in the type
|
|
92
|
+
|
|
93
|
+
this.log.debug(`Running C++ simulation with world state revision ${JSON.stringify(wsRevision)}`);
|
|
94
|
+
|
|
95
|
+
// Create the fast simulation inputs
|
|
96
|
+
const txHint = AvmTxHint.fromTx(tx, this.globalVariables.gasFees);
|
|
97
|
+
const protocolContracts = ProtocolContractsList;
|
|
98
|
+
const fastSimInputs = new AvmFastSimulationInputs(
|
|
99
|
+
wsRevision,
|
|
100
|
+
this.config,
|
|
101
|
+
txHint,
|
|
102
|
+
this.globalVariables,
|
|
103
|
+
protocolContracts,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
// Create contract provider for callbacks to TypeScript PublicContractsDB from C++
|
|
107
|
+
const contractProvider = new ContractProviderForCpp(this.contractsDB, this.globalVariables, this.bindings);
|
|
108
|
+
|
|
109
|
+
// Serialize to msgpack and call the C++ simulator
|
|
110
|
+
this.log.debug(`Serializing fast simulation inputs to msgpack...`);
|
|
111
|
+
const inputBuffer = fastSimInputs.serializeWithMessagePack();
|
|
112
|
+
|
|
113
|
+
let resultBuffer: Buffer;
|
|
114
|
+
try {
|
|
115
|
+
this.log.debug(`Calling C++ simulator for tx ${txHash}`);
|
|
116
|
+
resultBuffer = await avmSimulate(inputBuffer, contractProvider, wsCppHandle, logLevel);
|
|
117
|
+
} catch (error: any) {
|
|
118
|
+
throw new SimulationError(`C++ simulation failed: ${error.message}`, []);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// If we've reached this point, C++ succeeded during simulation,
|
|
122
|
+
// so we assert that TS also succeeded.
|
|
123
|
+
assert(tsResult !== undefined, 'TS simulation should have succeeded if C++ succeeded');
|
|
124
|
+
assert(tsStateRef !== undefined, 'TS state reference should have been captured if C++ succeeded');
|
|
125
|
+
|
|
126
|
+
// Deserialize the msgpack result
|
|
127
|
+
this.log.debug(`Deserializing C++ from buffer (size: ${resultBuffer.length})...`);
|
|
128
|
+
const cppResultJSON: object = deserializeFromMessagePack(resultBuffer);
|
|
129
|
+
this.log.debug(`Deserializing C++ result to PublicTxResult...`);
|
|
130
|
+
const cppResult = PublicTxResult.fromPlainObject(cppResultJSON);
|
|
131
|
+
this.log.debug(`Done.`);
|
|
132
|
+
assert(cppResult.revertCode.equals(tsResult.revertCode));
|
|
133
|
+
assert(cppResult.gasUsed.totalGas.equals(tsResult.gasUsed.totalGas));
|
|
134
|
+
assert(cppResult.gasUsed.publicGas.equals(tsResult.gasUsed.publicGas));
|
|
135
|
+
assert(cppResult.gasUsed.teardownGas.equals(tsResult.gasUsed.teardownGas));
|
|
136
|
+
assert(cppResult.gasUsed.billedGas.equals(tsResult.gasUsed.billedGas));
|
|
137
|
+
assert(cppResult.publicTxEffect.equals(tsResult.publicTxEffect));
|
|
138
|
+
if (cppResult.publicInputs !== undefined) {
|
|
139
|
+
assert(cppResult.publicInputs!.toBuffer().equals(tsResult.publicInputs!.toBuffer()));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// TODO(fcarreiro): complete this.
|
|
143
|
+
// Check that C++ hints are a strict subset of TS hints.
|
|
144
|
+
// Then enable for misc tests and validate hints.
|
|
145
|
+
//if (this.config?.collectHints) {
|
|
146
|
+
//}
|
|
147
|
+
|
|
148
|
+
if (this.config?.collectCallMetadata) {
|
|
149
|
+
assert(cppResult.getAppLogicReturnValues().length === tsResult.getAppLogicReturnValues().length);
|
|
150
|
+
for (let i = 0; i < cppResult.getAppLogicReturnValues().length; i++) {
|
|
151
|
+
assert(cppResult.getAppLogicReturnValues()[i].equals(tsResult.getAppLogicReturnValues()[i]));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Messages are still not ok for exceptional halts (they are not plumbed in C++).
|
|
155
|
+
const cppRevertReason = cppResult.findRevertReason() || {};
|
|
156
|
+
const tsRevertReason = tsResult.findRevertReason() || {};
|
|
157
|
+
const cppRevertReasonAsObject = JSON.parse(JSON.stringify(cppRevertReason));
|
|
158
|
+
const tsRevertReasonAsObject = JSON.parse(JSON.stringify(tsRevertReason));
|
|
159
|
+
if (JSON.stringify(cppRevertReasonAsObject) !== JSON.stringify(tsRevertReasonAsObject)) {
|
|
160
|
+
this.log.debug('cppResult.findRevertReason()', cppRevertReasonAsObject);
|
|
161
|
+
this.log.debug('tsResult.findRevertReason()', tsRevertReasonAsObject);
|
|
162
|
+
}
|
|
163
|
+
// TODO: dont compare the strings since this is not deterministic.
|
|
164
|
+
|
|
165
|
+
// Sometimes error messages are different between C++ and TS, so we omit in the default comparison
|
|
166
|
+
const cppRevertReasonWithoutMessage = { ...cppRevertReasonAsObject, originalMessage: undefined };
|
|
167
|
+
const tsRevertReasonWithoutMessage = { ...tsRevertReasonAsObject, originalMessage: undefined };
|
|
168
|
+
assert(JSON.stringify(cppRevertReasonWithoutMessage) === JSON.stringify(tsRevertReasonWithoutMessage));
|
|
169
|
+
|
|
170
|
+
const cppHasRevertMessage =
|
|
171
|
+
cppRevertReasonAsObject.originalMessage && cppRevertReasonAsObject.originalMessage.length > 0;
|
|
172
|
+
const tsHasRevertMessage =
|
|
173
|
+
tsRevertReasonAsObject.originalMessage && tsRevertReasonAsObject.originalMessage.length > 0;
|
|
174
|
+
// assert that if one of the error messages is non-empty, the other is
|
|
175
|
+
assert(
|
|
176
|
+
cppHasRevertMessage === tsHasRevertMessage,
|
|
177
|
+
'One of the AVM simulators (C++ or TS) produced a revert message, but the other did not',
|
|
178
|
+
);
|
|
179
|
+
// Ideally, we'd love to be able to compare full error messages, but without a lot of work
|
|
180
|
+
// the two simulators will always be able to produce some differing errors.
|
|
181
|
+
// Commenting out the code below will enforce that the error messages are at least
|
|
182
|
+
// similar (one contains the other). Even this is not something we can guarantee.
|
|
183
|
+
//if (cppHasRevertMessage) {
|
|
184
|
+
// const cppRevertMessageContainsTs = cppRevertReasonAsObject.originalMessage.includes(
|
|
185
|
+
// tsRevertReasonAsObject.originalMessage,
|
|
186
|
+
// );
|
|
187
|
+
// const tsRevertMessageContainsCpp = tsRevertReasonAsObject.originalMessage.includes(
|
|
188
|
+
// cppRevertReasonAsObject.originalMessage,
|
|
189
|
+
// );
|
|
190
|
+
// assert(
|
|
191
|
+
// cppRevertMessageContainsTs || tsRevertMessageContainsCpp,
|
|
192
|
+
// 'The AVM simulators (C++ and TS) produced different revert messages (neither was a substring of the other)',
|
|
193
|
+
// );
|
|
194
|
+
//}
|
|
195
|
+
|
|
196
|
+
// Confirm that tree roots match
|
|
197
|
+
const cppStateRef = await this.merkleTree.getStateReference();
|
|
198
|
+
assert(
|
|
199
|
+
cppStateRef.equals(tsStateRef),
|
|
200
|
+
`Tree roots mismatch between TS and C++ public simulations for tx ${txHash}`,
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
this.log.debug(`C++ simulation completed for tx ${txHash}`, {
|
|
204
|
+
txHash,
|
|
205
|
+
reverted: !cppResult.revertCode.isOK(),
|
|
206
|
+
cppGasUsed: cppResult.gasUsed.totalGas.l2Gas,
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// Return cpp result as it has more detailed metadata / revert reasons
|
|
210
|
+
return cppResult;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export class MeasuredCppVsTsPublicTxSimulator
|
|
215
|
+
extends CppVsTsPublicTxSimulator
|
|
216
|
+
implements MeasuredPublicTxSimulatorInterface
|
|
217
|
+
{
|
|
218
|
+
constructor(
|
|
219
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
220
|
+
contractsDB: PublicContractsDB,
|
|
221
|
+
globalVariables: GlobalVariables,
|
|
222
|
+
protected readonly metrics: ExecutorMetricsInterface,
|
|
223
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
224
|
+
bindings?: LoggerBindings,
|
|
225
|
+
) {
|
|
226
|
+
super(merkleTree, contractsDB, globalVariables, config, bindings);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
public override async simulate(tx: Tx, txLabel: string = 'unlabeledTx'): Promise<PublicTxResult> {
|
|
230
|
+
this.metrics.startRecordingTxSimulation(txLabel);
|
|
231
|
+
let result: PublicTxResult | undefined;
|
|
232
|
+
try {
|
|
233
|
+
result = await super.simulate(tx);
|
|
234
|
+
} finally {
|
|
235
|
+
this.metrics.stopRecordingTxSimulation(txLabel, result?.gasUsed, result?.revertCode);
|
|
236
|
+
}
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { LoggerBindings } from '@aztec/foundation/log';
|
|
2
|
+
import {
|
|
3
|
+
AvmCircuitInputs,
|
|
4
|
+
AvmCircuitPublicInputs,
|
|
5
|
+
AvmExecutionHints,
|
|
6
|
+
type PublicSimulatorConfig,
|
|
7
|
+
PublicTxResult,
|
|
8
|
+
serializeWithMessagePack,
|
|
9
|
+
} from '@aztec/stdlib/avm';
|
|
10
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
11
|
+
import type { GlobalVariables, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
12
|
+
|
|
13
|
+
import { strict as assert } from 'assert';
|
|
14
|
+
import { mkdirSync, writeFileSync } from 'fs';
|
|
15
|
+
import { join } from 'path';
|
|
16
|
+
|
|
17
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
18
|
+
import { CppPublicTxSimulator } from './cpp_public_tx_simulator.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A C++ public tx simulator that dumps AVM circuit inputs to disk after simulation.
|
|
22
|
+
* Used during nightly CI runs to collect circuit inputs for benchmarking.
|
|
23
|
+
*/
|
|
24
|
+
export class DumpingCppPublicTxSimulator extends CppPublicTxSimulator {
|
|
25
|
+
private readonly outputDir: string;
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
29
|
+
contractsDB: PublicContractsDB,
|
|
30
|
+
globalVariables: GlobalVariables,
|
|
31
|
+
config: Partial<PublicSimulatorConfig>,
|
|
32
|
+
outputDir: string,
|
|
33
|
+
bindings?: LoggerBindings,
|
|
34
|
+
) {
|
|
35
|
+
super(merkleTree, contractsDB, globalVariables, config, bindings);
|
|
36
|
+
assert(config.collectHints === true, 'collectHints must be enabled to dump AVM circuit inputs');
|
|
37
|
+
assert(config.collectPublicInputs === true, 'collectPublicInputs must be enabled to dump AVM circuit inputs');
|
|
38
|
+
this.outputDir = outputDir;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public override async simulate(tx: Tx): Promise<PublicTxResult> {
|
|
42
|
+
const result = await super.simulate(tx);
|
|
43
|
+
|
|
44
|
+
// Dump the circuit inputs after successful simulation
|
|
45
|
+
const txHash = this.computeTxHash(tx);
|
|
46
|
+
this.dumpAvmCircuitInputs(result, txHash);
|
|
47
|
+
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Dumps AVM circuit inputs to disk.
|
|
53
|
+
*
|
|
54
|
+
* @param result - The simulation result containing hints and public inputs
|
|
55
|
+
* @param txHash - The transaction hash to use in the filename
|
|
56
|
+
*/
|
|
57
|
+
private dumpAvmCircuitInputs(result: PublicTxResult, txHash: TxHash): void {
|
|
58
|
+
try {
|
|
59
|
+
// Ensure the output directory exists
|
|
60
|
+
mkdirSync(this.outputDir, { recursive: true });
|
|
61
|
+
|
|
62
|
+
// Generate filename using transaction hash
|
|
63
|
+
const filename = `avm-circuit-inputs-tx-${txHash.toString()}.bin`;
|
|
64
|
+
const filepath = join(this.outputDir, filename);
|
|
65
|
+
|
|
66
|
+
// Create circuit inputs from the result
|
|
67
|
+
const hints = result.hints ?? AvmExecutionHints.empty();
|
|
68
|
+
const publicInputs = result.publicInputs ?? AvmCircuitPublicInputs.empty();
|
|
69
|
+
const avmCircuitInputs = new AvmCircuitInputs(hints, publicInputs);
|
|
70
|
+
|
|
71
|
+
// Serialize the circuit inputs using MessagePack
|
|
72
|
+
const serialized = serializeWithMessagePack(avmCircuitInputs);
|
|
73
|
+
|
|
74
|
+
// Write to disk
|
|
75
|
+
writeFileSync(filepath, serialized);
|
|
76
|
+
|
|
77
|
+
this.log.debug(`Dumped AVM circuit inputs to ${filepath}`);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
// Non-blocking error handling - log but don't interrupt processing
|
|
80
|
+
this.log.warn(`Failed to dump AVM circuit inputs for tx ${txHash.toString()}: ${error}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { LoggerBindings } from '@aztec/foundation/log';
|
|
2
|
+
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
3
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
4
|
+
import type { GlobalVariables } from '@aztec/stdlib/tx';
|
|
5
|
+
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
6
|
+
|
|
7
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
8
|
+
import { TelemetryCppPublicTxSimulator } from './cpp_public_tx_simulator.js';
|
|
9
|
+
import { DumpingCppPublicTxSimulator } from './dumping_cpp_public_tx_simulator.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates a public tx simulator for block building.
|
|
13
|
+
* Uses DumpingCppPublicTxSimulator if DUMP_AVM_INPUTS_TO_DIR env var is set (for CI/testing avm circuit),
|
|
14
|
+
* otherwise uses TelemetryCppPublicTxSimulator (for production).
|
|
15
|
+
*/
|
|
16
|
+
export function createPublicTxSimulatorForBlockBuilding(
|
|
17
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
18
|
+
contractsDB: PublicContractsDB,
|
|
19
|
+
globalVariables: GlobalVariables,
|
|
20
|
+
telemetryClient: TelemetryClient,
|
|
21
|
+
bindings?: LoggerBindings,
|
|
22
|
+
collectDebugLogs = false,
|
|
23
|
+
) {
|
|
24
|
+
const config = PublicSimulatorConfig.from({
|
|
25
|
+
skipFeeEnforcement: false,
|
|
26
|
+
collectDebugLogs,
|
|
27
|
+
collectHints: false,
|
|
28
|
+
collectPublicInputs: false,
|
|
29
|
+
collectStatistics: false,
|
|
30
|
+
collectCallMetadata: false,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const dumpDir = process.env.DUMP_AVM_INPUTS_TO_DIR;
|
|
34
|
+
if (dumpDir) {
|
|
35
|
+
// must collect hints and PIs for dumping
|
|
36
|
+
const dumpingConfig = {
|
|
37
|
+
...config,
|
|
38
|
+
collectHints: true,
|
|
39
|
+
collectPublicInputs: true,
|
|
40
|
+
};
|
|
41
|
+
return new DumpingCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, dumpingConfig, dumpDir, bindings);
|
|
42
|
+
}
|
|
43
|
+
return new TelemetryCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, telemetryClient, config, bindings);
|
|
44
|
+
}
|
|
@@ -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,8 +6,8 @@ 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/
|
|
10
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
9
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
11
11
|
import {
|
|
12
12
|
AvmAccumulatedData,
|
|
13
13
|
AvmAccumulatedDataArrayLengths,
|
|
@@ -87,8 +87,9 @@ export class PublicTxContext {
|
|
|
87
87
|
public readonly revertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData,
|
|
88
88
|
public readonly feePayer: AztecAddress,
|
|
89
89
|
private readonly trace: SideEffectTrace,
|
|
90
|
+
bindings?: LoggerBindings,
|
|
90
91
|
) {
|
|
91
|
-
this.log = createLogger(`simulator:public_tx_context
|
|
92
|
+
this.log = createLogger(`simulator:public_tx_context`, bindings);
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
public static async create(
|
|
@@ -98,13 +99,14 @@ export class PublicTxContext {
|
|
|
98
99
|
globalVariables: GlobalVariables,
|
|
99
100
|
protocolContracts: ProtocolContracts,
|
|
100
101
|
proverId: Fr,
|
|
102
|
+
bindings?: LoggerBindings,
|
|
101
103
|
) {
|
|
102
104
|
const contractDeploymentData = AllContractDeploymentData.fromTx(tx);
|
|
103
105
|
const nonRevertibleContractDeploymentData = contractDeploymentData.getNonRevertibleContractDeploymentData();
|
|
104
106
|
const revertibleContractDeploymentData = contractDeploymentData.getRevertibleContractDeploymentData();
|
|
105
107
|
const nonRevertibleAccumulatedDataFromPrivate = tx.data.forPublic!.nonRevertibleAccumulatedData;
|
|
106
108
|
|
|
107
|
-
const trace = new SideEffectTrace();
|
|
109
|
+
const trace = new SideEffectTrace(0, bindings);
|
|
108
110
|
|
|
109
111
|
const firstNullifier = nonRevertibleAccumulatedDataFromPrivate.nullifiers[0];
|
|
110
112
|
|
|
@@ -115,6 +117,7 @@ export class PublicTxContext {
|
|
|
115
117
|
trace,
|
|
116
118
|
firstNullifier,
|
|
117
119
|
globalVariables.timestamp,
|
|
120
|
+
bindings,
|
|
118
121
|
);
|
|
119
122
|
|
|
120
123
|
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
@@ -124,7 +127,7 @@ export class PublicTxContext {
|
|
|
124
127
|
|
|
125
128
|
return new PublicTxContext(
|
|
126
129
|
tx.getTxHash(),
|
|
127
|
-
new PhaseStateManager(txStateManager),
|
|
130
|
+
new PhaseStateManager(txStateManager, bindings),
|
|
128
131
|
await txStateManager.getTreeSnapshots(),
|
|
129
132
|
globalVariables,
|
|
130
133
|
protocolContracts,
|
|
@@ -142,6 +145,7 @@ export class PublicTxContext {
|
|
|
142
145
|
tx.data.forPublic!.revertibleAccumulatedData,
|
|
143
146
|
tx.data.feePayer,
|
|
144
147
|
trace,
|
|
148
|
+
bindings,
|
|
145
149
|
);
|
|
146
150
|
}
|
|
147
151
|
|
|
@@ -441,8 +445,11 @@ class PhaseStateManager {
|
|
|
441
445
|
|
|
442
446
|
private currentlyActiveStateManager: PublicPersistableStateManager | undefined;
|
|
443
447
|
|
|
444
|
-
constructor(
|
|
445
|
-
|
|
448
|
+
constructor(
|
|
449
|
+
private readonly txStateManager: PublicPersistableStateManager,
|
|
450
|
+
bindings?: LoggerBindings,
|
|
451
|
+
) {
|
|
452
|
+
this.log = createLogger(`simulator:public_phase_state_manager`, bindings);
|
|
446
453
|
}
|
|
447
454
|
|
|
448
455
|
async fork() {
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
3
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
1
|
+
import { MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { type Logger, type LoggerBindings, 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';
|
|
@@ -79,15 +81,19 @@ type ProcessedPhase = {
|
|
|
79
81
|
export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
80
82
|
protected log: Logger;
|
|
81
83
|
protected readonly config: PublicSimulatorConfig;
|
|
84
|
+
protected readonly bindings?: LoggerBindings;
|
|
82
85
|
|
|
83
86
|
constructor(
|
|
84
87
|
protected merkleTree: MerkleTreeWriteOperations,
|
|
85
88
|
protected contractsDB: PublicContractsDB,
|
|
86
89
|
protected globalVariables: GlobalVariables,
|
|
87
90
|
config?: Partial<PublicSimulatorConfig>,
|
|
91
|
+
protected protocolContracts: ProtocolContracts = ProtocolContractsList,
|
|
92
|
+
bindings?: LoggerBindings,
|
|
88
93
|
) {
|
|
89
94
|
this.config = PublicSimulatorConfig.from(config ?? {});
|
|
90
|
-
this.
|
|
95
|
+
this.bindings = bindings;
|
|
96
|
+
this.log = createLogger(`simulator:public_tx_simulator`, bindings);
|
|
91
97
|
}
|
|
92
98
|
|
|
93
99
|
/**
|
|
@@ -103,7 +109,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
103
109
|
const hints = new AvmExecutionHints(
|
|
104
110
|
this.globalVariables,
|
|
105
111
|
AvmTxHint.fromTx(tx, this.globalVariables.gasFees),
|
|
106
|
-
|
|
112
|
+
this.protocolContracts,
|
|
107
113
|
);
|
|
108
114
|
const hintingMerkleTree = await HintingMerkleWriteOperations.create(this.merkleTree, hints);
|
|
109
115
|
const hintingTreesDB = new PublicTreesDB(hintingMerkleTree);
|
|
@@ -114,8 +120,9 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
114
120
|
hintingContractsDB,
|
|
115
121
|
tx,
|
|
116
122
|
this.globalVariables,
|
|
117
|
-
|
|
123
|
+
this.protocolContracts,
|
|
118
124
|
this.config.proverId,
|
|
125
|
+
this.bindings,
|
|
119
126
|
);
|
|
120
127
|
|
|
121
128
|
// This will throw if there is a nullifier collision.
|
|
@@ -129,7 +136,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
129
136
|
const setupResult = await this.simulatePhase(TxExecutionPhase.SETUP, context);
|
|
130
137
|
if (setupResult.reverted) {
|
|
131
138
|
throw new Error(
|
|
132
|
-
`
|
|
139
|
+
`[SETUP] UNRECOVERABLE ERROR! The transaction will be thrown out. ${setupResult.revertReason?.message}`,
|
|
133
140
|
);
|
|
134
141
|
}
|
|
135
142
|
processedPhases.push(setupResult);
|
|
@@ -192,18 +199,33 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
192
199
|
|
|
193
200
|
// Such transactions should be filtered by GasTxValidator.
|
|
194
201
|
assert(
|
|
195
|
-
context.getActualGasUsed().l2Gas <=
|
|
196
|
-
`Transaction consumes ${context.getActualGasUsed().l2Gas} L2 gas, which exceeds the
|
|
202
|
+
context.getActualGasUsed().l2Gas <= MAX_PROCESSABLE_L2_GAS,
|
|
203
|
+
`Transaction consumes ${context.getActualGasUsed().l2Gas} L2 gas, which exceeds the maximum processable gas of ${MAX_PROCESSABLE_L2_GAS}`,
|
|
197
204
|
);
|
|
198
205
|
await this.payFee(context);
|
|
199
206
|
|
|
200
207
|
const publicInputs = await context.generateAvmCircuitPublicInputs();
|
|
201
208
|
const revertCode = context.getFinalRevertCode();
|
|
202
209
|
|
|
203
|
-
// We only return the app logic phase information.
|
|
204
|
-
const appLogicReturnValues =
|
|
210
|
+
// We only return the app logic phase information, and only 1 per phase.
|
|
211
|
+
const appLogicReturnValues: NestedProcessReturnValues[] =
|
|
205
212
|
processedPhases.find(({ phase }) => phase === TxExecutionPhase.APP_LOGIC)?.returnValues ?? [];
|
|
206
213
|
|
|
214
|
+
// TODO(fcarreiro): This is a temporary backwards compatibility layer until we migrate to the C++ simulator.
|
|
215
|
+
if (context.revertReason !== undefined) {
|
|
216
|
+
(appLogicReturnValues as any).revertReason = context.revertReason;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Create PublicTxEffect from PublicInputs.
|
|
220
|
+
const publicTxEffect = new PublicTxEffect(
|
|
221
|
+
publicInputs.transactionFee,
|
|
222
|
+
publicInputs.accumulatedData.noteHashes.filter(h => !h.isEmpty()),
|
|
223
|
+
publicInputs.accumulatedData.nullifiers.filter(n => !n.isEmpty()),
|
|
224
|
+
publicInputs.accumulatedData.l2ToL1Msgs.filter(m => !m.isEmpty()),
|
|
225
|
+
publicInputs.accumulatedData.publicLogs.toLogs(),
|
|
226
|
+
publicInputs.accumulatedData.publicDataWrites.filter(w => !w.isEmpty()),
|
|
227
|
+
);
|
|
228
|
+
|
|
207
229
|
return new PublicTxResult(
|
|
208
230
|
/*gasUsed=*/ {
|
|
209
231
|
totalGas: context.getActualGasUsed(),
|
|
@@ -212,8 +234,8 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
212
234
|
billedGas: context.getTotalGasUsed(),
|
|
213
235
|
},
|
|
214
236
|
/*revertCode=*/ revertCode,
|
|
215
|
-
/*
|
|
216
|
-
/*
|
|
237
|
+
/*publicTxEffect=*/ publicTxEffect,
|
|
238
|
+
/*callStackMetadata=*/ appLogicReturnValues,
|
|
217
239
|
/*logs=*/ context.state.getActiveStateManager().getLogs(),
|
|
218
240
|
/*hints=*/ hints,
|
|
219
241
|
/*publicInputs=*/ publicInputs,
|
|
@@ -250,7 +272,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
250
272
|
|
|
251
273
|
const enqueuedCallResult = await this.simulateEnqueuedCall(phase, context, callRequest);
|
|
252
274
|
|
|
253
|
-
returnValues.push(new NestedProcessReturnValues(enqueuedCallResult.output));
|
|
275
|
+
returnValues.push(new NestedProcessReturnValues(enqueuedCallResult.output.bestEffortReadAll()));
|
|
254
276
|
|
|
255
277
|
if (enqueuedCallResult.reverted) {
|
|
256
278
|
reverted = true;
|
|
@@ -280,7 +302,11 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
280
302
|
): Promise<AvmFinalizedCallResult> {
|
|
281
303
|
const stateManager = context.state.getActiveStateManager();
|
|
282
304
|
const contractAddress = callRequest.request.contractAddress;
|
|
283
|
-
const fnName = await getPublicFunctionDebugName(
|
|
305
|
+
const fnName = await getPublicFunctionDebugName(
|
|
306
|
+
this.contractsDB,
|
|
307
|
+
contractAddress,
|
|
308
|
+
new CallDataArray(callRequest.calldata),
|
|
309
|
+
);
|
|
284
310
|
|
|
285
311
|
const allocatedGas = context.getGasLeftAtPhase(phase);
|
|
286
312
|
|
|
@@ -299,7 +325,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
299
325
|
);
|
|
300
326
|
|
|
301
327
|
if (result.reverted) {
|
|
302
|
-
const culprit = `${contractAddress}:${
|
|
328
|
+
const culprit = `${contractAddress}:${fnName}`;
|
|
303
329
|
context.revert(phase, result.revertReason, culprit);
|
|
304
330
|
}
|
|
305
331
|
|
|
@@ -340,7 +366,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
340
366
|
transactionFee,
|
|
341
367
|
this.globalVariables,
|
|
342
368
|
request.isStaticCall,
|
|
343
|
-
calldata,
|
|
369
|
+
new CallDataArray(calldata),
|
|
344
370
|
allocatedGas,
|
|
345
371
|
this.config,
|
|
346
372
|
);
|
|
@@ -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';
|