@aztec/archiver 2.1.8 → 2.1.9

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