@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
@@ -4,7 +4,7 @@ import { Schnorr } from '@aztec/foundation/crypto/schnorr';
4
4
  import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import { LogLevels, applyStringFormatting, createLogger } from '@aztec/foundation/log';
6
6
  import { TestDateProvider } from '@aztec/foundation/timer';
7
- import { ORACLE_VERSION, enrichPublicSimulationError, syncState } from '@aztec/pxe/server';
7
+ import { ORACLE_VERSION, enrichPublicSimulationError } from '@aztec/pxe/server';
8
8
  import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, Oracle, PrivateExecutionOracle, UtilityExecutionOracle, executePrivateFunction, generateSimulatedProvingResult } from '@aztec/pxe/simulator';
9
9
  import { ExecutionError, WASMSimulator, createSimulationError, extractCallStack, resolveAssertionMessageFromError, toACVMWitness, witnessMapToFields } from '@aztec/simulator/client';
10
10
  import { CppPublicTxSimulator, GuardedMerkleTreeOperations, PublicContractsDB, PublicProcessor } from '@aztec/simulator/server';
@@ -36,15 +36,15 @@ export class TXEOracleTopLevelContext {
36
36
  senderAddressBookStore;
37
37
  capsuleStore;
38
38
  privateEventStore;
39
- jobId;
40
39
  nextBlockTimestamp;
41
40
  version;
42
41
  chainId;
43
42
  authwits;
43
+ contractSyncService;
44
44
  isMisc;
45
45
  isTxe;
46
46
  logger;
47
- constructor(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobId, nextBlockTimestamp, version, chainId, authwits){
47
+ constructor(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, nextBlockTimestamp, version, chainId, authwits, contractSyncService){
48
48
  this.stateMachine = stateMachine;
49
49
  this.contractStore = contractStore;
50
50
  this.noteStore = noteStore;
@@ -56,49 +56,50 @@ export class TXEOracleTopLevelContext {
56
56
  this.senderAddressBookStore = senderAddressBookStore;
57
57
  this.capsuleStore = capsuleStore;
58
58
  this.privateEventStore = privateEventStore;
59
- this.jobId = jobId;
60
59
  this.nextBlockTimestamp = nextBlockTimestamp;
61
60
  this.version = version;
62
61
  this.chainId = chainId;
63
62
  this.authwits = authwits;
63
+ this.contractSyncService = contractSyncService;
64
64
  this.isMisc = true;
65
65
  this.isTxe = true;
66
66
  this.logger = createLogger('txe:top_level_context');
67
67
  this.logger.debug('Entering Top Level Context');
68
68
  }
69
- utilityAssertCompatibleOracleVersion(version) {
69
+ assertCompatibleOracleVersion(version) {
70
70
  if (version !== ORACLE_VERSION) {
71
71
  throw new Error(`Incompatible oracle version. TXE is using version '${ORACLE_VERSION}', but got a request for '${version}'.`);
72
72
  }
73
73
  }
74
74
  // This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
75
75
  // setup.
76
- utilityGetRandomField() {
76
+ getRandomField() {
77
77
  return Fr.random();
78
78
  }
79
79
  // We instruct users to debug contracts via this oracle, so it makes sense that they'd expect it to also work in tests
80
- utilityDebugLog(level, message, fields) {
80
+ log(level, message, fields) {
81
81
  if (!LogLevels[level]) {
82
- throw new Error(`Invalid debug log level: ${level}`);
82
+ throw new Error(`Invalid log level: ${level}`);
83
83
  }
84
84
  const levelName = LogLevels[level];
85
85
  this.logger[levelName](`${applyStringFormatting(message, fields)}`, {
86
86
  module: `${this.logger.module}:debug_log`
87
87
  });
88
+ return Promise.resolve();
88
89
  }
89
- txeGetDefaultAddress() {
90
+ getDefaultAddress() {
90
91
  return DEFAULT_ADDRESS;
91
92
  }
92
- async txeGetNextBlockNumber() {
93
+ async getNextBlockNumber() {
93
94
  return BlockNumber(await this.getLastBlockNumber() + 1);
94
95
  }
95
- txeGetNextBlockTimestamp() {
96
+ getNextBlockTimestamp() {
96
97
  return Promise.resolve(this.nextBlockTimestamp);
97
98
  }
98
- async txeGetLastBlockTimestamp() {
99
+ async getLastBlockTimestamp() {
99
100
  return (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.timestamp;
100
101
  }
101
- async txeGetLastTxEffects() {
102
+ async getLastTxEffects() {
102
103
  const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
103
104
  const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
104
105
  if (block.body.txEffects.length != 1) {
@@ -112,7 +113,19 @@ export class TXEOracleTopLevelContext {
112
113
  nullifiers: txEffects.nullifiers
113
114
  };
114
115
  }
115
- async txeGetPrivateEvents(selector, contractAddress, scope) {
116
+ async syncContractNonOracleMethod(contractAddress, scope, jobId) {
117
+ if (contractAddress.equals(DEFAULT_ADDRESS)) {
118
+ this.logger.debug(`Skipping sync in getPrivateEvents because the events correspond to the default address.`);
119
+ return;
120
+ }
121
+ const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
122
+ await this.stateMachine.contractSyncService.ensureContractSynced(contractAddress, null, async (call, execScopes)=>{
123
+ await this.executeUtilityCall(call, execScopes, jobId);
124
+ }, blockHeader, jobId, [
125
+ scope
126
+ ]);
127
+ }
128
+ async getPrivateEvents(selector, contractAddress, scope) {
116
129
  return (await this.privateEventStore.getPrivateEvents(selector, {
117
130
  contractAddress,
118
131
  scopes: [
@@ -122,17 +135,17 @@ export class TXEOracleTopLevelContext {
122
135
  toBlock: await this.getLastBlockNumber() + 1
123
136
  })).map((e)=>e.packedEvent);
124
137
  }
125
- async txeAdvanceBlocksBy(blocks) {
138
+ async advanceBlocksBy(blocks) {
126
139
  this.logger.debug(`time traveling ${blocks} blocks`);
127
140
  for(let i = 0; i < blocks; i++){
128
141
  await this.mineBlock();
129
142
  }
130
143
  }
131
- txeAdvanceTimestampBy(duration) {
144
+ advanceTimestampBy(duration) {
132
145
  this.logger.debug(`time traveling ${duration} seconds`);
133
146
  this.nextBlockTimestamp += duration;
134
147
  }
135
- async txeDeploy(artifact, instance, secret) {
148
+ async deploy(artifact, instance, secret) {
136
149
  // Emit deployment nullifier
137
150
  await this.mineBlock({
138
151
  nullifiers: [
@@ -140,25 +153,25 @@ export class TXEOracleTopLevelContext {
140
153
  ]
141
154
  });
142
155
  if (!secret.equals(Fr.ZERO)) {
143
- await this.txeAddAccount(artifact, instance, secret);
156
+ await this.addAccount(artifact, instance, secret);
144
157
  } else {
145
158
  await this.contractStore.addContractInstance(instance);
146
- await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
159
+ await this.contractStore.addContractArtifact(artifact);
147
160
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
148
161
  }
149
162
  }
150
- async txeAddAccount(artifact, instance, secret) {
163
+ async addAccount(artifact, instance, secret) {
151
164
  const partialAddress = await computePartialAddress(instance);
152
165
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
153
166
  await this.contractStore.addContractInstance(instance);
154
- await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
167
+ await this.contractStore.addContractArtifact(artifact);
155
168
  const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
156
169
  await this.accountStore.setAccount(completeAddress.address, completeAddress);
157
170
  await this.addressStore.addCompleteAddress(completeAddress);
158
171
  this.logger.debug(`Created account ${completeAddress.address}`);
159
172
  return completeAddress;
160
173
  }
161
- async txeCreateAccount(secret) {
174
+ async createAccount(secret) {
162
175
  // This is a foot gun !
163
176
  const completeAddress = await this.keyStore.addAccount(secret, secret);
164
177
  await this.accountStore.setAccount(completeAddress.address, completeAddress);
@@ -166,7 +179,7 @@ export class TXEOracleTopLevelContext {
166
179
  this.logger.debug(`Created account ${completeAddress.address}`);
167
180
  return completeAddress;
168
181
  }
169
- async txeAddAuthWitness(address, messageHash) {
182
+ async addAuthWitness(address, messageHash) {
170
183
  const account = await this.accountStore.getAccount(address);
171
184
  const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
172
185
  const schnorr = new Schnorr();
@@ -177,7 +190,7 @@ export class TXEOracleTopLevelContext {
177
190
  this.authwits.set(authWitness.requestHash.toString(), authWitness);
178
191
  }
179
192
  async mineBlock(options = {}) {
180
- const blockNumber = await this.txeGetNextBlockNumber();
193
+ const blockNumber = await this.getNextBlockNumber();
181
194
  const txEffect = TxEffect.empty();
182
195
  txEffect.nullifiers = [
183
196
  getSingleTxBlockRequestHash(blockNumber),
@@ -199,25 +212,30 @@ export class TXEOracleTopLevelContext {
199
212
  this.logger.info(`Created block ${blockNumber} with timestamp ${block.header.globalVariables.timestamp}`);
200
213
  await this.stateMachine.handleL2Block(block);
201
214
  }
202
- async txePrivateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false) {
215
+ async privateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false, jobId) {
203
216
  this.logger.verbose(`Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`);
204
217
  const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
205
218
  if (!artifact) {
206
219
  const message = functionSelector.equals(await FunctionSelector.fromSignature('verify_private_authwit(Field)')) ? 'Found no account contract artifact for a private authwit check - use `create_contract_account` instead of `create_light_account` for authwit support.' : 'Function Artifact does not exist';
207
220
  throw new Error(message);
208
221
  }
222
+ // When `from` is the zero address (e.g. when deploying a new account contract), we return an
223
+ // empty scope list which acts as deny-all: no notes are visible and no keys are accessible.
224
+ const effectiveScopes = from.isZero() ? [] : [
225
+ from
226
+ ];
209
227
  // Sync notes before executing private function to discover notes from previous transactions
210
- const utilityExecutor = async (call)=>{
211
- await this.executeUtilityCall(call);
228
+ const utilityExecutor = async (call, execScopes)=>{
229
+ await this.executeUtilityCall(call, execScopes, jobId);
212
230
  };
213
- await syncState(targetContractAddress, this.contractStore, functionSelector, utilityExecutor);
214
- const blockNumber = await this.txeGetNextBlockNumber();
231
+ const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
232
+ await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, utilityExecutor, blockHeader, jobId, effectiveScopes);
233
+ const blockNumber = await this.getNextBlockNumber();
215
234
  const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
216
235
  const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
217
236
  const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
218
237
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
219
238
  const txContext = new TxContext(this.chainId, this.version, gasSettings);
220
- const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
221
239
  const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
222
240
  const noteCache = new ExecutionNoteCache(protocolNullifier);
223
241
  // In production, the account contract sets the min revertible counter before calling the app function.
@@ -227,12 +245,40 @@ export class TXEOracleTopLevelContext {
227
245
  await noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
228
246
  const taggingIndexCache = new ExecutionTaggingIndexCache();
229
247
  const simulator = new WASMSimulator();
230
- const privateExecutionOracle = new PrivateExecutionOracle(argsHash, txContext, callContext, /** Header of a block whose state is used during private execution (not the block the transaction is included in). */ blockHeader, utilityExecutor, /** List of transient auth witnesses to be used during this simulation */ Array.from(this.authwits.values()), /** List of transient auth witnesses to be used during this simulation */ [], HashedValuesCache.create([
231
- new HashedValues(args, argsHash)
232
- ]), noteCache, taggingIndexCache, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.stateMachine.node, this.stateMachine.anchorBlockStore, this.senderTaggingStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.jobId, 0, minRevertibleSideEffectCounter, undefined, undefined, /**
233
- * In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
234
- * contract would perform, including setting senderForTags.
235
- */ from, simulator);
248
+ const privateExecutionOracle = new PrivateExecutionOracle({
249
+ argsHash,
250
+ txContext,
251
+ callContext,
252
+ anchorBlockHeader: blockHeader,
253
+ utilityExecutor,
254
+ authWitnesses: Array.from(this.authwits.values()),
255
+ capsules: [],
256
+ executionCache: HashedValuesCache.create([
257
+ new HashedValues(args, argsHash)
258
+ ]),
259
+ noteCache,
260
+ taggingIndexCache,
261
+ contractStore: this.contractStore,
262
+ noteStore: this.noteStore,
263
+ keyStore: this.keyStore,
264
+ addressStore: this.addressStore,
265
+ aztecNode: this.stateMachine.node,
266
+ senderTaggingStore: this.senderTaggingStore,
267
+ recipientTaggingStore: this.recipientTaggingStore,
268
+ senderAddressBookStore: this.senderAddressBookStore,
269
+ capsuleStore: this.capsuleStore,
270
+ privateEventStore: this.privateEventStore,
271
+ contractSyncService: this.stateMachine.contractSyncService,
272
+ jobId,
273
+ totalPublicCalldataCount: 0,
274
+ sideEffectCounter: minRevertibleSideEffectCounter,
275
+ scopes: effectiveScopes,
276
+ // In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
277
+ // contract would perform, including setting senderForTags.
278
+ senderForTags: from,
279
+ simulator,
280
+ messageContextService: this.stateMachine.messageContextService
281
+ });
236
282
  // 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.
237
283
  let result;
238
284
  let executionResult;
@@ -244,7 +290,7 @@ export class TXEOracleTopLevelContext {
244
290
  r.publicInputs.publicTeardownCallRequest
245
291
  ]));
246
292
  const publicFunctionsCalldata = await Promise.all(publicCallRequests.map(async (r)=>{
247
- const calldata = await privateExecutionOracle.privateLoadFromExecutionCache(r.calldataHash);
293
+ const calldata = await privateExecutionOracle.loadFromExecutionCache(r.calldataHash);
248
294
  return new HashedValues(calldata, r.calldataHash);
249
295
  }));
250
296
  noteCache.finish();
@@ -256,7 +302,7 @@ export class TXEOracleTopLevelContext {
256
302
  // According to the protocol rules, there must be at least one nullifier in the tx. The first nullifier is used as
257
303
  // the nonce generator for the note hashes.
258
304
  // We pass the non-zero minRevertibleSideEffectCounter to make sure the side effects are split correctly.
259
- const { publicInputs } = await generateSimulatedProvingResult(result, this.contractStore, minRevertibleSideEffectCounter);
305
+ const { publicInputs } = await generateSimulatedProvingResult(result, (addr, sel)=>this.contractStore.getDebugFunctionName(addr, sel), this.stateMachine.node, minRevertibleSideEffectCounter);
260
306
  const globals = makeGlobalVariables();
261
307
  globals.blockNumber = blockNumber;
262
308
  globals.timestamp = this.nextBlockTimestamp;
@@ -324,9 +370,9 @@ export class TXEOracleTopLevelContext {
324
370
  await forkedWorldTrees.close();
325
371
  return executionResult.returnValues ?? [];
326
372
  }
327
- async txePublicCallNewFlow(from, targetContractAddress, calldata, isStaticCall) {
373
+ async publicCallNewFlow(from, targetContractAddress, calldata, isStaticCall) {
328
374
  this.logger.verbose(`Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`);
329
- const blockNumber = await this.txeGetNextBlockNumber();
375
+ const blockNumber = await this.getNextBlockNumber();
330
376
  const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
331
377
  const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
332
378
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
@@ -365,7 +411,7 @@ export class TXEOracleTopLevelContext {
365
411
  revertibleAccumulatedData.publicCallRequests[0] = new PublicCallRequest(from, targetContractAddress, isStaticCall, calldataHash);
366
412
  const inputsForPublic = new PartialPrivateTailPublicInputsForPublic(nonRevertibleAccumulatedData, revertibleAccumulatedData, PublicCallRequest.empty());
367
413
  const constantData = new TxConstantData(anchorBlockHeader, txContext, Fr.zero(), Fr.zero());
368
- const txData = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*includeByTimestamp=*/ 0n, inputsForPublic, undefined);
414
+ const txData = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*expirationTimestamp=*/ 0n, inputsForPublic, undefined);
369
415
  const tx = await Tx.create({
370
416
  data: txData,
371
417
  chonkProof: ChonkProof.empty(),
@@ -418,19 +464,29 @@ export class TXEOracleTopLevelContext {
418
464
  await forkedWorldTrees.close();
419
465
  return returnValues ?? [];
420
466
  }
421
- async txeSimulateUtilityFunction(targetContractAddress, functionSelector, args) {
467
+ async executeUtilityFunction(targetContractAddress, functionSelector, args, jobId) {
422
468
  const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
423
469
  if (!artifact) {
424
470
  throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
425
471
  }
426
472
  // Sync notes before executing utility function to discover notes from previous transactions
427
- await syncState(targetContractAddress, this.contractStore, functionSelector, async (call)=>{
428
- await this.executeUtilityCall(call);
473
+ const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
474
+ await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, async (call, execScopes)=>{
475
+ await this.executeUtilityCall(call, execScopes, jobId);
476
+ }, blockHeader, jobId, 'ALL_SCOPES');
477
+ const call = FunctionCall.from({
478
+ name: artifact.name,
479
+ to: targetContractAddress,
480
+ selector: functionSelector,
481
+ type: FunctionType.UTILITY,
482
+ hideMsgSender: false,
483
+ isStatic: false,
484
+ args,
485
+ returnTypes: []
429
486
  });
430
- const call = new FunctionCall(artifact.name, targetContractAddress, functionSelector, FunctionType.UTILITY, false, false, args, []);
431
- return this.executeUtilityCall(call);
487
+ return this.executeUtilityCall(call, 'ALL_SCOPES', jobId);
432
488
  }
433
- async executeUtilityCall(call) {
489
+ async executeUtilityCall(call, scopes, jobId) {
434
490
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
435
491
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
436
492
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
@@ -441,7 +497,25 @@ export class TXEOracleTopLevelContext {
441
497
  });
442
498
  try {
443
499
  const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
444
- const oracle = new UtilityExecutionOracle(call.to, [], [], anchorBlockHeader, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.stateMachine.node, this.stateMachine.anchorBlockStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.jobId);
500
+ const oracle = new UtilityExecutionOracle({
501
+ contractAddress: call.to,
502
+ authWitnesses: [],
503
+ capsules: [],
504
+ anchorBlockHeader,
505
+ contractStore: this.contractStore,
506
+ noteStore: this.noteStore,
507
+ keyStore: this.keyStore,
508
+ addressStore: this.addressStore,
509
+ aztecNode: this.stateMachine.node,
510
+ recipientTaggingStore: this.recipientTaggingStore,
511
+ senderAddressBookStore: this.senderAddressBookStore,
512
+ capsuleStore: this.capsuleStore,
513
+ privateEventStore: this.privateEventStore,
514
+ messageContextService: this.stateMachine.messageContextService,
515
+ contractSyncService: this.contractSyncService,
516
+ jobId,
517
+ scopes
518
+ });
445
519
  const acirExecutionResult = await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
446
520
  err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
447
521
  throw new ExecutionError(err.message, {
@@ -451,10 +525,10 @@ export class TXEOracleTopLevelContext {
451
525
  cause: err
452
526
  });
453
527
  });
454
- this.logger.verbose(`Utility simulation for ${call.to}.${call.selector} completed`);
528
+ this.logger.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
455
529
  return witnessMapToFields(acirExecutionResult.returnWitness);
456
530
  } catch (err) {
457
- throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility simulation'));
531
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility execution'));
458
532
  }
459
533
  }
460
534
  close() {