@aztec/pxe 0.0.1-commit.64b6bbb → 0.0.1-commit.69c59a8b3

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 (238) hide show
  1. package/dest/bin/check_oracle_version.js +4 -4
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +1 -1
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  4. package/dest/block_synchronizer/block_synchronizer.js +6 -0
  5. package/dest/config/index.d.ts +2 -2
  6. package/dest/config/index.d.ts.map +1 -1
  7. package/dest/config/index.js +8 -15
  8. package/dest/config/package_info.js +1 -1
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts +17 -7
  10. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  11. package/dest/contract_function_simulator/contract_function_simulator.js +145 -48
  12. package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
  13. package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
  14. package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
  15. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  16. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
  18. package/dest/contract_function_simulator/index.d.ts +2 -1
  19. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/index.js +1 -0
  21. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -6
  22. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +8 -10
  24. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
  25. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
  26. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
  27. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +2 -4
  29. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +4 -7
  30. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +6 -11
  32. package/dest/contract_function_simulator/oracle/interfaces.d.ts +61 -45
  33. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  35. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  36. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +47 -0
  37. package/dest/contract_function_simulator/oracle/oracle.d.ts +75 -44
  38. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  39. package/dest/contract_function_simulator/oracle/oracle.js +281 -96
  40. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  41. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +23 -48
  42. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  43. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +51 -73
  44. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +92 -56
  45. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  46. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +275 -106
  47. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  48. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  49. package/dest/contract_function_simulator/pick_notes.js +14 -3
  50. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
  51. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  52. package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
  53. package/dest/contract_logging.d.ts +27 -0
  54. package/dest/contract_logging.d.ts.map +1 -0
  55. package/dest/contract_logging.js +38 -0
  56. package/dest/contract_sync/contract_sync_service.d.ts +7 -4
  57. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  58. package/dest/contract_sync/contract_sync_service.js +69 -35
  59. package/dest/contract_sync/helpers.d.ts +2 -2
  60. package/dest/contract_sync/helpers.d.ts.map +1 -1
  61. package/dest/contract_sync/helpers.js +9 -4
  62. package/dest/debug/pxe_debug_utils.d.ts +4 -3
  63. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  64. package/dest/debug/pxe_debug_utils.js +4 -4
  65. package/dest/entrypoints/client/bundle/index.d.ts +3 -1
  66. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  67. package/dest/entrypoints/client/bundle/index.js +2 -0
  68. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  69. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  70. package/dest/entrypoints/client/bundle/utils.js +2 -2
  71. package/dest/entrypoints/client/lazy/index.d.ts +3 -1
  72. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  73. package/dest/entrypoints/client/lazy/index.js +2 -0
  74. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  75. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  76. package/dest/entrypoints/client/lazy/utils.js +2 -2
  77. package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
  78. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  79. package/dest/entrypoints/pxe_creation_options.js +3 -1
  80. package/dest/entrypoints/server/index.d.ts +3 -2
  81. package/dest/entrypoints/server/index.d.ts.map +1 -1
  82. package/dest/entrypoints/server/index.js +2 -1
  83. package/dest/entrypoints/server/utils.d.ts +2 -2
  84. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  85. package/dest/entrypoints/server/utils.js +2 -2
  86. package/dest/events/event_service.d.ts +3 -2
  87. package/dest/events/event_service.d.ts.map +1 -1
  88. package/dest/events/event_service.js +16 -4
  89. package/dest/events/private_event_filter_validator.d.ts +3 -2
  90. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  91. package/dest/events/private_event_filter_validator.js +15 -0
  92. package/dest/logs/log_service.d.ts +7 -7
  93. package/dest/logs/log_service.d.ts.map +1 -1
  94. package/dest/logs/log_service.js +33 -48
  95. package/dest/messages/message_context_service.d.ts +17 -0
  96. package/dest/messages/message_context_service.d.ts.map +1 -0
  97. package/dest/messages/message_context_service.js +36 -0
  98. package/dest/notes/note_service.d.ts +4 -4
  99. package/dest/notes/note_service.d.ts.map +1 -1
  100. package/dest/notes/note_service.js +17 -7
  101. package/dest/notes_filter.d.ts +24 -0
  102. package/dest/notes_filter.d.ts.map +1 -0
  103. package/dest/notes_filter.js +4 -0
  104. package/dest/oracle_version.d.ts +4 -3
  105. package/dest/oracle_version.d.ts.map +1 -1
  106. package/dest/oracle_version.js +20 -10
  107. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  108. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  109. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  110. package/dest/private_kernel/hints/index.d.ts +1 -1
  111. package/dest/private_kernel/hints/index.js +1 -1
  112. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  113. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  114. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  115. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  116. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  117. package/dest/private_kernel/hints/test_utils.js +203 -0
  118. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  119. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  120. package/dest/private_kernel/private_kernel_execution_prover.js +18 -13
  121. package/dest/private_kernel/private_kernel_oracle.d.ts +6 -2
  122. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  123. package/dest/private_kernel/private_kernel_oracle.js +7 -3
  124. package/dest/pxe.d.ts +23 -15
  125. package/dest/pxe.d.ts.map +1 -1
  126. package/dest/pxe.js +87 -54
  127. package/dest/storage/anchor_block_store/anchor_block_store.js +1 -1
  128. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  129. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  130. package/dest/storage/capsule_store/capsule_service.js +50 -0
  131. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  132. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  133. package/dest/storage/capsule_store/capsule_store.js +36 -28
  134. package/dest/storage/capsule_store/index.d.ts +2 -1
  135. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  136. package/dest/storage/capsule_store/index.js +1 -0
  137. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  138. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  139. package/dest/storage/contract_store/contract_store.js +143 -65
  140. package/dest/storage/metadata.d.ts +1 -1
  141. package/dest/storage/metadata.js +1 -1
  142. package/dest/storage/note_store/note_store.d.ts +3 -3
  143. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  144. package/dest/storage/note_store/note_store.js +3 -4
  145. package/dest/storage/private_event_store/stored_private_event.js +1 -1
  146. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  147. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  148. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  149. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  150. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  151. package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
  152. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  153. package/dest/tagging/get_all_logs_by_tags.js +17 -3
  154. package/dest/tagging/index.d.ts +3 -3
  155. package/dest/tagging/index.d.ts.map +1 -1
  156. package/dest/tagging/index.js +1 -1
  157. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
  158. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  159. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -21
  160. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  161. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
  162. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  163. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  164. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
  165. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  166. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
  167. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  168. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  169. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  170. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
  171. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  172. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
  173. package/package.json +16 -16
  174. package/src/bin/check_oracle_version.ts +4 -4
  175. package/src/block_synchronizer/block_synchronizer.ts +6 -0
  176. package/src/config/index.ts +3 -9
  177. package/src/config/package_info.ts +1 -1
  178. package/src/contract_function_simulator/contract_function_simulator.ts +261 -67
  179. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  180. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  181. package/src/contract_function_simulator/index.ts +1 -0
  182. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +9 -9
  183. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
  184. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
  185. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +4 -10
  186. package/src/contract_function_simulator/oracle/interfaces.ts +82 -54
  187. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
  188. package/src/contract_function_simulator/oracle/oracle.ts +363 -139
  189. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  190. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +58 -91
  191. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +455 -143
  192. package/src/contract_function_simulator/pick_notes.ts +14 -3
  193. package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
  194. package/src/contract_logging.ts +52 -0
  195. package/src/contract_sync/contract_sync_service.ts +102 -55
  196. package/src/contract_sync/helpers.ts +8 -3
  197. package/src/debug/pxe_debug_utils.ts +10 -8
  198. package/src/entrypoints/client/bundle/index.ts +2 -0
  199. package/src/entrypoints/client/bundle/utils.ts +2 -3
  200. package/src/entrypoints/client/lazy/index.ts +2 -0
  201. package/src/entrypoints/client/lazy/utils.ts +2 -3
  202. package/src/entrypoints/pxe_creation_options.ts +7 -0
  203. package/src/entrypoints/server/index.ts +2 -1
  204. package/src/entrypoints/server/utils.ts +2 -3
  205. package/src/events/event_service.ts +17 -4
  206. package/src/events/private_event_filter_validator.ts +21 -1
  207. package/src/logs/log_service.ts +63 -91
  208. package/src/messages/message_context_service.ts +44 -0
  209. package/src/notes/note_service.ts +19 -8
  210. package/src/notes_filter.ts +24 -0
  211. package/src/oracle_version.ts +20 -10
  212. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  213. package/src/private_kernel/hints/index.ts +1 -1
  214. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  215. package/src/private_kernel/hints/test_utils.ts +325 -0
  216. package/src/private_kernel/private_kernel_execution_prover.ts +18 -16
  217. package/src/private_kernel/private_kernel_oracle.ts +7 -7
  218. package/src/pxe.ts +129 -72
  219. package/src/storage/anchor_block_store/anchor_block_store.ts +1 -1
  220. package/src/storage/capsule_store/capsule_service.ts +90 -0
  221. package/src/storage/capsule_store/capsule_store.ts +44 -26
  222. package/src/storage/capsule_store/index.ts +1 -0
  223. package/src/storage/contract_store/contract_store.ts +177 -76
  224. package/src/storage/metadata.ts +1 -1
  225. package/src/storage/note_store/note_store.ts +5 -5
  226. package/src/storage/private_event_store/stored_private_event.ts +1 -1
  227. package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
  228. package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
  229. package/src/tagging/get_all_logs_by_tags.ts +28 -4
  230. package/src/tagging/index.ts +2 -2
  231. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +9 -24
  232. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  233. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
  234. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
  235. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  236. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
  237. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  238. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
package/src/pxe.ts CHANGED
@@ -18,6 +18,7 @@ import {
18
18
  } from '@aztec/stdlib/abi';
19
19
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
20
20
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
21
+ import type { L2TipsProvider } from '@aztec/stdlib/block';
21
22
  import {
22
23
  CompleteAddress,
23
24
  type ContractInstanceWithAddress,
@@ -47,7 +48,7 @@ import {
47
48
  TxProfileResult,
48
49
  TxProvingResult,
49
50
  TxSimulationResult,
50
- UtilitySimulationResult,
51
+ UtilityExecutionResult,
51
52
  } from '@aztec/stdlib/tx';
52
53
 
53
54
  import { inspect } from 'util';
@@ -60,12 +61,14 @@ import {
60
61
  generateSimulatedProvingResult,
61
62
  } from './contract_function_simulator/contract_function_simulator.js';
62
63
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
64
+ import { displayDebugLogs } from './contract_logging.js';
63
65
  import { ContractSyncService } from './contract_sync/contract_sync_service.js';
64
66
  import { readCurrentClassId } from './contract_sync/helpers.js';
65
67
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
66
68
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
67
69
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
68
70
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
71
+ import { MessageContextService } from './messages/message_context_service.js';
69
72
  import {
70
73
  PrivateKernelExecutionProver,
71
74
  type PrivateKernelExecutionProverConfig,
@@ -92,6 +95,8 @@ export type ProfileTxOpts = {
92
95
  profileMode: 'full' | 'execution-steps' | 'gates';
93
96
  /** If true, proof generation is skipped during profiling. Defaults to true. */
94
97
  skipProofGeneration?: boolean;
98
+ /** Addresses whose private state and keys are accessible during private execution. */
99
+ scopes: AztecAddress[];
95
100
  };
96
101
 
97
102
  /** Options for PXE.simulateTx. */
@@ -102,18 +107,20 @@ export type SimulateTxOpts = {
102
107
  skipTxValidation?: boolean;
103
108
  /** If false, fees are enforced. */
104
109
  skipFeeEnforcement?: boolean;
105
- /** State overrides for the simulation, such as contract instances and artifacts. */
110
+ /** If true, kernel logic is emulated in TS for simulation */
111
+ skipKernels?: boolean;
112
+ /** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
106
113
  overrides?: SimulationOverrides;
107
- /** The accounts whose notes we can access in this call. Defaults to all. */
108
- scopes?: AztecAddress[];
114
+ /** Addresses whose private state and keys are accessible during private execution */
115
+ scopes: AztecAddress[];
109
116
  };
110
117
 
111
- /** Options for PXE.simulateUtility. */
112
- export type SimulateUtilityOpts = {
118
+ /** Options for PXE.executeUtility. */
119
+ export type ExecuteUtilityOpts = {
113
120
  /** The authentication witnesses required for the function call. */
114
121
  authwits?: AuthWitness[];
115
- /** The accounts whose notes we can access in this call. Defaults to all. */
116
- scopes?: AztecAddress[];
122
+ /** The accounts whose notes we can access in this call */
123
+ scopes: AztecAddress[];
117
124
  };
118
125
 
119
126
  /** Args for PXE.create. */
@@ -141,6 +148,7 @@ export type PXECreateArgs = {
141
148
  export class PXE {
142
149
  private constructor(
143
150
  private node: AztecNode,
151
+ private db: AztecAsyncKVStore,
144
152
  private blockStateSynchronizer: BlockSynchronizer,
145
153
  private keyStore: KeyStore,
146
154
  private contractStore: ContractStore,
@@ -153,6 +161,8 @@ export class PXE {
153
161
  private addressStore: AddressStore,
154
162
  private privateEventStore: PrivateEventStore,
155
163
  private contractSyncService: ContractSyncService,
164
+ private messageContextService: MessageContextService,
165
+ private l2TipsStore: L2TipsProvider,
156
166
  private simulator: CircuitSimulator,
157
167
  private proverEnabled: boolean,
158
168
  private proofCreator: PrivateKernelProver,
@@ -188,7 +198,9 @@ export class PXE {
188
198
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
189
199
  : loggerOrSuffix;
190
200
 
191
- const proverEnabled = !!config.proverEnabled;
201
+ const info = await node.getNodeInfo();
202
+
203
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
192
204
  const addressStore = new AddressStore(store);
193
205
  const privateEventStore = new PrivateEventStore(store);
194
206
  const contractStore = new ContractStore(store);
@@ -206,6 +218,8 @@ export class PXE {
206
218
  noteStore,
207
219
  createLogger('pxe:contract_sync', bindings),
208
220
  );
221
+ const messageContextService = new MessageContextService(node);
222
+
209
223
  const synchronizer = new BlockSynchronizer(
210
224
  node,
211
225
  store,
@@ -234,6 +248,7 @@ export class PXE {
234
248
 
235
249
  const pxe = new PXE(
236
250
  node,
251
+ store,
237
252
  synchronizer,
238
253
  keyStore,
239
254
  contractStore,
@@ -246,6 +261,8 @@ export class PXE {
246
261
  addressStore,
247
262
  privateEventStore,
248
263
  contractSyncService,
264
+ messageContextService,
265
+ tipsStore,
249
266
  simulator,
250
267
  proverEnabled,
251
268
  proofCreator,
@@ -259,13 +276,12 @@ export class PXE {
259
276
  debugUtils.setPXEHelpers(
260
277
  pxe.#putInJobQueue.bind(pxe),
261
278
  pxe.#getSimulatorForTx.bind(pxe),
262
- pxe.#simulateUtility.bind(pxe),
279
+ pxe.#executeUtility.bind(pxe),
263
280
  );
264
281
 
265
282
  pxe.jobQueue.start();
266
283
 
267
284
  await pxe.#registerProtocolContracts();
268
- const info = await node.getNodeInfo();
269
285
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
270
286
  return pxe;
271
287
  }
@@ -281,6 +297,7 @@ export class PXE {
281
297
  keyStore: this.keyStore,
282
298
  addressStore: this.addressStore,
283
299
  aztecNode: BenchmarkedNodeFactory.create(this.node),
300
+ l2TipsStore: this.l2TipsStore,
284
301
  senderTaggingStore: this.senderTaggingStore,
285
302
  recipientTaggingStore: this.recipientTaggingStore,
286
303
  senderAddressBookStore: this.senderAddressBookStore,
@@ -288,6 +305,7 @@ export class PXE {
288
305
  privateEventStore: this.privateEventStore,
289
306
  simulator: this.simulator,
290
307
  contractSyncService: this.contractSyncService,
308
+ messageContextService: this.messageContextService,
291
309
  });
292
310
  }
293
311
 
@@ -340,9 +358,8 @@ export class PXE {
340
358
  async #registerProtocolContracts() {
341
359
  const registered: Record<string, string> = {};
342
360
  for (const name of protocolContractNames) {
343
- const { address, contractClass, instance, artifact } =
344
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
345
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
361
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
362
+ await this.contractStore.addContractArtifact(artifact);
346
363
  await this.contractStore.addContractInstance(instance);
347
364
  registered[name] = address.toString();
348
365
  }
@@ -354,7 +371,7 @@ export class PXE {
354
371
  async #executePrivate(
355
372
  contractFunctionSimulator: ContractFunctionSimulator,
356
373
  txRequest: TxExecutionRequest,
357
- scopes: AztecAddress[] | undefined,
374
+ scopes: AztecAddress[],
358
375
  jobId: string,
359
376
  ): Promise<PrivateExecutionResult> {
360
377
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -365,9 +382,11 @@ export class PXE {
365
382
  await this.contractSyncService.ensureContractSynced(
366
383
  contractAddress,
367
384
  functionSelector,
368
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
385
+ (privateSyncCall, execScopes) =>
386
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
369
387
  anchorBlockHeader,
370
388
  jobId,
389
+ scopes,
371
390
  );
372
391
 
373
392
  const result = await contractFunctionSimulator.run(txRequest, {
@@ -388,25 +407,32 @@ export class PXE {
388
407
  }
389
408
 
390
409
  /**
391
- * Simulate a utility function call on the given contract.
410
+ * Execute a utility function call on the given contract.
392
411
  * @param contractFunctionSimulator - The simulator to use for the function call.
393
412
  * @param call - The function call to execute.
394
413
  * @param authWitnesses - Authentication witnesses required for the function call.
395
414
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
396
415
  * accounts if not specified.
397
416
  * @param jobId - The job ID for staged writes.
398
- * @returns The simulation result containing the outputs of the utility function.
417
+ * @returns The execution result containing the outputs of the utility function.
399
418
  */
400
- async #simulateUtility(
419
+ async #executeUtility(
401
420
  contractFunctionSimulator: ContractFunctionSimulator,
402
421
  call: FunctionCall,
403
422
  authWitnesses: AuthWitness[] | undefined,
404
- scopes: AztecAddress[] | undefined,
423
+ scopes: AztecAddress[],
405
424
  jobId: string,
406
425
  ) {
407
426
  try {
408
427
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
409
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
428
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
429
+ call,
430
+ authWitnesses ?? [],
431
+ anchorBlockHeader,
432
+ scopes,
433
+ jobId,
434
+ );
435
+ return { result, offchainEffects };
410
436
  } catch (err) {
411
437
  if (err instanceof SimulationError) {
412
438
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -479,7 +505,9 @@ export class PXE {
479
505
  * @returns The synced block header
480
506
  */
481
507
  public getSyncedBlockHeader(): Promise<BlockHeader> {
482
- return this.anchorBlockStore.getBlockHeader();
508
+ return this.#putInJobQueue(() => {
509
+ return this.anchorBlockStore.getBlockHeader();
510
+ });
483
511
  }
484
512
 
485
513
  /**
@@ -536,6 +564,12 @@ export class PXE {
536
564
  * TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
537
565
  */
538
566
  public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
567
+ if (!(await sender.isValid())) {
568
+ throw new Error(
569
+ `Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
570
+ );
571
+ }
572
+
539
573
  const accounts = await this.keyStore.getAccounts();
540
574
  if (accounts.includes(sender)) {
541
575
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
@@ -546,6 +580,9 @@ export class PXE {
546
580
 
547
581
  if (wasAdded) {
548
582
  this.log.info(`Added sender:\n ${sender.toString()}`);
583
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
584
+ // all contracts must re-sync to discover them.
585
+ this.contractSyncService.wipe();
549
586
  } else {
550
587
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
551
588
  }
@@ -595,8 +632,7 @@ export class PXE {
595
632
  * @param artifact - The build artifact for the contract class.
596
633
  */
597
634
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
598
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
599
- await this.contractStore.addContractArtifact(contractClassId, artifact);
635
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
600
636
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
601
637
  }
602
638
 
@@ -615,17 +651,17 @@ export class PXE {
615
651
  if (artifact) {
616
652
  // If the user provides an artifact, validate it against the expected class id and register it
617
653
  const contractClass = await getContractClassFromArtifact(artifact);
618
- const contractClassId = contractClass.id;
619
- if (!contractClassId.equals(instance.currentContractClassId)) {
654
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
620
655
  throw new Error(
621
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
656
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
622
657
  );
623
658
  }
624
659
  const computedAddress = await computeContractAddressFromInstance(instance);
625
660
  if (!computedAddress.equals(instance.address)) {
626
661
  throw new Error('Added a contract in which the address does not match the contract instance.');
627
662
  }
628
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
663
+
664
+ await this.contractStore.addContractArtifact(artifact, contractClass);
629
665
 
630
666
  const publicFunctionSignatures = artifact.functions
631
667
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -674,15 +710,16 @@ export class PXE {
674
710
  throw new Error('Could not update contract to a class different from the current one.');
675
711
  }
676
712
 
677
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
678
-
679
713
  const publicFunctionSignatures = artifact.functions
680
714
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
681
715
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
682
716
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
683
717
 
684
718
  currentInstance.currentContractClassId = contractClass.id;
685
- await this.contractStore.addContractInstance(currentInstance);
719
+ await Promise.all([
720
+ this.contractStore.addContractArtifact(artifact, contractClass),
721
+ this.contractStore.addContractInstance(currentInstance),
722
+ ]);
686
723
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
687
724
  });
688
725
  }
@@ -700,11 +737,12 @@ export class PXE {
700
737
  * (where validators prove the public portion).
701
738
  *
702
739
  * @param txRequest - An authenticated tx request ready for proving
740
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
703
741
  * @returns A result containing the proof and public inputs of the tail circuit.
704
742
  * @throws If contract code not found, or public simulation reverts.
705
743
  * Also throws if simulatePublic is true and public simulation reverts.
706
744
  */
707
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
745
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
708
746
  let privateExecutionResult: PrivateExecutionResult;
709
747
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
710
748
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -715,7 +753,7 @@ export class PXE {
715
753
  await this.blockStateSynchronizer.sync();
716
754
  const syncTime = syncTimer.ms();
717
755
  const contractFunctionSimulator = this.#getSimulatorForTx();
718
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
756
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
719
757
 
720
758
  const {
721
759
  publicInputs,
@@ -757,17 +795,17 @@ export class PXE {
757
795
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
758
796
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
759
797
  // storing the tags here prevents linkage of txs sent from the same PXE.
760
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
761
- if (preTagsUsedInTheTx.length > 0) {
798
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
799
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
762
800
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
763
801
  const txHash = (await txProvingResult.toTx()).txHash;
764
802
 
765
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
766
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
767
- preTagsUsedInTheTx,
803
+ await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
804
+ this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
805
+ taggingIndexRangesUsedInTheTx,
768
806
  });
769
807
  } else {
770
- this.log.debug(`No pre-tags used in the tx`);
808
+ this.log.debug(`No tagging index ranges used in the tx`);
771
809
  }
772
810
 
773
811
  return txProvingResult;
@@ -785,7 +823,7 @@ export class PXE {
785
823
  */
786
824
  public profileTx(
787
825
  txRequest: TxExecutionRequest,
788
- { profileMode, skipProofGeneration = true }: ProfileTxOpts,
826
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
789
827
  ): Promise<TxProfileResult> {
790
828
  // We disable concurrent profiles for consistency with simulateTx.
791
829
  return this.#putInJobQueue(async jobId => {
@@ -808,12 +846,7 @@ export class PXE {
808
846
  const syncTime = syncTimer.ms();
809
847
 
810
848
  const contractFunctionSimulator = this.#getSimulatorForTx();
811
- const privateExecutionResult = await this.#executePrivate(
812
- contractFunctionSimulator,
813
- txRequest,
814
- undefined,
815
- jobId,
816
- );
849
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
817
850
 
818
851
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
819
852
  txRequest,
@@ -879,7 +912,14 @@ export class PXE {
879
912
  */
880
913
  public simulateTx(
881
914
  txRequest: TxExecutionRequest,
882
- { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
915
+ {
916
+ simulatePublic,
917
+ skipTxValidation = false,
918
+ skipFeeEnforcement = false,
919
+ skipKernels = true,
920
+ overrides,
921
+ scopes,
922
+ }: SimulateTxOpts,
883
923
  ): Promise<TxSimulationResult> {
884
924
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
885
925
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -903,17 +943,20 @@ export class PXE {
903
943
  await this.blockStateSynchronizer.sync();
904
944
  const syncTime = syncTimer.ms();
905
945
 
906
- const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
907
- // Temporary: in case there are overrides, we have to skip the kernels or validations
908
- // will fail. Consider handing control to the user/wallet on whether they want to run them
909
- // or not.
910
946
  const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
911
947
  const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
912
- const skipKernels = hasOverriddenContracts;
913
948
 
914
- // Set overridden contracts on the sync service so it knows to skip syncing them
949
+ if (hasOverriddenContracts && !skipKernels) {
950
+ throw new Error(
951
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
952
+ );
953
+ }
954
+ const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
955
+
915
956
  if (hasOverriddenContracts) {
916
- this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
957
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
958
+ // We exclude them so the sync service skips them entirely.
959
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
917
960
  }
918
961
 
919
962
  // Execution of private functions only; no proving, and no kernel logic.
@@ -926,6 +969,7 @@ export class PXE {
926
969
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
927
970
  privateExecutionResult,
928
971
  (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
972
+ this.node,
929
973
  ));
930
974
  } else {
931
975
  // Kernel logic, plus proving of all private functions and kernels.
@@ -944,6 +988,9 @@ export class PXE {
944
988
  const publicSimulationTimer = new Timer();
945
989
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
946
990
  publicSimulationTime = publicSimulationTimer.ms();
991
+ if (publicOutput?.debugLogs?.length) {
992
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
993
+ }
947
994
  }
948
995
 
949
996
  let validationTime: number | undefined;
@@ -952,7 +999,8 @@ export class PXE {
952
999
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
953
1000
  validationTime = validationTimer.ms();
954
1001
  if (validationResult.result === 'invalid') {
955
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
1002
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
1003
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
956
1004
  }
957
1005
  }
958
1006
 
@@ -1003,23 +1051,23 @@ export class PXE {
1003
1051
  inspect(txRequest),
1004
1052
  `simulatePublic=${simulatePublic}`,
1005
1053
  `skipTxValidation=${skipTxValidation}`,
1006
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1054
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1007
1055
  );
1008
1056
  }
1009
1057
  });
1010
1058
  }
1011
1059
 
1012
1060
  /**
1013
- * Simulates the execution of a contract utility function.
1061
+ * Executes a contract utility function.
1014
1062
  * @param call - The function call containing the function details, arguments, and target contract address.
1015
1063
  */
1016
- public simulateUtility(
1064
+ public executeUtility(
1017
1065
  call: FunctionCall,
1018
- { authwits, scopes }: SimulateUtilityOpts = {},
1019
- ): Promise<UtilitySimulationResult> {
1020
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1066
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
1067
+ ): Promise<UtilityExecutionResult> {
1068
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
1021
1069
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
1022
- // delete the same read value, or reading values that another simulation is currently modifying).
1070
+ // delete the same read value, or reading values that another execution is currently modifying).
1023
1071
  return this.#putInJobQueue(async jobId => {
1024
1072
  try {
1025
1073
  const totalTimer = new Timer();
@@ -1033,12 +1081,14 @@ export class PXE {
1033
1081
  await this.contractSyncService.ensureContractSynced(
1034
1082
  call.to,
1035
1083
  call.selector,
1036
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1084
+ (privateSyncCall, execScopes) =>
1085
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1037
1086
  anchorBlockHeader,
1038
1087
  jobId,
1088
+ scopes,
1039
1089
  );
1040
1090
 
1041
- const executionResult = await this.#simulateUtility(
1091
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
1042
1092
  contractFunctionSimulator,
1043
1093
  call,
1044
1094
  authwits ?? [],
@@ -1059,14 +1109,19 @@ export class PXE {
1059
1109
  };
1060
1110
 
1061
1111
  const simulationStats = contractFunctionSimulator.getStats();
1062
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1112
+ return {
1113
+ result: executionResult,
1114
+ offchainEffects,
1115
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1116
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1117
+ };
1063
1118
  } catch (err: any) {
1064
1119
  const { to, name, args } = call;
1065
1120
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1066
1121
  throw this.#contextualizeError(
1067
1122
  err,
1068
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1069
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1123
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1124
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1070
1125
  );
1071
1126
  }
1072
1127
  });
@@ -1102,10 +1157,11 @@ export class PXE {
1102
1157
  await this.contractSyncService.ensureContractSynced(
1103
1158
  filter.contractAddress,
1104
1159
  null,
1105
- async privateSyncCall =>
1106
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1160
+ async (privateSyncCall, execScopes) =>
1161
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1107
1162
  anchorBlockHeader,
1108
1163
  jobId,
1164
+ filter.scopes,
1109
1165
  );
1110
1166
  });
1111
1167
 
@@ -1120,9 +1176,10 @@ export class PXE {
1120
1176
  }
1121
1177
 
1122
1178
  /**
1123
- * Stops the PXE's job queue.
1179
+ * Stops the PXE's job queue and closes the backing store.
1124
1180
  */
1125
- public stop(): Promise<void> {
1126
- return this.jobQueue.end();
1181
+ public async stop(): Promise<void> {
1182
+ await this.jobQueue.end();
1183
+ await this.db.close();
1127
1184
  }
1128
1185
  }
@@ -23,7 +23,7 @@ export class AnchorBlockStore {
23
23
  }
24
24
 
25
25
  async getBlockHeader(): Promise<BlockHeader> {
26
- const headerBuffer = await this.#synchronizedHeader.getAsync();
26
+ const headerBuffer = await this.#store.transactionAsync(() => this.#synchronizedHeader.getAsync());
27
27
  if (!headerBuffer) {
28
28
  throw new Error(`Trying to get block header with a not-yet-synchronized PXE - this should never happen`);
29
29
  }
@@ -0,0 +1,90 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import type { Capsule } from '@aztec/stdlib/tx';
4
+
5
+ import type { CapsuleStore } from './capsule_store.js';
6
+
7
+ /**
8
+ * Wraps a CapsuleStore with scope-based access control. Each operation asserts that the requested scope is in the
9
+ * allowed scopes list before delegating to the underlying store.
10
+ */
11
+ export class CapsuleService {
12
+ constructor(
13
+ private readonly capsuleStore: CapsuleStore,
14
+ private readonly allowedScopes: AztecAddress[],
15
+ ) {}
16
+
17
+ setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], jobId: string, scope: AztecAddress) {
18
+ assertAllowedScope(scope, this.allowedScopes);
19
+ this.capsuleStore.setCapsule(contractAddress, slot, capsule, jobId, scope);
20
+ }
21
+
22
+ async getCapsule(
23
+ contractAddress: AztecAddress,
24
+ slot: Fr,
25
+ jobId: string,
26
+ scope: AztecAddress,
27
+ transientCapsules?: Capsule[],
28
+ ): Promise<Fr[] | null> {
29
+ assertAllowedScope(scope, this.allowedScopes);
30
+
31
+ // TODO(#12425): On the following line, the pertinent capsule gets overshadowed by the transient one. Tackle this.
32
+ const maybeTransientCapsule = transientCapsules?.find(
33
+ c =>
34
+ c.contractAddress.equals(contractAddress) &&
35
+ c.storageSlot.equals(slot) &&
36
+ (c.scope ?? AztecAddress.ZERO).equals(scope),
37
+ )?.data;
38
+
39
+ return maybeTransientCapsule ?? (await this.capsuleStore.getCapsule(contractAddress, slot, jobId, scope));
40
+ }
41
+
42
+ deleteCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress) {
43
+ assertAllowedScope(scope, this.allowedScopes);
44
+ this.capsuleStore.deleteCapsule(contractAddress, slot, jobId, scope);
45
+ }
46
+
47
+ copyCapsule(
48
+ contractAddress: AztecAddress,
49
+ srcSlot: Fr,
50
+ dstSlot: Fr,
51
+ numEntries: number,
52
+ jobId: string,
53
+ scope: AztecAddress,
54
+ ): Promise<void> {
55
+ assertAllowedScope(scope, this.allowedScopes);
56
+ return this.capsuleStore.copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, jobId, scope);
57
+ }
58
+
59
+ appendToCapsuleArray(
60
+ contractAddress: AztecAddress,
61
+ baseSlot: Fr,
62
+ content: Fr[][],
63
+ jobId: string,
64
+ scope: AztecAddress,
65
+ ): Promise<void> {
66
+ assertAllowedScope(scope, this.allowedScopes);
67
+ return this.capsuleStore.appendToCapsuleArray(contractAddress, baseSlot, content, jobId, scope);
68
+ }
69
+
70
+ readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, jobId: string, scope: AztecAddress): Promise<Fr[][]> {
71
+ assertAllowedScope(scope, this.allowedScopes);
72
+ return this.capsuleStore.readCapsuleArray(contractAddress, baseSlot, jobId, scope);
73
+ }
74
+
75
+ setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string, scope: AztecAddress) {
76
+ assertAllowedScope(scope, this.allowedScopes);
77
+ return this.capsuleStore.setCapsuleArray(contractAddress, baseSlot, content, jobId, scope);
78
+ }
79
+ }
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
+ }