@aztec/simulator 0.0.0-test.1 → 0.0.1-commit.5daedc8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dest/client.d.ts +6 -4
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +4 -2
- package/dest/common/errors.d.ts +5 -14
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/common/errors.js +51 -32
- package/dest/common/index.d.ts +1 -2
- package/dest/common/index.d.ts.map +1 -1
- package/dest/common/index.js +0 -1
- package/dest/common/stats/index.d.ts +1 -1
- package/dest/common/stats/stats.d.ts +1 -1
- package/dest/private/acvm/acvm.d.ts +12 -6
- package/dest/private/acvm/acvm.d.ts.map +1 -1
- package/dest/private/acvm/acvm.js +10 -16
- package/dest/private/acvm/acvm_types.d.ts +2 -2
- package/dest/private/acvm/acvm_types.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.d.ts +18 -19
- package/dest/private/acvm/deserialize.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.js +31 -23
- package/dest/private/acvm/index.d.ts +1 -2
- package/dest/private/acvm/index.d.ts.map +1 -1
- package/dest/private/acvm/index.js +0 -1
- package/dest/private/acvm/serialize.d.ts +20 -3
- package/dest/private/acvm/serialize.d.ts.map +1 -1
- package/dest/private/acvm/serialize.js +53 -0
- package/dest/private/acvm_native.d.ts +39 -0
- package/dest/private/acvm_native.d.ts.map +1 -0
- package/dest/private/{providers/acvm_native.js → acvm_native.js} +26 -20
- package/dest/private/acvm_wasm.d.ts +15 -0
- package/dest/private/acvm_wasm.d.ts.map +1 -0
- package/dest/private/{providers/acvm_wasm.js → acvm_wasm.js} +22 -19
- package/dest/private/acvm_wasm_with_blobs.d.ts +20 -0
- package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -0
- package/dest/private/acvm_wasm_with_blobs.js +35 -0
- package/dest/private/circuit_recording/circuit_recorder.d.ts +108 -0
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -0
- package/dest/private/circuit_recording/circuit_recorder.js +209 -0
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts +31 -0
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -0
- package/dest/private/circuit_recording/file_circuit_recorder.js +135 -0
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +5 -0
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -0
- package/dest/private/circuit_recording/memory_circuit_recorder.js +9 -0
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +21 -0
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -0
- package/dest/private/circuit_recording/simulator_recorder_wrapper.js +44 -0
- package/dest/private/circuit_simulator.d.ts +35 -0
- package/dest/private/circuit_simulator.d.ts.map +1 -0
- package/dest/private/circuit_simulator.js +43 -0
- package/dest/private/factory.d.ts +12 -0
- package/dest/private/factory.d.ts.map +1 -0
- package/dest/private/{providers/factory.js → factory.js} +2 -2
- package/dest/public/avm/avm_context.d.ts +6 -6
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts +5 -3
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.js +11 -7
- package/dest/public/avm/avm_execution_environment.d.ts +4 -2
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.js +4 -2
- package/dest/public/avm/avm_gas.d.ts +5 -21
- package/dest/public/avm/avm_gas.d.ts.map +1 -1
- package/dest/public/avm/avm_gas.js +27 -35
- package/dest/public/avm/avm_machine_state.d.ts +3 -1
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.js +2 -0
- package/dest/public/avm/avm_memory_types.d.ts +99 -88
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.js +17 -6
- package/dest/public/avm/avm_simulator.d.ts +6 -6
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +23 -35
- package/dest/public/avm/avm_simulator_interface.d.ts +9 -0
- package/dest/public/avm/avm_simulator_interface.d.ts.map +1 -0
- package/dest/public/avm/avm_simulator_interface.js +3 -0
- package/dest/public/avm/errors.d.ts +7 -31
- package/dest/public/avm/errors.d.ts.map +1 -1
- package/dest/public/avm/errors.js +7 -57
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +6 -5
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +22 -15
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +7 -5
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +37 -14
- package/dest/public/avm/fixtures/initializers.d.ts +42 -0
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -0
- package/dest/public/avm/fixtures/initializers.js +44 -0
- package/dest/public/avm/fixtures/utils.d.ts +38 -0
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -0
- package/dest/public/avm/fixtures/utils.js +95 -0
- package/dest/public/avm/index.d.ts +1 -3
- package/dest/public/avm/index.d.ts.map +1 -1
- package/dest/public/avm/index.js +0 -2
- package/dest/public/avm/opcodes/accrued_substate.d.ts +3 -3
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +28 -25
- package/dest/public/avm/opcodes/addressing_mode.d.ts +12 -8
- package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/public/avm/opcodes/addressing_mode.js +46 -26
- package/dest/public/avm/opcodes/arithmetic.d.ts +17 -7
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.js +16 -2
- package/dest/public/avm/opcodes/bitwise.d.ts +10 -18
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/public/avm/opcodes/bitwise.js +19 -26
- package/dest/public/avm/opcodes/comparators.d.ts +4 -4
- package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/public/avm/opcodes/comparators.js +3 -3
- package/dest/public/avm/opcodes/contract.d.ts +2 -3
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/contract.js +9 -10
- package/dest/public/avm/opcodes/control_flow.d.ts +1 -1
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/public/avm/opcodes/control_flow.js +10 -8
- package/dest/public/avm/opcodes/conversion.d.ts +2 -1
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.js +267 -3
- package/dest/public/avm/opcodes/ec_add.d.ts +2 -2
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.js +6 -6
- package/dest/public/avm/opcodes/environment_getters.d.ts +3 -3
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/environment_getters.js +17 -19
- package/dest/public/avm/opcodes/external_calls.d.ts +9 -8
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +39 -34
- package/dest/public/avm/opcodes/hashing.d.ts +2 -2
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/public/avm/opcodes/hashing.js +6 -6
- package/dest/public/avm/opcodes/index.d.ts +1 -1
- package/dest/public/avm/opcodes/instruction.d.ts +15 -11
- package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/public/avm/opcodes/instruction.js +23 -19
- package/dest/public/avm/opcodes/instruction_impl.d.ts +1 -1
- package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.d.ts +6 -6
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +37 -33
- package/dest/public/avm/opcodes/misc.d.ts +3 -2
- package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/public/avm/opcodes/misc.js +41 -16
- package/dest/public/avm/opcodes/storage.d.ts +3 -3
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/public/avm/opcodes/storage.js +7 -5
- package/dest/public/avm/revert_reason.d.ts +18 -0
- package/dest/public/avm/revert_reason.d.ts.map +1 -0
- package/dest/public/avm/revert_reason.js +38 -0
- package/dest/public/avm/serialization/buffer_cursor.d.ts +1 -3
- package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.d.ts +3 -7
- package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.js +70 -69
- package/dest/public/avm/serialization/instruction_serialization.d.ts +14 -5
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +70 -35
- package/dest/public/avm/test_utils.d.ts +11 -14
- package/dest/public/avm/test_utils.d.ts.map +1 -1
- package/dest/public/avm/test_utils.js +16 -24
- package/dest/public/contracts_db_checkpoint.d.ts +16 -0
- package/dest/public/contracts_db_checkpoint.d.ts.map +1 -0
- package/dest/public/contracts_db_checkpoint.js +30 -0
- package/dest/public/db_interfaces.d.ts +68 -0
- package/dest/public/db_interfaces.d.ts.map +1 -0
- package/dest/public/db_interfaces.js +3 -0
- package/dest/public/debug_fn_name.d.ts +5 -0
- package/dest/public/debug_fn_name.d.ts.map +1 -0
- package/dest/public/debug_fn_name.js +9 -0
- package/dest/public/executor_metrics.d.ts +12 -4
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +37 -6
- package/dest/public/executor_metrics_interface.d.ts +10 -0
- package/dest/public/executor_metrics_interface.d.ts.map +1 -0
- package/dest/public/executor_metrics_interface.js +1 -0
- package/dest/public/fixtures/amm_test.d.ts +10 -0
- package/dest/public/fixtures/amm_test.d.ts.map +1 -0
- package/dest/public/fixtures/amm_test.js +213 -0
- package/dest/public/fixtures/bulk_test.d.ts +6 -0
- package/dest/public/fixtures/bulk_test.d.ts.map +1 -0
- package/dest/public/fixtures/bulk_test.js +326 -0
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +12 -0
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -0
- package/dest/public/fixtures/custom_bytecode_tester.js +29 -0
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +9 -0
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -0
- package/dest/public/fixtures/custom_bytecode_tests.js +109 -0
- package/dest/public/fixtures/index.d.ts +8 -1
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +7 -0
- package/dest/public/fixtures/minimal_public_tx.d.ts +9 -0
- package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -0
- package/dest/public/fixtures/minimal_public_tx.js +29 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +35 -14
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +100 -71
- package/dest/public/fixtures/simple_contract_data_source.d.ts +35 -0
- package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -0
- package/dest/public/{avm/fixtures → fixtures}/simple_contract_data_source.js +31 -10
- package/dest/public/fixtures/token_test.d.ts +8 -0
- package/dest/public/fixtures/token_test.d.ts.map +1 -0
- package/dest/public/fixtures/token_test.js +94 -0
- package/dest/public/fixtures/utils.d.ts +17 -4
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +100 -58
- package/dest/public/hinting_db_sources.d.ts +78 -0
- package/dest/public/hinting_db_sources.d.ts.map +1 -0
- package/dest/public/hinting_db_sources.js +350 -0
- package/dest/public/index.d.ts +6 -9
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +4 -7
- package/dest/public/public_db_sources.d.ts +51 -101
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +219 -192
- package/dest/public/public_errors.d.ts +12 -0
- package/dest/public/public_errors.d.ts.map +1 -0
- package/dest/public/public_errors.js +13 -0
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +49 -0
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -0
- package/dest/public/public_processor/guarded_merkle_tree.js +108 -0
- package/dest/public/public_processor/public_processor.d.ts +25 -37
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +154 -111
- package/dest/public/public_processor/public_processor_metrics.d.ts +3 -3
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor_metrics.js +1 -1
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +30 -0
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +133 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +66 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +210 -0
- package/dest/public/public_tx_simulator/index.d.ts +5 -0
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/index.js +2 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +31 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +51 -0
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +23 -30
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +71 -91
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +36 -58
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +208 -206
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +9 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.js +1 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +21 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +39 -0
- package/dest/public/side_effect_errors.d.ts +42 -2
- package/dest/public/side_effect_errors.d.ts.map +1 -1
- package/dest/public/side_effect_errors.js +70 -1
- package/dest/public/side_effect_trace.d.ts +21 -67
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +71 -121
- package/dest/public/side_effect_trace_interface.d.ts +12 -24
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/state_manager/index.d.ts +2 -0
- package/dest/public/state_manager/index.d.ts.map +1 -0
- package/dest/public/state_manager/index.js +1 -0
- package/dest/public/{avm/journal → state_manager}/nullifiers.d.ts +3 -6
- package/dest/public/state_manager/nullifiers.d.ts.map +1 -0
- package/dest/public/{avm/journal → state_manager}/nullifiers.js +3 -8
- package/dest/public/{avm/journal → state_manager}/public_storage.d.ts +3 -3
- package/dest/public/state_manager/public_storage.d.ts.map +1 -0
- package/dest/public/state_manager/state_manager.d.ts +159 -0
- package/dest/public/state_manager/state_manager.d.ts.map +1 -0
- package/dest/public/state_manager/state_manager.js +392 -0
- package/dest/public/test_executor_metrics.d.ts +55 -0
- package/dest/public/test_executor_metrics.d.ts.map +1 -0
- package/dest/public/test_executor_metrics.js +307 -0
- package/dest/public/unique_class_ids.d.ts +1 -1
- package/dest/public/unique_class_ids.d.ts.map +1 -1
- package/dest/public/utils.d.ts +3 -5
- package/dest/public/utils.d.ts.map +1 -1
- package/dest/public/utils.js +4 -21
- package/dest/server.d.ts +7 -4
- package/dest/server.d.ts.map +1 -1
- package/dest/server.js +5 -2
- package/dest/testing.d.ts +2 -0
- package/dest/testing.d.ts.map +1 -0
- package/dest/testing.js +1 -0
- package/package.json +39 -33
- package/src/client.ts +5 -3
- package/src/common/errors.ts +79 -44
- package/src/common/index.ts +0 -1
- package/src/private/acvm/acvm.ts +17 -32
- package/src/private/acvm/acvm_types.ts +1 -1
- package/src/private/acvm/deserialize.ts +35 -29
- package/src/private/acvm/index.ts +0 -1
- package/src/private/acvm/serialize.ts +63 -0
- package/src/private/{providers/acvm_native.ts → acvm_native.ts} +47 -24
- package/src/private/acvm_wasm.ts +72 -0
- package/src/private/acvm_wasm_with_blobs.ts +54 -0
- package/src/private/circuit_recording/circuit_recorder.ts +260 -0
- package/src/private/circuit_recording/file_circuit_recorder.ts +158 -0
- package/src/private/circuit_recording/memory_circuit_recorder.ts +11 -0
- package/src/private/circuit_recording/simulator_recorder_wrapper.ts +91 -0
- package/src/private/circuit_simulator.ts +90 -0
- package/src/private/{providers/factory.ts → factory.ts} +6 -6
- package/src/public/avm/avm_context.ts +4 -4
- package/src/public/avm/avm_contract_call_result.ts +17 -5
- package/src/public/avm/avm_execution_environment.ts +8 -1
- package/src/public/avm/avm_gas.ts +23 -35
- package/src/public/avm/avm_machine_state.ts +5 -0
- package/src/public/avm/avm_memory_types.ts +19 -6
- package/src/public/avm/avm_simulator.ts +43 -54
- package/src/public/avm/avm_simulator_interface.ts +8 -0
- package/src/public/avm/errors.ts +8 -77
- package/src/public/avm/fixtures/avm_simulation_tester.ts +32 -21
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +45 -12
- package/src/public/avm/fixtures/initializers.ts +102 -0
- package/src/public/avm/fixtures/utils.ts +150 -0
- package/src/public/avm/index.ts +0 -2
- package/src/public/avm/opcodes/accrued_substate.ts +64 -29
- package/src/public/avm/opcodes/addressing_mode.ts +56 -32
- package/src/public/avm/opcodes/arithmetic.ts +24 -2
- package/src/public/avm/opcodes/bitwise.ts +33 -29
- package/src/public/avm/opcodes/comparators.ts +6 -3
- package/src/public/avm/opcodes/contract.ts +10 -7
- package/src/public/avm/opcodes/control_flow.ts +19 -10
- package/src/public/avm/opcodes/conversion.ts +27 -3
- package/src/public/avm/opcodes/ec_add.ts +9 -6
- package/src/public/avm/opcodes/environment_getters.ts +27 -22
- package/src/public/avm/opcodes/external_calls.ts +61 -29
- package/src/public/avm/opcodes/hashing.ts +28 -8
- package/src/public/avm/opcodes/instruction.ts +31 -21
- package/src/public/avm/opcodes/memory.ts +71 -32
- package/src/public/avm/opcodes/misc.ts +60 -18
- package/src/public/avm/opcodes/storage.ts +22 -6
- package/src/public/avm/revert_reason.ts +55 -0
- package/src/public/avm/serialization/buffer_cursor.ts +4 -1
- package/src/public/avm/serialization/bytecode_serialization.ts +72 -74
- package/src/public/avm/serialization/instruction_serialization.ts +75 -34
- package/src/public/avm/test_utils.ts +24 -41
- package/src/public/contracts_db_checkpoint.ts +41 -0
- package/src/public/db_interfaces.ts +76 -0
- package/src/{common → public}/debug_fn_name.ts +7 -7
- package/src/public/executor_metrics.ts +56 -6
- package/src/public/executor_metrics_interface.ts +15 -0
- package/src/public/fixtures/amm_test.ts +331 -0
- package/src/public/fixtures/bulk_test.ts +169 -0
- package/src/public/fixtures/custom_bytecode_tester.ts +49 -0
- package/src/public/fixtures/custom_bytecode_tests.ts +135 -0
- package/src/public/fixtures/index.ts +7 -0
- package/src/public/fixtures/minimal_public_tx.ts +35 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +166 -113
- package/src/public/{avm/fixtures → fixtures}/simple_contract_data_source.ts +36 -18
- package/src/public/fixtures/token_test.ts +139 -0
- package/src/public/fixtures/utils.ts +141 -68
- package/src/public/hinting_db_sources.ts +602 -0
- package/src/public/index.ts +5 -8
- package/src/public/public_db_sources.ts +278 -258
- package/src/public/public_errors.ts +14 -0
- package/src/public/public_processor/guarded_merkle_tree.ts +153 -0
- package/src/public/public_processor/public_processor.ts +212 -164
- package/src/public/public_processor/public_processor_metrics.ts +2 -2
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +162 -0
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +306 -0
- package/src/public/public_tx_simulator/index.ts +4 -0
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +105 -0
- package/src/public/public_tx_simulator/public_tx_context.ts +167 -194
- package/src/public/public_tx_simulator/public_tx_simulator.ts +292 -265
- package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +10 -0
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +63 -0
- package/src/public/side_effect_errors.ts +91 -1
- package/src/public/side_effect_trace.ts +94 -320
- package/src/public/side_effect_trace_interface.ts +10 -58
- package/src/public/state_manager/index.ts +1 -0
- package/src/public/{avm/journal → state_manager}/nullifiers.ts +5 -11
- package/src/public/{avm/journal → state_manager}/public_storage.ts +2 -2
- package/src/public/state_manager/state_manager.ts +553 -0
- package/src/public/test_executor_metrics.ts +397 -0
- package/src/public/utils.ts +5 -21
- package/src/server.ts +6 -3
- package/src/testing.ts +1 -0
- package/dest/common/db_interfaces.d.ts +0 -80
- package/dest/common/db_interfaces.d.ts.map +0 -1
- package/dest/common/db_interfaces.js +0 -1
- package/dest/common/debug_fn_name.d.ts +0 -5
- package/dest/common/debug_fn_name.d.ts.map +0 -1
- package/dest/common/debug_fn_name.js +0 -6
- package/dest/common/message_load_oracle_inputs.d.ts +0 -15
- package/dest/common/message_load_oracle_inputs.d.ts.map +0 -1
- package/dest/common/message_load_oracle_inputs.js +0 -15
- package/dest/private/acvm/oracle/index.d.ts +0 -14
- package/dest/private/acvm/oracle/index.d.ts.map +0 -1
- package/dest/private/acvm/oracle/index.js +0 -2
- package/dest/private/acvm/oracle/oracle.d.ts +0 -49
- package/dest/private/acvm/oracle/oracle.d.ts.map +0 -1
- package/dest/private/acvm/oracle/oracle.js +0 -263
- package/dest/private/acvm/oracle/typed_oracle.d.ts +0 -83
- package/dest/private/acvm/oracle/typed_oracle.d.ts.map +0 -1
- package/dest/private/acvm/oracle/typed_oracle.js +0 -132
- package/dest/private/execution_data_provider.d.ts +0 -261
- package/dest/private/execution_data_provider.d.ts.map +0 -1
- package/dest/private/execution_data_provider.js +0 -14
- package/dest/private/execution_note_cache.d.ts +0 -93
- package/dest/private/execution_note_cache.d.ts.map +0 -1
- package/dest/private/execution_note_cache.js +0 -180
- package/dest/private/hashed_values_cache.d.ts +0 -28
- package/dest/private/hashed_values_cache.d.ts.map +0 -1
- package/dest/private/hashed_values_cache.js +0 -46
- package/dest/private/index.d.ts +0 -13
- package/dest/private/index.d.ts.map +0 -1
- package/dest/private/index.js +0 -12
- package/dest/private/pick_notes.d.ts +0 -85
- package/dest/private/pick_notes.d.ts.map +0 -1
- package/dest/private/pick_notes.js +0 -51
- package/dest/private/private_execution.d.ts +0 -25
- package/dest/private/private_execution.d.ts.map +0 -1
- package/dest/private/private_execution.js +0 -92
- package/dest/private/private_execution_oracle.d.ts +0 -215
- package/dest/private/private_execution_oracle.d.ts.map +0 -1
- package/dest/private/private_execution_oracle.js +0 -382
- package/dest/private/providers/acvm_native.d.ts +0 -40
- package/dest/private/providers/acvm_native.d.ts.map +0 -1
- package/dest/private/providers/acvm_wasm.d.ts +0 -15
- package/dest/private/providers/acvm_wasm.d.ts.map +0 -1
- package/dest/private/providers/acvm_wasm_with_blobs.d.ts +0 -19
- package/dest/private/providers/acvm_wasm_with_blobs.d.ts.map +0 -1
- package/dest/private/providers/acvm_wasm_with_blobs.js +0 -32
- package/dest/private/providers/factory.d.ts +0 -12
- package/dest/private/providers/factory.d.ts.map +0 -1
- package/dest/private/providers/simulation_provider.d.ts +0 -19
- package/dest/private/providers/simulation_provider.d.ts.map +0 -1
- package/dest/private/providers/simulation_provider.js +0 -24
- package/dest/private/simulator.d.ts +0 -34
- package/dest/private/simulator.d.ts.map +0 -1
- package/dest/private/simulator.js +0 -76
- package/dest/private/unconstrained_execution.d.ts +0 -10
- package/dest/private/unconstrained_execution.d.ts.map +0 -1
- package/dest/private/unconstrained_execution.js +0 -27
- package/dest/private/unconstrained_execution_oracle.d.ts +0 -161
- package/dest/private/unconstrained_execution_oracle.d.ts.map +0 -1
- package/dest/private/unconstrained_execution_oracle.js +0 -258
- package/dest/public/avm/bytecode_utils.d.ts +0 -5
- package/dest/public/avm/bytecode_utils.d.ts.map +0 -1
- package/dest/public/avm/bytecode_utils.js +0 -17
- package/dest/public/avm/fixtures/index.d.ts +0 -84
- package/dest/public/avm/fixtures/index.d.ts.map +0 -1
- package/dest/public/avm/fixtures/index.js +0 -175
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts +0 -35
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +0 -1
- package/dest/public/avm/journal/index.d.ts +0 -2
- package/dest/public/avm/journal/index.d.ts.map +0 -1
- package/dest/public/avm/journal/index.js +0 -1
- package/dest/public/avm/journal/journal.d.ts +0 -209
- package/dest/public/avm/journal/journal.d.ts.map +0 -1
- package/dest/public/avm/journal/journal.js +0 -486
- package/dest/public/avm/journal/nullifiers.d.ts.map +0 -1
- package/dest/public/avm/journal/public_storage.d.ts.map +0 -1
- package/dest/public/bytecode_errors.d.ts +0 -4
- package/dest/public/bytecode_errors.d.ts.map +0 -1
- package/dest/public/bytecode_errors.js +0 -6
- package/dest/public/execution.d.ts +0 -108
- package/dest/public/execution.d.ts.map +0 -1
- package/dest/public/execution.js +0 -9
- package/dest/public/tx_contract_cache.d.ts +0 -41
- package/dest/public/tx_contract_cache.d.ts.map +0 -1
- package/dest/public/tx_contract_cache.js +0 -49
- package/dest/test/utils.d.ts +0 -13
- package/dest/test/utils.d.ts.map +0 -1
- package/dest/test/utils.js +0 -22
- package/src/common/db_interfaces.ts +0 -94
- package/src/common/message_load_oracle_inputs.ts +0 -15
- package/src/private/acvm/oracle/index.ts +0 -16
- package/src/private/acvm/oracle/oracle.ts +0 -455
- package/src/private/acvm/oracle/typed_oracle.ts +0 -259
- package/src/private/execution_data_provider.ts +0 -323
- package/src/private/execution_note_cache.ts +0 -217
- package/src/private/hashed_values_cache.ts +0 -55
- package/src/private/index.ts +0 -16
- package/src/private/pick_notes.ts +0 -141
- package/src/private/private_execution.ts +0 -151
- package/src/private/private_execution_oracle.ts +0 -614
- package/src/private/providers/acvm_wasm.ts +0 -63
- package/src/private/providers/acvm_wasm_with_blobs.ts +0 -50
- package/src/private/providers/simulation_provider.ts +0 -45
- package/src/private/simulator.ts +0 -147
- package/src/private/unconstrained_execution.ts +0 -50
- package/src/private/unconstrained_execution_oracle.ts +0 -373
- package/src/public/avm/bytecode_utils.ts +0 -17
- package/src/public/avm/fixtures/index.ts +0 -296
- package/src/public/avm/journal/index.ts +0 -1
- package/src/public/avm/journal/journal.ts +0 -742
- package/src/public/avm/opcodes/.eslintrc.cjs +0 -8
- package/src/public/bytecode_errors.ts +0 -6
- package/src/public/execution.ts +0 -140
- package/src/public/tx_contract_cache.ts +0 -69
- package/src/test/utils.ts +0 -36
- /package/dest/public/{avm/journal → state_manager}/public_storage.js +0 -0
|
@@ -1,327 +1,268 @@
|
|
|
1
|
+
import {
|
|
2
|
+
L1_TO_L2_MSG_TREE_LEAF_COUNT,
|
|
3
|
+
NOTE_HASH_TREE_LEAF_COUNT,
|
|
4
|
+
NULLIFIER_SUBTREE_HEIGHT,
|
|
5
|
+
PUBLIC_DATA_SUBTREE_HEIGHT,
|
|
6
|
+
} from '@aztec/constants';
|
|
1
7
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
8
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
9
|
import { Timer } from '@aztec/foundation/timer';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
10
|
+
import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
|
|
11
|
+
import { ContractInstancePublishedEvent } from '@aztec/protocol-contracts/instance-registry';
|
|
6
12
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
7
13
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
8
14
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
9
15
|
import {
|
|
16
|
+
AllContractDeploymentData,
|
|
10
17
|
type ContractClassPublic,
|
|
11
18
|
type ContractDataSource,
|
|
19
|
+
type ContractDeploymentData,
|
|
12
20
|
type ContractInstanceWithAddress,
|
|
13
21
|
computePublicBytecodeCommitment,
|
|
14
22
|
} from '@aztec/stdlib/contract';
|
|
15
23
|
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';
|
|
24
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
22
25
|
import type { PublicDBAccessStats } from '@aztec/stdlib/stats';
|
|
23
|
-
import {
|
|
24
|
-
|
|
26
|
+
import {
|
|
27
|
+
MerkleTreeId,
|
|
28
|
+
NullifierLeaf,
|
|
29
|
+
PublicDataTreeLeaf,
|
|
30
|
+
type PublicDataTreeLeafPreimage,
|
|
31
|
+
getTreeName,
|
|
32
|
+
} from '@aztec/stdlib/trees';
|
|
33
|
+
import { TreeSnapshots, type Tx } from '@aztec/stdlib/tx';
|
|
34
|
+
import type { UInt64 } from '@aztec/stdlib/types';
|
|
35
|
+
|
|
36
|
+
import { strict as assert } from 'assert';
|
|
25
37
|
|
|
26
|
-
import
|
|
27
|
-
import {
|
|
38
|
+
import { ContractsDbCheckpoint } from './contracts_db_checkpoint.js';
|
|
39
|
+
import type { PublicContractsDBInterface, PublicStateDBInterface } from './db_interfaces.js';
|
|
40
|
+
import { L1ToL2MessageIndexOutOfRangeError, NoteHashIndexOutOfRangeError } from './side_effect_errors.js';
|
|
28
41
|
|
|
29
42
|
/**
|
|
30
|
-
* Implements the
|
|
31
|
-
*
|
|
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).
|
|
43
|
+
* Implements the PublicContractsDBInterface using a ContractDataSource.
|
|
44
|
+
* Uses a stack-based checkpoint model for managing contract state.
|
|
34
45
|
*/
|
|
35
|
-
export class
|
|
36
|
-
|
|
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>();
|
|
46
|
+
export class PublicContractsDB implements PublicContractsDBInterface {
|
|
47
|
+
private contractStateStack: ContractsDbCheckpoint[] = [new ContractsDbCheckpoint()];
|
|
48
48
|
|
|
49
49
|
private log = createLogger('simulator:contracts-data-source');
|
|
50
50
|
|
|
51
51
|
constructor(private dataSource: ContractDataSource) {}
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
}
|
|
53
|
+
public async addContracts(contractDeploymentData: ContractDeploymentData): Promise<void> {
|
|
54
|
+
const currentState = this.getCurrentState();
|
|
63
55
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
}
|
|
56
|
+
await this.addContractClassesFromEvents(
|
|
57
|
+
ContractClassPublishedEvent.extractContractClassEvents(contractDeploymentData.getContractClassLogs()),
|
|
58
|
+
currentState,
|
|
59
|
+
);
|
|
97
60
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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');
|
|
61
|
+
this.addContractInstancesFromEvents(
|
|
62
|
+
ContractInstancePublishedEvent.extractContractInstanceEvents(contractDeploymentData.getPrivateLogs()),
|
|
63
|
+
currentState,
|
|
64
|
+
);
|
|
112
65
|
}
|
|
113
66
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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');
|
|
67
|
+
public async addNewContracts(tx: Tx): Promise<void> {
|
|
68
|
+
const contractDeploymentData = AllContractDeploymentData.fromTx(tx);
|
|
69
|
+
await this.addContracts(contractDeploymentData.getNonRevertibleContractDeploymentData());
|
|
70
|
+
await this.addContracts(contractDeploymentData.getRevertibleContractDeploymentData());
|
|
125
71
|
}
|
|
126
72
|
|
|
127
73
|
/**
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* @param tx - The transaction to add revertible contract instances from.
|
|
74
|
+
* Creates a new checkpoint, copying the current state for upcoming modifications,
|
|
75
|
+
* and enabling rollbacks to current state in case of a revert.
|
|
131
76
|
*/
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
this.addContractInstancesFromLogs(contractInstanceLogs, this.currentTxRevertibleCache, 'revertible');
|
|
77
|
+
public createCheckpoint(): void {
|
|
78
|
+
const currentState = this.getCurrentState();
|
|
79
|
+
const newState = currentState.deepCopy();
|
|
80
|
+
this.contractStateStack.push(newState);
|
|
138
81
|
}
|
|
139
82
|
|
|
140
83
|
/**
|
|
141
|
-
*
|
|
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)
|
|
84
|
+
* Commits the current checkpoint, accepting its state latest.
|
|
145
85
|
*/
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
});
|
|
86
|
+
public commitCheckpoint(): void {
|
|
87
|
+
if (this.contractStateStack.length <= 1) {
|
|
88
|
+
throw new Error('No checkpoint to commit');
|
|
89
|
+
}
|
|
90
|
+
const topState = this.contractStateStack.pop()!;
|
|
91
|
+
this.contractStateStack[this.contractStateStack.length - 1] = topState;
|
|
184
92
|
}
|
|
185
93
|
|
|
186
94
|
/**
|
|
187
|
-
*
|
|
95
|
+
* Commits the current checkpoint, not erroring if there is no checkpoint
|
|
96
|
+
* to commit. This is useful to do a sanity commit at the end of tx execution,
|
|
97
|
+
* doing nothing if the checkpoint was already reverted, but truly committing
|
|
98
|
+
* otherwise.
|
|
188
99
|
*/
|
|
189
|
-
public
|
|
190
|
-
this.
|
|
191
|
-
|
|
192
|
-
|
|
100
|
+
public commitCheckpointOkIfNone(): void {
|
|
101
|
+
if (this.contractStateStack.length <= 1) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const topState = this.contractStateStack.pop()!;
|
|
105
|
+
this.contractStateStack[this.contractStateStack.length - 1] = topState;
|
|
193
106
|
}
|
|
194
107
|
|
|
195
108
|
/**
|
|
196
|
-
*
|
|
197
|
-
*
|
|
109
|
+
* Reverts the current checkpoint, discarding its state and rolling back
|
|
110
|
+
* to the state as of the latest checkpoint.
|
|
198
111
|
*/
|
|
199
|
-
public
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (!onlyNonRevertibles) {
|
|
204
|
-
// Merge revertible tx cache into block cache
|
|
205
|
-
this.blockCache.mergeFrom(this.currentTxRevertibleCache);
|
|
112
|
+
public revertCheckpoint(): void {
|
|
113
|
+
if (this.contractStateStack.length <= 1) {
|
|
114
|
+
throw new Error('No checkpoint to revert');
|
|
206
115
|
}
|
|
116
|
+
this.contractStateStack.pop();
|
|
117
|
+
}
|
|
207
118
|
|
|
208
|
-
|
|
209
|
-
this.
|
|
210
|
-
this.currentTxRevertibleCache.clear();
|
|
119
|
+
private getCurrentState(): ContractsDbCheckpoint {
|
|
120
|
+
return this.contractStateStack[this.contractStateStack.length - 1];
|
|
211
121
|
}
|
|
212
122
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
123
|
+
// TODO(fcarreiro/alvaro): This method currently needs a blockNumber. Since this class
|
|
124
|
+
// is only ever used for a given block, it should be possible to construct it with the
|
|
125
|
+
// block number and then forget about it. However, since this class (and interface) is
|
|
126
|
+
// currently more externally exposed than we'd want to, Facundo preferred to not add it
|
|
127
|
+
// to the constructor right now. If we can make this class more private, we should
|
|
128
|
+
// reconsider this. A litmus test is in how many places we need to initialize with a
|
|
129
|
+
// dummy block number (tests or not) and pass block numbers to `super`.
|
|
130
|
+
// Note: Block number got changed to timestamp so this comment ^ is outdated. Keeping
|
|
131
|
+
// the comment as is as I am not part of the AVM cabal.
|
|
132
|
+
public async getContractInstance(
|
|
133
|
+
address: AztecAddress,
|
|
134
|
+
timestamp: UInt64,
|
|
135
|
+
): Promise<ContractInstanceWithAddress | undefined> {
|
|
136
|
+
const currentState = this.getCurrentState();
|
|
137
|
+
return currentState.getInstance(address) ?? (await this.dataSource.getContract(address, timestamp));
|
|
221
138
|
}
|
|
222
139
|
|
|
223
140
|
public async getContractClass(contractClassId: Fr): Promise<ContractClassPublic | undefined> {
|
|
224
|
-
|
|
225
|
-
return (
|
|
226
|
-
this.currentTxRevertibleCache.getClass(contractClassId) ??
|
|
227
|
-
this.currentTxNonRevertibleCache.getClass(contractClassId) ??
|
|
228
|
-
this.blockCache.getClass(contractClassId) ??
|
|
229
|
-
(await this.dataSource.getContractClass(contractClassId))
|
|
230
|
-
);
|
|
141
|
+
const currentState = this.getCurrentState();
|
|
142
|
+
return currentState.getClass(contractClassId) ?? (await this.dataSource.getContractClass(contractClassId));
|
|
231
143
|
}
|
|
232
144
|
|
|
233
145
|
public async getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined> {
|
|
234
|
-
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
146
|
+
const currentState = this.getCurrentState();
|
|
147
|
+
const commitment =
|
|
148
|
+
currentState.getBytecodeCommitment(contractClassId) ??
|
|
149
|
+
(await this.dataSource.getBytecodeCommitment(contractClassId));
|
|
150
|
+
if (commitment !== undefined) {
|
|
151
|
+
return commitment;
|
|
239
152
|
}
|
|
240
|
-
//
|
|
241
|
-
|
|
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
|
|
153
|
+
// Not in the current state or the store, compute it here
|
|
154
|
+
// Get the contract class
|
|
248
155
|
const contractClass = await this.getContractClass(contractClassId);
|
|
156
|
+
|
|
249
157
|
if (contractClass === undefined) {
|
|
158
|
+
// cannot compute bytecode commitment if contract class is not found
|
|
250
159
|
return undefined;
|
|
251
160
|
}
|
|
252
161
|
|
|
253
162
|
const value = await computePublicBytecodeCommitment(contractClass.packedBytecode);
|
|
254
|
-
|
|
163
|
+
// Add to cache (current checkpoint state) so we don't compute again
|
|
164
|
+
currentState.addBytecodeCommitment(contractClassId, value);
|
|
255
165
|
return value;
|
|
256
166
|
}
|
|
257
167
|
|
|
258
168
|
public async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
|
|
259
|
-
return await this.dataSource.
|
|
169
|
+
return await this.dataSource.getDebugFunctionName(address, selector);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private async addContractClassesFromEvents(
|
|
173
|
+
contractClassEvents: ContractClassPublishedEvent[],
|
|
174
|
+
state: ContractsDbCheckpoint,
|
|
175
|
+
) {
|
|
176
|
+
await Promise.all(
|
|
177
|
+
contractClassEvents.map(async (event: ContractClassPublishedEvent) => {
|
|
178
|
+
this.log.debug(`Adding class ${event.contractClassId.toString()} to contract state`);
|
|
179
|
+
const contractClass = await event.toContractClassPublic();
|
|
180
|
+
state.addClass(event.contractClassId, contractClass);
|
|
181
|
+
}),
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private addContractInstancesFromEvents(
|
|
186
|
+
contractInstanceEvents: ContractInstancePublishedEvent[],
|
|
187
|
+
state: ContractsDbCheckpoint,
|
|
188
|
+
) {
|
|
189
|
+
contractInstanceEvents.forEach(e => {
|
|
190
|
+
this.log.debug(
|
|
191
|
+
`Adding instance ${e.address.toString()} with class ${e.contractClassId.toString()} to contract state`,
|
|
192
|
+
);
|
|
193
|
+
state.addInstance(e.address, e.toContractInstance());
|
|
194
|
+
});
|
|
260
195
|
}
|
|
261
196
|
}
|
|
262
197
|
|
|
263
198
|
/**
|
|
264
|
-
* A
|
|
199
|
+
* A high-level class that provides access to the merkle trees.
|
|
200
|
+
*
|
|
201
|
+
* This class is just a helper wrapper around a merkle db. Anything that you can do with it
|
|
202
|
+
* can also be done directly with the merkle db. This class should NOT be exposed or used
|
|
203
|
+
* outside of `simulator/src/public`.
|
|
204
|
+
*
|
|
205
|
+
* NOTE: This class is currently written in such a way that it would generate the
|
|
206
|
+
* necessary hints if used with a hinting merkle db. This is a bit of a leak of concepts.
|
|
207
|
+
* Eventually we can have everything depend on a config/factory at the TxSimulator level
|
|
208
|
+
* to decide whether to use hints or not (same with tracing, etc).
|
|
265
209
|
*/
|
|
266
|
-
export class
|
|
267
|
-
private logger = createLogger('simulator:
|
|
210
|
+
export class PublicTreesDB implements PublicStateDBInterface {
|
|
211
|
+
private logger = createLogger('simulator:public-trees-db');
|
|
268
212
|
|
|
269
|
-
constructor(
|
|
270
|
-
super(dataSource);
|
|
271
|
-
}
|
|
213
|
+
constructor(private readonly db: MerkleTreeWriteOperations) {}
|
|
272
214
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
public async createCheckpoint() {
|
|
277
|
-
await this.db.createCheckpoint();
|
|
278
|
-
}
|
|
215
|
+
public async storageRead(contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
216
|
+
const timer = new Timer();
|
|
217
|
+
const leafSlot = (await computePublicDataTreeLeafSlot(contract, slot)).toBigInt();
|
|
279
218
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
await this.db.commitCheckpoint();
|
|
285
|
-
}
|
|
219
|
+
const lowLeafResult = await this.db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
|
|
220
|
+
if (!lowLeafResult) {
|
|
221
|
+
throw new Error('Low leaf not found');
|
|
222
|
+
}
|
|
286
223
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
224
|
+
// TODO: We need this for the hints. See class comment for more details.
|
|
225
|
+
await this.db.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
226
|
+
// Unconditionally fetching the preimage for the hints. Move it to the hinting layer?
|
|
227
|
+
const preimage = (await this.db.getLeafPreimage(
|
|
228
|
+
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
229
|
+
lowLeafResult.index,
|
|
230
|
+
)) as PublicDataTreeLeafPreimage;
|
|
293
231
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
232
|
+
const result = lowLeafResult.alreadyPresent ? preimage.leaf.value : Fr.ZERO;
|
|
233
|
+
this.logger.debug(`Storage read (contract=${contract}, slot=${slot}, value=${result})`, {
|
|
234
|
+
eventName: 'public-db-access',
|
|
235
|
+
duration: timer.ms(),
|
|
236
|
+
operation: 'storage-read',
|
|
237
|
+
} satisfies PublicDBAccessStats);
|
|
297
238
|
|
|
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);
|
|
239
|
+
return result;
|
|
306
240
|
}
|
|
307
241
|
|
|
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
242
|
public async storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise<void> {
|
|
243
|
+
const timer = new Timer();
|
|
316
244
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
317
245
|
const publicDataWrite = new PublicDataWrite(leafSlot, newValue);
|
|
318
246
|
await this.db.sequentialInsert(MerkleTreeId.PUBLIC_DATA_TREE, [publicDataWrite.toBuffer()]);
|
|
247
|
+
|
|
248
|
+
this.logger.debug(`Storage write (contract=${contract}, slot=${slot}, value=${newValue})`, {
|
|
249
|
+
eventName: 'public-db-access',
|
|
250
|
+
duration: timer.ms(),
|
|
251
|
+
operation: 'storage-write',
|
|
252
|
+
} satisfies PublicDBAccessStats);
|
|
319
253
|
}
|
|
320
254
|
|
|
321
|
-
public async getL1ToL2LeafValue(leafIndex: bigint): Promise<Fr
|
|
255
|
+
public async getL1ToL2LeafValue(leafIndex: bigint): Promise<Fr> {
|
|
322
256
|
const timer = new Timer();
|
|
257
|
+
if (leafIndex > L1_TO_L2_MSG_TREE_LEAF_COUNT) {
|
|
258
|
+
throw new L1ToL2MessageIndexOutOfRangeError(Number(leafIndex));
|
|
259
|
+
}
|
|
323
260
|
const leafValue = await this.db.getLeafValue(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, leafIndex);
|
|
324
|
-
|
|
261
|
+
assert(leafValue !== undefined, 'Unexpected null response from l1 to l2 message tree');
|
|
262
|
+
// TODO: We need this for the hints. See class comment for more details.
|
|
263
|
+
await this.db.getSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, leafIndex);
|
|
264
|
+
|
|
265
|
+
this.logger.debug(`Fetched L1 to L2 message leaf value (leafIndex=${leafIndex}, value=${leafValue})`, {
|
|
325
266
|
eventName: 'public-db-access',
|
|
326
267
|
duration: timer.ms(),
|
|
327
268
|
operation: 'get-l1-to-l2-message-leaf-value',
|
|
@@ -329,41 +270,120 @@ export class WorldStateDB extends ContractsDataSourcePublicDB implements PublicS
|
|
|
329
270
|
return leafValue;
|
|
330
271
|
}
|
|
331
272
|
|
|
332
|
-
public async
|
|
273
|
+
public async getNoteHash(leafIndex: bigint): Promise<Fr> {
|
|
333
274
|
const timer = new Timer();
|
|
275
|
+
if (leafIndex > NOTE_HASH_TREE_LEAF_COUNT) {
|
|
276
|
+
throw new NoteHashIndexOutOfRangeError(Number(leafIndex));
|
|
277
|
+
}
|
|
334
278
|
const leafValue = await this.db.getLeafValue(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
335
|
-
|
|
279
|
+
assert(leafValue !== undefined, 'Unexpected null response from note hash tree');
|
|
280
|
+
// TODO: We need this for the hints. See class comment for more details.
|
|
281
|
+
await this.db.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
282
|
+
|
|
283
|
+
this.logger.debug(`Fetched note hash leaf value (leafIndex=${leafIndex}, value=${leafValue})`, {
|
|
336
284
|
eventName: 'public-db-access',
|
|
337
285
|
duration: timer.ms(),
|
|
338
|
-
operation: 'get-
|
|
286
|
+
operation: 'get-note-hash',
|
|
339
287
|
} satisfies PublicDBAccessStats);
|
|
340
288
|
return leafValue;
|
|
341
289
|
}
|
|
342
290
|
|
|
343
|
-
public async
|
|
291
|
+
public async writeNoteHash(noteHash: Fr): Promise<void> {
|
|
344
292
|
const timer = new Timer();
|
|
345
|
-
|
|
346
|
-
|
|
293
|
+
await this.db.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, [noteHash]);
|
|
294
|
+
|
|
295
|
+
this.logger.debug(`Wrote note hash (noteHash=${noteHash})`, {
|
|
347
296
|
eventName: 'public-db-access',
|
|
348
297
|
duration: timer.ms(),
|
|
349
|
-
operation: '
|
|
298
|
+
operation: 'write-note-hash',
|
|
350
299
|
} satisfies PublicDBAccessStats);
|
|
351
|
-
return index;
|
|
352
300
|
}
|
|
353
|
-
}
|
|
354
301
|
|
|
355
|
-
|
|
356
|
-
|
|
302
|
+
public async checkNullifierExists(nullifier: Fr): Promise<boolean> {
|
|
303
|
+
const timer = new Timer();
|
|
304
|
+
const lowLeafResult = await this.db.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
305
|
+
if (!lowLeafResult) {
|
|
306
|
+
throw new Error('Low leaf not found');
|
|
307
|
+
}
|
|
308
|
+
// TODO: We need this for the hints. See class comment for more details.
|
|
309
|
+
await this.db.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, lowLeafResult.index);
|
|
310
|
+
// TODO: We need this for the hints. See class comment for more details.
|
|
311
|
+
await this.db.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, lowLeafResult.index);
|
|
312
|
+
const exists = lowLeafResult.alreadyPresent;
|
|
357
313
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
314
|
+
this.logger.debug(`Checked nullifier exists (nullifier=${nullifier}, exists=${exists})`, {
|
|
315
|
+
eventName: 'public-db-access',
|
|
316
|
+
duration: timer.ms(),
|
|
317
|
+
operation: 'check-nullifier-exists',
|
|
318
|
+
} satisfies PublicDBAccessStats);
|
|
319
|
+
return exists;
|
|
361
320
|
}
|
|
362
321
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
322
|
+
public async writeNullifier(siloedNullifier: Fr): Promise<void> {
|
|
323
|
+
const timer = new Timer();
|
|
324
|
+
await this.db.sequentialInsert(MerkleTreeId.NULLIFIER_TREE, [siloedNullifier.toBuffer()]);
|
|
325
|
+
|
|
326
|
+
this.logger.debug(`Wrote nullifier (nullifier=${siloedNullifier})`, {
|
|
327
|
+
eventName: 'public-db-access',
|
|
328
|
+
duration: timer.ms(),
|
|
329
|
+
operation: 'write-nullifier',
|
|
330
|
+
} satisfies PublicDBAccessStats);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
public async padTree(treeId: MerkleTreeId, leavesToInsert: number): Promise<void> {
|
|
334
|
+
const timer = new Timer();
|
|
335
|
+
|
|
336
|
+
switch (treeId) {
|
|
337
|
+
// Indexed trees.
|
|
338
|
+
case MerkleTreeId.NULLIFIER_TREE:
|
|
339
|
+
await this.db.batchInsert(
|
|
340
|
+
treeId,
|
|
341
|
+
Array(leavesToInsert).fill(NullifierLeaf.empty().toBuffer()),
|
|
342
|
+
NULLIFIER_SUBTREE_HEIGHT,
|
|
343
|
+
);
|
|
344
|
+
break;
|
|
345
|
+
case MerkleTreeId.PUBLIC_DATA_TREE:
|
|
346
|
+
await this.db.batchInsert(
|
|
347
|
+
treeId,
|
|
348
|
+
Array(leavesToInsert).fill(PublicDataTreeLeaf.empty().toBuffer()),
|
|
349
|
+
PUBLIC_DATA_SUBTREE_HEIGHT,
|
|
350
|
+
);
|
|
351
|
+
break;
|
|
352
|
+
// Append-only trees.
|
|
353
|
+
case MerkleTreeId.L1_TO_L2_MESSAGE_TREE:
|
|
354
|
+
case MerkleTreeId.NOTE_HASH_TREE:
|
|
355
|
+
await this.db.appendLeaves(treeId, Array(leavesToInsert).fill(Fr.ZERO));
|
|
356
|
+
break;
|
|
357
|
+
default:
|
|
358
|
+
throw new Error(`Padding not supported for tree ${treeId}`);
|
|
359
|
+
}
|
|
367
360
|
|
|
368
|
-
|
|
361
|
+
this.logger.debug(`Padded tree (tree=${getTreeName(treeId)}, leavesToInsert=${leavesToInsert})`, {
|
|
362
|
+
eventName: 'public-db-access',
|
|
363
|
+
duration: timer.ms(),
|
|
364
|
+
operation: 'pad-tree',
|
|
365
|
+
} satisfies PublicDBAccessStats);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
public async createCheckpoint(): Promise<void> {
|
|
369
|
+
await this.db.createCheckpoint();
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
public async commitCheckpoint(): Promise<void> {
|
|
373
|
+
await this.db.commitCheckpoint();
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
public async revertCheckpoint(): Promise<void> {
|
|
377
|
+
await this.db.revertCheckpoint();
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
public async getTreeSnapshots(): Promise<TreeSnapshots> {
|
|
381
|
+
const stateReference = await this.db.getStateReference();
|
|
382
|
+
return new TreeSnapshots(
|
|
383
|
+
stateReference.l1ToL2MessageTree,
|
|
384
|
+
stateReference.partial.noteHashTree,
|
|
385
|
+
stateReference.partial.nullifierTree,
|
|
386
|
+
stateReference.partial.publicDataTree,
|
|
387
|
+
);
|
|
388
|
+
}
|
|
369
389
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Any known (and checked) error that can be thrown during public execution.
|
|
3
|
+
* Includes AvmExecutionErrors and SideEffectErrors.
|
|
4
|
+
*
|
|
5
|
+
* AvmSimulator catches any checked errors before returning a boolean "reverted".
|
|
6
|
+
* Unchecked errors are generally the result of a bug. They are propagated and
|
|
7
|
+
* ultimately will be the resonsibility of PublicProcessor to handle.
|
|
8
|
+
*/
|
|
9
|
+
export abstract class CheckedPublicExecutionError extends Error {
|
|
10
|
+
constructor(message: string) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'CheckedPublicExecutionError';
|
|
13
|
+
}
|
|
14
|
+
}
|