@aztec/slasher 0.0.1-commit.e3c1de76 → 0.0.1-commit.e57c76e
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 +41 -29
- 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 +25 -2
- 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 +8 -6
- package/dest/generated/slasher-defaults.d.ts.map +1 -1
- package/dest/generated/slasher-defaults.js +7 -5
- 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 -34
- 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} +45 -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 +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 +48 -29
- package/src/factory/create_facade.ts +32 -4
- 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 +7 -5
- package/src/index.ts +5 -3
- package/src/null_slasher_client.ts +2 -6
- package/src/slash_offenses_collector.ts +70 -36
- package/src/{tally_slasher_client.ts → slasher_client.ts} +63 -54
- package/src/slasher_client_facade.ts +6 -11
- 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 -38
- package/dest/watchers/epoch_prune_watcher.d.ts.map +0 -1
- package/dest/watchers/epoch_prune_watcher.js +0 -158
- package/src/empire_slasher_client.ts +0 -649
- package/src/stores/payloads_store.ts +0 -149
- package/src/watchers/epoch_prune_watcher.ts +0 -221
package/src/config.ts
CHANGED
|
@@ -14,18 +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),
|
|
25
|
+
slashDuplicateProposalPenalty: BigInt(slasherDefaultEnv.SLASH_DUPLICATE_PROPOSAL_PENALTY),
|
|
26
|
+
slashDuplicateAttestationPenalty: BigInt(slasherDefaultEnv.SLASH_DUPLICATE_ATTESTATION_PENALTY),
|
|
26
27
|
slashInactivityPenalty: BigInt(slasherDefaultEnv.SLASH_INACTIVITY_PENALTY),
|
|
27
28
|
slashProposeInvalidAttestationsPenalty: BigInt(slasherDefaultEnv.SLASH_PROPOSE_INVALID_ATTESTATIONS_PENALTY),
|
|
28
|
-
|
|
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
|
+
),
|
|
29
35
|
slashUnknownPenalty: BigInt(slasherDefaultEnv.SLASH_UNKNOWN_PENALTY),
|
|
30
36
|
slashOffenseExpirationRounds: slasherDefaultEnv.SLASH_OFFENSE_EXPIRATION_ROUNDS,
|
|
31
37
|
slashMaxPayloadSize: slasherDefaultEnv.SLASH_MAX_PAYLOAD_SIZE,
|
|
@@ -38,19 +44,9 @@ export const slasherConfigMappings: ConfigMappingsType<SlasherConfig> = {
|
|
|
38
44
|
slashOverridePayload: {
|
|
39
45
|
env: 'SLASH_OVERRIDE_PAYLOAD',
|
|
40
46
|
description: 'An Ethereum address for a slash payload to vote for unconditionally.',
|
|
41
|
-
parseEnv: (val: string) =>
|
|
47
|
+
parseEnv: (val: string) => EthAddress.fromString(val),
|
|
42
48
|
defaultValue: DefaultSlasherConfig.slashOverridePayload,
|
|
43
49
|
},
|
|
44
|
-
slashMinPenaltyPercentage: {
|
|
45
|
-
env: 'SLASH_MIN_PENALTY_PERCENTAGE',
|
|
46
|
-
description: 'Minimum penalty percentage for slashing offenses (0.1 is 10%).',
|
|
47
|
-
...floatConfigHelper(DefaultSlasherConfig.slashMinPenaltyPercentage),
|
|
48
|
-
},
|
|
49
|
-
slashMaxPenaltyPercentage: {
|
|
50
|
-
env: 'SLASH_MAX_PENALTY_PERCENTAGE',
|
|
51
|
-
description: 'Maximum penalty percentage for slashing offenses (2.0 is 200%).',
|
|
52
|
-
...floatConfigHelper(DefaultSlasherConfig.slashMaxPenaltyPercentage),
|
|
53
|
-
},
|
|
54
50
|
slashValidatorsAlways: {
|
|
55
51
|
env: 'SLASH_VALIDATORS_ALWAYS',
|
|
56
52
|
description: 'Comma-separated list of validator addresses that should always be slashed.',
|
|
@@ -73,21 +69,38 @@ export const slasherConfigMappings: ConfigMappingsType<SlasherConfig> = {
|
|
|
73
69
|
.map(addr => EthAddress.fromString(addr)),
|
|
74
70
|
defaultValue: DefaultSlasherConfig.slashValidatorsNever,
|
|
75
71
|
},
|
|
76
|
-
slashPrunePenalty: {
|
|
77
|
-
env: 'SLASH_PRUNE_PENALTY',
|
|
78
|
-
description: 'Penalty amount for slashing validators of a valid pruned epoch (set to 0 to disable).',
|
|
79
|
-
...bigintConfigHelper(DefaultSlasherConfig.slashPrunePenalty),
|
|
80
|
-
},
|
|
81
72
|
slashDataWithholdingPenalty: {
|
|
82
73
|
env: 'SLASH_DATA_WITHHOLDING_PENALTY',
|
|
83
|
-
description: 'Penalty
|
|
74
|
+
description: 'Penalty for data withholding (0 records offenses without slash votes).',
|
|
84
75
|
...bigintConfigHelper(DefaultSlasherConfig.slashDataWithholdingPenalty),
|
|
85
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
|
+
},
|
|
86
83
|
slashBroadcastedInvalidBlockPenalty: {
|
|
87
84
|
env: 'SLASH_INVALID_BLOCK_PENALTY',
|
|
88
85
|
description: 'Penalty amount for slashing a validator for an invalid block proposed via p2p.',
|
|
89
86
|
...bigintConfigHelper(DefaultSlasherConfig.slashBroadcastedInvalidBlockPenalty),
|
|
90
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
|
+
slashDuplicateProposalPenalty: {
|
|
94
|
+
env: 'SLASH_DUPLICATE_PROPOSAL_PENALTY',
|
|
95
|
+
description: 'Penalty amount for slashing a validator for sending duplicate proposals.',
|
|
96
|
+
...bigintConfigHelper(DefaultSlasherConfig.slashDuplicateProposalPenalty),
|
|
97
|
+
},
|
|
98
|
+
slashDuplicateAttestationPenalty: {
|
|
99
|
+
env: 'SLASH_DUPLICATE_ATTESTATION_PENALTY',
|
|
100
|
+
description:
|
|
101
|
+
'Penalty amount for slashing a validator for signing attestations for different proposals at the same slot.',
|
|
102
|
+
...bigintConfigHelper(DefaultSlasherConfig.slashDuplicateAttestationPenalty),
|
|
103
|
+
},
|
|
91
104
|
slashInactivityTargetPercentage: {
|
|
92
105
|
env: 'SLASH_INACTIVITY_TARGET_PERCENTAGE',
|
|
93
106
|
description:
|
|
@@ -112,23 +125,28 @@ export const slasherConfigMappings: ConfigMappingsType<SlasherConfig> = {
|
|
|
112
125
|
},
|
|
113
126
|
slashInactivityPenalty: {
|
|
114
127
|
env: 'SLASH_INACTIVITY_PENALTY',
|
|
115
|
-
description: 'Penalty
|
|
128
|
+
description: 'Penalty for an inactive validator (0 records offenses without slash votes).',
|
|
116
129
|
...bigintConfigHelper(DefaultSlasherConfig.slashInactivityPenalty),
|
|
117
130
|
},
|
|
118
131
|
slashProposeInvalidAttestationsPenalty: {
|
|
119
132
|
env: 'SLASH_PROPOSE_INVALID_ATTESTATIONS_PENALTY',
|
|
120
|
-
description: 'Penalty
|
|
133
|
+
description: 'Penalty for proposing invalid attestations (0 records offenses without slash votes).',
|
|
121
134
|
...bigintConfigHelper(DefaultSlasherConfig.slashProposeInvalidAttestationsPenalty),
|
|
122
135
|
},
|
|
123
|
-
|
|
124
|
-
env: '
|
|
136
|
+
slashProposeDescendantOfCheckpointWithInvalidAttestationsPenalty: {
|
|
137
|
+
env: 'SLASH_PROPOSE_DESCENDANT_OF_CHECKPOINT_WITH_INVALID_ATTESTATIONS_PENALTY',
|
|
125
138
|
description:
|
|
126
|
-
'Penalty
|
|
127
|
-
...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),
|
|
128
146
|
},
|
|
129
147
|
slashUnknownPenalty: {
|
|
130
148
|
env: 'SLASH_UNKNOWN_PENALTY',
|
|
131
|
-
description: 'Penalty
|
|
149
|
+
description: 'Penalty for an unknown offense (0 records offenses without slash votes).',
|
|
132
150
|
...bigintConfigHelper(DefaultSlasherConfig.slashUnknownPenalty),
|
|
133
151
|
},
|
|
134
152
|
slashOffenseExpirationRounds: {
|
|
@@ -142,7 +160,8 @@ export const slasherConfigMappings: ConfigMappingsType<SlasherConfig> = {
|
|
|
142
160
|
...numberConfigHelper(DefaultSlasherConfig.slashMaxPayloadSize),
|
|
143
161
|
},
|
|
144
162
|
slashGracePeriodL2Slots: {
|
|
145
|
-
description:
|
|
163
|
+
description:
|
|
164
|
+
'Number of L2 slots after the network upgrade during which slashing offenses are ignored. The upgrade time is determined from the CanonicalRollupUpdated event.',
|
|
146
165
|
env: 'SLASH_GRACE_PERIOD_L2_SLOTS',
|
|
147
166
|
...numberConfigHelper(DefaultSlasherConfig.slashGracePeriodL2Slots),
|
|
148
167
|
},
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
-
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
2
|
+
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
3
3
|
import type { L1ReaderConfig } from '@aztec/ethereum/l1-reader';
|
|
4
4
|
import type { ViemClient } from '@aztec/ethereum/types';
|
|
5
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
5
6
|
import { unique } from '@aztec/foundation/collection';
|
|
6
7
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
7
8
|
import { createLogger } from '@aztec/foundation/log';
|
|
8
9
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
9
|
-
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
10
10
|
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
11
|
+
import { getSlotAtTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
11
12
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
13
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
12
14
|
|
|
13
15
|
import { SlasherClientFacade } from '../slasher_client_facade.js';
|
|
14
16
|
import type { SlasherClientInterface } from '../slasher_client_interface.js';
|
|
@@ -18,7 +20,7 @@ import type { Watcher } from '../watcher.js';
|
|
|
18
20
|
/** Creates a slasher client facade that updates itself whenever the rollup slasher changes */
|
|
19
21
|
export async function createSlasherFacade(
|
|
20
22
|
config: SlasherConfig & DataStoreConfig & { ethereumSlotDuration: number },
|
|
21
|
-
l1Contracts: Pick<L1ReaderConfig
|
|
23
|
+
l1Contracts: Pick<L1ReaderConfig, 'rollupAddress' | 'registryAddress'>,
|
|
22
24
|
l1Client: ViemClient,
|
|
23
25
|
watchers: Watcher[],
|
|
24
26
|
dateProvider: DateProvider,
|
|
@@ -34,6 +36,32 @@ export async function createSlasherFacade(
|
|
|
34
36
|
const kvStore = await createStore('slasher', SCHEMA_VERSION, config, logger.getBindings());
|
|
35
37
|
const rollup = new RollupContract(l1Client, l1Contracts.rollupAddress);
|
|
36
38
|
|
|
39
|
+
// Compute and cache the L2 slot at which the rollup was registered as canonical
|
|
40
|
+
const settingsMap = kvStore.openMap<string, number>('slasher-settings');
|
|
41
|
+
const cacheKey = `registeredSlot:${l1Contracts.rollupAddress}`;
|
|
42
|
+
let rollupRegisteredAtL2Slot = (await settingsMap.getAsync(cacheKey)) as SlotNumber | undefined;
|
|
43
|
+
|
|
44
|
+
if (rollupRegisteredAtL2Slot === undefined) {
|
|
45
|
+
const registry = new RegistryContract(l1Client, l1Contracts.registryAddress);
|
|
46
|
+
const l1StartBlock = await rollup.getL1StartBlock();
|
|
47
|
+
const registrationTimestamp = await registry.getCanonicalRollupRegistrationTimestamp(
|
|
48
|
+
l1Contracts.rollupAddress,
|
|
49
|
+
l1StartBlock,
|
|
50
|
+
);
|
|
51
|
+
if (registrationTimestamp !== undefined) {
|
|
52
|
+
const l1GenesisTime = await rollup.getL1GenesisTime();
|
|
53
|
+
const slotDuration = await rollup.getSlotDuration();
|
|
54
|
+
rollupRegisteredAtL2Slot = getSlotAtTimestamp(registrationTimestamp, {
|
|
55
|
+
l1GenesisTime,
|
|
56
|
+
slotDuration: Number(slotDuration),
|
|
57
|
+
});
|
|
58
|
+
} else {
|
|
59
|
+
rollupRegisteredAtL2Slot = SlotNumber(0);
|
|
60
|
+
}
|
|
61
|
+
await settingsMap.set(cacheKey, rollupRegisteredAtL2Slot);
|
|
62
|
+
logger.info(`Canonical rollup registered at L2 slot ${rollupRegisteredAtL2Slot}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
37
65
|
const slashValidatorsNever = config.slashSelfAllowed
|
|
38
66
|
? config.slashValidatorsNever
|
|
39
67
|
: unique([...config.slashValidatorsNever, ...validatorAddresses].map(a => a.toString())).map(EthAddress.fromString);
|
|
@@ -43,11 +71,11 @@ export async function createSlasherFacade(
|
|
|
43
71
|
updatedConfig,
|
|
44
72
|
rollup,
|
|
45
73
|
l1Client,
|
|
46
|
-
l1Contracts.slashFactoryAddress,
|
|
47
74
|
watchers,
|
|
48
75
|
epochCache,
|
|
49
76
|
dateProvider,
|
|
50
77
|
kvStore,
|
|
78
|
+
rollupRegisteredAtL2Slot,
|
|
51
79
|
logger,
|
|
52
80
|
);
|
|
53
81
|
}
|
|
@@ -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,19 +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
|
-
SLASH_MAX_PAYLOAD_SIZE:
|
|
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,
|
|
17
|
+
SLASH_DUPLICATE_PROPOSAL_PENALTY: 0,
|
|
18
|
+
SLASH_DUPLICATE_ATTESTATION_PENALTY: 0,
|
|
18
19
|
SLASH_UNKNOWN_PENALTY: 10000000000000000000,
|
|
19
20
|
SLASH_INVALID_BLOCK_PENALTY: 10000000000000000000,
|
|
21
|
+
SLASH_INVALID_CHECKPOINT_PROPOSAL_PENALTY: 0,
|
|
20
22
|
SLASH_GRACE_PERIOD_L2_SLOTS: 0,
|
|
21
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';
|
|
@@ -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
|
|