@aztec/archiver 4.0.0-devnet.2-patch.4 → 4.0.0-devnet.3-patch.1

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 (78) hide show
  1. package/dest/archiver.d.ts +3 -3
  2. package/dest/archiver.d.ts.map +1 -1
  3. package/dest/archiver.js +67 -22
  4. package/dest/errors.d.ts +7 -9
  5. package/dest/errors.d.ts.map +1 -1
  6. package/dest/errors.js +9 -14
  7. package/dest/factory.d.ts +3 -4
  8. package/dest/factory.d.ts.map +1 -1
  9. package/dest/factory.js +25 -23
  10. package/dest/l1/bin/retrieve-calldata.js +32 -28
  11. package/dest/l1/calldata_retriever.d.ts +70 -53
  12. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  13. package/dest/l1/calldata_retriever.js +178 -260
  14. package/dest/l1/data_retrieval.d.ts +2 -6
  15. package/dest/l1/data_retrieval.d.ts.map +1 -1
  16. package/dest/l1/data_retrieval.js +6 -11
  17. package/dest/l1/spire_proposer.d.ts +5 -5
  18. package/dest/l1/spire_proposer.d.ts.map +1 -1
  19. package/dest/l1/spire_proposer.js +9 -17
  20. package/dest/modules/data_source_base.d.ts +3 -3
  21. package/dest/modules/data_source_base.d.ts.map +1 -1
  22. package/dest/modules/data_source_base.js +1 -1
  23. package/dest/modules/data_store_updater.d.ts +15 -7
  24. package/dest/modules/data_store_updater.d.ts.map +1 -1
  25. package/dest/modules/data_store_updater.js +75 -23
  26. package/dest/modules/l1_synchronizer.d.ts +3 -7
  27. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  28. package/dest/modules/l1_synchronizer.js +36 -6
  29. package/dest/store/block_store.d.ts +13 -13
  30. package/dest/store/block_store.d.ts.map +1 -1
  31. package/dest/store/block_store.js +111 -66
  32. package/dest/store/contract_class_store.d.ts +1 -1
  33. package/dest/store/contract_class_store.d.ts.map +1 -1
  34. package/dest/store/contract_class_store.js +6 -2
  35. package/dest/store/contract_instance_store.d.ts +1 -1
  36. package/dest/store/contract_instance_store.d.ts.map +1 -1
  37. package/dest/store/contract_instance_store.js +6 -2
  38. package/dest/store/kv_archiver_store.d.ts +20 -12
  39. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  40. package/dest/store/kv_archiver_store.js +24 -13
  41. package/dest/store/log_store.d.ts +1 -1
  42. package/dest/store/log_store.d.ts.map +1 -1
  43. package/dest/store/log_store.js +48 -10
  44. package/dest/store/message_store.js +1 -1
  45. package/dest/test/fake_l1_state.d.ts +17 -1
  46. package/dest/test/fake_l1_state.d.ts.map +1 -1
  47. package/dest/test/fake_l1_state.js +83 -12
  48. package/dest/test/mock_l2_block_source.d.ts +4 -3
  49. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  50. package/dest/test/mock_l2_block_source.js +7 -4
  51. package/dest/test/mock_structs.d.ts +4 -1
  52. package/dest/test/mock_structs.d.ts.map +1 -1
  53. package/dest/test/mock_structs.js +13 -1
  54. package/dest/test/noop_l1_archiver.d.ts +4 -1
  55. package/dest/test/noop_l1_archiver.d.ts.map +1 -1
  56. package/dest/test/noop_l1_archiver.js +5 -1
  57. package/package.json +13 -13
  58. package/src/archiver.ts +80 -22
  59. package/src/errors.ts +10 -24
  60. package/src/factory.ts +22 -13
  61. package/src/l1/README.md +25 -68
  62. package/src/l1/bin/retrieve-calldata.ts +40 -27
  63. package/src/l1/calldata_retriever.ts +231 -383
  64. package/src/l1/data_retrieval.ts +3 -16
  65. package/src/l1/spire_proposer.ts +7 -15
  66. package/src/modules/data_source_base.ts +3 -3
  67. package/src/modules/data_store_updater.ts +81 -26
  68. package/src/modules/l1_synchronizer.ts +41 -10
  69. package/src/store/block_store.ts +134 -74
  70. package/src/store/contract_class_store.ts +7 -3
  71. package/src/store/contract_instance_store.ts +8 -5
  72. package/src/store/kv_archiver_store.ts +31 -17
  73. package/src/store/log_store.ts +66 -12
  74. package/src/store/message_store.ts +1 -1
  75. package/src/test/fake_l1_state.ts +110 -14
  76. package/src/test/mock_l2_block_source.ts +15 -3
  77. package/src/test/mock_structs.ts +20 -6
  78. package/src/test/noop_l1_archiver.ts +7 -1
@@ -14,6 +14,7 @@ import { CommitteeAttestation, CommitteeAttestationsAndSigners, L2Block } from '
14
14
  import { Checkpoint } from '@aztec/stdlib/checkpoint';
15
15
  import { getSlotAtTimestamp } from '@aztec/stdlib/epoch-helpers';
16
16
  import { InboxLeaf } from '@aztec/stdlib/messaging';
17
+ import { ConsensusPayload, SignatureDomainSeparator } from '@aztec/stdlib/p2p';
17
18
  import {
18
19
  makeAndSignCommitteeAttestationsAndSigners,
19
20
  makeCheckpointAttestationFromCheckpoint,
@@ -22,7 +23,16 @@ import {
22
23
  import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
23
24
 
24
25
  import { type MockProxy, mock } from 'jest-mock-extended';
25
- import { type FormattedBlock, type Transaction, encodeFunctionData, multicall3Abi, toHex } from 'viem';
26
+ import {
27
+ type AbiParameter,
28
+ type FormattedBlock,
29
+ type Transaction,
30
+ encodeAbiParameters,
31
+ encodeFunctionData,
32
+ keccak256,
33
+ multicall3Abi,
34
+ toHex,
35
+ } from 'viem';
26
36
 
27
37
  import { updateRollingHash } from '../structs/inbox_message.js';
28
38
 
@@ -87,6 +97,10 @@ type CheckpointData = {
87
97
  blobHashes: `0x${string}`[];
88
98
  blobs: Blob[];
89
99
  signers: Secp256k1Signer[];
100
+ /** Hash of the packed attestations, matching what the L1 event emits. */
101
+ attestationsHash: Buffer32;
102
+ /** Payload digest, matching what the L1 event emits. */
103
+ payloadDigest: Buffer32;
90
104
  /** If true, archiveAt will ignore it */
91
105
  pruned?: boolean;
92
106
  };
@@ -136,8 +150,12 @@ export class FakeL1State {
136
150
  // Computed from checkpoints based on L1 block visibility
137
151
  private pendingCheckpointNumber: CheckpointNumber = CheckpointNumber(0);
138
152
 
153
+ // The L1 block number reported as "finalized" (defaults to the start block)
154
+ private finalizedL1BlockNumber: bigint;
155
+
139
156
  constructor(private readonly config: FakeL1StateConfig) {
140
157
  this.l1BlockNumber = config.l1StartBlock;
158
+ this.finalizedL1BlockNumber = config.l1StartBlock;
141
159
  this.lastArchive = new AppendOnlyTreeSnapshot(config.genesisArchiveRoot, 1);
142
160
  }
143
161
 
@@ -194,8 +212,8 @@ export class FakeL1State {
194
212
  // Store the messages internally so they match the checkpoint's inHash
195
213
  this.addMessages(checkpointNumber, messagesL1BlockNumber, messages);
196
214
 
197
- // Create the transaction and blobs
198
- const tx = await this.makeRollupTx(checkpoint, signers);
215
+ // Create the transaction, blobs, and event hashes
216
+ const { tx, attestationsHash, payloadDigest } = await this.makeRollupTx(checkpoint, signers);
199
217
  const blobHashes = await this.makeVersionedBlobHashes(checkpoint);
200
218
  const blobs = await this.makeBlobsFromCheckpoint(checkpoint);
201
219
 
@@ -208,6 +226,8 @@ export class FakeL1State {
208
226
  blobHashes,
209
227
  blobs,
210
228
  signers,
229
+ attestationsHash,
230
+ payloadDigest,
211
231
  });
212
232
 
213
233
  // Update last archive for auto-chaining
@@ -267,11 +287,30 @@ export class FakeL1State {
267
287
  this.updatePendingCheckpointNumber();
268
288
  }
269
289
 
290
+ /** Sets the L1 block number that will be reported as "finalized". */
291
+ setFinalizedL1BlockNumber(blockNumber: bigint): void {
292
+ this.finalizedL1BlockNumber = blockNumber;
293
+ }
294
+
270
295
  /** Marks a checkpoint as proven. Updates provenCheckpointNumber. */
271
296
  markCheckpointAsProven(checkpointNumber: CheckpointNumber): void {
272
297
  this.provenCheckpointNumber = checkpointNumber;
273
298
  }
274
299
 
300
+ /**
301
+ * Simulates what `rollup.getProvenCheckpointNumber({ blockNumber: atL1Block })` would return.
302
+ */
303
+ getProvenCheckpointNumberAtL1Block(atL1Block: bigint): CheckpointNumber {
304
+ if (this.provenCheckpointNumber === 0) {
305
+ return CheckpointNumber(0);
306
+ }
307
+ const checkpoint = this.checkpoints.find(cp => cp.checkpointNumber === this.provenCheckpointNumber);
308
+ if (checkpoint && checkpoint.l1BlockNumber <= atL1Block) {
309
+ return this.provenCheckpointNumber;
310
+ }
311
+ return CheckpointNumber(0);
312
+ }
313
+
275
314
  /** Sets the target committee size for attestation validation. */
276
315
  setTargetCommitteeSize(size: number): void {
277
316
  this.targetCommitteeSize = size;
@@ -292,6 +331,21 @@ export class FakeL1State {
292
331
  this.updatePendingCheckpointNumber();
293
332
  }
294
333
 
334
+ /**
335
+ * Moves a checkpoint to a different L1 block number (simulates L1 reorg that
336
+ * re-includes the same checkpoint transaction in a different block).
337
+ * The checkpoint content stays the same — only the L1 metadata changes.
338
+ * Auto-updates pending status.
339
+ */
340
+ moveCheckpointToL1Block(checkpointNumber: CheckpointNumber, newL1BlockNumber: bigint): void {
341
+ for (const cpData of this.checkpoints) {
342
+ if (cpData.checkpointNumber === checkpointNumber) {
343
+ cpData.l1BlockNumber = newL1BlockNumber;
344
+ }
345
+ }
346
+ this.updatePendingCheckpointNumber();
347
+ }
348
+
295
349
  /**
296
350
  * Removes messages after a given total index (simulates L1 reorg).
297
351
  * Auto-updates rolling hash.
@@ -390,6 +444,11 @@ export class FakeL1State {
390
444
  });
391
445
  });
392
446
 
447
+ mockRollup.getProvenCheckpointNumber.mockImplementation((options?: { blockNumber?: bigint }) => {
448
+ const atBlock = options?.blockNumber ?? this.l1BlockNumber;
449
+ return Promise.resolve(this.getProvenCheckpointNumberAtL1Block(atBlock));
450
+ });
451
+
393
452
  mockRollup.canPruneAtTime.mockImplementation(() => Promise.resolve(this.canPruneResult));
394
453
 
395
454
  // Mock the wrapper method for fetching checkpoint events
@@ -433,10 +492,13 @@ export class FakeL1State {
433
492
  publicClient.getChainId.mockResolvedValue(1);
434
493
  publicClient.getBlockNumber.mockImplementation(() => Promise.resolve(this.l1BlockNumber));
435
494
 
436
- // Use async function pattern that existing test uses for getBlock
437
-
438
- publicClient.getBlock.mockImplementation((async (args: { blockNumber?: bigint } = {}) => {
439
- const blockNum = args.blockNumber ?? (await publicClient.getBlockNumber());
495
+ publicClient.getBlock.mockImplementation((async (args: { blockNumber?: bigint; blockTag?: string } = {}) => {
496
+ let blockNum: bigint;
497
+ if (args.blockTag === 'finalized') {
498
+ blockNum = this.finalizedL1BlockNumber;
499
+ } else {
500
+ blockNum = args.blockNumber ?? (await publicClient.getBlockNumber());
501
+ }
440
502
  return {
441
503
  number: blockNum,
442
504
  timestamp: BigInt(blockNum) * BigInt(this.config.ethereumSlotDuration) + this.config.l1GenesisTime,
@@ -510,10 +572,8 @@ export class FakeL1State {
510
572
  checkpointNumber: cpData.checkpointNumber,
511
573
  archive: cpData.checkpoint.archive.root,
512
574
  versionedBlobHashes: cpData.blobHashes.map(h => Buffer.from(h.slice(2), 'hex')),
513
- // These are intentionally undefined to skip hash validation in the archiver
514
- // (validation is skipped when these fields are falsy)
515
- payloadDigest: undefined,
516
- attestationsHash: undefined,
575
+ attestationsHash: cpData.attestationsHash,
576
+ payloadDigest: cpData.payloadDigest,
517
577
  },
518
578
  }));
519
579
  }
@@ -539,7 +599,10 @@ export class FakeL1State {
539
599
  }));
540
600
  }
541
601
 
542
- private async makeRollupTx(checkpoint: Checkpoint, signers: Secp256k1Signer[]): Promise<Transaction> {
602
+ private async makeRollupTx(
603
+ checkpoint: Checkpoint,
604
+ signers: Secp256k1Signer[],
605
+ ): Promise<{ tx: Transaction; attestationsHash: Buffer32; payloadDigest: Buffer32 }> {
543
606
  const attestations = signers
544
607
  .map(signer => makeCheckpointAttestationFromCheckpoint(checkpoint, signer))
545
608
  .map(attestation => CommitteeAttestation.fromSignature(attestation.signature))
@@ -557,6 +620,8 @@ export class FakeL1State {
557
620
  signers[0],
558
621
  );
559
622
 
623
+ const packedAttestations = attestationsAndSigners.getPackedAttestations();
624
+
560
625
  const rollupInput = encodeFunctionData({
561
626
  abi: RollupAbi,
562
627
  functionName: 'propose',
@@ -566,7 +631,7 @@ export class FakeL1State {
566
631
  archive,
567
632
  oracleInput: { feeAssetPriceModifier: 0n },
568
633
  },
569
- attestationsAndSigners.getPackedAttestations(),
634
+ packedAttestations,
570
635
  attestationsAndSigners.getSigners().map(signer => signer.toString()),
571
636
  attestationsAndSignersSignature.toViemSignature(),
572
637
  blobInput,
@@ -587,12 +652,43 @@ export class FakeL1State {
587
652
  ],
588
653
  });
589
654
 
590
- return {
655
+ // Compute attestationsHash (same logic as CalldataRetriever)
656
+ const attestationsHash = Buffer32.fromString(
657
+ keccak256(encodeAbiParameters([this.getCommitteeAttestationsStructDef()], [packedAttestations])),
658
+ );
659
+
660
+ // Compute payloadDigest (same logic as CalldataRetriever)
661
+ const consensusPayload = ConsensusPayload.fromCheckpoint(checkpoint);
662
+ const payloadToSign = consensusPayload.getPayloadToSign(SignatureDomainSeparator.checkpointAttestation);
663
+ const payloadDigest = Buffer32.fromString(keccak256(payloadToSign));
664
+
665
+ const tx = {
591
666
  input: multiCallInput,
592
667
  hash: archive,
593
668
  blockHash: archive,
594
669
  to: MULTI_CALL_3_ADDRESS as `0x${string}`,
595
670
  } as Transaction<bigint, number>;
671
+
672
+ return { tx, attestationsHash, payloadDigest };
673
+ }
674
+
675
+ /** Extracts the CommitteeAttestations struct definition from RollupAbi for hash computation. */
676
+ private getCommitteeAttestationsStructDef(): AbiParameter {
677
+ const proposeFunction = RollupAbi.find(item => item.type === 'function' && item.name === 'propose') as
678
+ | { type: 'function'; name: string; inputs: readonly AbiParameter[] }
679
+ | undefined;
680
+
681
+ if (!proposeFunction) {
682
+ throw new Error('propose function not found in RollupAbi');
683
+ }
684
+
685
+ const attestationsParam = proposeFunction.inputs.find(param => param.name === '_attestations');
686
+ if (!attestationsParam) {
687
+ throw new Error('_attestations parameter not found in propose function');
688
+ }
689
+
690
+ const tupleParam = attestationsParam as unknown as { type: 'tuple'; components?: readonly AbiParameter[] };
691
+ return { type: 'tuple', components: tupleParam.components || [] } as AbiParameter;
596
692
  }
597
693
 
598
694
  private async makeVersionedBlobHashes(checkpoint: Checkpoint): Promise<`0x${string}`[]> {
@@ -18,7 +18,12 @@ import {
18
18
  } from '@aztec/stdlib/block';
19
19
  import { Checkpoint, type CheckpointData, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
20
20
  import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
21
- import { EmptyL1RollupConstants, type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
21
+ import {
22
+ EmptyL1RollupConstants,
23
+ type L1RollupConstants,
24
+ getEpochAtSlot,
25
+ getSlotRangeForEpoch,
26
+ } from '@aztec/stdlib/epoch-helpers';
22
27
  import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
23
28
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
24
29
  import { type BlockHeader, TxExecutionResult, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
@@ -42,6 +47,12 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
42
47
  await this.createCheckpoints(numBlocks, 1);
43
48
  }
44
49
 
50
+ public getCheckpointNumber(): Promise<CheckpointNumber> {
51
+ return Promise.resolve(
52
+ this.checkpointList.length === 0 ? CheckpointNumber.ZERO : CheckpointNumber(this.checkpointList.length),
53
+ );
54
+ }
55
+
45
56
  /** Creates checkpoints, each containing `blocksPerCheckpoint` blocks. */
46
57
  public async createCheckpoints(numCheckpoints: number, blocksPerCheckpoint: number = 1) {
47
58
  for (let c = 0; c < numCheckpoints; c++) {
@@ -388,6 +399,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
388
399
  txEffect.transactionFee.toBigInt(),
389
400
  await block.hash(),
390
401
  block.number,
402
+ getEpochAtSlot(block.slot, EmptyL1RollupConstants),
391
403
  );
392
404
  }
393
405
  }
@@ -441,11 +453,11 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
441
453
  };
442
454
  }
443
455
 
444
- getL2EpochNumber(): Promise<EpochNumber> {
456
+ getSyncedL2EpochNumber(): Promise<EpochNumber> {
445
457
  throw new Error('Method not implemented.');
446
458
  }
447
459
 
448
- getL2SlotNumber(): Promise<SlotNumber> {
460
+ getSyncedL2SlotNumber(): Promise<SlotNumber> {
449
461
  throw new Error('Method not implemented.');
450
462
  }
451
463
 
@@ -127,6 +127,25 @@ export function makeL1PublishedData(l1BlockNumber: number): L1PublishedData {
127
127
  return new L1PublishedData(BigInt(l1BlockNumber), BigInt(l1BlockNumber * 1000), makeBlockHash(l1BlockNumber));
128
128
  }
129
129
 
130
+ /** Creates a Checkpoint from a list of blocks with a header that matches the blocks' structure. */
131
+ export function makeCheckpoint(blocks: L2Block[], checkpointNumber = CheckpointNumber(1)): Checkpoint {
132
+ const firstBlock = blocks[0];
133
+ const { slotNumber, timestamp, coinbase, feeRecipient, gasFees } = firstBlock.header.globalVariables;
134
+ return new Checkpoint(
135
+ blocks.at(-1)!.archive,
136
+ CheckpointHeader.random({
137
+ lastArchiveRoot: firstBlock.header.lastArchive.root,
138
+ slotNumber,
139
+ timestamp,
140
+ coinbase,
141
+ feeRecipient,
142
+ gasFees,
143
+ }),
144
+ blocks,
145
+ checkpointNumber,
146
+ );
147
+ }
148
+
130
149
  /** Wraps a Checkpoint with L1 published data and random attestations. */
131
150
  export function makePublishedCheckpoint(
132
151
  checkpoint: Checkpoint,
@@ -301,11 +320,6 @@ export async function makeCheckpointWithLogs(
301
320
  return txEffect;
302
321
  });
303
322
 
304
- const checkpoint = new Checkpoint(
305
- AppendOnlyTreeSnapshot.random(),
306
- CheckpointHeader.random(),
307
- [block],
308
- CheckpointNumber.fromBlockNumber(BlockNumber(blockNumber)),
309
- );
323
+ const checkpoint = makeCheckpoint([block], CheckpointNumber.fromBlockNumber(BlockNumber(blockNumber)));
310
324
  return makePublishedCheckpoint(checkpoint, blockNumber);
311
325
  }
@@ -1,6 +1,7 @@
1
1
  import type { BlobClientInterface } from '@aztec/blob-client/client';
2
2
  import type { RollupContract } from '@aztec/ethereum/contracts';
3
3
  import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
4
+ import { SlotNumber } from '@aztec/foundation/branded-types';
4
5
  import { Buffer32 } from '@aztec/foundation/buffer';
5
6
  import { Fr } from '@aztec/foundation/curves/bn254';
6
7
  import { EthAddress } from '@aztec/foundation/eth-address';
@@ -30,7 +31,7 @@ class NoopL1Synchronizer implements FunctionsOf<ArchiverL1Synchronizer> {
30
31
  return 0n;
31
32
  }
32
33
  getL1Timestamp(): bigint | undefined {
33
- return 0n;
34
+ return undefined;
34
35
  }
35
36
  testEthereumNodeSynced(): Promise<void> {
36
37
  return Promise.resolve();
@@ -96,6 +97,11 @@ export class NoopL1Archiver extends Archiver {
96
97
  this.runningPromise.start();
97
98
  return Promise.resolve();
98
99
  }
100
+
101
+ /** Always reports as fully synced since there is no real L1 to sync from. */
102
+ public override getSyncedL2SlotNumber(): Promise<SlotNumber | undefined> {
103
+ return Promise.resolve(SlotNumber(Number.MAX_SAFE_INTEGER));
104
+ }
99
105
  }
100
106
 
101
107
  /** Creates an archiver with mocked L1 connectivity for testing. */