@aztec/simulator 3.0.0-canary.a9708bd → 3.0.0-devnet.2-patch.1
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 +1 -1
- 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 +7 -7
- 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 +1 -1
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/environment_getters.js +5 -7
- 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 +0 -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 +3 -1
- 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 +19 -0
- 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 +64 -131
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +12 -0
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -0
- package/dest/public/fixtures/custom_bytecode_tester.js +29 -0
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +10 -0
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -0
- package/dest/public/fixtures/custom_bytecode_tests.js +130 -0
- package/dest/public/fixtures/index.d.ts +3 -2
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +2 -1
- package/dest/public/fixtures/minimal_public_tx.d.ts +4 -4
- package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
- package/dest/public/fixtures/minimal_public_tx.js +8 -22
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +11 -4
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +29 -10
- 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 +4 -4
- 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 +136 -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 +84 -0
- package/dest/public/hinting_db_sources.d.ts +15 -4
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +69 -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 +5 -2
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
- package/dest/public/public_processor/guarded_merkle_tree.js +3 -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 +61 -43
- package/dest/public/public_processor/public_processor_metrics.d.ts +1 -1
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_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 +94 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +38 -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 +93 -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 +170 -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 +9 -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 +2 -2
- 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 +1 -1
- 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 +4 -4
- 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 +6 -8
- package/src/public/avm/opcodes/external_calls.ts +0 -1
- package/src/public/avm/opcodes/hashing.ts +3 -1
- 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 +26 -1
- 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 +42 -24
- package/src/public/fixtures/custom_bytecode_tester.ts +49 -0
- package/src/public/fixtures/custom_bytecode_tests.ts +159 -0
- package/src/public/fixtures/index.ts +2 -1
- package/src/public/fixtures/minimal_public_tx.ts +9 -33
- package/src/public/fixtures/public_tx_simulation_tester.ts +52 -17
- 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 +4 -4
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +233 -0
- package/src/public/fuzzing/avm_simulator_bin.ts +121 -0
- package/src/public/hinting_db_sources.ts +113 -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 +6 -1
- package/src/public/public_processor/public_processor.ts +92 -70
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +116 -0
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +155 -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 +236 -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 +10 -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
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT } from '@aztec/constants';
|
|
2
2
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
3
|
-
import { Fr } from '@aztec/foundation/
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
5
|
import { sleep } from '@aztec/foundation/sleep';
|
|
6
6
|
import { DateProvider, Timer, elapsed, executeTimeout } from '@aztec/foundation/timer';
|
|
7
7
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
8
8
|
import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
|
|
9
9
|
import { computeFeePayerBalanceLeafSlot, computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
AvmCircuitInputs,
|
|
12
|
+
AvmCircuitPublicInputs,
|
|
13
|
+
AvmExecutionHints,
|
|
14
|
+
type AvmProvingRequest,
|
|
15
|
+
PublicDataWrite,
|
|
16
|
+
PublicSimulatorConfig,
|
|
17
|
+
} from '@aztec/stdlib/avm';
|
|
11
18
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
12
19
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
13
20
|
import { computeTransactionFee } from '@aztec/stdlib/fees';
|
|
@@ -18,6 +25,7 @@ import type {
|
|
|
18
25
|
PublicProcessorValidator,
|
|
19
26
|
SequencerConfig,
|
|
20
27
|
} from '@aztec/stdlib/interfaces/server';
|
|
28
|
+
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
21
29
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
22
30
|
import {
|
|
23
31
|
type FailedTx,
|
|
@@ -26,8 +34,6 @@ import {
|
|
|
26
34
|
type ProcessedTx,
|
|
27
35
|
StateReference,
|
|
28
36
|
Tx,
|
|
29
|
-
TxExecutionPhase,
|
|
30
|
-
type TxValidator,
|
|
31
37
|
makeProcessedTxFromPrivateOnlyTx,
|
|
32
38
|
makeProcessedTxFromTxWithPublicCalls,
|
|
33
39
|
} from '@aztec/stdlib/tx';
|
|
@@ -41,8 +47,14 @@ import {
|
|
|
41
47
|
} from '@aztec/telemetry-client';
|
|
42
48
|
import { ForkCheckpoint } from '@aztec/world-state/native';
|
|
43
49
|
|
|
50
|
+
import { AssertionError } from 'assert';
|
|
51
|
+
|
|
44
52
|
import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
|
|
45
|
-
import {
|
|
53
|
+
import {
|
|
54
|
+
type PublicTxSimulatorConfig,
|
|
55
|
+
type PublicTxSimulatorInterface,
|
|
56
|
+
TelemetryCppPublicTxSimulator,
|
|
57
|
+
} from '../public_tx_simulator/index.js';
|
|
46
58
|
import { GuardedMerkleTreeOperations } from './guarded_merkle_tree.js';
|
|
47
59
|
import { PublicProcessorMetrics } from './public_processor_metrics.js';
|
|
48
60
|
|
|
@@ -58,7 +70,6 @@ export class PublicProcessorFactory {
|
|
|
58
70
|
|
|
59
71
|
/**
|
|
60
72
|
* Creates a new instance of a PublicProcessor.
|
|
61
|
-
* @param historicalHeader - The header of a block previous to the one in which the tx is included.
|
|
62
73
|
* @param globalVariables - The global variables for the block being processed.
|
|
63
74
|
* @param skipFeeEnforcement - Allows disabling balance checks for fee estimations.
|
|
64
75
|
* @returns A new instance of a PublicProcessor.
|
|
@@ -66,20 +77,12 @@ export class PublicProcessorFactory {
|
|
|
66
77
|
public create(
|
|
67
78
|
merkleTree: MerkleTreeWriteOperations,
|
|
68
79
|
globalVariables: GlobalVariables,
|
|
69
|
-
|
|
70
|
-
clientInitiatedSimulation: boolean = false,
|
|
80
|
+
config: PublicSimulatorConfig,
|
|
71
81
|
): PublicProcessor {
|
|
72
82
|
const contractsDB = new PublicContractsDB(this.contractDataSource);
|
|
73
83
|
|
|
74
84
|
const guardedFork = new GuardedMerkleTreeOperations(merkleTree);
|
|
75
|
-
const publicTxSimulator = this.createPublicTxSimulator(
|
|
76
|
-
guardedFork,
|
|
77
|
-
contractsDB,
|
|
78
|
-
globalVariables,
|
|
79
|
-
/*doMerkleOperations=*/ true,
|
|
80
|
-
skipFeeEnforcement,
|
|
81
|
-
clientInitiatedSimulation,
|
|
82
|
-
);
|
|
85
|
+
const publicTxSimulator = this.createPublicTxSimulator(guardedFork, contractsDB, globalVariables, config);
|
|
83
86
|
|
|
84
87
|
return new PublicProcessor(
|
|
85
88
|
globalVariables,
|
|
@@ -95,19 +98,9 @@ export class PublicProcessorFactory {
|
|
|
95
98
|
merkleTree: MerkleTreeWriteOperations,
|
|
96
99
|
contractsDB: PublicContractsDB,
|
|
97
100
|
globalVariables: GlobalVariables,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
): PublicTxSimulator {
|
|
102
|
-
return new TelemetryPublicTxSimulator(
|
|
103
|
-
merkleTree,
|
|
104
|
-
contractsDB,
|
|
105
|
-
globalVariables,
|
|
106
|
-
doMerkleOperations,
|
|
107
|
-
skipFeeEnforcement,
|
|
108
|
-
clientInitiatedSimulation,
|
|
109
|
-
this.telemetryClient,
|
|
110
|
-
);
|
|
101
|
+
config?: Partial<PublicTxSimulatorConfig>,
|
|
102
|
+
): PublicTxSimulatorInterface {
|
|
103
|
+
return new TelemetryCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, this.telemetryClient, config);
|
|
111
104
|
}
|
|
112
105
|
}
|
|
113
106
|
|
|
@@ -129,7 +122,7 @@ export class PublicProcessor implements Traceable {
|
|
|
129
122
|
protected globalVariables: GlobalVariables,
|
|
130
123
|
private guardedMerkleTree: GuardedMerkleTreeOperations,
|
|
131
124
|
protected contractsDB: PublicContractsDB,
|
|
132
|
-
protected publicTxSimulator:
|
|
125
|
+
protected publicTxSimulator: PublicTxSimulatorInterface,
|
|
133
126
|
private dateProvider: DateProvider,
|
|
134
127
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
135
128
|
private log = createLogger('simulator:public-processor'),
|
|
@@ -154,7 +147,7 @@ export class PublicProcessor implements Traceable {
|
|
|
154
147
|
limits: PublicProcessorLimits = {},
|
|
155
148
|
validator: PublicProcessorValidator = {},
|
|
156
149
|
): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[]]> {
|
|
157
|
-
const { maxTransactions, maxBlockSize, deadline, maxBlockGas } = limits;
|
|
150
|
+
const { maxTransactions, maxBlockSize, deadline, maxBlockGas, maxBlobFields } = limits;
|
|
158
151
|
const { preprocessValidator, nullifierCache } = validator;
|
|
159
152
|
const result: ProcessedTx[] = [];
|
|
160
153
|
const usedTxs: Tx[] = [];
|
|
@@ -165,6 +158,7 @@ export class PublicProcessor implements Traceable {
|
|
|
165
158
|
let returns: NestedProcessReturnValues[] = [];
|
|
166
159
|
let totalPublicGas = new Gas(0, 0);
|
|
167
160
|
let totalBlockGas = new Gas(0, 0);
|
|
161
|
+
let totalBlobFields = 0;
|
|
168
162
|
|
|
169
163
|
for await (const origTx of txs) {
|
|
170
164
|
// Only process up to the max tx limit
|
|
@@ -234,12 +228,15 @@ export class PublicProcessor implements Traceable {
|
|
|
234
228
|
// Note: We use the underlying fork here not the guarded one, this ensures that it's not impacted by stopping the guarded version
|
|
235
229
|
const checkpoint = await ForkCheckpoint.new(this.guardedMerkleTree.getUnderlyingFork());
|
|
236
230
|
const startStateReference = await this.guardedMerkleTree.getUnderlyingFork().getStateReference();
|
|
231
|
+
this.contractsDB.createCheckpoint();
|
|
237
232
|
|
|
238
233
|
try {
|
|
239
234
|
const [processedTx, returnValues] = await this.processTx(tx, deadline);
|
|
240
235
|
|
|
236
|
+
const txBlobFields = processedTx.txEffect.getNumBlobFields();
|
|
237
|
+
|
|
241
238
|
// If the actual size of this tx would exceed block size, skip it
|
|
242
|
-
const txSize =
|
|
239
|
+
const txSize = txBlobFields * Fr.SIZE_IN_BYTES;
|
|
243
240
|
if (maxBlockSize !== undefined && totalSizeInBytes + txSize > maxBlockSize) {
|
|
244
241
|
this.log.debug(`Skipping processed tx ${txHash} sized ${txSize} due to max block size.`, {
|
|
245
242
|
txHash,
|
|
@@ -249,6 +246,24 @@ export class PublicProcessor implements Traceable {
|
|
|
249
246
|
});
|
|
250
247
|
// Need to revert the checkpoint here and don't go any further
|
|
251
248
|
await checkpoint.revert();
|
|
249
|
+
this.contractsDB.revertCheckpoint();
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// If the actual blob fields of this tx would exceed the limit, skip it
|
|
254
|
+
if (maxBlobFields !== undefined && totalBlobFields + txBlobFields > maxBlobFields) {
|
|
255
|
+
this.log.debug(
|
|
256
|
+
`Skipping processed tx ${txHash} with ${txBlobFields} blob fields due to max blob fields limit.`,
|
|
257
|
+
{
|
|
258
|
+
txHash,
|
|
259
|
+
txBlobFields,
|
|
260
|
+
totalBlobFields,
|
|
261
|
+
maxBlobFields,
|
|
262
|
+
},
|
|
263
|
+
);
|
|
264
|
+
// Need to revert the checkpoint here and don't go any further
|
|
265
|
+
await checkpoint.revert();
|
|
266
|
+
this.contractsDB.revertCheckpoint();
|
|
252
267
|
continue;
|
|
253
268
|
}
|
|
254
269
|
|
|
@@ -262,6 +277,7 @@ export class PublicProcessor implements Traceable {
|
|
|
262
277
|
totalPublicGas = totalPublicGas.add(processedTx.gasUsed.publicGas);
|
|
263
278
|
totalBlockGas = totalBlockGas.add(processedTx.gasUsed.totalGas);
|
|
264
279
|
totalSizeInBytes += txSize;
|
|
280
|
+
totalBlobFields += txBlobFields;
|
|
265
281
|
} catch (err: any) {
|
|
266
282
|
if (err?.name === 'PublicProcessorTimeoutError') {
|
|
267
283
|
this.log.warn(`Stopping tx processing due to timeout.`);
|
|
@@ -282,6 +298,9 @@ export class PublicProcessor implements Traceable {
|
|
|
282
298
|
// This needs to be done directly on the underlying fork as the guarded fork has been stopped.
|
|
283
299
|
await this.guardedMerkleTree.getUnderlyingFork().revertAllCheckpoints();
|
|
284
300
|
|
|
301
|
+
// Revert any contracts added to the DB for the tx.
|
|
302
|
+
this.contractsDB.revertCheckpoint();
|
|
303
|
+
|
|
285
304
|
// Ensure we're at the same state as when we started processing this tx.
|
|
286
305
|
await this.checkWorldStateUnchanged(startStateReference, txHash, err);
|
|
287
306
|
|
|
@@ -292,7 +311,8 @@ export class PublicProcessor implements Traceable {
|
|
|
292
311
|
// Roll back state to start of TX before proceeding to next TX
|
|
293
312
|
await checkpoint.revert();
|
|
294
313
|
await this.guardedMerkleTree.getUnderlyingFork().revertAllCheckpoints();
|
|
295
|
-
|
|
314
|
+
this.contractsDB.revertCheckpoint();
|
|
315
|
+
const errorMessage = err instanceof Error || err instanceof AssertionError ? err.message : 'Unknown error';
|
|
296
316
|
this.log.warn(`Failed to process tx ${txHash.toString()}: ${errorMessage} ${err?.stack}`);
|
|
297
317
|
failed.push({ tx, error: err instanceof Error ? err : new Error(errorMessage) });
|
|
298
318
|
returns.push(new NestedProcessReturnValues([]));
|
|
@@ -302,8 +322,7 @@ export class PublicProcessor implements Traceable {
|
|
|
302
322
|
} finally {
|
|
303
323
|
// Base case is we always commit the checkpoint. Using the ForkCheckpoint means this has no effect if the tx was previously reverted
|
|
304
324
|
await checkpoint.commit();
|
|
305
|
-
|
|
306
|
-
this.contractsDB.clearContractsForTx();
|
|
325
|
+
this.contractsDB.commitCheckpointOkIfNone();
|
|
307
326
|
}
|
|
308
327
|
}
|
|
309
328
|
|
|
@@ -366,10 +385,7 @@ export class PublicProcessor implements Traceable {
|
|
|
366
385
|
return [processedTx, returnValues ?? []];
|
|
367
386
|
}
|
|
368
387
|
|
|
369
|
-
private async doTreeInsertionsForPrivateOnlyTx(
|
|
370
|
-
processedTx: ProcessedTx,
|
|
371
|
-
txValidator?: TxValidator<ProcessedTx>,
|
|
372
|
-
): Promise<void> {
|
|
388
|
+
private async doTreeInsertionsForPrivateOnlyTx(processedTx: ProcessedTx): Promise<void> {
|
|
373
389
|
const treeInsertionStart = process.hrtime.bigint();
|
|
374
390
|
|
|
375
391
|
// Update the state so that the next tx in the loop has the correct .startState
|
|
@@ -388,14 +404,8 @@ export class PublicProcessor implements Traceable {
|
|
|
388
404
|
padArrayEnd(processedTx.txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map(n => n.toBuffer()),
|
|
389
405
|
NULLIFIER_SUBTREE_HEIGHT,
|
|
390
406
|
);
|
|
391
|
-
} catch {
|
|
392
|
-
|
|
393
|
-
// Ideally the validator has already caught this above, but just in case:
|
|
394
|
-
throw new Error(`Transaction ${processedTx.hash} invalid after processing public functions`);
|
|
395
|
-
} else {
|
|
396
|
-
// We have no validator and assume this call should blindly process txs with duplicates being caught later
|
|
397
|
-
this.log.warn(`Detected duplicate nullifier after public processing for: ${processedTx.hash}.`);
|
|
398
|
-
}
|
|
407
|
+
} catch (cause) {
|
|
408
|
+
throw new Error(`Transaction ${processedTx.hash} failed with duplicate nullifiers`, { cause });
|
|
399
409
|
}
|
|
400
410
|
|
|
401
411
|
const treeInsertionEnd = process.hrtime.bigint();
|
|
@@ -500,10 +510,7 @@ export class PublicProcessor implements Traceable {
|
|
|
500
510
|
// Fee payment insertion has already been done. Do the rest.
|
|
501
511
|
await this.doTreeInsertionsForPrivateOnlyTx(processedTx);
|
|
502
512
|
|
|
503
|
-
// Add any contracts registered/deployed in this private-only tx to the block-level cache
|
|
504
|
-
// (add to tx-level cache and then commit to block-level cache)
|
|
505
513
|
await this.contractsDB.addNewContracts(tx);
|
|
506
|
-
this.contractsDB.commitContractsForTx();
|
|
507
514
|
|
|
508
515
|
return [processedTx, undefined];
|
|
509
516
|
}
|
|
@@ -514,21 +521,9 @@ export class PublicProcessor implements Traceable {
|
|
|
514
521
|
private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, NestedProcessReturnValues[]]> {
|
|
515
522
|
const timer = new Timer();
|
|
516
523
|
|
|
517
|
-
const
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
if (!avmProvingRequest) {
|
|
521
|
-
this.metrics.recordFailedTx();
|
|
522
|
-
throw new Error('Avm proving result was not generated.');
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
processedPhases.forEach(phase => {
|
|
526
|
-
if (phase.reverted) {
|
|
527
|
-
this.metrics.recordRevertedPhase(phase.phase);
|
|
528
|
-
} else {
|
|
529
|
-
this.metrics.recordPhaseDuration(phase.phase, phase.durationMs ?? 0);
|
|
530
|
-
}
|
|
531
|
-
});
|
|
524
|
+
const result = await this.publicTxSimulator.simulate(tx);
|
|
525
|
+
// TODO: use the callStackMetadata here to extract more data about public execution
|
|
526
|
+
const { hints, publicInputs, publicTxEffect, gasUsed, revertCode /*callStackMetadata*/ } = result;
|
|
532
527
|
|
|
533
528
|
const contractClassLogs = revertCode.isOK()
|
|
534
529
|
? tx.getContractClassLogs()
|
|
@@ -539,14 +534,41 @@ export class PublicProcessor implements Traceable {
|
|
|
539
534
|
.map(log => ContractClassPublishedEvent.fromLog(log)),
|
|
540
535
|
);
|
|
541
536
|
|
|
542
|
-
|
|
537
|
+
// TODO(fcarreiro): remove phase count metric.
|
|
543
538
|
const durationMs = timer.ms();
|
|
544
|
-
this.metrics.recordTx(phaseCount, durationMs, gasUsed.publicGas);
|
|
539
|
+
this.metrics.recordTx(/*phaseCount=*/ 1, durationMs, gasUsed.publicGas);
|
|
540
|
+
|
|
541
|
+
// Extract the return values from the call stack metadata.
|
|
542
|
+
const appLogicReturnValues: NestedProcessReturnValues[] = result.getAppLogicReturnValues();
|
|
543
|
+
// Extract the revert reason from the call stack metadata.
|
|
544
|
+
const revertReason = result.findRevertReason();
|
|
545
|
+
// Create proving request if we have hints and public inputs.
|
|
546
|
+
const avmProvingRequest =
|
|
547
|
+
hints && publicInputs ? PublicProcessor.generateProvingRequest(publicInputs, hints) : undefined;
|
|
545
548
|
|
|
546
|
-
const processedTx = makeProcessedTxFromTxWithPublicCalls(
|
|
549
|
+
const processedTx = makeProcessedTxFromTxWithPublicCalls(
|
|
550
|
+
tx,
|
|
551
|
+
this.globalVariables,
|
|
552
|
+
avmProvingRequest,
|
|
553
|
+
publicTxEffect,
|
|
554
|
+
gasUsed,
|
|
555
|
+
revertCode,
|
|
556
|
+
revertReason,
|
|
557
|
+
);
|
|
547
558
|
|
|
548
|
-
|
|
559
|
+
return [processedTx, appLogicReturnValues];
|
|
560
|
+
}
|
|
549
561
|
|
|
550
|
-
|
|
562
|
+
/**
|
|
563
|
+
* Generate the proving request for the AVM circuit.
|
|
564
|
+
*/
|
|
565
|
+
private static generateProvingRequest(
|
|
566
|
+
publicInputs: AvmCircuitPublicInputs,
|
|
567
|
+
hints: AvmExecutionHints = AvmExecutionHints.empty(),
|
|
568
|
+
): AvmProvingRequest {
|
|
569
|
+
return {
|
|
570
|
+
type: ProvingRequestType.PUBLIC_VM,
|
|
571
|
+
inputs: new AvmCircuitInputs(hints, publicInputs),
|
|
572
|
+
};
|
|
551
573
|
}
|
|
552
574
|
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import type { ContractProvider } from '@aztec/native';
|
|
4
|
+
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
5
|
+
import { deserializeFromMessagePack, serializeWithMessagePack } from '@aztec/stdlib/avm';
|
|
6
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
|
+
import { ContractDeploymentData } from '@aztec/stdlib/contract';
|
|
8
|
+
import type { GlobalVariables } from '@aztec/stdlib/tx';
|
|
9
|
+
|
|
10
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
11
|
+
|
|
12
|
+
export class ContractProviderForCpp implements ContractProvider {
|
|
13
|
+
private log: Logger = createLogger('simulator:contract_provider_for_cpp');
|
|
14
|
+
|
|
15
|
+
constructor(
|
|
16
|
+
private contractsDB: PublicContractsDB,
|
|
17
|
+
private globalVariables: GlobalVariables,
|
|
18
|
+
) {}
|
|
19
|
+
|
|
20
|
+
public getContractInstance = async (address: string): Promise<Buffer | undefined> => {
|
|
21
|
+
this.log.debug(`Contract provider callback: getContractInstance(${address})`);
|
|
22
|
+
|
|
23
|
+
const aztecAddr = AztecAddress.fromString(address);
|
|
24
|
+
|
|
25
|
+
const instance = await this.contractsDB.getContractInstance(aztecAddr, this.globalVariables.timestamp);
|
|
26
|
+
|
|
27
|
+
if (!instance) {
|
|
28
|
+
this.log.debug(`Contract instance not found: ${address}`);
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return serializeWithMessagePack(instance);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
public getContractClass = async (classId: string): Promise<Buffer | undefined> => {
|
|
36
|
+
this.log.debug(`Contract provider callback: getContractClass(${classId})`);
|
|
37
|
+
|
|
38
|
+
// Parse classId string to Fr
|
|
39
|
+
const classIdFr = Fr.fromString(classId);
|
|
40
|
+
|
|
41
|
+
// Fetch contract class from the contracts DB
|
|
42
|
+
const contractClass = await this.contractsDB.getContractClass(classIdFr);
|
|
43
|
+
|
|
44
|
+
if (!contractClass) {
|
|
45
|
+
this.log.debug(`Contract class not found: ${classId}`);
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return serializeWithMessagePack(contractClass);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
public addContracts = async (contractDeploymentDataBuffer: Buffer): Promise<void> => {
|
|
53
|
+
this.log.debug(`Contract provider callback: addContracts`);
|
|
54
|
+
|
|
55
|
+
const rawData: any = deserializeFromMessagePack(contractDeploymentDataBuffer);
|
|
56
|
+
|
|
57
|
+
// Construct ContractDeploymentData from plain object.
|
|
58
|
+
const contractDeploymentData = ContractDeploymentData.fromPlainObject(rawData);
|
|
59
|
+
|
|
60
|
+
// Add contracts to the contracts DB
|
|
61
|
+
this.log.debug(`Calling contractsDB.addContracts`);
|
|
62
|
+
await this.contractsDB.addContracts(contractDeploymentData);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
public getBytecodeCommitment = async (classId: string): Promise<Buffer | undefined> => {
|
|
66
|
+
this.log.debug(`Contract provider callback: getBytecodeCommitment(${classId})`);
|
|
67
|
+
|
|
68
|
+
// Parse classId string to Fr
|
|
69
|
+
const classIdFr = Fr.fromString(classId);
|
|
70
|
+
|
|
71
|
+
// Fetch bytecode commitment from the contracts DB
|
|
72
|
+
const commitment = await this.contractsDB.getBytecodeCommitment(classIdFr);
|
|
73
|
+
|
|
74
|
+
if (!commitment) {
|
|
75
|
+
this.log.debug(`Bytecode commitment not found: ${classId}`);
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Serialize the Fr to buffer
|
|
80
|
+
return serializeWithMessagePack(commitment);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
public getDebugFunctionName = async (address: string, selector: string): Promise<string | undefined> => {
|
|
84
|
+
this.log.debug(`Contract provider callback: getDebugFunctionName(${address}, ${selector})`);
|
|
85
|
+
|
|
86
|
+
// Parse address and selector strings
|
|
87
|
+
const aztecAddr = AztecAddress.fromString(address);
|
|
88
|
+
const selectorFr = Fr.fromString(selector);
|
|
89
|
+
const functionSelector = FunctionSelector.fromField(selectorFr);
|
|
90
|
+
|
|
91
|
+
// Fetch debug function name from the contracts DB
|
|
92
|
+
const name = await this.contractsDB.getDebugFunctionName(aztecAddr, functionSelector);
|
|
93
|
+
|
|
94
|
+
if (!name) {
|
|
95
|
+
this.log.debug(`Debug function name not found for ${address}:${selector}`);
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return name;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
public createCheckpoint = (): Promise<void> => {
|
|
103
|
+
this.log.debug(`Contract provider callback: createCheckpoint`);
|
|
104
|
+
return Promise.resolve(this.contractsDB.createCheckpoint());
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
public commitCheckpoint = (): Promise<void> => {
|
|
108
|
+
this.log.debug(`Contract provider callback: commitCheckpoint`);
|
|
109
|
+
return Promise.resolve(this.contractsDB.commitCheckpoint());
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
public revertCheckpoint = (): Promise<void> => {
|
|
113
|
+
this.log.debug(`Contract provider callback: revertCheckpoint`);
|
|
114
|
+
return Promise.resolve(this.contractsDB.revertCheckpoint());
|
|
115
|
+
};
|
|
116
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
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, Tx } from '@aztec/stdlib/tx';
|
|
14
|
+
import { WorldStateRevisionWithHandle } from '@aztec/stdlib/world-state';
|
|
15
|
+
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
16
|
+
|
|
17
|
+
import { strict as assert } from 'assert';
|
|
18
|
+
|
|
19
|
+
import { ExecutorMetrics } from '../executor_metrics.js';
|
|
20
|
+
import type { ExecutorMetricsInterface } from '../executor_metrics_interface.js';
|
|
21
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
22
|
+
import { ContractProviderForCpp } from './contract_provider_for_cpp.js';
|
|
23
|
+
import { PublicTxSimulator } from './public_tx_simulator.js';
|
|
24
|
+
import type {
|
|
25
|
+
MeasuredPublicTxSimulatorInterface,
|
|
26
|
+
PublicTxSimulatorInterface,
|
|
27
|
+
} from './public_tx_simulator_interface.js';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* C++ implementation of PublicTxSimulator using the C++ simulator.
|
|
31
|
+
* The C++ simulator accesses the world state directly/natively within C++.
|
|
32
|
+
* For contract DB accesses, it makes callbacks through NAPI back to the TS PublicContractsDB cache.
|
|
33
|
+
*/
|
|
34
|
+
export class CppPublicTxSimulator extends PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
35
|
+
protected override log: Logger;
|
|
36
|
+
|
|
37
|
+
constructor(
|
|
38
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
39
|
+
contractsDB: PublicContractsDB,
|
|
40
|
+
globalVariables: GlobalVariables,
|
|
41
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
42
|
+
) {
|
|
43
|
+
super(merkleTree, contractsDB, globalVariables, config);
|
|
44
|
+
this.log = createLogger(`simulator:cpp_public_tx_simulator`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Simulate a transaction's public portion using the C++ avvm simulator.
|
|
49
|
+
*
|
|
50
|
+
* @param tx - The transaction to simulate.
|
|
51
|
+
* @returns The result of the transaction's public execution.
|
|
52
|
+
*/
|
|
53
|
+
public override async simulate(tx: Tx): Promise<PublicTxResult> {
|
|
54
|
+
const txHash = this.computeTxHash(tx);
|
|
55
|
+
this.log.debug(`C++ simulation of ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, {
|
|
56
|
+
txHash,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Using the "as WorldStateRevisionWithHandle" is a bit of a "trust me bro", hence the assert.
|
|
60
|
+
let wsRevision = this.merkleTree.getRevision();
|
|
61
|
+
assert(
|
|
62
|
+
wsRevision instanceof WorldStateRevisionWithHandle,
|
|
63
|
+
'CppPublicTxSimulator a real NativeWorldStateInstance with a handle to the C++ WorldState object',
|
|
64
|
+
);
|
|
65
|
+
const wsCppHandle = (wsRevision as WorldStateRevisionWithHandle).handle;
|
|
66
|
+
wsRevision = wsRevision.toWorldStateRevision(); // for msgpack serialization, we don't include the handle in the type
|
|
67
|
+
|
|
68
|
+
this.log.trace(`Running C++ simulation with world state revision ${JSON.stringify(wsRevision)}`);
|
|
69
|
+
|
|
70
|
+
// Create the fast simulation inputs
|
|
71
|
+
const txHint = AvmTxHint.fromTx(tx, this.globalVariables.gasFees);
|
|
72
|
+
const protocolContracts = ProtocolContractsList;
|
|
73
|
+
const fastSimInputs = new AvmFastSimulationInputs(
|
|
74
|
+
wsRevision,
|
|
75
|
+
this.config,
|
|
76
|
+
txHint,
|
|
77
|
+
this.globalVariables,
|
|
78
|
+
protocolContracts,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
// Create contract provider for callbacks to TypeScript PublicContractsDB from C++
|
|
82
|
+
const contractProvider = new ContractProviderForCpp(this.contractsDB, this.globalVariables);
|
|
83
|
+
|
|
84
|
+
// Serialize to msgpack and call the C++ simulator
|
|
85
|
+
this.log.trace(`Serializing fast simulation inputs to msgpack...`);
|
|
86
|
+
const inputBuffer = fastSimInputs.serializeWithMessagePack();
|
|
87
|
+
|
|
88
|
+
let resultBuffer: Buffer;
|
|
89
|
+
try {
|
|
90
|
+
this.log.debug(`Calling C++ simulator for tx ${txHash}`);
|
|
91
|
+
resultBuffer = await avmSimulate(inputBuffer, contractProvider, wsCppHandle, logLevel);
|
|
92
|
+
} catch (error: any) {
|
|
93
|
+
throw new SimulationError(`C++ simulation failed: ${error.message}`, []);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// If we've reached this point, C++ succeeded during simulation,
|
|
97
|
+
|
|
98
|
+
// Deserialize the msgpack result
|
|
99
|
+
this.log.trace(`Deserializing C++ from buffer (size: ${resultBuffer.length})...`);
|
|
100
|
+
const cppResultJSON: object = deserializeFromMessagePack(resultBuffer);
|
|
101
|
+
this.log.trace(`Deserializing C++ result to PublicTxResult...`);
|
|
102
|
+
const cppResult = PublicTxResult.fromPlainObject(cppResultJSON);
|
|
103
|
+
|
|
104
|
+
this.log.trace(`C++ simulation completed for tx ${txHash}`, {
|
|
105
|
+
txHash,
|
|
106
|
+
reverted: !cppResult.revertCode.isOK(),
|
|
107
|
+
cppGasUsed: cppResult.gasUsed.totalGas.l2Gas,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return cppResult;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export class MeasuredCppPublicTxSimulator extends CppPublicTxSimulator implements MeasuredPublicTxSimulatorInterface {
|
|
115
|
+
constructor(
|
|
116
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
117
|
+
contractsDB: PublicContractsDB,
|
|
118
|
+
globalVariables: GlobalVariables,
|
|
119
|
+
protected readonly metrics: ExecutorMetricsInterface,
|
|
120
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
121
|
+
) {
|
|
122
|
+
super(merkleTree, contractsDB, globalVariables, config);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public override async simulate(tx: Tx, txLabel: string = 'unlabeledTx'): Promise<PublicTxResult> {
|
|
126
|
+
this.metrics.startRecordingTxSimulation(txLabel);
|
|
127
|
+
let result: PublicTxResult | undefined;
|
|
128
|
+
try {
|
|
129
|
+
result = await super.simulate(tx);
|
|
130
|
+
} finally {
|
|
131
|
+
this.metrics.stopRecordingTxSimulation(txLabel, result?.gasUsed, result?.revertCode);
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* A C++ public tx simulator that tracks runtime/production metrics with telemetry.
|
|
139
|
+
*/
|
|
140
|
+
export class TelemetryCppPublicTxSimulator extends MeasuredCppPublicTxSimulator {
|
|
141
|
+
/* tracer needed by trackSpans */
|
|
142
|
+
public readonly tracer: Tracer;
|
|
143
|
+
|
|
144
|
+
constructor(
|
|
145
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
146
|
+
contractsDB: PublicContractsDB,
|
|
147
|
+
globalVariables: GlobalVariables,
|
|
148
|
+
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
149
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
150
|
+
) {
|
|
151
|
+
const metrics = new ExecutorMetrics(telemetryClient, 'CppPublicTxSimulator');
|
|
152
|
+
super(merkleTree, contractsDB, globalVariables, metrics, config);
|
|
153
|
+
this.tracer = metrics.tracer;
|
|
154
|
+
}
|
|
155
|
+
}
|