@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,82 @@
|
|
|
1
|
+
import type { AvmContext } from '../avm_context.js';
|
|
2
|
+
import { Field, Uint64 } 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 EnvironmentVariable {
|
|
9
|
+
ADDRESS,
|
|
10
|
+
SENDER,
|
|
11
|
+
TRANSACTIONFEE,
|
|
12
|
+
CHAINID,
|
|
13
|
+
VERSION,
|
|
14
|
+
BLOCKNUMBER,
|
|
15
|
+
TIMESTAMP,
|
|
16
|
+
FEEPERL2GAS,
|
|
17
|
+
FEEPERDAGAS,
|
|
18
|
+
ISSTATICCALL,
|
|
19
|
+
L2GASLEFT,
|
|
20
|
+
DAGASLEFT,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getValue(e: EnvironmentVariable, ctx: AvmContext) {
|
|
24
|
+
switch (e) {
|
|
25
|
+
case EnvironmentVariable.ADDRESS:
|
|
26
|
+
return new Field(ctx.environment.address.toField());
|
|
27
|
+
case EnvironmentVariable.SENDER:
|
|
28
|
+
return new Field(ctx.environment.sender.toField());
|
|
29
|
+
case EnvironmentVariable.TRANSACTIONFEE:
|
|
30
|
+
return new Field(ctx.environment.transactionFee);
|
|
31
|
+
case EnvironmentVariable.CHAINID:
|
|
32
|
+
return new Field(ctx.environment.globals.chainId);
|
|
33
|
+
case EnvironmentVariable.VERSION:
|
|
34
|
+
return new Field(ctx.environment.globals.version);
|
|
35
|
+
case EnvironmentVariable.BLOCKNUMBER:
|
|
36
|
+
return new Field(ctx.environment.globals.blockNumber);
|
|
37
|
+
case EnvironmentVariable.TIMESTAMP:
|
|
38
|
+
return new Uint64(ctx.environment.globals.timestamp.toBigInt());
|
|
39
|
+
case EnvironmentVariable.FEEPERL2GAS:
|
|
40
|
+
return new Field(ctx.environment.globals.gasFees.feePerL2Gas);
|
|
41
|
+
case EnvironmentVariable.FEEPERDAGAS:
|
|
42
|
+
return new Field(ctx.environment.globals.gasFees.feePerDaGas);
|
|
43
|
+
case EnvironmentVariable.ISSTATICCALL:
|
|
44
|
+
return new Field(ctx.environment.isStaticCall ? 1 : 0);
|
|
45
|
+
case EnvironmentVariable.L2GASLEFT:
|
|
46
|
+
return new Field(ctx.machineState.l2GasLeft);
|
|
47
|
+
case EnvironmentVariable.DAGASLEFT:
|
|
48
|
+
return new Field(ctx.machineState.daGasLeft);
|
|
49
|
+
default:
|
|
50
|
+
throw new Error(`Unknown environment variable ${e}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export class GetEnvVar extends Instruction {
|
|
55
|
+
public static readonly type: string = 'GETENVVAR';
|
|
56
|
+
public static readonly opcode: Opcode = Opcode.GETENVVAR_16;
|
|
57
|
+
static readonly wireFormat16: OperandType[] = [
|
|
58
|
+
OperandType.UINT8, // opcode
|
|
59
|
+
OperandType.UINT8, // indirect
|
|
60
|
+
OperandType.UINT16, // dstOffset
|
|
61
|
+
OperandType.UINT8, // variable enum (immediate)
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
constructor(private indirect: number, private dstOffset: number, private varEnum: number) {
|
|
65
|
+
super();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
69
|
+
const memory = context.machineState.memory;
|
|
70
|
+
context.machineState.consumeGas(this.gasCost());
|
|
71
|
+
|
|
72
|
+
if (!(this.varEnum in EnvironmentVariable)) {
|
|
73
|
+
throw new InstructionExecutionError(`Invalid GETENVVAR var enum ${this.varEnum}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const operands = [this.dstOffset];
|
|
77
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
78
|
+
const [dstOffset] = addressing.resolve(operands, memory);
|
|
79
|
+
|
|
80
|
+
memory.set(dstOffset, getValue(this.varEnum as EnvironmentVariable, context));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import type { AvmContext } from '../avm_context.js';
|
|
2
|
+
import type { AvmContractCallResult } from '../avm_contract_call_result.js';
|
|
3
|
+
import { type Field, TypeTag, Uint1 } from '../avm_memory_types.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 ExternalCall extends Instruction {
|
|
9
|
+
// Informs (de)serialization. See Instruction.deserialize.
|
|
10
|
+
static readonly wireFormat: OperandType[] = [
|
|
11
|
+
OperandType.UINT8,
|
|
12
|
+
OperandType.UINT8, // Indirect
|
|
13
|
+
OperandType.UINT16,
|
|
14
|
+
OperandType.UINT16,
|
|
15
|
+
OperandType.UINT16,
|
|
16
|
+
OperandType.UINT16,
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
constructor(
|
|
20
|
+
private indirect: number,
|
|
21
|
+
private gasOffset: number,
|
|
22
|
+
private addrOffset: number,
|
|
23
|
+
private argsOffset: number,
|
|
24
|
+
private argsSizeOffset: number,
|
|
25
|
+
) {
|
|
26
|
+
super();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public async execute(context: AvmContext) {
|
|
30
|
+
const memory = context.machineState.memory;
|
|
31
|
+
const operands = [this.gasOffset, this.addrOffset, this.argsOffset, this.argsSizeOffset];
|
|
32
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
33
|
+
const [gasOffset, addrOffset, argsOffset, argsSizeOffset] = addressing.resolve(operands, memory);
|
|
34
|
+
memory.checkTags(TypeTag.FIELD, gasOffset, gasOffset + 1);
|
|
35
|
+
memory.checkTag(TypeTag.FIELD, addrOffset);
|
|
36
|
+
memory.checkTag(TypeTag.UINT32, argsSizeOffset);
|
|
37
|
+
|
|
38
|
+
const calldataSize = memory.get(argsSizeOffset).toNumber();
|
|
39
|
+
const calldata = memory.getSlice(argsOffset, calldataSize).map(f => f.toFr());
|
|
40
|
+
memory.checkTagsRange(TypeTag.FIELD, argsOffset, calldataSize);
|
|
41
|
+
|
|
42
|
+
const callAddress = memory.getAs<Field>(addrOffset);
|
|
43
|
+
// If we are already in a static call, we propagate the environment.
|
|
44
|
+
const callType = context.environment.isStaticCall ? 'STATICCALL' : this.type;
|
|
45
|
+
|
|
46
|
+
// First we consume the gas for this operation.
|
|
47
|
+
context.machineState.consumeGas(this.gasCost(calldataSize));
|
|
48
|
+
// Then we consume the gas allocated for the nested call. The excess will be refunded later.
|
|
49
|
+
// Gas allocation is capped by the amount of gas left in the current context.
|
|
50
|
+
// We have to do some dancing here because the gas allocation is a field,
|
|
51
|
+
// but in the machine state we track gas as a number.
|
|
52
|
+
const allocatedL2Gas = Number(BigIntMin(memory.get(gasOffset).toBigInt(), BigInt(context.machineState.l2GasLeft)));
|
|
53
|
+
const allocatedDaGas = Number(
|
|
54
|
+
BigIntMin(memory.get(gasOffset + 1).toBigInt(), BigInt(context.machineState.daGasLeft)),
|
|
55
|
+
);
|
|
56
|
+
const allocatedGas = { l2Gas: allocatedL2Gas, daGas: allocatedDaGas };
|
|
57
|
+
context.machineState.consumeGas(allocatedGas);
|
|
58
|
+
|
|
59
|
+
const aztecAddress = callAddress.toAztecAddress();
|
|
60
|
+
const nestedContext = await context.createNestedContractCallContext(aztecAddress, calldata, allocatedGas, callType);
|
|
61
|
+
|
|
62
|
+
const simulator = await context.provideSimulator!(nestedContext);
|
|
63
|
+
const nestedCallResults: AvmContractCallResult = await simulator.execute();
|
|
64
|
+
const success = !nestedCallResults.reverted;
|
|
65
|
+
|
|
66
|
+
// Save return/revert data for later.
|
|
67
|
+
const fullReturnData = nestedCallResults.output;
|
|
68
|
+
context.machineState.nestedReturndata = fullReturnData;
|
|
69
|
+
|
|
70
|
+
// Track the success status directly
|
|
71
|
+
context.machineState.nestedCallSuccess = success;
|
|
72
|
+
|
|
73
|
+
// If the nested call reverted, we try to save the reason and the revert data.
|
|
74
|
+
// This will be used by the caller to try to reconstruct the call stack.
|
|
75
|
+
// This is only a heuristic and may not always work. It is intended to work
|
|
76
|
+
// for the case where a nested call reverts and the caller always rethrows
|
|
77
|
+
// (in Noir code).
|
|
78
|
+
if (!success) {
|
|
79
|
+
context.machineState.collectedRevertInfo = {
|
|
80
|
+
revertDataRepresentative: fullReturnData,
|
|
81
|
+
recursiveRevertReason: nestedCallResults.revertReason!,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Refund unused gas
|
|
86
|
+
context.machineState.refundGas(nestedCallResults.gasLeft);
|
|
87
|
+
|
|
88
|
+
// Merge nested call's state and trace based on whether it succeeded.
|
|
89
|
+
if (success) {
|
|
90
|
+
await context.persistableState.merge(nestedContext.persistableState);
|
|
91
|
+
} else {
|
|
92
|
+
await context.persistableState.reject(nestedContext.persistableState);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public abstract override get type(): 'CALL' | 'STATICCALL';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export class Call extends ExternalCall {
|
|
100
|
+
static type = 'CALL' as const;
|
|
101
|
+
static readonly opcode: Opcode = Opcode.CALL;
|
|
102
|
+
|
|
103
|
+
public get type() {
|
|
104
|
+
return Call.type;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export class StaticCall extends ExternalCall {
|
|
109
|
+
static type = 'STATICCALL' as const;
|
|
110
|
+
static readonly opcode: Opcode = Opcode.STATICCALL;
|
|
111
|
+
|
|
112
|
+
public get type() {
|
|
113
|
+
return StaticCall.type;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export class SuccessCopy extends Instruction {
|
|
118
|
+
static type: string = 'SUCCESSCOPY';
|
|
119
|
+
static readonly opcode: Opcode = Opcode.SUCCESSCOPY;
|
|
120
|
+
// Informs (de)serialization. See Instruction.deserialize.
|
|
121
|
+
static readonly wireFormat: OperandType[] = [
|
|
122
|
+
OperandType.UINT8,
|
|
123
|
+
OperandType.UINT8, // Indirect (8-bit)
|
|
124
|
+
OperandType.UINT16, // dstOffset (16-bit)
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
constructor(private indirect: number, private dstOffset: number) {
|
|
128
|
+
super();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
132
|
+
const memory = context.machineState.memory;
|
|
133
|
+
|
|
134
|
+
const operands = [this.dstOffset];
|
|
135
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
136
|
+
const [dstOffset] = addressing.resolve(operands, memory);
|
|
137
|
+
|
|
138
|
+
// Use the direct success tracking property
|
|
139
|
+
const success = context.machineState.nestedCallSuccess;
|
|
140
|
+
|
|
141
|
+
// Write the success flag to the provided memory location
|
|
142
|
+
memory.set(dstOffset, new Uint1(success ? 1 : 0));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export class Return extends Instruction {
|
|
147
|
+
static type: string = 'RETURN';
|
|
148
|
+
static readonly opcode: Opcode = Opcode.RETURN;
|
|
149
|
+
// Informs (de)serialization. See Instruction.deserialize.
|
|
150
|
+
static readonly wireFormat: OperandType[] = [
|
|
151
|
+
OperandType.UINT8,
|
|
152
|
+
OperandType.UINT8,
|
|
153
|
+
OperandType.UINT16,
|
|
154
|
+
OperandType.UINT16,
|
|
155
|
+
];
|
|
156
|
+
|
|
157
|
+
constructor(private indirect: number, private returnOffset: number, private returnSizeOffset: number) {
|
|
158
|
+
super();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
162
|
+
const memory = context.machineState.memory;
|
|
163
|
+
|
|
164
|
+
const operands = [this.returnOffset, this.returnSizeOffset];
|
|
165
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
166
|
+
const [returnOffset, returnSizeOffset] = addressing.resolve(operands, memory);
|
|
167
|
+
|
|
168
|
+
memory.checkTag(TypeTag.UINT32, returnSizeOffset);
|
|
169
|
+
const returnSize = memory.get(returnSizeOffset).toNumber();
|
|
170
|
+
context.machineState.consumeGas(this.gasCost(returnSize));
|
|
171
|
+
|
|
172
|
+
const output = memory.getSlice(returnOffset, returnSize).map(word => word.toFr());
|
|
173
|
+
|
|
174
|
+
context.machineState.return(output);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
public override handlesPC(): boolean {
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export class Revert extends Instruction {
|
|
183
|
+
static type: string = 'REVERT';
|
|
184
|
+
static readonly opcode: Opcode = Opcode.REVERT_8;
|
|
185
|
+
|
|
186
|
+
static readonly wireFormat8: OperandType[] = [
|
|
187
|
+
OperandType.UINT8,
|
|
188
|
+
OperandType.UINT8,
|
|
189
|
+
OperandType.UINT8,
|
|
190
|
+
OperandType.UINT8,
|
|
191
|
+
];
|
|
192
|
+
static readonly wireFormat16: OperandType[] = [
|
|
193
|
+
OperandType.UINT8,
|
|
194
|
+
OperandType.UINT8,
|
|
195
|
+
OperandType.UINT16,
|
|
196
|
+
OperandType.UINT16,
|
|
197
|
+
];
|
|
198
|
+
|
|
199
|
+
constructor(private indirect: number, private returnOffset: number, private retSizeOffset: number) {
|
|
200
|
+
super();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
204
|
+
const memory = context.machineState.memory;
|
|
205
|
+
|
|
206
|
+
const operands = [this.returnOffset, this.retSizeOffset];
|
|
207
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
208
|
+
const [returnOffset, retSizeOffset] = addressing.resolve(operands, memory);
|
|
209
|
+
|
|
210
|
+
memory.checkTag(TypeTag.UINT32, retSizeOffset);
|
|
211
|
+
const retSize = memory.get(retSizeOffset).toNumber();
|
|
212
|
+
context.machineState.consumeGas(this.gasCost(retSize));
|
|
213
|
+
const output = memory.getSlice(returnOffset, retSize).map(word => word.toFr());
|
|
214
|
+
|
|
215
|
+
context.machineState.revert(output);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// We don't want to increase the PC after reverting because it breaks messages.
|
|
219
|
+
// Maybe we can remove this once messages don't depend on PCs.
|
|
220
|
+
public override handlesPC(): boolean {
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** Returns the smaller of two bigints. */
|
|
226
|
+
function BigIntMin(a: bigint, b: bigint): bigint {
|
|
227
|
+
return a < b ? a : b;
|
|
228
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { keccakf1600, poseidon2Permutation, sha256Compression } from '@aztec/foundation/crypto';
|
|
2
|
+
|
|
3
|
+
import type { AvmContext } from '../avm_context.js';
|
|
4
|
+
import { Field, TypeTag, Uint32, Uint64 } 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 Poseidon2 extends Instruction {
|
|
10
|
+
static type: string = 'POSEIDON2';
|
|
11
|
+
static readonly opcode: Opcode = Opcode.POSEIDON2;
|
|
12
|
+
static readonly stateSize = 4;
|
|
13
|
+
|
|
14
|
+
// Informs (de)serialization. See Instruction.deserialize.
|
|
15
|
+
static readonly wireFormat: OperandType[] = [
|
|
16
|
+
OperandType.UINT8,
|
|
17
|
+
OperandType.UINT8,
|
|
18
|
+
OperandType.UINT16,
|
|
19
|
+
OperandType.UINT16,
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
constructor(private indirect: number, private inputStateOffset: number, private outputStateOffset: number) {
|
|
23
|
+
super();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
27
|
+
const memory = context.machineState.memory;
|
|
28
|
+
context.machineState.consumeGas(this.gasCost());
|
|
29
|
+
|
|
30
|
+
const operands = [this.inputStateOffset, this.outputStateOffset];
|
|
31
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
32
|
+
const [inputOffset, outputOffset] = addressing.resolve(operands, memory);
|
|
33
|
+
|
|
34
|
+
const inputState = memory.getSlice(inputOffset, Poseidon2.stateSize);
|
|
35
|
+
memory.checkTagsRange(TypeTag.FIELD, inputOffset, Poseidon2.stateSize);
|
|
36
|
+
|
|
37
|
+
const outputState = await poseidon2Permutation(inputState);
|
|
38
|
+
memory.setSlice(
|
|
39
|
+
outputOffset,
|
|
40
|
+
outputState.map(word => new Field(word)),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export class KeccakF1600 extends Instruction {
|
|
46
|
+
static type: string = 'KECCAKF1600';
|
|
47
|
+
static readonly opcode: Opcode = Opcode.KECCAKF1600;
|
|
48
|
+
|
|
49
|
+
// Informs (de)serialization. See Instruction.deserialize.
|
|
50
|
+
static readonly wireFormat: OperandType[] = [
|
|
51
|
+
OperandType.UINT8,
|
|
52
|
+
OperandType.UINT8,
|
|
53
|
+
OperandType.UINT16,
|
|
54
|
+
OperandType.UINT16,
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
constructor(private indirect: number, private dstOffset: number, private inputOffset: number) {
|
|
58
|
+
super();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// pub fn keccakf1600(input: [u64; 25]) -> [u64; 25]
|
|
62
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
63
|
+
const inputSize = 25;
|
|
64
|
+
const memory = context.machineState.memory;
|
|
65
|
+
const operands = [this.dstOffset, this.inputOffset];
|
|
66
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
67
|
+
const [dstOffset, inputOffset] = addressing.resolve(operands, memory);
|
|
68
|
+
context.machineState.consumeGas(this.gasCost());
|
|
69
|
+
|
|
70
|
+
const stateData = memory.getSlice(inputOffset, inputSize).map(word => word.toBigInt());
|
|
71
|
+
memory.checkTagsRange(TypeTag.UINT64, inputOffset, inputSize);
|
|
72
|
+
|
|
73
|
+
const updatedState = keccakf1600(stateData);
|
|
74
|
+
|
|
75
|
+
const res = updatedState.map(word => new Uint64(word));
|
|
76
|
+
memory.setSlice(dstOffset, res);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export class Sha256Compression extends Instruction {
|
|
81
|
+
static type: string = 'SHA256COMPRESSION';
|
|
82
|
+
static readonly opcode: Opcode = Opcode.SHA256COMPRESSION;
|
|
83
|
+
|
|
84
|
+
// Informs (de)serialization. See Instruction.deserialize.
|
|
85
|
+
static readonly wireFormat: OperandType[] = [
|
|
86
|
+
OperandType.UINT8,
|
|
87
|
+
OperandType.UINT8,
|
|
88
|
+
OperandType.UINT16,
|
|
89
|
+
OperandType.UINT16,
|
|
90
|
+
OperandType.UINT16,
|
|
91
|
+
];
|
|
92
|
+
|
|
93
|
+
constructor(
|
|
94
|
+
private indirect: number,
|
|
95
|
+
private outputOffset: number,
|
|
96
|
+
private stateOffset: number,
|
|
97
|
+
private inputsOffset: number,
|
|
98
|
+
) {
|
|
99
|
+
super();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public async execute(context: AvmContext): Promise<void> {
|
|
103
|
+
const STATE_SIZE = 8;
|
|
104
|
+
const INPUTS_SIZE = 16;
|
|
105
|
+
|
|
106
|
+
const memory = context.machineState.memory;
|
|
107
|
+
const operands = [this.outputOffset, this.stateOffset, this.inputsOffset];
|
|
108
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
109
|
+
const [outputOffset, stateOffset, inputsOffset] = addressing.resolve(operands, memory);
|
|
110
|
+
|
|
111
|
+
// Note: size of output is same as size of state
|
|
112
|
+
context.machineState.consumeGas(this.gasCost());
|
|
113
|
+
const inputs = Uint32Array.from(memory.getSlice(inputsOffset, INPUTS_SIZE).map(word => word.toNumber()));
|
|
114
|
+
const state = Uint32Array.from(memory.getSlice(stateOffset, STATE_SIZE).map(word => word.toNumber()));
|
|
115
|
+
|
|
116
|
+
memory.checkTagsRange(TypeTag.UINT32, inputsOffset, INPUTS_SIZE);
|
|
117
|
+
memory.checkTagsRange(TypeTag.UINT32, stateOffset, STATE_SIZE);
|
|
118
|
+
|
|
119
|
+
const output = sha256Compression(state, inputs);
|
|
120
|
+
|
|
121
|
+
// Conversion required from Uint32Array to Uint32[] (can't map directly, need `...`)
|
|
122
|
+
const res = [...output].map(word => new Uint32(word));
|
|
123
|
+
memory.setSlice(outputOffset, res);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './arithmetic.js';
|
|
2
|
+
export * from './bitwise.js';
|
|
3
|
+
export * from './control_flow.js';
|
|
4
|
+
export * from './contract.js';
|
|
5
|
+
export * from './conversion.js';
|
|
6
|
+
export * from './instruction.js';
|
|
7
|
+
export * from './comparators.js';
|
|
8
|
+
export * from './memory.js';
|
|
9
|
+
export * from './misc.js';
|
|
10
|
+
export * from './storage.js';
|
|
11
|
+
export * from './external_calls.js';
|
|
12
|
+
export * from './environment_getters.js';
|
|
13
|
+
export * from './accrued_substate.js';
|
|
14
|
+
export * from './hashing.js';
|
|
15
|
+
export * from './ec_add.js';
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { strict as assert } from 'assert';
|
|
2
|
+
|
|
3
|
+
import type { AvmContext } from '../avm_context.js';
|
|
4
|
+
import { type Gas, getBaseGasCost, getDynamicGasCost, mulGas, sumGas } from '../avm_gas.js';
|
|
5
|
+
import type { BufferCursor } from '../serialization/buffer_cursor.js';
|
|
6
|
+
import type { Serializable } from '../serialization/bytecode_serialization.js';
|
|
7
|
+
import { Opcode, type OperandType, deserialize, serializeAs } from '../serialization/instruction_serialization.js';
|
|
8
|
+
|
|
9
|
+
type InstructionConstructor = {
|
|
10
|
+
new (...args: any[]): Instruction;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Parent class for all AVM instructions.
|
|
15
|
+
* It's most important aspects are execute and (de)serialize.
|
|
16
|
+
*/
|
|
17
|
+
export abstract class Instruction {
|
|
18
|
+
/**
|
|
19
|
+
* Consumes gas and executes the instruction.
|
|
20
|
+
* This is the main entry point for the instruction.
|
|
21
|
+
* @param context - The AvmContext in which the instruction executes.
|
|
22
|
+
*/
|
|
23
|
+
public abstract execute(context: AvmContext): Promise<void>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Whether the instruction will modify the PC itself.
|
|
27
|
+
*/
|
|
28
|
+
public handlesPC(): boolean {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Generate a string representation of the instruction including
|
|
34
|
+
* the instruction sub-class name all of its flags and operands.
|
|
35
|
+
* @returns Thee string representation.
|
|
36
|
+
*/
|
|
37
|
+
public toString(): string {
|
|
38
|
+
let instructionStr = this.constructor.name + ': ';
|
|
39
|
+
// assumes that all properties are flags or operands
|
|
40
|
+
for (const prop of Object.getOwnPropertyNames(this) as (keyof Instruction)[]) {
|
|
41
|
+
instructionStr += `${prop}:${this[prop].toString()}, `;
|
|
42
|
+
}
|
|
43
|
+
return instructionStr;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Default deserialization which uses Class.opcode and Class.wireFormat.
|
|
47
|
+
public static deserialize(
|
|
48
|
+
this: InstructionConstructor & { wireFormat: OperandType[]; as: any },
|
|
49
|
+
buf: BufferCursor | Buffer,
|
|
50
|
+
): Instruction {
|
|
51
|
+
return this.as(this.wireFormat).deserialize(buf);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Default serialization which uses Class.opcode and Class.wireFormat.
|
|
55
|
+
public serialize(): Buffer {
|
|
56
|
+
const klass = this.constructor as any;
|
|
57
|
+
assert(klass.opcode !== undefined && klass.opcode !== null);
|
|
58
|
+
assert(klass.wireFormat !== undefined && klass.wireFormat !== null);
|
|
59
|
+
return this.as(klass.opcode, klass.wireFormat).serialize();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Returns a new instruction instance that can be serialized with the given opcode and wire format.
|
|
64
|
+
* @param opcode The opcode of the instruction.
|
|
65
|
+
* @param wireFormat The wire format of the instruction.
|
|
66
|
+
* @returns The new instruction instance.
|
|
67
|
+
*/
|
|
68
|
+
public as(opcode: Opcode, wireFormat: OperandType[]): Instruction & Serializable {
|
|
69
|
+
return Object.defineProperty(this, 'serialize', {
|
|
70
|
+
value: (): Buffer => {
|
|
71
|
+
return serializeAs(wireFormat, opcode, this);
|
|
72
|
+
},
|
|
73
|
+
enumerable: false,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Returns a new instruction class that can be deserialized with the given opcode and wire format.
|
|
79
|
+
* @param opcode The opcode of the instruction.
|
|
80
|
+
* @param wireFormat The wire format of the instruction.
|
|
81
|
+
* @returns The new instruction class.
|
|
82
|
+
*/
|
|
83
|
+
public static as(this: InstructionConstructor, wireFormat: OperandType[]) {
|
|
84
|
+
return Object.assign(this, {
|
|
85
|
+
deserialize: (buf: BufferCursor | Buffer): Instruction => {
|
|
86
|
+
const res = deserialize(buf, wireFormat);
|
|
87
|
+
const args = res.slice(1); // Remove opcode.
|
|
88
|
+
return new this(...args);
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Computes gas cost for the instruction based on its base cost and memory operations.
|
|
95
|
+
* @returns Gas cost.
|
|
96
|
+
*/
|
|
97
|
+
protected gasCost(dynMultiplier: number = 0): Gas {
|
|
98
|
+
const baseGasCost = getBaseGasCost(this.opcode);
|
|
99
|
+
const dynGasCost = mulGas(getDynamicGasCost(this.opcode), dynMultiplier);
|
|
100
|
+
return sumGas(baseGasCost, dynGasCost);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Returns the stringified type of the instruction.
|
|
105
|
+
* Instruction sub-classes should have a static `type` property.
|
|
106
|
+
*/
|
|
107
|
+
public get type(): string {
|
|
108
|
+
const type = 'type' in this.constructor && (this.constructor.type as string);
|
|
109
|
+
if (!type) {
|
|
110
|
+
throw new Error(`Instruction class ${this.constructor.name} does not have a static 'type' property defined.`);
|
|
111
|
+
}
|
|
112
|
+
return type;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Returns the opcode of the instruction.
|
|
117
|
+
* Instruction sub-classes should have a static `opcode` property.
|
|
118
|
+
*/
|
|
119
|
+
public get opcode(): Opcode {
|
|
120
|
+
const opcode = 'opcode' in this.constructor ? (this.constructor.opcode as Opcode) : undefined;
|
|
121
|
+
if (opcode === undefined || Opcode[opcode] === undefined) {
|
|
122
|
+
throw new Error(`Instruction class ${this.constructor.name} does not have a static 'opcode' property defined.`);
|
|
123
|
+
}
|
|
124
|
+
return opcode;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { OperandType } from '../serialization/instruction_serialization.js';
|
|
2
|
+
import { Instruction } from './instruction.js';
|
|
3
|
+
|
|
4
|
+
/** Wire format that informs deserialization for instructions with three operands. */
|
|
5
|
+
export const ThreeOperandWireFormat8 = [
|
|
6
|
+
OperandType.UINT8,
|
|
7
|
+
OperandType.UINT8,
|
|
8
|
+
OperandType.UINT8,
|
|
9
|
+
OperandType.UINT8,
|
|
10
|
+
OperandType.UINT8,
|
|
11
|
+
];
|
|
12
|
+
export const ThreeOperandWireFormat16 = [
|
|
13
|
+
OperandType.UINT8,
|
|
14
|
+
OperandType.UINT8,
|
|
15
|
+
OperandType.UINT16,
|
|
16
|
+
OperandType.UINT16,
|
|
17
|
+
OperandType.UINT16,
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Covers (de)serialization for an instruction with:
|
|
22
|
+
* indirect, inTag, and three operands.
|
|
23
|
+
*/
|
|
24
|
+
export abstract class ThreeOperandInstruction extends Instruction {
|
|
25
|
+
static readonly wireFormat8: OperandType[] = ThreeOperandWireFormat8;
|
|
26
|
+
static readonly wireFormat16: OperandType[] = ThreeOperandWireFormat16;
|
|
27
|
+
|
|
28
|
+
constructor(
|
|
29
|
+
protected indirect: number,
|
|
30
|
+
protected aOffset: number,
|
|
31
|
+
protected bOffset: number,
|
|
32
|
+
protected dstOffset: number,
|
|
33
|
+
) {
|
|
34
|
+
super();
|
|
35
|
+
}
|
|
36
|
+
}
|