@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,199 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CONTRACT_CLASS_LOG_DATA_SIZE_IN_FIELDS,
|
|
3
|
+
DEFAULT_GAS_LIMIT,
|
|
4
|
+
DEPLOYER_CONTRACT_ADDRESS,
|
|
5
|
+
MAX_L2_GAS_PER_TX_PUBLIC_PORTION,
|
|
6
|
+
PRIVATE_LOG_SIZE_IN_FIELDS,
|
|
7
|
+
REGISTERER_CONTRACT_ADDRESS,
|
|
8
|
+
REGISTERER_CONTRACT_CLASS_REGISTERED_MAGIC_VALUE,
|
|
9
|
+
} from '@aztec/constants';
|
|
10
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
11
|
+
import { assertLength } from '@aztec/foundation/serialize';
|
|
12
|
+
import { DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_TAG } from '@aztec/protocol-contracts';
|
|
13
|
+
import { bufferAsFields } from '@aztec/stdlib/abi';
|
|
14
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
|
+
import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
16
|
+
import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
17
|
+
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
18
|
+
import {
|
|
19
|
+
PartialPrivateTailPublicInputsForPublic,
|
|
20
|
+
PartialPrivateTailPublicInputsForRollup,
|
|
21
|
+
PrivateKernelTailCircuitPublicInputs,
|
|
22
|
+
RollupValidationRequests,
|
|
23
|
+
ScopedLogHash,
|
|
24
|
+
countAccumulatedItems,
|
|
25
|
+
} from '@aztec/stdlib/kernel';
|
|
26
|
+
import { ContractClassLog, PrivateLog } from '@aztec/stdlib/logs';
|
|
27
|
+
import { type PublicExecutionRequest, Tx } from '@aztec/stdlib/tx';
|
|
28
|
+
import { BlockHeader, TxConstantData, TxContext } from '@aztec/stdlib/tx';
|
|
29
|
+
|
|
30
|
+
import { strict as assert } from 'assert';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Craft a carrier transaction for some public calls for simulation by PublicTxSimulator.
|
|
34
|
+
*/
|
|
35
|
+
export async function createTxForPublicCalls(
|
|
36
|
+
firstNullifier: Fr,
|
|
37
|
+
setupExecutionRequests: PublicExecutionRequest[],
|
|
38
|
+
appExecutionRequests: PublicExecutionRequest[],
|
|
39
|
+
teardownExecutionRequest?: PublicExecutionRequest,
|
|
40
|
+
feePayer = AztecAddress.zero(),
|
|
41
|
+
gasUsedByPrivate: Gas = Gas.empty(),
|
|
42
|
+
): Promise<Tx> {
|
|
43
|
+
assert(
|
|
44
|
+
setupExecutionRequests.length > 0 || appExecutionRequests.length > 0 || teardownExecutionRequest !== undefined,
|
|
45
|
+
"Can't create public tx with no enqueued calls",
|
|
46
|
+
);
|
|
47
|
+
const setupCallRequests = await Promise.all(setupExecutionRequests.map(er => er.toCallRequest()));
|
|
48
|
+
const appCallRequests = await Promise.all(appExecutionRequests.map(er => er.toCallRequest()));
|
|
49
|
+
// use max limits
|
|
50
|
+
const gasLimits = new Gas(DEFAULT_GAS_LIMIT, MAX_L2_GAS_PER_TX_PUBLIC_PORTION);
|
|
51
|
+
|
|
52
|
+
const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
|
|
53
|
+
// TODO(#9269): Remove this fake nullifier method as we move away from 1st nullifier as hash.
|
|
54
|
+
forPublic.nonRevertibleAccumulatedData.nullifiers[0] = firstNullifier;
|
|
55
|
+
|
|
56
|
+
// We reverse order because the simulator expects it to be like a "stack" of calls to pop from
|
|
57
|
+
for (let i = setupCallRequests.length - 1; i >= 0; i--) {
|
|
58
|
+
forPublic.nonRevertibleAccumulatedData.publicCallRequests[i] = setupCallRequests[i];
|
|
59
|
+
}
|
|
60
|
+
for (let i = appCallRequests.length - 1; i >= 0; i--) {
|
|
61
|
+
forPublic.revertibleAccumulatedData.publicCallRequests[i] = appCallRequests[i];
|
|
62
|
+
}
|
|
63
|
+
if (teardownExecutionRequest) {
|
|
64
|
+
forPublic.publicTeardownCallRequest = await teardownExecutionRequest.toCallRequest();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const maxFeesPerGas = feePayer.isZero() ? GasFees.empty() : new GasFees(10, 10);
|
|
68
|
+
const teardownGasLimits = teardownExecutionRequest ? gasLimits : Gas.empty();
|
|
69
|
+
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, maxFeesPerGas, GasFees.empty());
|
|
70
|
+
const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
|
|
71
|
+
const constantData = new TxConstantData(BlockHeader.empty(), txContext, Fr.zero(), Fr.zero());
|
|
72
|
+
|
|
73
|
+
const txData = new PrivateKernelTailCircuitPublicInputs(
|
|
74
|
+
constantData,
|
|
75
|
+
RollupValidationRequests.empty(),
|
|
76
|
+
/*gasUsed=*/ gasUsedByPrivate,
|
|
77
|
+
feePayer,
|
|
78
|
+
forPublic,
|
|
79
|
+
);
|
|
80
|
+
const tx = Tx.newWithTxData(txData, teardownExecutionRequest);
|
|
81
|
+
|
|
82
|
+
// Reverse order because the simulator expects it to be like a "stack" of calls to pop from.
|
|
83
|
+
// Also push app calls before setup calls for this reason.
|
|
84
|
+
for (let i = appExecutionRequests.length - 1; i >= 0; i--) {
|
|
85
|
+
tx.enqueuedPublicFunctionCalls.push(appExecutionRequests[i]);
|
|
86
|
+
}
|
|
87
|
+
for (let i = setupExecutionRequests.length - 1; i >= 0; i--) {
|
|
88
|
+
tx.enqueuedPublicFunctionCalls.push(setupExecutionRequests[i]);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return tx;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function createTxForPrivateOnly(feePayer = AztecAddress.zero(), gasUsedByPrivate: Gas = new Gas(10, 10)): Tx {
|
|
95
|
+
// use max limits
|
|
96
|
+
const gasLimits = new Gas(DEFAULT_GAS_LIMIT, MAX_L2_GAS_PER_TX_PUBLIC_PORTION);
|
|
97
|
+
|
|
98
|
+
const forRollup = PartialPrivateTailPublicInputsForRollup.empty();
|
|
99
|
+
|
|
100
|
+
const maxFeesPerGas = feePayer.isZero() ? GasFees.empty() : new GasFees(10, 10);
|
|
101
|
+
const gasSettings = new GasSettings(gasLimits, Gas.empty(), maxFeesPerGas, GasFees.empty());
|
|
102
|
+
const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
|
|
103
|
+
const constantData = new TxConstantData(BlockHeader.empty(), txContext, Fr.zero(), Fr.zero());
|
|
104
|
+
|
|
105
|
+
const txData = new PrivateKernelTailCircuitPublicInputs(
|
|
106
|
+
constantData,
|
|
107
|
+
RollupValidationRequests.empty(),
|
|
108
|
+
/*gasUsed=*/ gasUsedByPrivate,
|
|
109
|
+
feePayer,
|
|
110
|
+
/*forPublic=*/ undefined,
|
|
111
|
+
forRollup,
|
|
112
|
+
);
|
|
113
|
+
return Tx.newWithTxData(txData);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export async function addNewContractClassToTx(
|
|
117
|
+
tx: Tx,
|
|
118
|
+
contractClass: ContractClassPublic,
|
|
119
|
+
skipNullifierInsertion = false,
|
|
120
|
+
) {
|
|
121
|
+
const contractClassLogFields = [
|
|
122
|
+
new Fr(REGISTERER_CONTRACT_CLASS_REGISTERED_MAGIC_VALUE),
|
|
123
|
+
contractClass.id,
|
|
124
|
+
new Fr(contractClass.version),
|
|
125
|
+
new Fr(contractClass.artifactHash),
|
|
126
|
+
new Fr(contractClass.privateFunctionsRoot),
|
|
127
|
+
...bufferAsFields(contractClass.packedBytecode, Math.ceil(contractClass.packedBytecode.length / 31) + 1),
|
|
128
|
+
];
|
|
129
|
+
const contractClassLog = ContractClassLog.fromFields([
|
|
130
|
+
new Fr(REGISTERER_CONTRACT_ADDRESS),
|
|
131
|
+
...contractClassLogFields.concat(
|
|
132
|
+
new Array(CONTRACT_CLASS_LOG_DATA_SIZE_IN_FIELDS - contractClassLogFields.length).fill(Fr.ZERO),
|
|
133
|
+
),
|
|
134
|
+
]);
|
|
135
|
+
const contractClassLogHash = ScopedLogHash.fromFields([
|
|
136
|
+
await contractClassLog.hash(),
|
|
137
|
+
new Fr(7),
|
|
138
|
+
new Fr(contractClassLog.getEmittedLength()),
|
|
139
|
+
new Fr(REGISTERER_CONTRACT_ADDRESS),
|
|
140
|
+
]);
|
|
141
|
+
|
|
142
|
+
const accumulatedData = tx.data.forPublic ? tx.data.forPublic!.revertibleAccumulatedData : tx.data.forRollup!.end;
|
|
143
|
+
if (!skipNullifierInsertion) {
|
|
144
|
+
const nextNullifierIndex = countAccumulatedItems(accumulatedData.nullifiers);
|
|
145
|
+
accumulatedData.nullifiers[nextNullifierIndex] = contractClass.id;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const nextLogIndex = countAccumulatedItems(accumulatedData.contractClassLogsHashes);
|
|
149
|
+
accumulatedData.contractClassLogsHashes[nextLogIndex] = contractClassLogHash;
|
|
150
|
+
|
|
151
|
+
tx.contractClassLogs.push(contractClassLog);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export async function addNewContractInstanceToTx(
|
|
155
|
+
tx: Tx,
|
|
156
|
+
contractInstance: ContractInstanceWithAddress,
|
|
157
|
+
skipNullifierInsertion = false,
|
|
158
|
+
) {
|
|
159
|
+
// can't use publicKeys.toFields() because it includes isInfinite which
|
|
160
|
+
// is not broadcast in such private logs
|
|
161
|
+
const publicKeysAsFields = [
|
|
162
|
+
contractInstance.publicKeys.masterNullifierPublicKey.x,
|
|
163
|
+
contractInstance.publicKeys.masterNullifierPublicKey.y,
|
|
164
|
+
contractInstance.publicKeys.masterIncomingViewingPublicKey.x,
|
|
165
|
+
contractInstance.publicKeys.masterIncomingViewingPublicKey.y,
|
|
166
|
+
contractInstance.publicKeys.masterOutgoingViewingPublicKey.x,
|
|
167
|
+
contractInstance.publicKeys.masterOutgoingViewingPublicKey.y,
|
|
168
|
+
contractInstance.publicKeys.masterTaggingPublicKey.x,
|
|
169
|
+
contractInstance.publicKeys.masterTaggingPublicKey.y,
|
|
170
|
+
];
|
|
171
|
+
const fields = [
|
|
172
|
+
DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_TAG,
|
|
173
|
+
contractInstance.address.toField(),
|
|
174
|
+
new Fr(contractInstance.version),
|
|
175
|
+
new Fr(contractInstance.salt),
|
|
176
|
+
contractInstance.currentContractClassId,
|
|
177
|
+
contractInstance.initializationHash,
|
|
178
|
+
...publicKeysAsFields,
|
|
179
|
+
contractInstance.deployer.toField(),
|
|
180
|
+
new Fr(0),
|
|
181
|
+
new Fr(0),
|
|
182
|
+
new Fr(0),
|
|
183
|
+
];
|
|
184
|
+
const contractInstanceLog = new PrivateLog(assertLength(fields, PRIVATE_LOG_SIZE_IN_FIELDS));
|
|
185
|
+
|
|
186
|
+
const contractAddressNullifier = await siloNullifier(
|
|
187
|
+
AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS),
|
|
188
|
+
contractInstance.address.toField(),
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const accumulatedData = tx.data.forPublic ? tx.data.forPublic!.revertibleAccumulatedData : tx.data.forRollup!.end;
|
|
192
|
+
if (!skipNullifierInsertion) {
|
|
193
|
+
const nextNullifierIndex = countAccumulatedItems(accumulatedData.nullifiers);
|
|
194
|
+
accumulatedData.nullifiers[nextNullifierIndex] = contractAddressNullifier;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const nextLogIndex = countAccumulatedItems(accumulatedData.privateLogs);
|
|
198
|
+
accumulatedData.privateLogs[nextLogIndex] = contractInstanceLog;
|
|
199
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from '../common/db_interfaces.js';
|
|
2
|
+
export * from './public_tx_simulator/public_tx_simulator.js';
|
|
3
|
+
export { type EnqueuedPublicCallExecutionResult, type PublicFunctionCallResult } from './execution.js';
|
|
4
|
+
export * from './public_db_sources.js';
|
|
5
|
+
export { PublicProcessor, PublicProcessorFactory } from './public_processor/public_processor.js';
|
|
6
|
+
export { SideEffectTrace } from './side_effect_trace.js';
|
|
7
|
+
export { getExecutionRequestsByPhase } from './utils.js';
|
|
8
|
+
export { PublicTxSimulationTester } from './fixtures/index.js';
|
|
9
|
+
export * from './avm/index.js';
|
|
@@ -0,0 +1,369 @@
|
|
|
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 type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
7
|
+
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
8
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
9
|
+
import {
|
|
10
|
+
type ContractClassPublic,
|
|
11
|
+
type ContractDataSource,
|
|
12
|
+
type ContractInstanceWithAddress,
|
|
13
|
+
computePublicBytecodeCommitment,
|
|
14
|
+
} from '@aztec/stdlib/contract';
|
|
15
|
+
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
16
|
+
import type {
|
|
17
|
+
MerkleTreeCheckpointOperations,
|
|
18
|
+
MerkleTreeReadOperations,
|
|
19
|
+
MerkleTreeWriteOperations,
|
|
20
|
+
} from '@aztec/stdlib/interfaces/server';
|
|
21
|
+
import { ContractClassLog, PrivateLog } from '@aztec/stdlib/logs';
|
|
22
|
+
import type { PublicDBAccessStats } from '@aztec/stdlib/stats';
|
|
23
|
+
import { MerkleTreeId, type PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
|
|
24
|
+
import type { Tx } from '@aztec/stdlib/tx';
|
|
25
|
+
|
|
26
|
+
import type { PublicContractsDB, PublicStateDB } from '../common/db_interfaces.js';
|
|
27
|
+
import { TxContractCache } from './tx_contract_cache.js';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Implements the PublicContractsDB using a ContractDataSource.
|
|
31
|
+
* Progressively records contracts in transaction as they are processed in a block.
|
|
32
|
+
* Separates block-level contract information (from processed/included txs) from the
|
|
33
|
+
* current tx's contract information (which may be cleared on tx revert/death).
|
|
34
|
+
*/
|
|
35
|
+
export class ContractsDataSourcePublicDB implements PublicContractsDB {
|
|
36
|
+
// Two caching layers for contract classes and instances.
|
|
37
|
+
// Tx-level cache:
|
|
38
|
+
// - The current tx's new contract information is cached
|
|
39
|
+
// in currentTxNonRevertibleCache and currentTxRevertibleCache.
|
|
40
|
+
// Block-level cache:
|
|
41
|
+
// - Contract information from earlier in the block, usable by later txs.
|
|
42
|
+
// When a tx succeeds, that tx's caches are merged into the block cache and cleared.
|
|
43
|
+
private currentTxNonRevertibleCache = new TxContractCache();
|
|
44
|
+
private currentTxRevertibleCache = new TxContractCache();
|
|
45
|
+
private blockCache = new TxContractCache();
|
|
46
|
+
// Separate flat cache for bytecode commitments.
|
|
47
|
+
private bytecodeCommitmentCache = new Map<string, Fr>();
|
|
48
|
+
|
|
49
|
+
private log = createLogger('simulator:contracts-data-source');
|
|
50
|
+
|
|
51
|
+
constructor(private dataSource: ContractDataSource) {}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Add new contracts from a transaction
|
|
55
|
+
* @param tx - The transaction to add contracts from.
|
|
56
|
+
*/
|
|
57
|
+
public async addNewContracts(tx: Tx): Promise<void> {
|
|
58
|
+
await this.addNonRevertibleContractClasses(tx);
|
|
59
|
+
await this.addRevertibleContractClasses(tx);
|
|
60
|
+
this.addNonRevertibleContractInstances(tx);
|
|
61
|
+
this.addRevertibleContractInstances(tx);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Add non revertible contracts from a transaction
|
|
66
|
+
* @param tx - The transaction to add non revertible contracts from.
|
|
67
|
+
*/
|
|
68
|
+
public async addNewNonRevertibleContracts(tx: Tx) {
|
|
69
|
+
await this.addNonRevertibleContractClasses(tx);
|
|
70
|
+
this.addNonRevertibleContractInstances(tx);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Add revertible contracts from a transaction
|
|
75
|
+
* @param tx - The transaction to add revertible contracts from.
|
|
76
|
+
*/
|
|
77
|
+
public async addNewRevertibleContracts(tx: Tx) {
|
|
78
|
+
await this.addRevertibleContractClasses(tx);
|
|
79
|
+
this.addRevertibleContractInstances(tx);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Add non-revertible contract classes from a transaction
|
|
84
|
+
* For private-only txs, this will be all contract classes (found in tx.data.forPublic)
|
|
85
|
+
* @param tx - The transaction to add non-revertible contract classes from.
|
|
86
|
+
*/
|
|
87
|
+
private async addNonRevertibleContractClasses(tx: Tx) {
|
|
88
|
+
const siloedContractClassLogs = tx.data.forPublic
|
|
89
|
+
? await tx.filterContractClassLogs(
|
|
90
|
+
tx.data.forPublic!.nonRevertibleAccumulatedData.contractClassLogsHashes,
|
|
91
|
+
/*siloed=*/ true,
|
|
92
|
+
)
|
|
93
|
+
: await tx.filterContractClassLogs(tx.data.forRollup!.end.contractClassLogsHashes, /*siloed=*/ true);
|
|
94
|
+
|
|
95
|
+
await this.addContractClassesFromLogs(siloedContractClassLogs, this.currentTxNonRevertibleCache, 'non-revertible');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Add revertible contract classes from a transaction
|
|
100
|
+
* None for private-only txs.
|
|
101
|
+
* @param tx - The transaction to add revertible contract classes from.
|
|
102
|
+
*/
|
|
103
|
+
private async addRevertibleContractClasses(tx: Tx) {
|
|
104
|
+
const siloedContractClassLogs = tx.data.forPublic
|
|
105
|
+
? await tx.filterContractClassLogs(
|
|
106
|
+
tx.data.forPublic!.revertibleAccumulatedData.contractClassLogsHashes,
|
|
107
|
+
/*siloed=*/ true,
|
|
108
|
+
)
|
|
109
|
+
: [];
|
|
110
|
+
|
|
111
|
+
await this.addContractClassesFromLogs(siloedContractClassLogs, this.currentTxRevertibleCache, 'revertible');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Add non-revertible contract instances from a transaction
|
|
116
|
+
* For private-only txs, this will be all contract instances (found in tx.data.forRollup)
|
|
117
|
+
* @param tx - The transaction to add non-revertible contract instances from.
|
|
118
|
+
*/
|
|
119
|
+
private addNonRevertibleContractInstances(tx: Tx) {
|
|
120
|
+
const contractInstanceLogs = tx.data.forPublic
|
|
121
|
+
? tx.data.forPublic!.nonRevertibleAccumulatedData.privateLogs.filter(l => !l.isEmpty())
|
|
122
|
+
: tx.data.forRollup!.end.privateLogs.filter(l => !l.isEmpty());
|
|
123
|
+
|
|
124
|
+
this.addContractInstancesFromLogs(contractInstanceLogs, this.currentTxNonRevertibleCache, 'non-revertible');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Add revertible contract instances from a transaction
|
|
129
|
+
* None for private-only txs.
|
|
130
|
+
* @param tx - The transaction to add revertible contract instances from.
|
|
131
|
+
*/
|
|
132
|
+
private addRevertibleContractInstances(tx: Tx) {
|
|
133
|
+
const contractInstanceLogs = tx.data.forPublic
|
|
134
|
+
? tx.data.forPublic!.revertibleAccumulatedData.privateLogs.filter(l => !l.isEmpty())
|
|
135
|
+
: [];
|
|
136
|
+
|
|
137
|
+
this.addContractInstancesFromLogs(contractInstanceLogs, this.currentTxRevertibleCache, 'revertible');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Given a tx's siloed contract class logs, add the contract classes to the cache
|
|
142
|
+
* @param siloedContractClassLogs - Contract class logs to process
|
|
143
|
+
* @param cache - The cache to store the contract classes in
|
|
144
|
+
* @param cacheType - Type of cache (for logging)
|
|
145
|
+
*/
|
|
146
|
+
private async addContractClassesFromLogs(
|
|
147
|
+
siloedContractClassLogs: ContractClassLog[],
|
|
148
|
+
cache: TxContractCache,
|
|
149
|
+
cacheType: string,
|
|
150
|
+
) {
|
|
151
|
+
const contractClassEvents = siloedContractClassLogs
|
|
152
|
+
.filter((log: ContractClassLog) => ContractClassRegisteredEvent.isContractClassRegisteredEvent(log))
|
|
153
|
+
.map((log: ContractClassLog) => ContractClassRegisteredEvent.fromLog(log));
|
|
154
|
+
|
|
155
|
+
// Cache contract classes
|
|
156
|
+
await Promise.all(
|
|
157
|
+
contractClassEvents.map(async (event: ContractClassRegisteredEvent) => {
|
|
158
|
+
this.log.debug(`Adding class ${event.contractClassId.toString()} to contract's ${cacheType} tx cache`);
|
|
159
|
+
const contractClass = await event.toContractClassPublic();
|
|
160
|
+
|
|
161
|
+
cache.addClass(event.contractClassId, contractClass);
|
|
162
|
+
}),
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Given a tx's contract instance logs, add the contract instances to the cache
|
|
168
|
+
* @param contractInstanceLogs - Contract instance logs to process
|
|
169
|
+
* @param cache - The cache to store the contract instances in
|
|
170
|
+
* @param cacheType - Type of cache (for logging)
|
|
171
|
+
*/
|
|
172
|
+
private addContractInstancesFromLogs(contractInstanceLogs: PrivateLog[], cache: TxContractCache, cacheType: string) {
|
|
173
|
+
const contractInstanceEvents = contractInstanceLogs
|
|
174
|
+
.filter(log => ContractInstanceDeployedEvent.isContractInstanceDeployedEvent(log))
|
|
175
|
+
.map(log => ContractInstanceDeployedEvent.fromLog(log));
|
|
176
|
+
|
|
177
|
+
// Cache contract instances
|
|
178
|
+
contractInstanceEvents.forEach(e => {
|
|
179
|
+
this.log.debug(
|
|
180
|
+
`Adding instance ${e.address.toString()} with class ${e.contractClassId.toString()} to ${cacheType} tx contract cache`,
|
|
181
|
+
);
|
|
182
|
+
cache.addInstance(e.address, e.toContractInstance());
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Clear new contracts from the current tx's cache
|
|
188
|
+
*/
|
|
189
|
+
public clearContractsForTx() {
|
|
190
|
+
this.currentTxRevertibleCache.clear();
|
|
191
|
+
this.currentTxRevertibleCache.clear();
|
|
192
|
+
this.currentTxNonRevertibleCache.clear();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Commits the current transaction's cached contracts to the block-level cache.
|
|
197
|
+
* Then, clears the tx cache.
|
|
198
|
+
*/
|
|
199
|
+
public commitContractsForTx(onlyNonRevertibles: boolean = false) {
|
|
200
|
+
// Merge non-revertible tx cache into block cache
|
|
201
|
+
this.blockCache.mergeFrom(this.currentTxNonRevertibleCache);
|
|
202
|
+
|
|
203
|
+
if (!onlyNonRevertibles) {
|
|
204
|
+
// Merge revertible tx cache into block cache
|
|
205
|
+
this.blockCache.mergeFrom(this.currentTxRevertibleCache);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Clear the tx's caches
|
|
209
|
+
this.currentTxNonRevertibleCache.clear();
|
|
210
|
+
this.currentTxRevertibleCache.clear();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
public async getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
214
|
+
// Check caches in order: tx revertible -> tx non-revertible -> block -> data source
|
|
215
|
+
return (
|
|
216
|
+
this.currentTxRevertibleCache.getInstance(address) ??
|
|
217
|
+
this.currentTxNonRevertibleCache.getInstance(address) ??
|
|
218
|
+
this.blockCache.getInstance(address) ??
|
|
219
|
+
(await this.dataSource.getContract(address))
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
public async getContractClass(contractClassId: Fr): Promise<ContractClassPublic | undefined> {
|
|
224
|
+
// Check caches in order: tx revertible -> tx non-revertible -> block -> data source
|
|
225
|
+
return (
|
|
226
|
+
this.currentTxRevertibleCache.getClass(contractClassId) ??
|
|
227
|
+
this.currentTxNonRevertibleCache.getClass(contractClassId) ??
|
|
228
|
+
this.blockCache.getClass(contractClassId) ??
|
|
229
|
+
(await this.dataSource.getContractClass(contractClassId))
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
public async getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined> {
|
|
234
|
+
// Try and retrieve from cache
|
|
235
|
+
const key = contractClassId.toString();
|
|
236
|
+
const result = this.bytecodeCommitmentCache.get(key);
|
|
237
|
+
if (result !== undefined) {
|
|
238
|
+
return result;
|
|
239
|
+
}
|
|
240
|
+
// Now try from the store
|
|
241
|
+
const fromStore = await this.dataSource.getBytecodeCommitment(contractClassId);
|
|
242
|
+
if (fromStore !== undefined) {
|
|
243
|
+
this.bytecodeCommitmentCache.set(key, fromStore);
|
|
244
|
+
return fromStore;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Not in either the store or the cache, build it here and cache
|
|
248
|
+
const contractClass = await this.getContractClass(contractClassId);
|
|
249
|
+
if (contractClass === undefined) {
|
|
250
|
+
return undefined;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const value = await computePublicBytecodeCommitment(contractClass.packedBytecode);
|
|
254
|
+
this.bytecodeCommitmentCache.set(key, value);
|
|
255
|
+
return value;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
public async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
|
|
259
|
+
return await this.dataSource.getContractFunctionName(address, selector);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* A public state DB that reads and writes to the world state.
|
|
265
|
+
*/
|
|
266
|
+
export class WorldStateDB extends ContractsDataSourcePublicDB implements PublicStateDB, MerkleTreeCheckpointOperations {
|
|
267
|
+
private logger = createLogger('simulator:world-state-db');
|
|
268
|
+
|
|
269
|
+
constructor(public db: MerkleTreeWriteOperations, dataSource: ContractDataSource) {
|
|
270
|
+
super(dataSource);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Checkpoints the current fork state
|
|
275
|
+
*/
|
|
276
|
+
public async createCheckpoint() {
|
|
277
|
+
await this.db.createCheckpoint();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Commits the current checkpoint
|
|
282
|
+
*/
|
|
283
|
+
public async commitCheckpoint() {
|
|
284
|
+
await this.db.commitCheckpoint();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Reverts the current checkpoint
|
|
289
|
+
*/
|
|
290
|
+
public async revertCheckpoint() {
|
|
291
|
+
await this.db.revertCheckpoint();
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
public getMerkleInterface(): MerkleTreeWriteOperations {
|
|
295
|
+
return this.db;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Reads a value from public storage, returning zero if none.
|
|
300
|
+
* @param contract - Owner of the storage.
|
|
301
|
+
* @param slot - Slot to read in the contract storage.
|
|
302
|
+
* @returns The current value in the storage slot.
|
|
303
|
+
*/
|
|
304
|
+
public async storageRead(contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
305
|
+
return await readPublicState(this.db, contract, slot);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Records a write to public storage.
|
|
310
|
+
* @param contract - Owner of the storage.
|
|
311
|
+
* @param slot - Slot to read in the contract storage.
|
|
312
|
+
* @param newValue - The new value to store.
|
|
313
|
+
* @returns The slot of the written leaf in the public data tree.
|
|
314
|
+
*/
|
|
315
|
+
public async storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise<void> {
|
|
316
|
+
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
317
|
+
const publicDataWrite = new PublicDataWrite(leafSlot, newValue);
|
|
318
|
+
await this.db.sequentialInsert(MerkleTreeId.PUBLIC_DATA_TREE, [publicDataWrite.toBuffer()]);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
public async getL1ToL2LeafValue(leafIndex: bigint): Promise<Fr | undefined> {
|
|
322
|
+
const timer = new Timer();
|
|
323
|
+
const leafValue = await this.db.getLeafValue(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, leafIndex);
|
|
324
|
+
this.logger.debug(`[DB] Fetched L1 to L2 message leaf value`, {
|
|
325
|
+
eventName: 'public-db-access',
|
|
326
|
+
duration: timer.ms(),
|
|
327
|
+
operation: 'get-l1-to-l2-message-leaf-value',
|
|
328
|
+
} satisfies PublicDBAccessStats);
|
|
329
|
+
return leafValue;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
public async getCommitmentValue(leafIndex: bigint): Promise<Fr | undefined> {
|
|
333
|
+
const timer = new Timer();
|
|
334
|
+
const leafValue = await this.db.getLeafValue(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
335
|
+
this.logger.debug(`[DB] Fetched commitment leaf value`, {
|
|
336
|
+
eventName: 'public-db-access',
|
|
337
|
+
duration: timer.ms(),
|
|
338
|
+
operation: 'get-commitment-leaf-value',
|
|
339
|
+
} satisfies PublicDBAccessStats);
|
|
340
|
+
return leafValue;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
public async getNullifierIndex(nullifier: Fr): Promise<bigint | undefined> {
|
|
344
|
+
const timer = new Timer();
|
|
345
|
+
const index = (await this.db.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]))[0];
|
|
346
|
+
this.logger.debug(`[DB] Fetched nullifier index`, {
|
|
347
|
+
eventName: 'public-db-access',
|
|
348
|
+
duration: timer.ms(),
|
|
349
|
+
operation: 'get-nullifier-index',
|
|
350
|
+
} satisfies PublicDBAccessStats);
|
|
351
|
+
return index;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export async function readPublicState(db: MerkleTreeReadOperations, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
356
|
+
const leafSlot = (await computePublicDataTreeLeafSlot(contract, slot)).toBigInt();
|
|
357
|
+
|
|
358
|
+
const lowLeafResult = await db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
|
|
359
|
+
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
360
|
+
return Fr.ZERO;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const preimage = (await db.getLeafPreimage(
|
|
364
|
+
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
365
|
+
lowLeafResult.index,
|
|
366
|
+
)) as PublicDataTreeLeafPreimage;
|
|
367
|
+
|
|
368
|
+
return preimage.value;
|
|
369
|
+
}
|