@aztec/txe 0.0.1-commit.3469e52 → 0.0.1-commit.35158ae7e

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 (58) 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 +15 -15
  7. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  8. package/dest/oracle/txe_oracle_public_context.js +16 -16
  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 +130 -54
  12. package/dest/rpc_translator.d.ts +92 -81
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +315 -169
  15. package/dest/state_machine/archiver.d.ts +4 -4
  16. package/dest/state_machine/archiver.d.ts.map +1 -1
  17. package/dest/state_machine/archiver.js +8 -9
  18. package/dest/state_machine/dummy_p2p_client.d.ts +16 -12
  19. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  20. package/dest/state_machine/dummy_p2p_client.js +28 -16
  21. package/dest/state_machine/index.d.ts +9 -7
  22. package/dest/state_machine/index.d.ts.map +1 -1
  23. package/dest/state_machine/index.js +35 -17
  24. package/dest/state_machine/mock_epoch_cache.d.ts +22 -4
  25. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  26. package/dest/state_machine/mock_epoch_cache.js +38 -3
  27. package/dest/state_machine/synchronizer.d.ts +6 -6
  28. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  29. package/dest/state_machine/synchronizer.js +3 -3
  30. package/dest/txe_session.d.ts +10 -6
  31. package/dest/txe_session.d.ts.map +1 -1
  32. package/dest/txe_session.js +97 -28
  33. package/dest/util/encoding.d.ts +69 -1
  34. package/dest/util/encoding.d.ts.map +1 -1
  35. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  36. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  37. package/dest/util/txe_public_contract_data_source.js +6 -25
  38. package/dest/utils/block_creation.d.ts +5 -5
  39. package/dest/utils/block_creation.d.ts.map +1 -1
  40. package/dest/utils/block_creation.js +7 -5
  41. package/package.json +15 -15
  42. package/src/index.ts +89 -52
  43. package/src/oracle/interfaces.ts +32 -31
  44. package/src/oracle/txe_oracle_public_context.ts +18 -20
  45. package/src/oracle/txe_oracle_top_level_context.ts +160 -102
  46. package/src/rpc_translator.ts +349 -185
  47. package/src/state_machine/archiver.ts +9 -11
  48. package/src/state_machine/dummy_p2p_client.ts +40 -22
  49. package/src/state_machine/index.ts +54 -19
  50. package/src/state_machine/mock_epoch_cache.ts +49 -4
  51. package/src/state_machine/synchronizer.ts +5 -5
  52. package/src/txe_session.ts +115 -86
  53. package/src/util/txe_public_contract_data_source.ts +10 -38
  54. package/src/utils/block_creation.ts +8 -6
  55. package/dest/util/txe_contract_store.d.ts +0 -12
  56. package/dest/util/txe_contract_store.d.ts.map +0 -1
  57. package/dest/util/txe_contract_store.js +0 -22
  58. package/src/util/txe_contract_store.ts +0 -36
@@ -10,8 +10,7 @@ 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 { L2BlockHash } from '@aztec/stdlib/block';
14
- import { MerkleTreeId } from '@aztec/stdlib/trees';
13
+ import { BlockHash } from '@aztec/stdlib/block';
15
14
 
16
15
  import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
17
16
  import type { TXESessionStateHandler } from './txe_session.js';
@@ -31,7 +30,7 @@ import {
31
30
  toSingle,
32
31
  } from './util/encoding.js';
33
32
 
34
- 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
35
34
  const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
36
35
 
37
36
  export class UnavailableOracleError extends Error {
@@ -105,13 +104,15 @@ export class RPCTranslator {
105
104
 
106
105
  // TXE session state transition functions - these get handled by the state handler
107
106
 
108
- async txeSetTopLevelTXEContext() {
107
+ // eslint-disable-next-line camelcase
108
+ async aztec_txe_setTopLevelTXEContext() {
109
109
  await this.stateHandler.enterTopLevelState();
110
110
 
111
111
  return toForeignCallResult([]);
112
112
  }
113
113
 
114
- async txeSetPrivateTXEContext(
114
+ // eslint-disable-next-line camelcase
115
+ async aztec_txe_setPrivateTXEContext(
115
116
  foreignContractAddressIsSome: ForeignCallSingle,
116
117
  foreignContractAddressValue: ForeignCallSingle,
117
118
  foreignAnchorBlockNumberIsSome: ForeignCallSingle,
@@ -130,7 +131,8 @@ export class RPCTranslator {
130
131
  return toForeignCallResult(privateContextInputs.toFields().map(toSingle));
131
132
  }
132
133
 
133
- async txeSetPublicTXEContext(
134
+ // eslint-disable-next-line camelcase
135
+ async aztec_txe_setPublicTXEContext(
134
136
  foreignContractAddressIsSome: ForeignCallSingle,
135
137
  foreignContractAddressValue: ForeignCallSingle,
136
138
  ) {
@@ -143,7 +145,8 @@ export class RPCTranslator {
143
145
  return toForeignCallResult([]);
144
146
  }
145
147
 
146
- async txeSetUtilityTXEContext(
148
+ // eslint-disable-next-line camelcase
149
+ async aztec_txe_setUtilityTXEContext(
147
150
  foreignContractAddressIsSome: ForeignCallSingle,
148
151
  foreignContractAddressValue: ForeignCallSingle,
149
152
  ) {
@@ -160,44 +163,54 @@ export class RPCTranslator {
160
163
 
161
164
  // TXE-specific oracles
162
165
 
163
- txeGetDefaultAddress() {
164
- const defaultAddress = this.handlerAsTxe().txeGetDefaultAddress();
166
+ // eslint-disable-next-line camelcase
167
+ aztec_txe_getDefaultAddress() {
168
+ const defaultAddress = this.handlerAsTxe().getDefaultAddress();
165
169
 
166
170
  return toForeignCallResult([toSingle(defaultAddress)]);
167
171
  }
168
172
 
169
- async txeGetNextBlockNumber() {
170
- const nextBlockNumber = await this.handlerAsTxe().txeGetNextBlockNumber();
173
+ // eslint-disable-next-line camelcase
174
+ async aztec_txe_getNextBlockNumber() {
175
+ const nextBlockNumber = await this.handlerAsTxe().getNextBlockNumber();
171
176
 
172
177
  return toForeignCallResult([toSingle(nextBlockNumber)]);
173
178
  }
174
179
 
175
- async txeGetNextBlockTimestamp() {
176
- const nextBlockTimestamp = await this.handlerAsTxe().txeGetNextBlockTimestamp();
180
+ // eslint-disable-next-line camelcase
181
+ async aztec_txe_getNextBlockTimestamp() {
182
+ const nextBlockTimestamp = await this.handlerAsTxe().getNextBlockTimestamp();
177
183
 
178
184
  return toForeignCallResult([toSingle(nextBlockTimestamp)]);
179
185
  }
180
186
 
181
- async txeAdvanceBlocksBy(foreignBlocks: ForeignCallSingle) {
187
+ // eslint-disable-next-line camelcase
188
+ async aztec_txe_advanceBlocksBy(foreignBlocks: ForeignCallSingle) {
182
189
  const blocks = fromSingle(foreignBlocks).toNumber();
183
190
 
184
- await this.handlerAsTxe().txeAdvanceBlocksBy(blocks);
191
+ await this.handlerAsTxe().advanceBlocksBy(blocks);
185
192
 
186
193
  return toForeignCallResult([]);
187
194
  }
188
195
 
189
- txeAdvanceTimestampBy(foreignDuration: ForeignCallSingle) {
196
+ // eslint-disable-next-line camelcase
197
+ aztec_txe_advanceTimestampBy(foreignDuration: ForeignCallSingle) {
190
198
  const duration = fromSingle(foreignDuration).toBigInt();
191
199
 
192
- this.handlerAsTxe().txeAdvanceTimestampBy(duration);
200
+ this.handlerAsTxe().advanceTimestampBy(duration);
193
201
 
194
202
  return toForeignCallResult([]);
195
203
  }
196
204
 
197
- 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
+ ) {
198
211
  const secret = fromSingle(foreignSecret);
199
212
 
200
- await this.handlerAsTxe().txeDeploy(artifact, instance, secret);
213
+ await this.handlerAsTxe().deploy(artifact, instance, secret);
201
214
 
202
215
  return toForeignCallResult([
203
216
  toArray([
@@ -210,10 +223,11 @@ export class RPCTranslator {
210
223
  ]);
211
224
  }
212
225
 
213
- async txeCreateAccount(foreignSecret: ForeignCallSingle) {
226
+ // eslint-disable-next-line camelcase
227
+ async aztec_txe_createAccount(foreignSecret: ForeignCallSingle) {
214
228
  const secret = fromSingle(foreignSecret);
215
229
 
216
- const completeAddress = await this.handlerAsTxe().txeCreateAccount(secret);
230
+ const completeAddress = await this.handlerAsTxe().createAccount(secret);
217
231
 
218
232
  return toForeignCallResult([
219
233
  toSingle(completeAddress.address),
@@ -221,14 +235,15 @@ export class RPCTranslator {
221
235
  ]);
222
236
  }
223
237
 
224
- async txeAddAccount(
238
+ // eslint-disable-next-line camelcase
239
+ async aztec_txe_addAccount(
225
240
  artifact: ContractArtifact,
226
241
  instance: ContractInstanceWithAddress,
227
242
  foreignSecret: ForeignCallSingle,
228
243
  ) {
229
244
  const secret = fromSingle(foreignSecret);
230
245
 
231
- const completeAddress = await this.handlerAsTxe().txeAddAccount(artifact, instance, secret);
246
+ const completeAddress = await this.handlerAsTxe().addAccount(artifact, instance, secret);
232
247
 
233
248
  return toForeignCallResult([
234
249
  toSingle(completeAddress.address),
@@ -236,39 +251,44 @@ export class RPCTranslator {
236
251
  ]);
237
252
  }
238
253
 
239
- async txeAddAuthWitness(foreignAddress: ForeignCallSingle, foreignMessageHash: ForeignCallSingle) {
254
+ // eslint-disable-next-line camelcase
255
+ async aztec_txe_addAuthWitness(foreignAddress: ForeignCallSingle, foreignMessageHash: ForeignCallSingle) {
240
256
  const address = addressFromSingle(foreignAddress);
241
257
  const messageHash = fromSingle(foreignMessageHash);
242
258
 
243
- await this.handlerAsTxe().txeAddAuthWitness(address, messageHash);
259
+ await this.handlerAsTxe().addAuthWitness(address, messageHash);
244
260
 
245
261
  return toForeignCallResult([]);
246
262
  }
247
263
 
248
264
  // PXE oracles
249
265
 
250
- utilityAssertCompatibleOracleVersion(foreignVersion: ForeignCallSingle) {
266
+ // eslint-disable-next-line camelcase
267
+ aztec_utl_assertCompatibleOracleVersion(foreignVersion: ForeignCallSingle) {
251
268
  const version = fromSingle(foreignVersion).toNumber();
252
269
 
253
- this.handlerAsMisc().utilityAssertCompatibleOracleVersion(version);
270
+ this.handlerAsMisc().assertCompatibleOracleVersion(version);
254
271
 
255
272
  return toForeignCallResult([]);
256
273
  }
257
274
 
258
- utilityGetRandomField() {
259
- const randomField = this.handlerAsMisc().utilityGetRandomField();
275
+ // eslint-disable-next-line camelcase
276
+ aztec_utl_getRandomField() {
277
+ const randomField = this.handlerAsMisc().getRandomField();
260
278
 
261
279
  return toForeignCallResult([toSingle(randomField)]);
262
280
  }
263
281
 
264
- async txeGetLastBlockTimestamp() {
265
- const timestamp = await this.handlerAsTxe().txeGetLastBlockTimestamp();
282
+ // eslint-disable-next-line camelcase
283
+ async aztec_txe_getLastBlockTimestamp() {
284
+ const timestamp = await this.handlerAsTxe().getLastBlockTimestamp();
266
285
 
267
286
  return toForeignCallResult([toSingle(new Fr(timestamp))]);
268
287
  }
269
288
 
270
- async txeGetLastTxEffects() {
271
- 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();
272
292
 
273
293
  return toForeignCallResult([
274
294
  toSingle(txHash.hash),
@@ -277,7 +297,8 @@ export class RPCTranslator {
277
297
  ]);
278
298
  }
279
299
 
280
- async txeGetPrivateEvents(
300
+ // eslint-disable-next-line camelcase
301
+ async aztec_txe_getPrivateEvents(
281
302
  foreignSelector: ForeignCallSingle,
282
303
  foreignContractAddress: ForeignCallSingle,
283
304
  foreignScope: ForeignCallSingle,
@@ -286,7 +307,14 @@ export class RPCTranslator {
286
307
  const contractAddress = addressFromSingle(foreignContractAddress);
287
308
  const scope = addressFromSingle(foreignScope);
288
309
 
289
- 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);
290
318
 
291
319
  if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
292
320
  throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
@@ -310,26 +338,29 @@ export class RPCTranslator {
310
338
  return toForeignCallResult([toArray(rawArrayStorage), toArray(eventLengths), toSingle(queryLength)]);
311
339
  }
312
340
 
313
- privateStoreInExecutionCache(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
341
+ // eslint-disable-next-line camelcase
342
+ aztec_prv_storeInExecutionCache(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
314
343
  const values = fromArray(foreignValues);
315
344
  const hash = fromSingle(foreignHash);
316
345
 
317
- this.handlerAsPrivate().privateStoreInExecutionCache(values, hash);
346
+ this.handlerAsPrivate().storeInExecutionCache(values, hash);
318
347
 
319
348
  return toForeignCallResult([]);
320
349
  }
321
350
 
322
- async privateLoadFromExecutionCache(foreignHash: ForeignCallSingle) {
351
+ // eslint-disable-next-line camelcase
352
+ async aztec_prv_loadFromExecutionCache(foreignHash: ForeignCallSingle) {
323
353
  const hash = fromSingle(foreignHash);
324
354
 
325
- const returns = await this.handlerAsPrivate().privateLoadFromExecutionCache(hash);
355
+ const returns = await this.handlerAsPrivate().loadFromExecutionCache(hash);
326
356
 
327
357
  return toForeignCallResult([toArray(returns)]);
328
358
  }
329
359
 
330
360
  // When the argument is a slice, noir automatically adds a length field to oracle call.
331
361
  // When the argument is an array, we add the field length manually to the signature.
332
- utilityDebugLog(
362
+ // eslint-disable-next-line camelcase
363
+ async aztec_utl_log(
333
364
  foreignLevel: ForeignCallSingle,
334
365
  foreignMessage: ForeignCallArray,
335
366
  _foreignLength: ForeignCallSingle,
@@ -341,23 +372,24 @@ export class RPCTranslator {
341
372
  .join('');
342
373
  const fields = fromArray(foreignFields);
343
374
 
344
- this.handlerAsMisc().utilityDebugLog(level, message, fields);
375
+ await this.handlerAsMisc().log(level, message, fields);
345
376
 
346
377
  return toForeignCallResult([]);
347
378
  }
348
379
 
349
- async utilityStorageRead(
380
+ // eslint-disable-next-line camelcase
381
+ async aztec_utl_storageRead(
350
382
  foreignBlockHash: ForeignCallSingle,
351
383
  foreignContractAddress: ForeignCallSingle,
352
384
  foreignStartStorageSlot: ForeignCallSingle,
353
385
  foreignNumberOfElements: ForeignCallSingle,
354
386
  ) {
355
- const blockHash = L2BlockHash.fromString(foreignBlockHash);
387
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
356
388
  const contractAddress = addressFromSingle(foreignContractAddress);
357
389
  const startStorageSlot = fromSingle(foreignStartStorageSlot);
358
390
  const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
359
391
 
360
- const values = await this.handlerAsUtility().utilityStorageRead(
392
+ const values = await this.handlerAsUtility().storageRead(
361
393
  blockHash,
362
394
  contractAddress,
363
395
  startStorageSlot,
@@ -367,11 +399,12 @@ export class RPCTranslator {
367
399
  return toForeignCallResult([toArray(values)]);
368
400
  }
369
401
 
370
- async utilityGetPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
371
- const blockHash = L2BlockHash.fromString(foreignBlockHash);
402
+ // eslint-disable-next-line camelcase
403
+ async aztec_utl_getPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
404
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
372
405
  const leafSlot = fromSingle(foreignLeafSlot);
373
406
 
374
- const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockHash, leafSlot);
407
+ const witness = await this.handlerAsUtility().getPublicDataWitness(blockHash, leafSlot);
375
408
 
376
409
  if (!witness) {
377
410
  throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
@@ -379,7 +412,8 @@ export class RPCTranslator {
379
412
  return toForeignCallResult(witness.toNoirRepresentation());
380
413
  }
381
414
 
382
- async utilityGetNotes(
415
+ // eslint-disable-next-line camelcase
416
+ async aztec_utl_getNotes(
383
417
  foreignOwnerIsSome: ForeignCallSingle,
384
418
  foreignOwnerValue: ForeignCallSingle,
385
419
  foreignStorageSlot: ForeignCallSingle,
@@ -420,7 +454,7 @@ export class RPCTranslator {
420
454
  const maxNotes = fromSingle(foreignMaxNotes).toNumber();
421
455
  const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
422
456
 
423
- const noteDatas = await this.handlerAsUtility().utilityGetNotes(
457
+ const noteDatas = await this.handlerAsUtility().getNotes(
424
458
  owner,
425
459
  storageSlot,
426
460
  numSelects,
@@ -461,7 +495,8 @@ export class RPCTranslator {
461
495
  );
462
496
  }
463
497
 
464
- privateNotifyCreatedNote(
498
+ // eslint-disable-next-line camelcase
499
+ aztec_prv_notifyCreatedNote(
465
500
  foreignOwner: ForeignCallSingle,
466
501
  foreignStorageSlot: ForeignCallSingle,
467
502
  foreignRandomness: ForeignCallSingle,
@@ -478,20 +513,13 @@ export class RPCTranslator {
478
513
  const noteHash = fromSingle(foreignNoteHash);
479
514
  const counter = fromSingle(foreignCounter).toNumber();
480
515
 
481
- this.handlerAsPrivate().privateNotifyCreatedNote(
482
- owner,
483
- storageSlot,
484
- randomness,
485
- noteTypeId,
486
- note,
487
- noteHash,
488
- counter,
489
- );
516
+ this.handlerAsPrivate().notifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
490
517
 
491
518
  return toForeignCallResult([]);
492
519
  }
493
520
 
494
- async privateNotifyNullifiedNote(
521
+ // eslint-disable-next-line camelcase
522
+ async aztec_prv_notifyNullifiedNote(
495
523
  foreignInnerNullifier: ForeignCallSingle,
496
524
  foreignNoteHash: ForeignCallSingle,
497
525
  foreignCounter: ForeignCallSingle,
@@ -500,31 +528,47 @@ export class RPCTranslator {
500
528
  const noteHash = fromSingle(foreignNoteHash);
501
529
  const counter = fromSingle(foreignCounter).toNumber();
502
530
 
503
- await this.handlerAsPrivate().privateNotifyNullifiedNote(innerNullifier, noteHash, counter);
531
+ await this.handlerAsPrivate().notifyNullifiedNote(innerNullifier, noteHash, counter);
504
532
 
505
533
  return toForeignCallResult([]);
506
534
  }
507
535
 
508
- async privateNotifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
536
+ // eslint-disable-next-line camelcase
537
+ async aztec_prv_notifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
509
538
  const innerNullifier = fromSingle(foreignInnerNullifier);
510
539
 
511
- await this.handlerAsPrivate().privateNotifyCreatedNullifier(innerNullifier);
540
+ await this.handlerAsPrivate().notifyCreatedNullifier(innerNullifier);
512
541
 
513
542
  return toForeignCallResult([]);
514
543
  }
515
544
 
516
- async utilityCheckNullifierExists(foreignInnerNullifier: ForeignCallSingle) {
545
+ // eslint-disable-next-line camelcase
546
+ async aztec_prv_isNullifierPending(
547
+ foreignInnerNullifier: ForeignCallSingle,
548
+ foreignContractAddress: ForeignCallSingle,
549
+ ) {
517
550
  const innerNullifier = fromSingle(foreignInnerNullifier);
551
+ const contractAddress = addressFromSingle(foreignContractAddress);
518
552
 
519
- const exists = await this.handlerAsUtility().utilityCheckNullifierExists(innerNullifier);
553
+ const isPending = await this.handlerAsPrivate().isNullifierPending(innerNullifier, contractAddress);
554
+
555
+ return toForeignCallResult([toSingle(new Fr(isPending))]);
556
+ }
557
+
558
+ // eslint-disable-next-line camelcase
559
+ async aztec_utl_checkNullifierExists(foreignInnerNullifier: ForeignCallSingle) {
560
+ const innerNullifier = fromSingle(foreignInnerNullifier);
561
+
562
+ const exists = await this.handlerAsUtility().checkNullifierExists(innerNullifier);
520
563
 
521
564
  return toForeignCallResult([toSingle(new Fr(exists))]);
522
565
  }
523
566
 
524
- async utilityGetContractInstance(foreignAddress: ForeignCallSingle) {
567
+ // eslint-disable-next-line camelcase
568
+ async aztec_utl_getContractInstance(foreignAddress: ForeignCallSingle) {
525
569
  const address = addressFromSingle(foreignAddress);
526
570
 
527
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
571
+ const instance = await this.handlerAsUtility().getContractInstance(address);
528
572
 
529
573
  return toForeignCallResult(
530
574
  [
@@ -537,23 +581,37 @@ export class RPCTranslator {
537
581
  );
538
582
  }
539
583
 
540
- async utilityGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
584
+ // eslint-disable-next-line camelcase
585
+ async aztec_utl_tryGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
541
586
  const address = addressFromSingle(foreignAddress);
542
587
 
543
- const { publicKeys, partialAddress } = await this.handlerAsUtility().utilityGetPublicKeysAndPartialAddress(address);
588
+ const result = await this.handlerAsUtility().tryGetPublicKeysAndPartialAddress(address);
544
589
 
545
- 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
+ }
546
602
  }
547
603
 
548
- async utilityGetKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
604
+ // eslint-disable-next-line camelcase
605
+ async aztec_utl_getKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
549
606
  const pkMHash = fromSingle(foreignPkMHash);
550
607
 
551
- const keyValidationRequest = await this.handlerAsUtility().utilityGetKeyValidationRequest(pkMHash);
608
+ const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
552
609
 
553
610
  return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
554
611
  }
555
612
 
556
- privateCallPrivateFunction(
613
+ // eslint-disable-next-line camelcase
614
+ aztec_prv_callPrivateFunction(
557
615
  _foreignTargetContractAddress: ForeignCallSingle,
558
616
  _foreignFunctionSelector: ForeignCallSingle,
559
617
  _foreignArgsHash: ForeignCallSingle,
@@ -565,11 +623,15 @@ export class RPCTranslator {
565
623
  );
566
624
  }
567
625
 
568
- async utilityGetNullifierMembershipWitness(foreignBlockHash: ForeignCallSingle, foreignNullifier: ForeignCallSingle) {
569
- const blockHash = L2BlockHash.fromString(foreignBlockHash);
626
+ // eslint-disable-next-line camelcase
627
+ async aztec_utl_getNullifierMembershipWitness(
628
+ foreignBlockHash: ForeignCallSingle,
629
+ foreignNullifier: ForeignCallSingle,
630
+ ) {
631
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
570
632
  const nullifier = fromSingle(foreignNullifier);
571
633
 
572
- const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
634
+ const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
573
635
 
574
636
  if (!witness) {
575
637
  throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
@@ -577,10 +639,11 @@ export class RPCTranslator {
577
639
  return toForeignCallResult(witness.toNoirRepresentation());
578
640
  }
579
641
 
580
- async utilityGetAuthWitness(foreignMessageHash: ForeignCallSingle) {
642
+ // eslint-disable-next-line camelcase
643
+ async aztec_utl_getAuthWitness(foreignMessageHash: ForeignCallSingle) {
581
644
  const messageHash = fromSingle(foreignMessageHash);
582
645
 
583
- const authWitness = await this.handlerAsUtility().utilityGetAuthWitness(messageHash);
646
+ const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
584
647
 
585
648
  if (!authWitness) {
586
649
  throw new Error(`Auth witness not found for message hash ${messageHash}.`);
@@ -588,44 +651,35 @@ export class RPCTranslator {
588
651
  return toForeignCallResult([toArray(authWitness)]);
589
652
  }
590
653
 
591
- public privateNotifyEnqueuedPublicFunctionCall(
592
- _foreignTargetContractAddress: ForeignCallSingle,
593
- _foreignCalldataHash: ForeignCallSingle,
594
- _foreignSideEffectCounter: ForeignCallSingle,
595
- _foreignIsStaticCall: ForeignCallSingle,
596
- ) {
654
+ // eslint-disable-next-line camelcase
655
+ public aztec_prv_validatePublicCalldata(_foreignCalldataHash: ForeignCallSingle) {
597
656
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
598
657
  }
599
658
 
600
- public privateNotifySetPublicTeardownFunctionCall(
601
- _foreignTargetContractAddress: ForeignCallSingle,
602
- _foreignCalldataHash: ForeignCallSingle,
603
- _foreignSideEffectCounter: ForeignCallSingle,
604
- _foreignIsStaticCall: ForeignCallSingle,
605
- ) {
659
+ // eslint-disable-next-line camelcase
660
+ public aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
606
661
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
607
662
  }
608
663
 
609
- public privateNotifySetMinRevertibleSideEffectCounter(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
610
- throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
611
- }
612
-
613
- public async privateIsSideEffectCounterRevertible(foreignSideEffectCounter: ForeignCallSingle) {
664
+ // eslint-disable-next-line camelcase
665
+ public async aztec_prv_inRevertiblePhase(foreignSideEffectCounter: ForeignCallSingle) {
614
666
  const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
615
- const isRevertible = await this.handlerAsPrivate().privateIsSideEffectCounterRevertible(sideEffectCounter);
667
+ const isRevertible = await this.handlerAsPrivate().inRevertiblePhase(sideEffectCounter);
616
668
  return toForeignCallResult([toSingle(new Fr(isRevertible))]);
617
669
  }
618
670
 
619
- utilityGetUtilityContext() {
620
- const context = this.handlerAsUtility().utilityGetUtilityContext();
671
+ // eslint-disable-next-line camelcase
672
+ aztec_utl_getUtilityContext() {
673
+ const context = this.handlerAsUtility().getUtilityContext();
621
674
 
622
675
  return toForeignCallResult(context.toNoirRepresentation());
623
676
  }
624
677
 
625
- async utilityGetBlockHeader(foreignBlockNumber: ForeignCallSingle) {
678
+ // eslint-disable-next-line camelcase
679
+ async aztec_utl_getBlockHeader(foreignBlockNumber: ForeignCallSingle) {
626
680
  const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
627
681
 
628
- const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
682
+ const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
629
683
 
630
684
  if (!header) {
631
685
  throw new Error(`Block header not found for block ${blockNumber}.`);
@@ -633,33 +687,49 @@ export class RPCTranslator {
633
687
  return toForeignCallResult(header.toFields().map(toSingle));
634
688
  }
635
689
 
636
- async utilityGetMembershipWitness(
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);
697
+
698
+ const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
699
+
700
+ if (!witness) {
701
+ throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
702
+ }
703
+ return toForeignCallResult(witness.toNoirRepresentation());
704
+ }
705
+
706
+ // eslint-disable-next-line camelcase
707
+ async aztec_utl_getBlockHashMembershipWitness(
708
+ foreignAnchorBlockHash: ForeignCallSingle,
637
709
  foreignBlockHash: ForeignCallSingle,
638
- foreignTreeId: ForeignCallSingle,
639
- foreignLeafValue: ForeignCallSingle,
640
710
  ) {
641
- const blockHash = L2BlockHash.fromString(foreignBlockHash);
642
- const treeId = fromSingle(foreignTreeId).toNumber();
643
- const leafValue = fromSingle(foreignLeafValue);
711
+ const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
712
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
644
713
 
645
- const witness = await this.handlerAsUtility().utilityGetMembershipWitness(blockHash, treeId, leafValue);
714
+ const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
646
715
 
647
716
  if (!witness) {
648
717
  throw new Error(
649
- `Membership witness in tree ${MerkleTreeId[treeId]} not found for value ${leafValue} at block ${blockHash}.`,
718
+ `Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`,
650
719
  );
651
720
  }
652
- return toForeignCallResult([toSingle(witness[0]), toArray(witness.slice(1))]);
721
+ return toForeignCallResult(witness.toNoirRepresentation());
653
722
  }
654
723
 
655
- async utilityGetLowNullifierMembershipWitness(
724
+ // eslint-disable-next-line camelcase
725
+ async aztec_utl_getLowNullifierMembershipWitness(
656
726
  foreignBlockHash: ForeignCallSingle,
657
727
  foreignNullifier: ForeignCallSingle,
658
728
  ) {
659
- const blockHash = L2BlockHash.fromString(foreignBlockHash);
729
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
660
730
  const nullifier = fromSingle(foreignNullifier);
661
731
 
662
- const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
732
+ const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
663
733
 
664
734
  if (!witness) {
665
735
  throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
@@ -667,33 +737,42 @@ export class RPCTranslator {
667
737
  return toForeignCallResult(witness.toNoirRepresentation());
668
738
  }
669
739
 
670
- async utilityFetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
740
+ // eslint-disable-next-line camelcase
741
+ async aztec_utl_fetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
671
742
  const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
672
743
 
673
- await this.handlerAsUtility().utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
744
+ await this.handlerAsUtility().fetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
674
745
 
675
746
  return toForeignCallResult([]);
676
747
  }
677
748
 
678
- public async utilityValidateEnqueuedNotesAndEvents(
749
+ // eslint-disable-next-line camelcase
750
+ public async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(
679
751
  foreignContractAddress: ForeignCallSingle,
680
752
  foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
681
753
  foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
754
+ foreignMaxNotePackedLen: ForeignCallSingle,
755
+ foreignMaxEventSerializedLen: ForeignCallSingle,
682
756
  ) {
683
757
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
684
758
  const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
685
759
  const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
760
+ const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
761
+ const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
686
762
 
687
- await this.handlerAsUtility().utilityValidateEnqueuedNotesAndEvents(
763
+ await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
688
764
  contractAddress,
689
765
  noteValidationRequestsArrayBaseSlot,
690
766
  eventValidationRequestsArrayBaseSlot,
767
+ maxNotePackedLen,
768
+ maxEventSerializedLen,
691
769
  );
692
770
 
693
771
  return toForeignCallResult([]);
694
772
  }
695
773
 
696
- public async utilityBulkRetrieveLogs(
774
+ // eslint-disable-next-line camelcase
775
+ public async aztec_utl_bulkRetrieveLogs(
697
776
  foreignContractAddress: ForeignCallSingle,
698
777
  foreignLogRetrievalRequestsArrayBaseSlot: ForeignCallSingle,
699
778
  foreignLogRetrievalResponsesArrayBaseSlot: ForeignCallSingle,
@@ -702,7 +781,7 @@ export class RPCTranslator {
702
781
  const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
703
782
  const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
704
783
 
705
- await this.handlerAsUtility().utilityBulkRetrieveLogs(
784
+ await this.handlerAsUtility().bulkRetrieveLogs(
706
785
  contractAddress,
707
786
  logRetrievalRequestsArrayBaseSlot,
708
787
  logRetrievalResponsesArrayBaseSlot,
@@ -711,7 +790,27 @@ export class RPCTranslator {
711
790
  return toForeignCallResult([]);
712
791
  }
713
792
 
714
- async utilityStoreCapsule(
793
+ // eslint-disable-next-line camelcase
794
+ public async aztec_utl_utilityResolveMessageContexts(
795
+ foreignContractAddress: ForeignCallSingle,
796
+ foreignMessageContextRequestsArrayBaseSlot: ForeignCallSingle,
797
+ foreignMessageContextResponsesArrayBaseSlot: ForeignCallSingle,
798
+ ) {
799
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
800
+ const messageContextRequestsArrayBaseSlot = fromSingle(foreignMessageContextRequestsArrayBaseSlot);
801
+ const messageContextResponsesArrayBaseSlot = fromSingle(foreignMessageContextResponsesArrayBaseSlot);
802
+
803
+ await this.handlerAsUtility().utilityResolveMessageContexts(
804
+ contractAddress,
805
+ messageContextRequestsArrayBaseSlot,
806
+ messageContextResponsesArrayBaseSlot,
807
+ );
808
+
809
+ return toForeignCallResult([]);
810
+ }
811
+
812
+ // eslint-disable-next-line camelcase
813
+ async aztec_utl_storeCapsule(
715
814
  foreignContractAddress: ForeignCallSingle,
716
815
  foreignSlot: ForeignCallSingle,
717
816
  foreignCapsule: ForeignCallArray,
@@ -720,12 +819,13 @@ export class RPCTranslator {
720
819
  const slot = fromSingle(foreignSlot);
721
820
  const capsule = fromArray(foreignCapsule);
722
821
 
723
- await this.handlerAsUtility().utilityStoreCapsule(contractAddress, slot, capsule);
822
+ await this.handlerAsUtility().storeCapsule(contractAddress, slot, capsule);
724
823
 
725
824
  return toForeignCallResult([]);
726
825
  }
727
826
 
728
- async utilityLoadCapsule(
827
+ // eslint-disable-next-line camelcase
828
+ async aztec_utl_loadCapsule(
729
829
  foreignContractAddress: ForeignCallSingle,
730
830
  foreignSlot: ForeignCallSingle,
731
831
  foreignTSize: ForeignCallSingle,
@@ -734,7 +834,7 @@ export class RPCTranslator {
734
834
  const slot = fromSingle(foreignSlot);
735
835
  const tSize = fromSingle(foreignTSize).toNumber();
736
836
 
737
- const values = await this.handlerAsUtility().utilityLoadCapsule(contractAddress, slot);
837
+ const values = await this.handlerAsUtility().loadCapsule(contractAddress, slot);
738
838
 
739
839
  // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
740
840
  // with two fields: `some` (a boolean) and `value` (a field array in this case).
@@ -747,16 +847,18 @@ export class RPCTranslator {
747
847
  }
748
848
  }
749
849
 
750
- async utilityDeleteCapsule(foreignContractAddress: ForeignCallSingle, foreignSlot: ForeignCallSingle) {
850
+ // eslint-disable-next-line camelcase
851
+ async aztec_utl_deleteCapsule(foreignContractAddress: ForeignCallSingle, foreignSlot: ForeignCallSingle) {
751
852
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
752
853
  const slot = fromSingle(foreignSlot);
753
854
 
754
- await this.handlerAsUtility().utilityDeleteCapsule(contractAddress, slot);
855
+ await this.handlerAsUtility().deleteCapsule(contractAddress, slot);
755
856
 
756
857
  return toForeignCallResult([]);
757
858
  }
758
859
 
759
- async utilityCopyCapsule(
860
+ // eslint-disable-next-line camelcase
861
+ async aztec_utl_copyCapsule(
760
862
  foreignContractAddress: ForeignCallSingle,
761
863
  foreignSrcSlot: ForeignCallSingle,
762
864
  foreignDstSlot: ForeignCallSingle,
@@ -767,7 +869,7 @@ export class RPCTranslator {
767
869
  const dstSlot = fromSingle(foreignDstSlot);
768
870
  const numEntries = fromSingle(foreignNumEntries).toNumber();
769
871
 
770
- await this.handlerAsUtility().utilityCopyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
872
+ await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
771
873
 
772
874
  return toForeignCallResult([]);
773
875
  }
@@ -776,7 +878,8 @@ export class RPCTranslator {
776
878
  // 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
777
879
  // to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
778
880
  // existence of a txe_oracle method?
779
- async utilityAes128Decrypt(
881
+ // eslint-disable-next-line camelcase
882
+ async aztec_utl_tryAes128Decrypt(
780
883
  foreignCiphertextBVecStorage: ForeignCallArray,
781
884
  foreignCiphertextLength: ForeignCallSingle,
782
885
  foreignIv: ForeignCallArray,
@@ -786,14 +889,22 @@ export class RPCTranslator {
786
889
  const iv = fromUintArray(foreignIv, 8);
787
890
  const symKey = fromUintArray(foreignSymKey, 8);
788
891
 
789
- const plaintextBuffer = await this.handlerAsUtility().utilityAes128Decrypt(ciphertext, iv, symKey);
790
-
791
- return toForeignCallResult(
792
- arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length),
793
- );
892
+ // Noir Option<BoundedVec> is encoded as [is_some: Field, storage: Field[], length: Field].
893
+ try {
894
+ const plaintextBuffer = await this.handlerAsUtility().aes128Decrypt(ciphertext, iv, symKey);
895
+ const [storage, length] = arrayToBoundedVec(
896
+ bufferToU8Array(plaintextBuffer),
897
+ foreignCiphertextBVecStorage.length,
898
+ );
899
+ return toForeignCallResult([toSingle(new Fr(1)), storage, length]);
900
+ } catch {
901
+ const zeroStorage = toArray(Array(foreignCiphertextBVecStorage.length).fill(new Fr(0)));
902
+ return toForeignCallResult([toSingle(new Fr(0)), zeroStorage, toSingle(new Fr(0))]);
903
+ }
794
904
  }
795
905
 
796
- async utilityGetSharedSecret(
906
+ // eslint-disable-next-line camelcase
907
+ async aztec_utl_getSharedSecret(
797
908
  foreignAddress: ForeignCallSingle,
798
909
  foreignEphPKField0: ForeignCallSingle,
799
910
  foreignEphPKField1: ForeignCallSingle,
@@ -806,43 +917,66 @@ export class RPCTranslator {
806
917
  fromSingle(foreignEphPKField2),
807
918
  ]);
808
919
 
809
- const secret = await this.handlerAsUtility().utilityGetSharedSecret(address, ephPK);
920
+ const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK);
810
921
 
811
922
  return toForeignCallResult(secret.toFields().map(toSingle));
812
923
  }
813
924
 
814
- emitOffchainEffect(_foreignData: ForeignCallArray) {
925
+ // eslint-disable-next-line camelcase
926
+ aztec_utl_invalidateContractSyncCache(
927
+ foreignContractAddress: ForeignCallSingle,
928
+ foreignScopes: ForeignCallArray,
929
+ foreignScopeCount: ForeignCallSingle,
930
+ ) {
931
+ const contractAddress = addressFromSingle(foreignContractAddress);
932
+ const count = fromSingle(foreignScopeCount).toNumber();
933
+ const scopes = fromArray(foreignScopes)
934
+ .slice(0, count)
935
+ .map(f => new AztecAddress(f));
936
+
937
+ this.handlerAsUtility().invalidateContractSyncCache(contractAddress, scopes);
938
+
939
+ return Promise.resolve(toForeignCallResult([]));
940
+ }
941
+
942
+ // eslint-disable-next-line camelcase
943
+ aztec_utl_emitOffchainEffect(_foreignData: ForeignCallArray) {
815
944
  throw new Error('Offchain effects are not yet supported in the TestEnvironment');
816
945
  }
817
946
 
818
947
  // AVM opcodes
819
948
 
820
- avmOpcodeEmitUnencryptedLog(_foreignMessage: ForeignCallArray) {
949
+ // eslint-disable-next-line camelcase
950
+ aztec_avm_emitPublicLog(_foreignMessage: ForeignCallArray) {
821
951
  // TODO(#8811): Implement
822
952
  return toForeignCallResult([]);
823
953
  }
824
954
 
825
- async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle) {
955
+ // eslint-disable-next-line camelcase
956
+ async aztec_avm_storageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
826
957
  const slot = fromSingle(foreignSlot);
958
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
827
959
 
828
- const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot)).value;
960
+ const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
829
961
 
830
962
  return toForeignCallResult([toSingle(new Fr(value))]);
831
963
  }
832
964
 
833
- async avmOpcodeStorageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
965
+ // eslint-disable-next-line camelcase
966
+ async aztec_avm_storageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
834
967
  const slot = fromSingle(foreignSlot);
835
968
  const value = fromSingle(foreignValue);
836
969
 
837
- await this.handlerAsAvm().avmOpcodeStorageWrite(slot, value);
970
+ await this.handlerAsAvm().storageWrite(slot, value);
838
971
 
839
972
  return toForeignCallResult([]);
840
973
  }
841
974
 
842
- async avmOpcodeGetContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
975
+ // eslint-disable-next-line camelcase
976
+ async aztec_avm_getContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
843
977
  const address = addressFromSingle(foreignAddress);
844
978
 
845
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
979
+ const instance = await this.handlerAsUtility().getContractInstance(address);
846
980
 
847
981
  return toForeignCallResult([
848
982
  toSingle(instance.deployer),
@@ -851,10 +985,11 @@ export class RPCTranslator {
851
985
  ]);
852
986
  }
853
987
 
854
- async avmOpcodeGetContractInstanceClassId(foreignAddress: ForeignCallSingle) {
988
+ // eslint-disable-next-line camelcase
989
+ async aztec_avm_getContractInstanceClassId(foreignAddress: ForeignCallSingle) {
855
990
  const address = addressFromSingle(foreignAddress);
856
991
 
857
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
992
+ const instance = await this.handlerAsUtility().getContractInstance(address);
858
993
 
859
994
  return toForeignCallResult([
860
995
  toSingle(instance.currentContractClassId),
@@ -863,10 +998,11 @@ export class RPCTranslator {
863
998
  ]);
864
999
  }
865
1000
 
866
- async avmOpcodeGetContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
1001
+ // eslint-disable-next-line camelcase
1002
+ async aztec_avm_getContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
867
1003
  const address = addressFromSingle(foreignAddress);
868
1004
 
869
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
1005
+ const instance = await this.handlerAsUtility().getContractInstance(address);
870
1006
 
871
1007
  return toForeignCallResult([
872
1008
  toSingle(instance.initializationHash),
@@ -875,86 +1011,98 @@ export class RPCTranslator {
875
1011
  ]);
876
1012
  }
877
1013
 
878
- async avmOpcodeSender() {
879
- const sender = await this.handlerAsAvm().avmOpcodeSender();
1014
+ // eslint-disable-next-line camelcase
1015
+ async aztec_avm_sender() {
1016
+ const sender = await this.handlerAsAvm().sender();
880
1017
 
881
1018
  return toForeignCallResult([toSingle(sender)]);
882
1019
  }
883
1020
 
884
- async avmOpcodeEmitNullifier(foreignNullifier: ForeignCallSingle) {
1021
+ // eslint-disable-next-line camelcase
1022
+ async aztec_avm_emitNullifier(foreignNullifier: ForeignCallSingle) {
885
1023
  const nullifier = fromSingle(foreignNullifier);
886
1024
 
887
- await this.handlerAsAvm().avmOpcodeEmitNullifier(nullifier);
1025
+ await this.handlerAsAvm().emitNullifier(nullifier);
888
1026
 
889
1027
  return toForeignCallResult([]);
890
1028
  }
891
1029
 
892
- async avmOpcodeEmitNoteHash(foreignNoteHash: ForeignCallSingle) {
1030
+ // eslint-disable-next-line camelcase
1031
+ async aztec_avm_emitNoteHash(foreignNoteHash: ForeignCallSingle) {
893
1032
  const noteHash = fromSingle(foreignNoteHash);
894
1033
 
895
- await this.handlerAsAvm().avmOpcodeEmitNoteHash(noteHash);
1034
+ await this.handlerAsAvm().emitNoteHash(noteHash);
896
1035
 
897
1036
  return toForeignCallResult([]);
898
1037
  }
899
1038
 
900
- async avmOpcodeNullifierExists(foreignInnerNullifier: ForeignCallSingle, foreignTargetAddress: ForeignCallSingle) {
901
- const innerNullifier = fromSingle(foreignInnerNullifier);
902
- const targetAddress = AztecAddress.fromField(fromSingle(foreignTargetAddress));
1039
+ // eslint-disable-next-line camelcase
1040
+ async aztec_avm_nullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
1041
+ const siloedNullifier = fromSingle(foreignSiloedNullifier);
903
1042
 
904
- const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(innerNullifier, targetAddress);
1043
+ const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
905
1044
 
906
1045
  return toForeignCallResult([toSingle(new Fr(exists))]);
907
1046
  }
908
1047
 
909
- async avmOpcodeAddress() {
910
- const contractAddress = await this.handlerAsAvm().avmOpcodeAddress();
1048
+ // eslint-disable-next-line camelcase
1049
+ async aztec_avm_address() {
1050
+ const contractAddress = await this.handlerAsAvm().address();
911
1051
 
912
1052
  return toForeignCallResult([toSingle(contractAddress.toField())]);
913
1053
  }
914
1054
 
915
- async avmOpcodeBlockNumber() {
916
- const blockNumber = await this.handlerAsAvm().avmOpcodeBlockNumber();
1055
+ // eslint-disable-next-line camelcase
1056
+ async aztec_avm_blockNumber() {
1057
+ const blockNumber = await this.handlerAsAvm().blockNumber();
917
1058
 
918
1059
  return toForeignCallResult([toSingle(new Fr(blockNumber))]);
919
1060
  }
920
1061
 
921
- async avmOpcodeTimestamp() {
922
- const timestamp = await this.handlerAsAvm().avmOpcodeTimestamp();
1062
+ // eslint-disable-next-line camelcase
1063
+ async aztec_avm_timestamp() {
1064
+ const timestamp = await this.handlerAsAvm().timestamp();
923
1065
 
924
1066
  return toForeignCallResult([toSingle(new Fr(timestamp))]);
925
1067
  }
926
1068
 
927
- async avmOpcodeIsStaticCall() {
928
- const isStaticCall = await this.handlerAsAvm().avmOpcodeIsStaticCall();
1069
+ // eslint-disable-next-line camelcase
1070
+ async aztec_avm_isStaticCall() {
1071
+ const isStaticCall = await this.handlerAsAvm().isStaticCall();
929
1072
 
930
1073
  return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
931
1074
  }
932
1075
 
933
- async avmOpcodeChainId() {
934
- const chainId = await this.handlerAsAvm().avmOpcodeChainId();
1076
+ // eslint-disable-next-line camelcase
1077
+ async aztec_avm_chainId() {
1078
+ const chainId = await this.handlerAsAvm().chainId();
935
1079
 
936
1080
  return toForeignCallResult([toSingle(chainId)]);
937
1081
  }
938
1082
 
939
- async avmOpcodeVersion() {
940
- const version = await this.handlerAsAvm().avmOpcodeVersion();
1083
+ // eslint-disable-next-line camelcase
1084
+ async aztec_avm_version() {
1085
+ const version = await this.handlerAsAvm().version();
941
1086
 
942
1087
  return toForeignCallResult([toSingle(version)]);
943
1088
  }
944
1089
 
945
- avmOpcodeReturndataSize() {
1090
+ // eslint-disable-next-line camelcase
1091
+ aztec_avm_returndataSize() {
946
1092
  throw new Error(
947
1093
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
948
1094
  );
949
1095
  }
950
1096
 
951
- avmOpcodeReturndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
1097
+ // eslint-disable-next-line camelcase
1098
+ aztec_avm_returndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
952
1099
  throw new Error(
953
1100
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
954
1101
  );
955
1102
  }
956
1103
 
957
- avmOpcodeCall(
1104
+ // eslint-disable-next-line camelcase
1105
+ aztec_avm_call(
958
1106
  _foreignL2Gas: ForeignCallSingle,
959
1107
  _foreignDaGas: ForeignCallSingle,
960
1108
  _foreignAddress: ForeignCallSingle,
@@ -966,7 +1114,8 @@ export class RPCTranslator {
966
1114
  );
967
1115
  }
968
1116
 
969
- avmOpcodeStaticCall(
1117
+ // eslint-disable-next-line camelcase
1118
+ aztec_avm_staticCall(
970
1119
  _foreignL2Gas: ForeignCallSingle,
971
1120
  _foreignDaGas: ForeignCallSingle,
972
1121
  _foreignAddress: ForeignCallSingle,
@@ -978,13 +1127,15 @@ export class RPCTranslator {
978
1127
  );
979
1128
  }
980
1129
 
981
- avmOpcodeSuccessCopy() {
1130
+ // eslint-disable-next-line camelcase
1131
+ aztec_avm_successCopy() {
982
1132
  throw new Error(
983
1133
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
984
1134
  );
985
1135
  }
986
1136
 
987
- async txePrivateCallNewFlow(
1137
+ // eslint-disable-next-line camelcase
1138
+ async aztec_txe_privateCallNewFlow(
988
1139
  foreignFrom: ForeignCallSingle,
989
1140
  foreignTargetContractAddress: ForeignCallSingle,
990
1141
  foreignFunctionSelector: ForeignCallSingle,
@@ -999,19 +1150,23 @@ export class RPCTranslator {
999
1150
  const argsHash = fromSingle(foreignArgsHash);
1000
1151
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
1001
1152
 
1002
- const returnValues = await this.handlerAsTxe().txePrivateCallNewFlow(
1153
+ const returnValues = await this.handlerAsTxe().privateCallNewFlow(
1003
1154
  from,
1004
1155
  targetContractAddress,
1005
1156
  functionSelector,
1006
1157
  args,
1007
1158
  argsHash,
1008
1159
  isStaticCall,
1160
+ this.stateHandler.getCurrentJob(),
1009
1161
  );
1010
1162
 
1163
+ // TODO(F-335): Avoid doing the following call here.
1164
+ await this.stateHandler.cycleJob();
1011
1165
  return toForeignCallResult([toArray(returnValues)]);
1012
1166
  }
1013
1167
 
1014
- async txeSimulateUtilityFunction(
1168
+ // eslint-disable-next-line camelcase
1169
+ async aztec_txe_executeUtilityFunction(
1015
1170
  foreignTargetContractAddress: ForeignCallSingle,
1016
1171
  foreignFunctionSelector: ForeignCallSingle,
1017
1172
  foreignArgs: ForeignCallArray,
@@ -1020,16 +1175,20 @@ export class RPCTranslator {
1020
1175
  const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
1021
1176
  const args = fromArray(foreignArgs);
1022
1177
 
1023
- const returnValues = await this.handlerAsTxe().txeSimulateUtilityFunction(
1178
+ const returnValues = await this.handlerAsTxe().executeUtilityFunction(
1024
1179
  targetContractAddress,
1025
1180
  functionSelector,
1026
1181
  args,
1182
+ this.stateHandler.getCurrentJob(),
1027
1183
  );
1028
1184
 
1185
+ // TODO(F-335): Avoid doing the following call here.
1186
+ await this.stateHandler.cycleJob();
1029
1187
  return toForeignCallResult([toArray(returnValues)]);
1030
1188
  }
1031
1189
 
1032
- async txePublicCallNewFlow(
1190
+ // eslint-disable-next-line camelcase
1191
+ async aztec_txe_publicCallNewFlow(
1033
1192
  foreignFrom: ForeignCallSingle,
1034
1193
  foreignAddress: ForeignCallSingle,
1035
1194
  foreignCalldata: ForeignCallArray,
@@ -1040,13 +1199,16 @@ export class RPCTranslator {
1040
1199
  const calldata = fromArray(foreignCalldata);
1041
1200
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
1042
1201
 
1043
- const returnValues = await this.handlerAsTxe().txePublicCallNewFlow(from, address, calldata, isStaticCall);
1202
+ const returnValues = await this.handlerAsTxe().publicCallNewFlow(from, address, calldata, isStaticCall);
1044
1203
 
1204
+ // TODO(F-335): Avoid doing the following call here.
1205
+ await this.stateHandler.cycleJob();
1045
1206
  return toForeignCallResult([toArray(returnValues)]);
1046
1207
  }
1047
1208
 
1048
- async privateGetSenderForTags() {
1049
- const sender = await this.handlerAsPrivate().privateGetSenderForTags();
1209
+ // eslint-disable-next-line camelcase
1210
+ async aztec_prv_getSenderForTags() {
1211
+ const sender = await this.handlerAsPrivate().getSenderForTags();
1050
1212
 
1051
1213
  // Return a Noir Option struct with `some` and `value` fields
1052
1214
  if (sender === undefined) {
@@ -1058,19 +1220,21 @@ export class RPCTranslator {
1058
1220
  }
1059
1221
  }
1060
1222
 
1061
- async privateSetSenderForTags(foreignSenderForTags: ForeignCallSingle) {
1223
+ // eslint-disable-next-line camelcase
1224
+ async aztec_prv_setSenderForTags(foreignSenderForTags: ForeignCallSingle) {
1062
1225
  const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
1063
1226
 
1064
- await this.handlerAsPrivate().privateSetSenderForTags(senderForTags);
1227
+ await this.handlerAsPrivate().setSenderForTags(senderForTags);
1065
1228
 
1066
1229
  return toForeignCallResult([]);
1067
1230
  }
1068
1231
 
1069
- async privateGetNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
1232
+ // eslint-disable-next-line camelcase
1233
+ async aztec_prv_getNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
1070
1234
  const sender = AztecAddress.fromField(fromSingle(foreignSender));
1071
1235
  const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
1072
1236
 
1073
- const nextAppTag = await this.handlerAsPrivate().privateGetNextAppTagAsSender(sender, recipient);
1237
+ const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
1074
1238
 
1075
1239
  return toForeignCallResult([toSingle(nextAppTag.value)]);
1076
1240
  }