@aztec/txe 0.0.1-commit.c2595eba → 0.0.1-commit.c2eed6949

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 (58) hide show
  1. package/dest/index.d.ts +1 -1
  2. package/dest/index.d.ts.map +1 -1
  3. package/dest/index.js +88 -54
  4. package/dest/oracle/interfaces.d.ts +29 -28
  5. package/dest/oracle/interfaces.d.ts.map +1 -1
  6. package/dest/oracle/txe_oracle_public_context.d.ts +13 -13
  7. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  8. package/dest/oracle/txe_oracle_public_context.js +12 -12
  9. package/dest/oracle/txe_oracle_top_level_context.d.ts +23 -23
  10. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_top_level_context.js +124 -50
  12. package/dest/rpc_translator.d.ts +88 -83
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +296 -162
  15. package/dest/state_machine/archiver.d.ts +3 -3
  16. package/dest/state_machine/archiver.d.ts.map +1 -1
  17. package/dest/state_machine/archiver.js +7 -7
  18. package/dest/state_machine/dummy_p2p_client.d.ts +16 -12
  19. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  20. package/dest/state_machine/dummy_p2p_client.js +28 -16
  21. package/dest/state_machine/index.d.ts +7 -5
  22. package/dest/state_machine/index.d.ts.map +1 -1
  23. package/dest/state_machine/index.js +19 -10
  24. package/dest/state_machine/mock_epoch_cache.d.ts +19 -3
  25. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  26. package/dest/state_machine/mock_epoch_cache.js +36 -2
  27. package/dest/state_machine/synchronizer.d.ts +5 -5
  28. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  29. package/dest/state_machine/synchronizer.js +3 -3
  30. package/dest/txe_session.d.ts +10 -6
  31. package/dest/txe_session.d.ts.map +1 -1
  32. package/dest/txe_session.js +94 -26
  33. package/dest/util/encoding.d.ts +69 -1
  34. package/dest/util/encoding.d.ts.map +1 -1
  35. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  36. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  37. package/dest/util/txe_public_contract_data_source.js +6 -25
  38. package/dest/utils/block_creation.d.ts +1 -1
  39. package/dest/utils/block_creation.d.ts.map +1 -1
  40. package/dest/utils/block_creation.js +3 -1
  41. package/package.json +15 -15
  42. package/src/index.ts +89 -52
  43. package/src/oracle/interfaces.ts +32 -31
  44. package/src/oracle/txe_oracle_public_context.ts +12 -12
  45. package/src/oracle/txe_oracle_top_level_context.ts +137 -98
  46. package/src/rpc_translator.ts +330 -179
  47. package/src/state_machine/archiver.ts +7 -5
  48. package/src/state_machine/dummy_p2p_client.ts +40 -22
  49. package/src/state_machine/index.ts +30 -9
  50. package/src/state_machine/mock_epoch_cache.ts +47 -3
  51. package/src/state_machine/synchronizer.ts +4 -4
  52. package/src/txe_session.ts +106 -85
  53. package/src/util/txe_public_contract_data_source.ts +10 -38
  54. package/src/utils/block_creation.ts +3 -1
  55. package/dest/util/txe_contract_store.d.ts +0 -12
  56. package/dest/util/txe_contract_store.d.ts.map +0 -1
  57. package/dest/util/txe_contract_store.js +0 -22
  58. package/src/util/txe_contract_store.ts +0 -36
@@ -12,9 +12,12 @@ import { Fr } from '@aztec/foundation/curves/bn254';
12
12
  import { LogLevels, type Logger, applyStringFormatting, createLogger } from '@aztec/foundation/log';
13
13
  import { TestDateProvider } from '@aztec/foundation/timer';
14
14
  import type { KeyStore } from '@aztec/key-store';
15
+ import type { AccessScopes } from '@aztec/pxe/client/lazy';
15
16
  import {
16
17
  AddressStore,
17
18
  CapsuleStore,
19
+ type ContractStore,
20
+ type ContractSyncService,
18
21
  NoteStore,
19
22
  ORACLE_VERSION,
20
23
  PrivateEventStore,
@@ -22,7 +25,6 @@ import {
22
25
  SenderAddressBookStore,
23
26
  SenderTaggingStore,
24
27
  enrichPublicSimulationError,
25
- syncState,
26
28
  } from '@aztec/pxe/server';
27
29
  import {
28
30
  ExecutionNoteCache,
@@ -84,7 +86,6 @@ import { ForkCheckpoint } from '@aztec/world-state';
84
86
  import { DEFAULT_ADDRESS } from '../constants.js';
85
87
  import type { TXEStateMachine } from '../state_machine/index.js';
86
88
  import type { TXEAccountStore } from '../util/txe_account_store.js';
87
- import type { TXEContractStore } from '../util/txe_contract_store.js';
88
89
  import { TXEPublicContractDataSource } from '../util/txe_public_contract_data_source.js';
89
90
  import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from '../utils/block_creation.js';
90
91
  import type { ITxeExecutionOracle } from './interfaces.js';
@@ -97,7 +98,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
97
98
 
98
99
  constructor(
99
100
  private stateMachine: TXEStateMachine,
100
- private contractStore: TXEContractStore,
101
+ private contractStore: ContractStore,
101
102
  private noteStore: NoteStore,
102
103
  private keyStore: KeyStore,
103
104
  private addressStore: AddressStore,
@@ -107,17 +108,17 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
107
108
  private senderAddressBookStore: SenderAddressBookStore,
108
109
  private capsuleStore: CapsuleStore,
109
110
  private privateEventStore: PrivateEventStore,
110
- private jobId: string,
111
111
  private nextBlockTimestamp: bigint,
112
112
  private version: Fr,
113
113
  private chainId: Fr,
114
114
  private authwits: Map<string, AuthWitness>,
115
+ private readonly contractSyncService: ContractSyncService,
115
116
  ) {
116
117
  this.logger = createLogger('txe:top_level_context');
117
118
  this.logger.debug('Entering Top Level Context');
118
119
  }
119
120
 
120
- utilityAssertCompatibleOracleVersion(version: number): void {
121
+ assertCompatibleOracleVersion(version: number): void {
121
122
  if (version !== ORACLE_VERSION) {
122
123
  throw new Error(
123
124
  `Incompatible oracle version. TXE is using version '${ORACLE_VERSION}', but got a request for '${version}'.`,
@@ -127,37 +128,38 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
127
128
 
128
129
  // This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
129
130
  // setup.
130
- utilityGetRandomField(): Fr {
131
+ getRandomField(): Fr {
131
132
  return Fr.random();
132
133
  }
133
134
 
134
135
  // We instruct users to debug contracts via this oracle, so it makes sense that they'd expect it to also work in tests
135
- utilityDebugLog(level: number, message: string, fields: Fr[]): void {
136
+ log(level: number, message: string, fields: Fr[]): Promise<void> {
136
137
  if (!LogLevels[level]) {
137
- throw new Error(`Invalid debug log level: ${level}`);
138
+ throw new Error(`Invalid log level: ${level}`);
138
139
  }
139
140
  const levelName = LogLevels[level];
140
141
 
141
142
  this.logger[levelName](`${applyStringFormatting(message, fields)}`, { module: `${this.logger.module}:debug_log` });
143
+ return Promise.resolve();
142
144
  }
143
145
 
144
- txeGetDefaultAddress(): AztecAddress {
146
+ getDefaultAddress(): AztecAddress {
145
147
  return DEFAULT_ADDRESS;
146
148
  }
147
149
 
148
- async txeGetNextBlockNumber(): Promise<BlockNumber> {
150
+ async getNextBlockNumber(): Promise<BlockNumber> {
149
151
  return BlockNumber((await this.getLastBlockNumber()) + 1);
150
152
  }
151
153
 
152
- txeGetNextBlockTimestamp(): Promise<bigint> {
154
+ getNextBlockTimestamp(): Promise<bigint> {
153
155
  return Promise.resolve(this.nextBlockTimestamp);
154
156
  }
155
157
 
156
- async txeGetLastBlockTimestamp() {
158
+ async getLastBlockTimestamp() {
157
159
  return (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.timestamp;
158
160
  }
159
161
 
160
- async txeGetLastTxEffects() {
162
+ async getLastTxEffects() {
161
163
  const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
162
164
  const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
163
165
 
@@ -171,7 +173,26 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
171
173
  return { txHash: txEffects.txHash, noteHashes: txEffects.noteHashes, nullifiers: txEffects.nullifiers };
172
174
  }
173
175
 
174
- async txeGetPrivateEvents(selector: EventSelector, contractAddress: AztecAddress, scope: AztecAddress) {
176
+ async syncContractNonOracleMethod(contractAddress: AztecAddress, scope: AztecAddress, jobId: string) {
177
+ if (contractAddress.equals(DEFAULT_ADDRESS)) {
178
+ this.logger.debug(`Skipping sync in getPrivateEvents because the events correspond to the default address.`);
179
+ return;
180
+ }
181
+
182
+ const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
183
+ await this.stateMachine.contractSyncService.ensureContractSynced(
184
+ contractAddress,
185
+ null,
186
+ async (call, execScopes) => {
187
+ await this.executeUtilityCall(call, execScopes, jobId);
188
+ },
189
+ blockHeader,
190
+ jobId,
191
+ [scope],
192
+ );
193
+ }
194
+
195
+ async getPrivateEvents(selector: EventSelector, contractAddress: AztecAddress, scope: AztecAddress) {
175
196
  return (
176
197
  await this.privateEventStore.getPrivateEvents(selector, {
177
198
  contractAddress,
@@ -182,7 +203,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
182
203
  ).map(e => e.packedEvent);
183
204
  }
184
205
 
185
- async txeAdvanceBlocksBy(blocks: number) {
206
+ async advanceBlocksBy(blocks: number) {
186
207
  this.logger.debug(`time traveling ${blocks} blocks`);
187
208
 
188
209
  for (let i = 0; i < blocks; i++) {
@@ -190,12 +211,12 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
190
211
  }
191
212
  }
192
213
 
193
- txeAdvanceTimestampBy(duration: UInt64) {
214
+ advanceTimestampBy(duration: UInt64) {
194
215
  this.logger.debug(`time traveling ${duration} seconds`);
195
216
  this.nextBlockTimestamp += duration;
196
217
  }
197
218
 
198
- async txeDeploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
219
+ async deploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
199
220
  // Emit deployment nullifier
200
221
  await this.mineBlock({
201
222
  nullifiers: [
@@ -207,20 +228,20 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
207
228
  });
208
229
 
209
230
  if (!secret.equals(Fr.ZERO)) {
210
- await this.txeAddAccount(artifact, instance, secret);
231
+ await this.addAccount(artifact, instance, secret);
211
232
  } else {
212
233
  await this.contractStore.addContractInstance(instance);
213
- await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
234
+ await this.contractStore.addContractArtifact(artifact);
214
235
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
215
236
  }
216
237
  }
217
238
 
218
- async txeAddAccount(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
239
+ async addAccount(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
219
240
  const partialAddress = await computePartialAddress(instance);
220
241
 
221
242
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
222
243
  await this.contractStore.addContractInstance(instance);
223
- await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
244
+ await this.contractStore.addContractArtifact(artifact);
224
245
 
225
246
  const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
226
247
  await this.accountStore.setAccount(completeAddress.address, completeAddress);
@@ -230,7 +251,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
230
251
  return completeAddress;
231
252
  }
232
253
 
233
- async txeCreateAccount(secret: Fr) {
254
+ async createAccount(secret: Fr) {
234
255
  // This is a foot gun !
235
256
  const completeAddress = await this.keyStore.addAccount(secret, secret);
236
257
  await this.accountStore.setAccount(completeAddress.address, completeAddress);
@@ -240,7 +261,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
240
261
  return completeAddress;
241
262
  }
242
263
 
243
- async txeAddAuthWitness(address: AztecAddress, messageHash: Fr) {
264
+ async addAuthWitness(address: AztecAddress, messageHash: Fr) {
244
265
  const account = await this.accountStore.getAccount(address);
245
266
  const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
246
267
 
@@ -253,7 +274,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
253
274
  }
254
275
 
255
276
  async mineBlock(options: { nullifiers?: Fr[] } = {}) {
256
- const blockNumber = await this.txeGetNextBlockNumber();
277
+ const blockNumber = await this.getNextBlockNumber();
257
278
 
258
279
  const txEffect = TxEffect.empty();
259
280
  txEffect.nullifiers = [getSingleTxBlockRequestHash(blockNumber), ...(options.nullifiers ?? [])];
@@ -277,13 +298,14 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
277
298
  await this.stateMachine.handleL2Block(block);
278
299
  }
279
300
 
280
- async txePrivateCallNewFlow(
301
+ async privateCallNewFlow(
281
302
  from: AztecAddress,
282
303
  targetContractAddress: AztecAddress = AztecAddress.zero(),
283
304
  functionSelector: FunctionSelector = FunctionSelector.empty(),
284
305
  args: Fr[],
285
306
  argsHash: Fr = Fr.zero(),
286
307
  isStaticCall: boolean = false,
308
+ jobId: string,
287
309
  ) {
288
310
  this.logger.verbose(
289
311
  `Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`,
@@ -297,14 +319,26 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
297
319
  throw new Error(message);
298
320
  }
299
321
 
322
+ // When `from` is the zero address (e.g. when deploying a new account contract), we return an
323
+ // empty scope list which acts as deny-all: no notes are visible and no keys are accessible.
324
+ const effectiveScopes = from.isZero() ? [] : [from];
325
+
300
326
  // Sync notes before executing private function to discover notes from previous transactions
301
- const utilityExecutor = async (call: FunctionCall) => {
302
- await this.executeUtilityCall(call);
327
+ const utilityExecutor = async (call: FunctionCall, execScopes: AccessScopes) => {
328
+ await this.executeUtilityCall(call, execScopes, jobId);
303
329
  };
304
330
 
305
- await syncState(targetContractAddress, this.contractStore, functionSelector, utilityExecutor);
331
+ const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
332
+ await this.stateMachine.contractSyncService.ensureContractSynced(
333
+ targetContractAddress,
334
+ functionSelector,
335
+ utilityExecutor,
336
+ blockHeader,
337
+ jobId,
338
+ effectiveScopes,
339
+ );
306
340
 
307
- const blockNumber = await this.txeGetNextBlockNumber();
341
+ const blockNumber = await this.getNextBlockNumber();
308
342
 
309
343
  const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
310
344
 
@@ -314,8 +348,6 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
314
348
 
315
349
  const txContext = new TxContext(this.chainId, this.version, gasSettings);
316
350
 
317
- const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
318
-
319
351
  const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
320
352
  const noteCache = new ExecutionNoteCache(protocolNullifier);
321
353
  // In production, the account contract sets the min revertible counter before calling the app function.
@@ -327,43 +359,38 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
327
359
 
328
360
  const simulator = new WASMSimulator();
329
361
 
330
- const privateExecutionOracle = new PrivateExecutionOracle(
362
+ const privateExecutionOracle = new PrivateExecutionOracle({
331
363
  argsHash,
332
364
  txContext,
333
365
  callContext,
334
- /** Header of a block whose state is used during private execution (not the block the transaction is included in). */
335
- blockHeader,
366
+ anchorBlockHeader: blockHeader,
336
367
  utilityExecutor,
337
- /** List of transient auth witnesses to be used during this simulation */
338
- Array.from(this.authwits.values()),
339
- /** List of transient auth witnesses to be used during this simulation */
340
- [],
341
- HashedValuesCache.create([new HashedValues(args, argsHash)]),
368
+ authWitnesses: Array.from(this.authwits.values()),
369
+ capsules: [],
370
+ executionCache: HashedValuesCache.create([new HashedValues(args, argsHash)]),
342
371
  noteCache,
343
372
  taggingIndexCache,
344
- this.contractStore,
345
- this.noteStore,
346
- this.keyStore,
347
- this.addressStore,
348
- this.stateMachine.node,
349
- this.stateMachine.anchorBlockStore,
350
- this.senderTaggingStore,
351
- this.recipientTaggingStore,
352
- this.senderAddressBookStore,
353
- this.capsuleStore,
354
- this.privateEventStore,
355
- this.jobId,
356
- 0, // totalPublicArgsCount
357
- minRevertibleSideEffectCounter, // (start) sideEffectCounter
358
- undefined, // log
359
- undefined, // scopes
360
- /**
361
- * In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
362
- * contract would perform, including setting senderForTags.
363
- */
364
- from,
373
+ contractStore: this.contractStore,
374
+ noteStore: this.noteStore,
375
+ keyStore: this.keyStore,
376
+ addressStore: this.addressStore,
377
+ aztecNode: this.stateMachine.node,
378
+ senderTaggingStore: this.senderTaggingStore,
379
+ recipientTaggingStore: this.recipientTaggingStore,
380
+ senderAddressBookStore: this.senderAddressBookStore,
381
+ capsuleStore: this.capsuleStore,
382
+ privateEventStore: this.privateEventStore,
383
+ contractSyncService: this.stateMachine.contractSyncService,
384
+ jobId,
385
+ totalPublicCalldataCount: 0,
386
+ sideEffectCounter: minRevertibleSideEffectCounter,
387
+ scopes: effectiveScopes,
388
+ // In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
389
+ // contract would perform, including setting senderForTags.
390
+ senderForTags: from,
365
391
  simulator,
366
- );
392
+ messageContextService: this.stateMachine.messageContextService,
393
+ });
367
394
 
368
395
  // Note: This is a slight modification of simulator.run without any of the checks. Maybe we should modify simulator.run with a boolean value to skip checks.
369
396
  let result: PrivateExecutionResult;
@@ -385,7 +412,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
385
412
  );
386
413
  const publicFunctionsCalldata = await Promise.all(
387
414
  publicCallRequests.map(async r => {
388
- const calldata = await privateExecutionOracle.privateLoadFromExecutionCache(r.calldataHash);
415
+ const calldata = await privateExecutionOracle.loadFromExecutionCache(r.calldataHash);
389
416
  return new HashedValues(calldata, r.calldataHash);
390
417
  }),
391
418
  );
@@ -402,7 +429,8 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
402
429
  // We pass the non-zero minRevertibleSideEffectCounter to make sure the side effects are split correctly.
403
430
  const { publicInputs } = await generateSimulatedProvingResult(
404
431
  result,
405
- this.contractStore,
432
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
433
+ this.stateMachine.node,
406
434
  minRevertibleSideEffectCounter,
407
435
  );
408
436
 
@@ -498,7 +526,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
498
526
  return executionResult.returnValues ?? [];
499
527
  }
500
528
 
501
- async txePublicCallNewFlow(
529
+ async publicCallNewFlow(
502
530
  from: AztecAddress,
503
531
  targetContractAddress: AztecAddress,
504
532
  calldata: Fr[],
@@ -508,7 +536,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
508
536
  `Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`,
509
537
  );
510
538
 
511
- const blockNumber = await this.txeGetNextBlockNumber();
539
+ const blockNumber = await this.getNextBlockNumber();
512
540
 
513
541
  const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
514
542
 
@@ -585,7 +613,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
585
613
  constantData,
586
614
  /*gasUsed=*/ new Gas(0, 0),
587
615
  /*feePayer=*/ AztecAddress.zero(),
588
- /*includeByTimestamp=*/ 0n,
616
+ /*expirationTimestamp=*/ 0n,
589
617
  inputsForPublic,
590
618
  undefined,
591
619
  );
@@ -653,10 +681,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
653
681
  return returnValues ?? [];
654
682
  }
655
683
 
656
- async txeSimulateUtilityFunction(
684
+ async executeUtilityFunction(
657
685
  targetContractAddress: AztecAddress,
658
686
  functionSelector: FunctionSelector,
659
687
  args: Fr[],
688
+ jobId: string,
660
689
  ) {
661
690
  const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
662
691
  if (!artifact) {
@@ -664,25 +693,33 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
664
693
  }
665
694
 
666
695
  // Sync notes before executing utility function to discover notes from previous transactions
667
- await syncState(targetContractAddress, this.contractStore, functionSelector, async call => {
668
- await this.executeUtilityCall(call);
669
- });
670
-
671
- const call = new FunctionCall(
672
- artifact.name,
696
+ const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
697
+ await this.stateMachine.contractSyncService.ensureContractSynced(
673
698
  targetContractAddress,
674
699
  functionSelector,
675
- FunctionType.UTILITY,
676
- false,
677
- false,
678
- args,
679
- [],
700
+ async (call, execScopes) => {
701
+ await this.executeUtilityCall(call, execScopes, jobId);
702
+ },
703
+ blockHeader,
704
+ jobId,
705
+ 'ALL_SCOPES',
680
706
  );
681
707
 
682
- return this.executeUtilityCall(call);
708
+ const call = FunctionCall.from({
709
+ name: artifact.name,
710
+ to: targetContractAddress,
711
+ selector: functionSelector,
712
+ type: FunctionType.UTILITY,
713
+ hideMsgSender: false,
714
+ isStatic: false,
715
+ args,
716
+ returnTypes: [],
717
+ });
718
+
719
+ return this.executeUtilityCall(call, 'ALL_SCOPES', jobId);
683
720
  }
684
721
 
685
- private async executeUtilityCall(call: FunctionCall): Promise<Fr[]> {
722
+ private async executeUtilityCall(call: FunctionCall, scopes: AccessScopes, jobId: string): Promise<Fr[]> {
686
723
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
687
724
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
688
725
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
@@ -695,23 +732,25 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
695
732
 
696
733
  try {
697
734
  const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
698
- const oracle = new UtilityExecutionOracle(
699
- call.to,
700
- [],
701
- [],
735
+ const oracle = new UtilityExecutionOracle({
736
+ contractAddress: call.to,
737
+ authWitnesses: [],
738
+ capsules: [],
702
739
  anchorBlockHeader,
703
- this.contractStore,
704
- this.noteStore,
705
- this.keyStore,
706
- this.addressStore,
707
- this.stateMachine.node,
708
- this.stateMachine.anchorBlockStore,
709
- this.recipientTaggingStore,
710
- this.senderAddressBookStore,
711
- this.capsuleStore,
712
- this.privateEventStore,
713
- this.jobId,
714
- );
740
+ contractStore: this.contractStore,
741
+ noteStore: this.noteStore,
742
+ keyStore: this.keyStore,
743
+ addressStore: this.addressStore,
744
+ aztecNode: this.stateMachine.node,
745
+ recipientTaggingStore: this.recipientTaggingStore,
746
+ senderAddressBookStore: this.senderAddressBookStore,
747
+ capsuleStore: this.capsuleStore,
748
+ privateEventStore: this.privateEventStore,
749
+ messageContextService: this.stateMachine.messageContextService,
750
+ contractSyncService: this.contractSyncService,
751
+ jobId,
752
+ scopes,
753
+ });
715
754
  const acirExecutionResult = await new WASMSimulator()
716
755
  .executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
717
756
  .catch((err: Error) => {
@@ -727,10 +766,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
727
766
  );
728
767
  });
729
768
 
730
- this.logger.verbose(`Utility simulation for ${call.to}.${call.selector} completed`);
769
+ this.logger.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
731
770
  return witnessMapToFields(acirExecutionResult.returnWitness);
732
771
  } catch (err) {
733
- throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility simulation'));
772
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility execution'));
734
773
  }
735
774
  }
736
775