@aztec/pxe 5.0.0-rc.2 → 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_synchronizer.d.ts +5 -3
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +7 -1
- 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 +9 -3
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +31 -14
- 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 +4 -2
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +2 -1
- package/dest/contract_function_simulator/noir-structs/fact.d.ts +5 -5
- package/dest/contract_function_simulator/noir-structs/fact.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/fact.js +2 -2
- package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts +3 -3
- package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/fact_collection.js +3 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +7 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- 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 +2 -2
- 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 -1
- package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts +8 -1
- package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.js +17 -0
- 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/oracle_registry.d.ts +10 -7
- package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle_registry.js +41 -10
- package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +48 -9
- package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +51 -30
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +10 -2
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +73 -32
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +20 -16
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +68 -47
- 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.js +2 -2
- package/dest/entrypoints/client/lazy/utils.js +2 -2
- package/dest/entrypoints/server/index.d.ts +5 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.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 +12 -10
- package/dest/hooks/execution_hooks.d.ts +15 -4
- package/dest/hooks/execution_hooks.d.ts.map +1 -1
- package/dest/hooks/index.d.ts +3 -2
- 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 +10 -1
- package/dest/hooks/resolve_tagging_secret_strategy.d.ts.map +1 -1
- package/dest/hooks/resolve_tagging_secret_strategy.js +3 -3
- package/dest/logs/log_service.d.ts +3 -2
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +33 -16
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +2 -2
- 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/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 +81 -46
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +135 -104
- 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 +31 -7
- 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 +63 -74
- package/dest/storage/fact_store/fact_service.d.ts +6 -4
- package/dest/storage/fact_store/fact_service.d.ts.map +1 -1
- package/dest/storage/fact_store/fact_service.js +19 -4
- package/dest/storage/fact_store/fact_store.d.ts +1 -1
- package/dest/storage/fact_store/fact_store.js +1 -1
- package/dest/storage/fact_store/index.d.ts +2 -1
- package/dest/storage/fact_store/index.d.ts.map +1 -1
- package/dest/storage/fact_store/index.js +1 -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/metadata.d.ts +2 -2
- package/dest/storage/metadata.d.ts.map +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts +17 -6
- package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/tagging_secret_sources_store.js +24 -11
- 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_synchronizer.ts +9 -1
- 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 +56 -14
- package/src/contract_function_simulator/execution_note_cache.ts +7 -28
- package/src/contract_function_simulator/index.ts +7 -1
- package/src/contract_function_simulator/noir-structs/fact.ts +4 -4
- package/src/contract_function_simulator/noir-structs/fact_collection.ts +9 -4
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +6 -0
- package/src/contract_function_simulator/noir-structs/pending_tagged_log.ts +12 -0
- package/src/contract_function_simulator/noir-structs/provided_secret.ts +1 -1
- package/src/contract_function_simulator/noir-structs/resolved_tagging_strategy.ts +21 -0
- 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/oracle_registry.ts +32 -7
- package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +49 -32
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +92 -41
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +104 -59
- package/src/debug/pxe_debug_utils.ts +1 -1
- package/src/entrypoints/client/bundle/utils.ts +2 -2
- package/src/entrypoints/client/lazy/utils.ts +2 -2
- package/src/entrypoints/server/index.ts +5 -1
- package/src/error_enriching.ts +26 -10
- package/src/hooks/execution_hooks.ts +14 -3
- package/src/hooks/index.ts +2 -0
- package/src/hooks/resolve_custom_request.ts +24 -0
- package/src/hooks/resolve_tagging_secret_strategy.ts +14 -0
- package/src/logs/log_service.ts +31 -11
- package/src/oracle_version.ts +2 -2
- package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +11 -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 +209 -143
- 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__/KeyStore.json +12 -12
- 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 +3 -3
- package/src/storage/backwards_compatibility_tests/__snapshots__/opened_stores.json +1 -1
- package/src/storage/backwards_compatibility_tests/schema_tests.ts +38 -4
- package/src/storage/contract_store/contract_store.ts +85 -92
- package/src/storage/fact_store/fact_service.ts +29 -5
- package/src/storage/fact_store/fact_store.ts +1 -1
- package/src/storage/fact_store/index.ts +10 -0
- package/src/storage/fact_store/origin_state.ts +75 -0
- package/src/storage/metadata.ts +1 -1
- package/src/storage/tagging_store/tagging_secret_sources_store.ts +36 -15
- 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 -28
- package/dest/contract_sync/helpers.d.ts.map +0 -1
- package/dest/contract_sync/helpers.js +0 -48
- package/src/contract_function_simulator/proxied_contract_data_source.ts +0 -60
- package/src/contract_sync/helpers.ts +0 -79
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { Point } from '@aztec/foundation/curves/grumpkin';
|
|
2
2
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
3
3
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
/**
|
|
5
|
+
* The kinds of shared secret an entry can hold.
|
|
6
|
+
*/
|
|
7
|
+
export type SharedSecretKind = 'arbitrary-secret' | 'handshake';
|
|
8
|
+
/** A shared secret registered for a recipient, with the kind that determines which tag streams it backs. */
|
|
9
|
+
export type SharedSecret = {
|
|
10
|
+
kind: SharedSecretKind;
|
|
11
|
+
secret: Point;
|
|
12
|
+
};
|
|
4
13
|
/**
|
|
5
14
|
* Stores the sources from which directional app tagging secrets are derived during recipient log synchronization.
|
|
6
15
|
*
|
|
@@ -11,7 +20,8 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
11
20
|
* - Pre-shared tagging secrets: shared secret points registered directly, bypassing ECDH. These are scoped to a
|
|
12
21
|
* specific recipient, since the derivation of the directional app tagging secret does not require any secret
|
|
13
22
|
* recipient data: given the original secret anyone can derive a recipient's app-siloed directional tagging secret,
|
|
14
|
-
* and so these must not be reused to preserve privacy.
|
|
23
|
+
* and so these must not be reused across recipients to preserve privacy. Each carries the {@link SharedSecretKind}
|
|
24
|
+
* it was registered through, which determines the tag streams it is scanned under.
|
|
15
25
|
*/
|
|
16
26
|
export declare class TaggingSecretSourcesStore {
|
|
17
27
|
#private;
|
|
@@ -23,18 +33,19 @@ export declare class TaggingSecretSourcesStore {
|
|
|
23
33
|
* Registers a pre-shared tagging secret scoped to a recipient.
|
|
24
34
|
* @returns true if the secret was newly added, false if it was already registered for that recipient.
|
|
25
35
|
*/
|
|
26
|
-
addSharedSecret(recipient: AztecAddress, secret: Point): Promise<boolean>;
|
|
36
|
+
addSharedSecret(recipient: AztecAddress, kind: SharedSecretKind, secret: Point): Promise<boolean>;
|
|
27
37
|
/** Returns the pre-shared tagging secrets registered for a given recipient. */
|
|
28
|
-
getSharedSecretsForRecipient(recipient: AztecAddress): Promise<
|
|
38
|
+
getSharedSecretsForRecipient(recipient: AztecAddress): Promise<SharedSecret[]>;
|
|
29
39
|
/** Returns every registered pre-shared tagging secret, each paired with the recipient it is scoped to. */
|
|
30
40
|
getAllSharedSecrets(): Promise<{
|
|
31
41
|
recipient: AztecAddress;
|
|
42
|
+
kind: SharedSecretKind;
|
|
32
43
|
secret: Point;
|
|
33
44
|
}[]>;
|
|
34
45
|
/**
|
|
35
|
-
* Removes a pre-shared tagging secret scoped to a recipient.
|
|
46
|
+
* Removes a pre-shared tagging secret scoped to a recipient. Both the secret and its kind must match.
|
|
36
47
|
* @returns true if the secret was registered and removed, false if it was not registered for that recipient.
|
|
37
48
|
*/
|
|
38
|
-
removeSharedSecret(recipient: AztecAddress, secret: Point): Promise<boolean>;
|
|
49
|
+
removeSharedSecret(recipient: AztecAddress, kind: SharedSecretKind, secret: Point): Promise<boolean>;
|
|
39
50
|
}
|
|
40
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
51
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFnZ2luZ19zZWNyZXRfc291cmNlc19zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2UvdGFnZ2luZ19zdG9yZS90YWdnaW5nX3NlY3JldF9zb3VyY2VzX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxLQUFLLEVBQUUsTUFBTSxtQ0FBbUMsQ0FBQztBQUUxRCxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBcUMsTUFBTSxpQkFBaUIsQ0FBQztBQUM1RixPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFFM0Q7O0dBRUc7QUFDSCxNQUFNLE1BQU0sZ0JBQWdCLEdBQUcsa0JBQWtCLEdBQUcsV0FBVyxDQUFDO0FBRWhFLDRHQUE0RztBQUM1RyxNQUFNLE1BQU0sWUFBWSxHQUFHO0lBQUUsSUFBSSxFQUFFLGdCQUFnQixDQUFDO0lBQUMsTUFBTSxFQUFFLEtBQUssQ0FBQTtDQUFFLENBQUM7QUFFckU7Ozs7Ozs7Ozs7OztHQVlHO0FBQ0gscUJBQWEseUJBQXlCOztJQUtwQyxZQUFZLEtBQUssRUFBRSxpQkFBaUIsRUFLbkM7SUFFRCxTQUFTLENBQUMsT0FBTyxFQUFFLFlBQVksR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBVWpEO0lBRUQsVUFBVSxJQUFJLE9BQU8sQ0FBQyxZQUFZLEVBQUUsQ0FBQyxDQUlwQztJQUVELFlBQVksQ0FBQyxPQUFPLEVBQUUsWUFBWSxHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FVcEQ7SUFFRDs7O09BR0c7SUFDSCxlQUFlLENBQUMsU0FBUyxFQUFFLFlBQVksRUFBRSxJQUFJLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxFQUFFLEtBQUssR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBbUJoRztJQUVELCtFQUErRTtJQUMvRSw0QkFBNEIsQ0FBQyxTQUFTLEVBQUUsWUFBWSxHQUFHLE9BQU8sQ0FBQyxZQUFZLEVBQUUsQ0FBQyxDQU03RTtJQUVELDBHQUEwRztJQUMxRyxtQkFBbUIsSUFBSSxPQUFPLENBQUM7UUFBRSxTQUFTLEVBQUUsWUFBWSxDQUFDO1FBQUMsSUFBSSxFQUFFLGdCQUFnQixDQUFDO1FBQUMsTUFBTSxFQUFFLEtBQUssQ0FBQTtLQUFFLEVBQUUsQ0FBQyxDQVFuRztJQUVEOzs7T0FHRztJQUNILGtCQUFrQixDQUFDLFNBQVMsRUFBRSxZQUFZLEVBQUUsSUFBSSxFQUFFLGdCQUFnQixFQUFFLE1BQU0sRUFBRSxLQUFLLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQVluRztDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tagging_secret_sources_store.d.ts","sourceRoot":"","sources":["../../../src/storage/tagging_store/tagging_secret_sources_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAE1D,OAAO,KAAK,EAAE,iBAAiB,EAAqC,MAAM,iBAAiB,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D
|
|
1
|
+
{"version":3,"file":"tagging_secret_sources_store.d.ts","sourceRoot":"","sources":["../../../src/storage/tagging_store/tagging_secret_sources_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAE1D,OAAO,KAAK,EAAE,iBAAiB,EAAqC,MAAM,iBAAiB,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,GAAG,WAAW,CAAC;AAEhE,4GAA4G;AAC5G,MAAM,MAAM,YAAY,GAAG;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,KAAK,CAAA;CAAE,CAAC;AAErE;;;;;;;;;;;;GAYG;AACH,qBAAa,yBAAyB;;IAKpC,YAAY,KAAK,EAAE,iBAAiB,EAKnC;IAED,SAAS,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAUjD;IAED,UAAU,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC,CAIpC;IAED,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAUpD;IAED;;;OAGG;IACH,eAAe,CAAC,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAmBhG;IAED,+EAA+E;IAC/E,4BAA4B,CAAC,SAAS,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAM7E;IAED,0GAA0G;IAC1G,mBAAmB,IAAI,OAAO,CAAC;QAAE,SAAS,EAAE,YAAY,CAAC;QAAC,IAAI,EAAE,gBAAgB,CAAC;QAAC,MAAM,EAAE,KAAK,CAAA;KAAE,EAAE,CAAC,CAQnG;IAED;;;OAGG;IACH,kBAAkB,CAAC,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAYnG;CACF"}
|
|
@@ -11,7 +11,8 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
11
11
|
* - Pre-shared tagging secrets: shared secret points registered directly, bypassing ECDH. These are scoped to a
|
|
12
12
|
* specific recipient, since the derivation of the directional app tagging secret does not require any secret
|
|
13
13
|
* recipient data: given the original secret anyone can derive a recipient's app-siloed directional tagging secret,
|
|
14
|
-
* and so these must not be reused to preserve privacy.
|
|
14
|
+
* and so these must not be reused across recipients to preserve privacy. Each carries the {@link SharedSecretKind}
|
|
15
|
+
* it was registered through, which determines the tag streams it is scanned under.
|
|
15
16
|
*/ export class TaggingSecretSourcesStore {
|
|
16
17
|
#store;
|
|
17
18
|
#senders;
|
|
@@ -47,42 +48,48 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
47
48
|
/**
|
|
48
49
|
* Registers a pre-shared tagging secret scoped to a recipient.
|
|
49
50
|
* @returns true if the secret was newly added, false if it was already registered for that recipient.
|
|
50
|
-
*/ addSharedSecret(recipient, secret) {
|
|
51
|
+
*/ addSharedSecret(recipient, kind, secret) {
|
|
51
52
|
return this.#store.transactionAsync(async ()=>{
|
|
52
53
|
const secretStr = secret.toString();
|
|
53
54
|
// MultiMap.set silently ignores an identical (key, value), so we scan to report whether this is a new secret.
|
|
54
55
|
for await (const existing of this.#sharedSecretsByRecipient.getValuesAsync(recipient.toString())){
|
|
55
|
-
if (existing === secretStr) {
|
|
56
|
+
if (existing.secret === secretStr) {
|
|
57
|
+
if (existing.kind !== kind) {
|
|
58
|
+
throw new Error(`Secret already registered for recipient with kind '${existing.kind}', cannot re-register it as '${kind}'.`);
|
|
59
|
+
}
|
|
56
60
|
return false;
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
|
-
await this.#sharedSecretsByRecipient.set(recipient.toString(),
|
|
63
|
+
await this.#sharedSecretsByRecipient.set(recipient.toString(), {
|
|
64
|
+
kind,
|
|
65
|
+
secret: secretStr
|
|
66
|
+
});
|
|
60
67
|
return true;
|
|
61
68
|
});
|
|
62
69
|
}
|
|
63
70
|
/** Returns the pre-shared tagging secrets registered for a given recipient. */ getSharedSecretsForRecipient(recipient) {
|
|
64
71
|
return this.#store.transactionAsync(async ()=>{
|
|
65
|
-
return (await toArray(this.#sharedSecretsByRecipient.getValuesAsync(recipient.toString()))).map(
|
|
72
|
+
return (await toArray(this.#sharedSecretsByRecipient.getValuesAsync(recipient.toString()))).map(deserializeSharedSecret);
|
|
66
73
|
});
|
|
67
74
|
}
|
|
68
75
|
/** Returns every registered pre-shared tagging secret, each paired with the recipient it is scoped to. */ getAllSharedSecrets() {
|
|
69
76
|
return this.#store.transactionAsync(async ()=>{
|
|
70
77
|
const entries = await toArray(this.#sharedSecretsByRecipient.entriesAsync());
|
|
71
|
-
return entries.map(([recipient,
|
|
78
|
+
return entries.map(([recipient, entry])=>({
|
|
72
79
|
recipient: AztecAddress.fromStringUnsafe(recipient),
|
|
73
|
-
|
|
80
|
+
...deserializeSharedSecret(entry)
|
|
74
81
|
}));
|
|
75
82
|
});
|
|
76
83
|
}
|
|
77
84
|
/**
|
|
78
|
-
* Removes a pre-shared tagging secret scoped to a recipient.
|
|
85
|
+
* Removes a pre-shared tagging secret scoped to a recipient. Both the secret and its kind must match.
|
|
79
86
|
* @returns true if the secret was registered and removed, false if it was not registered for that recipient.
|
|
80
|
-
*/ removeSharedSecret(recipient, secret) {
|
|
87
|
+
*/ removeSharedSecret(recipient, kind, secret) {
|
|
81
88
|
return this.#store.transactionAsync(async ()=>{
|
|
82
89
|
const secretStr = secret.toString();
|
|
83
90
|
for await (const existing of this.#sharedSecretsByRecipient.getValuesAsync(recipient.toString())){
|
|
84
|
-
if (existing === secretStr) {
|
|
85
|
-
await this.#sharedSecretsByRecipient.deleteValue(recipient.toString(),
|
|
91
|
+
if (existing.kind === kind && existing.secret === secretStr) {
|
|
92
|
+
await this.#sharedSecretsByRecipient.deleteValue(recipient.toString(), existing);
|
|
86
93
|
return true;
|
|
87
94
|
}
|
|
88
95
|
}
|
|
@@ -90,3 +97,9 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
90
97
|
});
|
|
91
98
|
}
|
|
92
99
|
}
|
|
100
|
+
function deserializeSharedSecret(entry) {
|
|
101
|
+
return {
|
|
102
|
+
kind: entry.kind,
|
|
103
|
+
secret: Point.fromString(entry.secret)
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN
|
|
2
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
1
|
+
export declare const UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN: number;
|
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RhbnRzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdGFnZ2luZy9jb25zdGFudHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBbUJBLGVBQU8sTUFBTSxzQ0FBc0MsUUFBK0IsQ0FBQyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/tagging/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/tagging/constants.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,sCAAsC,QAA+B,CAAC"}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// MAX_PRIVATE_LOGS_PER_TX indexes consumed in case the logs are squashed. This happens when the log contains a note
|
|
5
|
-
// and the note is nullified in the same tx.
|
|
1
|
+
import { MAX_PRIVATE_LOGS_PER_TX } from '@aztec/constants';
|
|
2
|
+
// This window bounds how far a sender's next tag index for a directional app tagging secret can run ahead of that
|
|
3
|
+
// secret's highest finalized index before `PXE::proveTx` throws.
|
|
6
4
|
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
5
|
+
// MAX_PRIVATE_LOGS_PER_TX is a floor for ordinary transaction patterns: the private kernel accumulates every
|
|
6
|
+
// surviving private log into a single tx-wide array of exactly this size, so a fresh secret's very first
|
|
7
|
+
// ordinary tx can consume that many indexes before anything is finalized.
|
|
8
|
+
//
|
|
9
|
+
// The +20 on top is headroom for multiple pending ordinary txs to the same counterparty stacking up
|
|
10
|
+
// before the first one is observed as mined. Only a run of near-MAX_PRIVATE_LOGS_PER_TX txs back-to-back would
|
|
11
|
+
// exhaust this; ordinary transfers use far fewer logs per tx, so the same margin covers many more of those. Keep the
|
|
12
|
+
// margin additive rather than another multiple of the floor. A larger window also makes recipient-side sync more
|
|
13
|
+
// expensive, since discovery has to probe ahead of the last finalized index for every active secret.
|
|
14
|
+
//
|
|
15
|
+
// TODO(F-783): MAX_PRIVATE_LOGS_PER_TX is not a hard ceiling in general — a tx that creates and nullifies (squashes)
|
|
16
|
+
// many notes/logs to the same secret can drive that secret's raw tag index arbitrarily higher, since indexes are
|
|
17
|
+
// reserved at log emission time, before squashing is decided, and the kernel's reset/squash loop is not bounded by
|
|
18
|
+
// MAX_PRIVATE_LOGS_PER_TX. No fixed window value closes that gap.
|
|
19
|
+
export const UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN = MAX_PRIVATE_LOGS_PER_TX + 20;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/pxe",
|
|
3
|
-
"version": "5.0.0
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"typedocOptions": {
|
|
6
6
|
"entryPoints": [
|
|
@@ -71,20 +71,20 @@
|
|
|
71
71
|
]
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@aztec/bb-prover": "5.0.0
|
|
75
|
-
"@aztec/bb.js": "5.0.0
|
|
76
|
-
"@aztec/builder": "5.0.0
|
|
77
|
-
"@aztec/constants": "5.0.0
|
|
78
|
-
"@aztec/ethereum": "5.0.0
|
|
79
|
-
"@aztec/foundation": "5.0.0
|
|
80
|
-
"@aztec/key-store": "5.0.0
|
|
81
|
-
"@aztec/kv-store": "5.0.0
|
|
82
|
-
"@aztec/noir-protocol-circuits-types": "5.0.0
|
|
83
|
-
"@aztec/noir-types": "5.0.0
|
|
84
|
-
"@aztec/protocol-contracts": "5.0.0
|
|
85
|
-
"@aztec/simulator": "5.0.0
|
|
86
|
-
"@aztec/standard-contracts": "5.0.0
|
|
87
|
-
"@aztec/stdlib": "5.0.0
|
|
74
|
+
"@aztec/bb-prover": "5.0.0",
|
|
75
|
+
"@aztec/bb.js": "5.0.0",
|
|
76
|
+
"@aztec/builder": "5.0.0",
|
|
77
|
+
"@aztec/constants": "5.0.0",
|
|
78
|
+
"@aztec/ethereum": "5.0.0",
|
|
79
|
+
"@aztec/foundation": "5.0.0",
|
|
80
|
+
"@aztec/key-store": "5.0.0",
|
|
81
|
+
"@aztec/kv-store": "5.0.0",
|
|
82
|
+
"@aztec/noir-protocol-circuits-types": "5.0.0",
|
|
83
|
+
"@aztec/noir-types": "5.0.0",
|
|
84
|
+
"@aztec/protocol-contracts": "5.0.0",
|
|
85
|
+
"@aztec/simulator": "5.0.0",
|
|
86
|
+
"@aztec/standard-contracts": "5.0.0",
|
|
87
|
+
"@aztec/stdlib": "5.0.0",
|
|
88
88
|
"koa": "^2.16.1",
|
|
89
89
|
"koa-router": "^13.1.1",
|
|
90
90
|
"lodash.omit": "^4.5.0",
|
|
@@ -93,8 +93,8 @@
|
|
|
93
93
|
"viem": "npm:@aztec/viem@2.38.2"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
|
-
"@aztec/noir-test-contracts.js": "5.0.0
|
|
97
|
-
"@aztec/world-state": "5.0.0
|
|
96
|
+
"@aztec/noir-test-contracts.js": "5.0.0",
|
|
97
|
+
"@aztec/world-state": "5.0.0",
|
|
98
98
|
"@jest/globals": "^30.0.0",
|
|
99
99
|
"@types/jest": "^30.0.0",
|
|
100
100
|
"@types/lodash.omit": "^4.5.7",
|
|
@@ -8,7 +8,8 @@ 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';
|
|
13
14
|
import type { FactStore } from '../storage/fact_store/fact_store.js';
|
|
14
15
|
import type { NoteStore } from '../storage/note_store/index.js';
|
|
@@ -35,6 +36,7 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
35
36
|
private readonly factStore: FactStore,
|
|
36
37
|
private readonly l2TipsStore: L2TipsKVStore,
|
|
37
38
|
private readonly contractSyncService: ContractSyncService,
|
|
39
|
+
private readonly contractClassService: ContractClassService,
|
|
38
40
|
private readonly config: Partial<BlockSynchronizerConfig> = {},
|
|
39
41
|
bindings?: LoggerBindings,
|
|
40
42
|
) {
|
|
@@ -177,6 +179,12 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
177
179
|
// Therefore, we clear the contract synchronization cache here such that the sync is re-triggered upon new
|
|
178
180
|
// execution.
|
|
179
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
|
+
|
|
180
188
|
this.log.verbose(`Updated pxe last block to ${blockHeader.getBlockNumber()}`, blockHeader.toInspect());
|
|
181
189
|
await this.anchorBlockStore.setHeader(blockHeader);
|
|
182
190
|
}
|
|
@@ -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
|
+
}
|