@aztec/txe 0.0.1-commit.934299a21 → 0.0.1-commit.949a33fd8

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 (56) hide show
  1. package/dest/index.d.ts +1 -1
  2. package/dest/index.d.ts.map +1 -1
  3. package/dest/index.js +8 -6
  4. package/dest/oracle/interfaces.d.ts +31 -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 +27 -19
  10. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_top_level_context.js +72 -42
  12. package/dest/rpc_translator.d.ts +128 -82
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +458 -170
  15. package/dest/state_machine/archiver.d.ts +3 -3
  16. package/dest/state_machine/archiver.d.ts.map +1 -1
  17. package/dest/state_machine/archiver.js +7 -8
  18. package/dest/state_machine/dummy_p2p_client.d.ts +3 -2
  19. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  20. package/dest/state_machine/dummy_p2p_client.js +5 -2
  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 +4 -2
  25. package/dest/state_machine/index.d.ts.map +1 -1
  26. package/dest/state_machine/index.js +8 -4
  27. package/dest/state_machine/mock_epoch_cache.d.ts +18 -3
  28. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  29. package/dest/state_machine/mock_epoch_cache.js +35 -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 +46 -1
  34. package/dest/txe_session.d.ts.map +1 -1
  35. package/dest/txe_session.js +86 -17
  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 +1 -1
  40. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  41. package/dest/util/txe_public_contract_data_source.js +1 -3
  42. package/package.json +15 -15
  43. package/src/index.ts +8 -5
  44. package/src/oracle/interfaces.ts +28 -32
  45. package/src/oracle/txe_oracle_public_context.ts +12 -12
  46. package/src/oracle/txe_oracle_top_level_context.ts +75 -46
  47. package/src/rpc_translator.ts +532 -204
  48. package/src/state_machine/archiver.ts +6 -5
  49. package/src/state_machine/dummy_p2p_client.ts +6 -2
  50. package/src/state_machine/global_variable_builder.ts +18 -3
  51. package/src/state_machine/index.ts +9 -2
  52. package/src/state_machine/mock_epoch_cache.ts +46 -3
  53. package/src/state_machine/synchronizer.ts +4 -4
  54. package/src/txe_session.ts +148 -17
  55. package/src/util/encoding.ts +5 -0
  56. package/src/util/txe_public_contract_data_source.ts +0 -2
@@ -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,
@@ -292,7 +355,7 @@ export class RPCTranslator {
292
355
  await this.stateHandler.cycleJob();
293
356
  }
294
357
 
295
- const events = await this.handlerAsTxe().txeGetPrivateEvents(selector, contractAddress, scope);
358
+ const events = await this.handlerAsTxe().getPrivateEvents(selector, contractAddress, scope);
296
359
 
297
360
  if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
298
361
  throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
@@ -316,26 +379,29 @@ export class RPCTranslator {
316
379
  return toForeignCallResult([toArray(rawArrayStorage), toArray(eventLengths), toSingle(queryLength)]);
317
380
  }
318
381
 
319
- privateStoreInExecutionCache(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
382
+ // eslint-disable-next-line camelcase
383
+ aztec_prv_setHashPreimage(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
320
384
  const values = fromArray(foreignValues);
321
385
  const hash = fromSingle(foreignHash);
322
386
 
323
- this.handlerAsPrivate().privateStoreInExecutionCache(values, hash);
387
+ this.handlerAsPrivate().setHashPreimage(values, hash);
324
388
 
325
389
  return toForeignCallResult([]);
326
390
  }
327
391
 
328
- async privateLoadFromExecutionCache(foreignHash: ForeignCallSingle) {
392
+ // eslint-disable-next-line camelcase
393
+ async aztec_prv_getHashPreimage(foreignHash: ForeignCallSingle) {
329
394
  const hash = fromSingle(foreignHash);
330
395
 
331
- const returns = await this.handlerAsPrivate().privateLoadFromExecutionCache(hash);
396
+ const returns = await this.handlerAsPrivate().getHashPreimage(hash);
332
397
 
333
398
  return toForeignCallResult([toArray(returns)]);
334
399
  }
335
400
 
336
401
  // When the argument is a slice, noir automatically adds a length field to oracle call.
337
402
  // When the argument is an array, we add the field length manually to the signature.
338
- async utilityLog(
403
+ // eslint-disable-next-line camelcase
404
+ async aztec_utl_log(
339
405
  foreignLevel: ForeignCallSingle,
340
406
  foreignMessage: ForeignCallArray,
341
407
  _foreignLength: ForeignCallSingle,
@@ -347,23 +413,24 @@ export class RPCTranslator {
347
413
  .join('');
348
414
  const fields = fromArray(foreignFields);
349
415
 
350
- await this.handlerAsMisc().utilityLog(level, message, fields);
416
+ await this.handlerAsMisc().log(level, message, fields);
351
417
 
352
418
  return toForeignCallResult([]);
353
419
  }
354
420
 
355
- async utilityStorageRead(
421
+ // eslint-disable-next-line camelcase
422
+ async aztec_utl_getFromPublicStorage(
356
423
  foreignBlockHash: ForeignCallSingle,
357
424
  foreignContractAddress: ForeignCallSingle,
358
425
  foreignStartStorageSlot: ForeignCallSingle,
359
426
  foreignNumberOfElements: ForeignCallSingle,
360
427
  ) {
361
- const blockHash = new BlockHash(fromSingle(foreignBlockHash));
428
+ const blockHash = blockHashFromSingle(foreignBlockHash);
362
429
  const contractAddress = addressFromSingle(foreignContractAddress);
363
430
  const startStorageSlot = fromSingle(foreignStartStorageSlot);
364
431
  const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
365
432
 
366
- const values = await this.handlerAsUtility().utilityStorageRead(
433
+ const values = await this.handlerAsUtility().getFromPublicStorage(
367
434
  blockHash,
368
435
  contractAddress,
369
436
  startStorageSlot,
@@ -373,11 +440,12 @@ export class RPCTranslator {
373
440
  return toForeignCallResult([toArray(values)]);
374
441
  }
375
442
 
376
- async utilityGetPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
377
- 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);
378
446
  const leafSlot = fromSingle(foreignLeafSlot);
379
447
 
380
- const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockHash, leafSlot);
448
+ const witness = await this.handlerAsUtility().getPublicDataWitness(blockHash, leafSlot);
381
449
 
382
450
  if (!witness) {
383
451
  throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
@@ -385,7 +453,8 @@ export class RPCTranslator {
385
453
  return toForeignCallResult(witness.toNoirRepresentation());
386
454
  }
387
455
 
388
- async utilityGetNotes(
456
+ // eslint-disable-next-line camelcase
457
+ async aztec_utl_getNotes(
389
458
  foreignOwnerIsSome: ForeignCallSingle,
390
459
  foreignOwnerValue: ForeignCallSingle,
391
460
  foreignStorageSlot: ForeignCallSingle,
@@ -426,7 +495,7 @@ export class RPCTranslator {
426
495
  const maxNotes = fromSingle(foreignMaxNotes).toNumber();
427
496
  const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
428
497
 
429
- const noteDatas = await this.handlerAsUtility().utilityGetNotes(
498
+ const noteDatas = await this.handlerAsUtility().getNotes(
430
499
  owner,
431
500
  storageSlot,
432
501
  numSelects,
@@ -467,7 +536,8 @@ export class RPCTranslator {
467
536
  );
468
537
  }
469
538
 
470
- privateNotifyCreatedNote(
539
+ // eslint-disable-next-line camelcase
540
+ aztec_prv_notifyCreatedNote(
471
541
  foreignOwner: ForeignCallSingle,
472
542
  foreignStorageSlot: ForeignCallSingle,
473
543
  foreignRandomness: ForeignCallSingle,
@@ -484,20 +554,13 @@ export class RPCTranslator {
484
554
  const noteHash = fromSingle(foreignNoteHash);
485
555
  const counter = fromSingle(foreignCounter).toNumber();
486
556
 
487
- this.handlerAsPrivate().privateNotifyCreatedNote(
488
- owner,
489
- storageSlot,
490
- randomness,
491
- noteTypeId,
492
- note,
493
- noteHash,
494
- counter,
495
- );
557
+ this.handlerAsPrivate().notifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
496
558
 
497
559
  return toForeignCallResult([]);
498
560
  }
499
561
 
500
- async privateNotifyNullifiedNote(
562
+ // eslint-disable-next-line camelcase
563
+ async aztec_prv_notifyNullifiedNote(
501
564
  foreignInnerNullifier: ForeignCallSingle,
502
565
  foreignNoteHash: ForeignCallSingle,
503
566
  foreignCounter: ForeignCallSingle,
@@ -506,40 +569,47 @@ export class RPCTranslator {
506
569
  const noteHash = fromSingle(foreignNoteHash);
507
570
  const counter = fromSingle(foreignCounter).toNumber();
508
571
 
509
- await this.handlerAsPrivate().privateNotifyNullifiedNote(innerNullifier, noteHash, counter);
572
+ await this.handlerAsPrivate().notifyNullifiedNote(innerNullifier, noteHash, counter);
510
573
 
511
574
  return toForeignCallResult([]);
512
575
  }
513
576
 
514
- async privateNotifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
577
+ // eslint-disable-next-line camelcase
578
+ async aztec_prv_notifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
515
579
  const innerNullifier = fromSingle(foreignInnerNullifier);
516
580
 
517
- await this.handlerAsPrivate().privateNotifyCreatedNullifier(innerNullifier);
581
+ await this.handlerAsPrivate().notifyCreatedNullifier(innerNullifier);
518
582
 
519
583
  return toForeignCallResult([]);
520
584
  }
521
585
 
522
- async privateIsNullifierPending(foreignInnerNullifier: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
586
+ // eslint-disable-next-line camelcase
587
+ async aztec_prv_isNullifierPending(
588
+ foreignInnerNullifier: ForeignCallSingle,
589
+ foreignContractAddress: ForeignCallSingle,
590
+ ) {
523
591
  const innerNullifier = fromSingle(foreignInnerNullifier);
524
592
  const contractAddress = addressFromSingle(foreignContractAddress);
525
593
 
526
- const isPending = await this.handlerAsPrivate().privateIsNullifierPending(innerNullifier, contractAddress);
594
+ const isPending = await this.handlerAsPrivate().isNullifierPending(innerNullifier, contractAddress);
527
595
 
528
596
  return toForeignCallResult([toSingle(new Fr(isPending))]);
529
597
  }
530
598
 
531
- async utilityCheckNullifierExists(foreignInnerNullifier: ForeignCallSingle) {
599
+ // eslint-disable-next-line camelcase
600
+ async aztec_utl_doesNullifierExist(foreignInnerNullifier: ForeignCallSingle) {
532
601
  const innerNullifier = fromSingle(foreignInnerNullifier);
533
602
 
534
- const exists = await this.handlerAsUtility().utilityCheckNullifierExists(innerNullifier);
603
+ const exists = await this.handlerAsUtility().doesNullifierExist(innerNullifier);
535
604
 
536
605
  return toForeignCallResult([toSingle(new Fr(exists))]);
537
606
  }
538
607
 
539
- async utilityGetContractInstance(foreignAddress: ForeignCallSingle) {
608
+ // eslint-disable-next-line camelcase
609
+ async aztec_utl_getContractInstance(foreignAddress: ForeignCallSingle) {
540
610
  const address = addressFromSingle(foreignAddress);
541
611
 
542
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
612
+ const instance = await this.handlerAsUtility().getContractInstance(address);
543
613
 
544
614
  return toForeignCallResult(
545
615
  [
@@ -552,10 +622,11 @@ export class RPCTranslator {
552
622
  );
553
623
  }
554
624
 
555
- async utilityTryGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
625
+ // eslint-disable-next-line camelcase
626
+ async aztec_utl_getPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
556
627
  const address = addressFromSingle(foreignAddress);
557
628
 
558
- const result = await this.handlerAsUtility().utilityTryGetPublicKeysAndPartialAddress(address);
629
+ const result = await this.handlerAsUtility().getPublicKeysAndPartialAddress(address);
559
630
 
560
631
  // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
561
632
  // with two fields: `some` (a boolean) and `value` (a field array in this case).
@@ -571,15 +642,17 @@ export class RPCTranslator {
571
642
  }
572
643
  }
573
644
 
574
- async utilityGetKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
645
+ // eslint-disable-next-line camelcase
646
+ async aztec_utl_getKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
575
647
  const pkMHash = fromSingle(foreignPkMHash);
576
648
 
577
- const keyValidationRequest = await this.handlerAsUtility().utilityGetKeyValidationRequest(pkMHash);
649
+ const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
578
650
 
579
651
  return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
580
652
  }
581
653
 
582
- privateCallPrivateFunction(
654
+ // eslint-disable-next-line camelcase
655
+ aztec_prv_callPrivateFunction(
583
656
  _foreignTargetContractAddress: ForeignCallSingle,
584
657
  _foreignFunctionSelector: ForeignCallSingle,
585
658
  _foreignArgsHash: ForeignCallSingle,
@@ -591,11 +664,15 @@ export class RPCTranslator {
591
664
  );
592
665
  }
593
666
 
594
- async utilityGetNullifierMembershipWitness(foreignBlockHash: ForeignCallSingle, foreignNullifier: ForeignCallSingle) {
595
- 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);
596
673
  const nullifier = fromSingle(foreignNullifier);
597
674
 
598
- const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
675
+ const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
599
676
 
600
677
  if (!witness) {
601
678
  throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
@@ -603,10 +680,11 @@ export class RPCTranslator {
603
680
  return toForeignCallResult(witness.toNoirRepresentation());
604
681
  }
605
682
 
606
- async utilityGetAuthWitness(foreignMessageHash: ForeignCallSingle) {
683
+ // eslint-disable-next-line camelcase
684
+ async aztec_utl_getAuthWitness(foreignMessageHash: ForeignCallSingle) {
607
685
  const messageHash = fromSingle(foreignMessageHash);
608
686
 
609
- const authWitness = await this.handlerAsUtility().utilityGetAuthWitness(messageHash);
687
+ const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
610
688
 
611
689
  if (!authWitness) {
612
690
  throw new Error(`Auth witness not found for message hash ${messageHash}.`);
@@ -614,44 +692,35 @@ export class RPCTranslator {
614
692
  return toForeignCallResult([toArray(authWitness)]);
615
693
  }
616
694
 
617
- public privateNotifyEnqueuedPublicFunctionCall(
618
- _foreignTargetContractAddress: ForeignCallSingle,
619
- _foreignCalldataHash: ForeignCallSingle,
620
- _foreignSideEffectCounter: ForeignCallSingle,
621
- _foreignIsStaticCall: ForeignCallSingle,
622
- ) {
695
+ // eslint-disable-next-line camelcase
696
+ public aztec_prv_assertValidPublicCalldata(_foreignCalldataHash: ForeignCallSingle) {
623
697
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
624
698
  }
625
699
 
626
- public privateNotifySetPublicTeardownFunctionCall(
627
- _foreignTargetContractAddress: ForeignCallSingle,
628
- _foreignCalldataHash: ForeignCallSingle,
629
- _foreignSideEffectCounter: ForeignCallSingle,
630
- _foreignIsStaticCall: ForeignCallSingle,
631
- ) {
700
+ // eslint-disable-next-line camelcase
701
+ public aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
632
702
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
633
703
  }
634
704
 
635
- public privateNotifySetMinRevertibleSideEffectCounter(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
636
- throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
637
- }
638
-
639
- public async privateIsSideEffectCounterRevertible(foreignSideEffectCounter: ForeignCallSingle) {
705
+ // eslint-disable-next-line camelcase
706
+ public async aztec_prv_isExecutionInRevertiblePhase(foreignSideEffectCounter: ForeignCallSingle) {
640
707
  const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
641
- const isRevertible = await this.handlerAsPrivate().privateIsSideEffectCounterRevertible(sideEffectCounter);
708
+ const isRevertible = await this.handlerAsPrivate().isExecutionInRevertiblePhase(sideEffectCounter);
642
709
  return toForeignCallResult([toSingle(new Fr(isRevertible))]);
643
710
  }
644
711
 
645
- utilityGetUtilityContext() {
646
- const context = this.handlerAsUtility().utilityGetUtilityContext();
712
+ // eslint-disable-next-line camelcase
713
+ aztec_utl_getUtilityContext() {
714
+ const context = this.handlerAsUtility().getUtilityContext();
647
715
 
648
716
  return toForeignCallResult(context.toNoirRepresentation());
649
717
  }
650
718
 
651
- async utilityGetBlockHeader(foreignBlockNumber: ForeignCallSingle) {
719
+ // eslint-disable-next-line camelcase
720
+ async aztec_utl_getBlockHeader(foreignBlockNumber: ForeignCallSingle) {
652
721
  const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
653
722
 
654
- const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
723
+ const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
655
724
 
656
725
  if (!header) {
657
726
  throw new Error(`Block header not found for block ${blockNumber}.`);
@@ -659,14 +728,15 @@ export class RPCTranslator {
659
728
  return toForeignCallResult(header.toFields().map(toSingle));
660
729
  }
661
730
 
662
- async utilityGetNoteHashMembershipWitness(
731
+ // eslint-disable-next-line camelcase
732
+ async aztec_utl_getNoteHashMembershipWitness(
663
733
  foreignAnchorBlockHash: ForeignCallSingle,
664
734
  foreignNoteHash: ForeignCallSingle,
665
735
  ) {
666
- const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
736
+ const blockHash = blockHashFromSingle(foreignAnchorBlockHash);
667
737
  const noteHash = fromSingle(foreignNoteHash);
668
738
 
669
- const witness = await this.handlerAsUtility().utilityGetNoteHashMembershipWitness(blockHash, noteHash);
739
+ const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
670
740
 
671
741
  if (!witness) {
672
742
  throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
@@ -674,14 +744,15 @@ export class RPCTranslator {
674
744
  return toForeignCallResult(witness.toNoirRepresentation());
675
745
  }
676
746
 
677
- async utilityGetBlockHashMembershipWitness(
747
+ // eslint-disable-next-line camelcase
748
+ async aztec_utl_getBlockHashMembershipWitness(
678
749
  foreignAnchorBlockHash: ForeignCallSingle,
679
750
  foreignBlockHash: ForeignCallSingle,
680
751
  ) {
681
- const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
682
- const blockHash = new BlockHash(fromSingle(foreignBlockHash));
752
+ const anchorBlockHash = blockHashFromSingle(foreignAnchorBlockHash);
753
+ const blockHash = blockHashFromSingle(foreignBlockHash);
683
754
 
684
- const witness = await this.handlerAsUtility().utilityGetBlockHashMembershipWitness(anchorBlockHash, blockHash);
755
+ const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
685
756
 
686
757
  if (!witness) {
687
758
  throw new Error(
@@ -691,14 +762,15 @@ export class RPCTranslator {
691
762
  return toForeignCallResult(witness.toNoirRepresentation());
692
763
  }
693
764
 
694
- async utilityGetLowNullifierMembershipWitness(
765
+ // eslint-disable-next-line camelcase
766
+ async aztec_utl_getLowNullifierMembershipWitness(
695
767
  foreignBlockHash: ForeignCallSingle,
696
768
  foreignNullifier: ForeignCallSingle,
697
769
  ) {
698
- const blockHash = new BlockHash(fromSingle(foreignBlockHash));
770
+ const blockHash = blockHashFromSingle(foreignBlockHash);
699
771
  const nullifier = fromSingle(foreignNullifier);
700
772
 
701
- const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
773
+ const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
702
774
 
703
775
  if (!witness) {
704
776
  throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
@@ -706,74 +778,167 @@ export class RPCTranslator {
706
778
  return toForeignCallResult(witness.toNoirRepresentation());
707
779
  }
708
780
 
709
- async utilityFetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
781
+ // eslint-disable-next-line camelcase
782
+ async aztec_utl_getPendingTaggedLogs(
783
+ foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle,
784
+ foreignScope: ForeignCallSingle,
785
+ ) {
710
786
  const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
787
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
711
788
 
712
- await this.handlerAsUtility().utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
789
+ await this.handlerAsUtility().getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot, scope);
713
790
 
714
791
  return toForeignCallResult([]);
715
792
  }
716
793
 
717
- 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(
718
803
  foreignContractAddress: ForeignCallSingle,
719
804
  foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
720
805
  foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
806
+ foreignMaxNotePackedLen: ForeignCallSingle,
807
+ foreignMaxEventSerializedLen: ForeignCallSingle,
808
+ foreignScope: ForeignCallSingle,
721
809
  ) {
722
810
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
723
811
  const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
724
812
  const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
813
+ const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
814
+ const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
815
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
725
816
 
726
- await this.handlerAsUtility().utilityValidateAndStoreEnqueuedNotesAndEvents(
817
+ await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
727
818
  contractAddress,
728
819
  noteValidationRequestsArrayBaseSlot,
729
820
  eventValidationRequestsArrayBaseSlot,
821
+ maxNotePackedLen,
822
+ maxEventSerializedLen,
823
+ scope,
730
824
  );
731
825
 
732
826
  return toForeignCallResult([]);
733
827
  }
734
828
 
735
- 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(
736
856
  foreignContractAddress: ForeignCallSingle,
737
857
  foreignLogRetrievalRequestsArrayBaseSlot: ForeignCallSingle,
738
858
  foreignLogRetrievalResponsesArrayBaseSlot: ForeignCallSingle,
859
+ foreignScope: ForeignCallSingle,
739
860
  ) {
740
861
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
741
862
  const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
742
863
  const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
864
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
743
865
 
744
- await this.handlerAsUtility().utilityBulkRetrieveLogs(
866
+ await this.handlerAsUtility().getLogsByTag(
745
867
  contractAddress,
746
868
  logRetrievalRequestsArrayBaseSlot,
747
869
  logRetrievalResponsesArrayBaseSlot,
870
+ scope,
871
+ );
872
+
873
+ return toForeignCallResult([]);
874
+ }
875
+
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,
748
893
  );
749
894
 
750
895
  return toForeignCallResult([]);
751
896
  }
752
897
 
753
- async utilityStoreCapsule(
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(
754
914
  foreignContractAddress: ForeignCallSingle,
755
915
  foreignSlot: ForeignCallSingle,
756
916
  foreignCapsule: ForeignCallArray,
917
+ foreignScope: ForeignCallSingle,
757
918
  ) {
758
919
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
759
920
  const slot = fromSingle(foreignSlot);
760
921
  const capsule = fromArray(foreignCapsule);
922
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
761
923
 
762
- await this.handlerAsUtility().utilityStoreCapsule(contractAddress, slot, capsule);
924
+ this.handlerAsUtility().setCapsule(contractAddress, slot, capsule, scope);
763
925
 
764
926
  return toForeignCallResult([]);
765
927
  }
766
928
 
767
- async utilityLoadCapsule(
929
+ // eslint-disable-next-line camelcase
930
+ async aztec_utl_getCapsule(
768
931
  foreignContractAddress: ForeignCallSingle,
769
932
  foreignSlot: ForeignCallSingle,
770
933
  foreignTSize: ForeignCallSingle,
934
+ foreignScope: ForeignCallSingle,
771
935
  ) {
772
936
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
773
937
  const slot = fromSingle(foreignSlot);
774
938
  const tSize = fromSingle(foreignTSize).toNumber();
939
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
775
940
 
776
- const values = await this.handlerAsUtility().utilityLoadCapsule(contractAddress, slot);
941
+ const values = await this.handlerAsUtility().getCapsule(contractAddress, slot, scope);
777
942
 
778
943
  // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
779
944
  // with two fields: `some` (a boolean) and `value` (a field array in this case).
@@ -786,28 +951,95 @@ export class RPCTranslator {
786
951
  }
787
952
  }
788
953
 
789
- 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
+ ) {
790
960
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
791
961
  const slot = fromSingle(foreignSlot);
962
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
792
963
 
793
- await this.handlerAsUtility().utilityDeleteCapsule(contractAddress, slot);
964
+ this.handlerAsUtility().deleteCapsule(contractAddress, slot, scope);
794
965
 
795
966
  return toForeignCallResult([]);
796
967
  }
797
968
 
798
- async utilityCopyCapsule(
969
+ // eslint-disable-next-line camelcase
970
+ async aztec_utl_copyCapsule(
799
971
  foreignContractAddress: ForeignCallSingle,
800
972
  foreignSrcSlot: ForeignCallSingle,
801
973
  foreignDstSlot: ForeignCallSingle,
802
974
  foreignNumEntries: ForeignCallSingle,
975
+ foreignScope: ForeignCallSingle,
803
976
  ) {
804
977
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
805
978
  const srcSlot = fromSingle(foreignSrcSlot);
806
979
  const dstSlot = fromSingle(foreignDstSlot);
807
980
  const numEntries = fromSingle(foreignNumEntries).toNumber();
981
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
982
+
983
+ await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, scope);
984
+
985
+ return toForeignCallResult([]);
986
+ }
808
987
 
809
- await this.handlerAsUtility().utilityCopyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
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
+ }
810
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);
811
1043
  return toForeignCallResult([]);
812
1044
  }
813
1045
 
@@ -815,7 +1047,8 @@ export class RPCTranslator {
815
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
816
1048
  // to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
817
1049
  // existence of a txe_oracle method?
818
- async utilityAes128Decrypt(
1050
+ // eslint-disable-next-line camelcase
1051
+ async aztec_utl_decryptAes128(
819
1052
  foreignCiphertextBVecStorage: ForeignCallArray,
820
1053
  foreignCiphertextLength: ForeignCallSingle,
821
1054
  foreignIv: ForeignCallArray,
@@ -825,18 +1058,27 @@ export class RPCTranslator {
825
1058
  const iv = fromUintArray(foreignIv, 8);
826
1059
  const symKey = fromUintArray(foreignSymKey, 8);
827
1060
 
828
- const plaintextBuffer = await this.handlerAsUtility().utilityAes128Decrypt(ciphertext, iv, symKey);
829
-
830
- return toForeignCallResult(
831
- arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length),
832
- );
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
+ }
833
1073
  }
834
1074
 
835
- async utilityGetSharedSecret(
1075
+ // eslint-disable-next-line camelcase
1076
+ async aztec_utl_getSharedSecret(
836
1077
  foreignAddress: ForeignCallSingle,
837
1078
  foreignEphPKField0: ForeignCallSingle,
838
1079
  foreignEphPKField1: ForeignCallSingle,
839
1080
  foreignEphPKField2: ForeignCallSingle,
1081
+ foreignContractAddress: ForeignCallSingle,
840
1082
  ) {
841
1083
  const address = AztecAddress.fromField(fromSingle(foreignAddress));
842
1084
  const ephPK = Point.fromFields([
@@ -844,45 +1086,73 @@ export class RPCTranslator {
844
1086
  fromSingle(foreignEphPKField1),
845
1087
  fromSingle(foreignEphPKField2),
846
1088
  ]);
1089
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
847
1090
 
848
- const secret = await this.handlerAsUtility().utilityGetSharedSecret(address, ephPK);
1091
+ const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK, contractAddress);
849
1092
 
850
- return toForeignCallResult(secret.toFields().map(toSingle));
1093
+ return toForeignCallResult([toSingle(secret)]);
851
1094
  }
852
1095
 
853
- emitOffchainEffect(_foreignData: ForeignCallArray) {
854
- 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([]));
855
1121
  }
856
1122
 
857
1123
  // AVM opcodes
858
1124
 
859
- avmOpcodeEmitPublicLog(_foreignMessage: ForeignCallArray) {
1125
+ // eslint-disable-next-line camelcase
1126
+ aztec_avm_emitPublicLog(_foreignMessage: ForeignCallArray) {
860
1127
  // TODO(#8811): Implement
861
1128
  return toForeignCallResult([]);
862
1129
  }
863
1130
 
864
- async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
1131
+ // eslint-disable-next-line camelcase
1132
+ async aztec_avm_storageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
865
1133
  const slot = fromSingle(foreignSlot);
866
1134
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
867
1135
 
868
- const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot, contractAddress)).value;
1136
+ const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
869
1137
 
870
1138
  return toForeignCallResult([toSingle(new Fr(value))]);
871
1139
  }
872
1140
 
873
- async avmOpcodeStorageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
1141
+ // eslint-disable-next-line camelcase
1142
+ async aztec_avm_storageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
874
1143
  const slot = fromSingle(foreignSlot);
875
1144
  const value = fromSingle(foreignValue);
876
1145
 
877
- await this.handlerAsAvm().avmOpcodeStorageWrite(slot, value);
1146
+ await this.handlerAsAvm().storageWrite(slot, value);
878
1147
 
879
1148
  return toForeignCallResult([]);
880
1149
  }
881
1150
 
882
- async avmOpcodeGetContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
1151
+ // eslint-disable-next-line camelcase
1152
+ async aztec_avm_getContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
883
1153
  const address = addressFromSingle(foreignAddress);
884
1154
 
885
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
1155
+ const instance = await this.handlerAsUtility().getContractInstance(address);
886
1156
 
887
1157
  return toForeignCallResult([
888
1158
  toSingle(instance.deployer),
@@ -891,10 +1161,11 @@ export class RPCTranslator {
891
1161
  ]);
892
1162
  }
893
1163
 
894
- async avmOpcodeGetContractInstanceClassId(foreignAddress: ForeignCallSingle) {
1164
+ // eslint-disable-next-line camelcase
1165
+ async aztec_avm_getContractInstanceClassId(foreignAddress: ForeignCallSingle) {
895
1166
  const address = addressFromSingle(foreignAddress);
896
1167
 
897
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
1168
+ const instance = await this.handlerAsUtility().getContractInstance(address);
898
1169
 
899
1170
  return toForeignCallResult([
900
1171
  toSingle(instance.currentContractClassId),
@@ -903,10 +1174,11 @@ export class RPCTranslator {
903
1174
  ]);
904
1175
  }
905
1176
 
906
- async avmOpcodeGetContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
1177
+ // eslint-disable-next-line camelcase
1178
+ async aztec_avm_getContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
907
1179
  const address = addressFromSingle(foreignAddress);
908
1180
 
909
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
1181
+ const instance = await this.handlerAsUtility().getContractInstance(address);
910
1182
 
911
1183
  return toForeignCallResult([
912
1184
  toSingle(instance.initializationHash),
@@ -915,85 +1187,98 @@ export class RPCTranslator {
915
1187
  ]);
916
1188
  }
917
1189
 
918
- async avmOpcodeSender() {
919
- const sender = await this.handlerAsAvm().avmOpcodeSender();
1190
+ // eslint-disable-next-line camelcase
1191
+ async aztec_avm_sender() {
1192
+ const sender = await this.handlerAsAvm().sender();
920
1193
 
921
1194
  return toForeignCallResult([toSingle(sender)]);
922
1195
  }
923
1196
 
924
- async avmOpcodeEmitNullifier(foreignNullifier: ForeignCallSingle) {
1197
+ // eslint-disable-next-line camelcase
1198
+ async aztec_avm_emitNullifier(foreignNullifier: ForeignCallSingle) {
925
1199
  const nullifier = fromSingle(foreignNullifier);
926
1200
 
927
- await this.handlerAsAvm().avmOpcodeEmitNullifier(nullifier);
1201
+ await this.handlerAsAvm().emitNullifier(nullifier);
928
1202
 
929
1203
  return toForeignCallResult([]);
930
1204
  }
931
1205
 
932
- async avmOpcodeEmitNoteHash(foreignNoteHash: ForeignCallSingle) {
1206
+ // eslint-disable-next-line camelcase
1207
+ async aztec_avm_emitNoteHash(foreignNoteHash: ForeignCallSingle) {
933
1208
  const noteHash = fromSingle(foreignNoteHash);
934
1209
 
935
- await this.handlerAsAvm().avmOpcodeEmitNoteHash(noteHash);
1210
+ await this.handlerAsAvm().emitNoteHash(noteHash);
936
1211
 
937
1212
  return toForeignCallResult([]);
938
1213
  }
939
1214
 
940
- async avmOpcodeNullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
1215
+ // eslint-disable-next-line camelcase
1216
+ async aztec_avm_nullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
941
1217
  const siloedNullifier = fromSingle(foreignSiloedNullifier);
942
1218
 
943
- const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(siloedNullifier);
1219
+ const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
944
1220
 
945
1221
  return toForeignCallResult([toSingle(new Fr(exists))]);
946
1222
  }
947
1223
 
948
- async avmOpcodeAddress() {
949
- const contractAddress = await this.handlerAsAvm().avmOpcodeAddress();
1224
+ // eslint-disable-next-line camelcase
1225
+ async aztec_avm_address() {
1226
+ const contractAddress = await this.handlerAsAvm().address();
950
1227
 
951
1228
  return toForeignCallResult([toSingle(contractAddress.toField())]);
952
1229
  }
953
1230
 
954
- async avmOpcodeBlockNumber() {
955
- const blockNumber = await this.handlerAsAvm().avmOpcodeBlockNumber();
1231
+ // eslint-disable-next-line camelcase
1232
+ async aztec_avm_blockNumber() {
1233
+ const blockNumber = await this.handlerAsAvm().blockNumber();
956
1234
 
957
1235
  return toForeignCallResult([toSingle(new Fr(blockNumber))]);
958
1236
  }
959
1237
 
960
- async avmOpcodeTimestamp() {
961
- const timestamp = await this.handlerAsAvm().avmOpcodeTimestamp();
1238
+ // eslint-disable-next-line camelcase
1239
+ async aztec_avm_timestamp() {
1240
+ const timestamp = await this.handlerAsAvm().timestamp();
962
1241
 
963
1242
  return toForeignCallResult([toSingle(new Fr(timestamp))]);
964
1243
  }
965
1244
 
966
- async avmOpcodeIsStaticCall() {
967
- const isStaticCall = await this.handlerAsAvm().avmOpcodeIsStaticCall();
1245
+ // eslint-disable-next-line camelcase
1246
+ async aztec_avm_isStaticCall() {
1247
+ const isStaticCall = await this.handlerAsAvm().isStaticCall();
968
1248
 
969
1249
  return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
970
1250
  }
971
1251
 
972
- async avmOpcodeChainId() {
973
- const chainId = await this.handlerAsAvm().avmOpcodeChainId();
1252
+ // eslint-disable-next-line camelcase
1253
+ async aztec_avm_chainId() {
1254
+ const chainId = await this.handlerAsAvm().chainId();
974
1255
 
975
1256
  return toForeignCallResult([toSingle(chainId)]);
976
1257
  }
977
1258
 
978
- async avmOpcodeVersion() {
979
- const version = await this.handlerAsAvm().avmOpcodeVersion();
1259
+ // eslint-disable-next-line camelcase
1260
+ async aztec_avm_version() {
1261
+ const version = await this.handlerAsAvm().version();
980
1262
 
981
1263
  return toForeignCallResult([toSingle(version)]);
982
1264
  }
983
1265
 
984
- avmOpcodeReturndataSize() {
1266
+ // eslint-disable-next-line camelcase
1267
+ aztec_avm_returndataSize() {
985
1268
  throw new Error(
986
1269
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
987
1270
  );
988
1271
  }
989
1272
 
990
- avmOpcodeReturndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
1273
+ // eslint-disable-next-line camelcase
1274
+ aztec_avm_returndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
991
1275
  throw new Error(
992
1276
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
993
1277
  );
994
1278
  }
995
1279
 
996
- avmOpcodeCall(
1280
+ // eslint-disable-next-line camelcase
1281
+ aztec_avm_call(
997
1282
  _foreignL2Gas: ForeignCallSingle,
998
1283
  _foreignDaGas: ForeignCallSingle,
999
1284
  _foreignAddress: ForeignCallSingle,
@@ -1005,7 +1290,8 @@ export class RPCTranslator {
1005
1290
  );
1006
1291
  }
1007
1292
 
1008
- avmOpcodeStaticCall(
1293
+ // eslint-disable-next-line camelcase
1294
+ aztec_avm_staticCall(
1009
1295
  _foreignL2Gas: ForeignCallSingle,
1010
1296
  _foreignDaGas: ForeignCallSingle,
1011
1297
  _foreignAddress: ForeignCallSingle,
@@ -1017,13 +1303,15 @@ export class RPCTranslator {
1017
1303
  );
1018
1304
  }
1019
1305
 
1020
- avmOpcodeSuccessCopy() {
1306
+ // eslint-disable-next-line camelcase
1307
+ aztec_avm_successCopy() {
1021
1308
  throw new Error(
1022
1309
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
1023
1310
  );
1024
1311
  }
1025
1312
 
1026
- async txePrivateCallNewFlow(
1313
+ // eslint-disable-next-line camelcase
1314
+ async aztec_txe_privateCallNewFlow(
1027
1315
  foreignFrom: ForeignCallSingle,
1028
1316
  foreignTargetContractAddress: ForeignCallSingle,
1029
1317
  foreignFunctionSelector: ForeignCallSingle,
@@ -1038,22 +1326,43 @@ export class RPCTranslator {
1038
1326
  const argsHash = fromSingle(foreignArgsHash);
1039
1327
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
1040
1328
 
1041
- const returnValues = await this.handlerAsTxe().txePrivateCallNewFlow(
1042
- from,
1043
- targetContractAddress,
1044
- functionSelector,
1045
- args,
1046
- argsHash,
1047
- isStaticCall,
1048
- this.stateHandler.getCurrentJob(),
1049
- );
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
+ });
1050
1360
 
1051
- // TODO(F-335): Avoid doing the following call here.
1052
- await this.stateHandler.cycleJob();
1053
1361
  return toForeignCallResult([toArray(returnValues)]);
1054
1362
  }
1055
1363
 
1056
- async txeExecuteUtilityFunction(
1364
+ // eslint-disable-next-line camelcase
1365
+ async aztec_txe_executeUtilityFunction(
1057
1366
  foreignTargetContractAddress: ForeignCallSingle,
1058
1367
  foreignFunctionSelector: ForeignCallSingle,
1059
1368
  foreignArgs: ForeignCallArray,
@@ -1062,19 +1371,25 @@ export class RPCTranslator {
1062
1371
  const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
1063
1372
  const args = fromArray(foreignArgs);
1064
1373
 
1065
- const returnValues = await this.handlerAsTxe().txeExecuteUtilityFunction(
1066
- targetContractAddress,
1067
- functionSelector,
1068
- args,
1069
- this.stateHandler.getCurrentJob(),
1070
- );
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
+ });
1071
1387
 
1072
- // TODO(F-335): Avoid doing the following call here.
1073
- await this.stateHandler.cycleJob();
1074
1388
  return toForeignCallResult([toArray(returnValues)]);
1075
1389
  }
1076
1390
 
1077
- async txePublicCallNewFlow(
1391
+ // eslint-disable-next-line camelcase
1392
+ async aztec_txe_publicCallNewFlow(
1078
1393
  foreignFrom: ForeignCallSingle,
1079
1394
  foreignAddress: ForeignCallSingle,
1080
1395
  foreignCalldata: ForeignCallArray,
@@ -1085,15 +1400,26 @@ export class RPCTranslator {
1085
1400
  const calldata = fromArray(foreignCalldata);
1086
1401
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
1087
1402
 
1088
- 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
+ });
1089
1416
 
1090
- // TODO(F-335): Avoid doing the following call here.
1091
- await this.stateHandler.cycleJob();
1092
1417
  return toForeignCallResult([toArray(returnValues)]);
1093
1418
  }
1094
1419
 
1095
- async privateGetSenderForTags() {
1096
- const sender = await this.handlerAsPrivate().privateGetSenderForTags();
1420
+ // eslint-disable-next-line camelcase
1421
+ async aztec_prv_getSenderForTags() {
1422
+ const sender = await this.handlerAsPrivate().getSenderForTags();
1097
1423
 
1098
1424
  // Return a Noir Option struct with `some` and `value` fields
1099
1425
  if (sender === undefined) {
@@ -1105,19 +1431,21 @@ export class RPCTranslator {
1105
1431
  }
1106
1432
  }
1107
1433
 
1108
- async privateSetSenderForTags(foreignSenderForTags: ForeignCallSingle) {
1434
+ // eslint-disable-next-line camelcase
1435
+ async aztec_prv_setSenderForTags(foreignSenderForTags: ForeignCallSingle) {
1109
1436
  const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
1110
1437
 
1111
- await this.handlerAsPrivate().privateSetSenderForTags(senderForTags);
1438
+ await this.handlerAsPrivate().setSenderForTags(senderForTags);
1112
1439
 
1113
1440
  return toForeignCallResult([]);
1114
1441
  }
1115
1442
 
1116
- async privateGetNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
1443
+ // eslint-disable-next-line camelcase
1444
+ async aztec_prv_getNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
1117
1445
  const sender = AztecAddress.fromField(fromSingle(foreignSender));
1118
1446
  const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
1119
1447
 
1120
- const nextAppTag = await this.handlerAsPrivate().privateGetNextAppTagAsSender(sender, recipient);
1448
+ const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
1121
1449
 
1122
1450
  return toForeignCallResult([toSingle(nextAppTag.value)]);
1123
1451
  }