@aztec/archiver 0.0.1-commit.96bb3f7 → 0.0.1-commit.96dac018d
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.
- package/README.md +156 -22
- package/dest/archiver.d.ts +139 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +699 -0
- package/dest/{archiver/config.d.ts → config.d.ts} +9 -1
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +9 -0
- package/dest/errors.d.ts +41 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/{archiver/errors.js → errors.js} +8 -0
- package/dest/factory.d.ts +9 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +91 -11
- package/dest/index.d.ts +11 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +9 -3
- package/dest/interfaces.d.ts +9 -0
- package/dest/interfaces.d.ts.map +1 -0
- package/dest/interfaces.js +3 -0
- package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.d.ts +1 -1
- package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.js +35 -32
- package/dest/l1/calldata_retriever.d.ts +135 -0
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/l1/calldata_retriever.js +402 -0
- package/dest/l1/data_retrieval.d.ts +85 -0
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/data_retrieval.js +43 -66
- package/dest/{archiver/l1 → l1}/debug_tx.d.ts +1 -1
- package/dest/l1/debug_tx.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/spire_proposer.d.ts +5 -5
- package/dest/l1/spire_proposer.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/spire_proposer.js +9 -17
- package/dest/{archiver/l1 → l1}/trace_tx.d.ts +1 -1
- package/dest/l1/trace_tx.d.ts.map +1 -0
- package/dest/l1/types.d.ts +12 -0
- package/dest/l1/types.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/validate_trace.d.ts +6 -3
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/validate_trace.js +13 -9
- package/dest/modules/data_source_base.d.ts +89 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +216 -0
- package/dest/modules/data_store_updater.d.ts +80 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +323 -0
- package/dest/modules/instrumentation.d.ts +50 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/{archiver → modules}/instrumentation.js +36 -12
- package/dest/modules/l1_synchronizer.d.ts +71 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1117 -0
- package/dest/{archiver → modules}/validation.d.ts +1 -1
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +6 -0
- package/dest/store/block_store.d.ts +196 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/block_store.js +207 -60
- package/dest/store/contract_class_store.d.ts +18 -0
- package/dest/store/contract_class_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +12 -8
- package/dest/store/contract_instance_store.d.ts +24 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
- package/dest/store/kv_archiver_store.d.ts +354 -0
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/store/kv_archiver_store.js +464 -0
- package/dest/store/l2_tips_cache.d.ts +19 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +89 -0
- package/dest/store/log_store.d.ts +54 -0
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/log_store.js +146 -91
- package/dest/{archiver/kv_archiver_store → store}/message_store.d.ts +1 -1
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
- package/dest/structs/data_retrieval.d.ts.map +1 -0
- package/dest/structs/inbox_message.d.ts +15 -0
- package/dest/structs/inbox_message.d.ts.map +1 -0
- package/dest/{archiver/structs → structs}/published.d.ts +1 -1
- package/dest/structs/published.d.ts.map +1 -0
- package/dest/test/fake_l1_state.d.ts +195 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +421 -0
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +4 -1
- package/dest/test/mock_archiver.d.ts +2 -2
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -3
- package/dest/test/mock_l2_block_source.d.ts +35 -17
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +177 -74
- package/dest/test/mock_structs.d.ts +78 -3
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +140 -7
- package/dest/test/noop_l1_archiver.d.ts +23 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +68 -0
- package/package.json +16 -17
- package/src/archiver.ts +443 -0
- package/src/{archiver/config.ts → config.ts} +11 -0
- package/src/{archiver/errors.ts → errors.ts} +12 -0
- package/src/factory.ts +139 -11
- package/src/index.ts +11 -3
- package/src/interfaces.ts +9 -0
- package/src/l1/README.md +55 -0
- package/src/{archiver/l1 → l1}/bin/retrieve-calldata.ts +45 -33
- package/src/l1/calldata_retriever.ts +511 -0
- package/src/{archiver/l1 → l1}/data_retrieval.ts +61 -88
- package/src/{archiver/l1 → l1}/spire_proposer.ts +7 -15
- package/src/{archiver/l1 → l1}/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +328 -0
- package/src/modules/data_store_updater.ts +448 -0
- package/src/{archiver → modules}/instrumentation.ts +46 -14
- package/src/modules/l1_synchronizer.ts +933 -0
- package/src/{archiver → modules}/validation.ts +5 -0
- package/src/{archiver/kv_archiver_store → store}/block_store.ts +258 -93
- package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +12 -8
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +1 -1
- package/src/{archiver/kv_archiver_store → store}/kv_archiver_store.ts +267 -38
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/{archiver/kv_archiver_store → store}/log_store.ts +242 -121
- package/src/test/fake_l1_state.ts +657 -0
- package/src/test/index.ts +4 -0
- package/src/test/mock_archiver.ts +4 -3
- package/src/test/mock_l2_block_source.ts +218 -90
- package/src/test/mock_structs.ts +269 -8
- package/src/test/noop_l1_archiver.ts +109 -0
- package/dest/archiver/archiver.d.ts +0 -307
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -2102
- package/dest/archiver/archiver_store.d.ts +0 -315
- package/dest/archiver/archiver_store.d.ts.map +0 -1
- package/dest/archiver/archiver_store.js +0 -4
- package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
- package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
- package/dest/archiver/archiver_store_test_suite.js +0 -2770
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts +0 -36
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/index.d.ts +0 -7
- package/dest/archiver/index.d.ts.map +0 -1
- package/dest/archiver/index.js +0 -4
- package/dest/archiver/instrumentation.d.ts +0 -37
- package/dest/archiver/instrumentation.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -164
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -159
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -316
- package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -45
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
- package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +0 -1
- package/dest/archiver/l1/calldata_retriever.d.ts +0 -112
- package/dest/archiver/l1/calldata_retriever.d.ts.map +0 -1
- package/dest/archiver/l1/calldata_retriever.js +0 -471
- package/dest/archiver/l1/data_retrieval.d.ts +0 -90
- package/dest/archiver/l1/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/l1/debug_tx.d.ts.map +0 -1
- package/dest/archiver/l1/spire_proposer.d.ts.map +0 -1
- package/dest/archiver/l1/trace_tx.d.ts.map +0 -1
- package/dest/archiver/l1/types.d.ts +0 -12
- package/dest/archiver/l1/types.d.ts.map +0 -1
- package/dest/archiver/l1/validate_trace.d.ts.map +0 -1
- package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/structs/inbox_message.d.ts +0 -15
- package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
- package/dest/archiver/structs/published.d.ts.map +0 -1
- package/dest/archiver/validation.d.ts.map +0 -1
- package/dest/rpc/index.d.ts +0 -9
- package/dest/rpc/index.d.ts.map +0 -1
- package/dest/rpc/index.js +0 -15
- package/src/archiver/archiver.ts +0 -2265
- package/src/archiver/archiver_store.ts +0 -380
- package/src/archiver/archiver_store_test_suite.ts +0 -2842
- package/src/archiver/index.ts +0 -6
- package/src/archiver/l1/README.md +0 -98
- package/src/archiver/l1/calldata_retriever.ts +0 -641
- package/src/rpc/index.ts +0 -16
- /package/dest/{archiver/l1 → l1}/debug_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/trace_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/types.js +0 -0
- /package/dest/{archiver/kv_archiver_store → store}/message_store.js +0 -0
- /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
- /package/dest/{archiver/structs → structs}/inbox_message.js +0 -0
- /package/dest/{archiver/structs → structs}/published.js +0 -0
- /package/src/{archiver/l1 → l1}/debug_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/trace_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/types.ts +0 -0
- /package/src/{archiver/kv_archiver_store → store}/message_store.ts +0 -0
- /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
- /package/src/{archiver/structs → structs}/inbox_message.ts +0 -0
- /package/src/{archiver/structs → structs}/published.ts +0 -0
|
@@ -0,0 +1,511 @@
|
|
|
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 { Logger } from '@aztec/foundation/log';
|
|
7
|
+
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
8
|
+
import { CommitteeAttestation } from '@aztec/stdlib/block';
|
|
9
|
+
import { ConsensusPayload, SignatureDomainSeparator } from '@aztec/stdlib/p2p';
|
|
10
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
type AbiParameter,
|
|
14
|
+
type Hex,
|
|
15
|
+
type Transaction,
|
|
16
|
+
decodeFunctionData,
|
|
17
|
+
encodeAbiParameters,
|
|
18
|
+
hexToBytes,
|
|
19
|
+
keccak256,
|
|
20
|
+
multicall3Abi,
|
|
21
|
+
toFunctionSelector,
|
|
22
|
+
} from 'viem';
|
|
23
|
+
|
|
24
|
+
import type { ArchiverInstrumentation } from '../modules/instrumentation.js';
|
|
25
|
+
import { getSuccessfulCallsFromDebug } from './debug_tx.js';
|
|
26
|
+
import { getCallsFromSpireProposer } from './spire_proposer.js';
|
|
27
|
+
import { getSuccessfulCallsFromTrace } from './trace_tx.js';
|
|
28
|
+
import type { CallInfo } from './types.js';
|
|
29
|
+
|
|
30
|
+
/** Decoded checkpoint data from a propose calldata. */
|
|
31
|
+
type CheckpointData = {
|
|
32
|
+
checkpointNumber: CheckpointNumber;
|
|
33
|
+
archiveRoot: Fr;
|
|
34
|
+
header: CheckpointHeader;
|
|
35
|
+
attestations: CommitteeAttestation[];
|
|
36
|
+
blockHash: string;
|
|
37
|
+
feeAssetPriceModifier: bigint;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Extracts calldata to the `propose` method of the rollup contract from an L1 transaction
|
|
42
|
+
* in order to reconstruct an L2 block header. Uses hash matching against expected hashes
|
|
43
|
+
* from the CheckpointProposed event to verify the correct propose calldata.
|
|
44
|
+
*/
|
|
45
|
+
export class CalldataRetriever {
|
|
46
|
+
/** Tx hashes we've already logged for trace+debug failure (log once per tx per process). */
|
|
47
|
+
private static readonly traceFailureWarnedTxHashes = new Set<string>();
|
|
48
|
+
|
|
49
|
+
/** Clears the trace-failure warned set. For testing only. */
|
|
50
|
+
static resetTraceFailureWarnedForTesting(): void {
|
|
51
|
+
CalldataRetriever.traceFailureWarnedTxHashes.clear();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
constructor(
|
|
55
|
+
private readonly publicClient: ViemPublicClient,
|
|
56
|
+
private readonly debugClient: ViemPublicDebugClient,
|
|
57
|
+
private readonly targetCommitteeSize: number,
|
|
58
|
+
private readonly instrumentation: ArchiverInstrumentation | undefined,
|
|
59
|
+
private readonly logger: Logger,
|
|
60
|
+
private readonly rollupAddress: EthAddress,
|
|
61
|
+
) {}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Gets checkpoint header and metadata from the calldata of an L1 transaction.
|
|
65
|
+
* Tries multicall3 decoding, falls back to trace-based extraction.
|
|
66
|
+
* @param txHash - Hash of the tx that published it.
|
|
67
|
+
* @param blobHashes - Blob hashes for the checkpoint.
|
|
68
|
+
* @param checkpointNumber - Checkpoint number.
|
|
69
|
+
* @param expectedHashes - Expected hashes from the CheckpointProposed event for validation
|
|
70
|
+
* @returns Checkpoint header and metadata from the calldata, deserialized
|
|
71
|
+
*/
|
|
72
|
+
async getCheckpointFromRollupTx(
|
|
73
|
+
txHash: `0x${string}`,
|
|
74
|
+
_blobHashes: Buffer[],
|
|
75
|
+
checkpointNumber: CheckpointNumber,
|
|
76
|
+
expectedHashes: {
|
|
77
|
+
attestationsHash: Hex;
|
|
78
|
+
payloadDigest: Hex;
|
|
79
|
+
},
|
|
80
|
+
): Promise<CheckpointData> {
|
|
81
|
+
this.logger.trace(`Fetching checkpoint ${checkpointNumber} from rollup tx ${txHash}`);
|
|
82
|
+
const tx = await this.publicClient.getTransaction({ hash: txHash });
|
|
83
|
+
return this.getCheckpointFromTx(tx, checkpointNumber, expectedHashes);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Gets checkpoint data from a transaction by trying decode strategies then falling back to trace. */
|
|
87
|
+
protected async getCheckpointFromTx(
|
|
88
|
+
tx: Transaction,
|
|
89
|
+
checkpointNumber: CheckpointNumber,
|
|
90
|
+
expectedHashes: { attestationsHash: Hex; payloadDigest: Hex },
|
|
91
|
+
): Promise<CheckpointData> {
|
|
92
|
+
// Try to decode as multicall3 with hash-verified matching
|
|
93
|
+
const multicall3Result = this.tryDecodeMulticall3(tx, expectedHashes, checkpointNumber, tx.blockHash!);
|
|
94
|
+
if (multicall3Result) {
|
|
95
|
+
this.logger.trace(`Decoded propose calldata from multicall3 for tx ${tx.hash}`);
|
|
96
|
+
this.instrumentation?.recordBlockProposalTxTarget(tx.to!, false);
|
|
97
|
+
return multicall3Result;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Try to decode as direct propose call
|
|
101
|
+
const directResult = this.tryDecodeDirectPropose(tx, expectedHashes, checkpointNumber, tx.blockHash!);
|
|
102
|
+
if (directResult) {
|
|
103
|
+
this.logger.trace(`Decoded propose calldata from direct call for tx ${tx.hash}`);
|
|
104
|
+
this.instrumentation?.recordBlockProposalTxTarget(tx.to!, false);
|
|
105
|
+
return directResult;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Try to decode as Spire Proposer multicall wrapper
|
|
109
|
+
const spireResult = await this.tryDecodeSpireProposer(tx, expectedHashes, checkpointNumber, tx.blockHash!);
|
|
110
|
+
if (spireResult) {
|
|
111
|
+
this.logger.trace(`Decoded propose calldata from Spire Proposer for tx ${tx.hash}`);
|
|
112
|
+
this.instrumentation?.recordBlockProposalTxTarget(tx.to!, false);
|
|
113
|
+
return spireResult;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Fall back to trace-based extraction
|
|
117
|
+
this.logger.warn(
|
|
118
|
+
`Failed to decode multicall3, direct propose, or Spire proposer for L1 tx ${tx.hash}, falling back to trace for checkpoint ${checkpointNumber}`,
|
|
119
|
+
);
|
|
120
|
+
this.instrumentation?.recordBlockProposalTxTarget(tx.to ?? EthAddress.ZERO.toString(), true);
|
|
121
|
+
const tracedCalldata = await this.extractCalldataViaTrace(tx.hash);
|
|
122
|
+
const tracedResult = this.tryDecodeAndVerifyPropose(
|
|
123
|
+
tracedCalldata,
|
|
124
|
+
expectedHashes,
|
|
125
|
+
checkpointNumber,
|
|
126
|
+
tx.blockHash!,
|
|
127
|
+
);
|
|
128
|
+
if (!tracedResult) {
|
|
129
|
+
throw new Error(`Hash mismatch for traced propose calldata in tx ${tx.hash} for checkpoint ${checkpointNumber}`);
|
|
130
|
+
}
|
|
131
|
+
return tracedResult;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Attempts to decode a transaction as a Spire Proposer multicall wrapper.
|
|
136
|
+
* If successful, iterates all wrapped calls and validates each as either multicall3
|
|
137
|
+
* or direct propose, verifying against expected hashes.
|
|
138
|
+
* @param tx - The transaction to decode
|
|
139
|
+
* @param expectedHashes - Expected hashes for hash-verified matching
|
|
140
|
+
* @param checkpointNumber - The checkpoint number
|
|
141
|
+
* @param blockHash - The L1 block hash
|
|
142
|
+
* @returns The checkpoint data if successfully decoded and validated, undefined otherwise
|
|
143
|
+
*/
|
|
144
|
+
protected async tryDecodeSpireProposer(
|
|
145
|
+
tx: Transaction,
|
|
146
|
+
expectedHashes: { attestationsHash: Hex; payloadDigest: Hex },
|
|
147
|
+
checkpointNumber: CheckpointNumber,
|
|
148
|
+
blockHash: Hex,
|
|
149
|
+
): Promise<CheckpointData | undefined> {
|
|
150
|
+
// Try to decode as Spire Proposer multicall (extracts all wrapped calls)
|
|
151
|
+
const spireWrappedCalls = await getCallsFromSpireProposer(tx, this.publicClient, this.logger);
|
|
152
|
+
if (!spireWrappedCalls) {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
this.logger.trace(`Decoded Spire Proposer wrapping for tx ${tx.hash}, ${spireWrappedCalls.length} inner call(s)`);
|
|
157
|
+
|
|
158
|
+
// Try each wrapped call as either multicall3 or direct propose
|
|
159
|
+
for (const spireWrappedCall of spireWrappedCalls) {
|
|
160
|
+
const wrappedTx = { to: spireWrappedCall.to, input: spireWrappedCall.data, hash: tx.hash };
|
|
161
|
+
|
|
162
|
+
const multicall3Result = this.tryDecodeMulticall3(wrappedTx, expectedHashes, checkpointNumber, blockHash);
|
|
163
|
+
if (multicall3Result) {
|
|
164
|
+
this.logger.trace(`Decoded propose calldata from Spire Proposer to multicall3 for tx ${tx.hash}`);
|
|
165
|
+
return multicall3Result;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const directResult = this.tryDecodeDirectPropose(wrappedTx, expectedHashes, checkpointNumber, blockHash);
|
|
169
|
+
if (directResult) {
|
|
170
|
+
this.logger.trace(`Decoded propose calldata from Spire Proposer to direct propose for tx ${tx.hash}`);
|
|
171
|
+
return directResult;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
this.logger.warn(
|
|
176
|
+
`Spire Proposer wrapped calls could not be decoded as multicall3 or direct propose for tx ${tx.hash}`,
|
|
177
|
+
);
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Attempts to decode transaction input as multicall3 and extract propose calldata.
|
|
183
|
+
* Finds all calls matching the rollup address and propose selector, then decodes
|
|
184
|
+
* and verifies each candidate against expected hashes from the CheckpointProposed event.
|
|
185
|
+
* @param tx - The transaction-like object with to, input, and hash
|
|
186
|
+
* @param expectedHashes - Expected hashes from CheckpointProposed event
|
|
187
|
+
* @param checkpointNumber - The checkpoint number
|
|
188
|
+
* @param blockHash - The L1 block hash
|
|
189
|
+
* @returns The checkpoint data if successfully validated, undefined otherwise
|
|
190
|
+
*/
|
|
191
|
+
protected tryDecodeMulticall3(
|
|
192
|
+
tx: { to: Hex | null | undefined; input: Hex; hash: Hex },
|
|
193
|
+
expectedHashes: { attestationsHash: Hex; payloadDigest: Hex },
|
|
194
|
+
checkpointNumber: CheckpointNumber,
|
|
195
|
+
blockHash: Hex,
|
|
196
|
+
): CheckpointData | undefined {
|
|
197
|
+
const txHash = tx.hash;
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
// Check if transaction is to Multicall3 address
|
|
201
|
+
if (!tx.to || !EthAddress.areEqual(tx.to, MULTI_CALL_3_ADDRESS)) {
|
|
202
|
+
this.logger.debug(`Transaction is not to Multicall3 address (to: ${tx.to})`, { txHash, to: tx.to });
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Try to decode as multicall3 aggregate3 call
|
|
207
|
+
const { functionName: multicall3Fn, args: multicall3Args } = decodeFunctionData({
|
|
208
|
+
abi: multicall3Abi,
|
|
209
|
+
data: tx.input,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// If not aggregate3, return undefined (not a multicall3 transaction)
|
|
213
|
+
if (multicall3Fn !== 'aggregate3') {
|
|
214
|
+
this.logger.warn(`Transaction is not multicall3 aggregate3 (got ${multicall3Fn})`, { txHash });
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (multicall3Args.length !== 1) {
|
|
219
|
+
this.logger.warn(`Unexpected number of arguments for multicall3 (got ${multicall3Args.length})`, { txHash });
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const [calls] = multicall3Args;
|
|
224
|
+
|
|
225
|
+
// Find all calls matching rollup address + propose selector
|
|
226
|
+
const rollupAddressLower = this.rollupAddress.toString().toLowerCase();
|
|
227
|
+
const proposeSelectorLower = PROPOSE_SELECTOR.toLowerCase();
|
|
228
|
+
const candidates: Hex[] = [];
|
|
229
|
+
|
|
230
|
+
for (const call of calls) {
|
|
231
|
+
const addr = call.target.toLowerCase();
|
|
232
|
+
const callData = call.callData;
|
|
233
|
+
|
|
234
|
+
if (callData.length < 10) {
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const selector = callData.slice(0, 10).toLowerCase();
|
|
239
|
+
if (addr === rollupAddressLower && selector === proposeSelectorLower) {
|
|
240
|
+
candidates.push(callData);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (candidates.length === 0) {
|
|
245
|
+
this.logger.debug(`No propose candidates found in multicall3`, { txHash });
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Decode, verify, and build for each candidate
|
|
250
|
+
const verified: CheckpointData[] = [];
|
|
251
|
+
for (const candidate of candidates) {
|
|
252
|
+
const result = this.tryDecodeAndVerifyPropose(candidate, expectedHashes, checkpointNumber, blockHash);
|
|
253
|
+
if (result) {
|
|
254
|
+
verified.push(result);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (verified.length === 1) {
|
|
259
|
+
this.logger.trace(`Verified single propose candidate via hash matching`, { txHash });
|
|
260
|
+
return verified[0];
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (verified.length > 1) {
|
|
264
|
+
this.logger.warn(
|
|
265
|
+
`Multiple propose candidates verified (${verified.length}), returning first (identical data)`,
|
|
266
|
+
{ txHash },
|
|
267
|
+
);
|
|
268
|
+
return verified[0];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
this.logger.debug(`No candidates verified against expected hashes`, { txHash });
|
|
272
|
+
return undefined;
|
|
273
|
+
} catch (err) {
|
|
274
|
+
// Any decoding error triggers fallback to trace
|
|
275
|
+
this.logger.warn(`Failed to decode multicall3: ${err}`, { txHash });
|
|
276
|
+
return undefined;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Attempts to decode transaction as a direct propose call to the rollup contract.
|
|
282
|
+
* Decodes, verifies hashes, and builds checkpoint data in a single pass.
|
|
283
|
+
* @param tx - The transaction-like object with to, input, and hash
|
|
284
|
+
* @param expectedHashes - Expected hashes from CheckpointProposed event
|
|
285
|
+
* @param checkpointNumber - The checkpoint number
|
|
286
|
+
* @param blockHash - The L1 block hash
|
|
287
|
+
* @returns The checkpoint data if successfully validated, undefined otherwise
|
|
288
|
+
*/
|
|
289
|
+
protected tryDecodeDirectPropose(
|
|
290
|
+
tx: { to: Hex | null | undefined; input: Hex; hash: Hex },
|
|
291
|
+
expectedHashes: { attestationsHash: Hex; payloadDigest: Hex },
|
|
292
|
+
checkpointNumber: CheckpointNumber,
|
|
293
|
+
blockHash: Hex,
|
|
294
|
+
): CheckpointData | undefined {
|
|
295
|
+
const txHash = tx.hash;
|
|
296
|
+
try {
|
|
297
|
+
// Check if transaction is to the rollup address
|
|
298
|
+
if (!tx.to || !EthAddress.areEqual(tx.to, this.rollupAddress)) {
|
|
299
|
+
this.logger.debug(`Transaction is not to rollup address (to: ${tx.to})`, { txHash });
|
|
300
|
+
return undefined;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Validate it's a propose call before full decode+verify
|
|
304
|
+
const { functionName } = decodeFunctionData({ abi: RollupAbi, data: tx.input });
|
|
305
|
+
if (functionName !== 'propose') {
|
|
306
|
+
this.logger.warn(`Transaction to rollup is not propose (got ${functionName})`, { txHash });
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Decode, verify hashes, and build checkpoint data
|
|
311
|
+
this.logger.trace(`Validated direct propose call to rollup`, { txHash });
|
|
312
|
+
return this.tryDecodeAndVerifyPropose(tx.input, expectedHashes, checkpointNumber, blockHash);
|
|
313
|
+
} catch (err) {
|
|
314
|
+
// Any decoding error means it's not a valid propose call
|
|
315
|
+
this.logger.warn(`Failed to decode as direct propose: ${err}`, { txHash });
|
|
316
|
+
return undefined;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Uses debug/trace RPC to extract the actual calldata from the successful propose call.
|
|
322
|
+
* This is the definitive fallback that works for any transaction pattern.
|
|
323
|
+
* Tries trace_transaction first, then falls back to debug_traceTransaction.
|
|
324
|
+
* @param txHash - The transaction hash to trace
|
|
325
|
+
* @returns The propose calldata from the successful call
|
|
326
|
+
*/
|
|
327
|
+
protected async extractCalldataViaTrace(txHash: Hex): Promise<Hex> {
|
|
328
|
+
const rollupAddress = this.rollupAddress;
|
|
329
|
+
const selector = PROPOSE_SELECTOR;
|
|
330
|
+
|
|
331
|
+
let calls: CallInfo[];
|
|
332
|
+
try {
|
|
333
|
+
// Try trace_transaction first (using Parity/OpenEthereum/Erigon RPC)
|
|
334
|
+
this.logger.debug(`Attempting to trace transaction ${txHash} using trace_transaction`);
|
|
335
|
+
calls = await getSuccessfulCallsFromTrace(this.debugClient, txHash, rollupAddress, selector, this.logger);
|
|
336
|
+
this.logger.debug(`Successfully traced using trace_transaction, found ${calls.length} calls`);
|
|
337
|
+
} catch (err) {
|
|
338
|
+
const traceError = err instanceof Error ? err : new Error(String(err));
|
|
339
|
+
this.logger.verbose(`Failed trace_transaction for ${txHash}: ${traceError.message}`);
|
|
340
|
+
this.logger.debug(`Trace failure details for ${txHash}`, { traceError });
|
|
341
|
+
|
|
342
|
+
try {
|
|
343
|
+
// Fall back to debug_traceTransaction (Geth RPC)
|
|
344
|
+
this.logger.debug(`Attempting to trace transaction ${txHash} using debug_traceTransaction`);
|
|
345
|
+
calls = await getSuccessfulCallsFromDebug(this.debugClient, txHash, rollupAddress, selector, this.logger);
|
|
346
|
+
this.logger.debug(`Successfully traced using debug_traceTransaction, found ${calls.length} calls`);
|
|
347
|
+
} catch (debugErr) {
|
|
348
|
+
const debugError = debugErr instanceof Error ? debugErr : new Error(String(debugErr));
|
|
349
|
+
// Log once per tx so we don't spam on every sync cycle when sync point doesn't advance
|
|
350
|
+
if (!CalldataRetriever.traceFailureWarnedTxHashes.has(txHash)) {
|
|
351
|
+
CalldataRetriever.traceFailureWarnedTxHashes.add(txHash);
|
|
352
|
+
this.logger.warn(
|
|
353
|
+
`Cannot decode L1 tx ${txHash}: trace and debug RPC failed or unavailable. ` +
|
|
354
|
+
`trace_transaction: ${traceError.message}; debug_traceTransaction: ${debugError.message}`,
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
// Full error objects can be very long; keep at debug only
|
|
358
|
+
this.logger.debug(`Trace/debug failure details for tx ${txHash}`, {
|
|
359
|
+
traceError,
|
|
360
|
+
debugError,
|
|
361
|
+
txHash,
|
|
362
|
+
});
|
|
363
|
+
throw new Error(`Failed to trace transaction ${txHash} to extract propose calldata`);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// Validate exactly ONE successful propose call
|
|
368
|
+
if (calls.length === 0) {
|
|
369
|
+
throw new Error(`No successful propose calls found in transaction ${txHash}`);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (calls.length > 1) {
|
|
373
|
+
throw new Error(`Multiple successful propose calls found in transaction ${txHash} (${calls.length})`);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Return the calldata from the single successful propose call
|
|
377
|
+
return calls[0].input;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Decodes propose calldata, verifies against expected hashes, and builds checkpoint data.
|
|
382
|
+
* Returns undefined on decode errors or hash mismatches (soft failure for try-based callers).
|
|
383
|
+
* @param proposeCalldata - The propose function calldata
|
|
384
|
+
* @param expectedHashes - Expected hashes from the CheckpointProposed event
|
|
385
|
+
* @param checkpointNumber - The checkpoint number
|
|
386
|
+
* @param blockHash - The L1 block hash
|
|
387
|
+
* @returns The decoded checkpoint data, or undefined on failure
|
|
388
|
+
*/
|
|
389
|
+
protected tryDecodeAndVerifyPropose(
|
|
390
|
+
proposeCalldata: Hex,
|
|
391
|
+
expectedHashes: { attestationsHash: Hex; payloadDigest: Hex },
|
|
392
|
+
checkpointNumber: CheckpointNumber,
|
|
393
|
+
blockHash: Hex,
|
|
394
|
+
): CheckpointData | undefined {
|
|
395
|
+
try {
|
|
396
|
+
const { functionName, args } = decodeFunctionData({ abi: RollupAbi, data: proposeCalldata });
|
|
397
|
+
if (functionName !== 'propose') {
|
|
398
|
+
return undefined;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const [decodedArgs, packedAttestations] = args! as readonly [
|
|
402
|
+
{ archive: Hex; oracleInput: { feeAssetPriceModifier: bigint }; header: ViemHeader },
|
|
403
|
+
ViemCommitteeAttestations,
|
|
404
|
+
...unknown[],
|
|
405
|
+
];
|
|
406
|
+
|
|
407
|
+
// Verify attestationsHash
|
|
408
|
+
const computedAttestationsHash = this.computeAttestationsHash(packedAttestations);
|
|
409
|
+
if (
|
|
410
|
+
!Buffer.from(hexToBytes(computedAttestationsHash)).equals(
|
|
411
|
+
Buffer.from(hexToBytes(expectedHashes.attestationsHash)),
|
|
412
|
+
)
|
|
413
|
+
) {
|
|
414
|
+
this.logger.warn(`Attestations hash mismatch during verification`, {
|
|
415
|
+
computed: computedAttestationsHash,
|
|
416
|
+
expected: expectedHashes.attestationsHash,
|
|
417
|
+
});
|
|
418
|
+
return undefined;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// Verify payloadDigest
|
|
422
|
+
const header = CheckpointHeader.fromViem(decodedArgs.header);
|
|
423
|
+
const archiveRoot = new Fr(Buffer.from(hexToBytes(decodedArgs.archive)));
|
|
424
|
+
const feeAssetPriceModifier = decodedArgs.oracleInput.feeAssetPriceModifier;
|
|
425
|
+
const computedPayloadDigest = this.computePayloadDigest(header, archiveRoot, feeAssetPriceModifier);
|
|
426
|
+
if (
|
|
427
|
+
!Buffer.from(hexToBytes(computedPayloadDigest)).equals(Buffer.from(hexToBytes(expectedHashes.payloadDigest)))
|
|
428
|
+
) {
|
|
429
|
+
this.logger.warn(`Payload digest mismatch during verification`, {
|
|
430
|
+
computed: computedPayloadDigest,
|
|
431
|
+
expected: expectedHashes.payloadDigest,
|
|
432
|
+
});
|
|
433
|
+
return undefined;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const attestations = CommitteeAttestation.fromPacked(packedAttestations, this.targetCommitteeSize);
|
|
437
|
+
|
|
438
|
+
this.logger.trace(`Validated and decoded propose calldata for checkpoint ${checkpointNumber}`, {
|
|
439
|
+
checkpointNumber,
|
|
440
|
+
archive: decodedArgs.archive,
|
|
441
|
+
header: decodedArgs.header,
|
|
442
|
+
l1BlockHash: blockHash,
|
|
443
|
+
attestations,
|
|
444
|
+
packedAttestations,
|
|
445
|
+
targetCommitteeSize: this.targetCommitteeSize,
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
return {
|
|
449
|
+
checkpointNumber,
|
|
450
|
+
archiveRoot,
|
|
451
|
+
header,
|
|
452
|
+
attestations,
|
|
453
|
+
blockHash,
|
|
454
|
+
feeAssetPriceModifier,
|
|
455
|
+
};
|
|
456
|
+
} catch {
|
|
457
|
+
return undefined;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/** Computes the keccak256 hash of ABI-encoded CommitteeAttestations. */
|
|
462
|
+
private computeAttestationsHash(packedAttestations: ViemCommitteeAttestations): Hex {
|
|
463
|
+
return keccak256(encodeAbiParameters([this.getCommitteeAttestationsStructDef()], [packedAttestations]));
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/** Computes the keccak256 payload digest from the checkpoint header, archive root, and fee asset price modifier. */
|
|
467
|
+
private computePayloadDigest(header: CheckpointHeader, archiveRoot: Fr, feeAssetPriceModifier: bigint): Hex {
|
|
468
|
+
const consensusPayload = new ConsensusPayload(header, archiveRoot, feeAssetPriceModifier);
|
|
469
|
+
const payloadToSign = consensusPayload.getPayloadToSign(SignatureDomainSeparator.checkpointAttestation);
|
|
470
|
+
return keccak256(payloadToSign);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Extracts the CommitteeAttestations struct definition from RollupAbi.
|
|
475
|
+
* Finds the _attestations parameter by name in the propose function.
|
|
476
|
+
*/
|
|
477
|
+
private getCommitteeAttestationsStructDef(): AbiParameter {
|
|
478
|
+
const proposeFunction = RollupAbi.find(item => item.type === 'function' && item.name === 'propose') as
|
|
479
|
+
| { type: 'function'; name: string; inputs: readonly AbiParameter[] }
|
|
480
|
+
| undefined;
|
|
481
|
+
|
|
482
|
+
if (!proposeFunction) {
|
|
483
|
+
throw new Error('propose function not found in RollupAbi');
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// Find the _attestations parameter by name, not by index
|
|
487
|
+
const attestationsParam = proposeFunction.inputs.find(param => param.name === '_attestations');
|
|
488
|
+
|
|
489
|
+
if (!attestationsParam) {
|
|
490
|
+
throw new Error('_attestations parameter not found in propose function');
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
if (attestationsParam.type !== 'tuple') {
|
|
494
|
+
throw new Error(`Expected _attestations parameter to be a tuple, got ${attestationsParam.type}`);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// Extract the tuple components (struct fields)
|
|
498
|
+
const tupleParam = attestationsParam as unknown as {
|
|
499
|
+
type: 'tuple';
|
|
500
|
+
components?: readonly AbiParameter[];
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
return {
|
|
504
|
+
type: 'tuple',
|
|
505
|
+
components: tupleParam.components || [],
|
|
506
|
+
} as AbiParameter;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/** Function selector for the `propose` method of the rollup contract. */
|
|
511
|
+
const PROPOSE_SELECTOR = toFunctionSelector(RollupAbi.find(x => x.type === 'function' && x.name === 'propose')!);
|