@aztec/txe 0.0.1-commit.d3ec352c → 0.0.1-commit.f295ac2

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 (80) hide show
  1. package/dest/constants.d.ts +3 -0
  2. package/dest/constants.d.ts.map +1 -0
  3. package/dest/constants.js +2 -0
  4. package/dest/index.d.ts +1 -1
  5. package/dest/index.d.ts.map +1 -1
  6. package/dest/index.js +3 -2
  7. package/dest/oracle/interfaces.d.ts +5 -3
  8. package/dest/oracle/interfaces.d.ts.map +1 -1
  9. package/dest/oracle/txe_oracle_public_context.d.ts +4 -4
  10. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_public_context.js +4 -6
  12. package/dest/oracle/txe_oracle_top_level_context.d.ts +20 -11
  13. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  14. package/dest/oracle/txe_oracle_top_level_context.js +99 -62
  15. package/dest/rpc_translator.d.ts +15 -9
  16. package/dest/rpc_translator.d.ts.map +1 -1
  17. package/dest/rpc_translator.js +65 -25
  18. package/dest/state_machine/archiver.d.ts +21 -57
  19. package/dest/state_machine/archiver.d.ts.map +1 -1
  20. package/dest/state_machine/archiver.js +62 -107
  21. package/dest/state_machine/dummy_p2p_client.d.ts +8 -7
  22. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  23. package/dest/state_machine/dummy_p2p_client.js +16 -11
  24. package/dest/state_machine/global_variable_builder.d.ts +4 -3
  25. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  26. package/dest/state_machine/global_variable_builder.js +13 -1
  27. package/dest/state_machine/index.d.ts +6 -6
  28. package/dest/state_machine/index.d.ts.map +1 -1
  29. package/dest/state_machine/index.js +23 -20
  30. package/dest/state_machine/mock_epoch_cache.d.ts +2 -1
  31. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  32. package/dest/state_machine/mock_epoch_cache.js +5 -1
  33. package/dest/state_machine/synchronizer.d.ts +1 -1
  34. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  35. package/dest/state_machine/synchronizer.js +2 -2
  36. package/dest/txe_session.d.ts +18 -10
  37. package/dest/txe_session.d.ts.map +1 -1
  38. package/dest/txe_session.js +90 -45
  39. package/dest/util/encoding.d.ts +618 -19
  40. package/dest/util/encoding.d.ts.map +1 -1
  41. package/dest/util/encoding.js +1 -1
  42. package/dest/util/txe_account_store.d.ts +10 -0
  43. package/dest/util/txe_account_store.d.ts.map +1 -0
  44. package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
  45. package/dest/util/txe_contract_store.d.ts +12 -0
  46. package/dest/util/txe_contract_store.d.ts.map +1 -0
  47. package/dest/util/{txe_contract_data_provider.js → txe_contract_store.js} +3 -3
  48. package/dest/util/txe_public_contract_data_source.d.ts +5 -5
  49. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  50. package/dest/util/txe_public_contract_data_source.js +11 -11
  51. package/dest/utils/block_creation.d.ts +19 -5
  52. package/dest/utils/block_creation.d.ts.map +1 -1
  53. package/dest/utils/block_creation.js +36 -4
  54. package/dest/utils/tx_effect_creation.d.ts +2 -3
  55. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  56. package/dest/utils/tx_effect_creation.js +4 -7
  57. package/package.json +16 -16
  58. package/src/constants.ts +3 -0
  59. package/src/index.ts +15 -12
  60. package/src/oracle/interfaces.ts +4 -2
  61. package/src/oracle/txe_oracle_public_context.ts +5 -10
  62. package/src/oracle/txe_oracle_top_level_context.ts +148 -88
  63. package/src/rpc_translator.ts +82 -28
  64. package/src/state_machine/archiver.ts +60 -130
  65. package/src/state_machine/dummy_p2p_client.ts +21 -14
  66. package/src/state_machine/global_variable_builder.ts +19 -2
  67. package/src/state_machine/index.ts +28 -19
  68. package/src/state_machine/mock_epoch_cache.ts +5 -0
  69. package/src/state_machine/synchronizer.ts +1 -2
  70. package/src/txe_session.ts +179 -76
  71. package/src/util/encoding.ts +1 -1
  72. package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
  73. package/src/util/{txe_contract_data_provider.ts → txe_contract_store.ts} +3 -3
  74. package/src/util/txe_public_contract_data_source.ts +10 -10
  75. package/src/utils/block_creation.ts +46 -15
  76. package/src/utils/tx_effect_creation.ts +4 -12
  77. package/dest/util/txe_account_data_provider.d.ts +0 -10
  78. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  79. package/dest/util/txe_contract_data_provider.d.ts +0 -12
  80. package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
@@ -8,8 +8,9 @@ import {
8
8
  type IUtilityExecutionOracle,
9
9
  packAsRetrievedNote,
10
10
  } from '@aztec/pxe/simulator';
11
- import { type ContractArtifact, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
11
+ import { type ContractArtifact, EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
12
12
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
13
+ import { L2BlockHash } from '@aztec/stdlib/block';
13
14
  import { MerkleTreeId } from '@aztec/stdlib/trees';
14
15
 
15
16
  import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
@@ -30,6 +31,9 @@ import {
30
31
  toSingle,
31
32
  } from './util/encoding.js';
32
33
 
34
+ const MAX_EVENT_LEN = 12; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_RESERVED_FIELDS
35
+ const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
36
+
33
37
  export class UnavailableOracleError extends Error {
34
38
  constructor(oracleName: string) {
35
39
  super(`${oracleName} oracles not available with the current handler`);
@@ -156,6 +160,12 @@ export class RPCTranslator {
156
160
 
157
161
  // TXE-specific oracles
158
162
 
163
+ txeGetDefaultAddress() {
164
+ const defaultAddress = this.handlerAsTxe().txeGetDefaultAddress();
165
+
166
+ return toForeignCallResult([toSingle(defaultAddress)]);
167
+ }
168
+
159
169
  async txeGetNextBlockNumber() {
160
170
  const nextBlockNumber = await this.handlerAsTxe().txeGetNextBlockNumber();
161
171
 
@@ -267,6 +277,39 @@ export class RPCTranslator {
267
277
  ]);
268
278
  }
269
279
 
280
+ async txeGetPrivateEvents(
281
+ foreignSelector: ForeignCallSingle,
282
+ foreignContractAddress: ForeignCallSingle,
283
+ foreignScope: ForeignCallSingle,
284
+ ) {
285
+ const selector = EventSelector.fromField(fromSingle(foreignSelector));
286
+ const contractAddress = addressFromSingle(foreignContractAddress);
287
+ const scope = addressFromSingle(foreignScope);
288
+
289
+ const events = await this.handlerAsTxe().txeGetPrivateEvents(selector, contractAddress, scope);
290
+
291
+ if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
292
+ throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
293
+ }
294
+
295
+ if (events.some(e => e.length > MAX_EVENT_LEN)) {
296
+ throw new Error(`Some private event has length larger than maxLen ${MAX_EVENT_LEN}`);
297
+ }
298
+
299
+ // This is a workaround as Noir does not currently let us return nested structs with arrays. We instead return a raw
300
+ // multidimensional array in get_private_events_oracle and create the BoundedVecs here.
301
+ const rawArrayStorage = events
302
+ .map(e => e.concat(Array(MAX_EVENT_LEN - e.length).fill(new Fr(0))))
303
+ .concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(Array(MAX_EVENT_LEN).fill(new Fr(0))))
304
+ .flat();
305
+ const eventLengths = events
306
+ .map(e => new Fr(e.length))
307
+ .concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(new Fr(0)));
308
+ const queryLength = new Fr(events.length);
309
+
310
+ return toForeignCallResult([toArray(rawArrayStorage), toArray(eventLengths), toSingle(queryLength)]);
311
+ }
312
+
270
313
  privateStoreInExecutionCache(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
271
314
  const values = fromArray(foreignValues);
272
315
  const hash = fromSingle(foreignHash);
@@ -304,40 +347,41 @@ export class RPCTranslator {
304
347
  }
305
348
 
306
349
  async utilityStorageRead(
350
+ foreignBlockHash: ForeignCallSingle,
307
351
  foreignContractAddress: ForeignCallSingle,
308
352
  foreignStartStorageSlot: ForeignCallSingle,
309
- foreignBlockNumber: ForeignCallSingle,
310
353
  foreignNumberOfElements: ForeignCallSingle,
311
354
  ) {
355
+ const blockHash = L2BlockHash.fromString(foreignBlockHash);
312
356
  const contractAddress = addressFromSingle(foreignContractAddress);
313
357
  const startStorageSlot = fromSingle(foreignStartStorageSlot);
314
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
315
358
  const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
316
359
 
317
360
  const values = await this.handlerAsUtility().utilityStorageRead(
361
+ blockHash,
318
362
  contractAddress,
319
363
  startStorageSlot,
320
- blockNumber,
321
364
  numberOfElements,
322
365
  );
323
366
 
324
367
  return toForeignCallResult([toArray(values)]);
325
368
  }
326
369
 
327
- async utilityGetPublicDataWitness(foreignBlockNumber: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
328
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
370
+ async utilityGetPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
371
+ const blockHash = L2BlockHash.fromString(foreignBlockHash);
329
372
  const leafSlot = fromSingle(foreignLeafSlot);
330
373
 
331
- const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockNumber, leafSlot);
374
+ const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockHash, leafSlot);
332
375
 
333
376
  if (!witness) {
334
- throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockNumber}.`);
377
+ throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
335
378
  }
336
379
  return toForeignCallResult(witness.toNoirRepresentation());
337
380
  }
338
381
 
339
382
  async utilityGetNotes(
340
- foreignOwner: ForeignCallSingle,
383
+ foreignOwnerIsSome: ForeignCallSingle,
384
+ foreignOwnerValue: ForeignCallSingle,
341
385
  foreignStorageSlot: ForeignCallSingle,
342
386
  foreignNumSelects: ForeignCallSingle,
343
387
  foreignSelectByIndexes: ForeignCallArray,
@@ -355,7 +399,10 @@ export class RPCTranslator {
355
399
  foreignMaxNotes: ForeignCallSingle,
356
400
  foreignPackedRetrievedNoteLength: ForeignCallSingle,
357
401
  ) {
358
- const owner = addressFromSingle(foreignOwner);
402
+ // Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
403
+ const owner = fromSingle(foreignOwnerIsSome).toBool()
404
+ ? AztecAddress.fromField(fromSingle(foreignOwnerValue))
405
+ : undefined;
359
406
  const storageSlot = fromSingle(foreignStorageSlot);
360
407
  const numSelects = fromSingle(foreignNumSelects).toNumber();
361
408
  const selectByIndexes = fromArray(foreignSelectByIndexes).map(fr => fr.toNumber());
@@ -391,7 +438,17 @@ export class RPCTranslator {
391
438
  status,
392
439
  );
393
440
 
394
- const returnDataAsArrayOfArrays = noteDatas.map(packAsRetrievedNote);
441
+ const returnDataAsArrayOfArrays = noteDatas.map(noteData =>
442
+ packAsRetrievedNote({
443
+ contractAddress: noteData.contractAddress,
444
+ owner: noteData.owner,
445
+ randomness: noteData.randomness,
446
+ storageSlot: noteData.storageSlot,
447
+ noteNonce: noteData.noteNonce,
448
+ isPending: noteData.isPending,
449
+ note: noteData.note,
450
+ }),
451
+ );
395
452
 
396
453
  // Now we convert each sub-array to an array of ForeignCallSingles
397
454
  const returnDataAsArrayOfForeignCallSingleArrays = returnDataAsArrayOfArrays.map(subArray =>
@@ -512,17 +569,14 @@ export class RPCTranslator {
512
569
  );
513
570
  }
514
571
 
515
- async utilityGetNullifierMembershipWitness(
516
- foreignBlockNumber: ForeignCallSingle,
517
- foreignNullifier: ForeignCallSingle,
518
- ) {
519
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
572
+ async utilityGetNullifierMembershipWitness(foreignBlockHash: ForeignCallSingle, foreignNullifier: ForeignCallSingle) {
573
+ const blockHash = L2BlockHash.fromString(foreignBlockHash);
520
574
  const nullifier = fromSingle(foreignNullifier);
521
575
 
522
- const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockNumber, nullifier);
576
+ const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
523
577
 
524
578
  if (!witness) {
525
- throw new Error(`Nullifier membership witness not found at block ${blockNumber}.`);
579
+ throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
526
580
  }
527
581
  return toForeignCallResult(witness.toNoirRepresentation());
528
582
  }
@@ -566,8 +620,8 @@ export class RPCTranslator {
566
620
  return toForeignCallResult([toSingle(new Fr(isRevertible))]);
567
621
  }
568
622
 
569
- async utilityGetUtilityContext() {
570
- const context = await this.handlerAsUtility().utilityGetUtilityContext();
623
+ utilityGetUtilityContext() {
624
+ const context = this.handlerAsUtility().utilityGetUtilityContext();
571
625
 
572
626
  return toForeignCallResult(context.toNoirRepresentation());
573
627
  }
@@ -584,35 +638,35 @@ export class RPCTranslator {
584
638
  }
585
639
 
586
640
  async utilityGetMembershipWitness(
587
- foreignBlockNumber: ForeignCallSingle,
641
+ foreignBlockHash: ForeignCallSingle,
588
642
  foreignTreeId: ForeignCallSingle,
589
643
  foreignLeafValue: ForeignCallSingle,
590
644
  ) {
591
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
645
+ const blockHash = L2BlockHash.fromString(foreignBlockHash);
592
646
  const treeId = fromSingle(foreignTreeId).toNumber();
593
647
  const leafValue = fromSingle(foreignLeafValue);
594
648
 
595
- const witness = await this.handlerAsUtility().utilityGetMembershipWitness(blockNumber, treeId, leafValue);
649
+ const witness = await this.handlerAsUtility().utilityGetMembershipWitness(blockHash, treeId, leafValue);
596
650
 
597
651
  if (!witness) {
598
652
  throw new Error(
599
- `Membership witness in tree ${MerkleTreeId[treeId]} not found for value ${leafValue} at block ${blockNumber}.`,
653
+ `Membership witness in tree ${MerkleTreeId[treeId]} not found for value ${leafValue} at block ${blockHash}.`,
600
654
  );
601
655
  }
602
656
  return toForeignCallResult([toSingle(witness[0]), toArray(witness.slice(1))]);
603
657
  }
604
658
 
605
659
  async utilityGetLowNullifierMembershipWitness(
606
- foreignBlockNumber: ForeignCallSingle,
660
+ foreignBlockHash: ForeignCallSingle,
607
661
  foreignNullifier: ForeignCallSingle,
608
662
  ) {
609
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
663
+ const blockHash = L2BlockHash.fromString(foreignBlockHash);
610
664
  const nullifier = fromSingle(foreignNullifier);
611
665
 
612
- const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockNumber, nullifier);
666
+ const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
613
667
 
614
668
  if (!witness) {
615
- throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockNumber}.`);
669
+ throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
616
670
  }
617
671
  return toForeignCallResult(witness.toNoirRepresentation());
618
672
  }
@@ -1,169 +1,99 @@
1
- import { ArchiverStoreHelper, KVArchiverDataStore, type PublishedL2Block } from '@aztec/archiver';
1
+ import { ArchiverDataSourceBase, ArchiverDataStoreUpdater, KVArchiverDataStore } from '@aztec/archiver';
2
2
  import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
3
- import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { CheckpointNumber, type EpochNumber, type SlotNumber } from '@aztec/foundation/branded-types';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
5
  import type { EthAddress } from '@aztec/foundation/eth-address';
5
- import { Fr } from '@aztec/foundation/fields';
6
6
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
7
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
8
- import type { L2Block, L2BlockSource, L2Tips, ValidateBlockResult } from '@aztec/stdlib/block';
9
- import type { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
10
- import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
7
+ import type { CheckpointId, L2BlockId, L2TipId, L2Tips, ValidateCheckpointResult } from '@aztec/stdlib/block';
8
+ import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
11
9
  import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
12
- import type { BlockHeader } from '@aztec/stdlib/tx';
13
- import type { UInt64 } from '@aztec/stdlib/types';
14
10
 
15
- // We are extending the ArchiverDataStoreHelper here because it provides most of the endpoints needed by the
16
- // node for reading from and writing to state, without needing any of the extra overhead that the Archiver itself
17
- // requires (i.e. an L1 client)
18
- export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
11
+ /**
12
+ * TXE Archiver implementation.
13
+ * Provides most of the endpoints needed by the node for reading from and writing to state,
14
+ * without needing any of the extra overhead that the Archiver itself requires (i.e. an L1 client).
15
+ */
16
+ export class TXEArchiver extends ArchiverDataSourceBase {
17
+ private readonly updater = new ArchiverDataStoreUpdater(this.store);
18
+
19
19
  constructor(db: AztecAsyncKVStore) {
20
- super(new KVArchiverDataStore(db, 9999));
20
+ const store = new KVArchiverDataStore(db, 9999);
21
+ super(store);
21
22
  }
22
23
 
23
- public override async addBlocks(blocks: PublishedL2Block[]): Promise<boolean> {
24
- const opResults = await Promise.all([
25
- this.store.addLogs(blocks.map(block => block.block)),
26
- this.store.addBlocks(blocks),
27
- ]);
28
-
29
- return opResults.every(Boolean);
24
+ // TXE-specific method for adding checkpoints
25
+ public async addCheckpoints(checkpoints: PublishedCheckpoint[], result?: ValidateCheckpointResult): Promise<boolean> {
26
+ await this.updater.setNewCheckpointData(checkpoints, result);
27
+ return true;
30
28
  }
31
29
 
32
- /**
33
- * Gets the number of the latest L2 block processed by the block source implementation.
34
- * @returns The number of the latest L2 block processed by the block source implementation.
35
- */
36
- public getBlockNumber(): Promise<BlockNumber> {
37
- return this.store.getSynchedL2BlockNumber();
38
- }
30
+ // Abstract method implementations
39
31
 
40
- /**
41
- * Gets the number of the latest L2 block proven seen by the block source implementation.
42
- * @returns The number of the latest L2 block proven seen by the block source implementation.
43
- */
44
- public getProvenBlockNumber(): Promise<BlockNumber> {
45
- return this.store.getSynchedL2BlockNumber();
32
+ public getRollupAddress(): Promise<EthAddress> {
33
+ throw new Error('TXE Archiver does not implement "getRollupAddress"');
46
34
  }
47
35
 
48
- /**
49
- * Gets a published l2 block. If a negative number is passed, the block returned is the most recent.
50
- * @param number - The block number to return (inclusive).
51
- * @returns The requested L2 block.
52
- */
53
- public override async getPublishedBlock(number: number): Promise<PublishedL2Block | undefined> {
54
- // If the number provided is -ve, then return the latest block.
55
- if (number < 0) {
56
- number = await this.store.getSynchedL2BlockNumber();
57
- }
58
- if (number == 0) {
59
- return undefined;
60
- }
61
- const blocks = await this.store.getPublishedBlocks(BlockNumber(number), 1);
62
- return blocks.length === 0 ? undefined : blocks[0];
36
+ public getRegistryAddress(): Promise<EthAddress> {
37
+ throw new Error('TXE Archiver does not implement "getRegistryAddress"');
63
38
  }
64
39
 
65
- /**
66
- * Gets an l2 block. If a negative number is passed, the block returned is the most recent.
67
- * @param number - The block number to return (inclusive).
68
- * @returns The requested L2 block.
69
- */
70
- public getBlock(number: number | 'latest'): Promise<L2Block | undefined> {
71
- return this.getPublishedBlock(number != 'latest' ? number : -1).then(block => block?.block);
40
+ public getL1Constants(): Promise<L1RollupConstants> {
41
+ throw new Error('TXE Archiver does not implement "getL1Constants"');
72
42
  }
73
43
 
74
- /**
75
- * Gets an l2 block header.
76
- * @param number - The block number to return or 'latest' for the most recent one.
77
- * @returns The requested L2 block header.
78
- */
79
- public async getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
80
- if (number === 'latest') {
81
- number = await this.store.getSynchedL2BlockNumber();
82
- }
83
- if (number === 0) {
84
- return undefined;
85
- }
86
- const headers = await this.store.getBlockHeaders(BlockNumber(number), 1);
87
- return headers.length === 0 ? undefined : headers[0];
44
+ public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
45
+ return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
88
46
  }
89
47
 
90
- public getBlocks(from: number, limit: number, _proven?: boolean): Promise<L2Block[]> {
91
- return this.getPublishedBlocks(BlockNumber(from), limit).then(blocks => blocks.map(b => b.block));
48
+ public getL1Timestamp(): Promise<bigint | undefined> {
49
+ throw new Error('TXE Archiver does not implement "getL1Timestamp"');
92
50
  }
93
51
 
94
- public getPublishedCheckpoints(_from: CheckpointNumber, _limit: number): Promise<PublishedCheckpoint[]> {
95
- throw new Error('TXE Archiver does not implement "getPublishedCheckpoints"');
96
- }
52
+ public async getL2Tips(): Promise<L2Tips> {
53
+ // In TXE there is no possibility of reorgs and no blocks are ever getting proven so we just set 'latest', 'proven'
54
+ // and 'finalized' to the latest block.
55
+ const blockHeader = await this.getBlockHeader('latest');
56
+ if (!blockHeader) {
57
+ throw new Error('L2Tips requested from TXE Archiver but no block header found');
58
+ }
97
59
 
98
- public getCheckpointByArchive(_archive: Fr): Promise<Checkpoint | undefined> {
99
- throw new Error('TXE Archiver does not implement "getCheckpointByArchive"');
60
+ const number = blockHeader.globalVariables.blockNumber;
61
+ const hash = (await blockHeader.hash()).toString();
62
+ const checkpointedBlock = await this.getCheckpointedBlock(number);
63
+ if (!checkpointedBlock) {
64
+ throw new Error(`L2Tips requested from TXE Archiver but no checkpointed block found for block number ${number}`);
65
+ }
66
+ const checkpoint = await this.store.getRangeOfCheckpoints(CheckpointNumber(number), 1);
67
+ if (checkpoint.length === 0) {
68
+ throw new Error(`L2Tips requested from TXE Archiver but no checkpoint found for block number ${number}`);
69
+ }
70
+ const blockId: L2BlockId = { number, hash };
71
+ const checkpointId: CheckpointId = {
72
+ number: checkpoint[0].checkpointNumber,
73
+ hash: checkpoint[0].header.hash().toString(),
74
+ };
75
+ const tipId: L2TipId = { block: blockId, checkpoint: checkpointId };
76
+ return {
77
+ proposed: blockId,
78
+ proven: tipId,
79
+ finalized: tipId,
80
+ checkpointed: tipId,
81
+ };
100
82
  }
101
83
 
102
84
  public getL2SlotNumber(): Promise<SlotNumber | undefined> {
103
85
  throw new Error('TXE Archiver does not implement "getL2SlotNumber"');
104
86
  }
105
87
 
106
- public getL2EpochNumber(): Promise<EpochNumber> {
88
+ public getL2EpochNumber(): Promise<EpochNumber | undefined> {
107
89
  throw new Error('TXE Archiver does not implement "getL2EpochNumber"');
108
90
  }
109
91
 
110
- public getCheckpointsForEpoch(_epochNumber: EpochNumber): Promise<Checkpoint[]> {
111
- throw new Error('TXE Archiver does not implement "getCheckpointsForEpoch"');
112
- }
113
-
114
- public getBlocksForEpoch(_epochNumber: EpochNumber): Promise<L2Block[]> {
115
- throw new Error('TXE Archiver does not implement "getBlocksForEpoch"');
116
- }
117
-
118
- public getBlockHeadersForEpoch(_epochNumber: EpochNumber): Promise<BlockHeader[]> {
119
- throw new Error('TXE Archiver does not implement "getBlockHeadersForEpoch"');
120
- }
121
-
122
- public getL1ToL2MessagesForCheckpoint(_checkpointNumber: CheckpointNumber): Promise<Fr[]> {
123
- throw new Error('TXE Archiver does not implement "getL1ToL2MessagesForCheckpoint"');
124
- }
125
-
126
92
  public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
127
93
  throw new Error('TXE Archiver does not implement "isEpochComplete"');
128
94
  }
129
95
 
130
- public getL2Tips(): Promise<L2Tips> {
131
- throw new Error('TXE Archiver does not implement "getL2Tips"');
132
- }
133
-
134
- public getL1Constants(): Promise<L1RollupConstants> {
135
- throw new Error('TXE Archiver does not implement "getL2Constants"');
136
- }
137
-
138
- public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
139
- return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
140
- }
141
-
142
96
  public syncImmediate(): Promise<void> {
143
97
  throw new Error('TXE Archiver does not implement "syncImmediate"');
144
98
  }
145
-
146
- public getContract(_address: AztecAddress, _timestamp?: UInt64): Promise<ContractInstanceWithAddress | undefined> {
147
- throw new Error('TXE Archiver does not implement "getContract"');
148
- }
149
-
150
- public getRollupAddress(): Promise<EthAddress> {
151
- throw new Error('TXE Archiver does not implement "getRollupAddress"');
152
- }
153
-
154
- public getRegistryAddress(): Promise<EthAddress> {
155
- throw new Error('TXE Archiver does not implement "getRegistryAddress"');
156
- }
157
-
158
- public getL1Timestamp(): Promise<bigint> {
159
- throw new Error('TXE Archiver does not implement "getL1Timestamp"');
160
- }
161
-
162
- public isPendingChainInvalid(): Promise<boolean> {
163
- return Promise.resolve(false);
164
- }
165
-
166
- public override getPendingChainValidationStatus(): Promise<ValidateBlockResult> {
167
- return Promise.resolve({ valid: true });
168
- }
169
99
  }
@@ -4,6 +4,7 @@ import type {
4
4
  ENR,
5
5
  P2P,
6
6
  P2PBlockReceivedCallback,
7
+ P2PCheckpointReceivedCallback,
7
8
  P2PConfig,
8
9
  P2PSyncState,
9
10
  PeerId,
@@ -14,14 +15,10 @@ import type {
14
15
  } from '@aztec/p2p';
15
16
  import type { EthAddress, L2BlockStreamEvent, L2Tips } from '@aztec/stdlib/block';
16
17
  import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
17
- import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
18
+ import type { BlockProposal, CheckpointAttestation, CheckpointProposal } from '@aztec/stdlib/p2p';
18
19
  import type { Tx, TxHash } from '@aztec/stdlib/tx';
19
20
 
20
21
  export class DummyP2P implements P2P {
21
- public broadcastAttestations(_attestations: BlockAttestation[]): Promise<void> {
22
- return Promise.resolve();
23
- }
24
-
25
22
  public validate(_txs: Tx[]): Promise<void> {
26
23
  return Promise.resolve();
27
24
  }
@@ -46,10 +43,22 @@ export class DummyP2P implements P2P {
46
43
  throw new Error('DummyP2P does not implement "broadcastProposal"');
47
44
  }
48
45
 
46
+ public broadcastCheckpointProposal(_proposal: CheckpointProposal): Promise<void> {
47
+ throw new Error('DummyP2P does not implement "broadcastCheckpointProposal"');
48
+ }
49
+
50
+ public broadcastCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
51
+ throw new Error('DummyP2P does not implement "broadcastCheckpointAttestations"');
52
+ }
53
+
49
54
  public registerBlockProposalHandler(_handler: P2PBlockReceivedCallback): void {
50
55
  throw new Error('DummyP2P does not implement "registerBlockProposalHandler"');
51
56
  }
52
57
 
58
+ public registerCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
59
+ throw new Error('DummyP2P does not implement "registerCheckpointProposalHandler"');
60
+ }
61
+
53
62
  public requestTxs(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
54
63
  throw new Error('DummyP2P does not implement "requestTxs"');
55
64
  }
@@ -79,7 +88,9 @@ export class DummyP2P implements P2P {
79
88
  }
80
89
 
81
90
  public getTxStatus(_txHash: TxHash): Promise<'pending' | 'mined' | undefined> {
82
- throw new Error('DummyP2P does not implement "getTxStatus"');
91
+ // In TXE there is no concept of transactions but we need to implement this because of tagging. We return 'mined'
92
+ // tx status for any tx hash.
93
+ return Promise.resolve('mined');
83
94
  }
84
95
 
85
96
  public iteratePendingTxs(): AsyncIterableIterator<Tx> {
@@ -118,16 +129,12 @@ export class DummyP2P implements P2P {
118
129
  throw new Error('DummyP2P does not implement "getTxsByHash"');
119
130
  }
120
131
 
121
- public getAttestationsForSlot(_slot: SlotNumber, _proposalId?: string): Promise<BlockAttestation[]> {
122
- throw new Error('DummyP2P does not implement "getAttestationForSlot"');
123
- }
124
-
125
- public deleteAttestation(_attestation: BlockAttestation): Promise<void> {
126
- return Promise.resolve();
132
+ public getCheckpointAttestationsForSlot(_slot: SlotNumber, _proposalId?: string): Promise<CheckpointAttestation[]> {
133
+ throw new Error('DummyP2P does not implement "getCheckpointAttestationsForSlot"');
127
134
  }
128
135
 
129
- public addAttestations(_attestations: BlockAttestation[]): Promise<void> {
130
- throw new Error('DummyP2P does not implement "addAttestations"');
136
+ public addCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
137
+ throw new Error('DummyP2P does not implement "addCheckpointAttestations"');
131
138
  }
132
139
 
133
140
  public getL2BlockHash(_number: number): Promise<string | undefined> {
@@ -3,10 +3,10 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import { GasFees } from '@aztec/stdlib/gas';
5
5
  import { makeGlobalVariables } from '@aztec/stdlib/testing';
6
- import { type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
6
+ import { type CheckpointGlobalVariables, type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
7
7
 
8
8
  export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
9
- public getCurrentBaseFees(): Promise<GasFees> {
9
+ public getCurrentMinFees(): Promise<GasFees> {
10
10
  return Promise.resolve(new GasFees(0, 0));
11
11
  }
12
12
 
@@ -18,4 +18,21 @@ export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
18
18
  ): Promise<GlobalVariables> {
19
19
  return Promise.resolve(makeGlobalVariables());
20
20
  }
21
+
22
+ public buildCheckpointGlobalVariables(
23
+ _coinbase: EthAddress,
24
+ _feeRecipient: AztecAddress,
25
+ _slotNumber: SlotNumber,
26
+ ): Promise<CheckpointGlobalVariables> {
27
+ const vars = makeGlobalVariables();
28
+ return Promise.resolve({
29
+ chainId: vars.chainId,
30
+ version: vars.version,
31
+ slotNumber: vars.slotNumber,
32
+ timestamp: vars.timestamp,
33
+ coinbase: vars.coinbase,
34
+ feeRecipient: vars.feeRecipient,
35
+ gasFees: vars.gasFees,
36
+ });
37
+ }
21
38
  }
@@ -2,8 +2,9 @@ import { type AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
2
2
  import { TestCircuitVerifier } from '@aztec/bb-prover/test';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
5
- import { SyncDataProvider } from '@aztec/pxe/server';
6
- import { type L2Block, PublishedL2Block } from '@aztec/stdlib/block';
5
+ import { AnchorBlockStore } from '@aztec/pxe/server';
6
+ import { L2BlockNew } from '@aztec/stdlib/block';
7
+ import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
7
8
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
8
9
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
9
10
 
@@ -21,13 +22,13 @@ export class TXEStateMachine {
21
22
  public node: AztecNode,
22
23
  public synchronizer: TXESynchronizer,
23
24
  public archiver: TXEArchiver,
24
- public syncDataProvider: SyncDataProvider,
25
+ public anchorBlockStore: AnchorBlockStore,
25
26
  ) {}
26
27
 
27
28
  public static async create(db: AztecAsyncKVStore) {
28
29
  const archiver = new TXEArchiver(db);
29
30
  const synchronizer = await TXESynchronizer.create();
30
- const syncDataProvider = new SyncDataProvider(db);
31
+ const anchorBlockStore = new AnchorBlockStore(db);
31
32
 
32
33
  const aztecNodeConfig = {} as AztecNodeConfig;
33
34
 
@@ -54,24 +55,32 @@ export class TXEStateMachine {
54
55
  log,
55
56
  );
56
57
 
57
- return new this(node, synchronizer, archiver, syncDataProvider);
58
+ return new this(node, synchronizer, archiver, anchorBlockStore);
58
59
  }
59
60
 
60
- public async handleL2Block(block: L2Block) {
61
+ public async handleL2Block(block: L2BlockNew) {
62
+ // Create a checkpoint from the block - L2BlockNew doesn't have toCheckpoint() method
63
+ // We need to construct the Checkpoint manually
64
+ const checkpoint = await Checkpoint.random(block.checkpointNumber, {
65
+ numBlocks: 1,
66
+ startBlockNumber: Number(block.number),
67
+ });
68
+ // Replace the random block with our actual block
69
+ checkpoint.blocks = [block];
70
+
71
+ const publishedCheckpoint = new PublishedCheckpoint(
72
+ checkpoint,
73
+ new L1PublishedData(
74
+ BigInt(block.header.globalVariables.blockNumber),
75
+ block.header.globalVariables.timestamp,
76
+ block.header.globalVariables.blockNumber.toString(),
77
+ ),
78
+ [],
79
+ );
61
80
  await Promise.all([
62
- this.synchronizer.handleL2Block(block.toL2Block()),
63
- this.archiver.addBlocks([
64
- PublishedL2Block.fromFields({
65
- block,
66
- l1: {
67
- blockHash: block.header.globalVariables.blockNumber.toString(),
68
- blockNumber: BigInt(block.header.globalVariables.blockNumber),
69
- timestamp: block.header.globalVariables.timestamp,
70
- },
71
- attestations: [],
72
- }),
73
- ]),
74
- this.syncDataProvider.setHeader(block.getBlockHeader()),
81
+ this.synchronizer.handleL2Block(block), // L2BlockNew doesn't need toL2Block() conversion
82
+ this.archiver.addCheckpoints([publishedCheckpoint], undefined),
83
+ this.anchorBlockStore.setHeader(block.header), // Use .header property directly
75
84
  ]);
76
85
  }
77
86
  }
@@ -12,6 +12,7 @@ export class MockEpochCache implements EpochCacheInterface {
12
12
  committee: undefined,
13
13
  seed: 0n,
14
14
  epoch: EpochNumber.ZERO,
15
+ isEscapeHatchOpen: false,
15
16
  });
16
17
  }
17
18
 
@@ -54,6 +55,10 @@ export class MockEpochCache implements EpochCacheInterface {
54
55
  });
55
56
  }
56
57
 
58
+ getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined> {
59
+ return Promise.resolve(undefined);
60
+ }
61
+
57
62
  isInCommittee(_slot: SlotTag, _validator: EthAddress): Promise<boolean> {
58
63
  return Promise.resolve(false);
59
64
  }