@aztec/txe 0.0.1-commit.9d2bcf6d → 0.0.1-commit.9ebd450e8

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 +32 -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 +30 -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 +156 -60
  12. package/dest/rpc_translator.d.ts +129 -83
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +464 -164
  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 +54 -6
  34. package/dest/txe_session.d.ts.map +1 -1
  35. package/dest/txe_session.js +151 -27
  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 +33 -32
  48. package/src/oracle/txe_oracle_public_context.ts +12 -12
  49. package/src/oracle/txe_oracle_top_level_context.ts +162 -117
  50. package/src/rpc_translator.ts +539 -196
  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 +216 -75
  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,6 +1,6 @@
1
1
  import type { ContractInstanceWithAddress } from '@aztec/aztec.js/contracts';
2
2
  import { Fr, Point } from '@aztec/aztec.js/fields';
3
- import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX } from '@aztec/constants';
3
+ import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, PRIVATE_LOG_CIPHERTEXT_LEN } from '@aztec/constants';
4
4
  import { BlockNumber } from '@aztec/foundation/branded-types';
5
5
  import {
6
6
  type IMiscOracle,
@@ -10,7 +10,6 @@ import {
10
10
  } from '@aztec/pxe/simulator';
11
11
  import { type ContractArtifact, EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
12
12
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
13
- import { BlockHash } from '@aztec/stdlib/block';
14
13
 
15
14
  import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
16
15
  import type { TXESessionStateHandler } from './txe_session.js';
@@ -20,6 +19,7 @@ import {
20
19
  addressFromSingle,
21
20
  arrayOfArraysToBoundedVecOfArrays,
22
21
  arrayToBoundedVec,
22
+ blockHashFromSingle,
23
23
  bufferToU8Array,
24
24
  fromArray,
25
25
  fromSingle,
@@ -30,7 +30,7 @@ import {
30
30
  toSingle,
31
31
  } from './util/encoding.js';
32
32
 
33
- const MAX_EVENT_LEN = 12; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_RESERVED_FIELDS
33
+ const MAX_EVENT_LEN = 10; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN
34
34
  const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
35
35
 
36
36
  export class UnavailableOracleError extends Error {
@@ -104,13 +104,15 @@ export class RPCTranslator {
104
104
 
105
105
  // TXE session state transition functions - these get handled by the state handler
106
106
 
107
- async txeSetTopLevelTXEContext() {
107
+ // eslint-disable-next-line camelcase
108
+ async aztec_txe_setTopLevelTXEContext() {
108
109
  await this.stateHandler.enterTopLevelState();
109
110
 
110
111
  return toForeignCallResult([]);
111
112
  }
112
113
 
113
- async txeSetPrivateTXEContext(
114
+ // eslint-disable-next-line camelcase
115
+ async aztec_txe_setPrivateTXEContext(
114
116
  foreignContractAddressIsSome: ForeignCallSingle,
115
117
  foreignContractAddressValue: ForeignCallSingle,
116
118
  foreignAnchorBlockNumberIsSome: ForeignCallSingle,
@@ -129,7 +131,8 @@ export class RPCTranslator {
129
131
  return toForeignCallResult(privateContextInputs.toFields().map(toSingle));
130
132
  }
131
133
 
132
- async txeSetPublicTXEContext(
134
+ // eslint-disable-next-line camelcase
135
+ async aztec_txe_setPublicTXEContext(
133
136
  foreignContractAddressIsSome: ForeignCallSingle,
134
137
  foreignContractAddressValue: ForeignCallSingle,
135
138
  ) {
@@ -142,7 +145,8 @@ export class RPCTranslator {
142
145
  return toForeignCallResult([]);
143
146
  }
144
147
 
145
- async txeSetUtilityTXEContext(
148
+ // eslint-disable-next-line camelcase
149
+ async aztec_txe_setUtilityTXEContext(
146
150
  foreignContractAddressIsSome: ForeignCallSingle,
147
151
  foreignContractAddressValue: ForeignCallSingle,
148
152
  ) {
@@ -159,44 +163,54 @@ export class RPCTranslator {
159
163
 
160
164
  // TXE-specific oracles
161
165
 
162
- txeGetDefaultAddress() {
163
- const defaultAddress = this.handlerAsTxe().txeGetDefaultAddress();
166
+ // eslint-disable-next-line camelcase
167
+ aztec_txe_getDefaultAddress() {
168
+ const defaultAddress = this.handlerAsTxe().getDefaultAddress();
164
169
 
165
170
  return toForeignCallResult([toSingle(defaultAddress)]);
166
171
  }
167
172
 
168
- async txeGetNextBlockNumber() {
169
- const nextBlockNumber = await this.handlerAsTxe().txeGetNextBlockNumber();
173
+ // eslint-disable-next-line camelcase
174
+ async aztec_txe_getNextBlockNumber() {
175
+ const nextBlockNumber = await this.handlerAsTxe().getNextBlockNumber();
170
176
 
171
177
  return toForeignCallResult([toSingle(nextBlockNumber)]);
172
178
  }
173
179
 
174
- async txeGetNextBlockTimestamp() {
175
- const nextBlockTimestamp = await this.handlerAsTxe().txeGetNextBlockTimestamp();
180
+ // eslint-disable-next-line camelcase
181
+ async aztec_txe_getNextBlockTimestamp() {
182
+ const nextBlockTimestamp = await this.handlerAsTxe().getNextBlockTimestamp();
176
183
 
177
184
  return toForeignCallResult([toSingle(nextBlockTimestamp)]);
178
185
  }
179
186
 
180
- async txeAdvanceBlocksBy(foreignBlocks: ForeignCallSingle) {
187
+ // eslint-disable-next-line camelcase
188
+ async aztec_txe_advanceBlocksBy(foreignBlocks: ForeignCallSingle) {
181
189
  const blocks = fromSingle(foreignBlocks).toNumber();
182
190
 
183
- await this.handlerAsTxe().txeAdvanceBlocksBy(blocks);
191
+ await this.handlerAsTxe().advanceBlocksBy(blocks);
184
192
 
185
193
  return toForeignCallResult([]);
186
194
  }
187
195
 
188
- txeAdvanceTimestampBy(foreignDuration: ForeignCallSingle) {
196
+ // eslint-disable-next-line camelcase
197
+ aztec_txe_advanceTimestampBy(foreignDuration: ForeignCallSingle) {
189
198
  const duration = fromSingle(foreignDuration).toBigInt();
190
199
 
191
- this.handlerAsTxe().txeAdvanceTimestampBy(duration);
200
+ this.handlerAsTxe().advanceTimestampBy(duration);
192
201
 
193
202
  return toForeignCallResult([]);
194
203
  }
195
204
 
196
- async txeDeploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, foreignSecret: ForeignCallSingle) {
205
+ // eslint-disable-next-line camelcase
206
+ async aztec_txe_deploy(
207
+ artifact: ContractArtifact,
208
+ instance: ContractInstanceWithAddress,
209
+ foreignSecret: ForeignCallSingle,
210
+ ) {
197
211
  const secret = fromSingle(foreignSecret);
198
212
 
199
- await this.handlerAsTxe().txeDeploy(artifact, instance, secret);
213
+ await this.handlerAsTxe().deploy(artifact, instance, secret);
200
214
 
201
215
  return toForeignCallResult([
202
216
  toArray([
@@ -209,10 +223,11 @@ export class RPCTranslator {
209
223
  ]);
210
224
  }
211
225
 
212
- async txeCreateAccount(foreignSecret: ForeignCallSingle) {
226
+ // eslint-disable-next-line camelcase
227
+ async aztec_txe_createAccount(foreignSecret: ForeignCallSingle) {
213
228
  const secret = fromSingle(foreignSecret);
214
229
 
215
- const completeAddress = await this.handlerAsTxe().txeCreateAccount(secret);
230
+ const completeAddress = await this.handlerAsTxe().createAccount(secret);
216
231
 
217
232
  return toForeignCallResult([
218
233
  toSingle(completeAddress.address),
@@ -220,14 +235,15 @@ export class RPCTranslator {
220
235
  ]);
221
236
  }
222
237
 
223
- async txeAddAccount(
238
+ // eslint-disable-next-line camelcase
239
+ async aztec_txe_addAccount(
224
240
  artifact: ContractArtifact,
225
241
  instance: ContractInstanceWithAddress,
226
242
  foreignSecret: ForeignCallSingle,
227
243
  ) {
228
244
  const secret = fromSingle(foreignSecret);
229
245
 
230
- const completeAddress = await this.handlerAsTxe().txeAddAccount(artifact, instance, secret);
246
+ const completeAddress = await this.handlerAsTxe().addAccount(artifact, instance, secret);
231
247
 
232
248
  return toForeignCallResult([
233
249
  toSingle(completeAddress.address),
@@ -235,39 +251,45 @@ export class RPCTranslator {
235
251
  ]);
236
252
  }
237
253
 
238
- async txeAddAuthWitness(foreignAddress: ForeignCallSingle, foreignMessageHash: ForeignCallSingle) {
254
+ // eslint-disable-next-line camelcase
255
+ async aztec_txe_addAuthWitness(foreignAddress: ForeignCallSingle, foreignMessageHash: ForeignCallSingle) {
239
256
  const address = addressFromSingle(foreignAddress);
240
257
  const messageHash = fromSingle(foreignMessageHash);
241
258
 
242
- await this.handlerAsTxe().txeAddAuthWitness(address, messageHash);
259
+ await this.handlerAsTxe().addAuthWitness(address, messageHash);
243
260
 
244
261
  return toForeignCallResult([]);
245
262
  }
246
263
 
247
264
  // PXE oracles
248
265
 
249
- utilityAssertCompatibleOracleVersion(foreignVersion: ForeignCallSingle) {
250
- const version = fromSingle(foreignVersion).toNumber();
266
+ // eslint-disable-next-line camelcase
267
+ aztec_utl_assertCompatibleOracleVersionV2(foreignMajor: ForeignCallSingle, foreignMinor: ForeignCallSingle) {
268
+ const major = fromSingle(foreignMajor).toNumber();
269
+ const minor = fromSingle(foreignMinor).toNumber();
251
270
 
252
- this.handlerAsMisc().utilityAssertCompatibleOracleVersion(version);
271
+ this.handlerAsMisc().assertCompatibleOracleVersion(major, minor);
253
272
 
254
273
  return toForeignCallResult([]);
255
274
  }
256
275
 
257
- utilityGetRandomField() {
258
- const randomField = this.handlerAsMisc().utilityGetRandomField();
276
+ // eslint-disable-next-line camelcase
277
+ aztec_utl_getRandomField() {
278
+ const randomField = this.handlerAsMisc().getRandomField();
259
279
 
260
280
  return toForeignCallResult([toSingle(randomField)]);
261
281
  }
262
282
 
263
- async txeGetLastBlockTimestamp() {
264
- const timestamp = await this.handlerAsTxe().txeGetLastBlockTimestamp();
283
+ // eslint-disable-next-line camelcase
284
+ async aztec_txe_getLastBlockTimestamp() {
285
+ const timestamp = await this.handlerAsTxe().getLastBlockTimestamp();
265
286
 
266
287
  return toForeignCallResult([toSingle(new Fr(timestamp))]);
267
288
  }
268
289
 
269
- async txeGetLastTxEffects() {
270
- const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().txeGetLastTxEffects();
290
+ // eslint-disable-next-line camelcase
291
+ async aztec_txe_getLastTxEffects() {
292
+ const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().getLastTxEffects();
271
293
 
272
294
  return toForeignCallResult([
273
295
  toSingle(txHash.hash),
@@ -276,7 +298,48 @@ export class RPCTranslator {
276
298
  ]);
277
299
  }
278
300
 
279
- async txeGetPrivateEvents(
301
+ // eslint-disable-next-line camelcase
302
+ aztec_txe_getLastCallOffchainEffects() {
303
+ // This oracle returns all offchain effect payloads (messages, authwit requests, etc.) emitted by the last top-level call,
304
+ // MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY is arbitrarily set at 64 because we need a bound. Nothing inherent about it.
305
+ const MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY = 64;
306
+ // Must match MAX_OFFCHAIN_EFFECT_LEN in txe_oracles.nr.
307
+ const MAX_OFFCHAIN_EFFECT_LEN = 2 + PRIVATE_LOG_CIPHERTEXT_LEN;
308
+
309
+ const { effects } = this.stateHandler.getLastCallOffchainEffects();
310
+
311
+ if (effects.length > MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY) {
312
+ throw new Error(`${effects.length} offchain effects exceed max ${MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY}`);
313
+ }
314
+ if (effects.some(e => e.length > MAX_OFFCHAIN_EFFECT_LEN)) {
315
+ throw new Error(`Some offchain effect has length larger than max ${MAX_OFFCHAIN_EFFECT_LEN}`);
316
+ }
317
+
318
+ const rawArrayStorage = effects
319
+ .map(e => e.concat(Array(MAX_OFFCHAIN_EFFECT_LEN - e.length).fill(new Fr(0))))
320
+ .concat(
321
+ Array(MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY - effects.length).fill(Array(MAX_OFFCHAIN_EFFECT_LEN).fill(new Fr(0))),
322
+ )
323
+ .flat();
324
+
325
+ const effectLengths = effects
326
+ .map(e => new Fr(e.length))
327
+ .concat(Array(MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY - effects.length).fill(new Fr(0)));
328
+
329
+ const count = new Fr(effects.length);
330
+
331
+ return toForeignCallResult([toArray(rawArrayStorage), toArray(effectLengths), toSingle(count)]);
332
+ }
333
+
334
+ // eslint-disable-next-line camelcase
335
+ aztec_txe_getLastCallContext() {
336
+ const { txHash, anchorBlockTimestamp } = this.stateHandler.getLastCallContext();
337
+ const isSome = txHash.isZero() ? 0 : 1;
338
+ return toForeignCallResult([toSingle(isSome), toSingle(txHash), toSingle(new Fr(anchorBlockTimestamp))]);
339
+ }
340
+
341
+ // eslint-disable-next-line camelcase
342
+ async aztec_txe_getPrivateEvents(
280
343
  foreignSelector: ForeignCallSingle,
281
344
  foreignContractAddress: ForeignCallSingle,
282
345
  foreignScope: ForeignCallSingle,
@@ -285,7 +348,14 @@ export class RPCTranslator {
285
348
  const contractAddress = addressFromSingle(foreignContractAddress);
286
349
  const scope = addressFromSingle(foreignScope);
287
350
 
288
- const events = await this.handlerAsTxe().txeGetPrivateEvents(selector, contractAddress, scope);
351
+ // TODO(F-335): Avoid doing the following 2 calls here.
352
+ {
353
+ await this.handlerAsTxe().syncContractNonOracleMethod(contractAddress, scope, this.stateHandler.getCurrentJob());
354
+ // We cycle job to commit the stores after the contract sync.
355
+ await this.stateHandler.cycleJob();
356
+ }
357
+
358
+ const events = await this.handlerAsTxe().getPrivateEvents(selector, contractAddress, scope);
289
359
 
290
360
  if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
291
361
  throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
@@ -309,26 +379,29 @@ export class RPCTranslator {
309
379
  return toForeignCallResult([toArray(rawArrayStorage), toArray(eventLengths), toSingle(queryLength)]);
310
380
  }
311
381
 
312
- privateStoreInExecutionCache(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
382
+ // eslint-disable-next-line camelcase
383
+ aztec_prv_setHashPreimage(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
313
384
  const values = fromArray(foreignValues);
314
385
  const hash = fromSingle(foreignHash);
315
386
 
316
- this.handlerAsPrivate().privateStoreInExecutionCache(values, hash);
387
+ this.handlerAsPrivate().setHashPreimage(values, hash);
317
388
 
318
389
  return toForeignCallResult([]);
319
390
  }
320
391
 
321
- async privateLoadFromExecutionCache(foreignHash: ForeignCallSingle) {
392
+ // eslint-disable-next-line camelcase
393
+ async aztec_prv_getHashPreimage(foreignHash: ForeignCallSingle) {
322
394
  const hash = fromSingle(foreignHash);
323
395
 
324
- const returns = await this.handlerAsPrivate().privateLoadFromExecutionCache(hash);
396
+ const returns = await this.handlerAsPrivate().getHashPreimage(hash);
325
397
 
326
398
  return toForeignCallResult([toArray(returns)]);
327
399
  }
328
400
 
329
401
  // When the argument is a slice, noir automatically adds a length field to oracle call.
330
402
  // When the argument is an array, we add the field length manually to the signature.
331
- utilityDebugLog(
403
+ // eslint-disable-next-line camelcase
404
+ async aztec_utl_log(
332
405
  foreignLevel: ForeignCallSingle,
333
406
  foreignMessage: ForeignCallArray,
334
407
  _foreignLength: ForeignCallSingle,
@@ -340,23 +413,24 @@ export class RPCTranslator {
340
413
  .join('');
341
414
  const fields = fromArray(foreignFields);
342
415
 
343
- this.handlerAsMisc().utilityDebugLog(level, message, fields);
416
+ await this.handlerAsMisc().log(level, message, fields);
344
417
 
345
418
  return toForeignCallResult([]);
346
419
  }
347
420
 
348
- async utilityStorageRead(
421
+ // eslint-disable-next-line camelcase
422
+ async aztec_utl_getFromPublicStorage(
349
423
  foreignBlockHash: ForeignCallSingle,
350
424
  foreignContractAddress: ForeignCallSingle,
351
425
  foreignStartStorageSlot: ForeignCallSingle,
352
426
  foreignNumberOfElements: ForeignCallSingle,
353
427
  ) {
354
- const blockHash = new BlockHash(fromSingle(foreignBlockHash));
428
+ const blockHash = blockHashFromSingle(foreignBlockHash);
355
429
  const contractAddress = addressFromSingle(foreignContractAddress);
356
430
  const startStorageSlot = fromSingle(foreignStartStorageSlot);
357
431
  const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
358
432
 
359
- const values = await this.handlerAsUtility().utilityStorageRead(
433
+ const values = await this.handlerAsUtility().getFromPublicStorage(
360
434
  blockHash,
361
435
  contractAddress,
362
436
  startStorageSlot,
@@ -366,11 +440,12 @@ export class RPCTranslator {
366
440
  return toForeignCallResult([toArray(values)]);
367
441
  }
368
442
 
369
- async utilityGetPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
370
- const blockHash = new BlockHash(fromSingle(foreignBlockHash));
443
+ // eslint-disable-next-line camelcase
444
+ async aztec_utl_getPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
445
+ const blockHash = blockHashFromSingle(foreignBlockHash);
371
446
  const leafSlot = fromSingle(foreignLeafSlot);
372
447
 
373
- const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockHash, leafSlot);
448
+ const witness = await this.handlerAsUtility().getPublicDataWitness(blockHash, leafSlot);
374
449
 
375
450
  if (!witness) {
376
451
  throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
@@ -378,7 +453,8 @@ export class RPCTranslator {
378
453
  return toForeignCallResult(witness.toNoirRepresentation());
379
454
  }
380
455
 
381
- async utilityGetNotes(
456
+ // eslint-disable-next-line camelcase
457
+ async aztec_utl_getNotes(
382
458
  foreignOwnerIsSome: ForeignCallSingle,
383
459
  foreignOwnerValue: ForeignCallSingle,
384
460
  foreignStorageSlot: ForeignCallSingle,
@@ -419,7 +495,7 @@ export class RPCTranslator {
419
495
  const maxNotes = fromSingle(foreignMaxNotes).toNumber();
420
496
  const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
421
497
 
422
- const noteDatas = await this.handlerAsUtility().utilityGetNotes(
498
+ const noteDatas = await this.handlerAsUtility().getNotes(
423
499
  owner,
424
500
  storageSlot,
425
501
  numSelects,
@@ -460,7 +536,8 @@ export class RPCTranslator {
460
536
  );
461
537
  }
462
538
 
463
- privateNotifyCreatedNote(
539
+ // eslint-disable-next-line camelcase
540
+ aztec_prv_notifyCreatedNote(
464
541
  foreignOwner: ForeignCallSingle,
465
542
  foreignStorageSlot: ForeignCallSingle,
466
543
  foreignRandomness: ForeignCallSingle,
@@ -477,20 +554,13 @@ export class RPCTranslator {
477
554
  const noteHash = fromSingle(foreignNoteHash);
478
555
  const counter = fromSingle(foreignCounter).toNumber();
479
556
 
480
- this.handlerAsPrivate().privateNotifyCreatedNote(
481
- owner,
482
- storageSlot,
483
- randomness,
484
- noteTypeId,
485
- note,
486
- noteHash,
487
- counter,
488
- );
557
+ this.handlerAsPrivate().notifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
489
558
 
490
559
  return toForeignCallResult([]);
491
560
  }
492
561
 
493
- async privateNotifyNullifiedNote(
562
+ // eslint-disable-next-line camelcase
563
+ async aztec_prv_notifyNullifiedNote(
494
564
  foreignInnerNullifier: ForeignCallSingle,
495
565
  foreignNoteHash: ForeignCallSingle,
496
566
  foreignCounter: ForeignCallSingle,
@@ -499,40 +569,47 @@ export class RPCTranslator {
499
569
  const noteHash = fromSingle(foreignNoteHash);
500
570
  const counter = fromSingle(foreignCounter).toNumber();
501
571
 
502
- await this.handlerAsPrivate().privateNotifyNullifiedNote(innerNullifier, noteHash, counter);
572
+ await this.handlerAsPrivate().notifyNullifiedNote(innerNullifier, noteHash, counter);
503
573
 
504
574
  return toForeignCallResult([]);
505
575
  }
506
576
 
507
- async privateNotifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
577
+ // eslint-disable-next-line camelcase
578
+ async aztec_prv_notifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
508
579
  const innerNullifier = fromSingle(foreignInnerNullifier);
509
580
 
510
- await this.handlerAsPrivate().privateNotifyCreatedNullifier(innerNullifier);
581
+ await this.handlerAsPrivate().notifyCreatedNullifier(innerNullifier);
511
582
 
512
583
  return toForeignCallResult([]);
513
584
  }
514
585
 
515
- async privateIsNullifierPending(foreignInnerNullifier: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
586
+ // eslint-disable-next-line camelcase
587
+ async aztec_prv_isNullifierPending(
588
+ foreignInnerNullifier: ForeignCallSingle,
589
+ foreignContractAddress: ForeignCallSingle,
590
+ ) {
516
591
  const innerNullifier = fromSingle(foreignInnerNullifier);
517
592
  const contractAddress = addressFromSingle(foreignContractAddress);
518
593
 
519
- const isPending = await this.handlerAsPrivate().privateIsNullifierPending(innerNullifier, contractAddress);
594
+ const isPending = await this.handlerAsPrivate().isNullifierPending(innerNullifier, contractAddress);
520
595
 
521
596
  return toForeignCallResult([toSingle(new Fr(isPending))]);
522
597
  }
523
598
 
524
- async utilityCheckNullifierExists(foreignInnerNullifier: ForeignCallSingle) {
599
+ // eslint-disable-next-line camelcase
600
+ async aztec_utl_doesNullifierExist(foreignInnerNullifier: ForeignCallSingle) {
525
601
  const innerNullifier = fromSingle(foreignInnerNullifier);
526
602
 
527
- const exists = await this.handlerAsUtility().utilityCheckNullifierExists(innerNullifier);
603
+ const exists = await this.handlerAsUtility().doesNullifierExist(innerNullifier);
528
604
 
529
605
  return toForeignCallResult([toSingle(new Fr(exists))]);
530
606
  }
531
607
 
532
- async utilityGetContractInstance(foreignAddress: ForeignCallSingle) {
608
+ // eslint-disable-next-line camelcase
609
+ async aztec_utl_getContractInstance(foreignAddress: ForeignCallSingle) {
533
610
  const address = addressFromSingle(foreignAddress);
534
611
 
535
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
612
+ const instance = await this.handlerAsUtility().getContractInstance(address);
536
613
 
537
614
  return toForeignCallResult(
538
615
  [
@@ -545,10 +622,11 @@ export class RPCTranslator {
545
622
  );
546
623
  }
547
624
 
548
- async utilityTryGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
625
+ // eslint-disable-next-line camelcase
626
+ async aztec_utl_getPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
549
627
  const address = addressFromSingle(foreignAddress);
550
628
 
551
- const result = await this.handlerAsUtility().utilityTryGetPublicKeysAndPartialAddress(address);
629
+ const result = await this.handlerAsUtility().getPublicKeysAndPartialAddress(address);
552
630
 
553
631
  // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
554
632
  // with two fields: `some` (a boolean) and `value` (a field array in this case).
@@ -564,15 +642,17 @@ export class RPCTranslator {
564
642
  }
565
643
  }
566
644
 
567
- async utilityGetKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
645
+ // eslint-disable-next-line camelcase
646
+ async aztec_utl_getKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
568
647
  const pkMHash = fromSingle(foreignPkMHash);
569
648
 
570
- const keyValidationRequest = await this.handlerAsUtility().utilityGetKeyValidationRequest(pkMHash);
649
+ const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
571
650
 
572
651
  return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
573
652
  }
574
653
 
575
- privateCallPrivateFunction(
654
+ // eslint-disable-next-line camelcase
655
+ aztec_prv_callPrivateFunction(
576
656
  _foreignTargetContractAddress: ForeignCallSingle,
577
657
  _foreignFunctionSelector: ForeignCallSingle,
578
658
  _foreignArgsHash: ForeignCallSingle,
@@ -584,11 +664,15 @@ export class RPCTranslator {
584
664
  );
585
665
  }
586
666
 
587
- async utilityGetNullifierMembershipWitness(foreignBlockHash: ForeignCallSingle, foreignNullifier: ForeignCallSingle) {
588
- const blockHash = new BlockHash(fromSingle(foreignBlockHash));
667
+ // eslint-disable-next-line camelcase
668
+ async aztec_utl_getNullifierMembershipWitness(
669
+ foreignBlockHash: ForeignCallSingle,
670
+ foreignNullifier: ForeignCallSingle,
671
+ ) {
672
+ const blockHash = blockHashFromSingle(foreignBlockHash);
589
673
  const nullifier = fromSingle(foreignNullifier);
590
674
 
591
- const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
675
+ const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
592
676
 
593
677
  if (!witness) {
594
678
  throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
@@ -596,10 +680,11 @@ export class RPCTranslator {
596
680
  return toForeignCallResult(witness.toNoirRepresentation());
597
681
  }
598
682
 
599
- async utilityGetAuthWitness(foreignMessageHash: ForeignCallSingle) {
683
+ // eslint-disable-next-line camelcase
684
+ async aztec_utl_getAuthWitness(foreignMessageHash: ForeignCallSingle) {
600
685
  const messageHash = fromSingle(foreignMessageHash);
601
686
 
602
- const authWitness = await this.handlerAsUtility().utilityGetAuthWitness(messageHash);
687
+ const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
603
688
 
604
689
  if (!authWitness) {
605
690
  throw new Error(`Auth witness not found for message hash ${messageHash}.`);
@@ -607,44 +692,35 @@ export class RPCTranslator {
607
692
  return toForeignCallResult([toArray(authWitness)]);
608
693
  }
609
694
 
610
- public privateNotifyEnqueuedPublicFunctionCall(
611
- _foreignTargetContractAddress: ForeignCallSingle,
612
- _foreignCalldataHash: ForeignCallSingle,
613
- _foreignSideEffectCounter: ForeignCallSingle,
614
- _foreignIsStaticCall: ForeignCallSingle,
615
- ) {
616
- throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
617
- }
618
-
619
- public privateNotifySetPublicTeardownFunctionCall(
620
- _foreignTargetContractAddress: ForeignCallSingle,
621
- _foreignCalldataHash: ForeignCallSingle,
622
- _foreignSideEffectCounter: ForeignCallSingle,
623
- _foreignIsStaticCall: ForeignCallSingle,
624
- ) {
695
+ // eslint-disable-next-line camelcase
696
+ public aztec_prv_assertValidPublicCalldata(_foreignCalldataHash: ForeignCallSingle) {
625
697
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
626
698
  }
627
699
 
628
- public privateNotifySetMinRevertibleSideEffectCounter(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
700
+ // eslint-disable-next-line camelcase
701
+ public aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
629
702
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
630
703
  }
631
704
 
632
- public async privateIsSideEffectCounterRevertible(foreignSideEffectCounter: ForeignCallSingle) {
705
+ // eslint-disable-next-line camelcase
706
+ public async aztec_prv_isExecutionInRevertiblePhase(foreignSideEffectCounter: ForeignCallSingle) {
633
707
  const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
634
- const isRevertible = await this.handlerAsPrivate().privateIsSideEffectCounterRevertible(sideEffectCounter);
708
+ const isRevertible = await this.handlerAsPrivate().isExecutionInRevertiblePhase(sideEffectCounter);
635
709
  return toForeignCallResult([toSingle(new Fr(isRevertible))]);
636
710
  }
637
711
 
638
- utilityGetUtilityContext() {
639
- const context = this.handlerAsUtility().utilityGetUtilityContext();
712
+ // eslint-disable-next-line camelcase
713
+ aztec_utl_getUtilityContext() {
714
+ const context = this.handlerAsUtility().getUtilityContext();
640
715
 
641
716
  return toForeignCallResult(context.toNoirRepresentation());
642
717
  }
643
718
 
644
- async utilityGetBlockHeader(foreignBlockNumber: ForeignCallSingle) {
719
+ // eslint-disable-next-line camelcase
720
+ async aztec_utl_getBlockHeader(foreignBlockNumber: ForeignCallSingle) {
645
721
  const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
646
722
 
647
- const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
723
+ const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
648
724
 
649
725
  if (!header) {
650
726
  throw new Error(`Block header not found for block ${blockNumber}.`);
@@ -652,14 +728,15 @@ export class RPCTranslator {
652
728
  return toForeignCallResult(header.toFields().map(toSingle));
653
729
  }
654
730
 
655
- async utilityGetNoteHashMembershipWitness(
731
+ // eslint-disable-next-line camelcase
732
+ async aztec_utl_getNoteHashMembershipWitness(
656
733
  foreignAnchorBlockHash: ForeignCallSingle,
657
734
  foreignNoteHash: ForeignCallSingle,
658
735
  ) {
659
- const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
736
+ const blockHash = blockHashFromSingle(foreignAnchorBlockHash);
660
737
  const noteHash = fromSingle(foreignNoteHash);
661
738
 
662
- const witness = await this.handlerAsUtility().utilityGetNoteHashMembershipWitness(blockHash, noteHash);
739
+ const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
663
740
 
664
741
  if (!witness) {
665
742
  throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
@@ -667,14 +744,15 @@ export class RPCTranslator {
667
744
  return toForeignCallResult(witness.toNoirRepresentation());
668
745
  }
669
746
 
670
- async utilityGetBlockHashMembershipWitness(
747
+ // eslint-disable-next-line camelcase
748
+ async aztec_utl_getBlockHashMembershipWitness(
671
749
  foreignAnchorBlockHash: ForeignCallSingle,
672
750
  foreignBlockHash: ForeignCallSingle,
673
751
  ) {
674
- const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
675
- const blockHash = new BlockHash(fromSingle(foreignBlockHash));
752
+ const anchorBlockHash = blockHashFromSingle(foreignAnchorBlockHash);
753
+ const blockHash = blockHashFromSingle(foreignBlockHash);
676
754
 
677
- const witness = await this.handlerAsUtility().utilityGetBlockHashMembershipWitness(anchorBlockHash, blockHash);
755
+ const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
678
756
 
679
757
  if (!witness) {
680
758
  throw new Error(
@@ -684,14 +762,15 @@ export class RPCTranslator {
684
762
  return toForeignCallResult(witness.toNoirRepresentation());
685
763
  }
686
764
 
687
- async utilityGetLowNullifierMembershipWitness(
765
+ // eslint-disable-next-line camelcase
766
+ async aztec_utl_getLowNullifierMembershipWitness(
688
767
  foreignBlockHash: ForeignCallSingle,
689
768
  foreignNullifier: ForeignCallSingle,
690
769
  ) {
691
- const blockHash = new BlockHash(fromSingle(foreignBlockHash));
770
+ const blockHash = blockHashFromSingle(foreignBlockHash);
692
771
  const nullifier = fromSingle(foreignNullifier);
693
772
 
694
- const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
773
+ const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
695
774
 
696
775
  if (!witness) {
697
776
  throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
@@ -699,74 +778,167 @@ export class RPCTranslator {
699
778
  return toForeignCallResult(witness.toNoirRepresentation());
700
779
  }
701
780
 
702
- async utilityFetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
781
+ // eslint-disable-next-line camelcase
782
+ async aztec_utl_getPendingTaggedLogs(
783
+ foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle,
784
+ foreignScope: ForeignCallSingle,
785
+ ) {
703
786
  const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
787
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
704
788
 
705
- await this.handlerAsUtility().utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
789
+ await this.handlerAsUtility().getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot, scope);
706
790
 
707
791
  return toForeignCallResult([]);
708
792
  }
709
793
 
710
- public async utilityValidateAndStoreEnqueuedNotesAndEvents(
794
+ // eslint-disable-next-line camelcase
795
+ async aztec_utl_getPendingTaggedLogs_v2(foreignScope: ForeignCallSingle) {
796
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
797
+ const slot = await this.handlerAsUtility().getPendingTaggedLogsV2(scope);
798
+ return toForeignCallResult([toSingle(slot)]);
799
+ }
800
+
801
+ // eslint-disable-next-line camelcase
802
+ public async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(
711
803
  foreignContractAddress: ForeignCallSingle,
712
804
  foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
713
805
  foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
806
+ foreignMaxNotePackedLen: ForeignCallSingle,
807
+ foreignMaxEventSerializedLen: ForeignCallSingle,
808
+ foreignScope: ForeignCallSingle,
714
809
  ) {
715
810
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
716
811
  const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
717
812
  const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
813
+ const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
814
+ const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
815
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
718
816
 
719
- await this.handlerAsUtility().utilityValidateAndStoreEnqueuedNotesAndEvents(
817
+ await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
720
818
  contractAddress,
721
819
  noteValidationRequestsArrayBaseSlot,
722
820
  eventValidationRequestsArrayBaseSlot,
821
+ maxNotePackedLen,
822
+ maxEventSerializedLen,
823
+ scope,
723
824
  );
724
825
 
725
826
  return toForeignCallResult([]);
726
827
  }
727
828
 
728
- public async utilityBulkRetrieveLogs(
829
+ // eslint-disable-next-line camelcase
830
+ public async aztec_utl_validateAndStoreEnqueuedNotesAndEvents_v2(
831
+ foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
832
+ foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
833
+ foreignMaxNotePackedLen: ForeignCallSingle,
834
+ foreignMaxEventSerializedLen: ForeignCallSingle,
835
+ foreignScope: ForeignCallSingle,
836
+ ) {
837
+ const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
838
+ const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
839
+ const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
840
+ const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
841
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
842
+
843
+ await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEventsV2(
844
+ noteValidationRequestsArrayBaseSlot,
845
+ eventValidationRequestsArrayBaseSlot,
846
+ maxNotePackedLen,
847
+ maxEventSerializedLen,
848
+ scope,
849
+ );
850
+
851
+ return toForeignCallResult([]);
852
+ }
853
+
854
+ // eslint-disable-next-line camelcase
855
+ public async aztec_utl_getLogsByTag(
729
856
  foreignContractAddress: ForeignCallSingle,
730
857
  foreignLogRetrievalRequestsArrayBaseSlot: ForeignCallSingle,
731
858
  foreignLogRetrievalResponsesArrayBaseSlot: ForeignCallSingle,
859
+ foreignScope: ForeignCallSingle,
732
860
  ) {
733
861
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
734
862
  const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
735
863
  const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
864
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
736
865
 
737
- await this.handlerAsUtility().utilityBulkRetrieveLogs(
866
+ await this.handlerAsUtility().getLogsByTag(
738
867
  contractAddress,
739
868
  logRetrievalRequestsArrayBaseSlot,
740
869
  logRetrievalResponsesArrayBaseSlot,
870
+ scope,
741
871
  );
742
872
 
743
873
  return toForeignCallResult([]);
744
874
  }
745
875
 
746
- async utilityStoreCapsule(
876
+ // eslint-disable-next-line camelcase
877
+ public async aztec_utl_getMessageContextsByTxHash(
878
+ foreignContractAddress: ForeignCallSingle,
879
+ foreignMessageContextRequestsArrayBaseSlot: ForeignCallSingle,
880
+ foreignMessageContextResponsesArrayBaseSlot: ForeignCallSingle,
881
+ foreignScope: ForeignCallSingle,
882
+ ) {
883
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
884
+ const messageContextRequestsArrayBaseSlot = fromSingle(foreignMessageContextRequestsArrayBaseSlot);
885
+ const messageContextResponsesArrayBaseSlot = fromSingle(foreignMessageContextResponsesArrayBaseSlot);
886
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
887
+
888
+ await this.handlerAsUtility().getMessageContextsByTxHash(
889
+ contractAddress,
890
+ messageContextRequestsArrayBaseSlot,
891
+ messageContextResponsesArrayBaseSlot,
892
+ scope,
893
+ );
894
+
895
+ return toForeignCallResult([]);
896
+ }
897
+
898
+ // eslint-disable-next-line camelcase
899
+ async aztec_utl_getLogsByTag_v2(foreignRequestArrayBaseSlot: ForeignCallSingle) {
900
+ const requestArrayBaseSlot = fromSingle(foreignRequestArrayBaseSlot);
901
+ const responseSlot = await this.handlerAsUtility().getLogsByTagV2(requestArrayBaseSlot);
902
+ return toForeignCallResult([toSingle(responseSlot)]);
903
+ }
904
+
905
+ // eslint-disable-next-line camelcase
906
+ async aztec_utl_getMessageContextsByTxHash_v2(foreignRequestArrayBaseSlot: ForeignCallSingle) {
907
+ const requestArrayBaseSlot = fromSingle(foreignRequestArrayBaseSlot);
908
+ const responseSlot = await this.handlerAsUtility().getMessageContextsByTxHashV2(requestArrayBaseSlot);
909
+ return toForeignCallResult([toSingle(responseSlot)]);
910
+ }
911
+
912
+ // eslint-disable-next-line camelcase
913
+ aztec_utl_setCapsule(
747
914
  foreignContractAddress: ForeignCallSingle,
748
915
  foreignSlot: ForeignCallSingle,
749
916
  foreignCapsule: ForeignCallArray,
917
+ foreignScope: ForeignCallSingle,
750
918
  ) {
751
919
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
752
920
  const slot = fromSingle(foreignSlot);
753
921
  const capsule = fromArray(foreignCapsule);
922
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
754
923
 
755
- await this.handlerAsUtility().utilityStoreCapsule(contractAddress, slot, capsule);
924
+ this.handlerAsUtility().setCapsule(contractAddress, slot, capsule, scope);
756
925
 
757
926
  return toForeignCallResult([]);
758
927
  }
759
928
 
760
- async utilityLoadCapsule(
929
+ // eslint-disable-next-line camelcase
930
+ async aztec_utl_getCapsule(
761
931
  foreignContractAddress: ForeignCallSingle,
762
932
  foreignSlot: ForeignCallSingle,
763
933
  foreignTSize: ForeignCallSingle,
934
+ foreignScope: ForeignCallSingle,
764
935
  ) {
765
936
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
766
937
  const slot = fromSingle(foreignSlot);
767
938
  const tSize = fromSingle(foreignTSize).toNumber();
939
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
768
940
 
769
- const values = await this.handlerAsUtility().utilityLoadCapsule(contractAddress, slot);
941
+ const values = await this.handlerAsUtility().getCapsule(contractAddress, slot, scope);
770
942
 
771
943
  // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
772
944
  // with two fields: `some` (a boolean) and `value` (a field array in this case).
@@ -779,36 +951,104 @@ export class RPCTranslator {
779
951
  }
780
952
  }
781
953
 
782
- async utilityDeleteCapsule(foreignContractAddress: ForeignCallSingle, foreignSlot: ForeignCallSingle) {
954
+ // eslint-disable-next-line camelcase
955
+ aztec_utl_deleteCapsule(
956
+ foreignContractAddress: ForeignCallSingle,
957
+ foreignSlot: ForeignCallSingle,
958
+ foreignScope: ForeignCallSingle,
959
+ ) {
783
960
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
784
961
  const slot = fromSingle(foreignSlot);
962
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
785
963
 
786
- await this.handlerAsUtility().utilityDeleteCapsule(contractAddress, slot);
964
+ this.handlerAsUtility().deleteCapsule(contractAddress, slot, scope);
787
965
 
788
966
  return toForeignCallResult([]);
789
967
  }
790
968
 
791
- async utilityCopyCapsule(
969
+ // eslint-disable-next-line camelcase
970
+ async aztec_utl_copyCapsule(
792
971
  foreignContractAddress: ForeignCallSingle,
793
972
  foreignSrcSlot: ForeignCallSingle,
794
973
  foreignDstSlot: ForeignCallSingle,
795
974
  foreignNumEntries: ForeignCallSingle,
975
+ foreignScope: ForeignCallSingle,
796
976
  ) {
797
977
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
798
978
  const srcSlot = fromSingle(foreignSrcSlot);
799
979
  const dstSlot = fromSingle(foreignDstSlot);
800
980
  const numEntries = fromSingle(foreignNumEntries).toNumber();
981
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
801
982
 
802
- await this.handlerAsUtility().utilityCopyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
983
+ await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, scope);
803
984
 
804
985
  return toForeignCallResult([]);
805
986
  }
806
987
 
988
+ // eslint-disable-next-line camelcase
989
+ aztec_utl_pushEphemeral(foreignSlot: ForeignCallSingle, foreignElements: ForeignCallArray) {
990
+ const slot = fromSingle(foreignSlot);
991
+ const elements = fromArray(foreignElements);
992
+ const newLen = this.handlerAsUtility().pushEphemeral(slot, elements);
993
+ return toForeignCallResult([toSingle(new Fr(newLen))]);
994
+ }
995
+
996
+ // eslint-disable-next-line camelcase
997
+ aztec_utl_popEphemeral(foreignSlot: ForeignCallSingle) {
998
+ const slot = fromSingle(foreignSlot);
999
+ const element = this.handlerAsUtility().popEphemeral(slot);
1000
+ return toForeignCallResult([toArray(element)]);
1001
+ }
1002
+
1003
+ // eslint-disable-next-line camelcase
1004
+ aztec_utl_getEphemeral(foreignSlot: ForeignCallSingle, foreignIndex: ForeignCallSingle) {
1005
+ const slot = fromSingle(foreignSlot);
1006
+ const index = fromSingle(foreignIndex).toNumber();
1007
+ const element = this.handlerAsUtility().getEphemeral(slot, index);
1008
+ return toForeignCallResult([toArray(element)]);
1009
+ }
1010
+
1011
+ // eslint-disable-next-line camelcase
1012
+ aztec_utl_setEphemeral(
1013
+ foreignSlot: ForeignCallSingle,
1014
+ foreignIndex: ForeignCallSingle,
1015
+ foreignElements: ForeignCallArray,
1016
+ ) {
1017
+ const slot = fromSingle(foreignSlot);
1018
+ const index = fromSingle(foreignIndex).toNumber();
1019
+ const elements = fromArray(foreignElements);
1020
+ this.handlerAsUtility().setEphemeral(slot, index, elements);
1021
+ return toForeignCallResult([]);
1022
+ }
1023
+
1024
+ // eslint-disable-next-line camelcase
1025
+ aztec_utl_getEphemeralLen(foreignSlot: ForeignCallSingle) {
1026
+ const slot = fromSingle(foreignSlot);
1027
+ const len = this.handlerAsUtility().getEphemeralLen(slot);
1028
+ return toForeignCallResult([toSingle(new Fr(len))]);
1029
+ }
1030
+
1031
+ // eslint-disable-next-line camelcase
1032
+ aztec_utl_removeEphemeral(foreignSlot: ForeignCallSingle, foreignIndex: ForeignCallSingle) {
1033
+ const slot = fromSingle(foreignSlot);
1034
+ const index = fromSingle(foreignIndex).toNumber();
1035
+ this.handlerAsUtility().removeEphemeral(slot, index);
1036
+ return toForeignCallResult([]);
1037
+ }
1038
+
1039
+ // eslint-disable-next-line camelcase
1040
+ aztec_utl_clearEphemeral(foreignSlot: ForeignCallSingle) {
1041
+ const slot = fromSingle(foreignSlot);
1042
+ this.handlerAsUtility().clearEphemeral(slot);
1043
+ return toForeignCallResult([]);
1044
+ }
1045
+
807
1046
  // TODO: I forgot to add a corresponding function here, when I introduced an oracle method to txe_oracle.ts.
808
1047
  // The compiler didn't throw an error, so it took me a while to learn of the existence of this file, and that I need
809
1048
  // to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
810
1049
  // existence of a txe_oracle method?
811
- async utilityAes128Decrypt(
1050
+ // eslint-disable-next-line camelcase
1051
+ async aztec_utl_decryptAes128(
812
1052
  foreignCiphertextBVecStorage: ForeignCallArray,
813
1053
  foreignCiphertextLength: ForeignCallSingle,
814
1054
  foreignIv: ForeignCallArray,
@@ -818,18 +1058,27 @@ export class RPCTranslator {
818
1058
  const iv = fromUintArray(foreignIv, 8);
819
1059
  const symKey = fromUintArray(foreignSymKey, 8);
820
1060
 
821
- const plaintextBuffer = await this.handlerAsUtility().utilityAes128Decrypt(ciphertext, iv, symKey);
822
-
823
- return toForeignCallResult(
824
- arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length),
825
- );
1061
+ // Noir Option<BoundedVec> is encoded as [is_some: Field, storage: Field[], length: Field].
1062
+ try {
1063
+ const plaintextBuffer = await this.handlerAsUtility().decryptAes128(ciphertext, iv, symKey);
1064
+ const [storage, length] = arrayToBoundedVec(
1065
+ bufferToU8Array(plaintextBuffer),
1066
+ foreignCiphertextBVecStorage.length,
1067
+ );
1068
+ return toForeignCallResult([toSingle(new Fr(1)), storage, length]);
1069
+ } catch {
1070
+ const zeroStorage = toArray(Array(foreignCiphertextBVecStorage.length).fill(new Fr(0)));
1071
+ return toForeignCallResult([toSingle(new Fr(0)), zeroStorage, toSingle(new Fr(0))]);
1072
+ }
826
1073
  }
827
1074
 
828
- async utilityGetSharedSecret(
1075
+ // eslint-disable-next-line camelcase
1076
+ async aztec_utl_getSharedSecret(
829
1077
  foreignAddress: ForeignCallSingle,
830
1078
  foreignEphPKField0: ForeignCallSingle,
831
1079
  foreignEphPKField1: ForeignCallSingle,
832
1080
  foreignEphPKField2: ForeignCallSingle,
1081
+ foreignContractAddress: ForeignCallSingle,
833
1082
  ) {
834
1083
  const address = AztecAddress.fromField(fromSingle(foreignAddress));
835
1084
  const ephPK = Point.fromFields([
@@ -837,45 +1086,73 @@ export class RPCTranslator {
837
1086
  fromSingle(foreignEphPKField1),
838
1087
  fromSingle(foreignEphPKField2),
839
1088
  ]);
1089
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
840
1090
 
841
- const secret = await this.handlerAsUtility().utilityGetSharedSecret(address, ephPK);
1091
+ const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK, contractAddress);
842
1092
 
843
- return toForeignCallResult(secret.toFields().map(toSingle));
1093
+ return toForeignCallResult([toSingle(secret)]);
844
1094
  }
845
1095
 
846
- emitOffchainEffect(_foreignData: ForeignCallArray) {
847
- throw new Error('Offchain effects are not yet supported in the TestEnvironment');
1096
+ // eslint-disable-next-line camelcase
1097
+ aztec_utl_setContractSyncCacheInvalid(
1098
+ foreignContractAddress: ForeignCallSingle,
1099
+ foreignScopes: ForeignCallArray,
1100
+ foreignScopeCount: ForeignCallSingle,
1101
+ ) {
1102
+ const contractAddress = addressFromSingle(foreignContractAddress);
1103
+ const count = fromSingle(foreignScopeCount).toNumber();
1104
+ const scopes = fromArray(foreignScopes)
1105
+ .slice(0, count)
1106
+ .map(f => new AztecAddress(f));
1107
+
1108
+ this.handlerAsUtility().setContractSyncCacheInvalid(contractAddress, scopes);
1109
+
1110
+ return Promise.resolve(toForeignCallResult([]));
1111
+ }
1112
+
1113
+ // eslint-disable-next-line camelcase
1114
+ aztec_utl_emitOffchainEffect(foreignData: ForeignCallArray) {
1115
+ // Record the raw payload against the currently-executing top-level call. The Noir side
1116
+ // (via `env.offchain_messages()`) is responsible for decoding the protocol-reserved prefix
1117
+ // (`OFFCHAIN_MESSAGE_IDENTIFIER`, recipient) and turning each payload into an `OffchainMessage` struct suitable
1118
+ // for `offchain_receive`.
1119
+ this.stateHandler.recordOffchainEffect(fromArray(foreignData));
1120
+ return Promise.resolve(toForeignCallResult([]));
848
1121
  }
849
1122
 
850
1123
  // AVM opcodes
851
1124
 
852
- avmOpcodeEmitUnencryptedLog(_foreignMessage: ForeignCallArray) {
1125
+ // eslint-disable-next-line camelcase
1126
+ aztec_avm_emitPublicLog(_foreignMessage: ForeignCallArray) {
853
1127
  // TODO(#8811): Implement
854
1128
  return toForeignCallResult([]);
855
1129
  }
856
1130
 
857
- async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
1131
+ // eslint-disable-next-line camelcase
1132
+ async aztec_avm_storageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
858
1133
  const slot = fromSingle(foreignSlot);
859
1134
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
860
1135
 
861
- const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot, contractAddress)).value;
1136
+ const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
862
1137
 
863
1138
  return toForeignCallResult([toSingle(new Fr(value))]);
864
1139
  }
865
1140
 
866
- async avmOpcodeStorageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
1141
+ // eslint-disable-next-line camelcase
1142
+ async aztec_avm_storageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
867
1143
  const slot = fromSingle(foreignSlot);
868
1144
  const value = fromSingle(foreignValue);
869
1145
 
870
- await this.handlerAsAvm().avmOpcodeStorageWrite(slot, value);
1146
+ await this.handlerAsAvm().storageWrite(slot, value);
871
1147
 
872
1148
  return toForeignCallResult([]);
873
1149
  }
874
1150
 
875
- async avmOpcodeGetContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
1151
+ // eslint-disable-next-line camelcase
1152
+ async aztec_avm_getContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
876
1153
  const address = addressFromSingle(foreignAddress);
877
1154
 
878
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
1155
+ const instance = await this.handlerAsUtility().getContractInstance(address);
879
1156
 
880
1157
  return toForeignCallResult([
881
1158
  toSingle(instance.deployer),
@@ -884,10 +1161,11 @@ export class RPCTranslator {
884
1161
  ]);
885
1162
  }
886
1163
 
887
- async avmOpcodeGetContractInstanceClassId(foreignAddress: ForeignCallSingle) {
1164
+ // eslint-disable-next-line camelcase
1165
+ async aztec_avm_getContractInstanceClassId(foreignAddress: ForeignCallSingle) {
888
1166
  const address = addressFromSingle(foreignAddress);
889
1167
 
890
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
1168
+ const instance = await this.handlerAsUtility().getContractInstance(address);
891
1169
 
892
1170
  return toForeignCallResult([
893
1171
  toSingle(instance.currentContractClassId),
@@ -896,10 +1174,11 @@ export class RPCTranslator {
896
1174
  ]);
897
1175
  }
898
1176
 
899
- async avmOpcodeGetContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
1177
+ // eslint-disable-next-line camelcase
1178
+ async aztec_avm_getContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
900
1179
  const address = addressFromSingle(foreignAddress);
901
1180
 
902
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
1181
+ const instance = await this.handlerAsUtility().getContractInstance(address);
903
1182
 
904
1183
  return toForeignCallResult([
905
1184
  toSingle(instance.initializationHash),
@@ -908,85 +1187,98 @@ export class RPCTranslator {
908
1187
  ]);
909
1188
  }
910
1189
 
911
- async avmOpcodeSender() {
912
- const sender = await this.handlerAsAvm().avmOpcodeSender();
1190
+ // eslint-disable-next-line camelcase
1191
+ async aztec_avm_sender() {
1192
+ const sender = await this.handlerAsAvm().sender();
913
1193
 
914
1194
  return toForeignCallResult([toSingle(sender)]);
915
1195
  }
916
1196
 
917
- async avmOpcodeEmitNullifier(foreignNullifier: ForeignCallSingle) {
1197
+ // eslint-disable-next-line camelcase
1198
+ async aztec_avm_emitNullifier(foreignNullifier: ForeignCallSingle) {
918
1199
  const nullifier = fromSingle(foreignNullifier);
919
1200
 
920
- await this.handlerAsAvm().avmOpcodeEmitNullifier(nullifier);
1201
+ await this.handlerAsAvm().emitNullifier(nullifier);
921
1202
 
922
1203
  return toForeignCallResult([]);
923
1204
  }
924
1205
 
925
- async avmOpcodeEmitNoteHash(foreignNoteHash: ForeignCallSingle) {
1206
+ // eslint-disable-next-line camelcase
1207
+ async aztec_avm_emitNoteHash(foreignNoteHash: ForeignCallSingle) {
926
1208
  const noteHash = fromSingle(foreignNoteHash);
927
1209
 
928
- await this.handlerAsAvm().avmOpcodeEmitNoteHash(noteHash);
1210
+ await this.handlerAsAvm().emitNoteHash(noteHash);
929
1211
 
930
1212
  return toForeignCallResult([]);
931
1213
  }
932
1214
 
933
- async avmOpcodeNullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
1215
+ // eslint-disable-next-line camelcase
1216
+ async aztec_avm_nullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
934
1217
  const siloedNullifier = fromSingle(foreignSiloedNullifier);
935
1218
 
936
- const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(siloedNullifier);
1219
+ const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
937
1220
 
938
1221
  return toForeignCallResult([toSingle(new Fr(exists))]);
939
1222
  }
940
1223
 
941
- async avmOpcodeAddress() {
942
- const contractAddress = await this.handlerAsAvm().avmOpcodeAddress();
1224
+ // eslint-disable-next-line camelcase
1225
+ async aztec_avm_address() {
1226
+ const contractAddress = await this.handlerAsAvm().address();
943
1227
 
944
1228
  return toForeignCallResult([toSingle(contractAddress.toField())]);
945
1229
  }
946
1230
 
947
- async avmOpcodeBlockNumber() {
948
- const blockNumber = await this.handlerAsAvm().avmOpcodeBlockNumber();
1231
+ // eslint-disable-next-line camelcase
1232
+ async aztec_avm_blockNumber() {
1233
+ const blockNumber = await this.handlerAsAvm().blockNumber();
949
1234
 
950
1235
  return toForeignCallResult([toSingle(new Fr(blockNumber))]);
951
1236
  }
952
1237
 
953
- async avmOpcodeTimestamp() {
954
- const timestamp = await this.handlerAsAvm().avmOpcodeTimestamp();
1238
+ // eslint-disable-next-line camelcase
1239
+ async aztec_avm_timestamp() {
1240
+ const timestamp = await this.handlerAsAvm().timestamp();
955
1241
 
956
1242
  return toForeignCallResult([toSingle(new Fr(timestamp))]);
957
1243
  }
958
1244
 
959
- async avmOpcodeIsStaticCall() {
960
- const isStaticCall = await this.handlerAsAvm().avmOpcodeIsStaticCall();
1245
+ // eslint-disable-next-line camelcase
1246
+ async aztec_avm_isStaticCall() {
1247
+ const isStaticCall = await this.handlerAsAvm().isStaticCall();
961
1248
 
962
1249
  return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
963
1250
  }
964
1251
 
965
- async avmOpcodeChainId() {
966
- const chainId = await this.handlerAsAvm().avmOpcodeChainId();
1252
+ // eslint-disable-next-line camelcase
1253
+ async aztec_avm_chainId() {
1254
+ const chainId = await this.handlerAsAvm().chainId();
967
1255
 
968
1256
  return toForeignCallResult([toSingle(chainId)]);
969
1257
  }
970
1258
 
971
- async avmOpcodeVersion() {
972
- const version = await this.handlerAsAvm().avmOpcodeVersion();
1259
+ // eslint-disable-next-line camelcase
1260
+ async aztec_avm_version() {
1261
+ const version = await this.handlerAsAvm().version();
973
1262
 
974
1263
  return toForeignCallResult([toSingle(version)]);
975
1264
  }
976
1265
 
977
- avmOpcodeReturndataSize() {
1266
+ // eslint-disable-next-line camelcase
1267
+ aztec_avm_returndataSize() {
978
1268
  throw new Error(
979
1269
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
980
1270
  );
981
1271
  }
982
1272
 
983
- avmOpcodeReturndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
1273
+ // eslint-disable-next-line camelcase
1274
+ aztec_avm_returndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
984
1275
  throw new Error(
985
1276
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
986
1277
  );
987
1278
  }
988
1279
 
989
- avmOpcodeCall(
1280
+ // eslint-disable-next-line camelcase
1281
+ aztec_avm_call(
990
1282
  _foreignL2Gas: ForeignCallSingle,
991
1283
  _foreignDaGas: ForeignCallSingle,
992
1284
  _foreignAddress: ForeignCallSingle,
@@ -998,7 +1290,8 @@ export class RPCTranslator {
998
1290
  );
999
1291
  }
1000
1292
 
1001
- avmOpcodeStaticCall(
1293
+ // eslint-disable-next-line camelcase
1294
+ aztec_avm_staticCall(
1002
1295
  _foreignL2Gas: ForeignCallSingle,
1003
1296
  _foreignDaGas: ForeignCallSingle,
1004
1297
  _foreignAddress: ForeignCallSingle,
@@ -1010,13 +1303,15 @@ export class RPCTranslator {
1010
1303
  );
1011
1304
  }
1012
1305
 
1013
- avmOpcodeSuccessCopy() {
1306
+ // eslint-disable-next-line camelcase
1307
+ aztec_avm_successCopy() {
1014
1308
  throw new Error(
1015
1309
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
1016
1310
  );
1017
1311
  }
1018
1312
 
1019
- async txePrivateCallNewFlow(
1313
+ // eslint-disable-next-line camelcase
1314
+ async aztec_txe_privateCallNewFlow(
1020
1315
  foreignFrom: ForeignCallSingle,
1021
1316
  foreignTargetContractAddress: ForeignCallSingle,
1022
1317
  foreignFunctionSelector: ForeignCallSingle,
@@ -1031,19 +1326,43 @@ export class RPCTranslator {
1031
1326
  const argsHash = fromSingle(foreignArgsHash);
1032
1327
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
1033
1328
 
1034
- const returnValues = await this.handlerAsTxe().txePrivateCallNewFlow(
1035
- from,
1036
- targetContractAddress,
1037
- functionSelector,
1038
- args,
1039
- argsHash,
1040
- isStaticCall,
1041
- );
1329
+ const returnValues = await this.stateHandler.withTopLevelCallTracking(async () => {
1330
+ const { returnValues, offchainEffects } = await this.handlerAsTxe().privateCallNewFlow(
1331
+ from,
1332
+ targetContractAddress,
1333
+ functionSelector,
1334
+ args,
1335
+ argsHash,
1336
+ isStaticCall,
1337
+ this.stateHandler.getCurrentJob(),
1338
+ );
1339
+
1340
+ // Private execution collects offchain effects inside PXE's PrivateExecutionOracle rather than
1341
+ // round-tripping them through `aztec_utl_emitOffchainEffect`, so the session buffer is empty
1342
+ // at this point. Drain the effects from the execution tree into the session buffer so the
1343
+ // next `env.offchain_messages()` call in the test sees them.
1344
+ for (const data of offchainEffects) {
1345
+ this.stateHandler.recordOffchainEffect(data);
1346
+ }
1347
+
1348
+ // TODO(F-335): Avoid doing the following call here.
1349
+ await this.stateHandler.cycleJob();
1350
+
1351
+ if (isStaticCall) {
1352
+ // Static calls revert their checkpoint and mine no block, so there is no tx hash to tag
1353
+ // offchain effects with. Querying `getLastTxEffects()` here would return an unrelated
1354
+ // predecessor tx.
1355
+ return { result: returnValues };
1356
+ }
1357
+ const { txHash } = await this.handlerAsTxe().getLastTxEffects();
1358
+ return { result: returnValues, txHash: txHash.hash };
1359
+ });
1042
1360
 
1043
1361
  return toForeignCallResult([toArray(returnValues)]);
1044
1362
  }
1045
1363
 
1046
- async txeSimulateUtilityFunction(
1364
+ // eslint-disable-next-line camelcase
1365
+ async aztec_txe_executeUtilityFunction(
1047
1366
  foreignTargetContractAddress: ForeignCallSingle,
1048
1367
  foreignFunctionSelector: ForeignCallSingle,
1049
1368
  foreignArgs: ForeignCallArray,
@@ -1052,16 +1371,25 @@ export class RPCTranslator {
1052
1371
  const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
1053
1372
  const args = fromArray(foreignArgs);
1054
1373
 
1055
- const returnValues = await this.handlerAsTxe().txeSimulateUtilityFunction(
1056
- targetContractAddress,
1057
- functionSelector,
1058
- args,
1059
- );
1374
+ const returnValues = await this.stateHandler.withTopLevelCallTracking(async () => {
1375
+ const returnValues = await this.handlerAsTxe().executeUtilityFunction(
1376
+ targetContractAddress,
1377
+ functionSelector,
1378
+ args,
1379
+ this.stateHandler.getCurrentJob(),
1380
+ );
1381
+
1382
+ // TODO(F-335): Avoid doing the following call here.
1383
+ await this.stateHandler.cycleJob();
1384
+
1385
+ return { result: returnValues };
1386
+ });
1060
1387
 
1061
1388
  return toForeignCallResult([toArray(returnValues)]);
1062
1389
  }
1063
1390
 
1064
- async txePublicCallNewFlow(
1391
+ // eslint-disable-next-line camelcase
1392
+ async aztec_txe_publicCallNewFlow(
1065
1393
  foreignFrom: ForeignCallSingle,
1066
1394
  foreignAddress: ForeignCallSingle,
1067
1395
  foreignCalldata: ForeignCallArray,
@@ -1072,13 +1400,26 @@ export class RPCTranslator {
1072
1400
  const calldata = fromArray(foreignCalldata);
1073
1401
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
1074
1402
 
1075
- const returnValues = await this.handlerAsTxe().txePublicCallNewFlow(from, address, calldata, isStaticCall);
1403
+ const returnValues = await this.stateHandler.withTopLevelCallTracking(async () => {
1404
+ const returnValues = await this.handlerAsTxe().publicCallNewFlow(from, address, calldata, isStaticCall);
1405
+
1406
+ // TODO(F-335): Avoid doing the following call here.
1407
+ await this.stateHandler.cycleJob();
1408
+
1409
+ if (isStaticCall) {
1410
+ // See equivalent branch in `aztec_txe_privateCallNewFlow`.
1411
+ return { result: returnValues };
1412
+ }
1413
+ const { txHash } = await this.handlerAsTxe().getLastTxEffects();
1414
+ return { result: returnValues, txHash: txHash.hash };
1415
+ });
1076
1416
 
1077
1417
  return toForeignCallResult([toArray(returnValues)]);
1078
1418
  }
1079
1419
 
1080
- async privateGetSenderForTags() {
1081
- const sender = await this.handlerAsPrivate().privateGetSenderForTags();
1420
+ // eslint-disable-next-line camelcase
1421
+ async aztec_prv_getSenderForTags() {
1422
+ const sender = await this.handlerAsPrivate().getSenderForTags();
1082
1423
 
1083
1424
  // Return a Noir Option struct with `some` and `value` fields
1084
1425
  if (sender === undefined) {
@@ -1090,19 +1431,21 @@ export class RPCTranslator {
1090
1431
  }
1091
1432
  }
1092
1433
 
1093
- async privateSetSenderForTags(foreignSenderForTags: ForeignCallSingle) {
1434
+ // eslint-disable-next-line camelcase
1435
+ async aztec_prv_setSenderForTags(foreignSenderForTags: ForeignCallSingle) {
1094
1436
  const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
1095
1437
 
1096
- await this.handlerAsPrivate().privateSetSenderForTags(senderForTags);
1438
+ await this.handlerAsPrivate().setSenderForTags(senderForTags);
1097
1439
 
1098
1440
  return toForeignCallResult([]);
1099
1441
  }
1100
1442
 
1101
- async privateGetNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
1443
+ // eslint-disable-next-line camelcase
1444
+ async aztec_prv_getNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
1102
1445
  const sender = AztecAddress.fromField(fromSingle(foreignSender));
1103
1446
  const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
1104
1447
 
1105
- const nextAppTag = await this.handlerAsPrivate().privateGetNextAppTagAsSender(sender, recipient);
1448
+ const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
1106
1449
 
1107
1450
  return toForeignCallResult([toSingle(nextAppTag.value)]);
1108
1451
  }