@aztec/txe 0.0.1-commit.e3c1de76 → 0.0.1-commit.e588bc7e5

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