@aztec/slasher 0.0.1-commit.d431d1c → 0.0.1-commit.d939eb5aa
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 +51 -65
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +14 -14
- package/dest/factory/create_facade.d.ts +3 -3
- package/dest/factory/create_facade.d.ts.map +1 -1
- package/dest/factory/create_facade.js +26 -3
- package/dest/factory/create_implementation.d.ts +6 -7
- package/dest/factory/create_implementation.d.ts.map +1 -1
- package/dest/factory/create_implementation.js +8 -56
- 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 +3 -3
- package/dest/generated/slasher-defaults.js +3 -3
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- 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 +5 -8
- package/dest/slash_offenses_collector.d.ts.map +1 -1
- package/dest/slash_offenses_collector.js +9 -18
- package/dest/slasher_client.d.ts +112 -0
- package/dest/slasher_client.d.ts.map +1 -0
- package/dest/{tally_slasher_client.js → slasher_client.js} +30 -39
- package/dest/slasher_client_facade.d.ts +6 -8
- package/dest/slasher_client_facade.d.ts.map +1 -1
- package/dest/slasher_client_facade.js +6 -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 +6 -12
- package/dest/stores/offenses_store.d.ts.map +1 -1
- package/dest/stores/offenses_store.js +8 -25
- package/dest/watchers/epoch_prune_watcher.d.ts +7 -6
- package/dest/watchers/epoch_prune_watcher.d.ts.map +1 -1
- package/dest/watchers/epoch_prune_watcher.js +47 -26
- package/package.json +9 -9
- package/src/config.ts +16 -14
- package/src/factory/create_facade.ts +33 -5
- package/src/factory/create_implementation.ts +24 -105
- package/src/factory/get_settings.ts +8 -8
- package/src/factory/index.ts +1 -1
- package/src/generated/slasher-defaults.ts +3 -3
- package/src/index.ts +1 -2
- package/src/null_slasher_client.ts +2 -6
- package/src/slash_offenses_collector.ts +16 -20
- package/src/{tally_slasher_client.ts → slasher_client.ts} +37 -48
- package/src/slasher_client_facade.ts +6 -11
- package/src/slasher_client_interface.ts +6 -21
- package/src/stores/offenses_store.ts +11 -34
- package/src/watchers/epoch_prune_watcher.ts +64 -28
- 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 -572
- 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 -125
- package/dest/tally_slasher_client.d.ts +0 -125
- package/dest/tally_slasher_client.d.ts.map +0 -1
- package/src/empire_slasher_client.ts +0 -657
- package/src/stores/payloads_store.ts +0 -146
|
@@ -1,142 +1,61 @@
|
|
|
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
|
-
import {
|
|
4
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
9
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
10
6
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
11
|
-
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
12
7
|
import { AztecLMDBStoreV2 } from '@aztec/kv-store/lmdb-v2';
|
|
13
8
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
14
|
-
import {
|
|
9
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
15
10
|
|
|
16
|
-
import { EmpireSlasherClient, type EmpireSlasherSettings } from '../empire_slasher_client.js';
|
|
17
11
|
import { NullSlasherClient } from '../null_slasher_client.js';
|
|
12
|
+
import { SlasherClient } from '../slasher_client.js';
|
|
18
13
|
import { SlasherOffensesStore } from '../stores/offenses_store.js';
|
|
19
|
-
import { SlasherPayloadsStore } from '../stores/payloads_store.js';
|
|
20
|
-
import { TallySlasherClient } from '../tally_slasher_client.js';
|
|
21
14
|
import type { Watcher } from '../watcher.js';
|
|
22
|
-
import {
|
|
15
|
+
import { getSlasherSettings } from './get_settings.js';
|
|
23
16
|
|
|
24
|
-
/** Creates a slasher client implementation
|
|
17
|
+
/** Creates a slasher client implementation based on the slasher proposer type in the rollup */
|
|
25
18
|
export async function createSlasherImplementation(
|
|
26
19
|
config: SlasherConfig & DataStoreConfig & { ethereumSlotDuration: number },
|
|
27
20
|
rollup: RollupContract,
|
|
28
21
|
l1Client: ViemClient,
|
|
29
|
-
slashFactoryAddress: EthAddress | undefined,
|
|
30
22
|
watchers: Watcher[],
|
|
31
23
|
epochCache: EpochCache,
|
|
32
24
|
dateProvider: DateProvider,
|
|
33
25
|
kvStore: AztecLMDBStoreV2,
|
|
26
|
+
rollupRegisteredAtL2Slot: SlotNumber,
|
|
34
27
|
logger = createLogger('slasher'),
|
|
35
28
|
) {
|
|
36
29
|
const proposer = await rollup.getSlashingProposer();
|
|
37
30
|
if (!proposer) {
|
|
38
31
|
return new NullSlasherClient(config);
|
|
39
|
-
} else if (proposer.type === 'tally') {
|
|
40
|
-
return createTallySlasher(config, rollup, proposer, watchers, dateProvider, epochCache, kvStore, logger);
|
|
41
32
|
} else {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
return createSlasher(
|
|
34
|
+
config,
|
|
35
|
+
rollup,
|
|
36
|
+
proposer,
|
|
37
|
+
watchers,
|
|
38
|
+
dateProvider,
|
|
39
|
+
epochCache,
|
|
40
|
+
kvStore,
|
|
41
|
+
rollupRegisteredAtL2Slot,
|
|
42
|
+
logger,
|
|
43
|
+
);
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
46
|
|
|
50
|
-
async function
|
|
51
|
-
config: SlasherConfig & DataStoreConfig & { ethereumSlotDuration: number },
|
|
52
|
-
rollup: RollupContract,
|
|
53
|
-
slashingProposer: EmpireSlashingProposerContract,
|
|
54
|
-
slashFactoryContract: SlashFactoryContract,
|
|
55
|
-
watchers: Watcher[],
|
|
56
|
-
dateProvider: DateProvider,
|
|
57
|
-
kvStore: AztecLMDBStoreV2,
|
|
58
|
-
logger = createLogger('slasher'),
|
|
59
|
-
): Promise<EmpireSlasherClient> {
|
|
60
|
-
if (slashingProposer.type !== 'empire') {
|
|
61
|
-
throw new Error('Slashing proposer contract is not of type Empire');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const [
|
|
65
|
-
slashingExecutionDelayInRounds,
|
|
66
|
-
slashingPayloadLifetimeInRounds,
|
|
67
|
-
slashingRoundSize,
|
|
68
|
-
slashingQuorumSize,
|
|
69
|
-
epochDuration,
|
|
70
|
-
proofSubmissionEpochs,
|
|
71
|
-
l1GenesisTime,
|
|
72
|
-
slotDuration,
|
|
73
|
-
l1StartBlock,
|
|
74
|
-
slasher,
|
|
75
|
-
] = await Promise.all([
|
|
76
|
-
slashingProposer.getExecutionDelayInRounds(),
|
|
77
|
-
slashingProposer.getLifetimeInRounds(),
|
|
78
|
-
slashingProposer.getRoundSize(),
|
|
79
|
-
slashingProposer.getQuorumSize(),
|
|
80
|
-
rollup.getEpochDuration(),
|
|
81
|
-
rollup.getProofSubmissionEpochs(),
|
|
82
|
-
rollup.getL1GenesisTime(),
|
|
83
|
-
rollup.getSlotDuration(),
|
|
84
|
-
rollup.getL1StartBlock(),
|
|
85
|
-
rollup.getSlasherContract(),
|
|
86
|
-
]);
|
|
87
|
-
|
|
88
|
-
const settings: EmpireSlasherSettings = {
|
|
89
|
-
slashingExecutionDelayInRounds: Number(slashingExecutionDelayInRounds),
|
|
90
|
-
slashingPayloadLifetimeInRounds: Number(slashingPayloadLifetimeInRounds),
|
|
91
|
-
slashingRoundSize: Number(slashingRoundSize),
|
|
92
|
-
slashingQuorumSize: Number(slashingQuorumSize),
|
|
93
|
-
epochDuration: Number(epochDuration),
|
|
94
|
-
proofSubmissionEpochs: Number(proofSubmissionEpochs),
|
|
95
|
-
l1GenesisTime: l1GenesisTime,
|
|
96
|
-
slotDuration: Number(slotDuration),
|
|
97
|
-
l1StartBlock,
|
|
98
|
-
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
99
|
-
slashingAmounts: undefined,
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const payloadsStore = new SlasherPayloadsStore(kvStore, {
|
|
103
|
-
slashingPayloadLifetimeInRounds: settings.slashingPayloadLifetimeInRounds,
|
|
104
|
-
});
|
|
105
|
-
const offensesStore = new SlasherOffensesStore(kvStore, {
|
|
106
|
-
...settings,
|
|
107
|
-
slashOffenseExpirationRounds: config.slashOffenseExpirationRounds,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
return new EmpireSlasherClient(
|
|
111
|
-
config,
|
|
112
|
-
settings,
|
|
113
|
-
slashFactoryContract,
|
|
114
|
-
slashingProposer,
|
|
115
|
-
slasher!,
|
|
116
|
-
rollup,
|
|
117
|
-
watchers,
|
|
118
|
-
dateProvider,
|
|
119
|
-
offensesStore,
|
|
120
|
-
payloadsStore,
|
|
121
|
-
logger,
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async function createTallySlasher(
|
|
47
|
+
async function createSlasher(
|
|
126
48
|
config: SlasherConfig & DataStoreConfig,
|
|
127
49
|
rollup: RollupContract,
|
|
128
|
-
slashingProposer:
|
|
50
|
+
slashingProposer: SlashingProposerContract,
|
|
129
51
|
watchers: Watcher[],
|
|
130
52
|
dateProvider: DateProvider,
|
|
131
53
|
epochCache: EpochCache,
|
|
132
54
|
kvStore: AztecLMDBStoreV2,
|
|
55
|
+
rollupRegisteredAtL2Slot: SlotNumber,
|
|
133
56
|
logger = createLogger('slasher'),
|
|
134
|
-
): Promise<
|
|
135
|
-
|
|
136
|
-
throw new Error('Slashing proposer contract is not of type tally');
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const settings = await getTallySlasherSettings(rollup, slashingProposer);
|
|
57
|
+
): Promise<SlasherClient> {
|
|
58
|
+
const settings = { ...(await getSlasherSettings(rollup, slashingProposer)), rollupRegisteredAtL2Slot };
|
|
140
59
|
const slasher = await rollup.getSlasherContract();
|
|
141
60
|
|
|
142
61
|
const offensesStore = new SlasherOffensesStore(kvStore, {
|
|
@@ -144,7 +63,7 @@ async function createTallySlasher(
|
|
|
144
63
|
slashOffenseExpirationRounds: config.slashOffenseExpirationRounds,
|
|
145
64
|
});
|
|
146
65
|
|
|
147
|
-
return new
|
|
66
|
+
return new SlasherClient(
|
|
148
67
|
config,
|
|
149
68
|
settings,
|
|
150
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<
|
|
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:
|
|
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,10 +3,8 @@
|
|
|
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
|
-
SLASH_MAX_PAYLOAD_SIZE:
|
|
7
|
+
SLASH_MAX_PAYLOAD_SIZE: 80,
|
|
10
8
|
SLASH_EXECUTE_ROUNDS_LOOK_BACK: 4,
|
|
11
9
|
SLASH_PRUNE_PENALTY: 10000000000000000000,
|
|
12
10
|
SLASH_DATA_WITHHOLDING_PENALTY: 10000000000000000000,
|
|
@@ -15,6 +13,8 @@ export const slasherDefaultEnv = {
|
|
|
15
13
|
SLASH_INACTIVITY_PENALTY: 10000000000000000000,
|
|
16
14
|
SLASH_PROPOSE_INVALID_ATTESTATIONS_PENALTY: 10000000000000000000,
|
|
17
15
|
SLASH_ATTEST_DESCENDANT_OF_INVALID_PENALTY: 10000000000000000000,
|
|
16
|
+
SLASH_DUPLICATE_PROPOSAL_PENALTY: 0,
|
|
17
|
+
SLASH_DUPLICATE_ATTESTATION_PENALTY: 0,
|
|
18
18
|
SLASH_UNKNOWN_PENALTY: 10000000000000000000,
|
|
19
19
|
SLASH_INVALID_BLOCK_PENALTY: 10000000000000000000,
|
|
20
20
|
SLASH_GRACE_PERIOD_L2_SLOTS: 0,
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export * from './config.js';
|
|
2
2
|
export * from './watchers/epoch_prune_watcher.js';
|
|
3
3
|
export * from './watchers/attestations_block_watcher.js';
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './tally_slasher_client.js';
|
|
4
|
+
export * from './slasher_client.js';
|
|
6
5
|
export * from './slash_offenses_collector.js';
|
|
7
6
|
export * from './slasher_client_interface.js';
|
|
8
7
|
export * from './factory/index.js';
|
|
@@ -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,15 +1,20 @@
|
|
|
1
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
3
|
import type { Prettify } from '@aztec/foundation/types';
|
|
3
4
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
4
5
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
5
|
-
import { type Offense,
|
|
6
|
+
import { type Offense, getSlotForOffense } from '@aztec/stdlib/slashing';
|
|
6
7
|
|
|
7
8
|
import type { SlasherOffensesStore } from './stores/offenses_store.js';
|
|
8
9
|
import { WANT_TO_SLASH_EVENT, type WantToSlashArgs, type Watcher } from './watcher.js';
|
|
9
10
|
|
|
10
11
|
export type SlashOffensesCollectorConfig = Prettify<Pick<SlasherConfig, 'slashGracePeriodL2Slots'>>;
|
|
11
12
|
export type SlashOffensesCollectorSettings = Prettify<
|
|
12
|
-
Pick<L1RollupConstants, 'epochDuration'> & {
|
|
13
|
+
Pick<L1RollupConstants, 'epochDuration'> & {
|
|
14
|
+
slashingAmounts: [bigint, bigint, bigint] | undefined;
|
|
15
|
+
/** L2 slot at which the rollup was registered as canonical in the Registry. Used to anchor the slash grace period. */
|
|
16
|
+
rollupRegisteredAtL2Slot: SlotNumber;
|
|
17
|
+
}
|
|
13
18
|
>;
|
|
14
19
|
|
|
15
20
|
/**
|
|
@@ -61,20 +66,20 @@ export class SlashOffensesCollector {
|
|
|
61
66
|
*/
|
|
62
67
|
public async handleWantToSlash(args: WantToSlashArgs[]) {
|
|
63
68
|
for (const arg of args) {
|
|
64
|
-
const
|
|
69
|
+
const offense: Offense = {
|
|
65
70
|
validator: arg.validator,
|
|
66
71
|
amount: arg.amount,
|
|
67
72
|
offenseType: arg.offenseType,
|
|
68
73
|
epochOrSlot: arg.epochOrSlot,
|
|
69
74
|
};
|
|
70
75
|
|
|
71
|
-
if (this.shouldSkipOffense(
|
|
72
|
-
this.log.verbose('Skipping offense during grace period',
|
|
76
|
+
if (this.shouldSkipOffense(offense)) {
|
|
77
|
+
this.log.verbose('Skipping offense during grace period', offense);
|
|
73
78
|
continue;
|
|
74
79
|
}
|
|
75
80
|
|
|
76
|
-
if (await this.offensesStore.hasOffense(
|
|
77
|
-
this.log.debug('Skipping repeated offense',
|
|
81
|
+
if (await this.offensesStore.hasOffense(offense)) {
|
|
82
|
+
this.log.debug('Skipping repeated offense', offense);
|
|
78
83
|
continue;
|
|
79
84
|
}
|
|
80
85
|
|
|
@@ -85,8 +90,8 @@ export class SlashOffensesCollector {
|
|
|
85
90
|
}
|
|
86
91
|
}
|
|
87
92
|
|
|
88
|
-
this.log.info(`Adding pending offense for validator ${arg.validator}`,
|
|
89
|
-
await this.offensesStore.
|
|
93
|
+
this.log.info(`Adding pending offense for validator ${arg.validator}`, offense);
|
|
94
|
+
await this.offensesStore.addOffense(offense);
|
|
90
95
|
}
|
|
91
96
|
}
|
|
92
97
|
|
|
@@ -101,18 +106,9 @@ export class SlashOffensesCollector {
|
|
|
101
106
|
}
|
|
102
107
|
}
|
|
103
108
|
|
|
104
|
-
/**
|
|
105
|
-
* Marks offenses as slashed (no longer pending)
|
|
106
|
-
* @param offenses - The offenses to mark as slashed
|
|
107
|
-
*/
|
|
108
|
-
public markAsSlashed(offenses: OffenseIdentifier[]) {
|
|
109
|
-
this.log.verbose(`Marking offenses as slashed`, { offenses });
|
|
110
|
-
return this.offensesStore.markAsSlashed(offenses);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** Returns whether to skip an offense if it happened during the grace period at the beginning of the chain */
|
|
109
|
+
/** Returns whether to skip an offense if it happened during the grace period after the network upgrade */
|
|
114
110
|
private shouldSkipOffense(offense: Offense): boolean {
|
|
115
111
|
const offenseSlot = getSlotForOffense(offense, this.settings);
|
|
116
|
-
return offenseSlot < this.config.slashGracePeriodL2Slots;
|
|
112
|
+
return offenseSlot < this.settings.rollupRegisteredAtL2Slot + this.config.slashGracePeriodL2Slots;
|
|
117
113
|
}
|
|
118
114
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { EthAddress } from '@aztec/aztec.js/addresses';
|
|
2
2
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
3
|
-
import { RollupContract, SlasherContract,
|
|
3
|
+
import { RollupContract, SlasherContract, SlashingProposerContract } from '@aztec/ethereum/contracts';
|
|
4
4
|
import { maxBigint } from '@aztec/foundation/bigint';
|
|
5
5
|
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
6
6
|
import { compactArray, partition, times } from '@aztec/foundation/collection';
|
|
7
7
|
import { createLogger } from '@aztec/foundation/log';
|
|
8
|
-
import { sleep } from '@aztec/foundation/sleep';
|
|
9
8
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
10
9
|
import type { Prettify } from '@aztec/foundation/types';
|
|
11
10
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
@@ -14,7 +13,6 @@ import {
|
|
|
14
13
|
OffenseType,
|
|
15
14
|
type ProposerSlashAction,
|
|
16
15
|
type ProposerSlashActionProvider,
|
|
17
|
-
type SlashPayloadRound,
|
|
18
16
|
getEpochsForRound,
|
|
19
17
|
getSlashConsensusVotesFromOffenses,
|
|
20
18
|
} from '@aztec/stdlib/slashing';
|
|
@@ -31,8 +29,8 @@ import type { SlasherClientInterface } from './slasher_client_interface.js';
|
|
|
31
29
|
import type { SlasherOffensesStore } from './stores/offenses_store.js';
|
|
32
30
|
import type { Watcher } from './watcher.js';
|
|
33
31
|
|
|
34
|
-
/** Settings used in the
|
|
35
|
-
export type
|
|
32
|
+
/** Settings used in the slasher client, loaded from the L1 contracts during initialization */
|
|
33
|
+
export type SlasherSettings = Prettify<
|
|
36
34
|
SlashRoundMonitorSettings &
|
|
37
35
|
SlashOffensesCollectorSettings & {
|
|
38
36
|
slashingLifetimeInRounds: number;
|
|
@@ -46,11 +44,14 @@ export type TallySlasherSettings = Prettify<
|
|
|
46
44
|
}
|
|
47
45
|
>;
|
|
48
46
|
|
|
49
|
-
export type
|
|
50
|
-
Pick<
|
|
47
|
+
export type SlasherClientConfig = SlashOffensesCollectorConfig &
|
|
48
|
+
Pick<
|
|
49
|
+
SlasherConfig,
|
|
50
|
+
'slashValidatorsAlways' | 'slashValidatorsNever' | 'slashExecuteRoundsLookBack' | 'slashMaxPayloadSize'
|
|
51
|
+
>;
|
|
51
52
|
|
|
52
53
|
/**
|
|
53
|
-
* The
|
|
54
|
+
* The Slasher client is responsible for managing slashable offenses using
|
|
54
55
|
* the consensus-based slashing model where proposers vote on individual validator offenses.
|
|
55
56
|
*
|
|
56
57
|
* The client subscribes to several slash watchers that emit offenses and tracks them. When the slasher is the
|
|
@@ -74,22 +75,16 @@ export type TallySlasherClientConfig = SlashOffensesCollectorConfig &
|
|
|
74
75
|
* - Validators that reach the quorum threshold are slashed. A vote for slashing N units is also considered
|
|
75
76
|
* a vote for slashing N-1, N-2, ..., 1 units. The system slashes for the largest amount that reaches quorum.
|
|
76
77
|
* - The client monitors executable rounds and triggers execution when appropriate.
|
|
77
|
-
*
|
|
78
|
-
* Differences from Empire model
|
|
79
|
-
* - No fixed slash payloads - votes are for individual validator offenses encoded in bytes
|
|
80
|
-
* - The L1 contract determines which offenses reach quorum rather than nodes agreeing on a payload
|
|
81
|
-
* - Proposers vote directly on which validators to slash and by how much
|
|
82
|
-
* - Uses a slash offset to vote on validators from past rounds (e.g., round N votes on round N-2)
|
|
83
78
|
*/
|
|
84
|
-
export class
|
|
79
|
+
export class SlasherClient implements ProposerSlashActionProvider, SlasherClientInterface {
|
|
85
80
|
protected unwatchCallbacks: (() => void)[] = [];
|
|
86
81
|
protected roundMonitor: SlashRoundMonitor;
|
|
87
82
|
protected offensesCollector: SlashOffensesCollector;
|
|
88
83
|
|
|
89
84
|
constructor(
|
|
90
|
-
private config:
|
|
91
|
-
private settings:
|
|
92
|
-
private
|
|
85
|
+
private config: SlasherClientConfig,
|
|
86
|
+
private settings: SlasherSettings,
|
|
87
|
+
private slashingProposer: SlashingProposerContract,
|
|
93
88
|
private slasher: SlasherContract,
|
|
94
89
|
private rollup: RollupContract,
|
|
95
90
|
watchers: Watcher[],
|
|
@@ -103,14 +98,14 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
103
98
|
}
|
|
104
99
|
|
|
105
100
|
public async start() {
|
|
106
|
-
this.log.debug('Starting
|
|
101
|
+
this.log.debug('Starting slasher client...');
|
|
107
102
|
|
|
108
103
|
this.roundMonitor.start();
|
|
109
104
|
await this.offensesCollector.start();
|
|
110
105
|
|
|
111
106
|
// Listen for RoundExecuted events
|
|
112
107
|
this.unwatchCallbacks.push(
|
|
113
|
-
this.
|
|
108
|
+
this.slashingProposer.listenToRoundExecuted(
|
|
114
109
|
({ round, slashCount, l1BlockHash }) =>
|
|
115
110
|
void this.handleRoundExecuted(round, slashCount, l1BlockHash).catch(err =>
|
|
116
111
|
this.log.error('Error handling round executed', err),
|
|
@@ -121,15 +116,13 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
121
116
|
// Check for round changes
|
|
122
117
|
this.unwatchCallbacks.push(this.roundMonitor.listenToNewRound(round => this.handleNewRound(round)));
|
|
123
118
|
|
|
124
|
-
this.log.info(`Started
|
|
119
|
+
this.log.info(`Started slasher client`);
|
|
125
120
|
return Promise.resolve();
|
|
126
121
|
}
|
|
127
122
|
|
|
128
|
-
/**
|
|
129
|
-
* Stop the tally slasher client
|
|
130
|
-
*/
|
|
123
|
+
/** Stop the slasher client */
|
|
131
124
|
public async stop() {
|
|
132
|
-
this.log.debug('Stopping
|
|
125
|
+
this.log.debug('Stopping slasher client...');
|
|
133
126
|
|
|
134
127
|
for (const unwatchCallback of this.unwatchCallbacks) {
|
|
135
128
|
unwatchCallback();
|
|
@@ -138,9 +131,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
138
131
|
this.roundMonitor.stop();
|
|
139
132
|
await this.offensesCollector.stop();
|
|
140
133
|
|
|
141
|
-
|
|
142
|
-
await sleep(2000);
|
|
143
|
-
this.log.info('Tally Slasher client stopped');
|
|
134
|
+
this.log.info('Slasher client stopped');
|
|
144
135
|
}
|
|
145
136
|
|
|
146
137
|
/** Returns the current config */
|
|
@@ -155,11 +146,11 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
155
146
|
|
|
156
147
|
/** Triggered on a time basis when we enter a new slashing round. Clears expired offenses. */
|
|
157
148
|
protected async handleNewRound(round: bigint) {
|
|
158
|
-
this.log.info(`Starting new
|
|
149
|
+
this.log.info(`Starting new slashing round ${round}`);
|
|
159
150
|
await this.offensesCollector.handleNewRound(round);
|
|
160
151
|
}
|
|
161
152
|
|
|
162
|
-
/** Called when we see a RoundExecuted event on the
|
|
153
|
+
/** Called when we see a RoundExecuted event on the SlashingProposer (just for logging). */
|
|
163
154
|
protected async handleRoundExecuted(round: bigint, slashCount: bigint, l1BlockHash: Hex) {
|
|
164
155
|
const slashes = await this.rollup.getSlashEvents(l1BlockHash);
|
|
165
156
|
this.log.info(`Slashing round ${round} has been executed with ${slashCount} slashes`, { slashes });
|
|
@@ -240,7 +231,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
240
231
|
this.log.debug(`Testing if slashing round ${executableRound} is executable`, logData);
|
|
241
232
|
|
|
242
233
|
try {
|
|
243
|
-
const roundInfo = await this.
|
|
234
|
+
const roundInfo = await this.slashingProposer.getRound(executableRound);
|
|
244
235
|
logData = { ...logData, roundInfo };
|
|
245
236
|
if (roundInfo.isExecuted) {
|
|
246
237
|
this.log.verbose(`Round ${executableRound} has already been executed`, logData);
|
|
@@ -254,7 +245,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
254
245
|
}
|
|
255
246
|
|
|
256
247
|
// Check if round is ready to execute at the given slot
|
|
257
|
-
const isReadyToExecute = await this.
|
|
248
|
+
const isReadyToExecute = await this.slashingProposer.isRoundReadyToExecute(executableRound, slotNumber);
|
|
258
249
|
if (!isReadyToExecute) {
|
|
259
250
|
this.log.warn(
|
|
260
251
|
`Round ${executableRound} is not ready to execute at slot ${slotNumber} according to contract check`,
|
|
@@ -264,14 +255,14 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
264
255
|
}
|
|
265
256
|
|
|
266
257
|
// Check if the round yields any slashing at all
|
|
267
|
-
const { actions: slashActions, committees } = await this.
|
|
258
|
+
const { actions: slashActions, committees } = await this.slashingProposer.getTally(executableRound);
|
|
268
259
|
if (slashActions.length === 0) {
|
|
269
260
|
this.log.verbose(`Round ${executableRound} does not resolve in any slashing`, logData);
|
|
270
261
|
return undefined;
|
|
271
262
|
}
|
|
272
263
|
|
|
273
264
|
// Check if the slash payload is vetoed
|
|
274
|
-
const payload = await this.
|
|
265
|
+
const payload = await this.slashingProposer.getPayload(executableRound);
|
|
275
266
|
const isVetoed = await this.slasher.isPayloadVetoed(payload.address);
|
|
276
267
|
if (isVetoed) {
|
|
277
268
|
this.log.warn(`Round ${executableRound} payload is vetoed (skipping execution)`, {
|
|
@@ -281,8 +272,12 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
281
272
|
return undefined;
|
|
282
273
|
}
|
|
283
274
|
|
|
275
|
+
const slashActionsWithAmounts = slashActions.map(action => ({
|
|
276
|
+
validator: action.validator.toString(),
|
|
277
|
+
slashAmount: action.slashAmount.toString(),
|
|
278
|
+
}));
|
|
284
279
|
this.log.info(`Round ${executableRound} is ready to execute with ${slashActions.length} slashes`, {
|
|
285
|
-
slashActions,
|
|
280
|
+
slashActions: slashActionsWithAmounts,
|
|
286
281
|
payloadAddress: payload.address.toString(),
|
|
287
282
|
...logData,
|
|
288
283
|
});
|
|
@@ -357,11 +352,13 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
357
352
|
|
|
358
353
|
const committees = await this.collectCommitteesActiveDuringRound(slashedRound);
|
|
359
354
|
const epochsForCommittees = getEpochsForRound(slashedRound, this.settings);
|
|
355
|
+
const { slashMaxPayloadSize } = this.config;
|
|
360
356
|
const votes = getSlashConsensusVotesFromOffenses(
|
|
361
357
|
offensesToSlash,
|
|
362
358
|
committees,
|
|
363
359
|
epochsForCommittees.map(e => BigInt(e)),
|
|
364
|
-
this.settings,
|
|
360
|
+
{ ...this.settings, maxSlashedValidators: slashMaxPayloadSize },
|
|
361
|
+
this.log,
|
|
365
362
|
);
|
|
366
363
|
if (votes.every(v => v === 0)) {
|
|
367
364
|
this.log.warn(`Computed votes for offenses are all zero. Skipping vote.`, {
|
|
@@ -399,17 +396,9 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
399
396
|
);
|
|
400
397
|
}
|
|
401
398
|
|
|
402
|
-
/**
|
|
403
|
-
* Get slash payloads is NOT SUPPORTED in tally model
|
|
404
|
-
* @throws Error indicating this operation is not supported
|
|
405
|
-
*/
|
|
406
|
-
public getSlashPayloads(): Promise<SlashPayloadRound[]> {
|
|
407
|
-
return Promise.reject(new Error('Tally slashing model does not support slash payloads'));
|
|
408
|
-
}
|
|
409
|
-
|
|
410
399
|
/**
|
|
411
400
|
* Gather offenses to be slashed on a given round.
|
|
412
|
-
*
|
|
401
|
+
* Round N slashes validators from round N - slashOffsetInRounds.
|
|
413
402
|
* @param round - The round to get offenses for, defaults to current round
|
|
414
403
|
* @returns Array of pending offenses for the round with offset applied
|
|
415
404
|
*/
|
|
@@ -422,9 +411,9 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
422
411
|
return await this.offensesStore.getOffensesForRound(targetRound);
|
|
423
412
|
}
|
|
424
413
|
|
|
425
|
-
/** Returns all
|
|
426
|
-
public
|
|
427
|
-
return this.offensesStore.
|
|
414
|
+
/** Returns all offenses stored */
|
|
415
|
+
public getOffenses(): Promise<Offense[]> {
|
|
416
|
+
return this.offensesStore.getOffenses();
|
|
428
417
|
}
|
|
429
418
|
|
|
430
419
|
/**
|
|
@@ -2,13 +2,12 @@ import { EpochCache } from '@aztec/epoch-cache';
|
|
|
2
2
|
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
3
3
|
import type { ViemClient } from '@aztec/ethereum/types';
|
|
4
4
|
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
5
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
7
6
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
8
|
-
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
9
7
|
import { AztecLMDBStoreV2 } from '@aztec/kv-store/lmdb-v2';
|
|
10
8
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
11
|
-
import type {
|
|
9
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
10
|
+
import type { Offense, ProposerSlashAction } from '@aztec/stdlib/slashing';
|
|
12
11
|
|
|
13
12
|
import { createSlasherImplementation } from './factory/create_implementation.js';
|
|
14
13
|
import type { SlasherClientInterface } from './slasher_client_interface.js';
|
|
@@ -27,11 +26,11 @@ export class SlasherClientFacade implements SlasherClientInterface {
|
|
|
27
26
|
private config: SlasherConfig & DataStoreConfig & { ethereumSlotDuration: number },
|
|
28
27
|
private rollup: RollupContract,
|
|
29
28
|
private l1Client: ViemClient,
|
|
30
|
-
private slashFactoryAddress: EthAddress | undefined,
|
|
31
29
|
private watchers: Watcher[],
|
|
32
30
|
private epochCache: EpochCache,
|
|
33
31
|
private dateProvider: DateProvider,
|
|
34
32
|
private kvStore: AztecLMDBStoreV2,
|
|
33
|
+
private rollupRegisteredAtL2Slot: SlotNumber,
|
|
35
34
|
private logger = createLogger('slasher'),
|
|
36
35
|
) {}
|
|
37
36
|
|
|
@@ -62,16 +61,12 @@ export class SlasherClientFacade implements SlasherClientInterface {
|
|
|
62
61
|
this.watchers.forEach(watcher => watcher.updateConfig?.(config));
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
public getSlashPayloads(): Promise<SlashPayloadRound[]> {
|
|
66
|
-
return this.client?.getSlashPayloads() ?? Promise.reject(new Error('Slasher client not initialized'));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
64
|
public gatherOffensesForRound(round?: bigint): Promise<Offense[]> {
|
|
70
65
|
return this.client?.gatherOffensesForRound(round) ?? Promise.reject(new Error('Slasher client not initialized'));
|
|
71
66
|
}
|
|
72
67
|
|
|
73
|
-
public
|
|
74
|
-
return this.client?.
|
|
68
|
+
public getOffenses(): Promise<Offense[]> {
|
|
69
|
+
return this.client?.getOffenses() ?? Promise.reject(new Error('Slasher client not initialized'));
|
|
75
70
|
}
|
|
76
71
|
|
|
77
72
|
public getProposerActions(slotNumber: SlotNumber): Promise<ProposerSlashAction[]> {
|
|
@@ -83,11 +78,11 @@ export class SlasherClientFacade implements SlasherClientInterface {
|
|
|
83
78
|
this.config,
|
|
84
79
|
this.rollup,
|
|
85
80
|
this.l1Client,
|
|
86
|
-
this.slashFactoryAddress,
|
|
87
81
|
this.watchers,
|
|
88
82
|
this.epochCache,
|
|
89
83
|
this.dateProvider,
|
|
90
84
|
this.kvStore,
|
|
85
|
+
this.rollupRegisteredAtL2Slot,
|
|
91
86
|
this.logger,
|
|
92
87
|
);
|
|
93
88
|
}
|