@aztec/pxe 0.0.1-commit.8afd444 → 0.0.1-commit.8f9871590

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 (108) hide show
  1. package/dest/access_scopes.d.ts +9 -0
  2. package/dest/access_scopes.d.ts.map +1 -0
  3. package/dest/access_scopes.js +6 -0
  4. package/dest/block_synchronizer/block_synchronizer.d.ts +4 -2
  5. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  6. package/dest/block_synchronizer/block_synchronizer.js +7 -1
  7. package/dest/contract_function_simulator/contract_function_simulator.d.ts +54 -28
  8. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  9. package/dest/contract_function_simulator/contract_function_simulator.js +170 -64
  10. package/dest/contract_function_simulator/oracle/interfaces.d.ts +2 -2
  11. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  12. package/dest/contract_function_simulator/oracle/oracle.d.ts +2 -2
  13. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  14. package/dest/contract_function_simulator/oracle/oracle.js +3 -3
  15. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +36 -35
  16. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +72 -19
  18. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +32 -11
  19. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +58 -29
  21. package/dest/contract_sync/contract_sync_service.d.ts +43 -0
  22. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  23. package/dest/contract_sync/contract_sync_service.js +97 -0
  24. package/dest/contract_sync/helpers.d.ts +29 -0
  25. package/dest/contract_sync/helpers.d.ts.map +1 -0
  26. package/dest/contract_sync/{index.js → helpers.js} +8 -14
  27. package/dest/debug/pxe_debug_utils.d.ts +14 -10
  28. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  29. package/dest/debug/pxe_debug_utils.js +16 -15
  30. package/dest/entrypoints/client/bundle/index.d.ts +3 -1
  31. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  32. package/dest/entrypoints/client/bundle/index.js +2 -0
  33. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  34. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  35. package/dest/entrypoints/client/bundle/utils.js +9 -1
  36. package/dest/entrypoints/client/lazy/index.d.ts +3 -1
  37. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  38. package/dest/entrypoints/client/lazy/index.js +2 -0
  39. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  40. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  41. package/dest/entrypoints/client/lazy/utils.js +9 -1
  42. package/dest/entrypoints/server/index.d.ts +4 -2
  43. package/dest/entrypoints/server/index.d.ts.map +1 -1
  44. package/dest/entrypoints/server/index.js +3 -1
  45. package/dest/entrypoints/server/utils.js +9 -1
  46. package/dest/logs/log_service.d.ts +3 -2
  47. package/dest/logs/log_service.d.ts.map +1 -1
  48. package/dest/logs/log_service.js +5 -10
  49. package/dest/notes/note_service.d.ts +4 -3
  50. package/dest/notes/note_service.d.ts.map +1 -1
  51. package/dest/notes/note_service.js +3 -2
  52. package/dest/notes_filter.d.ts +25 -0
  53. package/dest/notes_filter.d.ts.map +1 -0
  54. package/dest/notes_filter.js +4 -0
  55. package/dest/oracle_version.d.ts +2 -2
  56. package/dest/oracle_version.js +2 -2
  57. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  58. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  59. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  60. package/dest/private_kernel/hints/index.d.ts +1 -1
  61. package/dest/private_kernel/hints/index.js +1 -1
  62. package/dest/private_kernel/private_kernel_execution_prover.js +6 -6
  63. package/dest/pxe.d.ts +69 -23
  64. package/dest/pxe.d.ts.map +1 -1
  65. package/dest/pxe.js +72 -44
  66. package/dest/storage/contract_store/contract_store.js +5 -5
  67. package/dest/storage/note_store/note_store.d.ts +3 -3
  68. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  69. package/dest/storage/note_store/note_store.js +6 -4
  70. package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
  71. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  72. package/dest/tagging/get_all_logs_by_tags.js +17 -3
  73. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +4 -4
  74. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  75. package/package.json +25 -16
  76. package/src/access_scopes.ts +9 -0
  77. package/src/block_synchronizer/block_synchronizer.ts +6 -0
  78. package/src/contract_function_simulator/contract_function_simulator.ts +318 -121
  79. package/src/contract_function_simulator/oracle/interfaces.ts +1 -1
  80. package/src/contract_function_simulator/oracle/oracle.ts +3 -3
  81. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +94 -96
  82. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +100 -28
  83. package/src/contract_sync/contract_sync_service.ts +152 -0
  84. package/src/contract_sync/{index.ts → helpers.ts} +13 -34
  85. package/src/debug/pxe_debug_utils.ts +48 -18
  86. package/src/entrypoints/client/bundle/index.ts +2 -0
  87. package/src/entrypoints/client/bundle/utils.ts +9 -1
  88. package/src/entrypoints/client/lazy/index.ts +2 -0
  89. package/src/entrypoints/client/lazy/utils.ts +9 -1
  90. package/src/entrypoints/server/index.ts +3 -1
  91. package/src/entrypoints/server/utils.ts +7 -7
  92. package/src/logs/log_service.ts +7 -19
  93. package/src/notes/note_service.ts +4 -3
  94. package/src/notes_filter.ts +26 -0
  95. package/src/oracle_version.ts +2 -2
  96. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  97. package/src/private_kernel/hints/index.ts +1 -1
  98. package/src/private_kernel/private_kernel_execution_prover.ts +6 -6
  99. package/src/pxe.ts +148 -90
  100. package/src/storage/contract_store/contract_store.ts +4 -4
  101. package/src/storage/note_store/note_store.ts +12 -5
  102. package/src/tagging/get_all_logs_by_tags.ts +28 -4
  103. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +4 -4
  104. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  105. package/dest/contract_sync/index.d.ts +0 -24
  106. package/dest/contract_sync/index.d.ts.map +0 -1
  107. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  108. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
package/src/pxe.ts CHANGED
@@ -33,6 +33,7 @@ import type {
33
33
  PrivateKernelTailCircuitPublicInputs,
34
34
  } from '@aztec/stdlib/kernel';
35
35
  import {
36
+ BlockHeader,
36
37
  type ContractOverrides,
37
38
  type InTx,
38
39
  PrivateExecutionResult,
@@ -51,6 +52,7 @@ import {
51
52
 
52
53
  import { inspect } from 'util';
53
54
 
55
+ import type { AccessScopes } from './access_scopes.js';
54
56
  import { BlockSynchronizer } from './block_synchronizer/index.js';
55
57
  import type { PXEConfig } from './config/index.js';
56
58
  import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
@@ -59,7 +61,8 @@ import {
59
61
  generateSimulatedProvingResult,
60
62
  } from './contract_function_simulator/contract_function_simulator.js';
61
63
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
62
- import { ensureContractSynced, readCurrentClassId } from './contract_sync/index.js';
64
+ import { ContractSyncService } from './contract_sync/contract_sync_service.js';
65
+ import { readCurrentClassId } from './contract_sync/helpers.js';
63
66
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
64
67
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
65
68
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
@@ -84,6 +87,56 @@ export type PackedPrivateEvent = InTx & {
84
87
  eventSelector: EventSelector;
85
88
  };
86
89
 
90
+ /** Options for PXE.profileTx. */
91
+ export type ProfileTxOpts = {
92
+ /** The profiling mode to use. */
93
+ profileMode: 'full' | 'execution-steps' | 'gates';
94
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
95
+ skipProofGeneration?: boolean;
96
+ /** Addresses whose private state and keys are accessible during private execution. */
97
+ scopes: AccessScopes;
98
+ };
99
+
100
+ /** Options for PXE.simulateTx. */
101
+ export type SimulateTxOpts = {
102
+ /** Whether to simulate the public part of the transaction. */
103
+ simulatePublic: boolean;
104
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
105
+ skipTxValidation?: boolean;
106
+ /** If false, fees are enforced. */
107
+ skipFeeEnforcement?: boolean;
108
+ /** State overrides for the simulation, such as contract instances and artifacts. */
109
+ overrides?: SimulationOverrides;
110
+ /** Addresses whose private state and keys are accessible during private execution */
111
+ scopes: AccessScopes;
112
+ };
113
+
114
+ /** Options for PXE.simulateUtility. */
115
+ export type SimulateUtilityOpts = {
116
+ /** The authentication witnesses required for the function call. */
117
+ authwits?: AuthWitness[];
118
+ /** The accounts whose notes we can access in this call */
119
+ scopes: AccessScopes;
120
+ };
121
+
122
+ /** Args for PXE.create. */
123
+ export type PXECreateArgs = {
124
+ /** The Aztec node to connect to. */
125
+ node: AztecNode;
126
+ /** The key-value store for persisting PXE state. */
127
+ store: AztecAsyncKVStore;
128
+ /** The prover for generating private kernel proofs. */
129
+ proofCreator: PrivateKernelProver;
130
+ /** The circuit simulator for executing ACIR circuits. */
131
+ simulator: CircuitSimulator;
132
+ /** Provider for protocol contract artifacts and instances. */
133
+ protocolContractsProvider: ProtocolContractsProvider;
134
+ /** PXE configuration options. */
135
+ config: PXEConfig;
136
+ /** Optional logger instance or string suffix for the logger name. */
137
+ loggerOrSuffix?: string | Logger;
138
+ };
139
+
87
140
  /**
88
141
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
89
142
  * manage private state of users.
@@ -102,6 +155,7 @@ export class PXE {
102
155
  private recipientTaggingStore: RecipientTaggingStore,
103
156
  private addressStore: AddressStore,
104
157
  private privateEventStore: PrivateEventStore,
158
+ private contractSyncService: ContractSyncService,
105
159
  private simulator: CircuitSimulator,
106
160
  private proverEnabled: boolean,
107
161
  private proofCreator: PrivateKernelProver,
@@ -119,15 +173,15 @@ export class PXE {
119
173
  *
120
174
  * @returns A promise that resolves PXE is ready to be used.
121
175
  */
122
- public static async create(
123
- node: AztecNode,
124
- store: AztecAsyncKVStore,
125
- proofCreator: PrivateKernelProver,
126
- simulator: CircuitSimulator,
127
- protocolContractsProvider: ProtocolContractsProvider,
128
- config: PXEConfig,
129
- loggerOrSuffix?: string | Logger,
130
- ) {
176
+ public static async create({
177
+ node,
178
+ store,
179
+ proofCreator,
180
+ simulator,
181
+ protocolContractsProvider,
182
+ config,
183
+ loggerOrSuffix,
184
+ }: PXECreateArgs) {
131
185
  // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
132
186
  const bindings: LoggerBindings | undefined =
133
187
  loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
@@ -137,7 +191,9 @@ export class PXE {
137
191
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
138
192
  : loggerOrSuffix;
139
193
 
140
- const proverEnabled = !!config.proverEnabled;
194
+ const info = await node.getNodeInfo();
195
+
196
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
141
197
  const addressStore = new AddressStore(store);
142
198
  const privateEventStore = new PrivateEventStore(store);
143
199
  const contractStore = new ContractStore(store);
@@ -149,6 +205,12 @@ export class PXE {
149
205
  const capsuleStore = new CapsuleStore(store);
150
206
  const keyStore = new KeyStore(store);
151
207
  const tipsStore = new L2TipsKVStore(store, 'pxe');
208
+ const contractSyncService = new ContractSyncService(
209
+ node,
210
+ contractStore,
211
+ noteStore,
212
+ createLogger('pxe:contract_sync', bindings),
213
+ );
152
214
  const synchronizer = new BlockSynchronizer(
153
215
  node,
154
216
  store,
@@ -156,6 +218,7 @@ export class PXE {
156
218
  noteStore,
157
219
  privateEventStore,
158
220
  tipsStore,
221
+ contractSyncService,
159
222
  config,
160
223
  bindings,
161
224
  );
@@ -167,9 +230,10 @@ export class PXE {
167
230
  recipientTaggingStore,
168
231
  privateEventStore,
169
232
  noteStore,
233
+ contractSyncService,
170
234
  ]);
171
235
 
172
- const debugUtils = new PXEDebugUtils(contractStore, noteStore, synchronizer, anchorBlockStore);
236
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
173
237
 
174
238
  const jobQueue = new SerialQueue();
175
239
 
@@ -186,6 +250,7 @@ export class PXE {
186
250
  recipientTaggingStore,
187
251
  addressStore,
188
252
  privateEventStore,
253
+ contractSyncService,
189
254
  simulator,
190
255
  proverEnabled,
191
256
  proofCreator,
@@ -196,12 +261,15 @@ export class PXE {
196
261
  debugUtils,
197
262
  );
198
263
 
199
- debugUtils.setPXE(pxe, pxe.#putInJobQueue.bind(pxe));
264
+ debugUtils.setPXEHelpers(
265
+ pxe.#putInJobQueue.bind(pxe),
266
+ pxe.#getSimulatorForTx.bind(pxe),
267
+ pxe.#simulateUtility.bind(pxe),
268
+ );
200
269
 
201
270
  pxe.jobQueue.start();
202
271
 
203
272
  await pxe.#registerProtocolContracts();
204
- const info = await node.getNodeInfo();
205
273
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
206
274
  return pxe;
207
275
  }
@@ -211,19 +279,20 @@ export class PXE {
211
279
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
212
280
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
213
281
 
214
- return new ContractFunctionSimulator(
215
- proxyContractStore,
216
- this.noteStore,
217
- this.keyStore,
218
- this.addressStore,
219
- BenchmarkedNodeFactory.create(this.node),
220
- this.senderTaggingStore,
221
- this.recipientTaggingStore,
222
- this.senderAddressBookStore,
223
- this.capsuleStore,
224
- this.privateEventStore,
225
- this.simulator,
226
- );
282
+ return new ContractFunctionSimulator({
283
+ contractStore: proxyContractStore,
284
+ noteStore: this.noteStore,
285
+ keyStore: this.keyStore,
286
+ addressStore: this.addressStore,
287
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
288
+ senderTaggingStore: this.senderTaggingStore,
289
+ recipientTaggingStore: this.recipientTaggingStore,
290
+ senderAddressBookStore: this.senderAddressBookStore,
291
+ capsuleStore: this.capsuleStore,
292
+ privateEventStore: this.privateEventStore,
293
+ simulator: this.simulator,
294
+ contractSyncService: this.contractSyncService,
295
+ });
227
296
  }
228
297
 
229
298
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -289,7 +358,7 @@ export class PXE {
289
358
  async #executePrivate(
290
359
  contractFunctionSimulator: ContractFunctionSimulator,
291
360
  txRequest: TxExecutionRequest,
292
- scopes: AztecAddress[] | undefined,
361
+ scopes: AccessScopes,
293
362
  jobId: string,
294
363
  ): Promise<PrivateExecutionResult> {
295
364
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -297,29 +366,23 @@ export class PXE {
297
366
  try {
298
367
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
299
368
 
300
- await ensureContractSynced(
369
+ await this.contractSyncService.ensureContractSynced(
301
370
  contractAddress,
302
371
  functionSelector,
303
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
304
- this.node,
305
- this.contractStore,
306
- this.noteStore,
372
+ (privateSyncCall, execScopes) =>
373
+ this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
307
374
  anchorBlockHeader,
308
375
  jobId,
376
+ scopes,
309
377
  );
310
378
 
311
- const result = await contractFunctionSimulator.run(
312
- txRequest,
379
+ const result = await contractFunctionSimulator.run(txRequest, {
313
380
  contractAddress,
314
- functionSelector,
315
- undefined,
381
+ selector: functionSelector,
316
382
  anchorBlockHeader,
317
- // The sender for tags is set by contracts, typically by an account
318
- // contract entrypoint
319
- undefined, // senderForTags
320
383
  scopes,
321
384
  jobId,
322
- );
385
+ });
323
386
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
324
387
  return result;
325
388
  } catch (err) {
@@ -344,7 +407,7 @@ export class PXE {
344
407
  contractFunctionSimulator: ContractFunctionSimulator,
345
408
  call: FunctionCall,
346
409
  authWitnesses: AuthWitness[] | undefined,
347
- scopes: AztecAddress[] | undefined,
410
+ scopes: AccessScopes,
348
411
  jobId: string,
349
412
  ) {
350
413
  try {
@@ -417,6 +480,19 @@ export class PXE {
417
480
 
418
481
  // Public API
419
482
 
483
+ /**
484
+ * Returns the block header up to which the PXE has synced.
485
+ * @returns The synced block header
486
+ */
487
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
488
+ return this.anchorBlockStore.getBlockHeader();
489
+ }
490
+
491
+ /**
492
+ * Returns the contract instance for a given address, if it's registered in the PXE.
493
+ * @param address - The contract address.
494
+ * @returns The contract instance if found, undefined otherwise.
495
+ */
420
496
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
421
497
  return this.contractStore.getContractInstance(address);
422
498
  }
@@ -630,11 +706,12 @@ export class PXE {
630
706
  * (where validators prove the public portion).
631
707
  *
632
708
  * @param txRequest - An authenticated tx request ready for proving
709
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
633
710
  * @returns A result containing the proof and public inputs of the tail circuit.
634
711
  * @throws If contract code not found, or public simulation reverts.
635
712
  * Also throws if simulatePublic is true and public simulation reverts.
636
713
  */
637
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
714
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
638
715
  let privateExecutionResult: PrivateExecutionResult;
639
716
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
640
717
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -645,7 +722,7 @@ export class PXE {
645
722
  await this.blockStateSynchronizer.sync();
646
723
  const syncTime = syncTimer.ms();
647
724
  const contractFunctionSimulator = this.#getSimulatorForTx();
648
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
725
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
649
726
 
650
727
  const {
651
728
  publicInputs,
@@ -709,17 +786,13 @@ export class PXE {
709
786
 
710
787
  /**
711
788
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
712
- *
713
- * @param txRequest - An authenticated tx request ready for simulation
714
- * @param msgSender - (Optional) The message sender to use for the simulation.
715
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
789
+ * @param txRequest - An authenticated tx request ready for simulation.
716
790
  * @returns A trace of the program execution with gate counts.
717
791
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
718
792
  */
719
793
  public profileTx(
720
794
  txRequest: TxExecutionRequest,
721
- profileMode: 'full' | 'execution-steps' | 'gates',
722
- skipProofGeneration: boolean = true,
795
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
723
796
  ): Promise<TxProfileResult> {
724
797
  // We disable concurrent profiles for consistency with simulateTx.
725
798
  return this.#putInJobQueue(async jobId => {
@@ -742,12 +815,7 @@ export class PXE {
742
815
  const syncTime = syncTimer.ms();
743
816
 
744
817
  const contractFunctionSimulator = this.#getSimulatorForTx();
745
- const privateExecutionResult = await this.#executePrivate(
746
- contractFunctionSimulator,
747
- txRequest,
748
- undefined,
749
- jobId,
750
- );
818
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
751
819
 
752
820
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
753
821
  txRequest,
@@ -804,12 +872,7 @@ export class PXE {
804
872
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
805
873
  *
806
874
  *
807
- * @param txRequest - An authenticated tx request ready for simulation
808
- * @param simulatePublic - Whether to simulate the public part of the transaction.
809
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
810
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
811
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
812
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
875
+ * @param txRequest - An authenticated tx request ready for simulation.
813
876
  * @returns A simulated transaction result object that includes public and private return values.
814
877
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
815
878
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -818,11 +881,7 @@ export class PXE {
818
881
  */
819
882
  public simulateTx(
820
883
  txRequest: TxExecutionRequest,
821
- simulatePublic: boolean,
822
- skipTxValidation: boolean = false,
823
- skipFeeEnforcement: boolean = false,
824
- overrides?: SimulationOverrides,
825
- scopes?: AztecAddress[],
884
+ { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
826
885
  ): Promise<TxSimulationResult> {
827
886
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
828
887
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -850,7 +909,14 @@ export class PXE {
850
909
  // Temporary: in case there are overrides, we have to skip the kernels or validations
851
910
  // will fail. Consider handing control to the user/wallet on whether they want to run them
852
911
  // or not.
853
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
912
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
913
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
914
+ const skipKernels = hasOverriddenContracts;
915
+
916
+ // Set overridden contracts on the sync service so it knows to skip syncing them
917
+ if (hasOverriddenContracts) {
918
+ this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
919
+ }
854
920
 
855
921
  // Execution of private functions only; no proving, and no kernel logic.
856
922
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
@@ -861,7 +927,8 @@ export class PXE {
861
927
  if (skipKernels) {
862
928
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
863
929
  privateExecutionResult,
864
- this.contractStore,
930
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
931
+ this.node,
865
932
  ));
866
933
  } else {
867
934
  // Kernel logic, plus proving of all private functions and kernels.
@@ -939,25 +1006,19 @@ export class PXE {
939
1006
  inspect(txRequest),
940
1007
  `simulatePublic=${simulatePublic}`,
941
1008
  `skipTxValidation=${skipTxValidation}`,
942
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1009
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
943
1010
  );
944
1011
  }
945
1012
  });
946
1013
  }
947
1014
 
948
1015
  /**
949
- * Simulate the execution of a contract utility function.
950
- *
1016
+ * Simulates the execution of a contract utility function.
951
1017
  * @param call - The function call containing the function details, arguments, and target contract address.
952
- * @param authwits - (Optional) The authentication witnesses required for the function call.
953
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
954
- * default to all.
955
- * @returns The result of the utility function call, structured based on the function ABI.
956
1018
  */
957
1019
  public simulateUtility(
958
1020
  call: FunctionCall,
959
- authwits?: AuthWitness[],
960
- scopes?: AztecAddress[],
1021
+ { authwits, scopes }: SimulateUtilityOpts = { scopes: 'ALL_SCOPES' },
961
1022
  ): Promise<UtilitySimulationResult> {
962
1023
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
963
1024
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -972,15 +1033,14 @@ export class PXE {
972
1033
  const contractFunctionSimulator = this.#getSimulatorForTx();
973
1034
 
974
1035
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
975
- await ensureContractSynced(
1036
+ await this.contractSyncService.ensureContractSynced(
976
1037
  call.to,
977
1038
  call.selector,
978
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
979
- this.node,
980
- this.contractStore,
981
- this.noteStore,
1039
+ (privateSyncCall, execScopes) =>
1040
+ this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
982
1041
  anchorBlockHeader,
983
1042
  jobId,
1043
+ scopes,
984
1044
  );
985
1045
 
986
1046
  const executionResult = await this.#simulateUtility(
@@ -1011,7 +1071,7 @@ export class PXE {
1011
1071
  throw this.#contextualizeError(
1012
1072
  err,
1013
1073
  `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1014
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1074
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1015
1075
  );
1016
1076
  }
1017
1077
  });
@@ -1044,16 +1104,14 @@ export class PXE {
1044
1104
 
1045
1105
  const contractFunctionSimulator = this.#getSimulatorForTx();
1046
1106
 
1047
- await ensureContractSynced(
1107
+ await this.contractSyncService.ensureContractSynced(
1048
1108
  filter.contractAddress,
1049
1109
  null,
1050
- async privateSyncCall =>
1051
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1052
- this.node,
1053
- this.contractStore,
1054
- this.noteStore,
1110
+ async (privateSyncCall, execScopes) =>
1111
+ await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1055
1112
  anchorBlockHeader,
1056
1113
  jobId,
1114
+ filter.scopes,
1057
1115
  );
1058
1116
  });
1059
1117
 
@@ -316,15 +316,15 @@ export class ContractStore {
316
316
  throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
317
317
  }
318
318
 
319
- return {
319
+ return FunctionCall.from({
320
320
  name: functionDao.name,
321
- args: encodeArguments(functionDao, args),
321
+ to,
322
322
  selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
323
323
  type: functionDao.functionType,
324
- to,
325
324
  hideMsgSender: false,
326
325
  isStatic: functionDao.isStatic,
326
+ args: encodeArguments(functionDao, args),
327
327
  returnTypes: functionDao.returnTypes,
328
- };
328
+ });
329
329
  }
330
330
  }
@@ -3,9 +3,10 @@ import type { Fr } from '@aztec/foundation/schemas';
3
3
  import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
4
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
5
  import type { DataInBlock } from '@aztec/stdlib/block';
6
- import { NoteDao, NoteStatus, type NotesFilter } from '@aztec/stdlib/note';
6
+ import { NoteDao, NoteStatus } from '@aztec/stdlib/note';
7
7
 
8
8
  import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
9
+ import type { NotesFilter } from '../../notes_filter.js';
9
10
  import { StoredNote } from './stored_note.js';
10
11
 
11
12
  /**
@@ -103,11 +104,10 @@ export class NoteStore implements StagedStore {
103
104
  * @params jobId - the job context to read from.
104
105
  * @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
105
106
  * returned once if this is the case)
106
- * @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
107
107
  */
108
108
  getNotes(filter: NotesFilter, jobId: string): Promise<NoteDao[]> {
109
- if (filter.scopes !== undefined && filter.scopes.length === 0) {
110
- return Promise.reject(new Error('Trying to get notes with an empty scopes array'));
109
+ if (filter.scopes !== 'ALL_SCOPES' && filter.scopes.length === 0) {
110
+ return Promise.resolve([]);
111
111
  }
112
112
 
113
113
  return this.#store.transactionAsync(async () => {
@@ -180,7 +180,10 @@ export class NoteStore implements StagedStore {
180
180
  continue;
181
181
  }
182
182
 
183
- if (filter.scopes && note.scopes.intersection(new Set(filter.scopes.map(s => s.toString()))).size === 0) {
183
+ if (
184
+ filter.scopes !== 'ALL_SCOPES' &&
185
+ note.scopes.intersection(new Set(filter.scopes.map(s => s.toString()))).size === 0
186
+ ) {
184
187
  continue;
185
188
  }
186
189
 
@@ -220,6 +223,10 @@ export class NoteStore implements StagedStore {
220
223
  return Promise.resolve([]);
221
224
  }
222
225
 
226
+ if (nullifiers.some(n => n.l2BlockNumber === 0)) {
227
+ return Promise.reject(new Error('applyNullifiers: nullifiers cannot have been emitted at block 0'));
228
+ }
229
+
223
230
  return this.#withJobLock(jobId, () =>
224
231
  this.#store.transactionAsync(async () => {
225
232
  const notesToNullify = await Promise.all(
@@ -1,6 +1,6 @@
1
1
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2
2
  import type { BlockHash } from '@aztec/stdlib/block';
3
- import { MAX_LOGS_PER_TAG } from '@aztec/stdlib/interfaces/api-limit';
3
+ import { MAX_LOGS_PER_TAG, MAX_RPC_LEN } from '@aztec/stdlib/interfaces/api-limit';
4
4
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
5
5
  import type { SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
6
6
 
@@ -31,6 +31,26 @@ async function getAllPages<T>(numTags: number, fetchPage: (page: number) => Prom
31
31
  return allResultsPerTag;
32
32
  }
33
33
 
34
+ /**
35
+ * Splits tags into chunks of MAX_RPC_LEN, fetches logs for each chunk using getAllPages, then stitches the results
36
+ * back into a single array preserving the original tag order.
37
+ */
38
+ async function getAllPagesInBatches<Tag, T>(
39
+ tags: Tag[],
40
+ fetchAllPagesForBatch: (batch: Tag[]) => Promise<T[][]>,
41
+ ): Promise<T[][]> {
42
+ if (tags.length <= MAX_RPC_LEN) {
43
+ return fetchAllPagesForBatch(tags);
44
+ }
45
+
46
+ const batches: Tag[][] = [];
47
+ for (let i = 0; i < tags.length; i += MAX_RPC_LEN) {
48
+ batches.push(tags.slice(i, i + MAX_RPC_LEN));
49
+ }
50
+ const batchResults = await Promise.all(batches.map(fetchAllPagesForBatch));
51
+ return batchResults.flat();
52
+ }
53
+
34
54
  /**
35
55
  * Fetches all private logs for the given tags, automatically paginating through all pages.
36
56
  * @param aztecNode - The Aztec node to query.
@@ -44,7 +64,9 @@ export function getAllPrivateLogsByTags(
44
64
  tags: SiloedTag[],
45
65
  anchorBlockHash: BlockHash,
46
66
  ): Promise<TxScopedL2Log[][]> {
47
- return getAllPages(tags.length, page => aztecNode.getPrivateLogsByTags(tags, page, anchorBlockHash));
67
+ return getAllPagesInBatches(tags, batch =>
68
+ getAllPages(batch.length, page => aztecNode.getPrivateLogsByTags(batch, page, anchorBlockHash)),
69
+ );
48
70
  }
49
71
 
50
72
  /**
@@ -62,7 +84,9 @@ export function getAllPublicLogsByTagsFromContract(
62
84
  tags: Tag[],
63
85
  anchorBlockHash: BlockHash,
64
86
  ): Promise<TxScopedL2Log[][]> {
65
- return getAllPages(tags.length, page =>
66
- aztecNode.getPublicLogsByTagsFromContract(contractAddress, tags, page, anchorBlockHash),
87
+ return getAllPagesInBatches(tags, batch =>
88
+ getAllPages(batch.length, page =>
89
+ aztecNode.getPublicLogsByTagsFromContract(contractAddress, batch, page, anchorBlockHash),
90
+ ),
67
91
  );
68
92
  }
@@ -30,7 +30,7 @@ export async function loadPrivateLogsForSenderRecipientPair(
30
30
  // (highestAgedIndex, highestFinalizedIndex + WINDOW_LEN]
31
31
  //
32
32
  // highestAgedIndex is the highest index that was used in a tx that is included in a block at least
33
- // `MAX_INCLUDE_BY_TIMESTAMP_DURATION` seconds ago.
33
+ // `MAX_TX_LIFETIME` seconds ago.
34
34
  // highestFinalizedIndex is the highest index that was used in a tx that is included in a finalized block.
35
35
  //
36
36
  // "(" denotes an open end of the range - the index is not included in the range.
@@ -42,19 +42,19 @@ export async function loadPrivateLogsForSenderRecipientPair(
42
42
  // ever appear.
43
43
  //
44
44
  // This relies on the "maximum inclusion timestamp" rule enforced by the kernel and rollup circuits:
45
- // - a transaction's maximum inclusion timestamp is at most `MAX_INCLUDE_BY_TIMESTAMP_DURATION` seconds after
45
+ // - a transaction's maximum inclusion timestamp is at most `MAX_TX_LIFETIME` seconds after
46
46
  // the timestamp of its anchor block; and
47
47
  // - a rollup only includes transactions whose inclusion timestamp is >= the L2 block's timestamp.
48
48
  //
49
49
  // Suppose some device used index `I` in a transaction anchored to block `B_N` at time `N`, and that block is now at
50
- // least `MAX_INCLUDE_BY_TIMESTAMP_DURATION` seconds in the past. Then there is no possibility of any *other* device
50
+ // least `MAX_TX_LIFETIME` seconds in the past. Then there is no possibility of any *other* device
51
51
  // trying to use an index <= `I` while anchoring to a *newer* block than `B_N` because if we were anchoring to
52
52
  // a newer block than `B_N` then we would already have seen the log with index `I` and hence the device would have
53
53
  // chosen a larger index.
54
54
  // If that *other* device would anchor to a block older than `B_N` then that tx could never be included in a block
55
55
  // because it would already have been expired.
56
56
  //
57
- // Therefore, once we see that index `I` has been used in a block that is at least `MAX_INCLUDE_BY_TIMESTAMP_DURATION`
57
+ // Therefore, once we see that index `I` has been used in a block that is at least `MAX_TX_LIFETIME`
58
58
  // seconds old, we can safely stop syncing logs for all indexes <= `I` and set highestAgedIndex = `I`.
59
59
  //
60
60
  // ## Explanation of the upper bound `highestFinalizedIndex + WINDOW_LEN`
@@ -1,4 +1,4 @@
1
- import { MAX_INCLUDE_BY_TIMESTAMP_DURATION } from '@aztec/constants';
1
+ import { MAX_TX_LIFETIME } from '@aztec/constants';
2
2
  import type { TxScopedL2Log } from '@aztec/stdlib/logs';
3
3
 
4
4
  /**
@@ -16,7 +16,7 @@ export function findHighestIndexes(
16
16
  const ageInSeconds = currentTimestamp - log.blockTimestamp;
17
17
 
18
18
  if (
19
- ageInSeconds >= BigInt(MAX_INCLUDE_BY_TIMESTAMP_DURATION) &&
19
+ ageInSeconds >= BigInt(MAX_TX_LIFETIME) &&
20
20
  (highestAgedIndex === undefined || taggingIndex > highestAgedIndex)
21
21
  ) {
22
22
  highestAgedIndex = taggingIndex;