@aztec/archiver 0.0.1-commit.f2ce05ee → 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 (132) hide show
  1. package/README.md +19 -13
  2. package/dest/archiver.d.ts +76 -18
  3. package/dest/archiver.d.ts.map +1 -1
  4. package/dest/archiver.js +329 -162
  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 +87 -39
  14. package/dest/index.d.ts +12 -3
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +11 -2
  17. package/dest/l1/bin/retrieve-calldata.js +32 -28
  18. package/dest/l1/calldata_retriever.d.ts +81 -50
  19. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  20. package/dest/l1/calldata_retriever.js +202 -260
  21. package/dest/l1/data_retrieval.d.ts +32 -18
  22. package/dest/l1/data_retrieval.d.ts.map +1 -1
  23. package/dest/l1/data_retrieval.js +42 -47
  24. package/dest/l1/spire_proposer.d.ts +5 -5
  25. package/dest/l1/spire_proposer.d.ts.map +1 -1
  26. package/dest/l1/spire_proposer.js +9 -17
  27. package/dest/l1/trace_tx.d.ts +12 -66
  28. package/dest/l1/trace_tx.d.ts.map +1 -1
  29. package/dest/l1/validate_historical_logs.d.ts +23 -0
  30. package/dest/l1/validate_historical_logs.d.ts.map +1 -0
  31. package/dest/l1/validate_historical_logs.js +108 -0
  32. package/dest/modules/contract_data_source_adapter.d.ts +25 -0
  33. package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
  34. package/dest/modules/contract_data_source_adapter.js +32 -0
  35. package/dest/modules/data_source_base.d.ts +74 -46
  36. package/dest/modules/data_source_base.d.ts.map +1 -1
  37. package/dest/modules/data_source_base.js +252 -190
  38. package/dest/modules/data_store_updater.d.ts +49 -17
  39. package/dest/modules/data_store_updater.d.ts.map +1 -1
  40. package/dest/modules/data_store_updater.js +218 -122
  41. package/dest/modules/instrumentation.d.ts +29 -3
  42. package/dest/modules/instrumentation.d.ts.map +1 -1
  43. package/dest/modules/instrumentation.js +67 -11
  44. package/dest/modules/l1_synchronizer.d.ts +16 -14
  45. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  46. package/dest/modules/l1_synchronizer.js +488 -219
  47. package/dest/modules/outbox_trees_resolver.d.ts +64 -0
  48. package/dest/modules/outbox_trees_resolver.d.ts.map +1 -0
  49. package/dest/modules/outbox_trees_resolver.js +184 -0
  50. package/dest/modules/validation.d.ts +30 -7
  51. package/dest/modules/validation.d.ts.map +1 -1
  52. package/dest/modules/validation.js +35 -17
  53. package/dest/store/block_store.d.ts +186 -74
  54. package/dest/store/block_store.d.ts.map +1 -1
  55. package/dest/store/block_store.js +810 -285
  56. package/dest/store/contract_class_store.d.ts +17 -4
  57. package/dest/store/contract_class_store.d.ts.map +1 -1
  58. package/dest/store/contract_class_store.js +42 -68
  59. package/dest/store/contract_instance_store.d.ts +28 -1
  60. package/dest/store/contract_instance_store.d.ts.map +1 -1
  61. package/dest/store/contract_instance_store.js +58 -6
  62. package/dest/store/data_stores.d.ts +68 -0
  63. package/dest/store/data_stores.d.ts.map +1 -0
  64. package/dest/store/data_stores.js +54 -0
  65. package/dest/store/function_names_cache.d.ts +17 -0
  66. package/dest/store/function_names_cache.d.ts.map +1 -0
  67. package/dest/store/function_names_cache.js +30 -0
  68. package/dest/store/l2_tips_cache.d.ts +25 -0
  69. package/dest/store/l2_tips_cache.d.ts.map +1 -0
  70. package/dest/store/l2_tips_cache.js +26 -0
  71. package/dest/store/log_store.d.ts +42 -37
  72. package/dest/store/log_store.d.ts.map +1 -1
  73. package/dest/store/log_store.js +262 -408
  74. package/dest/store/log_store_codec.d.ts +78 -0
  75. package/dest/store/log_store_codec.d.ts.map +1 -0
  76. package/dest/store/log_store_codec.js +110 -0
  77. package/dest/store/message_store.d.ts +11 -1
  78. package/dest/store/message_store.d.ts.map +1 -1
  79. package/dest/store/message_store.js +51 -9
  80. package/dest/test/fake_l1_state.d.ts +25 -1
  81. package/dest/test/fake_l1_state.d.ts.map +1 -1
  82. package/dest/test/fake_l1_state.js +166 -32
  83. package/dest/test/mock_archiver.d.ts +1 -1
  84. package/dest/test/mock_archiver.d.ts.map +1 -1
  85. package/dest/test/mock_archiver.js +3 -2
  86. package/dest/test/mock_l2_block_source.d.ts +61 -47
  87. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  88. package/dest/test/mock_l2_block_source.js +306 -211
  89. package/dest/test/mock_structs.d.ts +4 -1
  90. package/dest/test/mock_structs.d.ts.map +1 -1
  91. package/dest/test/mock_structs.js +15 -3
  92. package/dest/test/noop_l1_archiver.d.ts +17 -6
  93. package/dest/test/noop_l1_archiver.d.ts.map +1 -1
  94. package/dest/test/noop_l1_archiver.js +31 -11
  95. package/package.json +15 -14
  96. package/src/archiver.ts +427 -185
  97. package/src/config.ts +51 -13
  98. package/src/errors.ts +122 -21
  99. package/src/factory.ts +104 -29
  100. package/src/index.ts +19 -2
  101. package/src/l1/README.md +25 -68
  102. package/src/l1/bin/retrieve-calldata.ts +40 -27
  103. package/src/l1/calldata_retriever.ts +267 -379
  104. package/src/l1/data_retrieval.ts +66 -70
  105. package/src/l1/spire_proposer.ts +7 -15
  106. package/src/l1/validate_historical_logs.ts +140 -0
  107. package/src/modules/contract_data_source_adapter.ts +46 -0
  108. package/src/modules/data_source_base.ts +337 -238
  109. package/src/modules/data_store_updater.ts +259 -154
  110. package/src/modules/instrumentation.ts +71 -11
  111. package/src/modules/l1_synchronizer.ts +659 -269
  112. package/src/modules/outbox_trees_resolver.ts +220 -0
  113. package/src/modules/validation.ts +80 -23
  114. package/src/store/block_store.ts +989 -358
  115. package/src/store/contract_class_store.ts +49 -103
  116. package/src/store/contract_instance_store.ts +74 -11
  117. package/src/store/data_stores.ts +104 -0
  118. package/src/store/function_names_cache.ts +37 -0
  119. package/src/store/l2_tips_cache.ts +35 -0
  120. package/src/store/log_store.ts +302 -559
  121. package/src/store/log_store_codec.ts +143 -0
  122. package/src/store/message_store.ts +60 -10
  123. package/src/structs/inbox_message.ts +1 -1
  124. package/src/test/fake_l1_state.ts +213 -42
  125. package/src/test/mock_archiver.ts +3 -2
  126. package/src/test/mock_l2_block_source.ts +378 -233
  127. package/src/test/mock_structs.ts +25 -8
  128. package/src/test/noop_l1_archiver.ts +61 -12
  129. package/dest/store/kv_archiver_store.d.ts +0 -340
  130. package/dest/store/kv_archiver_store.d.ts.map +0 -1
  131. package/dest/store/kv_archiver_store.js +0 -446
  132. package/src/store/kv_archiver_store.ts +0 -639
@@ -0,0 +1,220 @@
1
+ import type { OutboxContract } from '@aztec/ethereum/contracts';
2
+ import type { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
3
+ import { chunkBy } from '@aztec/foundation/collection';
4
+ import type { Fr } from '@aztec/foundation/curves/bn254';
5
+ import { type Logger, createLogger } from '@aztec/foundation/log';
6
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
7
+ import type { L2Block } from '@aztec/stdlib/block';
8
+ import type { CheckpointData } from '@aztec/stdlib/checkpoint';
9
+ import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
10
+ import { type L2ToL1MembershipWitness, computeL2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
11
+ import type { IndexedTxEffect, TxHash } from '@aztec/stdlib/tx';
12
+
13
+ /**
14
+ * Archiver-side view of the data the resolver needs to assemble a witness. The archiver implements
15
+ * each of these natively, so no L2 RPC plumbing is required.
16
+ */
17
+ export interface OutboxTreesArchiverView {
18
+ getBlocks(query: { epoch: EpochNumber; onlyCheckpointed: true }): Promise<L2Block[]>;
19
+ getBlock(query: { number: BlockNumber }): Promise<L2Block | undefined>;
20
+ getCheckpointsData(query: { epoch: EpochNumber }): Promise<CheckpointData[]>;
21
+ getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined>;
22
+ }
23
+
24
+ /** A cached per-epoch set of Outbox roots, tagged with the synced L1 block they were read at. */
25
+ type CachedRoots = {
26
+ /** The `MAX_CHECKPOINTS_PER_EPOCH`-length array of partial-proof roots the L1 Outbox holds for the epoch. */
27
+ roots: Fr[];
28
+ /** The node's synced L1 block number at the moment we fetched these roots. */
29
+ fetchedAtL1Block: bigint;
30
+ };
31
+
32
+ /**
33
+ * Holds an in-memory cache of per-epoch Outbox roots used to build L2-to-L1 message membership
34
+ * witnesses, plus the single-flight registry that dedupes concurrent fetches.
35
+ *
36
+ * Roots are fetched lazily on request and cached against the node's synced L1 block: a cached entry
37
+ * is reused only while the synced L1 block is unchanged, and re-fetched from L1 once the node
38
+ * advances. The cache is intentionally not persisted — entries are valid for at most one L1 slot, so
39
+ * there is nothing worth carrying across restarts. The four merkle-tree levels are rebuilt per
40
+ * request from the archiver's raw L2 data via `computeL2ToL1MembershipWitness`; no trees or
41
+ * intermediate out-hashes are cached.
42
+ *
43
+ * TODO: Re-add permanent caching for sealed-and-L1-finalized epochs so their roots can be frozen
44
+ * and served without any L1 read once they can no longer change. That logic was dropped here to keep
45
+ * the cache simple; it would likely want a persisted store again.
46
+ */
47
+ export class OutboxTreesResolver {
48
+ /** In-memory cache of per-epoch Outbox roots, keyed by epoch number. */
49
+ #cache: Map<EpochNumber, CachedRoots> = new Map();
50
+
51
+ /** Single-flight registry for in-flight roots fetches, keyed by epoch number. */
52
+ #pending: Map<EpochNumber, Promise<Fr[] | undefined>> = new Map();
53
+
54
+ /** Adapter exposing the slice of the node API that `computeL2ToL1MembershipWitness` requires. */
55
+ #node: Parameters<typeof computeL2ToL1MembershipWitness>[0];
56
+
57
+ constructor(
58
+ private readonly outbox: OutboxContract,
59
+ private readonly archiver: OutboxTreesArchiverView,
60
+ private readonly store: AztecAsyncKVStore,
61
+ private readonly getSyncedL1BlockNumber: () => Promise<bigint | undefined>,
62
+ private readonly epochDuration: number,
63
+ private readonly log: Logger = createLogger('archiver:outbox'),
64
+ ) {
65
+ this.#node = this.makeNodeView();
66
+ }
67
+
68
+ /**
69
+ * Builds the L2-to-L1 membership witness for `message` in tx `txHash`. Returns `undefined` if the
70
+ * tx isn't yet in a block/epoch, or if the Outbox holds no covering partial-proof root for the
71
+ * tx's checkpoint as of the node's synced L1 block — callers should retry in that case.
72
+ */
73
+ public async getL2ToL1MembershipWitness(
74
+ txHash: TxHash,
75
+ message: Fr,
76
+ messageIndexInTx?: number,
77
+ ): Promise<L2ToL1MembershipWitness | undefined> {
78
+ // Read the tx effect once up front only to learn which epoch's Outbox roots to fetch. The roots
79
+ // read hits L1, so it stays outside the store transaction below: holding the archiver's writer
80
+ // lock across a network round-trip would stall block sync.
81
+ const indexed = await this.archiver.getTxEffect(txHash);
82
+ if (!indexed) {
83
+ this.log.trace(`No tx effect for tx, no witness available`, { txHash });
84
+ return undefined;
85
+ }
86
+
87
+ // Derive the epoch from the tx's slot the same way the node assembles a mined receipt, so the
88
+ // witness helper sees the same view a `getTxReceipt` caller would.
89
+ const epochNumber = getEpochAtSlot(indexed.slotNumber, { epochDuration: this.epochDuration });
90
+ const roots = await this.#getRoots(epochNumber);
91
+ if (roots === undefined) {
92
+ return undefined;
93
+ }
94
+
95
+ const syncedBefore = await this.getSyncedL1BlockNumber();
96
+ try {
97
+ // Assemble the witness inside a single store transaction so every archiver read it depends on
98
+ // (the tx effect, the epoch's blocks, the target block and the checkpoint metadata) observes one
99
+ // consistent snapshot. `transactionAsync` serializes against writers, and the substore reads
100
+ // below bind to it automatically, so no store commit can land mid-assembly and splice together
101
+ // two different chain states — which would otherwise surface as a spurious "message does not
102
+ // exist" error even when the tx-effect index is healthy.
103
+ return await this.store.transactionAsync(async () => {
104
+ // Re-read the tx effect within the snapshot so the receipt's block number and tx index stay
105
+ // consistent with the block and checkpoint data read while building the witness. The epoch is
106
+ // reused from the pre-transaction read (it selected the roots above); if a reorg moved the tx
107
+ // to a different epoch in between, the block lookups simply miss and the helper returns
108
+ // undefined for the caller to retry.
109
+ const indexedInSnapshot = await this.archiver.getTxEffect(txHash);
110
+ if (!indexedInSnapshot) {
111
+ return undefined;
112
+ }
113
+ const receipt = {
114
+ txHash,
115
+ epochNumber,
116
+ blockNumber: indexedInSnapshot.l2BlockNumber,
117
+ txIndexInBlock: indexedInSnapshot.txIndexInBlock,
118
+ };
119
+ return await computeL2ToL1MembershipWitness(this.#node, roots, message, receipt, messageIndexInTx);
120
+ });
121
+ } catch (err) {
122
+ // The helper throws if the locally-assembled epoch root disagrees with the cached Outbox root.
123
+ // The cached roots are pinned to the node's synced L1 block, but the block / checkpoint data is
124
+ // read from a store snapshot taken after that fetch, so if the archiver advanced in between the
125
+ // two can reflect different heights and produce a transient mismatch. When the synced block moved
126
+ // during assembly we treat the mismatch as transient and return undefined so the caller can
127
+ // retry; a mismatch at a stable synced block is a genuine node/L1 disagreement and must surface.
128
+ const syncedAfter = await this.getSyncedL1BlockNumber();
129
+ if (syncedBefore !== syncedAfter && err instanceof Error && err.message.includes('does not match Outbox')) {
130
+ this.log.debug(`Transient outbox root mismatch during sync, returning no witness`, {
131
+ txHash,
132
+ epoch: epochNumber,
133
+ });
134
+ return undefined;
135
+ }
136
+ throw err;
137
+ }
138
+ }
139
+
140
+ /**
141
+ * Lazily returns the per-epoch Outbox roots, reusing the cached entry while the node's synced L1
142
+ * block is unchanged and re-fetching from L1 once it advances. Returns `undefined` if the node has
143
+ * not established a synced L1 block yet. Concurrent requests for the same epoch share a single
144
+ * in-flight fetch via {@link #pending}.
145
+ */
146
+ #getRoots(epoch: EpochNumber): Promise<Fr[] | undefined> {
147
+ const inFlight = this.#pending.get(epoch);
148
+ if (inFlight) {
149
+ return inFlight;
150
+ }
151
+
152
+ const promise = this.#refreshRoots(epoch).finally(() => {
153
+ this.#pending.delete(epoch);
154
+ });
155
+ this.#pending.set(epoch, promise);
156
+ return promise;
157
+ }
158
+
159
+ /**
160
+ * Single-flight body for {@link #getRoots}. Re-reads the cached entry and synced block here —
161
+ * rather than capturing them before winning the {@link #pending} slot — so a late entrant that
162
+ * missed the slot cannot overwrite a fresher entry the previous winner just wrote.
163
+ */
164
+ async #refreshRoots(epoch: EpochNumber): Promise<Fr[] | undefined> {
165
+ const synced = await this.getSyncedL1BlockNumber();
166
+ if (synced === undefined) {
167
+ // The archiver has no synced L1 block yet, so there is no consistent height to read the Outbox
168
+ // at. The caller retries once the node has synced.
169
+ return undefined;
170
+ }
171
+
172
+ const cached = this.#cache.get(epoch);
173
+ if (cached && cached.fetchedAtL1Block === synced) {
174
+ return cached.roots;
175
+ }
176
+
177
+ // TODO: Re-add permanent caching for sealed-and-L1-finalized epochs so we can skip the L1 read
178
+ // entirely once an epoch's roots can no longer change. For now the cache is valid only for the
179
+ // current synced L1 block and we re-query the Outbox whenever the node advances.
180
+ const roots = await this.outbox.getRoots(epoch, { blockNumber: synced });
181
+ this.#cache.set(epoch, { roots, fetchedAtL1Block: synced });
182
+ this.log.trace(`Fetched outbox roots for epoch ${epoch}`, {
183
+ epoch,
184
+ syncedL1Block: synced,
185
+ nonZeroRoots: roots.filter(r => !r.isZero()).length,
186
+ });
187
+ return roots;
188
+ }
189
+
190
+ /**
191
+ * Returns the L2-to-L1 messages in `epoch`, organized as `checkpoint[] → block[] → tx[] →
192
+ * message[]`. Mirrors `AztecNodeService.getL2ToL1Messages` so the resolver can run off the
193
+ * archiver directly without going through the node RPC surface.
194
+ */
195
+ async #getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
196
+ const blocks = await this.archiver.getBlocks({ epoch, onlyCheckpointed: true });
197
+ const blocksInCheckpoints = chunkBy(blocks, block => block.header.globalVariables.slotNumber);
198
+ return blocksInCheckpoints.map(slotBlocks =>
199
+ slotBlocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
200
+ );
201
+ }
202
+
203
+ /**
204
+ * Builds the node-shaped adapter handed to `computeL2ToL1MembershipWitness`. The helper invokes
205
+ * `getL2ToL1Messages` / `getBlock` / `getCheckpointsData`; `getTxReceipt` is part of the helper's
206
+ * node type but is never invoked because we always pass an already-resolved receipt.
207
+ */
208
+ private makeNodeView(): Parameters<typeof computeL2ToL1MembershipWitness>[0] {
209
+ return {
210
+ getL2ToL1Messages: (epoch: EpochNumber) => this.#getL2ToL1Messages(epoch),
211
+ getBlock: ((param: BlockNumber) => this.archiver.getBlock({ number: param })) as Parameters<
212
+ typeof computeL2ToL1MembershipWitness
213
+ >[0]['getBlock'],
214
+ getCheckpointsData: (query: { epoch: EpochNumber }) => this.archiver.getCheckpointsData(query),
215
+ getTxReceipt: (() => {
216
+ throw new Error('OutboxTreesResolver always passes a resolved receipt; getTxReceipt must not be called');
217
+ }) as Parameters<typeof computeL2ToL1MembershipWitness>[0]['getTxReceipt'],
218
+ };
219
+ }
220
+ }
@@ -1,16 +1,20 @@
1
1
  import type { EpochCache } from '@aztec/epoch-cache';
2
- import { EpochNumber } from '@aztec/foundation/branded-types';
2
+ import type { ViemCommitteeAttestations } from '@aztec/ethereum/contracts';
3
+ import { type CheckpointNumber, EpochNumber } from '@aztec/foundation/branded-types';
3
4
  import { compactArray } from '@aztec/foundation/collection';
5
+ import type { Fr } from '@aztec/foundation/curves/bn254';
4
6
  import type { Logger } from '@aztec/foundation/log';
5
7
  import {
6
8
  type AttestationInfo,
9
+ type CommitteeAttestation,
7
10
  type ValidateCheckpointNegativeResult,
8
11
  type ValidateCheckpointResult,
9
12
  getAttestationInfoFromPayload,
10
13
  } from '@aztec/stdlib/block';
11
- import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
12
- import { type L1RollupConstants, getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
13
- import { ConsensusPayload } from '@aztec/stdlib/p2p';
14
+ import type { CheckpointInfo, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
15
+ import { type L1RollupConstants, computeQuorum, getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
16
+ import { ConsensusPayload, type CoordinationSignatureContext } from '@aztec/stdlib/p2p';
17
+ import type { CheckpointHeader } from '@aztec/stdlib/rollup';
14
18
 
15
19
  export type { ValidateCheckpointResult };
16
20
 
@@ -18,35 +22,87 @@ export type { ValidateCheckpointResult };
18
22
  * Extracts attestation information from a published checkpoint.
19
23
  * Returns info for each attestation, preserving array indices.
20
24
  */
21
- export function getAttestationInfoFromPublishedCheckpoint({
22
- checkpoint,
23
- attestations,
24
- }: PublishedCheckpoint): AttestationInfo[] {
25
- const payload = ConsensusPayload.fromCheckpoint(checkpoint);
25
+ export function getAttestationInfoFromPublishedCheckpoint(
26
+ { checkpoint, attestations }: PublishedCheckpoint,
27
+ signatureContext: CoordinationSignatureContext,
28
+ ): AttestationInfo[] {
29
+ const payload = ConsensusPayload.fromCheckpoint(checkpoint, signatureContext);
26
30
  return getAttestationInfoFromPayload(payload, attestations);
27
31
  }
28
32
 
33
+ /** The subset of a calldata-only checkpoint needed to validate its committee attestations. */
34
+ export type CalldataCheckpointForAttestations = {
35
+ checkpointNumber: CheckpointNumber;
36
+ archiveRoot: Fr;
37
+ feeAssetPriceModifier: bigint;
38
+ header: CheckpointHeader;
39
+ attestations: CommitteeAttestation[];
40
+ /** The exact packed attestations tuple from L1 calldata, carried verbatim for byte-faithful invalidation. */
41
+ verbatimAttestations: ViemCommitteeAttestations;
42
+ };
43
+
44
+ /**
45
+ * Validates the attestations of a checkpoint from L1 calldata only, without fetching or decoding its blobs.
46
+ * The signed consensus payload (header, archive root, fee asset price modifier) is fully available from
47
+ * calldata, so an invalid-attestation checkpoint can be rejected before any (possibly malformed) blob is
48
+ * fetched and decoded.
49
+ */
50
+ export function validateCheckpointAttestationsFromCalldata(
51
+ checkpoint: CalldataCheckpointForAttestations,
52
+ epochCache: EpochCache,
53
+ constants: Pick<L1RollupConstants, 'epochDuration'>,
54
+ signatureContext: CoordinationSignatureContext,
55
+ logger?: Logger,
56
+ ): Promise<ValidateCheckpointResult> {
57
+ const payload = new ConsensusPayload(
58
+ checkpoint.header,
59
+ checkpoint.archiveRoot,
60
+ checkpoint.feeAssetPriceModifier,
61
+ signatureContext,
62
+ );
63
+ const checkpointInfo: CheckpointInfo = {
64
+ archive: checkpoint.archiveRoot,
65
+ lastArchive: checkpoint.header.lastArchiveRoot,
66
+ slotNumber: checkpoint.header.slotNumber,
67
+ checkpointNumber: checkpoint.checkpointNumber,
68
+ timestamp: checkpoint.header.timestamp,
69
+ };
70
+ return validateAttestations(
71
+ payload,
72
+ checkpoint.attestations,
73
+ checkpoint.verbatimAttestations,
74
+ checkpointInfo,
75
+ epochCache,
76
+ constants,
77
+ logger,
78
+ );
79
+ }
80
+
29
81
  /**
30
- * Validates the attestations submitted for the given checkpoint.
31
- * Returns true if the attestations are valid and sufficient, false otherwise.
82
+ * Core attestation validation over a consensus payload, its attestations, and checkpoint metadata --
83
+ * independent of whether the checkpoint's blocks have been decoded from blobs. Returns true if the
84
+ * attestations are valid and sufficient, false otherwise.
32
85
  */
33
- export async function validateCheckpointAttestations(
34
- publishedCheckpoint: PublishedCheckpoint,
86
+ export async function validateAttestations(
87
+ payload: ConsensusPayload,
88
+ attestations: CommitteeAttestation[],
89
+ verbatimAttestations: ViemCommitteeAttestations,
90
+ checkpointInfo: CheckpointInfo,
35
91
  epochCache: EpochCache,
36
92
  constants: Pick<L1RollupConstants, 'epochDuration'>,
37
93
  logger?: Logger,
38
94
  ): Promise<ValidateCheckpointResult> {
39
- const attestorInfos = getAttestationInfoFromPublishedCheckpoint(publishedCheckpoint);
95
+ const attestorInfos = getAttestationInfoFromPayload(payload, attestations);
40
96
  const attestors = compactArray(attestorInfos.map(info => ('address' in info ? info.address : undefined)));
41
- const { checkpoint, attestations } = publishedCheckpoint;
42
- const headerHash = checkpoint.header.hash();
43
- const archiveRoot = checkpoint.archive.root.toString();
44
- const slot = checkpoint.header.slotNumber;
97
+ const headerHash = payload.header.hash();
98
+ const archiveRoot = payload.archive.toString();
99
+ const slot = payload.header.slotNumber;
100
+ const checkpointNumber = checkpointInfo.checkpointNumber;
45
101
  const epoch: EpochNumber = getEpochAtSlot(slot, constants);
46
102
  const { committee, seed } = await epochCache.getCommitteeForEpoch(epoch);
47
- const logData = { checkpointNumber: checkpoint.number, slot, epoch, headerHash, archiveRoot };
103
+ const logData = { checkpointNumber, slot, epoch, headerHash, archiveRoot };
48
104
 
49
- logger?.debug(`Validating attestations for checkpoint ${checkpoint.number} at slot ${slot} in epoch ${epoch}`, {
105
+ logger?.debug(`Validating attestations for checkpoint ${checkpointNumber} at slot ${slot} in epoch ${epoch}`, {
50
106
  committee: (committee ?? []).map(member => member.toString()),
51
107
  recoveredAttestors: attestorInfos,
52
108
  postedAttestations: attestations.map(a => (a.address.isZero() ? a.signature : a.address).toString()),
@@ -66,17 +122,18 @@ export async function validateCheckpointAttestations(
66
122
  return { valid: true };
67
123
  }
68
124
 
69
- const requiredAttestationCount = Math.floor((committee.length * 2) / 3) + 1;
125
+ const requiredAttestationCount = computeQuorum(committee.length);
70
126
 
71
127
  const failedValidationResult = <TReason extends ValidateCheckpointNegativeResult['reason']>(reason: TReason) => ({
72
128
  valid: false as const,
73
129
  reason,
74
- checkpoint: checkpoint.toCheckpointInfo(),
130
+ checkpoint: checkpointInfo,
75
131
  committee,
76
132
  seed,
77
133
  epoch,
78
134
  attestors,
79
135
  attestations,
136
+ verbatimAttestations,
80
137
  });
81
138
 
82
139
  for (let i = 0; i < attestorInfos.length; i++) {
@@ -122,7 +179,7 @@ export async function validateCheckpointAttestations(
122
179
  }
123
180
 
124
181
  logger?.debug(
125
- `Checkpoint attestations validated successfully for checkpoint ${checkpoint.number} at slot ${slot}`,
182
+ `Checkpoint attestations validated successfully for checkpoint ${checkpointNumber} at slot ${slot}`,
126
183
  logData,
127
184
  );
128
185
  return { valid: true };