@aztec/txe 0.0.1-commit.9372f48 → 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 (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 +160 -61
  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 +482 -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 +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 +156 -28
  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 +176 -111
  50. package/src/rpc_translator.ts +551 -197
  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 +33 -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 +221 -76
  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,23 +622,37 @@ export class RPCTranslator {
545
622
  );
546
623
  }
547
624
 
548
- async utilityGetPublicKeysAndPartialAddress(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 { publicKeys, partialAddress } = await this.handlerAsUtility().utilityGetPublicKeysAndPartialAddress(address);
629
+ const result = await this.handlerAsUtility().getPublicKeysAndPartialAddress(address);
552
630
 
553
- return toForeignCallResult([toArray([...publicKeys.toFields(), partialAddress])]);
631
+ // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
632
+ // with two fields: `some` (a boolean) and `value` (a field array in this case).
633
+ if (result === undefined) {
634
+ // No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
635
+ return toForeignCallResult([toSingle(new Fr(0)), toArray(Array(13).fill(new Fr(0)))]);
636
+ } else {
637
+ // Data was found so we set `some` to 1 and return it along with `value`.
638
+ return toForeignCallResult([
639
+ toSingle(new Fr(1)),
640
+ toArray([...result.publicKeys.toFields(), result.partialAddress]),
641
+ ]);
642
+ }
554
643
  }
555
644
 
556
- async utilityGetKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
645
+ // eslint-disable-next-line camelcase
646
+ async aztec_utl_getKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
557
647
  const pkMHash = fromSingle(foreignPkMHash);
558
648
 
559
- const keyValidationRequest = await this.handlerAsUtility().utilityGetKeyValidationRequest(pkMHash);
649
+ const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
560
650
 
561
651
  return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
562
652
  }
563
653
 
564
- privateCallPrivateFunction(
654
+ // eslint-disable-next-line camelcase
655
+ aztec_prv_callPrivateFunction(
565
656
  _foreignTargetContractAddress: ForeignCallSingle,
566
657
  _foreignFunctionSelector: ForeignCallSingle,
567
658
  _foreignArgsHash: ForeignCallSingle,
@@ -573,11 +664,15 @@ export class RPCTranslator {
573
664
  );
574
665
  }
575
666
 
576
- async utilityGetNullifierMembershipWitness(foreignBlockHash: ForeignCallSingle, foreignNullifier: ForeignCallSingle) {
577
- 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);
578
673
  const nullifier = fromSingle(foreignNullifier);
579
674
 
580
- const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
675
+ const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
581
676
 
582
677
  if (!witness) {
583
678
  throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
@@ -585,10 +680,11 @@ export class RPCTranslator {
585
680
  return toForeignCallResult(witness.toNoirRepresentation());
586
681
  }
587
682
 
588
- async utilityGetAuthWitness(foreignMessageHash: ForeignCallSingle) {
683
+ // eslint-disable-next-line camelcase
684
+ async aztec_utl_getAuthWitness(foreignMessageHash: ForeignCallSingle) {
589
685
  const messageHash = fromSingle(foreignMessageHash);
590
686
 
591
- const authWitness = await this.handlerAsUtility().utilityGetAuthWitness(messageHash);
687
+ const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
592
688
 
593
689
  if (!authWitness) {
594
690
  throw new Error(`Auth witness not found for message hash ${messageHash}.`);
@@ -596,44 +692,35 @@ export class RPCTranslator {
596
692
  return toForeignCallResult([toArray(authWitness)]);
597
693
  }
598
694
 
599
- public privateNotifyEnqueuedPublicFunctionCall(
600
- _foreignTargetContractAddress: ForeignCallSingle,
601
- _foreignCalldataHash: ForeignCallSingle,
602
- _foreignSideEffectCounter: ForeignCallSingle,
603
- _foreignIsStaticCall: ForeignCallSingle,
604
- ) {
695
+ // eslint-disable-next-line camelcase
696
+ public aztec_prv_assertValidPublicCalldata(_foreignCalldataHash: ForeignCallSingle) {
605
697
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
606
698
  }
607
699
 
608
- public privateNotifySetPublicTeardownFunctionCall(
609
- _foreignTargetContractAddress: ForeignCallSingle,
610
- _foreignCalldataHash: ForeignCallSingle,
611
- _foreignSideEffectCounter: ForeignCallSingle,
612
- _foreignIsStaticCall: ForeignCallSingle,
613
- ) {
700
+ // eslint-disable-next-line camelcase
701
+ public aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
614
702
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
615
703
  }
616
704
 
617
- public privateNotifySetMinRevertibleSideEffectCounter(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
618
- throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
619
- }
620
-
621
- public async privateIsSideEffectCounterRevertible(foreignSideEffectCounter: ForeignCallSingle) {
705
+ // eslint-disable-next-line camelcase
706
+ public async aztec_prv_isExecutionInRevertiblePhase(foreignSideEffectCounter: ForeignCallSingle) {
622
707
  const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
623
- const isRevertible = await this.handlerAsPrivate().privateIsSideEffectCounterRevertible(sideEffectCounter);
708
+ const isRevertible = await this.handlerAsPrivate().isExecutionInRevertiblePhase(sideEffectCounter);
624
709
  return toForeignCallResult([toSingle(new Fr(isRevertible))]);
625
710
  }
626
711
 
627
- utilityGetUtilityContext() {
628
- const context = this.handlerAsUtility().utilityGetUtilityContext();
712
+ // eslint-disable-next-line camelcase
713
+ aztec_utl_getUtilityContext() {
714
+ const context = this.handlerAsUtility().getUtilityContext();
629
715
 
630
716
  return toForeignCallResult(context.toNoirRepresentation());
631
717
  }
632
718
 
633
- async utilityGetBlockHeader(foreignBlockNumber: ForeignCallSingle) {
719
+ // eslint-disable-next-line camelcase
720
+ async aztec_utl_getBlockHeader(foreignBlockNumber: ForeignCallSingle) {
634
721
  const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
635
722
 
636
- const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
723
+ const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
637
724
 
638
725
  if (!header) {
639
726
  throw new Error(`Block header not found for block ${blockNumber}.`);
@@ -641,14 +728,15 @@ export class RPCTranslator {
641
728
  return toForeignCallResult(header.toFields().map(toSingle));
642
729
  }
643
730
 
644
- async utilityGetNoteHashMembershipWitness(
731
+ // eslint-disable-next-line camelcase
732
+ async aztec_utl_getNoteHashMembershipWitness(
645
733
  foreignAnchorBlockHash: ForeignCallSingle,
646
734
  foreignNoteHash: ForeignCallSingle,
647
735
  ) {
648
- const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
736
+ const blockHash = blockHashFromSingle(foreignAnchorBlockHash);
649
737
  const noteHash = fromSingle(foreignNoteHash);
650
738
 
651
- const witness = await this.handlerAsUtility().utilityGetNoteHashMembershipWitness(blockHash, noteHash);
739
+ const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
652
740
 
653
741
  if (!witness) {
654
742
  throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
@@ -656,14 +744,15 @@ export class RPCTranslator {
656
744
  return toForeignCallResult(witness.toNoirRepresentation());
657
745
  }
658
746
 
659
- async utilityGetBlockHashMembershipWitness(
747
+ // eslint-disable-next-line camelcase
748
+ async aztec_utl_getBlockHashMembershipWitness(
660
749
  foreignAnchorBlockHash: ForeignCallSingle,
661
750
  foreignBlockHash: ForeignCallSingle,
662
751
  ) {
663
- const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
664
- const blockHash = new BlockHash(fromSingle(foreignBlockHash));
752
+ const anchorBlockHash = blockHashFromSingle(foreignAnchorBlockHash);
753
+ const blockHash = blockHashFromSingle(foreignBlockHash);
665
754
 
666
- const witness = await this.handlerAsUtility().utilityGetBlockHashMembershipWitness(anchorBlockHash, blockHash);
755
+ const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
667
756
 
668
757
  if (!witness) {
669
758
  throw new Error(
@@ -673,14 +762,15 @@ export class RPCTranslator {
673
762
  return toForeignCallResult(witness.toNoirRepresentation());
674
763
  }
675
764
 
676
- async utilityGetLowNullifierMembershipWitness(
765
+ // eslint-disable-next-line camelcase
766
+ async aztec_utl_getLowNullifierMembershipWitness(
677
767
  foreignBlockHash: ForeignCallSingle,
678
768
  foreignNullifier: ForeignCallSingle,
679
769
  ) {
680
- const blockHash = new BlockHash(fromSingle(foreignBlockHash));
770
+ const blockHash = blockHashFromSingle(foreignBlockHash);
681
771
  const nullifier = fromSingle(foreignNullifier);
682
772
 
683
- const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
773
+ const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
684
774
 
685
775
  if (!witness) {
686
776
  throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
@@ -688,74 +778,167 @@ export class RPCTranslator {
688
778
  return toForeignCallResult(witness.toNoirRepresentation());
689
779
  }
690
780
 
691
- async utilityFetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
781
+ // eslint-disable-next-line camelcase
782
+ async aztec_utl_getPendingTaggedLogs(
783
+ foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle,
784
+ foreignScope: ForeignCallSingle,
785
+ ) {
692
786
  const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
787
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
693
788
 
694
- await this.handlerAsUtility().utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
789
+ await this.handlerAsUtility().getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot, scope);
695
790
 
696
791
  return toForeignCallResult([]);
697
792
  }
698
793
 
699
- 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(
700
803
  foreignContractAddress: ForeignCallSingle,
701
804
  foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
702
805
  foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
806
+ foreignMaxNotePackedLen: ForeignCallSingle,
807
+ foreignMaxEventSerializedLen: ForeignCallSingle,
808
+ foreignScope: ForeignCallSingle,
703
809
  ) {
704
810
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
705
811
  const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
706
812
  const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
813
+ const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
814
+ const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
815
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
707
816
 
708
- await this.handlerAsUtility().utilityValidateAndStoreEnqueuedNotesAndEvents(
817
+ await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
709
818
  contractAddress,
710
819
  noteValidationRequestsArrayBaseSlot,
711
820
  eventValidationRequestsArrayBaseSlot,
821
+ maxNotePackedLen,
822
+ maxEventSerializedLen,
823
+ scope,
824
+ );
825
+
826
+ return toForeignCallResult([]);
827
+ }
828
+
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,
712
849
  );
713
850
 
714
851
  return toForeignCallResult([]);
715
852
  }
716
853
 
717
- public async utilityBulkRetrieveLogs(
854
+ // eslint-disable-next-line camelcase
855
+ public async aztec_utl_getLogsByTag(
718
856
  foreignContractAddress: ForeignCallSingle,
719
857
  foreignLogRetrievalRequestsArrayBaseSlot: ForeignCallSingle,
720
858
  foreignLogRetrievalResponsesArrayBaseSlot: ForeignCallSingle,
859
+ foreignScope: ForeignCallSingle,
721
860
  ) {
722
861
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
723
862
  const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
724
863
  const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
864
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
725
865
 
726
- await this.handlerAsUtility().utilityBulkRetrieveLogs(
866
+ await this.handlerAsUtility().getLogsByTag(
727
867
  contractAddress,
728
868
  logRetrievalRequestsArrayBaseSlot,
729
869
  logRetrievalResponsesArrayBaseSlot,
870
+ scope,
730
871
  );
731
872
 
732
873
  return toForeignCallResult([]);
733
874
  }
734
875
 
735
- 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(
736
914
  foreignContractAddress: ForeignCallSingle,
737
915
  foreignSlot: ForeignCallSingle,
738
916
  foreignCapsule: ForeignCallArray,
917
+ foreignScope: ForeignCallSingle,
739
918
  ) {
740
919
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
741
920
  const slot = fromSingle(foreignSlot);
742
921
  const capsule = fromArray(foreignCapsule);
922
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
743
923
 
744
- await this.handlerAsUtility().utilityStoreCapsule(contractAddress, slot, capsule);
924
+ this.handlerAsUtility().setCapsule(contractAddress, slot, capsule, scope);
745
925
 
746
926
  return toForeignCallResult([]);
747
927
  }
748
928
 
749
- async utilityLoadCapsule(
929
+ // eslint-disable-next-line camelcase
930
+ async aztec_utl_getCapsule(
750
931
  foreignContractAddress: ForeignCallSingle,
751
932
  foreignSlot: ForeignCallSingle,
752
933
  foreignTSize: ForeignCallSingle,
934
+ foreignScope: ForeignCallSingle,
753
935
  ) {
754
936
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
755
937
  const slot = fromSingle(foreignSlot);
756
938
  const tSize = fromSingle(foreignTSize).toNumber();
939
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
757
940
 
758
- const values = await this.handlerAsUtility().utilityLoadCapsule(contractAddress, slot);
941
+ const values = await this.handlerAsUtility().getCapsule(contractAddress, slot, scope);
759
942
 
760
943
  // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
761
944
  // with two fields: `some` (a boolean) and `value` (a field array in this case).
@@ -768,28 +951,95 @@ export class RPCTranslator {
768
951
  }
769
952
  }
770
953
 
771
- 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
+ ) {
772
960
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
773
961
  const slot = fromSingle(foreignSlot);
962
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
774
963
 
775
- await this.handlerAsUtility().utilityDeleteCapsule(contractAddress, slot);
964
+ this.handlerAsUtility().deleteCapsule(contractAddress, slot, scope);
776
965
 
777
966
  return toForeignCallResult([]);
778
967
  }
779
968
 
780
- async utilityCopyCapsule(
969
+ // eslint-disable-next-line camelcase
970
+ async aztec_utl_copyCapsule(
781
971
  foreignContractAddress: ForeignCallSingle,
782
972
  foreignSrcSlot: ForeignCallSingle,
783
973
  foreignDstSlot: ForeignCallSingle,
784
974
  foreignNumEntries: ForeignCallSingle,
975
+ foreignScope: ForeignCallSingle,
785
976
  ) {
786
977
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
787
978
  const srcSlot = fromSingle(foreignSrcSlot);
788
979
  const dstSlot = fromSingle(foreignDstSlot);
789
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
+ }
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
+ }
790
1023
 
791
- await this.handlerAsUtility().utilityCopyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
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
+ }
792
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);
793
1043
  return toForeignCallResult([]);
794
1044
  }
795
1045
 
@@ -797,7 +1047,8 @@ export class RPCTranslator {
797
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
798
1048
  // to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
799
1049
  // existence of a txe_oracle method?
800
- async utilityAes128Decrypt(
1050
+ // eslint-disable-next-line camelcase
1051
+ async aztec_utl_decryptAes128(
801
1052
  foreignCiphertextBVecStorage: ForeignCallArray,
802
1053
  foreignCiphertextLength: ForeignCallSingle,
803
1054
  foreignIv: ForeignCallArray,
@@ -807,18 +1058,27 @@ export class RPCTranslator {
807
1058
  const iv = fromUintArray(foreignIv, 8);
808
1059
  const symKey = fromUintArray(foreignSymKey, 8);
809
1060
 
810
- const plaintextBuffer = await this.handlerAsUtility().utilityAes128Decrypt(ciphertext, iv, symKey);
811
-
812
- return toForeignCallResult(
813
- arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length),
814
- );
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
+ }
815
1073
  }
816
1074
 
817
- async utilityGetSharedSecret(
1075
+ // eslint-disable-next-line camelcase
1076
+ async aztec_utl_getSharedSecret(
818
1077
  foreignAddress: ForeignCallSingle,
819
1078
  foreignEphPKField0: ForeignCallSingle,
820
1079
  foreignEphPKField1: ForeignCallSingle,
821
1080
  foreignEphPKField2: ForeignCallSingle,
1081
+ foreignContractAddress: ForeignCallSingle,
822
1082
  ) {
823
1083
  const address = AztecAddress.fromField(fromSingle(foreignAddress));
824
1084
  const ephPK = Point.fromFields([
@@ -826,45 +1086,73 @@ export class RPCTranslator {
826
1086
  fromSingle(foreignEphPKField1),
827
1087
  fromSingle(foreignEphPKField2),
828
1088
  ]);
1089
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
829
1090
 
830
- const secret = await this.handlerAsUtility().utilityGetSharedSecret(address, ephPK);
1091
+ const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK, contractAddress);
831
1092
 
832
- return toForeignCallResult(secret.toFields().map(toSingle));
1093
+ return toForeignCallResult([toSingle(secret)]);
833
1094
  }
834
1095
 
835
- emitOffchainEffect(_foreignData: ForeignCallArray) {
836
- 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([]));
837
1121
  }
838
1122
 
839
1123
  // AVM opcodes
840
1124
 
841
- avmOpcodeEmitUnencryptedLog(_foreignMessage: ForeignCallArray) {
1125
+ // eslint-disable-next-line camelcase
1126
+ aztec_avm_emitPublicLog(_foreignMessage: ForeignCallArray) {
842
1127
  // TODO(#8811): Implement
843
1128
  return toForeignCallResult([]);
844
1129
  }
845
1130
 
846
- async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
1131
+ // eslint-disable-next-line camelcase
1132
+ async aztec_avm_storageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
847
1133
  const slot = fromSingle(foreignSlot);
848
1134
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
849
1135
 
850
- const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot, contractAddress)).value;
1136
+ const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
851
1137
 
852
1138
  return toForeignCallResult([toSingle(new Fr(value))]);
853
1139
  }
854
1140
 
855
- async avmOpcodeStorageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
1141
+ // eslint-disable-next-line camelcase
1142
+ async aztec_avm_storageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
856
1143
  const slot = fromSingle(foreignSlot);
857
1144
  const value = fromSingle(foreignValue);
858
1145
 
859
- await this.handlerAsAvm().avmOpcodeStorageWrite(slot, value);
1146
+ await this.handlerAsAvm().storageWrite(slot, value);
860
1147
 
861
1148
  return toForeignCallResult([]);
862
1149
  }
863
1150
 
864
- async avmOpcodeGetContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
1151
+ // eslint-disable-next-line camelcase
1152
+ async aztec_avm_getContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
865
1153
  const address = addressFromSingle(foreignAddress);
866
1154
 
867
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
1155
+ const instance = await this.handlerAsUtility().getContractInstance(address);
868
1156
 
869
1157
  return toForeignCallResult([
870
1158
  toSingle(instance.deployer),
@@ -873,10 +1161,11 @@ export class RPCTranslator {
873
1161
  ]);
874
1162
  }
875
1163
 
876
- async avmOpcodeGetContractInstanceClassId(foreignAddress: ForeignCallSingle) {
1164
+ // eslint-disable-next-line camelcase
1165
+ async aztec_avm_getContractInstanceClassId(foreignAddress: ForeignCallSingle) {
877
1166
  const address = addressFromSingle(foreignAddress);
878
1167
 
879
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
1168
+ const instance = await this.handlerAsUtility().getContractInstance(address);
880
1169
 
881
1170
  return toForeignCallResult([
882
1171
  toSingle(instance.currentContractClassId),
@@ -885,10 +1174,11 @@ export class RPCTranslator {
885
1174
  ]);
886
1175
  }
887
1176
 
888
- async avmOpcodeGetContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
1177
+ // eslint-disable-next-line camelcase
1178
+ async aztec_avm_getContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
889
1179
  const address = addressFromSingle(foreignAddress);
890
1180
 
891
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
1181
+ const instance = await this.handlerAsUtility().getContractInstance(address);
892
1182
 
893
1183
  return toForeignCallResult([
894
1184
  toSingle(instance.initializationHash),
@@ -897,85 +1187,98 @@ export class RPCTranslator {
897
1187
  ]);
898
1188
  }
899
1189
 
900
- async avmOpcodeSender() {
901
- const sender = await this.handlerAsAvm().avmOpcodeSender();
1190
+ // eslint-disable-next-line camelcase
1191
+ async aztec_avm_sender() {
1192
+ const sender = await this.handlerAsAvm().sender();
902
1193
 
903
1194
  return toForeignCallResult([toSingle(sender)]);
904
1195
  }
905
1196
 
906
- async avmOpcodeEmitNullifier(foreignNullifier: ForeignCallSingle) {
1197
+ // eslint-disable-next-line camelcase
1198
+ async aztec_avm_emitNullifier(foreignNullifier: ForeignCallSingle) {
907
1199
  const nullifier = fromSingle(foreignNullifier);
908
1200
 
909
- await this.handlerAsAvm().avmOpcodeEmitNullifier(nullifier);
1201
+ await this.handlerAsAvm().emitNullifier(nullifier);
910
1202
 
911
1203
  return toForeignCallResult([]);
912
1204
  }
913
1205
 
914
- async avmOpcodeEmitNoteHash(foreignNoteHash: ForeignCallSingle) {
1206
+ // eslint-disable-next-line camelcase
1207
+ async aztec_avm_emitNoteHash(foreignNoteHash: ForeignCallSingle) {
915
1208
  const noteHash = fromSingle(foreignNoteHash);
916
1209
 
917
- await this.handlerAsAvm().avmOpcodeEmitNoteHash(noteHash);
1210
+ await this.handlerAsAvm().emitNoteHash(noteHash);
918
1211
 
919
1212
  return toForeignCallResult([]);
920
1213
  }
921
1214
 
922
- async avmOpcodeNullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
1215
+ // eslint-disable-next-line camelcase
1216
+ async aztec_avm_nullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
923
1217
  const siloedNullifier = fromSingle(foreignSiloedNullifier);
924
1218
 
925
- const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(siloedNullifier);
1219
+ const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
926
1220
 
927
1221
  return toForeignCallResult([toSingle(new Fr(exists))]);
928
1222
  }
929
1223
 
930
- async avmOpcodeAddress() {
931
- const contractAddress = await this.handlerAsAvm().avmOpcodeAddress();
1224
+ // eslint-disable-next-line camelcase
1225
+ async aztec_avm_address() {
1226
+ const contractAddress = await this.handlerAsAvm().address();
932
1227
 
933
1228
  return toForeignCallResult([toSingle(contractAddress.toField())]);
934
1229
  }
935
1230
 
936
- async avmOpcodeBlockNumber() {
937
- const blockNumber = await this.handlerAsAvm().avmOpcodeBlockNumber();
1231
+ // eslint-disable-next-line camelcase
1232
+ async aztec_avm_blockNumber() {
1233
+ const blockNumber = await this.handlerAsAvm().blockNumber();
938
1234
 
939
1235
  return toForeignCallResult([toSingle(new Fr(blockNumber))]);
940
1236
  }
941
1237
 
942
- async avmOpcodeTimestamp() {
943
- const timestamp = await this.handlerAsAvm().avmOpcodeTimestamp();
1238
+ // eslint-disable-next-line camelcase
1239
+ async aztec_avm_timestamp() {
1240
+ const timestamp = await this.handlerAsAvm().timestamp();
944
1241
 
945
1242
  return toForeignCallResult([toSingle(new Fr(timestamp))]);
946
1243
  }
947
1244
 
948
- async avmOpcodeIsStaticCall() {
949
- const isStaticCall = await this.handlerAsAvm().avmOpcodeIsStaticCall();
1245
+ // eslint-disable-next-line camelcase
1246
+ async aztec_avm_isStaticCall() {
1247
+ const isStaticCall = await this.handlerAsAvm().isStaticCall();
950
1248
 
951
1249
  return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
952
1250
  }
953
1251
 
954
- async avmOpcodeChainId() {
955
- const chainId = await this.handlerAsAvm().avmOpcodeChainId();
1252
+ // eslint-disable-next-line camelcase
1253
+ async aztec_avm_chainId() {
1254
+ const chainId = await this.handlerAsAvm().chainId();
956
1255
 
957
1256
  return toForeignCallResult([toSingle(chainId)]);
958
1257
  }
959
1258
 
960
- async avmOpcodeVersion() {
961
- const version = await this.handlerAsAvm().avmOpcodeVersion();
1259
+ // eslint-disable-next-line camelcase
1260
+ async aztec_avm_version() {
1261
+ const version = await this.handlerAsAvm().version();
962
1262
 
963
1263
  return toForeignCallResult([toSingle(version)]);
964
1264
  }
965
1265
 
966
- avmOpcodeReturndataSize() {
1266
+ // eslint-disable-next-line camelcase
1267
+ aztec_avm_returndataSize() {
967
1268
  throw new Error(
968
1269
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
969
1270
  );
970
1271
  }
971
1272
 
972
- avmOpcodeReturndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
1273
+ // eslint-disable-next-line camelcase
1274
+ aztec_avm_returndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
973
1275
  throw new Error(
974
1276
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
975
1277
  );
976
1278
  }
977
1279
 
978
- avmOpcodeCall(
1280
+ // eslint-disable-next-line camelcase
1281
+ aztec_avm_call(
979
1282
  _foreignL2Gas: ForeignCallSingle,
980
1283
  _foreignDaGas: ForeignCallSingle,
981
1284
  _foreignAddress: ForeignCallSingle,
@@ -987,7 +1290,8 @@ export class RPCTranslator {
987
1290
  );
988
1291
  }
989
1292
 
990
- avmOpcodeStaticCall(
1293
+ // eslint-disable-next-line camelcase
1294
+ aztec_avm_staticCall(
991
1295
  _foreignL2Gas: ForeignCallSingle,
992
1296
  _foreignDaGas: ForeignCallSingle,
993
1297
  _foreignAddress: ForeignCallSingle,
@@ -999,13 +1303,15 @@ export class RPCTranslator {
999
1303
  );
1000
1304
  }
1001
1305
 
1002
- avmOpcodeSuccessCopy() {
1306
+ // eslint-disable-next-line camelcase
1307
+ aztec_avm_successCopy() {
1003
1308
  throw new Error(
1004
1309
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
1005
1310
  );
1006
1311
  }
1007
1312
 
1008
- async txePrivateCallNewFlow(
1313
+ // eslint-disable-next-line camelcase
1314
+ async aztec_txe_privateCallNewFlow(
1009
1315
  foreignFrom: ForeignCallSingle,
1010
1316
  foreignTargetContractAddress: ForeignCallSingle,
1011
1317
  foreignFunctionSelector: ForeignCallSingle,
@@ -1020,19 +1326,43 @@ export class RPCTranslator {
1020
1326
  const argsHash = fromSingle(foreignArgsHash);
1021
1327
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
1022
1328
 
1023
- const returnValues = await this.handlerAsTxe().txePrivateCallNewFlow(
1024
- from,
1025
- targetContractAddress,
1026
- functionSelector,
1027
- args,
1028
- argsHash,
1029
- isStaticCall,
1030
- );
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
+ });
1031
1360
 
1032
1361
  return toForeignCallResult([toArray(returnValues)]);
1033
1362
  }
1034
1363
 
1035
- async txeSimulateUtilityFunction(
1364
+ // eslint-disable-next-line camelcase
1365
+ async aztec_txe_executeUtilityFunction(
1036
1366
  foreignTargetContractAddress: ForeignCallSingle,
1037
1367
  foreignFunctionSelector: ForeignCallSingle,
1038
1368
  foreignArgs: ForeignCallArray,
@@ -1041,16 +1371,25 @@ export class RPCTranslator {
1041
1371
  const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
1042
1372
  const args = fromArray(foreignArgs);
1043
1373
 
1044
- const returnValues = await this.handlerAsTxe().txeSimulateUtilityFunction(
1045
- targetContractAddress,
1046
- functionSelector,
1047
- args,
1048
- );
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
+ });
1049
1387
 
1050
1388
  return toForeignCallResult([toArray(returnValues)]);
1051
1389
  }
1052
1390
 
1053
- async txePublicCallNewFlow(
1391
+ // eslint-disable-next-line camelcase
1392
+ async aztec_txe_publicCallNewFlow(
1054
1393
  foreignFrom: ForeignCallSingle,
1055
1394
  foreignAddress: ForeignCallSingle,
1056
1395
  foreignCalldata: ForeignCallArray,
@@ -1061,13 +1400,26 @@ export class RPCTranslator {
1061
1400
  const calldata = fromArray(foreignCalldata);
1062
1401
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
1063
1402
 
1064
- 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
+ });
1065
1416
 
1066
1417
  return toForeignCallResult([toArray(returnValues)]);
1067
1418
  }
1068
1419
 
1069
- async privateGetSenderForTags() {
1070
- const sender = await this.handlerAsPrivate().privateGetSenderForTags();
1420
+ // eslint-disable-next-line camelcase
1421
+ async aztec_prv_getSenderForTags() {
1422
+ const sender = await this.handlerAsPrivate().getSenderForTags();
1071
1423
 
1072
1424
  // Return a Noir Option struct with `some` and `value` fields
1073
1425
  if (sender === undefined) {
@@ -1079,19 +1431,21 @@ export class RPCTranslator {
1079
1431
  }
1080
1432
  }
1081
1433
 
1082
- async privateSetSenderForTags(foreignSenderForTags: ForeignCallSingle) {
1434
+ // eslint-disable-next-line camelcase
1435
+ async aztec_prv_setSenderForTags(foreignSenderForTags: ForeignCallSingle) {
1083
1436
  const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
1084
1437
 
1085
- await this.handlerAsPrivate().privateSetSenderForTags(senderForTags);
1438
+ await this.handlerAsPrivate().setSenderForTags(senderForTags);
1086
1439
 
1087
1440
  return toForeignCallResult([]);
1088
1441
  }
1089
1442
 
1090
- async privateGetNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
1443
+ // eslint-disable-next-line camelcase
1444
+ async aztec_prv_getNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
1091
1445
  const sender = AztecAddress.fromField(fromSingle(foreignSender));
1092
1446
  const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
1093
1447
 
1094
- const nextAppTag = await this.handlerAsPrivate().privateGetNextAppTagAsSender(sender, recipient);
1448
+ const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
1095
1449
 
1096
1450
  return toForeignCallResult([toSingle(nextAppTag.value)]);
1097
1451
  }