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