@aztec/pxe 4.1.2 → 4.2.0-aztecnr-rc.2

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 (109) hide show
  1. package/dest/config/package_info.js +1 -1
  2. package/dest/contract_function_simulator/contract_function_simulator.d.ts +9 -3
  3. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  4. package/dest/contract_function_simulator/contract_function_simulator.js +26 -4
  5. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
  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 +17 -9
  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 +45 -44
  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 +41 -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 +22 -47
  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 +32 -72
  32. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +54 -38
  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 +173 -80
  35. package/dest/contract_logging.d.ts +9 -4
  36. package/dest/contract_logging.d.ts.map +1 -1
  37. package/dest/contract_logging.js +21 -6
  38. package/dest/contract_sync/contract_sync_service.d.ts +7 -4
  39. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  40. package/dest/contract_sync/contract_sync_service.js +59 -32
  41. package/dest/contract_sync/helpers.d.ts +2 -2
  42. package/dest/contract_sync/helpers.d.ts.map +1 -1
  43. package/dest/contract_sync/helpers.js +7 -2
  44. package/dest/events/event_service.d.ts +3 -2
  45. package/dest/events/event_service.d.ts.map +1 -1
  46. package/dest/events/event_service.js +16 -4
  47. package/dest/logs/log_service.d.ts +3 -4
  48. package/dest/logs/log_service.d.ts.map +1 -1
  49. package/dest/logs/log_service.js +16 -25
  50. package/dest/messages/message_context_service.d.ts +17 -0
  51. package/dest/messages/message_context_service.d.ts.map +1 -0
  52. package/dest/messages/message_context_service.js +36 -0
  53. package/dest/notes/note_service.d.ts +2 -2
  54. package/dest/notes/note_service.d.ts.map +1 -1
  55. package/dest/notes/note_service.js +14 -5
  56. package/dest/oracle_version.d.ts +2 -2
  57. package/dest/oracle_version.js +3 -3
  58. package/dest/pxe.d.ts +6 -3
  59. package/dest/pxe.d.ts.map +1 -1
  60. package/dest/pxe.js +39 -22
  61. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  62. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  63. package/dest/storage/capsule_store/capsule_store.js +33 -28
  64. package/dest/storage/metadata.d.ts +1 -1
  65. package/dest/storage/metadata.js +1 -1
  66. package/dest/storage/tagging_store/sender_tagging_store.d.ts +26 -25
  67. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  68. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  69. package/dest/tagging/index.d.ts +2 -2
  70. package/dest/tagging/index.d.ts.map +1 -1
  71. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +1 -1
  72. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  73. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +10 -1
  74. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  75. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  76. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  77. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +2 -1
  78. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  79. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +24 -11
  80. package/package.json +16 -16
  81. package/src/config/package_info.ts +1 -1
  82. package/src/contract_function_simulator/contract_function_simulator.ts +37 -5
  83. package/src/contract_function_simulator/execution_tagging_index_cache.ts +16 -11
  84. package/src/contract_function_simulator/index.ts +1 -0
  85. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -8
  86. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
  87. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -9
  88. package/src/contract_function_simulator/oracle/interfaces.ts +59 -53
  89. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +107 -0
  90. package/src/contract_function_simulator/oracle/oracle.ts +223 -139
  91. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  92. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +34 -91
  93. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +279 -93
  94. package/src/contract_logging.ts +18 -5
  95. package/src/contract_sync/contract_sync_service.ts +89 -49
  96. package/src/contract_sync/helpers.ts +3 -2
  97. package/src/events/event_service.ts +17 -4
  98. package/src/logs/log_service.ts +40 -44
  99. package/src/messages/message_context_service.ts +44 -0
  100. package/src/notes/note_service.ts +16 -5
  101. package/src/oracle_version.ts +3 -3
  102. package/src/pxe.ts +57 -20
  103. package/src/storage/capsule_store/capsule_store.ts +34 -26
  104. package/src/storage/metadata.ts +1 -1
  105. package/src/storage/tagging_store/sender_tagging_store.ts +182 -135
  106. package/src/tagging/index.ts +1 -1
  107. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +19 -1
  108. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  109. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +19 -9
package/src/pxe.ts CHANGED
@@ -68,6 +68,7 @@ import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
68
68
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
69
69
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
70
70
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
71
+ import { MessageContextService } from './messages/message_context_service.js';
71
72
  import {
72
73
  PrivateKernelExecutionProver,
73
74
  type PrivateKernelExecutionProverConfig,
@@ -106,7 +107,9 @@ export type SimulateTxOpts = {
106
107
  skipTxValidation?: boolean;
107
108
  /** If false, fees are enforced. */
108
109
  skipFeeEnforcement?: boolean;
109
- /** 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 */
110
113
  overrides?: SimulationOverrides;
111
114
  /** Addresses whose private state and keys are accessible during private execution */
112
115
  scopes: AccessScopes;
@@ -157,6 +160,7 @@ export class PXE {
157
160
  private addressStore: AddressStore,
158
161
  private privateEventStore: PrivateEventStore,
159
162
  private contractSyncService: ContractSyncService,
163
+ private messageContextService: MessageContextService,
160
164
  private simulator: CircuitSimulator,
161
165
  private proverEnabled: boolean,
162
166
  private proofCreator: PrivateKernelProver,
@@ -210,8 +214,11 @@ export class PXE {
210
214
  node,
211
215
  contractStore,
212
216
  noteStore,
217
+ () => keyStore.getAccounts(),
213
218
  createLogger('pxe:contract_sync', bindings),
214
219
  );
220
+ const messageContextService = new MessageContextService(node);
221
+
215
222
  const synchronizer = new BlockSynchronizer(
216
223
  node,
217
224
  store,
@@ -252,6 +259,7 @@ export class PXE {
252
259
  addressStore,
253
260
  privateEventStore,
254
261
  contractSyncService,
262
+ messageContextService,
255
263
  simulator,
256
264
  proverEnabled,
257
265
  proofCreator,
@@ -293,6 +301,7 @@ export class PXE {
293
301
  privateEventStore: this.privateEventStore,
294
302
  simulator: this.simulator,
295
303
  contractSyncService: this.contractSyncService,
304
+ messageContextService: this.messageContextService,
296
305
  });
297
306
  }
298
307
 
@@ -412,7 +421,14 @@ export class PXE {
412
421
  ) {
413
422
  try {
414
423
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
415
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
424
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
425
+ call,
426
+ authWitnesses ?? [],
427
+ anchorBlockHeader,
428
+ scopes,
429
+ jobId,
430
+ );
431
+ return { result, offchainEffects };
416
432
  } catch (err) {
417
433
  if (err instanceof SimulationError) {
418
434
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -485,7 +501,9 @@ export class PXE {
485
501
  * @returns The synced block header
486
502
  */
487
503
  public getSyncedBlockHeader(): Promise<BlockHeader> {
488
- return this.anchorBlockStore.getBlockHeader();
504
+ return this.#putInJobQueue(() => {
505
+ return this.anchorBlockStore.getBlockHeader();
506
+ });
489
507
  }
490
508
 
491
509
  /**
@@ -552,6 +570,9 @@ export class PXE {
552
570
 
553
571
  if (wasAdded) {
554
572
  this.log.info(`Added sender:\n ${sender.toString()}`);
573
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
574
+ // all contracts must re-sync to discover them.
575
+ this.contractSyncService.wipe();
555
576
  } else {
556
577
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
557
578
  }
@@ -764,17 +785,17 @@ export class PXE {
764
785
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
765
786
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
766
787
  // storing the tags here prevents linkage of txs sent from the same PXE.
767
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
768
- if (preTagsUsedInTheTx.length > 0) {
788
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
789
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
769
790
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
770
791
  const txHash = (await txProvingResult.toTx()).txHash;
771
792
 
772
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
773
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
774
- preTagsUsedInTheTx,
793
+ await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
794
+ this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
795
+ taggingIndexRangesUsedInTheTx,
775
796
  });
776
797
  } else {
777
- this.log.debug(`No pre-tags used in the tx`);
798
+ this.log.debug(`No tagging index ranges used in the tx`);
778
799
  }
779
800
 
780
801
  return txProvingResult;
@@ -881,7 +902,14 @@ export class PXE {
881
902
  */
882
903
  public simulateTx(
883
904
  txRequest: TxExecutionRequest,
884
- { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
905
+ {
906
+ simulatePublic,
907
+ skipTxValidation = false,
908
+ skipFeeEnforcement = false,
909
+ skipKernels = true,
910
+ overrides,
911
+ scopes,
912
+ }: SimulateTxOpts,
885
913
  ): Promise<TxSimulationResult> {
886
914
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
887
915
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -905,17 +933,20 @@ export class PXE {
905
933
  await this.blockStateSynchronizer.sync();
906
934
  const syncTime = syncTimer.ms();
907
935
 
908
- const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
909
- // Temporary: in case there are overrides, we have to skip the kernels or validations
910
- // will fail. Consider handing control to the user/wallet on whether they want to run them
911
- // or not.
912
936
  const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
913
937
  const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
914
- const skipKernels = hasOverriddenContracts;
915
938
 
916
- // Set overridden contracts on the sync service so it knows to skip syncing them
939
+ if (hasOverriddenContracts && !skipKernels) {
940
+ throw new Error(
941
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
942
+ );
943
+ }
944
+ const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
945
+
917
946
  if (hasOverriddenContracts) {
918
- this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
947
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
948
+ // We exclude them so the sync service skips them entirely.
949
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
919
950
  }
920
951
 
921
952
  // Execution of private functions only; no proving, and no kernel logic.
@@ -958,7 +989,8 @@ export class PXE {
958
989
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
959
990
  validationTime = validationTimer.ms();
960
991
  if (validationResult.result === 'invalid') {
961
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
992
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
993
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
962
994
  }
963
995
  }
964
996
 
@@ -1046,7 +1078,7 @@ export class PXE {
1046
1078
  scopes,
1047
1079
  );
1048
1080
 
1049
- const executionResult = await this.#executeUtility(
1081
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
1050
1082
  contractFunctionSimulator,
1051
1083
  call,
1052
1084
  authwits ?? [],
@@ -1067,7 +1099,12 @@ export class PXE {
1067
1099
  };
1068
1100
 
1069
1101
  const simulationStats = contractFunctionSimulator.getStats();
1070
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1102
+ return {
1103
+ result: executionResult,
1104
+ offchainEffects,
1105
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1106
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1107
+ };
1071
1108
  } catch (err: any) {
1072
1109
  const { to, name, args } = call;
1073
1110
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
@@ -1,7 +1,7 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
3
  import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
4
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
5
 
6
6
  import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
7
7
 
@@ -10,11 +10,12 @@ export class CapsuleStore implements StagedStore {
10
10
 
11
11
  #store: AztecAsyncKVStore;
12
12
 
13
- // Arbitrary data stored by contracts. Key is computed as `${contractAddress}:${key}`
13
+ // Arbitrary data stored by contracts. Key is computed as `${contractAddress}:${scope}:${key}`, using the zero
14
+ // address for the global scope.
14
15
  #capsules: AztecAsyncMap<string, Buffer>;
15
16
 
16
- // jobId => `${contractAddress}:${key}` => capsule data
17
- // when `#stagedCapsules.get('some-job-id').get('${some-contract-address:some-key') === null`,
17
+ // jobId => `${contractAddress}:${scope}:${key}` => capsule data
18
+ // when `#stagedCapsules.get('some-job-id').get('${some-contract-address}:${some-scope}:${some-key}') === null`,
18
19
  // it signals that the capsule was deleted during the job, so it needs to be deleted on commit
19
20
  #stagedCapsules: Map<string, Map<string, Buffer | null>>;
20
21
 
@@ -134,8 +135,8 @@ export class CapsuleStore implements StagedStore {
134
135
  * to public contract storage in that it's indexed by the contract address and storage slot but instead of the global
135
136
  * network state it's backed by local PXE db.
136
137
  */
137
- storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], jobId: string) {
138
- const dbSlotKey = dbSlotToKey(contractAddress, slot);
138
+ setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], jobId: string, scope: AztecAddress) {
139
+ const dbSlotKey = dbSlotToKey(contractAddress, slot, scope);
139
140
 
140
141
  // A store overrides any pre-existing data on the slot
141
142
  this.#setOnStage(jobId, dbSlotKey, Buffer.concat(capsule.map(value => value.toBuffer())));
@@ -147,8 +148,8 @@ export class CapsuleStore implements StagedStore {
147
148
  * @param slot - The slot in the database to read.
148
149
  * @returns The stored data or `null` if no data is stored under the slot.
149
150
  */
150
- async loadCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string): Promise<Fr[] | null> {
151
- const dataBuffer = await this.#getFromStage(jobId, dbSlotToKey(contractAddress, slot));
151
+ async getCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress): Promise<Fr[] | null> {
152
+ const dataBuffer = await this.#getFromStage(jobId, dbSlotToKey(contractAddress, slot, scope));
152
153
  if (!dataBuffer) {
153
154
  this.logger.trace(`Data not found for contract ${contractAddress.toString()} and slot ${slot.toString()}`);
154
155
  return null;
@@ -165,9 +166,9 @@ export class CapsuleStore implements StagedStore {
165
166
  * @param contractAddress - The contract address under which the data is scoped.
166
167
  * @param slot - The slot in the database to delete.
167
168
  */
168
- deleteCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string) {
169
+ deleteCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress) {
169
170
  // When we commit this, we will interpret null as a deletion, so we'll propagate the delete to the KV store
170
- this.#deleteOnStage(jobId, dbSlotToKey(contractAddress, slot));
171
+ this.#deleteOnStage(jobId, dbSlotToKey(contractAddress, slot, scope));
171
172
  }
172
173
 
173
174
  /**
@@ -187,6 +188,7 @@ export class CapsuleStore implements StagedStore {
187
188
  dstSlot: Fr,
188
189
  numEntries: number,
189
190
  jobId: string,
191
+ scope: AztecAddress,
190
192
  ): Promise<void> {
191
193
  // This transactional context gives us "copy atomicity":
192
194
  // there shouldn't be concurrent writes to what's being copied here.
@@ -203,8 +205,8 @@ export class CapsuleStore implements StagedStore {
203
205
  }
204
206
 
205
207
  for (const i of indexes) {
206
- const currentSrcSlot = dbSlotToKey(contractAddress, srcSlot.add(new Fr(i)));
207
- const currentDstSlot = dbSlotToKey(contractAddress, dstSlot.add(new Fr(i)));
208
+ const currentSrcSlot = dbSlotToKey(contractAddress, srcSlot.add(new Fr(i)), scope);
209
+ const currentDstSlot = dbSlotToKey(contractAddress, dstSlot.add(new Fr(i)), scope);
208
210
 
209
211
  const toCopy = await this.#getFromStage(jobId, currentSrcSlot);
210
212
  if (!toCopy) {
@@ -224,7 +226,13 @@ export class CapsuleStore implements StagedStore {
224
226
  * @param baseSlot - The slot where the array length is stored
225
227
  * @param content - Array of capsule data to append
226
228
  */
227
- appendToCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string): Promise<void> {
229
+ appendToCapsuleArray(
230
+ contractAddress: AztecAddress,
231
+ baseSlot: Fr,
232
+ content: Fr[][],
233
+ jobId: string,
234
+ scope: AztecAddress,
235
+ ): Promise<void> {
228
236
  // We wrap this in a transaction to serialize concurrent calls from Promise.all.
229
237
  // Without this, concurrent appends to the same array could race: both read length=0,
230
238
  // both write at the same slots, one overwrites the other.
@@ -232,22 +240,22 @@ export class CapsuleStore implements StagedStore {
232
240
  // and not using a transaction here would heavily impact performance.
233
241
  return this.#store.transactionAsync(async () => {
234
242
  // Load current length, defaulting to 0 if not found
235
- const lengthData = await this.loadCapsule(contractAddress, baseSlot, jobId);
243
+ const lengthData = await this.getCapsule(contractAddress, baseSlot, jobId, scope);
236
244
  const currentLength = lengthData ? lengthData[0].toNumber() : 0;
237
245
 
238
246
  // Store each capsule at consecutive slots after baseSlot + 1 + currentLength
239
247
  for (let i = 0; i < content.length; i++) {
240
248
  const nextSlot = arraySlot(baseSlot, currentLength + i);
241
- this.storeCapsule(contractAddress, nextSlot, content[i], jobId);
249
+ this.setCapsule(contractAddress, nextSlot, content[i], jobId, scope);
242
250
  }
243
251
 
244
252
  // Update length to include all new capsules
245
253
  const newLength = currentLength + content.length;
246
- this.storeCapsule(contractAddress, baseSlot, [new Fr(newLength)], jobId);
254
+ this.setCapsule(contractAddress, baseSlot, [new Fr(newLength)], jobId, scope);
247
255
  });
248
256
  }
249
257
 
250
- readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, jobId: string): Promise<Fr[][]> {
258
+ readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, jobId: string, scope: AztecAddress): Promise<Fr[][]> {
251
259
  // I'm leaving this transactional context here though because I'm assuming this
252
260
  // gives us "read array atomicity": there shouldn't be concurrent writes to what's being copied
253
261
  // here.
@@ -255,14 +263,14 @@ export class CapsuleStore implements StagedStore {
255
263
  // of jobs: different calls running concurrently on the same contract may cause trouble.
256
264
  return this.#store.transactionAsync(async () => {
257
265
  // Load length, defaulting to 0 if not found
258
- const maybeLength = await this.loadCapsule(contractAddress, baseSlot, jobId);
266
+ const maybeLength = await this.getCapsule(contractAddress, baseSlot, jobId, scope);
259
267
  const length = maybeLength ? maybeLength[0].toBigInt() : 0n;
260
268
 
261
269
  const values: Fr[][] = [];
262
270
 
263
271
  // Read each capsule at consecutive slots after baseSlot
264
272
  for (let i = 0; i < length; i++) {
265
- const currentValue = await this.loadCapsule(contractAddress, arraySlot(baseSlot, i), jobId);
273
+ const currentValue = await this.getCapsule(contractAddress, arraySlot(baseSlot, i), jobId, scope);
266
274
  if (currentValue == undefined) {
267
275
  throw new Error(
268
276
  `Expected non-empty value at capsule array in base slot ${baseSlot} at index ${i} for contract ${contractAddress}`,
@@ -276,7 +284,7 @@ export class CapsuleStore implements StagedStore {
276
284
  });
277
285
  }
278
286
 
279
- setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string) {
287
+ setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string, scope: AztecAddress) {
280
288
  // This transactional context in theory isn't so critical now because we aren't
281
289
  // writing to DB so if there's exceptions midway and it blows up, no visible impact
282
290
  // to persistent storage will happen.
@@ -287,27 +295,27 @@ export class CapsuleStore implements StagedStore {
287
295
  // of jobs: different calls running concurrently on the same contract may cause trouble.
288
296
  return this.#store.transactionAsync(async () => {
289
297
  // Load current length, defaulting to 0 if not found
290
- const maybeLength = await this.loadCapsule(contractAddress, baseSlot, jobId);
298
+ const maybeLength = await this.getCapsule(contractAddress, baseSlot, jobId, scope);
291
299
  const originalLength = maybeLength ? maybeLength[0].toNumber() : 0;
292
300
 
293
301
  // Set the new length
294
- this.storeCapsule(contractAddress, baseSlot, [new Fr(content.length)], jobId);
302
+ this.setCapsule(contractAddress, baseSlot, [new Fr(content.length)], jobId, scope);
295
303
 
296
304
  // Store the new content, possibly overwriting existing values
297
305
  for (let i = 0; i < content.length; i++) {
298
- this.storeCapsule(contractAddress, arraySlot(baseSlot, i), content[i], jobId);
306
+ this.setCapsule(contractAddress, arraySlot(baseSlot, i), content[i], jobId, scope);
299
307
  }
300
308
 
301
309
  // Clear any stragglers
302
310
  for (let i = content.length; i < originalLength; i++) {
303
- this.deleteCapsule(contractAddress, arraySlot(baseSlot, i), jobId);
311
+ this.deleteCapsule(contractAddress, arraySlot(baseSlot, i), jobId, scope);
304
312
  }
305
313
  });
306
314
  }
307
315
  }
308
316
 
309
- function dbSlotToKey(contractAddress: AztecAddress, slot: Fr): string {
310
- return `${contractAddress.toString()}:${slot.toString()}`;
317
+ function dbSlotToKey(contractAddress: AztecAddress, slot: Fr, scope: AztecAddress): string {
318
+ return [contractAddress.toString(), scope.toString(), slot.toString()].join(':');
311
319
  }
312
320
 
313
321
  function arraySlot(baseSlot: Fr, index: number) {
@@ -1 +1 @@
1
- export const PXE_DATA_SCHEMA_VERSION = 3;
1
+ export const PXE_DATA_SCHEMA_VERSION = 5;