@aztec/pxe 0.0.1-commit.0b941701 → 0.0.1-commit.0c875d939

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 (160) 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 +5 -3
  5. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  6. package/dest/block_synchronizer/block_synchronizer.js +11 -5
  7. package/dest/contract_function_simulator/contract_function_simulator.d.ts +54 -30
  8. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  9. package/dest/contract_function_simulator/contract_function_simulator.js +169 -65
  10. package/dest/contract_function_simulator/oracle/interfaces.d.ts +10 -10
  11. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  12. package/dest/contract_function_simulator/oracle/oracle.d.ts +5 -5
  13. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  14. package/dest/contract_function_simulator/oracle/oracle.js +38 -26
  15. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +36 -36
  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 +74 -21
  18. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +53 -29
  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 +85 -61
  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} +13 -12
  27. package/dest/debug/pxe_debug_utils.d.ts +24 -10
  28. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  29. package/dest/debug/pxe_debug_utils.js +28 -18
  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 +21 -7
  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 +2 -2
  40. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  41. package/dest/entrypoints/client/lazy/utils.js +22 -8
  42. package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
  43. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  44. package/dest/entrypoints/server/index.d.ts +4 -2
  45. package/dest/entrypoints/server/index.d.ts.map +1 -1
  46. package/dest/entrypoints/server/index.js +3 -1
  47. package/dest/entrypoints/server/utils.d.ts +1 -1
  48. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  49. package/dest/entrypoints/server/utils.js +28 -9
  50. package/dest/events/event_service.d.ts +4 -5
  51. package/dest/events/event_service.d.ts.map +1 -1
  52. package/dest/events/event_service.js +5 -6
  53. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  54. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  55. package/dest/job_coordinator/job_coordinator.js +3 -2
  56. package/dest/logs/log_service.d.ts +7 -5
  57. package/dest/logs/log_service.d.ts.map +1 -1
  58. package/dest/logs/log_service.js +15 -25
  59. package/dest/notes/note_service.d.ts +7 -7
  60. package/dest/notes/note_service.d.ts.map +1 -1
  61. package/dest/notes/note_service.js +9 -9
  62. package/dest/notes_filter.d.ts +25 -0
  63. package/dest/notes_filter.d.ts.map +1 -0
  64. package/dest/notes_filter.js +4 -0
  65. package/dest/oracle_version.d.ts +3 -3
  66. package/dest/oracle_version.d.ts.map +1 -1
  67. package/dest/oracle_version.js +2 -2
  68. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  69. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  70. package/dest/private_kernel/private_kernel_execution_prover.js +2 -2
  71. package/dest/private_kernel/private_kernel_oracle.d.ts +3 -3
  72. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  73. package/dest/pxe.d.ts +69 -23
  74. package/dest/pxe.d.ts.map +1 -1
  75. package/dest/pxe.js +76 -46
  76. package/dest/storage/address_store/address_store.d.ts +1 -1
  77. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  78. package/dest/storage/address_store/address_store.js +12 -11
  79. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  80. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  81. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  82. package/dest/storage/capsule_store/capsule_store.js +6 -8
  83. package/dest/storage/contract_store/contract_store.d.ts +1 -1
  84. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  85. package/dest/storage/contract_store/contract_store.js +27 -18
  86. package/dest/storage/metadata.d.ts +1 -1
  87. package/dest/storage/metadata.js +1 -1
  88. package/dest/storage/note_store/note_store.d.ts +13 -3
  89. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  90. package/dest/storage/note_store/note_store.js +147 -107
  91. package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
  92. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  93. package/dest/storage/private_event_store/private_event_store.js +84 -61
  94. package/dest/storage/private_event_store/stored_private_event.d.ts +4 -4
  95. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -1
  96. package/dest/storage/private_event_store/stored_private_event.js +2 -2
  97. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +1 -1
  98. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  99. package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
  100. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  101. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  102. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  103. package/dest/storage/tagging_store/sender_tagging_store.d.ts +1 -1
  104. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  105. package/dest/storage/tagging_store/sender_tagging_store.js +183 -113
  106. package/dest/tagging/get_all_logs_by_tags.d.ts +4 -4
  107. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  108. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -3
  109. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  110. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -3
  111. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  112. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -3
  113. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  114. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +3 -3
  115. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  116. package/package.json +25 -16
  117. package/src/access_scopes.ts +9 -0
  118. package/src/block_synchronizer/block_synchronizer.ts +23 -19
  119. package/src/contract_function_simulator/contract_function_simulator.ts +317 -120
  120. package/src/contract_function_simulator/oracle/interfaces.ts +12 -12
  121. package/src/contract_function_simulator/oracle/oracle.ts +41 -24
  122. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +97 -101
  123. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +137 -69
  124. package/src/contract_sync/contract_sync_service.ts +152 -0
  125. package/src/contract_sync/{index.ts → helpers.ts} +21 -21
  126. package/src/debug/pxe_debug_utils.ts +63 -19
  127. package/src/entrypoints/client/bundle/index.ts +2 -0
  128. package/src/entrypoints/client/bundle/utils.ts +16 -15
  129. package/src/entrypoints/client/lazy/index.ts +2 -0
  130. package/src/entrypoints/client/lazy/utils.ts +17 -15
  131. package/src/entrypoints/pxe_creation_options.ts +2 -1
  132. package/src/entrypoints/server/index.ts +3 -1
  133. package/src/entrypoints/server/utils.ts +22 -26
  134. package/src/events/event_service.ts +4 -6
  135. package/src/job_coordinator/job_coordinator.ts +4 -3
  136. package/src/logs/log_service.ts +20 -32
  137. package/src/notes/note_service.ts +9 -10
  138. package/src/notes_filter.ts +26 -0
  139. package/src/oracle_version.ts +2 -2
  140. package/src/private_kernel/private_kernel_execution_prover.ts +6 -3
  141. package/src/private_kernel/private_kernel_oracle.ts +2 -2
  142. package/src/pxe.ts +164 -92
  143. package/src/storage/address_store/address_store.ts +15 -15
  144. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  145. package/src/storage/capsule_store/capsule_store.ts +8 -8
  146. package/src/storage/contract_store/contract_store.ts +26 -15
  147. package/src/storage/metadata.ts +1 -1
  148. package/src/storage/note_store/note_store.ts +169 -132
  149. package/src/storage/private_event_store/private_event_store.ts +102 -81
  150. package/src/storage/private_event_store/stored_private_event.ts +3 -3
  151. package/src/storage/tagging_store/recipient_tagging_store.ts +31 -21
  152. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  153. package/src/storage/tagging_store/sender_tagging_store.ts +210 -126
  154. package/src/tagging/get_all_logs_by_tags.ts +3 -3
  155. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +2 -2
  156. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +2 -2
  157. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +2 -2
  158. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +3 -3
  159. package/dest/contract_sync/index.d.ts +0 -23
  160. package/dest/contract_sync/index.d.ts.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { vkAsFieldsMegaHonk } from '@aztec/foundation/crypto/keys';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { createLogger } from '@aztec/foundation/log';
3
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
4
4
  import { pushTestData } from '@aztec/foundation/testing';
5
5
  import { Timer } from '@aztec/foundation/timer';
6
6
  import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
@@ -56,13 +56,16 @@ export interface PrivateKernelExecutionProverConfig {
56
56
  * inform state tree updates.
57
57
  */
58
58
  export class PrivateKernelExecutionProver {
59
- private log = createLogger('pxe:private-kernel-execution-prover');
59
+ private log: Logger;
60
60
 
61
61
  constructor(
62
62
  private oracle: PrivateKernelOracle,
63
63
  private proofCreator: PrivateKernelProver,
64
64
  private fakeProofs = false,
65
- ) {}
65
+ bindings?: LoggerBindings,
66
+ ) {
67
+ this.log = createLogger('pxe:private-kernel-execution-prover', bindings);
68
+ }
66
69
 
67
70
  /**
68
71
  * Generate a proof for a given transaction request and execution result.
@@ -7,7 +7,7 @@ import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-type
7
7
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
8
8
  import type { FunctionSelector } from '@aztec/stdlib/abi';
9
9
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
10
- import { L2BlockHash } from '@aztec/stdlib/block';
10
+ import { BlockHash } from '@aztec/stdlib/block';
11
11
  import {
12
12
  type ContractInstanceWithAddress,
13
13
  computeContractClassIdPreimage,
@@ -30,7 +30,7 @@ export class PrivateKernelOracle {
30
30
  private contractStore: ContractStore,
31
31
  private keyStore: KeyStore,
32
32
  private node: AztecNode,
33
- private blockHash: L2BlockHash,
33
+ private blockHash: BlockHash,
34
34
  ) {}
35
35
 
36
36
  /** Retrieves the preimage of a contract address from the registered contract instances db. */
package/src/pxe.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
2
  import { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
- import { type Logger, createLogger } from '@aztec/foundation/log';
4
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
5
5
  import { SerialQueue } from '@aztec/foundation/queue';
6
6
  import { Timer } from '@aztec/foundation/timer';
7
7
  import { KeyStore } from '@aztec/key-store';
@@ -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,21 +173,27 @@ 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) {
185
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
186
+ const bindings: LoggerBindings | undefined =
187
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
188
+
131
189
  const log =
132
190
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
133
191
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
134
192
  : loggerOrSuffix;
135
193
 
136
- const proverEnabled = !!config.proverEnabled;
194
+ const info = await node.getNodeInfo();
195
+
196
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
137
197
  const addressStore = new AddressStore(store);
138
198
  const privateEventStore = new PrivateEventStore(store);
139
199
  const contractStore = new ContractStore(store);
@@ -145,6 +205,12 @@ export class PXE {
145
205
  const capsuleStore = new CapsuleStore(store);
146
206
  const keyStore = new KeyStore(store);
147
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
+ );
148
214
  const synchronizer = new BlockSynchronizer(
149
215
  node,
150
216
  store,
@@ -152,20 +218,22 @@ export class PXE {
152
218
  noteStore,
153
219
  privateEventStore,
154
220
  tipsStore,
221
+ contractSyncService,
155
222
  config,
156
- loggerOrSuffix,
223
+ bindings,
157
224
  );
158
225
 
159
- const jobCoordinator = new JobCoordinator(store);
226
+ const jobCoordinator = new JobCoordinator(store, bindings);
160
227
  jobCoordinator.registerStores([
161
228
  capsuleStore,
162
229
  senderTaggingStore,
163
230
  recipientTaggingStore,
164
231
  privateEventStore,
165
232
  noteStore,
233
+ contractSyncService,
166
234
  ]);
167
235
 
168
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
236
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
169
237
 
170
238
  const jobQueue = new SerialQueue();
171
239
 
@@ -182,6 +250,7 @@ export class PXE {
182
250
  recipientTaggingStore,
183
251
  addressStore,
184
252
  privateEventStore,
253
+ contractSyncService,
185
254
  simulator,
186
255
  proverEnabled,
187
256
  proofCreator,
@@ -192,12 +261,15 @@ export class PXE {
192
261
  debugUtils,
193
262
  );
194
263
 
195
- debugUtils.setPXE(pxe);
264
+ debugUtils.setPXEHelpers(
265
+ pxe.#putInJobQueue.bind(pxe),
266
+ pxe.#getSimulatorForTx.bind(pxe),
267
+ pxe.#simulateUtility.bind(pxe),
268
+ );
196
269
 
197
270
  pxe.jobQueue.start();
198
271
 
199
272
  await pxe.#registerProtocolContracts();
200
- const info = await node.getNodeInfo();
201
273
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
202
274
  return pxe;
203
275
  }
@@ -207,20 +279,20 @@ export class PXE {
207
279
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
208
280
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
209
281
 
210
- return new ContractFunctionSimulator(
211
- proxyContractStore,
212
- this.noteStore,
213
- this.keyStore,
214
- this.addressStore,
215
- BenchmarkedNodeFactory.create(this.node),
216
- this.anchorBlockStore,
217
- this.senderTaggingStore,
218
- this.recipientTaggingStore,
219
- this.senderAddressBookStore,
220
- this.capsuleStore,
221
- this.privateEventStore,
222
- this.simulator,
223
- );
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
+ });
224
296
  }
225
297
 
226
298
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -286,7 +358,7 @@ export class PXE {
286
358
  async #executePrivate(
287
359
  contractFunctionSimulator: ContractFunctionSimulator,
288
360
  txRequest: TxExecutionRequest,
289
- scopes: AztecAddress[] | undefined,
361
+ scopes: AccessScopes,
290
362
  jobId: string,
291
363
  ): Promise<PrivateExecutionResult> {
292
364
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -294,27 +366,23 @@ export class PXE {
294
366
  try {
295
367
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
296
368
 
297
- await ensureContractSynced(
369
+ await this.contractSyncService.ensureContractSynced(
298
370
  contractAddress,
299
371
  functionSelector,
300
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
301
- this.node,
302
- this.contractStore,
372
+ (privateSyncCall, execScopes) =>
373
+ this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
303
374
  anchorBlockHeader,
375
+ jobId,
376
+ scopes,
304
377
  );
305
378
 
306
- const result = await contractFunctionSimulator.run(
307
- txRequest,
379
+ const result = await contractFunctionSimulator.run(txRequest, {
308
380
  contractAddress,
309
- functionSelector,
310
- undefined,
381
+ selector: functionSelector,
311
382
  anchorBlockHeader,
312
- // The sender for tags is set by contracts, typically by an account
313
- // contract entrypoint
314
- undefined, // senderForTags
315
383
  scopes,
316
384
  jobId,
317
- );
385
+ });
318
386
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
319
387
  return result;
320
388
  } catch (err) {
@@ -339,7 +407,7 @@ export class PXE {
339
407
  contractFunctionSimulator: ContractFunctionSimulator,
340
408
  call: FunctionCall,
341
409
  authWitnesses: AuthWitness[] | undefined,
342
- scopes: AztecAddress[] | undefined,
410
+ scopes: AccessScopes,
343
411
  jobId: string,
344
412
  ) {
345
413
  try {
@@ -400,13 +468,31 @@ export class PXE {
400
468
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
401
469
  const anchorBlockHash = await anchorBlockHeader.hash();
402
470
  const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
403
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
471
+ const kernelTraceProver = new PrivateKernelExecutionProver(
472
+ kernelOracle,
473
+ proofCreator,
474
+ !this.proverEnabled,
475
+ this.log.getBindings(),
476
+ );
404
477
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
405
478
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
406
479
  }
407
480
 
408
481
  // Public API
409
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
+ */
410
496
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
411
497
  return this.contractStore.getContractInstance(address);
412
498
  }
@@ -620,11 +706,12 @@ export class PXE {
620
706
  * (where validators prove the public portion).
621
707
  *
622
708
  * @param txRequest - An authenticated tx request ready for proving
709
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
623
710
  * @returns A result containing the proof and public inputs of the tail circuit.
624
711
  * @throws If contract code not found, or public simulation reverts.
625
712
  * Also throws if simulatePublic is true and public simulation reverts.
626
713
  */
627
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
714
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
628
715
  let privateExecutionResult: PrivateExecutionResult;
629
716
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
630
717
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -635,7 +722,7 @@ export class PXE {
635
722
  await this.blockStateSynchronizer.sync();
636
723
  const syncTime = syncTimer.ms();
637
724
  const contractFunctionSimulator = this.#getSimulatorForTx();
638
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
725
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
639
726
 
640
727
  const {
641
728
  publicInputs,
@@ -699,17 +786,13 @@ export class PXE {
699
786
 
700
787
  /**
701
788
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
702
- *
703
- * @param txRequest - An authenticated tx request ready for simulation
704
- * @param msgSender - (Optional) The message sender to use for the simulation.
705
- * @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.
706
790
  * @returns A trace of the program execution with gate counts.
707
791
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
708
792
  */
709
793
  public profileTx(
710
794
  txRequest: TxExecutionRequest,
711
- profileMode: 'full' | 'execution-steps' | 'gates',
712
- skipProofGeneration: boolean = true,
795
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
713
796
  ): Promise<TxProfileResult> {
714
797
  // We disable concurrent profiles for consistency with simulateTx.
715
798
  return this.#putInJobQueue(async jobId => {
@@ -732,12 +815,7 @@ export class PXE {
732
815
  const syncTime = syncTimer.ms();
733
816
 
734
817
  const contractFunctionSimulator = this.#getSimulatorForTx();
735
- const privateExecutionResult = await this.#executePrivate(
736
- contractFunctionSimulator,
737
- txRequest,
738
- undefined,
739
- jobId,
740
- );
818
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
741
819
 
742
820
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
743
821
  txRequest,
@@ -794,12 +872,7 @@ export class PXE {
794
872
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
795
873
  *
796
874
  *
797
- * @param txRequest - An authenticated tx request ready for simulation
798
- * @param simulatePublic - Whether to simulate the public part of the transaction.
799
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
800
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
801
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
802
- * @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.
803
876
  * @returns A simulated transaction result object that includes public and private return values.
804
877
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
805
878
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -808,11 +881,7 @@ export class PXE {
808
881
  */
809
882
  public simulateTx(
810
883
  txRequest: TxExecutionRequest,
811
- simulatePublic: boolean,
812
- skipTxValidation: boolean = false,
813
- skipFeeEnforcement: boolean = false,
814
- overrides?: SimulationOverrides,
815
- scopes?: AztecAddress[],
884
+ { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
816
885
  ): Promise<TxSimulationResult> {
817
886
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
818
887
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -840,7 +909,14 @@ export class PXE {
840
909
  // Temporary: in case there are overrides, we have to skip the kernels or validations
841
910
  // will fail. Consider handing control to the user/wallet on whether they want to run them
842
911
  // or not.
843
- 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
+ }
844
920
 
845
921
  // Execution of private functions only; no proving, and no kernel logic.
846
922
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
@@ -851,7 +927,8 @@ export class PXE {
851
927
  if (skipKernels) {
852
928
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
853
929
  privateExecutionResult,
854
- this.contractStore,
930
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
931
+ this.node,
855
932
  ));
856
933
  } else {
857
934
  // Kernel logic, plus proving of all private functions and kernels.
@@ -929,25 +1006,19 @@ export class PXE {
929
1006
  inspect(txRequest),
930
1007
  `simulatePublic=${simulatePublic}`,
931
1008
  `skipTxValidation=${skipTxValidation}`,
932
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1009
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
933
1010
  );
934
1011
  }
935
1012
  });
936
1013
  }
937
1014
 
938
1015
  /**
939
- * Simulate the execution of a contract utility function.
940
- *
1016
+ * Simulates the execution of a contract utility function.
941
1017
  * @param call - The function call containing the function details, arguments, and target contract address.
942
- * @param authwits - (Optional) The authentication witnesses required for the function call.
943
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
944
- * default to all.
945
- * @returns The result of the utility function call, structured based on the function ABI.
946
1018
  */
947
1019
  public simulateUtility(
948
1020
  call: FunctionCall,
949
- authwits?: AuthWitness[],
950
- scopes?: AztecAddress[],
1021
+ { authwits, scopes }: SimulateUtilityOpts = { scopes: 'ALL_SCOPES' },
951
1022
  ): Promise<UtilitySimulationResult> {
952
1023
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
953
1024
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -962,13 +1033,14 @@ export class PXE {
962
1033
  const contractFunctionSimulator = this.#getSimulatorForTx();
963
1034
 
964
1035
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
965
- await ensureContractSynced(
1036
+ await this.contractSyncService.ensureContractSynced(
966
1037
  call.to,
967
1038
  call.selector,
968
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
969
- this.node,
970
- this.contractStore,
1039
+ (privateSyncCall, execScopes) =>
1040
+ this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
971
1041
  anchorBlockHeader,
1042
+ jobId,
1043
+ scopes,
972
1044
  );
973
1045
 
974
1046
  const executionResult = await this.#simulateUtility(
@@ -999,7 +1071,7 @@ export class PXE {
999
1071
  throw this.#contextualizeError(
1000
1072
  err,
1001
1073
  `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1002
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1074
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1003
1075
  );
1004
1076
  }
1005
1077
  });
@@ -1032,14 +1104,14 @@ export class PXE {
1032
1104
 
1033
1105
  const contractFunctionSimulator = this.#getSimulatorForTx();
1034
1106
 
1035
- await ensureContractSynced(
1107
+ await this.contractSyncService.ensureContractSynced(
1036
1108
  filter.contractAddress,
1037
1109
  null,
1038
- async privateSyncCall =>
1039
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1040
- this.node,
1041
- this.contractStore,
1110
+ async (privateSyncCall, execScopes) =>
1111
+ await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1042
1112
  anchorBlockHeader,
1113
+ jobId,
1114
+ filter.scopes,
1043
1115
  );
1044
1116
  });
1045
1117
 
@@ -43,23 +43,23 @@ export class AddressStore {
43
43
  });
44
44
  }
45
45
 
46
- async #getCompleteAddress(address: AztecAddress): Promise<CompleteAddress | undefined> {
47
- const index = await this.#completeAddressIndex.getAsync(address.toString());
48
- if (index === undefined) {
49
- return undefined;
50
- }
51
-
52
- const value = await this.#completeAddresses.atAsync(index);
53
- return value ? await CompleteAddress.fromBuffer(value) : undefined;
54
- }
55
-
56
46
  getCompleteAddress(account: AztecAddress): Promise<CompleteAddress | undefined> {
57
- return this.#getCompleteAddress(account);
47
+ return this.#store.transactionAsync(async () => {
48
+ const index = await this.#completeAddressIndex.getAsync(account.toString());
49
+ if (index === undefined) {
50
+ return undefined;
51
+ }
52
+
53
+ const value = await this.#completeAddresses.atAsync(index);
54
+ return value ? await CompleteAddress.fromBuffer(value) : undefined;
55
+ });
58
56
  }
59
57
 
60
- async getCompleteAddresses(): Promise<CompleteAddress[]> {
61
- return await Promise.all(
62
- (await toArray(this.#completeAddresses.valuesAsync())).map(v => CompleteAddress.fromBuffer(v)),
63
- );
58
+ getCompleteAddresses(): Promise<CompleteAddress[]> {
59
+ return this.#store.transactionAsync(async () => {
60
+ return await Promise.all(
61
+ (await toArray(this.#completeAddresses.valuesAsync())).map(v => CompleteAddress.fromBuffer(v)),
62
+ );
63
+ });
64
64
  }
65
65
  }
@@ -10,6 +10,14 @@ export class AnchorBlockStore {
10
10
  this.#synchronizedHeader = this.#store.openSingleton('header');
11
11
  }
12
12
 
13
+ /**
14
+ * Sets the currently synchronized block
15
+ *
16
+ * Important: this method is only called from BlockSynchronizer, and since we need it to run atomically with other
17
+ * stores in the case of a reorg, it MUST NOT be wrapped in a `transactionAsync` call. Doing so would result in a
18
+ * deadlock when the backend is IndexedDB, because `transactionAsync` is not designed to support reentrancy.
19
+ *
20
+ */
13
21
  async setHeader(header: BlockHeader): Promise<void> {
14
22
  await this.#synchronizedHeader.set(header.toBuffer());
15
23
  }
@@ -57,14 +57,14 @@ export class CapsuleStore implements StagedStore {
57
57
  */
58
58
  async #getFromStage(jobId: string, dbSlotKey: string): Promise<Buffer | null | undefined> {
59
59
  const jobStagedCapsules = this.#getJobStagedCapsules(jobId);
60
- let staged: Buffer | null | undefined = jobStagedCapsules.get(dbSlotKey);
61
- // Note that if staged === null, we marked it for deletion, so we don't want to
62
- // re-read it from DB
63
- if (staged === undefined) {
64
- // If we don't have a staged version of this dbSlotKey, first we check if there's one in DB
65
- staged = await this.#loadCapsuleFromDb(dbSlotKey);
66
- }
67
- return staged;
60
+ const staged: Buffer | null | undefined = jobStagedCapsules.get(dbSlotKey);
61
+
62
+ // Always issue DB read to keep IndexedDB transaction alive, even if the value is in the job staged data. This
63
+ // keeps IndexedDB transactions alive (they auto-commit when a new micro-task starts and there are no pending read
64
+ // requests). The staged value still takes precedence if it exists (including null for deletions).
65
+ const dbValue = await this.#loadCapsuleFromDb(dbSlotKey);
66
+
67
+ return staged !== undefined ? staged : dbValue;
68
68
  }
69
69
 
70
70
  /**