@aztec/slasher 5.0.0-private.20260319 → 5.0.0-rc.2
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/README.md +76 -79
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +28 -28
- package/dest/factory/create_facade.d.ts +2 -2
- package/dest/factory/create_facade.d.ts.map +1 -1
- package/dest/factory/create_facade.js +1 -1
- package/dest/factory/create_implementation.d.ts +4 -6
- package/dest/factory/create_implementation.d.ts.map +1 -1
- package/dest/factory/create_implementation.js +7 -59
- package/dest/factory/get_settings.d.ts +4 -4
- package/dest/factory/get_settings.d.ts.map +1 -1
- package/dest/factory/get_settings.js +3 -3
- package/dest/factory/index.d.ts +2 -2
- package/dest/factory/index.d.ts.map +1 -1
- package/dest/factory/index.js +1 -1
- package/dest/generated/slasher-defaults.d.ts +4 -4
- package/dest/generated/slasher-defaults.js +4 -4
- package/dest/index.d.ts +6 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +5 -3
- package/dest/metrics.d.ts +7 -0
- package/dest/metrics.d.ts.map +1 -0
- package/dest/metrics.js +11 -0
- package/dest/null_slasher_client.d.ts +3 -4
- package/dest/null_slasher_client.d.ts.map +1 -1
- package/dest/null_slasher_client.js +1 -4
- package/dest/slash_offenses_collector.d.ts +6 -8
- package/dest/slash_offenses_collector.d.ts.map +1 -1
- package/dest/slash_offenses_collector.js +48 -28
- package/dest/slasher_client.d.ts +114 -0
- package/dest/slasher_client.d.ts.map +1 -0
- package/dest/{tally_slasher_client.js → slasher_client.js} +45 -40
- package/dest/slasher_client_facade.d.ts +4 -7
- package/dest/slasher_client_facade.d.ts.map +1 -1
- package/dest/slasher_client_facade.js +4 -9
- package/dest/slasher_client_interface.d.ts +7 -21
- package/dest/slasher_client_interface.d.ts.map +1 -1
- package/dest/slasher_client_interface.js +1 -4
- package/dest/stores/offenses_store.d.ts +12 -12
- package/dest/stores/offenses_store.d.ts.map +1 -1
- package/dest/stores/offenses_store.js +61 -38
- package/dest/watcher.d.ts +8 -1
- package/dest/watcher.d.ts.map +1 -1
- package/dest/watcher.js +1 -0
- package/dest/watchers/attestations_block_watcher.d.ts +26 -13
- package/dest/watchers/attestations_block_watcher.d.ts.map +1 -1
- package/dest/watchers/attestations_block_watcher.js +76 -61
- package/dest/watchers/attested_invalid_proposal_watcher.d.ts +42 -0
- package/dest/watchers/attested_invalid_proposal_watcher.d.ts.map +1 -0
- package/dest/watchers/attested_invalid_proposal_watcher.js +117 -0
- package/dest/watchers/broadcasted_invalid_checkpoint_proposal_watcher.d.ts +38 -0
- package/dest/watchers/broadcasted_invalid_checkpoint_proposal_watcher.d.ts.map +1 -0
- package/dest/watchers/broadcasted_invalid_checkpoint_proposal_watcher.js +138 -0
- package/dest/watchers/checkpoint_equivocation_watcher.d.ts +30 -0
- package/dest/watchers/checkpoint_equivocation_watcher.d.ts.map +1 -0
- package/dest/watchers/checkpoint_equivocation_watcher.js +69 -0
- package/dest/watchers/data_withholding_watcher.d.ts +63 -0
- package/dest/watchers/data_withholding_watcher.d.ts.map +1 -0
- package/dest/watchers/data_withholding_watcher.js +193 -0
- package/package.json +10 -10
- package/src/config.ts +33 -28
- package/src/factory/create_facade.ts +1 -2
- package/src/factory/create_implementation.ts +11 -117
- package/src/factory/get_settings.ts +8 -8
- package/src/factory/index.ts +1 -1
- package/src/generated/slasher-defaults.ts +4 -4
- package/src/index.ts +5 -3
- package/src/metrics.ts +19 -0
- package/src/null_slasher_client.ts +2 -6
- package/src/slash_offenses_collector.ts +62 -29
- package/src/{tally_slasher_client.ts → slasher_client.ts} +60 -48
- package/src/slasher_client_facade.ts +3 -10
- package/src/slasher_client_interface.ts +6 -21
- package/src/stores/offenses_store.ts +73 -47
- package/src/watcher.ts +8 -0
- package/src/watchers/attestations_block_watcher.ts +88 -82
- package/src/watchers/attested_invalid_proposal_watcher.ts +168 -0
- package/src/watchers/broadcasted_invalid_checkpoint_proposal_watcher.ts +192 -0
- package/src/watchers/checkpoint_equivocation_watcher.ts +96 -0
- package/src/watchers/data_withholding_watcher.ts +225 -0
- package/dest/empire_slasher_client.d.ts +0 -190
- package/dest/empire_slasher_client.d.ts.map +0 -1
- package/dest/empire_slasher_client.js +0 -564
- package/dest/stores/payloads_store.d.ts +0 -29
- package/dest/stores/payloads_store.d.ts.map +0 -1
- package/dest/stores/payloads_store.js +0 -128
- package/dest/tally_slasher_client.d.ts +0 -125
- package/dest/tally_slasher_client.d.ts.map +0 -1
- package/dest/watchers/epoch_prune_watcher.d.ts +0 -39
- package/dest/watchers/epoch_prune_watcher.d.ts.map +0 -1
- package/dest/watchers/epoch_prune_watcher.js +0 -179
- package/src/empire_slasher_client.ts +0 -649
- package/src/stores/payloads_store.ts +0 -149
- package/src/watchers/epoch_prune_watcher.ts +0 -256
package/src/config.ts
CHANGED
|
@@ -14,20 +14,24 @@ export type { SlasherConfig };
|
|
|
14
14
|
|
|
15
15
|
export const DefaultSlasherConfig: SlasherConfig = {
|
|
16
16
|
slashOverridePayload: undefined,
|
|
17
|
-
slashMinPenaltyPercentage: slasherDefaultEnv.SLASH_MIN_PENALTY_PERCENTAGE,
|
|
18
|
-
slashMaxPenaltyPercentage: slasherDefaultEnv.SLASH_MAX_PENALTY_PERCENTAGE,
|
|
19
17
|
slashValidatorsAlways: [], // Empty by default
|
|
20
18
|
slashValidatorsNever: [], // Empty by default
|
|
21
|
-
slashPrunePenalty: BigInt(slasherDefaultEnv.SLASH_PRUNE_PENALTY),
|
|
22
19
|
slashDataWithholdingPenalty: BigInt(slasherDefaultEnv.SLASH_DATA_WITHHOLDING_PENALTY),
|
|
20
|
+
slashDataWithholdingToleranceSlots: slasherDefaultEnv.SLASH_DATA_WITHHOLDING_TOLERANCE_SLOTS,
|
|
23
21
|
slashInactivityTargetPercentage: slasherDefaultEnv.SLASH_INACTIVITY_TARGET_PERCENTAGE,
|
|
24
22
|
slashInactivityConsecutiveEpochThreshold: slasherDefaultEnv.SLASH_INACTIVITY_CONSECUTIVE_EPOCH_THRESHOLD,
|
|
25
23
|
slashBroadcastedInvalidBlockPenalty: BigInt(slasherDefaultEnv.SLASH_INVALID_BLOCK_PENALTY),
|
|
24
|
+
slashBroadcastedInvalidCheckpointProposalPenalty: BigInt(slasherDefaultEnv.SLASH_INVALID_CHECKPOINT_PROPOSAL_PENALTY),
|
|
26
25
|
slashDuplicateProposalPenalty: BigInt(slasherDefaultEnv.SLASH_DUPLICATE_PROPOSAL_PENALTY),
|
|
27
26
|
slashDuplicateAttestationPenalty: BigInt(slasherDefaultEnv.SLASH_DUPLICATE_ATTESTATION_PENALTY),
|
|
28
27
|
slashInactivityPenalty: BigInt(slasherDefaultEnv.SLASH_INACTIVITY_PENALTY),
|
|
29
28
|
slashProposeInvalidAttestationsPenalty: BigInt(slasherDefaultEnv.SLASH_PROPOSE_INVALID_ATTESTATIONS_PENALTY),
|
|
30
|
-
|
|
29
|
+
slashProposeDescendantOfCheckpointWithInvalidAttestationsPenalty: BigInt(
|
|
30
|
+
slasherDefaultEnv.SLASH_PROPOSE_DESCENDANT_OF_CHECKPOINT_WITH_INVALID_ATTESTATIONS_PENALTY,
|
|
31
|
+
),
|
|
32
|
+
slashAttestInvalidCheckpointProposalPenalty: BigInt(
|
|
33
|
+
slasherDefaultEnv.SLASH_ATTEST_INVALID_CHECKPOINT_PROPOSAL_PENALTY,
|
|
34
|
+
),
|
|
31
35
|
slashUnknownPenalty: BigInt(slasherDefaultEnv.SLASH_UNKNOWN_PENALTY),
|
|
32
36
|
slashOffenseExpirationRounds: slasherDefaultEnv.SLASH_OFFENSE_EXPIRATION_ROUNDS,
|
|
33
37
|
slashMaxPayloadSize: slasherDefaultEnv.SLASH_MAX_PAYLOAD_SIZE,
|
|
@@ -40,19 +44,9 @@ export const slasherConfigMappings: ConfigMappingsType<SlasherConfig> = {
|
|
|
40
44
|
slashOverridePayload: {
|
|
41
45
|
env: 'SLASH_OVERRIDE_PAYLOAD',
|
|
42
46
|
description: 'An Ethereum address for a slash payload to vote for unconditionally.',
|
|
43
|
-
parseEnv: (val: string) =>
|
|
47
|
+
parseEnv: (val: string) => EthAddress.fromString(val),
|
|
44
48
|
defaultValue: DefaultSlasherConfig.slashOverridePayload,
|
|
45
49
|
},
|
|
46
|
-
slashMinPenaltyPercentage: {
|
|
47
|
-
env: 'SLASH_MIN_PENALTY_PERCENTAGE',
|
|
48
|
-
description: 'Minimum penalty percentage for slashing offenses (0.1 is 10%).',
|
|
49
|
-
...floatConfigHelper(DefaultSlasherConfig.slashMinPenaltyPercentage),
|
|
50
|
-
},
|
|
51
|
-
slashMaxPenaltyPercentage: {
|
|
52
|
-
env: 'SLASH_MAX_PENALTY_PERCENTAGE',
|
|
53
|
-
description: 'Maximum penalty percentage for slashing offenses (2.0 is 200%).',
|
|
54
|
-
...floatConfigHelper(DefaultSlasherConfig.slashMaxPenaltyPercentage),
|
|
55
|
-
},
|
|
56
50
|
slashValidatorsAlways: {
|
|
57
51
|
env: 'SLASH_VALIDATORS_ALWAYS',
|
|
58
52
|
description: 'Comma-separated list of validator addresses that should always be slashed.',
|
|
@@ -75,21 +69,27 @@ export const slasherConfigMappings: ConfigMappingsType<SlasherConfig> = {
|
|
|
75
69
|
.map(addr => EthAddress.fromString(addr)),
|
|
76
70
|
defaultValue: DefaultSlasherConfig.slashValidatorsNever,
|
|
77
71
|
},
|
|
78
|
-
slashPrunePenalty: {
|
|
79
|
-
env: 'SLASH_PRUNE_PENALTY',
|
|
80
|
-
description: 'Penalty amount for slashing validators of a valid pruned epoch (set to 0 to disable).',
|
|
81
|
-
...bigintConfigHelper(DefaultSlasherConfig.slashPrunePenalty),
|
|
82
|
-
},
|
|
83
72
|
slashDataWithholdingPenalty: {
|
|
84
73
|
env: 'SLASH_DATA_WITHHOLDING_PENALTY',
|
|
85
|
-
description: 'Penalty
|
|
74
|
+
description: 'Penalty for data withholding (0 records offenses without slash votes).',
|
|
86
75
|
...bigintConfigHelper(DefaultSlasherConfig.slashDataWithholdingPenalty),
|
|
87
76
|
},
|
|
77
|
+
slashDataWithholdingToleranceSlots: {
|
|
78
|
+
env: 'SLASH_DATA_WITHHOLDING_TOLERANCE_SLOTS',
|
|
79
|
+
description:
|
|
80
|
+
'Number of full L2 slots that must elapse after a checkpoint slot before declaring its txs missing and slashing its attesters for data withholding.',
|
|
81
|
+
...numberConfigHelper(DefaultSlasherConfig.slashDataWithholdingToleranceSlots),
|
|
82
|
+
},
|
|
88
83
|
slashBroadcastedInvalidBlockPenalty: {
|
|
89
84
|
env: 'SLASH_INVALID_BLOCK_PENALTY',
|
|
90
85
|
description: 'Penalty amount for slashing a validator for an invalid block proposed via p2p.',
|
|
91
86
|
...bigintConfigHelper(DefaultSlasherConfig.slashBroadcastedInvalidBlockPenalty),
|
|
92
87
|
},
|
|
88
|
+
slashBroadcastedInvalidCheckpointProposalPenalty: {
|
|
89
|
+
env: 'SLASH_INVALID_CHECKPOINT_PROPOSAL_PENALTY',
|
|
90
|
+
description: 'Penalty amount for slashing a validator for an invalid checkpoint proposal proposed via p2p.',
|
|
91
|
+
...bigintConfigHelper(DefaultSlasherConfig.slashBroadcastedInvalidCheckpointProposalPenalty),
|
|
92
|
+
},
|
|
93
93
|
slashDuplicateProposalPenalty: {
|
|
94
94
|
env: 'SLASH_DUPLICATE_PROPOSAL_PENALTY',
|
|
95
95
|
description: 'Penalty amount for slashing a validator for sending duplicate proposals.',
|
|
@@ -125,23 +125,28 @@ export const slasherConfigMappings: ConfigMappingsType<SlasherConfig> = {
|
|
|
125
125
|
},
|
|
126
126
|
slashInactivityPenalty: {
|
|
127
127
|
env: 'SLASH_INACTIVITY_PENALTY',
|
|
128
|
-
description: 'Penalty
|
|
128
|
+
description: 'Penalty for an inactive validator (0 records offenses without slash votes).',
|
|
129
129
|
...bigintConfigHelper(DefaultSlasherConfig.slashInactivityPenalty),
|
|
130
130
|
},
|
|
131
131
|
slashProposeInvalidAttestationsPenalty: {
|
|
132
132
|
env: 'SLASH_PROPOSE_INVALID_ATTESTATIONS_PENALTY',
|
|
133
|
-
description: 'Penalty
|
|
133
|
+
description: 'Penalty for proposing invalid attestations (0 records offenses without slash votes).',
|
|
134
134
|
...bigintConfigHelper(DefaultSlasherConfig.slashProposeInvalidAttestationsPenalty),
|
|
135
135
|
},
|
|
136
|
-
|
|
137
|
-
env: '
|
|
136
|
+
slashProposeDescendantOfCheckpointWithInvalidAttestationsPenalty: {
|
|
137
|
+
env: 'SLASH_PROPOSE_DESCENDANT_OF_CHECKPOINT_WITH_INVALID_ATTESTATIONS_PENALTY',
|
|
138
138
|
description:
|
|
139
|
-
'Penalty
|
|
140
|
-
...bigintConfigHelper(DefaultSlasherConfig.
|
|
139
|
+
'Penalty for publishing a checkpoint building on an invalid checkpoint (0 records offenses without slash votes).',
|
|
140
|
+
...bigintConfigHelper(DefaultSlasherConfig.slashProposeDescendantOfCheckpointWithInvalidAttestationsPenalty),
|
|
141
|
+
},
|
|
142
|
+
slashAttestInvalidCheckpointProposalPenalty: {
|
|
143
|
+
env: 'SLASH_ATTEST_INVALID_CHECKPOINT_PROPOSAL_PENALTY',
|
|
144
|
+
description: 'Penalty for attesting to an invalid checkpoint proposal (0 records offenses without slash votes).',
|
|
145
|
+
...bigintConfigHelper(DefaultSlasherConfig.slashAttestInvalidCheckpointProposalPenalty),
|
|
141
146
|
},
|
|
142
147
|
slashUnknownPenalty: {
|
|
143
148
|
env: 'SLASH_UNKNOWN_PENALTY',
|
|
144
|
-
description: 'Penalty
|
|
149
|
+
description: 'Penalty for an unknown offense (0 records offenses without slash votes).',
|
|
145
150
|
...bigintConfigHelper(DefaultSlasherConfig.slashUnknownPenalty),
|
|
146
151
|
},
|
|
147
152
|
slashOffenseExpirationRounds: {
|
|
@@ -20,7 +20,7 @@ import type { Watcher } from '../watcher.js';
|
|
|
20
20
|
/** Creates a slasher client facade that updates itself whenever the rollup slasher changes */
|
|
21
21
|
export async function createSlasherFacade(
|
|
22
22
|
config: SlasherConfig & DataStoreConfig & { ethereumSlotDuration: number },
|
|
23
|
-
l1Contracts: Pick<L1ReaderConfig
|
|
23
|
+
l1Contracts: Pick<L1ReaderConfig, 'rollupAddress' | 'registryAddress'>,
|
|
24
24
|
l1Client: ViemClient,
|
|
25
25
|
watchers: Watcher[],
|
|
26
26
|
dateProvider: DateProvider,
|
|
@@ -71,7 +71,6 @@ export async function createSlasherFacade(
|
|
|
71
71
|
updatedConfig,
|
|
72
72
|
rollup,
|
|
73
73
|
l1Client,
|
|
74
|
-
l1Contracts.slashFactoryAddress,
|
|
75
74
|
watchers,
|
|
76
75
|
epochCache,
|
|
77
76
|
dateProvider,
|
|
@@ -1,33 +1,24 @@
|
|
|
1
1
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
-
import {
|
|
3
|
-
EmpireSlashingProposerContract,
|
|
4
|
-
RollupContract,
|
|
5
|
-
TallySlashingProposerContract,
|
|
6
|
-
} from '@aztec/ethereum/contracts';
|
|
2
|
+
import { RollupContract, SlashingProposerContract } from '@aztec/ethereum/contracts';
|
|
7
3
|
import type { ViemClient } from '@aztec/ethereum/types';
|
|
8
4
|
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
9
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
10
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
11
6
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
12
7
|
import { AztecLMDBStoreV2 } from '@aztec/kv-store/lmdb-v2';
|
|
13
8
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
14
9
|
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
15
|
-
import { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
|
|
16
10
|
|
|
17
|
-
import { EmpireSlasherClient, type EmpireSlasherSettings } from '../empire_slasher_client.js';
|
|
18
11
|
import { NullSlasherClient } from '../null_slasher_client.js';
|
|
12
|
+
import { SlasherClient } from '../slasher_client.js';
|
|
19
13
|
import { SlasherOffensesStore } from '../stores/offenses_store.js';
|
|
20
|
-
import { SlasherPayloadsStore } from '../stores/payloads_store.js';
|
|
21
|
-
import { TallySlasherClient } from '../tally_slasher_client.js';
|
|
22
14
|
import type { Watcher } from '../watcher.js';
|
|
23
|
-
import {
|
|
15
|
+
import { getSlasherSettings } from './get_settings.js';
|
|
24
16
|
|
|
25
|
-
/** Creates a slasher client implementation
|
|
17
|
+
/** Creates a slasher client implementation based on the slasher proposer type in the rollup */
|
|
26
18
|
export async function createSlasherImplementation(
|
|
27
19
|
config: SlasherConfig & DataStoreConfig & { ethereumSlotDuration: number },
|
|
28
20
|
rollup: RollupContract,
|
|
29
21
|
l1Client: ViemClient,
|
|
30
|
-
slashFactoryAddress: EthAddress | undefined,
|
|
31
22
|
watchers: Watcher[],
|
|
32
23
|
epochCache: EpochCache,
|
|
33
24
|
dateProvider: DateProvider,
|
|
@@ -38,30 +29,14 @@ export async function createSlasherImplementation(
|
|
|
38
29
|
const proposer = await rollup.getSlashingProposer();
|
|
39
30
|
if (!proposer) {
|
|
40
31
|
return new NullSlasherClient(config);
|
|
41
|
-
} else if (proposer.type === 'tally') {
|
|
42
|
-
return createTallySlasher(
|
|
43
|
-
config,
|
|
44
|
-
rollup,
|
|
45
|
-
proposer,
|
|
46
|
-
watchers,
|
|
47
|
-
dateProvider,
|
|
48
|
-
epochCache,
|
|
49
|
-
kvStore,
|
|
50
|
-
rollupRegisteredAtL2Slot,
|
|
51
|
-
logger,
|
|
52
|
-
);
|
|
53
32
|
} else {
|
|
54
|
-
|
|
55
|
-
throw new Error('Cannot initialize an empire-based SlasherClient without a SlashFactory address');
|
|
56
|
-
}
|
|
57
|
-
const slashFactory = new SlashFactoryContract(l1Client, slashFactoryAddress.toString());
|
|
58
|
-
return createEmpireSlasher(
|
|
33
|
+
return createSlasher(
|
|
59
34
|
config,
|
|
60
35
|
rollup,
|
|
61
36
|
proposer,
|
|
62
|
-
slashFactory,
|
|
63
37
|
watchers,
|
|
64
38
|
dateProvider,
|
|
39
|
+
epochCache,
|
|
65
40
|
kvStore,
|
|
66
41
|
rollupRegisteredAtL2Slot,
|
|
67
42
|
logger,
|
|
@@ -69,99 +44,18 @@ export async function createSlasherImplementation(
|
|
|
69
44
|
}
|
|
70
45
|
}
|
|
71
46
|
|
|
72
|
-
async function
|
|
73
|
-
config: SlasherConfig & DataStoreConfig & { ethereumSlotDuration: number },
|
|
74
|
-
rollup: RollupContract,
|
|
75
|
-
slashingProposer: EmpireSlashingProposerContract,
|
|
76
|
-
slashFactoryContract: SlashFactoryContract,
|
|
77
|
-
watchers: Watcher[],
|
|
78
|
-
dateProvider: DateProvider,
|
|
79
|
-
kvStore: AztecLMDBStoreV2,
|
|
80
|
-
rollupRegisteredAtL2Slot: SlotNumber,
|
|
81
|
-
logger = createLogger('slasher'),
|
|
82
|
-
): Promise<EmpireSlasherClient> {
|
|
83
|
-
if (slashingProposer.type !== 'empire') {
|
|
84
|
-
throw new Error('Slashing proposer contract is not of type Empire');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const [
|
|
88
|
-
slashingExecutionDelayInRounds,
|
|
89
|
-
slashingPayloadLifetimeInRounds,
|
|
90
|
-
slashingRoundSize,
|
|
91
|
-
slashingQuorumSize,
|
|
92
|
-
epochDuration,
|
|
93
|
-
proofSubmissionEpochs,
|
|
94
|
-
l1GenesisTime,
|
|
95
|
-
slotDuration,
|
|
96
|
-
l1StartBlock,
|
|
97
|
-
slasher,
|
|
98
|
-
] = await Promise.all([
|
|
99
|
-
slashingProposer.getExecutionDelayInRounds(),
|
|
100
|
-
slashingProposer.getLifetimeInRounds(),
|
|
101
|
-
slashingProposer.getRoundSize(),
|
|
102
|
-
slashingProposer.getQuorumSize(),
|
|
103
|
-
rollup.getEpochDuration(),
|
|
104
|
-
rollup.getProofSubmissionEpochs(),
|
|
105
|
-
rollup.getL1GenesisTime(),
|
|
106
|
-
rollup.getSlotDuration(),
|
|
107
|
-
rollup.getL1StartBlock(),
|
|
108
|
-
rollup.getSlasherContract(),
|
|
109
|
-
]);
|
|
110
|
-
|
|
111
|
-
const settings: EmpireSlasherSettings = {
|
|
112
|
-
slashingExecutionDelayInRounds: Number(slashingExecutionDelayInRounds),
|
|
113
|
-
slashingPayloadLifetimeInRounds: Number(slashingPayloadLifetimeInRounds),
|
|
114
|
-
slashingRoundSize: Number(slashingRoundSize),
|
|
115
|
-
slashingQuorumSize: Number(slashingQuorumSize),
|
|
116
|
-
epochDuration: Number(epochDuration),
|
|
117
|
-
proofSubmissionEpochs: Number(proofSubmissionEpochs),
|
|
118
|
-
l1GenesisTime: l1GenesisTime,
|
|
119
|
-
slotDuration: Number(slotDuration),
|
|
120
|
-
l1StartBlock,
|
|
121
|
-
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
122
|
-
slashingAmounts: undefined,
|
|
123
|
-
rollupRegisteredAtL2Slot,
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const payloadsStore = new SlasherPayloadsStore(kvStore, {
|
|
127
|
-
slashingPayloadLifetimeInRounds: settings.slashingPayloadLifetimeInRounds,
|
|
128
|
-
});
|
|
129
|
-
const offensesStore = new SlasherOffensesStore(kvStore, {
|
|
130
|
-
...settings,
|
|
131
|
-
slashOffenseExpirationRounds: config.slashOffenseExpirationRounds,
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
return new EmpireSlasherClient(
|
|
135
|
-
config,
|
|
136
|
-
settings,
|
|
137
|
-
slashFactoryContract,
|
|
138
|
-
slashingProposer,
|
|
139
|
-
slasher!,
|
|
140
|
-
rollup,
|
|
141
|
-
watchers,
|
|
142
|
-
dateProvider,
|
|
143
|
-
offensesStore,
|
|
144
|
-
payloadsStore,
|
|
145
|
-
logger,
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async function createTallySlasher(
|
|
47
|
+
async function createSlasher(
|
|
150
48
|
config: SlasherConfig & DataStoreConfig,
|
|
151
49
|
rollup: RollupContract,
|
|
152
|
-
slashingProposer:
|
|
50
|
+
slashingProposer: SlashingProposerContract,
|
|
153
51
|
watchers: Watcher[],
|
|
154
52
|
dateProvider: DateProvider,
|
|
155
53
|
epochCache: EpochCache,
|
|
156
54
|
kvStore: AztecLMDBStoreV2,
|
|
157
55
|
rollupRegisteredAtL2Slot: SlotNumber,
|
|
158
56
|
logger = createLogger('slasher'),
|
|
159
|
-
): Promise<
|
|
160
|
-
|
|
161
|
-
throw new Error('Slashing proposer contract is not of type tally');
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const settings = { ...(await getTallySlasherSettings(rollup, slashingProposer)), rollupRegisteredAtL2Slot };
|
|
57
|
+
): Promise<SlasherClient> {
|
|
58
|
+
const settings = { ...(await getSlasherSettings(rollup, slashingProposer)), rollupRegisteredAtL2Slot };
|
|
165
59
|
const slasher = await rollup.getSlasherContract();
|
|
166
60
|
|
|
167
61
|
const offensesStore = new SlasherOffensesStore(kvStore, {
|
|
@@ -169,7 +63,7 @@ async function createTallySlasher(
|
|
|
169
63
|
slashOffenseExpirationRounds: config.slashOffenseExpirationRounds,
|
|
170
64
|
});
|
|
171
65
|
|
|
172
|
-
return new
|
|
66
|
+
return new SlasherClient(
|
|
173
67
|
config,
|
|
174
68
|
settings,
|
|
175
69
|
slashingProposer,
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { RollupContract,
|
|
1
|
+
import type { RollupContract, SlashingProposerContract } from '@aztec/ethereum/contracts';
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { SlasherSettings } from '../slasher_client.js';
|
|
4
4
|
|
|
5
|
-
export async function
|
|
5
|
+
export async function getSlasherSettings(
|
|
6
6
|
rollup: RollupContract,
|
|
7
|
-
slashingProposer?:
|
|
8
|
-
): Promise<Omit<
|
|
7
|
+
slashingProposer?: SlashingProposerContract,
|
|
8
|
+
): Promise<Omit<SlasherSettings, 'rollupRegisteredAtL2Slot'>> {
|
|
9
9
|
if (!slashingProposer) {
|
|
10
10
|
const rollupSlashingProposer = await rollup.getSlashingProposer();
|
|
11
|
-
if (!rollupSlashingProposer
|
|
12
|
-
throw new Error('Rollup slashing proposer
|
|
11
|
+
if (!rollupSlashingProposer) {
|
|
12
|
+
throw new Error('Rollup slashing proposer not found');
|
|
13
13
|
}
|
|
14
14
|
slashingProposer = rollupSlashingProposer;
|
|
15
15
|
}
|
|
@@ -40,7 +40,7 @@ export async function getTallySlasherSettings(
|
|
|
40
40
|
rollup.getTargetCommitteeSize(),
|
|
41
41
|
]);
|
|
42
42
|
|
|
43
|
-
const settings: Omit<
|
|
43
|
+
const settings: Omit<SlasherSettings, 'rollupRegisteredAtL2Slot'> = {
|
|
44
44
|
slashingExecutionDelayInRounds: Number(slashingExecutionDelayInRounds),
|
|
45
45
|
slashingRoundSize: Number(slashingRoundSize),
|
|
46
46
|
slashingRoundSizeInEpochs: Number(slashingRoundSizeInEpochs),
|
package/src/factory/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { createSlasherFacade as createSlasher } from './create_facade.js';
|
|
2
|
-
export {
|
|
2
|
+
export { getSlasherSettings } from './get_settings.js';
|
|
@@ -3,21 +3,21 @@
|
|
|
3
3
|
|
|
4
4
|
/** Default slasher configuration values from network-defaults.yml */
|
|
5
5
|
export const slasherDefaultEnv = {
|
|
6
|
-
SLASH_MIN_PENALTY_PERCENTAGE: 0.5,
|
|
7
|
-
SLASH_MAX_PENALTY_PERCENTAGE: 2,
|
|
8
6
|
SLASH_OFFENSE_EXPIRATION_ROUNDS: 4,
|
|
9
7
|
SLASH_MAX_PAYLOAD_SIZE: 80,
|
|
10
8
|
SLASH_EXECUTE_ROUNDS_LOOK_BACK: 4,
|
|
11
|
-
SLASH_PRUNE_PENALTY: 10000000000000000000,
|
|
12
9
|
SLASH_DATA_WITHHOLDING_PENALTY: 10000000000000000000,
|
|
10
|
+
SLASH_DATA_WITHHOLDING_TOLERANCE_SLOTS: 3,
|
|
13
11
|
SLASH_INACTIVITY_TARGET_PERCENTAGE: 0.9,
|
|
14
12
|
SLASH_INACTIVITY_CONSECUTIVE_EPOCH_THRESHOLD: 1,
|
|
15
13
|
SLASH_INACTIVITY_PENALTY: 10000000000000000000,
|
|
16
14
|
SLASH_PROPOSE_INVALID_ATTESTATIONS_PENALTY: 10000000000000000000,
|
|
17
|
-
|
|
15
|
+
SLASH_PROPOSE_DESCENDANT_OF_CHECKPOINT_WITH_INVALID_ATTESTATIONS_PENALTY: 10000000000000000000,
|
|
16
|
+
SLASH_ATTEST_INVALID_CHECKPOINT_PROPOSAL_PENALTY: 10000000000000000000,
|
|
18
17
|
SLASH_DUPLICATE_PROPOSAL_PENALTY: 0,
|
|
19
18
|
SLASH_DUPLICATE_ATTESTATION_PENALTY: 0,
|
|
20
19
|
SLASH_UNKNOWN_PENALTY: 10000000000000000000,
|
|
21
20
|
SLASH_INVALID_BLOCK_PENALTY: 10000000000000000000,
|
|
21
|
+
SLASH_INVALID_CHECKPOINT_PROPOSAL_PENALTY: 0,
|
|
22
22
|
SLASH_GRACE_PERIOD_L2_SLOTS: 0,
|
|
23
23
|
} as const;
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export * from './config.js';
|
|
2
|
-
export * from './watchers/
|
|
2
|
+
export * from './watchers/data_withholding_watcher.js';
|
|
3
3
|
export * from './watchers/attestations_block_watcher.js';
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
4
|
+
export * from './watchers/attested_invalid_proposal_watcher.js';
|
|
5
|
+
export * from './watchers/broadcasted_invalid_checkpoint_proposal_watcher.js';
|
|
6
|
+
export * from './watchers/checkpoint_equivocation_watcher.js';
|
|
7
|
+
export * from './slasher_client.js';
|
|
6
8
|
export * from './slash_offenses_collector.js';
|
|
7
9
|
export * from './slasher_client_interface.js';
|
|
8
10
|
export * from './factory/index.js';
|
package/src/metrics.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Metrics,
|
|
3
|
+
type TelemetryClient,
|
|
4
|
+
type UpDownCounter,
|
|
5
|
+
createUpDownCounterWithDefault,
|
|
6
|
+
} from '@aztec/telemetry-client';
|
|
7
|
+
|
|
8
|
+
export class SlasherMetrics {
|
|
9
|
+
private readonly roundExecuted: UpDownCounter;
|
|
10
|
+
|
|
11
|
+
constructor(client: TelemetryClient, name = 'Slasher') {
|
|
12
|
+
const meter = client.getMeter(name);
|
|
13
|
+
this.roundExecuted = createUpDownCounterWithDefault(meter, Metrics.SLASHER_ROUND_EXECUTED_COUNT);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public recordRoundExecuted(): void {
|
|
17
|
+
this.roundExecuted.add(1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import type { Offense, ProposerSlashAction
|
|
2
|
+
import type { Offense, ProposerSlashAction } from '@aztec/stdlib/slashing';
|
|
3
3
|
|
|
4
4
|
import type { SlasherConfig } from './config.js';
|
|
5
5
|
import type { SlasherClientInterface } from './slasher_client_interface.js';
|
|
@@ -15,15 +15,11 @@ export class NullSlasherClient implements SlasherClientInterface {
|
|
|
15
15
|
return Promise.resolve();
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
public getSlashPayloads(): Promise<SlashPayloadRound[]> {
|
|
19
|
-
return Promise.resolve([]);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
18
|
public gatherOffensesForRound(_round?: bigint): Promise<Offense[]> {
|
|
23
19
|
return Promise.resolve([]);
|
|
24
20
|
}
|
|
25
21
|
|
|
26
|
-
public
|
|
22
|
+
public getOffenses(): Promise<Offense[]> {
|
|
27
23
|
return Promise.resolve([]);
|
|
28
24
|
}
|
|
29
25
|
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { SerialQueue } from '@aztec/foundation/queue';
|
|
3
4
|
import type { Prettify } from '@aztec/foundation/types';
|
|
4
5
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
5
6
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
6
|
-
import { type Offense,
|
|
7
|
+
import { type Offense, getOffenseTypeName, getSlotForOffense } from '@aztec/stdlib/slashing';
|
|
7
8
|
|
|
8
9
|
import type { SlasherOffensesStore } from './stores/offenses_store.js';
|
|
9
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
WANT_TO_CLEAR_SLASH_EVENT,
|
|
12
|
+
WANT_TO_SLASH_EVENT,
|
|
13
|
+
type WantToClearSlashArgs,
|
|
14
|
+
type WantToSlashArgs,
|
|
15
|
+
type Watcher,
|
|
16
|
+
} from './watcher.js';
|
|
10
17
|
|
|
11
18
|
export type SlashOffensesCollectorConfig = Prettify<Pick<SlasherConfig, 'slashGracePeriodL2Slots'>>;
|
|
12
19
|
export type SlashOffensesCollectorSettings = Prettify<
|
|
@@ -24,6 +31,7 @@ export type SlashOffensesCollectorSettings = Prettify<
|
|
|
24
31
|
*/
|
|
25
32
|
export class SlashOffensesCollector {
|
|
26
33
|
private readonly unwatchCallbacks: (() => void)[] = [];
|
|
34
|
+
private readonly storeMutationQueue = new SerialQueue();
|
|
27
35
|
|
|
28
36
|
constructor(
|
|
29
37
|
private readonly config: SlashOffensesCollectorConfig,
|
|
@@ -35,28 +43,35 @@ export class SlashOffensesCollector {
|
|
|
35
43
|
|
|
36
44
|
public start() {
|
|
37
45
|
this.log.debug('Starting SlashOffensesCollector...');
|
|
46
|
+
this.storeMutationQueue.start();
|
|
38
47
|
|
|
39
|
-
// Subscribe to
|
|
48
|
+
// Subscribe to watcher slashing events.
|
|
40
49
|
for (const watcher of this.watchers) {
|
|
41
50
|
const wantToSlashCallback = (args: WantToSlashArgs[]) =>
|
|
42
|
-
|
|
51
|
+
this.enqueueStoreMutation('wantToSlash', () => this.handleWantToSlash(args));
|
|
43
52
|
watcher.on(WANT_TO_SLASH_EVENT, wantToSlashCallback);
|
|
44
53
|
this.unwatchCallbacks.push(() => watcher.removeListener(WANT_TO_SLASH_EVENT, wantToSlashCallback));
|
|
54
|
+
|
|
55
|
+
const wantToClearSlashCallback = (args: WantToClearSlashArgs[]) =>
|
|
56
|
+
this.enqueueStoreMutation('wantToClearSlash', () => this.handleWantToClearSlash(args));
|
|
57
|
+
watcher.on(WANT_TO_CLEAR_SLASH_EVENT, wantToClearSlashCallback);
|
|
58
|
+
this.unwatchCallbacks.push(() => watcher.removeListener(WANT_TO_CLEAR_SLASH_EVENT, wantToClearSlashCallback));
|
|
45
59
|
}
|
|
46
60
|
|
|
47
61
|
this.log.info('Started SlashOffensesCollector');
|
|
48
62
|
return Promise.resolve();
|
|
49
63
|
}
|
|
50
64
|
|
|
51
|
-
public stop() {
|
|
65
|
+
public async stop() {
|
|
52
66
|
this.log.debug('Stopping SlashOffensesCollector...');
|
|
53
67
|
|
|
54
68
|
for (const unwatchCallback of this.unwatchCallbacks) {
|
|
55
69
|
unwatchCallback();
|
|
56
70
|
}
|
|
57
71
|
|
|
72
|
+
await this.storeMutationQueue.end();
|
|
73
|
+
|
|
58
74
|
this.log.info('SlashOffensesCollector stopped');
|
|
59
|
-
return Promise.resolve();
|
|
60
75
|
}
|
|
61
76
|
|
|
62
77
|
/**
|
|
@@ -66,32 +81,47 @@ export class SlashOffensesCollector {
|
|
|
66
81
|
*/
|
|
67
82
|
public async handleWantToSlash(args: WantToSlashArgs[]) {
|
|
68
83
|
for (const arg of args) {
|
|
69
|
-
const
|
|
84
|
+
const offense: Offense = {
|
|
70
85
|
validator: arg.validator,
|
|
71
86
|
amount: arg.amount,
|
|
72
87
|
offenseType: arg.offenseType,
|
|
73
88
|
epochOrSlot: arg.epochOrSlot,
|
|
74
89
|
};
|
|
75
90
|
|
|
76
|
-
if (this.shouldSkipOffense(
|
|
77
|
-
this.log.verbose('Skipping offense during grace period',
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (await this.offensesStore.hasOffense(pendingOffense)) {
|
|
82
|
-
this.log.debug('Skipping repeated offense', pendingOffense);
|
|
91
|
+
if (this.shouldSkipOffense(offense)) {
|
|
92
|
+
this.log.verbose('Skipping offense during grace period', this.getOffenseLogData(offense));
|
|
83
93
|
continue;
|
|
84
94
|
}
|
|
85
95
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
this.
|
|
96
|
+
const added = await this.offensesStore.addOffense(offense);
|
|
97
|
+
if (added) {
|
|
98
|
+
if (this.settings.slashingAmounts) {
|
|
99
|
+
const minSlash = this.settings.slashingAmounts[0];
|
|
100
|
+
if (arg.amount < minSlash) {
|
|
101
|
+
this.log.warn(
|
|
102
|
+
`Offense amount ${arg.amount} is below minimum slashing amount ${minSlash}`,
|
|
103
|
+
this.getOffenseLogData(offense),
|
|
104
|
+
);
|
|
105
|
+
}
|
|
90
106
|
}
|
|
107
|
+
|
|
108
|
+
this.log.info(`Adding pending offense for validator ${arg.validator}`, this.getOffenseLogData(offense));
|
|
109
|
+
} else {
|
|
110
|
+
this.log.debug('Skipping repeated offense', this.getOffenseLogData(offense));
|
|
91
111
|
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
92
114
|
|
|
93
|
-
|
|
94
|
-
|
|
115
|
+
public async handleWantToClearSlash(args: WantToClearSlashArgs[]) {
|
|
116
|
+
for (const arg of args) {
|
|
117
|
+
const cleared = await this.offensesStore.clearOffenses(arg);
|
|
118
|
+
if (cleared > 0) {
|
|
119
|
+
this.log.info(`Cleared ${cleared} pending offenses`, {
|
|
120
|
+
offenseType: getOffenseTypeName(arg.offenseType),
|
|
121
|
+
epochOrSlot: arg.epochOrSlot,
|
|
122
|
+
validators: arg.validators?.map(validator => validator.toString()),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
95
125
|
}
|
|
96
126
|
}
|
|
97
127
|
|
|
@@ -106,18 +136,21 @@ export class SlashOffensesCollector {
|
|
|
106
136
|
}
|
|
107
137
|
}
|
|
108
138
|
|
|
109
|
-
/**
|
|
110
|
-
* Marks offenses as slashed (no longer pending)
|
|
111
|
-
* @param offenses - The offenses to mark as slashed
|
|
112
|
-
*/
|
|
113
|
-
public markAsSlashed(offenses: OffenseIdentifier[]) {
|
|
114
|
-
this.log.verbose(`Marking offenses as slashed`, { offenses });
|
|
115
|
-
return this.offensesStore.markAsSlashed(offenses);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
139
|
/** Returns whether to skip an offense if it happened during the grace period after the network upgrade */
|
|
119
140
|
private shouldSkipOffense(offense: Offense): boolean {
|
|
120
141
|
const offenseSlot = getSlotForOffense(offense, this.settings);
|
|
121
142
|
return offenseSlot < this.settings.rollupRegisteredAtL2Slot + this.config.slashGracePeriodL2Slots;
|
|
122
143
|
}
|
|
144
|
+
|
|
145
|
+
private getOffenseLogData(offense: Offense) {
|
|
146
|
+
return {
|
|
147
|
+
...offense,
|
|
148
|
+
validator: offense.validator.toString(),
|
|
149
|
+
offenseType: getOffenseTypeName(offense.offenseType),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private enqueueStoreMutation(label: string, callback: () => Promise<void>) {
|
|
154
|
+
void this.storeMutationQueue.put(callback).catch(err => this.log.error(`Error handling ${label}`, err));
|
|
155
|
+
}
|
|
123
156
|
}
|