@aztec/txe 0.0.1-commit.3e3d0c9cd → 0.0.1-commit.3f5453c7b

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 (39) hide show
  1. package/dest/oracle/txe_oracle_top_level_context.d.ts +10 -4
  2. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  3. package/dest/oracle/txe_oracle_top_level_context.js +29 -16
  4. package/dest/rpc_translator.d.ts +55 -19
  5. package/dest/rpc_translator.d.ts.map +1 -1
  6. package/dest/rpc_translator.js +162 -39
  7. package/dest/state_machine/archiver.d.ts +1 -1
  8. package/dest/state_machine/archiver.d.ts.map +1 -1
  9. package/dest/state_machine/archiver.js +2 -1
  10. package/dest/state_machine/dummy_p2p_client.d.ts +3 -2
  11. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  12. package/dest/state_machine/dummy_p2p_client.js +5 -2
  13. package/dest/state_machine/global_variable_builder.d.ts +9 -4
  14. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  15. package/dest/state_machine/global_variable_builder.js +9 -3
  16. package/dest/state_machine/index.d.ts +1 -1
  17. package/dest/state_machine/index.d.ts.map +1 -1
  18. package/dest/state_machine/index.js +2 -2
  19. package/dest/state_machine/mock_epoch_cache.d.ts +18 -3
  20. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  21. package/dest/state_machine/mock_epoch_cache.js +35 -2
  22. package/dest/txe_session.d.ts +4 -3
  23. package/dest/txe_session.d.ts.map +1 -1
  24. package/dest/txe_session.js +18 -12
  25. package/dest/util/encoding.d.ts +69 -1
  26. package/dest/util/encoding.d.ts.map +1 -1
  27. package/dest/util/txe_public_contract_data_source.d.ts +1 -1
  28. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  29. package/dest/util/txe_public_contract_data_source.js +1 -3
  30. package/package.json +15 -15
  31. package/src/oracle/txe_oracle_top_level_context.ts +40 -21
  32. package/src/rpc_translator.ts +192 -38
  33. package/src/state_machine/archiver.ts +1 -0
  34. package/src/state_machine/dummy_p2p_client.ts +6 -2
  35. package/src/state_machine/global_variable_builder.ts +18 -3
  36. package/src/state_machine/index.ts +3 -1
  37. package/src/state_machine/mock_epoch_cache.ts +46 -3
  38. package/src/txe_session.ts +20 -10
  39. package/src/util/txe_public_contract_data_source.ts +0 -2
@@ -1,9 +1,7 @@
1
1
  import {
2
2
  CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS,
3
- DEFAULT_DA_GAS_LIMIT,
4
- DEFAULT_L2_GAS_LIMIT,
5
- DEFAULT_TEARDOWN_DA_GAS_LIMIT,
6
- DEFAULT_TEARDOWN_L2_GAS_LIMIT,
3
+ MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT,
4
+ MAX_PROCESSABLE_L2_GAS,
7
5
  NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
8
6
  } from '@aztec/constants';
9
7
  import { BlockNumber } from '@aztec/foundation/branded-types';
@@ -12,13 +10,14 @@ import { Fr } from '@aztec/foundation/curves/bn254';
12
10
  import { LogLevels, type Logger, applyStringFormatting, createLogger } from '@aztec/foundation/log';
13
11
  import { TestDateProvider } from '@aztec/foundation/timer';
14
12
  import type { KeyStore } from '@aztec/key-store';
15
- import type { AccessScopes } from '@aztec/pxe/client/lazy';
16
13
  import {
17
14
  AddressStore,
15
+ CapsuleService,
18
16
  CapsuleStore,
19
17
  type ContractStore,
18
+ type ContractSyncService,
20
19
  NoteStore,
21
- ORACLE_VERSION,
20
+ ORACLE_VERSION_MAJOR,
22
21
  PrivateEventStore,
23
22
  RecipientTaggingStore,
24
23
  SenderAddressBookStore,
@@ -56,7 +55,13 @@ import { AuthWitness } from '@aztec/stdlib/auth-witness';
56
55
  import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
57
56
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
58
57
  import { type ContractInstanceWithAddress, computePartialAddress } from '@aztec/stdlib/contract';
59
- import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
58
+ import {
59
+ FALLBACK_TEARDOWN_DA_GAS_LIMIT,
60
+ FALLBACK_TEARDOWN_L2_GAS_LIMIT,
61
+ Gas,
62
+ GasFees,
63
+ GasSettings,
64
+ } from '@aztec/stdlib/gas';
60
65
  import { computeCalldataHash, computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
61
66
  import {
62
67
  PartialPrivateTailPublicInputsForPublic,
@@ -111,17 +116,30 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
111
116
  private version: Fr,
112
117
  private chainId: Fr,
113
118
  private authwits: Map<string, AuthWitness>,
119
+ private readonly contractSyncService: ContractSyncService,
114
120
  ) {
115
121
  this.logger = createLogger('txe:top_level_context');
116
122
  this.logger.debug('Entering Top Level Context');
117
123
  }
118
124
 
119
- assertCompatibleOracleVersion(version: number): void {
120
- if (version !== ORACLE_VERSION) {
125
+ private contractOracleVersion: { major: number; minor: number } | undefined;
126
+
127
+ assertCompatibleOracleVersion(major: number, minor: number): void {
128
+ if (major !== ORACLE_VERSION_MAJOR) {
129
+ const hint =
130
+ major > ORACLE_VERSION_MAJOR
131
+ ? 'The contract was compiled with a newer version of Aztec.nr than this aztec cli version supports. Upgrade your aztec cli version to a compatible version.'
132
+ : 'The contract was compiled with an older version of Aztec.nr than this aztec cli version supports. Recompile the contract with a compatible version of Aztec.nr.';
121
133
  throw new Error(
122
- `Incompatible oracle version. TXE is using version '${ORACLE_VERSION}', but got a request for '${version}'.`,
134
+ `Incompatible aztec cli version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle major version ${ORACLE_VERSION_MAJOR}, got ${major})`,
123
135
  );
124
136
  }
137
+ this.contractOracleVersion = { major, minor };
138
+ }
139
+
140
+ // Prefixed with "nonOracleFunction" as it is not used as an oracle handler.
141
+ nonOracleFunctionGetContractOracleVersion(): { major: number; minor: number } | undefined {
142
+ return this.contractOracleVersion;
125
143
  }
126
144
 
127
145
  // This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
@@ -322,7 +340,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
322
340
  const effectiveScopes = from.isZero() ? [] : [from];
323
341
 
324
342
  // Sync notes before executing private function to discover notes from previous transactions
325
- const utilityExecutor = async (call: FunctionCall, execScopes: AccessScopes) => {
343
+ const utilityExecutor = async (call: FunctionCall, execScopes: AztecAddress[]) => {
326
344
  await this.executeUtilityCall(call, execScopes, jobId);
327
345
  };
328
346
 
@@ -340,8 +358,8 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
340
358
 
341
359
  const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
342
360
 
343
- const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
344
- const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
361
+ const gasLimits = new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
362
+ const teardownGasLimits = new Gas(FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT);
345
363
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
346
364
 
347
365
  const txContext = new TxContext(this.chainId, this.version, gasSettings);
@@ -376,7 +394,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
376
394
  senderTaggingStore: this.senderTaggingStore,
377
395
  recipientTaggingStore: this.recipientTaggingStore,
378
396
  senderAddressBookStore: this.senderAddressBookStore,
379
- capsuleStore: this.capsuleStore,
397
+ capsuleService: new CapsuleService(this.capsuleStore, effectiveScopes),
380
398
  privateEventStore: this.privateEventStore,
381
399
  contractSyncService: this.stateMachine.contractSyncService,
382
400
  jobId,
@@ -410,7 +428,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
410
428
  );
411
429
  const publicFunctionsCalldata = await Promise.all(
412
430
  publicCallRequests.map(async r => {
413
- const calldata = await privateExecutionOracle.loadFromExecutionCache(r.calldataHash);
431
+ const calldata = await privateExecutionOracle.getHashPreimage(r.calldataHash);
414
432
  return new HashedValues(calldata, r.calldataHash);
415
433
  }),
416
434
  );
@@ -536,9 +554,9 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
536
554
 
537
555
  const blockNumber = await this.getNextBlockNumber();
538
556
 
539
- const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
557
+ const gasLimits = new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
540
558
 
541
- const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
559
+ const teardownGasLimits = new Gas(FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT);
542
560
 
543
561
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
544
562
 
@@ -700,7 +718,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
700
718
  },
701
719
  blockHeader,
702
720
  jobId,
703
- 'ALL_SCOPES',
721
+ await this.keyStore.getAccounts(),
704
722
  );
705
723
 
706
724
  const call = FunctionCall.from({
@@ -714,10 +732,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
714
732
  returnTypes: [],
715
733
  });
716
734
 
717
- return this.executeUtilityCall(call, 'ALL_SCOPES', jobId);
735
+ return this.executeUtilityCall(call, await this.keyStore.getAccounts(), jobId);
718
736
  }
719
737
 
720
- private async executeUtilityCall(call: FunctionCall, scopes: AccessScopes, jobId: string): Promise<Fr[]> {
738
+ private async executeUtilityCall(call: FunctionCall, scopes: AztecAddress[], jobId: string): Promise<Fr[]> {
721
739
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
722
740
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
723
741
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
@@ -742,9 +760,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
742
760
  aztecNode: this.stateMachine.node,
743
761
  recipientTaggingStore: this.recipientTaggingStore,
744
762
  senderAddressBookStore: this.senderAddressBookStore,
745
- capsuleStore: this.capsuleStore,
763
+ capsuleService: new CapsuleService(this.capsuleStore, scopes),
746
764
  privateEventStore: this.privateEventStore,
747
765
  messageContextService: this.stateMachine.messageContextService,
766
+ contractSyncService: this.contractSyncService,
748
767
  jobId,
749
768
  scopes,
750
769
  });
@@ -264,10 +264,11 @@ export class RPCTranslator {
264
264
  // PXE oracles
265
265
 
266
266
  // eslint-disable-next-line camelcase
267
- aztec_utl_assertCompatibleOracleVersion(foreignVersion: ForeignCallSingle) {
268
- const version = fromSingle(foreignVersion).toNumber();
267
+ aztec_utl_assertCompatibleOracleVersionV2(foreignMajor: ForeignCallSingle, foreignMinor: ForeignCallSingle) {
268
+ const major = fromSingle(foreignMajor).toNumber();
269
+ const minor = fromSingle(foreignMinor).toNumber();
269
270
 
270
- this.handlerAsMisc().assertCompatibleOracleVersion(version);
271
+ this.handlerAsMisc().assertCompatibleOracleVersion(major, minor);
271
272
 
272
273
  return toForeignCallResult([]);
273
274
  }
@@ -339,20 +340,20 @@ export class RPCTranslator {
339
340
  }
340
341
 
341
342
  // eslint-disable-next-line camelcase
342
- aztec_prv_storeInExecutionCache(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
343
+ aztec_prv_setHashPreimage(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
343
344
  const values = fromArray(foreignValues);
344
345
  const hash = fromSingle(foreignHash);
345
346
 
346
- this.handlerAsPrivate().storeInExecutionCache(values, hash);
347
+ this.handlerAsPrivate().setHashPreimage(values, hash);
347
348
 
348
349
  return toForeignCallResult([]);
349
350
  }
350
351
 
351
352
  // eslint-disable-next-line camelcase
352
- async aztec_prv_loadFromExecutionCache(foreignHash: ForeignCallSingle) {
353
+ async aztec_prv_getHashPreimage(foreignHash: ForeignCallSingle) {
353
354
  const hash = fromSingle(foreignHash);
354
355
 
355
- const returns = await this.handlerAsPrivate().loadFromExecutionCache(hash);
356
+ const returns = await this.handlerAsPrivate().getHashPreimage(hash);
356
357
 
357
358
  return toForeignCallResult([toArray(returns)]);
358
359
  }
@@ -378,7 +379,7 @@ export class RPCTranslator {
378
379
  }
379
380
 
380
381
  // eslint-disable-next-line camelcase
381
- async aztec_utl_storageRead(
382
+ async aztec_utl_getFromPublicStorage(
382
383
  foreignBlockHash: ForeignCallSingle,
383
384
  foreignContractAddress: ForeignCallSingle,
384
385
  foreignStartStorageSlot: ForeignCallSingle,
@@ -389,7 +390,7 @@ export class RPCTranslator {
389
390
  const startStorageSlot = fromSingle(foreignStartStorageSlot);
390
391
  const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
391
392
 
392
- const values = await this.handlerAsUtility().storageRead(
393
+ const values = await this.handlerAsUtility().getFromPublicStorage(
393
394
  blockHash,
394
395
  contractAddress,
395
396
  startStorageSlot,
@@ -556,10 +557,10 @@ export class RPCTranslator {
556
557
  }
557
558
 
558
559
  // eslint-disable-next-line camelcase
559
- async aztec_utl_checkNullifierExists(foreignInnerNullifier: ForeignCallSingle) {
560
+ async aztec_utl_doesNullifierExist(foreignInnerNullifier: ForeignCallSingle) {
560
561
  const innerNullifier = fromSingle(foreignInnerNullifier);
561
562
 
562
- const exists = await this.handlerAsUtility().checkNullifierExists(innerNullifier);
563
+ const exists = await this.handlerAsUtility().doesNullifierExist(innerNullifier);
563
564
 
564
565
  return toForeignCallResult([toSingle(new Fr(exists))]);
565
566
  }
@@ -582,10 +583,10 @@ export class RPCTranslator {
582
583
  }
583
584
 
584
585
  // eslint-disable-next-line camelcase
585
- async aztec_utl_tryGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
586
+ async aztec_utl_getPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
586
587
  const address = addressFromSingle(foreignAddress);
587
588
 
588
- const result = await this.handlerAsUtility().tryGetPublicKeysAndPartialAddress(address);
589
+ const result = await this.handlerAsUtility().getPublicKeysAndPartialAddress(address);
589
590
 
590
591
  // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
591
592
  // with two fields: `some` (a boolean) and `value` (a field array in this case).
@@ -652,7 +653,7 @@ export class RPCTranslator {
652
653
  }
653
654
 
654
655
  // eslint-disable-next-line camelcase
655
- public aztec_prv_validatePublicCalldata(_foreignCalldataHash: ForeignCallSingle) {
656
+ public aztec_prv_assertValidPublicCalldata(_foreignCalldataHash: ForeignCallSingle) {
656
657
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
657
658
  }
658
659
 
@@ -662,9 +663,9 @@ export class RPCTranslator {
662
663
  }
663
664
 
664
665
  // eslint-disable-next-line camelcase
665
- public async aztec_prv_inRevertiblePhase(foreignSideEffectCounter: ForeignCallSingle) {
666
+ public async aztec_prv_isExecutionInRevertiblePhase(foreignSideEffectCounter: ForeignCallSingle) {
666
667
  const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
667
- const isRevertible = await this.handlerAsPrivate().inRevertiblePhase(sideEffectCounter);
668
+ const isRevertible = await this.handlerAsPrivate().isExecutionInRevertiblePhase(sideEffectCounter);
668
669
  return toForeignCallResult([toSingle(new Fr(isRevertible))]);
669
670
  }
670
671
 
@@ -738,14 +739,25 @@ export class RPCTranslator {
738
739
  }
739
740
 
740
741
  // eslint-disable-next-line camelcase
741
- async aztec_utl_fetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
742
+ async aztec_utl_getPendingTaggedLogs(
743
+ foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle,
744
+ foreignScope: ForeignCallSingle,
745
+ ) {
742
746
  const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
747
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
743
748
 
744
- await this.handlerAsUtility().fetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
749
+ await this.handlerAsUtility().getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot, scope);
745
750
 
746
751
  return toForeignCallResult([]);
747
752
  }
748
753
 
754
+ // eslint-disable-next-line camelcase
755
+ async aztec_utl_getPendingTaggedLogs_v2(foreignScope: ForeignCallSingle) {
756
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
757
+ const slot = await this.handlerAsUtility().getPendingTaggedLogsV2(scope);
758
+ return toForeignCallResult([toSingle(slot)]);
759
+ }
760
+
749
761
  // eslint-disable-next-line camelcase
750
762
  public async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(
751
763
  foreignContractAddress: ForeignCallSingle,
@@ -753,12 +765,14 @@ export class RPCTranslator {
753
765
  foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
754
766
  foreignMaxNotePackedLen: ForeignCallSingle,
755
767
  foreignMaxEventSerializedLen: ForeignCallSingle,
768
+ foreignScope: ForeignCallSingle,
756
769
  ) {
757
770
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
758
771
  const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
759
772
  const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
760
773
  const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
761
774
  const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
775
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
762
776
 
763
777
  await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
764
778
  contractAddress,
@@ -766,75 +780,125 @@ export class RPCTranslator {
766
780
  eventValidationRequestsArrayBaseSlot,
767
781
  maxNotePackedLen,
768
782
  maxEventSerializedLen,
783
+ scope,
769
784
  );
770
785
 
771
786
  return toForeignCallResult([]);
772
787
  }
773
788
 
774
789
  // eslint-disable-next-line camelcase
775
- public async aztec_utl_bulkRetrieveLogs(
790
+ public async aztec_utl_validateAndStoreEnqueuedNotesAndEvents_v2(
791
+ foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
792
+ foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
793
+ foreignMaxNotePackedLen: ForeignCallSingle,
794
+ foreignMaxEventSerializedLen: ForeignCallSingle,
795
+ foreignScope: ForeignCallSingle,
796
+ ) {
797
+ const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
798
+ const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
799
+ const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
800
+ const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
801
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
802
+
803
+ await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEventsV2(
804
+ noteValidationRequestsArrayBaseSlot,
805
+ eventValidationRequestsArrayBaseSlot,
806
+ maxNotePackedLen,
807
+ maxEventSerializedLen,
808
+ scope,
809
+ );
810
+
811
+ return toForeignCallResult([]);
812
+ }
813
+
814
+ // eslint-disable-next-line camelcase
815
+ public async aztec_utl_getLogsByTag(
776
816
  foreignContractAddress: ForeignCallSingle,
777
817
  foreignLogRetrievalRequestsArrayBaseSlot: ForeignCallSingle,
778
818
  foreignLogRetrievalResponsesArrayBaseSlot: ForeignCallSingle,
819
+ foreignScope: ForeignCallSingle,
779
820
  ) {
780
821
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
781
822
  const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
782
823
  const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
824
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
783
825
 
784
- await this.handlerAsUtility().bulkRetrieveLogs(
826
+ await this.handlerAsUtility().getLogsByTag(
785
827
  contractAddress,
786
828
  logRetrievalRequestsArrayBaseSlot,
787
829
  logRetrievalResponsesArrayBaseSlot,
830
+ scope,
788
831
  );
789
832
 
790
833
  return toForeignCallResult([]);
791
834
  }
792
835
 
793
836
  // eslint-disable-next-line camelcase
794
- public async aztec_utl_utilityResolveMessageContexts(
837
+ public async aztec_utl_getMessageContextsByTxHash(
795
838
  foreignContractAddress: ForeignCallSingle,
796
839
  foreignMessageContextRequestsArrayBaseSlot: ForeignCallSingle,
797
840
  foreignMessageContextResponsesArrayBaseSlot: ForeignCallSingle,
841
+ foreignScope: ForeignCallSingle,
798
842
  ) {
799
843
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
800
844
  const messageContextRequestsArrayBaseSlot = fromSingle(foreignMessageContextRequestsArrayBaseSlot);
801
845
  const messageContextResponsesArrayBaseSlot = fromSingle(foreignMessageContextResponsesArrayBaseSlot);
846
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
802
847
 
803
- await this.handlerAsUtility().utilityResolveMessageContexts(
848
+ await this.handlerAsUtility().getMessageContextsByTxHash(
804
849
  contractAddress,
805
850
  messageContextRequestsArrayBaseSlot,
806
851
  messageContextResponsesArrayBaseSlot,
852
+ scope,
807
853
  );
808
854
 
809
855
  return toForeignCallResult([]);
810
856
  }
811
857
 
812
858
  // eslint-disable-next-line camelcase
813
- async aztec_utl_storeCapsule(
859
+ async aztec_utl_getLogsByTag_v2(foreignRequestArrayBaseSlot: ForeignCallSingle) {
860
+ const requestArrayBaseSlot = fromSingle(foreignRequestArrayBaseSlot);
861
+ const responseSlot = await this.handlerAsUtility().getLogsByTagV2(requestArrayBaseSlot);
862
+ return toForeignCallResult([toSingle(responseSlot)]);
863
+ }
864
+
865
+ // eslint-disable-next-line camelcase
866
+ async aztec_utl_getMessageContextsByTxHash_v2(foreignRequestArrayBaseSlot: ForeignCallSingle) {
867
+ const requestArrayBaseSlot = fromSingle(foreignRequestArrayBaseSlot);
868
+ const responseSlot = await this.handlerAsUtility().getMessageContextsByTxHashV2(requestArrayBaseSlot);
869
+ return toForeignCallResult([toSingle(responseSlot)]);
870
+ }
871
+
872
+ // eslint-disable-next-line camelcase
873
+ aztec_utl_setCapsule(
814
874
  foreignContractAddress: ForeignCallSingle,
815
875
  foreignSlot: ForeignCallSingle,
816
876
  foreignCapsule: ForeignCallArray,
877
+ foreignScope: ForeignCallSingle,
817
878
  ) {
818
879
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
819
880
  const slot = fromSingle(foreignSlot);
820
881
  const capsule = fromArray(foreignCapsule);
882
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
821
883
 
822
- await this.handlerAsUtility().storeCapsule(contractAddress, slot, capsule);
884
+ this.handlerAsUtility().setCapsule(contractAddress, slot, capsule, scope);
823
885
 
824
886
  return toForeignCallResult([]);
825
887
  }
826
888
 
827
889
  // eslint-disable-next-line camelcase
828
- async aztec_utl_loadCapsule(
890
+ async aztec_utl_getCapsule(
829
891
  foreignContractAddress: ForeignCallSingle,
830
892
  foreignSlot: ForeignCallSingle,
831
893
  foreignTSize: ForeignCallSingle,
894
+ foreignScope: ForeignCallSingle,
832
895
  ) {
833
896
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
834
897
  const slot = fromSingle(foreignSlot);
835
898
  const tSize = fromSingle(foreignTSize).toNumber();
899
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
836
900
 
837
- const values = await this.handlerAsUtility().loadCapsule(contractAddress, slot);
901
+ const values = await this.handlerAsUtility().getCapsule(contractAddress, slot, scope);
838
902
 
839
903
  // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
840
904
  // with two fields: `some` (a boolean) and `value` (a field array in this case).
@@ -848,11 +912,16 @@ export class RPCTranslator {
848
912
  }
849
913
 
850
914
  // eslint-disable-next-line camelcase
851
- async aztec_utl_deleteCapsule(foreignContractAddress: ForeignCallSingle, foreignSlot: ForeignCallSingle) {
915
+ aztec_utl_deleteCapsule(
916
+ foreignContractAddress: ForeignCallSingle,
917
+ foreignSlot: ForeignCallSingle,
918
+ foreignScope: ForeignCallSingle,
919
+ ) {
852
920
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
853
921
  const slot = fromSingle(foreignSlot);
922
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
854
923
 
855
- await this.handlerAsUtility().deleteCapsule(contractAddress, slot);
924
+ this.handlerAsUtility().deleteCapsule(contractAddress, slot, scope);
856
925
 
857
926
  return toForeignCallResult([]);
858
927
  }
@@ -863,14 +932,74 @@ export class RPCTranslator {
863
932
  foreignSrcSlot: ForeignCallSingle,
864
933
  foreignDstSlot: ForeignCallSingle,
865
934
  foreignNumEntries: ForeignCallSingle,
935
+ foreignScope: ForeignCallSingle,
866
936
  ) {
867
937
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
868
938
  const srcSlot = fromSingle(foreignSrcSlot);
869
939
  const dstSlot = fromSingle(foreignDstSlot);
870
940
  const numEntries = fromSingle(foreignNumEntries).toNumber();
941
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
942
+
943
+ await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, scope);
944
+
945
+ return toForeignCallResult([]);
946
+ }
947
+
948
+ // eslint-disable-next-line camelcase
949
+ aztec_utl_pushEphemeral(foreignSlot: ForeignCallSingle, foreignElements: ForeignCallArray) {
950
+ const slot = fromSingle(foreignSlot);
951
+ const elements = fromArray(foreignElements);
952
+ const newLen = this.handlerAsUtility().pushEphemeral(slot, elements);
953
+ return toForeignCallResult([toSingle(new Fr(newLen))]);
954
+ }
955
+
956
+ // eslint-disable-next-line camelcase
957
+ aztec_utl_popEphemeral(foreignSlot: ForeignCallSingle) {
958
+ const slot = fromSingle(foreignSlot);
959
+ const element = this.handlerAsUtility().popEphemeral(slot);
960
+ return toForeignCallResult([toArray(element)]);
961
+ }
871
962
 
872
- await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
963
+ // eslint-disable-next-line camelcase
964
+ aztec_utl_getEphemeral(foreignSlot: ForeignCallSingle, foreignIndex: ForeignCallSingle) {
965
+ const slot = fromSingle(foreignSlot);
966
+ const index = fromSingle(foreignIndex).toNumber();
967
+ const element = this.handlerAsUtility().getEphemeral(slot, index);
968
+ return toForeignCallResult([toArray(element)]);
969
+ }
873
970
 
971
+ // eslint-disable-next-line camelcase
972
+ aztec_utl_setEphemeral(
973
+ foreignSlot: ForeignCallSingle,
974
+ foreignIndex: ForeignCallSingle,
975
+ foreignElements: ForeignCallArray,
976
+ ) {
977
+ const slot = fromSingle(foreignSlot);
978
+ const index = fromSingle(foreignIndex).toNumber();
979
+ const elements = fromArray(foreignElements);
980
+ this.handlerAsUtility().setEphemeral(slot, index, elements);
981
+ return toForeignCallResult([]);
982
+ }
983
+
984
+ // eslint-disable-next-line camelcase
985
+ aztec_utl_getEphemeralLen(foreignSlot: ForeignCallSingle) {
986
+ const slot = fromSingle(foreignSlot);
987
+ const len = this.handlerAsUtility().getEphemeralLen(slot);
988
+ return toForeignCallResult([toSingle(new Fr(len))]);
989
+ }
990
+
991
+ // eslint-disable-next-line camelcase
992
+ aztec_utl_removeEphemeral(foreignSlot: ForeignCallSingle, foreignIndex: ForeignCallSingle) {
993
+ const slot = fromSingle(foreignSlot);
994
+ const index = fromSingle(foreignIndex).toNumber();
995
+ this.handlerAsUtility().removeEphemeral(slot, index);
996
+ return toForeignCallResult([]);
997
+ }
998
+
999
+ // eslint-disable-next-line camelcase
1000
+ aztec_utl_clearEphemeral(foreignSlot: ForeignCallSingle) {
1001
+ const slot = fromSingle(foreignSlot);
1002
+ this.handlerAsUtility().clearEphemeral(slot);
874
1003
  return toForeignCallResult([]);
875
1004
  }
876
1005
 
@@ -878,9 +1007,8 @@ export class RPCTranslator {
878
1007
  // The compiler didn't throw an error, so it took me a while to learn of the existence of this file, and that I need
879
1008
  // to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
880
1009
  // existence of a txe_oracle method?
881
- // TODO(F-452): Return Option and wrap in try/catch so BB exceptions don't crash TXE.
882
1010
  // eslint-disable-next-line camelcase
883
- async aztec_utl_aes128Decrypt(
1011
+ async aztec_utl_decryptAes128(
884
1012
  foreignCiphertextBVecStorage: ForeignCallArray,
885
1013
  foreignCiphertextLength: ForeignCallSingle,
886
1014
  foreignIv: ForeignCallArray,
@@ -890,11 +1018,18 @@ export class RPCTranslator {
890
1018
  const iv = fromUintArray(foreignIv, 8);
891
1019
  const symKey = fromUintArray(foreignSymKey, 8);
892
1020
 
893
- const plaintextBuffer = await this.handlerAsUtility().aes128Decrypt(ciphertext, iv, symKey);
894
-
895
- return toForeignCallResult(
896
- arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length),
897
- );
1021
+ // Noir Option<BoundedVec> is encoded as [is_some: Field, storage: Field[], length: Field].
1022
+ try {
1023
+ const plaintextBuffer = await this.handlerAsUtility().decryptAes128(ciphertext, iv, symKey);
1024
+ const [storage, length] = arrayToBoundedVec(
1025
+ bufferToU8Array(plaintextBuffer),
1026
+ foreignCiphertextBVecStorage.length,
1027
+ );
1028
+ return toForeignCallResult([toSingle(new Fr(1)), storage, length]);
1029
+ } catch {
1030
+ const zeroStorage = toArray(Array(foreignCiphertextBVecStorage.length).fill(new Fr(0)));
1031
+ return toForeignCallResult([toSingle(new Fr(0)), zeroStorage, toSingle(new Fr(0))]);
1032
+ }
898
1033
  }
899
1034
 
900
1035
  // eslint-disable-next-line camelcase
@@ -903,6 +1038,7 @@ export class RPCTranslator {
903
1038
  foreignEphPKField0: ForeignCallSingle,
904
1039
  foreignEphPKField1: ForeignCallSingle,
905
1040
  foreignEphPKField2: ForeignCallSingle,
1041
+ foreignContractAddress: ForeignCallSingle,
906
1042
  ) {
907
1043
  const address = AztecAddress.fromField(fromSingle(foreignAddress));
908
1044
  const ephPK = Point.fromFields([
@@ -910,10 +1046,28 @@ export class RPCTranslator {
910
1046
  fromSingle(foreignEphPKField1),
911
1047
  fromSingle(foreignEphPKField2),
912
1048
  ]);
1049
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
1050
+
1051
+ const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK, contractAddress);
1052
+
1053
+ return toForeignCallResult([toSingle(secret)]);
1054
+ }
1055
+
1056
+ // eslint-disable-next-line camelcase
1057
+ aztec_utl_setContractSyncCacheInvalid(
1058
+ foreignContractAddress: ForeignCallSingle,
1059
+ foreignScopes: ForeignCallArray,
1060
+ foreignScopeCount: ForeignCallSingle,
1061
+ ) {
1062
+ const contractAddress = addressFromSingle(foreignContractAddress);
1063
+ const count = fromSingle(foreignScopeCount).toNumber();
1064
+ const scopes = fromArray(foreignScopes)
1065
+ .slice(0, count)
1066
+ .map(f => new AztecAddress(f));
913
1067
 
914
- const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK);
1068
+ this.handlerAsUtility().setContractSyncCacheInvalid(contractAddress, scopes);
915
1069
 
916
- return toForeignCallResult(secret.toFields().map(toSingle));
1070
+ return Promise.resolve(toForeignCallResult([]));
917
1071
  }
918
1072
 
919
1073
  // eslint-disable-next-line camelcase
@@ -76,6 +76,7 @@ export class TXEArchiver extends ArchiverDataSourceBase {
76
76
  proven: tipId,
77
77
  finalized: tipId,
78
78
  checkpointed: tipId,
79
+ proposedCheckpoint: tipId,
79
80
  };
80
81
  }
81
82
 
@@ -61,8 +61,12 @@ export class DummyP2P implements P2P {
61
61
  throw new Error('DummyP2P does not implement "registerBlockProposalHandler"');
62
62
  }
63
63
 
64
- public registerCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
65
- throw new Error('DummyP2P does not implement "registerCheckpointProposalHandler"');
64
+ public registerValidatorCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
65
+ throw new Error('DummyP2P does not implement "registerValidatorCheckpointProposalHandler"');
66
+ }
67
+
68
+ public registerAllNodesCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
69
+ throw new Error('DummyP2P does not implement "registerAllNodesCheckpointProposalHandler"');
66
70
  }
67
71
 
68
72
  public requestTxs(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
@@ -1,15 +1,29 @@
1
+ import type { SimulationOverridesPlan } from '@aztec/ethereum/contracts';
1
2
  import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { times } from '@aztec/foundation/collection';
2
4
  import type { EthAddress } from '@aztec/foundation/eth-address';
3
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
- import { GasFees } from '@aztec/stdlib/gas';
6
+ import { FEE_ORACLE_LAG, GasFees } from '@aztec/stdlib/gas';
5
7
  import { makeGlobalVariables } from '@aztec/stdlib/testing';
6
- import { type CheckpointGlobalVariables, type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
8
+ import {
9
+ type CheckpointGlobalVariables,
10
+ type FeeProvider,
11
+ type GlobalVariableBuilder,
12
+ GlobalVariables,
13
+ } from '@aztec/stdlib/tx';
7
14
 
8
- export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
15
+ /** Simple FeeProvider for TXE that returns zero fees. */
16
+ export class TXEFeeProvider implements FeeProvider {
9
17
  public getCurrentMinFees(): Promise<GasFees> {
10
18
  return Promise.resolve(new GasFees(0, 0));
11
19
  }
12
20
 
21
+ public getPredictedMinFees(): Promise<GasFees[]> {
22
+ return Promise.resolve(times(FEE_ORACLE_LAG, () => new GasFees(0, 0)));
23
+ }
24
+ }
25
+
26
+ export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
13
27
  public buildGlobalVariables(
14
28
  _blockNumber: BlockNumber,
15
29
  _coinbase: EthAddress,
@@ -23,6 +37,7 @@ export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
23
37
  _coinbase: EthAddress,
24
38
  _feeRecipient: AztecAddress,
25
39
  _slotNumber: SlotNumber,
40
+ _simulationOverridesPlan?: SimulationOverridesPlan,
26
41
  ): Promise<CheckpointGlobalVariables> {
27
42
  const vars = makeGlobalVariables();
28
43
  return Promise.resolve({