@aztec/txe 0.0.1-commit.0b941701 → 0.0.1-commit.10bd49492

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 (52) 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 +14 -15
  9. package/dest/oracle/txe_oracle_top_level_context.d.ts +22 -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 +128 -55
  12. package/dest/rpc_translator.d.ts +85 -83
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +279 -169
  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 +3 -1
  25. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  26. package/dest/state_machine/mock_epoch_cache.js +4 -0
  27. package/dest/txe_session.d.ts +9 -6
  28. package/dest/txe_session.d.ts.map +1 -1
  29. package/dest/txe_session.js +86 -24
  30. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  31. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  32. package/dest/util/txe_public_contract_data_source.js +5 -22
  33. package/dest/utils/block_creation.d.ts +1 -1
  34. package/dest/utils/block_creation.d.ts.map +1 -1
  35. package/dest/utils/block_creation.js +3 -1
  36. package/package.json +15 -15
  37. package/src/index.ts +89 -52
  38. package/src/oracle/interfaces.ts +32 -31
  39. package/src/oracle/txe_oracle_public_context.ts +14 -16
  40. package/src/oracle/txe_oracle_top_level_context.ts +157 -103
  41. package/src/rpc_translator.ts +309 -183
  42. package/src/state_machine/archiver.ts +7 -5
  43. package/src/state_machine/dummy_p2p_client.ts +40 -22
  44. package/src/state_machine/index.ts +29 -9
  45. package/src/state_machine/mock_epoch_cache.ts +5 -0
  46. package/src/txe_session.ts +95 -84
  47. package/src/util/txe_public_contract_data_source.ts +10 -36
  48. package/src/utils/block_creation.ts +3 -1
  49. package/dest/util/txe_contract_store.d.ts +0 -12
  50. package/dest/util/txe_contract_store.d.ts.map +0 -1
  51. package/dest/util/txe_contract_store.js +0 -22
  52. 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,7 +36,6 @@ export class TXEOracleTopLevelContext {
36
36
  senderAddressBookStore;
37
37
  capsuleStore;
38
38
  privateEventStore;
39
- jobId;
40
39
  nextBlockTimestamp;
41
40
  version;
42
41
  chainId;
@@ -44,7 +43,7 @@ export class TXEOracleTopLevelContext {
44
43
  isMisc;
45
44
  isTxe;
46
45
  logger;
47
- constructor(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobId, nextBlockTimestamp, version, chainId, authwits){
46
+ constructor(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, nextBlockTimestamp, version, chainId, authwits){
48
47
  this.stateMachine = stateMachine;
49
48
  this.contractStore = contractStore;
50
49
  this.noteStore = noteStore;
@@ -56,7 +55,6 @@ export class TXEOracleTopLevelContext {
56
55
  this.senderAddressBookStore = senderAddressBookStore;
57
56
  this.capsuleStore = capsuleStore;
58
57
  this.privateEventStore = privateEventStore;
59
- this.jobId = jobId;
60
58
  this.nextBlockTimestamp = nextBlockTimestamp;
61
59
  this.version = version;
62
60
  this.chainId = chainId;
@@ -66,39 +64,40 @@ export class TXEOracleTopLevelContext {
66
64
  this.logger = createLogger('txe:top_level_context');
67
65
  this.logger.debug('Entering Top Level Context');
68
66
  }
69
- utilityAssertCompatibleOracleVersion(version) {
67
+ assertCompatibleOracleVersion(version) {
70
68
  if (version !== ORACLE_VERSION) {
71
69
  throw new Error(`Incompatible oracle version. TXE is using version '${ORACLE_VERSION}', but got a request for '${version}'.`);
72
70
  }
73
71
  }
74
72
  // This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
75
73
  // setup.
76
- utilityGetRandomField() {
74
+ getRandomField() {
77
75
  return Fr.random();
78
76
  }
79
77
  // 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) {
78
+ log(level, message, fields) {
81
79
  if (!LogLevels[level]) {
82
- throw new Error(`Invalid debug log level: ${level}`);
80
+ throw new Error(`Invalid log level: ${level}`);
83
81
  }
84
82
  const levelName = LogLevels[level];
85
83
  this.logger[levelName](`${applyStringFormatting(message, fields)}`, {
86
84
  module: `${this.logger.module}:debug_log`
87
85
  });
86
+ return Promise.resolve();
88
87
  }
89
- txeGetDefaultAddress() {
88
+ getDefaultAddress() {
90
89
  return DEFAULT_ADDRESS;
91
90
  }
92
- async txeGetNextBlockNumber() {
91
+ async getNextBlockNumber() {
93
92
  return BlockNumber(await this.getLastBlockNumber() + 1);
94
93
  }
95
- txeGetNextBlockTimestamp() {
94
+ getNextBlockTimestamp() {
96
95
  return Promise.resolve(this.nextBlockTimestamp);
97
96
  }
98
- async txeGetLastBlockTimestamp() {
97
+ async getLastBlockTimestamp() {
99
98
  return (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.timestamp;
100
99
  }
101
- async txeGetLastTxEffects() {
100
+ async getLastTxEffects() {
102
101
  const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
103
102
  const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
104
103
  if (block.body.txEffects.length != 1) {
@@ -112,7 +111,19 @@ export class TXEOracleTopLevelContext {
112
111
  nullifiers: txEffects.nullifiers
113
112
  };
114
113
  }
115
- async txeGetPrivateEvents(selector, contractAddress, scope) {
114
+ async syncContractNonOracleMethod(contractAddress, scope, jobId) {
115
+ if (contractAddress.equals(DEFAULT_ADDRESS)) {
116
+ this.logger.debug(`Skipping sync in getPrivateEvents because the events correspond to the default address.`);
117
+ return;
118
+ }
119
+ const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
120
+ await this.stateMachine.contractSyncService.ensureContractSynced(contractAddress, null, async (call, execScopes)=>{
121
+ await this.executeUtilityCall(call, execScopes, jobId);
122
+ }, blockHeader, jobId, [
123
+ scope
124
+ ]);
125
+ }
126
+ async getPrivateEvents(selector, contractAddress, scope) {
116
127
  return (await this.privateEventStore.getPrivateEvents(selector, {
117
128
  contractAddress,
118
129
  scopes: [
@@ -122,17 +133,17 @@ export class TXEOracleTopLevelContext {
122
133
  toBlock: await this.getLastBlockNumber() + 1
123
134
  })).map((e)=>e.packedEvent);
124
135
  }
125
- async txeAdvanceBlocksBy(blocks) {
136
+ async advanceBlocksBy(blocks) {
126
137
  this.logger.debug(`time traveling ${blocks} blocks`);
127
138
  for(let i = 0; i < blocks; i++){
128
139
  await this.mineBlock();
129
140
  }
130
141
  }
131
- txeAdvanceTimestampBy(duration) {
142
+ advanceTimestampBy(duration) {
132
143
  this.logger.debug(`time traveling ${duration} seconds`);
133
144
  this.nextBlockTimestamp += duration;
134
145
  }
135
- async txeDeploy(artifact, instance, secret) {
146
+ async deploy(artifact, instance, secret) {
136
147
  // Emit deployment nullifier
137
148
  await this.mineBlock({
138
149
  nullifiers: [
@@ -140,25 +151,25 @@ export class TXEOracleTopLevelContext {
140
151
  ]
141
152
  });
142
153
  if (!secret.equals(Fr.ZERO)) {
143
- await this.txeAddAccount(artifact, instance, secret);
154
+ await this.addAccount(artifact, instance, secret);
144
155
  } else {
145
156
  await this.contractStore.addContractInstance(instance);
146
- await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
157
+ await this.contractStore.addContractArtifact(artifact);
147
158
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
148
159
  }
149
160
  }
150
- async txeAddAccount(artifact, instance, secret) {
161
+ async addAccount(artifact, instance, secret) {
151
162
  const partialAddress = await computePartialAddress(instance);
152
163
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
153
164
  await this.contractStore.addContractInstance(instance);
154
- await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
165
+ await this.contractStore.addContractArtifact(artifact);
155
166
  const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
156
167
  await this.accountStore.setAccount(completeAddress.address, completeAddress);
157
168
  await this.addressStore.addCompleteAddress(completeAddress);
158
169
  this.logger.debug(`Created account ${completeAddress.address}`);
159
170
  return completeAddress;
160
171
  }
161
- async txeCreateAccount(secret) {
172
+ async createAccount(secret) {
162
173
  // This is a foot gun !
163
174
  const completeAddress = await this.keyStore.addAccount(secret, secret);
164
175
  await this.accountStore.setAccount(completeAddress.address, completeAddress);
@@ -166,7 +177,7 @@ export class TXEOracleTopLevelContext {
166
177
  this.logger.debug(`Created account ${completeAddress.address}`);
167
178
  return completeAddress;
168
179
  }
169
- async txeAddAuthWitness(address, messageHash) {
180
+ async addAuthWitness(address, messageHash) {
170
181
  const account = await this.accountStore.getAccount(address);
171
182
  const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
172
183
  const schnorr = new Schnorr();
@@ -177,7 +188,7 @@ export class TXEOracleTopLevelContext {
177
188
  this.authwits.set(authWitness.requestHash.toString(), authWitness);
178
189
  }
179
190
  async mineBlock(options = {}) {
180
- const blockNumber = await this.txeGetNextBlockNumber();
191
+ const blockNumber = await this.getNextBlockNumber();
181
192
  const txEffect = TxEffect.empty();
182
193
  txEffect.nullifiers = [
183
194
  getSingleTxBlockRequestHash(blockNumber),
@@ -199,25 +210,30 @@ export class TXEOracleTopLevelContext {
199
210
  this.logger.info(`Created block ${blockNumber} with timestamp ${block.header.globalVariables.timestamp}`);
200
211
  await this.stateMachine.handleL2Block(block);
201
212
  }
202
- async txePrivateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false) {
213
+ async privateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false, jobId) {
203
214
  this.logger.verbose(`Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`);
204
215
  const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
205
216
  if (!artifact) {
206
217
  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
218
  throw new Error(message);
208
219
  }
220
+ // When `from` is the zero address (e.g. when deploying a new account contract), we return an
221
+ // empty scope list which acts as deny-all: no notes are visible and no keys are accessible.
222
+ const effectiveScopes = from.isZero() ? [] : [
223
+ from
224
+ ];
209
225
  // Sync notes before executing private function to discover notes from previous transactions
210
- const utilityExecutor = async (call)=>{
211
- await this.executeUtilityCall(call);
226
+ const utilityExecutor = async (call, execScopes)=>{
227
+ await this.executeUtilityCall(call, execScopes, jobId);
212
228
  };
213
- await syncState(targetContractAddress, this.contractStore, functionSelector, utilityExecutor);
214
- const blockNumber = await this.txeGetNextBlockNumber();
229
+ const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
230
+ await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, utilityExecutor, blockHeader, jobId, effectiveScopes);
231
+ const blockNumber = await this.getNextBlockNumber();
215
232
  const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
216
233
  const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
217
234
  const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
218
235
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
219
236
  const txContext = new TxContext(this.chainId, this.version, gasSettings);
220
- const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
221
237
  const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
222
238
  const noteCache = new ExecutionNoteCache(protocolNullifier);
223
239
  // In production, the account contract sets the min revertible counter before calling the app function.
@@ -227,12 +243,40 @@ export class TXEOracleTopLevelContext {
227
243
  await noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
228
244
  const taggingIndexCache = new ExecutionTaggingIndexCache();
229
245
  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);
246
+ const privateExecutionOracle = new PrivateExecutionOracle({
247
+ argsHash,
248
+ txContext,
249
+ callContext,
250
+ anchorBlockHeader: blockHeader,
251
+ utilityExecutor,
252
+ authWitnesses: Array.from(this.authwits.values()),
253
+ capsules: [],
254
+ executionCache: HashedValuesCache.create([
255
+ new HashedValues(args, argsHash)
256
+ ]),
257
+ noteCache,
258
+ taggingIndexCache,
259
+ contractStore: this.contractStore,
260
+ noteStore: this.noteStore,
261
+ keyStore: this.keyStore,
262
+ addressStore: this.addressStore,
263
+ aztecNode: this.stateMachine.node,
264
+ senderTaggingStore: this.senderTaggingStore,
265
+ recipientTaggingStore: this.recipientTaggingStore,
266
+ senderAddressBookStore: this.senderAddressBookStore,
267
+ capsuleStore: this.capsuleStore,
268
+ privateEventStore: this.privateEventStore,
269
+ contractSyncService: this.stateMachine.contractSyncService,
270
+ jobId,
271
+ totalPublicCalldataCount: 0,
272
+ sideEffectCounter: minRevertibleSideEffectCounter,
273
+ scopes: effectiveScopes,
274
+ // In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
275
+ // contract would perform, including setting senderForTags.
276
+ senderForTags: from,
277
+ simulator,
278
+ messageContextService: this.stateMachine.messageContextService
279
+ });
236
280
  // 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
281
  let result;
238
282
  let executionResult;
@@ -244,7 +288,7 @@ export class TXEOracleTopLevelContext {
244
288
  r.publicInputs.publicTeardownCallRequest
245
289
  ]));
246
290
  const publicFunctionsCalldata = await Promise.all(publicCallRequests.map(async (r)=>{
247
- const calldata = await privateExecutionOracle.privateLoadFromExecutionCache(r.calldataHash);
291
+ const calldata = await privateExecutionOracle.loadFromExecutionCache(r.calldataHash);
248
292
  return new HashedValues(calldata, r.calldataHash);
249
293
  }));
250
294
  noteCache.finish();
@@ -256,7 +300,7 @@ export class TXEOracleTopLevelContext {
256
300
  // According to the protocol rules, there must be at least one nullifier in the tx. The first nullifier is used as
257
301
  // the nonce generator for the note hashes.
258
302
  // We pass the non-zero minRevertibleSideEffectCounter to make sure the side effects are split correctly.
259
- const { publicInputs } = await generateSimulatedProvingResult(result, this.contractStore, minRevertibleSideEffectCounter);
303
+ const { publicInputs } = await generateSimulatedProvingResult(result, (addr, sel)=>this.contractStore.getDebugFunctionName(addr, sel), this.stateMachine.node, minRevertibleSideEffectCounter);
260
304
  const globals = makeGlobalVariables();
261
305
  globals.blockNumber = blockNumber;
262
306
  globals.timestamp = this.nextBlockTimestamp;
@@ -264,7 +308,8 @@ export class TXEOracleTopLevelContext {
264
308
  globals.version = this.version;
265
309
  globals.gasFees = GasFees.empty();
266
310
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
267
- const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore));
311
+ const bindings = this.logger.getBindings();
312
+ const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore), bindings);
268
313
  const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
269
314
  const config = PublicSimulatorConfig.from({
270
315
  skipFeeEnforcement: true,
@@ -273,7 +318,7 @@ export class TXEOracleTopLevelContext {
273
318
  collectStatistics: false,
274
319
  collectCallMetadata: true
275
320
  });
276
- const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config), new TestDateProvider());
321
+ const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config, bindings), new TestDateProvider(), undefined, createLogger('simulator:public-processor', bindings));
277
322
  const tx = await Tx.create({
278
323
  data: publicInputs,
279
324
  chonkProof: ChonkProof.empty(),
@@ -323,9 +368,9 @@ export class TXEOracleTopLevelContext {
323
368
  await forkedWorldTrees.close();
324
369
  return executionResult.returnValues ?? [];
325
370
  }
326
- async txePublicCallNewFlow(from, targetContractAddress, calldata, isStaticCall) {
371
+ async publicCallNewFlow(from, targetContractAddress, calldata, isStaticCall) {
327
372
  this.logger.verbose(`Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`);
328
- const blockNumber = await this.txeGetNextBlockNumber();
373
+ const blockNumber = await this.getNextBlockNumber();
329
374
  const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
330
375
  const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
331
376
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
@@ -340,7 +385,8 @@ export class TXEOracleTopLevelContext {
340
385
  globals.version = this.version;
341
386
  globals.gasFees = GasFees.empty();
342
387
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
343
- const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore));
388
+ const bindings2 = this.logger.getBindings();
389
+ const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore), bindings2);
344
390
  const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
345
391
  const config = PublicSimulatorConfig.from({
346
392
  skipFeeEnforcement: true,
@@ -349,8 +395,8 @@ export class TXEOracleTopLevelContext {
349
395
  collectStatistics: false,
350
396
  collectCallMetadata: true
351
397
  });
352
- const simulator = new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config);
353
- const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, simulator, new TestDateProvider());
398
+ const simulator = new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config, bindings2);
399
+ const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, simulator, new TestDateProvider(), undefined, createLogger('simulator:public-processor', bindings2));
354
400
  // We're simulating a scenario in which private execution immediately enqueues a public call and halts. The private
355
401
  // kernel init would in this case inject a nullifier with the transaction request hash as a non-revertible
356
402
  // side-effect, which the AVM then expects to exist in order to use it as the nonce generator when siloing notes as
@@ -363,7 +409,7 @@ export class TXEOracleTopLevelContext {
363
409
  revertibleAccumulatedData.publicCallRequests[0] = new PublicCallRequest(from, targetContractAddress, isStaticCall, calldataHash);
364
410
  const inputsForPublic = new PartialPrivateTailPublicInputsForPublic(nonRevertibleAccumulatedData, revertibleAccumulatedData, PublicCallRequest.empty());
365
411
  const constantData = new TxConstantData(anchorBlockHeader, txContext, Fr.zero(), Fr.zero());
366
- const txData = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*includeByTimestamp=*/ 0n, inputsForPublic, undefined);
412
+ const txData = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*expirationTimestamp=*/ 0n, inputsForPublic, undefined);
367
413
  const tx = await Tx.create({
368
414
  data: txData,
369
415
  chonkProof: ChonkProof.empty(),
@@ -416,19 +462,29 @@ export class TXEOracleTopLevelContext {
416
462
  await forkedWorldTrees.close();
417
463
  return returnValues ?? [];
418
464
  }
419
- async txeSimulateUtilityFunction(targetContractAddress, functionSelector, args) {
465
+ async executeUtilityFunction(targetContractAddress, functionSelector, args, jobId) {
420
466
  const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
421
467
  if (!artifact) {
422
468
  throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
423
469
  }
424
470
  // Sync notes before executing utility function to discover notes from previous transactions
425
- await syncState(targetContractAddress, this.contractStore, functionSelector, async (call)=>{
426
- await this.executeUtilityCall(call);
471
+ const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
472
+ await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, async (call, execScopes)=>{
473
+ await this.executeUtilityCall(call, execScopes, jobId);
474
+ }, blockHeader, jobId, 'ALL_SCOPES');
475
+ const call = FunctionCall.from({
476
+ name: artifact.name,
477
+ to: targetContractAddress,
478
+ selector: functionSelector,
479
+ type: FunctionType.UTILITY,
480
+ hideMsgSender: false,
481
+ isStatic: false,
482
+ args,
483
+ returnTypes: []
427
484
  });
428
- const call = new FunctionCall(artifact.name, targetContractAddress, functionSelector, FunctionType.UTILITY, false, false, args, []);
429
- return this.executeUtilityCall(call);
485
+ return this.executeUtilityCall(call, 'ALL_SCOPES', jobId);
430
486
  }
431
- async executeUtilityCall(call) {
487
+ async executeUtilityCall(call, scopes, jobId) {
432
488
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
433
489
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
434
490
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
@@ -439,7 +495,24 @@ export class TXEOracleTopLevelContext {
439
495
  });
440
496
  try {
441
497
  const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
442
- 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);
498
+ const oracle = new UtilityExecutionOracle({
499
+ contractAddress: call.to,
500
+ authWitnesses: [],
501
+ capsules: [],
502
+ anchorBlockHeader,
503
+ contractStore: this.contractStore,
504
+ noteStore: this.noteStore,
505
+ keyStore: this.keyStore,
506
+ addressStore: this.addressStore,
507
+ aztecNode: this.stateMachine.node,
508
+ recipientTaggingStore: this.recipientTaggingStore,
509
+ senderAddressBookStore: this.senderAddressBookStore,
510
+ capsuleStore: this.capsuleStore,
511
+ privateEventStore: this.privateEventStore,
512
+ messageContextService: this.stateMachine.messageContextService,
513
+ jobId,
514
+ scopes
515
+ });
443
516
  const acirExecutionResult = await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
444
517
  err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
445
518
  throw new ExecutionError(err.message, {
@@ -449,10 +522,10 @@ export class TXEOracleTopLevelContext {
449
522
  cause: err
450
523
  });
451
524
  });
452
- this.logger.verbose(`Utility simulation for ${call.to}.${call.selector} completed`);
525
+ this.logger.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
453
526
  return witnessMapToFields(acirExecutionResult.returnWitness);
454
527
  } catch (err) {
455
- throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility simulation'));
528
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility execution'));
456
529
  }
457
530
  }
458
531
  close() {