@aztec/archiver 4.0.0-nightly.20250907 → 4.0.0-nightly.20260107

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