@aztec/ethereum 0.0.0-test.1 → 0.0.1-commit.017a351

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