@aztec/txe 0.0.1-commit.dbf9cec → 0.0.1-commit.ddcf04837

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