@aztec/txe 0.86.0 → 0.87.0

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 (37) hide show
  1. package/dest/oracle/txe_oracle.d.ts +11 -6
  2. package/dest/oracle/txe_oracle.d.ts.map +1 -1
  3. package/dest/oracle/txe_oracle.js +209 -38
  4. package/dest/state_machine/archiver.d.ts +53 -0
  5. package/dest/state_machine/archiver.d.ts.map +1 -0
  6. package/dest/state_machine/archiver.js +100 -0
  7. package/dest/state_machine/dummy_p2p_client.d.ts +48 -0
  8. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -0
  9. package/dest/state_machine/dummy_p2p_client.js +122 -0
  10. package/dest/state_machine/global_variable_builder.d.ts +23 -0
  11. package/dest/state_machine/global_variable_builder.d.ts.map +1 -0
  12. package/dest/state_machine/global_variable_builder.js +29 -0
  13. package/dest/state_machine/index.d.ts +16 -0
  14. package/dest/state_machine/index.d.ts.map +1 -0
  15. package/dest/state_machine/index.js +48 -0
  16. package/dest/state_machine/synchronizer.d.ts +32 -0
  17. package/dest/state_machine/synchronizer.d.ts.map +1 -0
  18. package/dest/state_machine/synchronizer.js +58 -0
  19. package/dest/txe_service/txe_service.d.ts +12 -3
  20. package/dest/txe_service/txe_service.d.ts.map +1 -1
  21. package/dest/txe_service/txe_service.js +221 -37
  22. package/dest/util/encoding.d.ts +11 -4
  23. package/dest/util/encoding.d.ts.map +1 -1
  24. package/dest/util/encoding.js +38 -2
  25. package/package.json +18 -15
  26. package/src/oracle/txe_oracle.ts +387 -40
  27. package/src/state_machine/archiver.ts +132 -0
  28. package/src/state_machine/dummy_p2p_client.ts +167 -0
  29. package/src/state_machine/global_variable_builder.ts +55 -0
  30. package/src/state_machine/index.ts +71 -0
  31. package/src/state_machine/synchronizer.ts +87 -0
  32. package/src/txe_service/txe_service.ts +427 -31
  33. package/src/util/encoding.ts +51 -2
  34. package/dest/node/txe_node.d.ts +0 -320
  35. package/dest/node/txe_node.d.ts.map +0 -1
  36. package/dest/node/txe_node.js +0 -481
  37. package/src/node/txe_node.ts +0 -703
@@ -10,7 +10,7 @@ import { PublicDataWrite } from '@aztec/stdlib/avm';
10
10
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
11
11
  import { computePartialAddress } from '@aztec/stdlib/contract';
12
12
  import { SimulationError } from '@aztec/stdlib/errors';
13
- import { computePublicDataTreeLeafSlot, siloNullifier } from '@aztec/stdlib/hash';
13
+ import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
14
14
  import { LogWithTxData } from '@aztec/stdlib/logs';
15
15
  import { MerkleTreeId } from '@aztec/stdlib/trees';
16
16
 
@@ -19,6 +19,7 @@ import {
19
19
  type ForeignCallArray,
20
20
  type ForeignCallSingle,
21
21
  addressFromSingle,
22
+ arrayOfArraysToBoundedVecOfArrays,
22
23
  arrayToBoundedVec,
23
24
  bufferToU8Array,
24
25
  fromArray,
@@ -33,7 +34,12 @@ import {
33
34
  import { ExpectedFailureError } from '../util/expected_failure_error.js';
34
35
 
35
36
  export class TXEService {
36
- constructor(private logger: Logger, private typedOracle: TypedOracle) {}
37
+ public oraclesEnabled = true;
38
+
39
+ constructor(
40
+ private logger: Logger,
41
+ private typedOracle: TypedOracle,
42
+ ) {}
37
43
 
38
44
  static async init(logger: Logger, protocolContracts: ProtocolContract[]) {
39
45
  logger.debug(`TXE service initialized`);
@@ -76,9 +82,10 @@ export class TXEService {
76
82
 
77
83
  async deploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: ForeignCallSingle) {
78
84
  // Emit deployment nullifier
79
- (this.typedOracle as TXE).addSiloedNullifiersFromPublic([
80
- await siloNullifier(AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS), instance.address.toField()),
81
- ]);
85
+ await (this.typedOracle as TXE).noteCache.nullifierCreated(
86
+ AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS),
87
+ instance.address.toField(),
88
+ );
82
89
 
83
90
  if (!fromSingle(secret).equals(Fr.ZERO)) {
84
91
  await this.addAccount(artifact, instance, secret);
@@ -209,26 +216,56 @@ export class TXEService {
209
216
  // PXE oracles
210
217
 
211
218
  getRandomField() {
219
+ if (!this.oraclesEnabled) {
220
+ throw new Error(
221
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
222
+ );
223
+ }
224
+
212
225
  return toForeignCallResult([toSingle(this.typedOracle.getRandomField())]);
213
226
  }
214
227
 
215
228
  async getContractAddress() {
229
+ if (!this.oraclesEnabled) {
230
+ throw new Error(
231
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
232
+ );
233
+ }
234
+
216
235
  const contractAddress = await this.typedOracle.getContractAddress();
217
236
  return toForeignCallResult([toSingle(contractAddress.toField())]);
218
237
  }
219
238
 
220
239
  async getBlockNumber() {
240
+ if (!this.oraclesEnabled) {
241
+ throw new Error(
242
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
243
+ );
244
+ }
245
+
221
246
  const blockNumber = await this.typedOracle.getBlockNumber();
222
247
  return toForeignCallResult([toSingle(new Fr(blockNumber))]);
223
248
  }
224
249
 
225
250
  // Since the argument is a slice, noir automatically adds a length field to oracle call.
226
251
  storeInExecutionCache(_length: ForeignCallSingle, values: ForeignCallArray, hash: ForeignCallSingle) {
252
+ if (!this.oraclesEnabled) {
253
+ throw new Error(
254
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
255
+ );
256
+ }
257
+
227
258
  this.typedOracle.storeInExecutionCache(fromArray(values), fromSingle(hash));
228
259
  return toForeignCallResult([]);
229
260
  }
230
261
 
231
262
  async loadFromExecutionCache(hash: ForeignCallSingle) {
263
+ if (!this.oraclesEnabled) {
264
+ throw new Error(
265
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
266
+ );
267
+ }
268
+
232
269
  const returns = await this.typedOracle.loadFromExecutionCache(fromSingle(hash));
233
270
  return toForeignCallResult([toArray(returns)]);
234
271
  }
@@ -264,6 +301,12 @@ export class TXEService {
264
301
  }
265
302
 
266
303
  async getPublicDataWitness(blockNumber: ForeignCallSingle, leafSlot: ForeignCallSingle) {
304
+ if (!this.oraclesEnabled) {
305
+ throw new Error(
306
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
307
+ );
308
+ }
309
+
267
310
  const parsedBlockNumber = fromSingle(blockNumber).toNumber();
268
311
  const parsedLeafSlot = fromSingle(leafSlot);
269
312
 
@@ -289,8 +332,15 @@ export class TXEService {
289
332
  limit: ForeignCallSingle,
290
333
  offset: ForeignCallSingle,
291
334
  status: ForeignCallSingle,
292
- returnSize: ForeignCallSingle,
335
+ maxNotes: ForeignCallSingle,
336
+ packedRetrievedNoteLength: ForeignCallSingle,
293
337
  ) {
338
+ if (!this.oraclesEnabled) {
339
+ throw new Error(
340
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
341
+ );
342
+ }
343
+
294
344
  const noteDatas = await this.typedOracle.getNotes(
295
345
  fromSingle(storageSlot),
296
346
  fromSingle(numSelects).toNumber(),
@@ -307,32 +357,39 @@ export class TXEService {
307
357
  fromSingle(offset).toNumber(),
308
358
  fromSingle(status).toNumber(),
309
359
  );
310
- const noteLength = noteDatas?.[0]?.note.items.length ?? 0;
311
- if (!noteDatas.every(({ note }) => noteLength === note.items.length)) {
312
- throw new Error('Notes should all be the same length.');
313
- }
314
-
315
- const contractAddress = noteDatas[0]?.contractAddress ?? Fr.ZERO;
316
-
317
- // Values indicates whether the note is settled or transient.
318
- const noteTypes = {
319
- isSettled: new Fr(0),
320
- isTransient: new Fr(1),
321
- };
322
- const flattenData = noteDatas.flatMap(({ nonce, note, index }) => [
323
- nonce,
324
- index === undefined ? noteTypes.isTransient : noteTypes.isSettled,
325
- ...note.items,
326
- ]);
327
360
 
328
- const returnFieldSize = fromSingle(returnSize).toNumber();
329
- const returnData = [noteDatas.length, contractAddress.toField(), ...flattenData].map(v => new Fr(v));
330
- if (returnData.length > returnFieldSize) {
331
- throw new Error(`Return data size too big. Maximum ${returnFieldSize} fields. Got ${flattenData.length}.`);
361
+ if (noteDatas.length > 0) {
362
+ const noteLength = noteDatas[0].note.items.length;
363
+ if (!noteDatas.every(({ note }) => noteLength === note.items.length)) {
364
+ throw new Error('Notes should all be the same length.');
365
+ }
332
366
  }
333
367
 
334
- const paddedZeros = Array(returnFieldSize - returnData.length).fill(new Fr(0));
335
- return toForeignCallResult([toArray([...returnData, ...paddedZeros])]);
368
+ // The expected return type is a BoundedVec<[Field; packedRetrievedNoteLength], maxNotes> where each
369
+ // array is structured as [contract_address, nonce, nonzero_note_hash_counter, ...packed_note].
370
+
371
+ const returnDataAsArrayOfArrays = noteDatas.map(({ contractAddress, nonce, index, note }) => {
372
+ // If index is undefined, the note is transient which implies that the nonzero_note_hash_counter has to be true
373
+ const noteIsTransient = index === undefined;
374
+ const nonzeroNoteHashCounter = noteIsTransient ? true : false;
375
+ // If you change the array on the next line you have to change the `unpack_retrieved_note` function in
376
+ // `aztec/src/note/retrieved_note.nr`
377
+ return [contractAddress, nonce, nonzeroNoteHashCounter, ...note.items];
378
+ });
379
+
380
+ // Now we convert each sub-array to an array of ForeignCallSingles
381
+ const returnDataAsArrayOfForeignCallSingleArrays = returnDataAsArrayOfArrays.map(subArray =>
382
+ subArray.map(toSingle),
383
+ );
384
+
385
+ // At last we convert the array of arrays to a bounded vec of arrays
386
+ return toForeignCallResult(
387
+ arrayOfArraysToBoundedVecOfArrays(
388
+ returnDataAsArrayOfForeignCallSingleArrays,
389
+ fromSingle(maxNotes).toNumber(),
390
+ fromSingle(packedRetrievedNoteLength).toNumber(),
391
+ ),
392
+ );
336
393
  }
337
394
 
338
395
  notifyCreatedNote(
@@ -342,6 +399,12 @@ export class TXEService {
342
399
  noteHash: ForeignCallSingle,
343
400
  counter: ForeignCallSingle,
344
401
  ) {
402
+ if (!this.oraclesEnabled) {
403
+ throw new Error(
404
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
405
+ );
406
+ }
407
+
345
408
  this.typedOracle.notifyCreatedNote(
346
409
  fromSingle(storageSlot),
347
410
  NoteSelector.fromField(fromSingle(noteTypeId)),
@@ -357,6 +420,12 @@ export class TXEService {
357
420
  noteHash: ForeignCallSingle,
358
421
  counter: ForeignCallSingle,
359
422
  ) {
423
+ if (!this.oraclesEnabled) {
424
+ throw new Error(
425
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
426
+ );
427
+ }
428
+
360
429
  await this.typedOracle.notifyNullifiedNote(
361
430
  fromSingle(innerNullifier),
362
431
  fromSingle(noteHash),
@@ -366,16 +435,34 @@ export class TXEService {
366
435
  }
367
436
 
368
437
  async notifyCreatedNullifier(innerNullifier: ForeignCallSingle) {
438
+ if (!this.oraclesEnabled) {
439
+ throw new Error(
440
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
441
+ );
442
+ }
443
+
369
444
  await this.typedOracle.notifyCreatedNullifier(fromSingle(innerNullifier));
370
445
  return toForeignCallResult([]);
371
446
  }
372
447
 
373
448
  async checkNullifierExists(innerNullifier: ForeignCallSingle) {
449
+ if (!this.oraclesEnabled) {
450
+ throw new Error(
451
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
452
+ );
453
+ }
454
+
374
455
  const exists = await this.typedOracle.checkNullifierExists(fromSingle(innerNullifier));
375
456
  return toForeignCallResult([toSingle(new Fr(exists))]);
376
457
  }
377
458
 
378
459
  async getContractInstance(address: ForeignCallSingle) {
460
+ if (!this.oraclesEnabled) {
461
+ throw new Error(
462
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
463
+ );
464
+ }
465
+
379
466
  const instance = await this.typedOracle.getContractInstance(addressFromSingle(address));
380
467
  return toForeignCallResult(
381
468
  [
@@ -389,12 +476,24 @@ export class TXEService {
389
476
  }
390
477
 
391
478
  async getPublicKeysAndPartialAddress(address: ForeignCallSingle) {
479
+ if (!this.oraclesEnabled) {
480
+ throw new Error(
481
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
482
+ );
483
+ }
484
+
392
485
  const parsedAddress = addressFromSingle(address);
393
486
  const { publicKeys, partialAddress } = await this.typedOracle.getCompleteAddress(parsedAddress);
394
487
  return toForeignCallResult([toArray([...publicKeys.toFields(), partialAddress])]);
395
488
  }
396
489
 
397
490
  async getKeyValidationRequest(pkMHash: ForeignCallSingle) {
491
+ if (!this.oraclesEnabled) {
492
+ throw new Error(
493
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
494
+ );
495
+ }
496
+
398
497
  const keyValidationRequest = await this.typedOracle.getKeyValidationRequest(fromSingle(pkMHash));
399
498
  return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
400
499
  }
@@ -406,6 +505,12 @@ export class TXEService {
406
505
  sideEffectCounter: ForeignCallSingle,
407
506
  isStaticCall: ForeignCallSingle,
408
507
  ) {
508
+ if (!this.oraclesEnabled) {
509
+ throw new Error(
510
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
511
+ );
512
+ }
513
+
409
514
  const result = await this.typedOracle.callPrivateFunction(
410
515
  addressFromSingle(targetContractAddress),
411
516
  FunctionSelector.fromField(fromSingle(functionSelector)),
@@ -417,6 +522,12 @@ export class TXEService {
417
522
  }
418
523
 
419
524
  async getNullifierMembershipWitness(blockNumber: ForeignCallSingle, nullifier: ForeignCallSingle) {
525
+ if (!this.oraclesEnabled) {
526
+ throw new Error(
527
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
528
+ );
529
+ }
530
+
420
531
  const parsedBlockNumber = fromSingle(blockNumber).toNumber();
421
532
  const witness = await this.typedOracle.getNullifierMembershipWitness(parsedBlockNumber, fromSingle(nullifier));
422
533
  if (!witness) {
@@ -426,6 +537,12 @@ export class TXEService {
426
537
  }
427
538
 
428
539
  async getAuthWitness(messageHash: ForeignCallSingle) {
540
+ if (!this.oraclesEnabled) {
541
+ throw new Error(
542
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
543
+ );
544
+ }
545
+
429
546
  const parsedMessageHash = fromSingle(messageHash);
430
547
  const authWitness = await this.typedOracle.getAuthWitness(parsedMessageHash);
431
548
  if (!authWitness) {
@@ -440,6 +557,12 @@ export class TXEService {
440
557
  sideEffectCounter: ForeignCallSingle,
441
558
  isStaticCall: ForeignCallSingle,
442
559
  ) {
560
+ if (!this.oraclesEnabled) {
561
+ throw new Error(
562
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
563
+ );
564
+ }
565
+
443
566
  await this.typedOracle.notifyEnqueuedPublicFunctionCall(
444
567
  addressFromSingle(targetContractAddress),
445
568
  fromSingle(calldataHash),
@@ -455,6 +578,12 @@ export class TXEService {
455
578
  sideEffectCounter: ForeignCallSingle,
456
579
  isStaticCall: ForeignCallSingle,
457
580
  ) {
581
+ if (!this.oraclesEnabled) {
582
+ throw new Error(
583
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
584
+ );
585
+ }
586
+
458
587
  await this.typedOracle.notifySetPublicTeardownFunctionCall(
459
588
  addressFromSingle(targetContractAddress),
460
589
  fromSingle(calldataHash),
@@ -464,20 +593,46 @@ export class TXEService {
464
593
  return toForeignCallResult([]);
465
594
  }
466
595
 
467
- public notifySetMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: ForeignCallSingle) {
468
- this.typedOracle.notifySetMinRevertibleSideEffectCounter(fromSingle(minRevertibleSideEffectCounter).toNumber());
596
+ public async notifySetMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: ForeignCallSingle) {
597
+ if (!this.oraclesEnabled) {
598
+ throw new Error(
599
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
600
+ );
601
+ }
602
+
603
+ await this.typedOracle.notifySetMinRevertibleSideEffectCounter(
604
+ fromSingle(minRevertibleSideEffectCounter).toNumber(),
605
+ );
469
606
  return toForeignCallResult([]);
470
607
  }
471
608
 
472
609
  async getChainId() {
610
+ if (!this.oraclesEnabled) {
611
+ throw new Error(
612
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
613
+ );
614
+ }
615
+
473
616
  return toForeignCallResult([toSingle(await this.typedOracle.getChainId())]);
474
617
  }
475
618
 
476
619
  async getVersion() {
620
+ if (!this.oraclesEnabled) {
621
+ throw new Error(
622
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
623
+ );
624
+ }
625
+
477
626
  return toForeignCallResult([toSingle(await this.typedOracle.getVersion())]);
478
627
  }
479
628
 
480
629
  async getBlockHeader(blockNumber: ForeignCallSingle) {
630
+ if (!this.oraclesEnabled) {
631
+ throw new Error(
632
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
633
+ );
634
+ }
635
+
481
636
  const header = await this.typedOracle.getBlockHeader(fromSingle(blockNumber).toNumber());
482
637
  if (!header) {
483
638
  throw new Error(`Block header not found for block ${blockNumber}.`);
@@ -486,6 +641,12 @@ export class TXEService {
486
641
  }
487
642
 
488
643
  async getMembershipWitness(blockNumber: ForeignCallSingle, treeId: ForeignCallSingle, leafValue: ForeignCallSingle) {
644
+ if (!this.oraclesEnabled) {
645
+ throw new Error(
646
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
647
+ );
648
+ }
649
+
489
650
  const parsedBlockNumber = fromSingle(blockNumber).toNumber();
490
651
  const parsedTreeId = fromSingle(treeId).toNumber();
491
652
  const parsedLeafValue = fromSingle(leafValue);
@@ -499,6 +660,12 @@ export class TXEService {
499
660
  }
500
661
 
501
662
  async getLowNullifierMembershipWitness(blockNumber: ForeignCallSingle, nullifier: ForeignCallSingle) {
663
+ if (!this.oraclesEnabled) {
664
+ throw new Error(
665
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
666
+ );
667
+ }
668
+
502
669
  const parsedBlockNumber = fromSingle(blockNumber).toNumber();
503
670
 
504
671
  const witness = await this.typedOracle.getLowNullifierMembershipWitness(parsedBlockNumber, fromSingle(nullifier));
@@ -509,6 +676,12 @@ export class TXEService {
509
676
  }
510
677
 
511
678
  async getIndexedTaggingSecretAsSender(sender: ForeignCallSingle, recipient: ForeignCallSingle) {
679
+ if (!this.oraclesEnabled) {
680
+ throw new Error(
681
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
682
+ );
683
+ }
684
+
512
685
  const secret = await this.typedOracle.getIndexedTaggingSecretAsSender(
513
686
  AztecAddress.fromField(fromSingle(sender)),
514
687
  AztecAddress.fromField(fromSingle(recipient)),
@@ -517,6 +690,12 @@ export class TXEService {
517
690
  }
518
691
 
519
692
  async syncNotes(pendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
693
+ if (!this.oraclesEnabled) {
694
+ throw new Error(
695
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
696
+ );
697
+ }
698
+
520
699
  await this.typedOracle.syncNotes(fromSingle(pendingTaggedLogArrayBaseSlot));
521
700
  return toForeignCallResult([]);
522
701
  }
@@ -532,6 +711,12 @@ export class TXEService {
532
711
  txHash: ForeignCallSingle,
533
712
  recipient: ForeignCallSingle,
534
713
  ) {
714
+ if (!this.oraclesEnabled) {
715
+ throw new Error(
716
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
717
+ );
718
+ }
719
+
535
720
  await this.typedOracle.deliverNote(
536
721
  AztecAddress.fromField(fromSingle(contractAddress)),
537
722
  fromSingle(storageSlot),
@@ -547,6 +732,12 @@ export class TXEService {
547
732
  }
548
733
 
549
734
  async getLogByTag(tag: ForeignCallSingle) {
735
+ if (!this.oraclesEnabled) {
736
+ throw new Error(
737
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
738
+ );
739
+ }
740
+
550
741
  // TODO(AD): this was warning that getLogByTag did not return a promise.
551
742
  const log = await Promise.resolve(this.typedOracle.getLogByTag(fromSingle(tag)));
552
743
 
@@ -558,6 +749,12 @@ export class TXEService {
558
749
  }
559
750
 
560
751
  async storeCapsule(contractAddress: ForeignCallSingle, slot: ForeignCallSingle, capsule: ForeignCallArray) {
752
+ if (!this.oraclesEnabled) {
753
+ throw new Error(
754
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
755
+ );
756
+ }
757
+
561
758
  await this.typedOracle.storeCapsule(
562
759
  AztecAddress.fromField(fromSingle(contractAddress)),
563
760
  fromSingle(slot),
@@ -567,6 +764,12 @@ export class TXEService {
567
764
  }
568
765
 
569
766
  async loadCapsule(contractAddress: ForeignCallSingle, slot: ForeignCallSingle, tSize: ForeignCallSingle) {
767
+ if (!this.oraclesEnabled) {
768
+ throw new Error(
769
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
770
+ );
771
+ }
772
+
570
773
  const values = await this.typedOracle.loadCapsule(
571
774
  AztecAddress.fromField(fromSingle(contractAddress)),
572
775
  fromSingle(slot),
@@ -583,6 +786,12 @@ export class TXEService {
583
786
  }
584
787
 
585
788
  async deleteCapsule(contractAddress: ForeignCallSingle, slot: ForeignCallSingle) {
789
+ if (!this.oraclesEnabled) {
790
+ throw new Error(
791
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
792
+ );
793
+ }
794
+
586
795
  await this.typedOracle.deleteCapsule(AztecAddress.fromField(fromSingle(contractAddress)), fromSingle(slot));
587
796
  return toForeignCallResult([]);
588
797
  }
@@ -593,6 +802,12 @@ export class TXEService {
593
802
  dstSlot: ForeignCallSingle,
594
803
  numEntries: ForeignCallSingle,
595
804
  ) {
805
+ if (!this.oraclesEnabled) {
806
+ throw new Error(
807
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
808
+ );
809
+ }
810
+
596
811
  await this.typedOracle.copyCapsule(
597
812
  AztecAddress.fromField(fromSingle(contractAddress)),
598
813
  fromSingle(srcSlot),
@@ -613,6 +828,12 @@ export class TXEService {
613
828
  iv: ForeignCallArray,
614
829
  symKey: ForeignCallArray,
615
830
  ) {
831
+ if (!this.oraclesEnabled) {
832
+ throw new Error(
833
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
834
+ );
835
+ }
836
+
616
837
  const ciphertext = fromUintBoundedVec(ciphertextBVecStorage, ciphertextLength, 8);
617
838
  const ivBuffer = fromUintArray(iv, 8);
618
839
  const symKeyBuffer = fromUintArray(symKey, 8);
@@ -628,6 +849,12 @@ export class TXEService {
628
849
  ephPKField1: ForeignCallSingle,
629
850
  ephPKField2: ForeignCallSingle,
630
851
  ) {
852
+ if (!this.oraclesEnabled) {
853
+ throw new Error(
854
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
855
+ );
856
+ }
857
+
631
858
  const secret = await this.typedOracle.getSharedSecret(
632
859
  AztecAddress.fromField(fromSingle(address)),
633
860
  Point.fromFields([fromSingle(ephPKField0), fromSingle(ephPKField1), fromSingle(ephPKField2)]),
@@ -644,6 +871,12 @@ export class TXEService {
644
871
  logIndexInTx: ForeignCallSingle,
645
872
  txIndexInBlock: ForeignCallSingle,
646
873
  ) {
874
+ if (!this.oraclesEnabled) {
875
+ throw new Error(
876
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
877
+ );
878
+ }
879
+
647
880
  await this.typedOracle.storePrivateEventLog(
648
881
  AztecAddress.fromField(fromSingle(contractAddress)),
649
882
  AztecAddress.fromField(fromSingle(recipient)),
@@ -659,21 +892,45 @@ export class TXEService {
659
892
  // AVM opcodes
660
893
 
661
894
  avmOpcodeEmitUnencryptedLog(_message: ForeignCallArray) {
895
+ if (!this.oraclesEnabled) {
896
+ throw new Error(
897
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
898
+ );
899
+ }
900
+
662
901
  // TODO(#8811): Implement
663
902
  return toForeignCallResult([]);
664
903
  }
665
904
 
666
905
  async avmOpcodeStorageRead(slot: ForeignCallSingle) {
906
+ if (!this.oraclesEnabled) {
907
+ throw new Error(
908
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
909
+ );
910
+ }
911
+
667
912
  const value = (await (this.typedOracle as TXE).avmOpcodeStorageRead(fromSingle(slot))).value;
668
913
  return toForeignCallResult([toSingle(new Fr(value))]);
669
914
  }
670
915
 
671
916
  async avmOpcodeStorageWrite(slot: ForeignCallSingle, value: ForeignCallSingle) {
917
+ if (!this.oraclesEnabled) {
918
+ throw new Error(
919
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
920
+ );
921
+ }
922
+
672
923
  await this.typedOracle.storageWrite(fromSingle(slot), [fromSingle(value)]);
673
924
  return toForeignCallResult([]);
674
925
  }
675
926
 
676
927
  async avmOpcodeGetContractInstanceDeployer(address: ForeignCallSingle) {
928
+ if (!this.oraclesEnabled) {
929
+ throw new Error(
930
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
931
+ );
932
+ }
933
+
677
934
  const instance = await this.typedOracle.getContractInstance(addressFromSingle(address));
678
935
  return toForeignCallResult([
679
936
  toSingle(instance.deployer),
@@ -683,6 +940,12 @@ export class TXEService {
683
940
  }
684
941
 
685
942
  async avmOpcodeGetContractInstanceClassId(address: ForeignCallSingle) {
943
+ if (!this.oraclesEnabled) {
944
+ throw new Error(
945
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
946
+ );
947
+ }
948
+
686
949
  const instance = await this.typedOracle.getContractInstance(addressFromSingle(address));
687
950
  return toForeignCallResult([
688
951
  toSingle(instance.currentContractClassId),
@@ -692,6 +955,12 @@ export class TXEService {
692
955
  }
693
956
 
694
957
  async avmOpcodeGetContractInstanceInitializationHash(address: ForeignCallSingle) {
958
+ if (!this.oraclesEnabled) {
959
+ throw new Error(
960
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
961
+ );
962
+ }
963
+
695
964
  const instance = await this.typedOracle.getContractInstance(addressFromSingle(address));
696
965
  return toForeignCallResult([
697
966
  toSingle(instance.initializationHash),
@@ -701,21 +970,45 @@ export class TXEService {
701
970
  }
702
971
 
703
972
  avmOpcodeSender() {
973
+ if (!this.oraclesEnabled) {
974
+ throw new Error(
975
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
976
+ );
977
+ }
978
+
704
979
  const sender = (this.typedOracle as TXE).getMsgSender();
705
980
  return toForeignCallResult([toSingle(sender)]);
706
981
  }
707
982
 
708
983
  async avmOpcodeEmitNullifier(nullifier: ForeignCallSingle) {
984
+ if (!this.oraclesEnabled) {
985
+ throw new Error(
986
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
987
+ );
988
+ }
989
+
709
990
  await (this.typedOracle as TXE).avmOpcodeEmitNullifier(fromSingle(nullifier));
710
991
  return toForeignCallResult([]);
711
992
  }
712
993
 
713
994
  async avmOpcodeEmitNoteHash(noteHash: ForeignCallSingle) {
995
+ if (!this.oraclesEnabled) {
996
+ throw new Error(
997
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
998
+ );
999
+ }
1000
+
714
1001
  await (this.typedOracle as TXE).avmOpcodeEmitNoteHash(fromSingle(noteHash));
715
1002
  return toForeignCallResult([]);
716
1003
  }
717
1004
 
718
1005
  async avmOpcodeNullifierExists(innerNullifier: ForeignCallSingle, targetAddress: ForeignCallSingle) {
1006
+ if (!this.oraclesEnabled) {
1007
+ throw new Error(
1008
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
1009
+ );
1010
+ }
1011
+
719
1012
  const exists = await (this.typedOracle as TXE).avmOpcodeNullifierExists(
720
1013
  fromSingle(innerNullifier),
721
1014
  AztecAddress.fromField(fromSingle(targetAddress)),
@@ -724,36 +1017,78 @@ export class TXEService {
724
1017
  }
725
1018
 
726
1019
  async avmOpcodeAddress() {
1020
+ if (!this.oraclesEnabled) {
1021
+ throw new Error(
1022
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
1023
+ );
1024
+ }
1025
+
727
1026
  const contractAddress = await this.typedOracle.getContractAddress();
728
1027
  return toForeignCallResult([toSingle(contractAddress.toField())]);
729
1028
  }
730
1029
 
731
1030
  async avmOpcodeBlockNumber() {
1031
+ if (!this.oraclesEnabled) {
1032
+ throw new Error(
1033
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
1034
+ );
1035
+ }
1036
+
732
1037
  const blockNumber = await this.typedOracle.getBlockNumber();
733
1038
  return toForeignCallResult([toSingle(new Fr(blockNumber))]);
734
1039
  }
735
1040
 
736
1041
  avmOpcodeIsStaticCall() {
1042
+ if (!this.oraclesEnabled) {
1043
+ throw new Error(
1044
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
1045
+ );
1046
+ }
1047
+
737
1048
  const isStaticCall = (this.typedOracle as TXE).getIsStaticCall();
738
1049
  return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
739
1050
  }
740
1051
 
741
1052
  async avmOpcodeChainId() {
1053
+ if (!this.oraclesEnabled) {
1054
+ throw new Error(
1055
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
1056
+ );
1057
+ }
1058
+
742
1059
  const chainId = await (this.typedOracle as TXE).getChainId();
743
1060
  return toForeignCallResult([toSingle(chainId)]);
744
1061
  }
745
1062
 
746
1063
  async avmOpcodeVersion() {
1064
+ if (!this.oraclesEnabled) {
1065
+ throw new Error(
1066
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
1067
+ );
1068
+ }
1069
+
747
1070
  const version = await (this.typedOracle as TXE).getVersion();
748
1071
  return toForeignCallResult([toSingle(version)]);
749
1072
  }
750
1073
 
751
1074
  avmOpcodeReturndataSize() {
1075
+ if (!this.oraclesEnabled) {
1076
+ throw new Error(
1077
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
1078
+ );
1079
+ }
1080
+
752
1081
  const size = (this.typedOracle as TXE).avmOpcodeReturndataSize();
753
1082
  return toForeignCallResult([toSingle(new Fr(size))]);
754
1083
  }
755
1084
 
756
1085
  avmOpcodeReturndataCopy(rdOffset: ForeignCallSingle, copySize: ForeignCallSingle) {
1086
+ if (!this.oraclesEnabled) {
1087
+ throw new Error(
1088
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
1089
+ );
1090
+ }
1091
+
757
1092
  const returndata = (this.typedOracle as TXE).avmOpcodeReturndataCopy(
758
1093
  fromSingle(rdOffset).toNumber(),
759
1094
  fromSingle(copySize).toNumber(),
@@ -769,6 +1104,12 @@ export class TXEService {
769
1104
  _length: ForeignCallSingle,
770
1105
  args: ForeignCallArray,
771
1106
  ) {
1107
+ if (!this.oraclesEnabled) {
1108
+ throw new Error(
1109
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
1110
+ );
1111
+ }
1112
+
772
1113
  const result = await (this.typedOracle as TXE).avmOpcodeCall(
773
1114
  addressFromSingle(address),
774
1115
  fromArray(args),
@@ -799,6 +1140,12 @@ export class TXEService {
799
1140
  _length: ForeignCallSingle,
800
1141
  args: ForeignCallArray,
801
1142
  ) {
1143
+ if (!this.oraclesEnabled) {
1144
+ throw new Error(
1145
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
1146
+ );
1147
+ }
1148
+
802
1149
  const result = await (this.typedOracle as TXE).avmOpcodeCall(
803
1150
  addressFromSingle(address),
804
1151
  fromArray(args),
@@ -823,7 +1170,56 @@ export class TXEService {
823
1170
  }
824
1171
 
825
1172
  avmOpcodeSuccessCopy() {
1173
+ if (!this.oraclesEnabled) {
1174
+ throw new Error(
1175
+ 'Oracle access from the root of a TXe test are not enabled. Please use env._ to interact with the oracles.',
1176
+ );
1177
+ }
1178
+
826
1179
  const success = (this.typedOracle as TXE).avmOpcodeSuccessCopy();
827
1180
  return toForeignCallResult([toSingle(new Fr(success))]);
828
1181
  }
1182
+
1183
+ async privateCallNewFlow(
1184
+ from: ForeignCallSingle,
1185
+ targetContractAddress: ForeignCallSingle,
1186
+ functionSelector: ForeignCallSingle,
1187
+ _argsLength: ForeignCallSingle,
1188
+ args: ForeignCallArray,
1189
+ argsHash: ForeignCallSingle,
1190
+ isStaticCall: ForeignCallSingle,
1191
+ ) {
1192
+ const result = await (this.typedOracle as TXE).privateCallNewFlow(
1193
+ addressFromSingle(from),
1194
+ addressFromSingle(targetContractAddress),
1195
+ FunctionSelector.fromField(fromSingle(functionSelector)),
1196
+ fromArray(args),
1197
+ fromSingle(argsHash),
1198
+ fromSingle(isStaticCall).toBool(),
1199
+ );
1200
+
1201
+ return toForeignCallResult([toArray([result.endSideEffectCounter, result.returnsHash, result.txHash])]);
1202
+ }
1203
+
1204
+ disableOracles() {
1205
+ this.oraclesEnabled = false;
1206
+ }
1207
+
1208
+ enableOracles() {
1209
+ this.oraclesEnabled = true;
1210
+ }
1211
+
1212
+ async simulateUtilityFunction(
1213
+ targetContractAddress: ForeignCallSingle,
1214
+ functionSelector: ForeignCallSingle,
1215
+ argsHash: ForeignCallSingle,
1216
+ ) {
1217
+ const result = await (this.typedOracle as TXE).simulateUtilityFunction(
1218
+ addressFromSingle(targetContractAddress),
1219
+ FunctionSelector.fromField(fromSingle(functionSelector)),
1220
+ fromSingle(argsHash),
1221
+ );
1222
+
1223
+ return toForeignCallResult([toSingle(result)]);
1224
+ }
829
1225
  }