@aztec/simulator 0.0.1-commit.9593d84 → 0.0.1-commit.96dac018d
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 +21 -18
- 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 +22 -3
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +79 -15
- package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
- package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
- package/dest/public/fixtures/simple_contract_data_source.js +4 -4
- package/dest/public/fixtures/token_test.d.ts +6 -2
- package/dest/public/fixtures/token_test.d.ts.map +1 -1
- package/dest/public/fixtures/token_test.js +13 -11
- package/dest/public/fixtures/utils.d.ts +2 -2
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +8 -7
- 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 +458 -51
- 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 +22 -19
- 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 +103 -16
- 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 +6 -7
- 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 +84 -45
- 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,175 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import {
|
|
4
|
+
AvmCircuitPublicInputs,
|
|
5
|
+
type AvmTxHint,
|
|
6
|
+
PublicTxEffect,
|
|
7
|
+
deserializeFromMessagePack,
|
|
8
|
+
serializeWithMessagePack,
|
|
9
|
+
} from '@aztec/stdlib/avm';
|
|
10
|
+
import { GlobalVariables, ProtocolContracts, TreeSnapshots } from '@aztec/stdlib/tx';
|
|
11
|
+
import { NativeWorldStateService } from '@aztec/world-state';
|
|
12
|
+
|
|
13
|
+
import { createInterface } from 'readline';
|
|
14
|
+
|
|
15
|
+
import { AvmFuzzerSimulator, FuzzerSimulationRequest } from './avm_fuzzer_simulator.js';
|
|
16
|
+
|
|
17
|
+
/** Write data to stdout, letting Node handle buffering. */
|
|
18
|
+
function writeOutput(data: string): Promise<void> {
|
|
19
|
+
return new Promise<void>((resolve, reject) => {
|
|
20
|
+
process.stdout.write(data, err => {
|
|
21
|
+
if (err) {
|
|
22
|
+
reject(err);
|
|
23
|
+
} else {
|
|
24
|
+
resolve();
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// This cache holds opened world states to avoid reopening them for each invocation.
|
|
31
|
+
// It's a map so that in the future we could support multiple world states (if we had multiple fuzzers).
|
|
32
|
+
const worldStateCache = new Map<string, NativeWorldStateService>();
|
|
33
|
+
|
|
34
|
+
async function openExistingWorldState(dataDir: string, mapSizeKb: number): Promise<NativeWorldStateService> {
|
|
35
|
+
const cached = worldStateCache.get(dataDir);
|
|
36
|
+
if (cached) {
|
|
37
|
+
return cached;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const ws = await NativeWorldStateService.new(EthAddress.ZERO, dataDir, {
|
|
41
|
+
archiveTreeMapSizeKb: mapSizeKb,
|
|
42
|
+
nullifierTreeMapSizeKb: mapSizeKb,
|
|
43
|
+
noteHashTreeMapSizeKb: mapSizeKb,
|
|
44
|
+
messageTreeMapSizeKb: mapSizeKb,
|
|
45
|
+
publicDataTreeMapSizeKb: mapSizeKb,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
worldStateCache.set(dataDir, ws);
|
|
49
|
+
return ws;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function simulateWithFuzzer(
|
|
53
|
+
dataDir: string,
|
|
54
|
+
mapSizeKb: number,
|
|
55
|
+
txHint: AvmTxHint,
|
|
56
|
+
globals: GlobalVariables,
|
|
57
|
+
rawContractClasses: any[], // Replace these when we are moving contract classes to TS
|
|
58
|
+
rawContractInstances: [any, any][], // Replace these when we are moving contract instances to TS
|
|
59
|
+
rawPublicDataWrites: any[], // Public data tree writes to apply before simulation
|
|
60
|
+
rawNoteHashes: any[], // Note hashes to apply before simulation
|
|
61
|
+
protocolContracts: ProtocolContracts, // Protocol contracts mapping from C++
|
|
62
|
+
): Promise<{
|
|
63
|
+
reverted: boolean;
|
|
64
|
+
output: Fr[];
|
|
65
|
+
revertReason?: string;
|
|
66
|
+
publicInputs: AvmCircuitPublicInputs;
|
|
67
|
+
publicTxEffect: PublicTxEffect;
|
|
68
|
+
}> {
|
|
69
|
+
const worldStateService = await openExistingWorldState(dataDir, mapSizeKb);
|
|
70
|
+
|
|
71
|
+
const simulator = await AvmFuzzerSimulator.create(worldStateService, globals, protocolContracts);
|
|
72
|
+
|
|
73
|
+
await simulator.applyNoteHashes(rawNoteHashes);
|
|
74
|
+
|
|
75
|
+
// Register contract classes from C++ (must happen before public data writes to match C++ order)
|
|
76
|
+
for (const rawClass of rawContractClasses) {
|
|
77
|
+
await simulator.addContractClassFromCpp(rawClass);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Register contract instances from C++
|
|
81
|
+
for (const [rawAddress, rawInstance] of rawContractInstances) {
|
|
82
|
+
await simulator.addContractInstanceFromCpp(rawAddress, rawInstance);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Apply public data writes after contract registration (e.g., for bytecode upgrades)
|
|
86
|
+
// This must happen last to match C++ setup_fuzzer_state ordering
|
|
87
|
+
await simulator.applyPublicDataWrites(rawPublicDataWrites);
|
|
88
|
+
|
|
89
|
+
const result = await simulator.simulate(txHint);
|
|
90
|
+
|
|
91
|
+
const output = result
|
|
92
|
+
.getAppLogicReturnValues()
|
|
93
|
+
.flatMap((rv: { values?: Fr[] } | undefined) => rv?.values?.filter((v: Fr | null | undefined) => v != null) ?? []);
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
reverted: !result.revertCode.isOK(),
|
|
97
|
+
output,
|
|
98
|
+
revertReason: result.findRevertReason()?.message,
|
|
99
|
+
publicInputs: result.publicInputs!,
|
|
100
|
+
publicTxEffect: result.publicTxEffect,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function execute(base64Line: string): Promise<void> {
|
|
105
|
+
try {
|
|
106
|
+
// Decode base64 and deserialize the entire request from msgpack
|
|
107
|
+
const buffer = Buffer.from(base64Line.trim(), 'base64');
|
|
108
|
+
const rawRequest = deserializeFromMessagePack(buffer);
|
|
109
|
+
const request = FuzzerSimulationRequest.fromPlainObject(rawRequest);
|
|
110
|
+
|
|
111
|
+
// Run the TS simulation
|
|
112
|
+
const result = await simulateWithFuzzer(
|
|
113
|
+
request.wsDataDir,
|
|
114
|
+
request.wsMapSizeKb,
|
|
115
|
+
request.tx,
|
|
116
|
+
request.globals,
|
|
117
|
+
request.contractClasses,
|
|
118
|
+
request.contractInstances,
|
|
119
|
+
request.publicDataWrites,
|
|
120
|
+
request.noteHashes,
|
|
121
|
+
request.protocolContracts,
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// Serialize the result to msgpack and encode it in base64 for output
|
|
125
|
+
const resultBuffer = serializeWithMessagePack({
|
|
126
|
+
reverted: result.reverted,
|
|
127
|
+
output: result.output,
|
|
128
|
+
revertReason: result.revertReason ?? '',
|
|
129
|
+
endTreeSnapshots: result.publicInputs.endTreeSnapshots,
|
|
130
|
+
publicTxEffect: result.publicTxEffect,
|
|
131
|
+
});
|
|
132
|
+
const base64Response = resultBuffer.toString('base64') + '\n';
|
|
133
|
+
await writeOutput(base64Response);
|
|
134
|
+
} catch (error: any) {
|
|
135
|
+
// If we error, treat as reverted
|
|
136
|
+
const errorResult = serializeWithMessagePack({
|
|
137
|
+
reverted: true,
|
|
138
|
+
output: [] as Fr[],
|
|
139
|
+
revertReason: `Unexpected Error ${error.message}`,
|
|
140
|
+
endTreeSnapshots: TreeSnapshots.empty(),
|
|
141
|
+
publicTxEffect: PublicTxEffect.empty(),
|
|
142
|
+
});
|
|
143
|
+
await writeOutput(errorResult.toString('base64') + '\n');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function mainLoop() {
|
|
148
|
+
const rl = createInterface({ input: process.stdin, terminal: false });
|
|
149
|
+
|
|
150
|
+
// Process lines sequentially to avoid race conditions in responses
|
|
151
|
+
const lineQueue: string[] = [];
|
|
152
|
+
let processing = false;
|
|
153
|
+
|
|
154
|
+
async function processQueue() {
|
|
155
|
+
if (processing || lineQueue.length === 0) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
processing = true;
|
|
159
|
+
while (lineQueue.length > 0) {
|
|
160
|
+
const line = lineQueue.shift()!;
|
|
161
|
+
await execute(line);
|
|
162
|
+
}
|
|
163
|
+
processing = false;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
rl.on('line', (line: string) => {
|
|
167
|
+
if (line.trim()) {
|
|
168
|
+
lineQueue.push(line);
|
|
169
|
+
void processQueue();
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
rl.on('close', () => process.exit(0));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
void mainLoop();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { sha256Trunc } from '@aztec/foundation/crypto/sha256';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
5
|
import type { IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
|
|
5
6
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
@@ -571,6 +572,10 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
|
|
|
571
572
|
return await this.db.close();
|
|
572
573
|
}
|
|
573
574
|
|
|
575
|
+
async [Symbol.asyncDispose](): Promise<void> {
|
|
576
|
+
await this.close();
|
|
577
|
+
}
|
|
578
|
+
|
|
574
579
|
public async findLeafIndices<ID extends MerkleTreeId>(
|
|
575
580
|
treeId: ID,
|
|
576
581
|
values: MerkleTreeLeafType<ID>[],
|
|
@@ -596,7 +601,7 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
|
|
|
596
601
|
public async getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
|
|
597
602
|
treeId: ID,
|
|
598
603
|
leafIndices: bigint[],
|
|
599
|
-
): Promise<(
|
|
604
|
+
): Promise<(BlockNumber | undefined)[]> {
|
|
600
605
|
return await this.db.getBlockNumbersForLeafIndices(treeId, leafIndices);
|
|
601
606
|
}
|
|
602
607
|
}
|
package/src/public/index.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export { PublicContractsDB } from './public_db_sources.js';
|
|
2
2
|
export { GuardedMerkleTreeOperations } from './public_processor/guarded_merkle_tree.js';
|
|
3
3
|
export { PublicProcessor, PublicProcessorFactory } from './public_processor/public_processor.js';
|
|
4
|
-
export {
|
|
4
|
+
export {
|
|
5
|
+
CppPublicTxSimulator,
|
|
6
|
+
createPublicTxSimulatorForBlockBuilding,
|
|
7
|
+
DumpingCppPublicTxSimulator,
|
|
8
|
+
type PublicTxSimulatorInterface,
|
|
9
|
+
TelemetryCppPublicTxSimulator,
|
|
10
|
+
} from './public_tx_simulator/index.js';
|
|
5
11
|
export type { PublicTxResult, PublicSimulatorConfig as PublicTxSimulatorConfig } from '@aztec/stdlib/avm';
|
|
6
12
|
export { getCallRequestsWithCalldataByPhase } from './utils.js';
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
NULLIFIER_SUBTREE_HEIGHT,
|
|
5
5
|
PUBLIC_DATA_SUBTREE_HEIGHT,
|
|
6
6
|
} from '@aztec/constants';
|
|
7
|
-
import { Fr } from '@aztec/foundation/
|
|
8
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
8
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
9
9
|
import { Timer } from '@aztec/foundation/timer';
|
|
10
10
|
import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
|
|
11
11
|
import { ContractInstancePublishedEvent } from '@aztec/protocol-contracts/instance-registry';
|
|
@@ -46,9 +46,14 @@ import { L1ToL2MessageIndexOutOfRangeError, NoteHashIndexOutOfRangeError } from
|
|
|
46
46
|
export class PublicContractsDB implements PublicContractsDBInterface {
|
|
47
47
|
private contractStateStack: ContractsDbCheckpoint[] = [new ContractsDbCheckpoint()];
|
|
48
48
|
|
|
49
|
-
private log
|
|
49
|
+
private log: Logger;
|
|
50
50
|
|
|
51
|
-
constructor(
|
|
51
|
+
constructor(
|
|
52
|
+
private dataSource: ContractDataSource,
|
|
53
|
+
bindings?: LoggerBindings,
|
|
54
|
+
) {
|
|
55
|
+
this.log = createLogger('simulator:contracts-data-source', bindings);
|
|
56
|
+
}
|
|
52
57
|
|
|
53
58
|
public async addContracts(contractDeploymentData: ContractDeploymentData): Promise<void> {
|
|
54
59
|
const currentState = this.getCurrentState();
|
|
@@ -208,9 +213,14 @@ export class PublicContractsDB implements PublicContractsDBInterface {
|
|
|
208
213
|
* to decide whether to use hints or not (same with tracing, etc).
|
|
209
214
|
*/
|
|
210
215
|
export class PublicTreesDB implements PublicStateDBInterface {
|
|
211
|
-
private logger
|
|
216
|
+
private logger: Logger;
|
|
212
217
|
|
|
213
|
-
constructor(
|
|
218
|
+
constructor(
|
|
219
|
+
private readonly db: MerkleTreeWriteOperations,
|
|
220
|
+
bindings?: LoggerBindings,
|
|
221
|
+
) {
|
|
222
|
+
this.logger = createLogger('simulator:public-trees-db', bindings);
|
|
223
|
+
}
|
|
214
224
|
|
|
215
225
|
public async storageRead(contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
216
226
|
const timer = new Timer();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
2
3
|
import type { IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
|
|
3
4
|
import type {
|
|
@@ -80,6 +81,10 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
|
|
|
80
81
|
close(): Promise<void> {
|
|
81
82
|
return this.guardAndPush(() => this.target.close());
|
|
82
83
|
}
|
|
84
|
+
|
|
85
|
+
async [Symbol.asyncDispose](): Promise<void> {
|
|
86
|
+
await this.close();
|
|
87
|
+
}
|
|
83
88
|
getTreeInfo(treeId: MerkleTreeId): Promise<TreeInfo> {
|
|
84
89
|
return this.guardAndPush(() => this.target.getTreeInfo(treeId));
|
|
85
90
|
}
|
|
@@ -126,7 +131,7 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
|
|
|
126
131
|
getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
|
|
127
132
|
treeId: ID,
|
|
128
133
|
leafIndices: bigint[],
|
|
129
|
-
): Promise<(
|
|
134
|
+
): Promise<(BlockNumber | undefined)[]> {
|
|
130
135
|
return this.guardAndPush(() => this.target.getBlockNumbersForLeafIndices(treeId, leafIndices));
|
|
131
136
|
}
|
|
132
137
|
createCheckpoint(): Promise<void> {
|
|
@@ -1,7 +1,7 @@
|
|
|
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/
|
|
4
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
+
import { type Logger, type LoggerBindings, 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';
|
|
@@ -25,6 +25,7 @@ import type {
|
|
|
25
25
|
PublicProcessorValidator,
|
|
26
26
|
SequencerConfig,
|
|
27
27
|
} from '@aztec/stdlib/interfaces/server';
|
|
28
|
+
import { type DebugLog, type DebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
28
29
|
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
29
30
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
30
31
|
import {
|
|
@@ -51,9 +52,9 @@ import { AssertionError } from 'assert';
|
|
|
51
52
|
|
|
52
53
|
import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
|
|
53
54
|
import {
|
|
54
|
-
type PublicTxSimulator,
|
|
55
55
|
type PublicTxSimulatorConfig,
|
|
56
|
-
|
|
56
|
+
type PublicTxSimulatorInterface,
|
|
57
|
+
TelemetryCppPublicTxSimulator,
|
|
57
58
|
} from '../public_tx_simulator/index.js';
|
|
58
59
|
import { GuardedMerkleTreeOperations } from './guarded_merkle_tree.js';
|
|
59
60
|
import { PublicProcessorMetrics } from './public_processor_metrics.js';
|
|
@@ -62,11 +63,15 @@ import { PublicProcessorMetrics } from './public_processor_metrics.js';
|
|
|
62
63
|
* Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
|
|
63
64
|
*/
|
|
64
65
|
export class PublicProcessorFactory {
|
|
66
|
+
private log: Logger;
|
|
65
67
|
constructor(
|
|
66
68
|
private contractDataSource: ContractDataSource,
|
|
67
69
|
private dateProvider: DateProvider = new DateProvider(),
|
|
68
70
|
protected telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
69
|
-
|
|
71
|
+
bindings?: LoggerBindings,
|
|
72
|
+
) {
|
|
73
|
+
this.log = createLogger('simulator:public-processor-factory', bindings);
|
|
74
|
+
}
|
|
70
75
|
|
|
71
76
|
/**
|
|
72
77
|
* Creates a new instance of a PublicProcessor.
|
|
@@ -79,7 +84,8 @@ export class PublicProcessorFactory {
|
|
|
79
84
|
globalVariables: GlobalVariables,
|
|
80
85
|
config: PublicSimulatorConfig,
|
|
81
86
|
): PublicProcessor {
|
|
82
|
-
const
|
|
87
|
+
const bindings = this.log.getBindings();
|
|
88
|
+
const contractsDB = new PublicContractsDB(this.contractDataSource, bindings);
|
|
83
89
|
|
|
84
90
|
const guardedFork = new GuardedMerkleTreeOperations(merkleTree);
|
|
85
91
|
const publicTxSimulator = this.createPublicTxSimulator(guardedFork, contractsDB, globalVariables, config);
|
|
@@ -91,6 +97,7 @@ export class PublicProcessorFactory {
|
|
|
91
97
|
publicTxSimulator,
|
|
92
98
|
this.dateProvider,
|
|
93
99
|
this.telemetryClient,
|
|
100
|
+
createLogger('simulator:public-processor', bindings),
|
|
94
101
|
);
|
|
95
102
|
}
|
|
96
103
|
|
|
@@ -99,8 +106,15 @@ export class PublicProcessorFactory {
|
|
|
99
106
|
contractsDB: PublicContractsDB,
|
|
100
107
|
globalVariables: GlobalVariables,
|
|
101
108
|
config?: Partial<PublicTxSimulatorConfig>,
|
|
102
|
-
):
|
|
103
|
-
return new
|
|
109
|
+
): PublicTxSimulatorInterface {
|
|
110
|
+
return new TelemetryCppPublicTxSimulator(
|
|
111
|
+
merkleTree,
|
|
112
|
+
contractsDB,
|
|
113
|
+
globalVariables,
|
|
114
|
+
this.telemetryClient,
|
|
115
|
+
config,
|
|
116
|
+
this.log.getBindings(),
|
|
117
|
+
);
|
|
104
118
|
}
|
|
105
119
|
}
|
|
106
120
|
|
|
@@ -117,16 +131,16 @@ class PublicProcessorTimeoutError extends Error {
|
|
|
117
131
|
*/
|
|
118
132
|
export class PublicProcessor implements Traceable {
|
|
119
133
|
private metrics: PublicProcessorMetrics;
|
|
120
|
-
|
|
121
134
|
constructor(
|
|
122
135
|
protected globalVariables: GlobalVariables,
|
|
123
136
|
private guardedMerkleTree: GuardedMerkleTreeOperations,
|
|
124
137
|
protected contractsDB: PublicContractsDB,
|
|
125
|
-
protected publicTxSimulator:
|
|
138
|
+
protected publicTxSimulator: PublicTxSimulatorInterface,
|
|
126
139
|
private dateProvider: DateProvider,
|
|
127
140
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
128
|
-
private log
|
|
129
|
-
private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs'> = {},
|
|
141
|
+
private log: Logger,
|
|
142
|
+
private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs' | 'fakeThrowAfterProcessingTxCount'> = {},
|
|
143
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
130
144
|
) {
|
|
131
145
|
this.metrics = new PublicProcessorMetrics(telemetryClient, 'PublicProcessor');
|
|
132
146
|
}
|
|
@@ -146,12 +160,13 @@ export class PublicProcessor implements Traceable {
|
|
|
146
160
|
txs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
147
161
|
limits: PublicProcessorLimits = {},
|
|
148
162
|
validator: PublicProcessorValidator = {},
|
|
149
|
-
): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[]]> {
|
|
163
|
+
): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[], number, DebugLog[]]> {
|
|
150
164
|
const { maxTransactions, maxBlockSize, deadline, maxBlockGas, maxBlobFields } = limits;
|
|
151
165
|
const { preprocessValidator, nullifierCache } = validator;
|
|
152
166
|
const result: ProcessedTx[] = [];
|
|
153
167
|
const usedTxs: Tx[] = [];
|
|
154
168
|
const failed: FailedTx[] = [];
|
|
169
|
+
const debugLogs: DebugLog[] = [];
|
|
155
170
|
const timer = new Timer();
|
|
156
171
|
|
|
157
172
|
let totalSizeInBytes = 0;
|
|
@@ -160,7 +175,7 @@ export class PublicProcessor implements Traceable {
|
|
|
160
175
|
let totalBlockGas = new Gas(0, 0);
|
|
161
176
|
let totalBlobFields = 0;
|
|
162
177
|
|
|
163
|
-
for await (const
|
|
178
|
+
for await (const tx of txs) {
|
|
164
179
|
// Only process up to the max tx limit
|
|
165
180
|
if (maxTransactions !== undefined && result.length >= maxTransactions) {
|
|
166
181
|
this.log.debug(`Stopping tx processing due to reaching the max tx limit.`);
|
|
@@ -174,8 +189,8 @@ export class PublicProcessor implements Traceable {
|
|
|
174
189
|
}
|
|
175
190
|
|
|
176
191
|
// Skip this tx if it'd exceed max block size
|
|
177
|
-
const txHash =
|
|
178
|
-
const preTxSizeInBytes =
|
|
192
|
+
const txHash = tx.getTxHash().toString();
|
|
193
|
+
const preTxSizeInBytes = tx.getEstimatedPrivateTxEffectsSize();
|
|
179
194
|
if (maxBlockSize !== undefined && totalSizeInBytes + preTxSizeInBytes > maxBlockSize) {
|
|
180
195
|
this.log.warn(`Skipping processing of tx ${txHash} sized ${preTxSizeInBytes} bytes due to block size limit`, {
|
|
181
196
|
txHash,
|
|
@@ -187,7 +202,7 @@ export class PublicProcessor implements Traceable {
|
|
|
187
202
|
}
|
|
188
203
|
|
|
189
204
|
// Skip this tx if its gas limit would exceed the block gas limit
|
|
190
|
-
const txGasLimit =
|
|
205
|
+
const txGasLimit = tx.data.constants.txContext.gasSettings.gasLimits;
|
|
191
206
|
if (maxBlockGas !== undefined && totalBlockGas.add(txGasLimit).gtAny(maxBlockGas)) {
|
|
192
207
|
this.log.warn(`Skipping processing of tx ${txHash} due to block gas limit`, {
|
|
193
208
|
txHash,
|
|
@@ -198,9 +213,6 @@ export class PublicProcessor implements Traceable {
|
|
|
198
213
|
continue;
|
|
199
214
|
}
|
|
200
215
|
|
|
201
|
-
// The processor modifies the tx objects in place, so we need to clone them.
|
|
202
|
-
const tx = Tx.clone(origTx);
|
|
203
|
-
|
|
204
216
|
// We validate the tx before processing it, to avoid unnecessary work.
|
|
205
217
|
if (preprocessValidator) {
|
|
206
218
|
const result = await preprocessValidator.validateTx(tx);
|
|
@@ -231,7 +243,13 @@ export class PublicProcessor implements Traceable {
|
|
|
231
243
|
this.contractsDB.createCheckpoint();
|
|
232
244
|
|
|
233
245
|
try {
|
|
234
|
-
const [processedTx, returnValues] = await this.processTx(tx, deadline);
|
|
246
|
+
const [processedTx, returnValues, txDebugLogs] = await this.processTx(tx, deadline);
|
|
247
|
+
|
|
248
|
+
// Inject a fake processing failure after N txs if requested
|
|
249
|
+
const fakeThrowAfter = this.opts.fakeThrowAfterProcessingTxCount;
|
|
250
|
+
if (fakeThrowAfter !== undefined && result.length + failed.length + 1 >= fakeThrowAfter) {
|
|
251
|
+
throw new Error(`Fake error after processing ${fakeThrowAfter} txs`);
|
|
252
|
+
}
|
|
235
253
|
|
|
236
254
|
const txBlobFields = processedTx.txEffect.getNumBlobFields();
|
|
237
255
|
|
|
@@ -251,6 +269,7 @@ export class PublicProcessor implements Traceable {
|
|
|
251
269
|
}
|
|
252
270
|
|
|
253
271
|
// If the actual blob fields of this tx would exceed the limit, skip it
|
|
272
|
+
// Note: maxBlobFields already accounts for block end blob fields and previous blocks in checkpoint.
|
|
254
273
|
if (maxBlobFields !== undefined && totalBlobFields + txBlobFields > maxBlobFields) {
|
|
255
274
|
this.log.debug(
|
|
256
275
|
`Skipping processed tx ${txHash} with ${txBlobFields} blob fields due to max blob fields limit.`,
|
|
@@ -273,6 +292,9 @@ export class PublicProcessor implements Traceable {
|
|
|
273
292
|
result.push(processedTx);
|
|
274
293
|
usedTxs.push(tx);
|
|
275
294
|
returns = returns.concat(returnValues);
|
|
295
|
+
debugLogs.push(...txDebugLogs);
|
|
296
|
+
|
|
297
|
+
this.debugLogStore.storeLogs(processedTx.hash.toString(), txDebugLogs);
|
|
276
298
|
|
|
277
299
|
totalPublicGas = totalPublicGas.add(processedTx.gasUsed.publicGas);
|
|
278
300
|
totalBlockGas = totalBlockGas.add(processedTx.gasUsed.totalGas);
|
|
@@ -282,7 +304,15 @@ export class PublicProcessor implements Traceable {
|
|
|
282
304
|
if (err?.name === 'PublicProcessorTimeoutError') {
|
|
283
305
|
this.log.warn(`Stopping tx processing due to timeout.`);
|
|
284
306
|
// We hit the transaction execution deadline.
|
|
285
|
-
// There may still be a transaction executing
|
|
307
|
+
// There may still be a transaction executing on a worker thread (C++ via NAPI).
|
|
308
|
+
// Signal cancellation AND WAIT for the simulation to actually stop.
|
|
309
|
+
// This is critical because C++ might be in the middle of a slow operation (e.g., pad_trees)
|
|
310
|
+
// and won't check the cancellation flag until that operation completes.
|
|
311
|
+
// Without waiting, we'd proceed to revert checkpoints while C++ is still writing to state.
|
|
312
|
+
// Wait for C++ to stop gracefully.
|
|
313
|
+
await this.publicTxSimulator.cancel?.();
|
|
314
|
+
|
|
315
|
+
// Now stop the guarded fork to prevent any further TS-side access to the world state.
|
|
286
316
|
await this.guardedMerkleTree.stop();
|
|
287
317
|
|
|
288
318
|
// We now know there can't be any further access to world state. The fork is in a state where there is:
|
|
@@ -338,7 +368,7 @@ export class PublicProcessor implements Traceable {
|
|
|
338
368
|
totalSizeInBytes,
|
|
339
369
|
});
|
|
340
370
|
|
|
341
|
-
return [result, failed, usedTxs, returns];
|
|
371
|
+
return [result, failed, usedTxs, returns, totalBlobFields, debugLogs];
|
|
342
372
|
}
|
|
343
373
|
|
|
344
374
|
private async checkWorldStateUnchanged(
|
|
@@ -358,8 +388,13 @@ export class PublicProcessor implements Traceable {
|
|
|
358
388
|
}
|
|
359
389
|
|
|
360
390
|
@trackSpan('PublicProcessor.processTx', tx => ({ [Attributes.TX_HASH]: tx.getTxHash().toString() }))
|
|
361
|
-
private async processTx(
|
|
362
|
-
|
|
391
|
+
private async processTx(
|
|
392
|
+
tx: Tx,
|
|
393
|
+
deadline: Date | undefined,
|
|
394
|
+
): Promise<[ProcessedTx, NestedProcessReturnValues[], DebugLog[]]> {
|
|
395
|
+
const [time, [processedTx, returnValues, debugLogs]] = await elapsed(() =>
|
|
396
|
+
this.processTxWithinDeadline(tx, deadline),
|
|
397
|
+
);
|
|
363
398
|
|
|
364
399
|
this.log.verbose(
|
|
365
400
|
!tx.hasPublicCalls()
|
|
@@ -382,7 +417,7 @@ export class PublicProcessor implements Traceable {
|
|
|
382
417
|
},
|
|
383
418
|
);
|
|
384
419
|
|
|
385
|
-
return [processedTx, returnValues ?? []];
|
|
420
|
+
return [processedTx, returnValues ?? [], debugLogs];
|
|
386
421
|
}
|
|
387
422
|
|
|
388
423
|
private async doTreeInsertionsForPrivateOnlyTx(processedTx: ProcessedTx): Promise<void> {
|
|
@@ -416,10 +451,9 @@ export class PublicProcessor implements Traceable {
|
|
|
416
451
|
private async processTxWithinDeadline(
|
|
417
452
|
tx: Tx,
|
|
418
453
|
deadline: Date | undefined,
|
|
419
|
-
): Promise<[ProcessedTx, NestedProcessReturnValues[] | undefined]> {
|
|
420
|
-
const innerProcessFn: () => Promise<[ProcessedTx, NestedProcessReturnValues[] | undefined]> =
|
|
421
|
-
? () => this.processTxWithPublicCalls(tx)
|
|
422
|
-
: () => this.processPrivateOnlyTx(tx);
|
|
454
|
+
): Promise<[ProcessedTx, NestedProcessReturnValues[] | undefined, DebugLog[]]> {
|
|
455
|
+
const innerProcessFn: () => Promise<[ProcessedTx, NestedProcessReturnValues[] | undefined, DebugLog[]]> =
|
|
456
|
+
tx.hasPublicCalls() ? () => this.processTxWithPublicCalls(tx) : () => this.processPrivateOnlyTx(tx);
|
|
423
457
|
|
|
424
458
|
// Fake a delay per tx if instructed (used for tests)
|
|
425
459
|
const fakeDelayPerTxMs = this.opts.fakeProcessingDelayPerTxMs;
|
|
@@ -487,7 +521,7 @@ export class PublicProcessor implements Traceable {
|
|
|
487
521
|
@trackSpan('PublicProcessor.processPrivateOnlyTx', (tx: Tx) => ({
|
|
488
522
|
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
489
523
|
}))
|
|
490
|
-
private async processPrivateOnlyTx(tx: Tx): Promise<[ProcessedTx, undefined]> {
|
|
524
|
+
private async processPrivateOnlyTx(tx: Tx): Promise<[ProcessedTx, undefined, DebugLog[]]> {
|
|
491
525
|
const gasFees = this.globalVariables.gasFees;
|
|
492
526
|
const transactionFee = computeTransactionFee(gasFees, tx.data.constants.txContext.gasSettings, tx.data.gasUsed);
|
|
493
527
|
|
|
@@ -512,22 +546,18 @@ export class PublicProcessor implements Traceable {
|
|
|
512
546
|
|
|
513
547
|
await this.contractsDB.addNewContracts(tx);
|
|
514
548
|
|
|
515
|
-
return [processedTx, undefined];
|
|
549
|
+
return [processedTx, undefined, []];
|
|
516
550
|
}
|
|
517
551
|
|
|
518
552
|
@trackSpan('PublicProcessor.processTxWithPublicCalls', tx => ({
|
|
519
553
|
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
520
554
|
}))
|
|
521
|
-
private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, NestedProcessReturnValues[]]> {
|
|
555
|
+
private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, NestedProcessReturnValues[], DebugLog[]]> {
|
|
522
556
|
const timer = new Timer();
|
|
523
557
|
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
if (!hints) {
|
|
528
|
-
this.metrics.recordFailedTx();
|
|
529
|
-
throw new Error('Avm proving result was not generated.');
|
|
530
|
-
}
|
|
558
|
+
const result = await this.publicTxSimulator.simulate(tx);
|
|
559
|
+
// TODO: use the callStackMetadata here to extract more data about public execution
|
|
560
|
+
const { hints, publicInputs, publicTxEffect, gasUsed, revertCode /*callStackMetadata*/ } = result;
|
|
531
561
|
|
|
532
562
|
const contractClassLogs = revertCode.isOK()
|
|
533
563
|
? tx.getContractClassLogs()
|
|
@@ -539,19 +569,28 @@ export class PublicProcessor implements Traceable {
|
|
|
539
569
|
);
|
|
540
570
|
|
|
541
571
|
// TODO(fcarreiro): remove phase count metric.
|
|
542
|
-
const phaseCount = 1;
|
|
543
572
|
const durationMs = timer.ms();
|
|
544
|
-
this.metrics.recordTx(phaseCount, durationMs, gasUsed.publicGas);
|
|
573
|
+
this.metrics.recordTx(/*phaseCount=*/ 1, durationMs, gasUsed.publicGas);
|
|
574
|
+
|
|
575
|
+
// Extract the return values from the call stack metadata.
|
|
576
|
+
const appLogicReturnValues: NestedProcessReturnValues[] = result.getAppLogicReturnValues();
|
|
577
|
+
// Extract the revert reason from the call stack metadata.
|
|
578
|
+
const revertReason = result.findRevertReason();
|
|
579
|
+
// Create proving request if we have hints and public inputs.
|
|
580
|
+
const avmProvingRequest =
|
|
581
|
+
hints && publicInputs ? PublicProcessor.generateProvingRequest(publicInputs, hints) : undefined;
|
|
545
582
|
|
|
546
583
|
const processedTx = makeProcessedTxFromTxWithPublicCalls(
|
|
547
584
|
tx,
|
|
548
|
-
|
|
585
|
+
this.globalVariables,
|
|
586
|
+
avmProvingRequest,
|
|
587
|
+
publicTxEffect,
|
|
549
588
|
gasUsed,
|
|
550
589
|
revertCode,
|
|
551
590
|
revertReason,
|
|
552
591
|
);
|
|
553
592
|
|
|
554
|
-
return [processedTx, appLogicReturnValues ?? []];
|
|
593
|
+
return [processedTx, appLogicReturnValues, result.logs ?? []];
|
|
555
594
|
}
|
|
556
595
|
|
|
557
596
|
/**
|
|
@@ -559,7 +598,7 @@ export class PublicProcessor implements Traceable {
|
|
|
559
598
|
*/
|
|
560
599
|
private static generateProvingRequest(
|
|
561
600
|
publicInputs: AvmCircuitPublicInputs,
|
|
562
|
-
hints: AvmExecutionHints,
|
|
601
|
+
hints: AvmExecutionHints = AvmExecutionHints.empty(),
|
|
563
602
|
): AvmProvingRequest {
|
|
564
603
|
return {
|
|
565
604
|
type: ProvingRequestType.PUBLIC_VM,
|