@aztec/archiver 3.0.0-nightly.20251209 → 3.0.0-nightly.20251211

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 (108) hide show
  1. package/dest/archiver/archiver.d.ts +16 -14
  2. package/dest/archiver/archiver.d.ts.map +1 -1
  3. package/dest/archiver/archiver.js +59 -28
  4. package/dest/archiver/archiver_store.d.ts +9 -9
  5. package/dest/archiver/archiver_store.d.ts.map +1 -1
  6. package/dest/archiver/archiver_store_test_suite.d.ts +1 -1
  7. package/dest/archiver/archiver_store_test_suite.d.ts.map +1 -1
  8. package/dest/archiver/archiver_store_test_suite.js +47 -46
  9. package/dest/archiver/config.d.ts +3 -2
  10. package/dest/archiver/config.d.ts.map +1 -1
  11. package/dest/archiver/config.js +8 -1
  12. package/dest/archiver/instrumentation.d.ts +3 -1
  13. package/dest/archiver/instrumentation.d.ts.map +1 -1
  14. package/dest/archiver/instrumentation.js +11 -0
  15. package/dest/archiver/kv_archiver_store/block_store.d.ts +2 -2
  16. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
  17. package/dest/archiver/kv_archiver_store/block_store.js +1 -1
  18. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +2 -2
  19. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +1 -1
  20. package/dest/archiver/kv_archiver_store/contract_class_store.js +1 -1
  21. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +2 -2
  22. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +1 -1
  23. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +8 -8
  24. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
  25. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +6 -6
  26. package/dest/archiver/kv_archiver_store/log_store.d.ts +2 -2
  27. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +1 -1
  28. package/dest/archiver/kv_archiver_store/message_store.d.ts +6 -5
  29. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
  30. package/dest/archiver/kv_archiver_store/message_store.js +15 -14
  31. package/dest/archiver/l1/bin/retrieve-calldata.d.ts +3 -0
  32. package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +1 -0
  33. package/dest/archiver/l1/bin/retrieve-calldata.js +147 -0
  34. package/dest/archiver/l1/calldata_retriever.d.ts +98 -0
  35. package/dest/archiver/l1/calldata_retriever.d.ts.map +1 -0
  36. package/dest/archiver/l1/calldata_retriever.js +403 -0
  37. package/dest/archiver/l1/data_retrieval.d.ts +87 -0
  38. package/dest/archiver/l1/data_retrieval.d.ts.map +1 -0
  39. package/dest/archiver/{data_retrieval.js → l1/data_retrieval.js} +26 -95
  40. package/dest/archiver/l1/debug_tx.d.ts +19 -0
  41. package/dest/archiver/l1/debug_tx.d.ts.map +1 -0
  42. package/dest/archiver/l1/debug_tx.js +73 -0
  43. package/dest/archiver/l1/spire_proposer.d.ts +70 -0
  44. package/dest/archiver/l1/spire_proposer.d.ts.map +1 -0
  45. package/dest/archiver/l1/spire_proposer.js +157 -0
  46. package/dest/archiver/l1/trace_tx.d.ts +97 -0
  47. package/dest/archiver/l1/trace_tx.d.ts.map +1 -0
  48. package/dest/archiver/l1/trace_tx.js +91 -0
  49. package/dest/archiver/l1/types.d.ts +12 -0
  50. package/dest/archiver/l1/types.d.ts.map +1 -0
  51. package/dest/archiver/l1/types.js +3 -0
  52. package/dest/archiver/l1/validate_trace.d.ts +29 -0
  53. package/dest/archiver/l1/validate_trace.d.ts.map +1 -0
  54. package/dest/archiver/l1/validate_trace.js +150 -0
  55. package/dest/archiver/structs/inbox_message.d.ts +4 -4
  56. package/dest/archiver/structs/inbox_message.d.ts.map +1 -1
  57. package/dest/archiver/structs/inbox_message.js +6 -6
  58. package/dest/index.d.ts +2 -2
  59. package/dest/index.d.ts.map +1 -1
  60. package/dest/index.js +1 -1
  61. package/dest/test/mock_archiver.d.ts +4 -5
  62. package/dest/test/mock_archiver.d.ts.map +1 -1
  63. package/dest/test/mock_archiver.js +5 -9
  64. package/dest/test/mock_l1_to_l2_message_source.d.ts +5 -6
  65. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  66. package/dest/test/mock_l1_to_l2_message_source.js +7 -11
  67. package/dest/test/mock_l2_block_source.d.ts +2 -2
  68. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  69. package/dest/test/mock_l2_block_source.js +2 -2
  70. package/dest/test/mock_structs.d.ts +3 -2
  71. package/dest/test/mock_structs.d.ts.map +1 -1
  72. package/dest/test/mock_structs.js +9 -9
  73. package/package.json +15 -14
  74. package/src/archiver/archiver.ts +79 -40
  75. package/src/archiver/archiver_store.ts +8 -8
  76. package/src/archiver/archiver_store_test_suite.ts +56 -48
  77. package/src/archiver/config.ts +8 -7
  78. package/src/archiver/instrumentation.ts +14 -0
  79. package/src/archiver/kv_archiver_store/block_store.ts +1 -1
  80. package/src/archiver/kv_archiver_store/contract_class_store.ts +1 -1
  81. package/src/archiver/kv_archiver_store/contract_instance_store.ts +1 -1
  82. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +9 -9
  83. package/src/archiver/kv_archiver_store/log_store.ts +1 -1
  84. package/src/archiver/kv_archiver_store/message_store.ts +21 -18
  85. package/src/archiver/l1/README.md +98 -0
  86. package/src/archiver/l1/bin/retrieve-calldata.ts +182 -0
  87. package/src/archiver/l1/calldata_retriever.ts +531 -0
  88. package/src/archiver/{data_retrieval.ts → l1/data_retrieval.ts} +57 -143
  89. package/src/archiver/l1/debug_tx.ts +99 -0
  90. package/src/archiver/l1/spire_proposer.ts +160 -0
  91. package/src/archiver/l1/trace_tx.ts +128 -0
  92. package/src/archiver/l1/types.ts +13 -0
  93. package/src/archiver/l1/validate_trace.ts +211 -0
  94. package/src/archiver/structs/inbox_message.ts +7 -8
  95. package/src/index.ts +1 -1
  96. package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
  97. package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
  98. package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
  99. package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
  100. package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
  101. package/src/test/fixtures/trace_transaction-proxied.json +128 -0
  102. package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
  103. package/src/test/mock_archiver.ts +6 -11
  104. package/src/test/mock_l1_to_l2_message_source.ts +6 -11
  105. package/src/test/mock_l2_block_source.ts +2 -2
  106. package/src/test/mock_structs.ts +10 -10
  107. package/dest/archiver/data_retrieval.d.ts +0 -80
  108. package/dest/archiver/data_retrieval.d.ts.map +0 -1
@@ -0,0 +1,531 @@
1
+ import { MULTI_CALL_3_ADDRESS, type ViemCommitteeAttestations, type ViemHeader } from '@aztec/ethereum/contracts';
2
+ import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
3
+ import { CheckpointNumber } from '@aztec/foundation/branded-types';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
5
+ import { EthAddress } from '@aztec/foundation/eth-address';
6
+ import type { ViemSignature } from '@aztec/foundation/eth-signature';
7
+ import type { Logger } from '@aztec/foundation/log';
8
+ import {
9
+ EmpireSlashingProposerAbi,
10
+ GovernanceProposerAbi,
11
+ RollupAbi,
12
+ SlashFactoryAbi,
13
+ TallySlashingProposerAbi,
14
+ } from '@aztec/l1-artifacts';
15
+ import { CommitteeAttestation } from '@aztec/stdlib/block';
16
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
17
+
18
+ import { type Hex, type Transaction, decodeFunctionData, hexToBytes, multicall3Abi, toFunctionSelector } from 'viem';
19
+
20
+ import type { ArchiverInstrumentation } from '../instrumentation.js';
21
+ import { getSuccessfulCallsFromDebug } from './debug_tx.js';
22
+ import { getCallFromSpireProposer } from './spire_proposer.js';
23
+ import { getSuccessfulCallsFromTrace } from './trace_tx.js';
24
+ import type { CallInfo } from './types.js';
25
+
26
+ /**
27
+ * Extracts calldata to the `propose` method of the rollup contract from an L1 transaction
28
+ * in order to reconstruct an L2 block header.
29
+ */
30
+ export class CalldataRetriever {
31
+ /** Pre-computed valid contract calls for validation */
32
+ private readonly validContractCalls: ValidContractCall[];
33
+
34
+ private readonly rollupAddress: EthAddress;
35
+
36
+ constructor(
37
+ private readonly publicClient: ViemPublicClient,
38
+ private readonly debugClient: ViemPublicDebugClient,
39
+ private readonly targetCommitteeSize: number,
40
+ private readonly instrumentation: ArchiverInstrumentation | undefined,
41
+ private readonly logger: Logger,
42
+ contractAddresses: {
43
+ rollupAddress: EthAddress;
44
+ governanceProposerAddress: EthAddress;
45
+ slashingProposerAddress: EthAddress;
46
+ slashFactoryAddress?: EthAddress;
47
+ },
48
+ ) {
49
+ this.rollupAddress = contractAddresses.rollupAddress;
50
+ this.validContractCalls = computeValidContractCalls(contractAddresses);
51
+ }
52
+
53
+ /**
54
+ * Gets checkpoint header and metadata from the calldata of an L1 transaction.
55
+ * Tries multicall3 decoding, falls back to trace-based extraction.
56
+ * @param txHash - Hash of the tx that published it.
57
+ * @param blobHashes - Blob hashes for the checkpoint.
58
+ * @param checkpointNumber - Checkpoint number.
59
+ * @returns Checkpoint header and metadata from the calldata, deserialized
60
+ */
61
+ async getCheckpointFromRollupTx(
62
+ txHash: `0x${string}`,
63
+ blobHashes: Buffer[],
64
+ checkpointNumber: CheckpointNumber,
65
+ ): Promise<{
66
+ checkpointNumber: CheckpointNumber;
67
+ archiveRoot: Fr;
68
+ header: CheckpointHeader;
69
+ attestations: CommitteeAttestation[];
70
+ blockHash: string;
71
+ }> {
72
+ this.logger.trace(`Fetching checkpoint ${checkpointNumber} from rollup tx ${txHash}`);
73
+ const tx = await this.publicClient.getTransaction({ hash: txHash });
74
+ const proposeCalldata = await this.getProposeCallData(tx, checkpointNumber);
75
+ return this.decodeAndBuildCheckpoint(proposeCalldata, tx.blockHash!, checkpointNumber);
76
+ }
77
+
78
+ /** Gets rollup propose calldata from a transaction */
79
+ protected async getProposeCallData(tx: Transaction, checkpointNumber: CheckpointNumber): Promise<Hex> {
80
+ // Try to decode as multicall3 with validation
81
+ const proposeCalldata = this.tryDecodeMulticall3(tx);
82
+ if (proposeCalldata) {
83
+ this.logger.trace(`Decoded propose calldata from multicall3 for tx ${tx.hash}`);
84
+ this.instrumentation?.recordBlockProposalTxTarget(tx.to!, false);
85
+ return proposeCalldata;
86
+ }
87
+
88
+ // Try to decode as direct propose call
89
+ const directProposeCalldata = this.tryDecodeDirectPropose(tx);
90
+ if (directProposeCalldata) {
91
+ this.logger.trace(`Decoded propose calldata from direct call for tx ${tx.hash}`);
92
+ this.instrumentation?.recordBlockProposalTxTarget(tx.to!, false);
93
+ return directProposeCalldata;
94
+ }
95
+
96
+ // Try to decode as Spire Proposer multicall wrapper
97
+ const spireProposeCalldata = await this.tryDecodeSpireProposer(tx);
98
+ if (spireProposeCalldata) {
99
+ this.logger.trace(`Decoded propose calldata from Spire Proposer for tx ${tx.hash}`);
100
+ this.instrumentation?.recordBlockProposalTxTarget(tx.to!, false);
101
+ return spireProposeCalldata;
102
+ }
103
+
104
+ // Fall back to trace-based extraction
105
+ this.logger.warn(
106
+ `Failed to decode multicall3, direct propose, or Spire proposer for L1 tx ${tx.hash}, falling back to trace for checkpoint ${checkpointNumber}`,
107
+ );
108
+ this.instrumentation?.recordBlockProposalTxTarget(tx.to ?? EthAddress.ZERO.toString(), true);
109
+ return await this.extractCalldataViaTrace(tx.hash);
110
+ }
111
+
112
+ /**
113
+ * Attempts to decode a transaction as a Spire Proposer multicall wrapper.
114
+ * If successful, extracts the wrapped call and validates it as either multicall3 or direct propose.
115
+ * @param tx - The transaction to decode
116
+ * @returns The propose calldata if successfully decoded and validated, undefined otherwise
117
+ */
118
+ protected async tryDecodeSpireProposer(tx: Transaction): Promise<Hex | undefined> {
119
+ // Try to decode as Spire Proposer multicall (extracts the wrapped call)
120
+ const spireWrappedCall = await getCallFromSpireProposer(tx, this.publicClient, this.logger);
121
+ if (!spireWrappedCall) {
122
+ return undefined;
123
+ }
124
+
125
+ this.logger.trace(`Decoded Spire Proposer wrapping for tx ${tx.hash}, inner call to ${spireWrappedCall.to}`);
126
+
127
+ // Now try to decode the wrapped call as either multicall3 or direct propose
128
+ const wrappedTx = { to: spireWrappedCall.to, input: spireWrappedCall.data, hash: tx.hash };
129
+
130
+ const multicall3Calldata = this.tryDecodeMulticall3(wrappedTx);
131
+ if (multicall3Calldata) {
132
+ this.logger.trace(`Decoded propose calldata from Spire Proposer to multicall3 for tx ${tx.hash}`);
133
+ return multicall3Calldata;
134
+ }
135
+
136
+ const directProposeCalldata = this.tryDecodeDirectPropose(wrappedTx);
137
+ if (directProposeCalldata) {
138
+ this.logger.trace(`Decoded propose calldata from Spire Proposer to direct propose for tx ${tx.hash}`);
139
+ return directProposeCalldata;
140
+ }
141
+
142
+ this.logger.warn(
143
+ `Spire Proposer wrapped call could not be decoded as multicall3 or direct propose for tx ${tx.hash}`,
144
+ );
145
+ return undefined;
146
+ }
147
+
148
+ /**
149
+ * Attempts to decode transaction input as multicall3 and extract propose calldata.
150
+ * Returns undefined if validation fails.
151
+ * @param tx - The transaction-like object with to, input, and hash
152
+ * @returns The propose calldata if successfully validated, undefined otherwise
153
+ */
154
+ protected tryDecodeMulticall3(tx: { to: Hex | null | undefined; input: Hex; hash: Hex }): Hex | undefined {
155
+ const txHash = tx.hash;
156
+
157
+ try {
158
+ // Check if transaction is to Multicall3 address
159
+ if (!tx.to || !EthAddress.areEqual(tx.to, MULTI_CALL_3_ADDRESS)) {
160
+ this.logger.debug(`Transaction is not to Multicall3 address (to: ${tx.to})`, { txHash, to: tx.to });
161
+ return undefined;
162
+ }
163
+
164
+ // Try to decode as multicall3 aggregate3 call
165
+ const { functionName: multicall3Fn, args: multicall3Args } = decodeFunctionData({
166
+ abi: multicall3Abi,
167
+ data: tx.input,
168
+ });
169
+
170
+ // If not aggregate3, return undefined (not a multicall3 transaction)
171
+ if (multicall3Fn !== 'aggregate3') {
172
+ this.logger.warn(`Transaction is not multicall3 aggregate3 (got ${multicall3Fn})`, { txHash });
173
+ return undefined;
174
+ }
175
+
176
+ if (multicall3Args.length !== 1) {
177
+ this.logger.warn(`Unexpected number of arguments for multicall3 (got ${multicall3Args.length})`, { txHash });
178
+ return undefined;
179
+ }
180
+
181
+ const [calls] = multicall3Args;
182
+
183
+ // Validate all calls and find propose calls
184
+ const rollupAddressLower = this.rollupAddress.toString().toLowerCase();
185
+ const proposeCalls: Hex[] = [];
186
+
187
+ for (let i = 0; i < calls.length; i++) {
188
+ const addr = calls[i].target.toLowerCase();
189
+ const callData = calls[i].callData;
190
+
191
+ // Extract function selector (first 4 bytes)
192
+ if (callData.length < 10) {
193
+ // "0x" + 8 hex chars = 10 chars minimum for a valid function call
194
+ this.logger.warn(`Invalid calldata length at index ${i} (${callData.length})`, { txHash });
195
+ return undefined;
196
+ }
197
+ const functionSelector = callData.slice(0, 10) as Hex;
198
+
199
+ // Validate this call is allowed by searching through valid calls
200
+ const validCall = this.validContractCalls.find(
201
+ vc => vc.address === addr && vc.functionSelector === functionSelector,
202
+ );
203
+
204
+ if (!validCall) {
205
+ this.logger.warn(`Invalid contract call detected in multicall3`, {
206
+ index: i,
207
+ targetAddress: addr,
208
+ functionSelector,
209
+ validCalls: this.validContractCalls.map(c => ({ address: c.address, selector: c.functionSelector })),
210
+ txHash,
211
+ });
212
+ return undefined;
213
+ }
214
+
215
+ this.logger.trace(`Valid call found to ${addr}`, { validCall });
216
+
217
+ // Collect propose calls specifically
218
+ if (addr === rollupAddressLower && validCall.functionName === 'propose') {
219
+ proposeCalls.push(callData);
220
+ }
221
+ }
222
+
223
+ // Validate exactly ONE propose call
224
+ if (proposeCalls.length === 0) {
225
+ this.logger.warn(`No propose calls found in multicall3`, { txHash });
226
+ return undefined;
227
+ }
228
+
229
+ if (proposeCalls.length > 1) {
230
+ this.logger.warn(`Multiple propose calls found in multicall3 (${proposeCalls.length})`, { txHash });
231
+ return undefined;
232
+ }
233
+
234
+ // Successfully extracted single propose call
235
+ return proposeCalls[0];
236
+ } catch (err) {
237
+ // Any decoding error triggers fallback to trace
238
+ this.logger.warn(`Failed to decode multicall3: ${err}`, { txHash });
239
+ return undefined;
240
+ }
241
+ }
242
+
243
+ /**
244
+ * Attempts to decode transaction as a direct propose call to the rollup contract.
245
+ * Returns undefined if validation fails.
246
+ * @param tx - The transaction-like object with to, input, and hash
247
+ * @returns The propose calldata if successfully validated, undefined otherwise
248
+ */
249
+ protected tryDecodeDirectPropose(tx: { to: Hex | null | undefined; input: Hex; hash: Hex }): Hex | undefined {
250
+ const txHash = tx.hash;
251
+ try {
252
+ // Check if transaction is to the rollup address
253
+ if (!tx.to || !EthAddress.areEqual(tx.to, this.rollupAddress)) {
254
+ this.logger.debug(`Transaction is not to rollup address (to: ${tx.to})`, { txHash });
255
+ return undefined;
256
+ }
257
+
258
+ // Try to decode as propose call
259
+ const { functionName } = decodeFunctionData({ abi: RollupAbi, data: tx.input });
260
+
261
+ // If not propose, return undefined
262
+ if (functionName !== 'propose') {
263
+ this.logger.warn(`Transaction to rollup is not propose (got ${functionName})`, { txHash });
264
+ return undefined;
265
+ }
266
+
267
+ // Successfully validated direct propose call
268
+ this.logger.trace(`Validated direct propose call to rollup`, { txHash });
269
+ return tx.input;
270
+ } catch (err) {
271
+ // Any decoding error means it's not a valid propose call
272
+ this.logger.warn(`Failed to decode as direct propose: ${err}`, { txHash });
273
+ return undefined;
274
+ }
275
+ }
276
+
277
+ /**
278
+ * Uses debug/trace RPC to extract the actual calldata from the successful propose call.
279
+ * This is the definitive fallback that works for any transaction pattern.
280
+ * Tries trace_transaction first, then falls back to debug_traceTransaction.
281
+ * @param txHash - The transaction hash to trace
282
+ * @returns The propose calldata from the successful call
283
+ */
284
+ protected async extractCalldataViaTrace(txHash: Hex): Promise<Hex> {
285
+ const rollupAddress = this.rollupAddress;
286
+ const selector = PROPOSE_SELECTOR;
287
+
288
+ let calls: CallInfo[];
289
+ try {
290
+ // Try trace_transaction first (using Parity/OpenEthereum/Erigon RPC)
291
+ this.logger.debug(`Attempting to trace transaction ${txHash} using trace_transaction`);
292
+ calls = await getSuccessfulCallsFromTrace(this.debugClient, txHash, rollupAddress, selector, this.logger);
293
+ this.logger.debug(`Successfully traced using trace_transaction, found ${calls.length} calls`);
294
+ } catch (err) {
295
+ const traceError = err instanceof Error ? err : new Error(String(err));
296
+ this.logger.verbose(`Failed trace_transaction for ${txHash}`, { traceError });
297
+
298
+ try {
299
+ // Fall back to debug_traceTransaction (Geth RPC)
300
+ this.logger.debug(`Attempting to trace transaction ${txHash} using debug_traceTransaction`);
301
+ calls = await getSuccessfulCallsFromDebug(this.debugClient, txHash, rollupAddress, selector, this.logger);
302
+ this.logger.debug(`Successfully traced using debug_traceTransaction, found ${calls.length} calls`);
303
+ } catch (debugErr) {
304
+ const debugError = debugErr instanceof Error ? debugErr : new Error(String(debugErr));
305
+ this.logger.warn(`All tracing methods failed for tx ${txHash}`, {
306
+ traceError,
307
+ debugError,
308
+ txHash,
309
+ });
310
+ throw new Error(`Failed to trace transaction ${txHash} to extract propose calldata`);
311
+ }
312
+ }
313
+
314
+ // Validate exactly ONE successful propose call
315
+ if (calls.length === 0) {
316
+ throw new Error(`No successful propose calls found in transaction ${txHash}`);
317
+ }
318
+
319
+ if (calls.length > 1) {
320
+ throw new Error(`Multiple successful propose calls found in transaction ${txHash} (${calls.length})`);
321
+ }
322
+
323
+ // Return the calldata from the single successful propose call
324
+ return calls[0].input;
325
+ }
326
+
327
+ /**
328
+ * Decodes propose calldata and builds the checkpoint header structure.
329
+ * @param proposeCalldata - The propose function calldata
330
+ * @param blockHash - The L1 block hash containing this transaction
331
+ * @param checkpointNumber - The checkpoint number
332
+ * @returns The decoded checkpoint header and metadata
333
+ */
334
+ protected decodeAndBuildCheckpoint(
335
+ proposeCalldata: Hex,
336
+ blockHash: Hex,
337
+ checkpointNumber: CheckpointNumber,
338
+ ): {
339
+ checkpointNumber: CheckpointNumber;
340
+ archiveRoot: Fr;
341
+ header: CheckpointHeader;
342
+ attestations: CommitteeAttestation[];
343
+ blockHash: string;
344
+ } {
345
+ const { functionName: rollupFunctionName, args: rollupArgs } = decodeFunctionData({
346
+ abi: RollupAbi,
347
+ data: proposeCalldata,
348
+ });
349
+
350
+ if (rollupFunctionName !== 'propose') {
351
+ throw new Error(`Unexpected rollup method called ${rollupFunctionName}`);
352
+ }
353
+
354
+ const [decodedArgs, packedAttestations, _signers, _attestationsAndSignersSignature, _blobInput] =
355
+ rollupArgs! as readonly [
356
+ {
357
+ archive: Hex;
358
+ oracleInput: { feeAssetPriceModifier: bigint };
359
+ header: ViemHeader;
360
+ },
361
+ ViemCommitteeAttestations,
362
+ Hex[],
363
+ ViemSignature,
364
+ Hex,
365
+ ];
366
+
367
+ const attestations = CommitteeAttestation.fromPacked(packedAttestations, this.targetCommitteeSize);
368
+
369
+ this.logger.trace(`Decoded propose calldata`, {
370
+ checkpointNumber,
371
+ archive: decodedArgs.archive,
372
+ header: decodedArgs.header,
373
+ l1BlockHash: blockHash,
374
+ attestations,
375
+ packedAttestations,
376
+ targetCommitteeSize: this.targetCommitteeSize,
377
+ });
378
+
379
+ const header = CheckpointHeader.fromViem(decodedArgs.header);
380
+ const archiveRoot = new Fr(Buffer.from(hexToBytes(decodedArgs.archive)));
381
+
382
+ return {
383
+ checkpointNumber,
384
+ archiveRoot,
385
+ header,
386
+ attestations,
387
+ blockHash,
388
+ };
389
+ }
390
+ }
391
+
392
+ /**
393
+ * Pre-computed function selectors for all valid contract calls.
394
+ * These are computed once at module load time from the ABIs.
395
+ * Based on analysis of sequencer-client/src/publisher/sequencer-publisher.ts
396
+ */
397
+
398
+ // Rollup contract function selectors (always valid)
399
+ const PROPOSE_SELECTOR = toFunctionSelector(RollupAbi.find(x => x.type === 'function' && x.name === 'propose')!);
400
+ const INVALIDATE_BAD_ATTESTATION_SELECTOR = toFunctionSelector(
401
+ RollupAbi.find(x => x.type === 'function' && x.name === 'invalidateBadAttestation')!,
402
+ );
403
+ const INVALIDATE_INSUFFICIENT_ATTESTATIONS_SELECTOR = toFunctionSelector(
404
+ RollupAbi.find(x => x.type === 'function' && x.name === 'invalidateInsufficientAttestations')!,
405
+ );
406
+
407
+ // Governance proposer function selectors
408
+ const GOVERNANCE_SIGNAL_WITH_SIG_SELECTOR = toFunctionSelector(
409
+ GovernanceProposerAbi.find(x => x.type === 'function' && x.name === 'signalWithSig')!,
410
+ );
411
+
412
+ // Slash factory function selectors
413
+ const CREATE_SLASH_PAYLOAD_SELECTOR = toFunctionSelector(
414
+ SlashFactoryAbi.find(x => x.type === 'function' && x.name === 'createSlashPayload')!,
415
+ );
416
+
417
+ // Empire slashing proposer function selectors
418
+ const EMPIRE_SIGNAL_WITH_SIG_SELECTOR = toFunctionSelector(
419
+ EmpireSlashingProposerAbi.find(x => x.type === 'function' && x.name === 'signalWithSig')!,
420
+ );
421
+ const EMPIRE_SUBMIT_ROUND_WINNER_SELECTOR = toFunctionSelector(
422
+ EmpireSlashingProposerAbi.find(x => x.type === 'function' && x.name === 'submitRoundWinner')!,
423
+ );
424
+
425
+ // Tally slashing proposer function selectors
426
+ const TALLY_VOTE_SELECTOR = toFunctionSelector(
427
+ TallySlashingProposerAbi.find(x => x.type === 'function' && x.name === 'vote')!,
428
+ );
429
+ const TALLY_EXECUTE_ROUND_SELECTOR = toFunctionSelector(
430
+ TallySlashingProposerAbi.find(x => x.type === 'function' && x.name === 'executeRound')!,
431
+ );
432
+
433
+ /**
434
+ * Defines a valid contract call that can appear in a sequencer publisher transaction
435
+ */
436
+ interface ValidContractCall {
437
+ /** Contract address (lowercase for comparison) */
438
+ address: string;
439
+ /** Function selector (4 bytes) */
440
+ functionSelector: Hex;
441
+ /** Human-readable function name for logging */
442
+ functionName: string;
443
+ }
444
+
445
+ /**
446
+ * All valid contract calls that the sequencer publisher can make.
447
+ * Builds the list of valid (address, selector) pairs for validation.
448
+ *
449
+ * Alternatively, if we are absolutely sure that no code path from any of these
450
+ * contracts can eventually land on another call to `propose`, we can remove the
451
+ * function selectors.
452
+ */
453
+ function computeValidContractCalls(addresses: {
454
+ rollupAddress: EthAddress;
455
+ governanceProposerAddress?: EthAddress;
456
+ slashFactoryAddress?: EthAddress;
457
+ slashingProposerAddress?: EthAddress;
458
+ }): ValidContractCall[] {
459
+ const { rollupAddress, governanceProposerAddress, slashFactoryAddress, slashingProposerAddress } = addresses;
460
+ const calls: ValidContractCall[] = [];
461
+
462
+ // Rollup contract calls (always present)
463
+ calls.push(
464
+ {
465
+ address: rollupAddress.toString().toLowerCase(),
466
+ functionSelector: PROPOSE_SELECTOR,
467
+ functionName: 'propose',
468
+ },
469
+ {
470
+ address: rollupAddress.toString().toLowerCase(),
471
+ functionSelector: INVALIDATE_BAD_ATTESTATION_SELECTOR,
472
+ functionName: 'invalidateBadAttestation',
473
+ },
474
+ {
475
+ address: rollupAddress.toString().toLowerCase(),
476
+ functionSelector: INVALIDATE_INSUFFICIENT_ATTESTATIONS_SELECTOR,
477
+ functionName: 'invalidateInsufficientAttestations',
478
+ },
479
+ );
480
+
481
+ // Governance proposer calls (optional)
482
+ if (governanceProposerAddress && !governanceProposerAddress.isZero()) {
483
+ calls.push({
484
+ address: governanceProposerAddress.toString().toLowerCase(),
485
+ functionSelector: GOVERNANCE_SIGNAL_WITH_SIG_SELECTOR,
486
+ functionName: 'signalWithSig',
487
+ });
488
+ }
489
+
490
+ // Slash factory calls (optional)
491
+ if (slashFactoryAddress && !slashFactoryAddress.isZero()) {
492
+ calls.push({
493
+ address: slashFactoryAddress.toString().toLowerCase(),
494
+ functionSelector: CREATE_SLASH_PAYLOAD_SELECTOR,
495
+ functionName: 'createSlashPayload',
496
+ });
497
+ }
498
+
499
+ // Slashing proposer calls (optional, can be either Empire or Tally)
500
+ if (slashingProposerAddress && !slashingProposerAddress.isZero()) {
501
+ // Empire calls
502
+ calls.push(
503
+ {
504
+ address: slashingProposerAddress.toString().toLowerCase(),
505
+ functionSelector: EMPIRE_SIGNAL_WITH_SIG_SELECTOR,
506
+ functionName: 'signalWithSig (empire)',
507
+ },
508
+ {
509
+ address: slashingProposerAddress.toString().toLowerCase(),
510
+ functionSelector: EMPIRE_SUBMIT_ROUND_WINNER_SELECTOR,
511
+ functionName: 'submitRoundWinner',
512
+ },
513
+ );
514
+
515
+ // Tally calls
516
+ calls.push(
517
+ {
518
+ address: slashingProposerAddress.toString().toLowerCase(),
519
+ functionSelector: TALLY_VOTE_SELECTOR,
520
+ functionName: 'vote',
521
+ },
522
+ {
523
+ address: slashingProposerAddress.toString().toLowerCase(),
524
+ functionSelector: TALLY_EXECUTE_ROUND_SELECTOR,
525
+ functionName: 'executeRound',
526
+ },
527
+ );
528
+ }
529
+
530
+ return calls;
531
+ }