@aztec/simulator 4.0.0-nightly.20250907 → 4.0.0-nightly.20260107
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client.d.ts +1 -1
- package/dest/common/errors.d.ts +2 -8
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/common/index.d.ts +1 -1
- package/dest/common/stats/index.d.ts +1 -1
- package/dest/common/stats/stats.d.ts +1 -1
- package/dest/private/acvm/acvm.d.ts +1 -1
- package/dest/private/acvm/acvm_types.d.ts +1 -1
- package/dest/private/acvm/deserialize.d.ts +2 -2
- package/dest/private/acvm/deserialize.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.js +1 -1
- package/dest/private/acvm/index.d.ts +1 -1
- package/dest/private/acvm/serialize.d.ts +2 -2
- package/dest/private/acvm/serialize.d.ts.map +1 -1
- package/dest/private/acvm/serialize.js +1 -1
- package/dest/private/acvm_native.d.ts +2 -3
- package/dest/private/acvm_native.d.ts.map +1 -1
- package/dest/private/acvm_native.js +15 -13
- package/dest/private/acvm_wasm.d.ts +1 -1
- package/dest/private/acvm_wasm.d.ts.map +1 -1
- package/dest/private/acvm_wasm_with_blobs.d.ts +1 -1
- package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.d.ts +1 -1
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.js +16 -15
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts +1 -1
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +1 -1
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +2 -2
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
- package/dest/private/circuit_simulator.d.ts +1 -1
- package/dest/private/factory.d.ts +1 -1
- package/dest/public/avm/avm_context.d.ts +2 -2
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts +2 -2
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.d.ts +5 -4
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.js +5 -5
- package/dest/public/avm/avm_gas.d.ts +2 -2
- package/dest/public/avm/avm_gas.d.ts.map +1 -1
- package/dest/public/avm/avm_gas.js +2 -2
- package/dest/public/avm/avm_machine_state.d.ts +2 -2
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.d.ts +20 -14
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.js +10 -3
- package/dest/public/avm/avm_simulator.d.ts +4 -3
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +19 -25
- package/dest/public/avm/avm_simulator_interface.d.ts +1 -1
- package/dest/public/avm/errors.d.ts +13 -16
- package/dest/public/avm/errors.d.ts.map +1 -1
- package/dest/public/avm/errors.js +21 -22
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +3 -2
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +14 -6
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +4 -2
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +23 -1
- package/dest/public/avm/fixtures/initializers.d.ts +2 -3
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.js +6 -4
- package/dest/public/avm/fixtures/utils.d.ts +4 -3
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
- package/dest/public/avm/fixtures/utils.js +3 -2
- package/dest/public/avm/index.d.ts +1 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts +3 -3
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +8 -8
- package/dest/public/avm/opcodes/addressing_mode.d.ts +1 -1
- package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/public/avm/opcodes/addressing_mode.js +4 -5
- package/dest/public/avm/opcodes/arithmetic.d.ts +10 -8
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.js +11 -1
- package/dest/public/avm/opcodes/bitwise.d.ts +5 -5
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/public/avm/opcodes/comparators.d.ts +4 -4
- package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/public/avm/opcodes/contract.d.ts +1 -1
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/control_flow.d.ts +1 -1
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.d.ts +1 -1
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.js +3 -0
- package/dest/public/avm/opcodes/ec_add.d.ts +2 -2
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.js +6 -6
- package/dest/public/avm/opcodes/environment_getters.d.ts +1 -1
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/environment_getters.js +5 -7
- package/dest/public/avm/opcodes/external_calls.d.ts +1 -1
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +1 -1
- package/dest/public/avm/opcodes/hashing.d.ts +2 -2
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/public/avm/opcodes/hashing.js +9 -4
- package/dest/public/avm/opcodes/index.d.ts +1 -1
- package/dest/public/avm/opcodes/instruction.d.ts +2 -2
- package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/public/avm/opcodes/instruction.js +5 -6
- package/dest/public/avm/opcodes/instruction_impl.d.ts +1 -1
- package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.d.ts +2 -2
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +1 -1
- package/dest/public/avm/opcodes/misc.d.ts +3 -2
- package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/public/avm/opcodes/misc.js +28 -8
- package/dest/public/avm/opcodes/storage.d.ts +3 -3
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/public/avm/revert_reason.d.ts +2 -2
- package/dest/public/avm/revert_reason.d.ts.map +1 -1
- package/dest/public/avm/revert_reason.js +3 -2
- package/dest/public/avm/serialization/buffer_cursor.d.ts +1 -1
- package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.d.ts +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.js +9 -6
- package/dest/public/avm/serialization/instruction_serialization.d.ts +9 -1
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +11 -1
- package/dest/public/avm/test_utils.d.ts +4 -4
- package/dest/public/avm/test_utils.d.ts.map +1 -1
- package/dest/public/avm/test_utils.js +7 -10
- package/dest/public/contracts_db_checkpoint.d.ts +16 -0
- package/dest/public/contracts_db_checkpoint.d.ts.map +1 -0
- package/dest/public/contracts_db_checkpoint.js +30 -0
- package/dest/public/db_interfaces.d.ts +14 -2
- package/dest/public/db_interfaces.d.ts.map +1 -1
- package/dest/public/debug_fn_name.d.ts +15 -2
- package/dest/public/debug_fn_name.d.ts.map +1 -1
- package/dest/public/debug_fn_name.js +28 -2
- package/dest/public/executor_metrics.d.ts +3 -2
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +1 -1
- package/dest/public/executor_metrics_interface.d.ts +3 -2
- package/dest/public/executor_metrics_interface.d.ts.map +1 -1
- package/dest/public/fixtures/amm_test.d.ts +1 -1
- package/dest/public/fixtures/amm_test.js +2 -2
- package/dest/public/fixtures/bulk_test.d.ts +1 -1
- package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
- package/dest/public/fixtures/bulk_test.js +59 -161
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +34 -0
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -0
- package/dest/public/fixtures/custom_bytecode_tester.js +53 -0
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +12 -0
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -0
- package/dest/public/fixtures/custom_bytecode_tests.js +174 -0
- package/dest/public/fixtures/index.d.ts +5 -2
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +4 -1
- package/dest/public/fixtures/minimal_public_tx.d.ts +4 -9
- package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
- package/dest/public/fixtures/minimal_public_tx.js +8 -32
- package/dest/public/fixtures/opcode_spammer.d.ts +123 -0
- package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -0
- package/dest/public/fixtures/opcode_spammer.js +1681 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +25 -5
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +63 -17
- package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
- package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
- package/dest/public/fixtures/simple_contract_data_source.js +4 -4
- package/dest/public/fixtures/token_test.d.ts +6 -2
- package/dest/public/fixtures/token_test.d.ts.map +1 -1
- package/dest/public/fixtures/token_test.js +13 -12
- package/dest/public/fixtures/utils.d.ts +2 -2
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +7 -6
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +46 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +139 -0
- package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
- package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_simulator_bin.js +100 -0
- package/dest/public/hinting_db_sources.d.ts +16 -4
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +74 -13
- package/dest/public/index.d.ts +3 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +1 -1
- package/dest/public/public_db_sources.d.ts +24 -65
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +85 -132
- package/dest/public/public_errors.d.ts +12 -0
- package/dest/public/public_errors.d.ts.map +1 -0
- package/dest/public/public_errors.js +13 -0
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +6 -2
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
- package/dest/public/public_processor/guarded_merkle_tree.js +8 -0
- package/dest/public/public_processor/public_processor.d.ts +11 -13
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +477 -70
- package/dest/public/public_processor/public_processor_metrics.d.ts +1 -1
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +18 -0
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +98 -0
- 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 +22 -0
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +52 -0
- package/dest/public/public_tx_simulator/factories.d.ts +13 -0
- package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/factories.js +28 -0
- package/dest/public/public_tx_simulator/index.d.ts +6 -1
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/index.js +3 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +16 -8
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +7 -8
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +9 -4
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +22 -10
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +22 -29
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +178 -127
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +32 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.js +1 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +4 -3
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +396 -20
- package/dest/public/side_effect_errors.d.ts +42 -2
- package/dest/public/side_effect_errors.d.ts.map +1 -1
- package/dest/public/side_effect_errors.js +70 -1
- package/dest/public/side_effect_trace.d.ts +13 -7
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +36 -21
- package/dest/public/side_effect_trace_interface.d.ts +9 -4
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/state_manager/index.d.ts +1 -1
- package/dest/public/state_manager/nullifiers.d.ts +2 -5
- package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
- package/dest/public/state_manager/nullifiers.js +1 -6
- package/dest/public/state_manager/public_storage.d.ts +2 -2
- package/dest/public/state_manager/public_storage.d.ts.map +1 -1
- package/dest/public/state_manager/public_storage.js +1 -1
- package/dest/public/state_manager/state_manager.d.ts +16 -13
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +64 -21
- package/dest/public/test_executor_metrics.d.ts +4 -3
- package/dest/public/test_executor_metrics.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.js +5 -4
- package/dest/public/unique_class_ids.d.ts +1 -1
- package/dest/public/unique_class_ids.d.ts.map +1 -1
- package/dest/public/utils.d.ts +1 -1
- package/dest/server.d.ts +1 -1
- package/dest/testing.d.ts +1 -1
- package/package.json +24 -19
- package/src/common/errors.ts +1 -1
- package/src/private/acvm/deserialize.ts +1 -1
- package/src/private/acvm/serialize.ts +1 -1
- package/src/private/acvm_native.ts +18 -11
- package/src/private/circuit_recording/circuit_recorder.ts +17 -16
- package/src/private/circuit_recording/simulator_recorder_wrapper.ts +1 -1
- package/src/public/avm/avm_context.ts +1 -1
- package/src/public/avm/avm_contract_call_result.ts +1 -1
- package/src/public/avm/avm_execution_environment.ts +4 -3
- package/src/public/avm/avm_gas.ts +5 -5
- package/src/public/avm/avm_machine_state.ts +1 -1
- package/src/public/avm/avm_memory_types.ts +12 -3
- package/src/public/avm/avm_simulator.ts +24 -33
- package/src/public/avm/errors.ts +24 -27
- package/src/public/avm/fixtures/avm_simulation_tester.ts +14 -4
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +33 -1
- package/src/public/avm/fixtures/initializers.ts +7 -8
- package/src/public/avm/fixtures/utils.ts +3 -2
- package/src/public/avm/opcodes/accrued_substate.ts +5 -5
- package/src/public/avm/opcodes/addressing_mode.ts +5 -5
- package/src/public/avm/opcodes/arithmetic.ts +13 -1
- package/src/public/avm/opcodes/conversion.ts +4 -0
- package/src/public/avm/opcodes/ec_add.ts +6 -6
- package/src/public/avm/opcodes/environment_getters.ts +6 -8
- package/src/public/avm/opcodes/external_calls.ts +1 -1
- package/src/public/avm/opcodes/hashing.ts +10 -4
- package/src/public/avm/opcodes/instruction.ts +8 -6
- package/src/public/avm/opcodes/memory.ts +1 -1
- package/src/public/avm/opcodes/misc.ts +41 -7
- package/src/public/avm/revert_reason.ts +6 -3
- package/src/public/avm/serialization/bytecode_serialization.ts +17 -6
- package/src/public/avm/serialization/instruction_serialization.ts +13 -1
- package/src/public/avm/test_utils.ts +7 -15
- package/src/public/contracts_db_checkpoint.ts +41 -0
- package/src/public/db_interfaces.ts +16 -1
- package/src/public/debug_fn_name.ts +35 -3
- package/src/public/executor_metrics.ts +2 -1
- package/src/public/executor_metrics_interface.ts +2 -1
- package/src/public/fixtures/amm_test.ts +2 -2
- package/src/public/fixtures/bulk_test.ts +38 -25
- package/src/public/fixtures/custom_bytecode_tester.ts +83 -0
- package/src/public/fixtures/custom_bytecode_tests.ts +219 -0
- package/src/public/fixtures/index.ts +8 -1
- package/src/public/fixtures/minimal_public_tx.ts +9 -42
- package/src/public/fixtures/opcode_spammer.ts +1638 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +90 -22
- package/src/public/fixtures/simple_contract_data_source.ts +8 -9
- package/src/public/fixtures/token_test.ts +18 -10
- package/src/public/fixtures/utils.ts +5 -6
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +240 -0
- package/src/public/fuzzing/avm_simulator_bin.ts +140 -0
- package/src/public/hinting_db_sources.ts +117 -10
- package/src/public/index.ts +8 -1
- package/src/public/public_db_sources.ts +112 -175
- package/src/public/public_errors.ts +14 -0
- package/src/public/public_processor/guarded_merkle_tree.ts +10 -1
- package/src/public/public_processor/public_processor.ts +112 -79
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +121 -0
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +200 -0
- package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +132 -0
- package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +237 -0
- package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +81 -0
- package/src/public/public_tx_simulator/factories.ts +41 -0
- package/src/public/public_tx_simulator/index.ts +5 -0
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +13 -14
- package/src/public/public_tx_simulator/public_tx_context.ts +20 -7
- package/src/public/public_tx_simulator/public_tx_simulator.ts +265 -179
- package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +33 -0
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +4 -13
- package/src/public/side_effect_errors.ts +91 -1
- package/src/public/side_effect_trace.ts +49 -24
- package/src/public/side_effect_trace_interface.ts +7 -1
- package/src/public/state_manager/nullifiers.ts +2 -8
- package/src/public/state_manager/public_storage.ts +1 -1
- package/src/public/state_manager/state_manager.ts +87 -39
- package/src/public/test_executor_metrics.ts +7 -5
- package/dest/public/bytecode_errors.d.ts +0 -4
- package/dest/public/bytecode_errors.d.ts.map +0 -1
- package/dest/public/bytecode_errors.js +0 -6
- package/dest/public/tx_contract_cache.d.ts +0 -41
- package/dest/public/tx_contract_cache.d.ts.map +0 -1
- package/dest/public/tx_contract_cache.js +0 -49
- package/src/public/bytecode_errors.ts +0 -6
- package/src/public/tx_contract_cache.ts +0 -69
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { encodeArguments } from '@aztec/stdlib/abi';
|
|
3
|
+
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
3
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
5
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
5
6
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
@@ -37,9 +38,11 @@ export class AvmSimulationTester extends BaseAvmSimulationTester {
|
|
|
37
38
|
super(contractDataSource, merkleTrees);
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
static async create(
|
|
41
|
+
static async create(
|
|
42
|
+
worldStateService: NativeWorldStateService, // make sure to close this later
|
|
43
|
+
): Promise<AvmSimulationTester> {
|
|
41
44
|
const contractDataSource = new SimpleContractDataSource();
|
|
42
|
-
const merkleTrees = await
|
|
45
|
+
const merkleTrees = await worldStateService.fork();
|
|
43
46
|
const treesDB = new PublicTreesDB(merkleTrees);
|
|
44
47
|
const contractsDB = new PublicContractsDB(contractDataSource);
|
|
45
48
|
const trace = new SideEffectTrace();
|
|
@@ -49,7 +52,6 @@ export class AvmSimulationTester extends BaseAvmSimulationTester {
|
|
|
49
52
|
treesDB,
|
|
50
53
|
contractsDB,
|
|
51
54
|
trace,
|
|
52
|
-
/*doMerkleOperations=*/ false,
|
|
53
55
|
firstNullifier,
|
|
54
56
|
DEFAULT_TIMESTAMP,
|
|
55
57
|
);
|
|
@@ -79,12 +81,20 @@ export class AvmSimulationTester extends BaseAvmSimulationTester {
|
|
|
79
81
|
globals.timestamp = DEFAULT_TIMESTAMP;
|
|
80
82
|
globals.gasFees = DEFAULT_GAS_FEES;
|
|
81
83
|
|
|
84
|
+
const config = PublicSimulatorConfig.from({
|
|
85
|
+
skipFeeEnforcement: false,
|
|
86
|
+
collectDebugLogs: true,
|
|
87
|
+
collectHints: false,
|
|
88
|
+
collectStatistics: false,
|
|
89
|
+
collectCallMetadata: true,
|
|
90
|
+
});
|
|
82
91
|
const environment = initExecutionEnvironment({
|
|
83
92
|
calldata,
|
|
84
93
|
globals,
|
|
85
94
|
address,
|
|
86
95
|
sender,
|
|
87
96
|
isStaticCall,
|
|
97
|
+
config,
|
|
88
98
|
});
|
|
89
99
|
const persistableState = await this.stateManager.fork();
|
|
90
100
|
const context = initContext({ env: environment, persistableState });
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS } from '@aztec/constants';
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
5
|
+
import { getCanonicalAuthRegistry } from '@aztec/protocol-contracts/auth-registry';
|
|
5
6
|
import { computeFeePayerBalanceStorageSlot, getCanonicalFeeJuice } from '@aztec/protocol-contracts/fee-juice';
|
|
7
|
+
import { getCanonicalInstanceRegistry } from '@aztec/protocol-contracts/instance-registry';
|
|
6
8
|
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
7
9
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
8
10
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -88,6 +90,36 @@ export abstract class BaseAvmSimulationTester {
|
|
|
88
90
|
return feeJuice.instance;
|
|
89
91
|
}
|
|
90
92
|
|
|
93
|
+
async registerAuthContract(): Promise<ContractInstanceWithAddress> {
|
|
94
|
+
const authRegistry = await getCanonicalAuthRegistry();
|
|
95
|
+
const authRegistryContractClassPublic = {
|
|
96
|
+
...authRegistry.contractClass,
|
|
97
|
+
privateFunctions: [],
|
|
98
|
+
utilityFunctions: [],
|
|
99
|
+
};
|
|
100
|
+
await this.contractDataSource.addNewContract(
|
|
101
|
+
authRegistry.artifact,
|
|
102
|
+
authRegistryContractClassPublic,
|
|
103
|
+
authRegistry.instance,
|
|
104
|
+
);
|
|
105
|
+
return authRegistry.instance;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async registerInstanceRegistryContract(): Promise<ContractInstanceWithAddress> {
|
|
109
|
+
const instanceRegistry = await getCanonicalInstanceRegistry();
|
|
110
|
+
const instanceRegistryContractClassPublic = {
|
|
111
|
+
...instanceRegistry.contractClass,
|
|
112
|
+
privateFunctions: [],
|
|
113
|
+
utilityFunctions: [],
|
|
114
|
+
};
|
|
115
|
+
await this.contractDataSource.addNewContract(
|
|
116
|
+
instanceRegistry.artifact,
|
|
117
|
+
instanceRegistryContractClassPublic,
|
|
118
|
+
instanceRegistry.instance,
|
|
119
|
+
);
|
|
120
|
+
return instanceRegistry.instance;
|
|
121
|
+
}
|
|
122
|
+
|
|
91
123
|
async addContractInstance(contractInstance: ContractInstanceWithAddress, skipNullifierInsertion = false) {
|
|
92
124
|
if (!skipNullifierInsertion) {
|
|
93
125
|
await this.insertContractAddressNullifier(contractInstance.address);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { AVM_MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
|
|
2
|
+
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
-
import {
|
|
5
|
+
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
4
6
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
7
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
6
8
|
import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
@@ -43,7 +45,6 @@ export function initPersistableStateManager(overrides?: {
|
|
|
43
45
|
trace?: PublicSideEffectTraceInterface;
|
|
44
46
|
publicStorage?: PublicStorage;
|
|
45
47
|
nullifiers?: NullifierManager;
|
|
46
|
-
doMerkleOperations?: boolean;
|
|
47
48
|
firstNullifier?: Fr;
|
|
48
49
|
timestamp?: UInt64;
|
|
49
50
|
}): PublicPersistableStateManager {
|
|
@@ -54,9 +55,7 @@ export function initPersistableStateManager(overrides?: {
|
|
|
54
55
|
overrides?.trace || mock<PublicSideEffectTraceInterface>(),
|
|
55
56
|
overrides?.firstNullifier || new Fr(27),
|
|
56
57
|
overrides?.timestamp || DEFAULT_TIMESTAMP,
|
|
57
|
-
|
|
58
|
-
overrides?.publicStorage,
|
|
59
|
-
overrides?.nullifiers,
|
|
58
|
+
/*doMerkleOperations=*/ false,
|
|
60
59
|
);
|
|
61
60
|
}
|
|
62
61
|
|
|
@@ -72,7 +71,7 @@ export function initExecutionEnvironment(overrides?: Partial<AvmExecutionEnviron
|
|
|
72
71
|
overrides?.globals ?? GlobalVariables.empty(),
|
|
73
72
|
overrides?.isStaticCall ?? false,
|
|
74
73
|
overrides?.calldata ?? [],
|
|
75
|
-
overrides?.
|
|
74
|
+
overrides?.config ?? PublicSimulatorConfig.empty(),
|
|
76
75
|
);
|
|
77
76
|
}
|
|
78
77
|
|
|
@@ -83,8 +82,8 @@ export function initGlobalVariables(overrides?: Partial<GlobalVariables>): Globa
|
|
|
83
82
|
return new GlobalVariables(
|
|
84
83
|
overrides?.chainId ?? Fr.zero(),
|
|
85
84
|
overrides?.version ?? Fr.zero(),
|
|
86
|
-
overrides?.blockNumber ??
|
|
87
|
-
overrides?.slotNumber ??
|
|
85
|
+
overrides?.blockNumber ?? BlockNumber.ZERO,
|
|
86
|
+
overrides?.slotNumber ?? SlotNumber.ZERO,
|
|
88
87
|
overrides?.timestamp ?? 0n,
|
|
89
88
|
overrides?.coinbase ?? EthAddress.ZERO,
|
|
90
89
|
overrides?.feeRecipient ?? AztecAddress.zero(),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS } from '@aztec/constants';
|
|
2
|
-
import {
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import {
|
|
4
5
|
type ContractArtifact,
|
|
5
6
|
type FunctionAbi,
|
|
@@ -28,7 +29,7 @@ import type { AvmRevertReason } from '../errors.js';
|
|
|
28
29
|
|
|
29
30
|
export const PUBLIC_DISPATCH_FN_NAME = 'public_dispatch';
|
|
30
31
|
export const DEFAULT_TIMESTAMP: UInt64 = 99833n;
|
|
31
|
-
export const DEFAULT_BLOCK_NUMBER = 42;
|
|
32
|
+
export const DEFAULT_BLOCK_NUMBER = BlockNumber(42);
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* Create a new object with all the same properties as the original, except for the ones in the overrides object.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NullifierCollisionError } from '../../
|
|
1
|
+
import { NullifierCollisionError } from '../../side_effect_errors.js';
|
|
2
2
|
import type { AvmContext } from '../avm_context.js';
|
|
3
3
|
import { TypeTag, Uint1 } from '../avm_memory_types.js';
|
|
4
4
|
import { InstructionExecutionError, StaticCallAlterationError } from '../errors.js';
|
|
@@ -219,8 +219,8 @@ export class EmitUnencryptedLog extends Instruction {
|
|
|
219
219
|
|
|
220
220
|
constructor(
|
|
221
221
|
private indirect: number,
|
|
222
|
-
private logOffset: number,
|
|
223
222
|
private logSizeOffset: number,
|
|
223
|
+
private logOffset: number,
|
|
224
224
|
) {
|
|
225
225
|
super();
|
|
226
226
|
}
|
|
@@ -237,15 +237,15 @@ export class EmitUnencryptedLog extends Instruction {
|
|
|
237
237
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
238
238
|
);
|
|
239
239
|
|
|
240
|
-
const operands = [this.
|
|
241
|
-
const [
|
|
240
|
+
const operands = [this.logSizeOffset, this.logOffset];
|
|
241
|
+
const [logSizeOffset, logOffset] = addressing.resolve(operands, memory);
|
|
242
242
|
memory.checkTag(TypeTag.UINT32, logSizeOffset);
|
|
243
243
|
const logSize = memory.get(logSizeOffset).toNumber();
|
|
244
|
-
memory.checkTagsRange(TypeTag.FIELD, logOffset, logSize);
|
|
245
244
|
|
|
246
245
|
const contractAddress = context.environment.address;
|
|
247
246
|
|
|
248
247
|
context.machineState.consumeGas(this.dynamicGasCost(logSize));
|
|
248
|
+
memory.checkTagsRange(TypeTag.FIELD, logOffset, logSize);
|
|
249
249
|
const log = memory.getSlice(logOffset, logSize).map(f => f.toFr());
|
|
250
250
|
context.persistableState.writePublicLog(contractAddress, log);
|
|
251
251
|
}
|
|
@@ -2,6 +2,8 @@ import { AVM_MAX_OPERANDS } from '@aztec/constants';
|
|
|
2
2
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
3
3
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
4
4
|
|
|
5
|
+
import { strict as assert } from 'assert';
|
|
6
|
+
|
|
5
7
|
import { MemoryValue, TaggedMemory, type TaggedMemoryInterface, TypeTag } from '../avm_memory_types.js';
|
|
6
8
|
import { RelativeAddressOutOfRangeError, TagCheckError } from '../errors.js';
|
|
7
9
|
|
|
@@ -20,9 +22,7 @@ export class Addressing {
|
|
|
20
22
|
) {}
|
|
21
23
|
|
|
22
24
|
public static fromModes(modes: AddressingMode[]): Addressing {
|
|
23
|
-
|
|
24
|
-
throw new Error('Too many operands for addressing mode');
|
|
25
|
-
}
|
|
25
|
+
assert(modes.length <= AVM_MAX_OPERANDS, 'Too many operands for addressing mode');
|
|
26
26
|
return new Addressing(padArrayEnd(modes, AddressingMode.DIRECT, AVM_MAX_OPERANDS));
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -83,7 +83,7 @@ export class Addressing {
|
|
|
83
83
|
baseAddr = mem.get(0);
|
|
84
84
|
const baseAddrTag = baseAddr.getTag();
|
|
85
85
|
if (!TaggedMemory.isValidMemoryAddressTag(baseAddrTag!)) {
|
|
86
|
-
throw TagCheckError.
|
|
86
|
+
throw TagCheckError.forBaseAddress(TypeTag[baseAddrTag!]);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
// Here we know that resolved[i] is at most 32 bits and baseAddr is at most 32 bits.
|
|
@@ -100,7 +100,7 @@ export class Addressing {
|
|
|
100
100
|
|
|
101
101
|
// Final check.
|
|
102
102
|
if (!TaggedMemory.isValidMemoryAddressTag(resolvedTag)) {
|
|
103
|
-
throw TagCheckError.
|
|
103
|
+
throw TagCheckError.forIndirectAddress(resolved[i], TypeTag[resolvedTag]);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
resolved[i] = Number(resolvedValue.toBigInt());
|
|
@@ -88,7 +88,9 @@ export class FieldDiv extends ThreeOperandArithmeticInstruction {
|
|
|
88
88
|
static readonly opcode = Opcode.FDIV_8; // FIXME: needed for gas.
|
|
89
89
|
|
|
90
90
|
protected compute(a: Field, b: Field): Field {
|
|
91
|
-
|
|
91
|
+
if (b.toBigInt() === 0n) {
|
|
92
|
+
throw new ArithmeticError('Division by zero');
|
|
93
|
+
}
|
|
92
94
|
return a.fdiv(b);
|
|
93
95
|
}
|
|
94
96
|
|
|
@@ -105,6 +107,11 @@ export class Shl extends ThreeOperandArithmeticInstruction {
|
|
|
105
107
|
protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
|
|
106
108
|
return a.shl(b);
|
|
107
109
|
}
|
|
110
|
+
|
|
111
|
+
protected override checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
|
|
112
|
+
memory.checkTagsAreSame(aOffset, bOffset);
|
|
113
|
+
TaggedMemory.checkIsIntegralTag(memory.getTag(aOffset)); // Follows that bOffset tag is also of integral type
|
|
114
|
+
}
|
|
108
115
|
}
|
|
109
116
|
|
|
110
117
|
export class Shr extends ThreeOperandArithmeticInstruction {
|
|
@@ -114,4 +121,9 @@ export class Shr extends ThreeOperandArithmeticInstruction {
|
|
|
114
121
|
protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
|
|
115
122
|
return a.shr(b);
|
|
116
123
|
}
|
|
124
|
+
|
|
125
|
+
protected override checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
|
|
126
|
+
memory.checkTagsAreSame(aOffset, bOffset);
|
|
127
|
+
TaggedMemory.checkIsIntegralTag(memory.getTag(aOffset)); // Follows that bOffset tag is also of integral type
|
|
128
|
+
}
|
|
117
129
|
}
|
|
@@ -80,6 +80,10 @@ export class ToRadixBE extends Instruction {
|
|
|
80
80
|
value /= radixBN;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
if (value !== 0n) {
|
|
84
|
+
throw new InvalidToRadixInputsError(`Field failed to decompose in ${numLimbs} limbs.`);
|
|
85
|
+
}
|
|
86
|
+
|
|
83
87
|
const outputType = outputBits != 0 ? Uint1 : Uint8;
|
|
84
88
|
const res = limbArray.map(byte => new outputType(byte));
|
|
85
89
|
memory.setSlice(dstOffset, res);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Grumpkin } from '@aztec/foundation/crypto';
|
|
2
|
-
import { Point } from '@aztec/foundation/
|
|
1
|
+
import { Grumpkin } from '@aztec/foundation/crypto/grumpkin';
|
|
2
|
+
import { Point } from '@aztec/foundation/curves/grumpkin';
|
|
3
3
|
|
|
4
4
|
import type { AvmContext } from '../avm_context.js';
|
|
5
5
|
import { Field, TypeTag, Uint1 } from '../avm_memory_types.js';
|
|
6
|
+
import { EcAddPointNotOnCurveError } from '../errors.js';
|
|
6
7
|
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
7
8
|
import { Addressing } from './addressing_mode.js';
|
|
8
9
|
import { Instruction } from './instruction.js';
|
|
@@ -65,7 +66,7 @@ export class EcAdd extends Instruction {
|
|
|
65
66
|
const p1IsInfinite = memory.get(p1IsInfiniteOffset).toNumber() === 1;
|
|
66
67
|
const p1 = new Point(p1X.toFr(), p1Y.toFr(), p1IsInfinite);
|
|
67
68
|
if (!p1.isOnGrumpkin()) {
|
|
68
|
-
throw new
|
|
69
|
+
throw new EcAddPointNotOnCurveError(/*pointIndex=*/ 1, p1);
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
const p2X = memory.get(p2XOffset);
|
|
@@ -74,17 +75,16 @@ export class EcAdd extends Instruction {
|
|
|
74
75
|
const p2IsInfinite = memory.get(p2IsInfiniteOffset).toNumber() === 1;
|
|
75
76
|
const p2 = new Point(p2X.toFr(), p2Y.toFr(), p2IsInfinite);
|
|
76
77
|
if (!p2.isOnGrumpkin()) {
|
|
77
|
-
throw new
|
|
78
|
+
throw new EcAddPointNotOnCurveError(/*pointIndex=*/ 2, p2);
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
const grumpkin = new Grumpkin();
|
|
81
81
|
let dest;
|
|
82
82
|
if (p1IsInfinite) {
|
|
83
83
|
dest = p2;
|
|
84
84
|
} else if (p2IsInfinite) {
|
|
85
85
|
dest = p1;
|
|
86
86
|
} else {
|
|
87
|
-
dest = await
|
|
87
|
+
dest = await Grumpkin.add(p1, p2);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
// Important to use setSlice() and not set() in the two following statements as
|
|
@@ -20,8 +20,8 @@ export enum EnvironmentVariable {
|
|
|
20
20
|
DAGASLEFT,
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function getValue(
|
|
24
|
-
switch (
|
|
23
|
+
function getValue(varEnum: EnvironmentVariable, ctx: AvmContext) {
|
|
24
|
+
switch (varEnum) {
|
|
25
25
|
case EnvironmentVariable.ADDRESS:
|
|
26
26
|
return new Field(ctx.environment.address.toField());
|
|
27
27
|
case EnvironmentVariable.SENDER:
|
|
@@ -47,7 +47,7 @@ function getValue(e: EnvironmentVariable, ctx: AvmContext) {
|
|
|
47
47
|
case EnvironmentVariable.DAGASLEFT:
|
|
48
48
|
return new Uint32(ctx.machineState.daGasLeft);
|
|
49
49
|
default:
|
|
50
|
-
throw new
|
|
50
|
+
throw new InstructionExecutionError(`Invalid GETENVVAR var enum ${varEnum}`);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -77,13 +77,11 @@ export class GetEnvVar extends Instruction {
|
|
|
77
77
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
78
78
|
);
|
|
79
79
|
|
|
80
|
-
if (!(this.varEnum in EnvironmentVariable)) {
|
|
81
|
-
throw new InstructionExecutionError(`Invalid GETENVVAR var enum ${this.varEnum}`);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
80
|
const operands = [this.dstOffset];
|
|
85
81
|
const [dstOffset] = addressing.resolve(operands, memory);
|
|
86
82
|
|
|
87
|
-
|
|
83
|
+
const value = getValue(this.varEnum as EnvironmentVariable, context);
|
|
84
|
+
|
|
85
|
+
memory.set(dstOffset, value);
|
|
88
86
|
}
|
|
89
87
|
}
|
|
@@ -45,8 +45,8 @@ abstract class ExternalCall extends Instruction {
|
|
|
45
45
|
memory.checkTag(TypeTag.UINT32, argsSizeOffset);
|
|
46
46
|
|
|
47
47
|
const calldataSize = memory.get(argsSizeOffset).toNumber();
|
|
48
|
+
// This is a DOS vector. CalldataSize is chosen by the bytecode, and can be arbitrarily large leading to a OOM here.
|
|
48
49
|
const calldata = memory.getSlice(argsOffset, calldataSize).map(f => f.toFr());
|
|
49
|
-
memory.checkTagsRange(TypeTag.FIELD, argsOffset, calldataSize);
|
|
50
50
|
|
|
51
51
|
const callAddress = memory.getAs<Field>(addrOffset);
|
|
52
52
|
// If we are already in a static call, we propagate the environment.
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { keccakf1600
|
|
1
|
+
import { keccakf1600 } from '@aztec/foundation/crypto/keccak';
|
|
2
|
+
import { poseidon2Permutation } from '@aztec/foundation/crypto/poseidon';
|
|
3
|
+
import { sha256Compression } from '@aztec/foundation/crypto/sha256';
|
|
2
4
|
|
|
3
5
|
import type { AvmContext } from '../avm_context.js';
|
|
4
6
|
import { Field, TypeTag, Uint32, Uint64 } from '../avm_memory_types.js';
|
|
@@ -130,13 +132,17 @@ export class Sha256Compression extends Instruction {
|
|
|
130
132
|
const [outputOffset, stateOffset, inputsOffset] = addressing.resolve(operands, memory);
|
|
131
133
|
|
|
132
134
|
// Note: size of output is same as size of state
|
|
133
|
-
const inputs =
|
|
134
|
-
const state =
|
|
135
|
+
const inputs = memory.getSlice(inputsOffset, INPUTS_SIZE).map(word => word.toBigInt());
|
|
136
|
+
const state = memory.getSlice(stateOffset, STATE_SIZE).map(word => word.toBigInt());
|
|
135
137
|
|
|
136
138
|
memory.checkTagsRange(TypeTag.UINT32, inputsOffset, INPUTS_SIZE);
|
|
137
139
|
memory.checkTagsRange(TypeTag.UINT32, stateOffset, STATE_SIZE);
|
|
138
140
|
|
|
139
|
-
|
|
141
|
+
// At this point both state and inputs are Uint32Array-compatible
|
|
142
|
+
const inputsArray = new Uint32Array(inputs.map(i => Number(i)));
|
|
143
|
+
const stateArray = new Uint32Array(state.map(i => Number(i)));
|
|
144
|
+
|
|
145
|
+
const output = sha256Compression(stateArray, inputsArray);
|
|
140
146
|
|
|
141
147
|
// Conversion required from Uint32Array to Uint32[] (can't map directly, need `...`)
|
|
142
148
|
const res = [...output].map(word => new Uint32(word));
|
|
@@ -36,6 +36,8 @@ export abstract class Instruction {
|
|
|
36
36
|
* @returns Thee string representation.
|
|
37
37
|
*/
|
|
38
38
|
public toString(): string {
|
|
39
|
+
// Note: we could have this be the actual wire opcode if `bytecode_serialization.ts` were to
|
|
40
|
+
// pass it into the class' static `Instruction.as(this, wireFormat)` method.
|
|
39
41
|
let instructionStr = this.constructor.name + ': ';
|
|
40
42
|
// assumes that all properties are flags or operands
|
|
41
43
|
for (const prop of Object.getOwnPropertyNames(this) as (keyof Instruction)[]) {
|
|
@@ -114,9 +116,7 @@ export abstract class Instruction {
|
|
|
114
116
|
*/
|
|
115
117
|
public get type(): string {
|
|
116
118
|
const type = 'type' in this.constructor && (this.constructor.type as string);
|
|
117
|
-
|
|
118
|
-
throw new Error(`Instruction class ${this.constructor.name} does not have a static 'type' property defined.`);
|
|
119
|
-
}
|
|
119
|
+
assert(!!type, `Instruction class ${this.constructor.name} does not have a static 'type' property defined.`);
|
|
120
120
|
return type;
|
|
121
121
|
}
|
|
122
122
|
|
|
@@ -126,9 +126,11 @@ export abstract class Instruction {
|
|
|
126
126
|
*/
|
|
127
127
|
public get opcode(): Opcode {
|
|
128
128
|
const opcode = 'opcode' in this.constructor ? (this.constructor.opcode as Opcode) : undefined;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
assert(
|
|
130
|
+
opcode !== undefined,
|
|
131
|
+
`Instruction class ${this.constructor.name} does not have a static 'opcode' property defined.`,
|
|
132
|
+
);
|
|
133
|
+
assert(Opcode[opcode] !== undefined, `Invalid opcode ${opcode} for instruction class ${this.constructor.name}.`);
|
|
132
134
|
return opcode;
|
|
133
135
|
}
|
|
134
136
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
1
|
+
import { LogLevels, applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
2
2
|
|
|
3
3
|
import type { AvmContext } from '../avm_context.js';
|
|
4
4
|
import { TypeTag } from '../avm_memory_types.js';
|
|
@@ -15,6 +15,7 @@ export class DebugLog extends Instruction {
|
|
|
15
15
|
static readonly wireFormat: OperandType[] = [
|
|
16
16
|
OperandType.UINT8, // Opcode
|
|
17
17
|
OperandType.UINT8, // Indirect
|
|
18
|
+
OperandType.UINT16, // level memory address
|
|
18
19
|
OperandType.UINT16, // message memory address
|
|
19
20
|
OperandType.UINT16, // fields memory address
|
|
20
21
|
OperandType.UINT16, // fields size address
|
|
@@ -23,6 +24,7 @@ export class DebugLog extends Instruction {
|
|
|
23
24
|
|
|
24
25
|
constructor(
|
|
25
26
|
private indirect: number,
|
|
27
|
+
private levelOffset: number,
|
|
26
28
|
private messageOffset: number,
|
|
27
29
|
private fieldsOffset: number,
|
|
28
30
|
private fieldsSizeOffset: number,
|
|
@@ -39,16 +41,30 @@ export class DebugLog extends Instruction {
|
|
|
39
41
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
40
42
|
);
|
|
41
43
|
|
|
42
|
-
const operands = [this.messageOffset, this.fieldsOffset, this.fieldsSizeOffset];
|
|
43
|
-
const [messageOffset, fieldsOffset, fieldsSizeOffset] = addressing.resolve(operands, memory);
|
|
44
|
+
const operands = [this.levelOffset, this.messageOffset, this.fieldsOffset, this.fieldsSizeOffset];
|
|
45
|
+
const [levelOffset, messageOffset, fieldsOffset, fieldsSizeOffset] = addressing.resolve(operands, memory);
|
|
44
46
|
|
|
45
|
-
// DebugLog is a no-op except
|
|
47
|
+
// DebugLog is a no-op except unless the config is set to collect debug logs.
|
|
46
48
|
// Note that we still do address resolution and basic tag-checking (above)
|
|
47
49
|
// To avoid a special-case in the witness generator and circuit.
|
|
48
|
-
if (context.environment.
|
|
50
|
+
if (context.environment.config.collectDebugLogs) {
|
|
51
|
+
memory.checkTag(TypeTag.UINT8, levelOffset);
|
|
52
|
+
const levelNumber = memory.get(levelOffset).toNumber();
|
|
49
53
|
memory.checkTag(TypeTag.UINT32, fieldsSizeOffset);
|
|
50
54
|
const fieldsSize = memory.get(fieldsSizeOffset).toNumber();
|
|
51
55
|
|
|
56
|
+
const memoryReads = 1 /* level */ + 1 /* fieldsSize */ + this.messageSize /* message */ + fieldsSize; /* fields */
|
|
57
|
+
if (
|
|
58
|
+
context.persistableState.getDebugLogMemoryReads() + memoryReads >
|
|
59
|
+
context.environment.config.collectionLimits.maxDebugLogMemoryReads
|
|
60
|
+
) {
|
|
61
|
+
// Regular error on purpose: this is not a recoverable error.
|
|
62
|
+
throw new Error(
|
|
63
|
+
`Max debug log memory reads exceeded: ${context.persistableState.getDebugLogMemoryReads() + memoryReads} > ${context.environment.config.collectionLimits.maxDebugLogMemoryReads}`,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
context.persistableState.writeDebugLogMemoryReads(memoryReads);
|
|
67
|
+
|
|
52
68
|
const rawMessage = memory.getSlice(messageOffset, this.messageSize);
|
|
53
69
|
const fields = memory.getSlice(fieldsOffset, fieldsSize);
|
|
54
70
|
|
|
@@ -57,12 +73,30 @@ export class DebugLog extends Instruction {
|
|
|
57
73
|
|
|
58
74
|
// Interpret str<N> = [u8; N] to string.
|
|
59
75
|
const messageAsStr = rawMessage.map(field => String.fromCharCode(field.toNumber())).join('');
|
|
60
|
-
|
|
76
|
+
|
|
77
|
+
if (!LogLevels[levelNumber]) {
|
|
78
|
+
// Regular error on purpose: this is not a recoverable error.
|
|
79
|
+
throw new Error(`Invalid debug log level: ${levelNumber}`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const level = LogLevels[levelNumber];
|
|
83
|
+
|
|
84
|
+
context.persistableState.writeDebugLog(
|
|
85
|
+
context.environment.address,
|
|
86
|
+
level,
|
|
61
87
|
messageAsStr,
|
|
62
88
|
fields.map(field => field.toFr()),
|
|
63
89
|
);
|
|
64
90
|
|
|
65
|
-
|
|
91
|
+
// Skips string formatting if the level is disabled.
|
|
92
|
+
if (DebugLog.logger.isLevelEnabled(level)) {
|
|
93
|
+
const formattedStr = applyStringFormatting(
|
|
94
|
+
messageAsStr,
|
|
95
|
+
fields.map(field => field.toFr()),
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
DebugLog.logger[level](formattedStr);
|
|
99
|
+
}
|
|
66
100
|
}
|
|
67
101
|
}
|
|
68
102
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
|
|
3
3
|
import type { AvmContext } from './avm_context.js';
|
|
4
4
|
import { type AvmExecutionError, AvmRevertReason } from './errors.js';
|
|
@@ -18,13 +18,16 @@ async function createRevertReason(message: string, revertData: Fr[], context: Av
|
|
|
18
18
|
message = context.machineState.collectedRevertInfo.recursiveRevertReason.message;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const
|
|
21
|
+
const { functionSelector, functionName } = await context.persistableState.getPublicFunctionSelectorAndName(
|
|
22
|
+
context.environment,
|
|
23
|
+
);
|
|
22
24
|
|
|
23
25
|
return new AvmRevertReason(
|
|
24
26
|
message,
|
|
25
27
|
/*failingFunction=*/ {
|
|
26
28
|
contractAddress: context.environment.address,
|
|
27
|
-
|
|
29
|
+
functionSelector,
|
|
30
|
+
functionName,
|
|
28
31
|
},
|
|
29
32
|
/*noirCallStack=*/ [...internalCallStack, context.machineState.pc].map(pc => `0.${pc}`),
|
|
30
33
|
/*options=*/ { cause: nestedError },
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { type Bufferable, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
AvmExecutionError,
|
|
5
|
+
AvmParsingError,
|
|
6
|
+
InvalidOpcodeError,
|
|
7
|
+
InvalidProgramCounterError,
|
|
8
|
+
InvalidTagValueError,
|
|
9
|
+
duringInstrFetch,
|
|
10
|
+
} from '../errors.js';
|
|
4
11
|
import {
|
|
5
12
|
Add,
|
|
6
13
|
And,
|
|
@@ -172,7 +179,7 @@ export function decodeInstructionFromBytecode(
|
|
|
172
179
|
instructionSet: InstructionSet = INSTRUCTION_SET,
|
|
173
180
|
): [Instruction, number] {
|
|
174
181
|
if (pc >= bytecode.length) {
|
|
175
|
-
throw new InvalidProgramCounterError(pc, bytecode.length);
|
|
182
|
+
throw new InvalidProgramCounterError(pc, bytecode.length - 1);
|
|
176
183
|
}
|
|
177
184
|
|
|
178
185
|
try {
|
|
@@ -182,7 +189,7 @@ export function decodeInstructionFromBytecode(
|
|
|
182
189
|
|
|
183
190
|
if (opcode > MAX_OPCODE_VALUE) {
|
|
184
191
|
throw new InvalidOpcodeError(
|
|
185
|
-
`Opcode ${opcode} (0x${opcode.toString(16)}) value is not in the range of valid opcodes.`,
|
|
192
|
+
`Opcode ${opcode} (0x${opcode.toString(16)}) value is not in the range of valid opcodes (at PC ${pc}).`,
|
|
186
193
|
);
|
|
187
194
|
}
|
|
188
195
|
|
|
@@ -192,13 +199,17 @@ export function decodeInstructionFromBytecode(
|
|
|
192
199
|
}
|
|
193
200
|
|
|
194
201
|
const instructionDeserializer: InstructionDeserializer = instructionDeserializerOrUndef;
|
|
202
|
+
|
|
195
203
|
const instruction = instructionDeserializer(cursor);
|
|
196
204
|
return [instruction, cursor.position() - startingPosition];
|
|
197
205
|
} catch (error) {
|
|
198
|
-
if (error instanceof
|
|
199
|
-
throw error;
|
|
206
|
+
if (error instanceof InvalidTagValueError || error instanceof InvalidOpcodeError) {
|
|
207
|
+
throw duringInstrFetch(error, pc);
|
|
208
|
+
} else if (error instanceof AvmExecutionError) {
|
|
209
|
+
throw new AvmParsingError(`Instruction parsing error at pc ${pc}: ${error.message}`);
|
|
200
210
|
} else {
|
|
201
|
-
|
|
211
|
+
const msg = error instanceof Error ? `: ${error.message}` : '';
|
|
212
|
+
throw new AvmParsingError(`Instruction fetching error at pc ${pc}${msg}`);
|
|
202
213
|
}
|
|
203
214
|
}
|
|
204
215
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
|
|
3
3
|
import { strict as assert } from 'assert';
|
|
4
4
|
|
|
@@ -124,6 +124,18 @@ const OPERAND_SPEC = new Map<OperandType, [number, (offset: number) => OperandNa
|
|
|
124
124
|
[OperandType.TAG, [1, Buffer.prototype.readUint8, Buffer.prototype.writeUint8]],
|
|
125
125
|
]);
|
|
126
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Returns the size of an operand in bytes.
|
|
129
|
+
* Should not be called with unknown operand types.
|
|
130
|
+
* @param operandType
|
|
131
|
+
* @returns number size in bytes
|
|
132
|
+
* @throws AssertionError if the operand type is unknown
|
|
133
|
+
*/
|
|
134
|
+
export function getOperandSize(operandType: OperandType): number {
|
|
135
|
+
assert(OPERAND_SPEC.has(operandType), `Unknown operand type: ${operandType}`);
|
|
136
|
+
return OPERAND_SPEC.get(operandType)![0];
|
|
137
|
+
}
|
|
138
|
+
|
|
127
139
|
function readUintBE(buf: Buffer, offset: number, totalBytes: number): bigint {
|
|
128
140
|
let value: bigint = 0n;
|
|
129
141
|
for (let i = 0; i < totalBytes; ++i) {
|