@aztec/pxe 0.0.1-commit.6d63667d → 0.0.1-commit.86469d5

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 (49) hide show
  1. package/dest/block_synchronizer/block_synchronizer.d.ts +2 -4
  2. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  3. package/dest/block_synchronizer/block_synchronizer.js +1 -7
  4. package/dest/contract_function_simulator/contract_function_simulator.d.ts +2 -4
  5. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  6. package/dest/contract_function_simulator/contract_function_simulator.js +2 -4
  7. package/dest/contract_function_simulator/oracle/interfaces.d.ts +2 -2
  8. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  9. package/dest/contract_function_simulator/oracle/oracle.d.ts +2 -2
  10. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  11. package/dest/contract_function_simulator/oracle/oracle.js +8 -20
  12. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +2 -4
  13. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  14. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +6 -6
  15. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +5 -5
  16. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +7 -14
  18. package/dest/contract_sync/index.d.ts +24 -0
  19. package/dest/contract_sync/index.d.ts.map +1 -0
  20. package/dest/contract_sync/{helpers.js → index.js} +12 -6
  21. package/dest/debug/pxe_debug_utils.d.ts +7 -12
  22. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  23. package/dest/debug/pxe_debug_utils.js +12 -16
  24. package/dest/entrypoints/server/index.d.ts +2 -2
  25. package/dest/entrypoints/server/index.d.ts.map +1 -1
  26. package/dest/entrypoints/server/index.js +1 -1
  27. package/dest/oracle_version.d.ts +2 -2
  28. package/dest/oracle_version.js +2 -2
  29. package/dest/pxe.d.ts +1 -2
  30. package/dest/pxe.d.ts.map +1 -1
  31. package/dest/pxe.js +12 -23
  32. package/package.json +16 -25
  33. package/src/block_synchronizer/block_synchronizer.ts +0 -6
  34. package/src/contract_function_simulator/contract_function_simulator.ts +0 -3
  35. package/src/contract_function_simulator/oracle/interfaces.ts +1 -1
  36. package/src/contract_function_simulator/oracle/oracle.ts +4 -11
  37. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +6 -5
  38. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +7 -14
  39. package/src/contract_sync/{helpers.ts → index.ts} +32 -6
  40. package/src/debug/pxe_debug_utils.ts +13 -46
  41. package/src/entrypoints/server/index.ts +1 -1
  42. package/src/oracle_version.ts +2 -2
  43. package/src/pxe.ts +16 -30
  44. package/dest/contract_sync/contract_sync_service.d.ts +0 -41
  45. package/dest/contract_sync/contract_sync_service.d.ts.map +0 -1
  46. package/dest/contract_sync/contract_sync_service.js +0 -82
  47. package/dest/contract_sync/helpers.d.ts +0 -28
  48. package/dest/contract_sync/helpers.d.ts.map +0 -1
  49. package/src/contract_sync/contract_sync_service.ts +0 -129
@@ -248,19 +248,12 @@ export class Oracle {
248
248
  return [witness.map(toACVMField)];
249
249
  }
250
250
 
251
- async utilityTryGetPublicKeysAndPartialAddress([address]: ACVMField[]): Promise<(ACVMField | ACVMField[])[]> {
251
+ async utilityGetPublicKeysAndPartialAddress([address]: ACVMField[]): Promise<ACVMField[][]> {
252
252
  const parsedAddress = AztecAddress.fromField(Fr.fromString(address));
253
- const result = await this.handlerAsUtility().utilityTryGetPublicKeysAndPartialAddress(parsedAddress);
253
+ const { publicKeys, partialAddress } =
254
+ await this.handlerAsUtility().utilityGetPublicKeysAndPartialAddress(parsedAddress);
254
255
 
255
- // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
256
- // with two fields: `some` (a boolean) and `value` (a field array in this case).
257
- if (result === undefined) {
258
- // No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
259
- return [toACVMField(0), Array(13).fill(toACVMField(0))];
260
- } else {
261
- // Data was found so we set `some` to 1 and return it along with `value`.
262
- return [toACVMField(1), [...result.publicKeys.toFields(), result.partialAddress].map(toACVMField)];
263
- }
256
+ return [[...publicKeys.toFields(), partialAddress].map(toACVMField)];
264
257
  }
265
258
 
266
259
  async utilityGetNotes(
@@ -30,7 +30,7 @@ import {
30
30
  type TxContext,
31
31
  } from '@aztec/stdlib/tx';
32
32
 
33
- import type { ContractSyncService } from '../../contract_sync/contract_sync_service.js';
33
+ import { ensureContractSynced } from '../../contract_sync/index.js';
34
34
  import { NoteService } from '../../notes/note_service.js';
35
35
  import type { AddressStore } from '../../storage/address_store/address_store.js';
36
36
  import type { CapsuleStore } from '../../storage/capsule_store/capsule_store.js';
@@ -93,7 +93,6 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
93
93
  senderAddressBookStore: SenderAddressBookStore,
94
94
  capsuleStore: CapsuleStore,
95
95
  privateEventStore: PrivateEventStore,
96
- private readonly contractSyncService: ContractSyncService,
97
96
  jobId: string,
98
97
  private totalPublicCalldataCount: number = 0,
99
98
  protected sideEffectCounter: number = 0,
@@ -243,7 +242,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
243
242
  sender: AztecAddress,
244
243
  recipient: AztecAddress,
245
244
  ) {
246
- const senderCompleteAddress = await this.getCompleteAddressOrFail(sender);
245
+ const senderCompleteAddress = await this.getCompleteAddress(sender);
247
246
  const senderIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(sender);
248
247
  return DirectionalAppTaggingSecret.compute(
249
248
  senderCompleteAddress,
@@ -538,10 +537,13 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
538
537
 
539
538
  isStaticCall = isStaticCall || this.callContext.isStaticCall;
540
539
 
541
- await this.contractSyncService.ensureContractSynced(
540
+ await ensureContractSynced(
542
541
  targetContractAddress,
543
542
  functionSelector,
544
543
  this.utilityExecutor,
544
+ this.aztecNode,
545
+ this.contractStore,
546
+ this.noteStore,
545
547
  this.anchorBlockHeader,
546
548
  this.jobId,
547
549
  );
@@ -576,7 +578,6 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
576
578
  this.senderAddressBookStore,
577
579
  this.capsuleStore,
578
580
  this.privateEventStore,
579
- this.contractSyncService,
580
581
  this.jobId,
581
582
  this.totalPublicCalldataCount,
582
583
  sideEffectCounter,
@@ -88,16 +88,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
88
88
  * @param pkMHash - The master public key hash.
89
89
  * @returns A Promise that resolves to nullifier keys.
90
90
  * @throws If the keys are not registered in the key store.
91
- * @throws If scopes are defined and the account is not in the scopes.
92
91
  */
93
- public async utilityGetKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
94
- // If scopes are defined, check that the key belongs to an account in the scopes
95
- if (this.scopes && this.scopes.length > 0) {
96
- const [, account] = await this.keyStore.getKeyPrefixAndAccount(pkMHash);
97
- if (!this.scopes.some(scope => scope.equals(account))) {
98
- throw new Error(`Key validation request denied: account ${account.toString()} is not in the allowed scopes.`);
99
- }
100
- }
92
+ public utilityGetKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
101
93
  return this.keyStore.getKeyValidationRequest(pkMHash, this.contractAddress);
102
94
  }
103
95
 
@@ -190,13 +182,14 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
190
182
  /**
191
183
  * Retrieve the complete address associated to a given address.
192
184
  * @param account - The account address.
193
- * @returns A complete address associated with the input address, or `undefined` if not registered.
185
+ * @returns A complete address associated with the input address.
186
+ * @throws An error if the account is not registered in the database.
194
187
  */
195
- public utilityTryGetPublicKeysAndPartialAddress(account: AztecAddress): Promise<CompleteAddress | undefined> {
196
- return this.addressStore.getCompleteAddress(account);
188
+ public utilityGetPublicKeysAndPartialAddress(account: AztecAddress): Promise<CompleteAddress> {
189
+ return this.getCompleteAddress(account);
197
190
  }
198
191
 
199
- protected async getCompleteAddressOrFail(account: AztecAddress): Promise<CompleteAddress> {
192
+ protected async getCompleteAddress(account: AztecAddress): Promise<CompleteAddress> {
200
193
  const completeAddress = await this.addressStore.getCompleteAddress(account);
201
194
  if (!completeAddress) {
202
195
  throw new Error(
@@ -542,7 +535,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
542
535
 
543
536
  protected async getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point> {
544
537
  // TODO(#12656): return an app-siloed secret
545
- const recipientCompleteAddress = await this.getCompleteAddressOrFail(address);
538
+ const recipientCompleteAddress = await this.getCompleteAddress(address);
546
539
  const ivskM = await this.keyStore.getMasterSecretKey(
547
540
  recipientCompleteAddress.publicKeys.masterIncomingViewingPublicKey,
548
541
  );
@@ -45,7 +45,7 @@ export async function syncState(
45
45
  utilityExecutor: (privateSyncCall: FunctionCall) => Promise<any>,
46
46
  noteStore: NoteStore,
47
47
  aztecNode: AztecNode,
48
- anchorBlockHeader: BlockHeader,
48
+ header: BlockHeader,
49
49
  jobId: string,
50
50
  ) {
51
51
  // Protocol contracts don't have private state to sync
@@ -57,7 +57,7 @@ export async function syncState(
57
57
  );
58
58
  }
59
59
 
60
- const noteService = new NoteService(noteStore, aztecNode, anchorBlockHeader, jobId);
60
+ const noteService = new NoteService(noteStore, aztecNode, header, jobId);
61
61
 
62
62
  // Both sync_state and syncNoteNullifiers interact with the note store, but running them in parallel is safe
63
63
  // because note store is designed to handle concurrent operations.
@@ -68,12 +68,9 @@ export async function syncState(
68
68
  /**
69
69
  * Verify that the current class id of a contract obtained from AztecNode is the same as the one in contract data
70
70
  * provider (i.e. PXE's own storage).
71
- * @param contractAddress - The address of the contract to verify.
72
- * @param aztecNode - The Aztec node to query for storage.
73
- * @param contractStore - The contract store to fetch the local instance from.
74
71
  * @param header - The header of the block at which to verify the current class id.
75
72
  */
76
- export async function verifyCurrentClassId(
73
+ async function verifyCurrentClassId(
77
74
  contractAddress: AztecAddress,
78
75
  aztecNode: AztecNode,
79
76
  contractStore: ContractStore,
@@ -91,3 +88,32 @@ export async function verifyCurrentClassId(
91
88
  );
92
89
  }
93
90
  }
91
+
92
+ /**
93
+ * Ensures the contract's private state is synchronized and that the PXE holds the current class artifact for
94
+ * the contract.
95
+ */
96
+ export async function ensureContractSynced(
97
+ contractAddress: AztecAddress,
98
+ functionToInvokeAfterSync: FunctionSelector | null,
99
+ utilityExecutor: (call: FunctionCall) => Promise<any>,
100
+ aztecNode: AztecNode,
101
+ contractStore: ContractStore,
102
+ noteStore: NoteStore,
103
+ header: BlockHeader,
104
+ jobId: string,
105
+ ): Promise<void> {
106
+ await Promise.all([
107
+ syncState(
108
+ contractAddress,
109
+ contractStore,
110
+ functionToInvokeAfterSync,
111
+ utilityExecutor,
112
+ noteStore,
113
+ aztecNode,
114
+ header,
115
+ jobId,
116
+ ),
117
+ verifyCurrentClassId(contractAddress, aztecNode, contractStore, header),
118
+ ]);
119
+ }
@@ -1,12 +1,10 @@
1
- import type { FunctionCall } from '@aztec/stdlib/abi';
2
- import type { AuthWitness } from '@aztec/stdlib/auth-witness';
3
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
1
+ import { randomBytes } from '@aztec/foundation/crypto/random';
4
2
  import type { NoteDao, NotesFilter } from '@aztec/stdlib/note';
5
- import type { BlockHeader, ContractOverrides } from '@aztec/stdlib/tx';
3
+ import type { BlockHeader } from '@aztec/stdlib/tx';
6
4
 
7
5
  import type { BlockSynchronizer } from '../block_synchronizer/block_synchronizer.js';
8
- import type { ContractFunctionSimulator } from '../contract_function_simulator/contract_function_simulator.js';
9
- import type { ContractSyncService } from '../contract_sync/contract_sync_service.js';
6
+ import type { PXE } from '../pxe.js';
7
+ import type { ContractStore } from '../storage/contract_store/contract_store.js';
10
8
  import type { AnchorBlockStore } from '../storage/index.js';
11
9
  import type { NoteStore } from '../storage/note_store/note_store.js';
12
10
 
@@ -15,38 +13,20 @@ import type { NoteStore } from '../storage/note_store/note_store.js';
15
13
  * No backwards compatibility or API stability should be expected. Use at your own risk.
16
14
  */
17
15
  export class PXEDebugUtils {
16
+ #pxe!: PXE;
18
17
  #putJobInQueue!: <T>(job: (jobId: string) => Promise<T>) => Promise<T>;
19
- #getSimulatorForTx!: (overrides?: { contracts?: ContractOverrides }) => ContractFunctionSimulator;
20
- #simulateUtility!: (
21
- contractFunctionSimulator: ContractFunctionSimulator,
22
- call: FunctionCall,
23
- authWitnesses: AuthWitness[] | undefined,
24
- scopes: AztecAddress[] | undefined,
25
- jobId: string,
26
- ) => Promise<any>;
27
18
 
28
19
  constructor(
29
- private contractSyncService: ContractSyncService,
20
+ private contractStore: ContractStore,
30
21
  private noteStore: NoteStore,
31
22
  private blockStateSynchronizer: BlockSynchronizer,
32
23
  private anchorBlockStore: AnchorBlockStore,
33
24
  ) {}
34
25
 
35
26
  /** Not injected through constructor since they're are co-dependant */
36
- public setPXEHelpers(
37
- putJobInQueue: <T>(job: (jobId: string) => Promise<T>) => Promise<T>,
38
- getSimulatorForTx: (overrides?: { contracts?: ContractOverrides }) => ContractFunctionSimulator,
39
- simulateUtility: (
40
- contractFunctionSimulator: ContractFunctionSimulator,
41
- call: FunctionCall,
42
- authWitnesses: AuthWitness[] | undefined,
43
- scopes: AztecAddress[] | undefined,
44
- jobId: string,
45
- ) => Promise<any>,
46
- ) {
27
+ public setPXE(pxe: PXE, putJobInQueue: <T>(job: (jobId: string) => Promise<T>) => Promise<T>) {
28
+ this.#pxe = pxe;
47
29
  this.#putJobInQueue = putJobInQueue;
48
- this.#getSimulatorForTx = getSimulatorForTx;
49
- this.#simulateUtility = simulateUtility;
50
30
  }
51
31
 
52
32
  /**
@@ -60,25 +40,12 @@ export class PXEDebugUtils {
60
40
  * @param filter - The filter to apply to the notes.
61
41
  * @returns The requested notes.
62
42
  */
63
- public getNotes(filter: NotesFilter): Promise<NoteDao[]> {
64
- return this.#putJobInQueue(async (jobId: string) => {
65
- await this.blockStateSynchronizer.sync();
43
+ public async getNotes(filter: NotesFilter): Promise<NoteDao[]> {
44
+ // We need to manually trigger private state sync to have a guarantee that all the notes are available.
45
+ const call = await this.contractStore.getFunctionCall('sync_state', [], filter.contractAddress);
46
+ await this.#pxe.simulateUtility(call);
66
47
 
67
- const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
68
-
69
- const contractFunctionSimulator = this.#getSimulatorForTx();
70
-
71
- await this.contractSyncService.ensureContractSynced(
72
- filter.contractAddress,
73
- null,
74
- async privateSyncCall =>
75
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
76
- anchorBlockHeader,
77
- jobId,
78
- );
79
-
80
- return this.noteStore.getNotes(filter, jobId);
81
- });
48
+ return this.noteStore.getNotes(filter, randomBytes(8).toString('hex'));
82
49
  }
83
50
 
84
51
  /** Returns the block header up to which the PXE has synced. */
@@ -7,4 +7,4 @@ export { NoteService } from '../../notes/note_service.js';
7
7
  export { ORACLE_VERSION } from '../../oracle_version.js';
8
8
  export { type PXECreationOptions } from '../pxe_creation_options.js';
9
9
  export { JobCoordinator } from '../../job_coordinator/job_coordinator.js';
10
- export { ContractSyncService } from '../../contract_sync/contract_sync_service.js';
10
+ export { syncState } from '../../contract_sync/index.js';
@@ -4,9 +4,9 @@
4
4
  ///
5
5
  /// @dev Whenever a contract function or Noir test is run, the `utilityAssertCompatibleOracleVersion` oracle is called
6
6
  /// and if the oracle version is incompatible an error is thrown.
7
- export const ORACLE_VERSION = 11;
7
+ export const ORACLE_VERSION = 10;
8
8
 
9
9
  /// This hash is computed as by hashing the Oracle interface and it is used to detect when the Oracle interface changes,
10
10
  /// which in turn implies that you need to update the ORACLE_VERSION constant in this file and in
11
11
  /// `noir-projects/aztec-nr/aztec/src/oracle/version.nr`.
12
- export const ORACLE_INTERFACE_HASH = '20c4d02d8cd5e448c11001a5f72ea2e0927630aeda75e537550872a9627bf40b';
12
+ export const ORACLE_INTERFACE_HASH = 'a3b284ee5abff0509986d6d2fa78a3e6e2ec212325674de78355c5e70b05784c';
package/src/pxe.ts CHANGED
@@ -59,8 +59,7 @@ import {
59
59
  generateSimulatedProvingResult,
60
60
  } from './contract_function_simulator/contract_function_simulator.js';
61
61
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
62
- import { ContractSyncService } from './contract_sync/contract_sync_service.js';
63
- import { readCurrentClassId } from './contract_sync/helpers.js';
62
+ import { ensureContractSynced, readCurrentClassId } from './contract_sync/index.js';
64
63
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
65
64
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
66
65
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
@@ -103,7 +102,6 @@ export class PXE {
103
102
  private recipientTaggingStore: RecipientTaggingStore,
104
103
  private addressStore: AddressStore,
105
104
  private privateEventStore: PrivateEventStore,
106
- private contractSyncService: ContractSyncService,
107
105
  private simulator: CircuitSimulator,
108
106
  private proverEnabled: boolean,
109
107
  private proofCreator: PrivateKernelProver,
@@ -151,12 +149,6 @@ export class PXE {
151
149
  const capsuleStore = new CapsuleStore(store);
152
150
  const keyStore = new KeyStore(store);
153
151
  const tipsStore = new L2TipsKVStore(store, 'pxe');
154
- const contractSyncService = new ContractSyncService(
155
- node,
156
- contractStore,
157
- noteStore,
158
- createLogger('pxe:contract_sync', bindings),
159
- );
160
152
  const synchronizer = new BlockSynchronizer(
161
153
  node,
162
154
  store,
@@ -164,7 +156,6 @@ export class PXE {
164
156
  noteStore,
165
157
  privateEventStore,
166
158
  tipsStore,
167
- contractSyncService,
168
159
  config,
169
160
  bindings,
170
161
  );
@@ -176,10 +167,9 @@ export class PXE {
176
167
  recipientTaggingStore,
177
168
  privateEventStore,
178
169
  noteStore,
179
- contractSyncService,
180
170
  ]);
181
171
 
182
- const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
172
+ const debugUtils = new PXEDebugUtils(contractStore, noteStore, synchronizer, anchorBlockStore);
183
173
 
184
174
  const jobQueue = new SerialQueue();
185
175
 
@@ -196,7 +186,6 @@ export class PXE {
196
186
  recipientTaggingStore,
197
187
  addressStore,
198
188
  privateEventStore,
199
- contractSyncService,
200
189
  simulator,
201
190
  proverEnabled,
202
191
  proofCreator,
@@ -207,11 +196,7 @@ export class PXE {
207
196
  debugUtils,
208
197
  );
209
198
 
210
- debugUtils.setPXEHelpers(
211
- pxe.#putInJobQueue.bind(pxe),
212
- pxe.#getSimulatorForTx.bind(pxe),
213
- pxe.#simulateUtility.bind(pxe),
214
- );
199
+ debugUtils.setPXE(pxe, pxe.#putInJobQueue.bind(pxe));
215
200
 
216
201
  pxe.jobQueue.start();
217
202
 
@@ -238,7 +223,6 @@ export class PXE {
238
223
  this.capsuleStore,
239
224
  this.privateEventStore,
240
225
  this.simulator,
241
- this.contractSyncService,
242
226
  );
243
227
  }
244
228
 
@@ -313,10 +297,13 @@ export class PXE {
313
297
  try {
314
298
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
315
299
 
316
- await this.contractSyncService.ensureContractSynced(
300
+ await ensureContractSynced(
317
301
  contractAddress,
318
302
  functionSelector,
319
303
  privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
304
+ this.node,
305
+ this.contractStore,
306
+ this.noteStore,
320
307
  anchorBlockHeader,
321
308
  jobId,
322
309
  );
@@ -863,14 +850,7 @@ export class PXE {
863
850
  // Temporary: in case there are overrides, we have to skip the kernels or validations
864
851
  // will fail. Consider handing control to the user/wallet on whether they want to run them
865
852
  // or not.
866
- const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
867
- const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
868
- const skipKernels = hasOverriddenContracts;
869
-
870
- // Set overridden contracts on the sync service so it knows to skip syncing them
871
- if (hasOverriddenContracts) {
872
- this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
873
- }
853
+ const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
874
854
 
875
855
  // Execution of private functions only; no proving, and no kernel logic.
876
856
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
@@ -992,10 +972,13 @@ export class PXE {
992
972
  const contractFunctionSimulator = this.#getSimulatorForTx();
993
973
 
994
974
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
995
- await this.contractSyncService.ensureContractSynced(
975
+ await ensureContractSynced(
996
976
  call.to,
997
977
  call.selector,
998
978
  privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
979
+ this.node,
980
+ this.contractStore,
981
+ this.noteStore,
999
982
  anchorBlockHeader,
1000
983
  jobId,
1001
984
  );
@@ -1061,11 +1044,14 @@ export class PXE {
1061
1044
 
1062
1045
  const contractFunctionSimulator = this.#getSimulatorForTx();
1063
1046
 
1064
- await this.contractSyncService.ensureContractSynced(
1047
+ await ensureContractSynced(
1065
1048
  filter.contractAddress,
1066
1049
  null,
1067
1050
  async privateSyncCall =>
1068
1051
  await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1052
+ this.node,
1053
+ this.contractStore,
1054
+ this.noteStore,
1069
1055
  anchorBlockHeader,
1070
1056
  jobId,
1071
1057
  );
@@ -1,41 +0,0 @@
1
- import type { Logger } from '@aztec/foundation/log';
2
- import type { FunctionCall, FunctionSelector } from '@aztec/stdlib/abi';
3
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
- import type { AztecNode } from '@aztec/stdlib/interfaces/client';
5
- import type { BlockHeader } from '@aztec/stdlib/tx';
6
- import type { StagedStore } from '../job_coordinator/job_coordinator.js';
7
- import type { ContractStore } from '../storage/contract_store/contract_store.js';
8
- import type { NoteStore } from '../storage/note_store/note_store.js';
9
- /**
10
- * Service for syncing the private state of contracts and verifying that the PXE holds the current class artifact.
11
- * It uses a cache to avoid redundant sync operations - the cache is wiped when the anchor block changes.
12
- *
13
- * TODO: The StagedStore naming is broken here. Figure out a better name.
14
- */
15
- export declare class ContractSyncService implements StagedStore {
16
- #private;
17
- private aztecNode;
18
- private contractStore;
19
- private noteStore;
20
- private log;
21
- readonly storeName = "contract_sync";
22
- private syncedContracts;
23
- private overriddenContracts;
24
- constructor(aztecNode: AztecNode, contractStore: ContractStore, noteStore: NoteStore, log: Logger);
25
- /** Sets contracts that should be skipped during sync for a specific job. */
26
- setOverriddenContracts(jobId: string, addresses: Set<string>): void;
27
- /**
28
- * Ensures a contract's private state is synchronized and that the PXE holds the current class artifact.
29
- * Uses a cache to avoid redundant sync operations - the cache is wiped when the anchor block changes.
30
- * @param contractAddress - The address of the contract to sync.
31
- * @param functionToInvokeAfterSync - The function selector that will be called after sync (used to validate it's
32
- * not sync_state itself).
33
- * @param utilityExecutor - Executor function for running the sync_state utility function.
34
- */
35
- ensureContractSynced(contractAddress: AztecAddress, functionToInvokeAfterSync: FunctionSelector | null, utilityExecutor: (call: FunctionCall) => Promise<any>, anchorBlockHeader: BlockHeader, jobId: string): Promise<void>;
36
- /** Clears sync cache. Called by BlockSynchronizer when anchor block changes. */
37
- wipe(): void;
38
- commit(jobId: string): Promise<void>;
39
- discardStaged(jobId: string): Promise<void>;
40
- }
41
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJhY3Rfc3luY19zZXJ2aWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29udHJhY3Rfc3luYy9jb250cmFjdF9zeW5jX3NlcnZpY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFDcEQsT0FBTyxLQUFLLEVBQUUsWUFBWSxFQUFFLGdCQUFnQixFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFDeEUsT0FBTyxLQUFLLEVBQUUsWUFB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UFPLENBQUMsR0FBRyxDQUFDLEVBQ3JELGlCQUFpQixFQUFFLFdBQVcsRUFDOUIsS0FBSyxFQUFFLE1BQU0sR0FDWixPQUFPLENBQUMsSUFBSSxDQUFDLENBOEJmO0lBMEJELGdGQUFnRjtJQUNoRixJQUFJLElBQUksSUFBSSxDQUdYO0lBRUQsTUFBTSxDQUFDLEtBQUssRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUluQztJQUVELGFBQWEsQ0FBQyxLQUFLLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FNMUM7Q0FDRiJ9
@@ -1 +0,0 @@
1
- {"version":3,"file":"contract_sync_service.d.ts","sourceRoot":"","sources":["../../src/contract_sync/contract_sync_service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAGrE;;;;;GAKG;AACH,qBAAa,mBAAoB,YAAW,WAAW;;IAWnD,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,GAAG;IAbb,QAAQ,CAAC,SAAS,mBAAmB;IAIrC,OAAO,CAAC,eAAe,CAAyC;IAGhE,OAAO,CAAC,mBAAmB,CAAuC;IAElE,YACU,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,MAAM,EACjB;IAEJ,4EAA4E;IAC5E,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAElE;IAED;;;;;;;OAOG;IACG,oBAAoB,CACxB,eAAe,EAAE,YAAY,EAC7B,yBAAyB,EAAE,gBAAgB,GAAG,IAAI,EAClD,eAAe,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,OAAO,CAAC,GAAG,CAAC,EACrD,iBAAiB,EAAE,WAAW,EAC9B,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CA8Bf;IA0BD,gFAAgF;IAChF,IAAI,IAAI,IAAI,CAGX;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAInC;IAED,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAM1C;CACF"}
@@ -1,82 +0,0 @@
1
- import { syncState, verifyCurrentClassId } from './helpers.js';
2
- /**
3
- * Service for syncing the private state of contracts and verifying that the PXE holds the current class artifact.
4
- * It uses a cache to avoid redundant sync operations - the cache is wiped when the anchor block changes.
5
- *
6
- * TODO: The StagedStore naming is broken here. Figure out a better name.
7
- */ export class ContractSyncService {
8
- aztecNode;
9
- contractStore;
10
- noteStore;
11
- log;
12
- storeName;
13
- // Tracks contracts synced since last wipe. Key is contract address string, value is a promise that resolves when
14
- // the contract is synced.
15
- syncedContracts;
16
- // Per-job overridden contract addresses - these contracts should not be synced.
17
- overriddenContracts;
18
- constructor(aztecNode, contractStore, noteStore, log){
19
- this.aztecNode = aztecNode;
20
- this.contractStore = contractStore;
21
- this.noteStore = noteStore;
22
- this.log = log;
23
- this.storeName = 'contract_sync';
24
- this.syncedContracts = new Map();
25
- this.overriddenContracts = new Map();
26
- }
27
- /** Sets contracts that should be skipped during sync for a specific job. */ setOverriddenContracts(jobId, addresses) {
28
- this.overriddenContracts.set(jobId, addresses);
29
- }
30
- /**
31
- * Ensures a contract's private state is synchronized and that the PXE holds the current class artifact.
32
- * Uses a cache to avoid redundant sync operations - the cache is wiped when the anchor block changes.
33
- * @param contractAddress - The address of the contract to sync.
34
- * @param functionToInvokeAfterSync - The function selector that will be called after sync (used to validate it's
35
- * not sync_state itself).
36
- * @param utilityExecutor - Executor function for running the sync_state utility function.
37
- */ async ensureContractSynced(contractAddress, functionToInvokeAfterSync, utilityExecutor, anchorBlockHeader, jobId) {
38
- const key = contractAddress.toString();
39
- // Skip sync if this contract has an override for this job
40
- const overrides = this.overriddenContracts.get(jobId);
41
- if (overrides?.has(key)) {
42
- return;
43
- }
44
- const existing = this.syncedContracts.get(key);
45
- if (existing) {
46
- return existing;
47
- }
48
- const syncPromise = this.#doSync(contractAddress, functionToInvokeAfterSync, utilityExecutor, anchorBlockHeader, jobId);
49
- this.syncedContracts.set(key, syncPromise);
50
- try {
51
- await syncPromise;
52
- } catch (err) {
53
- // There was an error syncing the contract, so we remove it from the cache so that it can be retried.
54
- this.syncedContracts.delete(key);
55
- throw err;
56
- }
57
- }
58
- async #doSync(contractAddress, functionToInvokeAfterSync, utilityExecutor, anchorBlockHeader, jobId) {
59
- this.log.debug(`Syncing contract ${contractAddress}`);
60
- await Promise.all([
61
- syncState(contractAddress, this.contractStore, functionToInvokeAfterSync, utilityExecutor, this.noteStore, this.aztecNode, anchorBlockHeader, jobId),
62
- verifyCurrentClassId(contractAddress, this.aztecNode, this.contractStore, anchorBlockHeader)
63
- ]);
64
- this.log.debug(`Contract ${contractAddress} synced`);
65
- }
66
- /** Clears sync cache. Called by BlockSynchronizer when anchor block changes. */ wipe() {
67
- this.log.debug(`Wiping contract sync cache (${this.syncedContracts.size} entries)`);
68
- this.syncedContracts.clear();
69
- }
70
- commit(jobId) {
71
- // Clear overridden contracts for this job
72
- this.overriddenContracts.delete(jobId);
73
- return Promise.resolve();
74
- }
75
- discardStaged(jobId) {
76
- // We clear the synced contracts cache here because, when the job is discarded, any associated database writes from
77
- // the sync are also undone.
78
- this.syncedContracts.clear();
79
- this.overriddenContracts.delete(jobId);
80
- return Promise.resolve();
81
- }
82
- }
@@ -1,28 +0,0 @@
1
- import type { FunctionCall, FunctionSelector } from '@aztec/stdlib/abi';
2
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
- import type { ContractInstance } from '@aztec/stdlib/contract';
4
- import type { AztecNode } from '@aztec/stdlib/interfaces/client';
5
- import type { BlockHeader } from '@aztec/stdlib/tx';
6
- import type { ContractStore } from '../storage/contract_store/contract_store.js';
7
- import type { NoteStore } from '../storage/note_store/note_store.js';
8
- /**
9
- * Read the current class id of a contract from the execution data provider or AztecNode. If not found, class id
10
- * from the instance is used.
11
- * @param contractAddress - The address of the contract to read the class id for.
12
- * @param instance - The instance of the contract.
13
- * @param aztecNode - The Aztec node to query for storage.
14
- * @param header - The header of the block at which to load the DelayedPublicMutable storing the class id.
15
- * @returns The current class id.
16
- */
17
- export declare function readCurrentClassId(contractAddress: AztecAddress, instance: ContractInstance, aztecNode: AztecNode, header: BlockHeader): Promise<import("@aztec/foundation/schemas").Fr>;
18
- export declare function syncState(contractAddress: AztecAddress, contractStore: ContractStore, functionToInvokeAfterSync: FunctionSelector | null, utilityExecutor: (privateSyncCall: FunctionCall) => Promise<any>, noteStore: NoteStore, aztecNode: AztecNode, anchorBlockHeader: BlockHeader, jobId: string): Promise<void>;
19
- /**
20
- * Verify that the current class id of a contract obtained from AztecNode is the same as the one in contract data
21
- * provider (i.e. PXE's own storage).
22
- * @param contractAddress - The address of the contract to verify.
23
- * @param aztecNode - The Aztec node to query for storage.
24
- * @param contractStore - The contract store to fetch the local instance from.
25
- * @param header - The header of the block at which to verify the current class id.
26
- */
27
- export declare function verifyCurrentClassId(contractAddress: AztecAddress, aztecNode: AztecNode, contractStore: ContractStore, header: BlockHeader): Promise<void>;
28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