@aztec/txe 0.0.1-commit.e558bd1c → 0.0.1-commit.e5a3663dd

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