@aztec/txe 0.0.1-commit.f146247c → 0.0.1-commit.f1b29a41e

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