@aztec/simulator 0.0.0-test.1 → 0.0.1-commit.24de95ac
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 -0
- package/dest/client.d.ts +5 -3
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +4 -2
- package/dest/common/errors.d.ts +4 -7
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/common/errors.js +51 -32
- package/dest/common/index.d.ts +0 -1
- package/dest/common/index.d.ts.map +1 -1
- package/dest/common/index.js +0 -1
- package/dest/private/acvm/acvm.d.ts +11 -5
- package/dest/private/acvm/acvm.d.ts.map +1 -1
- package/dest/private/acvm/acvm.js +10 -16
- package/dest/private/acvm/acvm_types.d.ts +1 -1
- package/dest/private/acvm/acvm_types.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.d.ts +17 -18
- package/dest/private/acvm/deserialize.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.js +31 -23
- package/dest/private/acvm/index.d.ts +0 -1
- package/dest/private/acvm/index.d.ts.map +1 -1
- package/dest/private/acvm/index.js +0 -1
- package/dest/private/acvm/serialize.d.ts +19 -2
- package/dest/private/acvm/serialize.d.ts.map +1 -1
- package/dest/private/acvm/serialize.js +53 -0
- package/dest/private/{providers/acvm_native.d.ts → acvm_native.d.ts} +9 -10
- package/dest/private/acvm_native.d.ts.map +1 -0
- package/dest/private/{providers/acvm_native.js → acvm_native.js} +26 -20
- package/dest/private/acvm_wasm.d.ts +15 -0
- package/dest/private/acvm_wasm.d.ts.map +1 -0
- package/dest/private/{providers/acvm_wasm.js → acvm_wasm.js} +22 -19
- package/dest/private/acvm_wasm_with_blobs.d.ts +20 -0
- package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -0
- package/dest/private/acvm_wasm_with_blobs.js +35 -0
- package/dest/private/circuit_recording/circuit_recorder.d.ts +108 -0
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -0
- package/dest/private/circuit_recording/circuit_recorder.js +209 -0
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts +31 -0
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -0
- package/dest/private/circuit_recording/file_circuit_recorder.js +135 -0
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +5 -0
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -0
- package/dest/private/circuit_recording/memory_circuit_recorder.js +9 -0
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +21 -0
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -0
- package/dest/private/circuit_recording/simulator_recorder_wrapper.js +44 -0
- package/dest/private/circuit_simulator.d.ts +35 -0
- package/dest/private/circuit_simulator.d.ts.map +1 -0
- package/dest/private/circuit_simulator.js +43 -0
- package/dest/private/factory.d.ts +12 -0
- package/dest/private/factory.d.ts.map +1 -0
- package/dest/private/{providers/factory.js → factory.js} +2 -2
- package/dest/public/avm/avm_context.d.ts +5 -5
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts +4 -2
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.js +11 -7
- package/dest/public/avm/avm_execution_environment.d.ts +3 -1
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.js +7 -2
- package/dest/public/avm/avm_gas.d.ts +4 -20
- package/dest/public/avm/avm_gas.d.ts.map +1 -1
- package/dest/public/avm/avm_gas.js +27 -35
- package/dest/public/avm/avm_machine_state.d.ts +2 -0
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.js +2 -0
- package/dest/public/avm/avm_memory_types.d.ts +98 -87
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.js +17 -6
- package/dest/public/avm/avm_simulator.d.ts +4 -5
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +23 -35
- package/dest/public/avm/avm_simulator_interface.d.ts +9 -0
- package/dest/public/avm/avm_simulator_interface.d.ts.map +1 -0
- package/dest/public/avm/avm_simulator_interface.js +3 -0
- package/dest/public/avm/errors.d.ts +6 -30
- package/dest/public/avm/errors.d.ts.map +1 -1
- package/dest/public/avm/errors.js +7 -57
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +5 -4
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +12 -14
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +6 -4
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +37 -14
- package/dest/public/avm/fixtures/initializers.d.ts +43 -0
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -0
- package/dest/public/avm/fixtures/initializers.js +42 -0
- package/dest/public/avm/fixtures/utils.d.ts +38 -0
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -0
- package/dest/public/avm/fixtures/utils.js +95 -0
- package/dest/public/avm/index.d.ts +0 -2
- package/dest/public/avm/index.d.ts.map +1 -1
- package/dest/public/avm/index.js +0 -2
- package/dest/public/avm/opcodes/accrued_substate.d.ts +2 -2
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +28 -25
- package/dest/public/avm/opcodes/addressing_mode.d.ts +11 -7
- package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/public/avm/opcodes/addressing_mode.js +46 -26
- package/dest/public/avm/opcodes/arithmetic.d.ts +11 -1
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.js +16 -2
- package/dest/public/avm/opcodes/bitwise.d.ts +5 -13
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/public/avm/opcodes/bitwise.js +19 -26
- package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/public/avm/opcodes/comparators.js +3 -3
- package/dest/public/avm/opcodes/contract.d.ts +1 -2
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/contract.js +9 -10
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/public/avm/opcodes/control_flow.js +10 -8
- package/dest/public/avm/opcodes/conversion.d.ts +1 -0
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.js +267 -3
- 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 +2 -2
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/environment_getters.js +17 -19
- package/dest/public/avm/opcodes/external_calls.d.ts +8 -7
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +39 -34
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/public/avm/opcodes/hashing.js +6 -6
- package/dest/public/avm/opcodes/instruction.d.ts +14 -10
- package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/public/avm/opcodes/instruction.js +23 -19
- package/dest/public/avm/opcodes/memory.d.ts +4 -4
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +37 -33
- package/dest/public/avm/opcodes/misc.d.ts +2 -1
- package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/public/avm/opcodes/misc.js +41 -16
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/public/avm/opcodes/storage.js +7 -5
- package/dest/public/avm/revert_reason.d.ts +18 -0
- package/dest/public/avm/revert_reason.d.ts.map +1 -0
- package/dest/public/avm/revert_reason.js +38 -0
- package/dest/public/avm/serialization/buffer_cursor.d.ts +0 -2
- package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.d.ts +2 -6
- package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.js +70 -69
- package/dest/public/avm/serialization/instruction_serialization.d.ts +13 -4
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +70 -35
- package/dest/public/avm/test_utils.d.ts +10 -13
- package/dest/public/avm/test_utils.d.ts.map +1 -1
- package/dest/public/avm/test_utils.js +16 -24
- package/dest/public/db_interfaces.d.ts +56 -0
- package/dest/public/db_interfaces.d.ts.map +1 -0
- package/dest/public/db_interfaces.js +3 -0
- package/dest/public/debug_fn_name.d.ts +5 -0
- package/dest/public/debug_fn_name.d.ts.map +1 -0
- package/dest/public/debug_fn_name.js +9 -0
- package/dest/public/executor_metrics.d.ts +10 -3
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +37 -6
- package/dest/public/executor_metrics_interface.d.ts +9 -0
- package/dest/public/executor_metrics_interface.d.ts.map +1 -0
- package/dest/public/executor_metrics_interface.js +1 -0
- package/dest/public/fixtures/amm_test.d.ts +10 -0
- package/dest/public/fixtures/amm_test.d.ts.map +1 -0
- package/dest/public/fixtures/amm_test.js +213 -0
- package/dest/public/fixtures/bulk_test.d.ts +6 -0
- package/dest/public/fixtures/bulk_test.d.ts.map +1 -0
- package/dest/public/fixtures/bulk_test.js +326 -0
- 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 +9 -0
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -0
- package/dest/public/fixtures/custom_bytecode_tests.js +109 -0
- package/dest/public/fixtures/index.d.ts +7 -0
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +7 -0
- package/dest/public/fixtures/minimal_public_tx.d.ts +10 -0
- package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -0
- package/dest/public/fixtures/minimal_public_tx.js +29 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +35 -13
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +96 -71
- package/dest/public/{avm/fixtures → fixtures}/simple_contract_data_source.d.ts +6 -6
- package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -0
- package/dest/public/{avm/fixtures → fixtures}/simple_contract_data_source.js +31 -10
- package/dest/public/fixtures/token_test.d.ts +8 -0
- package/dest/public/fixtures/token_test.d.ts.map +1 -0
- package/dest/public/fixtures/token_test.js +95 -0
- package/dest/public/fixtures/utils.d.ts +16 -3
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +100 -58
- package/dest/public/hinting_db_sources.d.ts +70 -0
- package/dest/public/hinting_db_sources.d.ts.map +1 -0
- package/dest/public/hinting_db_sources.js +297 -0
- package/dest/public/index.d.ts +4 -8
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +4 -7
- package/dest/public/public_db_sources.d.ts +30 -39
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +151 -67
- 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 +49 -0
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -0
- package/dest/public/public_processor/guarded_merkle_tree.js +108 -0
- package/dest/public/public_processor/public_processor.d.ts +25 -30
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +141 -96
- 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 +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +41 -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 +89 -0
- package/dest/public/public_tx_simulator/index.d.ts +4 -0
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/index.js +2 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +24 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +51 -0
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +19 -29
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +63 -91
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +45 -47
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +209 -184
- 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 +21 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +39 -0
- package/dest/public/side_effect_errors.d.ts +41 -1
- 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 +20 -65
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +71 -121
- package/dest/public/side_effect_trace_interface.d.ts +11 -22
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/state_manager/index.d.ts +2 -0
- package/dest/public/state_manager/index.d.ts.map +1 -0
- package/dest/public/state_manager/index.js +1 -0
- package/dest/public/{avm/journal → state_manager}/nullifiers.d.ts +2 -5
- package/dest/public/state_manager/nullifiers.d.ts.map +1 -0
- package/dest/public/{avm/journal → state_manager}/nullifiers.js +3 -8
- package/dest/public/{avm/journal → state_manager}/public_storage.d.ts +2 -2
- package/dest/public/state_manager/public_storage.d.ts.map +1 -0
- package/dest/public/{avm/journal/journal.d.ts → state_manager/state_manager.d.ts} +42 -85
- package/dest/public/state_manager/state_manager.d.ts.map +1 -0
- package/dest/public/state_manager/state_manager.js +391 -0
- package/dest/public/test_executor_metrics.d.ts +54 -0
- package/dest/public/test_executor_metrics.d.ts.map +1 -0
- package/dest/public/test_executor_metrics.js +306 -0
- package/dest/public/unique_class_ids.d.ts.map +1 -1
- package/dest/public/utils.d.ts +2 -4
- package/dest/public/utils.d.ts.map +1 -1
- package/dest/public/utils.js +4 -21
- package/dest/server.d.ts +6 -3
- package/dest/server.d.ts.map +1 -1
- package/dest/server.js +5 -2
- package/dest/testing.d.ts +2 -0
- package/dest/testing.d.ts.map +1 -0
- package/dest/testing.js +1 -0
- package/package.json +36 -31
- package/src/client.ts +5 -3
- package/src/common/errors.ts +79 -44
- package/src/common/index.ts +0 -1
- package/src/private/acvm/acvm.ts +17 -32
- package/src/private/acvm/acvm_types.ts +1 -1
- package/src/private/acvm/deserialize.ts +35 -29
- package/src/private/acvm/index.ts +0 -1
- package/src/private/acvm/serialize.ts +63 -0
- package/src/private/{providers/acvm_native.ts → acvm_native.ts} +47 -24
- package/src/private/acvm_wasm.ts +72 -0
- package/src/private/acvm_wasm_with_blobs.ts +54 -0
- package/src/private/circuit_recording/circuit_recorder.ts +260 -0
- package/src/private/circuit_recording/file_circuit_recorder.ts +158 -0
- package/src/private/circuit_recording/memory_circuit_recorder.ts +11 -0
- package/src/private/circuit_recording/simulator_recorder_wrapper.ts +91 -0
- package/src/private/circuit_simulator.ts +90 -0
- package/src/private/{providers/factory.ts → factory.ts} +6 -6
- package/src/public/avm/avm_context.ts +4 -4
- package/src/public/avm/avm_contract_call_result.ts +17 -5
- package/src/public/avm/avm_execution_environment.ts +10 -1
- package/src/public/avm/avm_gas.ts +23 -35
- package/src/public/avm/avm_machine_state.ts +5 -0
- package/src/public/avm/avm_memory_types.ts +19 -6
- package/src/public/avm/avm_simulator.ts +44 -54
- package/src/public/avm/avm_simulator_interface.ts +8 -0
- package/src/public/avm/errors.ts +8 -77
- package/src/public/avm/fixtures/avm_simulation_tester.ts +23 -20
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +45 -12
- package/src/public/avm/fixtures/initializers.ts +104 -0
- package/src/public/avm/fixtures/utils.ts +150 -0
- package/src/public/avm/index.ts +0 -2
- package/src/public/avm/opcodes/accrued_substate.ts +64 -29
- package/src/public/avm/opcodes/addressing_mode.ts +56 -32
- package/src/public/avm/opcodes/arithmetic.ts +24 -2
- package/src/public/avm/opcodes/bitwise.ts +33 -29
- package/src/public/avm/opcodes/comparators.ts +6 -3
- package/src/public/avm/opcodes/contract.ts +10 -7
- package/src/public/avm/opcodes/control_flow.ts +19 -10
- package/src/public/avm/opcodes/conversion.ts +27 -3
- package/src/public/avm/opcodes/ec_add.ts +9 -6
- package/src/public/avm/opcodes/environment_getters.ts +27 -22
- package/src/public/avm/opcodes/external_calls.ts +61 -29
- package/src/public/avm/opcodes/hashing.ts +28 -8
- package/src/public/avm/opcodes/instruction.ts +31 -21
- package/src/public/avm/opcodes/memory.ts +71 -32
- package/src/public/avm/opcodes/misc.ts +60 -18
- package/src/public/avm/opcodes/storage.ts +22 -6
- package/src/public/avm/revert_reason.ts +55 -0
- package/src/public/avm/serialization/buffer_cursor.ts +4 -1
- package/src/public/avm/serialization/bytecode_serialization.ts +72 -74
- package/src/public/avm/serialization/instruction_serialization.ts +75 -34
- package/src/public/avm/test_utils.ts +24 -41
- package/src/public/db_interfaces.ts +61 -0
- package/src/{common → public}/debug_fn_name.ts +7 -7
- package/src/public/executor_metrics.ts +55 -6
- package/src/public/executor_metrics_interface.ts +14 -0
- package/src/public/fixtures/amm_test.ts +331 -0
- package/src/public/fixtures/bulk_test.ts +169 -0
- package/src/public/fixtures/custom_bytecode_tester.ts +49 -0
- package/src/public/fixtures/custom_bytecode_tests.ts +135 -0
- package/src/public/fixtures/index.ts +7 -0
- package/src/public/fixtures/minimal_public_tx.ts +36 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +158 -113
- package/src/public/{avm/fixtures → fixtures}/simple_contract_data_source.ts +36 -18
- package/src/public/fixtures/token_test.ts +140 -0
- package/src/public/fixtures/utils.ts +141 -68
- package/src/public/hinting_db_sources.ts +505 -0
- package/src/public/index.ts +9 -8
- package/src/public/public_db_sources.ts +196 -97
- package/src/public/public_errors.ts +14 -0
- package/src/public/public_processor/guarded_merkle_tree.ts +153 -0
- package/src/public/public_processor/public_processor.ts +191 -153
- package/src/public/public_processor/public_processor_metrics.ts +2 -2
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +128 -0
- package/src/public/public_tx_simulator/index.ts +3 -0
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +109 -0
- package/src/public/public_tx_simulator/public_tx_context.ts +160 -193
- package/src/public/public_tx_simulator/public_tx_simulator.ts +294 -220
- package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +11 -0
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +63 -0
- package/src/public/side_effect_errors.ts +91 -1
- package/src/public/side_effect_trace.ts +94 -320
- package/src/public/side_effect_trace_interface.ts +10 -58
- package/src/public/state_manager/index.ts +1 -0
- package/src/public/{avm/journal → state_manager}/nullifiers.ts +5 -11
- package/src/public/{avm/journal → state_manager}/public_storage.ts +2 -2
- package/src/public/state_manager/state_manager.ts +560 -0
- package/src/public/test_executor_metrics.ts +395 -0
- package/src/public/utils.ts +5 -21
- package/src/server.ts +6 -3
- package/src/testing.ts +1 -0
- package/dest/common/db_interfaces.d.ts +0 -80
- package/dest/common/db_interfaces.d.ts.map +0 -1
- package/dest/common/db_interfaces.js +0 -1
- package/dest/common/debug_fn_name.d.ts +0 -5
- package/dest/common/debug_fn_name.d.ts.map +0 -1
- package/dest/common/debug_fn_name.js +0 -6
- package/dest/common/message_load_oracle_inputs.d.ts +0 -15
- package/dest/common/message_load_oracle_inputs.d.ts.map +0 -1
- package/dest/common/message_load_oracle_inputs.js +0 -15
- package/dest/private/acvm/oracle/index.d.ts +0 -14
- package/dest/private/acvm/oracle/index.d.ts.map +0 -1
- package/dest/private/acvm/oracle/index.js +0 -2
- package/dest/private/acvm/oracle/oracle.d.ts +0 -49
- package/dest/private/acvm/oracle/oracle.d.ts.map +0 -1
- package/dest/private/acvm/oracle/oracle.js +0 -263
- package/dest/private/acvm/oracle/typed_oracle.d.ts +0 -83
- package/dest/private/acvm/oracle/typed_oracle.d.ts.map +0 -1
- package/dest/private/acvm/oracle/typed_oracle.js +0 -132
- package/dest/private/execution_data_provider.d.ts +0 -261
- package/dest/private/execution_data_provider.d.ts.map +0 -1
- package/dest/private/execution_data_provider.js +0 -14
- package/dest/private/execution_note_cache.d.ts +0 -93
- package/dest/private/execution_note_cache.d.ts.map +0 -1
- package/dest/private/execution_note_cache.js +0 -180
- package/dest/private/hashed_values_cache.d.ts +0 -28
- package/dest/private/hashed_values_cache.d.ts.map +0 -1
- package/dest/private/hashed_values_cache.js +0 -46
- package/dest/private/index.d.ts +0 -13
- package/dest/private/index.d.ts.map +0 -1
- package/dest/private/index.js +0 -12
- package/dest/private/pick_notes.d.ts +0 -85
- package/dest/private/pick_notes.d.ts.map +0 -1
- package/dest/private/pick_notes.js +0 -51
- package/dest/private/private_execution.d.ts +0 -25
- package/dest/private/private_execution.d.ts.map +0 -1
- package/dest/private/private_execution.js +0 -92
- package/dest/private/private_execution_oracle.d.ts +0 -215
- package/dest/private/private_execution_oracle.d.ts.map +0 -1
- package/dest/private/private_execution_oracle.js +0 -382
- package/dest/private/providers/acvm_native.d.ts.map +0 -1
- package/dest/private/providers/acvm_wasm.d.ts +0 -15
- package/dest/private/providers/acvm_wasm.d.ts.map +0 -1
- package/dest/private/providers/acvm_wasm_with_blobs.d.ts +0 -19
- package/dest/private/providers/acvm_wasm_with_blobs.d.ts.map +0 -1
- package/dest/private/providers/acvm_wasm_with_blobs.js +0 -32
- package/dest/private/providers/factory.d.ts +0 -12
- package/dest/private/providers/factory.d.ts.map +0 -1
- package/dest/private/providers/simulation_provider.d.ts +0 -19
- package/dest/private/providers/simulation_provider.d.ts.map +0 -1
- package/dest/private/providers/simulation_provider.js +0 -24
- package/dest/private/simulator.d.ts +0 -34
- package/dest/private/simulator.d.ts.map +0 -1
- package/dest/private/simulator.js +0 -76
- package/dest/private/unconstrained_execution.d.ts +0 -10
- package/dest/private/unconstrained_execution.d.ts.map +0 -1
- package/dest/private/unconstrained_execution.js +0 -27
- package/dest/private/unconstrained_execution_oracle.d.ts +0 -161
- package/dest/private/unconstrained_execution_oracle.d.ts.map +0 -1
- package/dest/private/unconstrained_execution_oracle.js +0 -258
- package/dest/public/avm/bytecode_utils.d.ts +0 -5
- package/dest/public/avm/bytecode_utils.d.ts.map +0 -1
- package/dest/public/avm/bytecode_utils.js +0 -17
- package/dest/public/avm/fixtures/index.d.ts +0 -84
- package/dest/public/avm/fixtures/index.d.ts.map +0 -1
- package/dest/public/avm/fixtures/index.js +0 -175
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +0 -1
- package/dest/public/avm/journal/index.d.ts +0 -2
- package/dest/public/avm/journal/index.d.ts.map +0 -1
- package/dest/public/avm/journal/index.js +0 -1
- package/dest/public/avm/journal/journal.d.ts.map +0 -1
- package/dest/public/avm/journal/journal.js +0 -486
- package/dest/public/avm/journal/nullifiers.d.ts.map +0 -1
- package/dest/public/avm/journal/public_storage.d.ts.map +0 -1
- 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/execution.d.ts +0 -108
- package/dest/public/execution.d.ts.map +0 -1
- package/dest/public/execution.js +0 -9
- package/dest/test/utils.d.ts +0 -13
- package/dest/test/utils.d.ts.map +0 -1
- package/dest/test/utils.js +0 -22
- package/src/common/db_interfaces.ts +0 -94
- package/src/common/message_load_oracle_inputs.ts +0 -15
- package/src/private/acvm/oracle/index.ts +0 -16
- package/src/private/acvm/oracle/oracle.ts +0 -455
- package/src/private/acvm/oracle/typed_oracle.ts +0 -259
- package/src/private/execution_data_provider.ts +0 -323
- package/src/private/execution_note_cache.ts +0 -217
- package/src/private/hashed_values_cache.ts +0 -55
- package/src/private/index.ts +0 -16
- package/src/private/pick_notes.ts +0 -141
- package/src/private/private_execution.ts +0 -151
- package/src/private/private_execution_oracle.ts +0 -614
- package/src/private/providers/acvm_wasm.ts +0 -63
- package/src/private/providers/acvm_wasm_with_blobs.ts +0 -50
- package/src/private/providers/simulation_provider.ts +0 -45
- package/src/private/simulator.ts +0 -147
- package/src/private/unconstrained_execution.ts +0 -50
- package/src/private/unconstrained_execution_oracle.ts +0 -373
- package/src/public/avm/bytecode_utils.ts +0 -17
- package/src/public/avm/fixtures/index.ts +0 -296
- package/src/public/avm/journal/index.ts +0 -1
- package/src/public/avm/journal/journal.ts +0 -742
- package/src/public/avm/opcodes/.eslintrc.cjs +0 -8
- package/src/public/bytecode_errors.ts +0 -6
- package/src/public/execution.ts +0 -140
- package/src/test/utils.ts +0 -36
- /package/dest/public/{avm/journal → state_manager}/public_storage.js +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
2
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
3
|
+
import type { GlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
4
|
+
import type { ExecutorMetricsInterface } from '../executor_metrics_interface.js';
|
|
5
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
6
|
+
import { type PublicTxResult, PublicTxSimulator, type PublicTxSimulatorConfig } from './public_tx_simulator.js';
|
|
7
|
+
import type { MeasuredPublicTxSimulatorInterface, PublicTxSimulatorInterface } from './public_tx_simulator_interface.js';
|
|
8
|
+
/**
|
|
9
|
+
* C++ implementation of PublicTxSimulator using pre-collected hints.
|
|
10
|
+
* This implementation runs TS simulation first to collect all hints,
|
|
11
|
+
* then passes the complete AvmCircuitInputs (hints + public inputs)
|
|
12
|
+
* to C++ to run hinted simulation.
|
|
13
|
+
*/
|
|
14
|
+
export declare class CppPublicTxSimulatorHintedDbs extends PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
15
|
+
protected log: Logger;
|
|
16
|
+
constructor(merkleTree: MerkleTreeWriteOperations, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, config?: Partial<PublicTxSimulatorConfig>);
|
|
17
|
+
/**
|
|
18
|
+
* Simulate a transaction's public portion using the C++ vm2 simulator with hinted DBs.
|
|
19
|
+
*
|
|
20
|
+
* This implementation:
|
|
21
|
+
* 1. Runs the full TypeScript simulation to generate AvmCircuitInputs (hints + public inputs)
|
|
22
|
+
* 2. Passes the complete AvmCircuitInputs to C++ to run hinted simulation
|
|
23
|
+
*
|
|
24
|
+
* @param tx - The transaction to simulate.
|
|
25
|
+
* @returns The result of the transaction's public execution.
|
|
26
|
+
*/
|
|
27
|
+
simulate(tx: Tx): Promise<PublicTxResult>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Class to record metrics for simulation.
|
|
31
|
+
*
|
|
32
|
+
* Note(dbanks12): We might not be able to collect all the same metrics in C++ as we do in TS!
|
|
33
|
+
* Unless we move some of the metrics collection to C++, we don't have inner functions exposed
|
|
34
|
+
* to TS for tracking.
|
|
35
|
+
*/
|
|
36
|
+
export declare class MeasuredCppPublicTxSimulatorHintedDbs extends CppPublicTxSimulatorHintedDbs implements MeasuredPublicTxSimulatorInterface {
|
|
37
|
+
protected readonly metrics: ExecutorMetricsInterface;
|
|
38
|
+
constructor(merkleTree: MerkleTreeWriteOperations, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, metrics: ExecutorMetricsInterface, config?: Partial<PublicTxSimulatorConfig>);
|
|
39
|
+
simulate(tx: Tx, txLabel?: string): Promise<PublicTxResult>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=cpp_public_tx_simulator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cpp_public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/cpp_public_tx_simulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAIlE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AACjF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,KAAK,cAAc,EAAE,iBAAiB,EAAE,KAAK,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAChH,OAAO,KAAK,EACV,kCAAkC,EAClC,0BAA0B,EAC3B,MAAM,oCAAoC,CAAC;AAE5C;;;;;GAKG;AACH,qBAAa,6BAA8B,SAAQ,iBAAkB,YAAW,0BAA0B;IACxG,UAAmB,GAAG,EAAE,MAAM,CAAC;gBAG7B,UAAU,EAAE,yBAAyB,EACrC,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EAChC,MAAM,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC;IAM3C;;;;;;;;;OASG;IACmB,QAAQ,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;CAkDhE;AAED;;;;;;GAMG;AACH,qBAAa,qCACX,SAAQ,6BACR,YAAW,kCAAkC;IAM3C,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,wBAAwB;gBAHpD,UAAU,EAAE,yBAAyB,EACrC,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EACb,OAAO,EAAE,wBAAwB,EACpD,MAAM,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC;IAKrB,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,GAAE,MAAsB,GAAG,OAAO,CAAC,cAAc,CAAC;CAUjG"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { avmSimulateWithHintedDbs } from '@aztec/native';
|
|
3
|
+
import { deserializeFromMessagePack } from '@aztec/stdlib/avm';
|
|
4
|
+
import { SimulationError } from '@aztec/stdlib/errors';
|
|
5
|
+
import { PublicTxSimulator } from './public_tx_simulator.js';
|
|
6
|
+
/**
|
|
7
|
+
* C++ implementation of PublicTxSimulator using pre-collected hints.
|
|
8
|
+
* This implementation runs TS simulation first to collect all hints,
|
|
9
|
+
* then passes the complete AvmCircuitInputs (hints + public inputs)
|
|
10
|
+
* to C++ to run hinted simulation.
|
|
11
|
+
*/ export class CppPublicTxSimulatorHintedDbs extends PublicTxSimulator {
|
|
12
|
+
log;
|
|
13
|
+
constructor(merkleTree, contractsDB, globalVariables, config){
|
|
14
|
+
super(merkleTree, contractsDB, globalVariables, config);
|
|
15
|
+
this.log = createLogger(`simulator:cpp_public_tx_simulator_hinted_dbs`);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Simulate a transaction's public portion using the C++ vm2 simulator with hinted DBs.
|
|
19
|
+
*
|
|
20
|
+
* This implementation:
|
|
21
|
+
* 1. Runs the full TypeScript simulation to generate AvmCircuitInputs (hints + public inputs)
|
|
22
|
+
* 2. Passes the complete AvmCircuitInputs to C++ to run hinted simulation
|
|
23
|
+
*
|
|
24
|
+
* @param tx - The transaction to simulate.
|
|
25
|
+
* @returns The result of the transaction's public execution.
|
|
26
|
+
*/ async simulate(tx) {
|
|
27
|
+
const txHash = this.computeTxHash(tx);
|
|
28
|
+
this.log.debug(`C++ hinted DB simulation of ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, {
|
|
29
|
+
txHash
|
|
30
|
+
});
|
|
31
|
+
// First, run TS simulation to generate hints and public inputs
|
|
32
|
+
this.log.debug(`Running TS simulation for tx ${txHash}`);
|
|
33
|
+
let tsResult;
|
|
34
|
+
try {
|
|
35
|
+
// Run the full TypeScript simulation using the parent class
|
|
36
|
+
// This will modify the merkle tree with the transaction's state changes
|
|
37
|
+
tsResult = await super.simulate(tx);
|
|
38
|
+
this.log.debug(`TS simulation succeeded for tx ${txHash}`);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
// If TS simulation fails, clear any partial contract additions and re-throw the error
|
|
41
|
+
this.contractsDB.clearContractsForTx();
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
// Extract the full AvmCircuitInputs from the TS result
|
|
45
|
+
const avmCircuitInputs = tsResult.avmProvingRequest.inputs;
|
|
46
|
+
// Second, run C++ simulation with hinted DBs
|
|
47
|
+
this.log.debug(`Running C++ simulation with hinted DBs for tx ${txHash}`);
|
|
48
|
+
// Serialize to msgpack and call the C++ simulator
|
|
49
|
+
const inputBuffer = avmCircuitInputs.serializeWithMessagePack();
|
|
50
|
+
let resultBuffer;
|
|
51
|
+
try {
|
|
52
|
+
resultBuffer = await avmSimulateWithHintedDbs(inputBuffer);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
throw new SimulationError(`C++ hinted simulation failed: ${error.message}`, []);
|
|
55
|
+
}
|
|
56
|
+
// Deserialize the msgpack result
|
|
57
|
+
const _success = deserializeFromMessagePack(resultBuffer);
|
|
58
|
+
this.log.debug(`C++ hinted simulation completed for tx ${txHash}`, {
|
|
59
|
+
txHash,
|
|
60
|
+
reverted: !tsResult.revertCode.isOK(),
|
|
61
|
+
tsGasUsed: tsResult.gasUsed.totalGas.l2Gas,
|
|
62
|
+
cppGasUsed: tsResult.gasUsed.totalGas.l2Gas
|
|
63
|
+
});
|
|
64
|
+
// TODO(dbanks12): C++ should return PublicTxResult (or something similar)
|
|
65
|
+
return tsResult;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Class to record metrics for simulation.
|
|
70
|
+
*
|
|
71
|
+
* Note(dbanks12): We might not be able to collect all the same metrics in C++ as we do in TS!
|
|
72
|
+
* Unless we move some of the metrics collection to C++, we don't have inner functions exposed
|
|
73
|
+
* to TS for tracking.
|
|
74
|
+
*/ export class MeasuredCppPublicTxSimulatorHintedDbs extends CppPublicTxSimulatorHintedDbs {
|
|
75
|
+
metrics;
|
|
76
|
+
constructor(merkleTree, contractsDB, globalVariables, metrics, config){
|
|
77
|
+
super(merkleTree, contractsDB, globalVariables, config), this.metrics = metrics;
|
|
78
|
+
}
|
|
79
|
+
async simulate(tx, txLabel = 'unlabeledTx') {
|
|
80
|
+
this.metrics.startRecordingTxSimulation(txLabel);
|
|
81
|
+
let result;
|
|
82
|
+
try {
|
|
83
|
+
result = await super.simulate(tx);
|
|
84
|
+
} finally{
|
|
85
|
+
this.metrics.stopRecordingTxSimulation(txLabel, result?.revertCode);
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,YAAY,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AACrF,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import type { Gas } from '@aztec/stdlib/gas';
|
|
3
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
4
|
+
import { type GlobalVariables, PublicCallRequestWithCalldata, Tx, TxExecutionPhase } from '@aztec/stdlib/tx';
|
|
5
|
+
import type { AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
|
|
6
|
+
import type { ExecutorMetricsInterface } from '../executor_metrics_interface.js';
|
|
7
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
8
|
+
import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
|
|
9
|
+
import { PublicTxContext } from './public_tx_context.js';
|
|
10
|
+
import { type ProcessedPhase, type PublicTxResult, PublicTxSimulator, type PublicTxSimulatorConfig } from './public_tx_simulator.js';
|
|
11
|
+
import type { MeasuredPublicTxSimulatorInterface } from './public_tx_simulator_interface.js';
|
|
12
|
+
/**
|
|
13
|
+
* A public tx simulator that tracks miscellaneous simulation metrics without telemetry.
|
|
14
|
+
*/
|
|
15
|
+
export declare class MeasuredPublicTxSimulator extends PublicTxSimulator implements MeasuredPublicTxSimulatorInterface {
|
|
16
|
+
protected readonly metrics: ExecutorMetricsInterface;
|
|
17
|
+
constructor(merkleTree: MerkleTreeWriteOperations, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, metrics: ExecutorMetricsInterface, config?: Partial<PublicTxSimulatorConfig>);
|
|
18
|
+
simulate(tx: Tx, txLabel?: string): Promise<PublicTxResult>;
|
|
19
|
+
protected insertNonRevertiblesFromPrivate(context: PublicTxContext, tx: Tx): Promise<void>;
|
|
20
|
+
protected insertRevertiblesFromPrivate(context: PublicTxContext, tx: Tx): Promise<void>;
|
|
21
|
+
protected simulatePhase(phase: TxExecutionPhase, context: PublicTxContext): Promise<ProcessedPhase>;
|
|
22
|
+
protected simulateEnqueuedCallInternal(stateManager: PublicPersistableStateManager, callRequest: PublicCallRequestWithCalldata, allocatedGas: Gas, transactionFee: Fr, fnName: string): Promise<AvmFinalizedCallResult>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=measured_public_tx_simulator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measured_public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/measured_public_tx_simulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,KAAK,eAAe,EAAE,6BAA6B,EAAE,EAAE,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE7G,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AACjF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AACjF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,iBAAiB,EACjB,KAAK,uBAAuB,EAC7B,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,oCAAoC,CAAC;AAE7F;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,iBAAkB,YAAW,kCAAkC;IAK1G,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,wBAAwB;gBAHpD,UAAU,EAAE,yBAAyB,EACrC,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EACb,OAAO,EAAE,wBAAwB,EACpD,MAAM,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC;IAKrB,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,GAAE,MAAsB,GAAG,OAAO,CAAC,cAAc,CAAC;cAWvE,+BAA+B,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,EAAE;cAMhE,4BAA4B,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,EAAE;cAM7D,aAAa,CAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;cAOzF,4BAA4B,CACnD,YAAY,EAAE,6BAA6B,EAC3C,WAAW,EAAE,6BAA6B,EAC1C,YAAY,EAAE,GAAG,EACjB,cAAc,EAAE,EAAE,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,sBAAsB,CAAC;CAsCnC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
2
|
+
import { PublicTxSimulator } from './public_tx_simulator.js';
|
|
3
|
+
/**
|
|
4
|
+
* A public tx simulator that tracks miscellaneous simulation metrics without telemetry.
|
|
5
|
+
*/ export class MeasuredPublicTxSimulator extends PublicTxSimulator {
|
|
6
|
+
metrics;
|
|
7
|
+
constructor(merkleTree, contractsDB, globalVariables, metrics, config){
|
|
8
|
+
super(merkleTree, contractsDB, globalVariables, config), this.metrics = metrics;
|
|
9
|
+
}
|
|
10
|
+
async simulate(tx, txLabel = 'unlabeledTx') {
|
|
11
|
+
this.metrics.startRecordingTxSimulation(txLabel);
|
|
12
|
+
let avmResult;
|
|
13
|
+
try {
|
|
14
|
+
avmResult = await super.simulate(tx);
|
|
15
|
+
} finally{
|
|
16
|
+
this.metrics.stopRecordingTxSimulation(txLabel, avmResult?.revertCode);
|
|
17
|
+
}
|
|
18
|
+
return avmResult;
|
|
19
|
+
}
|
|
20
|
+
async insertNonRevertiblesFromPrivate(context, tx) {
|
|
21
|
+
const timer = new Timer();
|
|
22
|
+
await super.insertNonRevertiblesFromPrivate(context, tx);
|
|
23
|
+
this.metrics.recordPrivateEffectsInsertion(timer.us(), 'non-revertible');
|
|
24
|
+
}
|
|
25
|
+
async insertRevertiblesFromPrivate(context, tx) {
|
|
26
|
+
const timer = new Timer();
|
|
27
|
+
await super.insertRevertiblesFromPrivate(context, tx);
|
|
28
|
+
this.metrics.recordPrivateEffectsInsertion(timer.us(), 'revertible');
|
|
29
|
+
}
|
|
30
|
+
async simulatePhase(phase, context) {
|
|
31
|
+
const timer = new Timer();
|
|
32
|
+
const result = await super.simulatePhase(phase, context);
|
|
33
|
+
result.durationMs = timer.ms();
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
async simulateEnqueuedCallInternal(stateManager, callRequest, allocatedGas, transactionFee, fnName) {
|
|
37
|
+
const timer = new Timer();
|
|
38
|
+
const result = await super.simulateEnqueuedCallInternal(stateManager, callRequest, allocatedGas, transactionFee, fnName);
|
|
39
|
+
this.log.verbose(result.reverted ? `Simulation of enqueued public call ${fnName} reverted with reason ${result.revertReason?.message}.` : `Simulation of enqueued public call ${fnName} completed successfully.`, {
|
|
40
|
+
eventName: 'avm-simulation',
|
|
41
|
+
appCircuitName: fnName,
|
|
42
|
+
duration: timer.ms()
|
|
43
|
+
});
|
|
44
|
+
if (result.reverted) {
|
|
45
|
+
this.metrics.recordEnqueuedCallSimulationFailure(fnName, timer.ms(), allocatedGas.sub(result.gasLeft).l2Gas, result.totalInstructions);
|
|
46
|
+
} else {
|
|
47
|
+
this.metrics.recordEnqueuedCallSimulation(fnName, timer.ms(), allocatedGas.sub(result.gasLeft).l2Gas, result.totalInstructions);
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,50 +1,48 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import {
|
|
2
|
+
import { AvmCircuitPublicInputs, RevertCode } from '@aztec/stdlib/avm';
|
|
3
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import type { SimulationError } from '@aztec/stdlib/errors';
|
|
5
|
-
import { Gas
|
|
6
|
-
import
|
|
7
|
-
import { type
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import { SideEffectTrace } from '../side_effect_trace.js';
|
|
5
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
6
|
+
import { PrivateToPublicAccumulatedData } from '@aztec/stdlib/kernel';
|
|
7
|
+
import { type GlobalVariables, ProtocolContracts, PublicCallRequestWithCalldata, type Tx, TxExecutionPhase, type TxHash } from '@aztec/stdlib/tx';
|
|
8
|
+
import type { PublicContractsDBInterface } from '../db_interfaces.js';
|
|
9
|
+
import type { PublicTreesDB } from '../public_db_sources.js';
|
|
10
|
+
import { PublicPersistableStateManager } from '../state_manager/state_manager.js';
|
|
12
11
|
/**
|
|
13
12
|
* The transaction-level context for public execution.
|
|
14
13
|
*/
|
|
15
14
|
export declare class PublicTxContext {
|
|
16
15
|
readonly txHash: TxHash;
|
|
17
16
|
readonly state: PhaseStateManager;
|
|
17
|
+
private readonly startTreeSnapshots;
|
|
18
18
|
private readonly globalVariables;
|
|
19
|
-
private readonly
|
|
19
|
+
private readonly protocolContracts;
|
|
20
|
+
private readonly proverId;
|
|
20
21
|
private readonly gasSettings;
|
|
21
22
|
private readonly gasUsedByPrivate;
|
|
22
23
|
private readonly gasAllocatedToPublic;
|
|
24
|
+
private readonly gasAllocatedToPublicTeardown;
|
|
23
25
|
private readonly setupCallRequests;
|
|
24
26
|
private readonly appLogicCallRequests;
|
|
25
27
|
private readonly teardownCallRequests;
|
|
26
|
-
private readonly setupExecutionRequests;
|
|
27
|
-
private readonly appLogicExecutionRequests;
|
|
28
|
-
private readonly teardownExecutionRequests;
|
|
29
28
|
readonly nonRevertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData;
|
|
30
29
|
readonly revertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData;
|
|
31
30
|
readonly feePayer: AztecAddress;
|
|
32
|
-
trace
|
|
31
|
+
private readonly trace;
|
|
33
32
|
private log;
|
|
34
33
|
private gasUsedByPublic;
|
|
35
34
|
teardownGasUsed: Gas;
|
|
36
35
|
private halted;
|
|
37
36
|
private revertCode;
|
|
38
37
|
revertReason: SimulationError | undefined;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
static create(db: MerkleTreeReadOperations, worldStateDB: WorldStateDB, tx: Tx, globalVariables: GlobalVariables, doMerkleOperations: boolean): Promise<PublicTxContext>;
|
|
38
|
+
private constructor();
|
|
39
|
+
static create(treesDB: PublicTreesDB, contractsDB: PublicContractsDBInterface, tx: Tx, globalVariables: GlobalVariables, protocolContracts: ProtocolContracts, doMerkleOperations: boolean, proverId: Fr): Promise<PublicTxContext>;
|
|
42
40
|
/**
|
|
43
41
|
* Signal that the entire transaction execution is done.
|
|
44
42
|
* All phases have been processed.
|
|
45
43
|
* Actual transaction fee and actual total consumed gas can now be queried.
|
|
46
44
|
*/
|
|
47
|
-
halt():
|
|
45
|
+
halt(): void;
|
|
48
46
|
/**
|
|
49
47
|
* Revert execution a phase. Populate revertReason & revertCode.
|
|
50
48
|
* If in setup, throw an error (transaction will be thrown out).
|
|
@@ -63,11 +61,7 @@ export declare class PublicTxContext {
|
|
|
63
61
|
/**
|
|
64
62
|
* Get the call requests for the specified phase (including args hashes).
|
|
65
63
|
*/
|
|
66
|
-
getCallRequestsForPhase(phase: TxExecutionPhase):
|
|
67
|
-
/**
|
|
68
|
-
* Get the call requests for the specified phase (including actual args).
|
|
69
|
-
*/
|
|
70
|
-
getExecutionRequestsForPhase(phase: TxExecutionPhase): PublicExecutionRequest[];
|
|
64
|
+
getCallRequestsForPhase(phase: TxExecutionPhase): PublicCallRequestWithCalldata[];
|
|
71
65
|
/**
|
|
72
66
|
* How much gas is left as of the specified phase?
|
|
73
67
|
*/
|
|
@@ -106,11 +100,7 @@ export declare class PublicTxContext {
|
|
|
106
100
|
/**
|
|
107
101
|
* Generate the public inputs for the AVM circuit.
|
|
108
102
|
*/
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Generate the proving request for the AVM circuit.
|
|
112
|
-
*/
|
|
113
|
-
generateProvingRequest(endStateReference: StateReference): Promise<AvmProvingRequest>;
|
|
103
|
+
generateAvmCircuitPublicInputs(): Promise<AvmCircuitPublicInputs>;
|
|
114
104
|
}
|
|
115
105
|
/**
|
|
116
106
|
* Thin wrapper around the state manager to handle forking and merging for phases.
|
|
@@ -126,9 +116,9 @@ declare class PhaseStateManager {
|
|
|
126
116
|
private readonly txStateManager;
|
|
127
117
|
private log;
|
|
128
118
|
private currentlyActiveStateManager;
|
|
129
|
-
constructor(txStateManager:
|
|
119
|
+
constructor(txStateManager: PublicPersistableStateManager);
|
|
130
120
|
fork(): Promise<void>;
|
|
131
|
-
getActiveStateManager():
|
|
121
|
+
getActiveStateManager(): PublicPersistableStateManager;
|
|
132
122
|
isForked(): boolean;
|
|
133
123
|
mergeForkedState(): Promise<void>;
|
|
134
124
|
discardForkedState(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public_tx_context.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/public_tx_context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"public_tx_context.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/public_tx_context.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,EAGL,sBAAsB,EAEtB,UAAU,EACX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,GAAG,EAAe,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAGL,8BAA8B,EAI/B,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EACL,KAAK,eAAe,EACpB,iBAAiB,EACjB,6BAA6B,EAE7B,KAAK,EAAE,EACP,gBAAgB,EAChB,KAAK,MAAM,EACZ,MAAM,kBAAkB,CAAC;AAK1B,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AAGlF;;GAEG;AACH,qBAAa,eAAe;aAeR,MAAM,EAAE,MAAM;aACd,KAAK,EAAE,iBAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IACrC,OAAO,CAAC,QAAQ,CAAC,4BAA4B;IAC7C,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IACrC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;aACrB,uCAAuC,EAAE,8BAA8B;aACvE,oCAAoC,EAAE,8BAA8B;aACpE,QAAQ,EAAE,YAAY;IACtC,OAAO,CAAC,QAAQ,CAAC,KAAK;IA9BxB,OAAO,CAAC,GAAG,CAAS;IAGpB,OAAO,CAAC,eAAe,CAAoB;IAEpC,eAAe,EAAE,GAAG,CAAe;IAG1C,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO,CAAC,UAAU,CAA6B;IAExC,YAAY,EAAE,eAAe,GAAG,SAAS,CAAC;IACjD,OAAO;WAsBa,MAAM,CACxB,OAAO,EAAE,aAAa,EACtB,WAAW,EAAE,0BAA0B,EACvC,EAAE,EAAE,EAAE,EACN,eAAe,EAAE,eAAe,EAChC,iBAAiB,EAAE,iBAAiB,EACpC,kBAAkB,EAAE,OAAO,EAC3B,QAAQ,EAAE,EAAE;IA4Cd;;;;OAIG;IACH,IAAI;IAKJ;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,gBAAgB,EAAE,YAAY,GAAE,eAAe,GAAG,SAAqB,EAAE,OAAO,SAAK;IAqBnG;;;OAGG;IACH,kBAAkB,IAAI,UAAU;IAKhC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO;IAW1C;;OAEG;IACH,uBAAuB,CAAC,KAAK,EAAE,gBAAgB,GAAG,6BAA6B,EAAE;IAWjF;;OAEG;IACH,iBAAiB,CAAC,KAAK,EAAE,gBAAgB,GAAG,GAAG;IAU/C;;OAEG;IACH,UAAU,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG;IAQ5C;;;OAGG;IACH,eAAe,IAAI,GAAG;IAItB;;;;;OAKG;IACH,gBAAgB,IAAI,GAAG;IAOvB;;;OAGG;IACH,sBAAsB,IAAI,GAAG;IAK7B;;;OAGG;IACH,iBAAiB,CAAC,KAAK,EAAE,gBAAgB,GAAG,EAAE;IAQ9C;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAa/B;;OAEG;IACU,8BAA8B,IAAI,OAAO,CAAC,sBAAsB,CAAC;CAwH/E;AAED;;;;;;;;;GASG;AACH,cAAM,iBAAiB;IAKT,OAAO,CAAC,QAAQ,CAAC,cAAc;IAJ3C,OAAO,CAAC,GAAG,CAAS;IAEpB,OAAO,CAAC,2BAA2B,CAA4C;gBAElD,cAAc,EAAE,6BAA6B;IAIpE,IAAI;IAMV,qBAAqB;IAIrB,QAAQ;IAIF,gBAAgB;IAQhB,kBAAkB;CAOzB"}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MAX_ENQUEUED_CALLS_PER_TX, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX } from '@aztec/constants';
|
|
2
2
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
3
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { computeTransactionFee } from '@aztec/stdlib/fees';
|
|
5
|
+
import { AvmAccumulatedData, AvmAccumulatedDataArrayLengths, AvmCircuitPublicInputs, PublicDataWrite, RevertCode } from '@aztec/stdlib/avm';
|
|
6
|
+
import { computeEffectiveGasFees, computeTransactionFee } from '@aztec/stdlib/fees';
|
|
8
7
|
import { Gas } from '@aztec/stdlib/gas';
|
|
9
|
-
import { PrivateToAvmAccumulatedData, PrivateToAvmAccumulatedDataArrayLengths, PublicCallRequest,
|
|
10
|
-
import {
|
|
8
|
+
import { PrivateToAvmAccumulatedData, PrivateToAvmAccumulatedDataArrayLengths, PublicCallRequest, PublicCallRequestArrayLengths, countAccumulatedItems } from '@aztec/stdlib/kernel';
|
|
9
|
+
import { FlatPublicLogs } from '@aztec/stdlib/logs';
|
|
10
|
+
import { ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
|
|
11
11
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
12
|
-
import {
|
|
12
|
+
import { TxExecutionPhase } from '@aztec/stdlib/tx';
|
|
13
13
|
import { strict as assert } from 'assert';
|
|
14
14
|
import { inspect } from 'util';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
15
|
+
import { SideEffectTrace } from '../side_effect_trace.js';
|
|
16
|
+
import { PublicPersistableStateManager } from '../state_manager/state_manager.js';
|
|
17
|
+
import { getCallRequestsWithCalldataByPhase } from '../utils.js';
|
|
18
18
|
/**
|
|
19
19
|
* The transaction-level context for public execution.
|
|
20
20
|
*/ export class PublicTxContext {
|
|
21
21
|
txHash;
|
|
22
22
|
state;
|
|
23
|
+
startTreeSnapshots;
|
|
23
24
|
globalVariables;
|
|
24
|
-
|
|
25
|
+
protocolContracts;
|
|
26
|
+
proverId;
|
|
25
27
|
gasSettings;
|
|
26
28
|
gasUsedByPrivate;
|
|
27
29
|
gasAllocatedToPublic;
|
|
30
|
+
gasAllocatedToPublicTeardown;
|
|
28
31
|
setupCallRequests;
|
|
29
32
|
appLogicCallRequests;
|
|
30
33
|
teardownCallRequests;
|
|
31
|
-
setupExecutionRequests;
|
|
32
|
-
appLogicExecutionRequests;
|
|
33
|
-
teardownExecutionRequests;
|
|
34
34
|
nonRevertibleAccumulatedDataFromPrivate;
|
|
35
35
|
revertibleAccumulatedDataFromPrivate;
|
|
36
36
|
feePayer;
|
|
@@ -41,21 +41,20 @@ import { getCallRequestsByPhase, getExecutionRequestsByPhase } from '../utils.js
|
|
|
41
41
|
/* Entire transaction execution is done. */ halted;
|
|
42
42
|
/* Where did reverts happen (if at all)? */ revertCode;
|
|
43
43
|
/* What caused a revert (if one occurred)? */ revertReason;
|
|
44
|
-
|
|
45
|
-
constructor(txHash, state, globalVariables, startStateReference, gasSettings, gasUsedByPrivate, gasAllocatedToPublic, setupCallRequests, appLogicCallRequests, teardownCallRequests, setupExecutionRequests, appLogicExecutionRequests, teardownExecutionRequests, nonRevertibleAccumulatedDataFromPrivate, revertibleAccumulatedDataFromPrivate, feePayer, trace){
|
|
44
|
+
constructor(txHash, state, startTreeSnapshots, globalVariables, protocolContracts, proverId, gasSettings, gasUsedByPrivate, gasAllocatedToPublic, gasAllocatedToPublicTeardown, setupCallRequests, appLogicCallRequests, teardownCallRequests, nonRevertibleAccumulatedDataFromPrivate, revertibleAccumulatedDataFromPrivate, feePayer, trace){
|
|
46
45
|
this.txHash = txHash;
|
|
47
46
|
this.state = state;
|
|
47
|
+
this.startTreeSnapshots = startTreeSnapshots;
|
|
48
48
|
this.globalVariables = globalVariables;
|
|
49
|
-
this.
|
|
49
|
+
this.protocolContracts = protocolContracts;
|
|
50
|
+
this.proverId = proverId;
|
|
50
51
|
this.gasSettings = gasSettings;
|
|
51
52
|
this.gasUsedByPrivate = gasUsedByPrivate;
|
|
52
53
|
this.gasAllocatedToPublic = gasAllocatedToPublic;
|
|
54
|
+
this.gasAllocatedToPublicTeardown = gasAllocatedToPublicTeardown;
|
|
53
55
|
this.setupCallRequests = setupCallRequests;
|
|
54
56
|
this.appLogicCallRequests = appLogicCallRequests;
|
|
55
57
|
this.teardownCallRequests = teardownCallRequests;
|
|
56
|
-
this.setupExecutionRequests = setupExecutionRequests;
|
|
57
|
-
this.appLogicExecutionRequests = appLogicExecutionRequests;
|
|
58
|
-
this.teardownExecutionRequests = teardownExecutionRequests;
|
|
59
58
|
this.nonRevertibleAccumulatedDataFromPrivate = nonRevertibleAccumulatedDataFromPrivate;
|
|
60
59
|
this.revertibleAccumulatedDataFromPrivate = revertibleAccumulatedDataFromPrivate;
|
|
61
60
|
this.feePayer = feePayer;
|
|
@@ -66,27 +65,24 @@ import { getCallRequestsByPhase, getExecutionRequestsByPhase } from '../utils.js
|
|
|
66
65
|
this.revertCode = RevertCode.OK;
|
|
67
66
|
this.log = createLogger(`simulator:public_tx_context`);
|
|
68
67
|
}
|
|
69
|
-
static async create(
|
|
68
|
+
static async create(treesDB, contractsDB, tx, globalVariables, protocolContracts, doMerkleOperations, proverId) {
|
|
70
69
|
const nonRevertibleAccumulatedDataFromPrivate = tx.data.forPublic.nonRevertibleAccumulatedData;
|
|
71
|
-
const
|
|
72
|
-
const trace = new SideEffectTrace(/*startSideEffectCounter=*/ 0, previousAccumulatedDataArrayLengths);
|
|
70
|
+
const trace = new SideEffectTrace();
|
|
73
71
|
const firstNullifier = nonRevertibleAccumulatedDataFromPrivate.nullifiers[0];
|
|
74
72
|
// Transaction level state manager that will be forked for revertible phases.
|
|
75
|
-
const txStateManager =
|
|
73
|
+
const txStateManager = PublicPersistableStateManager.create(treesDB, contractsDB, trace, doMerkleOperations, firstNullifier, globalVariables.timestamp);
|
|
76
74
|
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
77
75
|
const gasUsedByPrivate = tx.data.gasUsed;
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
return new PublicTxContext(
|
|
76
|
+
const gasAllocatedToPublic = gasSettings.gasLimits.sub(gasUsedByPrivate);
|
|
77
|
+
const gasAllocatedToPublicTeardown = gasSettings.teardownGasLimits;
|
|
78
|
+
return new PublicTxContext(tx.getTxHash(), new PhaseStateManager(txStateManager), await txStateManager.getTreeSnapshots(), globalVariables, protocolContracts, proverId, gasSettings, gasUsedByPrivate, gasAllocatedToPublic, gasAllocatedToPublicTeardown, getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.SETUP), getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.APP_LOGIC), getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.TEARDOWN), tx.data.forPublic.nonRevertibleAccumulatedData, tx.data.forPublic.revertibleAccumulatedData, tx.data.feePayer, trace);
|
|
81
79
|
}
|
|
82
80
|
/**
|
|
83
81
|
* Signal that the entire transaction execution is done.
|
|
84
82
|
* All phases have been processed.
|
|
85
83
|
* Actual transaction fee and actual total consumed gas can now be queried.
|
|
86
|
-
*/
|
|
87
|
-
|
|
88
|
-
await this.state.mergeForkedState();
|
|
89
|
-
}
|
|
84
|
+
*/ halt() {
|
|
85
|
+
assert(!this.state.isForked(), 'Cannot halt when state is forked');
|
|
90
86
|
this.halted = true;
|
|
91
87
|
}
|
|
92
88
|
/**
|
|
@@ -94,7 +90,7 @@ import { getCallRequestsByPhase, getExecutionRequestsByPhase } from '../utils.js
|
|
|
94
90
|
* If in setup, throw an error (transaction will be thrown out).
|
|
95
91
|
* NOTE: this does not "halt" the entire transaction execution.
|
|
96
92
|
*/ revert(phase, revertReason = undefined, culprit = '') {
|
|
97
|
-
this.log.warn(`${TxExecutionPhase[phase]} phase reverted! ${culprit} failed with reason: ${revertReason}`);
|
|
93
|
+
this.log.warn(`${TxExecutionPhase[phase]} phase reverted! ${culprit} failed with reason: ${revertReason?.message}`);
|
|
98
94
|
if (revertReason && !this.revertReason) {
|
|
99
95
|
// don't override revertReason
|
|
100
96
|
// (if app logic and teardown both revert, we want app logic's reason)
|
|
@@ -102,11 +98,6 @@ import { getCallRequestsByPhase, getExecutionRequestsByPhase } from '../utils.js
|
|
|
102
98
|
}
|
|
103
99
|
if (phase === TxExecutionPhase.SETUP) {
|
|
104
100
|
this.log.warn(`Setup phase reverted! The transaction will be thrown out.`);
|
|
105
|
-
if (revertReason) {
|
|
106
|
-
throw revertReason;
|
|
107
|
-
} else {
|
|
108
|
-
throw new Error(`Setup phase reverted! The transaction will be thrown out. ${culprit} failed`);
|
|
109
|
-
}
|
|
110
101
|
} else if (phase === TxExecutionPhase.APP_LOGIC) {
|
|
111
102
|
this.revertCode = RevertCode.APP_LOGIC_REVERTED;
|
|
112
103
|
} else if (phase === TxExecutionPhase.TEARDOWN) {
|
|
@@ -149,22 +140,11 @@ import { getCallRequestsByPhase, getExecutionRequestsByPhase } from '../utils.js
|
|
|
149
140
|
}
|
|
150
141
|
}
|
|
151
142
|
/**
|
|
152
|
-
* Get the call requests for the specified phase (including actual args).
|
|
153
|
-
*/ getExecutionRequestsForPhase(phase) {
|
|
154
|
-
switch(phase){
|
|
155
|
-
case TxExecutionPhase.SETUP:
|
|
156
|
-
return this.setupExecutionRequests;
|
|
157
|
-
case TxExecutionPhase.APP_LOGIC:
|
|
158
|
-
return this.appLogicExecutionRequests;
|
|
159
|
-
case TxExecutionPhase.TEARDOWN:
|
|
160
|
-
return this.teardownExecutionRequests;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
143
|
* How much gas is left as of the specified phase?
|
|
165
144
|
*/ getGasLeftAtPhase(phase) {
|
|
166
145
|
if (phase === TxExecutionPhase.TEARDOWN) {
|
|
167
|
-
|
|
146
|
+
const gasLeftForPublicTeardown = this.gasAllocatedToPublicTeardown.sub(this.teardownGasUsed);
|
|
147
|
+
return gasLeftForPublicTeardown;
|
|
168
148
|
} else {
|
|
169
149
|
const gasLeftForPublic = this.gasAllocatedToPublic.sub(this.gasUsedByPublic);
|
|
170
150
|
return gasLeftForPublic;
|
|
@@ -228,46 +208,43 @@ import { getCallRequestsByPhase, getExecutionRequestsByPhase } from '../utils.js
|
|
|
228
208
|
}
|
|
229
209
|
/**
|
|
230
210
|
* Generate the public inputs for the AVM circuit.
|
|
231
|
-
*/ async generateAvmCircuitPublicInputs(
|
|
211
|
+
*/ async generateAvmCircuitPublicInputs() {
|
|
232
212
|
assert(this.halted, 'Can only get AvmCircuitPublicInputs after tx execution ends');
|
|
233
213
|
const stateManager = this.state.getActiveStateManager();
|
|
234
|
-
|
|
235
|
-
//
|
|
236
|
-
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
avmCircuitPublicInputs.previousRevertibleAccumulatedDataArrayLengths = getArrayLengths(this.revertibleAccumulatedDataFromPrivate);
|
|
243
|
-
avmCircuitPublicInputs.previousNonRevertibleAccumulatedData = convertAccumulatedData(this.nonRevertibleAccumulatedDataFromPrivate);
|
|
244
|
-
avmCircuitPublicInputs.previousRevertibleAccumulatedData = convertAccumulatedData(this.revertibleAccumulatedDataFromPrivate);
|
|
245
|
-
const msgsFromPrivate = this.revertCode.isOK() ? mergeAccumulatedData(avmCircuitPublicInputs.previousNonRevertibleAccumulatedData.l2ToL1Msgs, avmCircuitPublicInputs.previousRevertibleAccumulatedData.l2ToL1Msgs) : avmCircuitPublicInputs.previousNonRevertibleAccumulatedData.l2ToL1Msgs;
|
|
246
|
-
avmCircuitPublicInputs.accumulatedData.l2ToL1Msgs = assertLength(mergeAccumulatedData(msgsFromPrivate, avmCircuitPublicInputs.accumulatedData.l2ToL1Msgs), MAX_L2_TO_L1_MSGS_PER_TX);
|
|
214
|
+
// We get the side effects from the AVM.
|
|
215
|
+
// The AVM will already have handled the conditional insertion of most private side-effects.
|
|
216
|
+
// (depending on the revert code of each stage). Only l2ToL1Msgs and publicLogs still need to be "merged".
|
|
217
|
+
const { publicDataWrites: avmPublicDataWrites, noteHashes: avmNoteHashes, nullifiers: avmNullifiers, l2ToL1Msgs: avmL2ToL1Msgs, publicLogs: avmPublicLogs } = this.trace.getSideEffects();
|
|
218
|
+
// Private generates PrivateLogs, and public execution generates PublicLogs.
|
|
219
|
+
// Since these are two different categories, they should not be merged.
|
|
220
|
+
const finalPublicLogs = avmPublicLogs;
|
|
221
|
+
// We squash public data writes.
|
|
247
222
|
// Maps slot to value. Maps in TS are iterable in insertion order, which is exactly what we want for
|
|
248
223
|
// squashing "to the left", where the first occurrence of a slot uses the value of the last write to it,
|
|
249
|
-
// and the rest occurrences are omitted
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
squashedPublicDataWrites
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
224
|
+
// and the rest occurrences are omitted.
|
|
225
|
+
// Note: you can't write public state from private, so we only squash what we got from the AVM.
|
|
226
|
+
const finalPublicDataWrites = (()=>{
|
|
227
|
+
const squashedPublicDataWrites = new Map();
|
|
228
|
+
for (const publicDataWrite of avmPublicDataWrites){
|
|
229
|
+
squashedPublicDataWrites.set(publicDataWrite.leafSlot.toBigInt(), publicDataWrite.newValue);
|
|
230
|
+
}
|
|
231
|
+
return Array.from(squashedPublicDataWrites.entries()).map(([slot, value])=>new PublicDataWrite(new Fr(slot), value));
|
|
232
|
+
})();
|
|
233
|
+
// Count before padding.
|
|
234
|
+
const accumulatedDataArrayLengths = new AvmAccumulatedDataArrayLengths(avmNoteHashes.length, avmNullifiers.length, avmL2ToL1Msgs.length, finalPublicDataWrites.length);
|
|
235
|
+
const accumulatedData = new AvmAccumulatedData(/*noteHashes=*/ padArrayEnd(avmNoteHashes.map((n)=>n.value), Fr.zero(), MAX_NOTE_HASHES_PER_TX), /*nullifiers=*/ padArrayEnd(avmNullifiers.map((n)=>n.value), Fr.zero(), MAX_NULLIFIERS_PER_TX), /*l2ToL1Msgs=*/ padArrayEnd(avmL2ToL1Msgs, ScopedL2ToL1Message.empty(), MAX_L2_TO_L1_MSGS_PER_TX), /*publicLogs=*/ FlatPublicLogs.fromLogs(finalPublicLogs), /*publicDataWrites=*/ padArrayEnd(finalPublicDataWrites, PublicDataWrite.empty(), MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX));
|
|
236
|
+
// Now we finally have enough information to pad the trees.
|
|
237
|
+
// NOTE(fcarreiro): a bit weird that a method that generates the PIs does this,
|
|
238
|
+
// but we do need the end tree snapshots. We can consider moving things to the caller.
|
|
239
|
+
const numNoteHashesToPad = MAX_NOTE_HASHES_PER_TX - avmNoteHashes.length;
|
|
240
|
+
const numNullifiersToPad = MAX_NULLIFIERS_PER_TX - avmNullifiers.length;
|
|
241
|
+
await stateManager.padTree(MerkleTreeId.NOTE_HASH_TREE, numNoteHashesToPad);
|
|
242
|
+
await stateManager.padTree(MerkleTreeId.NULLIFIER_TREE, numNullifiersToPad);
|
|
243
|
+
const endTreeSnapshots = await stateManager.getTreeSnapshots();
|
|
244
|
+
// This converts the private accumulated data to the avm accumulated data format.
|
|
245
|
+
const convertAccumulatedData = (from)=>new PrivateToAvmAccumulatedData(from.noteHashes, from.nullifiers, from.l2ToL1Msgs);
|
|
246
|
+
const getPreviousAccumulatedDataArrayLengths = (from)=>new PrivateToAvmAccumulatedDataArrayLengths(countAccumulatedItems(from.noteHashes), countAccumulatedItems(from.nullifiers), countAccumulatedItems(from.l2ToL1Msgs));
|
|
247
|
+
return new AvmCircuitPublicInputs(this.globalVariables, this.protocolContracts, this.startTreeSnapshots, /*startGasUsed=*/ this.gasUsedByPrivate, this.gasSettings, computeEffectiveGasFees(this.globalVariables.gasFees, this.gasSettings), this.feePayer, this.proverId, /*publicCallRequestArrayLengths=*/ new PublicCallRequestArrayLengths(this.setupCallRequests.length, this.appLogicCallRequests.length, this.teardownCallRequests.length > 0), /*publicSetupCallRequests=*/ padArrayEnd(this.setupCallRequests.map((r)=>r.request), PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX), /*publicAppLogicCallRequests=*/ padArrayEnd(this.appLogicCallRequests.map((r)=>r.request), PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX), /*publicTeardownCallRequests=*/ this.teardownCallRequests.length > 0 ? this.teardownCallRequests[0].request : PublicCallRequest.empty(), getPreviousAccumulatedDataArrayLengths(this.nonRevertibleAccumulatedDataFromPrivate), getPreviousAccumulatedDataArrayLengths(this.revertibleAccumulatedDataFromPrivate), convertAccumulatedData(this.nonRevertibleAccumulatedDataFromPrivate), convertAccumulatedData(this.revertibleAccumulatedDataFromPrivate), endTreeSnapshots, this.getTotalGasUsed(), accumulatedDataArrayLengths, accumulatedData, /*transactionFee=*/ this.getTransactionFeeUnsafe(), /*isReverted=*/ !this.revertCode.isOK());
|
|
271
248
|
}
|
|
272
249
|
}
|
|
273
250
|
/**
|
|
@@ -313,8 +290,3 @@ import { getCallRequestsByPhase, getExecutionRequestsByPhase } from '../utils.js
|
|
|
313
290
|
this.currentlyActiveStateManager = undefined;
|
|
314
291
|
}
|
|
315
292
|
}
|
|
316
|
-
/**
|
|
317
|
-
* Apply L2 gas maximum.
|
|
318
|
-
*/ function applyMaxToAvailableGas(availableGas) {
|
|
319
|
-
return new Gas(/*daGas=*/ availableGas.daGas, /*l2Gas=*/ Math.min(availableGas.l2Gas, MAX_L2_GAS_PER_TX_PUBLIC_PORTION));
|
|
320
|
-
}
|