@aztec/ethereum 0.0.0-test.1 → 0.0.1-commit.21caa21

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 (232) 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 +16 -2
  8. package/dest/config.d.ts +111 -17
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +462 -22
  11. package/dest/constants.d.ts +1 -1
  12. package/dest/contracts/empire_base.d.ts +24 -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 +66 -0
  16. package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -0
  17. package/dest/contracts/empire_slashing_proposer.js +200 -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 +16 -13
  31. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  32. package/dest/contracts/governance_proposer.js +37 -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 +204 -40
  49. package/dest/contracts/rollup.d.ts.map +1 -1
  50. package/dest/contracts/rollup.js +529 -79
  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 +139 -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_l1_contracts.d.ts +577 -21114
  61. package/dest/deploy_l1_contracts.d.ts.map +1 -1
  62. package/dest/deploy_l1_contracts.js +1225 -421
  63. package/dest/eth-signer/eth-signer.d.ts +21 -0
  64. package/dest/eth-signer/eth-signer.d.ts.map +1 -0
  65. package/dest/eth-signer/eth-signer.js +5 -0
  66. package/dest/eth-signer/index.d.ts +2 -0
  67. package/dest/eth-signer/index.d.ts.map +1 -0
  68. package/dest/eth-signer/index.js +1 -0
  69. package/dest/index.d.ts +7 -3
  70. package/dest/index.d.ts.map +1 -1
  71. package/dest/index.js +6 -2
  72. package/dest/l1_artifacts.d.ts +77344 -0
  73. package/dest/l1_artifacts.d.ts.map +1 -0
  74. package/dest/l1_artifacts.js +166 -0
  75. package/dest/l1_contract_addresses.d.ts +24 -4
  76. package/dest/l1_contract_addresses.d.ts.map +1 -1
  77. package/dest/l1_contract_addresses.js +22 -18
  78. package/dest/l1_reader.d.ts +2 -2
  79. package/dest/l1_reader.d.ts.map +1 -1
  80. package/dest/l1_reader.js +8 -8
  81. package/dest/l1_tx_utils/config.d.ts +59 -0
  82. package/dest/l1_tx_utils/config.d.ts.map +1 -0
  83. package/dest/l1_tx_utils/config.js +82 -0
  84. package/dest/l1_tx_utils/constants.d.ts +6 -0
  85. package/dest/l1_tx_utils/constants.d.ts.map +1 -0
  86. package/dest/l1_tx_utils/constants.js +14 -0
  87. package/dest/l1_tx_utils/factory.d.ts +24 -0
  88. package/dest/l1_tx_utils/factory.d.ts.map +1 -0
  89. package/dest/l1_tx_utils/factory.js +12 -0
  90. package/dest/l1_tx_utils/index.d.ts +10 -0
  91. package/dest/l1_tx_utils/index.d.ts.map +1 -0
  92. package/dest/l1_tx_utils/index.js +10 -0
  93. package/dest/l1_tx_utils/interfaces.d.ts +76 -0
  94. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
  95. package/dest/l1_tx_utils/interfaces.js +4 -0
  96. package/dest/l1_tx_utils/l1_tx_utils.d.ts +94 -0
  97. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
  98. package/dest/l1_tx_utils/l1_tx_utils.js +610 -0
  99. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +26 -0
  100. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +1 -0
  101. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +26 -0
  102. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +94 -0
  103. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
  104. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +430 -0
  105. package/dest/l1_tx_utils/signer.d.ts +4 -0
  106. package/dest/l1_tx_utils/signer.d.ts.map +1 -0
  107. package/dest/l1_tx_utils/signer.js +16 -0
  108. package/dest/l1_tx_utils/types.d.ts +67 -0
  109. package/dest/l1_tx_utils/types.d.ts.map +1 -0
  110. package/dest/l1_tx_utils/types.js +26 -0
  111. package/dest/l1_tx_utils/utils.d.ts +4 -0
  112. package/dest/l1_tx_utils/utils.d.ts.map +1 -0
  113. package/dest/l1_tx_utils/utils.js +14 -0
  114. package/dest/l1_types.d.ts +6 -0
  115. package/dest/l1_types.d.ts.map +1 -0
  116. package/dest/l1_types.js +1 -0
  117. package/dest/publisher_manager.d.ts +15 -0
  118. package/dest/publisher_manager.d.ts.map +1 -0
  119. package/dest/publisher_manager.js +88 -0
  120. package/dest/queries.d.ts +4 -2
  121. package/dest/queries.d.ts.map +1 -1
  122. package/dest/queries.js +53 -12
  123. package/dest/test/chain_monitor.d.ts +73 -0
  124. package/dest/test/chain_monitor.d.ts.map +1 -0
  125. package/dest/test/chain_monitor.js +215 -0
  126. package/dest/test/delayed_tx_utils.d.ts +8 -3
  127. package/dest/test/delayed_tx_utils.d.ts.map +1 -1
  128. package/dest/test/delayed_tx_utils.js +13 -6
  129. package/dest/test/eth_cheat_codes.d.ts +217 -0
  130. package/dest/test/eth_cheat_codes.d.ts.map +1 -0
  131. package/dest/test/eth_cheat_codes.js +558 -0
  132. package/dest/test/eth_cheat_codes_with_state.d.ts +2 -2
  133. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
  134. package/dest/test/eth_cheat_codes_with_state.js +1 -1
  135. package/dest/test/index.d.ts +4 -1
  136. package/dest/test/index.d.ts.map +1 -1
  137. package/dest/test/index.js +3 -0
  138. package/dest/test/rollup_cheat_codes.d.ts +87 -0
  139. package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
  140. package/dest/test/rollup_cheat_codes.js +266 -0
  141. package/dest/test/start_anvil.d.ts +7 -1
  142. package/dest/test/start_anvil.d.ts.map +1 -1
  143. package/dest/test/start_anvil.js +16 -7
  144. package/dest/test/tx_delayer.d.ts +18 -7
  145. package/dest/test/tx_delayer.d.ts.map +1 -1
  146. package/dest/test/tx_delayer.js +95 -19
  147. package/dest/test/upgrade_utils.d.ts +6 -5
  148. package/dest/test/upgrade_utils.d.ts.map +1 -1
  149. package/dest/test/upgrade_utils.js +23 -16
  150. package/dest/types.d.ts +7 -8
  151. package/dest/types.d.ts.map +1 -1
  152. package/dest/types.js +3 -1
  153. package/dest/utils.d.ts +2 -1
  154. package/dest/utils.d.ts.map +1 -1
  155. package/dest/utils.js +43 -88
  156. package/dest/zkPassportVerifierAddress.d.ts +15 -0
  157. package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
  158. package/dest/zkPassportVerifierAddress.js +11 -0
  159. package/package.json +28 -19
  160. package/src/account.ts +5 -0
  161. package/src/client.ts +42 -4
  162. package/src/config.ts +592 -31
  163. package/src/contracts/empire_base.ts +77 -7
  164. package/src/contracts/empire_slashing_proposer.ts +265 -0
  165. package/src/contracts/errors.ts +13 -0
  166. package/src/contracts/fee_asset_handler.ts +63 -0
  167. package/src/contracts/fee_juice.ts +29 -15
  168. package/src/contracts/governance.ts +80 -77
  169. package/src/contracts/governance_proposer.ts +66 -24
  170. package/src/contracts/gse.ts +88 -0
  171. package/src/contracts/inbox.ts +63 -0
  172. package/src/contracts/index.ts +8 -2
  173. package/src/contracts/multicall.ts +155 -0
  174. package/src/contracts/registry.ts +51 -26
  175. package/src/contracts/rollup.ts +596 -74
  176. package/src/contracts/slasher_contract.ts +89 -0
  177. package/src/contracts/tally_slashing_proposer.ts +316 -0
  178. package/src/contracts/utils.ts +14 -0
  179. package/src/deploy_l1_contracts.ts +1459 -538
  180. package/src/eth-signer/eth-signer.ts +25 -0
  181. package/src/eth-signer/index.ts +1 -0
  182. package/src/index.ts +6 -2
  183. package/src/l1_artifacts.ts +254 -0
  184. package/src/l1_contract_addresses.ts +32 -19
  185. package/src/l1_reader.ts +9 -9
  186. package/src/l1_tx_utils/README.md +177 -0
  187. package/src/l1_tx_utils/config.ts +143 -0
  188. package/src/l1_tx_utils/constants.ts +18 -0
  189. package/src/l1_tx_utils/factory.ts +64 -0
  190. package/src/l1_tx_utils/index.ts +12 -0
  191. package/src/l1_tx_utils/interfaces.ts +86 -0
  192. package/src/l1_tx_utils/l1_tx_utils.ts +718 -0
  193. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +77 -0
  194. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +558 -0
  195. package/src/l1_tx_utils/signer.ts +28 -0
  196. package/src/l1_tx_utils/types.ts +85 -0
  197. package/src/l1_tx_utils/utils.ts +16 -0
  198. package/src/l1_types.ts +6 -0
  199. package/src/publisher_manager.ts +106 -0
  200. package/src/queries.ts +73 -15
  201. package/src/test/chain_monitor.ts +243 -0
  202. package/src/test/delayed_tx_utils.ts +34 -6
  203. package/src/test/eth_cheat_codes.ts +588 -0
  204. package/src/test/eth_cheat_codes_with_state.ts +1 -1
  205. package/src/test/index.ts +3 -0
  206. package/src/test/rollup_cheat_codes.ts +307 -0
  207. package/src/test/start_anvil.ts +22 -5
  208. package/src/test/tx_delayer.ts +127 -26
  209. package/src/test/upgrade_utils.ts +30 -21
  210. package/src/types.ts +10 -8
  211. package/src/utils.ts +49 -90
  212. package/src/zkPassportVerifierAddress.ts +15 -0
  213. package/dest/contracts/forwarder.d.ts +0 -24
  214. package/dest/contracts/forwarder.d.ts.map +0 -1
  215. package/dest/contracts/forwarder.js +0 -101
  216. package/dest/contracts/slashing_proposer.d.ts +0 -21
  217. package/dest/contracts/slashing_proposer.d.ts.map +0 -1
  218. package/dest/contracts/slashing_proposer.js +0 -47
  219. package/dest/eth_cheat_codes.d.ts +0 -147
  220. package/dest/eth_cheat_codes.d.ts.map +0 -1
  221. package/dest/eth_cheat_codes.js +0 -303
  222. package/dest/l1_tx_utils.d.ts +0 -192
  223. package/dest/l1_tx_utils.d.ts.map +0 -1
  224. package/dest/l1_tx_utils.js +0 -641
  225. package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
  226. package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
  227. package/dest/l1_tx_utils_with_blobs.js +0 -64
  228. package/src/contracts/forwarder.ts +0 -132
  229. package/src/contracts/slashing_proposer.ts +0 -51
  230. package/src/eth_cheat_codes.ts +0 -314
  231. package/src/l1_tx_utils.ts +0 -847
  232. 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhc2hlcl9jb250cmFjdC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NvbnRyYWN0cy9zbGFzaGVyX2NvbnRyYWN0LnRzIl0sIm5hbWVzIjp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AO,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,139 @@
1
+ import { type L1TxRequest, type ViemClient } from '@aztec/ethereum';
2
+ import { SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { Buffer32 } from '@aztec/foundation/buffer';
4
+ import { EthAddress } from '@aztec/foundation/eth-address';
5
+ import { type Hex, type Log, type TypedDataDefinition } from 'viem';
6
+ /**
7
+ * Wrapper around the TallySlashingProposer contract that provides
8
+ * a TypeScript interface for interacting with the consensus-based slashing system.
9
+ */
10
+ export declare class TallySlashingProposerContract {
11
+ readonly client: ViemClient;
12
+ private readonly contract;
13
+ readonly type: "tally";
14
+ constructor(client: ViemClient, address: Hex | EthAddress);
15
+ get address(): EthAddress;
16
+ getQuorumSize(): Promise<bigint>;
17
+ getRoundSize(): Promise<bigint>;
18
+ getCommitteeSize(): Promise<bigint>;
19
+ getRoundSizeInEpochs(): Promise<bigint>;
20
+ getLifetimeInRounds(): Promise<bigint>;
21
+ getExecutionDelayInRounds(): Promise<bigint>;
22
+ getSlashingAmounts(): Promise<[bigint, bigint, bigint]>;
23
+ getSlashOffsetInRounds(): Promise<bigint>;
24
+ getCurrentRound(): Promise<bigint>;
25
+ /**
26
+ * Get round information
27
+ * @param round - The round number to query
28
+ * @returns Round status information
29
+ */
30
+ getRound(round: bigint): Promise<{
31
+ isExecuted: boolean;
32
+ voteCount: bigint;
33
+ }>;
34
+ /**
35
+ * Check if a round is ready to execute at a given slot
36
+ * @param round - The round number to check
37
+ * @param slot - The slot number to check at
38
+ * @returns Whether the round is ready to execute
39
+ */
40
+ isRoundReadyToExecute(round: bigint, slot: SlotNumber): Promise<boolean>;
41
+ /** Returns the slash actions and payload address for a given round (zero if no slash actions) */
42
+ getPayload(round: bigint): Promise<{
43
+ actions: {
44
+ slashAmount: bigint;
45
+ validator: EthAddress;
46
+ }[];
47
+ address: EthAddress;
48
+ }>;
49
+ /** Returns the slash actions to be executed for a given round based on votes */
50
+ getTally(round: bigint): Promise<{
51
+ actions: {
52
+ slashAmount: bigint;
53
+ validator: EthAddress;
54
+ }[];
55
+ committees: EthAddress[][];
56
+ }>;
57
+ private mapSlashActions;
58
+ /** Tries to extract a VoteCast event from the given logs. */
59
+ tryExtractVoteCastEvent(logs: Log[]): {
60
+ eventName: "VoteCast";
61
+ args: {
62
+ proposer: `0x${string}`;
63
+ round: bigint;
64
+ slot: bigint;
65
+ };
66
+ } | undefined;
67
+ /** Tries to extract a RoundExecuted event from the given logs. */
68
+ tryExtractRoundExecutedEvent(logs: Log[]): {
69
+ eventName: "RoundExecuted";
70
+ args: {
71
+ round: bigint;
72
+ slashCount: bigint;
73
+ };
74
+ } | undefined;
75
+ /**
76
+ * Create a transaction to vote for slashing offenses
77
+ * @param votes - The encoded votes for slashing
78
+ * @param slot - The slot number for the vote
79
+ * @param signer - The signer to produce the signature
80
+ * @returns L1 transaction request
81
+ */
82
+ buildVoteRequestFromSigner(votes: Hex, slot: SlotNumber, signer: (msg: TypedDataDefinition) => Promise<Hex>): Promise<L1TxRequest>;
83
+ /** Returns the typed data definition to EIP712-sign for voting */
84
+ buildVoteTypedData(votes: Hex, slot: SlotNumber): TypedDataDefinition;
85
+ /** Gets the digest to sign for voting directly from the contract */
86
+ getVoteDataDigest(votes: Hex, slot: SlotNumber): Promise<Buffer32>;
87
+ /**
88
+ * Create a transaction to vote for slashing offenses
89
+ * @param votes - The encoded votes for slashing
90
+ * @param signature - The signature from the current proposer
91
+ * @returns L1 transaction request
92
+ */
93
+ buildVoteRequestWithSignature(votes: Hex, signature: {
94
+ v: number;
95
+ r: Hex;
96
+ s: Hex;
97
+ }): L1TxRequest;
98
+ /**
99
+ * Create a transaction to execute a slashing round
100
+ * @param round - The round number to execute
101
+ * @param committees - The committees for each epoch in the round
102
+ * @returns L1 transaction request
103
+ */
104
+ buildExecuteRoundRequest(round: bigint, committees: EthAddress[][]): L1TxRequest;
105
+ /** Returns the last vote emitted for a given round */
106
+ getLastVote(round: bigint): Promise<{
107
+ validator: EthAddress;
108
+ slashAmount: bigint;
109
+ }[]>;
110
+ /**
111
+ * Listen for VoteCast events
112
+ * @param callback - Callback function to handle vote cast events
113
+ * @returns Unwatch function
114
+ */
115
+ listenToVoteCast(callback: (args: {
116
+ round: bigint;
117
+ proposer: string;
118
+ }) => void): () => void;
119
+ /**
120
+ * Listen for RoundExecuted events
121
+ * @param callback - Callback function to handle round executed events
122
+ * @returns Unwatch function
123
+ */
124
+ listenToRoundExecuted(callback: (args: {
125
+ round: bigint;
126
+ slashCount: bigint;
127
+ l1BlockHash: Hex;
128
+ }) => void): () => void;
129
+ }
130
+ /**
131
+ * Decodes a Buffer containing slash votes back into an array of numbers.
132
+ * Each vote is represented as a 2-bit value (0, 1, 2, or 3) representing slashing units.
133
+ * @dev This should live in stdlib next to encodeSlashConsensusVotes but is here since we
134
+ * do not have a dependency to stdlib from the ethereum package. We need a larger refactor to fix this.
135
+ * @param buffer - The Buffer containing encoded slash votes
136
+ * @returns An array of numbers representing the slash votes
137
+ */
138
+ export declare function decodeSlashConsensusVotes(buffer: Buffer): number[];
139
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFsbHlfc2xhc2hpbmdfcHJvcG9zZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb250cmFjdHMvdGFsbHlfc2xhc2hpbmdfcHJvcG9zZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEtBQUssV0FBVyxFQUFFLEtBQUssVUFBVSxFQUFtQixNQUFNLGlCQUFpQixDQUFDO0FBQ3JGLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUM3RCxPQUFPLEVBQUUsUUFBUSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDcEQsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBSzNELE9BQU8sRUFFTCxLQUFLLEdBQUcsRUFDUixLQUFLLEdBQUcsRUFDUixLQUFLLG1CQUFtQixFQUd6QixNQUFNLE1BQU0sQ0FBQztBQUVkOzs7R0FHRztBQUNILHFCQUFhLDZCQUE2QjthQU10QixNQUFNLEVBQUUsVUFBVTtJQUxwQyxPQUFPLENBQUMsUUFBUSxDQUFDLFFBQVEsQ0FBcUU7SUFFOUYsU0FBZ0IsSUFBSSxVQUFvQjtJQUV4QyxZQUNrQixNQUFNLEVBQUUsVUFBVSxFQUNsQyxPQUFPLEVBQUUsR0FBRyxHQUFHLFVBQVUsRUFPM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KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,GAAG,WAAW,CAStF;IAED,uDAAuD;IAC1C,WAAW,CAAC,KAAK,EAAE,MAAM;;;SAYrC;IAED;;;;OAIG;IACI,gBAAgB,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,GAAG,MAAM,IAAI,CAcjG;IAED;;;;OAIG;IACI,qBAAqB,CAC1B,QAAQ,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,GAAG,CAAA;KAAE,KAAK,IAAI,GAChF,MAAM,IAAI,CAcZ;CACF;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAelE"}
@@ -0,0 +1,313 @@
1
+ import { tryExtractEvent } from '@aztec/ethereum';
2
+ 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
+ }