@aztec/archiver 0.0.1-commit.e558bd1c → 0.0.1-commit.e5a3663dd
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 +12 -6
- package/dest/archiver.d.ts +26 -15
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +161 -153
- package/dest/config.d.ts +5 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -4
- package/dest/errors.d.ts +61 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +88 -14
- package/dest/factory.d.ts +6 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +40 -32
- package/dest/index.d.ts +11 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +10 -2
- package/dest/l1/bin/retrieve-calldata.js +32 -28
- package/dest/l1/calldata_retriever.d.ts +74 -50
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +197 -260
- package/dest/l1/data_retrieval.d.ts +26 -17
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +42 -47
- package/dest/l1/spire_proposer.d.ts +5 -5
- package/dest/l1/spire_proposer.d.ts.map +1 -1
- package/dest/l1/spire_proposer.js +9 -17
- package/dest/l1/validate_historical_logs.d.ts +23 -0
- package/dest/l1/validate_historical_logs.d.ts.map +1 -0
- package/dest/l1/validate_historical_logs.js +108 -0
- package/dest/modules/contract_data_source_adapter.d.ts +25 -0
- package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
- package/dest/modules/contract_data_source_adapter.js +42 -0
- package/dest/modules/data_source_base.d.ts +27 -14
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +98 -125
- package/dest/modules/data_store_updater.d.ts +37 -17
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +155 -112
- package/dest/modules/instrumentation.d.ts +21 -3
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +41 -8
- package/dest/modules/l1_synchronizer.d.ts +13 -11
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +355 -182
- package/dest/modules/validation.d.ts +4 -3
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +6 -6
- package/dest/store/block_store.d.ts +107 -31
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +477 -141
- package/dest/store/contract_class_store.d.ts +17 -4
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +24 -68
- package/dest/store/contract_instance_store.d.ts +28 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +37 -2
- package/dest/store/data_stores.d.ts +68 -0
- package/dest/store/data_stores.d.ts.map +1 -0
- package/dest/store/data_stores.js +50 -0
- package/dest/store/function_names_cache.d.ts +17 -0
- package/dest/store/function_names_cache.d.ts.map +1 -0
- package/dest/store/function_names_cache.js +30 -0
- package/dest/store/l2_tips_cache.d.ts +20 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +109 -0
- package/dest/store/log_store.d.ts +6 -3
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +95 -20
- package/dest/store/message_store.d.ts +11 -1
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +51 -9
- package/dest/test/fake_l1_state.d.ts +25 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +166 -32
- package/dest/test/mock_archiver.d.ts +1 -1
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -2
- package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +2 -1
- package/dest/test/mock_l2_block_source.d.ts +35 -5
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +182 -89
- package/dest/test/mock_structs.d.ts +4 -1
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +13 -1
- package/dest/test/noop_l1_archiver.d.ts +7 -4
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +14 -8
- package/package.json +13 -13
- package/src/archiver.ts +199 -174
- package/src/config.ts +23 -2
- package/src/errors.ts +133 -22
- package/src/factory.ts +53 -30
- package/src/index.ts +18 -2
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +40 -27
- package/src/l1/calldata_retriever.ts +261 -379
- package/src/l1/data_retrieval.ts +58 -69
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/modules/contract_data_source_adapter.ts +59 -0
- package/src/modules/data_source_base.ts +142 -144
- package/src/modules/data_store_updater.ts +187 -141
- package/src/modules/instrumentation.ts +56 -9
- package/src/modules/l1_synchronizer.ts +463 -218
- package/src/modules/validation.ts +10 -9
- package/src/store/block_store.ts +587 -177
- package/src/store/contract_class_store.ts +31 -103
- package/src/store/contract_instance_store.ts +51 -5
- package/src/store/data_stores.ts +108 -0
- package/src/store/function_names_cache.ts +37 -0
- package/src/store/l2_tips_cache.ts +134 -0
- package/src/store/log_store.ts +128 -32
- package/src/store/message_store.ts +60 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +213 -42
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +230 -82
- package/src/test/mock_structs.ts +20 -6
- package/src/test/noop_l1_archiver.ts +16 -8
- package/dest/store/kv_archiver_store.d.ts +0 -340
- package/dest/store/kv_archiver_store.d.ts.map +0 -1
- package/dest/store/kv_archiver_store.js +0 -446
- package/src/store/kv_archiver_store.ts +0 -639
|
@@ -1,33 +1,43 @@
|
|
|
1
1
|
import { MULTI_CALL_3_ADDRESS } from '@aztec/ethereum/contracts';
|
|
2
|
+
import { LruSet } from '@aztec/foundation/collection';
|
|
2
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
-
import {
|
|
5
|
+
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
5
6
|
import { CommitteeAttestation } from '@aztec/stdlib/block';
|
|
6
|
-
import { ConsensusPayload,
|
|
7
|
+
import { ConsensusPayload, getHashedSignaturePayloadTypedData } from '@aztec/stdlib/p2p';
|
|
7
8
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
8
9
|
import { decodeFunctionData, encodeAbiParameters, hexToBytes, keccak256, multicall3Abi, toFunctionSelector } from 'viem';
|
|
9
10
|
import { getSuccessfulCallsFromDebug } from './debug_tx.js';
|
|
10
|
-
import {
|
|
11
|
+
import { getCallsFromSpireProposer } from './spire_proposer.js';
|
|
11
12
|
import { getSuccessfulCallsFromTrace } from './trace_tx.js';
|
|
12
13
|
/**
|
|
13
14
|
* Extracts calldata to the `propose` method of the rollup contract from an L1 transaction
|
|
14
|
-
* in order to reconstruct an L2 block header.
|
|
15
|
+
* in order to reconstruct an L2 block header. Uses hash matching against expected hashes
|
|
16
|
+
* from the CheckpointProposed event to verify the correct propose calldata.
|
|
15
17
|
*/ export class CalldataRetriever {
|
|
16
18
|
publicClient;
|
|
17
19
|
debugClient;
|
|
18
20
|
targetCommitteeSize;
|
|
19
21
|
instrumentation;
|
|
20
22
|
logger;
|
|
21
|
-
/** Pre-computed valid contract calls for validation */ validContractCalls;
|
|
22
23
|
rollupAddress;
|
|
23
|
-
|
|
24
|
+
/** Tx hashes we've already logged for trace+debug failure (log once per tx per process). */ static traceFailureWarnedTxHashes = new LruSet(1000);
|
|
25
|
+
/** Clears the trace-failure warned set. For testing only. */ static resetTraceFailureWarnedForTesting() {
|
|
26
|
+
CalldataRetriever.traceFailureWarnedTxHashes.clear();
|
|
27
|
+
}
|
|
28
|
+
constructor(publicClient, debugClient, targetCommitteeSize, instrumentation, logger, rollupAddress){
|
|
24
29
|
this.publicClient = publicClient;
|
|
25
30
|
this.debugClient = debugClient;
|
|
26
31
|
this.targetCommitteeSize = targetCommitteeSize;
|
|
27
32
|
this.instrumentation = instrumentation;
|
|
28
33
|
this.logger = logger;
|
|
29
|
-
this.rollupAddress =
|
|
30
|
-
|
|
34
|
+
this.rollupAddress = rollupAddress;
|
|
35
|
+
}
|
|
36
|
+
getSignatureContext() {
|
|
37
|
+
return {
|
|
38
|
+
chainId: this.publicClient.chain.id,
|
|
39
|
+
rollupAddress: this.rollupAddress
|
|
40
|
+
};
|
|
31
41
|
}
|
|
32
42
|
/**
|
|
33
43
|
* Gets checkpoint header and metadata from the calldata of an L1 transaction.
|
|
@@ -35,84 +45,94 @@ import { getSuccessfulCallsFromTrace } from './trace_tx.js';
|
|
|
35
45
|
* @param txHash - Hash of the tx that published it.
|
|
36
46
|
* @param blobHashes - Blob hashes for the checkpoint.
|
|
37
47
|
* @param checkpointNumber - Checkpoint number.
|
|
38
|
-
* @param expectedHashes -
|
|
48
|
+
* @param expectedHashes - Expected hashes from the CheckpointProposed event for validation
|
|
39
49
|
* @returns Checkpoint header and metadata from the calldata, deserialized
|
|
40
50
|
*/ 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
|
-
});
|
|
51
|
+
this.logger.trace(`Fetching checkpoint ${checkpointNumber} from rollup tx ${txHash}`);
|
|
46
52
|
const tx = await this.publicClient.getTransaction({
|
|
47
53
|
hash: txHash
|
|
48
54
|
});
|
|
49
|
-
|
|
50
|
-
return this.decodeAndBuildCheckpoint(proposeCalldata, tx.blockHash, checkpointNumber, expectedHashes);
|
|
55
|
+
return this.getCheckpointFromTx(tx, checkpointNumber, expectedHashes);
|
|
51
56
|
}
|
|
52
|
-
/** Gets
|
|
53
|
-
// Try to decode as multicall3 with
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
57
|
+
/** Gets checkpoint data from a transaction by trying decode strategies then falling back to trace. */ async getCheckpointFromTx(tx, checkpointNumber, expectedHashes) {
|
|
58
|
+
// Try to decode as multicall3 with hash-verified matching
|
|
59
|
+
const multicall3Result = this.tryDecodeMulticall3(tx, expectedHashes, checkpointNumber, tx.blockHash);
|
|
60
|
+
if (multicall3Result) {
|
|
56
61
|
this.logger.trace(`Decoded propose calldata from multicall3 for tx ${tx.hash}`);
|
|
57
62
|
this.instrumentation?.recordBlockProposalTxTarget(tx.to, false);
|
|
58
|
-
return
|
|
63
|
+
return multicall3Result;
|
|
59
64
|
}
|
|
60
65
|
// Try to decode as direct propose call
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
66
|
+
const directResult = this.tryDecodeDirectPropose(tx, expectedHashes, checkpointNumber, tx.blockHash);
|
|
67
|
+
if (directResult) {
|
|
63
68
|
this.logger.trace(`Decoded propose calldata from direct call for tx ${tx.hash}`);
|
|
64
69
|
this.instrumentation?.recordBlockProposalTxTarget(tx.to, false);
|
|
65
|
-
return
|
|
70
|
+
return directResult;
|
|
66
71
|
}
|
|
67
72
|
// Try to decode as Spire Proposer multicall wrapper
|
|
68
|
-
const
|
|
69
|
-
if (
|
|
73
|
+
const spireResult = await this.tryDecodeSpireProposer(tx, expectedHashes, checkpointNumber, tx.blockHash);
|
|
74
|
+
if (spireResult) {
|
|
70
75
|
this.logger.trace(`Decoded propose calldata from Spire Proposer for tx ${tx.hash}`);
|
|
71
76
|
this.instrumentation?.recordBlockProposalTxTarget(tx.to, false);
|
|
72
|
-
return
|
|
77
|
+
return spireResult;
|
|
73
78
|
}
|
|
74
79
|
// Fall back to trace-based extraction
|
|
75
80
|
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
81
|
this.instrumentation?.recordBlockProposalTxTarget(tx.to ?? EthAddress.ZERO.toString(), true);
|
|
77
|
-
|
|
82
|
+
const tracedCalldata = await this.extractCalldataViaTrace(tx.hash);
|
|
83
|
+
const tracedResult = this.tryDecodeAndVerifyPropose(tracedCalldata, expectedHashes, checkpointNumber, tx.blockHash);
|
|
84
|
+
if (!tracedResult) {
|
|
85
|
+
throw new Error(`Hash mismatch for traced propose calldata in tx ${tx.hash} for checkpoint ${checkpointNumber}`);
|
|
86
|
+
}
|
|
87
|
+
return tracedResult;
|
|
78
88
|
}
|
|
79
89
|
/**
|
|
80
90
|
* Attempts to decode a transaction as a Spire Proposer multicall wrapper.
|
|
81
|
-
* If successful,
|
|
91
|
+
* If successful, iterates all wrapped calls and validates each as either multicall3
|
|
92
|
+
* or direct propose, verifying against expected hashes.
|
|
82
93
|
* @param tx - The transaction to decode
|
|
83
|
-
* @
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
* @param expectedHashes - Expected hashes for hash-verified matching
|
|
95
|
+
* @param checkpointNumber - The checkpoint number
|
|
96
|
+
* @param blockHash - The L1 block hash
|
|
97
|
+
* @returns The checkpoint data if successfully decoded and validated, undefined otherwise
|
|
98
|
+
*/ async tryDecodeSpireProposer(tx, expectedHashes, checkpointNumber, blockHash) {
|
|
99
|
+
// Try to decode as Spire Proposer multicall (extracts all wrapped calls)
|
|
100
|
+
const spireWrappedCalls = await getCallsFromSpireProposer(tx, this.publicClient, this.logger);
|
|
101
|
+
if (!spireWrappedCalls) {
|
|
88
102
|
return undefined;
|
|
89
103
|
}
|
|
90
|
-
this.logger.trace(`Decoded Spire Proposer wrapping for tx ${tx.hash},
|
|
91
|
-
//
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
this.logger.trace(`Decoded Spire Proposer wrapping for tx ${tx.hash}, ${spireWrappedCalls.length} inner call(s)`);
|
|
105
|
+
// Try each wrapped call as either multicall3 or direct propose
|
|
106
|
+
for (const spireWrappedCall of spireWrappedCalls){
|
|
107
|
+
const wrappedTx = {
|
|
108
|
+
to: spireWrappedCall.to,
|
|
109
|
+
input: spireWrappedCall.data,
|
|
110
|
+
hash: tx.hash
|
|
111
|
+
};
|
|
112
|
+
const multicall3Result = this.tryDecodeMulticall3(wrappedTx, expectedHashes, checkpointNumber, blockHash);
|
|
113
|
+
if (multicall3Result) {
|
|
114
|
+
this.logger.trace(`Decoded propose calldata from Spire Proposer to multicall3 for tx ${tx.hash}`);
|
|
115
|
+
return multicall3Result;
|
|
116
|
+
}
|
|
117
|
+
const directResult = this.tryDecodeDirectPropose(wrappedTx, expectedHashes, checkpointNumber, blockHash);
|
|
118
|
+
if (directResult) {
|
|
119
|
+
this.logger.trace(`Decoded propose calldata from Spire Proposer to direct propose for tx ${tx.hash}`);
|
|
120
|
+
return directResult;
|
|
121
|
+
}
|
|
106
122
|
}
|
|
107
|
-
this.logger.warn(`Spire Proposer wrapped
|
|
123
|
+
this.logger.warn(`Spire Proposer wrapped calls could not be decoded as multicall3 or direct propose for tx ${tx.hash}`);
|
|
108
124
|
return undefined;
|
|
109
125
|
}
|
|
110
126
|
/**
|
|
111
127
|
* Attempts to decode transaction input as multicall3 and extract propose calldata.
|
|
112
|
-
*
|
|
128
|
+
* Finds all calls matching the rollup address and propose selector, then decodes
|
|
129
|
+
* and verifies each candidate against expected hashes from the CheckpointProposed event.
|
|
113
130
|
* @param tx - The transaction-like object with to, input, and hash
|
|
114
|
-
* @
|
|
115
|
-
|
|
131
|
+
* @param expectedHashes - Expected hashes from CheckpointProposed event
|
|
132
|
+
* @param checkpointNumber - The checkpoint number
|
|
133
|
+
* @param blockHash - The L1 block hash
|
|
134
|
+
* @returns The checkpoint data if successfully validated, undefined otherwise
|
|
135
|
+
*/ tryDecodeMulticall3(tx, expectedHashes, checkpointNumber, blockHash) {
|
|
116
136
|
const txHash = tx.hash;
|
|
117
137
|
try {
|
|
118
138
|
// Check if transaction is to Multicall3 address
|
|
@@ -142,59 +162,51 @@ import { getSuccessfulCallsFromTrace } from './trace_tx.js';
|
|
|
142
162
|
return undefined;
|
|
143
163
|
}
|
|
144
164
|
const [calls] = multicall3Args;
|
|
145
|
-
//
|
|
165
|
+
// Find all calls matching rollup address + propose selector
|
|
146
166
|
const rollupAddressLower = this.rollupAddress.toString().toLowerCase();
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
167
|
+
const proposeSelectorLower = PROPOSE_SELECTOR.toLowerCase();
|
|
168
|
+
const candidates = [];
|
|
169
|
+
for (const call of calls){
|
|
170
|
+
const addr = call.target.toLowerCase();
|
|
171
|
+
const callData = call.callData;
|
|
152
172
|
if (callData.length < 10) {
|
|
153
|
-
|
|
154
|
-
this.logger.warn(`Invalid calldata length at index ${i} (${callData.length})`, {
|
|
155
|
-
txHash
|
|
156
|
-
});
|
|
157
|
-
return undefined;
|
|
173
|
+
continue;
|
|
158
174
|
}
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
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;
|
|
175
|
+
const selector = callData.slice(0, 10).toLowerCase();
|
|
176
|
+
if (addr === rollupAddressLower && selector === proposeSelectorLower) {
|
|
177
|
+
candidates.push(callData);
|
|
174
178
|
}
|
|
175
|
-
|
|
176
|
-
|
|
179
|
+
}
|
|
180
|
+
if (candidates.length === 0) {
|
|
181
|
+
this.logger.debug(`No propose candidates found in multicall3`, {
|
|
182
|
+
txHash
|
|
177
183
|
});
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
// Decode, verify, and build for each candidate
|
|
187
|
+
const verified = [];
|
|
188
|
+
for (const candidate of candidates){
|
|
189
|
+
const result = this.tryDecodeAndVerifyPropose(candidate, expectedHashes, checkpointNumber, blockHash);
|
|
190
|
+
if (result) {
|
|
191
|
+
verified.push(result);
|
|
181
192
|
}
|
|
182
193
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
this.logger.warn(`No propose calls found in multicall3`, {
|
|
194
|
+
if (verified.length === 1) {
|
|
195
|
+
this.logger.trace(`Verified single propose candidate via hash matching`, {
|
|
186
196
|
txHash
|
|
187
197
|
});
|
|
188
|
-
return
|
|
198
|
+
return verified[0];
|
|
189
199
|
}
|
|
190
|
-
if (
|
|
191
|
-
this.logger.warn(`Multiple propose
|
|
200
|
+
if (verified.length > 1) {
|
|
201
|
+
this.logger.warn(`Multiple propose candidates verified (${verified.length}), returning first (identical data)`, {
|
|
192
202
|
txHash
|
|
193
203
|
});
|
|
194
|
-
return
|
|
204
|
+
return verified[0];
|
|
195
205
|
}
|
|
196
|
-
|
|
197
|
-
|
|
206
|
+
this.logger.debug(`No candidates verified against expected hashes`, {
|
|
207
|
+
txHash
|
|
208
|
+
});
|
|
209
|
+
return undefined;
|
|
198
210
|
} catch (err) {
|
|
199
211
|
// Any decoding error triggers fallback to trace
|
|
200
212
|
this.logger.warn(`Failed to decode multicall3: ${err}`, {
|
|
@@ -205,10 +217,13 @@ import { getSuccessfulCallsFromTrace } from './trace_tx.js';
|
|
|
205
217
|
}
|
|
206
218
|
/**
|
|
207
219
|
* Attempts to decode transaction as a direct propose call to the rollup contract.
|
|
208
|
-
*
|
|
220
|
+
* Decodes, verifies hashes, and builds checkpoint data in a single pass.
|
|
209
221
|
* @param tx - The transaction-like object with to, input, and hash
|
|
210
|
-
* @
|
|
211
|
-
|
|
222
|
+
* @param expectedHashes - Expected hashes from CheckpointProposed event
|
|
223
|
+
* @param checkpointNumber - The checkpoint number
|
|
224
|
+
* @param blockHash - The L1 block hash
|
|
225
|
+
* @returns The checkpoint data if successfully validated, undefined otherwise
|
|
226
|
+
*/ tryDecodeDirectPropose(tx, expectedHashes, checkpointNumber, blockHash) {
|
|
212
227
|
const txHash = tx.hash;
|
|
213
228
|
try {
|
|
214
229
|
// Check if transaction is to the rollup address
|
|
@@ -218,23 +233,22 @@ import { getSuccessfulCallsFromTrace } from './trace_tx.js';
|
|
|
218
233
|
});
|
|
219
234
|
return undefined;
|
|
220
235
|
}
|
|
221
|
-
//
|
|
236
|
+
// Validate it's a propose call before full decode+verify
|
|
222
237
|
const { functionName } = decodeFunctionData({
|
|
223
238
|
abi: RollupAbi,
|
|
224
239
|
data: tx.input
|
|
225
240
|
});
|
|
226
|
-
// If not propose, return undefined
|
|
227
241
|
if (functionName !== 'propose') {
|
|
228
242
|
this.logger.warn(`Transaction to rollup is not propose (got ${functionName})`, {
|
|
229
243
|
txHash
|
|
230
244
|
});
|
|
231
245
|
return undefined;
|
|
232
246
|
}
|
|
233
|
-
//
|
|
247
|
+
// Decode, verify hashes, and build checkpoint data
|
|
234
248
|
this.logger.trace(`Validated direct propose call to rollup`, {
|
|
235
249
|
txHash
|
|
236
250
|
});
|
|
237
|
-
return tx.input;
|
|
251
|
+
return this.tryDecodeAndVerifyPropose(tx.input, expectedHashes, checkpointNumber, blockHash);
|
|
238
252
|
} catch (err) {
|
|
239
253
|
// Any decoding error means it's not a valid propose call
|
|
240
254
|
this.logger.warn(`Failed to decode as direct propose: ${err}`, {
|
|
@@ -260,7 +274,8 @@ import { getSuccessfulCallsFromTrace } from './trace_tx.js';
|
|
|
260
274
|
this.logger.debug(`Successfully traced using trace_transaction, found ${calls.length} calls`);
|
|
261
275
|
} catch (err) {
|
|
262
276
|
const traceError = err instanceof Error ? err : new Error(String(err));
|
|
263
|
-
this.logger.verbose(`Failed trace_transaction for ${txHash}
|
|
277
|
+
this.logger.verbose(`Failed trace_transaction for ${txHash}: ${traceError.message}`);
|
|
278
|
+
this.logger.debug(`Trace failure details for ${txHash}`, {
|
|
264
279
|
traceError
|
|
265
280
|
});
|
|
266
281
|
try {
|
|
@@ -270,7 +285,13 @@ import { getSuccessfulCallsFromTrace } from './trace_tx.js';
|
|
|
270
285
|
this.logger.debug(`Successfully traced using debug_traceTransaction, found ${calls.length} calls`);
|
|
271
286
|
} catch (debugErr) {
|
|
272
287
|
const debugError = debugErr instanceof Error ? debugErr : new Error(String(debugErr));
|
|
273
|
-
|
|
288
|
+
// Log once per tx so we don't spam on every sync cycle when sync point doesn't advance
|
|
289
|
+
if (!CalldataRetriever.traceFailureWarnedTxHashes.has(txHash)) {
|
|
290
|
+
CalldataRetriever.traceFailureWarnedTxHashes.add(txHash);
|
|
291
|
+
this.logger.warn(`Cannot decode L1 tx ${txHash}: trace and debug RPC failed or unavailable. ` + `trace_transaction: ${traceError.message}; debug_traceTransaction: ${debugError.message}`);
|
|
292
|
+
}
|
|
293
|
+
// Full error objects can be very long; keep at debug only
|
|
294
|
+
this.logger.debug(`Trace/debug failure details for tx ${txHash}`, {
|
|
274
295
|
traceError,
|
|
275
296
|
debugError,
|
|
276
297
|
txHash
|
|
@@ -289,9 +310,80 @@ import { getSuccessfulCallsFromTrace } from './trace_tx.js';
|
|
|
289
310
|
return calls[0].input;
|
|
290
311
|
}
|
|
291
312
|
/**
|
|
313
|
+
* Decodes propose calldata, verifies against expected hashes, and builds checkpoint data.
|
|
314
|
+
* Returns undefined on decode errors or hash mismatches (soft failure for try-based callers).
|
|
315
|
+
* @param proposeCalldata - The propose function calldata
|
|
316
|
+
* @param expectedHashes - Expected hashes from the CheckpointProposed event
|
|
317
|
+
* @param checkpointNumber - The checkpoint number
|
|
318
|
+
* @param blockHash - The L1 block hash
|
|
319
|
+
* @returns The decoded checkpoint data, or undefined on failure
|
|
320
|
+
*/ tryDecodeAndVerifyPropose(proposeCalldata, expectedHashes, checkpointNumber, blockHash) {
|
|
321
|
+
try {
|
|
322
|
+
const { functionName, args } = decodeFunctionData({
|
|
323
|
+
abi: RollupAbi,
|
|
324
|
+
data: proposeCalldata
|
|
325
|
+
});
|
|
326
|
+
if (functionName !== 'propose') {
|
|
327
|
+
return undefined;
|
|
328
|
+
}
|
|
329
|
+
const [decodedArgs, packedAttestations] = args;
|
|
330
|
+
// Verify attestationsHash
|
|
331
|
+
const computedAttestationsHash = this.computeAttestationsHash(packedAttestations);
|
|
332
|
+
if (!Buffer.from(hexToBytes(computedAttestationsHash)).equals(Buffer.from(hexToBytes(expectedHashes.attestationsHash)))) {
|
|
333
|
+
this.logger.warn(`Attestations hash mismatch during verification`, {
|
|
334
|
+
computed: computedAttestationsHash,
|
|
335
|
+
expected: expectedHashes.attestationsHash
|
|
336
|
+
});
|
|
337
|
+
return undefined;
|
|
338
|
+
}
|
|
339
|
+
// Verify payloadDigest
|
|
340
|
+
const header = CheckpointHeader.fromViem(decodedArgs.header);
|
|
341
|
+
const archiveRoot = new Fr(Buffer.from(hexToBytes(decodedArgs.archive)));
|
|
342
|
+
const feeAssetPriceModifier = decodedArgs.oracleInput.feeAssetPriceModifier;
|
|
343
|
+
const computedPayloadDigest = this.computePayloadDigest(header, archiveRoot, feeAssetPriceModifier);
|
|
344
|
+
if (!Buffer.from(hexToBytes(computedPayloadDigest)).equals(Buffer.from(hexToBytes(expectedHashes.payloadDigest)))) {
|
|
345
|
+
this.logger.warn(`Payload digest mismatch during verification`, {
|
|
346
|
+
computed: computedPayloadDigest,
|
|
347
|
+
expected: expectedHashes.payloadDigest
|
|
348
|
+
});
|
|
349
|
+
return undefined;
|
|
350
|
+
}
|
|
351
|
+
const attestations = CommitteeAttestation.fromPacked(packedAttestations, this.targetCommitteeSize);
|
|
352
|
+
this.logger.trace(`Validated and decoded propose calldata for checkpoint ${checkpointNumber}`, {
|
|
353
|
+
checkpointNumber,
|
|
354
|
+
archive: decodedArgs.archive,
|
|
355
|
+
header: decodedArgs.header,
|
|
356
|
+
l1BlockHash: blockHash,
|
|
357
|
+
attestations,
|
|
358
|
+
packedAttestations,
|
|
359
|
+
targetCommitteeSize: this.targetCommitteeSize
|
|
360
|
+
});
|
|
361
|
+
return {
|
|
362
|
+
checkpointNumber,
|
|
363
|
+
archiveRoot,
|
|
364
|
+
header,
|
|
365
|
+
attestations,
|
|
366
|
+
blockHash,
|
|
367
|
+
feeAssetPriceModifier
|
|
368
|
+
};
|
|
369
|
+
} catch {
|
|
370
|
+
return undefined;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
/** Computes the keccak256 hash of ABI-encoded CommitteeAttestations. */ computeAttestationsHash(packedAttestations) {
|
|
374
|
+
return keccak256(encodeAbiParameters([
|
|
375
|
+
this.getCommitteeAttestationsStructDef()
|
|
376
|
+
], [
|
|
377
|
+
packedAttestations
|
|
378
|
+
]));
|
|
379
|
+
}
|
|
380
|
+
/** Computes the keccak256 payload digest from the checkpoint header, archive root, and fee asset price modifier. */ computePayloadDigest(header, archiveRoot, feeAssetPriceModifier) {
|
|
381
|
+
const consensusPayload = new ConsensusPayload(header, archiveRoot, feeAssetPriceModifier, this.getSignatureContext());
|
|
382
|
+
return getHashedSignaturePayloadTypedData(consensusPayload).toString();
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
292
385
|
* Extracts the CommitteeAttestations struct definition from RollupAbi.
|
|
293
386
|
* Finds the _attestations parameter by name in the propose function.
|
|
294
|
-
* Lazy-loaded to avoid issues during module initialization.
|
|
295
387
|
*/ getCommitteeAttestationsStructDef() {
|
|
296
388
|
const proposeFunction = RollupAbi.find((item)=>item.type === 'function' && item.name === 'propose');
|
|
297
389
|
if (!proposeFunction) {
|
|
@@ -312,160 +404,5 @@ import { getSuccessfulCallsFromTrace } from './trace_tx.js';
|
|
|
312
404
|
components: tupleParam.components || []
|
|
313
405
|
};
|
|
314
406
|
}
|
|
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.checkpointAttestation);
|
|
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
407
|
}
|
|
408
|
+
/** Function selector for the `propose` method of the rollup contract. */ const PROPOSE_SELECTOR = toFunctionSelector(RollupAbi.find((x)=>x.type === 'function' && x.name === 'propose'));
|