@aztec/simulator 0.0.0-test.1 → 0.0.1-fake-ceab37513c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dest/client.d.ts +5 -3
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +4 -2
- package/dest/common/errors.d.ts +4 -7
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/common/errors.js +51 -32
- package/dest/common/index.d.ts +0 -1
- package/dest/common/index.d.ts.map +1 -1
- package/dest/common/index.js +0 -1
- package/dest/private/acvm/acvm.d.ts +11 -5
- package/dest/private/acvm/acvm.d.ts.map +1 -1
- package/dest/private/acvm/acvm.js +10 -16
- package/dest/private/acvm/acvm_types.d.ts +1 -1
- package/dest/private/acvm/acvm_types.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.d.ts +17 -18
- package/dest/private/acvm/deserialize.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.js +31 -23
- package/dest/private/acvm/index.d.ts +0 -1
- package/dest/private/acvm/index.d.ts.map +1 -1
- package/dest/private/acvm/index.js +0 -1
- package/dest/private/acvm/serialize.d.ts +19 -2
- package/dest/private/acvm/serialize.d.ts.map +1 -1
- package/dest/private/acvm/serialize.js +53 -0
- package/dest/private/{providers/acvm_native.d.ts → acvm_native.d.ts} +10 -10
- package/dest/private/acvm_native.d.ts.map +1 -0
- package/dest/private/{providers/acvm_native.js → acvm_native.js} +11 -7
- package/dest/private/acvm_wasm.d.ts +15 -0
- package/dest/private/acvm_wasm.d.ts.map +1 -0
- package/dest/private/{providers/acvm_wasm.js → acvm_wasm.js} +22 -19
- package/dest/private/acvm_wasm_with_blobs.d.ts +20 -0
- package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -0
- package/dest/private/acvm_wasm_with_blobs.js +35 -0
- package/dest/private/circuit_recording/circuit_recorder.d.ts +108 -0
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -0
- package/dest/private/circuit_recording/circuit_recorder.js +209 -0
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts +31 -0
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -0
- package/dest/private/circuit_recording/file_circuit_recorder.js +135 -0
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +5 -0
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -0
- package/dest/private/circuit_recording/memory_circuit_recorder.js +9 -0
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +21 -0
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -0
- package/dest/private/circuit_recording/simulator_recorder_wrapper.js +44 -0
- package/dest/private/circuit_simulator.d.ts +35 -0
- package/dest/private/circuit_simulator.d.ts.map +1 -0
- package/dest/private/circuit_simulator.js +43 -0
- package/dest/private/factory.d.ts +12 -0
- package/dest/private/factory.d.ts.map +1 -0
- package/dest/private/{providers/factory.js → factory.js} +2 -2
- package/dest/public/avm/avm_context.d.ts +5 -5
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts +4 -2
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.js +11 -7
- package/dest/public/avm/avm_execution_environment.d.ts +2 -1
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.js +4 -2
- package/dest/public/avm/avm_gas.d.ts +4 -20
- package/dest/public/avm/avm_gas.d.ts.map +1 -1
- package/dest/public/avm/avm_gas.js +27 -35
- package/dest/public/avm/avm_machine_state.d.ts +2 -0
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.js +2 -0
- package/dest/public/avm/avm_memory_types.d.ts +98 -87
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.js +17 -6
- package/dest/public/avm/avm_simulator.d.ts +4 -5
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +13 -18
- package/dest/public/avm/avm_simulator_interface.d.ts +9 -0
- package/dest/public/avm/avm_simulator_interface.d.ts.map +1 -0
- package/dest/public/avm/avm_simulator_interface.js +3 -0
- package/dest/public/avm/errors.d.ts +1 -16
- package/dest/public/avm/errors.d.ts.map +1 -1
- package/dest/public/avm/errors.js +0 -37
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +3 -3
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +10 -11
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +4 -4
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +16 -15
- package/dest/public/avm/fixtures/initializers.d.ts +43 -0
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -0
- package/dest/public/avm/fixtures/initializers.js +42 -0
- package/dest/public/avm/fixtures/utils.d.ts +38 -0
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -0
- package/dest/public/avm/fixtures/utils.js +95 -0
- package/dest/public/avm/index.d.ts +0 -2
- package/dest/public/avm/index.d.ts.map +1 -1
- package/dest/public/avm/index.js +0 -2
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +22 -19
- package/dest/public/avm/opcodes/addressing_mode.d.ts +11 -7
- package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/public/avm/opcodes/addressing_mode.js +48 -27
- package/dest/public/avm/opcodes/arithmetic.d.ts +11 -1
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.js +16 -2
- package/dest/public/avm/opcodes/bitwise.d.ts +5 -13
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/public/avm/opcodes/bitwise.js +19 -26
- package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/public/avm/opcodes/comparators.js +3 -3
- package/dest/public/avm/opcodes/contract.d.ts +1 -2
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/contract.js +9 -10
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/public/avm/opcodes/control_flow.js +10 -8
- package/dest/public/avm/opcodes/conversion.d.ts +1 -0
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.js +264 -3
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.js +2 -2
- package/dest/public/avm/opcodes/environment_getters.d.ts +2 -2
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/environment_getters.js +12 -12
- package/dest/public/avm/opcodes/external_calls.d.ts +8 -7
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +39 -33
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/public/avm/opcodes/hashing.js +6 -6
- package/dest/public/avm/opcodes/instruction.d.ts +14 -10
- package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/public/avm/opcodes/instruction.js +18 -13
- package/dest/public/avm/opcodes/memory.d.ts +4 -4
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +37 -33
- package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/public/avm/opcodes/misc.js +17 -12
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/public/avm/opcodes/storage.js +7 -5
- package/dest/public/avm/revert_reason.d.ts +18 -0
- package/dest/public/avm/revert_reason.d.ts.map +1 -0
- package/dest/public/avm/revert_reason.js +38 -0
- package/dest/public/avm/serialization/buffer_cursor.d.ts +0 -2
- package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.d.ts +2 -6
- package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.js +70 -69
- package/dest/public/avm/serialization/instruction_serialization.d.ts +5 -4
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +60 -35
- package/dest/public/avm/test_utils.d.ts +10 -13
- package/dest/public/avm/test_utils.d.ts.map +1 -1
- package/dest/public/avm/test_utils.js +12 -17
- package/dest/public/db_interfaces.d.ts +56 -0
- package/dest/public/db_interfaces.d.ts.map +1 -0
- package/dest/public/db_interfaces.js +3 -0
- package/dest/public/debug_fn_name.d.ts +5 -0
- package/dest/public/debug_fn_name.d.ts.map +1 -0
- package/dest/public/debug_fn_name.js +9 -0
- package/dest/public/executor_metrics.d.ts +10 -3
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +37 -6
- package/dest/public/executor_metrics_interface.d.ts +9 -0
- package/dest/public/executor_metrics_interface.d.ts.map +1 -0
- package/dest/public/executor_metrics_interface.js +1 -0
- package/dest/public/fixtures/amm_test.d.ts +10 -0
- package/dest/public/fixtures/amm_test.d.ts.map +1 -0
- package/dest/public/fixtures/amm_test.js +213 -0
- package/dest/public/fixtures/bulk_test.d.ts +6 -0
- package/dest/public/fixtures/bulk_test.d.ts.map +1 -0
- package/dest/public/fixtures/bulk_test.js +393 -0
- package/dest/public/fixtures/index.d.ts +6 -0
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +6 -0
- package/dest/public/fixtures/minimal_public_tx.d.ts +9 -0
- package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -0
- package/dest/public/fixtures/minimal_public_tx.js +43 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +33 -13
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +90 -70
- package/dest/public/{avm/fixtures → fixtures}/simple_contract_data_source.d.ts +6 -6
- package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -0
- package/dest/public/{avm/fixtures → fixtures}/simple_contract_data_source.js +31 -10
- package/dest/public/fixtures/token_test.d.ts +8 -0
- package/dest/public/fixtures/token_test.d.ts.map +1 -0
- package/dest/public/fixtures/token_test.js +95 -0
- package/dest/public/fixtures/utils.d.ts +16 -3
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +100 -58
- package/dest/public/hinting_db_sources.d.ts +68 -0
- package/dest/public/hinting_db_sources.d.ts.map +1 -0
- package/dest/public/hinting_db_sources.js +294 -0
- package/dest/public/index.d.ts +4 -8
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +4 -7
- package/dest/public/public_db_sources.d.ts +30 -39
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +141 -67
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +47 -0
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -0
- package/dest/public/public_processor/guarded_merkle_tree.js +105 -0
- package/dest/public/public_processor/public_processor.d.ts +19 -29
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +133 -94
- package/dest/public/public_processor/public_processor_metrics.d.ts +2 -2
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor_metrics.js +1 -1
- package/dest/public/public_tx_simulator/index.d.ts +3 -0
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/index.js +2 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +23 -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 +52 -0
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +17 -29
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +59 -91
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +27 -42
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +128 -171
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +20 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +39 -0
- package/dest/public/side_effect_trace.d.ts +10 -62
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +43 -108
- package/dest/public/side_effect_trace_interface.d.ts +5 -22
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/state_manager/index.d.ts +2 -0
- package/dest/public/state_manager/index.d.ts.map +1 -0
- package/dest/public/state_manager/index.js +1 -0
- package/dest/public/{avm/journal → state_manager}/nullifiers.d.ts +2 -2
- package/dest/public/state_manager/nullifiers.d.ts.map +1 -0
- package/dest/public/{avm/journal → state_manager}/nullifiers.js +2 -2
- package/dest/public/{avm/journal → state_manager}/public_storage.d.ts +2 -2
- package/dest/public/state_manager/public_storage.d.ts.map +1 -0
- package/dest/public/{avm/journal/journal.d.ts → state_manager/state_manager.d.ts} +37 -85
- package/dest/public/state_manager/state_manager.d.ts.map +1 -0
- package/dest/public/state_manager/state_manager.js +352 -0
- package/dest/public/test_executor_metrics.d.ts +54 -0
- package/dest/public/test_executor_metrics.d.ts.map +1 -0
- package/dest/public/test_executor_metrics.js +306 -0
- package/dest/public/unique_class_ids.d.ts.map +1 -1
- package/dest/public/utils.d.ts +2 -4
- package/dest/public/utils.d.ts.map +1 -1
- package/dest/public/utils.js +4 -21
- package/dest/server.d.ts +6 -3
- package/dest/server.d.ts.map +1 -1
- package/dest/server.js +5 -2
- package/dest/testing.d.ts +2 -0
- package/dest/testing.d.ts.map +1 -0
- package/dest/testing.js +1 -0
- package/package.json +31 -30
- package/src/client.ts +5 -3
- package/src/common/errors.ts +79 -44
- package/src/common/index.ts +0 -1
- package/src/private/acvm/acvm.ts +17 -32
- package/src/private/acvm/acvm_types.ts +1 -1
- package/src/private/acvm/deserialize.ts +35 -29
- package/src/private/acvm/index.ts +0 -1
- package/src/private/acvm/serialize.ts +63 -0
- package/src/private/{providers/acvm_native.ts → acvm_native.ts} +31 -15
- package/src/private/acvm_wasm.ts +72 -0
- package/src/private/acvm_wasm_with_blobs.ts +54 -0
- package/src/private/circuit_recording/circuit_recorder.ts +260 -0
- package/src/private/circuit_recording/file_circuit_recorder.ts +158 -0
- package/src/private/circuit_recording/memory_circuit_recorder.ts +11 -0
- package/src/private/circuit_recording/simulator_recorder_wrapper.ts +91 -0
- package/src/private/circuit_simulator.ts +90 -0
- package/src/private/{providers/factory.ts → factory.ts} +6 -6
- package/src/public/avm/avm_context.ts +4 -4
- package/src/public/avm/avm_contract_call_result.ts +17 -5
- package/src/public/avm/avm_execution_environment.ts +7 -1
- package/src/public/avm/avm_gas.ts +23 -35
- package/src/public/avm/avm_machine_state.ts +5 -0
- package/src/public/avm/avm_memory_types.ts +19 -6
- package/src/public/avm/avm_simulator.ts +30 -29
- package/src/public/avm/avm_simulator_interface.ts +8 -0
- package/src/public/avm/errors.ts +1 -53
- package/src/public/avm/fixtures/avm_simulation_tester.ts +19 -18
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +15 -14
- package/src/public/avm/fixtures/initializers.ts +103 -0
- package/src/public/avm/fixtures/utils.ts +150 -0
- package/src/public/avm/index.ts +0 -2
- package/src/public/avm/opcodes/accrued_substate.ts +62 -27
- package/src/public/avm/opcodes/addressing_mode.ts +57 -33
- package/src/public/avm/opcodes/arithmetic.ts +24 -2
- package/src/public/avm/opcodes/bitwise.ts +33 -29
- package/src/public/avm/opcodes/comparators.ts +6 -3
- package/src/public/avm/opcodes/contract.ts +10 -7
- package/src/public/avm/opcodes/control_flow.ts +19 -10
- package/src/public/avm/opcodes/conversion.ts +23 -3
- package/src/public/avm/opcodes/ec_add.ts +5 -2
- package/src/public/avm/opcodes/environment_getters.ts +22 -15
- package/src/public/avm/opcodes/external_calls.ts +61 -28
- package/src/public/avm/opcodes/hashing.ts +28 -8
- package/src/public/avm/opcodes/instruction.ts +23 -15
- package/src/public/avm/opcodes/memory.ts +71 -32
- package/src/public/avm/opcodes/misc.ts +24 -16
- package/src/public/avm/opcodes/storage.ts +22 -6
- package/src/public/avm/revert_reason.ts +55 -0
- package/src/public/avm/serialization/buffer_cursor.ts +4 -1
- package/src/public/avm/serialization/bytecode_serialization.ts +72 -74
- package/src/public/avm/serialization/instruction_serialization.ts +63 -34
- package/src/public/avm/test_utils.ts +23 -32
- package/src/public/db_interfaces.ts +61 -0
- package/src/{common → public}/debug_fn_name.ts +7 -7
- package/src/public/executor_metrics.ts +55 -6
- package/src/public/executor_metrics_interface.ts +14 -0
- package/src/public/fixtures/amm_test.ts +331 -0
- package/src/public/fixtures/bulk_test.ts +151 -0
- package/src/public/fixtures/index.ts +6 -0
- package/src/public/fixtures/minimal_public_tx.ts +59 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +154 -113
- package/src/public/{avm/fixtures → fixtures}/simple_contract_data_source.ts +36 -18
- package/src/public/fixtures/token_test.ts +140 -0
- package/src/public/fixtures/utils.ts +141 -68
- package/src/public/hinting_db_sources.ts +500 -0
- package/src/public/index.ts +4 -8
- package/src/public/public_db_sources.ts +179 -96
- package/src/public/public_processor/guarded_merkle_tree.ts +149 -0
- package/src/public/public_processor/public_processor.ts +179 -139
- package/src/public/public_processor/public_processor_metrics.ts +2 -2
- package/src/public/public_tx_simulator/index.ts +2 -0
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +106 -0
- package/src/public/public_tx_simulator/public_tx_context.ts +153 -193
- package/src/public/public_tx_simulator/public_tx_simulator.ts +167 -211
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +72 -0
- package/src/public/side_effect_trace.ts +52 -303
- package/src/public/side_effect_trace_interface.ts +4 -58
- package/src/public/state_manager/index.ts +1 -0
- package/src/public/{avm/journal → state_manager}/nullifiers.ts +4 -4
- package/src/public/{avm/journal → state_manager}/public_storage.ts +2 -2
- package/src/public/state_manager/state_manager.ts +512 -0
- package/src/public/test_executor_metrics.ts +395 -0
- package/src/public/utils.ts +5 -21
- package/src/server.ts +6 -3
- package/src/testing.ts +1 -0
- package/dest/common/db_interfaces.d.ts +0 -80
- package/dest/common/db_interfaces.d.ts.map +0 -1
- package/dest/common/db_interfaces.js +0 -1
- package/dest/common/debug_fn_name.d.ts +0 -5
- package/dest/common/debug_fn_name.d.ts.map +0 -1
- package/dest/common/debug_fn_name.js +0 -6
- package/dest/common/message_load_oracle_inputs.d.ts +0 -15
- package/dest/common/message_load_oracle_inputs.d.ts.map +0 -1
- package/dest/common/message_load_oracle_inputs.js +0 -15
- package/dest/private/acvm/oracle/index.d.ts +0 -14
- package/dest/private/acvm/oracle/index.d.ts.map +0 -1
- package/dest/private/acvm/oracle/index.js +0 -2
- package/dest/private/acvm/oracle/oracle.d.ts +0 -49
- package/dest/private/acvm/oracle/oracle.d.ts.map +0 -1
- package/dest/private/acvm/oracle/oracle.js +0 -263
- package/dest/private/acvm/oracle/typed_oracle.d.ts +0 -83
- package/dest/private/acvm/oracle/typed_oracle.d.ts.map +0 -1
- package/dest/private/acvm/oracle/typed_oracle.js +0 -132
- package/dest/private/execution_data_provider.d.ts +0 -261
- package/dest/private/execution_data_provider.d.ts.map +0 -1
- package/dest/private/execution_data_provider.js +0 -14
- package/dest/private/execution_note_cache.d.ts +0 -93
- package/dest/private/execution_note_cache.d.ts.map +0 -1
- package/dest/private/execution_note_cache.js +0 -180
- package/dest/private/hashed_values_cache.d.ts +0 -28
- package/dest/private/hashed_values_cache.d.ts.map +0 -1
- package/dest/private/hashed_values_cache.js +0 -46
- package/dest/private/index.d.ts +0 -13
- package/dest/private/index.d.ts.map +0 -1
- package/dest/private/index.js +0 -12
- package/dest/private/pick_notes.d.ts +0 -85
- package/dest/private/pick_notes.d.ts.map +0 -1
- package/dest/private/pick_notes.js +0 -51
- package/dest/private/private_execution.d.ts +0 -25
- package/dest/private/private_execution.d.ts.map +0 -1
- package/dest/private/private_execution.js +0 -92
- package/dest/private/private_execution_oracle.d.ts +0 -215
- package/dest/private/private_execution_oracle.d.ts.map +0 -1
- package/dest/private/private_execution_oracle.js +0 -382
- package/dest/private/providers/acvm_native.d.ts.map +0 -1
- package/dest/private/providers/acvm_wasm.d.ts +0 -15
- package/dest/private/providers/acvm_wasm.d.ts.map +0 -1
- package/dest/private/providers/acvm_wasm_with_blobs.d.ts +0 -19
- package/dest/private/providers/acvm_wasm_with_blobs.d.ts.map +0 -1
- package/dest/private/providers/acvm_wasm_with_blobs.js +0 -32
- package/dest/private/providers/factory.d.ts +0 -12
- package/dest/private/providers/factory.d.ts.map +0 -1
- package/dest/private/providers/simulation_provider.d.ts +0 -19
- package/dest/private/providers/simulation_provider.d.ts.map +0 -1
- package/dest/private/providers/simulation_provider.js +0 -24
- package/dest/private/simulator.d.ts +0 -34
- package/dest/private/simulator.d.ts.map +0 -1
- package/dest/private/simulator.js +0 -76
- package/dest/private/unconstrained_execution.d.ts +0 -10
- package/dest/private/unconstrained_execution.d.ts.map +0 -1
- package/dest/private/unconstrained_execution.js +0 -27
- package/dest/private/unconstrained_execution_oracle.d.ts +0 -161
- package/dest/private/unconstrained_execution_oracle.d.ts.map +0 -1
- package/dest/private/unconstrained_execution_oracle.js +0 -258
- package/dest/public/avm/bytecode_utils.d.ts +0 -5
- package/dest/public/avm/bytecode_utils.d.ts.map +0 -1
- package/dest/public/avm/bytecode_utils.js +0 -17
- package/dest/public/avm/fixtures/index.d.ts +0 -84
- package/dest/public/avm/fixtures/index.d.ts.map +0 -1
- package/dest/public/avm/fixtures/index.js +0 -175
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +0 -1
- package/dest/public/avm/journal/index.d.ts +0 -2
- package/dest/public/avm/journal/index.d.ts.map +0 -1
- package/dest/public/avm/journal/index.js +0 -1
- package/dest/public/avm/journal/journal.d.ts.map +0 -1
- package/dest/public/avm/journal/journal.js +0 -486
- package/dest/public/avm/journal/nullifiers.d.ts.map +0 -1
- package/dest/public/avm/journal/public_storage.d.ts.map +0 -1
- package/dest/public/execution.d.ts +0 -108
- package/dest/public/execution.d.ts.map +0 -1
- package/dest/public/execution.js +0 -9
- package/dest/test/utils.d.ts +0 -13
- package/dest/test/utils.d.ts.map +0 -1
- package/dest/test/utils.js +0 -22
- package/src/common/db_interfaces.ts +0 -94
- package/src/common/message_load_oracle_inputs.ts +0 -15
- package/src/private/acvm/oracle/index.ts +0 -16
- package/src/private/acvm/oracle/oracle.ts +0 -455
- package/src/private/acvm/oracle/typed_oracle.ts +0 -259
- package/src/private/execution_data_provider.ts +0 -323
- package/src/private/execution_note_cache.ts +0 -217
- package/src/private/hashed_values_cache.ts +0 -55
- package/src/private/index.ts +0 -16
- package/src/private/pick_notes.ts +0 -141
- package/src/private/private_execution.ts +0 -151
- package/src/private/private_execution_oracle.ts +0 -614
- package/src/private/providers/acvm_wasm.ts +0 -63
- package/src/private/providers/acvm_wasm_with_blobs.ts +0 -50
- package/src/private/providers/simulation_provider.ts +0 -45
- package/src/private/simulator.ts +0 -147
- package/src/private/unconstrained_execution.ts +0 -50
- package/src/private/unconstrained_execution_oracle.ts +0 -373
- package/src/public/avm/bytecode_utils.ts +0 -17
- package/src/public/avm/fixtures/index.ts +0 -296
- package/src/public/avm/journal/index.ts +0 -1
- package/src/public/avm/journal/journal.ts +0 -742
- package/src/public/avm/opcodes/.eslintrc.cjs +0 -8
- package/src/public/execution.ts +0 -140
- package/src/test/utils.ts +0 -36
- /package/dest/public/{avm/journal → state_manager}/public_storage.js +0 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { AVM_MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import { GasFees } from '@aztec/stdlib/gas';
|
|
6
|
+
import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
7
|
+
import type { UInt64 } from '@aztec/stdlib/types';
|
|
8
|
+
|
|
9
|
+
import { mock } from 'jest-mock-extended';
|
|
10
|
+
|
|
11
|
+
import type { PublicContractsDB, PublicTreesDB } from '../../public_db_sources.js';
|
|
12
|
+
import type { PublicSideEffectTraceInterface } from '../../side_effect_trace_interface.js';
|
|
13
|
+
import { NullifierManager } from '../../state_manager/nullifiers.js';
|
|
14
|
+
import { PublicStorage } from '../../state_manager/public_storage.js';
|
|
15
|
+
import { PublicPersistableStateManager } from '../../state_manager/state_manager.js';
|
|
16
|
+
import { AvmContext } from '../avm_context.js';
|
|
17
|
+
import { AvmExecutionEnvironment } from '../avm_execution_environment.js';
|
|
18
|
+
import { AvmMachineState } from '../avm_machine_state.js';
|
|
19
|
+
import { AvmSimulator } from '../avm_simulator.js';
|
|
20
|
+
import { DEFAULT_TIMESTAMP } from './utils.js';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Create a new AVM context with default values.
|
|
24
|
+
*/
|
|
25
|
+
export function initContext(overrides?: {
|
|
26
|
+
persistableState?: PublicPersistableStateManager;
|
|
27
|
+
env?: AvmExecutionEnvironment;
|
|
28
|
+
machineState?: AvmMachineState;
|
|
29
|
+
}): AvmContext {
|
|
30
|
+
const ctx = new AvmContext(
|
|
31
|
+
overrides?.persistableState || initPersistableStateManager(),
|
|
32
|
+
overrides?.env || initExecutionEnvironment(),
|
|
33
|
+
overrides?.machineState || initMachineState(),
|
|
34
|
+
);
|
|
35
|
+
ctx.provideSimulator = AvmSimulator.build;
|
|
36
|
+
return ctx;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Creates an empty state manager with mocked host storage. */
|
|
40
|
+
export function initPersistableStateManager(overrides?: {
|
|
41
|
+
treesDB?: PublicTreesDB;
|
|
42
|
+
contractsDB?: PublicContractsDB;
|
|
43
|
+
trace?: PublicSideEffectTraceInterface;
|
|
44
|
+
publicStorage?: PublicStorage;
|
|
45
|
+
nullifiers?: NullifierManager;
|
|
46
|
+
doMerkleOperations?: boolean;
|
|
47
|
+
firstNullifier?: Fr;
|
|
48
|
+
timestamp?: UInt64;
|
|
49
|
+
}): PublicPersistableStateManager {
|
|
50
|
+
const treesDB = overrides?.treesDB || mock<PublicTreesDB>();
|
|
51
|
+
return new PublicPersistableStateManager(
|
|
52
|
+
treesDB,
|
|
53
|
+
overrides?.contractsDB || mock<PublicContractsDB>(),
|
|
54
|
+
overrides?.trace || mock<PublicSideEffectTraceInterface>(),
|
|
55
|
+
overrides?.firstNullifier || new Fr(27),
|
|
56
|
+
overrides?.timestamp || DEFAULT_TIMESTAMP,
|
|
57
|
+
overrides?.doMerkleOperations || false,
|
|
58
|
+
overrides?.publicStorage,
|
|
59
|
+
overrides?.nullifiers,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Create an empty instance of the Execution Environment where all values are zero, unless overridden in the overrides object
|
|
65
|
+
*/
|
|
66
|
+
export function initExecutionEnvironment(overrides?: Partial<AvmExecutionEnvironment>): AvmExecutionEnvironment {
|
|
67
|
+
return new AvmExecutionEnvironment(
|
|
68
|
+
overrides?.address ?? AztecAddress.zero(),
|
|
69
|
+
overrides?.sender ?? AztecAddress.zero(),
|
|
70
|
+
overrides?.contractCallDepth ?? Fr.zero(),
|
|
71
|
+
overrides?.transactionFee ?? Fr.zero(),
|
|
72
|
+
overrides?.globals ?? GlobalVariables.empty(),
|
|
73
|
+
overrides?.isStaticCall ?? false,
|
|
74
|
+
overrides?.calldata ?? [],
|
|
75
|
+
overrides?.clientInitiatedSimulation ?? true, // default to true for testing even though internal default is false
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Create an empty instance of the Execution Environment where all values are zero, unless overridden in the overrides object
|
|
81
|
+
*/
|
|
82
|
+
export function initGlobalVariables(overrides?: Partial<GlobalVariables>): GlobalVariables {
|
|
83
|
+
return new GlobalVariables(
|
|
84
|
+
overrides?.chainId ?? Fr.zero(),
|
|
85
|
+
overrides?.version ?? Fr.zero(),
|
|
86
|
+
overrides?.blockNumber ?? 0,
|
|
87
|
+
overrides?.slotNumber ?? Fr.zero(),
|
|
88
|
+
overrides?.timestamp ?? 0n,
|
|
89
|
+
overrides?.coinbase ?? EthAddress.ZERO,
|
|
90
|
+
overrides?.feeRecipient ?? AztecAddress.zero(),
|
|
91
|
+
overrides?.gasFees ?? GasFees.empty(),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Create an empty instance of the Machine State where all values are set to a large enough amount, unless overridden in the overrides object
|
|
97
|
+
*/
|
|
98
|
+
export function initMachineState(overrides?: Partial<AvmMachineState>): AvmMachineState {
|
|
99
|
+
return AvmMachineState.fromState({
|
|
100
|
+
l2GasLeft: overrides?.l2GasLeft ?? AVM_MAX_PROCESSABLE_L2_GAS,
|
|
101
|
+
daGasLeft: overrides?.daGasLeft ?? 1e8,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS } from '@aztec/constants';
|
|
2
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import {
|
|
4
|
+
type ContractArtifact,
|
|
5
|
+
type FunctionAbi,
|
|
6
|
+
type FunctionArtifact,
|
|
7
|
+
FunctionSelector,
|
|
8
|
+
getAllFunctionAbis,
|
|
9
|
+
} from '@aztec/stdlib/abi';
|
|
10
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
11
|
+
import {
|
|
12
|
+
type ContractClassPublic,
|
|
13
|
+
type ContractInstanceWithAddress,
|
|
14
|
+
computeInitializationHash,
|
|
15
|
+
} from '@aztec/stdlib/contract';
|
|
16
|
+
import { isNoirCallStackUnresolved } from '@aztec/stdlib/errors';
|
|
17
|
+
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
18
|
+
import { deriveKeys } from '@aztec/stdlib/keys';
|
|
19
|
+
import { makeContractClassPublic, makeContractInstanceFromClassId } from '@aztec/stdlib/testing';
|
|
20
|
+
import type { UInt64 } from '@aztec/stdlib/types';
|
|
21
|
+
|
|
22
|
+
import { strict as assert } from 'assert';
|
|
23
|
+
import merge from 'lodash.merge';
|
|
24
|
+
|
|
25
|
+
import { resolveAssertionMessageFromRevertData, traverseCauseChain } from '../../../common/index.js';
|
|
26
|
+
import { Field, Uint8, Uint32, Uint64 } from '../avm_memory_types.js';
|
|
27
|
+
import type { AvmRevertReason } from '../errors.js';
|
|
28
|
+
|
|
29
|
+
export const PUBLIC_DISPATCH_FN_NAME = 'public_dispatch';
|
|
30
|
+
export const DEFAULT_TIMESTAMP: UInt64 = 99833n;
|
|
31
|
+
export const DEFAULT_BLOCK_NUMBER = 42;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Create a new object with all the same properties as the original, except for the ones in the overrides object.
|
|
35
|
+
*/
|
|
36
|
+
export function allSameExcept(original: any, overrides: any): any {
|
|
37
|
+
return merge({}, original, overrides);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function randomMemoryBytes(length: number): Uint8[] {
|
|
41
|
+
return [...Array(length)].map(_ => new Uint8(Math.floor(Math.random() * 255)));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function randomMemoryUint32s(length: number): Uint32[] {
|
|
45
|
+
return [...Array(length)].map(_ => new Uint32(Math.floor(Math.random() * 255)));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function randomMemoryUint64s(length: number): Uint64[] {
|
|
49
|
+
return [...Array(length)].map(_ => new Uint64(Math.floor(Math.random() * 255)));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function randomMemoryFields(length: number): Field[] {
|
|
53
|
+
return [...Array(length)].map(_ => new Field(Fr.random()));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function getFunctionSelector(
|
|
57
|
+
functionName: string,
|
|
58
|
+
contractArtifact: ContractArtifact,
|
|
59
|
+
): Promise<FunctionSelector> {
|
|
60
|
+
const fnArtifact = getAllFunctionAbis(contractArtifact).find(f => f.name === functionName)!;
|
|
61
|
+
assert(!!fnArtifact, `Function ${functionName} not found in ${contractArtifact.name}`);
|
|
62
|
+
const params = fnArtifact.parameters;
|
|
63
|
+
return FunctionSelector.fromNameAndParameters(fnArtifact.name, params);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function getContractFunctionArtifact(
|
|
67
|
+
functionName: string,
|
|
68
|
+
contractArtifact: ContractArtifact,
|
|
69
|
+
): FunctionArtifact | undefined {
|
|
70
|
+
return contractArtifact.functions.find(f => f.name === functionName);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function getContractFunctionAbi(
|
|
74
|
+
functionName: string,
|
|
75
|
+
contractArtifact: ContractArtifact,
|
|
76
|
+
): FunctionAbi | undefined {
|
|
77
|
+
return (
|
|
78
|
+
contractArtifact.functions.find(f => f.name === functionName) ??
|
|
79
|
+
contractArtifact.nonDispatchPublicFunctions.find(f => f.name === functionName)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function resolveContractAssertionMessage(
|
|
84
|
+
functionName: string,
|
|
85
|
+
revertReason: AvmRevertReason,
|
|
86
|
+
output: Fr[],
|
|
87
|
+
contractArtifact: ContractArtifact,
|
|
88
|
+
): string | undefined {
|
|
89
|
+
traverseCauseChain(revertReason, cause => {
|
|
90
|
+
revertReason = cause as AvmRevertReason;
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const functionArtifact = getAllFunctionAbis(contractArtifact).find(f => f.name === functionName);
|
|
94
|
+
if (!functionArtifact || !revertReason.noirCallStack || !isNoirCallStackUnresolved(revertReason.noirCallStack)) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return resolveAssertionMessageFromRevertData(output, functionArtifact);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Create a contract class and instance given constructor args, artifact, etc.
|
|
103
|
+
* NOTE: This is useful for testing real-ish contract class registration and instance deployment TXs (via logs)
|
|
104
|
+
* @param constructorArgs - The constructor arguments for the contract.
|
|
105
|
+
* @param deployer - The deployer of the contract.
|
|
106
|
+
* @param contractArtifact - The contract artifact for the contract.
|
|
107
|
+
* @param seed - The seed for the contract.
|
|
108
|
+
* @param originalContractClassId - The original contract class ID (if upgraded)
|
|
109
|
+
* @returns The contract class, instance, and contract address nullifier.
|
|
110
|
+
*/
|
|
111
|
+
export async function createContractClassAndInstance(
|
|
112
|
+
constructorArgs: any[],
|
|
113
|
+
deployer: AztecAddress,
|
|
114
|
+
contractArtifact: ContractArtifact,
|
|
115
|
+
seed = 0,
|
|
116
|
+
contractClassSeed = seed,
|
|
117
|
+
originalContractClassId?: Fr, // if previously upgraded
|
|
118
|
+
): Promise<{
|
|
119
|
+
contractClass: ContractClassPublic;
|
|
120
|
+
contractInstance: ContractInstanceWithAddress;
|
|
121
|
+
contractAddressNullifier: Fr;
|
|
122
|
+
}> {
|
|
123
|
+
const bytecode = (getContractFunctionArtifact(PUBLIC_DISPATCH_FN_NAME, contractArtifact) as FunctionArtifact)!
|
|
124
|
+
.bytecode;
|
|
125
|
+
const contractClass = await makeContractClassPublic(contractClassSeed, bytecode);
|
|
126
|
+
|
|
127
|
+
const constructorAbi = getContractFunctionAbi('constructor', contractArtifact);
|
|
128
|
+
const { publicKeys } = await deriveKeys(new Fr(seed));
|
|
129
|
+
const initializationHash = await computeInitializationHash(constructorAbi, constructorArgs);
|
|
130
|
+
const contractInstance =
|
|
131
|
+
originalContractClassId === undefined
|
|
132
|
+
? await makeContractInstanceFromClassId(contractClass.id, seed, {
|
|
133
|
+
deployer,
|
|
134
|
+
initializationHash,
|
|
135
|
+
publicKeys,
|
|
136
|
+
})
|
|
137
|
+
: await makeContractInstanceFromClassId(originalContractClassId, seed, {
|
|
138
|
+
deployer,
|
|
139
|
+
initializationHash,
|
|
140
|
+
currentClassId: contractClass.id,
|
|
141
|
+
publicKeys,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const contractAddressNullifier = await siloNullifier(
|
|
145
|
+
AztecAddress.fromNumber(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS),
|
|
146
|
+
contractInstance.address.toField(),
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
return { contractClass, contractInstance, contractAddressNullifier };
|
|
150
|
+
}
|
package/src/public/avm/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { NullifierCollisionError } from '../../state_manager/nullifiers.js';
|
|
1
2
|
import type { AvmContext } from '../avm_context.js';
|
|
2
3
|
import { TypeTag, Uint1 } from '../avm_memory_types.js';
|
|
3
4
|
import { InstructionExecutionError, StaticCallAlterationError } from '../errors.js';
|
|
4
|
-
import { NullifierCollisionError } from '../journal/nullifiers.js';
|
|
5
5
|
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
6
6
|
import { Addressing } from './addressing_mode.js';
|
|
7
7
|
import { Instruction } from './instruction.js';
|
|
@@ -29,15 +29,19 @@ export class NoteHashExists extends Instruction {
|
|
|
29
29
|
|
|
30
30
|
public async execute(context: AvmContext): Promise<void> {
|
|
31
31
|
const memory = context.machineState.memory;
|
|
32
|
-
|
|
32
|
+
const addressing = Addressing.fromWire(this.indirect);
|
|
33
|
+
|
|
34
|
+
context.machineState.consumeGas(
|
|
35
|
+
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
36
|
+
);
|
|
33
37
|
const operands = [this.noteHashOffset, this.leafIndexOffset, this.existsOffset];
|
|
34
|
-
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
35
38
|
const [noteHashOffset, leafIndexOffset, existsOffset] = addressing.resolve(operands, memory);
|
|
36
|
-
memory.
|
|
39
|
+
memory.checkTag(TypeTag.FIELD, noteHashOffset);
|
|
40
|
+
memory.checkTag(TypeTag.UINT64, leafIndexOffset);
|
|
37
41
|
|
|
38
42
|
// Note that this instruction accepts any type in memory, and converts to Field.
|
|
39
43
|
const noteHash = memory.get(noteHashOffset).toFr();
|
|
40
|
-
const leafIndex = memory.get(leafIndexOffset).
|
|
44
|
+
const leafIndex = memory.get(leafIndexOffset).toBigInt();
|
|
41
45
|
|
|
42
46
|
const exists = await context.persistableState.checkNoteHashExists(context.environment.address, noteHash, leafIndex);
|
|
43
47
|
memory.set(existsOffset, exists ? new Uint1(1) : new Uint1(0));
|
|
@@ -50,16 +54,22 @@ export class EmitNoteHash extends Instruction {
|
|
|
50
54
|
// Informs (de)serialization. See Instruction.deserialize.
|
|
51
55
|
static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16];
|
|
52
56
|
|
|
53
|
-
constructor(
|
|
57
|
+
constructor(
|
|
58
|
+
private indirect: number,
|
|
59
|
+
private noteHashOffset: number,
|
|
60
|
+
) {
|
|
54
61
|
super();
|
|
55
62
|
}
|
|
56
63
|
|
|
57
64
|
public async execute(context: AvmContext): Promise<void> {
|
|
58
65
|
const memory = context.machineState.memory;
|
|
59
|
-
|
|
66
|
+
const addressing = Addressing.fromWire(this.indirect);
|
|
67
|
+
|
|
68
|
+
context.machineState.consumeGas(
|
|
69
|
+
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
70
|
+
);
|
|
60
71
|
|
|
61
72
|
const operands = [this.noteHashOffset];
|
|
62
|
-
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
63
73
|
const [noteHashOffset] = addressing.resolve(operands, memory);
|
|
64
74
|
memory.checkTag(TypeTag.FIELD, noteHashOffset);
|
|
65
75
|
|
|
@@ -95,10 +105,13 @@ export class NullifierExists extends Instruction {
|
|
|
95
105
|
|
|
96
106
|
public async execute(context: AvmContext): Promise<void> {
|
|
97
107
|
const memory = context.machineState.memory;
|
|
98
|
-
|
|
108
|
+
const addressing = Addressing.fromWire(this.indirect);
|
|
109
|
+
|
|
110
|
+
context.machineState.consumeGas(
|
|
111
|
+
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
112
|
+
);
|
|
99
113
|
|
|
100
114
|
const operands = [this.nullifierOffset, this.addressOffset, this.existsOffset];
|
|
101
|
-
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
102
115
|
const [nullifierOffset, addressOffset, existsOffset] = addressing.resolve(operands, memory);
|
|
103
116
|
memory.checkTags(TypeTag.FIELD, nullifierOffset, addressOffset);
|
|
104
117
|
|
|
@@ -116,7 +129,10 @@ export class EmitNullifier extends Instruction {
|
|
|
116
129
|
// Informs (de)serialization. See Instruction.deserialize.
|
|
117
130
|
static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16];
|
|
118
131
|
|
|
119
|
-
constructor(
|
|
132
|
+
constructor(
|
|
133
|
+
private indirect: number,
|
|
134
|
+
private nullifierOffset: number,
|
|
135
|
+
) {
|
|
120
136
|
super();
|
|
121
137
|
}
|
|
122
138
|
|
|
@@ -126,10 +142,13 @@ export class EmitNullifier extends Instruction {
|
|
|
126
142
|
}
|
|
127
143
|
|
|
128
144
|
const memory = context.machineState.memory;
|
|
129
|
-
|
|
145
|
+
const addressing = Addressing.fromWire(this.indirect);
|
|
146
|
+
|
|
147
|
+
context.machineState.consumeGas(
|
|
148
|
+
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
149
|
+
);
|
|
130
150
|
|
|
131
151
|
const operands = [this.nullifierOffset];
|
|
132
|
-
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
133
152
|
const [nullifierOffset] = addressing.resolve(operands, memory);
|
|
134
153
|
memory.checkTag(TypeTag.FIELD, nullifierOffset);
|
|
135
154
|
|
|
@@ -172,20 +191,21 @@ export class L1ToL2MessageExists extends Instruction {
|
|
|
172
191
|
|
|
173
192
|
public async execute(context: AvmContext): Promise<void> {
|
|
174
193
|
const memory = context.machineState.memory;
|
|
175
|
-
|
|
194
|
+
const addressing = Addressing.fromWire(this.indirect);
|
|
195
|
+
|
|
196
|
+
context.machineState.consumeGas(
|
|
197
|
+
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
198
|
+
);
|
|
176
199
|
|
|
177
200
|
const operands = [this.msgHashOffset, this.msgLeafIndexOffset, this.existsOffset];
|
|
178
|
-
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
179
201
|
const [msgHashOffset, msgLeafIndexOffset, existsOffset] = addressing.resolve(operands, memory);
|
|
180
|
-
|
|
202
|
+
|
|
203
|
+
memory.checkTag(TypeTag.FIELD, msgHashOffset);
|
|
204
|
+
memory.checkTag(TypeTag.UINT64, msgLeafIndexOffset);
|
|
181
205
|
|
|
182
206
|
const msgHash = memory.get(msgHashOffset).toFr();
|
|
183
207
|
const msgLeafIndex = memory.get(msgLeafIndexOffset).toFr();
|
|
184
|
-
const exists = await context.persistableState.checkL1ToL2MessageExists(
|
|
185
|
-
context.environment.address,
|
|
186
|
-
msgHash,
|
|
187
|
-
msgLeafIndex,
|
|
188
|
-
);
|
|
208
|
+
const exists = await context.persistableState.checkL1ToL2MessageExists(msgHash, msgLeafIndex);
|
|
189
209
|
memory.set(existsOffset, exists ? new Uint1(1) : new Uint1(0));
|
|
190
210
|
}
|
|
191
211
|
}
|
|
@@ -197,7 +217,11 @@ export class EmitUnencryptedLog extends Instruction {
|
|
|
197
217
|
// Informs (de)serialization. See Instruction.deserialize.
|
|
198
218
|
static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16, OperandType.UINT16];
|
|
199
219
|
|
|
200
|
-
constructor(
|
|
220
|
+
constructor(
|
|
221
|
+
private indirect: number,
|
|
222
|
+
private logOffset: number,
|
|
223
|
+
private logSizeOffset: number,
|
|
224
|
+
) {
|
|
201
225
|
super();
|
|
202
226
|
}
|
|
203
227
|
|
|
@@ -207,9 +231,13 @@ export class EmitUnencryptedLog extends Instruction {
|
|
|
207
231
|
}
|
|
208
232
|
|
|
209
233
|
const memory = context.machineState.memory;
|
|
234
|
+
const addressing = Addressing.fromWire(this.indirect);
|
|
235
|
+
|
|
236
|
+
context.machineState.consumeGas(
|
|
237
|
+
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
238
|
+
);
|
|
210
239
|
|
|
211
240
|
const operands = [this.logOffset, this.logSizeOffset];
|
|
212
|
-
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
213
241
|
const [logOffset, logSizeOffset] = addressing.resolve(operands, memory);
|
|
214
242
|
memory.checkTag(TypeTag.UINT32, logSizeOffset);
|
|
215
243
|
const logSize = memory.get(logSizeOffset).toNumber();
|
|
@@ -217,7 +245,7 @@ export class EmitUnencryptedLog extends Instruction {
|
|
|
217
245
|
|
|
218
246
|
const contractAddress = context.environment.address;
|
|
219
247
|
|
|
220
|
-
context.machineState.consumeGas(this.
|
|
248
|
+
context.machineState.consumeGas(this.dynamicGasCost(logSize));
|
|
221
249
|
const log = memory.getSlice(logOffset, logSize).map(f => f.toFr());
|
|
222
250
|
context.persistableState.writePublicLog(contractAddress, log);
|
|
223
251
|
}
|
|
@@ -229,7 +257,11 @@ export class SendL2ToL1Message extends Instruction {
|
|
|
229
257
|
// Informs (de)serialization. See Instruction.deserialize.
|
|
230
258
|
static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16, OperandType.UINT16];
|
|
231
259
|
|
|
232
|
-
constructor(
|
|
260
|
+
constructor(
|
|
261
|
+
private indirect: number,
|
|
262
|
+
private recipientOffset: number,
|
|
263
|
+
private contentOffset: number,
|
|
264
|
+
) {
|
|
233
265
|
super();
|
|
234
266
|
}
|
|
235
267
|
|
|
@@ -239,10 +271,13 @@ export class SendL2ToL1Message extends Instruction {
|
|
|
239
271
|
}
|
|
240
272
|
|
|
241
273
|
const memory = context.machineState.memory;
|
|
242
|
-
|
|
274
|
+
const addressing = Addressing.fromWire(this.indirect);
|
|
275
|
+
|
|
276
|
+
context.machineState.consumeGas(
|
|
277
|
+
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
278
|
+
);
|
|
243
279
|
|
|
244
280
|
const operands = [this.recipientOffset, this.contentOffset];
|
|
245
|
-
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
246
281
|
const [recipientOffset, contentOffset] = addressing.resolve(operands, memory);
|
|
247
282
|
memory.checkTags(TypeTag.FIELD, recipientOffset, contentOffset);
|
|
248
283
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AVM_MAX_OPERANDS } from '@aztec/constants';
|
|
2
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
3
|
+
import type { Tuple } from '@aztec/foundation/serialize';
|
|
2
4
|
|
|
3
|
-
import { TaggedMemory, type TaggedMemoryInterface } from '../avm_memory_types.js';
|
|
4
|
-
import { RelativeAddressOutOfRangeError } from '../errors.js';
|
|
5
|
+
import { MemoryValue, TaggedMemory, type TaggedMemoryInterface, TypeTag } from '../avm_memory_types.js';
|
|
6
|
+
import { RelativeAddressOutOfRangeError, TagCheckError } from '../errors.js';
|
|
5
7
|
|
|
6
8
|
export enum AddressingMode {
|
|
7
9
|
DIRECT = 0,
|
|
@@ -13,21 +15,28 @@ export enum AddressingMode {
|
|
|
13
15
|
/** A class to represent the addressing mode of an instruction. */
|
|
14
16
|
export class Addressing {
|
|
15
17
|
public constructor(
|
|
16
|
-
/** The addressing mode for each operand.
|
|
17
|
-
private readonly modePerOperand: AddressingMode
|
|
18
|
+
/** The addressing mode for each possible operand. */
|
|
19
|
+
private readonly modePerOperand: Tuple<AddressingMode, typeof AVM_MAX_OPERANDS>,
|
|
18
20
|
) {}
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
public static fromModes(modes: AddressingMode[]): Addressing {
|
|
23
|
+
if (modes.length > AVM_MAX_OPERANDS) {
|
|
24
|
+
throw new Error('Too many operands for addressing mode');
|
|
25
|
+
}
|
|
26
|
+
return new Addressing(padArrayEnd(modes, AddressingMode.DIRECT, AVM_MAX_OPERANDS));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public static fromWire(wireModes: number): Addressing {
|
|
30
|
+
// The modes are stored in the wire format as one or two bytes, with each two bits representing the modes for an operand.
|
|
31
|
+
// Even bits are indirect, odd bits are relative.
|
|
32
|
+
const modes = new Array<AddressingMode>(AVM_MAX_OPERANDS);
|
|
33
|
+
for (let i = 0; i < AVM_MAX_OPERANDS; i++) {
|
|
26
34
|
modes[i] =
|
|
27
|
-
(((wireModes >> i) & 1) * AddressingMode.INDIRECT) |
|
|
28
|
-
(((wireModes >> (i +
|
|
35
|
+
(((wireModes >> (i * 2)) & 1) * AddressingMode.INDIRECT) |
|
|
36
|
+
(((wireModes >> (i * 2 + 1)) & 1) * AddressingMode.RELATIVE);
|
|
29
37
|
}
|
|
30
|
-
|
|
38
|
+
// Casting the array to tuple since it should be more performant than using makeTuple
|
|
39
|
+
return new Addressing(modes as Tuple<AddressingMode, typeof AVM_MAX_OPERANDS>);
|
|
31
40
|
}
|
|
32
41
|
|
|
33
42
|
public toWire(): number {
|
|
@@ -36,50 +45,65 @@ export class Addressing {
|
|
|
36
45
|
let wire: number = 0;
|
|
37
46
|
for (let i = 0; i < this.modePerOperand.length; i++) {
|
|
38
47
|
if (this.modePerOperand[i] & AddressingMode.INDIRECT) {
|
|
39
|
-
wire |= 1 << i;
|
|
48
|
+
wire |= 1 << (i * 2);
|
|
40
49
|
}
|
|
41
50
|
if (this.modePerOperand[i] & AddressingMode.RELATIVE) {
|
|
42
|
-
wire |= 1 << (
|
|
51
|
+
wire |= 1 << (i * 2 + 1);
|
|
43
52
|
}
|
|
44
53
|
}
|
|
45
54
|
return wire;
|
|
46
55
|
}
|
|
47
56
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
public indirectOperandsCount(): number {
|
|
58
|
+
return this.modePerOperand.filter(mode => mode & AddressingMode.INDIRECT).length;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public relativeOperandsCount(): number {
|
|
62
|
+
return this.modePerOperand.filter(mode => mode & AddressingMode.RELATIVE).length;
|
|
51
63
|
}
|
|
52
64
|
|
|
53
65
|
/**
|
|
54
66
|
* Resolves the offsets using the addressing mode.
|
|
55
67
|
* @param offsets The offsets to resolve.
|
|
56
68
|
* @param mem The memory to use for resolution.
|
|
57
|
-
* @returns The resolved offsets. The length of the returned array is the same as the length of the input array.
|
|
69
|
+
* @returns The resolved offsets. The length of the returned array is the same as the length of the input array and the resolved offsets are guaranteed to be valid addresses.
|
|
70
|
+
* @throws An error if any step failed. Should be treated as a black box.
|
|
58
71
|
*/
|
|
59
72
|
public resolve(offsets: number[], mem: TaggedMemoryInterface): number[] {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
let didRelativeOnce = false;
|
|
64
|
-
let baseAddr = 0;
|
|
73
|
+
const resolved: number[] = new Array(offsets.length);
|
|
74
|
+
// These will be read (once) if we have any relative operands.
|
|
75
|
+
let baseAddr: MemoryValue | undefined;
|
|
65
76
|
|
|
66
77
|
for (const [i, offset] of offsets.entries()) {
|
|
67
78
|
const mode = this.modePerOperand[i];
|
|
79
|
+
// The given offsets are assumed to be valid addresses.
|
|
68
80
|
resolved[i] = offset;
|
|
69
81
|
if (mode & AddressingMode.RELATIVE) {
|
|
70
|
-
if (!
|
|
71
|
-
mem.
|
|
72
|
-
|
|
73
|
-
|
|
82
|
+
if (!baseAddr) {
|
|
83
|
+
baseAddr = mem.get(0);
|
|
84
|
+
const baseAddrTag = baseAddr.getTag();
|
|
85
|
+
if (!TaggedMemory.isValidMemoryAddressTag(baseAddrTag!)) {
|
|
86
|
+
throw TagCheckError.forOffset(0, TypeTag[baseAddrTag!], TypeTag[TypeTag.UINT32]);
|
|
87
|
+
}
|
|
74
88
|
}
|
|
75
|
-
resolved[i]
|
|
89
|
+
// Here we know that resolved[i] is at most 32 bits and baseAddr is at most 32 bits.
|
|
90
|
+
// Therefore, the addition is safe since the `number` type fits more than 33 bits.
|
|
91
|
+
resolved[i] += Number(baseAddr.toBigInt());
|
|
76
92
|
if (resolved[i] >= TaggedMemory.MAX_MEMORY_SIZE) {
|
|
77
|
-
throw new RelativeAddressOutOfRangeError(baseAddr, offset);
|
|
93
|
+
throw new RelativeAddressOutOfRangeError(Number(baseAddr.toBigInt()), offset);
|
|
78
94
|
}
|
|
79
95
|
}
|
|
80
96
|
if (mode & AddressingMode.INDIRECT) {
|
|
81
|
-
|
|
82
|
-
|
|
97
|
+
// At this point we know that resolved[i] is a valid memory address.
|
|
98
|
+
const resolvedValue = mem.get(resolved[i]);
|
|
99
|
+
const resolvedTag = resolvedValue.getTag();
|
|
100
|
+
|
|
101
|
+
// Final check.
|
|
102
|
+
if (!TaggedMemory.isValidMemoryAddressTag(resolvedTag)) {
|
|
103
|
+
throw TagCheckError.forOffset(resolved[i], TypeTag[resolvedTag], TypeTag[TypeTag.UINT32]);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
resolved[i] = Number(resolvedValue.toBigInt());
|
|
83
107
|
}
|
|
84
108
|
}
|
|
85
109
|
return resolved;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AvmContext } from '../avm_context.js';
|
|
2
2
|
import {
|
|
3
3
|
type Field,
|
|
4
|
+
type IntegralValue,
|
|
4
5
|
type MemoryValue,
|
|
5
6
|
TaggedMemory,
|
|
6
7
|
type TaggedMemoryInterface,
|
|
@@ -14,10 +15,13 @@ import { ThreeOperandInstruction } from './instruction_impl.js';
|
|
|
14
15
|
export abstract class ThreeOperandArithmeticInstruction extends ThreeOperandInstruction {
|
|
15
16
|
public async execute(context: AvmContext): Promise<void> {
|
|
16
17
|
const memory = context.machineState.memory;
|
|
17
|
-
|
|
18
|
+
const addressing = Addressing.fromWire(this.indirect);
|
|
19
|
+
|
|
20
|
+
context.machineState.consumeGas(
|
|
21
|
+
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
22
|
+
);
|
|
18
23
|
|
|
19
24
|
const operands = [this.aOffset, this.bOffset, this.dstOffset];
|
|
20
|
-
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
21
25
|
const [aOffset, bOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
22
26
|
this.checkTags(memory, aOffset, bOffset);
|
|
23
27
|
|
|
@@ -93,3 +97,21 @@ export class FieldDiv extends ThreeOperandArithmeticInstruction {
|
|
|
93
97
|
memory.checkTag(TypeTag.FIELD, aOffset); // Follows that bOffset has also tag of type Field
|
|
94
98
|
}
|
|
95
99
|
}
|
|
100
|
+
|
|
101
|
+
export class Shl extends ThreeOperandArithmeticInstruction {
|
|
102
|
+
static readonly type: string = 'SHL';
|
|
103
|
+
static readonly opcode = Opcode.SHL_8; // FIXME: needed for gas.
|
|
104
|
+
|
|
105
|
+
protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
|
|
106
|
+
return a.shl(b);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export class Shr extends ThreeOperandArithmeticInstruction {
|
|
111
|
+
static readonly type: string = 'SHR';
|
|
112
|
+
static readonly opcode = Opcode.SHR_8; // FIXME: needed for gas.
|
|
113
|
+
|
|
114
|
+
protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
|
|
115
|
+
return a.shr(b);
|
|
116
|
+
}
|
|
117
|
+
}
|