@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,17 @@
|
|
|
1
|
+
import { Opcode } from './serialization/instruction_serialization.js';
|
|
2
|
+
|
|
3
|
+
const AVM_MAGIC_SUFFIX = Buffer.from([
|
|
4
|
+
Opcode.MOV_16, // opcode
|
|
5
|
+
0x00, // indirect
|
|
6
|
+
...Buffer.from('18ca', 'hex'), // srcOffset
|
|
7
|
+
...Buffer.from('18ca', 'hex'), // dstOffset
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
export function markBytecodeAsAvm(bytecode: Buffer): Buffer {
|
|
11
|
+
return Buffer.concat([bytecode, AVM_MAGIC_SUFFIX]);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function isAvmBytecode(bytecode: Buffer): boolean {
|
|
15
|
+
const magicSize = AVM_MAGIC_SUFFIX.length;
|
|
16
|
+
return bytecode.subarray(-magicSize).equals(AVM_MAGIC_SUFFIX);
|
|
17
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import type { Fr, Point } from '@aztec/foundation/fields';
|
|
2
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
+
import type { FailingFunction, NoirCallStack } from '@aztec/stdlib/errors';
|
|
4
|
+
|
|
5
|
+
import { ExecutionError } from '../../common/errors.js';
|
|
6
|
+
import type { AvmContext } from './avm_context.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Avm-specific errors should derive from this
|
|
10
|
+
*/
|
|
11
|
+
export abstract class AvmExecutionError extends Error {
|
|
12
|
+
constructor(message: string) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = 'AvmExecutionError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class NoBytecodeForContractError extends AvmExecutionError {
|
|
19
|
+
constructor(contractAddress: AztecAddress) {
|
|
20
|
+
super(`No bytecode found at: ${contractAddress}`);
|
|
21
|
+
this.name = 'NoBytecodeFoundInterpreterError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class ArithmeticError extends AvmExecutionError {
|
|
26
|
+
constructor(message: string) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.name = 'ArithmeticError';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Error is thrown when the program counter goes to an invalid location.
|
|
34
|
+
* There is no instruction at the provided pc
|
|
35
|
+
*/
|
|
36
|
+
export class InvalidProgramCounterError extends AvmExecutionError {
|
|
37
|
+
constructor(pc: number, max: number) {
|
|
38
|
+
super(`Invalid program counter ${pc}, max is ${max}`);
|
|
39
|
+
this.name = 'InvalidProgramCounterError';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Error is thrown when the program counter points to a byte
|
|
45
|
+
* of an invalid opcode.
|
|
46
|
+
*/
|
|
47
|
+
export class InvalidOpcodeError extends AvmExecutionError {
|
|
48
|
+
constructor(str: string) {
|
|
49
|
+
super(str);
|
|
50
|
+
this.name = 'InvalidOpcodeError';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Error is thrown during parsing.
|
|
56
|
+
*/
|
|
57
|
+
export class AvmParsingError extends AvmExecutionError {
|
|
58
|
+
constructor(str: string) {
|
|
59
|
+
super(str);
|
|
60
|
+
this.name = 'AvmParsingError';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Error is thrown when the tag has an invalid value.
|
|
66
|
+
*/
|
|
67
|
+
export class InvalidTagValueError extends AvmExecutionError {
|
|
68
|
+
constructor(tagValue: number) {
|
|
69
|
+
super(`Tag value ${tagValue} is invalid.`);
|
|
70
|
+
this.name = 'InvalidTagValueError';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Error thrown during an instruction's execution (during its execute()).
|
|
76
|
+
*/
|
|
77
|
+
export class InstructionExecutionError extends AvmExecutionError {
|
|
78
|
+
constructor(message: string) {
|
|
79
|
+
super(message);
|
|
80
|
+
this.name = 'InstructionExecutionError';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Error thrown on failed AVM memory tag check.
|
|
86
|
+
*/
|
|
87
|
+
export class TagCheckError extends AvmExecutionError {
|
|
88
|
+
public static forOffset(offset: number, gotTag: string, expectedTag: string): TagCheckError {
|
|
89
|
+
return new TagCheckError(`Tag mismatch at offset ${offset}, got ${gotTag}, expected ${expectedTag}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public static forTag(gotTag: string, expectedTag: string): TagCheckError {
|
|
93
|
+
return new TagCheckError(`Tag mismatch, got ${gotTag}, expected ${expectedTag}`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
constructor(message: string) {
|
|
97
|
+
super(message);
|
|
98
|
+
this.name = 'TagCheckError';
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Error is thrown when a relative memory address resolved to an offset which
|
|
104
|
+
* is out of range, i.e, greater than maxUint32.
|
|
105
|
+
*/
|
|
106
|
+
export class RelativeAddressOutOfRangeError extends AvmExecutionError {
|
|
107
|
+
constructor(baseAddr: number, relOffset: number) {
|
|
108
|
+
super(`Address out of range. Base address ${baseAddr}, relative offset ${relOffset}`);
|
|
109
|
+
this.name = 'RelativeAddressOutOfRangeError';
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Error is thrown when a memory slice contains addresses which are
|
|
115
|
+
* out of range, i.e, greater than maxUint32.
|
|
116
|
+
*/
|
|
117
|
+
export class MemorySliceOutOfRangeError extends AvmExecutionError {
|
|
118
|
+
constructor(baseAddr: number, size: number) {
|
|
119
|
+
super(`Memory slice is out of range. Base address ${baseAddr}, size ${size}`);
|
|
120
|
+
this.name = 'MemorySliceOutOfRangeError';
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Error thrown when out of gas. */
|
|
125
|
+
export class OutOfGasError extends AvmExecutionError {
|
|
126
|
+
constructor(dimensions: string[]) {
|
|
127
|
+
super(`Not enough ${dimensions.map(d => d.toUpperCase()).join(', ')} gas left`);
|
|
128
|
+
this.name = 'OutOfGasError';
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Error is thrown when the supplied points length is not a multiple of 3. Specific for MSM opcode.
|
|
134
|
+
*/
|
|
135
|
+
export class MSMPointsLengthError extends AvmExecutionError {
|
|
136
|
+
constructor(pointsReadLength: number) {
|
|
137
|
+
super(`Points vector length should be a multiple of 3, was ${pointsReadLength}`);
|
|
138
|
+
this.name = 'MSMPointsLengthError';
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Error is thrown when one of the supplied points does not lie on the Grumpkin curve. Specific for MSM opcode.
|
|
144
|
+
*/
|
|
145
|
+
export class MSMPointNotOnCurveError extends AvmExecutionError {
|
|
146
|
+
constructor(point: Point) {
|
|
147
|
+
super(`Point ${point.toString()} is not on the curve.`);
|
|
148
|
+
this.name = 'MSMPointNotOnCurveError';
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Error is thrown when some inputs of ToRadixBE are not valid.
|
|
154
|
+
*/
|
|
155
|
+
export class InvalidToRadixInputsError extends AvmExecutionError {
|
|
156
|
+
constructor(errorString: string) {
|
|
157
|
+
super(errorString);
|
|
158
|
+
this.name = 'InvalidToRadixInputsError';
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Error is thrown when a static call attempts to alter some state
|
|
164
|
+
*/
|
|
165
|
+
export class StaticCallAlterationError extends InstructionExecutionError {
|
|
166
|
+
constructor() {
|
|
167
|
+
super('Static call cannot update the state, emit L2->L1 messages or generate logs');
|
|
168
|
+
this.name = 'StaticCallAlterationError';
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Meaningfully named alias for ExecutionError when used in the context of the AVM.
|
|
174
|
+
* Maintains a recursive structure reflecting the AVM's external callstack/errorstack, where
|
|
175
|
+
* options.cause is the error that caused this error (if this is not the root-cause itself).
|
|
176
|
+
*/
|
|
177
|
+
export class AvmRevertReason extends ExecutionError {
|
|
178
|
+
constructor(message: string, failingFunction: FailingFunction, noirCallStack: NoirCallStack, options?: ErrorOptions) {
|
|
179
|
+
super(message, failingFunction, noirCallStack, options);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async function createRevertReason(message: string, revertData: Fr[], context: AvmContext): Promise<AvmRevertReason> {
|
|
184
|
+
// We drop the returnPc information.
|
|
185
|
+
const internalCallStack = context.machineState.internalCallStack.map(entry => entry.callPc);
|
|
186
|
+
|
|
187
|
+
// If we are reverting due to the same error that we have been tracking, we use the nested error as the cause.
|
|
188
|
+
let nestedError = undefined;
|
|
189
|
+
const revertDataEquals = (a: Fr[], b: Fr[]) => a.length === b.length && a.every((v, i) => v.equals(b[i]));
|
|
190
|
+
if (
|
|
191
|
+
context.machineState.collectedRevertInfo &&
|
|
192
|
+
revertDataEquals(context.machineState.collectedRevertInfo.revertDataRepresentative, revertData)
|
|
193
|
+
) {
|
|
194
|
+
nestedError = context.machineState.collectedRevertInfo.recursiveRevertReason;
|
|
195
|
+
message = context.machineState.collectedRevertInfo.recursiveRevertReason.message;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const fnName = await context.persistableState.getPublicFunctionDebugName(context.environment);
|
|
199
|
+
|
|
200
|
+
return new AvmRevertReason(
|
|
201
|
+
message,
|
|
202
|
+
/*failingFunction=*/ {
|
|
203
|
+
contractAddress: context.environment.address,
|
|
204
|
+
functionName: fnName,
|
|
205
|
+
},
|
|
206
|
+
/*noirCallStack=*/ [...internalCallStack, context.machineState.pc].map(pc => `0.${pc}`),
|
|
207
|
+
/*options=*/ { cause: nestedError },
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Create a "revert reason" error for an exceptional halt.
|
|
213
|
+
*
|
|
214
|
+
* @param haltingError - the lower-level error causing the exceptional halt
|
|
215
|
+
* @param context - the context of the AVM execution used to extract the failingFunction and noirCallStack
|
|
216
|
+
*/
|
|
217
|
+
export async function revertReasonFromExceptionalHalt(
|
|
218
|
+
haltingError: AvmExecutionError,
|
|
219
|
+
context: AvmContext,
|
|
220
|
+
): Promise<AvmRevertReason> {
|
|
221
|
+
return await createRevertReason(haltingError.message, [], context);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Create a "revert reason" error for an explicit revert (a root cause).
|
|
226
|
+
*
|
|
227
|
+
* @param revertData - output data of the explicit REVERT instruction
|
|
228
|
+
* @param context - the context of the AVM execution used to extract the failingFunction and noirCallStack
|
|
229
|
+
*/
|
|
230
|
+
export async function revertReasonFromExplicitRevert(revertData: Fr[], context: AvmContext): Promise<AvmRevertReason> {
|
|
231
|
+
return await createRevertReason('Assertion failed: ', revertData, context);
|
|
232
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { encodeArguments } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import { GasFees } from '@aztec/stdlib/gas';
|
|
5
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
6
|
+
import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
7
|
+
import { NativeWorldStateService } from '@aztec/world-state';
|
|
8
|
+
|
|
9
|
+
import { SideEffectTrace } from '../../../public/side_effect_trace.js';
|
|
10
|
+
import type { AvmContractCallResult } from '../../avm/avm_contract_call_result.js';
|
|
11
|
+
import {
|
|
12
|
+
getContractFunctionArtifact,
|
|
13
|
+
getFunctionSelector,
|
|
14
|
+
initContext,
|
|
15
|
+
initExecutionEnvironment,
|
|
16
|
+
resolveContractAssertionMessage,
|
|
17
|
+
} from '../../avm/fixtures/index.js';
|
|
18
|
+
import { AvmPersistableStateManager } from '../../avm/journal/journal.js';
|
|
19
|
+
import { WorldStateDB } from '../../public_db_sources.js';
|
|
20
|
+
import { AvmSimulator } from '../avm_simulator.js';
|
|
21
|
+
import { BaseAvmSimulationTester } from './base_avm_simulation_tester.js';
|
|
22
|
+
import { SimpleContractDataSource } from './simple_contract_data_source.js';
|
|
23
|
+
|
|
24
|
+
const TIMESTAMP = new Fr(99833);
|
|
25
|
+
const DEFAULT_GAS_FEES = new GasFees(2, 3);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A test class that extends the BaseAvmSimulationTester to enable real-app testing of the core AvmSimulator.
|
|
29
|
+
* It provides an interface for simulating one top-level call at a time and maintains state between
|
|
30
|
+
* subsequent top-level calls.
|
|
31
|
+
*/
|
|
32
|
+
export class AvmSimulationTester extends BaseAvmSimulationTester {
|
|
33
|
+
constructor(
|
|
34
|
+
contractDataSource: SimpleContractDataSource,
|
|
35
|
+
merkleTrees: MerkleTreeWriteOperations,
|
|
36
|
+
private stateManager: AvmPersistableStateManager,
|
|
37
|
+
) {
|
|
38
|
+
super(contractDataSource, merkleTrees);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static async create(): Promise<AvmSimulationTester> {
|
|
42
|
+
const contractDataSource = new SimpleContractDataSource();
|
|
43
|
+
const merkleTrees = await (await NativeWorldStateService.tmp()).fork();
|
|
44
|
+
const worldStateDB = new WorldStateDB(merkleTrees, contractDataSource);
|
|
45
|
+
const trace = new SideEffectTrace();
|
|
46
|
+
const firstNullifier = new Fr(420000);
|
|
47
|
+
// FIXME: merkle ops should work, but I'm seeing frequent (but inconsistent) bytecode retrieval
|
|
48
|
+
// failures on 2nd call to simulateCall with merkle ops on
|
|
49
|
+
const stateManager = AvmPersistableStateManager.create(
|
|
50
|
+
worldStateDB,
|
|
51
|
+
trace,
|
|
52
|
+
/*doMerkleOperations=*/ false,
|
|
53
|
+
firstNullifier,
|
|
54
|
+
);
|
|
55
|
+
return new AvmSimulationTester(contractDataSource, merkleTrees, stateManager);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Simulate a top-level contract call.
|
|
60
|
+
*/
|
|
61
|
+
async simulateCall(
|
|
62
|
+
sender: AztecAddress,
|
|
63
|
+
address: AztecAddress,
|
|
64
|
+
fnName: string,
|
|
65
|
+
args: any[],
|
|
66
|
+
isStaticCall = false,
|
|
67
|
+
): Promise<AvmContractCallResult> {
|
|
68
|
+
const contractArtifact = await this.contractDataSource.getContractArtifact(address);
|
|
69
|
+
if (!contractArtifact) {
|
|
70
|
+
throw new Error(`Contract not found at address: ${address}`);
|
|
71
|
+
}
|
|
72
|
+
const fnSelector = await getFunctionSelector(fnName, contractArtifact);
|
|
73
|
+
const fnAbi = getContractFunctionArtifact(fnName, contractArtifact);
|
|
74
|
+
const encodedArgs = encodeArguments(fnAbi!, args);
|
|
75
|
+
const calldata = [fnSelector.toField(), ...encodedArgs];
|
|
76
|
+
|
|
77
|
+
const globals = GlobalVariables.empty();
|
|
78
|
+
globals.timestamp = TIMESTAMP;
|
|
79
|
+
globals.gasFees = DEFAULT_GAS_FEES;
|
|
80
|
+
|
|
81
|
+
const environment = initExecutionEnvironment({
|
|
82
|
+
calldata,
|
|
83
|
+
globals,
|
|
84
|
+
address,
|
|
85
|
+
sender,
|
|
86
|
+
isStaticCall,
|
|
87
|
+
});
|
|
88
|
+
const persistableState = await this.stateManager.fork();
|
|
89
|
+
const context = initContext({ env: environment, persistableState });
|
|
90
|
+
|
|
91
|
+
// First we simulate (though it's not needed in this simple case).
|
|
92
|
+
const simulator = new AvmSimulator(context);
|
|
93
|
+
const result = await simulator.execute();
|
|
94
|
+
if (result.reverted) {
|
|
95
|
+
this.logger.error(`Error in ${fnName}:`);
|
|
96
|
+
this.logger.error(
|
|
97
|
+
resolveContractAssertionMessage(fnName, result.revertReason!, result.output, contractArtifact)!,
|
|
98
|
+
);
|
|
99
|
+
} else {
|
|
100
|
+
this.logger.info(`Simulation of function ${fnName} succeeded!`);
|
|
101
|
+
await this.stateManager.merge(persistableState);
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { DEPLOYER_CONTRACT_ADDRESS } from '@aztec/constants';
|
|
2
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
5
|
+
import { computeFeePayerBalanceStorageSlot, getCanonicalFeeJuice } from '@aztec/protocol-contracts/fee-juice';
|
|
6
|
+
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
7
|
+
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
8
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
9
|
+
import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
10
|
+
import { computePublicDataTreeLeafSlot, siloNullifier } from '@aztec/stdlib/hash';
|
|
11
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
12
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
13
|
+
|
|
14
|
+
import { createContractClassAndInstance } from './index.js';
|
|
15
|
+
import type { SimpleContractDataSource } from './simple_contract_data_source.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* An abstract test class that enables tests of real apps in the AVM without requiring e2e tests.
|
|
19
|
+
* It enables this by letting us (1) perform pseudo-contract-deployments (and registrations)
|
|
20
|
+
* that trigger merkle tree operations and (2) maintain a contract data source to store
|
|
21
|
+
* and retrieve contract classes and instances.
|
|
22
|
+
*
|
|
23
|
+
* This class is meant to be extended when writing tests for a specific simulation interface.
|
|
24
|
+
* For example, has been extended for testing of the core AvmSimulator, and again for the PublicTxSimulator,
|
|
25
|
+
* both of which benefit from such pseudo-deployments by populating merkle trees and a contract data source
|
|
26
|
+
* with contract information.
|
|
27
|
+
*/
|
|
28
|
+
export abstract class BaseAvmSimulationTester {
|
|
29
|
+
public logger = createLogger('avm-simulation-tester');
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
public contractDataSource: SimpleContractDataSource,
|
|
33
|
+
public merkleTrees: MerkleTreeWriteOperations,
|
|
34
|
+
private initialFeePayerBalance = new Fr(10 ** 10),
|
|
35
|
+
) {}
|
|
36
|
+
|
|
37
|
+
async setFeePayerBalance(feePayer: AztecAddress, balance = this.initialFeePayerBalance) {
|
|
38
|
+
const feeJuiceAddress = ProtocolContractAddress.FeeJuice;
|
|
39
|
+
const balanceSlot = await computeFeePayerBalanceStorageSlot(feePayer);
|
|
40
|
+
await this.setPublicStorage(feeJuiceAddress, balanceSlot, balance);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async setPublicStorage(address: AztecAddress, slot: Fr, value: Fr) {
|
|
44
|
+
const leafSlot = await computePublicDataTreeLeafSlot(address, slot);
|
|
45
|
+
// get existing preimage
|
|
46
|
+
const publicDataWrite = new PublicDataWrite(leafSlot, value);
|
|
47
|
+
await this.merkleTrees.batchInsert(MerkleTreeId.PUBLIC_DATA_TREE, [publicDataWrite.toBuffer()], 0);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Derive the contract class and instance with some seed.
|
|
52
|
+
* Add both to the contract data source along with the contract artifact.
|
|
53
|
+
*/
|
|
54
|
+
async registerAndDeployContract(
|
|
55
|
+
constructorArgs: any[],
|
|
56
|
+
deployer: AztecAddress,
|
|
57
|
+
contractArtifact: ContractArtifact,
|
|
58
|
+
skipNullifierInsertion = false,
|
|
59
|
+
seed = 0,
|
|
60
|
+
originalContractClassId?: Fr, // if previously upgraded
|
|
61
|
+
): Promise<ContractInstanceWithAddress> {
|
|
62
|
+
const { contractClass, contractInstance } = await createContractClassAndInstance(
|
|
63
|
+
constructorArgs,
|
|
64
|
+
deployer,
|
|
65
|
+
contractArtifact,
|
|
66
|
+
seed,
|
|
67
|
+
originalContractClassId,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
await this.contractDataSource.addNewContract(contractArtifact, contractClass, contractInstance);
|
|
71
|
+
|
|
72
|
+
if (!skipNullifierInsertion) {
|
|
73
|
+
await this.insertContractAddressNullifier(contractInstance.address);
|
|
74
|
+
}
|
|
75
|
+
return contractInstance;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async registerFeeJuiceContract(): Promise<ContractInstanceWithAddress> {
|
|
79
|
+
const feeJuice = await getCanonicalFeeJuice();
|
|
80
|
+
const feeJuiceContractClassPublic = {
|
|
81
|
+
...feeJuice.contractClass,
|
|
82
|
+
privateFunctions: [],
|
|
83
|
+
unconstrainedFunctions: [],
|
|
84
|
+
};
|
|
85
|
+
await this.contractDataSource.addNewContract(feeJuice.artifact, feeJuiceContractClassPublic, feeJuice.instance);
|
|
86
|
+
return feeJuice.instance;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
addContractClass(contractClass: ContractClassPublic, contractArtifact: ContractArtifact): Promise<void> {
|
|
90
|
+
this.logger.debug(`Adding contract class with Id ${contractClass.id}`);
|
|
91
|
+
this.contractDataSource.addContractArtifact(contractClass.id, contractArtifact);
|
|
92
|
+
return this.contractDataSource.addContractClass(contractClass);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async addContractInstance(contractInstance: ContractInstanceWithAddress, skipNullifierInsertion = false) {
|
|
96
|
+
if (!skipNullifierInsertion) {
|
|
97
|
+
await this.insertContractAddressNullifier(contractInstance.address);
|
|
98
|
+
}
|
|
99
|
+
await this.contractDataSource.addContractInstance(contractInstance);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private async insertContractAddressNullifier(contractAddress: AztecAddress) {
|
|
103
|
+
const contractAddressNullifier = await siloNullifier(
|
|
104
|
+
AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS),
|
|
105
|
+
contractAddress.toField(),
|
|
106
|
+
);
|
|
107
|
+
await this.merkleTrees.batchInsert(MerkleTreeId.NULLIFIER_TREE, [contractAddressNullifier.toBuffer()], 0);
|
|
108
|
+
}
|
|
109
|
+
}
|