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

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