@aztec/simulator 0.0.1-commit.2f68f620 → 0.0.1-commit.3100065
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client.d.ts +1 -3
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +0 -2
- package/dest/private/circuit_recording/circuit_recorder.d.ts +36 -23
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.js +65 -69
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts +7 -19
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/file_circuit_recorder.js +38 -42
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
- package/dest/private/circuit_recording/simulator_recorder_wrapper.js +11 -14
- package/dest/public/avm/avm_context.d.ts +41 -0
- package/dest/public/avm/avm_context.d.ts.map +1 -0
- package/dest/public/avm/avm_context.js +44 -0
- package/dest/public/avm/avm_contract_call_result.d.ts +32 -0
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -0
- package/dest/public/avm/avm_contract_call_result.js +54 -0
- package/dest/public/avm/avm_execution_environment.d.ts +24 -0
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -0
- package/dest/public/avm/avm_execution_environment.js +33 -0
- package/dest/public/avm/avm_gas.d.ts +44 -0
- package/dest/public/avm/avm_gas.d.ts.map +1 -0
- package/dest/public/avm/avm_gas.js +195 -0
- package/dest/public/avm/avm_machine_state.d.ts +98 -0
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -0
- package/dest/public/avm/avm_machine_state.js +110 -0
- package/dest/public/avm/avm_memory_types.d.ts +275 -0
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -0
- package/dest/public/avm/avm_memory_types.js +354 -0
- package/dest/public/avm/avm_simulator.d.ts +41 -0
- package/dest/public/avm/avm_simulator.d.ts.map +1 -0
- package/dest/public/avm/avm_simulator.js +192 -0
- 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/calldata.d.ts +51 -0
- package/dest/public/avm/calldata.d.ts.map +1 -0
- package/dest/public/avm/calldata.js +64 -0
- package/dest/public/avm/errors.d.ts +104 -0
- package/dest/public/avm/errors.d.ts.map +1 -0
- package/dest/public/avm/errors.js +141 -0
- 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/avm_simulation_tester.d.ts +22 -0
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -0
- package/dest/public/avm/fixtures/avm_simulation_tester.js +84 -0
- package/dest/public/avm/{testing → fixtures}/base_avm_simulation_tester.d.ts +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -0
- package/dest/public/avm/{testing → fixtures}/base_avm_simulation_tester.js +1 -1
- package/dest/public/avm/fixtures/initializers.d.ts +42 -0
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -0
- package/dest/public/avm/fixtures/initializers.js +45 -0
- package/dest/public/avm/fixtures/utils.d.ts +39 -0
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -0
- package/dest/public/avm/{testing → fixtures}/utils.js +34 -1
- package/dest/public/avm/index.d.ts +2 -0
- package/dest/public/avm/index.d.ts.map +1 -0
- package/dest/public/avm/index.js +1 -0
- package/dest/public/avm/opcodes/accrued_substate.d.ts +74 -0
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -0
- package/dest/public/avm/opcodes/accrued_substate.js +254 -0
- package/dest/public/avm/opcodes/addressing_mode.d.ts +31 -0
- package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -0
- package/dest/public/avm/opcodes/addressing_mode.js +94 -0
- package/dest/public/avm/opcodes/arithmetic.d.ts +49 -0
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -0
- package/dest/public/avm/opcodes/arithmetic.js +97 -0
- package/dest/public/avm/opcodes/bitwise.d.ts +42 -0
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -0
- package/dest/public/avm/opcodes/bitwise.js +99 -0
- package/dest/public/avm/opcodes/comparators.d.ts +25 -0
- package/dest/public/avm/opcodes/comparators.d.ts.map +1 -0
- package/dest/public/avm/opcodes/comparators.js +43 -0
- package/dest/public/avm/opcodes/contract.d.ts +21 -0
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -0
- package/dest/public/avm/opcodes/contract.js +69 -0
- package/dest/public/avm/opcodes/control_flow.d.ts +41 -0
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -0
- package/dest/public/avm/opcodes/control_flow.js +107 -0
- package/dest/public/avm/opcodes/conversion.d.ts +18 -0
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -0
- package/dest/public/avm/opcodes/conversion.js +333 -0
- package/dest/public/avm/opcodes/ec_add.d.ts +17 -0
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -0
- package/dest/public/avm/opcodes/ec_add.js +79 -0
- package/dest/public/avm/opcodes/environment_getters.d.ts +28 -0
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -0
- package/dest/public/avm/opcodes/environment_getters.js +77 -0
- package/dest/public/avm/opcodes/external_calls.d.ts +59 -0
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -0
- package/dest/public/avm/opcodes/external_calls.js +210 -0
- package/dest/public/avm/opcodes/hashing.d.ts +36 -0
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -0
- package/dest/public/avm/opcodes/hashing.js +119 -0
- package/dest/public/avm/opcodes/index.d.ts +16 -0
- package/dest/public/avm/opcodes/index.d.ts.map +1 -0
- package/dest/public/avm/opcodes/index.js +15 -0
- package/dest/public/avm/opcodes/instruction.d.ts +74 -0
- package/dest/public/avm/opcodes/instruction.d.ts.map +1 -0
- package/dest/public/avm/opcodes/instruction.js +95 -0
- package/dest/public/avm/opcodes/instruction_impl.d.ts +19 -0
- package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -0
- package/dest/public/avm/opcodes/instruction_impl.js +30 -0
- package/dest/public/avm/opcodes/memory.d.ts +74 -0
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -0
- package/dest/public/avm/opcodes/memory.js +257 -0
- package/dest/public/avm/opcodes/misc.d.ts +18 -0
- package/dest/public/avm/opcodes/misc.d.ts.map +1 -0
- package/dest/public/avm/opcodes/misc.js +73 -0
- package/dest/public/avm/opcodes/storage.d.ts +25 -0
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -0
- package/dest/public/avm/opcodes/storage.js +78 -0
- 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 +39 -0
- package/dest/public/avm/serialization/buffer_cursor.d.ts +26 -0
- package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -0
- package/dest/public/avm/serialization/buffer_cursor.js +99 -0
- package/dest/public/avm/serialization/bytecode_serialization.d.ts +17 -0
- package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -0
- package/dest/public/avm/serialization/bytecode_serialization.js +336 -0
- package/dest/public/avm/serialization/instruction_serialization.d.ts +114 -0
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -0
- package/dest/public/avm/serialization/instruction_serialization.js +261 -0
- package/dest/public/avm/test_utils.d.ts +15 -0
- package/dest/public/avm/test_utils.d.ts.map +1 -0
- package/dest/public/avm/test_utils.js +44 -0
- package/dest/public/debug_fn_name.d.ts +18 -0
- package/dest/public/debug_fn_name.d.ts.map +1 -0
- package/dest/public/debug_fn_name.js +37 -0
- package/dest/public/fixtures/amm_test.js +2 -2
- package/dest/public/fixtures/bulk_test.js +2 -2
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +1 -1
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tester.js +2 -2
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +19 -0
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -0
- package/dest/public/fixtures/custom_bytecode_tests.js +263 -0
- package/dest/public/fixtures/index.d.ts +4 -1
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +3 -0
- package/dest/public/fixtures/minimal_public_tx.d.ts +4 -0
- package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -0
- package/dest/public/fixtures/minimal_public_tx.js +19 -0
- 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 +1645 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +3 -3
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +38 -8
- package/dest/public/fixtures/simple_contract_data_source.js +1 -1
- package/dest/public/fixtures/token_test.js +3 -3
- package/dest/public/fixtures/utils.d.ts +1 -1
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +5 -3
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +4 -6
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -1
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +7 -12
- package/dest/public/fuzzing/avm_simulator_bin.js +4 -4
- package/dest/public/hinting_db_sources.d.ts +80 -0
- package/dest/public/hinting_db_sources.d.ts.map +1 -0
- package/dest/public/hinting_db_sources.js +356 -0
- 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_processor/guarded_merkle_tree.d.ts +3 -4
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
- package/dest/public/public_processor/guarded_merkle_tree.js +0 -3
- package/dest/public/public_processor/public_processor.d.ts +1 -1
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +22 -3
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +2 -2
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +53 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +131 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +42 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +86 -0
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +30 -0
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +171 -0
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +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_public_tx_simulator.js → dumping_cpp_public_tx_simulator.js} +2 -2
- package/dest/public/public_tx_simulator/factories.d.ts +6 -6
- package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/factories.js +6 -6
- package/dest/public/public_tx_simulator/index.d.ts +5 -3
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/index.js +4 -2
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +31 -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 +135 -0
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/public_tx_context.js +298 -0
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +74 -41
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +324 -98
- 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 +415 -0
- package/dest/public/side_effect_trace.d.ts +87 -0
- package/dest/public/side_effect_trace.d.ts.map +1 -0
- package/dest/public/side_effect_trace.js +199 -0
- package/dest/public/side_effect_trace_interface.d.ts +22 -0
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -0
- package/dest/public/side_effect_trace_interface.js +1 -0
- 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/state_manager/nullifiers.d.ts +61 -0
- package/dest/public/state_manager/nullifiers.d.ts.map +1 -0
- package/dest/public/state_manager/nullifiers.js +92 -0
- package/dest/public/state_manager/public_storage.d.ts +66 -0
- package/dest/public/state_manager/public_storage.d.ts.map +1 -0
- package/dest/public/state_manager/public_storage.js +145 -0
- package/dest/public/state_manager/state_manager.d.ts +170 -0
- package/dest/public/state_manager/state_manager.d.ts.map +1 -0
- package/dest/public/state_manager/state_manager.js +402 -0
- package/dest/public/test_executor_metrics.d.ts +6 -1
- package/dest/public/test_executor_metrics.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.js +22 -0
- package/package.json +18 -17
- package/src/client.ts +0 -2
- package/src/private/circuit_recording/circuit_recorder.ts +84 -78
- package/src/private/circuit_recording/file_circuit_recorder.ts +38 -48
- package/src/private/circuit_recording/simulator_recorder_wrapper.ts +9 -15
- package/src/public/avm/avm_context.ts +61 -0
- package/src/public/avm/avm_contract_call_result.ts +69 -0
- package/src/public/avm/avm_execution_environment.ts +51 -0
- package/src/public/avm/avm_gas.ts +183 -0
- package/src/public/avm/avm_machine_state.ts +170 -0
- package/src/public/avm/avm_memory_types.ts +440 -0
- package/src/public/avm/avm_simulator.ts +279 -0
- package/src/public/avm/avm_simulator_interface.ts +8 -0
- package/src/public/avm/calldata.ts +101 -0
- package/src/public/avm/errors.ts +177 -0
- package/src/public/avm/fixtures/avm_simulation_tester.ts +122 -0
- package/src/public/avm/{testing → fixtures}/base_avm_simulation_tester.ts +1 -1
- package/src/public/avm/fixtures/initializers.ts +103 -0
- package/src/public/avm/{testing → fixtures}/utils.ts +40 -1
- package/src/public/avm/index.ts +1 -0
- package/src/public/avm/opcodes/accrued_substate.ts +285 -0
- package/src/public/avm/opcodes/addressing_mode.ts +111 -0
- package/src/public/avm/opcodes/arithmetic.ts +129 -0
- package/src/public/avm/opcodes/bitwise.ts +113 -0
- package/src/public/avm/opcodes/comparators.ts +55 -0
- package/src/public/avm/opcodes/contract.ts +76 -0
- package/src/public/avm/opcodes/control_flow.ts +123 -0
- package/src/public/avm/opcodes/conversion.ts +104 -0
- package/src/public/avm/opcodes/ec_add.ts +86 -0
- package/src/public/avm/opcodes/environment_getters.ts +87 -0
- package/src/public/avm/opcodes/external_calls.ts +262 -0
- package/src/public/avm/opcodes/hashing.ts +151 -0
- package/src/public/avm/opcodes/index.ts +15 -0
- package/src/public/avm/opcodes/instruction.ts +136 -0
- package/src/public/avm/opcodes/instruction_impl.ts +36 -0
- package/src/public/avm/opcodes/memory.ts +293 -0
- package/src/public/avm/opcodes/misc.ts +102 -0
- package/src/public/avm/opcodes/storage.ts +95 -0
- package/src/public/avm/revert_reason.ts +58 -0
- package/src/public/avm/serialization/buffer_cursor.ts +118 -0
- package/src/public/avm/serialization/bytecode_serialization.ts +215 -0
- package/src/public/avm/serialization/instruction_serialization.ts +249 -0
- package/src/public/avm/test_utils.ts +64 -0
- package/src/public/debug_fn_name.ts +52 -0
- package/src/public/fixtures/amm_test.ts +2 -2
- package/src/public/fixtures/bulk_test.ts +2 -2
- package/src/public/fixtures/custom_bytecode_tester.ts +2 -2
- package/src/public/fixtures/custom_bytecode_tests.ts +435 -0
- package/src/public/fixtures/index.ts +3 -0
- package/src/public/fixtures/minimal_public_tx.ts +26 -0
- package/src/public/fixtures/opcode_spammer.ts +1713 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +36 -11
- package/src/public/fixtures/simple_contract_data_source.ts +1 -1
- package/src/public/fixtures/token_test.ts +3 -3
- package/src/public/fixtures/utils.ts +6 -11
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +18 -15
- package/src/public/fuzzing/avm_simulator_bin.ts +5 -3
- package/src/public/hinting_db_sources.ts +610 -0
- package/src/public/index.ts +3 -3
- package/src/public/public_processor/guarded_merkle_tree.ts +2 -5
- package/src/public/public_processor/public_processor.ts +24 -3
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +2 -2
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +210 -0
- 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_public_tx_simulator.ts → dumping_cpp_public_tx_simulator.ts} +2 -2
- package/src/public/public_tx_simulator/factories.ts +6 -6
- package/src/public/public_tx_simulator/index.ts +4 -2
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +105 -0
- package/src/public/public_tx_simulator/public_tx_context.ts +482 -0
- package/src/public/public_tx_simulator/public_tx_simulator.ts +480 -150
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +63 -0
- package/src/public/side_effect_trace.ts +293 -0
- package/src/public/side_effect_trace_interface.ts +28 -0
- package/src/public/state_manager/index.ts +1 -0
- package/src/public/state_manager/nullifiers.ts +103 -0
- package/src/public/state_manager/public_storage.ts +174 -0
- package/src/public/state_manager/state_manager.ts +569 -0
- package/src/public/test_executor_metrics.ts +24 -0
- package/dest/public/avm/testing/account_proof_fetcher.d.ts +0 -2
- package/dest/public/avm/testing/account_proof_fetcher.d.ts.map +0 -1
- package/dest/public/avm/testing/base_avm_simulation_tester.d.ts.map +0 -1
- package/dest/public/avm/testing/utils.d.ts +0 -32
- package/dest/public/avm/testing/utils.d.ts.map +0 -1
- package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts +0 -23
- package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts.map +0 -1
- package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts +0 -22
- package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts.map +0 -1
- package/dest/public/public_tx_simulator/public_tx_simulator_base.js +0 -28
- package/src/public/public_tx_simulator/public_tx_simulator_base.ts +0 -35
- /package/dest/public/avm/{testing → fixtures}/account_proof_fetcher.js +0 -0
- /package/src/public/avm/{testing → fixtures}/account_proof.json +0 -0
- /package/src/public/avm/{testing → fixtures}/account_proof_fetcher.ts +0 -0
|
@@ -24,6 +24,7 @@ function createEmptyTxMetrics() {
|
|
|
24
24
|
totalDurationMs: 0,
|
|
25
25
|
manaUsed: 0,
|
|
26
26
|
totalInstructionsExecuted: 0,
|
|
27
|
+
bytecodeSizes: [],
|
|
27
28
|
nonRevertiblePrivateInsertionsUs: undefined,
|
|
28
29
|
revertiblePrivateInsertionsUs: undefined,
|
|
29
30
|
enqueuedCalls: [],
|
|
@@ -99,6 +100,14 @@ export class TestExecutorMetrics {
|
|
|
99
100
|
txMetrics.nonRevertiblePrivateInsertionsUs = durationUs;
|
|
100
101
|
}
|
|
101
102
|
}
|
|
103
|
+
recordBytecodeSize(txLabel, contractName, sizeBytes) {
|
|
104
|
+
const txMetrics = this.txMetrics.get(txLabel);
|
|
105
|
+
assert(txMetrics, `Cannot record bytecode size for unknown tx label: ${txLabel}`);
|
|
106
|
+
txMetrics.bytecodeSizes.push({
|
|
107
|
+
contractName,
|
|
108
|
+
sizeBytes
|
|
109
|
+
});
|
|
110
|
+
}
|
|
102
111
|
recordProverMetrics(txLabel, metrics) {
|
|
103
112
|
if (!this.txMetrics.has(txLabel)) {
|
|
104
113
|
this.txMetrics.set(txLabel, createEmptyTxMetrics());
|
|
@@ -132,6 +141,12 @@ export class TestExecutorMetrics {
|
|
|
132
141
|
if (filter === 3 || filter === 1 || filter === 0) {
|
|
133
142
|
pretty += `${INDENT0}Total instructions executed: ${fmtNum(txMetrics.totalInstructionsExecuted)}\n`;
|
|
134
143
|
}
|
|
144
|
+
if ((filter === 1 || filter === 0) && txMetrics.bytecodeSizes.length > 0) {
|
|
145
|
+
pretty += `${INDENT0}Bytecode sizes:\n`;
|
|
146
|
+
for (const { contractName, sizeBytes } of txMetrics.bytecodeSizes){
|
|
147
|
+
pretty += `${INDENT1}${contractName}: ${fmtNum(sizeBytes, 'bytes')}\n`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
135
150
|
if (filter === 2 || filter === 0) {
|
|
136
151
|
pretty += `${INDENT0}Private insertions:\n`;
|
|
137
152
|
pretty += `${INDENT1}Non-revertible: ${fmtNum(txMetrics.nonRevertiblePrivateInsertionsUs / 1_000, 'ms')}\n`;
|
|
@@ -298,6 +313,13 @@ export class TestExecutorMetrics {
|
|
|
298
313
|
});
|
|
299
314
|
}
|
|
300
315
|
}
|
|
316
|
+
for (const { contractName, sizeBytes } of txMetrics.bytecodeSizes){
|
|
317
|
+
data.push({
|
|
318
|
+
name: `${txLabel}/bytecodeSizeBytes/${contractName}`,
|
|
319
|
+
value: sizeBytes,
|
|
320
|
+
unit: 'bytes'
|
|
321
|
+
});
|
|
322
|
+
}
|
|
301
323
|
}
|
|
302
324
|
return JSON.stringify(data, null, indent);
|
|
303
325
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/simulator",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.3100065",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": "./dest/server.js",
|
|
7
7
|
"./client": "./dest/client.js",
|
|
8
8
|
"./testing": "./dest/testing.js",
|
|
9
|
-
"./public/fixtures": "./dest/public/fixtures/index.js"
|
|
9
|
+
"./public/fixtures": "./dest/public/fixtures/index.js",
|
|
10
|
+
"./public/avm/opcodes": "./dest/public/avm/opcodes/index.js"
|
|
10
11
|
},
|
|
11
12
|
"typedocOptions": {
|
|
12
13
|
"entryPoints": [
|
|
@@ -63,26 +64,26 @@
|
|
|
63
64
|
]
|
|
64
65
|
},
|
|
65
66
|
"dependencies": {
|
|
66
|
-
"@aztec/constants": "0.0.1-commit.
|
|
67
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
68
|
-
"@aztec/native": "0.0.1-commit.
|
|
69
|
-
"@aztec/noir-acvm_js": "0.0.1-commit.
|
|
70
|
-
"@aztec/noir-noirc_abi": "0.0.1-commit.
|
|
71
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
72
|
-
"@aztec/noir-types": "0.0.1-commit.
|
|
73
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
74
|
-
"@aztec/standard-contracts": "0.0.1-commit.
|
|
75
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
76
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
77
|
-
"@aztec/world-state": "0.0.1-commit.
|
|
67
|
+
"@aztec/constants": "0.0.1-commit.3100065",
|
|
68
|
+
"@aztec/foundation": "0.0.1-commit.3100065",
|
|
69
|
+
"@aztec/native": "0.0.1-commit.3100065",
|
|
70
|
+
"@aztec/noir-acvm_js": "0.0.1-commit.3100065",
|
|
71
|
+
"@aztec/noir-noirc_abi": "0.0.1-commit.3100065",
|
|
72
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.3100065",
|
|
73
|
+
"@aztec/noir-types": "0.0.1-commit.3100065",
|
|
74
|
+
"@aztec/protocol-contracts": "0.0.1-commit.3100065",
|
|
75
|
+
"@aztec/standard-contracts": "0.0.1-commit.3100065",
|
|
76
|
+
"@aztec/stdlib": "0.0.1-commit.3100065",
|
|
77
|
+
"@aztec/telemetry-client": "0.0.1-commit.3100065",
|
|
78
|
+
"@aztec/world-state": "0.0.1-commit.3100065",
|
|
78
79
|
"lodash.clonedeep": "^4.5.0",
|
|
79
80
|
"lodash.merge": "^4.6.2",
|
|
80
81
|
"tslib": "^2.4.0"
|
|
81
82
|
},
|
|
82
83
|
"devDependencies": {
|
|
83
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
84
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
85
|
-
"@aztec/noir-test-contracts.js": "0.0.1-commit.
|
|
84
|
+
"@aztec/kv-store": "0.0.1-commit.3100065",
|
|
85
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.3100065",
|
|
86
|
+
"@aztec/noir-test-contracts.js": "0.0.1-commit.3100065",
|
|
86
87
|
"@jest/globals": "^30.0.0",
|
|
87
88
|
"@types/jest": "^30.0.0",
|
|
88
89
|
"@types/lodash.clonedeep": "^4.5.7",
|
package/src/client.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export * from './private/acvm/index.js';
|
|
2
2
|
export { WASMSimulator } from './private/acvm_wasm.js';
|
|
3
|
-
export { SimulatorRecorderWrapper } from './private/circuit_recording/simulator_recorder_wrapper.js';
|
|
4
|
-
export { MemoryCircuitRecorder } from './private/circuit_recording/memory_circuit_recorder.js';
|
|
5
3
|
export { type CircuitSimulator, type DecodedError } from './private/circuit_simulator.js';
|
|
6
4
|
export * from './common/index.js';
|
|
@@ -3,6 +3,8 @@ import { type Logger, type LoggerBindings, resolveLogger } from '@aztec/foundati
|
|
|
3
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
4
4
|
import type { ForeignCallHandler, ForeignCallInput, ForeignCallOutput } from '@aztec/noir-acvm_js';
|
|
5
5
|
|
|
6
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
7
|
+
|
|
6
8
|
import type { ACIRCallback } from '../acvm/acvm.js';
|
|
7
9
|
import type { ACVMWitness } from '../acvm/acvm_types.js';
|
|
8
10
|
|
|
@@ -43,10 +45,23 @@ export class CircuitRecording {
|
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
|
|
48
|
+
/** Inputs needed to open a recording for a single circuit execution. */
|
|
49
|
+
export type RecordingMetadata = {
|
|
50
|
+
input: ACVMWitness;
|
|
51
|
+
bytecode: Buffer;
|
|
52
|
+
circuitName: string;
|
|
53
|
+
functionName: string;
|
|
54
|
+
};
|
|
55
|
+
|
|
46
56
|
/**
|
|
47
57
|
* Class responsible for recording circuit inputs necessary to replay the circuit. These inputs are the initial witness
|
|
48
58
|
* map and the oracle calls made during the circuit execution/witness generation.
|
|
49
59
|
*
|
|
60
|
+
* The active recording for an execution lives in `AsyncLocalStorage`, so each (possibly nested) circuit execution owns
|
|
61
|
+
* its own recording and concurrent or re-entrant executions cannot corrupt one another's state. Nested executions
|
|
62
|
+
* (`aztec_prv_callPrivateFunction`, utility calls) re-enter {@link record}, which links the child to the recording
|
|
63
|
+
* active in the enclosing async context and lets ALS restore the parent automatically when the child completes.
|
|
64
|
+
*
|
|
50
65
|
* Example recording object:
|
|
51
66
|
* ```json
|
|
52
67
|
* {
|
|
@@ -91,37 +106,44 @@ export class CircuitRecording {
|
|
|
91
106
|
export class CircuitRecorder {
|
|
92
107
|
protected readonly logger: Logger;
|
|
93
108
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
private stackDepth: number = 0;
|
|
97
|
-
private newCircuit: boolean = true;
|
|
109
|
+
readonly #recordings = new AsyncLocalStorage<CircuitRecording>();
|
|
98
110
|
|
|
99
111
|
protected constructor(loggerOrBindings?: Logger | LoggerBindings) {
|
|
100
112
|
this.logger = resolveLogger('simulator:acvm:recording', loggerOrBindings);
|
|
101
113
|
}
|
|
102
114
|
|
|
103
115
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
116
|
+
* Records a single circuit execution. Opens a recording for the circuit (linked as a child of the recording active
|
|
117
|
+
* in the current async context, if any), runs `fn` within that recording's context, and finalizes it. The recording
|
|
118
|
+
* is returned alongside the result so callers can derive per-circuit stats (e.g. oracle timings).
|
|
119
|
+
*
|
|
120
|
+
* Recorder bookkeeping never alters execution: if `fn` throws, the error is attached to the recording and re-thrown
|
|
121
|
+
* unchanged.
|
|
122
|
+
* @param metadata - Identifies the circuit and its initial witness.
|
|
123
|
+
* @param fn - Runs the circuit execution; its oracle calls are recorded into this recording.
|
|
111
124
|
*/
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
this.recording.setParent(parentRef);
|
|
122
|
-
}
|
|
125
|
+
record<T>(metadata: RecordingMetadata, fn: () => Promise<T>): Promise<{ result: T; recording: CircuitRecording }> {
|
|
126
|
+
const parent = this.#recordings.getStore();
|
|
127
|
+
const recording = new CircuitRecording(
|
|
128
|
+
metadata.circuitName,
|
|
129
|
+
metadata.functionName,
|
|
130
|
+
sha512(metadata.bytecode).toString('hex'),
|
|
131
|
+
Object.fromEntries(metadata.input),
|
|
132
|
+
);
|
|
133
|
+
recording.setParent(parent);
|
|
123
134
|
|
|
124
|
-
return
|
|
135
|
+
return this.#recordings.run(recording, async () => {
|
|
136
|
+
await this.onStart(recording);
|
|
137
|
+
try {
|
|
138
|
+
const result = await fn();
|
|
139
|
+
await this.onFinish(recording);
|
|
140
|
+
return { result, recording };
|
|
141
|
+
} catch (error) {
|
|
142
|
+
recording.error = JSON.stringify(error);
|
|
143
|
+
await this.onError(recording, error);
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
125
147
|
}
|
|
126
148
|
|
|
127
149
|
/**
|
|
@@ -147,7 +169,9 @@ export class CircuitRecorder {
|
|
|
147
169
|
}
|
|
148
170
|
|
|
149
171
|
/**
|
|
150
|
-
* Wraps a user circuit callback to record all oracle calls.
|
|
172
|
+
* Wraps a user circuit callback to record all oracle calls. A nested circuit entered via an oracle (e.g.
|
|
173
|
+
* `aztec_prv_callPrivateFunction`) re-enters {@link record}, so its own oracle calls land on the child recording and
|
|
174
|
+
* this circuit's calls (including the entering oracle call itself) land on this recording once the child completes.
|
|
151
175
|
* @param callback - The original circuit callback.
|
|
152
176
|
* @returns A wrapped callback that records all oracle interactions which is to be provided to the ACVM.
|
|
153
177
|
*/
|
|
@@ -161,38 +185,16 @@ export class CircuitRecorder {
|
|
|
161
185
|
throw new Error(`Oracle method ${name} not found when setting up recording callback`);
|
|
162
186
|
}
|
|
163
187
|
|
|
164
|
-
const isExternalCall = (name as keyof ACIRCallback) === 'aztec_prv_callPrivateFunction';
|
|
165
|
-
|
|
166
188
|
recordingCallback[name as keyof ACIRCallback] = (...args: ForeignCallInput[]): ReturnType<typeof fn> => {
|
|
167
189
|
const timer = new Timer();
|
|
168
|
-
// If we're entering another circuit via `aztec_prv_callPrivateFunction`, we increase the stack depth and set the
|
|
169
|
-
// newCircuit variable to ensure we are creating a new recording object.
|
|
170
|
-
if (isExternalCall) {
|
|
171
|
-
this.stackDepth++;
|
|
172
|
-
this.newCircuit = true;
|
|
173
|
-
}
|
|
174
190
|
const result = fn.call(callback, ...args);
|
|
175
191
|
if (result instanceof Promise) {
|
|
176
192
|
return result.then(async r => {
|
|
177
|
-
|
|
178
|
-
// so that the parent circuit continues with its existing recording
|
|
179
|
-
// Note: recording restoration is handled by finish()
|
|
180
|
-
if (isExternalCall) {
|
|
181
|
-
this.stackDepth--;
|
|
182
|
-
this.newCircuit = false;
|
|
183
|
-
}
|
|
184
|
-
await this.recordCall(name, args, r, timer.ms(), this.stackDepth);
|
|
193
|
+
await this.recordCall(name, args, r, timer.ms());
|
|
185
194
|
return r;
|
|
186
195
|
}) as ReturnType<typeof fn>;
|
|
187
196
|
}
|
|
188
|
-
|
|
189
|
-
// so that the parent circuit continues with its existing recording
|
|
190
|
-
// Note: recording restoration is handled by finish()
|
|
191
|
-
if (isExternalCall) {
|
|
192
|
-
this.stackDepth--;
|
|
193
|
-
this.newCircuit = false;
|
|
194
|
-
}
|
|
195
|
-
void this.recordCall(name, args, result, timer.ms(), this.stackDepth);
|
|
197
|
+
void this.recordCall(name, args, result, timer.ms());
|
|
196
198
|
return result;
|
|
197
199
|
};
|
|
198
200
|
}
|
|
@@ -209,55 +211,59 @@ export class CircuitRecorder {
|
|
|
209
211
|
return async (name: string, inputs: ForeignCallInput[]): Promise<ForeignCallOutput[]> => {
|
|
210
212
|
const timer = new Timer();
|
|
211
213
|
const result = await callback(name, inputs);
|
|
212
|
-
await this.recordCall(name, inputs, result, timer.ms()
|
|
214
|
+
await this.recordCall(name, inputs, result, timer.ms());
|
|
213
215
|
return result;
|
|
214
216
|
};
|
|
215
217
|
}
|
|
216
218
|
|
|
217
219
|
/**
|
|
218
|
-
* Records a single oracle/foreign call with its inputs and outputs
|
|
220
|
+
* Records a single oracle/foreign call with its inputs and outputs against the recording active in the current
|
|
221
|
+
* async context.
|
|
219
222
|
* @param name - Name of the call
|
|
220
223
|
* @param inputs - Input arguments
|
|
221
224
|
* @param outputs - Output results
|
|
222
225
|
*/
|
|
223
|
-
recordCall(name: string, inputs: unknown[], outputs: unknown, time: number
|
|
226
|
+
recordCall(name: string, inputs: unknown[], outputs: unknown, time: number): Promise<OracleCall> {
|
|
227
|
+
const recording = this.#recordings.getStore();
|
|
224
228
|
const entry = {
|
|
225
229
|
name,
|
|
226
230
|
inputs,
|
|
227
231
|
outputs,
|
|
228
232
|
time,
|
|
229
|
-
stackDepth,
|
|
233
|
+
stackDepth: depthOf(recording),
|
|
230
234
|
};
|
|
231
|
-
|
|
235
|
+
// Outside any active recording context (e.g. a stray call after the scope closed, or a direct unit-test call)
|
|
236
|
+
// there is nowhere to record; return the entry without throwing into the execution path.
|
|
237
|
+
recording?.oracleCalls.push(entry);
|
|
232
238
|
return Promise.resolve(entry);
|
|
233
239
|
}
|
|
234
240
|
|
|
235
|
-
/**
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
finish(): Promise<CircuitRecording> {
|
|
239
|
-
const result = this.recording;
|
|
240
|
-
// If this is the top-level circuit recording, we reset the state for the next simulator call
|
|
241
|
-
if (!result!.parent) {
|
|
242
|
-
this.newCircuit = true;
|
|
243
|
-
this.recording = undefined;
|
|
244
|
-
} else {
|
|
245
|
-
// For nested circuits (utility calls, nested contract calls), restore to parent recording
|
|
246
|
-
// Note: we don't set newCircuit=false here because:
|
|
247
|
-
// - For privateCallPrivateFunction, the callback wrapper will set it to false
|
|
248
|
-
// - For utility calls, we want newCircuit to remain true so the next circuit creates its own recording
|
|
249
|
-
this.recording = result!.parent;
|
|
250
|
-
}
|
|
251
|
-
return Promise.resolve(result!);
|
|
241
|
+
/** The recording active in the current async context, if any. */
|
|
242
|
+
protected currentRecording(): CircuitRecording | undefined {
|
|
243
|
+
return this.#recordings.getStore();
|
|
252
244
|
}
|
|
253
245
|
|
|
254
|
-
/**
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return
|
|
246
|
+
/** Hook invoked when a recording opens, within the recording's context. Overridden to persist recordings. */
|
|
247
|
+
protected onStart(_recording: CircuitRecording): Promise<void> {
|
|
248
|
+
return Promise.resolve();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Hook invoked when a recording completes successfully, within the recording's context. */
|
|
252
|
+
protected onFinish(_recording: CircuitRecording): Promise<void> {
|
|
253
|
+
return Promise.resolve();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Hook invoked when a recording's execution throws, within the recording's context. */
|
|
257
|
+
protected onError(_recording: CircuitRecording, _error: unknown): Promise<void> {
|
|
258
|
+
return Promise.resolve();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Depth of a recording in the call tree: 0 for a top-level circuit, incremented per nested circuit. */
|
|
263
|
+
function depthOf(recording: CircuitRecording | undefined): number {
|
|
264
|
+
let depth = 0;
|
|
265
|
+
for (let ancestor = recording?.parent; ancestor; ancestor = ancestor.parent) {
|
|
266
|
+
depth++;
|
|
262
267
|
}
|
|
268
|
+
return depth;
|
|
263
269
|
}
|
|
@@ -3,11 +3,13 @@ import type { Logger } from '@aztec/foundation/log';
|
|
|
3
3
|
import fs from 'fs/promises';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
|
|
6
|
-
import type { ACVMWitness } from '../acvm/acvm_types.js';
|
|
7
6
|
import { CircuitRecorder, type CircuitRecording } from './circuit_recorder.js';
|
|
8
7
|
|
|
8
|
+
/** Per-recording file state, keyed by recording so concurrent/nested executions don't share it. */
|
|
9
|
+
type RecordingFileState = { filePath: string; isFirstCall: boolean };
|
|
10
|
+
|
|
9
11
|
export class FileCircuitRecorder extends CircuitRecorder {
|
|
10
|
-
|
|
12
|
+
readonly #fileState = new WeakMap<CircuitRecording, RecordingFileState>();
|
|
11
13
|
|
|
12
14
|
constructor(
|
|
13
15
|
private readonly recordDir: string,
|
|
@@ -16,16 +18,9 @@ export class FileCircuitRecorder extends CircuitRecorder {
|
|
|
16
18
|
super(logger);
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
override async
|
|
20
|
-
input: ACVMWitness,
|
|
21
|
-
circuitBytecode: Buffer,
|
|
22
|
-
circuitName: string,
|
|
23
|
-
functionName: string = 'main',
|
|
24
|
-
) {
|
|
25
|
-
await super.start(input, circuitBytecode, circuitName, functionName);
|
|
26
|
-
|
|
21
|
+
protected override async onStart(recording: CircuitRecording): Promise<void> {
|
|
27
22
|
const recordingStringWithoutClosingBracket = JSON.stringify(
|
|
28
|
-
{ ...
|
|
23
|
+
{ ...recording, parent: undefined, oracleCalls: undefined },
|
|
29
24
|
null,
|
|
30
25
|
2,
|
|
31
26
|
).slice(0, -2);
|
|
@@ -45,13 +40,13 @@ export class FileCircuitRecorder extends CircuitRecorder {
|
|
|
45
40
|
}
|
|
46
41
|
}
|
|
47
42
|
|
|
48
|
-
|
|
49
|
-
this.recording!.filePath = await FileCircuitRecorder.#computeFilePathAndStoreInitialRecording(
|
|
43
|
+
const filePath = await FileCircuitRecorder.#computeFilePathAndStoreInitialRecording(
|
|
50
44
|
this.recordDir,
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
recording.circuitName,
|
|
46
|
+
recording.functionName,
|
|
53
47
|
recordingStringWithoutClosingBracket,
|
|
54
48
|
);
|
|
49
|
+
this.#fileState.set(recording, { filePath, isFirstCall: true });
|
|
55
50
|
}
|
|
56
51
|
|
|
57
52
|
/**
|
|
@@ -95,53 +90,48 @@ export class FileCircuitRecorder extends CircuitRecorder {
|
|
|
95
90
|
* @param inputs - Input arguments
|
|
96
91
|
* @param outputs - Output results
|
|
97
92
|
*/
|
|
98
|
-
override async recordCall(name: string, inputs: unknown[], outputs: unknown, time: number
|
|
99
|
-
const entry = await super.recordCall(name, inputs, outputs, time
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
93
|
+
override async recordCall(name: string, inputs: unknown[], outputs: unknown, time: number) {
|
|
94
|
+
const entry = await super.recordCall(name, inputs, outputs, time);
|
|
95
|
+
const recording = this.currentRecording();
|
|
96
|
+
const state = recording && this.#fileState.get(recording);
|
|
97
|
+
if (state) {
|
|
98
|
+
try {
|
|
99
|
+
const prefix = state.isFirstCall ? ' ' : ' ,';
|
|
100
|
+
state.isFirstCall = false;
|
|
101
|
+
await fs.appendFile(state.filePath, prefix + JSON.stringify(entry) + '\n');
|
|
102
|
+
} catch (err) {
|
|
103
|
+
this.logger.error('Failed to log circuit call', { error: err });
|
|
104
|
+
}
|
|
106
105
|
}
|
|
107
106
|
return entry;
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
/**
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
// so we save the current file path before that
|
|
117
|
-
const filePath = this.recording!.filePath;
|
|
118
|
-
const result = await super.finish();
|
|
109
|
+
/** Closes the recording file with the trailing brackets so the JSON parses. */
|
|
110
|
+
protected override async onFinish(recording: CircuitRecording): Promise<void> {
|
|
111
|
+
const state = this.#fileState.get(recording);
|
|
112
|
+
if (!state) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
119
115
|
try {
|
|
120
|
-
await fs.appendFile(filePath, ' ]\n}\n');
|
|
116
|
+
await fs.appendFile(state.filePath, ' ]\n}\n');
|
|
121
117
|
} catch (err) {
|
|
122
118
|
this.logger.error('Failed to finalize recording file', { error: err });
|
|
123
119
|
}
|
|
124
|
-
return result!;
|
|
125
120
|
}
|
|
126
121
|
|
|
127
|
-
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
// Finish sets the recording to undefined if we are at the topmost circuit,
|
|
134
|
-
// so we save the current file path before that
|
|
135
|
-
const filePath = this.recording!.filePath;
|
|
136
|
-
const result = await super.finishWithError(error);
|
|
122
|
+
/** Closes the recording file with the execution error and trailing brackets so the JSON parses. */
|
|
123
|
+
protected override async onError(recording: CircuitRecording, error: unknown): Promise<void> {
|
|
124
|
+
const state = this.#fileState.get(recording);
|
|
125
|
+
if (!state) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
137
128
|
try {
|
|
138
|
-
await fs.appendFile(filePath, ' ],\n');
|
|
139
|
-
await fs.appendFile(filePath, ` "error": ${JSON.stringify(error)}\n`);
|
|
140
|
-
await fs.appendFile(filePath, '}\n');
|
|
129
|
+
await fs.appendFile(state.filePath, ' ],\n');
|
|
130
|
+
await fs.appendFile(state.filePath, ` "error": ${JSON.stringify(error)}\n`);
|
|
131
|
+
await fs.appendFile(state.filePath, '}\n');
|
|
141
132
|
} catch (err) {
|
|
142
133
|
this.logger.error('Failed to finalize recording file with error', { error: err });
|
|
143
134
|
}
|
|
144
|
-
return result!;
|
|
145
135
|
}
|
|
146
136
|
}
|
|
147
137
|
|
|
@@ -58,24 +58,18 @@ export class SimulatorRecorderWrapper implements CircuitSimulator {
|
|
|
58
58
|
functionName: string,
|
|
59
59
|
callback: C,
|
|
60
60
|
): Promise<T> {
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// If callback was provided, we wrap it in a circuit recorder callback wrapper
|
|
61
|
+
// If a callback was provided, we wrap it so that its oracle calls are recorded. The wrapped callback reads the
|
|
62
|
+
// active recording lazily, so it picks up the recording opened by record() below.
|
|
65
63
|
const wrappedCallback = this.recorder.wrapCallback(callback);
|
|
66
|
-
let result: T;
|
|
67
|
-
try {
|
|
68
|
-
result = await simulateFn(wrappedCallback as C);
|
|
69
|
-
} catch (error) {
|
|
70
|
-
// If an error occurs, we finalize the recording file with the error
|
|
71
|
-
await this.recorder.finishWithError(error);
|
|
72
|
-
throw error;
|
|
73
|
-
}
|
|
74
64
|
|
|
75
|
-
//
|
|
76
|
-
|
|
65
|
+
// record() opens a recording for this circuit, runs the simulation within it, and finalizes it. A simulation
|
|
66
|
+
// failure is re-thrown unchanged, so recorder bookkeeping never masks the underlying error.
|
|
67
|
+
const { result, recording } = await this.recorder.record(
|
|
68
|
+
{ input, bytecode, circuitName: contractName, functionName },
|
|
69
|
+
() => simulateFn(wrappedCallback as C),
|
|
70
|
+
);
|
|
77
71
|
|
|
78
|
-
(result as ACIRExecutionResult).oracles = recording.oracleCalls
|
|
72
|
+
(result as ACIRExecutionResult).oracles = recording.oracleCalls.reduce(
|
|
79
73
|
(acc, { time, name }) => {
|
|
80
74
|
if (!acc[name]) {
|
|
81
75
|
acc[name] = { times: [] };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
|
+
|
|
3
|
+
import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
|
|
4
|
+
import type { AvmExecutionEnvironment } from './avm_execution_environment.js';
|
|
5
|
+
import { type Gas, gasToGasLeft } from './avm_gas.js';
|
|
6
|
+
import { AvmMachineState } from './avm_machine_state.js';
|
|
7
|
+
import type { AvmSimulatorInterface } from './avm_simulator_interface.js';
|
|
8
|
+
import type { CallData } from './calldata.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* An execution context includes the information necessary to initiate AVM
|
|
12
|
+
* execution along with all state maintained by the AVM throughout execution.
|
|
13
|
+
*/
|
|
14
|
+
export class AvmContext {
|
|
15
|
+
/**
|
|
16
|
+
* Create a new AVM context
|
|
17
|
+
* @param persistableState - Manages world state and accrued substate during execution - (caching, fetching, tracing)
|
|
18
|
+
* @param environment - Contains constant variables provided by the kernel
|
|
19
|
+
* @param machineState - VM state that is modified on an instruction-by-instruction basis
|
|
20
|
+
* @returns new AvmContext instance
|
|
21
|
+
*/
|
|
22
|
+
constructor(
|
|
23
|
+
public persistableState: PublicPersistableStateManager,
|
|
24
|
+
public environment: AvmExecutionEnvironment,
|
|
25
|
+
public machineState: AvmMachineState,
|
|
26
|
+
) {}
|
|
27
|
+
|
|
28
|
+
// This is needed to break a dependency cycle created by the CALL opcode,
|
|
29
|
+
// which needs to create a new simulator but cannot depend directly on AvmSimulator.
|
|
30
|
+
public provideSimulator?: (context: AvmContext) => Promise<AvmSimulatorInterface>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Prepare a new AVM context that will be ready for an external/nested call
|
|
34
|
+
* - Fork the world state journal
|
|
35
|
+
* - Derive a machine state from the current state
|
|
36
|
+
* - E.g., gas metering is preserved but pc is reset
|
|
37
|
+
* - Derive an execution environment from the caller/parent
|
|
38
|
+
* - Alter address
|
|
39
|
+
*
|
|
40
|
+
* @param address - The contract instance to initialize a context for
|
|
41
|
+
* @param calldata - Data/arguments for nested call
|
|
42
|
+
* @param allocatedGas - Gas allocated for the nested call
|
|
43
|
+
* @param callType - Type of call (CALL or STATICCALL)
|
|
44
|
+
* @returns new AvmContext instance
|
|
45
|
+
*/
|
|
46
|
+
public async createNestedContractCallContext(
|
|
47
|
+
address: AztecAddress,
|
|
48
|
+
calldata: CallData,
|
|
49
|
+
allocatedGas: Gas,
|
|
50
|
+
callType: 'CALL' | 'STATICCALL',
|
|
51
|
+
): Promise<AvmContext> {
|
|
52
|
+
const deriveFn =
|
|
53
|
+
callType === 'CALL'
|
|
54
|
+
? this.environment.deriveEnvironmentForNestedCall
|
|
55
|
+
: this.environment.deriveEnvironmentForNestedStaticCall;
|
|
56
|
+
const newExecutionEnvironment = deriveFn.call(this.environment, address, calldata);
|
|
57
|
+
const forkedWorldState = await this.persistableState.fork();
|
|
58
|
+
const machineState = AvmMachineState.fromState(gasToGasLeft(allocatedGas));
|
|
59
|
+
return new AvmContext(forkedWorldState, newExecutionEnvironment, machineState);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { SimulationError } from '@aztec/stdlib/errors';
|
|
2
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
3
|
+
|
|
4
|
+
import { inspect } from 'util';
|
|
5
|
+
|
|
6
|
+
import { createSimulationError } from '../../common/errors.js';
|
|
7
|
+
import type { Gas as AvmGas } from './avm_gas.js';
|
|
8
|
+
import type { ReturnData } from './calldata.js';
|
|
9
|
+
import type { AvmRevertReason } from './errors.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Results of an contract call's execution in the AVM.
|
|
13
|
+
*/
|
|
14
|
+
export class AvmContractCallResult {
|
|
15
|
+
constructor(
|
|
16
|
+
public reverted: boolean,
|
|
17
|
+
public output: ReturnData,
|
|
18
|
+
public gasLeft: AvmGas,
|
|
19
|
+
public revertReason?: AvmRevertReason,
|
|
20
|
+
public totalInstructions: number = 0, // including nested calls
|
|
21
|
+
) {}
|
|
22
|
+
|
|
23
|
+
toString(): string {
|
|
24
|
+
let resultsStr = `reverted: ${this.reverted}, output: ${this.output.bestEffortReadAll(10)}${this.output.length() > 10 ? ' ...' : ''}, gasLeft: ${inspect(
|
|
25
|
+
this.gasLeft,
|
|
26
|
+
)}, totalInstructions: ${this.totalInstructions}`;
|
|
27
|
+
if (this.revertReason) {
|
|
28
|
+
resultsStr += `, revertReason: ${this.revertReason.message}`;
|
|
29
|
+
}
|
|
30
|
+
return resultsStr;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
finalize(): AvmFinalizedCallResult {
|
|
34
|
+
const revertReason = this.revertReason
|
|
35
|
+
? createSimulationError(this.revertReason, this.output.bestEffortReadAll())
|
|
36
|
+
: undefined;
|
|
37
|
+
return new AvmFinalizedCallResult(
|
|
38
|
+
this.reverted,
|
|
39
|
+
this.output,
|
|
40
|
+
Gas.from(this.gasLeft),
|
|
41
|
+
revertReason,
|
|
42
|
+
this.totalInstructions,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Similar to AvmContractCallResult, but with a SimulationError and standard Gas
|
|
49
|
+
* which are useful for consumption external to core AVM simulation.
|
|
50
|
+
*/
|
|
51
|
+
export class AvmFinalizedCallResult {
|
|
52
|
+
constructor(
|
|
53
|
+
public reverted: boolean,
|
|
54
|
+
public output: ReturnData,
|
|
55
|
+
public gasLeft: Gas,
|
|
56
|
+
public revertReason?: SimulationError,
|
|
57
|
+
public totalInstructions: number = 0, // including nested calls
|
|
58
|
+
) {}
|
|
59
|
+
|
|
60
|
+
toString(): string {
|
|
61
|
+
let resultsStr = `reverted: ${this.reverted}, output: ${this.output.bestEffortReadAll(10)}${this.output.length() > 10 ? ' ...' : ''}, gasLeft: ${inspect(
|
|
62
|
+
this.gasLeft,
|
|
63
|
+
)}, totalInstructions: ${this.totalInstructions}`;
|
|
64
|
+
if (this.revertReason) {
|
|
65
|
+
resultsStr += `, revertReason: ${this.revertReason.message}`;
|
|
66
|
+
}
|
|
67
|
+
return resultsStr;
|
|
68
|
+
}
|
|
69
|
+
}
|