@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
package/package.json
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aztec/simulator",
|
|
3
|
+
"version": "0.0.0-test.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./server": "./dest/server.js",
|
|
7
|
+
"./client": "./dest/client.js",
|
|
8
|
+
"./public/fixtures": "./dest/public/fixtures/index.js"
|
|
9
|
+
},
|
|
10
|
+
"typedocOptions": {
|
|
11
|
+
"entryPoints": [
|
|
12
|
+
"./src/index.ts"
|
|
13
|
+
],
|
|
14
|
+
"name": "Simulator",
|
|
15
|
+
"tsconfig": "./tsconfig.json"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "yarn clean && tsc -b",
|
|
19
|
+
"build:dev": "tsc -b --watch",
|
|
20
|
+
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
21
|
+
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
|
|
22
|
+
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
|
|
23
|
+
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
24
|
+
},
|
|
25
|
+
"inherits": [
|
|
26
|
+
"../package.common.json"
|
|
27
|
+
],
|
|
28
|
+
"jest": {
|
|
29
|
+
"moduleNameMapper": {
|
|
30
|
+
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
|
|
31
|
+
},
|
|
32
|
+
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
|
|
33
|
+
"rootDir": "./src",
|
|
34
|
+
"transform": {
|
|
35
|
+
"^.+\\.tsx?$": [
|
|
36
|
+
"@swc/jest",
|
|
37
|
+
{
|
|
38
|
+
"jsc": {
|
|
39
|
+
"parser": {
|
|
40
|
+
"syntax": "typescript",
|
|
41
|
+
"decorators": true
|
|
42
|
+
},
|
|
43
|
+
"transform": {
|
|
44
|
+
"decoratorVersion": "2022-03"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
"extensionsToTreatAsEsm": [
|
|
51
|
+
".ts"
|
|
52
|
+
],
|
|
53
|
+
"reporters": [
|
|
54
|
+
"default"
|
|
55
|
+
],
|
|
56
|
+
"testTimeout": 120000,
|
|
57
|
+
"setupFiles": [
|
|
58
|
+
"../../foundation/src/jest/setup.mjs"
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"@aztec/constants": "0.0.0-test.0",
|
|
63
|
+
"@aztec/foundation": "0.0.0-test.0",
|
|
64
|
+
"@aztec/noir-protocol-circuits-types": "0.0.0-test.0",
|
|
65
|
+
"@aztec/protocol-contracts": "0.0.0-test.0",
|
|
66
|
+
"@aztec/stdlib": "0.0.0-test.0",
|
|
67
|
+
"@aztec/telemetry-client": "0.0.0-test.0",
|
|
68
|
+
"@aztec/world-state": "0.0.0-test.0",
|
|
69
|
+
"levelup": "^5.1.1",
|
|
70
|
+
"lodash.clonedeep": "^4.5.0",
|
|
71
|
+
"lodash.merge": "^4.6.2",
|
|
72
|
+
"memdown": "^6.1.1",
|
|
73
|
+
"tslib": "^2.4.0",
|
|
74
|
+
"@aztec/noir-acvm_js": "0.0.0-test.0",
|
|
75
|
+
"@aztec/noir-noirc_abi": "0.0.0-test.0",
|
|
76
|
+
"@aztec/noir-types": "0.0.0-test.0"
|
|
77
|
+
},
|
|
78
|
+
"devDependencies": {
|
|
79
|
+
"@aztec/kv-store": "0.0.0-test.0",
|
|
80
|
+
"@aztec/merkle-tree": "0.0.0-test.0",
|
|
81
|
+
"@aztec/noir-contracts.js": "0.0.0-test.0",
|
|
82
|
+
"@jest/globals": "^29.5.0",
|
|
83
|
+
"@types/jest": "^29.5.0",
|
|
84
|
+
"@types/levelup": "^5.1.3",
|
|
85
|
+
"@types/lodash.clonedeep": "^4.5.7",
|
|
86
|
+
"@types/lodash.merge": "^4.6.9",
|
|
87
|
+
"@types/memdown": "^3.0.2",
|
|
88
|
+
"@types/node": "^18.7.23",
|
|
89
|
+
"jest": "^29.5.0",
|
|
90
|
+
"jest-mock-extended": "^3.0.4",
|
|
91
|
+
"ts-node": "^10.9.1",
|
|
92
|
+
"typescript": "^5.0.4",
|
|
93
|
+
"viem": "2.22.8"
|
|
94
|
+
},
|
|
95
|
+
"files": [
|
|
96
|
+
"dest",
|
|
97
|
+
"src",
|
|
98
|
+
"!*.test.*"
|
|
99
|
+
],
|
|
100
|
+
"types": "./dest/index.d.ts",
|
|
101
|
+
"engines": {
|
|
102
|
+
"node": ">=18"
|
|
103
|
+
}
|
|
104
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
4
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
6
|
+
import type { NullifierMembershipWitness } from '@aztec/stdlib/trees';
|
|
7
|
+
|
|
8
|
+
import type { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Database interface for providing access to public state.
|
|
12
|
+
*/
|
|
13
|
+
export interface PublicStateDB {
|
|
14
|
+
/**
|
|
15
|
+
* Reads a value from public storage, returning zero if none.
|
|
16
|
+
* @param contract - Owner of the storage.
|
|
17
|
+
* @param slot - Slot to read in the contract storage.
|
|
18
|
+
* @returns The current value in the storage slot.
|
|
19
|
+
*/
|
|
20
|
+
storageRead(contract: AztecAddress, slot: Fr): Promise<Fr>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Records a write to public storage.
|
|
24
|
+
* @param contract - Owner of the storage.
|
|
25
|
+
* @param slot - Slot to read in the contract storage.
|
|
26
|
+
* @param newValue - The new value to store.
|
|
27
|
+
*/
|
|
28
|
+
storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Database interface for providing access to public contract data.
|
|
33
|
+
*/
|
|
34
|
+
export interface PublicContractsDB {
|
|
35
|
+
/**
|
|
36
|
+
* Returns a publicly deployed contract instance.
|
|
37
|
+
* @param address - Address of the contract.
|
|
38
|
+
* @returns The contract instance or undefined if not found.
|
|
39
|
+
*/
|
|
40
|
+
getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined>;
|
|
41
|
+
|
|
42
|
+
getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Database interface for providing access to commitment tree, l1 to l2 message tree, and nullifier tree. */
|
|
46
|
+
export interface CommitmentsDB {
|
|
47
|
+
/**
|
|
48
|
+
* Fetches a message from the db, given its key.
|
|
49
|
+
* @param contractAddress - Address of a contract by which the message was emitted.
|
|
50
|
+
* @param messageHash - Hash of the message.
|
|
51
|
+
* @param secret - Secret used to compute a nullifier.
|
|
52
|
+
* @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages
|
|
53
|
+
* @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
|
|
54
|
+
*/
|
|
55
|
+
getL1ToL2MembershipWitness(
|
|
56
|
+
contractAddress: AztecAddress,
|
|
57
|
+
messageHash: Fr,
|
|
58
|
+
secret: Fr,
|
|
59
|
+
): Promise<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param leafIndex the leaf to look up
|
|
63
|
+
* @returns The l1 to l2 leaf value or undefined if not found.
|
|
64
|
+
*/
|
|
65
|
+
getL1ToL2LeafValue(leafIndex: bigint): Promise<Fr | undefined>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Gets the index of a commitment in the note hash tree.
|
|
69
|
+
* @param commitment - The commitment.
|
|
70
|
+
* @returns - The index of the commitment. Undefined if it does not exist in the tree.
|
|
71
|
+
*/
|
|
72
|
+
getCommitmentIndex(commitment: Fr): Promise<bigint | undefined>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Gets commitment in the note hash tree given a leaf index.
|
|
76
|
+
* @param leafIndex - the leaf to look up.
|
|
77
|
+
* @returns - The commitment at that index. Undefined if leaf index is not found.
|
|
78
|
+
*/
|
|
79
|
+
getCommitmentValue(leafIndex: bigint): Promise<Fr | undefined>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Gets the index of a nullifier in the nullifier tree.
|
|
83
|
+
* @param nullifier - The nullifier.
|
|
84
|
+
* @returns - The index of the nullifier. Undefined if it does not exist in the tree.
|
|
85
|
+
*/
|
|
86
|
+
getNullifierIndex(nullifier: Fr): Promise<bigint | undefined>;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Returns a nullifier membership witness for the given nullifier or undefined if not found.
|
|
90
|
+
* REFACTOR: Same as getL1ToL2MembershipWitness, can be combined with aztec-node method that does almost the same thing.
|
|
91
|
+
* @param nullifier - Nullifier we're looking for.
|
|
92
|
+
*/
|
|
93
|
+
getNullifierMembershipWitnessAtLatestBlock(nullifier: Fr): Promise<NullifierMembershipWitness | undefined>;
|
|
94
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
|
|
5
|
+
import type { WorldStateDB } from '../public/public_db_sources.js';
|
|
6
|
+
|
|
7
|
+
export async function getPublicFunctionDebugName(
|
|
8
|
+
db: WorldStateDB,
|
|
9
|
+
contractAddress: AztecAddress,
|
|
10
|
+
calldata: Fr[],
|
|
11
|
+
): Promise<string> {
|
|
12
|
+
// Public function is dispatched and therefore the target function is passed in the first argument.
|
|
13
|
+
const targetFunction =
|
|
14
|
+
calldata[0] !== undefined
|
|
15
|
+
? await db.getDebugFunctionName(contractAddress, FunctionSelector.fromField(calldata[0]))
|
|
16
|
+
: `<calldata[0] undefined> (Contract Address: ${contractAddress})`;
|
|
17
|
+
return `${targetFunction}`;
|
|
18
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
3
|
+
import type { BrilligFunctionId, FunctionAbi, FunctionDebugMetadata, OpcodeLocation } from '@aztec/stdlib/abi';
|
|
4
|
+
import {
|
|
5
|
+
type FailingFunction,
|
|
6
|
+
type NoirCallStack,
|
|
7
|
+
SimulationError,
|
|
8
|
+
type SourceCodeLocation,
|
|
9
|
+
} from '@aztec/stdlib/errors';
|
|
10
|
+
|
|
11
|
+
import type { RawAssertionPayload } from '@noir-lang/acvm_js';
|
|
12
|
+
import { abiDecodeError } from '@noir-lang/noirc_abi';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* An error that occurred during the execution of a function.
|
|
16
|
+
* @param message - the error message
|
|
17
|
+
* @param failingFunction - the Aztec function that failed
|
|
18
|
+
* @param noirCallStack - the internal call stack of the function that failed (within the failing Aztec function)
|
|
19
|
+
* @param options - additional error options (an optional "cause" entry allows for a recursive error stack where
|
|
20
|
+
* an error's cause may be an ExecutionError itself)
|
|
21
|
+
*/
|
|
22
|
+
export class ExecutionError extends Error {
|
|
23
|
+
constructor(
|
|
24
|
+
message: string,
|
|
25
|
+
/**
|
|
26
|
+
* The function that failed.
|
|
27
|
+
*/
|
|
28
|
+
public failingFunction: FailingFunction,
|
|
29
|
+
/**
|
|
30
|
+
* The noir call stack of the function that failed.
|
|
31
|
+
*/
|
|
32
|
+
public noirCallStack?: NoirCallStack,
|
|
33
|
+
options?: ErrorOptions,
|
|
34
|
+
) {
|
|
35
|
+
super(message, options);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Traverses the cause chain of an error.
|
|
41
|
+
* @param error - The error to start from.
|
|
42
|
+
* @param callback - A callback on every error, including the first one.
|
|
43
|
+
*/
|
|
44
|
+
export function traverseCauseChain(error: Error, callback: (error: Error) => void) {
|
|
45
|
+
let currentError: Error | undefined = error;
|
|
46
|
+
while (currentError) {
|
|
47
|
+
callback(currentError);
|
|
48
|
+
if (currentError.cause && currentError.cause instanceof Error) {
|
|
49
|
+
currentError = currentError.cause;
|
|
50
|
+
} else {
|
|
51
|
+
currentError = undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creates a simulation error from an error chain generated during the execution of a function.
|
|
58
|
+
* @param error - The error thrown during execution.
|
|
59
|
+
* @returns - A simulation error.
|
|
60
|
+
*/
|
|
61
|
+
export function createSimulationError(error: Error, revertData?: Fr[]): SimulationError {
|
|
62
|
+
let rootCause = error;
|
|
63
|
+
let noirCallStack: NoirCallStack | undefined = undefined;
|
|
64
|
+
const aztecCallStack: FailingFunction[] = [];
|
|
65
|
+
|
|
66
|
+
traverseCauseChain(error, cause => {
|
|
67
|
+
rootCause = cause;
|
|
68
|
+
if (cause instanceof ExecutionError) {
|
|
69
|
+
aztecCallStack.push(cause.failingFunction);
|
|
70
|
+
if (cause.noirCallStack) {
|
|
71
|
+
noirCallStack = cause.noirCallStack;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return new SimulationError(rootCause.message, aztecCallStack, revertData, noirCallStack, { cause: rootCause });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Extracts a brillig location from an opcode location.
|
|
81
|
+
* @param opcodeLocation - The opcode location to extract from. It should be in the format `acirLocation.brilligLocation` or `acirLocation`.
|
|
82
|
+
* @returns The brillig location if the opcode location contains one.
|
|
83
|
+
*/
|
|
84
|
+
function extractBrilligLocation(opcodeLocation: string): string | undefined {
|
|
85
|
+
const splitted = opcodeLocation.split('.');
|
|
86
|
+
if (splitted.length === 2) {
|
|
87
|
+
return splitted[1];
|
|
88
|
+
}
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Extracts the call stack from the location of a failing opcode and the debug metadata.
|
|
94
|
+
* One opcode can point to multiple calls due to inlining.
|
|
95
|
+
*/
|
|
96
|
+
function getSourceCodeLocationsFromOpcodeLocation(
|
|
97
|
+
opcodeLocation: string,
|
|
98
|
+
debug: FunctionDebugMetadata,
|
|
99
|
+
brilligFunctionId?: BrilligFunctionId,
|
|
100
|
+
): SourceCodeLocation[] {
|
|
101
|
+
const { debugSymbols, files } = debug;
|
|
102
|
+
|
|
103
|
+
let callStack = debugSymbols.locations[opcodeLocation] || [];
|
|
104
|
+
if (callStack.length === 0) {
|
|
105
|
+
const brilligLocation = extractBrilligLocation(opcodeLocation);
|
|
106
|
+
if (brilligFunctionId !== undefined && brilligLocation !== undefined) {
|
|
107
|
+
callStack = debugSymbols.brillig_locations[brilligFunctionId][brilligLocation] || [];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return callStack.map(call => {
|
|
111
|
+
const { file: fileId, span } = call;
|
|
112
|
+
|
|
113
|
+
const { path, source } = files[fileId];
|
|
114
|
+
|
|
115
|
+
const locationText = source.substring(span.start, span.end);
|
|
116
|
+
const precedingText = source.substring(0, span.start);
|
|
117
|
+
const previousLines = precedingText.split('\n');
|
|
118
|
+
// Lines and columns in stacks are one indexed.
|
|
119
|
+
const line = previousLines.length;
|
|
120
|
+
const column = previousLines[previousLines.length - 1].length + 1;
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
filePath: path,
|
|
124
|
+
line,
|
|
125
|
+
column,
|
|
126
|
+
fileSource: source,
|
|
127
|
+
locationText,
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Extracts the source code locations for an array of opcode locations
|
|
134
|
+
* @param opcodeLocations - The opcode locations that caused the error.
|
|
135
|
+
* @param debug - The debug metadata of the function.
|
|
136
|
+
* @returns The source code locations.
|
|
137
|
+
*/
|
|
138
|
+
export function resolveOpcodeLocations(
|
|
139
|
+
opcodeLocations: OpcodeLocation[],
|
|
140
|
+
debug: FunctionDebugMetadata,
|
|
141
|
+
brilligFunctionId?: BrilligFunctionId,
|
|
142
|
+
): SourceCodeLocation[] {
|
|
143
|
+
return opcodeLocations.flatMap(opcodeLocation =>
|
|
144
|
+
getSourceCodeLocationsFromOpcodeLocation(opcodeLocation, debug, brilligFunctionId),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function resolveAssertionMessage(errorPayload: RawAssertionPayload, abi: FunctionAbi): string | undefined {
|
|
149
|
+
const decoded = abiDecodeError(
|
|
150
|
+
{ parameters: [], error_types: abi.errorTypes, return_type: null }, // eslint-disable-line camelcase
|
|
151
|
+
errorPayload,
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
if (typeof decoded === 'string') {
|
|
155
|
+
return decoded;
|
|
156
|
+
} else {
|
|
157
|
+
return jsonStringify(decoded);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function resolveAssertionMessageFromRevertData(revertData: Fr[], abi: FunctionAbi): string | undefined {
|
|
162
|
+
if (revertData.length == 0) {
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const [errorSelector, ...errorData] = revertData;
|
|
167
|
+
|
|
168
|
+
return resolveAssertionMessage(
|
|
169
|
+
{
|
|
170
|
+
selector: errorSelector.toBigInt().toString(),
|
|
171
|
+
data: errorData.map(f => f.toString()),
|
|
172
|
+
},
|
|
173
|
+
abi,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function resolveAssertionMessageFromError(err: Error, abi: FunctionAbi): string {
|
|
178
|
+
if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err && err.rawAssertionPayload) {
|
|
179
|
+
return `Assertion failed: ${resolveAssertionMessage(err.rawAssertionPayload as RawAssertionPayload, abi)}`;
|
|
180
|
+
} else {
|
|
181
|
+
return err.message;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import type { SiblingPath } from '@aztec/foundation/trees';
|
|
3
|
+
|
|
4
|
+
export class MessageLoadOracleInputs<N extends number> {
|
|
5
|
+
constructor(
|
|
6
|
+
/** The index of the message commitment in the merkle tree. */
|
|
7
|
+
public index: bigint,
|
|
8
|
+
/** The path in the merkle tree to the message. */
|
|
9
|
+
public siblingPath: SiblingPath<N>,
|
|
10
|
+
) {}
|
|
11
|
+
|
|
12
|
+
toFields(): Fr[] {
|
|
13
|
+
return [new Fr(this.index), ...this.siblingPath.toFields()];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './stats.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
import type { CircuitName, CircuitSimulationStats } from '@aztec/stdlib/stats';
|
|
3
|
+
|
|
4
|
+
export function emitCircuitSimulationStats(
|
|
5
|
+
circuitName: CircuitName,
|
|
6
|
+
duration: number,
|
|
7
|
+
inputSize: number,
|
|
8
|
+
outputSize: number,
|
|
9
|
+
logger: Logger,
|
|
10
|
+
) {
|
|
11
|
+
const stats: CircuitSimulationStats = {
|
|
12
|
+
eventName: 'circuit-simulation',
|
|
13
|
+
circuitName,
|
|
14
|
+
inputSize,
|
|
15
|
+
outputSize,
|
|
16
|
+
duration,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
logger.debug('Circuit simulation stats', stats);
|
|
20
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import type { FunctionDebugMetadata } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { NoirCallStack } from '@aztec/stdlib/errors';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
type ExecutionError,
|
|
7
|
+
type ForeignCallInput,
|
|
8
|
+
type ForeignCallOutput,
|
|
9
|
+
executeCircuitWithReturnWitness,
|
|
10
|
+
} from '@noir-lang/acvm_js';
|
|
11
|
+
|
|
12
|
+
import { resolveOpcodeLocations, traverseCauseChain } from '../../common/errors.js';
|
|
13
|
+
import type { ACVMWitness } from './acvm_types.js';
|
|
14
|
+
import type { ORACLE_NAMES } from './oracle/index.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The callback interface for the ACIR.
|
|
18
|
+
*/
|
|
19
|
+
export type ACIRCallback = Record<
|
|
20
|
+
ORACLE_NAMES,
|
|
21
|
+
(
|
|
22
|
+
...args: ForeignCallInput[]
|
|
23
|
+
) =>
|
|
24
|
+
| void
|
|
25
|
+
| Promise<void>
|
|
26
|
+
| ForeignCallOutput
|
|
27
|
+
| ForeignCallOutput[]
|
|
28
|
+
| Promise<ForeignCallOutput>
|
|
29
|
+
| Promise<ForeignCallOutput[]>
|
|
30
|
+
>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The result of executing an ACIR.
|
|
34
|
+
*/
|
|
35
|
+
export interface ACIRExecutionResult {
|
|
36
|
+
/**
|
|
37
|
+
* An execution result contains two witnesses.
|
|
38
|
+
* 1. The partial witness of the execution.
|
|
39
|
+
* 2. The return witness which contains the given public return values within the full witness.
|
|
40
|
+
*/
|
|
41
|
+
partialWitness: ACVMWitness;
|
|
42
|
+
returnWitness: ACVMWitness;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The function call that executes an ACIR.
|
|
47
|
+
*/
|
|
48
|
+
export async function acvm(
|
|
49
|
+
acir: Buffer,
|
|
50
|
+
initialWitness: ACVMWitness,
|
|
51
|
+
callback: ACIRCallback,
|
|
52
|
+
): Promise<ACIRExecutionResult> {
|
|
53
|
+
const logger = createLogger('simulator:acvm');
|
|
54
|
+
|
|
55
|
+
const solvedAndReturnWitness = await executeCircuitWithReturnWitness(
|
|
56
|
+
acir,
|
|
57
|
+
initialWitness,
|
|
58
|
+
async (name: string, args: ForeignCallInput[]) => {
|
|
59
|
+
try {
|
|
60
|
+
logger.debug(`Oracle callback ${name}`);
|
|
61
|
+
const oracleFunction = callback[name as ORACLE_NAMES];
|
|
62
|
+
if (!oracleFunction) {
|
|
63
|
+
throw new Error(`Oracle callback ${name} not found`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const result = await oracleFunction.call(callback, ...args);
|
|
67
|
+
|
|
68
|
+
if (typeof result === 'undefined') {
|
|
69
|
+
return [];
|
|
70
|
+
} else if (result instanceof Array && !result.every(item => typeof item === 'string')) {
|
|
71
|
+
// We are dealing with a nested array which means that we do not need it wrap it in another array as to have
|
|
72
|
+
// the nested array structure it is already "wrapped".
|
|
73
|
+
return result;
|
|
74
|
+
} else {
|
|
75
|
+
return [result] as ForeignCallOutput[];
|
|
76
|
+
}
|
|
77
|
+
} catch (err) {
|
|
78
|
+
let typedError: Error;
|
|
79
|
+
if (err instanceof Error) {
|
|
80
|
+
typedError = err;
|
|
81
|
+
} else {
|
|
82
|
+
typedError = new Error(`Error in oracle callback ${err}`);
|
|
83
|
+
}
|
|
84
|
+
logger.error(`Error in oracle callback ${name}: ${typedError.message}`);
|
|
85
|
+
throw typedError;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
).catch((err: Error) => {
|
|
89
|
+
// Wasm callbacks act as a boundary for stack traces, so we capture it here and complete the error if it happens.
|
|
90
|
+
const stack = new Error().stack;
|
|
91
|
+
|
|
92
|
+
traverseCauseChain(err, cause => {
|
|
93
|
+
if (cause.stack) {
|
|
94
|
+
cause.stack += stack;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
throw err;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return { partialWitness: solvedAndReturnWitness.solvedWitness, returnWitness: solvedAndReturnWitness.returnWitness };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Extracts the call stack from an thrown by the acvm.
|
|
106
|
+
* @param error - The error to extract from.
|
|
107
|
+
* @param debug - The debug metadata of the function called.
|
|
108
|
+
* @returns The call stack, if available.
|
|
109
|
+
*/
|
|
110
|
+
export function extractCallStack(
|
|
111
|
+
error: Error | ExecutionError,
|
|
112
|
+
debug?: FunctionDebugMetadata,
|
|
113
|
+
): NoirCallStack | undefined {
|
|
114
|
+
if (!('callStack' in error) || !error.callStack) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
const { callStack, brilligFunctionId } = error;
|
|
118
|
+
if (!debug) {
|
|
119
|
+
return callStack;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
return resolveOpcodeLocations(callStack, debug, brilligFunctionId);
|
|
124
|
+
} catch (err) {
|
|
125
|
+
return callStack;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
|
|
3
|
+
import type { ACVMField, ACVMWitness } from './acvm_types.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Converts an ACVM field to a Fr.
|
|
7
|
+
* @param field - The ACVM field to convert.
|
|
8
|
+
* @returns The Fr.
|
|
9
|
+
*/
|
|
10
|
+
export function fromACVMField(field: ACVMField): Fr {
|
|
11
|
+
return Fr.fromBuffer(Buffer.from(field.slice(2), 'hex'));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Converts a field to a number.
|
|
16
|
+
* @param fr - The field to convert.
|
|
17
|
+
* @returns The number.
|
|
18
|
+
* TODO(#4102): Nuke this once block number is big int.
|
|
19
|
+
*/
|
|
20
|
+
export function frToNumber(fr: Fr): number {
|
|
21
|
+
return Number(fr.value);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Converts a field to a boolean.
|
|
26
|
+
* @param fr - The field to convert.
|
|
27
|
+
*/
|
|
28
|
+
export function frToBoolean(fr: Fr): boolean {
|
|
29
|
+
return fr.toBigInt() === BigInt(1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Converts a Noir BoundedVec of Fields into an Fr array. Note that BoundedVecs are structs, and therefore translated as
|
|
34
|
+
* two separate ACVMField values (an array and a single field).
|
|
35
|
+
*
|
|
36
|
+
* @param storage The array with the BoundedVec's storage (i.e. BoundedVec::storage())
|
|
37
|
+
* @param length The length of the BoundedVec (i.e. BoundedVec::len())
|
|
38
|
+
* @returns An array with the same content as the Noir version. Elements past the length are discarded.
|
|
39
|
+
*/
|
|
40
|
+
export function fromBoundedVec(storage: ACVMField[], length: ACVMField): Fr[] {
|
|
41
|
+
return storage.slice(0, frToNumber(fromACVMField(length))).map(fromACVMField);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Transforms a witness map to its field elements.
|
|
46
|
+
* @param witness - The witness to extract from.
|
|
47
|
+
* @returns The return values.
|
|
48
|
+
*/
|
|
49
|
+
export function witnessMapToFields(witness: ACVMWitness): Fr[] {
|
|
50
|
+
const sortedKeys = [...witness.keys()].sort((a, b) => a - b);
|
|
51
|
+
return sortedKeys.map(key => witness.get(key)!).map(fromACVMField);
|
|
52
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Oracle } from './oracle.js';
|
|
2
|
+
|
|
3
|
+
export * from './oracle.js';
|
|
4
|
+
export * from './typed_oracle.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A conditional type that takes a type `T` and returns a union of its method names.
|
|
8
|
+
*/
|
|
9
|
+
type MethodNames<T> = {
|
|
10
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
|
|
11
|
+
}[keyof T];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Available oracle function names.
|
|
15
|
+
*/
|
|
16
|
+
export type ORACLE_NAMES = MethodNames<Oracle>;
|