@aztec/txe 0.0.1-commit.8afd444 → 0.0.1-commit.8cb2d04d8

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 (64) 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 +28 -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 +143 -58
  12. package/dest/rpc_translator.d.ts +121 -83
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +384 -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 +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 +9 -4
  22. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  23. package/dest/state_machine/global_variable_builder.js +9 -3
  24. package/dest/state_machine/index.d.ts +7 -5
  25. package/dest/state_machine/index.d.ts.map +1 -1
  26. package/dest/state_machine/index.js +20 -11
  27. package/dest/state_machine/mock_epoch_cache.d.ts +20 -3
  28. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  29. package/dest/state_machine/mock_epoch_cache.js +39 -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 +96 -25
  36. package/dest/util/encoding.d.ts +71 -1
  37. package/dest/util/encoding.d.ts.map +1 -1
  38. package/dest/util/encoding.js +4 -0
  39. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  40. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  41. package/dest/util/txe_public_contract_data_source.js +6 -25
  42. package/dest/utils/block_creation.d.ts +1 -1
  43. package/dest/utils/block_creation.d.ts.map +1 -1
  44. package/dest/utils/block_creation.js +3 -1
  45. package/package.json +15 -15
  46. package/src/index.ts +89 -52
  47. package/src/oracle/interfaces.ts +32 -31
  48. package/src/oracle/txe_oracle_public_context.ts +12 -12
  49. package/src/oracle/txe_oracle_top_level_context.ts +156 -115
  50. package/src/rpc_translator.ts +446 -183
  51. package/src/state_machine/archiver.ts +8 -5
  52. package/src/state_machine/dummy_p2p_client.ts +46 -24
  53. package/src/state_machine/global_variable_builder.ts +18 -3
  54. package/src/state_machine/index.ts +32 -10
  55. package/src/state_machine/mock_epoch_cache.ts +51 -3
  56. package/src/state_machine/synchronizer.ts +4 -4
  57. package/src/txe_session.ts +102 -72
  58. package/src/util/encoding.ts +5 -0
  59. package/src/util/txe_public_contract_data_source.ts +10 -38
  60. package/src/utils/block_creation.ts +3 -1
  61. package/dest/util/txe_contract_store.d.ts +0 -12
  62. package/dest/util/txe_contract_store.d.ts.map +0 -1
  63. package/dest/util/txe_contract_store.js +0 -22
  64. package/src/util/txe_contract_store.ts +0 -36
@@ -1,10 +1,10 @@
1
- import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS, DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT, DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
1
+ import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS, MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
2
  import { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  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 { CapsuleService, ORACLE_VERSION_MAJOR, 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';
@@ -13,7 +13,7 @@ import { AuthWitness } from '@aztec/stdlib/auth-witness';
13
13
  import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
14
14
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
15
15
  import { computePartialAddress } from '@aztec/stdlib/contract';
16
- import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
16
+ import { FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT, Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
17
17
  import { computeCalldataHash, computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
18
18
  import { PartialPrivateTailPublicInputsForPublic, PrivateKernelTailCircuitPublicInputs, PrivateToPublicAccumulatedData, PublicCallRequest } from '@aztec/stdlib/kernel';
19
19
  import { ChonkProof } from '@aztec/stdlib/proofs';
@@ -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,60 @@ 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) {
70
- if (version !== ORACLE_VERSION) {
71
- throw new Error(`Incompatible oracle version. TXE is using version '${ORACLE_VERSION}', but got a request for '${version}'.`);
69
+ contractOracleVersion;
70
+ assertCompatibleOracleVersion(major, minor) {
71
+ if (major !== ORACLE_VERSION_MAJOR) {
72
+ const hint = major > ORACLE_VERSION_MAJOR ? '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.' : '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.';
73
+ throw new Error(`Incompatible aztec cli version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle major version ${ORACLE_VERSION_MAJOR}, got ${major})`);
72
74
  }
75
+ this.contractOracleVersion = {
76
+ major,
77
+ minor
78
+ };
79
+ }
80
+ // Prefixed with "nonOracleFunction" as it is not used as an oracle handler.
81
+ nonOracleFunctionGetContractOracleVersion() {
82
+ return this.contractOracleVersion;
73
83
  }
74
84
  // This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
75
85
  // setup.
76
- utilityGetRandomField() {
86
+ getRandomField() {
77
87
  return Fr.random();
78
88
  }
79
89
  // 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) {
90
+ log(level, message, fields) {
81
91
  if (!LogLevels[level]) {
82
- throw new Error(`Invalid debug log level: ${level}`);
92
+ throw new Error(`Invalid log level: ${level}`);
83
93
  }
84
94
  const levelName = LogLevels[level];
85
95
  this.logger[levelName](`${applyStringFormatting(message, fields)}`, {
86
96
  module: `${this.logger.module}:debug_log`
87
97
  });
98
+ return Promise.resolve();
88
99
  }
89
- txeGetDefaultAddress() {
100
+ getDefaultAddress() {
90
101
  return DEFAULT_ADDRESS;
91
102
  }
92
- async txeGetNextBlockNumber() {
103
+ async getNextBlockNumber() {
93
104
  return BlockNumber(await this.getLastBlockNumber() + 1);
94
105
  }
95
- txeGetNextBlockTimestamp() {
106
+ getNextBlockTimestamp() {
96
107
  return Promise.resolve(this.nextBlockTimestamp);
97
108
  }
98
- async txeGetLastBlockTimestamp() {
109
+ async getLastBlockTimestamp() {
99
110
  return (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.timestamp;
100
111
  }
101
- async txeGetLastTxEffects() {
112
+ async getLastTxEffects() {
102
113
  const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
103
114
  const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
104
115
  if (block.body.txEffects.length != 1) {
@@ -112,7 +123,19 @@ export class TXEOracleTopLevelContext {
112
123
  nullifiers: txEffects.nullifiers
113
124
  };
114
125
  }
115
- async txeGetPrivateEvents(selector, contractAddress, scope) {
126
+ async syncContractNonOracleMethod(contractAddress, scope, jobId) {
127
+ if (contractAddress.equals(DEFAULT_ADDRESS)) {
128
+ this.logger.debug(`Skipping sync in getPrivateEvents because the events correspond to the default address.`);
129
+ return;
130
+ }
131
+ const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
132
+ await this.stateMachine.contractSyncService.ensureContractSynced(contractAddress, null, async (call, execScopes)=>{
133
+ await this.executeUtilityCall(call, execScopes, jobId);
134
+ }, blockHeader, jobId, [
135
+ scope
136
+ ]);
137
+ }
138
+ async getPrivateEvents(selector, contractAddress, scope) {
116
139
  return (await this.privateEventStore.getPrivateEvents(selector, {
117
140
  contractAddress,
118
141
  scopes: [
@@ -122,17 +145,17 @@ export class TXEOracleTopLevelContext {
122
145
  toBlock: await this.getLastBlockNumber() + 1
123
146
  })).map((e)=>e.packedEvent);
124
147
  }
125
- async txeAdvanceBlocksBy(blocks) {
148
+ async advanceBlocksBy(blocks) {
126
149
  this.logger.debug(`time traveling ${blocks} blocks`);
127
150
  for(let i = 0; i < blocks; i++){
128
151
  await this.mineBlock();
129
152
  }
130
153
  }
131
- txeAdvanceTimestampBy(duration) {
154
+ advanceTimestampBy(duration) {
132
155
  this.logger.debug(`time traveling ${duration} seconds`);
133
156
  this.nextBlockTimestamp += duration;
134
157
  }
135
- async txeDeploy(artifact, instance, secret) {
158
+ async deploy(artifact, instance, secret) {
136
159
  // Emit deployment nullifier
137
160
  await this.mineBlock({
138
161
  nullifiers: [
@@ -140,25 +163,25 @@ export class TXEOracleTopLevelContext {
140
163
  ]
141
164
  });
142
165
  if (!secret.equals(Fr.ZERO)) {
143
- await this.txeAddAccount(artifact, instance, secret);
166
+ await this.addAccount(artifact, instance, secret);
144
167
  } else {
145
168
  await this.contractStore.addContractInstance(instance);
146
- await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
169
+ await this.contractStore.addContractArtifact(artifact);
147
170
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
148
171
  }
149
172
  }
150
- async txeAddAccount(artifact, instance, secret) {
173
+ async addAccount(artifact, instance, secret) {
151
174
  const partialAddress = await computePartialAddress(instance);
152
175
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
153
176
  await this.contractStore.addContractInstance(instance);
154
- await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
177
+ await this.contractStore.addContractArtifact(artifact);
155
178
  const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
156
179
  await this.accountStore.setAccount(completeAddress.address, completeAddress);
157
180
  await this.addressStore.addCompleteAddress(completeAddress);
158
181
  this.logger.debug(`Created account ${completeAddress.address}`);
159
182
  return completeAddress;
160
183
  }
161
- async txeCreateAccount(secret) {
184
+ async createAccount(secret) {
162
185
  // This is a foot gun !
163
186
  const completeAddress = await this.keyStore.addAccount(secret, secret);
164
187
  await this.accountStore.setAccount(completeAddress.address, completeAddress);
@@ -166,7 +189,7 @@ export class TXEOracleTopLevelContext {
166
189
  this.logger.debug(`Created account ${completeAddress.address}`);
167
190
  return completeAddress;
168
191
  }
169
- async txeAddAuthWitness(address, messageHash) {
192
+ async addAuthWitness(address, messageHash) {
170
193
  const account = await this.accountStore.getAccount(address);
171
194
  const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
172
195
  const schnorr = new Schnorr();
@@ -177,7 +200,7 @@ export class TXEOracleTopLevelContext {
177
200
  this.authwits.set(authWitness.requestHash.toString(), authWitness);
178
201
  }
179
202
  async mineBlock(options = {}) {
180
- const blockNumber = await this.txeGetNextBlockNumber();
203
+ const blockNumber = await this.getNextBlockNumber();
181
204
  const txEffect = TxEffect.empty();
182
205
  txEffect.nullifiers = [
183
206
  getSingleTxBlockRequestHash(blockNumber),
@@ -199,23 +222,28 @@ export class TXEOracleTopLevelContext {
199
222
  this.logger.info(`Created block ${blockNumber} with timestamp ${block.header.globalVariables.timestamp}`);
200
223
  await this.stateMachine.handleL2Block(block);
201
224
  }
202
- async txePrivateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false) {
225
+ async privateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false, jobId) {
203
226
  this.logger.verbose(`Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`);
204
227
  const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
205
228
  if (!artifact) {
206
229
  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
230
  throw new Error(message);
208
231
  }
232
+ // When `from` is the zero address (e.g. when deploying a new account contract), we return an
233
+ // empty scope list which acts as deny-all: no notes are visible and no keys are accessible.
234
+ const effectiveScopes = from.isZero() ? [] : [
235
+ from
236
+ ];
209
237
  // Sync notes before executing private function to discover notes from previous transactions
210
- const utilityExecutor = async (call)=>{
211
- await this.executeUtilityCall(call);
238
+ const utilityExecutor = async (call, execScopes)=>{
239
+ await this.executeUtilityCall(call, execScopes, jobId);
212
240
  };
213
241
  const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
214
- await syncState(targetContractAddress, this.contractStore, functionSelector, utilityExecutor, this.noteStore, this.stateMachine.node, blockHeader, this.jobId);
215
- const blockNumber = await this.txeGetNextBlockNumber();
242
+ await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, utilityExecutor, blockHeader, jobId, effectiveScopes);
243
+ const blockNumber = await this.getNextBlockNumber();
216
244
  const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
217
- const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
218
- const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
245
+ const gasLimits = new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
246
+ const teardownGasLimits = new Gas(FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT);
219
247
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
220
248
  const txContext = new TxContext(this.chainId, this.version, gasSettings);
221
249
  const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
@@ -227,12 +255,41 @@ export class TXEOracleTopLevelContext {
227
255
  await noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
228
256
  const taggingIndexCache = new ExecutionTaggingIndexCache();
229
257
  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.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);
258
+ const privateExecutionOracle = new PrivateExecutionOracle({
259
+ argsHash,
260
+ txContext,
261
+ callContext,
262
+ anchorBlockHeader: blockHeader,
263
+ utilityExecutor,
264
+ authWitnesses: Array.from(this.authwits.values()),
265
+ capsules: [],
266
+ executionCache: HashedValuesCache.create([
267
+ new HashedValues(args, argsHash)
268
+ ]),
269
+ noteCache,
270
+ taggingIndexCache,
271
+ contractStore: this.contractStore,
272
+ noteStore: this.noteStore,
273
+ keyStore: this.keyStore,
274
+ addressStore: this.addressStore,
275
+ aztecNode: this.stateMachine.node,
276
+ senderTaggingStore: this.senderTaggingStore,
277
+ recipientTaggingStore: this.recipientTaggingStore,
278
+ senderAddressBookStore: this.senderAddressBookStore,
279
+ capsuleService: new CapsuleService(this.capsuleStore, effectiveScopes),
280
+ privateEventStore: this.privateEventStore,
281
+ contractSyncService: this.stateMachine.contractSyncService,
282
+ jobId,
283
+ totalPublicCalldataCount: 0,
284
+ sideEffectCounter: minRevertibleSideEffectCounter,
285
+ scopes: effectiveScopes,
286
+ // In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
287
+ // contract would perform, including setting senderForTags.
288
+ senderForTags: from,
289
+ simulator,
290
+ messageContextService: this.stateMachine.messageContextService,
291
+ l2TipsStore: this.stateMachine.node
292
+ });
236
293
  // 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
294
  let result;
238
295
  let executionResult;
@@ -244,7 +301,7 @@ export class TXEOracleTopLevelContext {
244
301
  r.publicInputs.publicTeardownCallRequest
245
302
  ]));
246
303
  const publicFunctionsCalldata = await Promise.all(publicCallRequests.map(async (r)=>{
247
- const calldata = await privateExecutionOracle.privateLoadFromExecutionCache(r.calldataHash);
304
+ const calldata = await privateExecutionOracle.getHashPreimage(r.calldataHash);
248
305
  return new HashedValues(calldata, r.calldataHash);
249
306
  }));
250
307
  noteCache.finish();
@@ -256,7 +313,7 @@ export class TXEOracleTopLevelContext {
256
313
  // According to the protocol rules, there must be at least one nullifier in the tx. The first nullifier is used as
257
314
  // the nonce generator for the note hashes.
258
315
  // We pass the non-zero minRevertibleSideEffectCounter to make sure the side effects are split correctly.
259
- const { publicInputs } = await generateSimulatedProvingResult(result, this.contractStore, minRevertibleSideEffectCounter);
316
+ const { publicInputs } = await generateSimulatedProvingResult(result, (addr, sel)=>this.contractStore.getDebugFunctionName(addr, sel), this.stateMachine.node, minRevertibleSideEffectCounter);
260
317
  const globals = makeGlobalVariables();
261
318
  globals.blockNumber = blockNumber;
262
319
  globals.timestamp = this.nextBlockTimestamp;
@@ -324,11 +381,11 @@ export class TXEOracleTopLevelContext {
324
381
  await forkedWorldTrees.close();
325
382
  return executionResult.returnValues ?? [];
326
383
  }
327
- async txePublicCallNewFlow(from, targetContractAddress, calldata, isStaticCall) {
384
+ async publicCallNewFlow(from, targetContractAddress, calldata, isStaticCall) {
328
385
  this.logger.verbose(`Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`);
329
- const blockNumber = await this.txeGetNextBlockNumber();
330
- const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
331
- const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
386
+ const blockNumber = await this.getNextBlockNumber();
387
+ const gasLimits = new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
388
+ const teardownGasLimits = new Gas(FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT);
332
389
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
333
390
  const txContext = new TxContext(this.chainId, this.version, gasSettings);
334
391
  const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
@@ -365,7 +422,7 @@ export class TXEOracleTopLevelContext {
365
422
  revertibleAccumulatedData.publicCallRequests[0] = new PublicCallRequest(from, targetContractAddress, isStaticCall, calldataHash);
366
423
  const inputsForPublic = new PartialPrivateTailPublicInputsForPublic(nonRevertibleAccumulatedData, revertibleAccumulatedData, PublicCallRequest.empty());
367
424
  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);
425
+ const txData = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*expirationTimestamp=*/ 0n, inputsForPublic, undefined);
369
426
  const tx = await Tx.create({
370
427
  data: txData,
371
428
  chonkProof: ChonkProof.empty(),
@@ -418,20 +475,29 @@ export class TXEOracleTopLevelContext {
418
475
  await forkedWorldTrees.close();
419
476
  return returnValues ?? [];
420
477
  }
421
- async txeSimulateUtilityFunction(targetContractAddress, functionSelector, args) {
478
+ async executeUtilityFunction(targetContractAddress, functionSelector, args, jobId) {
422
479
  const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
423
480
  if (!artifact) {
424
481
  throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
425
482
  }
426
483
  // Sync notes before executing utility function to discover notes from previous transactions
427
484
  const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
428
- await syncState(targetContractAddress, this.contractStore, functionSelector, async (call)=>{
429
- await this.executeUtilityCall(call);
430
- }, this.noteStore, this.stateMachine.node, blockHeader, this.jobId);
431
- const call = new FunctionCall(artifact.name, targetContractAddress, functionSelector, FunctionType.UTILITY, false, false, args, []);
432
- return this.executeUtilityCall(call);
485
+ await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, async (call, execScopes)=>{
486
+ await this.executeUtilityCall(call, execScopes, jobId);
487
+ }, blockHeader, jobId, await this.keyStore.getAccounts());
488
+ const call = FunctionCall.from({
489
+ name: artifact.name,
490
+ to: targetContractAddress,
491
+ selector: functionSelector,
492
+ type: FunctionType.UTILITY,
493
+ hideMsgSender: false,
494
+ isStatic: false,
495
+ args,
496
+ returnTypes: []
497
+ });
498
+ return this.executeUtilityCall(call, await this.keyStore.getAccounts(), jobId);
433
499
  }
434
- async executeUtilityCall(call) {
500
+ async executeUtilityCall(call, scopes, jobId) {
435
501
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
436
502
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
437
503
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
@@ -442,7 +508,26 @@ export class TXEOracleTopLevelContext {
442
508
  });
443
509
  try {
444
510
  const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
445
- const oracle = new UtilityExecutionOracle(call.to, [], [], anchorBlockHeader, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.stateMachine.node, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.jobId);
511
+ const oracle = new UtilityExecutionOracle({
512
+ contractAddress: call.to,
513
+ authWitnesses: [],
514
+ capsules: [],
515
+ anchorBlockHeader,
516
+ contractStore: this.contractStore,
517
+ noteStore: this.noteStore,
518
+ keyStore: this.keyStore,
519
+ addressStore: this.addressStore,
520
+ aztecNode: this.stateMachine.node,
521
+ recipientTaggingStore: this.recipientTaggingStore,
522
+ senderAddressBookStore: this.senderAddressBookStore,
523
+ capsuleService: new CapsuleService(this.capsuleStore, scopes),
524
+ privateEventStore: this.privateEventStore,
525
+ messageContextService: this.stateMachine.messageContextService,
526
+ contractSyncService: this.contractSyncService,
527
+ l2TipsStore: this.stateMachine.node,
528
+ jobId,
529
+ scopes
530
+ });
446
531
  const acirExecutionResult = await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
447
532
  err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
448
533
  throw new ExecutionError(err.message, {
@@ -452,10 +537,10 @@ export class TXEOracleTopLevelContext {
452
537
  cause: err
453
538
  });
454
539
  });
455
- this.logger.verbose(`Utility simulation for ${call.to}.${call.selector} completed`);
540
+ this.logger.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
456
541
  return witnessMapToFields(acirExecutionResult.returnWitness);
457
542
  } catch (err) {
458
- throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility simulation'));
543
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility execution'));
459
544
  }
460
545
  }
461
546
  close() {