@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,254 @@
|
|
|
1
|
+
import type { AvmContext } from '../avm_context.js';
|
|
2
|
+
import { Field, TaggedMemory, TypeTag, Uint32 } 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
|
+
|
|
7
|
+
export class Set extends Instruction {
|
|
8
|
+
static readonly type: string = 'SET';
|
|
9
|
+
// Required for gas.
|
|
10
|
+
static readonly opcode: Opcode = Opcode.SET_8;
|
|
11
|
+
|
|
12
|
+
public static readonly wireFormat8: OperandType[] = [
|
|
13
|
+
OperandType.UINT8, // opcode
|
|
14
|
+
OperandType.UINT8, // indirect
|
|
15
|
+
OperandType.UINT8, // dstOffset
|
|
16
|
+
OperandType.UINT8, // tag
|
|
17
|
+
OperandType.UINT8, // const (value)
|
|
18
|
+
];
|
|
19
|
+
public static readonly wireFormat16: OperandType[] = [
|
|
20
|
+
OperandType.UINT8, // opcode
|
|
21
|
+
OperandType.UINT8, // indirect
|
|
22
|
+
OperandType.UINT16, // dstOffset
|
|
23
|
+
OperandType.UINT8, // tag
|
|
24
|
+
OperandType.UINT16, // const (value)
|
|
25
|
+
];
|
|
26
|
+
public static readonly wireFormat32: OperandType[] = [
|
|
27
|
+
OperandType.UINT8, // opcode
|
|
28
|
+
OperandType.UINT8, // indirect
|
|
29
|
+
OperandType.UINT16, // dstOffset
|
|
30
|
+
OperandType.UINT8, // tag
|
|
31
|
+
OperandType.UINT32, // const (value)
|
|
32
|
+
];
|
|
33
|
+
public static readonly wireFormat64: OperandType[] = [
|
|
34
|
+
OperandType.UINT8, // opcode
|
|
35
|
+
OperandType.UINT8, // indirect
|
|
36
|
+
OperandType.UINT16, // dstOffset
|
|
37
|
+
OperandType.UINT8, // tag
|
|
38
|
+
OperandType.UINT64, // const (value)
|
|
39
|
+
];
|
|
40
|
+
public static readonly wireFormat128: OperandType[] = [
|
|
41
|
+
OperandType.UINT8, // opcode
|
|
42
|
+
OperandType.UINT8, // indirect
|
|
43
|
+
OperandType.UINT16, // dstOffset
|
|
44
|
+
OperandType.UINT8, // tag
|
|
45
|
+
OperandType.UINT128, // const (value)
|
|
46
|
+
];
|
|
47
|
+
public static readonly wireFormatFF: OperandType[] = [
|
|
48
|
+
OperandType.UINT8, // opcode
|
|
49
|
+
OperandType.UINT8, // indirect
|
|
50
|
+
OperandType.UINT16, // dstOffset
|
|
51
|
+
OperandType.UINT8, // tag
|
|
52
|
+
OperandType.FF, // const (value)
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
constructor(
|
|
56
|
+
private indirect: number,
|
|
57
|
+
private dstOffset: number,
|
|
58
|
+
private inTag: number,
|
|
59
|
+
private value: bigint | number,
|
|
60
|
+
) {
|
|
61
|
+
super();
|
|
62
|
+
TaggedMemory.checkIsValidTag(inTag);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
66
|
+
// Constructor ensured that this.inTag is a valid tag
|
|
67
|
+
const res = TaggedMemory.buildFromTagTruncating(this.value, this.inTag);
|
|
68
|
+
|
|
69
|
+
const memory = context.machineState.memory;
|
|
70
|
+
context.machineState.consumeGas(this.gasCost());
|
|
71
|
+
|
|
72
|
+
const operands = [this.dstOffset];
|
|
73
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
74
|
+
const [dstOffset] = addressing.resolve(operands, memory);
|
|
75
|
+
memory.set(dstOffset, res);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export class Cast extends Instruction {
|
|
80
|
+
static readonly type: string = 'CAST';
|
|
81
|
+
static readonly opcode = Opcode.CAST_8;
|
|
82
|
+
|
|
83
|
+
static readonly wireFormat8 = [
|
|
84
|
+
OperandType.UINT8,
|
|
85
|
+
OperandType.UINT8,
|
|
86
|
+
OperandType.UINT8,
|
|
87
|
+
OperandType.UINT8,
|
|
88
|
+
OperandType.UINT8,
|
|
89
|
+
];
|
|
90
|
+
static readonly wireFormat16 = [
|
|
91
|
+
OperandType.UINT8,
|
|
92
|
+
OperandType.UINT8,
|
|
93
|
+
OperandType.UINT16,
|
|
94
|
+
OperandType.UINT16,
|
|
95
|
+
OperandType.UINT8,
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
constructor(private indirect: number, private srcOffset: number, private dstOffset: number, private dstTag: number) {
|
|
99
|
+
super();
|
|
100
|
+
TaggedMemory.checkIsValidTag(dstTag);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
104
|
+
const memory = context.machineState.memory;
|
|
105
|
+
context.machineState.consumeGas(this.gasCost());
|
|
106
|
+
|
|
107
|
+
const operands = [this.srcOffset, this.dstOffset];
|
|
108
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
109
|
+
const [srcOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
110
|
+
|
|
111
|
+
const a = memory.get(srcOffset);
|
|
112
|
+
// Constructor ensured that this.dstTag is a valid tag
|
|
113
|
+
const casted = TaggedMemory.buildFromTagTruncating(a.toBigInt(), this.dstTag);
|
|
114
|
+
|
|
115
|
+
memory.set(dstOffset, casted);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export class Mov extends Instruction {
|
|
120
|
+
static readonly type: string = 'MOV';
|
|
121
|
+
// FIXME: This is needed for gas.
|
|
122
|
+
static readonly opcode: Opcode = Opcode.MOV_8;
|
|
123
|
+
|
|
124
|
+
static readonly wireFormat8: OperandType[] = [
|
|
125
|
+
OperandType.UINT8,
|
|
126
|
+
OperandType.UINT8,
|
|
127
|
+
OperandType.UINT8,
|
|
128
|
+
OperandType.UINT8,
|
|
129
|
+
];
|
|
130
|
+
static readonly wireFormat16: OperandType[] = [
|
|
131
|
+
OperandType.UINT8,
|
|
132
|
+
OperandType.UINT8,
|
|
133
|
+
OperandType.UINT16,
|
|
134
|
+
OperandType.UINT16,
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
constructor(private indirect: number, private srcOffset: number, private dstOffset: number) {
|
|
138
|
+
super();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
142
|
+
const memory = context.machineState.memory;
|
|
143
|
+
context.machineState.consumeGas(this.gasCost());
|
|
144
|
+
|
|
145
|
+
const operands = [this.srcOffset, this.dstOffset];
|
|
146
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
147
|
+
const [srcOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
148
|
+
const a = memory.get(srcOffset);
|
|
149
|
+
memory.set(dstOffset, a);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export class CalldataCopy extends Instruction {
|
|
154
|
+
static readonly type: string = 'CALLDATACOPY';
|
|
155
|
+
static readonly opcode: Opcode = Opcode.CALLDATACOPY;
|
|
156
|
+
// Informs (de)serialization. See Instruction.deserialize.
|
|
157
|
+
static readonly wireFormat: OperandType[] = [
|
|
158
|
+
OperandType.UINT8,
|
|
159
|
+
OperandType.UINT8,
|
|
160
|
+
OperandType.UINT16,
|
|
161
|
+
OperandType.UINT16,
|
|
162
|
+
OperandType.UINT16,
|
|
163
|
+
];
|
|
164
|
+
|
|
165
|
+
constructor(
|
|
166
|
+
private indirect: number,
|
|
167
|
+
private cdStartOffset: number,
|
|
168
|
+
private copySizeOffset: number,
|
|
169
|
+
private dstOffset: number,
|
|
170
|
+
) {
|
|
171
|
+
super();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
175
|
+
const memory = context.machineState.memory;
|
|
176
|
+
const operands = [this.cdStartOffset, this.copySizeOffset, this.dstOffset];
|
|
177
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
178
|
+
const [cdStartOffset, copySizeOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
179
|
+
|
|
180
|
+
memory.checkTags(TypeTag.UINT32, cdStartOffset, copySizeOffset);
|
|
181
|
+
const cdStart = memory.get(cdStartOffset).toNumber();
|
|
182
|
+
const copySize = memory.get(copySizeOffset).toNumber();
|
|
183
|
+
context.machineState.consumeGas(this.gasCost(copySize));
|
|
184
|
+
|
|
185
|
+
// Values which are out-of-range of the calldata array will be set with Field(0);
|
|
186
|
+
const slice = context.environment.calldata.slice(cdStart, cdStart + copySize).map(f => new Field(f));
|
|
187
|
+
// slice has size = MIN(copySize, calldata.length - cdStart) as TS truncates out-of-range portion
|
|
188
|
+
const transformedData = [...slice, ...Array(copySize - slice.length).fill(new Field(0))];
|
|
189
|
+
|
|
190
|
+
memory.setSlice(dstOffset, transformedData);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export class ReturndataSize extends Instruction {
|
|
195
|
+
static readonly type: string = 'RETURNDATASIZE';
|
|
196
|
+
static readonly opcode: Opcode = Opcode.RETURNDATASIZE;
|
|
197
|
+
// Informs (de)serialization. See Instruction.deserialize.
|
|
198
|
+
static readonly wireFormat: OperandType[] = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16];
|
|
199
|
+
|
|
200
|
+
constructor(private indirect: number, private dstOffset: number) {
|
|
201
|
+
super();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
205
|
+
const memory = context.machineState.memory;
|
|
206
|
+
const operands = [this.dstOffset];
|
|
207
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
208
|
+
const [dstOffset] = addressing.resolve(operands, memory);
|
|
209
|
+
context.machineState.consumeGas(this.gasCost());
|
|
210
|
+
|
|
211
|
+
memory.set(dstOffset, new Uint32(context.machineState.nestedReturndata.length));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export class ReturndataCopy extends Instruction {
|
|
216
|
+
static readonly type: string = 'RETURNDATACOPY';
|
|
217
|
+
static readonly opcode: Opcode = Opcode.RETURNDATACOPY;
|
|
218
|
+
// Informs (de)serialization. See Instruction.deserialize.
|
|
219
|
+
static readonly wireFormat: OperandType[] = [
|
|
220
|
+
OperandType.UINT8,
|
|
221
|
+
OperandType.UINT8,
|
|
222
|
+
OperandType.UINT16,
|
|
223
|
+
OperandType.UINT16,
|
|
224
|
+
OperandType.UINT16,
|
|
225
|
+
];
|
|
226
|
+
|
|
227
|
+
constructor(
|
|
228
|
+
private indirect: number,
|
|
229
|
+
private rdStartOffset: number,
|
|
230
|
+
private copySizeOffset: number,
|
|
231
|
+
private dstOffset: number,
|
|
232
|
+
) {
|
|
233
|
+
super();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
237
|
+
const memory = context.machineState.memory;
|
|
238
|
+
const operands = [this.rdStartOffset, this.copySizeOffset, this.dstOffset];
|
|
239
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
240
|
+
const [rdStartOffset, copySizeOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
241
|
+
|
|
242
|
+
memory.checkTags(TypeTag.UINT32, rdStartOffset, copySizeOffset);
|
|
243
|
+
const rdStart = memory.get(rdStartOffset).toNumber();
|
|
244
|
+
const copySize = memory.get(copySizeOffset).toNumber();
|
|
245
|
+
context.machineState.consumeGas(this.gasCost(copySize));
|
|
246
|
+
|
|
247
|
+
// Values which are out-of-range of the returndata array will be set with Field(0);
|
|
248
|
+
const slice = context.machineState.nestedReturndata.slice(rdStart, rdStart + copySize).map(f => new Field(f));
|
|
249
|
+
// slice has size = MIN(copySize, returndata.length - rdStart) as TS truncates out-of-range portion
|
|
250
|
+
const transformedData = [...slice, ...Array(copySize - slice.length).fill(new Field(0))];
|
|
251
|
+
|
|
252
|
+
memory.setSlice(dstOffset, transformedData);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
|
|
3
|
+
import type { AvmContext } from '../avm_context.js';
|
|
4
|
+
import { TypeTag } from '../avm_memory_types.js';
|
|
5
|
+
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
6
|
+
import { Addressing } from './addressing_mode.js';
|
|
7
|
+
import { Instruction } from './instruction.js';
|
|
8
|
+
|
|
9
|
+
export class DebugLog extends Instruction {
|
|
10
|
+
static type: string = 'DEBUGLOG';
|
|
11
|
+
static readonly opcode: Opcode = Opcode.DEBUGLOG;
|
|
12
|
+
static readonly logger = createLogger('simulator:avm:debug_log');
|
|
13
|
+
|
|
14
|
+
// Informs (de)serialization. See Instruction.deserialize.
|
|
15
|
+
static readonly wireFormat: OperandType[] = [
|
|
16
|
+
OperandType.UINT8, // Opcode
|
|
17
|
+
OperandType.UINT8, // Indirect
|
|
18
|
+
OperandType.UINT16, // message memory address
|
|
19
|
+
OperandType.UINT16, // fields memory address
|
|
20
|
+
OperandType.UINT16, // fields size address
|
|
21
|
+
OperandType.UINT16, // message size
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
constructor(
|
|
25
|
+
private indirect: number,
|
|
26
|
+
private messageOffset: number,
|
|
27
|
+
private fieldsOffset: number,
|
|
28
|
+
private fieldsSizeOffset: number,
|
|
29
|
+
private messageSize: number,
|
|
30
|
+
) {
|
|
31
|
+
super();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
35
|
+
const memory = context.machineState.memory;
|
|
36
|
+
const operands = [this.messageOffset, this.fieldsOffset, this.fieldsSizeOffset];
|
|
37
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
38
|
+
const [messageOffset, fieldsOffset, fieldsSizeOffset] = addressing.resolve(operands, memory);
|
|
39
|
+
|
|
40
|
+
memory.checkTag(TypeTag.UINT32, fieldsSizeOffset);
|
|
41
|
+
const fieldsSize = memory.get(fieldsSizeOffset).toNumber();
|
|
42
|
+
|
|
43
|
+
const rawMessage = memory.getSlice(messageOffset, this.messageSize);
|
|
44
|
+
const fields = memory.getSlice(fieldsOffset, fieldsSize);
|
|
45
|
+
|
|
46
|
+
memory.checkTagsRange(TypeTag.UINT8, messageOffset, this.messageSize);
|
|
47
|
+
memory.checkTagsRange(TypeTag.FIELD, fieldsOffset, fieldsSize);
|
|
48
|
+
|
|
49
|
+
context.machineState.consumeGas(this.gasCost(this.messageSize + fieldsSize));
|
|
50
|
+
|
|
51
|
+
// Interpret str<N> = [u8; N] to string.
|
|
52
|
+
const messageAsStr = rawMessage.map(field => String.fromCharCode(field.toNumber())).join('');
|
|
53
|
+
const formattedStr = applyStringFormatting(
|
|
54
|
+
messageAsStr,
|
|
55
|
+
fields.map(field => field.toFr()),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
DebugLog.logger.verbose(formattedStr);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { AvmContext } from '../avm_context.js';
|
|
2
|
+
import { Field, TypeTag } from '../avm_memory_types.js';
|
|
3
|
+
import { StaticCallAlterationError } 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
|
+
abstract class BaseStorageInstruction extends Instruction {
|
|
9
|
+
// Informs (de)serialization. See Instruction.deserialize.
|
|
10
|
+
public static readonly wireFormat: OperandType[] = [
|
|
11
|
+
OperandType.UINT8,
|
|
12
|
+
OperandType.UINT8,
|
|
13
|
+
OperandType.UINT16,
|
|
14
|
+
OperandType.UINT16,
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
constructor(protected indirect: number, protected aOffset: number, protected bOffset: number) {
|
|
18
|
+
super();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class SStore extends BaseStorageInstruction {
|
|
23
|
+
static readonly type: string = 'SSTORE';
|
|
24
|
+
static readonly opcode = Opcode.SSTORE;
|
|
25
|
+
|
|
26
|
+
constructor(indirect: number, srcOffset: number, slotOffset: number) {
|
|
27
|
+
super(indirect, srcOffset, slotOffset);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
31
|
+
if (context.environment.isStaticCall) {
|
|
32
|
+
throw new StaticCallAlterationError();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const memory = context.machineState.memory;
|
|
36
|
+
context.machineState.consumeGas(this.gasCost());
|
|
37
|
+
|
|
38
|
+
const operands = [this.aOffset, this.bOffset];
|
|
39
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
40
|
+
const [srcOffset, slotOffset] = addressing.resolve(operands, memory);
|
|
41
|
+
memory.checkTag(TypeTag.FIELD, slotOffset);
|
|
42
|
+
memory.checkTag(TypeTag.FIELD, srcOffset);
|
|
43
|
+
|
|
44
|
+
const slot = memory.get(slotOffset).toFr();
|
|
45
|
+
const value = memory.get(srcOffset).toFr();
|
|
46
|
+
await context.persistableState.writeStorage(context.environment.address, slot, value);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export class SLoad extends BaseStorageInstruction {
|
|
51
|
+
static readonly type: string = 'SLOAD';
|
|
52
|
+
static readonly opcode = Opcode.SLOAD;
|
|
53
|
+
|
|
54
|
+
constructor(indirect: number, slotOffset: number, dstOffset: number) {
|
|
55
|
+
super(indirect, slotOffset, dstOffset);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
59
|
+
const memory = context.machineState.memory;
|
|
60
|
+
context.machineState.consumeGas(this.gasCost());
|
|
61
|
+
|
|
62
|
+
const operands = [this.aOffset, this.bOffset];
|
|
63
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
64
|
+
const [slotOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
65
|
+
memory.checkTag(TypeTag.FIELD, slotOffset);
|
|
66
|
+
|
|
67
|
+
const slot = memory.get(slotOffset).toFr();
|
|
68
|
+
const value = await context.persistableState.readStorage(context.environment.address, slot);
|
|
69
|
+
memory.set(dstOffset, new Field(value));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A Buffer-like class that automatically advances the position.
|
|
3
|
+
*/
|
|
4
|
+
export class BufferCursor {
|
|
5
|
+
constructor(private _buffer: Buffer, private _position: number = 0) {}
|
|
6
|
+
|
|
7
|
+
public position(): number {
|
|
8
|
+
return this._position;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public buffer(): Buffer {
|
|
12
|
+
return this._buffer;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public eof(): boolean {
|
|
16
|
+
return this._position === this._buffer.length;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public bufferAtPosition(): Buffer {
|
|
20
|
+
return this._buffer.subarray(this._position);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public advance(n: number): void {
|
|
24
|
+
this._position += n;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public peekUint8(): number {
|
|
28
|
+
const ret = this._buffer.readUint8(this._position);
|
|
29
|
+
return ret;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public readUint8(): number {
|
|
33
|
+
const ret = this._buffer.readUint8(this._position);
|
|
34
|
+
this._position += 1;
|
|
35
|
+
return ret;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public readUint16LE(): number {
|
|
39
|
+
const ret = this._buffer.readUint16LE(this._position);
|
|
40
|
+
this._position += 2;
|
|
41
|
+
return ret;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public readUint16BE(): number {
|
|
45
|
+
const ret = this._buffer.readUint16BE(this._position);
|
|
46
|
+
this._position += 2;
|
|
47
|
+
return ret;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public readUint32LE(): number {
|
|
51
|
+
const ret = this._buffer.readUint32LE(this._position);
|
|
52
|
+
this._position += 4;
|
|
53
|
+
return ret;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public readUint32BE(): number {
|
|
57
|
+
const ret = this._buffer.readUint32BE(this._position);
|
|
58
|
+
this._position += 4;
|
|
59
|
+
return ret;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public readBigInt64LE(): bigint {
|
|
63
|
+
const ret = this._buffer.readBigInt64LE(this._position);
|
|
64
|
+
this._position += 8;
|
|
65
|
+
return ret;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public readBigInt64BE(): bigint {
|
|
69
|
+
const ret = this._buffer.readBigInt64BE(this._position);
|
|
70
|
+
this._position += 8;
|
|
71
|
+
return ret;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public writeUint8(v: number) {
|
|
75
|
+
const ret = this._buffer.writeUint8(v, this._position);
|
|
76
|
+
this._position += 1;
|
|
77
|
+
return ret;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public writeUint16LE(v: number) {
|
|
81
|
+
const ret = this._buffer.writeUint16LE(v, this._position);
|
|
82
|
+
this._position += 2;
|
|
83
|
+
return ret;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public writeUint16BE(v: number) {
|
|
87
|
+
const ret = this._buffer.writeUint16BE(v, this._position);
|
|
88
|
+
this._position += 2;
|
|
89
|
+
return ret;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public writeUint32LE(v: number) {
|
|
93
|
+
const ret = this._buffer.writeUint32LE(v, this._position);
|
|
94
|
+
this._position += 4;
|
|
95
|
+
return ret;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public writeUint32BE(v: number) {
|
|
99
|
+
const ret = this._buffer.writeUint32BE(v, this._position);
|
|
100
|
+
this._position += 4;
|
|
101
|
+
return ret;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public writeBigInt64LE(v: bigint) {
|
|
105
|
+
const ret = this._buffer.writeBigInt64LE(v, this._position);
|
|
106
|
+
this._position += 8;
|
|
107
|
+
return ret;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public writeBigInt64BE(v: bigint) {
|
|
111
|
+
const ret = this._buffer.writeBigInt64BE(v, this._position);
|
|
112
|
+
this._position += 8;
|
|
113
|
+
return ret;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { AvmExecutionError, AvmParsingError, InvalidOpcodeError, InvalidProgramCounterError } from '../errors.js';
|
|
2
|
+
import {
|
|
3
|
+
Add,
|
|
4
|
+
And,
|
|
5
|
+
Call,
|
|
6
|
+
CalldataCopy,
|
|
7
|
+
Cast,
|
|
8
|
+
DebugLog,
|
|
9
|
+
Div,
|
|
10
|
+
EcAdd,
|
|
11
|
+
EmitNoteHash,
|
|
12
|
+
EmitNullifier,
|
|
13
|
+
EmitUnencryptedLog,
|
|
14
|
+
Eq,
|
|
15
|
+
FieldDiv,
|
|
16
|
+
GetContractInstance,
|
|
17
|
+
GetEnvVar,
|
|
18
|
+
Instruction,
|
|
19
|
+
InternalCall,
|
|
20
|
+
InternalReturn,
|
|
21
|
+
Jump,
|
|
22
|
+
JumpI,
|
|
23
|
+
KeccakF1600,
|
|
24
|
+
L1ToL2MessageExists,
|
|
25
|
+
Lt,
|
|
26
|
+
Lte,
|
|
27
|
+
Mov,
|
|
28
|
+
Mul,
|
|
29
|
+
Not,
|
|
30
|
+
NoteHashExists,
|
|
31
|
+
NullifierExists,
|
|
32
|
+
Or,
|
|
33
|
+
Poseidon2,
|
|
34
|
+
Return,
|
|
35
|
+
ReturndataCopy,
|
|
36
|
+
ReturndataSize,
|
|
37
|
+
Revert,
|
|
38
|
+
SLoad,
|
|
39
|
+
SStore,
|
|
40
|
+
SendL2ToL1Message,
|
|
41
|
+
Set,
|
|
42
|
+
Sha256Compression,
|
|
43
|
+
Shl,
|
|
44
|
+
Shr,
|
|
45
|
+
StaticCall,
|
|
46
|
+
Sub,
|
|
47
|
+
SuccessCopy,
|
|
48
|
+
ToRadixBE,
|
|
49
|
+
Xor,
|
|
50
|
+
} from '../opcodes/index.js';
|
|
51
|
+
import { BufferCursor } from './buffer_cursor.js';
|
|
52
|
+
import { MAX_OPCODE_VALUE, Opcode } from './instruction_serialization.js';
|
|
53
|
+
|
|
54
|
+
export type InstructionDeserializer = (buf: BufferCursor | Buffer) => Instruction;
|
|
55
|
+
|
|
56
|
+
export interface Serializable {
|
|
57
|
+
serialize(): Buffer;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface Deserializable {
|
|
61
|
+
deserialize: InstructionDeserializer;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type InstructionSet = Map<Opcode, InstructionDeserializer>;
|
|
65
|
+
export const INSTRUCTION_SET = new Map<Opcode, InstructionDeserializer>([
|
|
66
|
+
[Opcode.ADD_8, Add.as(Add.wireFormat8).deserialize],
|
|
67
|
+
[Opcode.ADD_16, Add.as(Add.wireFormat16).deserialize],
|
|
68
|
+
[Opcode.SUB_8, Sub.as(Sub.wireFormat8).deserialize],
|
|
69
|
+
[Opcode.SUB_16, Sub.as(Sub.wireFormat16).deserialize],
|
|
70
|
+
[Opcode.MUL_8, Mul.as(Mul.wireFormat8).deserialize],
|
|
71
|
+
[Opcode.MUL_16, Mul.as(Mul.wireFormat16).deserialize],
|
|
72
|
+
[Opcode.DIV_8, Div.as(Div.wireFormat8).deserialize],
|
|
73
|
+
[Opcode.DIV_16, Div.as(Div.wireFormat16).deserialize],
|
|
74
|
+
[Opcode.FDIV_8, FieldDiv.as(FieldDiv.wireFormat8).deserialize],
|
|
75
|
+
[Opcode.FDIV_16, FieldDiv.as(FieldDiv.wireFormat16).deserialize],
|
|
76
|
+
[Opcode.EQ_8, Eq.as(Eq.wireFormat8).deserialize],
|
|
77
|
+
[Opcode.EQ_16, Eq.as(Eq.wireFormat16).deserialize],
|
|
78
|
+
[Opcode.LT_8, Lt.as(Lt.wireFormat8).deserialize],
|
|
79
|
+
[Opcode.LT_16, Lt.as(Lt.wireFormat16).deserialize],
|
|
80
|
+
[Opcode.LTE_8, Lte.as(Lte.wireFormat8).deserialize],
|
|
81
|
+
[Opcode.LTE_16, Lte.as(Lte.wireFormat16).deserialize],
|
|
82
|
+
[Opcode.AND_8, And.as(And.wireFormat8).deserialize],
|
|
83
|
+
[Opcode.AND_16, And.as(And.wireFormat16).deserialize],
|
|
84
|
+
[Opcode.OR_8, Or.as(Or.wireFormat8).deserialize],
|
|
85
|
+
[Opcode.OR_16, Or.as(Or.wireFormat16).deserialize],
|
|
86
|
+
[Opcode.XOR_8, Xor.as(Xor.wireFormat8).deserialize],
|
|
87
|
+
[Opcode.XOR_16, Xor.as(Xor.wireFormat16).deserialize],
|
|
88
|
+
[Opcode.NOT_8, Not.as(Not.wireFormat8).deserialize],
|
|
89
|
+
[Opcode.NOT_16, Not.as(Not.wireFormat16).deserialize],
|
|
90
|
+
[Opcode.SHL_8, Shl.as(Shl.wireFormat8).deserialize],
|
|
91
|
+
[Opcode.SHL_16, Shl.as(Shl.wireFormat16).deserialize],
|
|
92
|
+
[Opcode.SHR_8, Shr.as(Shr.wireFormat8).deserialize],
|
|
93
|
+
[Opcode.SHR_16, Shr.as(Shr.wireFormat16).deserialize],
|
|
94
|
+
[Opcode.CAST_8, Cast.as(Cast.wireFormat8).deserialize],
|
|
95
|
+
[Opcode.CAST_16, Cast.as(Cast.wireFormat16).deserialize],
|
|
96
|
+
// Execution Environment
|
|
97
|
+
[Opcode.GETENVVAR_16, GetEnvVar.as(GetEnvVar.wireFormat16).deserialize],
|
|
98
|
+
[CalldataCopy.opcode, Instruction.deserialize.bind(CalldataCopy)],
|
|
99
|
+
[SuccessCopy.opcode, Instruction.deserialize.bind(SuccessCopy)],
|
|
100
|
+
[Opcode.RETURNDATASIZE, Instruction.deserialize.bind(ReturndataSize)],
|
|
101
|
+
[Opcode.RETURNDATACOPY, Instruction.deserialize.bind(ReturndataCopy)],
|
|
102
|
+
|
|
103
|
+
// Machine State - Internal Control Flow
|
|
104
|
+
[Jump.opcode, Instruction.deserialize.bind(Jump)],
|
|
105
|
+
[JumpI.opcode, Instruction.deserialize.bind(JumpI)],
|
|
106
|
+
[InternalCall.opcode, Instruction.deserialize.bind(InternalCall)],
|
|
107
|
+
[InternalReturn.opcode, Instruction.deserialize.bind(InternalReturn)],
|
|
108
|
+
[Opcode.SET_8, Set.as(Set.wireFormat8).deserialize],
|
|
109
|
+
[Opcode.SET_16, Set.as(Set.wireFormat16).deserialize],
|
|
110
|
+
[Opcode.SET_32, Set.as(Set.wireFormat32).deserialize],
|
|
111
|
+
[Opcode.SET_64, Set.as(Set.wireFormat64).deserialize],
|
|
112
|
+
[Opcode.SET_128, Set.as(Set.wireFormat128).deserialize],
|
|
113
|
+
[Opcode.SET_FF, Set.as(Set.wireFormatFF).deserialize],
|
|
114
|
+
[Opcode.MOV_8, Mov.as(Mov.wireFormat8).deserialize],
|
|
115
|
+
[Opcode.MOV_16, Mov.as(Mov.wireFormat16).deserialize],
|
|
116
|
+
|
|
117
|
+
// World State
|
|
118
|
+
[SLoad.opcode, Instruction.deserialize.bind(SLoad)], // Public Storage
|
|
119
|
+
[SStore.opcode, Instruction.deserialize.bind(SStore)], // Public Storage
|
|
120
|
+
[NoteHashExists.opcode, Instruction.deserialize.bind(NoteHashExists)], // Notes & Nullifiers
|
|
121
|
+
[EmitNoteHash.opcode, Instruction.deserialize.bind(EmitNoteHash)], // Notes & Nullifiers
|
|
122
|
+
[NullifierExists.opcode, Instruction.deserialize.bind(NullifierExists)], // Notes & Nullifiers
|
|
123
|
+
[EmitNullifier.opcode, Instruction.deserialize.bind(EmitNullifier)], // Notes & Nullifiers
|
|
124
|
+
[L1ToL2MessageExists.opcode, Instruction.deserialize.bind(L1ToL2MessageExists)], // Messages
|
|
125
|
+
|
|
126
|
+
// Accrued Substate
|
|
127
|
+
[EmitUnencryptedLog.opcode, Instruction.deserialize.bind(EmitUnencryptedLog)],
|
|
128
|
+
[SendL2ToL1Message.opcode, Instruction.deserialize.bind(SendL2ToL1Message)],
|
|
129
|
+
[GetContractInstance.opcode, Instruction.deserialize.bind(GetContractInstance)],
|
|
130
|
+
|
|
131
|
+
// Control Flow - Contract Calls
|
|
132
|
+
[Call.opcode, Instruction.deserialize.bind(Call)],
|
|
133
|
+
[StaticCall.opcode, Instruction.deserialize.bind(StaticCall)],
|
|
134
|
+
[Return.opcode, Instruction.deserialize.bind(Return)],
|
|
135
|
+
[Opcode.REVERT_8, Revert.as(Revert.wireFormat8).deserialize],
|
|
136
|
+
[Opcode.REVERT_16, Revert.as(Revert.wireFormat16).deserialize],
|
|
137
|
+
|
|
138
|
+
// Misc
|
|
139
|
+
[DebugLog.opcode, Instruction.deserialize.bind(DebugLog)],
|
|
140
|
+
|
|
141
|
+
// Gadgets
|
|
142
|
+
[EcAdd.opcode, Instruction.deserialize.bind(EcAdd)],
|
|
143
|
+
[Poseidon2.opcode, Instruction.deserialize.bind(Poseidon2)],
|
|
144
|
+
[Sha256Compression.opcode, Instruction.deserialize.bind(Sha256Compression)],
|
|
145
|
+
[KeccakF1600.opcode, Instruction.deserialize.bind(KeccakF1600)],
|
|
146
|
+
|
|
147
|
+
// Conversions
|
|
148
|
+
[ToRadixBE.opcode, Instruction.deserialize.bind(ToRadixBE)],
|
|
149
|
+
]);
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Serializes an array of instructions to bytecode.
|
|
153
|
+
*/
|
|
154
|
+
export function encodeToBytecode(instructions: Serializable[]): Buffer {
|
|
155
|
+
return Buffer.concat(instructions.map(i => i.serialize()));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// For testing only
|
|
159
|
+
export function decodeFromBytecode(bytecode: Buffer, instructionSet: InstructionSet = INSTRUCTION_SET): Instruction[] {
|
|
160
|
+
const instructions: Instruction[] = [];
|
|
161
|
+
let pc = 0;
|
|
162
|
+
while (pc < bytecode.length) {
|
|
163
|
+
const [instruction, bytesConsumed] = decodeInstructionFromBytecode(bytecode, pc, instructionSet);
|
|
164
|
+
instructions.push(instruction);
|
|
165
|
+
pc += bytesConsumed;
|
|
166
|
+
}
|
|
167
|
+
return instructions;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Returns the instruction and the number of bytes consumed.
|
|
171
|
+
export function decodeInstructionFromBytecode(
|
|
172
|
+
bytecode: Buffer,
|
|
173
|
+
pc: number,
|
|
174
|
+
instructionSet: InstructionSet = INSTRUCTION_SET,
|
|
175
|
+
): [Instruction, number] {
|
|
176
|
+
if (pc >= bytecode.length) {
|
|
177
|
+
throw new InvalidProgramCounterError(pc, bytecode.length);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
try {
|
|
181
|
+
const cursor = new BufferCursor(bytecode, pc);
|
|
182
|
+
const startingPosition = cursor.position();
|
|
183
|
+
const opcode: number = cursor.bufferAtPosition().readUint8(); // peek.
|
|
184
|
+
|
|
185
|
+
if (opcode > MAX_OPCODE_VALUE) {
|
|
186
|
+
throw new InvalidOpcodeError(
|
|
187
|
+
`Opcode ${opcode} (0x${opcode.toString(16)}) value is not in the range of valid opcodes.`,
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const instructionDeserializerOrUndef = instructionSet.get(opcode);
|
|
192
|
+
if (instructionDeserializerOrUndef === undefined) {
|
|
193
|
+
throw new InvalidOpcodeError(`Opcode ${Opcode[opcode]} (0x${opcode.toString(16)}) is not implemented`);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const instructionDeserializer: InstructionDeserializer = instructionDeserializerOrUndef;
|
|
197
|
+
const instruction = instructionDeserializer(cursor);
|
|
198
|
+
return [instruction, cursor.position() - startingPosition];
|
|
199
|
+
} catch (error) {
|
|
200
|
+
if (error instanceof InvalidOpcodeError || error instanceof AvmExecutionError) {
|
|
201
|
+
throw error;
|
|
202
|
+
} else {
|
|
203
|
+
throw new AvmParsingError(`${error}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|