@aztec/archiver 5.0.0-private.20260319 → 5.0.0-rc.2

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 +71 -15
  3. package/dest/archiver.d.ts.map +1 -1
  4. package/dest/archiver.js +268 -74
  5. package/dest/config.d.ts +7 -3
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +39 -16
  8. package/dest/errors.d.ts +44 -10
  9. package/dest/errors.d.ts.map +1 -1
  10. package/dest/errors.js +66 -12
  11. package/dest/factory.d.ts +12 -7
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +40 -25
  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 +2 -1
  18. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  19. package/dest/l1/calldata_retriever.js +15 -5
  20. package/dest/l1/data_retrieval.d.ts +19 -10
  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 +72 -48
  32. package/dest/modules/data_source_base.d.ts.map +1 -1
  33. package/dest/modules/data_source_base.js +266 -143
  34. package/dest/modules/data_store_updater.d.ts +30 -13
  35. package/dest/modules/data_store_updater.d.ts.map +1 -1
  36. package/dest/modules/data_store_updater.js +172 -117
  37. package/dest/modules/instrumentation.d.ts +7 -2
  38. package/dest/modules/instrumentation.d.ts.map +1 -1
  39. package/dest/modules/instrumentation.js +25 -7
  40. package/dest/modules/l1_synchronizer.d.ts +11 -6
  41. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  42. package/dest/modules/l1_synchronizer.js +437 -217
  43. package/dest/modules/outbox_trees_resolver.d.ts +62 -0
  44. package/dest/modules/outbox_trees_resolver.d.ts.map +1 -0
  45. package/dest/modules/outbox_trees_resolver.js +162 -0
  46. package/dest/modules/validation.d.ts +24 -5
  47. package/dest/modules/validation.d.ts.map +1 -1
  48. package/dest/modules/validation.js +40 -15
  49. package/dest/store/block_store.d.ts +164 -66
  50. package/dest/store/block_store.d.ts.map +1 -1
  51. package/dest/store/block_store.js +638 -233
  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 +36 -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 +48 -2
  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 -40
  68. package/dest/store/log_store.d.ts.map +1 -1
  69. package/dest/store/log_store.js +257 -480
  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 +9 -3
  74. package/dest/store/message_store.d.ts.map +1 -1
  75. package/dest/store/message_store.js +39 -10
  76. package/dest/test/fake_l1_state.d.ts +15 -3
  77. package/dest/test/fake_l1_state.d.ts.map +1 -1
  78. package/dest/test/fake_l1_state.js +80 -18
  79. package/dest/test/mock_l2_block_source.d.ts +48 -50
  80. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  81. package/dest/test/mock_l2_block_source.js +223 -179
  82. package/dest/test/mock_structs.d.ts +1 -1
  83. package/dest/test/mock_structs.d.ts.map +1 -1
  84. package/dest/test/mock_structs.js +2 -2
  85. package/dest/test/noop_l1_archiver.d.ts +14 -6
  86. package/dest/test/noop_l1_archiver.d.ts.map +1 -1
  87. package/dest/test/noop_l1_archiver.js +25 -9
  88. package/package.json +14 -14
  89. package/src/archiver.ts +353 -80
  90. package/src/config.ts +43 -20
  91. package/src/errors.ts +103 -18
  92. package/src/factory.ts +56 -24
  93. package/src/index.ts +18 -2
  94. package/src/l1/calldata_retriever.ts +16 -5
  95. package/src/l1/data_retrieval.ts +38 -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 +340 -189
  99. package/src/modules/data_store_updater.ts +211 -148
  100. package/src/modules/instrumentation.ts +28 -8
  101. package/src/modules/l1_synchronizer.ts +583 -255
  102. package/src/modules/outbox_trees_resolver.ts +199 -0
  103. package/src/modules/validation.ts +81 -21
  104. package/src/store/block_store.ts +792 -285
  105. package/src/store/contract_class_store.ts +43 -103
  106. package/src/store/contract_instance_store.ts +62 -5
  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 +296 -652
  111. package/src/store/log_store_codec.ts +143 -0
  112. package/src/store/message_store.ts +43 -12
  113. package/src/structs/inbox_message.ts +1 -1
  114. package/src/test/fake_l1_state.ts +99 -27
  115. package/src/test/mock_l2_block_source.ts +279 -233
  116. package/src/test/mock_structs.ts +5 -2
  117. package/src/test/noop_l1_archiver.ts +52 -9
  118. package/dest/store/kv_archiver_store.d.ts +0 -367
  119. package/dest/store/kv_archiver_store.d.ts.map +0 -1
  120. package/dest/store/kv_archiver_store.js +0 -481
  121. package/src/store/kv_archiver_store.ts +0 -697
@@ -0,0 +1,62 @@
1
+ import type { OutboxContract } from '@aztec/ethereum/contracts';
2
+ import type { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
3
+ import type { Fr } from '@aztec/foundation/curves/bn254';
4
+ import { type Logger } from '@aztec/foundation/log';
5
+ import type { L2Block } from '@aztec/stdlib/block';
6
+ import type { CheckpointData } from '@aztec/stdlib/checkpoint';
7
+ import { type L2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
8
+ import type { IndexedTxEffect, TxHash } from '@aztec/stdlib/tx';
9
+ /**
10
+ * Archiver-side view of the data the resolver needs to assemble a witness. The archiver implements
11
+ * each of these natively, so no L2 RPC plumbing is required.
12
+ */
13
+ export interface OutboxTreesArchiverView {
14
+ getBlocks(query: {
15
+ epoch: EpochNumber;
16
+ onlyCheckpointed: true;
17
+ }): Promise<L2Block[]>;
18
+ getBlock(query: {
19
+ number: BlockNumber;
20
+ }): Promise<L2Block | undefined>;
21
+ getCheckpointsData(query: {
22
+ epoch: EpochNumber;
23
+ }): Promise<CheckpointData[]>;
24
+ getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined>;
25
+ }
26
+ /**
27
+ * Holds an in-memory cache of per-epoch Outbox roots used to build L2-to-L1 message membership
28
+ * witnesses, plus the single-flight registry that dedupes concurrent fetches.
29
+ *
30
+ * Roots are fetched lazily on request and cached against the node's synced L1 block: a cached entry
31
+ * is reused only while the synced L1 block is unchanged, and re-fetched from L1 once the node
32
+ * advances. The cache is intentionally not persisted — entries are valid for at most one L1 slot, so
33
+ * there is nothing worth carrying across restarts. The four merkle-tree levels are rebuilt per
34
+ * request from the archiver's raw L2 data via `computeL2ToL1MembershipWitness`; no trees or
35
+ * intermediate out-hashes are cached.
36
+ *
37
+ * TODO: Re-add permanent caching for sealed-and-L1-finalized epochs so their roots can be frozen
38
+ * and served without any L1 read once they can no longer change. That logic was dropped here to keep
39
+ * the cache simple; it would likely want a persisted store again.
40
+ */
41
+ export declare class OutboxTreesResolver {
42
+ #private;
43
+ private readonly outbox;
44
+ private readonly archiver;
45
+ private readonly getSyncedL1BlockNumber;
46
+ private readonly epochDuration;
47
+ private readonly log;
48
+ constructor(outbox: OutboxContract, archiver: OutboxTreesArchiverView, getSyncedL1BlockNumber: () => Promise<bigint | undefined>, epochDuration: number, log?: Logger);
49
+ /**
50
+ * Builds the L2-to-L1 membership witness for `message` in tx `txHash`. Returns `undefined` if the
51
+ * tx isn't yet in a block/epoch, or if the Outbox holds no covering partial-proof root for the
52
+ * tx's checkpoint as of the node's synced L1 block — callers should retry in that case.
53
+ */
54
+ getL2ToL1MembershipWitness(txHash: TxHash, message: Fr, messageIndexInTx?: number): Promise<L2ToL1MembershipWitness | undefined>;
55
+ /**
56
+ * Builds the node-shaped adapter handed to `computeL2ToL1MembershipWitness`. The helper invokes
57
+ * `getL2ToL1Messages` / `getBlock` / `getCheckpointsData`; `getTxReceipt` is part of the helper's
58
+ * node type but is never invoked because we always pass an already-resolved receipt.
59
+ */
60
+ private makeNodeView;
61
+ }
62
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3V0Ym94X3RyZWVzX3Jlc29sdmVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kdWxlcy9vdXRib3hfdHJlZXNfcmVzb2x2ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsY0FBYyxFQUFFLE1BQU0sMkJBQTJCLENBQUM7QUFDaEUsT0FBTyxLQUFLLEVBQUUsV0FBVyxFQUFFLFdBQVcsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBRWhGLE9BQU8sS0FBSyxFQUFFLEVBQUUsRUFBRSxNQU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ation/collection';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+ import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
4
+ import { computeL2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
5
+ /**
6
+ * Holds an in-memory cache of per-epoch Outbox roots used to build L2-to-L1 message membership
7
+ * witnesses, plus the single-flight registry that dedupes concurrent fetches.
8
+ *
9
+ * Roots are fetched lazily on request and cached against the node's synced L1 block: a cached entry
10
+ * is reused only while the synced L1 block is unchanged, and re-fetched from L1 once the node
11
+ * advances. The cache is intentionally not persisted — entries are valid for at most one L1 slot, so
12
+ * there is nothing worth carrying across restarts. The four merkle-tree levels are rebuilt per
13
+ * request from the archiver's raw L2 data via `computeL2ToL1MembershipWitness`; no trees or
14
+ * intermediate out-hashes are cached.
15
+ *
16
+ * TODO: Re-add permanent caching for sealed-and-L1-finalized epochs so their roots can be frozen
17
+ * and served without any L1 read once they can no longer change. That logic was dropped here to keep
18
+ * the cache simple; it would likely want a persisted store again.
19
+ */ export class OutboxTreesResolver {
20
+ outbox;
21
+ archiver;
22
+ getSyncedL1BlockNumber;
23
+ epochDuration;
24
+ log;
25
+ /** In-memory cache of per-epoch Outbox roots, keyed by epoch number. */ #cache;
26
+ /** Single-flight registry for in-flight roots fetches, keyed by epoch number. */ #pending;
27
+ /** Adapter exposing the slice of the node API that `computeL2ToL1MembershipWitness` requires. */ #node;
28
+ constructor(outbox, archiver, getSyncedL1BlockNumber, epochDuration, log = createLogger('archiver:outbox')){
29
+ this.outbox = outbox;
30
+ this.archiver = archiver;
31
+ this.getSyncedL1BlockNumber = getSyncedL1BlockNumber;
32
+ this.epochDuration = epochDuration;
33
+ this.log = log;
34
+ this.#cache = new Map();
35
+ this.#pending = new Map();
36
+ this.#node = this.makeNodeView();
37
+ }
38
+ /**
39
+ * Builds the L2-to-L1 membership witness for `message` in tx `txHash`. Returns `undefined` if the
40
+ * tx isn't yet in a block/epoch, or if the Outbox holds no covering partial-proof root for the
41
+ * tx's checkpoint as of the node's synced L1 block — callers should retry in that case.
42
+ */ async getL2ToL1MembershipWitness(txHash, message, messageIndexInTx) {
43
+ const indexed = await this.archiver.getTxEffect(txHash);
44
+ if (!indexed) {
45
+ this.log.trace(`No tx effect for tx, no witness available`, {
46
+ txHash
47
+ });
48
+ return undefined;
49
+ }
50
+ // Derive the epoch from the tx's slot the same way the node assembles a mined receipt, so the
51
+ // witness helper sees the same view a `getTxReceipt` caller would.
52
+ const epochNumber = getEpochAtSlot(indexed.slotNumber, {
53
+ epochDuration: this.epochDuration
54
+ });
55
+ const roots = await this.#getRoots(epochNumber);
56
+ if (roots === undefined) {
57
+ return undefined;
58
+ }
59
+ const receipt = {
60
+ txHash,
61
+ epochNumber,
62
+ blockNumber: indexed.l2BlockNumber,
63
+ txIndexInBlock: indexed.txIndexInBlock
64
+ };
65
+ const syncedBefore = await this.getSyncedL1BlockNumber();
66
+ try {
67
+ return await computeL2ToL1MembershipWitness(this.#node, roots, message, receipt, messageIndexInTx);
68
+ } catch (err) {
69
+ // The helper throws if the locally-assembled epoch root disagrees with the cached Outbox root.
70
+ // The cached roots are pinned to the node's synced L1 block, but the helper reads block /
71
+ // checkpoint data live, so if the archiver advanced mid-assembly the two can momentarily reflect
72
+ // different heights and produce a transient mismatch. When the synced block moved during
73
+ // assembly we treat the mismatch as transient and return undefined so the caller can retry; a
74
+ // mismatch at a stable synced block is a genuine node/L1 disagreement and must surface.
75
+ const syncedAfter = await this.getSyncedL1BlockNumber();
76
+ if (syncedBefore !== syncedAfter && err instanceof Error && err.message.includes('does not match Outbox')) {
77
+ this.log.debug(`Transient outbox root mismatch during sync, returning no witness`, {
78
+ txHash,
79
+ epoch: epochNumber
80
+ });
81
+ return undefined;
82
+ }
83
+ throw err;
84
+ }
85
+ }
86
+ /**
87
+ * Lazily returns the per-epoch Outbox roots, reusing the cached entry while the node's synced L1
88
+ * block is unchanged and re-fetching from L1 once it advances. Returns `undefined` if the node has
89
+ * not established a synced L1 block yet. Concurrent requests for the same epoch share a single
90
+ * in-flight fetch via {@link #pending}.
91
+ */ #getRoots(epoch) {
92
+ const inFlight = this.#pending.get(epoch);
93
+ if (inFlight) {
94
+ return inFlight;
95
+ }
96
+ const promise = this.#refreshRoots(epoch).finally(()=>{
97
+ this.#pending.delete(epoch);
98
+ });
99
+ this.#pending.set(epoch, promise);
100
+ return promise;
101
+ }
102
+ /**
103
+ * Single-flight body for {@link #getRoots}. Re-reads the cached entry and synced block here —
104
+ * rather than capturing them before winning the {@link #pending} slot — so a late entrant that
105
+ * missed the slot cannot overwrite a fresher entry the previous winner just wrote.
106
+ */ async #refreshRoots(epoch) {
107
+ const synced = await this.getSyncedL1BlockNumber();
108
+ if (synced === undefined) {
109
+ // The archiver has no synced L1 block yet, so there is no consistent height to read the Outbox
110
+ // at. The caller retries once the node has synced.
111
+ return undefined;
112
+ }
113
+ const cached = this.#cache.get(epoch);
114
+ if (cached && cached.fetchedAtL1Block === synced) {
115
+ return cached.roots;
116
+ }
117
+ // TODO: Re-add permanent caching for sealed-and-L1-finalized epochs so we can skip the L1 read
118
+ // entirely once an epoch's roots can no longer change. For now the cache is valid only for the
119
+ // current synced L1 block and we re-query the Outbox whenever the node advances.
120
+ const roots = await this.outbox.getRoots(epoch, {
121
+ blockNumber: synced
122
+ });
123
+ this.#cache.set(epoch, {
124
+ roots,
125
+ fetchedAtL1Block: synced
126
+ });
127
+ this.log.trace(`Fetched outbox roots for epoch ${epoch}`, {
128
+ epoch,
129
+ syncedL1Block: synced,
130
+ nonZeroRoots: roots.filter((r)=>!r.isZero()).length
131
+ });
132
+ return roots;
133
+ }
134
+ /**
135
+ * Returns the L2-to-L1 messages in `epoch`, organized as `checkpoint[] → block[] → tx[] →
136
+ * message[]`. Mirrors `AztecNodeService.getL2ToL1Messages` so the resolver can run off the
137
+ * archiver directly without going through the node RPC surface.
138
+ */ async #getL2ToL1Messages(epoch) {
139
+ const blocks = await this.archiver.getBlocks({
140
+ epoch,
141
+ onlyCheckpointed: true
142
+ });
143
+ const blocksInCheckpoints = chunkBy(blocks, (block)=>block.header.globalVariables.slotNumber);
144
+ return blocksInCheckpoints.map((slotBlocks)=>slotBlocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
145
+ }
146
+ /**
147
+ * Builds the node-shaped adapter handed to `computeL2ToL1MembershipWitness`. The helper invokes
148
+ * `getL2ToL1Messages` / `getBlock` / `getCheckpointsData`; `getTxReceipt` is part of the helper's
149
+ * node type but is never invoked because we always pass an already-resolved receipt.
150
+ */ makeNodeView() {
151
+ return {
152
+ getL2ToL1Messages: (epoch)=>this.#getL2ToL1Messages(epoch),
153
+ getBlock: (param)=>this.archiver.getBlock({
154
+ number: param
155
+ }),
156
+ getCheckpointsData: (query)=>this.archiver.getCheckpointsData(query),
157
+ getTxReceipt: ()=>{
158
+ throw new Error('OutboxTreesResolver always passes a resolved receipt; getTxReceipt must not be called');
159
+ }
160
+ };
161
+ }
162
+ }
@@ -1,17 +1,36 @@
1
1
  import type { EpochCache } from '@aztec/epoch-cache';
2
+ import { type CheckpointNumber } from '@aztec/foundation/branded-types';
3
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
4
  import type { Logger } from '@aztec/foundation/log';
3
- import { type AttestationInfo, type ValidateCheckpointResult } from '@aztec/stdlib/block';
5
+ import { type AttestationInfo, type CommitteeAttestation, type ValidateCheckpointResult } from '@aztec/stdlib/block';
4
6
  import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
5
7
  import { type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
8
+ import { type CoordinationSignatureContext } from '@aztec/stdlib/p2p';
9
+ import type { CheckpointHeader } from '@aztec/stdlib/rollup';
6
10
  export type { ValidateCheckpointResult };
7
11
  /**
8
12
  * Extracts attestation information from a published checkpoint.
9
13
  * Returns info for each attestation, preserving array indices.
10
14
  */
11
- export declare function getAttestationInfoFromPublishedCheckpoint({ checkpoint, attestations }: PublishedCheckpoint): AttestationInfo[];
15
+ export declare function getAttestationInfoFromPublishedCheckpoint({ checkpoint, attestations }: PublishedCheckpoint, signatureContext: CoordinationSignatureContext): AttestationInfo[];
12
16
  /**
13
- * Validates the attestations submitted for the given checkpoint.
17
+ * Validates the attestations of a checkpoint already retrieved (with its blocks) from blobs.
14
18
  * Returns true if the attestations are valid and sufficient, false otherwise.
15
19
  */
16
- export declare function validateCheckpointAttestations(publishedCheckpoint: PublishedCheckpoint, epochCache: EpochCache, constants: Pick<L1RollupConstants, 'epochDuration'>, logger?: Logger): Promise<ValidateCheckpointResult>;
17
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsaWRhdGlvbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL21vZHVsZXMvdmFsaWRhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUdyRCxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUNwRCxPQUFPLEVBQ0wsS0FBSyxlQUFlLEVBRXBCLEtBQUssd0JBQXdCLEVBRTlCLE1BQU0scUJBQXFCLENBQUM7QUFDN0IsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUNwRSxPQUFPLEVBQUUsS0FBSyxpQkFBaUIsRUFBa0IsTUFBTSw2QkFBNkIsQ0FBQztBQUdyRixZQUFZLEVBQUUsd0JBQXdCLEVBQUUsQ0FBQztBQUV6Qzs7O0dBR0c7QUFDSCx3QkFBZ0IseUNBQXlDLENBQUMsRUFDeEQsVUFBVSxFQUNWLFlBQVksRUFDYixFQUFFLG1CQUFtQixHQUFHLGVBQWUsRUFBRSxDQUd6QztBQUVEOzs7R0FHRztBQUNILHdCQUFzQiw4QkFBOEIsQ0FDbEQsbUJBQW1CLEVBQUUsbUJBQW1CLEVBQ3hDLFVBQVUsRUFBRSxVQUFVLEVBQ3RCLFNBQVMsRUFBRSxJQUFJLENBQUMsaUJBQWlCLEVBQUUsZUFBZSxDQUFDLEVBQ25ELE1BQU0sQ0FBQyxFQUFFLE1BQU0sR0FDZCxPQUFPLENBQUMsd0JBQXdCLENBQUMsQ0EyRm5DIn0=
20
+ export declare function validateCheckpointAttestations(publishedCheckpoint: PublishedCheckpoint, epochCache: EpochCache, constants: Pick<L1RollupConstants, 'epochDuration'>, signatureContext: CoordinationSignatureContext, logger?: Logger): Promise<ValidateCheckpointResult>;
21
+ /** The subset of a calldata-only checkpoint needed to validate its committee attestations. */
22
+ export type CalldataCheckpointForAttestations = {
23
+ checkpointNumber: CheckpointNumber;
24
+ archiveRoot: Fr;
25
+ feeAssetPriceModifier: bigint;
26
+ header: CheckpointHeader;
27
+ attestations: CommitteeAttestation[];
28
+ };
29
+ /**
30
+ * Validates the attestations of a checkpoint from L1 calldata only, without fetching or decoding its blobs.
31
+ * The signed consensus payload (header, archive root, fee asset price modifier) is fully available from
32
+ * calldata, so an invalid-attestation checkpoint can be rejected before any (possibly malformed) blob is
33
+ * fetched and decoded.
34
+ */
35
+ export declare function validateCheckpointAttestationsFromCalldata(checkpoint: CalldataCheckpointForAttestations, epochCache: EpochCache, constants: Pick<L1RollupConstants, 'epochDuration'>, signatureContext: CoordinationSignatureContext, logger?: Logger): Promise<ValidateCheckpointResult>;
36
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsaWRhdGlvbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL21vZHVsZXMvdmFsaWRhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUNyRCxPQUFPLEVBQUUsS0FBSyxnQ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,CAAC,CAInC;AAED,8FAA8F;AAC9F,MAAM,MAAM,iCAAiC,GAAG;IAC9C,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,WAAW,EAAE,EAAE,CAAC;IAChB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,MAAM,EAAE,gBAAgB,CAAC;IACzB,YAAY,EAAE,oBAAoB,EAAE,CAAC;CACtC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,0CAA0C,CACxD,UAAU,EAAE,iCAAiC,EAC7C,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,CAAC,EACnD,gBAAgB,EAAE,4BAA4B,EAC9C,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,wBAAwB,CAAC,CAenC"}
@@ -1,34 +1,59 @@
1
1
  import { compactArray } from '@aztec/foundation/collection';
2
2
  import { getAttestationInfoFromPayload } from '@aztec/stdlib/block';
3
- import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
3
+ import { computeQuorum, getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
4
4
  import { ConsensusPayload } from '@aztec/stdlib/p2p';
5
5
  /**
6
6
  * Extracts attestation information from a published checkpoint.
7
7
  * Returns info for each attestation, preserving array indices.
8
- */ export function getAttestationInfoFromPublishedCheckpoint({ checkpoint, attestations }) {
9
- const payload = ConsensusPayload.fromCheckpoint(checkpoint);
8
+ */ export function getAttestationInfoFromPublishedCheckpoint({ checkpoint, attestations }, signatureContext) {
9
+ const payload = ConsensusPayload.fromCheckpoint(checkpoint, signatureContext);
10
10
  return getAttestationInfoFromPayload(payload, attestations);
11
11
  }
12
12
  /**
13
- * Validates the attestations submitted for the given checkpoint.
13
+ * Validates the attestations of a checkpoint already retrieved (with its blocks) from blobs.
14
14
  * Returns true if the attestations are valid and sufficient, false otherwise.
15
- */ export async function validateCheckpointAttestations(publishedCheckpoint, epochCache, constants, logger) {
16
- const attestorInfos = getAttestationInfoFromPublishedCheckpoint(publishedCheckpoint);
17
- const attestors = compactArray(attestorInfos.map((info)=>'address' in info ? info.address : undefined));
15
+ */ export function validateCheckpointAttestations(publishedCheckpoint, epochCache, constants, signatureContext, logger) {
18
16
  const { checkpoint, attestations } = publishedCheckpoint;
19
- const headerHash = checkpoint.header.hash();
20
- const archiveRoot = checkpoint.archive.root.toString();
21
- const slot = checkpoint.header.slotNumber;
17
+ const payload = ConsensusPayload.fromCheckpoint(checkpoint, signatureContext);
18
+ return validateAttestations(payload, attestations, checkpoint.toCheckpointInfo(), epochCache, constants, logger);
19
+ }
20
+ /**
21
+ * Validates the attestations of a checkpoint from L1 calldata only, without fetching or decoding its blobs.
22
+ * The signed consensus payload (header, archive root, fee asset price modifier) is fully available from
23
+ * calldata, so an invalid-attestation checkpoint can be rejected before any (possibly malformed) blob is
24
+ * fetched and decoded.
25
+ */ export function validateCheckpointAttestationsFromCalldata(checkpoint, epochCache, constants, signatureContext, logger) {
26
+ const payload = new ConsensusPayload(checkpoint.header, checkpoint.archiveRoot, checkpoint.feeAssetPriceModifier, signatureContext);
27
+ const checkpointInfo = {
28
+ archive: checkpoint.archiveRoot,
29
+ lastArchive: checkpoint.header.lastArchiveRoot,
30
+ slotNumber: checkpoint.header.slotNumber,
31
+ checkpointNumber: checkpoint.checkpointNumber,
32
+ timestamp: checkpoint.header.timestamp
33
+ };
34
+ return validateAttestations(payload, checkpoint.attestations, checkpointInfo, epochCache, constants, logger);
35
+ }
36
+ /**
37
+ * Core attestation validation over a consensus payload, its attestations, and checkpoint metadata --
38
+ * independent of whether the checkpoint's blocks have been decoded from blobs. Returns true if the
39
+ * attestations are valid and sufficient, false otherwise.
40
+ */ async function validateAttestations(payload, attestations, checkpointInfo, epochCache, constants, logger) {
41
+ const attestorInfos = getAttestationInfoFromPayload(payload, attestations);
42
+ const attestors = compactArray(attestorInfos.map((info)=>'address' in info ? info.address : undefined));
43
+ const headerHash = payload.header.hash();
44
+ const archiveRoot = payload.archive.toString();
45
+ const slot = payload.header.slotNumber;
46
+ const checkpointNumber = checkpointInfo.checkpointNumber;
22
47
  const epoch = getEpochAtSlot(slot, constants);
23
48
  const { committee, seed } = await epochCache.getCommitteeForEpoch(epoch);
24
49
  const logData = {
25
- checkpointNumber: checkpoint.number,
50
+ checkpointNumber,
26
51
  slot,
27
52
  epoch,
28
53
  headerHash,
29
54
  archiveRoot
30
55
  };
31
- logger?.debug(`Validating attestations for checkpoint ${checkpoint.number} at slot ${slot} in epoch ${epoch}`, {
56
+ logger?.debug(`Validating attestations for checkpoint ${checkpointNumber} at slot ${slot} in epoch ${epoch}`, {
32
57
  committee: (committee ?? []).map((member)=>member.toString()),
33
58
  recoveredAttestors: attestorInfos,
34
59
  postedAttestations: attestations.map((a)=>(a.address.isZero() ? a.signature : a.address).toString()),
@@ -46,11 +71,11 @@ import { ConsensusPayload } from '@aztec/stdlib/p2p';
46
71
  valid: true
47
72
  };
48
73
  }
49
- const requiredAttestationCount = Math.floor(committee.length * 2 / 3) + 1;
74
+ const requiredAttestationCount = computeQuorum(committee.length);
50
75
  const failedValidationResult = (reason)=>({
51
76
  valid: false,
52
77
  reason,
53
- checkpoint: checkpoint.toCheckpointInfo(),
78
+ checkpoint: checkpointInfo,
54
79
  committee,
55
80
  seed,
56
81
  epoch,
@@ -97,7 +122,7 @@ import { ConsensusPayload } from '@aztec/stdlib/p2p';
97
122
  });
98
123
  return failedValidationResult('insufficient-attestations');
99
124
  }
100
- logger?.debug(`Checkpoint attestations validated successfully for checkpoint ${checkpoint.number} at slot ${slot}`, logData);
125
+ logger?.debug(`Checkpoint attestations validated successfully for checkpoint ${checkpointNumber} at slot ${slot}`, logData);
101
126
  return {
102
127
  valid: true
103
128
  };