@aztec/pxe 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5d02921e

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.
Files changed (210) hide show
  1. package/dest/access_scopes.d.ts +9 -0
  2. package/dest/access_scopes.d.ts.map +1 -0
  3. package/dest/access_scopes.js +6 -0
  4. package/dest/block_synchronizer/block_synchronizer.d.ts +1 -1
  5. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  6. package/dest/block_synchronizer/block_synchronizer.js +6 -0
  7. package/dest/config/index.d.ts +2 -2
  8. package/dest/config/index.d.ts.map +1 -1
  9. package/dest/config/index.js +1 -1
  10. package/dest/config/package_info.js +1 -1
  11. package/dest/contract_function_simulator/contract_function_simulator.d.ts +60 -30
  12. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/contract_function_simulator.js +199 -72
  14. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  15. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
  17. package/dest/contract_function_simulator/index.d.ts +2 -1
  18. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/index.js +1 -0
  20. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -5
  21. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +7 -9
  23. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
  24. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -3
  26. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -6
  27. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +5 -10
  29. package/dest/contract_function_simulator/oracle/interfaces.d.ts +50 -45
  30. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  32. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  33. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +38 -0
  34. package/dest/contract_function_simulator/oracle/oracle.d.ts +64 -44
  35. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/oracle/oracle.js +187 -97
  37. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  38. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +54 -80
  39. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  40. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +98 -85
  41. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +90 -52
  42. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  43. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +213 -116
  44. package/dest/contract_logging.d.ts +27 -0
  45. package/dest/contract_logging.d.ts.map +1 -0
  46. package/dest/contract_logging.js +38 -0
  47. package/dest/contract_sync/contract_sync_service.d.ts +10 -5
  48. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  49. package/dest/contract_sync/contract_sync_service.js +72 -30
  50. package/dest/contract_sync/helpers.d.ts +3 -2
  51. package/dest/contract_sync/helpers.d.ts.map +1 -1
  52. package/dest/contract_sync/helpers.js +9 -4
  53. package/dest/debug/pxe_debug_utils.d.ts +5 -4
  54. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  55. package/dest/debug/pxe_debug_utils.js +4 -4
  56. package/dest/entrypoints/client/bundle/index.d.ts +4 -1
  57. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  58. package/dest/entrypoints/client/bundle/index.js +3 -0
  59. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  60. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  61. package/dest/entrypoints/client/bundle/utils.js +9 -1
  62. package/dest/entrypoints/client/lazy/index.d.ts +4 -1
  63. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  64. package/dest/entrypoints/client/lazy/index.js +3 -0
  65. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  66. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  67. package/dest/entrypoints/client/lazy/utils.js +9 -1
  68. package/dest/entrypoints/server/index.d.ts +3 -1
  69. package/dest/entrypoints/server/index.d.ts.map +1 -1
  70. package/dest/entrypoints/server/index.js +2 -0
  71. package/dest/entrypoints/server/utils.js +9 -1
  72. package/dest/events/event_service.d.ts +3 -2
  73. package/dest/events/event_service.d.ts.map +1 -1
  74. package/dest/events/event_service.js +16 -4
  75. package/dest/logs/log_service.d.ts +6 -6
  76. package/dest/logs/log_service.d.ts.map +1 -1
  77. package/dest/logs/log_service.js +31 -40
  78. package/dest/messages/message_context_service.d.ts +17 -0
  79. package/dest/messages/message_context_service.d.ts.map +1 -0
  80. package/dest/messages/message_context_service.js +36 -0
  81. package/dest/notes/note_service.d.ts +5 -4
  82. package/dest/notes/note_service.d.ts.map +1 -1
  83. package/dest/notes/note_service.js +17 -7
  84. package/dest/notes_filter.d.ts +25 -0
  85. package/dest/notes_filter.d.ts.map +1 -0
  86. package/dest/notes_filter.js +4 -0
  87. package/dest/oracle_version.d.ts +2 -2
  88. package/dest/oracle_version.js +3 -3
  89. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  90. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  91. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  92. package/dest/private_kernel/hints/index.d.ts +1 -1
  93. package/dest/private_kernel/hints/index.js +1 -1
  94. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  95. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  96. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  97. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  98. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  99. package/dest/private_kernel/hints/test_utils.js +203 -0
  100. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  101. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  102. package/dest/private_kernel/private_kernel_execution_prover.js +19 -11
  103. package/dest/private_kernel/private_kernel_oracle.d.ts +6 -2
  104. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  105. package/dest/private_kernel/private_kernel_oracle.js +7 -3
  106. package/dest/pxe.d.ts +63 -24
  107. package/dest/pxe.d.ts.map +1 -1
  108. package/dest/pxe.js +105 -74
  109. package/dest/storage/capsule_store/capsule_service.d.ts +22 -0
  110. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  111. package/dest/storage/capsule_store/capsule_service.js +50 -0
  112. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  113. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  114. package/dest/storage/capsule_store/capsule_store.js +33 -28
  115. package/dest/storage/capsule_store/index.d.ts +2 -1
  116. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  117. package/dest/storage/capsule_store/index.js +1 -0
  118. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  119. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  120. package/dest/storage/contract_store/contract_store.js +140 -64
  121. package/dest/storage/metadata.d.ts +1 -1
  122. package/dest/storage/metadata.js +1 -1
  123. package/dest/storage/note_store/note_store.d.ts +3 -3
  124. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  125. package/dest/storage/note_store/note_store.js +3 -4
  126. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  127. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  128. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  129. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  130. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  131. package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
  132. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  133. package/dest/tagging/get_all_logs_by_tags.js +17 -3
  134. package/dest/tagging/index.d.ts +3 -3
  135. package/dest/tagging/index.d.ts.map +1 -1
  136. package/dest/tagging/index.js +1 -1
  137. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
  138. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  139. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
  140. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  141. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
  142. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  143. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  144. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
  145. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  146. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
  147. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  148. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  149. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  150. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
  151. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  152. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
  153. package/package.json +16 -16
  154. package/src/access_scopes.ts +9 -0
  155. package/src/block_synchronizer/block_synchronizer.ts +6 -0
  156. package/src/config/index.ts +1 -1
  157. package/src/config/package_info.ts +1 -1
  158. package/src/contract_function_simulator/contract_function_simulator.ts +358 -133
  159. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  160. package/src/contract_function_simulator/index.ts +1 -0
  161. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -8
  162. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
  163. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -9
  164. package/src/contract_function_simulator/oracle/interfaces.ts +63 -54
  165. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +98 -0
  166. package/src/contract_function_simulator/oracle/oracle.ts +223 -139
  167. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  168. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +122 -177
  169. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +375 -131
  170. package/src/contract_logging.ts +52 -0
  171. package/src/contract_sync/contract_sync_service.ts +108 -45
  172. package/src/contract_sync/helpers.ts +9 -3
  173. package/src/debug/pxe_debug_utils.ts +11 -9
  174. package/src/entrypoints/client/bundle/index.ts +3 -0
  175. package/src/entrypoints/client/bundle/utils.ts +9 -1
  176. package/src/entrypoints/client/lazy/index.ts +3 -0
  177. package/src/entrypoints/client/lazy/utils.ts +9 -1
  178. package/src/entrypoints/server/index.ts +2 -0
  179. package/src/entrypoints/server/utils.ts +7 -7
  180. package/src/events/event_service.ts +17 -4
  181. package/src/logs/log_service.ts +61 -63
  182. package/src/messages/message_context_service.ts +44 -0
  183. package/src/notes/note_service.ts +20 -8
  184. package/src/notes_filter.ts +26 -0
  185. package/src/oracle_version.ts +3 -3
  186. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  187. package/src/private_kernel/hints/index.ts +1 -1
  188. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  189. package/src/private_kernel/hints/test_utils.ts +325 -0
  190. package/src/private_kernel/private_kernel_execution_prover.ts +19 -12
  191. package/src/private_kernel/private_kernel_oracle.ts +7 -7
  192. package/src/pxe.ts +190 -117
  193. package/src/storage/capsule_store/capsule_service.ts +91 -0
  194. package/src/storage/capsule_store/capsule_store.ts +34 -26
  195. package/src/storage/capsule_store/index.ts +1 -0
  196. package/src/storage/contract_store/contract_store.ts +170 -71
  197. package/src/storage/metadata.ts +1 -1
  198. package/src/storage/note_store/note_store.ts +8 -5
  199. package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
  200. package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
  201. package/src/tagging/get_all_logs_by_tags.ts +28 -4
  202. package/src/tagging/index.ts +2 -2
  203. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +7 -10
  204. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  205. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
  206. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
  207. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  208. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
  209. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  210. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
@@ -0,0 +1,52 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { type LogLevel, type Logger, applyStringFormatting, createLogger } from '@aztec/foundation/log';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import type { DebugLog } from '@aztec/stdlib/logs';
5
+
6
+ /** Resolves a contract address to a human-readable name, if available. */
7
+ export type ContractNameResolver = (address: AztecAddress) => Promise<string | undefined>;
8
+ export type CONTRACT_LOG_KIND = 'aztecnr' | 'user';
9
+
10
+ /**
11
+ * Creates a logger whose output is prefixed with `contract:<name>(<addrAbbrev>)`.
12
+ */
13
+ export async function createContractLogger(
14
+ contractAddress: AztecAddress,
15
+ getContractName: ContractNameResolver,
16
+ kind: CONTRACT_LOG_KIND,
17
+ options?: { instanceId?: string },
18
+ ): Promise<Logger> {
19
+ const addrAbbrev = contractAddress.toString().slice(0, 10);
20
+ const name = await getContractName(contractAddress);
21
+
22
+ const prefix = kind == 'aztecnr' ? 'aztecnr' : 'contract';
23
+ const module = name ? `${prefix}:${name}(${addrAbbrev})` : `${prefix}:Unknown(${addrAbbrev})`;
24
+ return createLogger(module, options);
25
+ }
26
+
27
+ /**
28
+ * Formats and emits a single contract log message through the given logger.
29
+ */
30
+ export function logContractMessage(logger: Logger, level: LogLevel, message: string, fields: Fr[]): void {
31
+ logger[level](applyStringFormatting(message, fields));
32
+ }
33
+
34
+ /**
35
+ * Displays debug logs collected during public function simulation,
36
+ * using the `contract:` prefixed logger format.
37
+ */
38
+ export async function displayDebugLogs(debugLogs: DebugLog[], getContractName: ContractNameResolver): Promise<void> {
39
+ for (const log of debugLogs) {
40
+ const { kind, message } = stripAztecnrLogPrefix(log.message);
41
+ const logger = await createContractLogger(log.contractAddress, getContractName, kind);
42
+ logContractMessage(logger, log.level, message, log.fields);
43
+ }
44
+ }
45
+
46
+ export function stripAztecnrLogPrefix(message: string): { kind: CONTRACT_LOG_KIND; message: string } {
47
+ if (message.startsWith('[aztec-nr] ')) {
48
+ return { kind: 'aztecnr', message: message.slice('[aztec-nr] '.length) };
49
+ } else {
50
+ return { kind: 'user', message };
51
+ }
52
+ }
@@ -4,6 +4,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
5
5
  import type { BlockHeader } from '@aztec/stdlib/tx';
6
6
 
7
+ import type { AccessScopes } from '../access_scopes.js';
7
8
  import type { StagedStore } from '../job_coordinator/job_coordinator.js';
8
9
  import type { ContractStore } from '../storage/contract_store/contract_store.js';
9
10
  import type { NoteStore } from '../storage/note_store/note_store.js';
@@ -18,23 +19,25 @@ import { syncState, verifyCurrentClassId } from './helpers.js';
18
19
  export class ContractSyncService implements StagedStore {
19
20
  readonly storeName = 'contract_sync';
20
21
 
21
- // Tracks contracts synced since last wipe. Key is contract address string, value is a promise that resolves when
22
- // the contract is synced.
22
+ // Tracks contracts synced since last wipe. The cache is keyed per individual scope address
23
+ // (`contractAddress:scopeAddress`), or `contractAddress:*` for all scopes (all accounts).
24
+ // The value is a promise that resolves when the contract is synced.
23
25
  private syncedContracts: Map<string, Promise<void>> = new Map();
24
26
 
25
- // Per-job overridden contract addresses - these contracts should not be synced.
26
- private overriddenContracts: Map<string, Set<string>> = new Map();
27
+ // Per-job excluded contract addresses - these contracts should not be synced.
28
+ private excludedFromSync: Map<string, Set<string>> = new Map();
27
29
 
28
30
  constructor(
29
31
  private aztecNode: AztecNode,
30
32
  private contractStore: ContractStore,
31
33
  private noteStore: NoteStore,
34
+ private getRegisteredAccounts: () => Promise<AztecAddress[]>,
32
35
  private log: Logger,
33
36
  ) {}
34
37
 
35
38
  /** Sets contracts that should be skipped during sync for a specific job. */
36
- setOverriddenContracts(jobId: string, addresses: Set<string>): void {
37
- this.overriddenContracts.set(jobId, addresses);
39
+ setExcludedFromSync(jobId: string, addresses: Set<string>): void {
40
+ this.excludedFromSync.set(jobId, addresses);
38
41
  }
39
42
 
40
43
  /**
@@ -44,64 +47,74 @@ export class ContractSyncService implements StagedStore {
44
47
  * @param functionToInvokeAfterSync - The function selector that will be called after sync (used to validate it's
45
48
  * not sync_state itself).
46
49
  * @param utilityExecutor - Executor function for running the sync_state utility function.
50
+ * @param scopes - Access scopes to pass through to the utility executor (affects whose account's private state is discovered).
47
51
  */
48
52
  async ensureContractSynced(
49
53
  contractAddress: AztecAddress,
50
54
  functionToInvokeAfterSync: FunctionSelector | null,
51
- utilityExecutor: (call: FunctionCall) => Promise<any>,
55
+ utilityExecutor: (call: FunctionCall, scopes: AccessScopes) => Promise<any>,
52
56
  anchorBlockHeader: BlockHeader,
53
57
  jobId: string,
58
+ scopes: AccessScopes,
54
59
  ): Promise<void> {
55
- const key = contractAddress.toString();
56
-
57
- // Skip sync if this contract has an override for this job
58
- const overrides = this.overriddenContracts.get(jobId);
59
- if (overrides?.has(key)) {
60
+ if (this.#shouldSkipSync(jobId, contractAddress)) {
60
61
  return;
61
62
  }
62
63
 
63
- const existing = this.syncedContracts.get(key);
64
- if (existing) {
65
- return existing;
66
- }
67
-
68
- const syncPromise = this.#doSync(
69
- contractAddress,
70
- functionToInvokeAfterSync,
71
- utilityExecutor,
72
- anchorBlockHeader,
73
- jobId,
64
+ this.#startSyncIfNeeded(contractAddress, scopes, scopesToSync =>
65
+ this.#syncContract(
66
+ contractAddress,
67
+ functionToInvokeAfterSync,
68
+ utilityExecutor,
69
+ anchorBlockHeader,
70
+ jobId,
71
+ scopesToSync,
72
+ ),
74
73
  );
75
- this.syncedContracts.set(key, syncPromise);
76
74
 
77
- try {
78
- await syncPromise;
79
- } catch (err) {
80
- // There was an error syncing the contract, so we remove it from the cache so that it can be retried.
81
- this.syncedContracts.delete(key);
82
- throw err;
75
+ await this.#awaitSync(contractAddress, scopes);
76
+ }
77
+
78
+ /** Clears sync cache entries for the given scopes of a contract. Also clears the ALL_SCOPES entry. */
79
+ invalidateContractForScopes(contractAddress: AztecAddress, scopes: AztecAddress[]): void {
80
+ if (scopes.length === 0) {
81
+ return;
83
82
  }
83
+ scopes.forEach(scope => this.syncedContracts.delete(toKey(contractAddress, scope)));
84
+ this.syncedContracts.delete(toKey(contractAddress, 'ALL_SCOPES'));
84
85
  }
85
86
 
86
- async #doSync(
87
+ async #syncContract(
87
88
  contractAddress: AztecAddress,
88
89
  functionToInvokeAfterSync: FunctionSelector | null,
89
- utilityExecutor: (call: FunctionCall) => Promise<any>,
90
+ utilityExecutor: (call: FunctionCall, scopes: AccessScopes) => Promise<any>,
90
91
  anchorBlockHeader: BlockHeader,
91
92
  jobId: string,
93
+ scopes: AccessScopes,
92
94
  ): Promise<void> {
93
95
  this.log.debug(`Syncing contract ${contractAddress}`);
96
+
97
+ // Resolve ALL_SCOPES to actual registered accounts, since sync_state must be called once per account.
98
+ const scopeAddresses = scopes === 'ALL_SCOPES' ? await this.getRegisteredAccounts() : scopes;
99
+
94
100
  await Promise.all([
95
- syncState(
96
- contractAddress,
97
- this.contractStore,
98
- functionToInvokeAfterSync,
99
- utilityExecutor,
100
- this.noteStore,
101
- this.aztecNode,
102
- anchorBlockHeader,
103
- jobId,
104
- ),
101
+ // Call sync_state sequentially for each scope address — each invocation synchronizes one account's private
102
+ // state using scoped capsule arrays.
103
+ (async () => {
104
+ for (const scope of scopeAddresses) {
105
+ await syncState(
106
+ contractAddress,
107
+ this.contractStore,
108
+ functionToInvokeAfterSync,
109
+ utilityExecutor,
110
+ this.noteStore,
111
+ this.aztecNode,
112
+ anchorBlockHeader,
113
+ jobId,
114
+ scope,
115
+ );
116
+ }
117
+ })(),
105
118
  verifyCurrentClassId(contractAddress, this.aztecNode, this.contractStore, anchorBlockHeader),
106
119
  ]);
107
120
  this.log.debug(`Contract ${contractAddress} synced`);
@@ -114,8 +127,8 @@ export class ContractSyncService implements StagedStore {
114
127
  }
115
128
 
116
129
  commit(jobId: string): Promise<void> {
117
- // Clear overridden contracts for this job
118
- this.overriddenContracts.delete(jobId);
130
+ // Clear excluded contracts for this job
131
+ this.excludedFromSync.delete(jobId);
119
132
  return Promise.resolve();
120
133
  }
121
134
 
@@ -123,7 +136,57 @@ export class ContractSyncService implements StagedStore {
123
136
  // We clear the synced contracts cache here because, when the job is discarded, any associated database writes from
124
137
  // the sync are also undone.
125
138
  this.syncedContracts.clear();
126
- this.overriddenContracts.delete(jobId);
139
+ this.excludedFromSync.delete(jobId);
127
140
  return Promise.resolve();
128
141
  }
142
+ /** Returns true if sync should be skipped for this contract */
143
+ #shouldSkipSync(jobId: string, contractAddress: AztecAddress): boolean {
144
+ return !!this.excludedFromSync.get(jobId)?.has(contractAddress.toString());
145
+ }
146
+
147
+ /** If there are unsynced scopes, starts sync and stores the promise in cache with error cleanup. */
148
+ #startSyncIfNeeded(
149
+ contractAddress: AztecAddress,
150
+ scopes: AccessScopes,
151
+ syncFn: (scopesToSync: AccessScopes) => Promise<void>,
152
+ ): void {
153
+ const scopesToSync = this.#getScopesToSync(contractAddress, scopes);
154
+ const keys = toKeys(contractAddress, scopesToSync);
155
+ if (keys.length === 0) {
156
+ return;
157
+ }
158
+ const promise = syncFn(scopesToSync).catch(err => {
159
+ keys.forEach(key => this.syncedContracts.delete(key));
160
+ throw err;
161
+ });
162
+ keys.forEach(key => this.syncedContracts.set(key, promise));
163
+ }
164
+
165
+ /** Filters out scopes that are already cached, returning only those that still need syncing. */
166
+ #getScopesToSync(contractAddress: AztecAddress, scopes: AccessScopes): AccessScopes {
167
+ if (this.syncedContracts.has(toKey(contractAddress, 'ALL_SCOPES'))) {
168
+ // If we are already syncing all scopes, then return an empty list
169
+ return [];
170
+ }
171
+ if (scopes === 'ALL_SCOPES') {
172
+ return 'ALL_SCOPES';
173
+ }
174
+ return scopes.filter(scope => !this.syncedContracts.has(toKey(contractAddress, scope)));
175
+ }
176
+
177
+ /** Collects all relevant scope promises (including in-flight ones from concurrent calls) and awaits them. */
178
+ async #awaitSync(contractAddress: AztecAddress, scopes: AccessScopes): Promise<void> {
179
+ const promises = toKeys(contractAddress, scopes)
180
+ .map(key => this.syncedContracts.get(key))
181
+ .filter(p => p !== undefined);
182
+ await Promise.all(promises);
183
+ }
184
+ }
185
+
186
+ function toKeys(contract: AztecAddress, scopes: AccessScopes) {
187
+ return scopes === 'ALL_SCOPES' ? [toKey(contract, scopes)] : scopes.map(scope => toKey(contract, scope));
188
+ }
189
+
190
+ function toKey(contract: AztecAddress, scope: AztecAddress | 'ALL_SCOPES') {
191
+ return scope === 'ALL_SCOPES' ? `${contract.toString()}:*` : `${contract.toString()}:${scope.toString()}`;
129
192
  }
@@ -6,6 +6,7 @@ import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '
6
6
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
7
7
  import type { BlockHeader } from '@aztec/stdlib/tx';
8
8
 
9
+ import type { AccessScopes } from '../access_scopes.js';
9
10
  import { NoteService } from '../notes/note_service.js';
10
11
  import type { ContractStore } from '../storage/contract_store/contract_store.js';
11
12
  import type { NoteStore } from '../storage/note_store/note_store.js';
@@ -42,15 +43,16 @@ export async function syncState(
42
43
  contractAddress: AztecAddress,
43
44
  contractStore: ContractStore,
44
45
  functionToInvokeAfterSync: FunctionSelector | null,
45
- utilityExecutor: (privateSyncCall: FunctionCall) => Promise<any>,
46
+ utilityExecutor: (privateSyncCall: FunctionCall, scopes: AccessScopes) => Promise<any>,
46
47
  noteStore: NoteStore,
47
48
  aztecNode: AztecNode,
48
49
  anchorBlockHeader: BlockHeader,
49
50
  jobId: string,
51
+ scope: AztecAddress,
50
52
  ) {
51
53
  // Protocol contracts don't have private state to sync
52
54
  if (!isProtocolContract(contractAddress)) {
53
- const syncStateFunctionCall = await contractStore.getFunctionCall('sync_state', [], contractAddress);
55
+ const syncStateFunctionCall = await contractStore.getFunctionCall('sync_state', [scope], contractAddress);
54
56
  if (functionToInvokeAfterSync && functionToInvokeAfterSync.equals(syncStateFunctionCall.selector)) {
55
57
  throw new Error(
56
58
  'Forbidden `sync_state` invocation. `sync_state` can only be invoked by PXE, manual execution can lead to inconsistencies.',
@@ -58,10 +60,14 @@ export async function syncState(
58
60
  }
59
61
 
60
62
  const noteService = new NoteService(noteStore, aztecNode, anchorBlockHeader, jobId);
63
+ const scopes: AccessScopes = [scope];
61
64
 
62
65
  // Both sync_state and syncNoteNullifiers interact with the note store, but running them in parallel is safe
63
66
  // because note store is designed to handle concurrent operations.
64
- await Promise.all([utilityExecutor(syncStateFunctionCall), noteService.syncNoteNullifiers(contractAddress)]);
67
+ await Promise.all([
68
+ utilityExecutor(syncStateFunctionCall, scopes),
69
+ noteService.syncNoteNullifiers(contractAddress, scopes),
70
+ ]);
65
71
  }
66
72
  }
67
73
 
@@ -1,12 +1,13 @@
1
1
  import type { FunctionCall } from '@aztec/stdlib/abi';
2
2
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
3
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
- import type { NoteDao, NotesFilter } from '@aztec/stdlib/note';
3
+ import type { NoteDao } from '@aztec/stdlib/note';
5
4
  import type { ContractOverrides } from '@aztec/stdlib/tx';
6
5
 
6
+ import type { AccessScopes } from '../access_scopes.js';
7
7
  import type { BlockSynchronizer } from '../block_synchronizer/block_synchronizer.js';
8
8
  import type { ContractFunctionSimulator } from '../contract_function_simulator/contract_function_simulator.js';
9
9
  import type { ContractSyncService } from '../contract_sync/contract_sync_service.js';
10
+ import type { NotesFilter } from '../notes_filter.js';
10
11
  import type { AnchorBlockStore } from '../storage/index.js';
11
12
  import type { NoteStore } from '../storage/note_store/note_store.js';
12
13
 
@@ -17,11 +18,11 @@ import type { NoteStore } from '../storage/note_store/note_store.js';
17
18
  export class PXEDebugUtils {
18
19
  #putJobInQueue!: <T>(job: (jobId: string) => Promise<T>) => Promise<T>;
19
20
  #getSimulatorForTx!: (overrides?: { contracts?: ContractOverrides }) => ContractFunctionSimulator;
20
- #simulateUtility!: (
21
+ #executeUtility!: (
21
22
  contractFunctionSimulator: ContractFunctionSimulator,
22
23
  call: FunctionCall,
23
24
  authWitnesses: AuthWitness[] | undefined,
24
- scopes: AztecAddress[] | undefined,
25
+ scopes: AccessScopes,
25
26
  jobId: string,
26
27
  ) => Promise<any>;
27
28
 
@@ -36,17 +37,17 @@ export class PXEDebugUtils {
36
37
  public setPXEHelpers(
37
38
  putJobInQueue: <T>(job: (jobId: string) => Promise<T>) => Promise<T>,
38
39
  getSimulatorForTx: (overrides?: { contracts?: ContractOverrides }) => ContractFunctionSimulator,
39
- simulateUtility: (
40
+ executeUtility: (
40
41
  contractFunctionSimulator: ContractFunctionSimulator,
41
42
  call: FunctionCall,
42
43
  authWitnesses: AuthWitness[] | undefined,
43
- scopes: AztecAddress[] | undefined,
44
+ scopes: AccessScopes,
44
45
  jobId: string,
45
46
  ) => Promise<any>,
46
47
  ) {
47
48
  this.#putJobInQueue = putJobInQueue;
48
49
  this.#getSimulatorForTx = getSimulatorForTx;
49
- this.#simulateUtility = simulateUtility;
50
+ this.#executeUtility = executeUtility;
50
51
  }
51
52
 
52
53
  /**
@@ -71,10 +72,11 @@ export class PXEDebugUtils {
71
72
  await this.contractSyncService.ensureContractSynced(
72
73
  filter.contractAddress,
73
74
  null,
74
- async privateSyncCall =>
75
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
75
+ async (privateSyncCall, execScopes) =>
76
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
76
77
  anchorBlockHeader,
77
78
  jobId,
79
+ filter.scopes,
78
80
  );
79
81
 
80
82
  return this.noteStore.getNotes(filter, jobId);
@@ -1,6 +1,9 @@
1
+ export * from '../../../access_scopes.js';
2
+ export * from '../../../notes_filter.js';
1
3
  export * from '../../../pxe.js';
2
4
  export * from '../../../config/index.js';
3
5
  export * from '../../../error_enriching.js';
6
+ export * from '../../../contract_logging.js';
4
7
  export * from '../../../storage/index.js';
5
8
  export * from './utils.js';
6
9
  export type { PXECreationOptions } from '../../pxe_creation_options.js';
@@ -52,6 +52,14 @@ export async function createPXE(
52
52
  const protocolContractsProvider = new BundledProtocolContractsProvider();
53
53
 
54
54
  const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
55
- const pxe = await PXE.create(aztecNode, store, prover, simulator, protocolContractsProvider, config, pxeLogger);
55
+ const pxe = await PXE.create({
56
+ node: aztecNode,
57
+ store,
58
+ proofCreator: prover,
59
+ simulator,
60
+ protocolContractsProvider,
61
+ config,
62
+ loggerOrSuffix: pxeLogger,
63
+ });
56
64
  return pxe;
57
65
  }
@@ -1,6 +1,9 @@
1
+ export * from '../../../access_scopes.js';
2
+ export * from '../../../notes_filter.js';
1
3
  export * from '../../../pxe.js';
2
4
  export * from '../../../config/index.js';
3
5
  export * from '../../../storage/index.js';
4
6
  export * from '../../../error_enriching.js';
7
+ export * from '../../../contract_logging.js';
5
8
  export * from './utils.js';
6
9
  export { type PXECreationOptions } from '../../pxe_creation_options.js';
@@ -52,6 +52,14 @@ export async function createPXE(
52
52
  const protocolContractsProvider = new LazyProtocolContractsProvider();
53
53
 
54
54
  const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
55
- const pxe = await PXE.create(aztecNode, store, prover, simulator, protocolContractsProvider, config, pxeLogger);
55
+ const pxe = await PXE.create({
56
+ node: aztecNode,
57
+ store,
58
+ proofCreator: prover,
59
+ simulator,
60
+ protocolContractsProvider,
61
+ config,
62
+ loggerOrSuffix: pxeLogger,
63
+ });
56
64
  return pxe;
57
65
  }
@@ -1,3 +1,5 @@
1
+ export * from '../../access_scopes.js';
2
+ export * from '../../notes_filter.js';
1
3
  export * from '../../pxe.js';
2
4
  export * from '../../config/index.js';
3
5
  export * from '../../error_enriching.js';
@@ -58,14 +58,14 @@ export async function createPXE(
58
58
  const protocolContractsProvider = new BundledProtocolContractsProvider();
59
59
 
60
60
  const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
61
- const pxe = await PXE.create(
62
- aztecNode,
63
- options.store,
64
- prover,
61
+ const pxe = await PXE.create({
62
+ node: aztecNode,
63
+ store: options.store,
64
+ proofCreator: prover,
65
65
  simulator,
66
66
  protocolContractsProvider,
67
- configWithContracts,
68
- pxeLogger,
69
- );
67
+ config: configWithContracts,
68
+ loggerOrSuffix: pxeLogger,
69
+ });
70
70
  return pxe;
71
71
  }
@@ -1,4 +1,5 @@
1
1
  import type { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { createLogger } from '@aztec/foundation/log';
2
3
  import type { EventSelector } from '@aztec/stdlib/abi';
3
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
5
  import { siloNullifier } from '@aztec/stdlib/hash';
@@ -13,6 +14,7 @@ export class EventService {
13
14
  private readonly aztecNode: AztecNode,
14
15
  private readonly privateEventStore: PrivateEventStore,
15
16
  private readonly jobId: string,
17
+ private readonly log = createLogger('pxe:event_service'),
16
18
  ) {}
17
19
 
18
20
  public async validateAndStoreEvent(
@@ -36,19 +38,30 @@ export class EventService {
36
38
  const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
37
39
 
38
40
  if (!txEffect) {
39
- throw new Error(`Could not find tx effect for tx hash ${txHash}`);
41
+ // We error out instead of just logging a warning and skipping the event because this would indicate a bug. This
42
+ // is because the node has already served info about this tx either when obtaining the log (TxScopedL2Log contain
43
+ // tx info) or when getting metadata for the offchain message (before the message got passed to `process_log`).
44
+ throw new Error(`Could not find tx effect for tx hash ${txHash} when processing an event.`);
40
45
  }
41
46
 
42
47
  if (txEffect.l2BlockNumber > anchorBlockNumber) {
43
- throw new Error(`Could not find tx effect for tx hash ${txHash} as of block number ${anchorBlockNumber}`);
48
+ // We should never process a message from a tx past the anchor block. If we got here, a preprocessing step made
49
+ // a mistake.
50
+ throw new Error(
51
+ `Obtained a newer tx effect for ${txHash} for an event validation request than the anchor block ${anchorBlockNumber}. This is a bug as smart contracts should not issue event validation requests for events from blocks newer than the anchor block.`,
52
+ );
44
53
  }
45
54
 
46
55
  // Find the index of the event commitment in the nullifiers array to determine event ordering within the tx
47
56
  const eventIndexInTx = txEffect.data.nullifiers.findIndex(n => n.equals(siloedEventCommitment));
48
57
  if (eventIndexInTx === -1) {
49
- throw new Error(
50
- `Event commitment ${eventCommitment} (siloed as ${siloedEventCommitment}) is not present in tx ${txHash}`,
58
+ // Unlike in NoteService, this might not be a bug since the commitment hasn't been verified yet in the message
59
+ // processing pipeline. A malformed or malicious message could trigger this condition. Because of this we don't
60
+ // error out and we just show a warning.
61
+ this.log.warn(
62
+ `Skipping event whose commitment is not present in its tx. siloedEventCommitment=${siloedEventCommitment}, contract=${contractAddress}, selector=${selector}, eventCommitment=${eventCommitment}, txHash=${txHash}`,
51
63
  );
64
+ return;
52
65
  }
53
66
 
54
67
  return this.privateEventStore.storePrivateEventLog(