@aztec/pxe 4.0.0-devnet.2-patch.4 → 4.0.0-devnet.3-patch.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.
Files changed (168) hide show
  1. package/dest/config/package_info.js +1 -1
  2. package/dest/contract_function_simulator/contract_function_simulator.d.ts +10 -5
  3. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  4. package/dest/contract_function_simulator/contract_function_simulator.js +35 -12
  5. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  6. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  7. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
  8. package/dest/contract_function_simulator/index.d.ts +2 -1
  9. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  10. package/dest/contract_function_simulator/index.js +1 -0
  11. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -5
  12. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +7 -9
  14. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
  15. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -3
  17. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -6
  18. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +5 -10
  20. package/dest/contract_function_simulator/oracle/interfaces.d.ts +50 -45
  21. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  23. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  24. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +38 -0
  25. package/dest/contract_function_simulator/oracle/oracle.d.ts +64 -44
  26. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  27. package/dest/contract_function_simulator/oracle/oracle.js +187 -97
  28. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  29. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +23 -49
  30. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +50 -81
  32. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +66 -47
  33. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +190 -99
  35. package/dest/contract_logging.d.ts +27 -0
  36. package/dest/contract_logging.d.ts.map +1 -0
  37. package/dest/contract_logging.js +38 -0
  38. package/dest/contract_sync/contract_sync_service.d.ts +6 -5
  39. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  40. package/dest/contract_sync/contract_sync_service.js +44 -37
  41. package/dest/contract_sync/helpers.d.ts +2 -3
  42. package/dest/contract_sync/helpers.d.ts.map +1 -1
  43. package/dest/contract_sync/helpers.js +7 -2
  44. package/dest/debug/pxe_debug_utils.d.ts +3 -3
  45. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  46. package/dest/debug/pxe_debug_utils.js +4 -4
  47. package/dest/entrypoints/client/bundle/index.d.ts +2 -2
  48. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  49. package/dest/entrypoints/client/bundle/index.js +1 -1
  50. package/dest/entrypoints/client/lazy/index.d.ts +2 -2
  51. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  52. package/dest/entrypoints/client/lazy/index.js +1 -1
  53. package/dest/entrypoints/server/index.d.ts +1 -2
  54. package/dest/entrypoints/server/index.d.ts.map +1 -1
  55. package/dest/entrypoints/server/index.js +0 -1
  56. package/dest/events/event_service.d.ts +3 -2
  57. package/dest/events/event_service.d.ts.map +1 -1
  58. package/dest/events/event_service.js +16 -4
  59. package/dest/logs/log_service.d.ts +6 -7
  60. package/dest/logs/log_service.d.ts.map +1 -1
  61. package/dest/logs/log_service.js +34 -32
  62. package/dest/messages/message_context_service.d.ts +17 -0
  63. package/dest/messages/message_context_service.d.ts.map +1 -0
  64. package/dest/messages/message_context_service.js +36 -0
  65. package/dest/notes/note_service.d.ts +4 -5
  66. package/dest/notes/note_service.d.ts.map +1 -1
  67. package/dest/notes/note_service.js +14 -5
  68. package/dest/notes_filter.d.ts +2 -3
  69. package/dest/notes_filter.d.ts.map +1 -1
  70. package/dest/oracle_version.d.ts +2 -2
  71. package/dest/oracle_version.js +3 -3
  72. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  73. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  74. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +125 -64
  75. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  76. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  77. package/dest/private_kernel/hints/test_utils.js +203 -0
  78. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  79. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  80. package/dest/private_kernel/private_kernel_execution_prover.js +13 -5
  81. package/dest/pxe.d.ts +14 -12
  82. package/dest/pxe.d.ts.map +1 -1
  83. package/dest/pxe.js +56 -35
  84. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  85. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  86. package/dest/storage/capsule_store/capsule_service.js +50 -0
  87. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  88. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  89. package/dest/storage/capsule_store/capsule_store.js +33 -28
  90. package/dest/storage/capsule_store/index.d.ts +2 -1
  91. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  92. package/dest/storage/capsule_store/index.js +1 -0
  93. package/dest/storage/metadata.d.ts +1 -1
  94. package/dest/storage/metadata.js +1 -1
  95. package/dest/storage/note_store/note_store.d.ts +1 -1
  96. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  97. package/dest/storage/note_store/note_store.js +2 -2
  98. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  99. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  100. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  101. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  102. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  103. package/dest/tagging/index.d.ts +3 -3
  104. package/dest/tagging/index.d.ts.map +1 -1
  105. package/dest/tagging/index.js +1 -1
  106. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
  107. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  108. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +3 -3
  109. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
  110. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  111. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  112. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
  113. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  114. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
  115. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  116. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  117. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  118. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
  119. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  120. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
  121. package/package.json +16 -16
  122. package/src/config/package_info.ts +1 -1
  123. package/src/contract_function_simulator/contract_function_simulator.ts +55 -24
  124. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  125. package/src/contract_function_simulator/index.ts +1 -0
  126. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -8
  127. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
  128. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -9
  129. package/src/contract_function_simulator/oracle/interfaces.ts +63 -54
  130. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +98 -0
  131. package/src/contract_function_simulator/oracle/oracle.ts +223 -139
  132. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  133. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +58 -103
  134. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +320 -123
  135. package/src/contract_logging.ts +52 -0
  136. package/src/contract_sync/contract_sync_service.ts +77 -59
  137. package/src/contract_sync/helpers.ts +4 -4
  138. package/src/debug/pxe_debug_utils.ts +7 -7
  139. package/src/entrypoints/client/bundle/index.ts +1 -1
  140. package/src/entrypoints/client/lazy/index.ts +1 -1
  141. package/src/entrypoints/server/index.ts +0 -1
  142. package/src/events/event_service.ts +17 -4
  143. package/src/logs/log_service.ts +72 -52
  144. package/src/messages/message_context_service.ts +44 -0
  145. package/src/notes/note_service.ts +18 -8
  146. package/src/notes_filter.ts +1 -3
  147. package/src/oracle_version.ts +3 -3
  148. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +157 -110
  149. package/src/private_kernel/hints/test_utils.ts +325 -0
  150. package/src/private_kernel/private_kernel_execution_prover.ts +13 -6
  151. package/src/pxe.ts +84 -45
  152. package/src/storage/capsule_store/capsule_service.ts +90 -0
  153. package/src/storage/capsule_store/capsule_store.ts +34 -26
  154. package/src/storage/capsule_store/index.ts +1 -0
  155. package/src/storage/metadata.ts +1 -1
  156. package/src/storage/note_store/note_store.ts +2 -5
  157. package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
  158. package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
  159. package/src/tagging/index.ts +2 -2
  160. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +3 -6
  161. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
  162. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
  163. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  164. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
  165. package/dest/access_scopes.d.ts +0 -9
  166. package/dest/access_scopes.d.ts.map +0 -1
  167. package/dest/access_scopes.js +0 -6
  168. package/src/access_scopes.ts +0 -9
package/dest/pxe.js CHANGED
@@ -13,12 +13,14 @@ import { BlockSynchronizer } from './block_synchronizer/index.js';
13
13
  import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
14
14
  import { ContractFunctionSimulator, generateSimulatedProvingResult } from './contract_function_simulator/contract_function_simulator.js';
15
15
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
16
+ import { displayDebugLogs } from './contract_logging.js';
16
17
  import { ContractSyncService } from './contract_sync/contract_sync_service.js';
17
18
  import { readCurrentClassId } from './contract_sync/helpers.js';
18
19
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
19
20
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
20
21
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
21
22
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
23
+ import { MessageContextService } from './messages/message_context_service.js';
22
24
  import { PrivateKernelExecutionProver } from './private_kernel/private_kernel_execution_prover.js';
23
25
  import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
24
26
  import { AddressStore } from './storage/address_store/address_store.js';
@@ -47,6 +49,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
47
49
  addressStore;
48
50
  privateEventStore;
49
51
  contractSyncService;
52
+ messageContextService;
50
53
  simulator;
51
54
  proverEnabled;
52
55
  proofCreator;
@@ -55,7 +58,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
55
58
  jobQueue;
56
59
  jobCoordinator;
57
60
  debug;
58
- constructor(node, blockStateSynchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, contractSyncService, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debug){
61
+ constructor(node, blockStateSynchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, contractSyncService, messageContextService, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debug){
59
62
  this.node = node;
60
63
  this.blockStateSynchronizer = blockStateSynchronizer;
61
64
  this.keyStore = keyStore;
@@ -69,6 +72,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
69
72
  this.addressStore = addressStore;
70
73
  this.privateEventStore = privateEventStore;
71
74
  this.contractSyncService = contractSyncService;
75
+ this.messageContextService = messageContextService;
72
76
  this.simulator = simulator;
73
77
  this.proverEnabled = proverEnabled;
74
78
  this.proofCreator = proofCreator;
@@ -102,6 +106,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
102
106
  const keyStore = new KeyStore(store);
103
107
  const tipsStore = new L2TipsKVStore(store, 'pxe');
104
108
  const contractSyncService = new ContractSyncService(node, contractStore, noteStore, createLogger('pxe:contract_sync', bindings));
109
+ const messageContextService = new MessageContextService(node);
105
110
  const synchronizer = new BlockSynchronizer(node, store, anchorBlockStore, noteStore, privateEventStore, tipsStore, contractSyncService, config, bindings);
106
111
  const jobCoordinator = new JobCoordinator(store, bindings);
107
112
  jobCoordinator.registerStores([
@@ -114,8 +119,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
114
119
  ]);
115
120
  const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
116
121
  const jobQueue = new SerialQueue();
117
- const pxe = new PXE(node, synchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, contractSyncService, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debugUtils);
118
- debugUtils.setPXEHelpers(pxe.#putInJobQueue.bind(pxe), pxe.#getSimulatorForTx.bind(pxe), pxe.#simulateUtility.bind(pxe));
122
+ const pxe = new PXE(node, synchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, contractSyncService, messageContextService, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debugUtils);
123
+ debugUtils.setPXEHelpers(pxe.#putInJobQueue.bind(pxe), pxe.#getSimulatorForTx.bind(pxe), pxe.#executeUtility.bind(pxe));
119
124
  pxe.jobQueue.start();
120
125
  await pxe.#registerProtocolContracts();
121
126
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
@@ -136,7 +141,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
136
141
  capsuleStore: this.capsuleStore,
137
142
  privateEventStore: this.privateEventStore,
138
143
  simulator: this.simulator,
139
- contractSyncService: this.contractSyncService
144
+ contractSyncService: this.contractSyncService,
145
+ messageContextService: this.messageContextService
140
146
  });
141
147
  }
142
148
  #contextualizeError(err, ...context) {
@@ -193,7 +199,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
193
199
  const { origin: contractAddress, functionSelector } = txRequest;
194
200
  try {
195
201
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
196
- await this.contractSyncService.ensureContractSynced(contractAddress, functionSelector, (privateSyncCall, execScopes)=>this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, scopes);
202
+ await this.contractSyncService.ensureContractSynced(contractAddress, functionSelector, (privateSyncCall, execScopes)=>this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, scopes);
197
203
  const result = await contractFunctionSimulator.run(txRequest, {
198
204
  contractAddress,
199
205
  selector: functionSelector,
@@ -211,18 +217,22 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
211
217
  }
212
218
  }
213
219
  /**
214
- * Simulate a utility function call on the given contract.
220
+ * Execute a utility function call on the given contract.
215
221
  * @param contractFunctionSimulator - The simulator to use for the function call.
216
222
  * @param call - The function call to execute.
217
223
  * @param authWitnesses - Authentication witnesses required for the function call.
218
224
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
219
225
  * accounts if not specified.
220
226
  * @param jobId - The job ID for staged writes.
221
- * @returns The simulation result containing the outputs of the utility function.
222
- */ async #simulateUtility(contractFunctionSimulator, call, authWitnesses, scopes, jobId) {
227
+ * @returns The execution result containing the outputs of the utility function.
228
+ */ async #executeUtility(contractFunctionSimulator, call, authWitnesses, scopes, jobId) {
223
229
  try {
224
230
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
225
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
231
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
232
+ return {
233
+ result,
234
+ offchainEffects
235
+ };
226
236
  } catch (err) {
227
237
  if (err instanceof SimulationError) {
228
238
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -278,7 +288,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
278
288
  * Returns the block header up to which the PXE has synced.
279
289
  * @returns The synced block header
280
290
  */ getSyncedBlockHeader() {
281
- return this.anchorBlockStore.getBlockHeader();
291
+ return this.#putInJobQueue(()=>{
292
+ return this.anchorBlockStore.getBlockHeader();
293
+ });
282
294
  }
283
295
  /**
284
296
  * Returns the contract instance for a given address, if it's registered in the PXE.
@@ -334,6 +346,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
334
346
  const wasAdded = await this.senderAddressBookStore.addSender(sender);
335
347
  if (wasAdded) {
336
348
  this.log.info(`Added sender:\n ${sender.toString()}`);
349
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
350
+ // all contracts must re-sync to discover them.
351
+ this.contractSyncService.wipe();
337
352
  } else {
338
353
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
339
354
  }
@@ -497,16 +512,16 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
497
512
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
498
513
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
499
514
  // storing the tags here prevents linkage of txs sent from the same PXE.
500
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
501
- if (preTagsUsedInTheTx.length > 0) {
515
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
516
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
502
517
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
503
518
  const txHash = (await txProvingResult.toTx()).txHash;
504
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
505
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
506
- preTagsUsedInTheTx
519
+ await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
520
+ this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
521
+ taggingIndexRangesUsedInTheTx
507
522
  });
508
523
  } else {
509
- this.log.debug(`No pre-tags used in the tx`);
524
+ this.log.debug(`No tagging index ranges used in the tx`);
510
525
  }
511
526
  return txProvingResult;
512
527
  } catch (err) {
@@ -588,7 +603,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
588
603
  * Also throws if simulatePublic is true and public simulation reverts.
589
604
  *
590
605
  * TODO(#7456) Prevent msgSender being defined here for the first call
591
- */ simulateTx(txRequest, { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }) {
606
+ */ simulateTx(txRequest, { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, skipKernels = true, overrides, scopes }) {
592
607
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
593
608
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
594
609
  // delete the same read value, or reading values that another simulation is currently modifying).
@@ -607,16 +622,16 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
607
622
  const syncTimer = new Timer();
608
623
  await this.blockStateSynchronizer.sync();
609
624
  const syncTime = syncTimer.ms();
610
- const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
611
- // Temporary: in case there are overrides, we have to skip the kernels or validations
612
- // will fail. Consider handing control to the user/wallet on whether they want to run them
613
- // or not.
614
625
  const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
615
626
  const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
616
- const skipKernels = hasOverriddenContracts;
617
- // Set overridden contracts on the sync service so it knows to skip syncing them
627
+ if (hasOverriddenContracts && !skipKernels) {
628
+ throw new Error('Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.');
629
+ }
630
+ const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
618
631
  if (hasOverriddenContracts) {
619
- this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
632
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
633
+ // We exclude them so the sync service skips them entirely.
634
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
620
635
  }
621
636
  // Execution of private functions only; no proving, and no kernel logic.
622
637
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
@@ -640,6 +655,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
640
655
  const publicSimulationTimer = new Timer();
641
656
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
642
657
  publicSimulationTime = publicSimulationTimer.ms();
658
+ if (publicOutput?.debugLogs?.length) {
659
+ await displayDebugLogs(publicOutput.debugLogs, (addr)=>this.contractStore.getDebugContractName(addr));
660
+ }
643
661
  }
644
662
  let validationTime;
645
663
  if (!skipTxValidation) {
@@ -650,7 +668,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
650
668
  });
651
669
  validationTime = validationTimer.ms();
652
670
  if (validationResult.result === 'invalid') {
653
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
671
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
672
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
654
673
  }
655
674
  }
656
675
  const txHash = simulatedTx.getTxHash();
@@ -683,19 +702,19 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
683
702
  nodeRPCCalls: simulatorStats.nodeRPCCalls
684
703
  });
685
704
  } catch (err) {
686
- throw this.#contextualizeError(err, inspect(txRequest), `simulatePublic=${simulatePublic}`, `skipTxValidation=${skipTxValidation}`, `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map((s)=>s.toString()).join(', ')}`);
705
+ throw this.#contextualizeError(err, inspect(txRequest), `simulatePublic=${simulatePublic}`, `skipTxValidation=${skipTxValidation}`, `scopes=${scopes.map((s)=>s.toString()).join(', ')}`);
687
706
  }
688
707
  });
689
708
  }
690
709
  /**
691
- * Simulates the execution of a contract utility function.
710
+ * Executes a contract utility function.
692
711
  * @param call - The function call containing the function details, arguments, and target contract address.
693
- */ simulateUtility(call, { authwits, scopes } = {
694
- scopes: 'ALL_SCOPES'
712
+ */ executeUtility(call, { authwits, scopes } = {
713
+ scopes: []
695
714
  }) {
696
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
715
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
697
716
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
698
- // delete the same read value, or reading values that another simulation is currently modifying).
717
+ // delete the same read value, or reading values that another execution is currently modifying).
699
718
  return this.#putInJobQueue(async (jobId)=>{
700
719
  try {
701
720
  const totalTimer = new Timer();
@@ -705,8 +724,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
705
724
  const functionTimer = new Timer();
706
725
  const contractFunctionSimulator = this.#getSimulatorForTx();
707
726
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
708
- await this.contractSyncService.ensureContractSynced(call.to, call.selector, (privateSyncCall, execScopes)=>this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, scopes);
709
- const executionResult = await this.#simulateUtility(contractFunctionSimulator, call, authwits ?? [], scopes, jobId);
727
+ await this.contractSyncService.ensureContractSynced(call.to, call.selector, (privateSyncCall, execScopes)=>this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, scopes);
728
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(contractFunctionSimulator, call, authwits ?? [], scopes, jobId);
710
729
  const functionTime = functionTimer.ms();
711
730
  const totalTime = totalTimer.ms();
712
731
  const perFunction = [
@@ -724,6 +743,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
724
743
  const simulationStats = contractFunctionSimulator.getStats();
725
744
  return {
726
745
  result: executionResult,
746
+ offchainEffects,
747
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
727
748
  stats: {
728
749
  timings,
729
750
  nodeRPCCalls: simulationStats.nodeRPCCalls
@@ -732,7 +753,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
732
753
  } catch (err) {
733
754
  const { to, name, args } = call;
734
755
  const stringifiedArgs = args.map((arg)=>arg.toString()).join(', ');
735
- throw this.#contextualizeError(err, `simulateUtility ${to}:${name}(${stringifiedArgs})`, `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map((s)=>s.toString()).join(', ')}`);
756
+ throw this.#contextualizeError(err, `executeUtility ${to}:${name}(${stringifiedArgs})`, `scopes=${scopes.map((s)=>s.toString()).join(', ')}`);
736
757
  }
737
758
  });
738
759
  }
@@ -755,7 +776,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
755
776
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
756
777
  anchorBlockNumber = anchorBlockHeader.getBlockNumber();
757
778
  const contractFunctionSimulator = this.#getSimulatorForTx();
758
- await this.contractSyncService.ensureContractSynced(filter.contractAddress, null, async (privateSyncCall, execScopes)=>await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, filter.scopes);
779
+ await this.contractSyncService.ensureContractSynced(filter.contractAddress, null, async (privateSyncCall, execScopes)=>await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, filter.scopes);
759
780
  });
760
781
  // anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
761
782
  const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber).validate(filter);
@@ -0,0 +1,21 @@
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
+ import type { CapsuleStore } from './capsule_store.js';
5
+ /**
6
+ * Wraps a CapsuleStore with scope-based access control. Each operation asserts that the requested scope is in the
7
+ * allowed scopes list before delegating to the underlying store.
8
+ */
9
+ export declare class CapsuleService {
10
+ private readonly capsuleStore;
11
+ private readonly allowedScopes;
12
+ constructor(capsuleStore: CapsuleStore, allowedScopes: AztecAddress[]);
13
+ setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], jobId: string, scope: AztecAddress): void;
14
+ getCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress, transientCapsules?: Capsule[]): Promise<Fr[] | null>;
15
+ deleteCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress): void;
16
+ copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number, jobId: string, scope: AztecAddress): Promise<void>;
17
+ appendToCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string, scope: AztecAddress): Promise<void>;
18
+ readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, jobId: string, scope: AztecAddress): Promise<Fr[][]>;
19
+ setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string, scope: AztecAddress): Promise<void>;
20
+ }
21
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2Fwc3VsZV9zZXJ2aWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc3RvcmFnZS9jYXBzdWxlX3N0b3JlL2NhcHN1bGVfc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN6RCxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFDM0QsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFaEQsT0FBTyxLQUFLLEVBQUUsWUFBWSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFFdkQ7OztHQUdHO0FBQ0gscUJBQWEsY0FBYztJQUV2QixPQUFPLENBQUMsUUFBUSxDQUF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AiB,CAAC,EAAE,OAAO,EAAE,GAC5B,OAAO,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAYtB;IAED,aAAa,CAAC,eAAe,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,QAGxF;IAED,WAAW,CACT,eAAe,EAAE,YAAY,EAC7B,OAAO,EAAE,EAAE,EACX,OAAO,EAAE,EAAE,EACX,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,IAAI,CAAC,CAGf;IAED,oBAAoB,CAClB,eAAe,EAAE,YAAY,EAC7B,QAAQ,EAAE,EAAE,EACZ,OAAO,EAAE,EAAE,EAAE,EAAE,EACf,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,IAAI,CAAC,CAGf;IAED,gBAAgB,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAGjH;IAED,eAAe,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,iBAG/G;CACF"}
@@ -0,0 +1,50 @@
1
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
2
+ /**
3
+ * Wraps a CapsuleStore with scope-based access control. Each operation asserts that the requested scope is in the
4
+ * allowed scopes list before delegating to the underlying store.
5
+ */ export class CapsuleService {
6
+ capsuleStore;
7
+ allowedScopes;
8
+ constructor(capsuleStore, allowedScopes){
9
+ this.capsuleStore = capsuleStore;
10
+ this.allowedScopes = allowedScopes;
11
+ }
12
+ setCapsule(contractAddress, slot, capsule, jobId, scope) {
13
+ assertAllowedScope(scope, this.allowedScopes);
14
+ this.capsuleStore.setCapsule(contractAddress, slot, capsule, jobId, scope);
15
+ }
16
+ async getCapsule(contractAddress, slot, jobId, scope, transientCapsules) {
17
+ assertAllowedScope(scope, this.allowedScopes);
18
+ // TODO(#12425): On the following line, the pertinent capsule gets overshadowed by the transient one. Tackle this.
19
+ const maybeTransientCapsule = transientCapsules?.find((c)=>c.contractAddress.equals(contractAddress) && c.storageSlot.equals(slot) && (c.scope ?? AztecAddress.ZERO).equals(scope))?.data;
20
+ return maybeTransientCapsule ?? await this.capsuleStore.getCapsule(contractAddress, slot, jobId, scope);
21
+ }
22
+ deleteCapsule(contractAddress, slot, jobId, scope) {
23
+ assertAllowedScope(scope, this.allowedScopes);
24
+ this.capsuleStore.deleteCapsule(contractAddress, slot, jobId, scope);
25
+ }
26
+ copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, jobId, scope) {
27
+ assertAllowedScope(scope, this.allowedScopes);
28
+ return this.capsuleStore.copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, jobId, scope);
29
+ }
30
+ appendToCapsuleArray(contractAddress, baseSlot, content, jobId, scope) {
31
+ assertAllowedScope(scope, this.allowedScopes);
32
+ return this.capsuleStore.appendToCapsuleArray(contractAddress, baseSlot, content, jobId, scope);
33
+ }
34
+ readCapsuleArray(contractAddress, baseSlot, jobId, scope) {
35
+ assertAllowedScope(scope, this.allowedScopes);
36
+ return this.capsuleStore.readCapsuleArray(contractAddress, baseSlot, jobId, scope);
37
+ }
38
+ setCapsuleArray(contractAddress, baseSlot, content, jobId, scope) {
39
+ assertAllowedScope(scope, this.allowedScopes);
40
+ return this.capsuleStore.setCapsuleArray(contractAddress, baseSlot, content, jobId, scope);
41
+ }
42
+ }
43
+ function assertAllowedScope(scope, allowedScopes) {
44
+ if (scope.equals(AztecAddress.ZERO)) {
45
+ return;
46
+ }
47
+ if (!allowedScopes.some((allowed)=>allowed.equals(scope))) {
48
+ throw new Error(`Scope ${scope.toString()} is not in the allowed scopes list: [${allowedScopes.map((s)=>s.toString()).join(', ')}]. See https://docs.aztec.network/errors/10`);
49
+ }
50
+ }
@@ -1,7 +1,7 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { type Logger } from '@aztec/foundation/log';
3
3
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
4
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
5
  import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
6
6
  export declare class CapsuleStore implements StagedStore {
7
7
  #private;
@@ -31,20 +31,20 @@ export declare class CapsuleStore implements StagedStore {
31
31
  * to public contract storage in that it's indexed by the contract address and storage slot but instead of the global
32
32
  * network state it's backed by local PXE db.
33
33
  */
34
- storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], jobId: string): void;
34
+ setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], jobId: string, scope: AztecAddress): void;
35
35
  /**
36
36
  * Returns data previously stored via `storeCapsule` in the per-contract non-volatile database.
37
37
  * @param contractAddress - The contract address under which the data is scoped.
38
38
  * @param slot - The slot in the database to read.
39
39
  * @returns The stored data or `null` if no data is stored under the slot.
40
40
  */
41
- loadCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string): Promise<Fr[] | null>;
41
+ getCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress): Promise<Fr[] | null>;
42
42
  /**
43
43
  * Deletes data in the per-contract non-volatile database. Does nothing if no data was present.
44
44
  * @param contractAddress - The contract address under which the data is scoped.
45
45
  * @param slot - The slot in the database to delete.
46
46
  */
47
- deleteCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string): void;
47
+ deleteCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress): void;
48
48
  /**
49
49
  * Copies a number of contiguous entries in the per-contract non-volatile database. This allows for efficient data
50
50
  * structures by avoiding repeated calls to `loadCapsule` and `storeCapsule`.
@@ -56,7 +56,7 @@ export declare class CapsuleStore implements StagedStore {
56
56
  * @param dstSlot - The first slot to copy to.
57
57
  * @param numEntries - The number of entries to copy.
58
58
  */
59
- copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number, jobId: string): Promise<void>;
59
+ copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number, jobId: string, scope: AztecAddress): Promise<void>;
60
60
  /**
61
61
  * Appends multiple capsules to a capsule array stored at the base slot.
62
62
  * The array length is stored at the base slot, and elements are stored in consecutive slots after it.
@@ -65,8 +65,8 @@ export declare class CapsuleStore implements StagedStore {
65
65
  * @param baseSlot - The slot where the array length is stored
66
66
  * @param content - Array of capsule data to append
67
67
  */
68
- appendToCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string): Promise<void>;
69
- readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, jobId: string): Promise<Fr[][]>;
70
- setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string): Promise<void>;
68
+ appendToCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string, scope: AztecAddress): Promise<void>;
69
+ readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, jobId: string, scope: AztecAddress): Promise<Fr[][]>;
70
+ setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string, scope: AztecAddress): Promise<void>;
71
71
  }
72
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2Fwc3VsZV9zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2UvY2Fwc3VsZV9zdG9yZS9jYXBzdWxlX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FB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OAKG;IACG,UAAU,CAAC,eAAe,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAWlH;IAED;;;;OAIG;IACH,aAAa,CAAC,eAAe,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,QAGxF;IAED;;;;;;;;;;OAUG;IACH,WAAW,CACT,eAAe,EAAE,YAAY,EAC7B,OAAO,EAAE,EAAE,EACX,OAAO,EAAE,EAAE,EACX,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,IAAI,CAAC,CA2Bf;IAED;;;;;;;OAOG;IACH,oBAAoB,CAClB,eAAe,EAAE,YAAY,EAC7B,QAAQ,EAAE,EAAE,EACZ,OAAO,EAAE,EAAE,EAAE,EAAE,EACf,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,IAAI,CAAC,CAqBf;IAED,gBAAgB,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CA2BjH;IAED,eAAe,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,iBA2B/G;CACF"}
@@ -3,10 +3,11 @@ import { createLogger } from '@aztec/foundation/log';
3
3
  export class CapsuleStore {
4
4
  storeName = 'capsule';
5
5
  #store;
6
- // Arbitrary data stored by contracts. Key is computed as `${contractAddress}:${key}`
6
+ // Arbitrary data stored by contracts. Key is computed as `${contractAddress}:${scope}:${key}`, using the zero
7
+ // address for the global scope.
7
8
  #capsules;
8
- // jobId => `${contractAddress}:${key}` => capsule data
9
- // when `#stagedCapsules.get('some-job-id').get('${some-contract-address:some-key') === null`,
9
+ // jobId => `${contractAddress}:${scope}:${key}` => capsule data
10
+ // when `#stagedCapsules.get('some-job-id').get('${some-contract-address}:${some-scope}:${some-key}') === null`,
10
11
  // it signals that the capsule was deleted during the job, so it needs to be deleted on commit
11
12
  #stagedCapsules;
12
13
  logger;
@@ -101,8 +102,8 @@ export class CapsuleStore {
101
102
  * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle. It works similarly
102
103
  * to public contract storage in that it's indexed by the contract address and storage slot but instead of the global
103
104
  * network state it's backed by local PXE db.
104
- */ storeCapsule(contractAddress, slot, capsule, jobId) {
105
- const dbSlotKey = dbSlotToKey(contractAddress, slot);
105
+ */ setCapsule(contractAddress, slot, capsule, jobId, scope) {
106
+ const dbSlotKey = dbSlotToKey(contractAddress, slot, scope);
106
107
  // A store overrides any pre-existing data on the slot
107
108
  this.#setOnStage(jobId, dbSlotKey, Buffer.concat(capsule.map((value)=>value.toBuffer())));
108
109
  }
@@ -111,8 +112,8 @@ export class CapsuleStore {
111
112
  * @param contractAddress - The contract address under which the data is scoped.
112
113
  * @param slot - The slot in the database to read.
113
114
  * @returns The stored data or `null` if no data is stored under the slot.
114
- */ async loadCapsule(contractAddress, slot, jobId) {
115
- const dataBuffer = await this.#getFromStage(jobId, dbSlotToKey(contractAddress, slot));
115
+ */ async getCapsule(contractAddress, slot, jobId, scope) {
116
+ const dataBuffer = await this.#getFromStage(jobId, dbSlotToKey(contractAddress, slot, scope));
116
117
  if (!dataBuffer) {
117
118
  this.logger.trace(`Data not found for contract ${contractAddress.toString()} and slot ${slot.toString()}`);
118
119
  return null;
@@ -127,9 +128,9 @@ export class CapsuleStore {
127
128
  * Deletes data in the per-contract non-volatile database. Does nothing if no data was present.
128
129
  * @param contractAddress - The contract address under which the data is scoped.
129
130
  * @param slot - The slot in the database to delete.
130
- */ deleteCapsule(contractAddress, slot, jobId) {
131
+ */ deleteCapsule(contractAddress, slot, jobId, scope) {
131
132
  // When we commit this, we will interpret null as a deletion, so we'll propagate the delete to the KV store
132
- this.#deleteOnStage(jobId, dbSlotToKey(contractAddress, slot));
133
+ this.#deleteOnStage(jobId, dbSlotToKey(contractAddress, slot, scope));
133
134
  }
134
135
  /**
135
136
  * Copies a number of contiguous entries in the per-contract non-volatile database. This allows for efficient data
@@ -141,7 +142,7 @@ export class CapsuleStore {
141
142
  * @param srcSlot - The first slot to copy from.
142
143
  * @param dstSlot - The first slot to copy to.
143
144
  * @param numEntries - The number of entries to copy.
144
- */ copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, jobId) {
145
+ */ copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, jobId, scope) {
145
146
  // This transactional context gives us "copy atomicity":
146
147
  // there shouldn't be concurrent writes to what's being copied here.
147
148
  // Equally important: this in practice is expected to perform thousands of DB operations
@@ -156,8 +157,8 @@ export class CapsuleStore {
156
157
  indexes.reverse();
157
158
  }
158
159
  for (const i of indexes){
159
- const currentSrcSlot = dbSlotToKey(contractAddress, srcSlot.add(new Fr(i)));
160
- const currentDstSlot = dbSlotToKey(contractAddress, dstSlot.add(new Fr(i)));
160
+ const currentSrcSlot = dbSlotToKey(contractAddress, srcSlot.add(new Fr(i)), scope);
161
+ const currentDstSlot = dbSlotToKey(contractAddress, dstSlot.add(new Fr(i)), scope);
161
162
  const toCopy = await this.#getFromStage(jobId, currentSrcSlot);
162
163
  if (!toCopy) {
163
164
  throw new Error(`Attempted to copy empty slot ${currentSrcSlot} for contract ${contractAddress.toString()}`);
@@ -173,7 +174,7 @@ export class CapsuleStore {
173
174
  * @param contractAddress - The contract address that owns the capsule array
174
175
  * @param baseSlot - The slot where the array length is stored
175
176
  * @param content - Array of capsule data to append
176
- */ appendToCapsuleArray(contractAddress, baseSlot, content, jobId) {
177
+ */ appendToCapsuleArray(contractAddress, baseSlot, content, jobId, scope) {
177
178
  // We wrap this in a transaction to serialize concurrent calls from Promise.all.
178
179
  // Without this, concurrent appends to the same array could race: both read length=0,
179
180
  // both write at the same slots, one overwrites the other.
@@ -181,21 +182,21 @@ export class CapsuleStore {
181
182
  // and not using a transaction here would heavily impact performance.
182
183
  return this.#store.transactionAsync(async ()=>{
183
184
  // Load current length, defaulting to 0 if not found
184
- const lengthData = await this.loadCapsule(contractAddress, baseSlot, jobId);
185
+ const lengthData = await this.getCapsule(contractAddress, baseSlot, jobId, scope);
185
186
  const currentLength = lengthData ? lengthData[0].toNumber() : 0;
186
187
  // Store each capsule at consecutive slots after baseSlot + 1 + currentLength
187
188
  for(let i = 0; i < content.length; i++){
188
189
  const nextSlot = arraySlot(baseSlot, currentLength + i);
189
- this.storeCapsule(contractAddress, nextSlot, content[i], jobId);
190
+ this.setCapsule(contractAddress, nextSlot, content[i], jobId, scope);
190
191
  }
191
192
  // Update length to include all new capsules
192
193
  const newLength = currentLength + content.length;
193
- this.storeCapsule(contractAddress, baseSlot, [
194
+ this.setCapsule(contractAddress, baseSlot, [
194
195
  new Fr(newLength)
195
- ], jobId);
196
+ ], jobId, scope);
196
197
  });
197
198
  }
198
- readCapsuleArray(contractAddress, baseSlot, jobId) {
199
+ readCapsuleArray(contractAddress, baseSlot, jobId, scope) {
199
200
  // I'm leaving this transactional context here though because I'm assuming this
200
201
  // gives us "read array atomicity": there shouldn't be concurrent writes to what's being copied
201
202
  // here.
@@ -203,12 +204,12 @@ export class CapsuleStore {
203
204
  // of jobs: different calls running concurrently on the same contract may cause trouble.
204
205
  return this.#store.transactionAsync(async ()=>{
205
206
  // Load length, defaulting to 0 if not found
206
- const maybeLength = await this.loadCapsule(contractAddress, baseSlot, jobId);
207
+ const maybeLength = await this.getCapsule(contractAddress, baseSlot, jobId, scope);
207
208
  const length = maybeLength ? maybeLength[0].toBigInt() : 0n;
208
209
  const values = [];
209
210
  // Read each capsule at consecutive slots after baseSlot
210
211
  for(let i = 0; i < length; i++){
211
- const currentValue = await this.loadCapsule(contractAddress, arraySlot(baseSlot, i), jobId);
212
+ const currentValue = await this.getCapsule(contractAddress, arraySlot(baseSlot, i), jobId, scope);
212
213
  if (currentValue == undefined) {
213
214
  throw new Error(`Expected non-empty value at capsule array in base slot ${baseSlot} at index ${i} for contract ${contractAddress}`);
214
215
  }
@@ -217,7 +218,7 @@ export class CapsuleStore {
217
218
  return values;
218
219
  });
219
220
  }
220
- setCapsuleArray(contractAddress, baseSlot, content, jobId) {
221
+ setCapsuleArray(contractAddress, baseSlot, content, jobId, scope) {
221
222
  // This transactional context in theory isn't so critical now because we aren't
222
223
  // writing to DB so if there's exceptions midway and it blows up, no visible impact
223
224
  // to persistent storage will happen.
@@ -228,25 +229,29 @@ export class CapsuleStore {
228
229
  // of jobs: different calls running concurrently on the same contract may cause trouble.
229
230
  return this.#store.transactionAsync(async ()=>{
230
231
  // Load current length, defaulting to 0 if not found
231
- const maybeLength = await this.loadCapsule(contractAddress, baseSlot, jobId);
232
+ const maybeLength = await this.getCapsule(contractAddress, baseSlot, jobId, scope);
232
233
  const originalLength = maybeLength ? maybeLength[0].toNumber() : 0;
233
234
  // Set the new length
234
- this.storeCapsule(contractAddress, baseSlot, [
235
+ this.setCapsule(contractAddress, baseSlot, [
235
236
  new Fr(content.length)
236
- ], jobId);
237
+ ], jobId, scope);
237
238
  // Store the new content, possibly overwriting existing values
238
239
  for(let i = 0; i < content.length; i++){
239
- this.storeCapsule(contractAddress, arraySlot(baseSlot, i), content[i], jobId);
240
+ this.setCapsule(contractAddress, arraySlot(baseSlot, i), content[i], jobId, scope);
240
241
  }
241
242
  // Clear any stragglers
242
243
  for(let i = content.length; i < originalLength; i++){
243
- this.deleteCapsule(contractAddress, arraySlot(baseSlot, i), jobId);
244
+ this.deleteCapsule(contractAddress, arraySlot(baseSlot, i), jobId, scope);
244
245
  }
245
246
  });
246
247
  }
247
248
  }
248
- function dbSlotToKey(contractAddress, slot) {
249
- return `${contractAddress.toString()}:${slot.toString()}`;
249
+ function dbSlotToKey(contractAddress, slot, scope) {
250
+ return [
251
+ contractAddress.toString(),
252
+ scope.toString(),
253
+ slot.toString()
254
+ ].join(':');
250
255
  }
251
256
  function arraySlot(baseSlot, index) {
252
257
  return baseSlot.add(new Fr(1)).add(new Fr(index));
@@ -1,2 +1,3 @@
1
+ export { CapsuleService } from './capsule_service.js';
1
2
  export { CapsuleStore } from './capsule_store.js';
2
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL2NhcHN1bGVfc3RvcmUvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLG9CQUFvQixDQUFDIn0=
3
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL2NhcHN1bGVfc3RvcmUvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGNBQWMsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQ3RELE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQyJ9
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/capsule_store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/capsule_store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
@@ -1 +1,2 @@
1
+ export { CapsuleService } from './capsule_service.js';
1
2
  export { CapsuleStore } from './capsule_store.js';
@@ -1,2 +1,2 @@
1
- export declare const PXE_DATA_SCHEMA_VERSION = 3;
1
+ export declare const PXE_DATA_SCHEMA_VERSION = 5;
2
2
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWV0YWRhdGEuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdG9yYWdlL21ldGFkYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGVBQU8sTUFBTSx1QkFBdUIsSUFBSSxDQUFDIn0=
@@ -1 +1 @@
1
- export const PXE_DATA_SCHEMA_VERSION = 3;
1
+ export const PXE_DATA_SCHEMA_VERSION = 5;