@aztec/archiver 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c

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