@aztec/ethereum 0.0.0-test.1 → 0.0.1-commit.023c3e5

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