@aztec/ethereum 0.0.0-test.0 → 0.0.1-commit.03f7ef2

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 (272) hide show
  1. package/dest/account.d.ts +2 -0
  2. package/dest/account.d.ts.map +1 -0
  3. package/dest/account.js +4 -0
  4. package/dest/chain.d.ts +1 -1
  5. package/dest/client.d.ts +6 -4
  6. package/dest/client.d.ts.map +1 -1
  7. package/dest/client.js +21 -3
  8. package/dest/config.d.ts +71 -16
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +138 -22
  11. package/dest/constants.d.ts +1 -1
  12. package/dest/contracts/empire_base.d.ts +25 -8
  13. package/dest/contracts/empire_base.d.ts.map +1 -1
  14. package/dest/contracts/empire_base.js +75 -2
  15. package/dest/contracts/empire_slashing_proposer.d.ts +67 -0
  16. package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -0
  17. package/dest/contracts/empire_slashing_proposer.js +209 -0
  18. package/dest/contracts/errors.d.ts +7 -0
  19. package/dest/contracts/errors.d.ts.map +1 -0
  20. package/dest/contracts/errors.js +12 -0
  21. package/dest/contracts/fee_asset_handler.d.ts +19 -0
  22. package/dest/contracts/fee_asset_handler.d.ts.map +1 -0
  23. package/dest/contracts/fee_asset_handler.js +57 -0
  24. package/dest/contracts/fee_juice.d.ts +6 -7
  25. package/dest/contracts/fee_juice.d.ts.map +1 -1
  26. package/dest/contracts/fee_juice.js +27 -20
  27. package/dest/contracts/governance.d.ts +43 -32
  28. package/dest/contracts/governance.d.ts.map +1 -1
  29. package/dest/contracts/governance.js +87 -84
  30. package/dest/contracts/governance_proposer.d.ts +17 -13
  31. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  32. package/dest/contracts/governance_proposer.js +46 -17
  33. package/dest/contracts/gse.d.ts +32 -0
  34. package/dest/contracts/gse.d.ts.map +1 -0
  35. package/dest/contracts/gse.js +72 -0
  36. package/dest/contracts/inbox.d.ts +26 -0
  37. package/dest/contracts/inbox.d.ts.map +1 -0
  38. package/dest/contracts/inbox.js +45 -0
  39. package/dest/contracts/index.d.ts +9 -3
  40. package/dest/contracts/index.d.ts.map +1 -1
  41. package/dest/contracts/index.js +8 -2
  42. package/dest/contracts/multicall.d.ts +21 -0
  43. package/dest/contracts/multicall.d.ts.map +1 -0
  44. package/dest/contracts/multicall.js +156 -0
  45. package/dest/contracts/registry.d.ts +10 -5
  46. package/dest/contracts/registry.d.ts.map +1 -1
  47. package/dest/contracts/registry.js +44 -16
  48. package/dest/contracts/rollup.d.ts +221 -41
  49. package/dest/contracts/rollup.d.ts.map +1 -1
  50. package/dest/contracts/rollup.js +549 -81
  51. package/dest/contracts/slasher_contract.d.ts +44 -0
  52. package/dest/contracts/slasher_contract.d.ts.map +1 -0
  53. package/dest/contracts/slasher_contract.js +75 -0
  54. package/dest/contracts/tally_slashing_proposer.d.ts +140 -0
  55. package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -0
  56. package/dest/contracts/tally_slashing_proposer.js +313 -0
  57. package/dest/contracts/utils.d.ts +3 -0
  58. package/dest/contracts/utils.d.ts.map +1 -0
  59. package/dest/contracts/utils.js +11 -0
  60. package/dest/deploy_aztec_l1_contracts.d.ts +245 -0
  61. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  62. package/dest/deploy_aztec_l1_contracts.js +335 -0
  63. package/dest/deploy_l1_contract.d.ts +68 -0
  64. package/dest/deploy_l1_contract.d.ts.map +1 -0
  65. package/dest/deploy_l1_contract.js +312 -0
  66. package/dest/eth-signer/eth-signer.d.ts +21 -0
  67. package/dest/eth-signer/eth-signer.d.ts.map +1 -0
  68. package/dest/eth-signer/eth-signer.js +5 -0
  69. package/dest/eth-signer/index.d.ts +2 -0
  70. package/dest/eth-signer/index.d.ts.map +1 -0
  71. package/dest/eth-signer/index.js +1 -0
  72. package/dest/forwarder_proxy.d.ts +32 -0
  73. package/dest/forwarder_proxy.d.ts.map +1 -0
  74. package/dest/forwarder_proxy.js +93 -0
  75. package/dest/l1_artifacts.d.ts +77364 -0
  76. package/dest/l1_artifacts.d.ts.map +1 -0
  77. package/dest/l1_artifacts.js +166 -0
  78. package/dest/l1_contract_addresses.d.ts +24 -4
  79. package/dest/l1_contract_addresses.d.ts.map +1 -1
  80. package/dest/l1_contract_addresses.js +25 -21
  81. package/dest/l1_reader.d.ts +4 -2
  82. package/dest/l1_reader.d.ts.map +1 -1
  83. package/dest/l1_reader.js +14 -8
  84. package/dest/l1_tx_utils/config.d.ts +59 -0
  85. package/dest/l1_tx_utils/config.d.ts.map +1 -0
  86. package/dest/l1_tx_utils/config.js +96 -0
  87. package/dest/l1_tx_utils/constants.d.ts +12 -0
  88. package/dest/l1_tx_utils/constants.d.ts.map +1 -0
  89. package/dest/l1_tx_utils/constants.js +39 -0
  90. package/dest/l1_tx_utils/factory.d.ts +24 -0
  91. package/dest/l1_tx_utils/factory.d.ts.map +1 -0
  92. package/dest/l1_tx_utils/factory.js +12 -0
  93. package/dest/l1_tx_utils/fee-strategies/index.d.ts +9 -0
  94. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  95. package/dest/l1_tx_utils/fee-strategies/index.js +11 -0
  96. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +18 -0
  97. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  98. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +111 -0
  99. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +32 -0
  100. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  101. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +173 -0
  102. package/dest/l1_tx_utils/fee-strategies/types.d.ts +64 -0
  103. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  104. package/dest/l1_tx_utils/fee-strategies/types.js +24 -0
  105. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
  106. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
  107. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +48 -0
  108. package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
  109. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
  110. package/dest/l1_tx_utils/index-blobs.js +2 -0
  111. package/dest/l1_tx_utils/index.d.ts +12 -0
  112. package/dest/l1_tx_utils/index.d.ts.map +1 -0
  113. package/dest/l1_tx_utils/index.js +12 -0
  114. package/dest/l1_tx_utils/interfaces.d.ts +76 -0
  115. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
  116. package/dest/l1_tx_utils/interfaces.js +4 -0
  117. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
  118. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  119. package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
  120. package/dest/l1_tx_utils/l1_tx_utils.d.ts +94 -0
  121. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
  122. package/dest/l1_tx_utils/l1_tx_utils.js +623 -0
  123. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +26 -0
  124. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +1 -0
  125. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +26 -0
  126. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +87 -0
  127. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
  128. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +360 -0
  129. package/dest/l1_tx_utils/signer.d.ts +4 -0
  130. package/dest/l1_tx_utils/signer.d.ts.map +1 -0
  131. package/dest/l1_tx_utils/signer.js +16 -0
  132. package/dest/l1_tx_utils/types.d.ts +67 -0
  133. package/dest/l1_tx_utils/types.d.ts.map +1 -0
  134. package/dest/l1_tx_utils/types.js +26 -0
  135. package/dest/l1_tx_utils/utils.d.ts +4 -0
  136. package/dest/l1_tx_utils/utils.d.ts.map +1 -0
  137. package/dest/l1_tx_utils/utils.js +14 -0
  138. package/dest/l1_types.d.ts +6 -0
  139. package/dest/l1_types.d.ts.map +1 -0
  140. package/dest/l1_types.js +1 -0
  141. package/dest/publisher_manager.d.ts +15 -0
  142. package/dest/publisher_manager.d.ts.map +1 -0
  143. package/dest/publisher_manager.js +88 -0
  144. package/dest/queries.d.ts +4 -2
  145. package/dest/queries.d.ts.map +1 -1
  146. package/dest/queries.js +53 -12
  147. package/dest/test/chain_monitor.d.ts +75 -0
  148. package/dest/test/chain_monitor.d.ts.map +1 -0
  149. package/dest/test/chain_monitor.js +214 -0
  150. package/dest/test/delayed_tx_utils.d.ts +8 -3
  151. package/dest/test/delayed_tx_utils.d.ts.map +1 -1
  152. package/dest/test/delayed_tx_utils.js +13 -6
  153. package/dest/test/eth_cheat_codes.d.ts +217 -0
  154. package/dest/test/eth_cheat_codes.d.ts.map +1 -0
  155. package/dest/test/eth_cheat_codes.js +560 -0
  156. package/dest/test/eth_cheat_codes_with_state.d.ts +2 -2
  157. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
  158. package/dest/test/eth_cheat_codes_with_state.js +1 -1
  159. package/dest/test/index.d.ts +4 -1
  160. package/dest/test/index.d.ts.map +1 -1
  161. package/dest/test/index.js +3 -0
  162. package/dest/test/rollup_cheat_codes.d.ts +87 -0
  163. package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
  164. package/dest/test/rollup_cheat_codes.js +275 -0
  165. package/dest/test/start_anvil.d.ts +9 -1
  166. package/dest/test/start_anvil.d.ts.map +1 -1
  167. package/dest/test/start_anvil.js +16 -7
  168. package/dest/test/tx_delayer.d.ts +18 -7
  169. package/dest/test/tx_delayer.d.ts.map +1 -1
  170. package/dest/test/tx_delayer.js +97 -20
  171. package/dest/test/upgrade_utils.d.ts +6 -5
  172. package/dest/test/upgrade_utils.d.ts.map +1 -1
  173. package/dest/test/upgrade_utils.js +23 -16
  174. package/dest/types.d.ts +62 -8
  175. package/dest/types.d.ts.map +1 -1
  176. package/dest/types.js +3 -1
  177. package/dest/utils.d.ts +16 -3
  178. package/dest/utils.d.ts.map +1 -1
  179. package/dest/utils.js +61 -88
  180. package/dest/zkPassportVerifierAddress.d.ts +15 -0
  181. package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
  182. package/dest/zkPassportVerifierAddress.js +11 -0
  183. package/package.json +50 -23
  184. package/src/account.ts +5 -0
  185. package/src/client.ts +43 -5
  186. package/src/config.ts +188 -31
  187. package/src/contracts/empire_base.ts +77 -7
  188. package/src/contracts/empire_slashing_proposer.ts +270 -0
  189. package/src/contracts/errors.ts +13 -0
  190. package/src/contracts/fee_asset_handler.ts +63 -0
  191. package/src/contracts/fee_juice.ts +29 -15
  192. package/src/contracts/governance.ts +80 -77
  193. package/src/contracts/governance_proposer.ts +71 -24
  194. package/src/contracts/gse.ts +88 -0
  195. package/src/contracts/inbox.ts +63 -0
  196. package/src/contracts/index.ts +8 -2
  197. package/src/contracts/multicall.ts +155 -0
  198. package/src/contracts/registry.ts +51 -26
  199. package/src/contracts/rollup.ts +624 -78
  200. package/src/contracts/slasher_contract.ts +89 -0
  201. package/src/contracts/tally_slashing_proposer.ts +318 -0
  202. package/src/contracts/utils.ts +14 -0
  203. package/src/deploy_aztec_l1_contracts.ts +556 -0
  204. package/src/deploy_l1_contract.ts +362 -0
  205. package/src/eth-signer/eth-signer.ts +25 -0
  206. package/src/eth-signer/index.ts +1 -0
  207. package/src/forwarder_proxy.ts +108 -0
  208. package/src/l1_artifacts.ts +254 -0
  209. package/src/l1_contract_addresses.ts +49 -34
  210. package/src/l1_reader.ts +17 -9
  211. package/src/l1_tx_utils/README.md +177 -0
  212. package/src/l1_tx_utils/config.ts +161 -0
  213. package/src/l1_tx_utils/constants.ts +29 -0
  214. package/src/l1_tx_utils/factory.ts +64 -0
  215. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  216. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +159 -0
  217. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +241 -0
  218. package/src/l1_tx_utils/fee-strategies/types.ts +88 -0
  219. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +119 -0
  220. package/src/l1_tx_utils/index-blobs.ts +2 -0
  221. package/src/l1_tx_utils/index.ts +14 -0
  222. package/src/l1_tx_utils/interfaces.ts +86 -0
  223. package/src/l1_tx_utils/l1_fee_analyzer.ts +804 -0
  224. package/src/l1_tx_utils/l1_tx_utils.ts +738 -0
  225. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +77 -0
  226. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +458 -0
  227. package/src/l1_tx_utils/signer.ts +28 -0
  228. package/src/l1_tx_utils/types.ts +85 -0
  229. package/src/l1_tx_utils/utils.ts +16 -0
  230. package/src/l1_types.ts +6 -0
  231. package/src/publisher_manager.ts +106 -0
  232. package/src/queries.ts +73 -15
  233. package/src/test/chain_monitor.ts +245 -0
  234. package/src/test/delayed_tx_utils.ts +34 -6
  235. package/src/test/eth_cheat_codes.ts +588 -0
  236. package/src/test/eth_cheat_codes_with_state.ts +1 -1
  237. package/src/test/index.ts +3 -0
  238. package/src/test/rollup_cheat_codes.ts +312 -0
  239. package/src/test/start_anvil.ts +24 -5
  240. package/src/test/tx_delayer.ts +130 -27
  241. package/src/test/upgrade_utils.ts +30 -21
  242. package/src/types.ts +71 -7
  243. package/src/utils.ts +79 -91
  244. package/src/zkPassportVerifierAddress.ts +15 -0
  245. package/dest/contracts/forwarder.d.ts +0 -24
  246. package/dest/contracts/forwarder.d.ts.map +0 -1
  247. package/dest/contracts/forwarder.js +0 -101
  248. package/dest/contracts/slashing_proposer.d.ts +0 -21
  249. package/dest/contracts/slashing_proposer.d.ts.map +0 -1
  250. package/dest/contracts/slashing_proposer.js +0 -47
  251. package/dest/deploy_l1_contracts.d.ts +0 -21210
  252. package/dest/deploy_l1_contracts.d.ts.map +0 -1
  253. package/dest/deploy_l1_contracts.js +0 -687
  254. package/dest/eth_cheat_codes.d.ts +0 -147
  255. package/dest/eth_cheat_codes.d.ts.map +0 -1
  256. package/dest/eth_cheat_codes.js +0 -303
  257. package/dest/index.d.ts +0 -14
  258. package/dest/index.d.ts.map +0 -1
  259. package/dest/index.js +0 -13
  260. package/dest/l1_tx_utils.d.ts +0 -192
  261. package/dest/l1_tx_utils.d.ts.map +0 -1
  262. package/dest/l1_tx_utils.js +0 -641
  263. package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
  264. package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
  265. package/dest/l1_tx_utils_with_blobs.js +0 -64
  266. package/src/contracts/forwarder.ts +0 -132
  267. package/src/contracts/slashing_proposer.ts +0 -51
  268. package/src/deploy_l1_contracts.ts +0 -948
  269. package/src/eth_cheat_codes.ts +0 -314
  270. package/src/index.ts +0 -13
  271. package/src/l1_tx_utils.ts +0 -847
  272. package/src/l1_tx_utils_with_blobs.ts +0 -86
@@ -0,0 +1,89 @@
1
+ import { EthAddress } from '@aztec/foundation/eth-address';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+ import { SlasherAbi } from '@aztec/l1-artifacts/SlasherAbi';
4
+
5
+ import { type GetContractReturnType, getContract } from 'viem';
6
+
7
+ import type { ViemClient } from '../types.js';
8
+
9
+ /**
10
+ * Typescript wrapper around the Slasher contract.
11
+ */
12
+ export class SlasherContract {
13
+ private contract: GetContractReturnType<typeof SlasherAbi, ViemClient>;
14
+
15
+ constructor(
16
+ private readonly client: ViemClient,
17
+ private readonly address: EthAddress,
18
+ private readonly log = createLogger('slasher-contract'),
19
+ ) {
20
+ this.contract = getContract({
21
+ address: this.address.toString(),
22
+ abi: SlasherAbi,
23
+ client: this.client,
24
+ });
25
+ }
26
+
27
+ /**
28
+ * Checks if a slash payload is vetoed.
29
+ * @param payloadAddress - The address of the payload to check
30
+ * @returns True if the payload is vetoed, false otherwise
31
+ */
32
+ public async isPayloadVetoed(payloadAddress: EthAddress): Promise<boolean> {
33
+ try {
34
+ return await this.contract.read.vetoedPayloads([payloadAddress.toString()]);
35
+ } catch (error) {
36
+ this.log.error(`Error checking if payload ${payloadAddress} is vetoed`, error);
37
+ throw error;
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Checks if slashing is currently enabled. Slashing can be disabled by the vetoer.
43
+ * @returns True if slashing is enabled, false otherwise
44
+ */
45
+ public async isSlashingEnabled(): Promise<boolean> {
46
+ try {
47
+ return await this.contract.read.isSlashingEnabled();
48
+ } catch (error) {
49
+ this.log.error(`Error checking if slashing is enabled`, error);
50
+ throw error;
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Gets the current vetoer address.
56
+ * @returns The vetoer address
57
+ */
58
+ public async getVetoer(): Promise<EthAddress> {
59
+ const vetoer = await this.contract.read.VETOER();
60
+ return EthAddress.fromString(vetoer);
61
+ }
62
+
63
+ /**
64
+ * Gets the disable duration by the vetoer.
65
+ * @returns The disable duration in seconds
66
+ */
67
+ public async getSlashingDisableDuration(): Promise<number> {
68
+ const duration = await this.contract.read.SLASHING_DISABLE_DURATION();
69
+ return Number(duration);
70
+ }
71
+
72
+ /**
73
+ * Gets the current governance address.
74
+ * @returns The governance address
75
+ */
76
+ public async getGovernance(): Promise<EthAddress> {
77
+ const governance = await this.contract.read.GOVERNANCE();
78
+ return EthAddress.fromString(governance);
79
+ }
80
+
81
+ /**
82
+ * Gets the current proposer address.
83
+ * @returns The proposer address
84
+ */
85
+ public async getProposer(): Promise<EthAddress> {
86
+ const proposer = await this.contract.read.PROPOSER();
87
+ return EthAddress.fromString(proposer);
88
+ }
89
+ }
@@ -0,0 +1,318 @@
1
+ import type { L1TxRequest } from '@aztec/ethereum/l1-tx-utils';
2
+ import type { ViemClient } from '@aztec/ethereum/types';
3
+ import { tryExtractEvent } from '@aztec/ethereum/utils';
4
+ import { SlotNumber } from '@aztec/foundation/branded-types';
5
+ import { Buffer32 } from '@aztec/foundation/buffer';
6
+ import { EthAddress } from '@aztec/foundation/eth-address';
7
+ import { Signature } from '@aztec/foundation/eth-signature';
8
+ import { hexToBuffer } from '@aztec/foundation/string';
9
+ import { TallySlashingProposerAbi } from '@aztec/l1-artifacts/TallySlashingProposerAbi';
10
+
11
+ import {
12
+ type GetContractReturnType,
13
+ type Hex,
14
+ type Log,
15
+ type TypedDataDefinition,
16
+ encodeFunctionData,
17
+ getContract,
18
+ } from 'viem';
19
+
20
+ /**
21
+ * Wrapper around the TallySlashingProposer contract that provides
22
+ * a TypeScript interface for interacting with the consensus-based slashing system.
23
+ */
24
+ export class TallySlashingProposerContract {
25
+ private readonly contract: GetContractReturnType<typeof TallySlashingProposerAbi, ViemClient>;
26
+
27
+ public readonly type = 'tally' as const;
28
+
29
+ constructor(
30
+ public readonly client: ViemClient,
31
+ address: Hex | EthAddress,
32
+ ) {
33
+ this.contract = getContract({
34
+ address: typeof address === 'string' ? address : address.toString(),
35
+ abi: TallySlashingProposerAbi,
36
+ client,
37
+ });
38
+ }
39
+
40
+ public get address() {
41
+ return EthAddress.fromString(this.contract.address);
42
+ }
43
+
44
+ public getQuorumSize(): Promise<bigint> {
45
+ return this.contract.read.QUORUM();
46
+ }
47
+
48
+ public getRoundSize(): Promise<bigint> {
49
+ return this.contract.read.ROUND_SIZE();
50
+ }
51
+
52
+ public getCommitteeSize(): Promise<bigint> {
53
+ return this.contract.read.COMMITTEE_SIZE();
54
+ }
55
+
56
+ public getRoundSizeInEpochs(): Promise<bigint> {
57
+ return this.contract.read.ROUND_SIZE_IN_EPOCHS();
58
+ }
59
+
60
+ public getLifetimeInRounds(): Promise<bigint> {
61
+ return this.contract.read.LIFETIME_IN_ROUNDS();
62
+ }
63
+
64
+ public getExecutionDelayInRounds(): Promise<bigint> {
65
+ return this.contract.read.EXECUTION_DELAY_IN_ROUNDS();
66
+ }
67
+
68
+ public getSlashingAmounts(): Promise<[bigint, bigint, bigint]> {
69
+ return Promise.all([
70
+ this.contract.read.SLASH_AMOUNT_SMALL(),
71
+ this.contract.read.SLASH_AMOUNT_MEDIUM(),
72
+ this.contract.read.SLASH_AMOUNT_LARGE(),
73
+ ]);
74
+ }
75
+
76
+ public getSlashOffsetInRounds(): Promise<bigint> {
77
+ return this.contract.read.SLASH_OFFSET_IN_ROUNDS();
78
+ }
79
+
80
+ public getCurrentRound(): Promise<bigint> {
81
+ return this.contract.read.getCurrentRound();
82
+ }
83
+
84
+ /**
85
+ * Get round information
86
+ * @param round - The round number to query
87
+ * @returns Round status information
88
+ */
89
+ public async getRound(round: bigint): Promise<{
90
+ isExecuted: boolean;
91
+ voteCount: bigint;
92
+ }> {
93
+ const [isExecuted, voteCount] = await this.contract.read.getRound([round]);
94
+ return { isExecuted, voteCount };
95
+ }
96
+
97
+ /**
98
+ * Check if a round is ready to execute at a given slot
99
+ * @param round - The round number to check
100
+ * @param slot - The slot number to check at
101
+ * @returns Whether the round is ready to execute
102
+ */
103
+ public async isRoundReadyToExecute(round: bigint, slot: SlotNumber): Promise<boolean> {
104
+ return await this.contract.read.isRoundReadyToExecute([round, BigInt(slot)]);
105
+ }
106
+
107
+ /** Returns the slash actions and payload address for a given round (zero if no slash actions) */
108
+ public async getPayload(
109
+ round: bigint,
110
+ ): Promise<{ actions: { slashAmount: bigint; validator: EthAddress }[]; address: EthAddress }> {
111
+ const { result: committees } = await this.contract.simulate.getSlashTargetCommittees([round]);
112
+ const tally = await this.contract.read.getTally([round, committees]);
113
+ const address = await this.contract.read.getPayloadAddress([round, tally]);
114
+ const actions = this.mapSlashActions(tally);
115
+ return { actions, address: EthAddress.fromString(address) };
116
+ }
117
+
118
+ /** Returns the slash actions to be executed for a given round based on votes */
119
+ public async getTally(
120
+ round: bigint,
121
+ ): Promise<{ actions: { slashAmount: bigint; validator: EthAddress }[]; committees: EthAddress[][] }> {
122
+ const { result: committees } = await this.contract.simulate.getSlashTargetCommittees([round]);
123
+ const tally = await this.contract.read.getTally([round, committees]);
124
+ return { actions: this.mapSlashActions(tally), committees: committees.map(c => c.map(EthAddress.fromString)) };
125
+ }
126
+
127
+ private mapSlashActions(
128
+ actions: readonly { slashAmount: bigint; validator: Hex }[],
129
+ ): { slashAmount: bigint; validator: EthAddress }[] {
130
+ return actions.map(({ validator, slashAmount }) => ({
131
+ validator: EthAddress.fromString(validator),
132
+ slashAmount,
133
+ }));
134
+ }
135
+
136
+ /** Tries to extract a VoteCast event from the given logs. */
137
+ public tryExtractVoteCastEvent(logs: Log[]) {
138
+ return tryExtractEvent(logs, this.address.toString(), TallySlashingProposerAbi, 'VoteCast');
139
+ }
140
+
141
+ /** Tries to extract a RoundExecuted event from the given logs. */
142
+ public tryExtractRoundExecutedEvent(logs: Log[]) {
143
+ return tryExtractEvent(logs, this.address.toString(), TallySlashingProposerAbi, 'RoundExecuted');
144
+ }
145
+
146
+ /**
147
+ * Create a transaction to vote for slashing offenses
148
+ * @param votes - The encoded votes for slashing
149
+ * @param slot - The slot number for the vote
150
+ * @param signer - The signer to produce the signature
151
+ * @returns L1 transaction request
152
+ */
153
+ public async buildVoteRequestFromSigner(
154
+ votes: Hex,
155
+ slot: SlotNumber,
156
+ signer: (msg: TypedDataDefinition) => Promise<Hex>,
157
+ ): Promise<L1TxRequest> {
158
+ const typedData = this.buildVoteTypedData(votes, slot);
159
+ const signature = Signature.fromString(await signer(typedData));
160
+
161
+ return {
162
+ to: this.contract.address,
163
+ data: encodeFunctionData({
164
+ abi: TallySlashingProposerAbi,
165
+ functionName: 'vote',
166
+ args: [votes, signature.toViemSignature()],
167
+ }),
168
+ };
169
+ }
170
+
171
+ /** Returns the typed data definition to EIP712-sign for voting */
172
+ public buildVoteTypedData(votes: Hex, slot: SlotNumber): TypedDataDefinition {
173
+ const domain = {
174
+ name: 'TallySlashingProposer',
175
+ version: '1',
176
+ chainId: this.client.chain.id,
177
+ verifyingContract: this.contract.address,
178
+ };
179
+
180
+ const types = {
181
+ EIP712Domain: [
182
+ { name: 'name', type: 'string' },
183
+ { name: 'version', type: 'string' },
184
+ { name: 'chainId', type: 'uint256' },
185
+ { name: 'verifyingContract', type: 'address' },
186
+ ],
187
+ Vote: [
188
+ { name: 'votes', type: 'bytes' },
189
+ { name: 'slot', type: 'uint256' },
190
+ ],
191
+ };
192
+
193
+ return { domain, types, primaryType: 'Vote', message: { votes, slot: BigInt(slot) } };
194
+ }
195
+
196
+ /** Gets the digest to sign for voting directly from the contract */
197
+ public async getVoteDataDigest(votes: Hex, slot: SlotNumber): Promise<Buffer32> {
198
+ return Buffer32.fromString(await this.contract.read.getVoteSignatureDigest([votes, BigInt(slot)]));
199
+ }
200
+
201
+ /**
202
+ * Create a transaction to vote for slashing offenses
203
+ * @param votes - The encoded votes for slashing
204
+ * @param signature - The signature from the current proposer
205
+ * @returns L1 transaction request
206
+ */
207
+ public buildVoteRequestWithSignature(votes: Hex, signature: { v: number; r: Hex; s: Hex }): L1TxRequest {
208
+ return {
209
+ to: this.contract.address,
210
+ data: encodeFunctionData({
211
+ abi: TallySlashingProposerAbi,
212
+ functionName: 'vote',
213
+ args: [votes, signature],
214
+ }),
215
+ };
216
+ }
217
+
218
+ /**
219
+ * Create a transaction to execute a slashing round
220
+ * @param round - The round number to execute
221
+ * @param committees - The committees for each epoch in the round
222
+ * @returns L1 transaction request
223
+ */
224
+ public buildExecuteRoundRequest(round: bigint, committees: EthAddress[][]): L1TxRequest {
225
+ return {
226
+ to: this.contract.address,
227
+ data: encodeFunctionData({
228
+ abi: TallySlashingProposerAbi,
229
+ functionName: 'executeRound',
230
+ args: [round, committees.map(c => c.map(addr => addr.toString()))],
231
+ }),
232
+ };
233
+ }
234
+
235
+ /** Returns the last vote emitted for a given round */
236
+ public async getLastVote(round: bigint) {
237
+ const { voteCount } = await this.getRound(round);
238
+ const validators = (await this.contract.simulate.getSlashTargetCommittees([round])).result.flat();
239
+ const vote = await this.contract.read.getVotes([round, voteCount - 1n]);
240
+ const decoded = decodeSlashConsensusVotes(hexToBuffer(vote));
241
+ const slashAmounts = await this.getSlashingAmounts();
242
+ return decoded
243
+ .map((units, i) => ({
244
+ validator: EthAddress.fromString(validators[i]),
245
+ slashAmount: slashAmounts[units - 1] ?? 0n,
246
+ }))
247
+ .filter(v => v.slashAmount > 0n);
248
+ }
249
+
250
+ /**
251
+ * Listen for VoteCast events
252
+ * @param callback - Callback function to handle vote cast events
253
+ * @returns Unwatch function
254
+ */
255
+ public listenToVoteCast(callback: (args: { round: bigint; proposer: string }) => void): () => void {
256
+ return this.contract.watchEvent.VoteCast(
257
+ {},
258
+ {
259
+ onLogs: logs => {
260
+ for (const log of logs) {
261
+ const { round, proposer } = log.args;
262
+ if (round !== undefined && proposer) {
263
+ callback({ round, proposer });
264
+ }
265
+ }
266
+ },
267
+ },
268
+ );
269
+ }
270
+
271
+ /**
272
+ * Listen for RoundExecuted events
273
+ * @param callback - Callback function to handle round executed events
274
+ * @returns Unwatch function
275
+ */
276
+ public listenToRoundExecuted(
277
+ callback: (args: { round: bigint; slashCount: bigint; l1BlockHash: Hex }) => void,
278
+ ): () => void {
279
+ return this.contract.watchEvent.RoundExecuted(
280
+ {},
281
+ {
282
+ onLogs: logs => {
283
+ for (const log of logs) {
284
+ const { round, slashCount } = log.args;
285
+ if (round !== undefined && slashCount !== undefined) {
286
+ callback({ round, slashCount, l1BlockHash: log.blockHash });
287
+ }
288
+ }
289
+ },
290
+ },
291
+ );
292
+ }
293
+ }
294
+
295
+ /**
296
+ * Decodes a Buffer containing slash votes back into an array of numbers.
297
+ * Each vote is represented as a 2-bit value (0, 1, 2, or 3) representing slashing units.
298
+ * @dev This should live in stdlib next to encodeSlashConsensusVotes but is here since we
299
+ * do not have a dependency to stdlib from the ethereum package. We need a larger refactor to fix this.
300
+ * @param buffer - The Buffer containing encoded slash votes
301
+ * @returns An array of numbers representing the slash votes
302
+ */
303
+ export function decodeSlashConsensusVotes(buffer: Buffer): number[] {
304
+ const votes: number[] = [];
305
+ for (let i = 0; i < buffer.length; i++) {
306
+ const voteByte = buffer.readUInt8(i);
307
+ // Decode votes from Solidity's bit order (LSB to MSB)
308
+ // Bits 0-1: validator at index i*4
309
+ // Bits 2-3: validator at index i*4+1
310
+ // Bits 4-5: validator at index i*4+2
311
+ // Bits 6-7: validator at index i*4+3
312
+ votes.push((voteByte >> 0) & 0x03);
313
+ votes.push((voteByte >> 2) & 0x03);
314
+ votes.push((voteByte >> 4) & 0x03);
315
+ votes.push((voteByte >> 6) & 0x03);
316
+ }
317
+ return votes;
318
+ }
@@ -0,0 +1,14 @@
1
+ import type { ViemClient } from '../types.js';
2
+ import { BlockTagTooOldError } from './errors.js';
3
+
4
+ const L1_NON_ARCHIVE_BLOCK_HISTORY_LENGTH = 128n;
5
+
6
+ export async function checkBlockTag(block: bigint | undefined, publicClient: ViemClient) {
7
+ if (block === undefined) {
8
+ return;
9
+ }
10
+ const latestBlock = await publicClient.getBlockNumber();
11
+ if (block < latestBlock - L1_NON_ARCHIVE_BLOCK_HISTORY_LENGTH) {
12
+ throw new BlockTagTooOldError(block, latestBlock);
13
+ }
14
+ }