@aztec/pxe 5.0.0-rc.1 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/block_synchronizer/block_stream_source.d.ts +5 -5
- package/dest/block_synchronizer/block_stream_source.d.ts.map +1 -1
- package/dest/block_synchronizer/block_stream_source.js +4 -29
- package/dest/block_synchronizer/block_synchronizer.d.ts +16 -12
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +49 -15
- package/dest/config/index.d.ts +2 -1
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +1 -0
- package/dest/contract/contract_class_service.d.ts +31 -0
- package/dest/contract/contract_class_service.d.ts.map +1 -0
- package/dest/contract/contract_class_service.js +68 -0
- package/dest/{contract_sync → contract}/contract_sync_service.d.ts +7 -6
- package/dest/contract/contract_sync_service.d.ts.map +1 -0
- package/dest/{contract_sync → contract}/contract_sync_service.js +10 -30
- package/dest/contract/helpers.d.ts +7 -0
- package/dest/contract/helpers.d.ts.map +1 -0
- package/dest/contract/helpers.js +20 -0
- package/dest/contract_function_simulator/anchored_contract_data.d.ts +36 -0
- package/dest/contract_function_simulator/anchored_contract_data.d.ts.map +1 -0
- package/dest/contract_function_simulator/anchored_contract_data.js +54 -0
- package/dest/contract_function_simulator/aztec_node_read_cache.d.ts +39 -0
- package/dest/contract_function_simulator/aztec_node_read_cache.d.ts.map +1 -0
- package/dest/contract_function_simulator/aztec_node_read_cache.js +60 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +19 -18
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +52 -31
- package/dest/contract_function_simulator/execution_note_cache.d.ts +3 -9
- package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_note_cache.js +8 -28
- package/dest/contract_function_simulator/index.d.ts +17 -9
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +4 -7
- package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts +8 -27
- package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/bounded_vec.js +8 -23
- package/dest/contract_function_simulator/noir-structs/contract_class_log_data.d.ts +9 -0
- package/dest/contract_function_simulator/noir-structs/contract_class_log_data.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/contract_class_log_data.js +1 -0
- package/dest/contract_function_simulator/noir-structs/embedded_curve_point.d.ts +7 -0
- package/dest/contract_function_simulator/noir-structs/embedded_curve_point.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/embedded_curve_point.js +1 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
- package/dest/contract_function_simulator/noir-structs/fact.d.ts +16 -0
- package/dest/contract_function_simulator/noir-structs/fact.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/fact.js +6 -0
- package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts +27 -0
- package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/fact_collection.js +31 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +11 -12
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +6 -49
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +10 -8
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -60
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +2 -2
- package/dest/contract_function_simulator/noir-structs/option.d.ts +9 -11
- package/dest/contract_function_simulator/noir-structs/option.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/option.js +18 -13
- package/dest/contract_function_simulator/noir-structs/origin_block.d.ts +11 -0
- package/dest/contract_function_simulator/noir-structs/origin_block.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/origin_block.js +5 -0
- package/dest/contract_function_simulator/noir-structs/pending_tagged_log.d.ts +11 -0
- package/dest/contract_function_simulator/noir-structs/pending_tagged_log.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/pending_tagged_log.js +4 -0
- package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts +6 -9
- package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/provided_secret.js +1 -14
- package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts +28 -0
- package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.js +50 -0
- package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts +21 -0
- package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/resolved_tx.js +50 -0
- package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts +14 -0
- package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/tx_effect_data.js +5 -0
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +6 -11
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/utility_context.js +1 -20
- package/dest/contract_function_simulator/oracle/acir_callback.d.ts +7 -2
- package/dest/contract_function_simulator/oracle/acir_callback.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/acir_callback.js +55 -11
- package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts +39 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_registry.js +107 -0
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -14
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -24
- package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +86 -8
- package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle_registry.js +168 -18
- package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +123 -40
- package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +947 -264
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +21 -8
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +126 -16
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +63 -33
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +175 -90
- package/dest/debug/pxe_debug_utils.d.ts +2 -2
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +3 -2
- package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +3 -2
- package/dest/entrypoints/pxe_creation_options.d.ts +8 -2
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/server/index.d.ts +5 -3
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +3 -2
- package/dest/entrypoints/server/utils.d.ts +1 -1
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +3 -1
- package/dest/error_enriching.d.ts +5 -3
- package/dest/error_enriching.d.ts.map +1 -1
- package/dest/error_enriching.js +13 -11
- package/dest/hooks/execution_hooks.d.ts +27 -7
- package/dest/hooks/execution_hooks.d.ts.map +1 -1
- package/dest/hooks/execution_hooks.js +3 -3
- package/dest/hooks/index.d.ts +4 -3
- package/dest/hooks/index.d.ts.map +1 -1
- package/dest/hooks/index.js +1 -0
- package/dest/hooks/resolve_custom_request.d.ts +23 -0
- package/dest/hooks/resolve_custom_request.d.ts.map +1 -0
- package/dest/hooks/resolve_custom_request.js +3 -0
- package/dest/hooks/resolve_tagging_secret_strategy.d.ts +50 -0
- package/dest/hooks/resolve_tagging_secret_strategy.d.ts.map +1 -0
- package/dest/hooks/resolve_tagging_secret_strategy.js +3 -0
- package/dest/logs/log_service.d.ts +7 -6
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +79 -28
- package/dest/messages/tx_resolver_service.d.ts +17 -0
- package/dest/messages/tx_resolver_service.d.ts.map +1 -0
- package/dest/messages/{message_context_service.js → tx_resolver_service.js} +8 -8
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.js +3 -3
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +6 -2
- package/dest/private_kernel/hints/test_utils.js +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +17 -36
- package/dest/private_kernel/private_kernel_oracle.d.ts +4 -2
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +17 -5
- package/dest/pxe.d.ts +109 -47
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +222 -139
- package/dest/storage/allowed_scopes.d.ts +6 -0
- package/dest/storage/allowed_scopes.d.ts.map +1 -0
- package/dest/storage/allowed_scopes.js +7 -0
- package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts +1 -1
- package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts.map +1 -1
- package/dest/storage/backwards_compatibility_tests/schema_tests.js +114 -37
- package/dest/storage/capsule_store/capsule_service.d.ts +1 -1
- package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_service.js +6 -9
- package/dest/storage/contract_store/contract_store.d.ts +27 -24
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +64 -75
- package/dest/storage/fact_store/fact_service.d.ts +22 -0
- package/dest/storage/fact_store/fact_service.d.ts.map +1 -0
- package/dest/storage/fact_store/fact_service.js +45 -0
- package/dest/storage/fact_store/fact_store.d.ts +95 -0
- package/dest/storage/fact_store/fact_store.d.ts.map +1 -0
- package/dest/storage/fact_store/fact_store.js +408 -0
- package/dest/storage/fact_store/fact_store_keys.d.ts +34 -0
- package/dest/storage/fact_store/fact_store_keys.d.ts.map +1 -0
- package/dest/storage/fact_store/fact_store_keys.js +50 -0
- package/dest/storage/fact_store/index.d.ts +6 -0
- package/dest/storage/fact_store/index.d.ts.map +1 -0
- package/dest/storage/fact_store/index.js +4 -0
- package/dest/storage/fact_store/origin_state.d.ts +57 -0
- package/dest/storage/fact_store/origin_state.d.ts.map +1 -0
- package/dest/storage/fact_store/origin_state.js +53 -0
- package/dest/storage/fact_store/stored_fact.d.ts +32 -0
- package/dest/storage/fact_store/stored_fact.d.ts.map +1 -0
- package/dest/storage/fact_store/stored_fact.js +64 -0
- package/dest/storage/index.d.ts +2 -1
- package/dest/storage/index.d.ts.map +1 -1
- package/dest/storage/index.js +1 -0
- package/dest/storage/metadata.d.ts +2 -2
- package/dest/storage/metadata.d.ts.map +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/open_pxe_stores.d.ts +5 -3
- package/dest/storage/open_pxe_stores.d.ts.map +1 -1
- package/dest/storage/open_pxe_stores.js +5 -3
- package/dest/storage/tagging_store/index.d.ts +2 -2
- package/dest/storage/tagging_store/index.d.ts.map +1 -1
- package/dest/storage/tagging_store/index.js +1 -1
- package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts +51 -0
- package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts.map +1 -0
- package/dest/storage/tagging_store/tagging_secret_sources_store.js +105 -0
- package/dest/tagging/constants.d.ts +2 -2
- package/dest/tagging/constants.d.ts.map +1 -1
- package/dest/tagging/constants.js +18 -9
- package/package.json +17 -17
- package/src/block_synchronizer/block_stream_source.ts +6 -45
- package/src/block_synchronizer/block_synchronizer.ts +65 -24
- package/src/config/index.ts +1 -0
- package/src/contract/contract_class_service.ts +83 -0
- package/src/{contract_sync → contract}/contract_sync_service.ts +18 -37
- package/src/contract/helpers.ts +35 -0
- package/src/contract_function_simulator/anchored_contract_data.ts +74 -0
- package/src/contract_function_simulator/aztec_node_read_cache.ts +89 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +86 -43
- package/src/contract_function_simulator/execution_note_cache.ts +7 -28
- package/src/contract_function_simulator/index.ts +24 -9
- package/src/contract_function_simulator/noir-structs/bounded_vec.ts +12 -24
- package/src/contract_function_simulator/noir-structs/contract_class_log_data.ts +9 -0
- package/src/contract_function_simulator/noir-structs/embedded_curve_point.ts +4 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/fact.ts +13 -0
- package/src/contract_function_simulator/noir-structs/fact_collection.ts +64 -0
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +20 -46
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +13 -60
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +2 -2
- package/src/contract_function_simulator/noir-structs/option.ts +17 -11
- package/src/contract_function_simulator/noir-structs/origin_block.ts +8 -0
- package/src/contract_function_simulator/noir-structs/pending_tagged_log.ts +12 -0
- package/src/contract_function_simulator/noir-structs/provided_secret.ts +4 -15
- package/src/contract_function_simulator/noir-structs/resolved_tagging_strategy.ts +66 -0
- package/src/contract_function_simulator/noir-structs/resolved_tx.ts +53 -0
- package/src/contract_function_simulator/noir-structs/tx_effect_data.ts +15 -0
- package/src/contract_function_simulator/noir-structs/utility_context.ts +5 -17
- package/src/contract_function_simulator/oracle/acir_callback.ts +58 -12
- package/src/contract_function_simulator/oracle/legacy_oracle_registry.ts +147 -0
- package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +6 -21
- package/src/contract_function_simulator/oracle/oracle_registry.ts +119 -86
- package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +659 -248
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +155 -24
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +300 -115
- package/src/debug/pxe_debug_utils.ts +1 -1
- package/src/entrypoints/client/bundle/utils.ts +3 -2
- package/src/entrypoints/client/lazy/utils.ts +3 -2
- package/src/entrypoints/pxe_creation_options.ts +7 -1
- package/src/entrypoints/server/index.ts +5 -2
- package/src/entrypoints/server/utils.ts +3 -1
- package/src/error_enriching.ts +27 -11
- package/src/hooks/execution_hooks.ts +28 -8
- package/src/hooks/index.ts +8 -2
- package/src/hooks/resolve_custom_request.ts +24 -0
- package/src/hooks/resolve_tagging_secret_strategy.ts +60 -0
- package/src/logs/log_service.ts +91 -37
- package/src/messages/{message_context_service.ts → tx_resolver_service.ts} +16 -9
- package/src/oracle_version.ts +3 -3
- package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +11 -1
- package/src/private_kernel/hints/test_utils.ts +1 -1
- package/src/private_kernel/private_kernel_execution_prover.ts +22 -52
- package/src/private_kernel/private_kernel_oracle.ts +23 -4
- package/src/pxe.ts +320 -158
- package/src/storage/allowed_scopes.ts +14 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/AddressStore.json +6 -6
- package/src/storage/backwards_compatibility_tests/__snapshots__/ContractStore.json +1 -1
- package/src/storage/backwards_compatibility_tests/__snapshots__/FactStore.json +40 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/KeyStore.json +12 -12
- package/src/storage/backwards_compatibility_tests/__snapshots__/L2TipsKVStore.json +1 -1
- package/src/storage/backwards_compatibility_tests/__snapshots__/RecipientTaggingStore.json +11 -3
- package/src/storage/backwards_compatibility_tests/__snapshots__/SenderTaggingStore.json +12 -4
- package/src/storage/backwards_compatibility_tests/__snapshots__/TaggingSecretSourcesStore.json +30 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/opened_stores.json +21 -5
- package/src/storage/backwards_compatibility_tests/schema_tests.ts +125 -36
- package/src/storage/capsule_store/capsule_service.ts +8 -13
- package/src/storage/contract_store/contract_store.ts +86 -93
- package/src/storage/fact_store/fact_service.ts +69 -0
- package/src/storage/fact_store/fact_store.ts +487 -0
- package/src/storage/fact_store/fact_store_keys.ts +75 -0
- package/src/storage/fact_store/index.ts +14 -0
- package/src/storage/fact_store/origin_state.ts +75 -0
- package/src/storage/fact_store/stored_fact.ts +80 -0
- package/src/storage/index.ts +1 -0
- package/src/storage/metadata.ts +1 -1
- package/src/storage/open_pxe_stores.ts +6 -3
- package/src/storage/tagging_store/index.ts +1 -1
- package/src/storage/tagging_store/tagging_secret_sources_store.ts +138 -0
- package/src/tagging/constants.ts +19 -9
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +0 -6
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +0 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.js +0 -51
- package/dest/contract_sync/contract_sync_service.d.ts.map +0 -1
- package/dest/contract_sync/helpers.d.ts +0 -27
- package/dest/contract_sync/helpers.d.ts.map +0 -1
- package/dest/contract_sync/helpers.js +0 -53
- package/dest/messages/message_context_service.d.ts +0 -17
- package/dest/messages/message_context_service.d.ts.map +0 -1
- package/dest/storage/tagging_store/sender_address_book_store.d.ts +0 -14
- package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +0 -1
- package/dest/storage/tagging_store/sender_address_book_store.js +0 -36
- package/src/contract_function_simulator/proxied_contract_data_source.ts +0 -60
- package/src/contract_sync/helpers.ts +0 -86
- package/src/storage/backwards_compatibility_tests/__snapshots__/SenderAddressBookStore.json +0 -16
- package/src/storage/tagging_store/sender_address_book_store.ts +0 -48
|
@@ -8,8 +8,10 @@ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
|
8
8
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
9
9
|
|
|
10
10
|
import type { BlockSynchronizerConfig } from '../config/index.js';
|
|
11
|
-
import type {
|
|
11
|
+
import type { ContractClassService } from '../contract/contract_class_service.js';
|
|
12
|
+
import type { ContractSyncService } from '../contract/contract_sync_service.js';
|
|
12
13
|
import type { AnchorBlockStore } from '../storage/anchor_block_store/index.js';
|
|
14
|
+
import type { FactStore } from '../storage/fact_store/fact_store.js';
|
|
13
15
|
import type { NoteStore } from '../storage/note_store/index.js';
|
|
14
16
|
import type { PrivateEventStore } from '../storage/private_event_store/private_event_store.js';
|
|
15
17
|
import { blockStreamSourceFromAztecNode } from './block_stream_source.js';
|
|
@@ -26,32 +28,33 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
26
28
|
protected readonly blockStream: L2BlockStream;
|
|
27
29
|
|
|
28
30
|
constructor(
|
|
29
|
-
private node: AztecNode,
|
|
30
|
-
private store: AztecAsyncKVStore,
|
|
31
|
-
private anchorBlockStore: AnchorBlockStore,
|
|
32
|
-
private noteStore: NoteStore,
|
|
33
|
-
private privateEventStore: PrivateEventStore,
|
|
34
|
-
private
|
|
35
|
-
private
|
|
36
|
-
private
|
|
31
|
+
private readonly node: AztecNode,
|
|
32
|
+
private readonly store: AztecAsyncKVStore,
|
|
33
|
+
private readonly anchorBlockStore: AnchorBlockStore,
|
|
34
|
+
private readonly noteStore: NoteStore,
|
|
35
|
+
private readonly privateEventStore: PrivateEventStore,
|
|
36
|
+
private readonly factStore: FactStore,
|
|
37
|
+
private readonly l2TipsStore: L2TipsKVStore,
|
|
38
|
+
private readonly contractSyncService: ContractSyncService,
|
|
39
|
+
private readonly contractClassService: ContractClassService,
|
|
40
|
+
private readonly config: Partial<BlockSynchronizerConfig> = {},
|
|
37
41
|
bindings?: LoggerBindings,
|
|
38
42
|
) {
|
|
39
43
|
this.log = createLogger('pxe:block_synchronizer', bindings);
|
|
40
|
-
this.blockStream = this.createBlockStream(
|
|
44
|
+
this.blockStream = this.createBlockStream();
|
|
41
45
|
this.eventQueue.start();
|
|
42
46
|
}
|
|
43
47
|
|
|
44
|
-
protected createBlockStream(
|
|
48
|
+
protected createBlockStream(): L2BlockStream {
|
|
45
49
|
return new L2BlockStream(
|
|
46
50
|
blockStreamSourceFromAztecNode(this.node),
|
|
47
51
|
this.l2TipsStore,
|
|
48
52
|
this,
|
|
49
53
|
createLogger('pxe:block_stream', this.log.getBindings()),
|
|
50
54
|
{
|
|
51
|
-
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
skipFinalized: true,
|
|
55
|
+
// PXE only tracks chain tips (it anchors on tip events and never replays payloads), so the stream runs
|
|
56
|
+
// in tips-only mode: no block downloads, just the tip events that move the anchor and detect reorgs.
|
|
57
|
+
tipsOnly: true,
|
|
55
58
|
},
|
|
56
59
|
);
|
|
57
60
|
}
|
|
@@ -62,21 +65,43 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
private async doHandleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void> {
|
|
65
|
-
await this.l2TipsStore.handleBlockStreamEvent(event);
|
|
66
|
-
|
|
67
68
|
switch (event.type) {
|
|
68
|
-
case '
|
|
69
|
+
case 'chain-proposed': {
|
|
69
70
|
if (this.config.syncChainTip === undefined || this.config.syncChainTip === 'proposed') {
|
|
70
|
-
|
|
71
|
-
await this.
|
|
71
|
+
// Fetch the proposed tip header by hash. By-hash is safer than by-number against a same-height reorg.
|
|
72
|
+
const block = await this.node.getBlockData(BlockHash.fromString(event.block.hash));
|
|
73
|
+
if (!block) {
|
|
74
|
+
// The node served a proposed tip whose block data it cannot return — a node inconsistency, since the
|
|
75
|
+
// stream events and the block data come from the same node (same reasoning as the chain-pruned throw
|
|
76
|
+
// below). Throwing here propagates before the tips-store cursor advances, so the cursor stays put and the
|
|
77
|
+
// next sync re-emits chain-proposed (at-least-once). Were we to warn-and-skip, the cursor would advance and
|
|
78
|
+
// a quiet chain would never re-emit, leaving the anchor stale indefinitely.
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Block header for proposed block ${event.block.number} and hash ${event.block.hash} not found. This ` +
|
|
81
|
+
`likely indicates a bug in the node, as we receive block stream events and fetch block headers from ` +
|
|
82
|
+
`the same node.`,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
await this.updateAnchorBlockHeader(block.header);
|
|
72
86
|
}
|
|
73
87
|
break;
|
|
74
88
|
}
|
|
89
|
+
// Never emitted in tips-only mode; PXE anchors on chain-proposed instead. Kept for union exhaustiveness.
|
|
90
|
+
case 'blocks-added':
|
|
91
|
+
break;
|
|
75
92
|
case 'chain-checkpointed': {
|
|
76
93
|
if (this.config.syncChainTip === 'checkpointed') {
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
94
|
+
// Fetch the checkpointed tip header by hash. By-hash is safer than by-number against a
|
|
95
|
+
// same-height reorg; a missing result means the block was reorged out between the event
|
|
96
|
+
// and this fetch, so we skip the anchor update and let a later event correct it.
|
|
97
|
+
const block = await this.node.getBlockData(BlockHash.fromString(event.block.hash));
|
|
98
|
+
if (block) {
|
|
99
|
+
await this.updateAnchorBlockHeader(block.header);
|
|
100
|
+
} else {
|
|
101
|
+
this.log.warn(
|
|
102
|
+
`Block header not found for checkpointed block ${event.block.number}, skipping anchor update`,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
80
105
|
}
|
|
81
106
|
break;
|
|
82
107
|
}
|
|
@@ -110,7 +135,7 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
110
135
|
`Ignoring prune event to block ${event.block.number} greater than current anchor block ${currentAnchorBlockNumber}`,
|
|
111
136
|
{ pruneEvent: event, currentAnchorBlockHeader: currentAnchorBlockHeader.toInspect() },
|
|
112
137
|
);
|
|
113
|
-
|
|
138
|
+
break;
|
|
114
139
|
}
|
|
115
140
|
|
|
116
141
|
this.log.warn(`Pruning data after block ${event.block.number} due to reorg`, { pruneBlock: event.block });
|
|
@@ -131,11 +156,21 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
131
156
|
await this.store.transactionAsync(async () => {
|
|
132
157
|
await this.noteStore.rollback(event.block.number);
|
|
133
158
|
await this.privateEventStore.rollback(event.block.number);
|
|
159
|
+
await this.factStore.rollback(event.block.number);
|
|
134
160
|
await this.updateAnchorBlockHeader(newAnchorBlockHeader);
|
|
135
161
|
});
|
|
136
162
|
break;
|
|
137
163
|
}
|
|
164
|
+
default: {
|
|
165
|
+
const _: never = event;
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
138
168
|
}
|
|
169
|
+
|
|
170
|
+
// Advance the tips store cursor only after the anchor update / prune rollback above succeeds. If that work
|
|
171
|
+
// throws, the cursor stays put and the stream re-emits this event on the next sync pass (at-least-once),
|
|
172
|
+
// matching the prover-node's handle-first/tips-last ordering. The SerialQueue makes this reorder safe.
|
|
173
|
+
await this.l2TipsStore.handleBlockStreamEvent(event);
|
|
139
174
|
}
|
|
140
175
|
|
|
141
176
|
/** Updates the anchor block header to the target block */
|
|
@@ -144,6 +179,12 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
144
179
|
// Therefore, we clear the contract synchronization cache here such that the sync is re-triggered upon new
|
|
145
180
|
// execution.
|
|
146
181
|
this.contractSyncService.wipe();
|
|
182
|
+
|
|
183
|
+
// The contract class service keeps a per-block cache - since updating our anchor means it is very unlikely we'd
|
|
184
|
+
// ever re-simulate at past anchors, we wipe its cache to prevent runaway memory growth on very long-lived PXE
|
|
185
|
+
// instances.
|
|
186
|
+
this.contractClassService.wipe();
|
|
187
|
+
|
|
147
188
|
this.log.verbose(`Updated pxe last block to ${blockHeader.getBlockNumber()}`, blockHeader.toInspect());
|
|
148
189
|
await this.anchorBlockStore.setHeader(blockHeader);
|
|
149
190
|
}
|
package/src/config/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { type ChainConfig, chainConfigMappings } from '@aztec/stdlib/config';
|
|
|
10
10
|
import { type DataStoreConfig, dataConfigMappings } from '@aztec/stdlib/kv-store';
|
|
11
11
|
|
|
12
12
|
export { getPackageInfo } from './package_info.js';
|
|
13
|
+
export * from '../hooks/index.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Configuration settings for the prover factory
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import { isProtocolContract } from '@aztec/protocol-contracts';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
5
|
+
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
6
|
+
|
|
7
|
+
import type { ContractStore } from '../storage/contract_store/contract_store.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Resolves the contract class id that an address runs at a given anchor block, as tracked by the chain.
|
|
11
|
+
*
|
|
12
|
+
* PXE does not store a contract's current class id: it is mutable, chain-derived state that changes when a contract is
|
|
13
|
+
* upgraded and can be undone by a reorg. Instead this service asks the node for the current class at an anchor block,
|
|
14
|
+
* falling back to a local instance if no upgrades were scheduled.
|
|
15
|
+
*/
|
|
16
|
+
export class ContractClassService {
|
|
17
|
+
/**
|
|
18
|
+
* Class ids are cached per `(address, anchorHash)`. This avoid unnecessary network roundtrips in scenarios where
|
|
19
|
+
* multiple executions are done on the same anchor block (e.g. simulation followed by witgen), or when the same
|
|
20
|
+
* contract is invoked multiple times in an execution (e.g. authwit checks).
|
|
21
|
+
* It also means the callers don't need to worry about caching this service's return values, simplifying callsites.
|
|
22
|
+
*/
|
|
23
|
+
#cache: Map<string, Promise<Fr | undefined>> = new Map();
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
private node: AztecNode,
|
|
27
|
+
private contractStore: ContractStore,
|
|
28
|
+
) {}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns the class id that corresponds to `address` as of `anchorBlockHeader`, or `undefined` if no instance is
|
|
32
|
+
* registered for `address`. A missing instance is an absence the caller decides how to handle, not an error; genuine
|
|
33
|
+
* failures (e.g. the node being unreachable) still throw.
|
|
34
|
+
*/
|
|
35
|
+
async getCurrentClassId(address: AztecAddress, anchorBlockHeader: BlockHeader): Promise<Fr | undefined> {
|
|
36
|
+
// Protocol contracts are not in the registry and cannot be upgraded, so their original class is always current.
|
|
37
|
+
// Short-circuiting avoids a node round-trip.
|
|
38
|
+
if (isProtocolContract(address)) {
|
|
39
|
+
const instance = await this.contractStore.getContractInstance(address);
|
|
40
|
+
return instance?.originalContractClassId;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const key = `${address.toString()}:${(await anchorBlockHeader.hash()).toString()}`;
|
|
44
|
+
let promise = this.#cache.get(key);
|
|
45
|
+
if (!promise) {
|
|
46
|
+
promise = (async () => {
|
|
47
|
+
// The node resolves the current class from the same scheduled value change the AVM enforces against the public
|
|
48
|
+
// data tree. If the contract was upgraded the node returns a non-undefined instance; an undefined result means
|
|
49
|
+
// no upgrade happened (or the node has no record of it, e.g. it was never publicly deployed), so the original
|
|
50
|
+
// class is current.
|
|
51
|
+
|
|
52
|
+
const nodeInstance = await this.node.getContract(address, await anchorBlockHeader.hash());
|
|
53
|
+
|
|
54
|
+
if (nodeInstance) {
|
|
55
|
+
return nodeInstance.currentContractClassId;
|
|
56
|
+
} else {
|
|
57
|
+
return (await this.contractStore.getContractInstance(address))?.originalContractClassId;
|
|
58
|
+
}
|
|
59
|
+
})().catch(err => {
|
|
60
|
+
this.#cache.delete(key);
|
|
61
|
+
throw err;
|
|
62
|
+
});
|
|
63
|
+
this.#cache.set(key, promise);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const classId = await promise;
|
|
67
|
+
if (classId === undefined) {
|
|
68
|
+
// Don't memoize a missing instance: it may be registered later in this PXE (e.g. via contract sync
|
|
69
|
+
// mid-execution), and a cached miss would then hide it. Only successful resolutions stay cached.
|
|
70
|
+
this.#cache.delete(key);
|
|
71
|
+
}
|
|
72
|
+
return classId;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Clears the cache.
|
|
77
|
+
*
|
|
78
|
+
* This is not required for correctness, only to limit how much memory the cache uses. The cache is resilient against
|
|
79
|
+
* reorgs etc. as it is based on block hashes, not block numbers. */
|
|
80
|
+
wipe(): void {
|
|
81
|
+
this.#cache.clear();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -10,7 +10,8 @@ import type { StagedStore } from '../job_coordinator/job_coordinator.js';
|
|
|
10
10
|
import { NoteService } from '../notes/note_service.js';
|
|
11
11
|
import type { ContractStore } from '../storage/contract_store/contract_store.js';
|
|
12
12
|
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
13
|
-
import {
|
|
13
|
+
import type { ContractClassService } from './contract_class_service.js';
|
|
14
|
+
import { syncScope } from './helpers.js';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Maximum number of scope syncs running concurrently within a single sync call. Sized to trade off parallelism
|
|
@@ -19,8 +20,8 @@ import { syncScope, verifyCurrentClassId } from './helpers.js';
|
|
|
19
20
|
export const MAX_CONCURRENT_SCOPE_SYNCS = 5;
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
|
-
* Service for syncing the private state of contracts
|
|
23
|
-
*
|
|
23
|
+
* Service for syncing the private state of contracts. It uses a cache to avoid redundant sync operations - the cache
|
|
24
|
+
* is wiped when the anchor block changes.
|
|
24
25
|
*
|
|
25
26
|
* TODO: The StagedStore naming is broken here. Figure out a better name.
|
|
26
27
|
*/
|
|
@@ -32,19 +33,16 @@ export class ContractSyncService implements StagedStore {
|
|
|
32
33
|
// The value is a promise that resolves when the contract is synced.
|
|
33
34
|
private syncedContracts: Map<string, Promise<void>> = new Map();
|
|
34
35
|
|
|
35
|
-
// Tracks class ID verification per contract. Keyed by contract address only (no scope), since
|
|
36
|
-
// class ID verification is scope-independent. Cleared on wipe/discard.
|
|
37
|
-
private classIdVerificationCache: Map<string, Promise<void>> = new Map();
|
|
38
|
-
|
|
39
36
|
constructor(
|
|
40
37
|
private aztecNode: AztecNode,
|
|
41
38
|
private contractStore: ContractStore,
|
|
39
|
+
private contractClassService: ContractClassService,
|
|
42
40
|
private noteStore: NoteStore,
|
|
43
41
|
private log: Logger,
|
|
44
42
|
) {}
|
|
45
43
|
|
|
46
44
|
/**
|
|
47
|
-
* Ensures a contract's private state is synchronized
|
|
45
|
+
* Ensures a contract's private state is synchronized.
|
|
48
46
|
* Uses a cache to avoid redundant sync operations - the cache is wiped when the anchor block changes.
|
|
49
47
|
* @param contractAddress - The address of the contract to sync.
|
|
50
48
|
* @param functionToInvokeAfterSync - The function selector that will be called after sync (used to validate it's
|
|
@@ -61,7 +59,15 @@ export class ContractSyncService implements StagedStore {
|
|
|
61
59
|
scopes: AztecAddress[],
|
|
62
60
|
): Promise<void> {
|
|
63
61
|
this.#startSyncIfNeeded(contractAddress, scopes, anchorBlockHeader, jobId, scope =>
|
|
64
|
-
syncScope(
|
|
62
|
+
syncScope(
|
|
63
|
+
contractAddress,
|
|
64
|
+
this.contractStore,
|
|
65
|
+
this.contractClassService,
|
|
66
|
+
anchorBlockHeader,
|
|
67
|
+
functionToInvokeAfterSync,
|
|
68
|
+
utilityExecutor,
|
|
69
|
+
scope,
|
|
70
|
+
),
|
|
65
71
|
);
|
|
66
72
|
|
|
67
73
|
await this.#awaitSync(contractAddress, scopes);
|
|
@@ -79,7 +85,6 @@ export class ContractSyncService implements StagedStore {
|
|
|
79
85
|
wipe(): void {
|
|
80
86
|
this.log.debug(`Wiping contract sync cache (${this.syncedContracts.size} entries)`);
|
|
81
87
|
this.syncedContracts.clear();
|
|
82
|
-
this.classIdVerificationCache.clear();
|
|
83
88
|
}
|
|
84
89
|
|
|
85
90
|
commit(_jobId: string): Promise<void> {
|
|
@@ -90,15 +95,13 @@ export class ContractSyncService implements StagedStore {
|
|
|
90
95
|
// We clear the synced contracts cache here because, when the job is discarded, any associated database writes from
|
|
91
96
|
// the sync are also undone.
|
|
92
97
|
this.syncedContracts.clear();
|
|
93
|
-
this.classIdVerificationCache.clear();
|
|
94
98
|
return Promise.resolve();
|
|
95
99
|
}
|
|
96
100
|
|
|
97
101
|
/**
|
|
98
102
|
* For each unsynced scope, creates a promise that waits on:
|
|
99
|
-
* 1.
|
|
100
|
-
* 2.
|
|
101
|
-
* 3. Per-scope sync (individual, semaphore-bounded).
|
|
103
|
+
* 1. Note nullifier sync (shared, batched across all unsynced scopes).
|
|
104
|
+
* 2. Per-scope sync (individual, semaphore-bounded).
|
|
102
105
|
*/
|
|
103
106
|
#startSyncIfNeeded(
|
|
104
107
|
contractAddress: AztecAddress,
|
|
@@ -114,7 +117,6 @@ export class ContractSyncService implements StagedStore {
|
|
|
114
117
|
|
|
115
118
|
this.log.debug(`Syncing contract ${contractAddress} for ${scopesToSync.length} scope(s)`);
|
|
116
119
|
|
|
117
|
-
const verifyPromise = this.#verifyClassId(contractAddress, anchorBlockHeader);
|
|
118
120
|
const syncNullifiersPromise = this.#syncNoteNullifiers(contractAddress, anchorBlockHeader, jobId, scopesToSync);
|
|
119
121
|
|
|
120
122
|
// We build a new semaphore for each sync call, so it rate-limits the scopes within that single call. We do
|
|
@@ -123,11 +125,7 @@ export class ContractSyncService implements StagedStore {
|
|
|
123
125
|
|
|
124
126
|
for (const scope of scopesToSync) {
|
|
125
127
|
const key = toKey(contractAddress, scope);
|
|
126
|
-
const promise = Promise.all([
|
|
127
|
-
verifyPromise,
|
|
128
|
-
syncNullifiersPromise,
|
|
129
|
-
runBounded(syncSlot, () => syncScopeFn(scope)),
|
|
130
|
-
])
|
|
128
|
+
const promise = Promise.all([syncNullifiersPromise, runBounded(syncSlot, () => syncScopeFn(scope))])
|
|
131
129
|
.then(() => {})
|
|
132
130
|
.catch(err => {
|
|
133
131
|
this.syncedContracts.delete(key);
|
|
@@ -137,23 +135,6 @@ export class ContractSyncService implements StagedStore {
|
|
|
137
135
|
}
|
|
138
136
|
}
|
|
139
137
|
|
|
140
|
-
/** Verifies the local class ID matches the on-chain value (cached, evicts on failure so retries re-verify). */
|
|
141
|
-
#verifyClassId(contractAddress: AztecAddress, anchorBlockHeader: BlockHeader): Promise<void> {
|
|
142
|
-
const contractKey = contractAddress.toString();
|
|
143
|
-
const cached = this.classIdVerificationCache.get(contractKey);
|
|
144
|
-
if (cached) {
|
|
145
|
-
return cached;
|
|
146
|
-
}
|
|
147
|
-
const promise = verifyCurrentClassId(contractAddress, this.aztecNode, this.contractStore, anchorBlockHeader).catch(
|
|
148
|
-
err => {
|
|
149
|
-
this.classIdVerificationCache.delete(contractKey);
|
|
150
|
-
throw err;
|
|
151
|
-
},
|
|
152
|
-
);
|
|
153
|
-
this.classIdVerificationCache.set(contractKey, promise);
|
|
154
|
-
return promise;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
138
|
/** Syncs note nullifiers across all unsynced scopes in a single batched call. */
|
|
158
139
|
async #syncNoteNullifiers(
|
|
159
140
|
contractAddress: AztecAddress,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isProtocolContract } from '@aztec/protocol-contracts';
|
|
2
|
+
import type { FunctionCall, FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
5
|
+
|
|
6
|
+
import type { ContractStore } from '../storage/contract_store/contract_store.js';
|
|
7
|
+
import type { ContractClassService } from './contract_class_service.js';
|
|
8
|
+
|
|
9
|
+
export async function syncScope(
|
|
10
|
+
contractAddress: AztecAddress,
|
|
11
|
+
contractStore: ContractStore,
|
|
12
|
+
contractClassService: ContractClassService,
|
|
13
|
+
anchorBlockHeader: BlockHeader,
|
|
14
|
+
functionToInvokeAfterSync: FunctionSelector | null,
|
|
15
|
+
utilityExecutor: (privateSyncCall: FunctionCall, scopes: AztecAddress[]) => Promise<any>,
|
|
16
|
+
scope: AztecAddress,
|
|
17
|
+
) {
|
|
18
|
+
// Protocol contracts don't have private state to sync
|
|
19
|
+
if (isProtocolContract(contractAddress)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const classId = await contractClassService.getCurrentClassId(contractAddress, anchorBlockHeader);
|
|
24
|
+
if (!classId) {
|
|
25
|
+
throw new Error(`Cannot sync contract ${contractAddress}: its instance is not registered nor published.`);
|
|
26
|
+
}
|
|
27
|
+
const syncStateFunctionCall = await contractStore.getFunctionCall('sync_state', [scope], contractAddress, classId);
|
|
28
|
+
if (functionToInvokeAfterSync && functionToInvokeAfterSync.equals(syncStateFunctionCall.selector)) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
'Forbidden `sync_state` invocation. `sync_state` can only be invoked by PXE, manual execution can lead to inconsistencies.',
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
await utilityExecutor(syncStateFunctionCall, [scope]);
|
|
35
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import type { FunctionArtifactWithContractName, FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import type { ContractInstancePreimageWithAddress } from '@aztec/stdlib/contract';
|
|
5
|
+
import type { BlockHeader, ContractOverrides } from '@aztec/stdlib/tx';
|
|
6
|
+
|
|
7
|
+
import type { ContractClassService } from '../contract/contract_class_service.js';
|
|
8
|
+
import type { ContractStore } from '../storage/contract_store/contract_store.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Per-run view of contract data for a single simulation, bound to its anchor block.
|
|
12
|
+
*
|
|
13
|
+
* The {@link ContractStore} is pure class-id-keyed storage and has no notion of which class an address runs. This
|
|
14
|
+
* class bridges that gap: it resolves an address to its current class id (via the {@link ContractClassService}
|
|
15
|
+
* at the run's anchor block) and then serves artifacts from the store. It is also the single place contract
|
|
16
|
+
* overrides are applied — when an address is overridden, both its instance and its class id come from the override
|
|
17
|
+
* rather than the chain, so a simulation can execute different bytecode at that address. Overrides are only set for
|
|
18
|
+
* `simulateTx` (which skips the kernels), so the override path never reaches proving.
|
|
19
|
+
*/
|
|
20
|
+
export class AnchoredContractData {
|
|
21
|
+
constructor(
|
|
22
|
+
private readonly store: ContractStore,
|
|
23
|
+
private readonly contractClassService: ContractClassService,
|
|
24
|
+
private readonly anchorBlockHeader: BlockHeader,
|
|
25
|
+
private readonly overrides?: ContractOverrides,
|
|
26
|
+
) {}
|
|
27
|
+
|
|
28
|
+
/** Returns the address preimage of the instance at `address`, from the override if any, else from storage. */
|
|
29
|
+
getContractInstance(address: AztecAddress): Promise<ContractInstancePreimageWithAddress | undefined> {
|
|
30
|
+
const override = this.overrides?.[address.toString()];
|
|
31
|
+
if (override) {
|
|
32
|
+
return Promise.resolve(override.instance);
|
|
33
|
+
}
|
|
34
|
+
return this.store.getContractInstance(address);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Resolves the class id `address` runs in this simulation: the override's class if overridden, else resolved against
|
|
39
|
+
* the chain at the anchor block.
|
|
40
|
+
*/
|
|
41
|
+
getCurrentClassId(address: AztecAddress): Promise<Fr | undefined> {
|
|
42
|
+
const override = this.overrides?.[address.toString()];
|
|
43
|
+
if (override) {
|
|
44
|
+
return Promise.resolve(override.instance.currentContractClassId);
|
|
45
|
+
}
|
|
46
|
+
return this.contractClassService.getCurrentClassId(address, this.anchorBlockHeader);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async getFunctionArtifact(
|
|
50
|
+
address: AztecAddress,
|
|
51
|
+
selector: FunctionSelector,
|
|
52
|
+
): Promise<FunctionArtifactWithContractName | undefined> {
|
|
53
|
+
const classId = await this.getCurrentClassId(address);
|
|
54
|
+
return classId ? this.store.getFunctionArtifact(classId, selector) : undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async getFunctionArtifactWithDebugMetadata(
|
|
58
|
+
address: AztecAddress,
|
|
59
|
+
selector: FunctionSelector,
|
|
60
|
+
): Promise<FunctionArtifactWithContractName | undefined> {
|
|
61
|
+
const classId = await this.getCurrentClassId(address);
|
|
62
|
+
return classId ? this.store.getFunctionArtifactWithDebugMetadata(classId, selector) : undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async getDebugContractName(address: AztecAddress): Promise<string | undefined> {
|
|
66
|
+
const classId = await this.getCurrentClassId(address);
|
|
67
|
+
return classId ? this.store.getDebugContractName(classId) : undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string> {
|
|
71
|
+
const classId = await this.getCurrentClassId(address);
|
|
72
|
+
return classId ? this.store.getDebugFunctionName(classId, selector) : `${address}:${selector}`;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
+
import type { BlockHash, BlockParameter } from '@aztec/stdlib/block';
|
|
4
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
5
|
+
import type { TxHash } from '@aztec/stdlib/tx';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Per-execution cache for immutable Aztec node reads.
|
|
9
|
+
*/
|
|
10
|
+
export class AztecNodeReadCache {
|
|
11
|
+
private readonly cache = new Map<string, Promise<unknown>>();
|
|
12
|
+
|
|
13
|
+
constructor(private readonly aztecNode: AztecNode) {}
|
|
14
|
+
|
|
15
|
+
/** Fetches a block without reissuing the same node request. */
|
|
16
|
+
public getBlock(block: BlockParameter) {
|
|
17
|
+
return this.#cachedRead(`block:${this.#keyPart(block)}`, () => this.aztecNode.getBlock(block));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Fetches a transaction receipt with its effect attached. */
|
|
21
|
+
public getTxReceiptWithEffect(txHash: TxHash) {
|
|
22
|
+
return this.#cachedRead(`tx-receipt-with-effect:${txHash.toString()}`, () =>
|
|
23
|
+
this.aztecNode.getTxReceipt(txHash, { includeTxEffect: true } as const),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Fetches an archive-tree witness for a block hash. */
|
|
28
|
+
public getBlockHashMembershipWitness(referenceBlock: BlockParameter, blockHash: BlockHash) {
|
|
29
|
+
return this.#cachedRead(
|
|
30
|
+
`block-hash-membership-witness:${this.#keyPart(referenceBlock)}:${blockHash.toString()}`,
|
|
31
|
+
() => this.aztecNode.getBlockHashMembershipWitness(referenceBlock, blockHash),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Fetches a public-data-tree witness for a leaf slot. */
|
|
36
|
+
public getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr) {
|
|
37
|
+
return this.#cachedRead(`public-data-witness:${this.#keyPart(referenceBlock)}:${leafSlot.toString()}`, () =>
|
|
38
|
+
this.aztecNode.getPublicDataWitness(referenceBlock, leafSlot),
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Fetches public storage for a single slot. */
|
|
43
|
+
public getPublicStorageAt(referenceBlock: BlockParameter, contractAddress: AztecAddress, storageSlot: Fr) {
|
|
44
|
+
return this.#cachedRead(
|
|
45
|
+
`public-storage:${this.#keyPart(referenceBlock)}:${contractAddress.toString()}:${storageSlot.toString()}`,
|
|
46
|
+
() => this.aztecNode.getPublicStorageAt(referenceBlock, contractAddress, storageSlot),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Fetches a contiguous public storage range, reusing cached reads for overlapping slots. */
|
|
51
|
+
public getPublicStorageRange(
|
|
52
|
+
referenceBlock: BlockParameter,
|
|
53
|
+
contractAddress: AztecAddress,
|
|
54
|
+
startStorageSlot: Fr,
|
|
55
|
+
numberOfElements: number,
|
|
56
|
+
) {
|
|
57
|
+
const slots = Array(numberOfElements)
|
|
58
|
+
.fill(0)
|
|
59
|
+
.map((_, i) => new Fr(startStorageSlot.value + BigInt(i)));
|
|
60
|
+
|
|
61
|
+
return Promise.all(slots.map(storageSlot => this.getPublicStorageAt(referenceBlock, contractAddress, storageSlot)));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#cachedRead<T>(key: string, fetch: () => Promise<T>): Promise<T> {
|
|
65
|
+
const cached = this.cache.get(key);
|
|
66
|
+
if (cached) {
|
|
67
|
+
return cached as Promise<T>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const promise = fetch();
|
|
71
|
+
promise.catch(() => this.cache.delete(key));
|
|
72
|
+
this.cache.set(key, promise);
|
|
73
|
+
return promise;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
#keyPart(value: unknown): string {
|
|
77
|
+
if (['string', 'number', 'bigint', 'boolean'].includes(typeof value)) {
|
|
78
|
+
return String(value);
|
|
79
|
+
}
|
|
80
|
+
if (value && typeof value === 'object') {
|
|
81
|
+
const toString = (value as { toString?: () => string }).toString;
|
|
82
|
+
if (toString && toString !== Object.prototype.toString) {
|
|
83
|
+
return toString.call(value);
|
|
84
|
+
}
|
|
85
|
+
return JSON.stringify(value, (_key, nested) => (typeof nested === 'bigint' ? nested.toString() : nested));
|
|
86
|
+
}
|
|
87
|
+
return String(value);
|
|
88
|
+
}
|
|
89
|
+
}
|