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