@aztec/archiver 0.0.1-commit.f504929 → 0.0.1-commit.f5a9928

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 (121) hide show
  1. package/README.md +19 -13
  2. package/dest/archiver.d.ts +73 -18
  3. package/dest/archiver.d.ts.map +1 -1
  4. package/dest/archiver.js +321 -81
  5. package/dest/config.d.ts +7 -3
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +43 -14
  8. package/dest/errors.d.ts +55 -9
  9. package/dest/errors.d.ts.map +1 -1
  10. package/dest/errors.js +81 -14
  11. package/dest/factory.d.ts +20 -9
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +85 -37
  14. package/dest/index.d.ts +11 -3
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +10 -2
  17. package/dest/l1/calldata_retriever.d.ts +9 -1
  18. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  19. package/dest/l1/calldata_retriever.js +22 -11
  20. package/dest/l1/data_retrieval.d.ts +25 -11
  21. package/dest/l1/data_retrieval.d.ts.map +1 -1
  22. package/dest/l1/data_retrieval.js +25 -32
  23. package/dest/l1/trace_tx.d.ts +12 -66
  24. package/dest/l1/trace_tx.d.ts.map +1 -1
  25. package/dest/l1/validate_historical_logs.d.ts +23 -0
  26. package/dest/l1/validate_historical_logs.d.ts.map +1 -0
  27. package/dest/l1/validate_historical_logs.js +108 -0
  28. package/dest/modules/contract_data_source_adapter.d.ts +25 -0
  29. package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
  30. package/dest/modules/contract_data_source_adapter.js +32 -0
  31. package/dest/modules/data_source_base.d.ts +73 -50
  32. package/dest/modules/data_source_base.d.ts.map +1 -1
  33. package/dest/modules/data_source_base.js +250 -144
  34. package/dest/modules/data_store_updater.d.ts +42 -17
  35. package/dest/modules/data_store_updater.d.ts.map +1 -1
  36. package/dest/modules/data_store_updater.js +198 -123
  37. package/dest/modules/instrumentation.d.ts +15 -2
  38. package/dest/modules/instrumentation.d.ts.map +1 -1
  39. package/dest/modules/instrumentation.js +48 -9
  40. package/dest/modules/l1_synchronizer.d.ts +14 -8
  41. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  42. package/dest/modules/l1_synchronizer.js +477 -213
  43. package/dest/modules/outbox_trees_resolver.d.ts +64 -0
  44. package/dest/modules/outbox_trees_resolver.d.ts.map +1 -0
  45. package/dest/modules/outbox_trees_resolver.js +184 -0
  46. package/dest/modules/validation.d.ts +30 -7
  47. package/dest/modules/validation.d.ts.map +1 -1
  48. package/dest/modules/validation.js +35 -17
  49. package/dest/store/block_store.d.ts +186 -78
  50. package/dest/store/block_store.d.ts.map +1 -1
  51. package/dest/store/block_store.js +763 -290
  52. package/dest/store/contract_class_store.d.ts +17 -4
  53. package/dest/store/contract_class_store.d.ts.map +1 -1
  54. package/dest/store/contract_class_store.js +42 -68
  55. package/dest/store/contract_instance_store.d.ts +28 -1
  56. package/dest/store/contract_instance_store.d.ts.map +1 -1
  57. package/dest/store/contract_instance_store.js +58 -6
  58. package/dest/store/data_stores.d.ts +68 -0
  59. package/dest/store/data_stores.d.ts.map +1 -0
  60. package/dest/store/data_stores.js +54 -0
  61. package/dest/store/function_names_cache.d.ts +17 -0
  62. package/dest/store/function_names_cache.d.ts.map +1 -0
  63. package/dest/store/function_names_cache.js +30 -0
  64. package/dest/store/l2_tips_cache.d.ts +13 -7
  65. package/dest/store/l2_tips_cache.d.ts.map +1 -1
  66. package/dest/store/l2_tips_cache.js +13 -76
  67. package/dest/store/log_store.d.ts +42 -37
  68. package/dest/store/log_store.d.ts.map +1 -1
  69. package/dest/store/log_store.js +262 -408
  70. package/dest/store/log_store_codec.d.ts +78 -0
  71. package/dest/store/log_store_codec.d.ts.map +1 -0
  72. package/dest/store/log_store_codec.js +110 -0
  73. package/dest/store/message_store.d.ts +11 -1
  74. package/dest/store/message_store.d.ts.map +1 -1
  75. package/dest/store/message_store.js +51 -9
  76. package/dest/test/fake_l1_state.d.ts +20 -1
  77. package/dest/test/fake_l1_state.d.ts.map +1 -1
  78. package/dest/test/fake_l1_state.js +117 -21
  79. package/dest/test/mock_l2_block_source.d.ts +51 -52
  80. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  81. package/dest/test/mock_l2_block_source.js +232 -180
  82. package/dest/test/mock_structs.d.ts +4 -1
  83. package/dest/test/mock_structs.d.ts.map +1 -1
  84. package/dest/test/mock_structs.js +15 -3
  85. package/dest/test/noop_l1_archiver.d.ts +17 -6
  86. package/dest/test/noop_l1_archiver.d.ts.map +1 -1
  87. package/dest/test/noop_l1_archiver.js +31 -11
  88. package/package.json +15 -14
  89. package/src/archiver.ts +415 -90
  90. package/src/config.ts +51 -13
  91. package/src/errors.ts +122 -21
  92. package/src/factory.ts +99 -30
  93. package/src/index.ts +18 -2
  94. package/src/l1/calldata_retriever.ts +29 -11
  95. package/src/l1/data_retrieval.ts +44 -46
  96. package/src/l1/validate_historical_logs.ts +140 -0
  97. package/src/modules/contract_data_source_adapter.ts +46 -0
  98. package/src/modules/data_source_base.ts +327 -189
  99. package/src/modules/data_store_updater.ts +235 -155
  100. package/src/modules/instrumentation.ts +43 -10
  101. package/src/modules/l1_synchronizer.ts +646 -259
  102. package/src/modules/outbox_trees_resolver.ts +220 -0
  103. package/src/modules/validation.ts +80 -23
  104. package/src/store/block_store.ts +930 -348
  105. package/src/store/contract_class_store.ts +49 -103
  106. package/src/store/contract_instance_store.ts +74 -11
  107. package/src/store/data_stores.ts +104 -0
  108. package/src/store/function_names_cache.ts +37 -0
  109. package/src/store/l2_tips_cache.ts +16 -70
  110. package/src/store/log_store.ts +302 -559
  111. package/src/store/log_store_codec.ts +143 -0
  112. package/src/store/message_store.ts +60 -10
  113. package/src/structs/inbox_message.ts +1 -1
  114. package/src/test/fake_l1_state.ts +145 -32
  115. package/src/test/mock_l2_block_source.ts +292 -227
  116. package/src/test/mock_structs.ts +25 -8
  117. package/src/test/noop_l1_archiver.ts +61 -12
  118. package/dest/store/kv_archiver_store.d.ts +0 -354
  119. package/dest/store/kv_archiver_store.d.ts.map +0 -1
  120. package/dest/store/kv_archiver_store.js +0 -464
  121. package/src/store/kv_archiver_store.ts +0 -671
@@ -1,12 +1,13 @@
1
1
  import { MULTI_CALL_3_ADDRESS, type ViemCommitteeAttestations, type ViemHeader } from '@aztec/ethereum/contracts';
2
2
  import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
3
3
  import { CheckpointNumber } from '@aztec/foundation/branded-types';
4
+ import { LruSet } from '@aztec/foundation/collection';
4
5
  import { Fr } from '@aztec/foundation/curves/bn254';
5
6
  import { EthAddress } from '@aztec/foundation/eth-address';
6
7
  import type { Logger } from '@aztec/foundation/log';
7
8
  import { RollupAbi } from '@aztec/l1-artifacts';
8
9
  import { CommitteeAttestation } from '@aztec/stdlib/block';
9
- import { ConsensusPayload, SignatureDomainSeparator } from '@aztec/stdlib/p2p';
10
+ import { computeCheckpointPayloadDigest } from '@aztec/stdlib/checkpoint';
10
11
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
11
12
 
12
13
  import {
@@ -33,6 +34,12 @@ type CheckpointData = {
33
34
  archiveRoot: Fr;
34
35
  header: CheckpointHeader;
35
36
  attestations: CommitteeAttestation[];
37
+ /**
38
+ * The exact packed `CommitteeAttestations` tuple as it appears in the propose calldata, preserved
39
+ * verbatim (never re-derived from {@link attestations}) so invalidation evidence stays byte-faithful to
40
+ * the on-chain `attestationsHash`.
41
+ */
42
+ verbatimAttestations: ViemCommitteeAttestations;
36
43
  blockHash: string;
37
44
  feeAssetPriceModifier: bigint;
38
45
  };
@@ -44,7 +51,7 @@ type CheckpointData = {
44
51
  */
45
52
  export class CalldataRetriever {
46
53
  /** Tx hashes we've already logged for trace+debug failure (log once per tx per process). */
47
- private static readonly traceFailureWarnedTxHashes = new Set<string>();
54
+ private static readonly traceFailureWarnedTxHashes = new LruSet<string>(1000);
48
55
 
49
56
  /** Clears the trace-failure warned set. For testing only. */
50
57
  static resetTraceFailureWarnedForTesting(): void {
@@ -60,6 +67,13 @@ export class CalldataRetriever {
60
67
  private readonly rollupAddress: EthAddress,
61
68
  ) {}
62
69
 
70
+ private getSignatureContext() {
71
+ return {
72
+ chainId: this.publicClient.chain.id,
73
+ rollupAddress: this.rollupAddress,
74
+ };
75
+ }
76
+
63
77
  /**
64
78
  * Gets checkpoint header and metadata from the calldata of an L1 transaction.
65
79
  * Tries multicall3 decoding, falls back to trace-based extraction.
@@ -398,14 +412,14 @@ export class CalldataRetriever {
398
412
  return undefined;
399
413
  }
400
414
 
401
- const [decodedArgs, packedAttestations] = args! as readonly [
415
+ const [decodedArgs, verbatimAttestations] = args! as readonly [
402
416
  { archive: Hex; oracleInput: { feeAssetPriceModifier: bigint }; header: ViemHeader },
403
417
  ViemCommitteeAttestations,
404
418
  ...unknown[],
405
419
  ];
406
420
 
407
421
  // Verify attestationsHash
408
- const computedAttestationsHash = this.computeAttestationsHash(packedAttestations);
422
+ const computedAttestationsHash = this.computeAttestationsHash(verbatimAttestations);
409
423
  if (
410
424
  !Buffer.from(hexToBytes(computedAttestationsHash)).equals(
411
425
  Buffer.from(hexToBytes(expectedHashes.attestationsHash)),
@@ -433,7 +447,7 @@ export class CalldataRetriever {
433
447
  return undefined;
434
448
  }
435
449
 
436
- const attestations = CommitteeAttestation.fromPacked(packedAttestations, this.targetCommitteeSize);
450
+ const attestations = CommitteeAttestation.fromPacked(verbatimAttestations, this.targetCommitteeSize);
437
451
 
438
452
  this.logger.trace(`Validated and decoded propose calldata for checkpoint ${checkpointNumber}`, {
439
453
  checkpointNumber,
@@ -441,7 +455,7 @@ export class CalldataRetriever {
441
455
  header: decodedArgs.header,
442
456
  l1BlockHash: blockHash,
443
457
  attestations,
444
- packedAttestations,
458
+ verbatimAttestations,
445
459
  targetCommitteeSize: this.targetCommitteeSize,
446
460
  });
447
461
 
@@ -450,6 +464,7 @@ export class CalldataRetriever {
450
464
  archiveRoot,
451
465
  header,
452
466
  attestations,
467
+ verbatimAttestations,
453
468
  blockHash,
454
469
  feeAssetPriceModifier,
455
470
  };
@@ -459,15 +474,18 @@ export class CalldataRetriever {
459
474
  }
460
475
 
461
476
  /** Computes the keccak256 hash of ABI-encoded CommitteeAttestations. */
462
- private computeAttestationsHash(packedAttestations: ViemCommitteeAttestations): Hex {
463
- return keccak256(encodeAbiParameters([this.getCommitteeAttestationsStructDef()], [packedAttestations]));
477
+ private computeAttestationsHash(verbatimAttestations: ViemCommitteeAttestations): Hex {
478
+ return keccak256(encodeAbiParameters([this.getCommitteeAttestationsStructDef()], [verbatimAttestations]));
464
479
  }
465
480
 
466
481
  /** Computes the keccak256 payload digest from the checkpoint header, archive root, and fee asset price modifier. */
467
482
  private computePayloadDigest(header: CheckpointHeader, archiveRoot: Fr, feeAssetPriceModifier: bigint): Hex {
468
- const consensusPayload = new ConsensusPayload(header, archiveRoot, feeAssetPriceModifier);
469
- const payloadToSign = consensusPayload.getPayloadToSign(SignatureDomainSeparator.checkpointAttestation);
470
- return keccak256(payloadToSign);
483
+ return computeCheckpointPayloadDigest({
484
+ header,
485
+ archiveRoot,
486
+ feeAssetPriceModifier,
487
+ signatureContext: this.getSignatureContext(),
488
+ }).toString();
471
489
  }
472
490
 
473
491
  /**
@@ -12,6 +12,8 @@ import type {
12
12
  InboxContract,
13
13
  MessageSentLog,
14
14
  RollupContract,
15
+ ViemCommitteeAttestations,
16
+ ViemHeader,
15
17
  } from '@aztec/ethereum/contracts';
16
18
  import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
17
19
  import { asyncPool } from '@aztec/foundation/async-pool';
@@ -35,18 +37,33 @@ import type { DataRetrieval } from '../structs/data_retrieval.js';
35
37
  import type { InboxMessage } from '../structs/inbox_message.js';
36
38
  import { CalldataRetriever } from './calldata_retriever.js';
37
39
 
38
- export type RetrievedCheckpoint = {
40
+ type RetrievedCheckpointBase = {
39
41
  checkpointNumber: CheckpointNumber;
40
42
  archiveRoot: Fr;
41
43
  feeAssetPriceModifier: bigint;
42
44
  header: CheckpointHeader;
43
- checkpointBlobData: CheckpointBlobData;
44
45
  l1: L1PublishedData;
45
46
  chainId: Fr;
46
47
  version: Fr;
47
48
  attestations: CommitteeAttestation[];
48
49
  };
49
50
 
51
+ /** Checkpoint data as retrieved from L1 calldata and blob data. */
52
+ export type RetrievedCheckpoint = RetrievedCheckpointBase & { checkpointBlobData: CheckpointBlobData };
53
+
54
+ /** Checkpoint data retrieved from L1 calldata only, without blob data. */
55
+ export type RetrievedCheckpointFromCalldata = RetrievedCheckpointBase & {
56
+ /** Versioned blob hashes from the checkpoint proposed event. */
57
+ blobHashes: Buffer[];
58
+ /** Parent beacon block root from the L1 block, used for blob fetching. */
59
+ parentBeaconBlockRoot: string | undefined;
60
+ /**
61
+ * The exact packed `CommitteeAttestations` tuple from the propose calldata, carried verbatim so that
62
+ * attestation validation can attach byte-faithful invalidation evidence to a negative result.
63
+ */
64
+ verbatimAttestations: ViemCommitteeAttestations;
65
+ };
66
+
50
67
  export async function retrievedToPublishedCheckpoint({
51
68
  checkpointNumber,
52
69
  archiveRoot,
@@ -137,31 +154,27 @@ export async function retrievedToPublishedCheckpoint({
137
154
  }
138
155
 
139
156
  /**
140
- * Fetches new checkpoints.
157
+ * Fetches checkpoint calldata from the rollup contract without fetching blob data.
158
+ * Returns RetrievedCheckpointFromCalldata objects that preserve the information needed for deferred blob fetching.
141
159
  * @param rollup - The rollup contract wrapper.
142
160
  * @param publicClient - The viem public client to use for transaction retrieval.
143
161
  * @param debugClient - The viem debug client to use for trace/debug RPC methods (optional).
144
- * @param blobClient - The blob client client for fetching blob data.
145
162
  * @param searchStartBlock - The block number to use for starting the search.
146
163
  * @param searchEndBlock - The highest block number that we should search up to.
147
- * @param contractAddresses - The contract addresses (governanceProposerAddress, slashFactoryAddress, slashingProposerAddress).
148
164
  * @param instrumentation - The archiver instrumentation instance.
149
165
  * @param logger - The logger instance.
150
- * @param isHistoricalSync - Whether this is a historical sync.
151
- * @returns An array of retrieved checkpoints.
166
+ * @returns An array of calldata-only checkpoints.
152
167
  */
153
- export async function retrieveCheckpointsFromRollup(
168
+ export async function retrieveCheckpointCalldataFromRollup(
154
169
  rollup: RollupContract,
155
170
  publicClient: ViemPublicClient,
156
171
  debugClient: ViemPublicDebugClient,
157
- blobClient: BlobClientInterface,
158
172
  searchStartBlock: bigint,
159
173
  searchEndBlock: bigint,
160
174
  instrumentation: ArchiverInstrumentation,
161
175
  logger: Logger = createLogger('archiver'),
162
- isHistoricalSync: boolean = false,
163
- ): Promise<RetrievedCheckpoint[]> {
164
- const retrievedCheckpoints: RetrievedCheckpoint[] = [];
176
+ ): Promise<RetrievedCheckpointFromCalldata[]> {
177
+ const retrievedCheckpoints: RetrievedCheckpointFromCalldata[] = [];
165
178
 
166
179
  let rollupConstants: { chainId: Fr; version: Fr; targetCommitteeSize: number } | undefined;
167
180
 
@@ -197,46 +210,39 @@ export async function retrieveCheckpointsFromRollup(
197
210
  rollup,
198
211
  publicClient,
199
212
  debugClient,
200
- blobClient,
201
213
  checkpointProposedLogs,
202
214
  rollupConstants,
203
215
  instrumentation,
204
216
  logger,
205
- isHistoricalSync,
206
217
  );
207
218
  retrievedCheckpoints.push(...newCheckpoints);
208
219
  searchStartBlock = lastLog.l1BlockNumber + 1n;
209
220
  } while (searchStartBlock <= searchEndBlock);
210
221
 
211
- // The asyncPool from processCheckpointProposedLogs will not necessarily return the checkpoints in order, so we sort them before returning.
212
222
  return retrievedCheckpoints.sort((a, b) => Number(a.l1.blockNumber - b.l1.blockNumber));
213
223
  }
214
224
 
215
225
  /**
216
- * Processes newly received CheckpointProposed logs.
226
+ * Processes CheckpointProposed logs, fetching only calldata (no blobs).
217
227
  * @param rollup - The rollup contract wrapper.
218
228
  * @param publicClient - The viem public client to use for transaction retrieval.
219
229
  * @param debugClient - The viem debug client to use for trace/debug RPC methods (optional).
220
- * @param blobClient - The blob client client for fetching blob data.
221
230
  * @param logs - CheckpointProposed logs.
222
231
  * @param rollupConstants - The rollup constants (chainId, version, targetCommitteeSize).
223
232
  * @param instrumentation - The archiver instrumentation instance.
224
233
  * @param logger - The logger instance.
225
- * @param isHistoricalSync - Whether this is a historical sync.
226
- * @returns An array of retrieved checkpoints.
234
+ * @returns An array of calldata-only checkpoints.
227
235
  */
228
236
  async function processCheckpointProposedLogs(
229
237
  rollup: RollupContract,
230
238
  publicClient: ViemPublicClient,
231
239
  debugClient: ViemPublicDebugClient,
232
- blobClient: BlobClientInterface,
233
240
  logs: CheckpointProposedLog[],
234
241
  { chainId, version, targetCommitteeSize }: { chainId: Fr; version: Fr; targetCommitteeSize: number },
235
242
  instrumentation: ArchiverInstrumentation,
236
243
  logger: Logger,
237
- isHistoricalSync: boolean,
238
- ): Promise<RetrievedCheckpoint[]> {
239
- const retrievedCheckpoints: RetrievedCheckpoint[] = [];
244
+ ): Promise<RetrievedCheckpointFromCalldata[]> {
245
+ const retrievedCheckpoints: RetrievedCheckpointFromCalldata[] = [];
240
246
  const calldataRetriever = new CalldataRetriever(
241
247
  publicClient,
242
248
  debugClient,
@@ -252,7 +258,6 @@ async function processCheckpointProposedLogs(
252
258
  const archiveFromChain = await rollup.archiveAt(checkpointNumber);
253
259
  const blobHashes = log.args.versionedBlobHashes;
254
260
 
255
- // The value from the event and contract will match only if the checkpoint is in the chain.
256
261
  if (archive.equals(archiveFromChain)) {
257
262
  const expectedHashes = {
258
263
  attestationsHash: log.args.attestationsHash.toString() as Hex,
@@ -268,19 +273,16 @@ async function processCheckpointProposedLogs(
268
273
  const { timestamp, parentBeaconBlockRoot } = await getL1Block(publicClient, log.l1BlockNumber);
269
274
  const l1 = new L1PublishedData(log.l1BlockNumber, timestamp, log.l1BlockHash.toString());
270
275
 
271
- const checkpointBlobData = await getCheckpointBlobDataFromBlobs(
272
- blobClient,
273
- checkpoint.blockHash,
276
+ retrievedCheckpoints.push({
277
+ ...checkpoint,
278
+ l1,
279
+ chainId,
280
+ version,
274
281
  blobHashes,
275
- checkpointNumber,
276
- logger,
277
- isHistoricalSync,
278
282
  parentBeaconBlockRoot,
279
- timestamp,
280
- );
283
+ });
281
284
 
282
- retrievedCheckpoints.push({ ...checkpoint, checkpointBlobData, l1, chainId, version });
283
- logger.trace(`Retrieved checkpoint ${checkpointNumber} from L1 tx ${log.l1TransactionHash}`, {
285
+ logger.trace(`Retrieved checkpoint calldata ${checkpointNumber} from L1 tx ${log.l1TransactionHash}`, {
284
286
  l1BlockNumber: log.l1BlockNumber,
285
287
  checkpointNumber,
286
288
  archive: archive.toString(),
@@ -344,14 +346,10 @@ export async function getCheckpointBlobDataFromBlobs(
344
346
  /** Given an L1 to L2 message, retrieves its corresponding event from the Inbox within a specific block range. */
345
347
  export async function retrieveL1ToL2Message(
346
348
  inbox: InboxContract,
347
- leaf: Fr,
348
- fromBlock: bigint,
349
- toBlock: bigint,
349
+ message: InboxMessage,
350
350
  ): Promise<InboxMessage | undefined> {
351
- const logs = await inbox.getMessageSentEventByHash(leaf.toString(), fromBlock, toBlock);
352
-
353
- const messages = mapLogsInboxMessage(logs);
354
- return messages.length > 0 ? messages[0] : undefined;
351
+ const log = await inbox.getMessageSentEventByHash(message.leaf.toString(), message.l1BlockNumber);
352
+ return log && mapLogInboxMessage(log);
355
353
  }
356
354
 
357
355
  /**
@@ -374,22 +372,22 @@ export async function retrieveL1ToL2Messages(
374
372
  break;
375
373
  }
376
374
 
377
- retrievedL1ToL2Messages.push(...mapLogsInboxMessage(messageSentLogs));
375
+ retrievedL1ToL2Messages.push(...messageSentLogs.map(mapLogInboxMessage));
378
376
  searchStartBlock = messageSentLogs.at(-1)!.l1BlockNumber + 1n;
379
377
  }
380
378
 
381
379
  return retrievedL1ToL2Messages;
382
380
  }
383
381
 
384
- function mapLogsInboxMessage(logs: MessageSentLog[]): InboxMessage[] {
385
- return logs.map(log => ({
382
+ function mapLogInboxMessage(log: MessageSentLog): InboxMessage {
383
+ return {
386
384
  index: log.args.index,
387
385
  leaf: log.args.leaf,
388
386
  l1BlockNumber: log.l1BlockNumber,
389
387
  l1BlockHash: log.l1BlockHash,
390
388
  checkpointNumber: log.args.checkpointNumber,
391
389
  rollingHash: log.args.rollingHash,
392
- }));
390
+ };
393
391
  }
394
392
 
395
393
  /** Retrieves L2ProofVerified events from the rollup contract. */
@@ -469,7 +467,7 @@ export async function getProofFromSubmitProofTx(
469
467
  start: bigint;
470
468
  end: bigint;
471
469
  args: EpochProofPublicInputArgs;
472
- fees: readonly Hex[];
470
+ headers: readonly ViemHeader[];
473
471
  proof: Hex;
474
472
  },
475
473
  ];
@@ -0,0 +1,140 @@
1
+ import { getPublicClient, getRpcUrlsFromClient } from '@aztec/ethereum/client';
2
+ import { RollupContract } from '@aztec/ethereum/contracts';
3
+ import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
4
+ import type { ViemPublicClient } from '@aztec/ethereum/types';
5
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
6
+
7
+ /** Subset of L1 contract addresses whose historical logs the Aztec node relies on. */
8
+ export type HistoricalLogsContractAddresses = Pick<
9
+ L1ContractAddresses,
10
+ 'rollupAddress' | 'inboxAddress' | 'registryAddress' | 'governanceProposerAddress'
11
+ >;
12
+
13
+ /** Result of probing a single RPC URL. */
14
+ type ProbeResult = { ok: true } | { ok: false; reason: string; clientVersion: string | undefined };
15
+
16
+ /**
17
+ * Validates that every configured L1 RPC URL returns historical logs for the Rollup contract.
18
+ *
19
+ * Some RPC providers prune old logs, which would cause L1 syncing to silently fail. To detect this,
20
+ * we query for the `OwnershipTransferred` event which every Rollup emits in its constructor (via
21
+ * Ownable) on the block it was deployed (`l1StartBlock`). The `client` is typically a viem fallback
22
+ * transport over several user-configured RPC URLs — checking only the first URL would miss a bad
23
+ * secondary, so we probe each URL independently. The first URL that fails aborts startup, unless
24
+ * the operator has explicitly opted out.
25
+ *
26
+ * @param client - The L1 public client built from the user-configured RPC URLs.
27
+ * @param addresses - The subset of L1 contract addresses we rely on for historical log retrieval.
28
+ * @param skipCheck - If true, log warnings instead of throwing.
29
+ * @param bindings - Optional logger bindings for context.
30
+ * @throws Error if any URL fails the probe and skipCheck is false.
31
+ */
32
+ export async function validateAndLogHistoricalLogsAvailability(
33
+ client: ViemPublicClient,
34
+ addresses: HistoricalLogsContractAddresses,
35
+ skipCheck: boolean,
36
+ bindings?: LoggerBindings,
37
+ ): Promise<void> {
38
+ const logger = createLogger('archiver:validate_historical_logs', bindings);
39
+ logger.debug('Validating historical log availability on L1 RPCs');
40
+
41
+ const urls = getRpcUrlsFromClient(client);
42
+ if (urls.length === 0) {
43
+ logger.warn('Could not determine L1 RPC URLs from the public client; skipping historical logs check.');
44
+ return;
45
+ }
46
+
47
+ const chainId = client.chain?.id;
48
+ if (chainId === undefined) {
49
+ logger.warn('Could not determine L1 chain ID from the public client; skipping historical logs check.');
50
+ return;
51
+ }
52
+
53
+ for (const url of urls) {
54
+ const probeClient = getPublicClient({ l1RpcUrls: [url], l1ChainId: chainId });
55
+ const rollup = new RollupContract(probeClient, addresses.rollupAddress.toString());
56
+ const result = await probeRpcUrl(rollup, probeClient, logger);
57
+
58
+ if (result.ok) {
59
+ logger.debug(`L1 RPC ${url} returned historical OwnershipTransferred log for the Rollup contract.`);
60
+ continue;
61
+ }
62
+
63
+ const errorMessage = buildErrorMessage(url, result, addresses);
64
+ if (skipCheck) {
65
+ logger.warn(`${errorMessage}\nContinuing because ARCHIVER_SKIP_HISTORICAL_LOGS_CHECK is true.`);
66
+ continue;
67
+ }
68
+
69
+ logger.error(errorMessage);
70
+ throw new Error(errorMessage);
71
+ }
72
+ }
73
+
74
+ /** Runs the OwnershipTransferred probe against a single RPC and queries its client version. */
75
+ async function probeRpcUrl(rollup: RollupContract, client: ViemPublicClient, logger: Logger): Promise<ProbeResult> {
76
+ let queryError: unknown;
77
+ try {
78
+ const logs = await rollup.getOwnershipTransferredEventsAtDeploy();
79
+ if (logs.length > 0) {
80
+ return { ok: true };
81
+ }
82
+ } catch (err) {
83
+ queryError = err;
84
+ }
85
+
86
+ const clientVersion = await getClientVersion(client, logger);
87
+
88
+ let reason: string;
89
+ if (queryError instanceof Error) {
90
+ reason = `Query for historical logs failed: ${queryError.message}`;
91
+ } else if (queryError !== undefined) {
92
+ reason = 'Query for historical logs failed with a non-Error value.';
93
+ } else {
94
+ reason = 'No OwnershipTransferred event was returned by the L1 RPC for the Rollup deploy block.';
95
+ }
96
+ return { ok: false, reason, clientVersion };
97
+ }
98
+
99
+ /** Builds the operator-facing error message for a failing RPC URL. */
100
+ function buildErrorMessage(
101
+ url: string,
102
+ result: Extract<ProbeResult, { ok: false }>,
103
+ addresses: HistoricalLogsContractAddresses,
104
+ ): string {
105
+ return [
106
+ `L1 RPC at ${url} does not return historical logs for the Rollup contract. ${result.reason}`,
107
+ `This likely means this Ethereum RPC node prunes old logs, which would cause the archiver ` +
108
+ `to silently miss data during L1 sync.`,
109
+ result.clientVersion
110
+ ? `Detected L1 client version for ${url}: ${result.clientVersion}.`
111
+ : `Could not determine L1 client version for ${url}.`,
112
+ `The following L1 contract addresses must have their historical logs retained by the RPC node:`,
113
+ ` - Rollup: ${addresses.rollupAddress.toString()}`,
114
+ ` - Inbox: ${addresses.inboxAddress.toString()}`,
115
+ ` - Registry: ${addresses.registryAddress.toString()}`,
116
+ ` - GovernanceProposer: ${addresses.governanceProposerAddress.toString()}`,
117
+ isReth(result.clientVersion)
118
+ ? `To retain logs for these contracts, configure reth with a ` +
119
+ `prune.segments.receipts_log_filter entry for each address above ` +
120
+ `so reth does not prune their receipts/logs. See https://reth.rs/run/pruning.html for details.`
121
+ : `Point this RPC endpoint at a node that retains full log history for the addresses above.`,
122
+ `Set ARCHIVER_SKIP_HISTORICAL_LOGS_CHECK=true to bypass this check at your own risk.`,
123
+ ].join('\n');
124
+ }
125
+
126
+ /** Queries `web3_clientVersion` on the L1 RPC. Returns undefined if the call fails or returns a non-string. */
127
+ async function getClientVersion(client: ViemPublicClient, logger: Logger): Promise<string | undefined> {
128
+ try {
129
+ const result = await client.request({ method: 'web3_clientVersion' });
130
+ return typeof result === 'string' ? result : undefined;
131
+ } catch (err) {
132
+ logger.debug(`Failed to query web3_clientVersion: ${err instanceof Error ? err.message : err}`);
133
+ return undefined;
134
+ }
135
+ }
136
+
137
+ /** Heuristic check for reth based on the web3_clientVersion string (reth returns e.g. "reth/v1.0.0-..."). */
138
+ function isReth(clientVersion: string | undefined): boolean {
139
+ return !!clientVersion && /reth/i.test(clientVersion);
140
+ }
@@ -0,0 +1,46 @@
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import type { Fr } from '@aztec/foundation/curves/bn254';
3
+ import type { FunctionSelector } from '@aztec/stdlib/abi';
4
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
+ import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
6
+ import type { UInt64 } from '@aztec/stdlib/types';
7
+
8
+ import type { ArchiverDataStores } from '../store/data_stores.js';
9
+
10
+ /**
11
+ * Thin {@link ContractDataSource} adapter over {@link ArchiverDataStores}.
12
+ *
13
+ * Used by contexts (e.g. offline epoch re-prover tools) that need a ContractDataSource
14
+ * but do not need a full archiver instance.
15
+ */
16
+ export class ArchiverContractDataSourceAdapter implements ContractDataSource {
17
+ constructor(private readonly stores: ArchiverDataStores) {}
18
+
19
+ public getBlockNumber(): Promise<BlockNumber> {
20
+ return this.stores.blocks.getLatestL2BlockNumber();
21
+ }
22
+
23
+ public getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
24
+ return this.stores.contractClasses.getContractClass(id);
25
+ }
26
+
27
+ public getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
28
+ return this.stores.contractClasses.getBytecodeCommitment(id);
29
+ }
30
+
31
+ public getContract(address: AztecAddress, timestamp: UInt64): Promise<ContractInstanceWithAddress | undefined> {
32
+ return this.stores.contractInstances.getContractInstance(address, timestamp);
33
+ }
34
+
35
+ public getContractClassIds(): Promise<Fr[]> {
36
+ return this.stores.contractClasses.getContractClassIds();
37
+ }
38
+
39
+ public getDebugFunctionName(_address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
40
+ return Promise.resolve(this.stores.functionNames.get(selector));
41
+ }
42
+
43
+ public registerContractFunctionSignatures(signatures: string[]): Promise<void> {
44
+ return this.stores.functionNames.register(signatures);
45
+ }
46
+ }