@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
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { CONTRACT_CLASS_LOG_SIZE_IN_FIELDS, PRIVATE_LOG_SIZE_IN_FIELDS } from '@aztec/constants';
|
|
3
3
|
import { BlockNumber, CheckpointNumber, IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
|
+
import { Point } from '@aztec/foundation/curves/grumpkin';
|
|
5
6
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
7
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
7
8
|
import { KeyStore } from '@aztec/key-store';
|
|
@@ -14,9 +15,10 @@ import { BlockHash, Body, GENESIS_BLOCK_HEADER_HASH, L2Block } from '@aztec/stdl
|
|
|
14
15
|
import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
15
16
|
import { CompleteAddress, SerializableContractInstance } from '@aztec/stdlib/contract';
|
|
16
17
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
17
|
-
import { PublicKey, PublicKeys } from '@aztec/stdlib/keys';
|
|
18
|
+
import { PublicKey, PublicKeys, deriveKeys } from '@aztec/stdlib/keys';
|
|
18
19
|
import {
|
|
19
20
|
AppTaggingSecret,
|
|
21
|
+
AppTaggingSecretKind,
|
|
20
22
|
ContractClassLog,
|
|
21
23
|
ContractClassLogFields,
|
|
22
24
|
PrivateLog,
|
|
@@ -39,9 +41,11 @@ import { AddressStore } from '../address_store/address_store.js';
|
|
|
39
41
|
import { AnchorBlockStore } from '../anchor_block_store/index.js';
|
|
40
42
|
import { CapsuleStore } from '../capsule_store/capsule_store.js';
|
|
41
43
|
import { ContractStore } from '../contract_store/contract_store.js';
|
|
44
|
+
import { FactStore } from '../fact_store/fact_store.js';
|
|
45
|
+
import { FactCollectionKey } from '../fact_store/fact_store_keys.js';
|
|
42
46
|
import { NoteStore } from '../note_store/note_store.js';
|
|
43
47
|
import { PrivateEventStore } from '../private_event_store/private_event_store.js';
|
|
44
|
-
import { RecipientTaggingStore,
|
|
48
|
+
import { RecipientTaggingStore, SenderTaggingStore, TaggingSecretSourcesStore } from '../tagging_store/index.js';
|
|
45
49
|
import { snapshotArray, snapshotMap, snapshotSingleton } from './kv_store_snapshot.js';
|
|
46
50
|
|
|
47
51
|
/**
|
|
@@ -106,7 +110,7 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
|
|
|
106
110
|
SlotNumber(47),
|
|
107
111
|
53n,
|
|
108
112
|
EthAddress.fromField(new Fr(59n)),
|
|
109
|
-
AztecAddress.
|
|
113
|
+
AztecAddress.fromBigIntUnsafe(61n),
|
|
110
114
|
new GasFees(67n, 71n),
|
|
111
115
|
),
|
|
112
116
|
new Fr(73n),
|
|
@@ -125,8 +129,8 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
|
|
|
125
129
|
const capsuleStore = new CapsuleStore(kvStore);
|
|
126
130
|
|
|
127
131
|
const jobId = 'fixture-job';
|
|
128
|
-
const contractAddress = AztecAddress.
|
|
129
|
-
const scope = AztecAddress.
|
|
132
|
+
const contractAddress = AztecAddress.fromBigIntUnsafe(2n);
|
|
133
|
+
const scope = AztecAddress.fromBigIntUnsafe(3n);
|
|
130
134
|
|
|
131
135
|
// Three setCapsule calls (2-element, 1-element, 0-element value vector) pin every value-encoding length case.
|
|
132
136
|
capsuleStore.setCapsule(contractAddress, new Fr(5n), [new Fr(7n), new Fr(11n)], jobId, scope);
|
|
@@ -188,7 +192,7 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
|
|
|
188
192
|
new SerializableContractInstance({
|
|
189
193
|
version: 2,
|
|
190
194
|
salt: new Fr(73n),
|
|
191
|
-
deployer: AztecAddress.
|
|
195
|
+
deployer: AztecAddress.fromBigIntUnsafe(79n),
|
|
192
196
|
currentContractClassId: new Fr(83n),
|
|
193
197
|
originalContractClassId: new Fr(89n),
|
|
194
198
|
initializationHash: new Fr(97n),
|
|
@@ -204,7 +208,7 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
|
|
|
204
208
|
new Fr(71n),
|
|
205
209
|
new Fr(73n),
|
|
206
210
|
),
|
|
207
|
-
}).withAddress(AztecAddress.
|
|
211
|
+
}).withAddress(AztecAddress.fromBigIntUnsafe(101n)),
|
|
208
212
|
);
|
|
209
213
|
},
|
|
210
214
|
snapshotStore: async kvStore => ({
|
|
@@ -214,11 +218,45 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
|
|
|
214
218
|
}),
|
|
215
219
|
},
|
|
216
220
|
|
|
221
|
+
{
|
|
222
|
+
name: 'FactStore',
|
|
223
|
+
writeToStore: async kvStore => {
|
|
224
|
+
const factStore = new FactStore(kvStore);
|
|
225
|
+
const jobId = 'fixture-job';
|
|
226
|
+
const contract = AztecAddress.fromBigIntUnsafe(100n);
|
|
227
|
+
const scope = AztecAddress.fromBigIntUnsafe(1n);
|
|
228
|
+
const factCollectionTypeId = new Fr(7n);
|
|
229
|
+
const keyA = FactCollectionKey.from({
|
|
230
|
+
contractAddress: contract,
|
|
231
|
+
scope,
|
|
232
|
+
factCollectionTypeId,
|
|
233
|
+
factCollectionId: new Fr(0xaan),
|
|
234
|
+
});
|
|
235
|
+
const keyB = FactCollectionKey.from({
|
|
236
|
+
contractAddress: contract,
|
|
237
|
+
scope,
|
|
238
|
+
factCollectionTypeId,
|
|
239
|
+
factCollectionId: new Fr(0xbbn),
|
|
240
|
+
});
|
|
241
|
+
// A collection whose only fact is retractable (origin block 6): pruned on a reorg above block 6.
|
|
242
|
+
await factStore.recordFact(keyA, new Fr(3n), [new Fr(5n)], { blockNumber: 6, blockHash: new Fr(2n) }, jobId);
|
|
243
|
+
// A collection with a non-retractable and a retractable fact.
|
|
244
|
+
await factStore.recordFact(keyB, new Fr(1n), [new Fr(9n)], undefined, jobId);
|
|
245
|
+
await factStore.recordFact(keyB, new Fr(2n), [], { blockNumber: 5, blockHash: new Fr(1n) }, jobId);
|
|
246
|
+
await kvStore.transactionAsync(() => factStore.commit(jobId));
|
|
247
|
+
},
|
|
248
|
+
snapshotStore: async kvStore => ({
|
|
249
|
+
facts: await snapshotMap(kvStore.openMap<string, Buffer>('facts')),
|
|
250
|
+
facts_by_collection: await snapshotMap(kvStore.openMultiMap<string, string>('facts_by_collection')),
|
|
251
|
+
facts_by_block: await snapshotMap(kvStore.openMultiMap<number, string>('facts_by_block')),
|
|
252
|
+
}),
|
|
253
|
+
},
|
|
254
|
+
|
|
217
255
|
{
|
|
218
256
|
name: 'KeyStore',
|
|
219
257
|
writeToStore: async kvStore => {
|
|
220
258
|
const keyStore = new KeyStore(kvStore);
|
|
221
|
-
await keyStore.addAccount(new Fr(2n), new Fr(3n));
|
|
259
|
+
await keyStore.addAccount(await deriveKeys(new Fr(2n)), new Fr(3n));
|
|
222
260
|
},
|
|
223
261
|
snapshotStore: async kvStore => ({
|
|
224
262
|
key_store: await snapshotMap(kvStore.openMap<string, Buffer>('key_store')),
|
|
@@ -243,9 +281,10 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
|
|
|
243
281
|
SlotNumber(19),
|
|
244
282
|
23n,
|
|
245
283
|
EthAddress.fromField(new Fr(29n)),
|
|
246
|
-
AztecAddress.
|
|
284
|
+
AztecAddress.fromBigIntUnsafe(31n),
|
|
247
285
|
new GasFees(37n, 41n),
|
|
248
286
|
new Fr(43n),
|
|
287
|
+
new Fr(47n),
|
|
249
288
|
),
|
|
250
289
|
[block],
|
|
251
290
|
CheckpointNumber(47),
|
|
@@ -261,7 +300,10 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
|
|
|
261
300
|
await l2TipsStore.handleBlockStreamEvent({
|
|
262
301
|
type: 'chain-checkpointed',
|
|
263
302
|
block: { number: BlockNumber(71), hash: new Fr(73n).toString() },
|
|
264
|
-
checkpoint:
|
|
303
|
+
checkpoint: {
|
|
304
|
+
number: publishedCheckpoint.checkpoint.number,
|
|
305
|
+
hash: publishedCheckpoint.checkpoint.hash().toString(),
|
|
306
|
+
},
|
|
265
307
|
});
|
|
266
308
|
// `'chain-proven'` writes the 'proven' tag. `'finalized'` is omitted because its handler runs delete-before
|
|
267
309
|
// logic that would depend on the order of preceding events.
|
|
@@ -289,17 +331,17 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
|
|
|
289
331
|
|
|
290
332
|
// Two contracts so `note_nullifiers_by_contract` exhibits both a multi-value row (contractA → {n1, n2}) and a
|
|
291
333
|
// single-value row (contractB → {n3}).
|
|
292
|
-
const contractA = AztecAddress.
|
|
293
|
-
const contractB = AztecAddress.
|
|
294
|
-
const scopeX = AztecAddress.
|
|
295
|
-
const scopeY = AztecAddress.
|
|
334
|
+
const contractA = AztecAddress.fromBigIntUnsafe(2n);
|
|
335
|
+
const contractB = AztecAddress.fromBigIntUnsafe(3n);
|
|
336
|
+
const scopeX = AztecAddress.fromBigIntUnsafe(5n);
|
|
337
|
+
const scopeY = AztecAddress.fromBigIntUnsafe(7n);
|
|
296
338
|
|
|
297
339
|
// note1: active, will be added under two scopes to exercise the multi-element scopes vector encoding in
|
|
298
340
|
// `StoredNote.toBuffer`.
|
|
299
341
|
const note1 = new NoteDao(
|
|
300
342
|
new Note([new Fr(13n), new Fr(17n), new Fr(19n)]),
|
|
301
343
|
contractA,
|
|
302
|
-
AztecAddress.
|
|
344
|
+
AztecAddress.fromBigIntUnsafe(23n),
|
|
303
345
|
new Fr(29n),
|
|
304
346
|
new Fr(31n),
|
|
305
347
|
new Fr(37n),
|
|
@@ -316,7 +358,7 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
|
|
|
316
358
|
const note2 = new NoteDao(
|
|
317
359
|
new Note([new Fr(71n), new Fr(73n), new Fr(79n)]),
|
|
318
360
|
contractA,
|
|
319
|
-
AztecAddress.
|
|
361
|
+
AztecAddress.fromBigIntUnsafe(83n),
|
|
320
362
|
new Fr(89n),
|
|
321
363
|
new Fr(97n),
|
|
322
364
|
new Fr(101n),
|
|
@@ -334,7 +376,7 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
|
|
|
334
376
|
const note3 = new NoteDao(
|
|
335
377
|
new Note([new Fr(139n), new Fr(149n), new Fr(151n)]),
|
|
336
378
|
contractB,
|
|
337
|
-
AztecAddress.
|
|
379
|
+
AztecAddress.fromBigIntUnsafe(157n),
|
|
338
380
|
new Fr(163n),
|
|
339
381
|
new Fr(167n),
|
|
340
382
|
new Fr(173n),
|
|
@@ -387,12 +429,12 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
|
|
|
387
429
|
|
|
388
430
|
// Two (contract, selector) pairs and two block numbers so each multimap exhibits both a multi-value row
|
|
389
431
|
// (contractA/selectorA → {e1, e2} and blockN1 → {e1, e2}) and a contrasting single-value row.
|
|
390
|
-
const contractA = AztecAddress.
|
|
391
|
-
const contractB = AztecAddress.
|
|
432
|
+
const contractA = AztecAddress.fromBigIntUnsafe(2n);
|
|
433
|
+
const contractB = AztecAddress.fromBigIntUnsafe(3n);
|
|
392
434
|
const selectorA = EventSelector.fromField(new Fr(5n));
|
|
393
435
|
const selectorB = EventSelector.fromField(new Fr(7n));
|
|
394
|
-
const scopeX = AztecAddress.
|
|
395
|
-
const scopeY = AztecAddress.
|
|
436
|
+
const scopeX = AztecAddress.fromBigIntUnsafe(11n);
|
|
437
|
+
const scopeY = AztecAddress.fromBigIntUnsafe(13n);
|
|
396
438
|
const blockN1 = BlockNumber(17);
|
|
397
439
|
const blockN2 = BlockNumber(19);
|
|
398
440
|
|
|
@@ -487,12 +529,20 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
|
|
|
487
529
|
const recipientTaggingStore = new RecipientTaggingStore(kvStore);
|
|
488
530
|
|
|
489
531
|
const jobId = 'fixture-job';
|
|
490
|
-
const secretA = new AppTaggingSecret(new Fr(2n), AztecAddress.
|
|
491
|
-
const secretB = new AppTaggingSecret(new Fr(5n), AztecAddress.
|
|
532
|
+
const secretA = new AppTaggingSecret(new Fr(2n), AztecAddress.fromBigIntUnsafe(3n));
|
|
533
|
+
const secretB = new AppTaggingSecret(new Fr(5n), AztecAddress.fromBigIntUnsafe(7n));
|
|
534
|
+
// A constrained secret keys under the `constrained:` prefix, so the snapshot pins both kinds side by side.
|
|
535
|
+
const secretConstrained = new AppTaggingSecret(
|
|
536
|
+
new Fr(19n),
|
|
537
|
+
AztecAddress.fromBigIntUnsafe(23n),
|
|
538
|
+
AppTaggingSecretKind.CONSTRAINED,
|
|
539
|
+
);
|
|
492
540
|
|
|
493
541
|
await recipientTaggingStore.updateHighestFinalizedIndex(secretA, 11, jobId);
|
|
494
542
|
await recipientTaggingStore.updateHighestAgedIndex(secretA, 13, jobId);
|
|
495
543
|
await recipientTaggingStore.updateHighestFinalizedIndex(secretB, 17, jobId);
|
|
544
|
+
await recipientTaggingStore.updateHighestFinalizedIndex(secretConstrained, 11, jobId);
|
|
545
|
+
await recipientTaggingStore.updateHighestAgedIndex(secretConstrained, 13, jobId);
|
|
496
546
|
await kvStore.transactionAsync(() => recipientTaggingStore.commit(jobId));
|
|
497
547
|
},
|
|
498
548
|
snapshotStore: async kvStore => ({
|
|
@@ -502,16 +552,35 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
|
|
|
502
552
|
},
|
|
503
553
|
|
|
504
554
|
{
|
|
505
|
-
name: '
|
|
555
|
+
name: 'TaggingSecretSourcesStore',
|
|
506
556
|
writeToStore: async kvStore => {
|
|
507
|
-
const
|
|
557
|
+
const taggingSecretSourcesStore = new TaggingSecretSourcesStore(kvStore);
|
|
558
|
+
|
|
559
|
+
await taggingSecretSourcesStore.addSender(AztecAddress.fromBigIntUnsafe(2n));
|
|
560
|
+
await taggingSecretSourcesStore.addSender(AztecAddress.fromBigIntUnsafe(3n));
|
|
561
|
+
await taggingSecretSourcesStore.addSender(AztecAddress.fromBigIntUnsafe(5n));
|
|
508
562
|
|
|
509
|
-
await
|
|
510
|
-
|
|
511
|
-
|
|
563
|
+
await taggingSecretSourcesStore.addSharedSecret(
|
|
564
|
+
AztecAddress.fromBigIntUnsafe(7n),
|
|
565
|
+
'arbitrary-secret',
|
|
566
|
+
new Point(new Fr(2n), new Fr(3n)),
|
|
567
|
+
);
|
|
568
|
+
await taggingSecretSourcesStore.addSharedSecret(
|
|
569
|
+
AztecAddress.fromBigIntUnsafe(7n),
|
|
570
|
+
'handshake',
|
|
571
|
+
new Point(new Fr(5n), new Fr(7n)),
|
|
572
|
+
);
|
|
573
|
+
await taggingSecretSourcesStore.addSharedSecret(
|
|
574
|
+
AztecAddress.fromBigIntUnsafe(11n),
|
|
575
|
+
'arbitrary-secret',
|
|
576
|
+
new Point(new Fr(13n), new Fr(17n)),
|
|
577
|
+
);
|
|
512
578
|
},
|
|
513
579
|
snapshotStore: async kvStore => ({
|
|
514
|
-
|
|
580
|
+
senders: await snapshotMap(kvStore.openMap<string, true>('senders')),
|
|
581
|
+
recipient_shared_secrets: await snapshotMap(
|
|
582
|
+
kvStore.openMultiMap<string, { kind: string; secret: string }>('recipient_shared_secrets'),
|
|
583
|
+
),
|
|
515
584
|
}),
|
|
516
585
|
},
|
|
517
586
|
|
|
@@ -521,13 +590,20 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
|
|
|
521
590
|
const senderTaggingStore = new SenderTaggingStore(kvStore);
|
|
522
591
|
|
|
523
592
|
const jobId = 'fixture-job';
|
|
524
|
-
const secretA = new AppTaggingSecret(new Fr(2n), AztecAddress.
|
|
525
|
-
const secretB = new AppTaggingSecret(new Fr(5n), AztecAddress.
|
|
526
|
-
const secretC = new AppTaggingSecret(new Fr(11n), AztecAddress.
|
|
593
|
+
const secretA = new AppTaggingSecret(new Fr(2n), AztecAddress.fromBigIntUnsafe(3n));
|
|
594
|
+
const secretB = new AppTaggingSecret(new Fr(5n), AztecAddress.fromBigIntUnsafe(7n));
|
|
595
|
+
const secretC = new AppTaggingSecret(new Fr(11n), AztecAddress.fromBigIntUnsafe(13n));
|
|
596
|
+
const secretConstrained = new AppTaggingSecret(
|
|
597
|
+
new Fr(19n),
|
|
598
|
+
AztecAddress.fromBigIntUnsafe(23n),
|
|
599
|
+
AppTaggingSecretKind.CONSTRAINED,
|
|
600
|
+
);
|
|
527
601
|
const txHashA = TxHash.fromBigInt(17n);
|
|
528
602
|
const txHashB = TxHash.fromBigInt(19n);
|
|
529
603
|
const txHashC = TxHash.fromBigInt(23n);
|
|
530
604
|
const txHashD = TxHash.fromBigInt(29n);
|
|
605
|
+
const txHashE = TxHash.fromBigInt(31n);
|
|
606
|
+
const txHashF = TxHash.fromBigInt(37n);
|
|
531
607
|
|
|
532
608
|
// secretA receives three pending ranges (one per tx); secretB receives one. After finalizing txHashA below,
|
|
533
609
|
// secretA's array shrinks to two elements (the txHashB and txHashC ranges, both with highestIndex > 3) which
|
|
@@ -566,7 +642,20 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
|
|
|
566
642
|
jobId,
|
|
567
643
|
);
|
|
568
644
|
|
|
569
|
-
|
|
645
|
+
// secretConstrained gets a finalized range (txHashE) plus a surviving higher pending range (txHashF), so the
|
|
646
|
+
// `constrained:` key lands in both pending_indexes and last_finalized_indexes.
|
|
647
|
+
await senderTaggingStore.storePendingIndexes(
|
|
648
|
+
[{ extendedSecret: secretConstrained, lowestIndex: 1, highestIndex: 3 }],
|
|
649
|
+
txHashE,
|
|
650
|
+
jobId,
|
|
651
|
+
);
|
|
652
|
+
await senderTaggingStore.storePendingIndexes(
|
|
653
|
+
[{ extendedSecret: secretConstrained, lowestIndex: 4, highestIndex: 7 }],
|
|
654
|
+
txHashF,
|
|
655
|
+
jobId,
|
|
656
|
+
);
|
|
657
|
+
|
|
658
|
+
await senderTaggingStore.finalizePendingIndexes([txHashA, txHashE], jobId);
|
|
570
659
|
|
|
571
660
|
await kvStore.transactionAsync(() => senderTaggingStore.commit(jobId));
|
|
572
661
|
},
|
|
@@ -617,7 +706,7 @@ function buildL2Block(): L2Block {
|
|
|
617
706
|
SlotNumber(181),
|
|
618
707
|
191n,
|
|
619
708
|
EthAddress.fromField(new Fr(193n)),
|
|
620
|
-
AztecAddress.
|
|
709
|
+
AztecAddress.fromBigIntUnsafe(197n),
|
|
621
710
|
new GasFees(199n, 211n),
|
|
622
711
|
),
|
|
623
712
|
new Fr(223n),
|
|
@@ -638,10 +727,10 @@ function buildL2Block(): L2Block {
|
|
|
638
727
|
3,
|
|
639
728
|
),
|
|
640
729
|
],
|
|
641
|
-
[new PublicLog(AztecAddress.
|
|
730
|
+
[new PublicLog(AztecAddress.fromBigIntUnsafe(281n), [new Fr(283n), new Fr(293n)])],
|
|
642
731
|
[
|
|
643
732
|
new ContractClassLog(
|
|
644
|
-
AztecAddress.
|
|
733
|
+
AztecAddress.fromBigIntUnsafe(307n),
|
|
645
734
|
new ContractClassLogFields(paddedFrs([311n, 313n, 317n], CONTRACT_CLASS_LOG_SIZE_IN_FIELDS)),
|
|
646
735
|
3,
|
|
647
736
|
),
|
|
@@ -2,6 +2,7 @@ import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
2
2
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
3
|
import type { Capsule } from '@aztec/stdlib/tx';
|
|
4
4
|
|
|
5
|
+
import { assertAllowedScope } from '../allowed_scopes.js';
|
|
5
6
|
import type { CapsuleStore } from './capsule_store.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -9,10 +10,15 @@ import type { CapsuleStore } from './capsule_store.js';
|
|
|
9
10
|
* allowed scopes list before delegating to the underlying store.
|
|
10
11
|
*/
|
|
11
12
|
export class CapsuleService {
|
|
13
|
+
private readonly allowedScopes: AztecAddress[];
|
|
14
|
+
|
|
12
15
|
constructor(
|
|
13
16
|
private readonly capsuleStore: CapsuleStore,
|
|
14
|
-
|
|
15
|
-
) {
|
|
17
|
+
allowedScopes: AztecAddress[],
|
|
18
|
+
) {
|
|
19
|
+
// The zero address denotes the global capsule scope, which is always permitted.
|
|
20
|
+
this.allowedScopes = [...allowedScopes, AztecAddress.ZERO];
|
|
21
|
+
}
|
|
16
22
|
|
|
17
23
|
setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], jobId: string, scope: AztecAddress) {
|
|
18
24
|
assertAllowedScope(scope, this.allowedScopes);
|
|
@@ -77,14 +83,3 @@ export class CapsuleService {
|
|
|
77
83
|
return this.capsuleStore.setCapsuleArray(contractAddress, baseSlot, content, jobId, scope);
|
|
78
84
|
}
|
|
79
85
|
}
|
|
80
|
-
|
|
81
|
-
function assertAllowedScope(scope: AztecAddress, allowedScopes: AztecAddress[]) {
|
|
82
|
-
if (scope.equals(AztecAddress.ZERO)) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if (!allowedScopes.some((allowed: AztecAddress) => allowed.equals(scope))) {
|
|
86
|
-
throw new Error(
|
|
87
|
-
`Scope ${scope.toString()} is not in the allowed scopes list: [${allowedScopes.map((s: AztecAddress) => s.toString()).join(', ')}]. See https://docs.aztec.network/errors/10`,
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
@@ -6,7 +6,6 @@ import type { MembershipWitness } from '@aztec/foundation/trees';
|
|
|
6
6
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
7
7
|
import {
|
|
8
8
|
type ContractArtifact,
|
|
9
|
-
type FunctionAbi,
|
|
10
9
|
type FunctionArtifactWithContractName,
|
|
11
10
|
FunctionCall,
|
|
12
11
|
type FunctionDebugMetadata,
|
|
@@ -23,8 +22,8 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
23
22
|
import {
|
|
24
23
|
type ContractClassIdPreimage,
|
|
25
24
|
type ContractClassWithId,
|
|
26
|
-
type
|
|
27
|
-
|
|
25
|
+
type ContractInstancePreimageWithAddress,
|
|
26
|
+
SerializableContractInstancePreimage,
|
|
28
27
|
getContractClassFromArtifact,
|
|
29
28
|
} from '@aztec/stdlib/contract';
|
|
30
29
|
|
|
@@ -112,9 +111,6 @@ export class ContractStore {
|
|
|
112
111
|
// TODO: Update it to be LRU cache so that it doesn't keep all the data all the time.
|
|
113
112
|
#contractArtifactCache: Map<string, ContractArtifact> = new Map();
|
|
114
113
|
|
|
115
|
-
/** Map from contract address to contract class id (avoids KV round-trip on hot path). */
|
|
116
|
-
#contractClassIdMap: Map<string, Fr> = new Map();
|
|
117
|
-
|
|
118
114
|
#store: AztecAsyncKVStore;
|
|
119
115
|
#contractArtifacts: AztecAsyncMap<string, Buffer>;
|
|
120
116
|
#contractClassData: AztecAsyncMap<string, Buffer>;
|
|
@@ -131,9 +127,10 @@ export class ContractStore {
|
|
|
131
127
|
|
|
132
128
|
/**
|
|
133
129
|
* Registers a new contract artifact and its corresponding class data.
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
130
|
+
*
|
|
131
|
+
* IMPORTANT: This method does not verify that the provided artifact matches the class data or that the class id
|
|
132
|
+
* matches the artifact. It is the caller's responsibility to ensure the consistency and correctness of the provided
|
|
133
|
+
* data. This is done to avoid redundant, expensive contract class computations.
|
|
137
134
|
*/
|
|
138
135
|
public async addContractArtifact(
|
|
139
136
|
contract: ContractArtifact,
|
|
@@ -168,31 +165,17 @@ export class ContractStore {
|
|
|
168
165
|
return contractClass.id;
|
|
169
166
|
}
|
|
170
167
|
|
|
171
|
-
async addContractInstance(contract:
|
|
168
|
+
async addContractInstance(contract: ContractInstancePreimageWithAddress): Promise<void> {
|
|
172
169
|
await this.#store.transactionAsync(async () => {
|
|
173
170
|
await this.#contractInstances.set(
|
|
174
171
|
contract.address.toString(),
|
|
175
|
-
new
|
|
172
|
+
new SerializableContractInstancePreimage(contract).toBuffer(),
|
|
176
173
|
);
|
|
177
174
|
});
|
|
178
|
-
|
|
179
|
-
this.#contractClassIdMap.set(contract.address.toString(), contract.currentContractClassId);
|
|
180
175
|
}
|
|
181
176
|
|
|
182
177
|
// Private getters
|
|
183
178
|
|
|
184
|
-
async #getContractClassId(contractAddress: AztecAddress): Promise<Fr | undefined> {
|
|
185
|
-
const key = contractAddress.toString();
|
|
186
|
-
if (!this.#contractClassIdMap.has(key)) {
|
|
187
|
-
const instance = await this.getContractInstance(contractAddress);
|
|
188
|
-
if (!instance) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
this.#contractClassIdMap.set(key, instance.currentContractClassId);
|
|
192
|
-
}
|
|
193
|
-
return this.#contractClassIdMap.get(key);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
179
|
async #getPrivateFunctionTreeForClassId(classId: Fr): Promise<PrivateFunctionsTree | undefined> {
|
|
197
180
|
if (!this.#privateFunctionTrees.has(classId.toString())) {
|
|
198
181
|
const artifact = await this.getContractArtifact(classId);
|
|
@@ -205,25 +188,20 @@ export class ContractStore {
|
|
|
205
188
|
return this.#privateFunctionTrees.get(classId.toString())!;
|
|
206
189
|
}
|
|
207
190
|
|
|
208
|
-
async #getArtifactByAddress(contractAddress: AztecAddress): Promise<ContractArtifact | undefined> {
|
|
209
|
-
const classId = await this.#getContractClassId(contractAddress);
|
|
210
|
-
return classId && this.getContractArtifact(classId);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
191
|
// Public getters
|
|
214
192
|
|
|
215
193
|
getContractsAddresses(): Promise<AztecAddress[]> {
|
|
216
194
|
return this.#store.transactionAsync(async () => {
|
|
217
195
|
const keys = await toArray(this.#contractInstances.keysAsync());
|
|
218
|
-
return keys.map(AztecAddress.
|
|
196
|
+
return keys.map(AztecAddress.fromStringUnsafe);
|
|
219
197
|
});
|
|
220
198
|
}
|
|
221
199
|
|
|
222
|
-
/** Returns
|
|
223
|
-
public getContractInstance(contractAddress: AztecAddress): Promise<
|
|
200
|
+
/** Returns the address preimage of a given address. */
|
|
201
|
+
public getContractInstance(contractAddress: AztecAddress): Promise<ContractInstancePreimageWithAddress | undefined> {
|
|
224
202
|
return this.#store.transactionAsync(async () => {
|
|
225
203
|
const contract = await this.#contractInstances.getAsync(contractAddress.toString());
|
|
226
|
-
return contract &&
|
|
204
|
+
return contract && SerializableContractInstancePreimage.fromBuffer(contract).withAddress(contractAddress);
|
|
227
205
|
});
|
|
228
206
|
}
|
|
229
207
|
|
|
@@ -262,82 +240,69 @@ export class ContractStore {
|
|
|
262
240
|
return { ...classData, packedBytecode };
|
|
263
241
|
}
|
|
264
242
|
|
|
265
|
-
public async getContract(
|
|
266
|
-
address: AztecAddress,
|
|
267
|
-
): Promise<(ContractInstanceWithAddress & ContractArtifact) | undefined> {
|
|
268
|
-
const instance = await this.getContractInstance(address);
|
|
269
|
-
if (!instance) {
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
const artifact = await this.getContractArtifact(instance.currentContractClassId);
|
|
273
|
-
if (!artifact) {
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
return { ...instance, ...artifact };
|
|
277
|
-
}
|
|
278
|
-
|
|
279
243
|
/**
|
|
280
|
-
* Retrieves the artifact of a specified function within a given contract.
|
|
244
|
+
* Retrieves the artifact of a specified function within a given contract class.
|
|
281
245
|
*
|
|
282
|
-
* @param
|
|
246
|
+
* @param contractClassId - The id of the contract class containing the function.
|
|
283
247
|
* @param selector - The function selector.
|
|
284
|
-
* @returns The corresponding function's artifact as an object.
|
|
248
|
+
* @returns The corresponding function's artifact as an object, or `undefined` if the class is not registered.
|
|
285
249
|
*/
|
|
286
250
|
public async getFunctionArtifact(
|
|
287
|
-
|
|
251
|
+
contractClassId: Fr,
|
|
288
252
|
selector: FunctionSelector,
|
|
289
253
|
): Promise<FunctionArtifactWithContractName | undefined> {
|
|
290
|
-
const artifact = await this
|
|
254
|
+
const artifact = await this.getContractArtifact(contractClassId);
|
|
291
255
|
if (!artifact) {
|
|
292
256
|
return undefined;
|
|
293
257
|
}
|
|
294
|
-
const fn = await findFunctionArtifactBySelector(artifact, selector)
|
|
295
|
-
|
|
258
|
+
const fn = assertSelectorInArtifact(artifact, await findFunctionArtifactBySelector(artifact, selector), {
|
|
259
|
+
contractClassId,
|
|
260
|
+
selector,
|
|
261
|
+
});
|
|
262
|
+
return { ...fn, contractName: artifact.name };
|
|
296
263
|
}
|
|
297
264
|
|
|
265
|
+
/**
|
|
266
|
+
* Same as {@link getFunctionArtifact} but with debug metadata attached. Returns `undefined` when the class artifact
|
|
267
|
+
* is not registered.
|
|
268
|
+
*/
|
|
298
269
|
public async getFunctionArtifactWithDebugMetadata(
|
|
299
|
-
|
|
270
|
+
contractClassId: Fr,
|
|
300
271
|
selector: FunctionSelector,
|
|
301
|
-
): Promise<FunctionArtifactWithContractName> {
|
|
302
|
-
const artifact = await this.
|
|
272
|
+
): Promise<FunctionArtifactWithContractName | undefined> {
|
|
273
|
+
const artifact = await this.getContractArtifact(contractClassId);
|
|
303
274
|
if (!artifact) {
|
|
304
|
-
|
|
275
|
+
return undefined;
|
|
305
276
|
}
|
|
306
|
-
const
|
|
277
|
+
const fn = assertSelectorInArtifact(artifact, await findFunctionArtifactBySelector(artifact, selector), {
|
|
278
|
+
contractClassId,
|
|
279
|
+
selector,
|
|
280
|
+
});
|
|
307
281
|
return {
|
|
308
|
-
...
|
|
309
|
-
|
|
282
|
+
...fn,
|
|
283
|
+
contractName: artifact.name,
|
|
284
|
+
debug: getFunctionDebugMetadata(artifact, fn),
|
|
310
285
|
};
|
|
311
286
|
}
|
|
312
287
|
|
|
313
|
-
public async getPublicFunctionArtifact(
|
|
314
|
-
|
|
315
|
-
): Promise<FunctionArtifactWithContractName | undefined> {
|
|
316
|
-
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
288
|
+
public async getPublicFunctionArtifact(contractClassId: Fr): Promise<FunctionArtifactWithContractName | undefined> {
|
|
289
|
+
const artifact = await this.getContractArtifact(contractClassId);
|
|
317
290
|
const fn = artifact && artifact.functions.find(f => f.functionType === FunctionType.PUBLIC);
|
|
318
291
|
return fn && { ...fn, contractName: artifact.name };
|
|
319
292
|
}
|
|
320
293
|
|
|
321
|
-
public async getFunctionAbi(
|
|
322
|
-
contractAddress: AztecAddress,
|
|
323
|
-
selector: FunctionSelector,
|
|
324
|
-
): Promise<FunctionAbi | undefined> {
|
|
325
|
-
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
326
|
-
return artifact && (await findFunctionAbiBySelector(artifact, selector));
|
|
327
|
-
}
|
|
328
|
-
|
|
329
294
|
/**
|
|
330
|
-
* Retrieves the debug metadata of a specified function within a given contract.
|
|
295
|
+
* Retrieves the debug metadata of a specified function within a given contract class.
|
|
331
296
|
*
|
|
332
|
-
* @param
|
|
297
|
+
* @param contractClassId - The id of the contract class containing the function.
|
|
333
298
|
* @param selector - The function selector.
|
|
334
299
|
* @returns The corresponding function's debug metadata, or undefined.
|
|
335
300
|
*/
|
|
336
301
|
public async getFunctionDebugMetadata(
|
|
337
|
-
|
|
302
|
+
contractClassId: Fr,
|
|
338
303
|
selector: FunctionSelector,
|
|
339
304
|
): Promise<FunctionDebugMetadata | undefined> {
|
|
340
|
-
const artifact = await this
|
|
305
|
+
const artifact = await this.getContractArtifact(contractClassId);
|
|
341
306
|
if (!artifact) {
|
|
342
307
|
return undefined;
|
|
343
308
|
}
|
|
@@ -345,10 +310,8 @@ export class ContractStore {
|
|
|
345
310
|
return fn && getFunctionDebugMetadata(artifact, fn);
|
|
346
311
|
}
|
|
347
312
|
|
|
348
|
-
public async getPublicFunctionDebugMetadata(
|
|
349
|
-
|
|
350
|
-
): Promise<FunctionDebugMetadata | undefined> {
|
|
351
|
-
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
313
|
+
public async getPublicFunctionDebugMetadata(contractClassId: Fr): Promise<FunctionDebugMetadata | undefined> {
|
|
314
|
+
const artifact = await this.getContractArtifact(contractClassId);
|
|
352
315
|
const fn = artifact && artifact.functions.find(f => f.functionType === FunctionType.PUBLIC);
|
|
353
316
|
return fn && getFunctionDebugMetadata(artifact, fn);
|
|
354
317
|
}
|
|
@@ -368,28 +331,34 @@ export class ContractStore {
|
|
|
368
331
|
return tree?.getFunctionMembershipWitness(selector);
|
|
369
332
|
}
|
|
370
333
|
|
|
371
|
-
public async getDebugContractName(
|
|
372
|
-
const artifact = await this
|
|
334
|
+
public async getDebugContractName(contractClassId: Fr) {
|
|
335
|
+
const artifact = await this.getContractArtifact(contractClassId);
|
|
373
336
|
return artifact?.name;
|
|
374
337
|
}
|
|
375
338
|
|
|
376
|
-
public async getDebugFunctionName(
|
|
377
|
-
const artifact = await this
|
|
339
|
+
public async getDebugFunctionName(contractClassId: Fr, selector: FunctionSelector) {
|
|
340
|
+
const artifact = await this.getContractArtifact(contractClassId);
|
|
378
341
|
const fn = artifact && (await findFunctionAbiBySelector(artifact, selector));
|
|
379
|
-
return `${artifact?.name ??
|
|
342
|
+
return `${artifact?.name ?? contractClassId}:${fn?.name ?? selector}`;
|
|
380
343
|
}
|
|
381
344
|
|
|
382
|
-
public async getFunctionCall(
|
|
383
|
-
|
|
384
|
-
|
|
345
|
+
public async getFunctionCall(
|
|
346
|
+
functionName: string,
|
|
347
|
+
args: any[],
|
|
348
|
+
to: AztecAddress,
|
|
349
|
+
contractClassId: Fr,
|
|
350
|
+
): Promise<FunctionCall> {
|
|
351
|
+
const artifact = await this.getContractArtifact(contractClassId);
|
|
352
|
+
if (!artifact) {
|
|
385
353
|
throw new Error(
|
|
386
|
-
`
|
|
354
|
+
`No artifact registered for contract class ${contractClassId} (contract ${to}): register it by calling ` +
|
|
355
|
+
`wallet.registerContract(...).\nSee docs for context: https://docs.aztec.network/errors/14`,
|
|
387
356
|
);
|
|
388
357
|
}
|
|
389
358
|
|
|
390
|
-
const functionDao =
|
|
359
|
+
const functionDao = artifact.functions.find(f => f.name === functionName);
|
|
391
360
|
if (!functionDao) {
|
|
392
|
-
throw new Error(`Unknown function ${functionName} in contract ${
|
|
361
|
+
throw new Error(`Unknown function ${functionName} in contract ${artifact.name}.`);
|
|
393
362
|
}
|
|
394
363
|
|
|
395
364
|
const selector = await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters);
|
|
@@ -406,3 +375,27 @@ export class ContractStore {
|
|
|
406
375
|
});
|
|
407
376
|
}
|
|
408
377
|
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Narrows the result of a selector lookup against a registered artifact. A missing class artifact is reported as
|
|
381
|
+
* `undefined` by the callers (an absence they can handle), but a selector that is absent from an artifact we *do* have
|
|
382
|
+
* is exceptional and throws rather than returning undefined. We cannot tell from here why the selector is missing: it
|
|
383
|
+
* may be that no such function exists in the contract (a wrong selector), or that the registered artifact does not
|
|
384
|
+
* correspond to the resolved class id (registration performs no validation, so a mismatched artifact is possible). The
|
|
385
|
+
* error names both possibilities.
|
|
386
|
+
*/
|
|
387
|
+
function assertSelectorInArtifact<T>(
|
|
388
|
+
artifact: ContractArtifact,
|
|
389
|
+
fn: T | undefined,
|
|
390
|
+
context: { contractClassId: Fr; selector: FunctionSelector },
|
|
391
|
+
): T {
|
|
392
|
+
if (!fn) {
|
|
393
|
+
throw new Error(
|
|
394
|
+
`Function with selector ${context.selector} not found in the registered artifact for contract class ` +
|
|
395
|
+
`${context.contractClassId} (${artifact.name}). Either no function with this selector exists in the ` +
|
|
396
|
+
`contract, or the registered artifact does not match the class id (re-register it via ` +
|
|
397
|
+
`wallet.registerContract(...)).`,
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
return fn;
|
|
401
|
+
}
|