@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,129 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import { type ContractClassPublic, type ContractDataSource, type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
5
|
+
import type { MerkleTreeCheckpointOperations, MerkleTreeReadOperations, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
6
|
+
import type { Tx } from '@aztec/stdlib/tx';
|
|
7
|
+
import type { PublicContractsDB, PublicStateDB } from '../common/db_interfaces.js';
|
|
8
|
+
/**
|
|
9
|
+
* Implements the PublicContractsDB using a ContractDataSource.
|
|
10
|
+
* Progressively records contracts in transaction as they are processed in a block.
|
|
11
|
+
* Separates block-level contract information (from processed/included txs) from the
|
|
12
|
+
* current tx's contract information (which may be cleared on tx revert/death).
|
|
13
|
+
*/
|
|
14
|
+
export declare class ContractsDataSourcePublicDB implements PublicContractsDB {
|
|
15
|
+
private dataSource;
|
|
16
|
+
private currentTxNonRevertibleCache;
|
|
17
|
+
private currentTxRevertibleCache;
|
|
18
|
+
private blockCache;
|
|
19
|
+
private bytecodeCommitmentCache;
|
|
20
|
+
private log;
|
|
21
|
+
constructor(dataSource: ContractDataSource);
|
|
22
|
+
/**
|
|
23
|
+
* Add new contracts from a transaction
|
|
24
|
+
* @param tx - The transaction to add contracts from.
|
|
25
|
+
*/
|
|
26
|
+
addNewContracts(tx: Tx): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Add non revertible contracts from a transaction
|
|
29
|
+
* @param tx - The transaction to add non revertible contracts from.
|
|
30
|
+
*/
|
|
31
|
+
addNewNonRevertibleContracts(tx: Tx): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Add revertible contracts from a transaction
|
|
34
|
+
* @param tx - The transaction to add revertible contracts from.
|
|
35
|
+
*/
|
|
36
|
+
addNewRevertibleContracts(tx: Tx): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Add non-revertible contract classes from a transaction
|
|
39
|
+
* For private-only txs, this will be all contract classes (found in tx.data.forPublic)
|
|
40
|
+
* @param tx - The transaction to add non-revertible contract classes from.
|
|
41
|
+
*/
|
|
42
|
+
private addNonRevertibleContractClasses;
|
|
43
|
+
/**
|
|
44
|
+
* Add revertible contract classes from a transaction
|
|
45
|
+
* None for private-only txs.
|
|
46
|
+
* @param tx - The transaction to add revertible contract classes from.
|
|
47
|
+
*/
|
|
48
|
+
private addRevertibleContractClasses;
|
|
49
|
+
/**
|
|
50
|
+
* Add non-revertible contract instances from a transaction
|
|
51
|
+
* For private-only txs, this will be all contract instances (found in tx.data.forRollup)
|
|
52
|
+
* @param tx - The transaction to add non-revertible contract instances from.
|
|
53
|
+
*/
|
|
54
|
+
private addNonRevertibleContractInstances;
|
|
55
|
+
/**
|
|
56
|
+
* Add revertible contract instances from a transaction
|
|
57
|
+
* None for private-only txs.
|
|
58
|
+
* @param tx - The transaction to add revertible contract instances from.
|
|
59
|
+
*/
|
|
60
|
+
private addRevertibleContractInstances;
|
|
61
|
+
/**
|
|
62
|
+
* Given a tx's siloed contract class logs, add the contract classes to the cache
|
|
63
|
+
* @param siloedContractClassLogs - Contract class logs to process
|
|
64
|
+
* @param cache - The cache to store the contract classes in
|
|
65
|
+
* @param cacheType - Type of cache (for logging)
|
|
66
|
+
*/
|
|
67
|
+
private addContractClassesFromLogs;
|
|
68
|
+
/**
|
|
69
|
+
* Given a tx's contract instance logs, add the contract instances to the cache
|
|
70
|
+
* @param contractInstanceLogs - Contract instance logs to process
|
|
71
|
+
* @param cache - The cache to store the contract instances in
|
|
72
|
+
* @param cacheType - Type of cache (for logging)
|
|
73
|
+
*/
|
|
74
|
+
private addContractInstancesFromLogs;
|
|
75
|
+
/**
|
|
76
|
+
* Clear new contracts from the current tx's cache
|
|
77
|
+
*/
|
|
78
|
+
clearContractsForTx(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Commits the current transaction's cached contracts to the block-level cache.
|
|
81
|
+
* Then, clears the tx cache.
|
|
82
|
+
*/
|
|
83
|
+
commitContractsForTx(onlyNonRevertibles?: boolean): void;
|
|
84
|
+
getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined>;
|
|
85
|
+
getContractClass(contractClassId: Fr): Promise<ContractClassPublic | undefined>;
|
|
86
|
+
getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined>;
|
|
87
|
+
getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* A public state DB that reads and writes to the world state.
|
|
91
|
+
*/
|
|
92
|
+
export declare class WorldStateDB extends ContractsDataSourcePublicDB implements PublicStateDB, MerkleTreeCheckpointOperations {
|
|
93
|
+
db: MerkleTreeWriteOperations;
|
|
94
|
+
private logger;
|
|
95
|
+
constructor(db: MerkleTreeWriteOperations, dataSource: ContractDataSource);
|
|
96
|
+
/**
|
|
97
|
+
* Checkpoints the current fork state
|
|
98
|
+
*/
|
|
99
|
+
createCheckpoint(): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Commits the current checkpoint
|
|
102
|
+
*/
|
|
103
|
+
commitCheckpoint(): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Reverts the current checkpoint
|
|
106
|
+
*/
|
|
107
|
+
revertCheckpoint(): Promise<void>;
|
|
108
|
+
getMerkleInterface(): MerkleTreeWriteOperations;
|
|
109
|
+
/**
|
|
110
|
+
* Reads a value from public storage, returning zero if none.
|
|
111
|
+
* @param contract - Owner of the storage.
|
|
112
|
+
* @param slot - Slot to read in the contract storage.
|
|
113
|
+
* @returns The current value in the storage slot.
|
|
114
|
+
*/
|
|
115
|
+
storageRead(contract: AztecAddress, slot: Fr): Promise<Fr>;
|
|
116
|
+
/**
|
|
117
|
+
* Records a write to public storage.
|
|
118
|
+
* @param contract - Owner of the storage.
|
|
119
|
+
* @param slot - Slot to read in the contract storage.
|
|
120
|
+
* @param newValue - The new value to store.
|
|
121
|
+
* @returns The slot of the written leaf in the public data tree.
|
|
122
|
+
*/
|
|
123
|
+
storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise<void>;
|
|
124
|
+
getL1ToL2LeafValue(leafIndex: bigint): Promise<Fr | undefined>;
|
|
125
|
+
getCommitmentValue(leafIndex: bigint): Promise<Fr | undefined>;
|
|
126
|
+
getNullifierIndex(nullifier: Fr): Promise<bigint | undefined>;
|
|
127
|
+
}
|
|
128
|
+
export declare function readPublicState(db: MerkleTreeReadOperations, contract: AztecAddress, slot: Fr): Promise<Fr>;
|
|
129
|
+
//# sourceMappingURL=public_db_sources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public_db_sources.d.ts","sourceRoot":"","sources":["../../src/public/public_db_sources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAK9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAEjC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EACV,8BAA8B,EAC9B,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,iCAAiC,CAAC;AAIzC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAGnF;;;;;GAKG;AACH,qBAAa,2BAA4B,YAAW,iBAAiB;IAgBvD,OAAO,CAAC,UAAU;IAR9B,OAAO,CAAC,2BAA2B,CAAyB;IAC5D,OAAO,CAAC,wBAAwB,CAAyB;IACzD,OAAO,CAAC,UAAU,CAAyB;IAE3C,OAAO,CAAC,uBAAuB,CAAyB;IAExD,OAAO,CAAC,GAAG,CAAmD;gBAE1C,UAAU,EAAE,kBAAkB;IAElD;;;OAGG;IACU,eAAe,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAOnD;;;OAGG;IACU,4BAA4B,CAAC,EAAE,EAAE,EAAE;IAKhD;;;OAGG;IACU,yBAAyB,CAAC,EAAE,EAAE,EAAE;IAK7C;;;;OAIG;YACW,+BAA+B;IAW7C;;;;OAIG;YACW,4BAA4B;IAW1C;;;;OAIG;IACH,OAAO,CAAC,iCAAiC;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AAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;IAW9D,iBAAiB,CAAC,SAAS,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CAU3E;AAED,wBAAsB,eAAe,CAAC,EAAE,EAAE,wBAAwB,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,CAcjH"}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
4
|
+
import { ContractClassRegisteredEvent } from '@aztec/protocol-contracts/class-registerer';
|
|
5
|
+
import { ContractInstanceDeployedEvent } from '@aztec/protocol-contracts/instance-deployer';
|
|
6
|
+
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
7
|
+
import { computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
|
|
8
|
+
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
9
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
10
|
+
import { TxContractCache } from './tx_contract_cache.js';
|
|
11
|
+
/**
|
|
12
|
+
* Implements the PublicContractsDB using a ContractDataSource.
|
|
13
|
+
* Progressively records contracts in transaction as they are processed in a block.
|
|
14
|
+
* Separates block-level contract information (from processed/included txs) from the
|
|
15
|
+
* current tx's contract information (which may be cleared on tx revert/death).
|
|
16
|
+
*/ export class ContractsDataSourcePublicDB {
|
|
17
|
+
dataSource;
|
|
18
|
+
// Two caching layers for contract classes and instances.
|
|
19
|
+
// Tx-level cache:
|
|
20
|
+
// - The current tx's new contract information is cached
|
|
21
|
+
// in currentTxNonRevertibleCache and currentTxRevertibleCache.
|
|
22
|
+
// Block-level cache:
|
|
23
|
+
// - Contract information from earlier in the block, usable by later txs.
|
|
24
|
+
// When a tx succeeds, that tx's caches are merged into the block cache and cleared.
|
|
25
|
+
currentTxNonRevertibleCache;
|
|
26
|
+
currentTxRevertibleCache;
|
|
27
|
+
blockCache;
|
|
28
|
+
// Separate flat cache for bytecode commitments.
|
|
29
|
+
bytecodeCommitmentCache;
|
|
30
|
+
log;
|
|
31
|
+
constructor(dataSource){
|
|
32
|
+
this.dataSource = dataSource;
|
|
33
|
+
this.currentTxNonRevertibleCache = new TxContractCache();
|
|
34
|
+
this.currentTxRevertibleCache = new TxContractCache();
|
|
35
|
+
this.blockCache = new TxContractCache();
|
|
36
|
+
this.bytecodeCommitmentCache = new Map();
|
|
37
|
+
this.log = createLogger('simulator:contracts-data-source');
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Add new contracts from a transaction
|
|
41
|
+
* @param tx - The transaction to add contracts from.
|
|
42
|
+
*/ async addNewContracts(tx) {
|
|
43
|
+
await this.addNonRevertibleContractClasses(tx);
|
|
44
|
+
await this.addRevertibleContractClasses(tx);
|
|
45
|
+
this.addNonRevertibleContractInstances(tx);
|
|
46
|
+
this.addRevertibleContractInstances(tx);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Add non revertible contracts from a transaction
|
|
50
|
+
* @param tx - The transaction to add non revertible contracts from.
|
|
51
|
+
*/ async addNewNonRevertibleContracts(tx) {
|
|
52
|
+
await this.addNonRevertibleContractClasses(tx);
|
|
53
|
+
this.addNonRevertibleContractInstances(tx);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Add revertible contracts from a transaction
|
|
57
|
+
* @param tx - The transaction to add revertible contracts from.
|
|
58
|
+
*/ async addNewRevertibleContracts(tx) {
|
|
59
|
+
await this.addRevertibleContractClasses(tx);
|
|
60
|
+
this.addRevertibleContractInstances(tx);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Add non-revertible contract classes from a transaction
|
|
64
|
+
* For private-only txs, this will be all contract classes (found in tx.data.forPublic)
|
|
65
|
+
* @param tx - The transaction to add non-revertible contract classes from.
|
|
66
|
+
*/ async addNonRevertibleContractClasses(tx) {
|
|
67
|
+
const siloedContractClassLogs = tx.data.forPublic ? await tx.filterContractClassLogs(tx.data.forPublic.nonRevertibleAccumulatedData.contractClassLogsHashes, /*siloed=*/ true) : await tx.filterContractClassLogs(tx.data.forRollup.end.contractClassLogsHashes, /*siloed=*/ true);
|
|
68
|
+
await this.addContractClassesFromLogs(siloedContractClassLogs, this.currentTxNonRevertibleCache, 'non-revertible');
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Add revertible contract classes from a transaction
|
|
72
|
+
* None for private-only txs.
|
|
73
|
+
* @param tx - The transaction to add revertible contract classes from.
|
|
74
|
+
*/ async addRevertibleContractClasses(tx) {
|
|
75
|
+
const siloedContractClassLogs = tx.data.forPublic ? await tx.filterContractClassLogs(tx.data.forPublic.revertibleAccumulatedData.contractClassLogsHashes, /*siloed=*/ true) : [];
|
|
76
|
+
await this.addContractClassesFromLogs(siloedContractClassLogs, this.currentTxRevertibleCache, 'revertible');
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Add non-revertible contract instances from a transaction
|
|
80
|
+
* For private-only txs, this will be all contract instances (found in tx.data.forRollup)
|
|
81
|
+
* @param tx - The transaction to add non-revertible contract instances from.
|
|
82
|
+
*/ addNonRevertibleContractInstances(tx) {
|
|
83
|
+
const contractInstanceLogs = tx.data.forPublic ? tx.data.forPublic.nonRevertibleAccumulatedData.privateLogs.filter((l)=>!l.isEmpty()) : tx.data.forRollup.end.privateLogs.filter((l)=>!l.isEmpty());
|
|
84
|
+
this.addContractInstancesFromLogs(contractInstanceLogs, this.currentTxNonRevertibleCache, 'non-revertible');
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Add revertible contract instances from a transaction
|
|
88
|
+
* None for private-only txs.
|
|
89
|
+
* @param tx - The transaction to add revertible contract instances from.
|
|
90
|
+
*/ addRevertibleContractInstances(tx) {
|
|
91
|
+
const contractInstanceLogs = tx.data.forPublic ? tx.data.forPublic.revertibleAccumulatedData.privateLogs.filter((l)=>!l.isEmpty()) : [];
|
|
92
|
+
this.addContractInstancesFromLogs(contractInstanceLogs, this.currentTxRevertibleCache, 'revertible');
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Given a tx's siloed contract class logs, add the contract classes to the cache
|
|
96
|
+
* @param siloedContractClassLogs - Contract class logs to process
|
|
97
|
+
* @param cache - The cache to store the contract classes in
|
|
98
|
+
* @param cacheType - Type of cache (for logging)
|
|
99
|
+
*/ async addContractClassesFromLogs(siloedContractClassLogs, cache, cacheType) {
|
|
100
|
+
const contractClassEvents = siloedContractClassLogs.filter((log)=>ContractClassRegisteredEvent.isContractClassRegisteredEvent(log)).map((log)=>ContractClassRegisteredEvent.fromLog(log));
|
|
101
|
+
// Cache contract classes
|
|
102
|
+
await Promise.all(contractClassEvents.map(async (event)=>{
|
|
103
|
+
this.log.debug(`Adding class ${event.contractClassId.toString()} to contract's ${cacheType} tx cache`);
|
|
104
|
+
const contractClass = await event.toContractClassPublic();
|
|
105
|
+
cache.addClass(event.contractClassId, contractClass);
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Given a tx's contract instance logs, add the contract instances to the cache
|
|
110
|
+
* @param contractInstanceLogs - Contract instance logs to process
|
|
111
|
+
* @param cache - The cache to store the contract instances in
|
|
112
|
+
* @param cacheType - Type of cache (for logging)
|
|
113
|
+
*/ addContractInstancesFromLogs(contractInstanceLogs, cache, cacheType) {
|
|
114
|
+
const contractInstanceEvents = contractInstanceLogs.filter((log)=>ContractInstanceDeployedEvent.isContractInstanceDeployedEvent(log)).map((log)=>ContractInstanceDeployedEvent.fromLog(log));
|
|
115
|
+
// Cache contract instances
|
|
116
|
+
contractInstanceEvents.forEach((e)=>{
|
|
117
|
+
this.log.debug(`Adding instance ${e.address.toString()} with class ${e.contractClassId.toString()} to ${cacheType} tx contract cache`);
|
|
118
|
+
cache.addInstance(e.address, e.toContractInstance());
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Clear new contracts from the current tx's cache
|
|
123
|
+
*/ clearContractsForTx() {
|
|
124
|
+
this.currentTxRevertibleCache.clear();
|
|
125
|
+
this.currentTxRevertibleCache.clear();
|
|
126
|
+
this.currentTxNonRevertibleCache.clear();
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Commits the current transaction's cached contracts to the block-level cache.
|
|
130
|
+
* Then, clears the tx cache.
|
|
131
|
+
*/ commitContractsForTx(onlyNonRevertibles = false) {
|
|
132
|
+
// Merge non-revertible tx cache into block cache
|
|
133
|
+
this.blockCache.mergeFrom(this.currentTxNonRevertibleCache);
|
|
134
|
+
if (!onlyNonRevertibles) {
|
|
135
|
+
// Merge revertible tx cache into block cache
|
|
136
|
+
this.blockCache.mergeFrom(this.currentTxRevertibleCache);
|
|
137
|
+
}
|
|
138
|
+
// Clear the tx's caches
|
|
139
|
+
this.currentTxNonRevertibleCache.clear();
|
|
140
|
+
this.currentTxRevertibleCache.clear();
|
|
141
|
+
}
|
|
142
|
+
async getContractInstance(address) {
|
|
143
|
+
// Check caches in order: tx revertible -> tx non-revertible -> block -> data source
|
|
144
|
+
return this.currentTxRevertibleCache.getInstance(address) ?? this.currentTxNonRevertibleCache.getInstance(address) ?? this.blockCache.getInstance(address) ?? await this.dataSource.getContract(address);
|
|
145
|
+
}
|
|
146
|
+
async getContractClass(contractClassId) {
|
|
147
|
+
// Check caches in order: tx revertible -> tx non-revertible -> block -> data source
|
|
148
|
+
return this.currentTxRevertibleCache.getClass(contractClassId) ?? this.currentTxNonRevertibleCache.getClass(contractClassId) ?? this.blockCache.getClass(contractClassId) ?? await this.dataSource.getContractClass(contractClassId);
|
|
149
|
+
}
|
|
150
|
+
async getBytecodeCommitment(contractClassId) {
|
|
151
|
+
// Try and retrieve from cache
|
|
152
|
+
const key = contractClassId.toString();
|
|
153
|
+
const result = this.bytecodeCommitmentCache.get(key);
|
|
154
|
+
if (result !== undefined) {
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
// Now try from the store
|
|
158
|
+
const fromStore = await this.dataSource.getBytecodeCommitment(contractClassId);
|
|
159
|
+
if (fromStore !== undefined) {
|
|
160
|
+
this.bytecodeCommitmentCache.set(key, fromStore);
|
|
161
|
+
return fromStore;
|
|
162
|
+
}
|
|
163
|
+
// Not in either the store or the cache, build it here and cache
|
|
164
|
+
const contractClass = await this.getContractClass(contractClassId);
|
|
165
|
+
if (contractClass === undefined) {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
const value = await computePublicBytecodeCommitment(contractClass.packedBytecode);
|
|
169
|
+
this.bytecodeCommitmentCache.set(key, value);
|
|
170
|
+
return value;
|
|
171
|
+
}
|
|
172
|
+
async getDebugFunctionName(address, selector) {
|
|
173
|
+
return await this.dataSource.getContractFunctionName(address, selector);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* A public state DB that reads and writes to the world state.
|
|
178
|
+
*/ export class WorldStateDB extends ContractsDataSourcePublicDB {
|
|
179
|
+
db;
|
|
180
|
+
logger;
|
|
181
|
+
constructor(db, dataSource){
|
|
182
|
+
super(dataSource), this.db = db, this.logger = createLogger('simulator:world-state-db');
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Checkpoints the current fork state
|
|
186
|
+
*/ async createCheckpoint() {
|
|
187
|
+
await this.db.createCheckpoint();
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Commits the current checkpoint
|
|
191
|
+
*/ async commitCheckpoint() {
|
|
192
|
+
await this.db.commitCheckpoint();
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Reverts the current checkpoint
|
|
196
|
+
*/ async revertCheckpoint() {
|
|
197
|
+
await this.db.revertCheckpoint();
|
|
198
|
+
}
|
|
199
|
+
getMerkleInterface() {
|
|
200
|
+
return this.db;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Reads a value from public storage, returning zero if none.
|
|
204
|
+
* @param contract - Owner of the storage.
|
|
205
|
+
* @param slot - Slot to read in the contract storage.
|
|
206
|
+
* @returns The current value in the storage slot.
|
|
207
|
+
*/ async storageRead(contract, slot) {
|
|
208
|
+
return await readPublicState(this.db, contract, slot);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Records a write to public storage.
|
|
212
|
+
* @param contract - Owner of the storage.
|
|
213
|
+
* @param slot - Slot to read in the contract storage.
|
|
214
|
+
* @param newValue - The new value to store.
|
|
215
|
+
* @returns The slot of the written leaf in the public data tree.
|
|
216
|
+
*/ async storageWrite(contract, slot, newValue) {
|
|
217
|
+
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
218
|
+
const publicDataWrite = new PublicDataWrite(leafSlot, newValue);
|
|
219
|
+
await this.db.sequentialInsert(MerkleTreeId.PUBLIC_DATA_TREE, [
|
|
220
|
+
publicDataWrite.toBuffer()
|
|
221
|
+
]);
|
|
222
|
+
}
|
|
223
|
+
async getL1ToL2LeafValue(leafIndex) {
|
|
224
|
+
const timer = new Timer();
|
|
225
|
+
const leafValue = await this.db.getLeafValue(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, leafIndex);
|
|
226
|
+
this.logger.debug(`[DB] Fetched L1 to L2 message leaf value`, {
|
|
227
|
+
eventName: 'public-db-access',
|
|
228
|
+
duration: timer.ms(),
|
|
229
|
+
operation: 'get-l1-to-l2-message-leaf-value'
|
|
230
|
+
});
|
|
231
|
+
return leafValue;
|
|
232
|
+
}
|
|
233
|
+
async getCommitmentValue(leafIndex) {
|
|
234
|
+
const timer = new Timer();
|
|
235
|
+
const leafValue = await this.db.getLeafValue(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
236
|
+
this.logger.debug(`[DB] Fetched commitment leaf value`, {
|
|
237
|
+
eventName: 'public-db-access',
|
|
238
|
+
duration: timer.ms(),
|
|
239
|
+
operation: 'get-commitment-leaf-value'
|
|
240
|
+
});
|
|
241
|
+
return leafValue;
|
|
242
|
+
}
|
|
243
|
+
async getNullifierIndex(nullifier) {
|
|
244
|
+
const timer = new Timer();
|
|
245
|
+
const index = (await this.db.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, [
|
|
246
|
+
nullifier.toBuffer()
|
|
247
|
+
]))[0];
|
|
248
|
+
this.logger.debug(`[DB] Fetched nullifier index`, {
|
|
249
|
+
eventName: 'public-db-access',
|
|
250
|
+
duration: timer.ms(),
|
|
251
|
+
operation: 'get-nullifier-index'
|
|
252
|
+
});
|
|
253
|
+
return index;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
export async function readPublicState(db, contract, slot) {
|
|
257
|
+
const leafSlot = (await computePublicDataTreeLeafSlot(contract, slot)).toBigInt();
|
|
258
|
+
const lowLeafResult = await db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
|
|
259
|
+
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
260
|
+
return Fr.ZERO;
|
|
261
|
+
}
|
|
262
|
+
const preimage = await db.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
263
|
+
return preimage.value;
|
|
264
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import { type DateProvider } from '@aztec/foundation/timer';
|
|
4
|
+
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
5
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
6
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
7
|
+
import { type FailedTx, GlobalVariables, NestedProcessReturnValues, type ProcessedTx, Tx, type TxValidator } from '@aztec/stdlib/tx';
|
|
8
|
+
import { type TelemetryClient, type Traceable, type Tracer } from '@aztec/telemetry-client';
|
|
9
|
+
import { WorldStateDB } from '../public_db_sources.js';
|
|
10
|
+
import { PublicTxSimulator } from '../public_tx_simulator/public_tx_simulator.js';
|
|
11
|
+
/**
|
|
12
|
+
* Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
|
|
13
|
+
*/
|
|
14
|
+
export declare class PublicProcessorFactory {
|
|
15
|
+
private contractDataSource;
|
|
16
|
+
private dateProvider;
|
|
17
|
+
private telemetryClient;
|
|
18
|
+
constructor(contractDataSource: ContractDataSource, dateProvider: DateProvider, telemetryClient?: TelemetryClient);
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new instance of a PublicProcessor.
|
|
21
|
+
* @param historicalHeader - The header of a block previous to the one in which the tx is included.
|
|
22
|
+
* @param globalVariables - The global variables for the block being processed.
|
|
23
|
+
* @param skipFeeEnforcement - Allows disabling balance checks for fee estimations.
|
|
24
|
+
* @returns A new instance of a PublicProcessor.
|
|
25
|
+
*/
|
|
26
|
+
create(merkleTree: MerkleTreeWriteOperations, globalVariables: GlobalVariables, skipFeeEnforcement: boolean): PublicProcessor;
|
|
27
|
+
protected createPublicTxSimulator(db: MerkleTreeWriteOperations, worldStateDB: WorldStateDB, globalVariables: GlobalVariables, doMerkleOperations: boolean, skipFeeEnforcement: boolean, telemetryClient: TelemetryClient): PublicTxSimulator;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Converts Txs lifted from the P2P module into ProcessedTx objects by executing
|
|
31
|
+
* any public function calls in them. Txs with private calls only are unaffected.
|
|
32
|
+
*/
|
|
33
|
+
export declare class PublicProcessor implements Traceable {
|
|
34
|
+
protected db: MerkleTreeWriteOperations;
|
|
35
|
+
protected globalVariables: GlobalVariables;
|
|
36
|
+
protected worldStateDB: WorldStateDB;
|
|
37
|
+
protected publicTxSimulator: PublicTxSimulator;
|
|
38
|
+
private dateProvider;
|
|
39
|
+
private log;
|
|
40
|
+
private metrics;
|
|
41
|
+
constructor(db: MerkleTreeWriteOperations, globalVariables: GlobalVariables, worldStateDB: WorldStateDB, publicTxSimulator: PublicTxSimulator, dateProvider: DateProvider, telemetryClient?: TelemetryClient, log?: import("@aztec/foundation/log").Logger);
|
|
42
|
+
get tracer(): Tracer;
|
|
43
|
+
/**
|
|
44
|
+
* Run each tx through the public circuit and the public kernel circuit if needed.
|
|
45
|
+
* @param txs - Txs to process.
|
|
46
|
+
* @param processedTxHandler - Handler for processed txs in the context of block building or proving.
|
|
47
|
+
* @returns The list of processed txs with their circuit simulation outputs.
|
|
48
|
+
*/
|
|
49
|
+
process(txs: Iterable<Tx> | AsyncIterable<Tx>, limits?: {
|
|
50
|
+
maxTransactions?: number;
|
|
51
|
+
maxBlockSize?: number;
|
|
52
|
+
maxBlockGas?: Gas;
|
|
53
|
+
deadline?: Date;
|
|
54
|
+
}, validators?: {
|
|
55
|
+
preprocessValidator?: TxValidator<Tx>;
|
|
56
|
+
postprocessValidator?: TxValidator<ProcessedTx>;
|
|
57
|
+
nullifierCache?: {
|
|
58
|
+
addNullifiers: (nullifiers: Buffer[]) => void;
|
|
59
|
+
};
|
|
60
|
+
}): Promise<[ProcessedTx[], FailedTx[], NestedProcessReturnValues[]]>;
|
|
61
|
+
private processTx;
|
|
62
|
+
private doTreeInsertionsForPrivateOnlyTx;
|
|
63
|
+
/** Processes the given tx within deadline. Returns timeout if deadline is hit. */
|
|
64
|
+
private processTxWithinDeadline;
|
|
65
|
+
/**
|
|
66
|
+
* Creates the public data write for paying the tx fee.
|
|
67
|
+
* This is used in private only txs, since for txs with public calls
|
|
68
|
+
* the avm handles the fee payment itself.
|
|
69
|
+
*/
|
|
70
|
+
private getFeePaymentPublicDataWrite;
|
|
71
|
+
private processPrivateOnlyTx;
|
|
72
|
+
private processTxWithPublicCalls;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=public_processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public_processor.d.ts","sourceRoot":"","sources":["../../../src/public/public_processor/public_processor.ts"],"names":[],"mappings":";;AAIA,OAAO,EAAE,KAAK,YAAY,EAA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