@aztec/simulator 3.0.0-devnet.6 → 3.0.0-devnet.6-patch.1
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/dest/client.d.ts +1 -1
- package/dest/common/errors.d.ts +2 -8
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/common/index.d.ts +1 -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 +1 -1
- package/dest/private/acvm/acvm_types.d.ts +1 -1
- package/dest/private/acvm/deserialize.d.ts +2 -2
- package/dest/private/acvm/deserialize.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.js +1 -1
- package/dest/private/acvm/index.d.ts +1 -1
- package/dest/private/acvm/serialize.d.ts +2 -2
- package/dest/private/acvm/serialize.d.ts.map +1 -1
- package/dest/private/acvm/serialize.js +1 -1
- package/dest/private/acvm_native.d.ts +1 -1
- package/dest/private/acvm_native.d.ts.map +1 -1
- package/dest/private/acvm_native.js +15 -13
- package/dest/private/acvm_wasm.d.ts +1 -1
- package/dest/private/acvm_wasm.d.ts.map +1 -1
- package/dest/private/acvm_wasm_with_blobs.d.ts +1 -1
- package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.d.ts +1 -1
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.js +1 -1
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts +1 -1
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +1 -1
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
- package/dest/private/circuit_simulator.d.ts +1 -1
- package/dest/private/factory.d.ts +1 -1
- package/dest/public/avm/avm_context.d.ts +2 -2
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts +2 -2
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.d.ts +5 -5
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.js +5 -8
- package/dest/public/avm/avm_gas.d.ts +2 -2
- package/dest/public/avm/avm_gas.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.d.ts +2 -2
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.d.ts +14 -14
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.js +1 -1
- package/dest/public/avm/avm_simulator.d.ts +4 -3
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +8 -7
- package/dest/public/avm/avm_simulator_interface.d.ts +1 -1
- package/dest/public/avm/errors.d.ts +8 -2
- package/dest/public/avm/errors.d.ts.map +1 -1
- package/dest/public/avm/errors.js +14 -2
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +12 -3
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -2
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +1 -1
- package/dest/public/avm/fixtures/initializers.d.ts +2 -3
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.js +7 -5
- package/dest/public/avm/fixtures/utils.d.ts +4 -3
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
- package/dest/public/avm/fixtures/utils.js +3 -2
- package/dest/public/avm/index.d.ts +1 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts +1 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/addressing_mode.d.ts +1 -1
- package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/public/avm/opcodes/addressing_mode.js +2 -2
- package/dest/public/avm/opcodes/arithmetic.d.ts +10 -8
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.js +11 -1
- package/dest/public/avm/opcodes/bitwise.d.ts +5 -5
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
- 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/contract.d.ts +1 -1
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- 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/conversion.d.ts +1 -1
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
- 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 +3 -4
- package/dest/public/avm/opcodes/environment_getters.d.ts +1 -1
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.d.ts +1 -1
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +0 -1
- 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 +3 -1
- package/dest/public/avm/opcodes/index.d.ts +1 -1
- package/dest/public/avm/opcodes/instruction.d.ts +2 -2
- package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
- 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 +2 -2
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +1 -1
- package/dest/public/avm/opcodes/misc.d.ts +1 -1
- package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/public/avm/opcodes/misc.js +4 -4
- 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/revert_reason.d.ts +2 -2
- package/dest/public/avm/revert_reason.d.ts.map +1 -1
- package/dest/public/avm/revert_reason.js +3 -2
- package/dest/public/avm/serialization/buffer_cursor.d.ts +1 -1
- package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.d.ts +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.js +9 -6
- package/dest/public/avm/serialization/instruction_serialization.d.ts +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +1 -1
- package/dest/public/avm/test_utils.d.ts +2 -2
- package/dest/public/avm/test_utils.d.ts.map +1 -1
- package/dest/public/avm/test_utils.js +1 -1
- 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 +14 -2
- package/dest/public/db_interfaces.d.ts.map +1 -1
- package/dest/public/debug_fn_name.d.ts +15 -2
- package/dest/public/debug_fn_name.d.ts.map +1 -1
- package/dest/public/debug_fn_name.js +19 -0
- package/dest/public/executor_metrics.d.ts +3 -2
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +1 -1
- package/dest/public/executor_metrics_interface.d.ts +3 -2
- package/dest/public/executor_metrics_interface.d.ts.map +1 -1
- package/dest/public/fixtures/amm_test.d.ts +1 -1
- package/dest/public/fixtures/amm_test.js +2 -2
- package/dest/public/fixtures/bulk_test.d.ts +1 -1
- package/dest/public/fixtures/bulk_test.js +1 -1
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +2 -2
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +2 -1
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tests.js +21 -0
- package/dest/public/fixtures/index.d.ts +1 -1
- package/dest/public/fixtures/minimal_public_tx.d.ts +2 -3
- package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
- package/dest/public/fixtures/minimal_public_tx.js +2 -2
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +10 -5
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +28 -14
- package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
- package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
- package/dest/public/fixtures/simple_contract_data_source.js +4 -4
- package/dest/public/fixtures/token_test.d.ts +6 -2
- package/dest/public/fixtures/token_test.d.ts.map +1 -1
- package/dest/public/fixtures/token_test.js +13 -12
- package/dest/public/fixtures/utils.d.ts +2 -2
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +4 -4
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +46 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +136 -0
- package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
- package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_simulator_bin.js +84 -0
- package/dest/public/hinting_db_sources.d.ts +13 -4
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +66 -13
- package/dest/public/index.d.ts +3 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +1 -1
- package/dest/public/public_db_sources.d.ts +22 -63
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +74 -131
- package/dest/public/public_errors.d.ts +1 -1
- package/dest/public/public_errors.d.ts.map +1 -1
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +5 -4
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.d.ts +11 -18
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +37 -36
- package/dest/public/public_processor/public_processor_metrics.d.ts +1 -1
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +18 -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 +94 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +19 -22
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +54 -50
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +42 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +86 -0
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +30 -0
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +170 -0
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +22 -0
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +52 -0
- package/dest/public/public_tx_simulator/factories.d.ts +13 -0
- package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/factories.js +28 -0
- package/dest/public/public_tx_simulator/index.d.ts +5 -1
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/index.js +3 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +14 -7
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +5 -5
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +6 -3
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +13 -5
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +11 -31
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +109 -126
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +2 -2
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +4 -4
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/side_effect_errors.d.ts +1 -1
- package/dest/public/side_effect_errors.d.ts.map +1 -1
- package/dest/public/side_effect_trace.d.ts +2 -3
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +1 -1
- package/dest/public/side_effect_trace_interface.d.ts +3 -4
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/state_manager/index.d.ts +1 -1
- package/dest/public/state_manager/nullifiers.d.ts +2 -2
- package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
- package/dest/public/state_manager/public_storage.d.ts +2 -2
- package/dest/public/state_manager/public_storage.d.ts.map +1 -1
- package/dest/public/state_manager/public_storage.js +1 -1
- package/dest/public/state_manager/state_manager.d.ts +9 -11
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +10 -6
- package/dest/public/test_executor_metrics.d.ts +4 -3
- package/dest/public/test_executor_metrics.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.js +5 -4
- 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 +1 -1
- package/dest/server.d.ts +1 -1
- package/dest/testing.d.ts +1 -1
- package/package.json +21 -20
- package/src/common/errors.ts +1 -1
- package/src/private/acvm/deserialize.ts +1 -1
- package/src/private/acvm/serialize.ts +1 -1
- package/src/private/acvm_native.ts +17 -9
- package/src/private/circuit_recording/circuit_recorder.ts +1 -1
- package/src/public/avm/avm_context.ts +1 -1
- package/src/public/avm/avm_contract_call_result.ts +1 -1
- package/src/public/avm/avm_execution_environment.ts +4 -6
- package/src/public/avm/avm_gas.ts +3 -3
- package/src/public/avm/avm_machine_state.ts +1 -1
- package/src/public/avm/avm_memory_types.ts +1 -1
- package/src/public/avm/avm_simulator.ts +11 -9
- package/src/public/avm/errors.ts +17 -3
- package/src/public/avm/fixtures/avm_simulation_tester.ts +10 -2
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
- package/src/public/avm/fixtures/initializers.ts +8 -10
- package/src/public/avm/fixtures/utils.ts +3 -2
- package/src/public/avm/opcodes/addressing_mode.ts +2 -2
- package/src/public/avm/opcodes/arithmetic.ts +13 -1
- package/src/public/avm/opcodes/ec_add.ts +3 -4
- package/src/public/avm/opcodes/external_calls.ts +0 -1
- package/src/public/avm/opcodes/hashing.ts +3 -1
- package/src/public/avm/opcodes/memory.ts +1 -1
- package/src/public/avm/opcodes/misc.ts +4 -4
- package/src/public/avm/revert_reason.ts +6 -3
- package/src/public/avm/serialization/bytecode_serialization.ts +17 -6
- package/src/public/avm/serialization/instruction_serialization.ts +1 -1
- package/src/public/avm/test_utils.ts +1 -1
- package/src/public/contracts_db_checkpoint.ts +41 -0
- package/src/public/db_interfaces.ts +16 -1
- package/src/public/debug_fn_name.ts +26 -1
- package/src/public/executor_metrics.ts +2 -1
- package/src/public/executor_metrics_interface.ts +2 -1
- package/src/public/fixtures/amm_test.ts +2 -2
- package/src/public/fixtures/bulk_test.ts +1 -1
- package/src/public/fixtures/custom_bytecode_tester.ts +1 -1
- package/src/public/fixtures/custom_bytecode_tests.ts +24 -0
- package/src/public/fixtures/minimal_public_tx.ts +3 -4
- package/src/public/fixtures/public_tx_simulation_tester.ts +47 -16
- package/src/public/fixtures/simple_contract_data_source.ts +8 -9
- package/src/public/fixtures/token_test.ts +18 -10
- package/src/public/fixtures/utils.ts +4 -4
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +233 -0
- package/src/public/fuzzing/avm_simulator_bin.ts +121 -0
- package/src/public/hinting_db_sources.ts +108 -10
- package/src/public/index.ts +6 -4
- package/src/public/public_db_sources.ts +93 -172
- package/src/public/public_processor/guarded_merkle_tree.ts +4 -3
- package/src/public/public_processor/public_processor.ts +63 -48
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +116 -0
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +84 -57
- package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +132 -0
- package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +236 -0
- package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +81 -0
- package/src/public/public_tx_simulator/factories.ts +41 -0
- package/src/public/public_tx_simulator/index.ts +4 -0
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +10 -14
- package/src/public/public_tx_simulator/public_tx_context.ts +9 -3
- package/src/public/public_tx_simulator/public_tx_simulator.ts +161 -193
- package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +1 -2
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +3 -3
- package/src/public/side_effect_trace.ts +1 -1
- package/src/public/side_effect_trace_interface.ts +1 -1
- package/src/public/state_manager/nullifiers.ts +1 -1
- package/src/public/state_manager/public_storage.ts +1 -1
- package/src/public/state_manager/state_manager.ts +14 -14
- package/src/public/test_executor_metrics.ts +7 -5
- 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/src/public/tx_contract_cache.ts +0 -69
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { sha256Trunc } from '@aztec/foundation/crypto/sha256';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
5
|
import type { IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
|
|
5
6
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
@@ -8,8 +9,12 @@ import {
|
|
|
8
9
|
AvmBytecodeCommitmentHint,
|
|
9
10
|
AvmCommitCheckpointHint,
|
|
10
11
|
AvmContractClassHint,
|
|
12
|
+
AvmContractDbCommitCheckpointHint,
|
|
13
|
+
AvmContractDbCreateCheckpointHint,
|
|
14
|
+
AvmContractDbRevertCheckpointHint,
|
|
11
15
|
AvmContractInstanceHint,
|
|
12
16
|
AvmCreateCheckpointHint,
|
|
17
|
+
AvmDebugFunctionNameHint,
|
|
13
18
|
type AvmExecutionHints,
|
|
14
19
|
AvmGetLeafPreimageHintNullifierTree,
|
|
15
20
|
AvmGetLeafPreimageHintPublicDataTree,
|
|
@@ -50,8 +55,11 @@ import type { PublicContractsDBInterface } from './db_interfaces.js';
|
|
|
50
55
|
* A public contracts database that forwards requests and collects AVM hints.
|
|
51
56
|
*/
|
|
52
57
|
export class HintingPublicContractsDB implements PublicContractsDBInterface {
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
private static readonly log: Logger = createLogger('simulator:hinting-public-contracts-db');
|
|
59
|
+
|
|
60
|
+
private checkpointActionCounter: number = 0;
|
|
61
|
+
private nextCheckpointId: number = 1;
|
|
62
|
+
private checkpointStack: number[] = [0];
|
|
55
63
|
|
|
56
64
|
constructor(
|
|
57
65
|
private readonly db: PublicContractsDBInterface,
|
|
@@ -64,9 +72,11 @@ export class HintingPublicContractsDB implements PublicContractsDBInterface {
|
|
|
64
72
|
): Promise<ContractInstanceWithAddress | undefined> {
|
|
65
73
|
const instance = await this.db.getContractInstance(address, timestamp);
|
|
66
74
|
if (instance) {
|
|
67
|
-
|
|
75
|
+
const hintKey = this.getHintKey();
|
|
76
|
+
|
|
68
77
|
this.hints.contractInstances.push(
|
|
69
78
|
new AvmContractInstanceHint(
|
|
79
|
+
hintKey,
|
|
70
80
|
instance.address,
|
|
71
81
|
instance.salt,
|
|
72
82
|
instance.deployer,
|
|
@@ -76,22 +86,31 @@ export class HintingPublicContractsDB implements PublicContractsDBInterface {
|
|
|
76
86
|
instance.publicKeys,
|
|
77
87
|
),
|
|
78
88
|
);
|
|
89
|
+
|
|
90
|
+
HintingPublicContractsDB.log.trace(
|
|
91
|
+
`[getContractInstance:${hintKey}] Added contract instance ${instance.address.toString()} to hints.`,
|
|
92
|
+
);
|
|
79
93
|
}
|
|
80
94
|
return instance;
|
|
81
95
|
}
|
|
82
96
|
|
|
83
97
|
public async getContractClass(contractClassId: Fr): Promise<ContractClassPublic | undefined> {
|
|
84
98
|
const contractClass = await this.db.getContractClass(contractClassId);
|
|
85
|
-
if (contractClass
|
|
86
|
-
this.
|
|
99
|
+
if (contractClass) {
|
|
100
|
+
const hintKey = this.getHintKey();
|
|
87
101
|
this.hints.contractClasses.push(
|
|
88
102
|
new AvmContractClassHint(
|
|
103
|
+
hintKey,
|
|
89
104
|
contractClass.id,
|
|
90
105
|
contractClass.artifactHash,
|
|
91
106
|
contractClass.privateFunctionsRoot,
|
|
92
107
|
contractClass.packedBytecode,
|
|
93
108
|
),
|
|
94
109
|
);
|
|
110
|
+
|
|
111
|
+
HintingPublicContractsDB.log.trace(
|
|
112
|
+
`[getContractClass:${hintKey}] Added contract class ${contractClassId.toString()} to hints.`,
|
|
113
|
+
);
|
|
95
114
|
}
|
|
96
115
|
return contractClass;
|
|
97
116
|
}
|
|
@@ -99,7 +118,12 @@ export class HintingPublicContractsDB implements PublicContractsDBInterface {
|
|
|
99
118
|
public async getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined> {
|
|
100
119
|
const commitment = await this.db.getBytecodeCommitment(contractClassId);
|
|
101
120
|
if (commitment) {
|
|
102
|
-
this.
|
|
121
|
+
const hintKey = this.getHintKey();
|
|
122
|
+
this.hints.bytecodeCommitments.push(new AvmBytecodeCommitmentHint(hintKey, contractClassId, commitment));
|
|
123
|
+
|
|
124
|
+
HintingPublicContractsDB.log.trace(
|
|
125
|
+
`[getBytecodeCommitment:${hintKey}] Added bytecode commitment ${commitment.toString()} to hints for contract class ${contractClassId.toString()}.`,
|
|
126
|
+
);
|
|
103
127
|
}
|
|
104
128
|
return commitment;
|
|
105
129
|
}
|
|
@@ -108,7 +132,81 @@ export class HintingPublicContractsDB implements PublicContractsDBInterface {
|
|
|
108
132
|
contractAddress: AztecAddress,
|
|
109
133
|
selector: FunctionSelector,
|
|
110
134
|
): Promise<string | undefined> {
|
|
111
|
-
|
|
135
|
+
const name = await this.db.getDebugFunctionName(contractAddress, selector);
|
|
136
|
+
if (name) {
|
|
137
|
+
HintingPublicContractsDB.log.debug(
|
|
138
|
+
`[getDebugFunctionName] Adding debug function name ${name} to hints for contract ${contractAddress.toString()} and selector ${selector.toString()}.`,
|
|
139
|
+
);
|
|
140
|
+
// We hint selector as a field to make things way simpler in C++.
|
|
141
|
+
this.hints.debugFunctionNames.push(new AvmDebugFunctionNameHint(contractAddress, selector.toField(), name));
|
|
142
|
+
}
|
|
143
|
+
return name;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
public createCheckpoint(): void {
|
|
147
|
+
const hintKey = this.getHintKey();
|
|
148
|
+
this.checkpointActionCounter++;
|
|
149
|
+
const oldCheckpointId = this.getCurrentCheckpointId();
|
|
150
|
+
|
|
151
|
+
this.db.createCheckpoint();
|
|
152
|
+
|
|
153
|
+
const newCheckpointId = this.nextCheckpointId++;
|
|
154
|
+
this.checkpointStack.push(newCheckpointId);
|
|
155
|
+
|
|
156
|
+
this.hints.contractDbCreateCheckpointHints.push(
|
|
157
|
+
new AvmContractDbCreateCheckpointHint(hintKey, oldCheckpointId, newCheckpointId),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
HintingPublicContractsDB.log.trace(
|
|
161
|
+
`[createCheckpoint:${hintKey}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId}.`,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
public commitCheckpoint(): void {
|
|
166
|
+
const hintKey = this.getHintKey();
|
|
167
|
+
this.checkpointActionCounter++;
|
|
168
|
+
const oldCheckpointId = this.getCurrentCheckpointId();
|
|
169
|
+
|
|
170
|
+
this.db.commitCheckpoint();
|
|
171
|
+
|
|
172
|
+
this.checkpointStack.pop();
|
|
173
|
+
const newCheckpointId = this.getCurrentCheckpointId();
|
|
174
|
+
|
|
175
|
+
this.hints.contractDbCommitCheckpointHints.push(
|
|
176
|
+
new AvmContractDbCommitCheckpointHint(hintKey, oldCheckpointId, newCheckpointId),
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
HintingPublicContractsDB.log.trace(
|
|
180
|
+
`[commitCheckpoint:${hintKey}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId}.`,
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public revertCheckpoint(): void {
|
|
185
|
+
const hintKey = this.getHintKey();
|
|
186
|
+
this.checkpointActionCounter++;
|
|
187
|
+
const oldCheckpointId = this.getCurrentCheckpointId();
|
|
188
|
+
|
|
189
|
+
this.db.revertCheckpoint();
|
|
190
|
+
|
|
191
|
+
this.checkpointStack.pop();
|
|
192
|
+
const newCheckpointId = this.getCurrentCheckpointId();
|
|
193
|
+
|
|
194
|
+
this.hints.contractDbRevertCheckpointHints.push(
|
|
195
|
+
new AvmContractDbRevertCheckpointHint(hintKey, oldCheckpointId, newCheckpointId),
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
HintingPublicContractsDB.log.trace(
|
|
199
|
+
`[revertCheckpoint:${hintKey}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId}.`,
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Private methods.
|
|
204
|
+
private getHintKey(): number {
|
|
205
|
+
return this.checkpointActionCounter;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private getCurrentCheckpointId(): number {
|
|
209
|
+
return this.checkpointStack[this.checkpointStack.length - 1];
|
|
112
210
|
}
|
|
113
211
|
}
|
|
114
212
|
|
|
@@ -499,7 +597,7 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
|
|
|
499
597
|
public async getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
|
|
500
598
|
treeId: ID,
|
|
501
599
|
leafIndices: bigint[],
|
|
502
|
-
): Promise<(
|
|
600
|
+
): Promise<(BlockNumber | undefined)[]> {
|
|
503
601
|
return await this.db.getBlockNumbersForLeafIndices(treeId, leafIndices);
|
|
504
602
|
}
|
|
505
603
|
}
|
package/src/public/index.ts
CHANGED
|
@@ -2,9 +2,11 @@ export { PublicContractsDB } from './public_db_sources.js';
|
|
|
2
2
|
export { GuardedMerkleTreeOperations } from './public_processor/guarded_merkle_tree.js';
|
|
3
3
|
export { PublicProcessor, PublicProcessorFactory } from './public_processor/public_processor.js';
|
|
4
4
|
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type
|
|
5
|
+
CppPublicTxSimulator,
|
|
6
|
+
createPublicTxSimulatorForBlockBuilding,
|
|
7
|
+
DumpingCppPublicTxSimulator,
|
|
8
|
+
type PublicTxSimulatorInterface,
|
|
9
|
+
TelemetryCppPublicTxSimulator,
|
|
9
10
|
} from './public_tx_simulator/index.js';
|
|
11
|
+
export type { PublicTxResult, PublicSimulatorConfig as PublicTxSimulatorConfig } from '@aztec/stdlib/avm';
|
|
10
12
|
export { getCallRequestsWithCalldataByPhase } from './utils.js';
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
NULLIFIER_SUBTREE_HEIGHT,
|
|
5
5
|
PUBLIC_DATA_SUBTREE_HEIGHT,
|
|
6
6
|
} from '@aztec/constants';
|
|
7
|
-
import { Fr } from '@aztec/foundation/
|
|
7
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
8
8
|
import { createLogger } from '@aztec/foundation/log';
|
|
9
9
|
import { Timer } from '@aztec/foundation/timer';
|
|
10
10
|
import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
|
|
@@ -13,14 +13,15 @@ import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
|
13
13
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
14
14
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
15
|
import {
|
|
16
|
+
AllContractDeploymentData,
|
|
16
17
|
type ContractClassPublic,
|
|
17
18
|
type ContractDataSource,
|
|
19
|
+
type ContractDeploymentData,
|
|
18
20
|
type ContractInstanceWithAddress,
|
|
19
21
|
computePublicBytecodeCommitment,
|
|
20
22
|
} from '@aztec/stdlib/contract';
|
|
21
23
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
22
24
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
23
|
-
import { ContractClassLog, PrivateLog } from '@aztec/stdlib/logs';
|
|
24
25
|
import type { PublicDBAccessStats } from '@aztec/stdlib/stats';
|
|
25
26
|
import {
|
|
26
27
|
MerkleTreeId,
|
|
@@ -34,182 +35,89 @@ import type { UInt64 } from '@aztec/stdlib/types';
|
|
|
34
35
|
|
|
35
36
|
import { strict as assert } from 'assert';
|
|
36
37
|
|
|
38
|
+
import { ContractsDbCheckpoint } from './contracts_db_checkpoint.js';
|
|
37
39
|
import type { PublicContractsDBInterface, PublicStateDBInterface } from './db_interfaces.js';
|
|
38
40
|
import { L1ToL2MessageIndexOutOfRangeError, NoteHashIndexOutOfRangeError } from './side_effect_errors.js';
|
|
39
|
-
import { TxContractCache } from './tx_contract_cache.js';
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
43
|
* Implements the PublicContractsDBInterface using a ContractDataSource.
|
|
43
|
-
*
|
|
44
|
-
* Separates block-level contract information (from processed/included txs) from the
|
|
45
|
-
* current tx's contract information (which may be cleared on tx revert/death).
|
|
44
|
+
* Uses a stack-based checkpoint model for managing contract state.
|
|
46
45
|
*/
|
|
47
46
|
export class PublicContractsDB implements PublicContractsDBInterface {
|
|
48
|
-
|
|
49
|
-
// Tx-level cache:
|
|
50
|
-
// - The current tx's new contract information is cached
|
|
51
|
-
// in currentTxNonRevertibleCache and currentTxRevertibleCache.
|
|
52
|
-
// Block-level cache:
|
|
53
|
-
// - Contract information from earlier in the block, usable by later txs.
|
|
54
|
-
// When a tx succeeds, that tx's caches are merged into the block cache and cleared.
|
|
55
|
-
private currentTxNonRevertibleCache = new TxContractCache();
|
|
56
|
-
private currentTxRevertibleCache = new TxContractCache();
|
|
57
|
-
private blockCache = new TxContractCache();
|
|
58
|
-
// Separate flat cache for bytecode commitments.
|
|
59
|
-
private bytecodeCommitmentCache = new Map<string, Fr>();
|
|
47
|
+
private contractStateStack: ContractsDbCheckpoint[] = [new ContractsDbCheckpoint()];
|
|
60
48
|
|
|
61
49
|
private log = createLogger('simulator:contracts-data-source');
|
|
62
50
|
|
|
63
51
|
constructor(private dataSource: ContractDataSource) {}
|
|
64
52
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
* @param tx - The transaction to add contracts from.
|
|
68
|
-
*/
|
|
69
|
-
public async addNewContracts(tx: Tx): Promise<void> {
|
|
70
|
-
await this.addNonRevertibleContractClasses(tx);
|
|
71
|
-
await this.addRevertibleContractClasses(tx);
|
|
72
|
-
this.addNonRevertibleContractInstances(tx);
|
|
73
|
-
this.addRevertibleContractInstances(tx);
|
|
74
|
-
}
|
|
53
|
+
public async addContracts(contractDeploymentData: ContractDeploymentData): Promise<void> {
|
|
54
|
+
const currentState = this.getCurrentState();
|
|
75
55
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
public async addNewNonRevertibleContracts(tx: Tx) {
|
|
81
|
-
await this.addNonRevertibleContractClasses(tx);
|
|
82
|
-
this.addNonRevertibleContractInstances(tx);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Add revertible contracts from a transaction
|
|
87
|
-
* @param tx - The transaction to add revertible contracts from.
|
|
88
|
-
*/
|
|
89
|
-
public async addNewRevertibleContracts(tx: Tx) {
|
|
90
|
-
await this.addRevertibleContractClasses(tx);
|
|
91
|
-
this.addRevertibleContractInstances(tx);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Add non-revertible contract classes from a transaction
|
|
96
|
-
* For private-only txs, this will be all contract classes (found in tx.data.forPublic)
|
|
97
|
-
* @param tx - The transaction to add non-revertible contract classes from.
|
|
98
|
-
*/
|
|
99
|
-
private async addNonRevertibleContractClasses(tx: Tx) {
|
|
100
|
-
const siloedContractClassLogs = tx.data.forPublic
|
|
101
|
-
? tx.getSplitContractClassLogs(false /* revertible */)
|
|
102
|
-
: tx.getContractClassLogs();
|
|
103
|
-
await this.addContractClassesFromLogs(siloedContractClassLogs, this.currentTxNonRevertibleCache, 'non-revertible');
|
|
104
|
-
}
|
|
56
|
+
await this.addContractClassesFromEvents(
|
|
57
|
+
ContractClassPublishedEvent.extractContractClassEvents(contractDeploymentData.getContractClassLogs()),
|
|
58
|
+
currentState,
|
|
59
|
+
);
|
|
105
60
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
*/
|
|
111
|
-
private async addRevertibleContractClasses(tx: Tx) {
|
|
112
|
-
const siloedContractClassLogs = tx.data.forPublic ? tx.getSplitContractClassLogs(true /* revertible */) : [];
|
|
113
|
-
await this.addContractClassesFromLogs(siloedContractClassLogs, this.currentTxRevertibleCache, 'revertible');
|
|
61
|
+
this.addContractInstancesFromEvents(
|
|
62
|
+
ContractInstancePublishedEvent.extractContractInstanceEvents(contractDeploymentData.getPrivateLogs()),
|
|
63
|
+
currentState,
|
|
64
|
+
);
|
|
114
65
|
}
|
|
115
66
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
*/
|
|
121
|
-
private addNonRevertibleContractInstances(tx: Tx) {
|
|
122
|
-
const contractInstanceLogs = tx.data.forPublic
|
|
123
|
-
? tx.data.forPublic!.nonRevertibleAccumulatedData.privateLogs.filter(l => !l.isEmpty())
|
|
124
|
-
: tx.data.forRollup!.end.privateLogs.filter(l => !l.isEmpty());
|
|
125
|
-
|
|
126
|
-
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());
|
|
127
71
|
}
|
|
128
72
|
|
|
129
73
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* @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.
|
|
133
76
|
*/
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
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);
|
|
140
81
|
}
|
|
141
82
|
|
|
142
83
|
/**
|
|
143
|
-
*
|
|
144
|
-
* @param siloedContractClassLogs - Contract class logs to process
|
|
145
|
-
* @param cache - The cache to store the contract classes in
|
|
146
|
-
* @param cacheType - Type of cache (for logging)
|
|
84
|
+
* Commits the current checkpoint, accepting its state latest.
|
|
147
85
|
*/
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
.filter((log: ContractClassLog) => ContractClassPublishedEvent.isContractClassPublishedEvent(log))
|
|
155
|
-
.map((log: ContractClassLog) => ContractClassPublishedEvent.fromLog(log));
|
|
156
|
-
|
|
157
|
-
// Cache contract classes
|
|
158
|
-
await Promise.all(
|
|
159
|
-
contractClassEvents.map(async (event: ContractClassPublishedEvent) => {
|
|
160
|
-
this.log.debug(`Adding class ${event.contractClassId.toString()} to contract's ${cacheType} tx cache`);
|
|
161
|
-
const contractClass = await event.toContractClassPublic();
|
|
162
|
-
|
|
163
|
-
cache.addClass(event.contractClassId, contractClass);
|
|
164
|
-
}),
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Given a tx's contract instance logs, add the contract instances to the cache
|
|
170
|
-
* @param contractInstanceLogs - Contract instance logs to process
|
|
171
|
-
* @param cache - The cache to store the contract instances in
|
|
172
|
-
* @param cacheType - Type of cache (for logging)
|
|
173
|
-
*/
|
|
174
|
-
private addContractInstancesFromLogs(contractInstanceLogs: PrivateLog[], cache: TxContractCache, cacheType: string) {
|
|
175
|
-
const contractInstanceEvents = contractInstanceLogs
|
|
176
|
-
.filter(log => ContractInstancePublishedEvent.isContractInstancePublishedEvent(log))
|
|
177
|
-
.map(log => ContractInstancePublishedEvent.fromLog(log));
|
|
178
|
-
|
|
179
|
-
// Cache contract instances
|
|
180
|
-
contractInstanceEvents.forEach(e => {
|
|
181
|
-
this.log.debug(
|
|
182
|
-
`Adding instance ${e.address.toString()} with class ${e.contractClassId.toString()} to ${cacheType} tx contract cache`,
|
|
183
|
-
);
|
|
184
|
-
cache.addInstance(e.address, e.toContractInstance());
|
|
185
|
-
});
|
|
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;
|
|
186
92
|
}
|
|
187
93
|
|
|
188
94
|
/**
|
|
189
|
-
*
|
|
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.
|
|
190
99
|
*/
|
|
191
|
-
public
|
|
192
|
-
this.
|
|
193
|
-
|
|
194
|
-
|
|
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;
|
|
195
106
|
}
|
|
196
107
|
|
|
197
108
|
/**
|
|
198
|
-
*
|
|
199
|
-
*
|
|
109
|
+
* Reverts the current checkpoint, discarding its state and rolling back
|
|
110
|
+
* to the state as of the latest checkpoint.
|
|
200
111
|
*/
|
|
201
|
-
public
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (!onlyNonRevertibles) {
|
|
206
|
-
// Merge revertible tx cache into block cache
|
|
207
|
-
this.blockCache.mergeFrom(this.currentTxRevertibleCache);
|
|
112
|
+
public revertCheckpoint(): void {
|
|
113
|
+
if (this.contractStateStack.length <= 1) {
|
|
114
|
+
throw new Error('No checkpoint to revert');
|
|
208
115
|
}
|
|
116
|
+
this.contractStateStack.pop();
|
|
117
|
+
}
|
|
209
118
|
|
|
210
|
-
|
|
211
|
-
this.
|
|
212
|
-
this.currentTxRevertibleCache.clear();
|
|
119
|
+
private getCurrentState(): ContractsDbCheckpoint {
|
|
120
|
+
return this.contractStateStack[this.contractStateStack.length - 1];
|
|
213
121
|
}
|
|
214
122
|
|
|
215
123
|
// TODO(fcarreiro/alvaro): This method currently needs a blockNumber. Since this class
|
|
@@ -225,53 +133,66 @@ export class PublicContractsDB implements PublicContractsDBInterface {
|
|
|
225
133
|
address: AztecAddress,
|
|
226
134
|
timestamp: UInt64,
|
|
227
135
|
): Promise<ContractInstanceWithAddress | undefined> {
|
|
228
|
-
|
|
229
|
-
return (
|
|
230
|
-
this.currentTxRevertibleCache.getInstance(address) ??
|
|
231
|
-
this.currentTxNonRevertibleCache.getInstance(address) ??
|
|
232
|
-
this.blockCache.getInstance(address) ??
|
|
233
|
-
(await this.dataSource.getContract(address, timestamp))
|
|
234
|
-
);
|
|
136
|
+
const currentState = this.getCurrentState();
|
|
137
|
+
return currentState.getInstance(address) ?? (await this.dataSource.getContract(address, timestamp));
|
|
235
138
|
}
|
|
236
139
|
|
|
237
140
|
public async getContractClass(contractClassId: Fr): Promise<ContractClassPublic | undefined> {
|
|
238
|
-
|
|
239
|
-
return (
|
|
240
|
-
this.currentTxRevertibleCache.getClass(contractClassId) ??
|
|
241
|
-
this.currentTxNonRevertibleCache.getClass(contractClassId) ??
|
|
242
|
-
this.blockCache.getClass(contractClassId) ??
|
|
243
|
-
(await this.dataSource.getContractClass(contractClassId))
|
|
244
|
-
);
|
|
141
|
+
const currentState = this.getCurrentState();
|
|
142
|
+
return currentState.getClass(contractClassId) ?? (await this.dataSource.getContractClass(contractClassId));
|
|
245
143
|
}
|
|
246
144
|
|
|
247
145
|
public async getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined> {
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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;
|
|
253
152
|
}
|
|
254
|
-
//
|
|
255
|
-
|
|
256
|
-
if (fromStore !== undefined) {
|
|
257
|
-
this.bytecodeCommitmentCache.set(key, fromStore);
|
|
258
|
-
return fromStore;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// 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
|
|
262
155
|
const contractClass = await this.getContractClass(contractClassId);
|
|
156
|
+
|
|
263
157
|
if (contractClass === undefined) {
|
|
158
|
+
// cannot compute bytecode commitment if contract class is not found
|
|
264
159
|
return undefined;
|
|
265
160
|
}
|
|
266
161
|
|
|
267
162
|
const value = await computePublicBytecodeCommitment(contractClass.packedBytecode);
|
|
268
|
-
|
|
163
|
+
// Add to cache (current checkpoint state) so we don't compute again
|
|
164
|
+
currentState.addBytecodeCommitment(contractClassId, value);
|
|
269
165
|
return value;
|
|
270
166
|
}
|
|
271
167
|
|
|
272
168
|
public async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
|
|
273
169
|
return await this.dataSource.getDebugFunctionName(address, selector);
|
|
274
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
|
+
});
|
|
195
|
+
}
|
|
275
196
|
}
|
|
276
197
|
|
|
277
198
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
2
3
|
import type { IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
|
|
3
4
|
import type {
|
|
@@ -11,7 +12,7 @@ import type {
|
|
|
11
12
|
TreeInfo,
|
|
12
13
|
} from '@aztec/stdlib/trees';
|
|
13
14
|
import type { BlockHeader, StateReference } from '@aztec/stdlib/tx';
|
|
14
|
-
import type { WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
15
|
+
import type { WorldStateRevision, WorldStateRevisionWithHandle } from '@aztec/stdlib/world-state';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Wraps an instance of `MerkleTreeWriteOperations` to allow the sequencer to gate access.
|
|
@@ -89,7 +90,7 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
|
|
|
89
90
|
getInitialHeader(): BlockHeader {
|
|
90
91
|
return this.target.getInitialHeader();
|
|
91
92
|
}
|
|
92
|
-
public getRevision(): WorldStateRevision {
|
|
93
|
+
public getRevision(): WorldStateRevision | WorldStateRevisionWithHandle {
|
|
93
94
|
return this.target.getRevision();
|
|
94
95
|
}
|
|
95
96
|
getSiblingPath<ID extends MerkleTreeId>(treeId: ID, index: bigint): Promise<SiblingPath<TreeHeights[ID]>> {
|
|
@@ -126,7 +127,7 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
|
|
|
126
127
|
getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
|
|
127
128
|
treeId: ID,
|
|
128
129
|
leafIndices: bigint[],
|
|
129
|
-
): Promise<(
|
|
130
|
+
): Promise<(BlockNumber | undefined)[]> {
|
|
130
131
|
return this.guardAndPush(() => this.target.getBlockNumbersForLeafIndices(treeId, leafIndices));
|
|
131
132
|
}
|
|
132
133
|
createCheckpoint(): Promise<void> {
|