@aztec/txe 0.0.1-commit.f504929 → 0.0.1-commit.f650c0a5c

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 (43) 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 +32 -17
  4. package/dest/rpc_translator.d.ts +58 -20
  5. package/dest/rpc_translator.d.ts.map +1 -1
  6. package/dest/rpc_translator.js +171 -41
  7. package/dest/state_machine/archiver.d.ts +3 -3
  8. package/dest/state_machine/archiver.d.ts.map +1 -1
  9. package/dest/state_machine/archiver.js +7 -8
  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 +3 -3
  14. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  15. package/dest/state_machine/global_variable_builder.js +1 -1
  16. package/dest/state_machine/index.d.ts +4 -2
  17. package/dest/state_machine/index.d.ts.map +1 -1
  18. package/dest/state_machine/index.js +7 -3
  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/state_machine/synchronizer.d.ts +5 -5
  23. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  24. package/dest/state_machine/synchronizer.js +3 -3
  25. package/dest/txe_session.d.ts +4 -3
  26. package/dest/txe_session.d.ts.map +1 -1
  27. package/dest/txe_session.js +21 -12
  28. package/dest/util/encoding.d.ts +69 -1
  29. package/dest/util/encoding.d.ts.map +1 -1
  30. package/dest/util/txe_public_contract_data_source.d.ts +1 -1
  31. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  32. package/dest/util/txe_public_contract_data_source.js +1 -3
  33. package/package.json +15 -15
  34. package/src/oracle/txe_oracle_top_level_context.ts +42 -21
  35. package/src/rpc_translator.ts +216 -51
  36. package/src/state_machine/archiver.ts +6 -5
  37. package/src/state_machine/dummy_p2p_client.ts +6 -2
  38. package/src/state_machine/global_variable_builder.ts +7 -1
  39. package/src/state_machine/index.ts +6 -1
  40. package/src/state_machine/mock_epoch_cache.ts +46 -3
  41. package/src/state_machine/synchronizer.ts +4 -4
  42. package/src/txe_session.ts +23 -10
  43. 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,
@@ -387,6 +405,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
387
405
  // contract would perform, including setting senderForTags.
388
406
  senderForTags: from,
389
407
  simulator,
408
+ messageContextService: this.stateMachine.messageContextService,
390
409
  });
391
410
 
392
411
  // Note: This is a slight modification of simulator.run without any of the checks. Maybe we should modify simulator.run with a boolean value to skip checks.
@@ -409,7 +428,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
409
428
  );
410
429
  const publicFunctionsCalldata = await Promise.all(
411
430
  publicCallRequests.map(async r => {
412
- const calldata = await privateExecutionOracle.loadFromExecutionCache(r.calldataHash);
431
+ const calldata = await privateExecutionOracle.getHashPreimage(r.calldataHash);
413
432
  return new HashedValues(calldata, r.calldataHash);
414
433
  }),
415
434
  );
@@ -535,9 +554,9 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
535
554
 
536
555
  const blockNumber = await this.getNextBlockNumber();
537
556
 
538
- 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);
539
558
 
540
- 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);
541
560
 
542
561
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
543
562
 
@@ -699,7 +718,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
699
718
  },
700
719
  blockHeader,
701
720
  jobId,
702
- 'ALL_SCOPES',
721
+ await this.keyStore.getAccounts(),
703
722
  );
704
723
 
705
724
  const call = FunctionCall.from({
@@ -713,10 +732,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
713
732
  returnTypes: [],
714
733
  });
715
734
 
716
- return this.executeUtilityCall(call, 'ALL_SCOPES', jobId);
735
+ return this.executeUtilityCall(call, await this.keyStore.getAccounts(), jobId);
717
736
  }
718
737
 
719
- private async executeUtilityCall(call: FunctionCall, scopes: AccessScopes, jobId: string): Promise<Fr[]> {
738
+ private async executeUtilityCall(call: FunctionCall, scopes: AztecAddress[], jobId: string): Promise<Fr[]> {
720
739
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
721
740
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
722
741
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
@@ -741,8 +760,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
741
760
  aztecNode: this.stateMachine.node,
742
761
  recipientTaggingStore: this.recipientTaggingStore,
743
762
  senderAddressBookStore: this.senderAddressBookStore,
744
- capsuleStore: this.capsuleStore,
763
+ capsuleService: new CapsuleService(this.capsuleStore, scopes),
745
764
  privateEventStore: this.privateEventStore,
765
+ messageContextService: this.stateMachine.messageContextService,
766
+ contractSyncService: this.contractSyncService,
746
767
  jobId,
747
768
  scopes,
748
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,34 +653,19 @@ export class RPCTranslator {
652
653
  }
653
654
 
654
655
  // eslint-disable-next-line camelcase
655
- public aztec_prv_notifyEnqueuedPublicFunctionCall(
656
- _foreignTargetContractAddress: ForeignCallSingle,
657
- _foreignCalldataHash: ForeignCallSingle,
658
- _foreignSideEffectCounter: ForeignCallSingle,
659
- _foreignIsStaticCall: ForeignCallSingle,
660
- ) {
661
- throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
662
- }
663
-
664
- // eslint-disable-next-line camelcase
665
- public aztec_prv_notifySetPublicTeardownFunctionCall(
666
- _foreignTargetContractAddress: ForeignCallSingle,
667
- _foreignCalldataHash: ForeignCallSingle,
668
- _foreignSideEffectCounter: ForeignCallSingle,
669
- _foreignIsStaticCall: ForeignCallSingle,
670
- ) {
656
+ public aztec_prv_assertValidPublicCalldata(_foreignCalldataHash: ForeignCallSingle) {
671
657
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
672
658
  }
673
659
 
674
660
  // eslint-disable-next-line camelcase
675
- public aztec_prv_notifySetMinRevertibleSideEffectCounter(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
661
+ public aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
676
662
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
677
663
  }
678
664
 
679
665
  // eslint-disable-next-line camelcase
680
- public async aztec_prv_isSideEffectCounterRevertible(foreignSideEffectCounter: ForeignCallSingle) {
666
+ public async aztec_prv_isExecutionInRevertiblePhase(foreignSideEffectCounter: ForeignCallSingle) {
681
667
  const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
682
- const isRevertible = await this.handlerAsPrivate().isSideEffectCounterRevertible(sideEffectCounter);
668
+ const isRevertible = await this.handlerAsPrivate().isExecutionInRevertiblePhase(sideEffectCounter);
683
669
  return toForeignCallResult([toSingle(new Fr(isRevertible))]);
684
670
  }
685
671
 
@@ -753,78 +739,166 @@ export class RPCTranslator {
753
739
  }
754
740
 
755
741
  // eslint-disable-next-line camelcase
756
- async aztec_utl_fetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
742
+ async aztec_utl_getPendingTaggedLogs(
743
+ foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle,
744
+ foreignScope: ForeignCallSingle,
745
+ ) {
757
746
  const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
747
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
758
748
 
759
- await this.handlerAsUtility().fetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
749
+ await this.handlerAsUtility().getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot, scope);
760
750
 
761
751
  return toForeignCallResult([]);
762
752
  }
763
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
+
764
761
  // eslint-disable-next-line camelcase
765
762
  public async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(
766
763
  foreignContractAddress: ForeignCallSingle,
767
764
  foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
768
765
  foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
766
+ foreignMaxNotePackedLen: ForeignCallSingle,
767
+ foreignMaxEventSerializedLen: ForeignCallSingle,
768
+ foreignScope: ForeignCallSingle,
769
769
  ) {
770
770
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
771
771
  const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
772
772
  const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
773
+ const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
774
+ const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
775
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
773
776
 
774
777
  await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
775
778
  contractAddress,
776
779
  noteValidationRequestsArrayBaseSlot,
777
780
  eventValidationRequestsArrayBaseSlot,
781
+ maxNotePackedLen,
782
+ maxEventSerializedLen,
783
+ scope,
784
+ );
785
+
786
+ return toForeignCallResult([]);
787
+ }
788
+
789
+ // eslint-disable-next-line camelcase
790
+ public async aztec_utl_validateAndStoreEnqueuedNotesAndEvents_v2(
791
+ foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
792
+ foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
793
+ foreignMaxNotePackedLen: ForeignCallSingle,
794
+ foreignMaxEventSerializedLen: ForeignCallSingle,
795
+ foreignScope: ForeignCallSingle,
796
+ ) {
797
+ const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
798
+ const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
799
+ const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
800
+ const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
801
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
802
+
803
+ await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEventsV2(
804
+ noteValidationRequestsArrayBaseSlot,
805
+ eventValidationRequestsArrayBaseSlot,
806
+ maxNotePackedLen,
807
+ maxEventSerializedLen,
808
+ scope,
778
809
  );
779
810
 
780
811
  return toForeignCallResult([]);
781
812
  }
782
813
 
783
814
  // eslint-disable-next-line camelcase
784
- public async aztec_utl_bulkRetrieveLogs(
815
+ public async aztec_utl_getLogsByTag(
785
816
  foreignContractAddress: ForeignCallSingle,
786
817
  foreignLogRetrievalRequestsArrayBaseSlot: ForeignCallSingle,
787
818
  foreignLogRetrievalResponsesArrayBaseSlot: ForeignCallSingle,
819
+ foreignScope: ForeignCallSingle,
788
820
  ) {
789
821
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
790
822
  const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
791
823
  const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
824
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
792
825
 
793
- await this.handlerAsUtility().bulkRetrieveLogs(
826
+ await this.handlerAsUtility().getLogsByTag(
794
827
  contractAddress,
795
828
  logRetrievalRequestsArrayBaseSlot,
796
829
  logRetrievalResponsesArrayBaseSlot,
830
+ scope,
797
831
  );
798
832
 
799
833
  return toForeignCallResult([]);
800
834
  }
801
835
 
802
836
  // eslint-disable-next-line camelcase
803
- async aztec_utl_storeCapsule(
837
+ public async aztec_utl_getMessageContextsByTxHash(
838
+ foreignContractAddress: ForeignCallSingle,
839
+ foreignMessageContextRequestsArrayBaseSlot: ForeignCallSingle,
840
+ foreignMessageContextResponsesArrayBaseSlot: ForeignCallSingle,
841
+ foreignScope: ForeignCallSingle,
842
+ ) {
843
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
844
+ const messageContextRequestsArrayBaseSlot = fromSingle(foreignMessageContextRequestsArrayBaseSlot);
845
+ const messageContextResponsesArrayBaseSlot = fromSingle(foreignMessageContextResponsesArrayBaseSlot);
846
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
847
+
848
+ await this.handlerAsUtility().getMessageContextsByTxHash(
849
+ contractAddress,
850
+ messageContextRequestsArrayBaseSlot,
851
+ messageContextResponsesArrayBaseSlot,
852
+ scope,
853
+ );
854
+
855
+ return toForeignCallResult([]);
856
+ }
857
+
858
+ // eslint-disable-next-line camelcase
859
+ async aztec_utl_getLogsByTag_v2(foreignRequestArrayBaseSlot: ForeignCallSingle) {
860
+ const requestArrayBaseSlot = fromSingle(foreignRequestArrayBaseSlot);
861
+ const responseSlot = await this.handlerAsUtility().getLogsByTagV2(requestArrayBaseSlot);
862
+ return toForeignCallResult([toSingle(responseSlot)]);
863
+ }
864
+
865
+ // eslint-disable-next-line camelcase
866
+ async aztec_utl_getMessageContextsByTxHash_v2(foreignRequestArrayBaseSlot: ForeignCallSingle) {
867
+ const requestArrayBaseSlot = fromSingle(foreignRequestArrayBaseSlot);
868
+ const responseSlot = await this.handlerAsUtility().getMessageContextsByTxHashV2(requestArrayBaseSlot);
869
+ return toForeignCallResult([toSingle(responseSlot)]);
870
+ }
871
+
872
+ // eslint-disable-next-line camelcase
873
+ aztec_utl_setCapsule(
804
874
  foreignContractAddress: ForeignCallSingle,
805
875
  foreignSlot: ForeignCallSingle,
806
876
  foreignCapsule: ForeignCallArray,
877
+ foreignScope: ForeignCallSingle,
807
878
  ) {
808
879
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
809
880
  const slot = fromSingle(foreignSlot);
810
881
  const capsule = fromArray(foreignCapsule);
882
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
811
883
 
812
- await this.handlerAsUtility().storeCapsule(contractAddress, slot, capsule);
884
+ this.handlerAsUtility().setCapsule(contractAddress, slot, capsule, scope);
813
885
 
814
886
  return toForeignCallResult([]);
815
887
  }
816
888
 
817
889
  // eslint-disable-next-line camelcase
818
- async aztec_utl_loadCapsule(
890
+ async aztec_utl_getCapsule(
819
891
  foreignContractAddress: ForeignCallSingle,
820
892
  foreignSlot: ForeignCallSingle,
821
893
  foreignTSize: ForeignCallSingle,
894
+ foreignScope: ForeignCallSingle,
822
895
  ) {
823
896
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
824
897
  const slot = fromSingle(foreignSlot);
825
898
  const tSize = fromSingle(foreignTSize).toNumber();
899
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
826
900
 
827
- const values = await this.handlerAsUtility().loadCapsule(contractAddress, slot);
901
+ const values = await this.handlerAsUtility().getCapsule(contractAddress, slot, scope);
828
902
 
829
903
  // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
830
904
  // with two fields: `some` (a boolean) and `value` (a field array in this case).
@@ -838,11 +912,16 @@ export class RPCTranslator {
838
912
  }
839
913
 
840
914
  // eslint-disable-next-line camelcase
841
- async aztec_utl_deleteCapsule(foreignContractAddress: ForeignCallSingle, foreignSlot: ForeignCallSingle) {
915
+ aztec_utl_deleteCapsule(
916
+ foreignContractAddress: ForeignCallSingle,
917
+ foreignSlot: ForeignCallSingle,
918
+ foreignScope: ForeignCallSingle,
919
+ ) {
842
920
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
843
921
  const slot = fromSingle(foreignSlot);
922
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
844
923
 
845
- await this.handlerAsUtility().deleteCapsule(contractAddress, slot);
924
+ this.handlerAsUtility().deleteCapsule(contractAddress, slot, scope);
846
925
 
847
926
  return toForeignCallResult([]);
848
927
  }
@@ -853,23 +932,83 @@ export class RPCTranslator {
853
932
  foreignSrcSlot: ForeignCallSingle,
854
933
  foreignDstSlot: ForeignCallSingle,
855
934
  foreignNumEntries: ForeignCallSingle,
935
+ foreignScope: ForeignCallSingle,
856
936
  ) {
857
937
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
858
938
  const srcSlot = fromSingle(foreignSrcSlot);
859
939
  const dstSlot = fromSingle(foreignDstSlot);
860
940
  const numEntries = fromSingle(foreignNumEntries).toNumber();
941
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
861
942
 
862
- await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
943
+ await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, scope);
863
944
 
864
945
  return toForeignCallResult([]);
865
946
  }
866
947
 
948
+ // eslint-disable-next-line camelcase
949
+ aztec_utl_pushEphemeral(foreignSlot: ForeignCallSingle, foreignElements: ForeignCallArray) {
950
+ const slot = fromSingle(foreignSlot);
951
+ const elements = fromArray(foreignElements);
952
+ const newLen = this.handlerAsUtility().pushEphemeral(slot, elements);
953
+ return toForeignCallResult([toSingle(new Fr(newLen))]);
954
+ }
955
+
956
+ // eslint-disable-next-line camelcase
957
+ aztec_utl_popEphemeral(foreignSlot: ForeignCallSingle) {
958
+ const slot = fromSingle(foreignSlot);
959
+ const element = this.handlerAsUtility().popEphemeral(slot);
960
+ return toForeignCallResult([toArray(element)]);
961
+ }
962
+
963
+ // eslint-disable-next-line camelcase
964
+ aztec_utl_getEphemeral(foreignSlot: ForeignCallSingle, foreignIndex: ForeignCallSingle) {
965
+ const slot = fromSingle(foreignSlot);
966
+ const index = fromSingle(foreignIndex).toNumber();
967
+ const element = this.handlerAsUtility().getEphemeral(slot, index);
968
+ return toForeignCallResult([toArray(element)]);
969
+ }
970
+
971
+ // eslint-disable-next-line camelcase
972
+ aztec_utl_setEphemeral(
973
+ foreignSlot: ForeignCallSingle,
974
+ foreignIndex: ForeignCallSingle,
975
+ foreignElements: ForeignCallArray,
976
+ ) {
977
+ const slot = fromSingle(foreignSlot);
978
+ const index = fromSingle(foreignIndex).toNumber();
979
+ const elements = fromArray(foreignElements);
980
+ this.handlerAsUtility().setEphemeral(slot, index, elements);
981
+ return toForeignCallResult([]);
982
+ }
983
+
984
+ // eslint-disable-next-line camelcase
985
+ aztec_utl_getEphemeralLen(foreignSlot: ForeignCallSingle) {
986
+ const slot = fromSingle(foreignSlot);
987
+ const len = this.handlerAsUtility().getEphemeralLen(slot);
988
+ return toForeignCallResult([toSingle(new Fr(len))]);
989
+ }
990
+
991
+ // eslint-disable-next-line camelcase
992
+ aztec_utl_removeEphemeral(foreignSlot: ForeignCallSingle, foreignIndex: ForeignCallSingle) {
993
+ const slot = fromSingle(foreignSlot);
994
+ const index = fromSingle(foreignIndex).toNumber();
995
+ this.handlerAsUtility().removeEphemeral(slot, index);
996
+ return toForeignCallResult([]);
997
+ }
998
+
999
+ // eslint-disable-next-line camelcase
1000
+ aztec_utl_clearEphemeral(foreignSlot: ForeignCallSingle) {
1001
+ const slot = fromSingle(foreignSlot);
1002
+ this.handlerAsUtility().clearEphemeral(slot);
1003
+ return toForeignCallResult([]);
1004
+ }
1005
+
867
1006
  // TODO: I forgot to add a corresponding function here, when I introduced an oracle method to txe_oracle.ts.
868
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
869
1008
  // to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
870
1009
  // existence of a txe_oracle method?
871
1010
  // eslint-disable-next-line camelcase
872
- async aztec_utl_aes128Decrypt(
1011
+ async aztec_utl_decryptAes128(
873
1012
  foreignCiphertextBVecStorage: ForeignCallArray,
874
1013
  foreignCiphertextLength: ForeignCallSingle,
875
1014
  foreignIv: ForeignCallArray,
@@ -879,11 +1018,18 @@ export class RPCTranslator {
879
1018
  const iv = fromUintArray(foreignIv, 8);
880
1019
  const symKey = fromUintArray(foreignSymKey, 8);
881
1020
 
882
- const plaintextBuffer = await this.handlerAsUtility().aes128Decrypt(ciphertext, iv, symKey);
883
-
884
- return toForeignCallResult(
885
- arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length),
886
- );
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
+ }
887
1033
  }
888
1034
 
889
1035
  // eslint-disable-next-line camelcase
@@ -892,6 +1038,7 @@ export class RPCTranslator {
892
1038
  foreignEphPKField0: ForeignCallSingle,
893
1039
  foreignEphPKField1: ForeignCallSingle,
894
1040
  foreignEphPKField2: ForeignCallSingle,
1041
+ foreignContractAddress: ForeignCallSingle,
895
1042
  ) {
896
1043
  const address = AztecAddress.fromField(fromSingle(foreignAddress));
897
1044
  const ephPK = Point.fromFields([
@@ -899,10 +1046,28 @@ export class RPCTranslator {
899
1046
  fromSingle(foreignEphPKField1),
900
1047
  fromSingle(foreignEphPKField2),
901
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));
902
1067
 
903
- const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK);
1068
+ this.handlerAsUtility().setContractSyncCacheInvalid(contractAddress, scopes);
904
1069
 
905
- return toForeignCallResult(secret.toFields().map(toSingle));
1070
+ return Promise.resolve(toForeignCallResult([]));
906
1071
  }
907
1072
 
908
1073
  // eslint-disable-next-line camelcase
@@ -17,7 +17,7 @@ export class TXEArchiver extends ArchiverDataSourceBase {
17
17
  private readonly updater = new ArchiverDataStoreUpdater(this.store);
18
18
 
19
19
  constructor(db: AztecAsyncKVStore) {
20
- const store = new KVArchiverDataStore(db, 9999, { epochDuration: 32 });
20
+ const store = new KVArchiverDataStore(db, 9999);
21
21
  super(store);
22
22
  }
23
23
 
@@ -76,15 +76,16 @@ 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
 
82
- public getL2SlotNumber(): Promise<SlotNumber | undefined> {
83
- throw new Error('TXE Archiver does not implement "getL2SlotNumber"');
83
+ public getSyncedL2SlotNumber(): Promise<SlotNumber | undefined> {
84
+ throw new Error('TXE Archiver does not implement "getSyncedL2SlotNumber"');
84
85
  }
85
86
 
86
- public getL2EpochNumber(): Promise<EpochNumber | undefined> {
87
- throw new Error('TXE Archiver does not implement "getL2EpochNumber"');
87
+ public getSyncedL2EpochNumber(): Promise<EpochNumber | undefined> {
88
+ throw new Error('TXE Archiver does not implement "getSyncedL2EpochNumber"');
88
89
  }
89
90
 
90
91
  public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
@@ -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)[]> {