@aztec/simulator 0.0.0-test.1 → 0.0.1-commit.5daedc8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dest/client.d.ts +6 -4
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +4 -2
- package/dest/common/errors.d.ts +5 -14
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/common/errors.js +51 -32
- package/dest/common/index.d.ts +1 -2
- package/dest/common/index.d.ts.map +1 -1
- package/dest/common/index.js +0 -1
- package/dest/common/stats/index.d.ts +1 -1
- package/dest/common/stats/stats.d.ts +1 -1
- package/dest/private/acvm/acvm.d.ts +12 -6
- package/dest/private/acvm/acvm.d.ts.map +1 -1
- package/dest/private/acvm/acvm.js +10 -16
- package/dest/private/acvm/acvm_types.d.ts +2 -2
- package/dest/private/acvm/acvm_types.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.d.ts +18 -19
- package/dest/private/acvm/deserialize.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.js +31 -23
- package/dest/private/acvm/index.d.ts +1 -2
- package/dest/private/acvm/index.d.ts.map +1 -1
- package/dest/private/acvm/index.js +0 -1
- package/dest/private/acvm/serialize.d.ts +20 -3
- package/dest/private/acvm/serialize.d.ts.map +1 -1
- package/dest/private/acvm/serialize.js +53 -0
- package/dest/private/acvm_native.d.ts +39 -0
- package/dest/private/acvm_native.d.ts.map +1 -0
- package/dest/private/{providers/acvm_native.js → acvm_native.js} +26 -20
- package/dest/private/acvm_wasm.d.ts +15 -0
- package/dest/private/acvm_wasm.d.ts.map +1 -0
- package/dest/private/{providers/acvm_wasm.js → acvm_wasm.js} +22 -19
- package/dest/private/acvm_wasm_with_blobs.d.ts +20 -0
- package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -0
- package/dest/private/acvm_wasm_with_blobs.js +35 -0
- package/dest/private/circuit_recording/circuit_recorder.d.ts +108 -0
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -0
- package/dest/private/circuit_recording/circuit_recorder.js +209 -0
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts +31 -0
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -0
- package/dest/private/circuit_recording/file_circuit_recorder.js +135 -0
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +5 -0
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -0
- package/dest/private/circuit_recording/memory_circuit_recorder.js +9 -0
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +21 -0
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -0
- package/dest/private/circuit_recording/simulator_recorder_wrapper.js +44 -0
- package/dest/private/circuit_simulator.d.ts +35 -0
- package/dest/private/circuit_simulator.d.ts.map +1 -0
- package/dest/private/circuit_simulator.js +43 -0
- package/dest/private/factory.d.ts +12 -0
- package/dest/private/factory.d.ts.map +1 -0
- package/dest/private/{providers/factory.js → factory.js} +2 -2
- package/dest/public/avm/avm_context.d.ts +6 -6
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts +5 -3
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.js +11 -7
- package/dest/public/avm/avm_execution_environment.d.ts +4 -2
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.js +4 -2
- package/dest/public/avm/avm_gas.d.ts +5 -21
- package/dest/public/avm/avm_gas.d.ts.map +1 -1
- package/dest/public/avm/avm_gas.js +27 -35
- package/dest/public/avm/avm_machine_state.d.ts +3 -1
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.js +2 -0
- package/dest/public/avm/avm_memory_types.d.ts +99 -88
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.js +17 -6
- package/dest/public/avm/avm_simulator.d.ts +6 -6
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +23 -35
- package/dest/public/avm/avm_simulator_interface.d.ts +9 -0
- package/dest/public/avm/avm_simulator_interface.d.ts.map +1 -0
- package/dest/public/avm/avm_simulator_interface.js +3 -0
- package/dest/public/avm/errors.d.ts +7 -31
- package/dest/public/avm/errors.d.ts.map +1 -1
- package/dest/public/avm/errors.js +7 -57
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +6 -5
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +22 -15
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +7 -5
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +37 -14
- package/dest/public/avm/fixtures/initializers.d.ts +42 -0
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -0
- package/dest/public/avm/fixtures/initializers.js +44 -0
- package/dest/public/avm/fixtures/utils.d.ts +38 -0
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -0
- package/dest/public/avm/fixtures/utils.js +95 -0
- package/dest/public/avm/index.d.ts +1 -3
- package/dest/public/avm/index.d.ts.map +1 -1
- package/dest/public/avm/index.js +0 -2
- package/dest/public/avm/opcodes/accrued_substate.d.ts +3 -3
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +28 -25
- package/dest/public/avm/opcodes/addressing_mode.d.ts +12 -8
- package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/public/avm/opcodes/addressing_mode.js +46 -26
- package/dest/public/avm/opcodes/arithmetic.d.ts +17 -7
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.js +16 -2
- package/dest/public/avm/opcodes/bitwise.d.ts +10 -18
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/public/avm/opcodes/bitwise.js +19 -26
- package/dest/public/avm/opcodes/comparators.d.ts +4 -4
- package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/public/avm/opcodes/comparators.js +3 -3
- package/dest/public/avm/opcodes/contract.d.ts +2 -3
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/contract.js +9 -10
- package/dest/public/avm/opcodes/control_flow.d.ts +1 -1
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/public/avm/opcodes/control_flow.js +10 -8
- package/dest/public/avm/opcodes/conversion.d.ts +2 -1
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.js +267 -3
- package/dest/public/avm/opcodes/ec_add.d.ts +2 -2
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.js +6 -6
- package/dest/public/avm/opcodes/environment_getters.d.ts +3 -3
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/environment_getters.js +17 -19
- package/dest/public/avm/opcodes/external_calls.d.ts +9 -8
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +39 -34
- package/dest/public/avm/opcodes/hashing.d.ts +2 -2
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/public/avm/opcodes/hashing.js +6 -6
- package/dest/public/avm/opcodes/index.d.ts +1 -1
- package/dest/public/avm/opcodes/instruction.d.ts +15 -11
- package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/public/avm/opcodes/instruction.js +23 -19
- package/dest/public/avm/opcodes/instruction_impl.d.ts +1 -1
- package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.d.ts +6 -6
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +37 -33
- package/dest/public/avm/opcodes/misc.d.ts +3 -2
- package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/public/avm/opcodes/misc.js +41 -16
- package/dest/public/avm/opcodes/storage.d.ts +3 -3
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/public/avm/opcodes/storage.js +7 -5
- package/dest/public/avm/revert_reason.d.ts +18 -0
- package/dest/public/avm/revert_reason.d.ts.map +1 -0
- package/dest/public/avm/revert_reason.js +38 -0
- package/dest/public/avm/serialization/buffer_cursor.d.ts +1 -3
- package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.d.ts +3 -7
- package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.js +70 -69
- package/dest/public/avm/serialization/instruction_serialization.d.ts +14 -5
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +70 -35
- package/dest/public/avm/test_utils.d.ts +11 -14
- package/dest/public/avm/test_utils.d.ts.map +1 -1
- package/dest/public/avm/test_utils.js +16 -24
- package/dest/public/contracts_db_checkpoint.d.ts +16 -0
- package/dest/public/contracts_db_checkpoint.d.ts.map +1 -0
- package/dest/public/contracts_db_checkpoint.js +30 -0
- package/dest/public/db_interfaces.d.ts +68 -0
- package/dest/public/db_interfaces.d.ts.map +1 -0
- package/dest/public/db_interfaces.js +3 -0
- package/dest/public/debug_fn_name.d.ts +5 -0
- package/dest/public/debug_fn_name.d.ts.map +1 -0
- package/dest/public/debug_fn_name.js +9 -0
- package/dest/public/executor_metrics.d.ts +12 -4
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +37 -6
- package/dest/public/executor_metrics_interface.d.ts +10 -0
- package/dest/public/executor_metrics_interface.d.ts.map +1 -0
- package/dest/public/executor_metrics_interface.js +1 -0
- package/dest/public/fixtures/amm_test.d.ts +10 -0
- package/dest/public/fixtures/amm_test.d.ts.map +1 -0
- package/dest/public/fixtures/amm_test.js +213 -0
- package/dest/public/fixtures/bulk_test.d.ts +6 -0
- package/dest/public/fixtures/bulk_test.d.ts.map +1 -0
- package/dest/public/fixtures/bulk_test.js +326 -0
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +12 -0
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -0
- package/dest/public/fixtures/custom_bytecode_tester.js +29 -0
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +9 -0
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -0
- package/dest/public/fixtures/custom_bytecode_tests.js +109 -0
- package/dest/public/fixtures/index.d.ts +8 -1
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +7 -0
- package/dest/public/fixtures/minimal_public_tx.d.ts +9 -0
- package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -0
- package/dest/public/fixtures/minimal_public_tx.js +29 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +35 -14
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +100 -71
- package/dest/public/fixtures/simple_contract_data_source.d.ts +35 -0
- package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -0
- package/dest/public/{avm/fixtures → fixtures}/simple_contract_data_source.js +31 -10
- package/dest/public/fixtures/token_test.d.ts +8 -0
- package/dest/public/fixtures/token_test.d.ts.map +1 -0
- package/dest/public/fixtures/token_test.js +94 -0
- package/dest/public/fixtures/utils.d.ts +17 -4
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +100 -58
- package/dest/public/hinting_db_sources.d.ts +78 -0
- package/dest/public/hinting_db_sources.d.ts.map +1 -0
- package/dest/public/hinting_db_sources.js +350 -0
- package/dest/public/index.d.ts +6 -9
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +4 -7
- package/dest/public/public_db_sources.d.ts +51 -101
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +219 -192
- package/dest/public/public_errors.d.ts +12 -0
- package/dest/public/public_errors.d.ts.map +1 -0
- package/dest/public/public_errors.js +13 -0
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +49 -0
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -0
- package/dest/public/public_processor/guarded_merkle_tree.js +108 -0
- package/dest/public/public_processor/public_processor.d.ts +25 -37
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +154 -111
- package/dest/public/public_processor/public_processor_metrics.d.ts +3 -3
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor_metrics.js +1 -1
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +30 -0
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +133 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +66 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +210 -0
- package/dest/public/public_tx_simulator/index.d.ts +5 -0
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/index.js +2 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +31 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +51 -0
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +23 -30
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +71 -91
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +36 -58
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +208 -206
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +9 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.js +1 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +21 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +39 -0
- package/dest/public/side_effect_errors.d.ts +42 -2
- package/dest/public/side_effect_errors.d.ts.map +1 -1
- package/dest/public/side_effect_errors.js +70 -1
- package/dest/public/side_effect_trace.d.ts +21 -67
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +71 -121
- package/dest/public/side_effect_trace_interface.d.ts +12 -24
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/state_manager/index.d.ts +2 -0
- package/dest/public/state_manager/index.d.ts.map +1 -0
- package/dest/public/state_manager/index.js +1 -0
- package/dest/public/{avm/journal → state_manager}/nullifiers.d.ts +3 -6
- package/dest/public/state_manager/nullifiers.d.ts.map +1 -0
- package/dest/public/{avm/journal → state_manager}/nullifiers.js +3 -8
- package/dest/public/{avm/journal → state_manager}/public_storage.d.ts +3 -3
- package/dest/public/state_manager/public_storage.d.ts.map +1 -0
- package/dest/public/state_manager/state_manager.d.ts +159 -0
- package/dest/public/state_manager/state_manager.d.ts.map +1 -0
- package/dest/public/state_manager/state_manager.js +392 -0
- package/dest/public/test_executor_metrics.d.ts +55 -0
- package/dest/public/test_executor_metrics.d.ts.map +1 -0
- package/dest/public/test_executor_metrics.js +307 -0
- package/dest/public/unique_class_ids.d.ts +1 -1
- package/dest/public/unique_class_ids.d.ts.map +1 -1
- package/dest/public/utils.d.ts +3 -5
- package/dest/public/utils.d.ts.map +1 -1
- package/dest/public/utils.js +4 -21
- package/dest/server.d.ts +7 -4
- package/dest/server.d.ts.map +1 -1
- package/dest/server.js +5 -2
- package/dest/testing.d.ts +2 -0
- package/dest/testing.d.ts.map +1 -0
- package/dest/testing.js +1 -0
- package/package.json +39 -33
- package/src/client.ts +5 -3
- package/src/common/errors.ts +79 -44
- package/src/common/index.ts +0 -1
- package/src/private/acvm/acvm.ts +17 -32
- package/src/private/acvm/acvm_types.ts +1 -1
- package/src/private/acvm/deserialize.ts +35 -29
- package/src/private/acvm/index.ts +0 -1
- package/src/private/acvm/serialize.ts +63 -0
- package/src/private/{providers/acvm_native.ts → acvm_native.ts} +47 -24
- package/src/private/acvm_wasm.ts +72 -0
- package/src/private/acvm_wasm_with_blobs.ts +54 -0
- package/src/private/circuit_recording/circuit_recorder.ts +260 -0
- package/src/private/circuit_recording/file_circuit_recorder.ts +158 -0
- package/src/private/circuit_recording/memory_circuit_recorder.ts +11 -0
- package/src/private/circuit_recording/simulator_recorder_wrapper.ts +91 -0
- package/src/private/circuit_simulator.ts +90 -0
- package/src/private/{providers/factory.ts → factory.ts} +6 -6
- package/src/public/avm/avm_context.ts +4 -4
- package/src/public/avm/avm_contract_call_result.ts +17 -5
- package/src/public/avm/avm_execution_environment.ts +8 -1
- package/src/public/avm/avm_gas.ts +23 -35
- package/src/public/avm/avm_machine_state.ts +5 -0
- package/src/public/avm/avm_memory_types.ts +19 -6
- package/src/public/avm/avm_simulator.ts +43 -54
- package/src/public/avm/avm_simulator_interface.ts +8 -0
- package/src/public/avm/errors.ts +8 -77
- package/src/public/avm/fixtures/avm_simulation_tester.ts +32 -21
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +45 -12
- package/src/public/avm/fixtures/initializers.ts +102 -0
- package/src/public/avm/fixtures/utils.ts +150 -0
- package/src/public/avm/index.ts +0 -2
- package/src/public/avm/opcodes/accrued_substate.ts +64 -29
- package/src/public/avm/opcodes/addressing_mode.ts +56 -32
- package/src/public/avm/opcodes/arithmetic.ts +24 -2
- package/src/public/avm/opcodes/bitwise.ts +33 -29
- package/src/public/avm/opcodes/comparators.ts +6 -3
- package/src/public/avm/opcodes/contract.ts +10 -7
- package/src/public/avm/opcodes/control_flow.ts +19 -10
- package/src/public/avm/opcodes/conversion.ts +27 -3
- package/src/public/avm/opcodes/ec_add.ts +9 -6
- package/src/public/avm/opcodes/environment_getters.ts +27 -22
- package/src/public/avm/opcodes/external_calls.ts +61 -29
- package/src/public/avm/opcodes/hashing.ts +28 -8
- package/src/public/avm/opcodes/instruction.ts +31 -21
- package/src/public/avm/opcodes/memory.ts +71 -32
- package/src/public/avm/opcodes/misc.ts +60 -18
- package/src/public/avm/opcodes/storage.ts +22 -6
- package/src/public/avm/revert_reason.ts +55 -0
- package/src/public/avm/serialization/buffer_cursor.ts +4 -1
- package/src/public/avm/serialization/bytecode_serialization.ts +72 -74
- package/src/public/avm/serialization/instruction_serialization.ts +75 -34
- package/src/public/avm/test_utils.ts +24 -41
- package/src/public/contracts_db_checkpoint.ts +41 -0
- package/src/public/db_interfaces.ts +76 -0
- package/src/{common → public}/debug_fn_name.ts +7 -7
- package/src/public/executor_metrics.ts +56 -6
- package/src/public/executor_metrics_interface.ts +15 -0
- package/src/public/fixtures/amm_test.ts +331 -0
- package/src/public/fixtures/bulk_test.ts +169 -0
- package/src/public/fixtures/custom_bytecode_tester.ts +49 -0
- package/src/public/fixtures/custom_bytecode_tests.ts +135 -0
- package/src/public/fixtures/index.ts +7 -0
- package/src/public/fixtures/minimal_public_tx.ts +35 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +166 -113
- package/src/public/{avm/fixtures → fixtures}/simple_contract_data_source.ts +36 -18
- package/src/public/fixtures/token_test.ts +139 -0
- package/src/public/fixtures/utils.ts +141 -68
- package/src/public/hinting_db_sources.ts +602 -0
- package/src/public/index.ts +5 -8
- package/src/public/public_db_sources.ts +278 -258
- package/src/public/public_errors.ts +14 -0
- package/src/public/public_processor/guarded_merkle_tree.ts +153 -0
- package/src/public/public_processor/public_processor.ts +212 -164
- package/src/public/public_processor/public_processor_metrics.ts +2 -2
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +162 -0
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +306 -0
- package/src/public/public_tx_simulator/index.ts +4 -0
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +105 -0
- package/src/public/public_tx_simulator/public_tx_context.ts +167 -194
- package/src/public/public_tx_simulator/public_tx_simulator.ts +292 -265
- package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +10 -0
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +63 -0
- package/src/public/side_effect_errors.ts +91 -1
- package/src/public/side_effect_trace.ts +94 -320
- package/src/public/side_effect_trace_interface.ts +10 -58
- package/src/public/state_manager/index.ts +1 -0
- package/src/public/{avm/journal → state_manager}/nullifiers.ts +5 -11
- package/src/public/{avm/journal → state_manager}/public_storage.ts +2 -2
- package/src/public/state_manager/state_manager.ts +553 -0
- package/src/public/test_executor_metrics.ts +397 -0
- package/src/public/utils.ts +5 -21
- package/src/server.ts +6 -3
- package/src/testing.ts +1 -0
- package/dest/common/db_interfaces.d.ts +0 -80
- package/dest/common/db_interfaces.d.ts.map +0 -1
- package/dest/common/db_interfaces.js +0 -1
- package/dest/common/debug_fn_name.d.ts +0 -5
- package/dest/common/debug_fn_name.d.ts.map +0 -1
- package/dest/common/debug_fn_name.js +0 -6
- package/dest/common/message_load_oracle_inputs.d.ts +0 -15
- package/dest/common/message_load_oracle_inputs.d.ts.map +0 -1
- package/dest/common/message_load_oracle_inputs.js +0 -15
- package/dest/private/acvm/oracle/index.d.ts +0 -14
- package/dest/private/acvm/oracle/index.d.ts.map +0 -1
- package/dest/private/acvm/oracle/index.js +0 -2
- package/dest/private/acvm/oracle/oracle.d.ts +0 -49
- package/dest/private/acvm/oracle/oracle.d.ts.map +0 -1
- package/dest/private/acvm/oracle/oracle.js +0 -263
- package/dest/private/acvm/oracle/typed_oracle.d.ts +0 -83
- package/dest/private/acvm/oracle/typed_oracle.d.ts.map +0 -1
- package/dest/private/acvm/oracle/typed_oracle.js +0 -132
- package/dest/private/execution_data_provider.d.ts +0 -261
- package/dest/private/execution_data_provider.d.ts.map +0 -1
- package/dest/private/execution_data_provider.js +0 -14
- package/dest/private/execution_note_cache.d.ts +0 -93
- package/dest/private/execution_note_cache.d.ts.map +0 -1
- package/dest/private/execution_note_cache.js +0 -180
- package/dest/private/hashed_values_cache.d.ts +0 -28
- package/dest/private/hashed_values_cache.d.ts.map +0 -1
- package/dest/private/hashed_values_cache.js +0 -46
- package/dest/private/index.d.ts +0 -13
- package/dest/private/index.d.ts.map +0 -1
- package/dest/private/index.js +0 -12
- package/dest/private/pick_notes.d.ts +0 -85
- package/dest/private/pick_notes.d.ts.map +0 -1
- package/dest/private/pick_notes.js +0 -51
- package/dest/private/private_execution.d.ts +0 -25
- package/dest/private/private_execution.d.ts.map +0 -1
- package/dest/private/private_execution.js +0 -92
- package/dest/private/private_execution_oracle.d.ts +0 -215
- package/dest/private/private_execution_oracle.d.ts.map +0 -1
- package/dest/private/private_execution_oracle.js +0 -382
- package/dest/private/providers/acvm_native.d.ts +0 -40
- package/dest/private/providers/acvm_native.d.ts.map +0 -1
- package/dest/private/providers/acvm_wasm.d.ts +0 -15
- package/dest/private/providers/acvm_wasm.d.ts.map +0 -1
- package/dest/private/providers/acvm_wasm_with_blobs.d.ts +0 -19
- package/dest/private/providers/acvm_wasm_with_blobs.d.ts.map +0 -1
- package/dest/private/providers/acvm_wasm_with_blobs.js +0 -32
- package/dest/private/providers/factory.d.ts +0 -12
- package/dest/private/providers/factory.d.ts.map +0 -1
- package/dest/private/providers/simulation_provider.d.ts +0 -19
- package/dest/private/providers/simulation_provider.d.ts.map +0 -1
- package/dest/private/providers/simulation_provider.js +0 -24
- package/dest/private/simulator.d.ts +0 -34
- package/dest/private/simulator.d.ts.map +0 -1
- package/dest/private/simulator.js +0 -76
- package/dest/private/unconstrained_execution.d.ts +0 -10
- package/dest/private/unconstrained_execution.d.ts.map +0 -1
- package/dest/private/unconstrained_execution.js +0 -27
- package/dest/private/unconstrained_execution_oracle.d.ts +0 -161
- package/dest/private/unconstrained_execution_oracle.d.ts.map +0 -1
- package/dest/private/unconstrained_execution_oracle.js +0 -258
- package/dest/public/avm/bytecode_utils.d.ts +0 -5
- package/dest/public/avm/bytecode_utils.d.ts.map +0 -1
- package/dest/public/avm/bytecode_utils.js +0 -17
- package/dest/public/avm/fixtures/index.d.ts +0 -84
- package/dest/public/avm/fixtures/index.d.ts.map +0 -1
- package/dest/public/avm/fixtures/index.js +0 -175
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts +0 -35
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +0 -1
- package/dest/public/avm/journal/index.d.ts +0 -2
- package/dest/public/avm/journal/index.d.ts.map +0 -1
- package/dest/public/avm/journal/index.js +0 -1
- package/dest/public/avm/journal/journal.d.ts +0 -209
- package/dest/public/avm/journal/journal.d.ts.map +0 -1
- package/dest/public/avm/journal/journal.js +0 -486
- package/dest/public/avm/journal/nullifiers.d.ts.map +0 -1
- package/dest/public/avm/journal/public_storage.d.ts.map +0 -1
- package/dest/public/bytecode_errors.d.ts +0 -4
- package/dest/public/bytecode_errors.d.ts.map +0 -1
- package/dest/public/bytecode_errors.js +0 -6
- package/dest/public/execution.d.ts +0 -108
- package/dest/public/execution.d.ts.map +0 -1
- package/dest/public/execution.js +0 -9
- package/dest/public/tx_contract_cache.d.ts +0 -41
- package/dest/public/tx_contract_cache.d.ts.map +0 -1
- package/dest/public/tx_contract_cache.js +0 -49
- package/dest/test/utils.d.ts +0 -13
- package/dest/test/utils.d.ts.map +0 -1
- package/dest/test/utils.js +0 -22
- package/src/common/db_interfaces.ts +0 -94
- package/src/common/message_load_oracle_inputs.ts +0 -15
- package/src/private/acvm/oracle/index.ts +0 -16
- package/src/private/acvm/oracle/oracle.ts +0 -455
- package/src/private/acvm/oracle/typed_oracle.ts +0 -259
- package/src/private/execution_data_provider.ts +0 -323
- package/src/private/execution_note_cache.ts +0 -217
- package/src/private/hashed_values_cache.ts +0 -55
- package/src/private/index.ts +0 -16
- package/src/private/pick_notes.ts +0 -141
- package/src/private/private_execution.ts +0 -151
- package/src/private/private_execution_oracle.ts +0 -614
- package/src/private/providers/acvm_wasm.ts +0 -63
- package/src/private/providers/acvm_wasm_with_blobs.ts +0 -50
- package/src/private/providers/simulation_provider.ts +0 -45
- package/src/private/simulator.ts +0 -147
- package/src/private/unconstrained_execution.ts +0 -50
- package/src/private/unconstrained_execution_oracle.ts +0 -373
- package/src/public/avm/bytecode_utils.ts +0 -17
- package/src/public/avm/fixtures/index.ts +0 -296
- package/src/public/avm/journal/index.ts +0 -1
- package/src/public/avm/journal/journal.ts +0 -742
- package/src/public/avm/opcodes/.eslintrc.cjs +0 -8
- package/src/public/bytecode_errors.ts +0 -6
- package/src/public/execution.ts +0 -140
- package/src/public/tx_contract_cache.ts +0 -69
- package/src/test/utils.ts +0 -36
- /package/dest/public/{avm/journal → state_manager}/public_storage.js +0 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { GeneratorIndex } from '@aztec/constants';
|
|
2
|
+
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
|
|
3
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
5
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
6
|
+
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
7
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
|
+
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
9
|
+
|
|
10
|
+
import { PublicTxSimulationTester } from './public_tx_simulation_tester.js';
|
|
11
|
+
import { setUpToken } from './token_test.js';
|
|
12
|
+
|
|
13
|
+
const INITIAL_TOKEN_BALANCE = 1_000_000_000n;
|
|
14
|
+
/**
|
|
15
|
+
* THIS TEST IS BRITTLE! If it breaks, don't try fixing it.
|
|
16
|
+
* `.skip` it or literally just delete it and notify AVM team.
|
|
17
|
+
* You do NOT need permission to remove this test!
|
|
18
|
+
*/
|
|
19
|
+
export async function ammTest(
|
|
20
|
+
tester: PublicTxSimulationTester,
|
|
21
|
+
logger: Logger,
|
|
22
|
+
tokenArtifact: ContractArtifact,
|
|
23
|
+
ammArtifact: ContractArtifact,
|
|
24
|
+
expectToBeTrue: (x: boolean) => void,
|
|
25
|
+
) {
|
|
26
|
+
const timer = new Timer();
|
|
27
|
+
|
|
28
|
+
const admin = AztecAddress.fromNumber(42);
|
|
29
|
+
const sender = AztecAddress.fromNumber(111);
|
|
30
|
+
|
|
31
|
+
logger.debug(`Deploying tokens`);
|
|
32
|
+
const token0 = await setUpToken(tester, tokenArtifact, admin, expectToBeTrue, /*seed=*/ 0);
|
|
33
|
+
const token1 = await setUpToken(tester, tokenArtifact, admin, expectToBeTrue, /*seed=*/ 1);
|
|
34
|
+
const liquidityToken = await setUpToken(tester, tokenArtifact, admin, expectToBeTrue, /*seed=*/ 2);
|
|
35
|
+
logger.debug(`Deploying AMM`);
|
|
36
|
+
const constructorArgs = [token0, token1, liquidityToken];
|
|
37
|
+
const amm = await tester.registerAndDeployContract(
|
|
38
|
+
constructorArgs,
|
|
39
|
+
/*deployer=*/ admin,
|
|
40
|
+
ammArtifact,
|
|
41
|
+
/*skipNullifierInsertion=*/ false,
|
|
42
|
+
/*seed=*/ 3,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
// EXECUTE! This means that if using AvmProvingTester subclass, it will PROVE the transaction!
|
|
46
|
+
const ammConstructorResult = await tester.executeTxWithLabel(
|
|
47
|
+
/*txLabel=*/ 'AMM/constructor',
|
|
48
|
+
/*sender=*/ admin,
|
|
49
|
+
/*setupCalls=*/ [],
|
|
50
|
+
/*appCalls=*/ [
|
|
51
|
+
{
|
|
52
|
+
fnName: 'constructor',
|
|
53
|
+
args: constructorArgs,
|
|
54
|
+
address: amm.address,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
);
|
|
58
|
+
expectToBeTrue(ammConstructorResult.revertCode.isOK());
|
|
59
|
+
|
|
60
|
+
logger.debug(`Setting AMM as minter for liquidity token`);
|
|
61
|
+
|
|
62
|
+
// set the AMM as the minter for the liquidity token
|
|
63
|
+
// EXECUTE! This means that if using AvmProvingTester subclass, it will PROVE the transaction!
|
|
64
|
+
const setMinterResult = await tester.executeTxWithLabel(
|
|
65
|
+
/*txLabel=*/ 'AMM/set_minter',
|
|
66
|
+
/*sender=*/ admin,
|
|
67
|
+
/*setupCalls=*/ [],
|
|
68
|
+
/*appCalls=*/ [
|
|
69
|
+
{
|
|
70
|
+
fnName: 'set_minter',
|
|
71
|
+
args: [/*minter=*/ amm, /*approve=*/ true],
|
|
72
|
+
address: liquidityToken.address,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
);
|
|
76
|
+
expectToBeTrue(setMinterResult.revertCode.isOK());
|
|
77
|
+
|
|
78
|
+
logger.debug(`Adding liquidity`);
|
|
79
|
+
const amount0Max = (INITIAL_TOKEN_BALANCE * 6n) / 10n;
|
|
80
|
+
const amount0Min = (INITIAL_TOKEN_BALANCE * 4n) / 10n;
|
|
81
|
+
const amount1Max = (INITIAL_TOKEN_BALANCE * 5n) / 10n;
|
|
82
|
+
const amount1Min = (INITIAL_TOKEN_BALANCE * 4n) / 10n;
|
|
83
|
+
|
|
84
|
+
const addLiquidityResult = await addLiquidity(
|
|
85
|
+
tester,
|
|
86
|
+
sender,
|
|
87
|
+
/*amm=*/ amm,
|
|
88
|
+
/*token0=*/ token0,
|
|
89
|
+
/*token1=*/ token1,
|
|
90
|
+
/*liquidityToken=*/ liquidityToken,
|
|
91
|
+
/*amount0Max=*/ amount0Max,
|
|
92
|
+
/*amount1Max=*/ amount1Max,
|
|
93
|
+
/*amount0Min=*/ amount0Min,
|
|
94
|
+
/*amount1Min=*/ amount1Min,
|
|
95
|
+
);
|
|
96
|
+
expectToBeTrue(addLiquidityResult.revertCode.isOK());
|
|
97
|
+
|
|
98
|
+
logger.debug(`Swapping tokens`);
|
|
99
|
+
const swapResult = await swapExactTokensForTokens(
|
|
100
|
+
tester,
|
|
101
|
+
sender,
|
|
102
|
+
/*amm=*/ amm,
|
|
103
|
+
/*tokenIn=*/ token0,
|
|
104
|
+
/*tokenOut=*/ token1,
|
|
105
|
+
/*amountIn=*/ amount0Min / 10n, // something smaller than total liquidity
|
|
106
|
+
/*amountOutMin=*/ amount1Min / 100n, // something even smaller
|
|
107
|
+
);
|
|
108
|
+
expectToBeTrue(swapResult.revertCode.isOK());
|
|
109
|
+
|
|
110
|
+
logger.debug(`Removing liquidity`);
|
|
111
|
+
const removeLiquidityResult = await removeLiquidity(
|
|
112
|
+
tester,
|
|
113
|
+
sender,
|
|
114
|
+
/*amm=*/ amm,
|
|
115
|
+
/*token0=*/ token0,
|
|
116
|
+
/*token1=*/ token1,
|
|
117
|
+
/*liquidityToken=*/ liquidityToken,
|
|
118
|
+
/*liquidity=*/ 100n,
|
|
119
|
+
/*amount0Min=*/ 1n, // remove some tiny amount
|
|
120
|
+
/*amount1Min=*/ 1n,
|
|
121
|
+
);
|
|
122
|
+
expectToBeTrue(removeLiquidityResult.revertCode.isOK());
|
|
123
|
+
|
|
124
|
+
logger.info(`AMM public tx simulator test took ${timer.ms()}ms\n`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function addLiquidity(
|
|
128
|
+
tester: PublicTxSimulationTester,
|
|
129
|
+
sender: AztecAddress,
|
|
130
|
+
amm: ContractInstanceWithAddress,
|
|
131
|
+
token0: ContractInstanceWithAddress,
|
|
132
|
+
token1: ContractInstanceWithAddress,
|
|
133
|
+
liquidityToken: ContractInstanceWithAddress,
|
|
134
|
+
amount0Max: bigint,
|
|
135
|
+
amount1Max: bigint,
|
|
136
|
+
amount0Min: bigint,
|
|
137
|
+
amount1Min: bigint,
|
|
138
|
+
_nonce?: bigint,
|
|
139
|
+
) {
|
|
140
|
+
const refundToken0PartialNote = {
|
|
141
|
+
commitment: new Fr(42),
|
|
142
|
+
};
|
|
143
|
+
const refundToken1PartialNote = {
|
|
144
|
+
commitment: new Fr(66),
|
|
145
|
+
};
|
|
146
|
+
const liquidityPartialNote = {
|
|
147
|
+
commitment: new Fr(99),
|
|
148
|
+
};
|
|
149
|
+
const refundToken0PartialNoteValidityCommitment = await computePartialNoteValidityCommitment(
|
|
150
|
+
refundToken0PartialNote,
|
|
151
|
+
amm.address,
|
|
152
|
+
);
|
|
153
|
+
const refundToken1PartialNoteValidityCommitment = await computePartialNoteValidityCommitment(
|
|
154
|
+
refundToken1PartialNote,
|
|
155
|
+
amm.address,
|
|
156
|
+
);
|
|
157
|
+
const liquidityPartialNoteValidityCommitment = await computePartialNoteValidityCommitment(
|
|
158
|
+
liquidityPartialNote,
|
|
159
|
+
amm.address,
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
// We need to inject the validity commitments into the nullifier tree as that would be performed by the private token
|
|
163
|
+
// functions that are not invoked in this test.
|
|
164
|
+
await tester.insertNullifier(token0.address, refundToken0PartialNoteValidityCommitment);
|
|
165
|
+
await tester.insertNullifier(token1.address, refundToken1PartialNoteValidityCommitment);
|
|
166
|
+
await tester.insertNullifier(liquidityToken.address, liquidityPartialNoteValidityCommitment);
|
|
167
|
+
|
|
168
|
+
// EXECUTE! This means that if using AvmProvingTester subclass, it will PROVE the transaction!
|
|
169
|
+
return await tester.executeTxWithLabel(
|
|
170
|
+
/*txLabel=*/ 'AMM/add_liquidity',
|
|
171
|
+
/*sender=*/ sender,
|
|
172
|
+
/*setupCalls=*/ [],
|
|
173
|
+
/*appCalls=*/ [
|
|
174
|
+
// token0.transfer_to_public enqueues a call to _increase_public_balance
|
|
175
|
+
{
|
|
176
|
+
sender: token0.address, // INTERNAL FUNCTION! Sender must be 'this'.
|
|
177
|
+
fnName: '_increase_public_balance',
|
|
178
|
+
args: [/*to=*/ amm.address, /*amount=*/ amount0Max],
|
|
179
|
+
address: token0.address,
|
|
180
|
+
},
|
|
181
|
+
// token1.transfer_to_public enqueues a call to _increase_public_balance
|
|
182
|
+
{
|
|
183
|
+
sender: token1.address, // INTERNAL FUNCTION! Sender must be 'this'.
|
|
184
|
+
fnName: '_increase_public_balance',
|
|
185
|
+
args: [/*to=*/ amm.address, /*amount=*/ amount1Max],
|
|
186
|
+
address: token1.address,
|
|
187
|
+
},
|
|
188
|
+
// amm.add_liquidity enqueues a call to _add_liquidity
|
|
189
|
+
{
|
|
190
|
+
sender: amm.address, // INTERNAL FUNCTION! Sender must be 'this'.
|
|
191
|
+
fnName: '_add_liquidity',
|
|
192
|
+
args: [
|
|
193
|
+
/*config=*/ {
|
|
194
|
+
token0: token0.address,
|
|
195
|
+
token1: token1.address,
|
|
196
|
+
// eslint-disable-next-line camelcase
|
|
197
|
+
liquidity_token: liquidityToken.address,
|
|
198
|
+
},
|
|
199
|
+
refundToken0PartialNote,
|
|
200
|
+
refundToken1PartialNote,
|
|
201
|
+
liquidityPartialNote,
|
|
202
|
+
amount0Max,
|
|
203
|
+
amount1Max,
|
|
204
|
+
amount0Min,
|
|
205
|
+
amount1Min,
|
|
206
|
+
],
|
|
207
|
+
address: amm.address,
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async function swapExactTokensForTokens(
|
|
214
|
+
tester: PublicTxSimulationTester,
|
|
215
|
+
sender: AztecAddress,
|
|
216
|
+
amm: ContractInstanceWithAddress,
|
|
217
|
+
tokenIn: ContractInstanceWithAddress,
|
|
218
|
+
tokenOut: ContractInstanceWithAddress,
|
|
219
|
+
amountIn: bigint,
|
|
220
|
+
amountOutMin: bigint,
|
|
221
|
+
_nonce?: bigint,
|
|
222
|
+
) {
|
|
223
|
+
const tokenOutPartialNote = {
|
|
224
|
+
commitment: new Fr(166),
|
|
225
|
+
};
|
|
226
|
+
const tokenOutPartialNoteValidityCommitment = await computePartialNoteValidityCommitment(
|
|
227
|
+
tokenOutPartialNote,
|
|
228
|
+
amm.address,
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
// We need to inject the validity commitment into the nullifier tree as that would be performed by the private token
|
|
232
|
+
// function that is not invoked in this test.
|
|
233
|
+
await tester.insertNullifier(tokenOut.address, tokenOutPartialNoteValidityCommitment);
|
|
234
|
+
|
|
235
|
+
// EXECUTE! This means that if using AvmProvingTester subclass, it will PROVE the transaction!
|
|
236
|
+
return await tester.executeTxWithLabel(
|
|
237
|
+
/*txLabel=*/ 'AMM/swap_exact_tokens_for_tokens',
|
|
238
|
+
/*sender=*/ sender,
|
|
239
|
+
/*setupCalls=*/ [],
|
|
240
|
+
/*appCalls=*/ [
|
|
241
|
+
// tokenIn.transfer_to_public enqueues a call to _increase_public_balance
|
|
242
|
+
{
|
|
243
|
+
sender: tokenIn.address, // INTERNAL FUNCTION! Sender must be 'this'.
|
|
244
|
+
fnName: '_increase_public_balance',
|
|
245
|
+
args: [/*to=*/ amm.address, /*amount=*/ amountIn],
|
|
246
|
+
address: tokenIn.address,
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
sender: amm.address, // INTERNAL FUNCTION! Sender must be 'this'.
|
|
250
|
+
fnName: '_swap_exact_tokens_for_tokens',
|
|
251
|
+
args: [tokenIn.address, tokenOut.address, amountIn, amountOutMin, tokenOutPartialNote],
|
|
252
|
+
address: amm.address,
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async function removeLiquidity(
|
|
259
|
+
tester: PublicTxSimulationTester,
|
|
260
|
+
sender: AztecAddress,
|
|
261
|
+
amm: ContractInstanceWithAddress,
|
|
262
|
+
token0: ContractInstanceWithAddress,
|
|
263
|
+
token1: ContractInstanceWithAddress,
|
|
264
|
+
liquidityToken: ContractInstanceWithAddress,
|
|
265
|
+
liquidity: bigint,
|
|
266
|
+
amount0Min: bigint,
|
|
267
|
+
amount1Min: bigint,
|
|
268
|
+
_nonce?: bigint,
|
|
269
|
+
) {
|
|
270
|
+
const token0PartialNote = {
|
|
271
|
+
commitment: new Fr(111),
|
|
272
|
+
};
|
|
273
|
+
const token1PartialNote = {
|
|
274
|
+
commitment: new Fr(222),
|
|
275
|
+
};
|
|
276
|
+
const token0PartialNoteValidityCommitment = await computePartialNoteValidityCommitment(
|
|
277
|
+
token0PartialNote,
|
|
278
|
+
amm.address,
|
|
279
|
+
);
|
|
280
|
+
const token1PartialNoteValidityCommitment = await computePartialNoteValidityCommitment(
|
|
281
|
+
token1PartialNote,
|
|
282
|
+
amm.address,
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
// We need to inject the validity commitments into the nullifier tree as that would be performed by the private token
|
|
286
|
+
// functions that are not invoked in this test.
|
|
287
|
+
await tester.insertNullifier(token0.address, token0PartialNoteValidityCommitment);
|
|
288
|
+
await tester.insertNullifier(token1.address, token1PartialNoteValidityCommitment);
|
|
289
|
+
|
|
290
|
+
// EXECUTE! This means that if using AvmProvingTester subclass, it will PROVE the transaction!
|
|
291
|
+
return await tester.executeTxWithLabel(
|
|
292
|
+
/*txLabel=*/ 'AMM/remove_liquidity',
|
|
293
|
+
/*sender=*/ sender,
|
|
294
|
+
/*setupCalls=*/ [],
|
|
295
|
+
/*appCalls=*/ [
|
|
296
|
+
// liquidityToken.transfer_to_public enqueues a call to _increase_public_balance
|
|
297
|
+
{
|
|
298
|
+
sender: liquidityToken.address, // INTERNAL FUNCTION! Sender must be 'this'.
|
|
299
|
+
fnName: '_increase_public_balance',
|
|
300
|
+
args: [/*to=*/ amm.address, /*amount=*/ liquidity],
|
|
301
|
+
address: liquidityToken.address,
|
|
302
|
+
},
|
|
303
|
+
// amm.remove_liquidity enqueues a call to _remove_liquidity
|
|
304
|
+
{
|
|
305
|
+
sender: amm.address, // INTERNAL FUNCTION! Sender must be 'this'.
|
|
306
|
+
fnName: '_remove_liquidity',
|
|
307
|
+
args: [
|
|
308
|
+
/*config=*/ {
|
|
309
|
+
token0: token0.address,
|
|
310
|
+
token1: token1.address,
|
|
311
|
+
// eslint-disable-next-line camelcase
|
|
312
|
+
liquidity_token: liquidityToken.address,
|
|
313
|
+
},
|
|
314
|
+
liquidity,
|
|
315
|
+
token0PartialNote,
|
|
316
|
+
token1PartialNote,
|
|
317
|
+
amount0Min,
|
|
318
|
+
amount1Min,
|
|
319
|
+
],
|
|
320
|
+
address: amm.address,
|
|
321
|
+
},
|
|
322
|
+
],
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
async function computePartialNoteValidityCommitment(partialNote: { commitment: Fr }, completer: AztecAddress) {
|
|
327
|
+
return await poseidon2HashWithSeparator(
|
|
328
|
+
[partialNote.commitment, completer],
|
|
329
|
+
GeneratorIndex.PARTIAL_NOTE_VALIDITY_COMMITMENT,
|
|
330
|
+
);
|
|
331
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
3
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
4
|
+
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
5
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
+
|
|
7
|
+
import { PublicTxSimulationTester } from './public_tx_simulation_tester.js';
|
|
8
|
+
|
|
9
|
+
export async function bulkTest(
|
|
10
|
+
tester: PublicTxSimulationTester,
|
|
11
|
+
logger: Logger,
|
|
12
|
+
avmTestContractArtifact: ContractArtifact,
|
|
13
|
+
) {
|
|
14
|
+
const timer = new Timer();
|
|
15
|
+
|
|
16
|
+
const deployer = AztecAddress.fromNumber(42);
|
|
17
|
+
const avmTestContract = await tester.registerAndDeployContract(
|
|
18
|
+
/*constructorArgs=*/ [],
|
|
19
|
+
deployer,
|
|
20
|
+
avmTestContractArtifact,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
// Needed since we invoke the Fee Juice Contract in the bulk test.registerFeeJuiceContract
|
|
24
|
+
await tester.registerFeeJuiceContract();
|
|
25
|
+
// Register multiple different protocol contracts (to ensure we don't dedup bytecode hashing events):
|
|
26
|
+
await tester.registerAuthContract();
|
|
27
|
+
await tester.registerInstanceRegistryContract();
|
|
28
|
+
|
|
29
|
+
// Get a deployed contract instance to pass to the contract
|
|
30
|
+
// for it to use as "expected" values when testing contract instance retrieval.
|
|
31
|
+
const expectContractInstance = avmTestContract;
|
|
32
|
+
const argsField = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
33
|
+
const argsU8 = [1, 2, 3, 4, 5, 6, 7, 8].map(x => new Fr(x));
|
|
34
|
+
argsU8.push(new Fr(2n ** 128n + 9n)); // Trigger truncation from large (> 128 bits) value (canonical decomposition event)
|
|
35
|
+
argsU8.push(new Fr(2n ** 125n + 10n)); // Trigger truncation from small (< 128 bits) value (no canonical decomposition event)
|
|
36
|
+
const args = [
|
|
37
|
+
argsField,
|
|
38
|
+
argsU8,
|
|
39
|
+
/*getInstanceForAddress=*/ expectContractInstance.address,
|
|
40
|
+
/*expectedDeployer=*/ expectContractInstance.deployer,
|
|
41
|
+
/*expectedClassId=*/ expectContractInstance.currentContractClassId,
|
|
42
|
+
/*expectedInitializationHash=*/ expectContractInstance.initializationHash,
|
|
43
|
+
/*skip_strictly_limited_side_effects=*/ false,
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const bulkResult = await tester.executeTxWithLabel(
|
|
47
|
+
/*txLabel=*/ 'AvmTest/bulk_testing',
|
|
48
|
+
/*sender=*/ deployer,
|
|
49
|
+
/*setupCalls=*/ [],
|
|
50
|
+
/*appCalls=*/ [
|
|
51
|
+
{
|
|
52
|
+
address: avmTestContract.address,
|
|
53
|
+
fnName: 'bulk_testing',
|
|
54
|
+
args,
|
|
55
|
+
},
|
|
56
|
+
// 3 calls creating calldata + asserting calldata copy:
|
|
57
|
+
{
|
|
58
|
+
address: avmTestContract.address,
|
|
59
|
+
fnName: 'assert_calldata_copy_large',
|
|
60
|
+
args: [Array.from({ length: 300 }, () => Fr.random()), /* with_selector: */ true],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
address: avmTestContract.address,
|
|
64
|
+
fnName: 'assert_calldata_copy',
|
|
65
|
+
args: [argsField.slice(3), /* with_selector: */ true],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
address: avmTestContract.address,
|
|
69
|
+
fnName: 'assert_calldata_copy_large',
|
|
70
|
+
args: [Array.from({ length: 300 }, () => Fr.random()), /* with_selector: */ true],
|
|
71
|
+
},
|
|
72
|
+
// 3 calls to external contracts
|
|
73
|
+
{ address: avmTestContract.address, fnName: 'call_fee_juice', args: [] },
|
|
74
|
+
{ address: avmTestContract.address, fnName: 'call_auth_registry', args: [] },
|
|
75
|
+
{ address: avmTestContract.address, fnName: 'call_instance_registry', args: [] },
|
|
76
|
+
],
|
|
77
|
+
/*teardownCall=*/ undefined,
|
|
78
|
+
/*feePayer*/ undefined,
|
|
79
|
+
/*privateInsertions=*/ {
|
|
80
|
+
nonRevertible: {
|
|
81
|
+
nullifiers: [new Fr(420000)],
|
|
82
|
+
noteHashes: [new Fr(420001)],
|
|
83
|
+
},
|
|
84
|
+
revertible: {
|
|
85
|
+
nullifiers: [new Fr(420002)],
|
|
86
|
+
noteHashes: [new Fr(420003)],
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
logger.info(`Bulk test took ${timer.ms()}ms\n`);
|
|
92
|
+
|
|
93
|
+
return bulkResult;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function megaBulkTest(
|
|
97
|
+
tester: PublicTxSimulationTester,
|
|
98
|
+
logger: Logger,
|
|
99
|
+
avmTestContractArtifact: ContractArtifact,
|
|
100
|
+
) {
|
|
101
|
+
const timer = new Timer();
|
|
102
|
+
|
|
103
|
+
const deployer = AztecAddress.fromNumber(42);
|
|
104
|
+
const avmTestContract = await tester.registerAndDeployContract(
|
|
105
|
+
/*constructorArgs=*/ [],
|
|
106
|
+
deployer,
|
|
107
|
+
avmTestContractArtifact,
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
// Needed since we invoke the Fee Juice Contract in the bulk test.registerFeeJuiceContract
|
|
111
|
+
await tester.registerFeeJuiceContract();
|
|
112
|
+
|
|
113
|
+
// Get a deployed contract instance to pass to the contract
|
|
114
|
+
// for it to use as "expected" values when testing contract instance retrieval.
|
|
115
|
+
const expectContractInstance = avmTestContract;
|
|
116
|
+
const argsField0 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
117
|
+
const argsField1 = [3, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
118
|
+
const argsField2 = [5, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
119
|
+
const argsField3 = [7, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
120
|
+
const argsField4 = [9, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
121
|
+
const argsField5 = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
122
|
+
const argsField6 = [13, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
123
|
+
const argsField7 = [15, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
124
|
+
const argsField8 = [17, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
125
|
+
const argsU8 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
126
|
+
const genArgs = (argsField: Fr[]) => [
|
|
127
|
+
argsField,
|
|
128
|
+
argsU8,
|
|
129
|
+
/*getInstanceForAddress=*/ expectContractInstance.address.toField(),
|
|
130
|
+
/*expectedDeployer=*/ expectContractInstance.deployer.toField(),
|
|
131
|
+
/*expectedClassId=*/ expectContractInstance.currentContractClassId.toField(),
|
|
132
|
+
/*expectedInitializationHash=*/ expectContractInstance.initializationHash.toField(),
|
|
133
|
+
// Must skip strictly limited side effects (logs, messages) so we can spam the bulk test several times.
|
|
134
|
+
/*skip_strictly_limited_side_effects=*/ true,
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
const bulkResult = await tester.executeTxWithLabel(
|
|
138
|
+
/*txLabel=*/ 'AvmTest/mega_bulk_testing',
|
|
139
|
+
/*sender=*/ deployer,
|
|
140
|
+
/*setupCalls=*/ [],
|
|
141
|
+
/*appCalls=*/ [
|
|
142
|
+
{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField0) },
|
|
143
|
+
{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField1) },
|
|
144
|
+
{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField2) },
|
|
145
|
+
{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField3) },
|
|
146
|
+
{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField4) },
|
|
147
|
+
{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField5) },
|
|
148
|
+
{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField6) },
|
|
149
|
+
{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField7) },
|
|
150
|
+
{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField8) },
|
|
151
|
+
],
|
|
152
|
+
/*teardownCall=*/ undefined,
|
|
153
|
+
/*feePayer*/ undefined,
|
|
154
|
+
/*privateInsertions=*/ {
|
|
155
|
+
nonRevertible: {
|
|
156
|
+
nullifiers: [new Fr(420000)],
|
|
157
|
+
noteHashes: [new Fr(420001)],
|
|
158
|
+
},
|
|
159
|
+
revertible: {
|
|
160
|
+
nullifiers: [new Fr(420002)],
|
|
161
|
+
noteHashes: [new Fr(420003)],
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
logger.info(`Mega bulk test took ${timer.ms()}ms\n`);
|
|
167
|
+
|
|
168
|
+
return bulkResult;
|
|
169
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { FunctionType, emptyContractArtifact, emptyFunctionArtifact } from '@aztec/stdlib/abi';
|
|
2
|
+
import type { PublicTxResult } from '@aztec/stdlib/avm';
|
|
3
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
|
|
5
|
+
import { PublicTxSimulationTester } from './public_tx_simulation_tester.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* Test custom bytecode (simulation or proving) with the provided bytecode.
|
|
10
|
+
* @param bytecode - The bytecode buffer to use
|
|
11
|
+
* @param tester - The tester to use (simulation or proving)
|
|
12
|
+
* @param txLabel - The label of the transaction
|
|
13
|
+
* @param contractName - The name of the contract (default: 'CustomBytecodeContract')
|
|
14
|
+
*/
|
|
15
|
+
export async function testCustomBytecode(
|
|
16
|
+
bytecode: Buffer,
|
|
17
|
+
tester: PublicTxSimulationTester,
|
|
18
|
+
txLabel: string,
|
|
19
|
+
contractName: string = 'CustomBytecodeContract',
|
|
20
|
+
): Promise<PublicTxResult> {
|
|
21
|
+
const deployer = AztecAddress.fromNumber(42);
|
|
22
|
+
|
|
23
|
+
const contractArtifact = emptyContractArtifact();
|
|
24
|
+
contractArtifact.name = contractName;
|
|
25
|
+
contractArtifact.functions = [emptyFunctionArtifact()];
|
|
26
|
+
contractArtifact.functions[0].name = 'public_dispatch';
|
|
27
|
+
contractArtifact.functions[0].functionType = FunctionType.PUBLIC;
|
|
28
|
+
contractArtifact.functions[0].bytecode = bytecode;
|
|
29
|
+
|
|
30
|
+
const testContract = await tester.registerAndDeployContract(
|
|
31
|
+
/*constructorArgs=*/ [],
|
|
32
|
+
deployer,
|
|
33
|
+
/*contractArtifact=*/ contractArtifact,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// EXECUTE! This means that if using AvmProvingTester subclass, it will PROVE the transaction!
|
|
37
|
+
return await tester.executeTxWithLabel(
|
|
38
|
+
/*txLabel=*/ txLabel,
|
|
39
|
+
/*sender=*/ deployer,
|
|
40
|
+
/*setupCalls=*/ [],
|
|
41
|
+
/*appCalls=*/ [
|
|
42
|
+
{
|
|
43
|
+
address: testContract.address,
|
|
44
|
+
fnName: 'public_dispatch',
|
|
45
|
+
args: [],
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { strict as assert } from 'assert';
|
|
2
|
+
|
|
3
|
+
import { TypeTag } from '../avm/avm_memory_types.js';
|
|
4
|
+
import { Addressing, AddressingMode } from '../avm/opcodes/addressing_mode.js';
|
|
5
|
+
import { CalldataCopy, Jump, Return, Set } from '../avm/opcodes/index.js';
|
|
6
|
+
import { encodeToBytecode } from '../avm/serialization/bytecode_serialization.js';
|
|
7
|
+
import {
|
|
8
|
+
MAX_OPCODE_VALUE,
|
|
9
|
+
Opcode,
|
|
10
|
+
OperandType,
|
|
11
|
+
getOperandSize,
|
|
12
|
+
} from '../avm/serialization/instruction_serialization.js';
|
|
13
|
+
import { testCustomBytecode } from './custom_bytecode_tester.js';
|
|
14
|
+
import { PublicTxSimulationTester } from './public_tx_simulation_tester.js';
|
|
15
|
+
|
|
16
|
+
// First instruction resolved a base address (offset 0) which is uninitialized and therefore
|
|
17
|
+
// of invalid tag (FF). This will trigger an exceptional halt.
|
|
18
|
+
export async function addressingWithBaseTagIssueTest(isIndirect: boolean, tester: PublicTxSimulationTester) {
|
|
19
|
+
const addressingMode = Addressing.fromModes([
|
|
20
|
+
isIndirect ? AddressingMode.INDIRECT_RELATIVE : AddressingMode.RELATIVE,
|
|
21
|
+
AddressingMode.DIRECT,
|
|
22
|
+
AddressingMode.DIRECT,
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const bytecode = encodeToBytecode([
|
|
26
|
+
new CalldataCopy(/*indirect=*/ addressingMode.toWire(), /*copySize=*/ 1, /*cdOffset=*/ 0, /*dstOffset=*/ 0),
|
|
27
|
+
new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
const txLabel = isIndirect ? 'AddressingWithBaseTagInvalidIndirect' : 'AddressingWithBaseTagInvalidDirect';
|
|
31
|
+
return await testCustomBytecode(bytecode, tester, txLabel);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function pcOutOfRangeTest(tester: PublicTxSimulationTester) {
|
|
35
|
+
const bytecode = encodeToBytecode([
|
|
36
|
+
new Jump(/*jumpOffset=*/ 123), // Jump to out-of-range pc offset.
|
|
37
|
+
new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
const txLabel = 'PcOutOfRange';
|
|
41
|
+
return await testCustomBytecode(bytecode, tester, txLabel);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function invalidOpcodeTest(tester: PublicTxSimulationTester) {
|
|
45
|
+
let bytecode = encodeToBytecode([
|
|
46
|
+
new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
const offsetReturnOpcodeByte = bytecode.length;
|
|
50
|
+
|
|
51
|
+
bytecode = Buffer.concat([
|
|
52
|
+
bytecode,
|
|
53
|
+
encodeToBytecode([new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0)]),
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
// Manipulate the Return opcode to make the opcode invalid (out of range).
|
|
57
|
+
bytecode[offsetReturnOpcodeByte] = MAX_OPCODE_VALUE + 1; // opcode is invalid.
|
|
58
|
+
|
|
59
|
+
const txLabel = 'InvalidOpcode';
|
|
60
|
+
return await testCustomBytecode(bytecode, tester, txLabel);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Single invalid byte in the bytecode.
|
|
64
|
+
export async function invalidByteTest(tester: PublicTxSimulationTester) {
|
|
65
|
+
const invalidOpcode = MAX_OPCODE_VALUE + 7;
|
|
66
|
+
assert(invalidOpcode < 256, 'Invalid opcode must fit in a single byte');
|
|
67
|
+
const bytecode = Buffer.from([invalidOpcode]);
|
|
68
|
+
|
|
69
|
+
const txLabel = 'InvalidByte';
|
|
70
|
+
return await testCustomBytecode(bytecode, tester, txLabel);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Truncate the last instruction in the bytecode.
|
|
74
|
+
export async function instructionTruncatedTest(tester: PublicTxSimulationTester) {
|
|
75
|
+
let bytecode = encodeToBytecode([
|
|
76
|
+
new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
// Truncate the bytecode.
|
|
80
|
+
bytecode = bytecode.subarray(0, -1);
|
|
81
|
+
|
|
82
|
+
const txLabel = 'InstructionTruncated';
|
|
83
|
+
return await testCustomBytecode(bytecode, tester, txLabel);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Invalid tag value byte in an instruction.
|
|
87
|
+
export async function invalidTagValueTest(tester: PublicTxSimulationTester) {
|
|
88
|
+
const bytecode = encodeToBytecode([
|
|
89
|
+
new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
|
|
90
|
+
new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
|
|
91
|
+
]);
|
|
92
|
+
|
|
93
|
+
const tagOffset = getTagOffsetInInstruction(Set.wireFormat8);
|
|
94
|
+
assert(bytecode[tagOffset].valueOf() == TypeTag.UINT32.valueOf(), 'Set instruction tag should be UINT32 in test');
|
|
95
|
+
bytecode[tagOffset] = TypeTag.INVALID;
|
|
96
|
+
|
|
97
|
+
const txLabel = 'InvalidTagValue';
|
|
98
|
+
return await testCustomBytecode(bytecode, tester, txLabel);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Combine an invalid tag in the last instruction that is truncated.
|
|
102
|
+
export async function invalidTagValueAndInstructionTruncatedTest(tester: PublicTxSimulationTester) {
|
|
103
|
+
let bytecode = encodeToBytecode([
|
|
104
|
+
// Important: value argument must be a bigint otherwise a type error will be thrown.
|
|
105
|
+
new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT128, /*value=*/ 0n).as(Opcode.SET_128, Set.wireFormat128),
|
|
106
|
+
]);
|
|
107
|
+
|
|
108
|
+
// Truncate the bytecode.
|
|
109
|
+
bytecode = bytecode.subarray(0, -5);
|
|
110
|
+
const tagOffset = getTagOffsetInInstruction(Set.wireFormat128);
|
|
111
|
+
assert(bytecode[tagOffset].valueOf() == TypeTag.UINT128.valueOf(), 'Set instruction tag should be UINT128 in test');
|
|
112
|
+
bytecode[tagOffset] = 0x6f; // Invalid tag value.
|
|
113
|
+
|
|
114
|
+
const txLabel = 'InvalidTagValueAndInstructionTruncated';
|
|
115
|
+
return await testCustomBytecode(bytecode, tester, txLabel);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Returns the offset of the tag in an instruction.
|
|
120
|
+
* @details Loops over the wire format operand type entries until it finds the tag.
|
|
121
|
+
* Returns the byte offset of the tag based on each operand size that is passed.
|
|
122
|
+
*
|
|
123
|
+
* @param wireFormat array of operand types
|
|
124
|
+
* @returns byte offset of the tag
|
|
125
|
+
*/
|
|
126
|
+
function getTagOffsetInInstruction(wireFormat: OperandType[]): number {
|
|
127
|
+
let offset = 0;
|
|
128
|
+
for (const operand of wireFormat) {
|
|
129
|
+
if (operand === OperandType.TAG) {
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
offset += getOperandSize(operand);
|
|
133
|
+
}
|
|
134
|
+
return offset;
|
|
135
|
+
}
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
export * from './public_tx_simulation_tester.js';
|
|
2
2
|
export * from './utils.js';
|
|
3
|
+
export * from './simple_contract_data_source.js';
|
|
4
|
+
export { readAvmMinimalPublicTxInputsFromFile, executeAvmMinimalPublicTx } from './minimal_public_tx.js';
|
|
5
|
+
export { TestExecutorMetrics } from '../test_executor_metrics.js';
|
|
6
|
+
export { ammTest } from './amm_test.js';
|
|
7
|
+
export { bulkTest, megaBulkTest } from './bulk_test.js';
|
|
8
|
+
export { tokenTest } from './token_test.js';
|
|
9
|
+
export * from './custom_bytecode_tests.js';
|