@aztec/simulator 0.0.0-test.0
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 +49 -0
- package/dest/client.d.ts +5 -0
- package/dest/client.d.ts.map +1 -0
- package/dest/client.js +3 -0
- package/dest/common/db_interfaces.d.ts +80 -0
- package/dest/common/db_interfaces.d.ts.map +1 -0
- package/dest/common/db_interfaces.js +1 -0
- package/dest/common/debug_fn_name.d.ts +5 -0
- package/dest/common/debug_fn_name.d.ts.map +1 -0
- package/dest/common/debug_fn_name.js +6 -0
- package/dest/common/errors.d.ts +54 -0
- package/dest/common/errors.d.ts.map +1 -0
- package/dest/common/errors.js +135 -0
- package/dest/common/index.d.ts +4 -0
- package/dest/common/index.d.ts.map +1 -0
- package/dest/common/index.js +3 -0
- package/dest/common/message_load_oracle_inputs.d.ts +15 -0
- package/dest/common/message_load_oracle_inputs.d.ts.map +1 -0
- package/dest/common/message_load_oracle_inputs.js +15 -0
- package/dest/common/stats/index.d.ts +2 -0
- package/dest/common/stats/index.d.ts.map +1 -0
- package/dest/common/stats/index.js +1 -0
- package/dest/common/stats/stats.d.ts +4 -0
- package/dest/common/stats/stats.d.ts.map +1 -0
- package/dest/common/stats/stats.js +10 -0
- package/dest/private/acvm/acvm.d.ts +35 -0
- package/dest/private/acvm/acvm.d.ts.map +1 -0
- package/dest/private/acvm/acvm.js +70 -0
- package/dest/private/acvm/acvm_types.d.ts +10 -0
- package/dest/private/acvm/acvm_types.d.ts.map +1 -0
- package/dest/private/acvm/acvm_types.js +3 -0
- package/dest/private/acvm/deserialize.d.ts +36 -0
- package/dest/private/acvm/deserialize.d.ts.map +1 -0
- package/dest/private/acvm/deserialize.js +42 -0
- package/dest/private/acvm/index.d.ts +6 -0
- package/dest/private/acvm/index.d.ts.map +1 -0
- package/dest/private/acvm/index.js +5 -0
- package/dest/private/acvm/oracle/index.d.ts +14 -0
- package/dest/private/acvm/oracle/index.d.ts.map +1 -0
- package/dest/private/acvm/oracle/index.js +2 -0
- package/dest/private/acvm/oracle/oracle.d.ts +49 -0
- package/dest/private/acvm/oracle/oracle.d.ts.map +1 -0
- package/dest/private/acvm/oracle/oracle.js +263 -0
- package/dest/private/acvm/oracle/typed_oracle.d.ts +83 -0
- package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -0
- package/dest/private/acvm/oracle/typed_oracle.js +132 -0
- package/dest/private/acvm/serialize.d.ts +24 -0
- package/dest/private/acvm/serialize.d.ts.map +1 -0
- package/dest/private/acvm/serialize.js +46 -0
- package/dest/private/execution_data_provider.d.ts +261 -0
- package/dest/private/execution_data_provider.d.ts.map +1 -0
- package/dest/private/execution_data_provider.js +14 -0
- package/dest/private/execution_note_cache.d.ts +93 -0
- package/dest/private/execution_note_cache.d.ts.map +1 -0
- package/dest/private/execution_note_cache.js +180 -0
- package/dest/private/hashed_values_cache.d.ts +28 -0
- package/dest/private/hashed_values_cache.d.ts.map +1 -0
- package/dest/private/hashed_values_cache.js +46 -0
- package/dest/private/index.d.ts +13 -0
- package/dest/private/index.d.ts.map +1 -0
- package/dest/private/index.js +12 -0
- package/dest/private/pick_notes.d.ts +85 -0
- package/dest/private/pick_notes.d.ts.map +1 -0
- package/dest/private/pick_notes.js +51 -0
- package/dest/private/private_execution.d.ts +25 -0
- package/dest/private/private_execution.d.ts.map +1 -0
- package/dest/private/private_execution.js +92 -0
- package/dest/private/private_execution_oracle.d.ts +215 -0
- package/dest/private/private_execution_oracle.d.ts.map +1 -0
- package/dest/private/private_execution_oracle.js +382 -0
- package/dest/private/providers/acvm_native.d.ts +40 -0
- package/dest/private/providers/acvm_native.d.ts.map +1 -0
- package/dest/private/providers/acvm_native.js +139 -0
- package/dest/private/providers/acvm_wasm.d.ts +15 -0
- package/dest/private/providers/acvm_wasm.d.ts.map +1 -0
- package/dest/private/providers/acvm_wasm.js +62 -0
- package/dest/private/providers/acvm_wasm_with_blobs.d.ts +19 -0
- package/dest/private/providers/acvm_wasm_with_blobs.d.ts.map +1 -0
- package/dest/private/providers/acvm_wasm_with_blobs.js +32 -0
- package/dest/private/providers/factory.d.ts +12 -0
- package/dest/private/providers/factory.d.ts.map +1 -0
- package/dest/private/providers/factory.js +27 -0
- package/dest/private/providers/simulation_provider.d.ts +19 -0
- package/dest/private/providers/simulation_provider.d.ts.map +1 -0
- package/dest/private/providers/simulation_provider.js +24 -0
- package/dest/private/simulator.d.ts +34 -0
- package/dest/private/simulator.d.ts.map +1 -0
- package/dest/private/simulator.js +76 -0
- package/dest/private/unconstrained_execution.d.ts +10 -0
- package/dest/private/unconstrained_execution.d.ts.map +1 -0
- package/dest/private/unconstrained_execution.js +27 -0
- package/dest/private/unconstrained_execution_oracle.d.ts +161 -0
- package/dest/private/unconstrained_execution_oracle.d.ts.map +1 -0
- package/dest/private/unconstrained_execution_oracle.js +258 -0
- package/dest/public/avm/avm_context.d.ts +41 -0
- package/dest/public/avm/avm_context.d.ts.map +1 -0
- package/dest/public/avm/avm_context.js +44 -0
- package/dest/public/avm/avm_contract_call_result.d.ts +30 -0
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -0
- package/dest/public/avm/avm_contract_call_result.js +50 -0
- package/dest/public/avm/avm_execution_environment.d.ts +21 -0
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -0
- package/dest/public/avm/avm_execution_environment.js +31 -0
- package/dest/public/avm/avm_gas.d.ts +60 -0
- package/dest/public/avm/avm_gas.d.ts.map +1 -0
- package/dest/public/avm/avm_gas.js +203 -0
- package/dest/public/avm/avm_machine_state.d.ts +95 -0
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -0
- package/dest/public/avm/avm_machine_state.js +107 -0
- package/dest/public/avm/avm_memory_types.d.ts +264 -0
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -0
- package/dest/public/avm/avm_memory_types.js +340 -0
- package/dest/public/avm/avm_simulator.d.ts +40 -0
- package/dest/public/avm/avm_simulator.d.ts.map +1 -0
- package/dest/public/avm/avm_simulator.js +202 -0
- package/dest/public/avm/bytecode_utils.d.ts +5 -0
- package/dest/public/avm/bytecode_utils.d.ts.map +1 -0
- package/dest/public/avm/bytecode_utils.js +17 -0
- package/dest/public/avm/errors.d.ts +122 -0
- package/dest/public/avm/errors.d.ts.map +1 -0
- package/dest/public/avm/errors.js +179 -0
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +21 -0
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -0
- package/dest/public/avm/fixtures/avm_simulation_tester.js +76 -0
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +36 -0
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -0
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +83 -0
- package/dest/public/avm/fixtures/index.d.ts +84 -0
- package/dest/public/avm/fixtures/index.d.ts.map +1 -0
- package/dest/public/avm/fixtures/index.js +175 -0
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts +35 -0
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +1 -0
- package/dest/public/avm/fixtures/simple_contract_data_source.js +74 -0
- package/dest/public/avm/index.d.ts +4 -0
- package/dest/public/avm/index.d.ts.map +1 -0
- package/dest/public/avm/index.js +3 -0
- package/dest/public/avm/journal/index.d.ts +2 -0
- package/dest/public/avm/journal/index.d.ts.map +1 -0
- package/dest/public/avm/journal/index.js +1 -0
- package/dest/public/avm/journal/journal.d.ts +209 -0
- package/dest/public/avm/journal/journal.d.ts.map +1 -0
- package/dest/public/avm/journal/journal.js +486 -0
- package/dest/public/avm/journal/nullifiers.d.ts +64 -0
- package/dest/public/avm/journal/nullifiers.d.ts.map +1 -0
- package/dest/public/avm/journal/nullifiers.js +97 -0
- package/dest/public/avm/journal/public_storage.d.ts +66 -0
- package/dest/public/avm/journal/public_storage.d.ts.map +1 -0
- package/dest/public/avm/journal/public_storage.js +145 -0
- package/dest/public/avm/opcodes/accrued_substate.d.ts +75 -0
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -0
- package/dest/public/avm/opcodes/accrued_substate.js +252 -0
- package/dest/public/avm/opcodes/addressing_mode.d.ts +27 -0
- package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -0
- package/dest/public/avm/opcodes/addressing_mode.js +74 -0
- package/dest/public/avm/opcodes/arithmetic.d.ts +37 -0
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -0
- package/dest/public/avm/opcodes/arithmetic.js +73 -0
- package/dest/public/avm/opcodes/bitwise.d.ts +50 -0
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -0
- package/dest/public/avm/opcodes/bitwise.js +106 -0
- package/dest/public/avm/opcodes/comparators.d.ts +25 -0
- package/dest/public/avm/opcodes/comparators.d.ts.map +1 -0
- package/dest/public/avm/opcodes/comparators.js +43 -0
- package/dest/public/avm/opcodes/contract.d.ts +21 -0
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -0
- package/dest/public/avm/opcodes/contract.js +66 -0
- package/dest/public/avm/opcodes/control_flow.d.ts +41 -0
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -0
- package/dest/public/avm/opcodes/control_flow.js +105 -0
- package/dest/public/avm/opcodes/conversion.d.ts +17 -0
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -0
- package/dest/public/avm/opcodes/conversion.js +69 -0
- package/dest/public/avm/opcodes/ec_add.d.ts +19 -0
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -0
- package/dest/public/avm/opcodes/ec_add.js +84 -0
- package/dest/public/avm/opcodes/environment_getters.d.ts +28 -0
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -0
- package/dest/public/avm/opcodes/environment_getters.js +79 -0
- package/dest/public/avm/opcodes/external_calls.d.ts +58 -0
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -0
- package/dest/public/avm/opcodes/external_calls.js +204 -0
- package/dest/public/avm/opcodes/hashing.d.ts +36 -0
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -0
- package/dest/public/avm/opcodes/hashing.js +114 -0
- package/dest/public/avm/opcodes/index.d.ts +16 -0
- package/dest/public/avm/opcodes/index.d.ts.map +1 -0
- package/dest/public/avm/opcodes/index.js +15 -0
- package/dest/public/avm/opcodes/instruction.d.ts +70 -0
- package/dest/public/avm/opcodes/instruction.d.ts.map +1 -0
- package/dest/public/avm/opcodes/instruction.js +91 -0
- package/dest/public/avm/opcodes/instruction_impl.d.ts +19 -0
- package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -0
- package/dest/public/avm/opcodes/instruction_impl.js +30 -0
- package/dest/public/avm/opcodes/memory.d.ts +74 -0
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -0
- package/dest/public/avm/opcodes/memory.js +253 -0
- package/dest/public/avm/opcodes/misc.d.ts +17 -0
- package/dest/public/avm/opcodes/misc.d.ts.map +1 -0
- package/dest/public/avm/opcodes/misc.js +48 -0
- package/dest/public/avm/opcodes/storage.d.ts +24 -0
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -0
- package/dest/public/avm/opcodes/storage.js +66 -0
- package/dest/public/avm/serialization/buffer_cursor.d.ts +28 -0
- package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -0
- package/dest/public/avm/serialization/buffer_cursor.js +99 -0
- package/dest/public/avm/serialization/bytecode_serialization.d.ts +21 -0
- package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -0
- package/dest/public/avm/serialization/bytecode_serialization.js +332 -0
- package/dest/public/avm/serialization/instruction_serialization.d.ts +105 -0
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -0
- package/dest/public/avm/serialization/instruction_serialization.js +226 -0
- package/dest/public/avm/test_utils.d.ts +18 -0
- package/dest/public/avm/test_utils.d.ts.map +1 -0
- package/dest/public/avm/test_utils.js +52 -0
- package/dest/public/bytecode_errors.d.ts +4 -0
- package/dest/public/bytecode_errors.d.ts.map +1 -0
- package/dest/public/bytecode_errors.js +6 -0
- package/dest/public/execution.d.ts +108 -0
- package/dest/public/execution.d.ts.map +1 -0
- package/dest/public/execution.js +9 -0
- package/dest/public/executor_metrics.d.ts +13 -0
- package/dest/public/executor_metrics.d.ts.map +1 -0
- package/dest/public/executor_metrics.js +54 -0
- package/dest/public/fixtures/index.d.ts +3 -0
- package/dest/public/fixtures/index.d.ts.map +1 -0
- package/dest/public/fixtures/index.js +2 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +32 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -0
- package/dest/public/fixtures/public_tx_simulation_tester.js +93 -0
- package/dest/public/fixtures/utils.d.ts +13 -0
- package/dest/public/fixtures/utils.d.ts.map +1 -0
- package/dest/public/fixtures/utils.js +126 -0
- package/dest/public/index.d.ts +10 -0
- package/dest/public/index.d.ts.map +1 -0
- package/dest/public/index.js +8 -0
- package/dest/public/public_db_sources.d.ts +129 -0
- package/dest/public/public_db_sources.d.ts.map +1 -0
- package/dest/public/public_db_sources.js +264 -0
- package/dest/public/public_processor/public_processor.d.ts +74 -0
- package/dest/public/public_processor/public_processor.d.ts.map +1 -0
- package/dest/public/public_processor/public_processor.js +379 -0
- package/dest/public/public_processor/public_processor_metrics.d.ts +27 -0
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -0
- package/dest/public/public_processor/public_processor_metrics.js +125 -0
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +137 -0
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/public_tx_context.js +320 -0
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +102 -0
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/public_tx_simulator.js +334 -0
- package/dest/public/side_effect_errors.d.ts +4 -0
- package/dest/public/side_effect_errors.d.ts.map +1 -0
- package/dest/public/side_effect_errors.js +6 -0
- package/dest/public/side_effect_trace.d.ts +132 -0
- package/dest/public/side_effect_trace.d.ts.map +1 -0
- package/dest/public/side_effect_trace.js +249 -0
- package/dest/public/side_effect_trace_interface.d.ts +34 -0
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -0
- package/dest/public/side_effect_trace_interface.js +1 -0
- package/dest/public/tx_contract_cache.d.ts +41 -0
- package/dest/public/tx_contract_cache.d.ts.map +1 -0
- package/dest/public/tx_contract_cache.js +49 -0
- package/dest/public/unique_class_ids.d.ts +37 -0
- package/dest/public/unique_class_ids.d.ts.map +1 -0
- package/dest/public/unique_class_ids.js +61 -0
- package/dest/public/utils.d.ts +5 -0
- package/dest/public/utils.d.ts.map +1 -0
- package/dest/public/utils.js +35 -0
- package/dest/server.d.ts +6 -0
- package/dest/server.d.ts.map +1 -0
- package/dest/server.js +4 -0
- package/dest/test/utils.d.ts +13 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +22 -0
- package/package.json +104 -0
- package/src/client.ts +4 -0
- package/src/common/db_interfaces.ts +94 -0
- package/src/common/debug_fn_name.ts +18 -0
- package/src/common/errors.ts +183 -0
- package/src/common/index.ts +3 -0
- package/src/common/message_load_oracle_inputs.ts +15 -0
- package/src/common/stats/index.ts +1 -0
- package/src/common/stats/stats.ts +20 -0
- package/src/private/acvm/acvm.ts +127 -0
- package/src/private/acvm/acvm_types.ts +11 -0
- package/src/private/acvm/deserialize.ts +52 -0
- package/src/private/acvm/index.ts +5 -0
- package/src/private/acvm/oracle/index.ts +16 -0
- package/src/private/acvm/oracle/oracle.ts +455 -0
- package/src/private/acvm/oracle/typed_oracle.ts +259 -0
- package/src/private/acvm/serialize.ts +60 -0
- package/src/private/execution_data_provider.ts +323 -0
- package/src/private/execution_note_cache.ts +217 -0
- package/src/private/hashed_values_cache.ts +55 -0
- package/src/private/index.ts +16 -0
- package/src/private/pick_notes.ts +141 -0
- package/src/private/private_execution.ts +151 -0
- package/src/private/private_execution_oracle.ts +614 -0
- package/src/private/providers/acvm_native.ts +171 -0
- package/src/private/providers/acvm_wasm.ts +63 -0
- package/src/private/providers/acvm_wasm_with_blobs.ts +50 -0
- package/src/private/providers/factory.ts +38 -0
- package/src/private/providers/simulation_provider.ts +45 -0
- package/src/private/simulator.ts +147 -0
- package/src/private/unconstrained_execution.ts +50 -0
- package/src/private/unconstrained_execution_oracle.ts +373 -0
- package/src/public/avm/avm_context.ts +61 -0
- package/src/public/avm/avm_contract_call_result.ts +55 -0
- package/src/public/avm/avm_execution_environment.ts +39 -0
- package/src/public/avm/avm_gas.ts +195 -0
- package/src/public/avm/avm_machine_state.ts +164 -0
- package/src/public/avm/avm_memory_types.ts +423 -0
- package/src/public/avm/avm_simulator.ts +284 -0
- package/src/public/avm/bytecode_utils.ts +17 -0
- package/src/public/avm/errors.ts +232 -0
- package/src/public/avm/fixtures/avm_simulation_tester.ts +105 -0
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +109 -0
- package/src/public/avm/fixtures/index.ts +296 -0
- package/src/public/avm/fixtures/simple_contract_data_source.ts +105 -0
- package/src/public/avm/index.ts +3 -0
- package/src/public/avm/journal/index.ts +1 -0
- package/src/public/avm/journal/journal.ts +742 -0
- package/src/public/avm/journal/nullifiers.ts +109 -0
- package/src/public/avm/journal/public_storage.ts +174 -0
- package/src/public/avm/opcodes/.eslintrc.cjs +8 -0
- package/src/public/avm/opcodes/accrued_substate.ts +253 -0
- package/src/public/avm/opcodes/addressing_mode.ts +87 -0
- package/src/public/avm/opcodes/arithmetic.ts +95 -0
- package/src/public/avm/opcodes/bitwise.ts +109 -0
- package/src/public/avm/opcodes/comparators.ts +52 -0
- package/src/public/avm/opcodes/contract.ts +72 -0
- package/src/public/avm/opcodes/control_flow.ts +114 -0
- package/src/public/avm/opcodes/conversion.ts +80 -0
- package/src/public/avm/opcodes/ec_add.ts +93 -0
- package/src/public/avm/opcodes/environment_getters.ts +82 -0
- package/src/public/avm/opcodes/external_calls.ts +228 -0
- package/src/public/avm/opcodes/hashing.ts +125 -0
- package/src/public/avm/opcodes/index.ts +15 -0
- package/src/public/avm/opcodes/instruction.ts +126 -0
- package/src/public/avm/opcodes/instruction_impl.ts +36 -0
- package/src/public/avm/opcodes/memory.ts +254 -0
- package/src/public/avm/opcodes/misc.ts +60 -0
- package/src/public/avm/opcodes/storage.ts +71 -0
- package/src/public/avm/serialization/buffer_cursor.ts +115 -0
- package/src/public/avm/serialization/bytecode_serialization.ts +206 -0
- package/src/public/avm/serialization/instruction_serialization.ts +208 -0
- package/src/public/avm/test_utils.ts +81 -0
- package/src/public/bytecode_errors.ts +6 -0
- package/src/public/execution.ts +140 -0
- package/src/public/executor_metrics.ts +71 -0
- package/src/public/fixtures/index.ts +2 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +179 -0
- package/src/public/fixtures/utils.ts +199 -0
- package/src/public/index.ts +9 -0
- package/src/public/public_db_sources.ts +369 -0
- package/src/public/public_processor/public_processor.ts +521 -0
- package/src/public/public_processor/public_processor_metrics.ts +154 -0
- package/src/public/public_tx_simulator/public_tx_context.ts +504 -0
- package/src/public/public_tx_simulator/public_tx_simulator.ts +474 -0
- package/src/public/side_effect_errors.ts +6 -0
- package/src/public/side_effect_trace.ts +516 -0
- package/src/public/side_effect_trace_interface.ts +76 -0
- package/src/public/tx_contract_cache.ts +69 -0
- package/src/public/unique_class_ids.ts +80 -0
- package/src/public/utils.ts +32 -0
- package/src/server.ts +5 -0
- package/src/test/utils.ts +36 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { AvmContext } from '../avm_context.js';
|
|
2
|
+
import {
|
|
3
|
+
type Field,
|
|
4
|
+
type MemoryValue,
|
|
5
|
+
TaggedMemory,
|
|
6
|
+
type TaggedMemoryInterface,
|
|
7
|
+
TypeTag,
|
|
8
|
+
} from '../avm_memory_types.js';
|
|
9
|
+
import { ArithmeticError } from '../errors.js';
|
|
10
|
+
import { Opcode } from '../serialization/instruction_serialization.js';
|
|
11
|
+
import { Addressing } from './addressing_mode.js';
|
|
12
|
+
import { ThreeOperandInstruction } from './instruction_impl.js';
|
|
13
|
+
|
|
14
|
+
export abstract class ThreeOperandArithmeticInstruction extends ThreeOperandInstruction {
|
|
15
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
16
|
+
const memory = context.machineState.memory;
|
|
17
|
+
context.machineState.consumeGas(this.gasCost());
|
|
18
|
+
|
|
19
|
+
const operands = [this.aOffset, this.bOffset, this.dstOffset];
|
|
20
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
21
|
+
const [aOffset, bOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
22
|
+
this.checkTags(memory, aOffset, bOffset);
|
|
23
|
+
|
|
24
|
+
const a = memory.get(aOffset);
|
|
25
|
+
const b = memory.get(bOffset);
|
|
26
|
+
|
|
27
|
+
const dest = this.compute(a, b);
|
|
28
|
+
memory.set(dstOffset, dest);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected abstract compute(a: MemoryValue, b: MemoryValue): MemoryValue;
|
|
32
|
+
protected checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
|
|
33
|
+
memory.checkTagsAreSame(aOffset, bOffset);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class Add extends ThreeOperandArithmeticInstruction {
|
|
38
|
+
static readonly type: string = 'ADD';
|
|
39
|
+
static readonly opcode = Opcode.ADD_8; // FIXME: needed for gas.
|
|
40
|
+
|
|
41
|
+
protected compute(a: MemoryValue, b: MemoryValue): MemoryValue {
|
|
42
|
+
return a.add(b);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class Sub extends ThreeOperandArithmeticInstruction {
|
|
47
|
+
static readonly type: string = 'SUB';
|
|
48
|
+
static readonly opcode = Opcode.SUB_8; // FIXME: needed for gas.
|
|
49
|
+
|
|
50
|
+
protected compute(a: MemoryValue, b: MemoryValue): MemoryValue {
|
|
51
|
+
return a.sub(b);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export class Mul extends ThreeOperandArithmeticInstruction {
|
|
56
|
+
static type: string = 'MUL';
|
|
57
|
+
static readonly opcode = Opcode.MUL_8; // FIXME: needed for gas.
|
|
58
|
+
|
|
59
|
+
protected compute(a: MemoryValue, b: MemoryValue): MemoryValue {
|
|
60
|
+
return a.mul(b);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export class Div extends ThreeOperandArithmeticInstruction {
|
|
65
|
+
static type: string = 'DIV';
|
|
66
|
+
static readonly opcode = Opcode.DIV_8; // FIXME: needed for gas.
|
|
67
|
+
|
|
68
|
+
protected compute(a: MemoryValue, b: MemoryValue): MemoryValue {
|
|
69
|
+
if (b.toBigInt() === 0n) {
|
|
70
|
+
throw new ArithmeticError('Division by zero');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return a.div(b);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
protected override checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
|
|
77
|
+
memory.checkTagsAreSame(aOffset, bOffset);
|
|
78
|
+
TaggedMemory.checkIsIntegralTag(memory.getTag(aOffset)); // Follows that bOffset tag is also of integral type
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export class FieldDiv extends ThreeOperandArithmeticInstruction {
|
|
83
|
+
static type: string = 'FDIV';
|
|
84
|
+
static readonly opcode = Opcode.FDIV_8; // FIXME: needed for gas.
|
|
85
|
+
|
|
86
|
+
protected compute(a: Field, b: Field): Field {
|
|
87
|
+
// return (a as Field).fdiv(b as Field);
|
|
88
|
+
return a.fdiv(b);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
protected override checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
|
|
92
|
+
memory.checkTagsAreSame(aOffset, bOffset);
|
|
93
|
+
memory.checkTag(TypeTag.FIELD, aOffset); // Follows that bOffset has also tag of type Field
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { AvmContext } from '../avm_context.js';
|
|
2
|
+
import { type IntegralValue, TaggedMemory, type TaggedMemoryInterface, TypeTag } from '../avm_memory_types.js';
|
|
3
|
+
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
4
|
+
import { Addressing } from './addressing_mode.js';
|
|
5
|
+
import { Instruction } from './instruction.js';
|
|
6
|
+
import { ThreeOperandInstruction } from './instruction_impl.js';
|
|
7
|
+
|
|
8
|
+
abstract class ThreeOperandBitwiseInstruction extends ThreeOperandInstruction {
|
|
9
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
10
|
+
const memory = context.machineState.memory;
|
|
11
|
+
context.machineState.consumeGas(this.gasCost());
|
|
12
|
+
|
|
13
|
+
const operands = [this.aOffset, this.bOffset, this.dstOffset];
|
|
14
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
15
|
+
const [aOffset, bOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
16
|
+
this.checkTags(memory, aOffset, bOffset);
|
|
17
|
+
|
|
18
|
+
const a = memory.getAs<IntegralValue>(aOffset);
|
|
19
|
+
const b = memory.getAs<IntegralValue>(bOffset);
|
|
20
|
+
|
|
21
|
+
const res = this.compute(a, b);
|
|
22
|
+
memory.set(dstOffset, res);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected abstract compute(a: IntegralValue, b: IntegralValue): IntegralValue;
|
|
26
|
+
protected checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
|
|
27
|
+
TaggedMemory.checkIsIntegralTag(memory.getTag(aOffset));
|
|
28
|
+
memory.checkTagsAreSame(aOffset, bOffset);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class And extends ThreeOperandBitwiseInstruction {
|
|
33
|
+
static readonly type: string = 'AND';
|
|
34
|
+
static readonly opcode = Opcode.AND_8; // FIXME: needed for gas.
|
|
35
|
+
|
|
36
|
+
protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
|
|
37
|
+
return a.and(b);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class Or extends ThreeOperandBitwiseInstruction {
|
|
42
|
+
static readonly type: string = 'OR';
|
|
43
|
+
static readonly opcode = Opcode.OR_8; // FIXME: needed for gas.
|
|
44
|
+
|
|
45
|
+
protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
|
|
46
|
+
return a.or(b);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export class Xor extends ThreeOperandBitwiseInstruction {
|
|
51
|
+
static readonly type: string = 'XOR';
|
|
52
|
+
static readonly opcode = Opcode.XOR_8; // FIXME: needed for gas.
|
|
53
|
+
|
|
54
|
+
protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
|
|
55
|
+
return a.xor(b);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export class Shl extends ThreeOperandBitwiseInstruction {
|
|
60
|
+
static readonly type: string = 'SHL';
|
|
61
|
+
static readonly opcode = Opcode.SHL_8; // FIXME: needed for gas.
|
|
62
|
+
|
|
63
|
+
protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
|
|
64
|
+
return a.shl(b);
|
|
65
|
+
}
|
|
66
|
+
protected override checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
|
|
67
|
+
TaggedMemory.checkIsIntegralTag(memory.getTag(aOffset));
|
|
68
|
+
memory.checkTag(TypeTag.UINT8, bOffset);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export class Shr extends ThreeOperandBitwiseInstruction {
|
|
73
|
+
static readonly type: string = 'SHR';
|
|
74
|
+
static readonly opcode = Opcode.SHR_8; // FIXME: needed for gas.
|
|
75
|
+
|
|
76
|
+
protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
|
|
77
|
+
return a.shr(b);
|
|
78
|
+
}
|
|
79
|
+
protected override checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
|
|
80
|
+
TaggedMemory.checkIsIntegralTag(memory.getTag(aOffset));
|
|
81
|
+
memory.checkTag(TypeTag.UINT8, bOffset);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export class Not extends Instruction {
|
|
86
|
+
static readonly type: string = 'NOT';
|
|
87
|
+
static readonly opcode = Opcode.NOT_8;
|
|
88
|
+
|
|
89
|
+
static readonly wireFormat8 = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT8, OperandType.UINT8];
|
|
90
|
+
static readonly wireFormat16 = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16, OperandType.UINT16];
|
|
91
|
+
|
|
92
|
+
constructor(private indirect: number, private srcOffset: number, private dstOffset: number) {
|
|
93
|
+
super();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
97
|
+
const memory = context.machineState.memory;
|
|
98
|
+
context.machineState.consumeGas(this.gasCost());
|
|
99
|
+
|
|
100
|
+
const operands = [this.srcOffset, this.dstOffset];
|
|
101
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
102
|
+
const [srcOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
103
|
+
TaggedMemory.checkIsIntegralTag(memory.getTag(srcOffset));
|
|
104
|
+
const value = memory.getAs<IntegralValue>(srcOffset);
|
|
105
|
+
|
|
106
|
+
const res = value.not();
|
|
107
|
+
memory.set(dstOffset, res);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { AvmContext } from '../avm_context.js';
|
|
2
|
+
import { type MemoryValue, Uint1 } from '../avm_memory_types.js';
|
|
3
|
+
import { Opcode } from '../serialization/instruction_serialization.js';
|
|
4
|
+
import { Addressing } from './addressing_mode.js';
|
|
5
|
+
import { ThreeOperandInstruction } from './instruction_impl.js';
|
|
6
|
+
|
|
7
|
+
abstract class ComparatorInstruction extends ThreeOperandInstruction {
|
|
8
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
9
|
+
const memory = context.machineState.memory;
|
|
10
|
+
context.machineState.consumeGas(this.gasCost());
|
|
11
|
+
|
|
12
|
+
const operands = [this.aOffset, this.bOffset, this.dstOffset];
|
|
13
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
14
|
+
const [aOffset, bOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
15
|
+
memory.checkTagsAreSame(aOffset, bOffset);
|
|
16
|
+
|
|
17
|
+
const a = memory.get(aOffset);
|
|
18
|
+
const b = memory.get(bOffset);
|
|
19
|
+
|
|
20
|
+
const dest = new Uint1(this.compare(a, b) ? 1 : 0);
|
|
21
|
+
memory.set(dstOffset, dest);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
protected abstract compare(a: MemoryValue, b: MemoryValue): boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class Eq extends ComparatorInstruction {
|
|
28
|
+
static readonly type: string = 'EQ';
|
|
29
|
+
static readonly opcode = Opcode.EQ_8; // FIXME: needed for gas.
|
|
30
|
+
|
|
31
|
+
protected compare(a: MemoryValue, b: MemoryValue): boolean {
|
|
32
|
+
return a.equals(b);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class Lt extends ComparatorInstruction {
|
|
37
|
+
static readonly type: string = 'LT';
|
|
38
|
+
static readonly opcode = Opcode.LT_8; // FIXME: needed for gas.
|
|
39
|
+
|
|
40
|
+
protected compare(a: MemoryValue, b: MemoryValue): boolean {
|
|
41
|
+
return a.lt(b);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export class Lte extends ComparatorInstruction {
|
|
46
|
+
static readonly type: string = 'LTE';
|
|
47
|
+
static readonly opcode = Opcode.LTE_8; // FIXME: needed for gas.
|
|
48
|
+
|
|
49
|
+
protected compare(a: MemoryValue, b: MemoryValue): boolean {
|
|
50
|
+
return a.lt(b) || a.equals(b);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { AvmContext } from '../avm_context.js';
|
|
2
|
+
import { Field, TypeTag, Uint1 } from '../avm_memory_types.js';
|
|
3
|
+
import { InstructionExecutionError } from '../errors.js';
|
|
4
|
+
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
5
|
+
import { Addressing } from './addressing_mode.js';
|
|
6
|
+
import { Instruction } from './instruction.js';
|
|
7
|
+
|
|
8
|
+
export enum ContractInstanceMember {
|
|
9
|
+
DEPLOYER,
|
|
10
|
+
CLASS_ID,
|
|
11
|
+
INIT_HASH,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class GetContractInstance extends Instruction {
|
|
15
|
+
static readonly type: string = 'GETCONTRACTINSTANCE';
|
|
16
|
+
static readonly opcode: Opcode = Opcode.GETCONTRACTINSTANCE;
|
|
17
|
+
// Informs (de)serialization. See Instruction.deserialize.
|
|
18
|
+
static readonly wireFormat: OperandType[] = [
|
|
19
|
+
OperandType.UINT8, // opcode
|
|
20
|
+
OperandType.UINT8, // indirect bits
|
|
21
|
+
OperandType.UINT16, // addressOffset
|
|
22
|
+
OperandType.UINT16, // dstOffset
|
|
23
|
+
OperandType.UINT16, // existsOfsset
|
|
24
|
+
OperandType.UINT8, // member enum (immediate)
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
private indirect: number,
|
|
29
|
+
private addressOffset: number,
|
|
30
|
+
private dstOffset: number,
|
|
31
|
+
private existsOffset: number,
|
|
32
|
+
private memberEnum: number,
|
|
33
|
+
) {
|
|
34
|
+
super();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async execute(context: AvmContext): Promise<void> {
|
|
38
|
+
const memory = context.machineState.memory;
|
|
39
|
+
context.machineState.consumeGas(this.gasCost());
|
|
40
|
+
|
|
41
|
+
if (!(this.memberEnum in ContractInstanceMember)) {
|
|
42
|
+
throw new InstructionExecutionError(`Invalid GETCONSTRACTINSTANCE member enum ${this.memberEnum}`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const operands = [this.addressOffset, this.dstOffset, this.existsOffset];
|
|
46
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
47
|
+
const [addressOffset, dstOffset, existsOffset] = addressing.resolve(operands, memory);
|
|
48
|
+
memory.checkTag(TypeTag.FIELD, addressOffset);
|
|
49
|
+
|
|
50
|
+
const address = memory.get(addressOffset).toAztecAddress();
|
|
51
|
+
const instance = await context.persistableState.getContractInstance(address);
|
|
52
|
+
const exists = instance !== undefined;
|
|
53
|
+
|
|
54
|
+
let memberValue = new Field(0);
|
|
55
|
+
if (exists) {
|
|
56
|
+
switch (this.memberEnum as ContractInstanceMember) {
|
|
57
|
+
case ContractInstanceMember.DEPLOYER:
|
|
58
|
+
memberValue = new Field(instance.deployer.toField());
|
|
59
|
+
break;
|
|
60
|
+
case ContractInstanceMember.CLASS_ID:
|
|
61
|
+
memberValue = new Field(instance.currentContractClassId.toField());
|
|
62
|
+
break;
|
|
63
|
+
case ContractInstanceMember.INIT_HASH:
|
|
64
|
+
memberValue = new Field(instance.initializationHash);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
memory.set(existsOffset, new Uint1(exists ? 1 : 0));
|
|
70
|
+
memory.set(dstOffset, memberValue);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { AvmContext } from '../avm_context.js';
|
|
2
|
+
import type { IntegralValue } from '../avm_memory_types.js';
|
|
3
|
+
import { InstructionExecutionError } from '../errors.js';
|
|
4
|
+
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
5
|
+
import { Addressing } from './addressing_mode.js';
|
|
6
|
+
import { Instruction } from './instruction.js';
|
|
7
|
+
|
|
8
|
+
export class Jump extends Instruction {
|
|
9
|
+
static type: string = 'JUMP';
|
|
10
|
+
static readonly opcode: Opcode = Opcode.JUMP_32;
|
|
11
|
+
// Informs (de)serialization. See Instruction.deserialize.
|
|
12
|
+
static readonly wireFormat: OperandType[] = [OperandType.UINT8, OperandType.UINT32];
|
|
13
|
+
|
|
14
|
+
constructor(private jumpOffset: number) {
|
|
15
|
+
super();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
19
|
+
context.machineState.consumeGas(this.gasCost());
|
|
20
|
+
|
|
21
|
+
context.machineState.pc = this.jumpOffset;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public override handlesPC(): boolean {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class JumpI extends Instruction {
|
|
30
|
+
static type: string = 'JUMPI';
|
|
31
|
+
static readonly opcode: Opcode = Opcode.JUMPI_32;
|
|
32
|
+
|
|
33
|
+
// Instruction wire format with opcode.
|
|
34
|
+
static readonly wireFormat: OperandType[] = [
|
|
35
|
+
OperandType.UINT8,
|
|
36
|
+
OperandType.UINT8,
|
|
37
|
+
OperandType.UINT16,
|
|
38
|
+
OperandType.UINT32,
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
constructor(private indirect: number, private condOffset: number, private loc: number) {
|
|
42
|
+
super();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
46
|
+
const memory = context.machineState.memory;
|
|
47
|
+
context.machineState.consumeGas(this.gasCost());
|
|
48
|
+
|
|
49
|
+
const operands = [this.condOffset];
|
|
50
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
51
|
+
const [condOffset] = addressing.resolve(operands, memory);
|
|
52
|
+
const condition = memory.getAs<IntegralValue>(condOffset);
|
|
53
|
+
|
|
54
|
+
if (condition.toBigInt() == 0n) {
|
|
55
|
+
context.machineState.pc = context.machineState.nextPc;
|
|
56
|
+
} else {
|
|
57
|
+
context.machineState.pc = this.loc;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public override handlesPC(): boolean {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export class InternalCall extends Instruction {
|
|
67
|
+
static readonly type: string = 'INTERNALCALL';
|
|
68
|
+
static readonly opcode: Opcode = Opcode.INTERNALCALL;
|
|
69
|
+
// Informs (de)serialization. See Instruction.deserialize.
|
|
70
|
+
static readonly wireFormat: OperandType[] = [OperandType.UINT8, OperandType.UINT32];
|
|
71
|
+
|
|
72
|
+
constructor(private loc: number) {
|
|
73
|
+
super();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
77
|
+
context.machineState.consumeGas(this.gasCost());
|
|
78
|
+
|
|
79
|
+
context.machineState.internalCallStack.push({
|
|
80
|
+
callPc: context.machineState.pc,
|
|
81
|
+
returnPc: context.machineState.nextPc,
|
|
82
|
+
});
|
|
83
|
+
context.machineState.pc = this.loc;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public override handlesPC(): boolean {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class InternalReturn extends Instruction {
|
|
92
|
+
static readonly type: string = 'INTERNALRETURN';
|
|
93
|
+
static readonly opcode: Opcode = Opcode.INTERNALRETURN;
|
|
94
|
+
// Informs (de)serialization. See Instruction.deserialize.
|
|
95
|
+
static readonly wireFormat: OperandType[] = [OperandType.UINT8];
|
|
96
|
+
|
|
97
|
+
constructor() {
|
|
98
|
+
super();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
102
|
+
context.machineState.consumeGas(this.gasCost());
|
|
103
|
+
|
|
104
|
+
const stackEntry = context.machineState.internalCallStack.pop();
|
|
105
|
+
if (stackEntry === undefined) {
|
|
106
|
+
throw new InstructionExecutionError('Internal call stack empty!');
|
|
107
|
+
}
|
|
108
|
+
context.machineState.pc = stackEntry.returnPc;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public override handlesPC(): boolean {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { AvmContext } from '../avm_context.js';
|
|
2
|
+
import { TypeTag, Uint1, Uint8 } from '../avm_memory_types.js';
|
|
3
|
+
import { InvalidToRadixInputsError } from '../errors.js';
|
|
4
|
+
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
5
|
+
import { Addressing } from './addressing_mode.js';
|
|
6
|
+
import { Instruction } from './instruction.js';
|
|
7
|
+
|
|
8
|
+
export class ToRadixBE extends Instruction {
|
|
9
|
+
static type: string = 'TORADIXBE';
|
|
10
|
+
static readonly opcode: Opcode = Opcode.TORADIXBE;
|
|
11
|
+
|
|
12
|
+
// Informs (de)serialization. See Instruction.deserialize.
|
|
13
|
+
static readonly wireFormat: OperandType[] = [
|
|
14
|
+
OperandType.UINT8, // Opcode
|
|
15
|
+
OperandType.UINT16, // Indirect
|
|
16
|
+
OperandType.UINT16, // src memory address
|
|
17
|
+
OperandType.UINT16, // radix memory address
|
|
18
|
+
OperandType.UINT16, // number of limbs address
|
|
19
|
+
OperandType.UINT16, // output is in "bits" mode memory address (boolean/Uint1 is stored)
|
|
20
|
+
OperandType.UINT16, // dst memory address
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
private indirect: number,
|
|
25
|
+
private srcOffset: number,
|
|
26
|
+
private radixOffset: number,
|
|
27
|
+
private numLimbsOffset: number,
|
|
28
|
+
private outputBitsOffset: number,
|
|
29
|
+
private dstOffset: number,
|
|
30
|
+
) {
|
|
31
|
+
super();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
35
|
+
const memory = context.machineState.memory;
|
|
36
|
+
const operands = [this.srcOffset, this.radixOffset, this.numLimbsOffset, this.outputBitsOffset, this.dstOffset];
|
|
37
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
38
|
+
const [srcOffset, radixOffset, numLimbsOffset, outputBitsOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
39
|
+
|
|
40
|
+
// The radix gadget only takes in a Field
|
|
41
|
+
memory.checkTag(TypeTag.FIELD, srcOffset);
|
|
42
|
+
memory.checkTag(TypeTag.UINT32, radixOffset);
|
|
43
|
+
memory.checkTag(TypeTag.UINT32, numLimbsOffset);
|
|
44
|
+
memory.checkTag(TypeTag.UINT1, outputBitsOffset);
|
|
45
|
+
|
|
46
|
+
const numLimbs = memory.get(numLimbsOffset).toNumber();
|
|
47
|
+
context.machineState.consumeGas(this.gasCost(numLimbs));
|
|
48
|
+
const outputBits = memory.get(outputBitsOffset).toNumber();
|
|
49
|
+
|
|
50
|
+
let value: bigint = memory.get(srcOffset).toBigInt();
|
|
51
|
+
const radix: bigint = memory.get(radixOffset).toBigInt();
|
|
52
|
+
|
|
53
|
+
if (radix < 2 || radix > 256) {
|
|
54
|
+
throw new InvalidToRadixInputsError(`ToRadixBE instruction's radix should be in range [2,256] (was ${radix}).`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (numLimbs < 1 && value != BigInt(0n)) {
|
|
58
|
+
throw new InvalidToRadixInputsError(
|
|
59
|
+
`ToRadixBE instruction's input value is not zero (was ${value}) but numLimbs zero.`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (outputBits != 0 && radix != BigInt(2n)) {
|
|
64
|
+
throw new InvalidToRadixInputsError(`Radix ${radix} is not equal to 2 and bit mode is activated.`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const radixBN: bigint = BigInt(radix);
|
|
68
|
+
const limbArray = new Array(numLimbs);
|
|
69
|
+
|
|
70
|
+
for (let i = numLimbs - 1; i >= 0; i--) {
|
|
71
|
+
const limb = value % radixBN;
|
|
72
|
+
limbArray[i] = limb;
|
|
73
|
+
value /= radixBN;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const outputType = outputBits != 0 ? Uint1 : Uint8;
|
|
77
|
+
const res = limbArray.map(byte => new outputType(byte));
|
|
78
|
+
memory.setSlice(dstOffset, res);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Grumpkin } from '@aztec/foundation/crypto';
|
|
2
|
+
import { Point } from '@aztec/foundation/fields';
|
|
3
|
+
|
|
4
|
+
import type { AvmContext } from '../avm_context.js';
|
|
5
|
+
import { Field, TypeTag, Uint1 } from '../avm_memory_types.js';
|
|
6
|
+
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
7
|
+
import { Addressing } from './addressing_mode.js';
|
|
8
|
+
import { Instruction } from './instruction.js';
|
|
9
|
+
|
|
10
|
+
export class EcAdd extends Instruction {
|
|
11
|
+
static type: string = 'ECADD';
|
|
12
|
+
static readonly opcode = Opcode.ECADD;
|
|
13
|
+
|
|
14
|
+
// Informs (de)serialization. See Instruction.deserialize.
|
|
15
|
+
static readonly wireFormat: OperandType[] = [
|
|
16
|
+
OperandType.UINT8, // reserved
|
|
17
|
+
OperandType.UINT16, // indirect
|
|
18
|
+
OperandType.UINT16, // p1X
|
|
19
|
+
OperandType.UINT16, // p1Y
|
|
20
|
+
OperandType.UINT16, // p1IsInfinite
|
|
21
|
+
OperandType.UINT16, // p2X
|
|
22
|
+
OperandType.UINT16, // p2Y
|
|
23
|
+
OperandType.UINT16, // p2IsInfinite
|
|
24
|
+
OperandType.UINT16, // dst
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
private indirect: number,
|
|
29
|
+
private p1XOffset: number,
|
|
30
|
+
private p1YOffset: number,
|
|
31
|
+
private p1IsInfiniteOffset: number,
|
|
32
|
+
private p2XOffset: number,
|
|
33
|
+
private p2YOffset: number,
|
|
34
|
+
private p2IsInfiniteOffset: number,
|
|
35
|
+
private dstOffset: number,
|
|
36
|
+
) {
|
|
37
|
+
super();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
41
|
+
const memory = context.machineState.memory;
|
|
42
|
+
context.machineState.consumeGas(this.gasCost());
|
|
43
|
+
|
|
44
|
+
const operands = [
|
|
45
|
+
this.p1XOffset,
|
|
46
|
+
this.p1YOffset,
|
|
47
|
+
this.p1IsInfiniteOffset,
|
|
48
|
+
this.p2XOffset,
|
|
49
|
+
this.p2YOffset,
|
|
50
|
+
this.p2IsInfiniteOffset,
|
|
51
|
+
this.dstOffset,
|
|
52
|
+
];
|
|
53
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
54
|
+
const [p1XOffset, p1YOffset, p1IsInfiniteOffset, p2XOffset, p2YOffset, p2IsInfiniteOffset, dstOffset] =
|
|
55
|
+
addressing.resolve(operands, memory);
|
|
56
|
+
|
|
57
|
+
memory.checkTags(TypeTag.FIELD, p1XOffset, p1YOffset, p2XOffset, p2YOffset);
|
|
58
|
+
memory.checkTags(TypeTag.UINT1, p1IsInfiniteOffset, p2IsInfiniteOffset);
|
|
59
|
+
|
|
60
|
+
const p1X = memory.get(p1XOffset);
|
|
61
|
+
const p1Y = memory.get(p1YOffset);
|
|
62
|
+
const p1IsInfinite = memory.get(p1IsInfiniteOffset).toNumber() === 1;
|
|
63
|
+
const p1 = new Point(p1X.toFr(), p1Y.toFr(), p1IsInfinite);
|
|
64
|
+
if (!p1.isOnGrumpkin()) {
|
|
65
|
+
throw new Error(`Point1 is not on the curve`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const p2X = memory.get(p2XOffset);
|
|
69
|
+
const p2Y = memory.get(p2YOffset);
|
|
70
|
+
// unused. Point doesn't store this information
|
|
71
|
+
const p2IsInfinite = memory.get(p2IsInfiniteOffset).toNumber() === 1;
|
|
72
|
+
const p2 = new Point(p2X.toFr(), p2Y.toFr(), p2IsInfinite);
|
|
73
|
+
if (!p2.isOnGrumpkin()) {
|
|
74
|
+
throw new Error(`Point1 is not on the curve`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const grumpkin = new Grumpkin();
|
|
78
|
+
let dest;
|
|
79
|
+
if (p1IsInfinite) {
|
|
80
|
+
dest = p2;
|
|
81
|
+
} else if (p2IsInfinite) {
|
|
82
|
+
dest = p1;
|
|
83
|
+
} else {
|
|
84
|
+
dest = await grumpkin.add(p1, p2);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Important to use setSlice() and not set() in the two following statements as
|
|
88
|
+
// this checks that the offsets lie within memory range.
|
|
89
|
+
memory.setSlice(dstOffset, [new Field(dest.x), new Field(dest.y)]);
|
|
90
|
+
// Check representation of infinity for grumpkin
|
|
91
|
+
memory.setSlice(dstOffset + 2, [new Uint1(dest.equals(Point.ZERO) ? 1 : 0)]);
|
|
92
|
+
}
|
|
93
|
+
}
|