@aztec/slasher 0.0.1-commit.96bb3f7 → 0.0.1-commit.993d240
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 +83 -76
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +53 -41
- 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 +21 -0
- package/dest/generated/slasher-defaults.d.ts.map +1 -0
- package/dest/generated/slasher-defaults.js +21 -0
- package/dest/index.d.ts +6 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +5 -3
- 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 +10 -9
- package/dest/slash_offenses_collector.d.ts.map +1 -1
- package/dest/slash_offenses_collector.js +50 -30
- 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} +50 -45
- 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 +12 -12
- package/dest/stores/offenses_store.d.ts.map +1 -1
- package/dest/stores/offenses_store.js +64 -39
- 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 +28 -14
- package/dest/watchers/attestations_block_watcher.d.ts.map +1 -1
- package/dest/watchers/attestations_block_watcher.js +80 -64
- 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 +15 -13
- package/src/config.ts +61 -41
- 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 +23 -0
- package/src/index.ts +5 -3
- package/src/null_slasher_client.ts +2 -6
- package/src/slash_offenses_collector.ts +70 -32
- package/src/{tally_slasher_client.ts → slasher_client.ts} +68 -54
- package/src/slasher_client_facade.ts +6 -11
- package/src/slasher_client_interface.ts +6 -21
- package/src/stores/offenses_store.ts +76 -48
- package/src/watcher.ts +8 -0
- package/src/watchers/attestations_block_watcher.ts +95 -84
- 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 -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/dest/watchers/epoch_prune_watcher.d.ts +0 -37
- package/dest/watchers/epoch_prune_watcher.d.ts.map +0 -1
- package/dest/watchers/epoch_prune_watcher.js +0 -137
- package/src/empire_slasher_client.ts +0 -657
- package/src/stores/payloads_store.ts +0 -146
- package/src/watchers/epoch_prune_watcher.ts +0 -194
|
@@ -1,15 +1,27 @@
|
|
|
1
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { SerialQueue } from '@aztec/foundation/queue';
|
|
2
4
|
import type { Prettify } from '@aztec/foundation/types';
|
|
3
5
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
4
6
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
5
|
-
import { type Offense,
|
|
7
|
+
import { type Offense, getOffenseTypeName, getSlotForOffense } from '@aztec/stdlib/slashing';
|
|
6
8
|
|
|
7
9
|
import type { SlasherOffensesStore } from './stores/offenses_store.js';
|
|
8
|
-
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';
|
|
9
17
|
|
|
10
18
|
export type SlashOffensesCollectorConfig = Prettify<Pick<SlasherConfig, 'slashGracePeriodL2Slots'>>;
|
|
11
19
|
export type SlashOffensesCollectorSettings = Prettify<
|
|
12
|
-
Pick<L1RollupConstants, 'epochDuration'> & {
|
|
20
|
+
Pick<L1RollupConstants, 'epochDuration'> & {
|
|
21
|
+
slashingAmounts: [bigint, bigint, bigint] | undefined;
|
|
22
|
+
/** L2 slot at which the rollup was registered as canonical in the Registry. Used to anchor the slash grace period. */
|
|
23
|
+
rollupRegisteredAtL2Slot: SlotNumber;
|
|
24
|
+
}
|
|
13
25
|
>;
|
|
14
26
|
|
|
15
27
|
/**
|
|
@@ -19,6 +31,7 @@ export type SlashOffensesCollectorSettings = Prettify<
|
|
|
19
31
|
*/
|
|
20
32
|
export class SlashOffensesCollector {
|
|
21
33
|
private readonly unwatchCallbacks: (() => void)[] = [];
|
|
34
|
+
private readonly storeMutationQueue = new SerialQueue();
|
|
22
35
|
|
|
23
36
|
constructor(
|
|
24
37
|
private readonly config: SlashOffensesCollectorConfig,
|
|
@@ -30,28 +43,35 @@ export class SlashOffensesCollector {
|
|
|
30
43
|
|
|
31
44
|
public start() {
|
|
32
45
|
this.log.debug('Starting SlashOffensesCollector...');
|
|
46
|
+
this.storeMutationQueue.start();
|
|
33
47
|
|
|
34
|
-
// Subscribe to
|
|
48
|
+
// Subscribe to watcher slashing events.
|
|
35
49
|
for (const watcher of this.watchers) {
|
|
36
50
|
const wantToSlashCallback = (args: WantToSlashArgs[]) =>
|
|
37
|
-
|
|
51
|
+
this.enqueueStoreMutation('wantToSlash', () => this.handleWantToSlash(args));
|
|
38
52
|
watcher.on(WANT_TO_SLASH_EVENT, wantToSlashCallback);
|
|
39
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));
|
|
40
59
|
}
|
|
41
60
|
|
|
42
61
|
this.log.info('Started SlashOffensesCollector');
|
|
43
62
|
return Promise.resolve();
|
|
44
63
|
}
|
|
45
64
|
|
|
46
|
-
public stop() {
|
|
65
|
+
public async stop() {
|
|
47
66
|
this.log.debug('Stopping SlashOffensesCollector...');
|
|
48
67
|
|
|
49
68
|
for (const unwatchCallback of this.unwatchCallbacks) {
|
|
50
69
|
unwatchCallback();
|
|
51
70
|
}
|
|
52
71
|
|
|
72
|
+
await this.storeMutationQueue.end();
|
|
73
|
+
|
|
53
74
|
this.log.info('SlashOffensesCollector stopped');
|
|
54
|
-
return Promise.resolve();
|
|
55
75
|
}
|
|
56
76
|
|
|
57
77
|
/**
|
|
@@ -61,32 +81,47 @@ export class SlashOffensesCollector {
|
|
|
61
81
|
*/
|
|
62
82
|
public async handleWantToSlash(args: WantToSlashArgs[]) {
|
|
63
83
|
for (const arg of args) {
|
|
64
|
-
const
|
|
84
|
+
const offense: Offense = {
|
|
65
85
|
validator: arg.validator,
|
|
66
86
|
amount: arg.amount,
|
|
67
87
|
offenseType: arg.offenseType,
|
|
68
88
|
epochOrSlot: arg.epochOrSlot,
|
|
69
89
|
};
|
|
70
90
|
|
|
71
|
-
if (this.shouldSkipOffense(
|
|
72
|
-
this.log.verbose('Skipping offense during grace period',
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (await this.offensesStore.hasOffense(pendingOffense)) {
|
|
77
|
-
this.log.debug('Skipping repeated offense', pendingOffense);
|
|
91
|
+
if (this.shouldSkipOffense(offense)) {
|
|
92
|
+
this.log.verbose('Skipping offense during grace period', this.getOffenseLogData(offense));
|
|
78
93
|
continue;
|
|
79
94
|
}
|
|
80
95
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
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
|
+
}
|
|
85
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));
|
|
86
111
|
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
87
114
|
|
|
88
|
-
|
|
89
|
-
|
|
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
|
+
}
|
|
90
125
|
}
|
|
91
126
|
}
|
|
92
127
|
|
|
@@ -101,18 +136,21 @@ export class SlashOffensesCollector {
|
|
|
101
136
|
}
|
|
102
137
|
}
|
|
103
138
|
|
|
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 */
|
|
139
|
+
/** Returns whether to skip an offense if it happened during the grace period after the network upgrade */
|
|
114
140
|
private shouldSkipOffense(offense: Offense): boolean {
|
|
115
141
|
const offenseSlot = getSlotForOffense(offense, this.settings);
|
|
116
|
-
return offenseSlot < this.config.slashGracePeriodL2Slots;
|
|
142
|
+
return offenseSlot < this.settings.rollupRegisteredAtL2Slot + this.config.slashGracePeriodL2Slots;
|
|
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));
|
|
117
155
|
}
|
|
118
156
|
}
|
|
@@ -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,8 +13,8 @@ import {
|
|
|
14
13
|
OffenseType,
|
|
15
14
|
type ProposerSlashAction,
|
|
16
15
|
type ProposerSlashActionProvider,
|
|
17
|
-
type SlashPayloadRound,
|
|
18
16
|
getEpochsForRound,
|
|
17
|
+
getOffenseTypeName,
|
|
19
18
|
getSlashConsensusVotesFromOffenses,
|
|
20
19
|
} from '@aztec/stdlib/slashing';
|
|
21
20
|
|
|
@@ -31,8 +30,8 @@ import type { SlasherClientInterface } from './slasher_client_interface.js';
|
|
|
31
30
|
import type { SlasherOffensesStore } from './stores/offenses_store.js';
|
|
32
31
|
import type { Watcher } from './watcher.js';
|
|
33
32
|
|
|
34
|
-
/** Settings used in the
|
|
35
|
-
export type
|
|
33
|
+
/** Settings used in the slasher client, loaded from the L1 contracts during initialization */
|
|
34
|
+
export type SlasherSettings = Prettify<
|
|
36
35
|
SlashRoundMonitorSettings &
|
|
37
36
|
SlashOffensesCollectorSettings & {
|
|
38
37
|
slashingLifetimeInRounds: number;
|
|
@@ -46,11 +45,22 @@ export type TallySlasherSettings = Prettify<
|
|
|
46
45
|
}
|
|
47
46
|
>;
|
|
48
47
|
|
|
49
|
-
export type
|
|
50
|
-
Pick<
|
|
48
|
+
export type SlasherClientConfig = SlashOffensesCollectorConfig &
|
|
49
|
+
Pick<
|
|
50
|
+
SlasherConfig,
|
|
51
|
+
'slashValidatorsAlways' | 'slashValidatorsNever' | 'slashExecuteRoundsLookBack' | 'slashMaxPayloadSize'
|
|
52
|
+
>;
|
|
53
|
+
|
|
54
|
+
type AlwaysSlashOffense = {
|
|
55
|
+
validator: EthAddress;
|
|
56
|
+
amount: bigint;
|
|
57
|
+
offenseType: OffenseType.UNKNOWN;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
type SlashVoteOffense = Offense | AlwaysSlashOffense;
|
|
51
61
|
|
|
52
62
|
/**
|
|
53
|
-
* The
|
|
63
|
+
* The Slasher client is responsible for managing slashable offenses using
|
|
54
64
|
* the consensus-based slashing model where proposers vote on individual validator offenses.
|
|
55
65
|
*
|
|
56
66
|
* The client subscribes to several slash watchers that emit offenses and tracks them. When the slasher is the
|
|
@@ -74,22 +84,16 @@ export type TallySlasherClientConfig = SlashOffensesCollectorConfig &
|
|
|
74
84
|
* - Validators that reach the quorum threshold are slashed. A vote for slashing N units is also considered
|
|
75
85
|
* a vote for slashing N-1, N-2, ..., 1 units. The system slashes for the largest amount that reaches quorum.
|
|
76
86
|
* - 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
87
|
*/
|
|
84
|
-
export class
|
|
88
|
+
export class SlasherClient implements ProposerSlashActionProvider, SlasherClientInterface {
|
|
85
89
|
protected unwatchCallbacks: (() => void)[] = [];
|
|
86
90
|
protected roundMonitor: SlashRoundMonitor;
|
|
87
91
|
protected offensesCollector: SlashOffensesCollector;
|
|
88
92
|
|
|
89
93
|
constructor(
|
|
90
|
-
private config:
|
|
91
|
-
private settings:
|
|
92
|
-
private
|
|
94
|
+
private config: SlasherClientConfig,
|
|
95
|
+
private settings: SlasherSettings,
|
|
96
|
+
private slashingProposer: SlashingProposerContract,
|
|
93
97
|
private slasher: SlasherContract,
|
|
94
98
|
private rollup: RollupContract,
|
|
95
99
|
watchers: Watcher[],
|
|
@@ -103,14 +107,14 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
103
107
|
}
|
|
104
108
|
|
|
105
109
|
public async start() {
|
|
106
|
-
this.log.debug('Starting
|
|
110
|
+
this.log.debug('Starting slasher client...');
|
|
107
111
|
|
|
108
112
|
this.roundMonitor.start();
|
|
109
113
|
await this.offensesCollector.start();
|
|
110
114
|
|
|
111
115
|
// Listen for RoundExecuted events
|
|
112
116
|
this.unwatchCallbacks.push(
|
|
113
|
-
this.
|
|
117
|
+
this.slashingProposer.listenToRoundExecuted(
|
|
114
118
|
({ round, slashCount, l1BlockHash }) =>
|
|
115
119
|
void this.handleRoundExecuted(round, slashCount, l1BlockHash).catch(err =>
|
|
116
120
|
this.log.error('Error handling round executed', err),
|
|
@@ -121,15 +125,13 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
121
125
|
// Check for round changes
|
|
122
126
|
this.unwatchCallbacks.push(this.roundMonitor.listenToNewRound(round => this.handleNewRound(round)));
|
|
123
127
|
|
|
124
|
-
this.log.info(`Started
|
|
128
|
+
this.log.info(`Started slasher client`);
|
|
125
129
|
return Promise.resolve();
|
|
126
130
|
}
|
|
127
131
|
|
|
128
|
-
/**
|
|
129
|
-
* Stop the tally slasher client
|
|
130
|
-
*/
|
|
132
|
+
/** Stop the slasher client */
|
|
131
133
|
public async stop() {
|
|
132
|
-
this.log.debug('Stopping
|
|
134
|
+
this.log.debug('Stopping slasher client...');
|
|
133
135
|
|
|
134
136
|
for (const unwatchCallback of this.unwatchCallbacks) {
|
|
135
137
|
unwatchCallback();
|
|
@@ -138,9 +140,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
138
140
|
this.roundMonitor.stop();
|
|
139
141
|
await this.offensesCollector.stop();
|
|
140
142
|
|
|
141
|
-
|
|
142
|
-
await sleep(2000);
|
|
143
|
-
this.log.info('Tally Slasher client stopped');
|
|
143
|
+
this.log.info('Slasher client stopped');
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
/** Returns the current config */
|
|
@@ -155,11 +155,11 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
155
155
|
|
|
156
156
|
/** Triggered on a time basis when we enter a new slashing round. Clears expired offenses. */
|
|
157
157
|
protected async handleNewRound(round: bigint) {
|
|
158
|
-
this.log.info(`Starting new
|
|
158
|
+
this.log.info(`Starting new slashing round ${round}`);
|
|
159
159
|
await this.offensesCollector.handleNewRound(round);
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
/** Called when we see a RoundExecuted event on the
|
|
162
|
+
/** Called when we see a RoundExecuted event on the SlashingProposer (just for logging). */
|
|
163
163
|
protected async handleRoundExecuted(round: bigint, slashCount: bigint, l1BlockHash: Hex) {
|
|
164
164
|
const slashes = await this.rollup.getSlashEvents(l1BlockHash);
|
|
165
165
|
this.log.info(`Slashing round ${round} has been executed with ${slashCount} slashes`, { slashes });
|
|
@@ -240,7 +240,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
240
240
|
this.log.debug(`Testing if slashing round ${executableRound} is executable`, logData);
|
|
241
241
|
|
|
242
242
|
try {
|
|
243
|
-
const roundInfo = await this.
|
|
243
|
+
const roundInfo = await this.slashingProposer.getRound(executableRound);
|
|
244
244
|
logData = { ...logData, roundInfo };
|
|
245
245
|
if (roundInfo.isExecuted) {
|
|
246
246
|
this.log.verbose(`Round ${executableRound} has already been executed`, logData);
|
|
@@ -254,7 +254,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
// Check if round is ready to execute at the given slot
|
|
257
|
-
const isReadyToExecute = await this.
|
|
257
|
+
const isReadyToExecute = await this.slashingProposer.isRoundReadyToExecute(executableRound, slotNumber);
|
|
258
258
|
if (!isReadyToExecute) {
|
|
259
259
|
this.log.warn(
|
|
260
260
|
`Round ${executableRound} is not ready to execute at slot ${slotNumber} according to contract check`,
|
|
@@ -264,14 +264,14 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
// Check if the round yields any slashing at all
|
|
267
|
-
const { actions: slashActions, committees } = await this.
|
|
267
|
+
const { actions: slashActions, committees } = await this.slashingProposer.getTally(executableRound);
|
|
268
268
|
if (slashActions.length === 0) {
|
|
269
269
|
this.log.verbose(`Round ${executableRound} does not resolve in any slashing`, logData);
|
|
270
270
|
return undefined;
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
// Check if the slash payload is vetoed
|
|
274
|
-
const payload = await this.
|
|
274
|
+
const payload = await this.slashingProposer.getPayload(executableRound);
|
|
275
275
|
const isVetoed = await this.slasher.isPayloadVetoed(payload.address);
|
|
276
276
|
if (isVetoed) {
|
|
277
277
|
this.log.warn(`Round ${executableRound} payload is vetoed (skipping execution)`, {
|
|
@@ -281,8 +281,12 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
281
281
|
return undefined;
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
+
const slashActionsWithAmounts = slashActions.map(action => ({
|
|
285
|
+
validator: action.validator.toString(),
|
|
286
|
+
slashAmount: action.slashAmount.toString(),
|
|
287
|
+
}));
|
|
284
288
|
this.log.info(`Round ${executableRound} is ready to execute with ${slashActions.length} slashes`, {
|
|
285
|
-
slashActions,
|
|
289
|
+
slashActions: slashActionsWithAmounts,
|
|
286
290
|
payloadAddress: payload.address.toString(),
|
|
287
291
|
...logData,
|
|
288
292
|
});
|
|
@@ -314,7 +318,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
314
318
|
// Compute offenses to slash, by loading the offenses for this round, adding synthetic offenses
|
|
315
319
|
// for validators that should always be slashed, and removing the ones that should never be slashed.
|
|
316
320
|
const offensesForRound = await this.gatherOffensesForRound(currentRound);
|
|
317
|
-
const offensesFromAlwaysSlash = (this.config.slashValidatorsAlways ?? []).map(validator => ({
|
|
321
|
+
const offensesFromAlwaysSlash: AlwaysSlashOffense[] = (this.config.slashValidatorsAlways ?? []).map(validator => ({
|
|
318
322
|
validator,
|
|
319
323
|
amount: this.settings.slashingAmounts[2],
|
|
320
324
|
offenseType: OffenseType.UNKNOWN,
|
|
@@ -328,7 +332,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
328
332
|
slotNumber,
|
|
329
333
|
currentRound,
|
|
330
334
|
slashedRound,
|
|
331
|
-
|
|
335
|
+
offensesFromAlwaysSlash: offensesFromAlwaysSlash.map(getOffenseLogData),
|
|
332
336
|
slashValidatorsAlways: this.config.slashValidatorsAlways,
|
|
333
337
|
});
|
|
334
338
|
}
|
|
@@ -338,7 +342,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
338
342
|
slotNumber,
|
|
339
343
|
currentRound,
|
|
340
344
|
slashedRound,
|
|
341
|
-
offensesToForgive,
|
|
345
|
+
offensesToForgive: offensesToForgive.map(getOffenseLogData),
|
|
342
346
|
slashValidatorsNever: this.config.slashValidatorsNever,
|
|
343
347
|
});
|
|
344
348
|
}
|
|
@@ -348,32 +352,42 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
348
352
|
return undefined;
|
|
349
353
|
}
|
|
350
354
|
|
|
351
|
-
this.log.
|
|
355
|
+
this.log.debug(`Computing slash votes for ${offensesToSlash.length} offenses`, {
|
|
352
356
|
slotNumber,
|
|
353
357
|
currentRound,
|
|
354
358
|
slashedRound,
|
|
355
|
-
offensesToSlash,
|
|
359
|
+
offensesToSlash: offensesToSlash.map(getOffenseLogData),
|
|
356
360
|
});
|
|
357
361
|
|
|
358
362
|
const committees = await this.collectCommitteesActiveDuringRound(slashedRound);
|
|
359
363
|
const epochsForCommittees = getEpochsForRound(slashedRound, this.settings);
|
|
364
|
+
const { slashMaxPayloadSize } = this.config;
|
|
360
365
|
const votes = getSlashConsensusVotesFromOffenses(
|
|
361
366
|
offensesToSlash,
|
|
362
367
|
committees,
|
|
363
368
|
epochsForCommittees.map(e => BigInt(e)),
|
|
364
|
-
this.settings,
|
|
369
|
+
{ ...this.settings, maxSlashedValidators: slashMaxPayloadSize },
|
|
370
|
+
this.log,
|
|
365
371
|
);
|
|
366
372
|
if (votes.every(v => v === 0)) {
|
|
367
373
|
this.log.warn(`Computed votes for offenses are all zero. Skipping vote.`, {
|
|
368
374
|
slotNumber,
|
|
369
375
|
currentRound,
|
|
370
376
|
slashedRound,
|
|
371
|
-
offensesToSlash,
|
|
377
|
+
offensesToSlash: offensesToSlash.map(getOffenseLogData),
|
|
372
378
|
committees,
|
|
373
379
|
});
|
|
374
380
|
return undefined;
|
|
375
381
|
}
|
|
376
382
|
|
|
383
|
+
this.log.info(`Voting to slash ${offensesToSlash.length} offenses`, {
|
|
384
|
+
slotNumber,
|
|
385
|
+
slashedRound,
|
|
386
|
+
currentRound,
|
|
387
|
+
votes,
|
|
388
|
+
offensesToSlash: offensesToSlash.map(getOffenseLogData),
|
|
389
|
+
});
|
|
390
|
+
|
|
377
391
|
this.log.debug(`Computed votes for slashing ${offensesToSlash.length} offenses`, {
|
|
378
392
|
slashedRound,
|
|
379
393
|
currentRound,
|
|
@@ -399,17 +413,9 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
399
413
|
);
|
|
400
414
|
}
|
|
401
415
|
|
|
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
416
|
/**
|
|
411
417
|
* Gather offenses to be slashed on a given round.
|
|
412
|
-
*
|
|
418
|
+
* Round N slashes validators from round N - slashOffsetInRounds.
|
|
413
419
|
* @param round - The round to get offenses for, defaults to current round
|
|
414
420
|
* @returns Array of pending offenses for the round with offset applied
|
|
415
421
|
*/
|
|
@@ -422,9 +428,9 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
422
428
|
return await this.offensesStore.getOffensesForRound(targetRound);
|
|
423
429
|
}
|
|
424
430
|
|
|
425
|
-
/** Returns all
|
|
426
|
-
public
|
|
427
|
-
return this.offensesStore.
|
|
431
|
+
/** Returns all offenses stored */
|
|
432
|
+
public getOffenses(): Promise<Offense[]> {
|
|
433
|
+
return this.offensesStore.getOffenses();
|
|
428
434
|
}
|
|
429
435
|
|
|
430
436
|
/**
|
|
@@ -440,3 +446,11 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
440
446
|
return round - BigInt(this.settings.slashingOffsetInRounds);
|
|
441
447
|
}
|
|
442
448
|
}
|
|
449
|
+
|
|
450
|
+
function getOffenseLogData(offense: SlashVoteOffense) {
|
|
451
|
+
return {
|
|
452
|
+
...offense,
|
|
453
|
+
validator: offense.validator.toString(),
|
|
454
|
+
offenseType: getOffenseTypeName(offense.offenseType),
|
|
455
|
+
};
|
|
456
|
+
}
|
|
@@ -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
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
import type { Offense, ProposerSlashAction
|
|
3
|
+
import type { Offense, ProposerSlashAction } from '@aztec/stdlib/slashing';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Common interface for slasher clients used by the Aztec node.
|
|
7
|
-
* Both Empire and Consensus slasher clients implement this interface.
|
|
8
|
-
*/
|
|
5
|
+
/** Common interface for slasher clients used by the Aztec node. */
|
|
9
6
|
export interface SlasherClientInterface {
|
|
10
7
|
/** Start the slasher client */
|
|
11
8
|
start(): Promise<void>;
|
|
@@ -13,25 +10,13 @@ export interface SlasherClientInterface {
|
|
|
13
10
|
/** Stop the slasher client */
|
|
14
11
|
stop(): Promise<void>;
|
|
15
12
|
|
|
16
|
-
/**
|
|
17
|
-
* Get slash payloads for the Empire model.
|
|
18
|
-
* The Consensus model should throw an error when this is called.
|
|
19
|
-
*/
|
|
20
|
-
getSlashPayloads(): Promise<SlashPayloadRound[]>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Gather offenses for a given round, defaults to current.
|
|
24
|
-
* Used by both Empire and Consensus models.
|
|
25
|
-
*/
|
|
13
|
+
/** Gather offenses for a given round, defaults to current. */
|
|
26
14
|
gatherOffensesForRound(round?: bigint): Promise<Offense[]>;
|
|
27
15
|
|
|
28
|
-
/** Returns all
|
|
29
|
-
|
|
16
|
+
/** Returns all offenses */
|
|
17
|
+
getOffenses(): Promise<Offense[]>;
|
|
30
18
|
|
|
31
|
-
/**
|
|
32
|
-
* Update the configuration.
|
|
33
|
-
* Used by both Empire and Consensus models.
|
|
34
|
-
*/
|
|
19
|
+
/** Update the configuration. */
|
|
35
20
|
updateConfig(config: Partial<SlasherConfig>): void;
|
|
36
21
|
|
|
37
22
|
/**
|