@aztec/slasher 0.0.1-commit.001888fc

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.
Files changed (86) hide show
  1. package/README.md +228 -0
  2. package/dest/config.d.ts +6 -0
  3. package/dest/config.d.ts.map +1 -0
  4. package/dest/config.js +146 -0
  5. package/dest/empire_slasher_client.d.ts +190 -0
  6. package/dest/empire_slasher_client.d.ts.map +1 -0
  7. package/dest/empire_slasher_client.js +564 -0
  8. package/dest/factory/create_facade.d.ts +16 -0
  9. package/dest/factory/create_facade.d.ts.map +1 -0
  10. package/dest/factory/create_facade.js +46 -0
  11. package/dest/factory/create_implementation.d.ts +18 -0
  12. package/dest/factory/create_implementation.d.ts.map +1 -0
  13. package/dest/factory/create_implementation.js +77 -0
  14. package/dest/factory/get_settings.d.ts +4 -0
  15. package/dest/factory/get_settings.d.ts.map +1 -0
  16. package/dest/factory/get_settings.js +36 -0
  17. package/dest/factory/index.d.ts +3 -0
  18. package/dest/factory/index.d.ts.map +1 -0
  19. package/dest/factory/index.js +2 -0
  20. package/dest/generated/slasher-defaults.d.ts +21 -0
  21. package/dest/generated/slasher-defaults.d.ts.map +1 -0
  22. package/dest/generated/slasher-defaults.js +21 -0
  23. package/dest/index.d.ts +11 -0
  24. package/dest/index.d.ts.map +1 -0
  25. package/dest/index.js +10 -0
  26. package/dest/null_slasher_client.d.ts +17 -0
  27. package/dest/null_slasher_client.d.ts.map +1 -0
  28. package/dest/null_slasher_client.js +33 -0
  29. package/dest/slash_offenses_collector.d.ts +48 -0
  30. package/dest/slash_offenses_collector.d.ts.map +1 -0
  31. package/dest/slash_offenses_collector.js +94 -0
  32. package/dest/slash_round_monitor.d.ts +30 -0
  33. package/dest/slash_round_monitor.d.ts.map +1 -0
  34. package/dest/slash_round_monitor.js +52 -0
  35. package/dest/slasher_client_facade.d.ts +45 -0
  36. package/dest/slasher_client_facade.d.ts.map +1 -0
  37. package/dest/slasher_client_facade.js +78 -0
  38. package/dest/slasher_client_interface.d.ts +39 -0
  39. package/dest/slasher_client_interface.d.ts.map +1 -0
  40. package/dest/slasher_client_interface.js +4 -0
  41. package/dest/stores/offenses_store.d.ts +37 -0
  42. package/dest/stores/offenses_store.d.ts.map +1 -0
  43. package/dest/stores/offenses_store.js +107 -0
  44. package/dest/stores/payloads_store.d.ts +29 -0
  45. package/dest/stores/payloads_store.d.ts.map +1 -0
  46. package/dest/stores/payloads_store.js +128 -0
  47. package/dest/stores/schema_version.d.ts +2 -0
  48. package/dest/stores/schema_version.d.ts.map +1 -0
  49. package/dest/stores/schema_version.js +1 -0
  50. package/dest/tally_slasher_client.d.ts +125 -0
  51. package/dest/tally_slasher_client.d.ts.map +1 -0
  52. package/dest/tally_slasher_client.js +354 -0
  53. package/dest/test/dummy_watcher.d.ts +11 -0
  54. package/dest/test/dummy_watcher.d.ts.map +1 -0
  55. package/dest/test/dummy_watcher.js +14 -0
  56. package/dest/watcher.d.ts +21 -0
  57. package/dest/watcher.d.ts.map +1 -0
  58. package/dest/watcher.js +1 -0
  59. package/dest/watchers/attestations_block_watcher.d.ts +34 -0
  60. package/dest/watchers/attestations_block_watcher.d.ts.map +1 -0
  61. package/dest/watchers/attestations_block_watcher.js +142 -0
  62. package/dest/watchers/epoch_prune_watcher.d.ts +39 -0
  63. package/dest/watchers/epoch_prune_watcher.d.ts.map +1 -0
  64. package/dest/watchers/epoch_prune_watcher.js +176 -0
  65. package/package.json +92 -0
  66. package/src/config.ts +172 -0
  67. package/src/empire_slasher_client.ts +649 -0
  68. package/src/factory/create_facade.ts +82 -0
  69. package/src/factory/create_implementation.ts +184 -0
  70. package/src/factory/get_settings.ts +58 -0
  71. package/src/factory/index.ts +2 -0
  72. package/src/generated/slasher-defaults.ts +23 -0
  73. package/src/index.ts +10 -0
  74. package/src/null_slasher_client.ts +41 -0
  75. package/src/slash_offenses_collector.ts +123 -0
  76. package/src/slash_round_monitor.ts +62 -0
  77. package/src/slasher_client_facade.ts +103 -0
  78. package/src/slasher_client_interface.ts +46 -0
  79. package/src/stores/offenses_store.ts +147 -0
  80. package/src/stores/payloads_store.ts +149 -0
  81. package/src/stores/schema_version.ts +1 -0
  82. package/src/tally_slasher_client.ts +448 -0
  83. package/src/test/dummy_watcher.ts +21 -0
  84. package/src/watcher.ts +27 -0
  85. package/src/watchers/attestations_block_watcher.ts +194 -0
  86. package/src/watchers/epoch_prune_watcher.ts +253 -0
@@ -0,0 +1,176 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { chunkBy, merge, pick } from '@aztec/foundation/collection';
3
+ import { createLogger } from '@aztec/foundation/log';
4
+ import { L2BlockSourceEvents } from '@aztec/stdlib/block';
5
+ import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
6
+ import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
7
+ import { OffenseType, getOffenseTypeName } from '@aztec/stdlib/slashing';
8
+ import { ReExFailedTxsError, ReExStateMismatchError, TransactionsNotAvailableError, ValidatorError } from '@aztec/stdlib/validators';
9
+ import EventEmitter from 'node:events';
10
+ import { WANT_TO_SLASH_EVENT } from '../watcher.js';
11
+ const EpochPruneWatcherPenaltiesConfigKeys = [
12
+ 'slashPrunePenalty',
13
+ 'slashDataWithholdingPenalty'
14
+ ];
15
+ /**
16
+ * This watcher is responsible for detecting chain prunes and creating slashing arguments for the committee.
17
+ * It only wants to slash if:
18
+ * - the transactions are not available
19
+ * - OR the archive roots match when re-building all the blocks in the epoch (i.e. the epoch *could* have been proven)
20
+ */ export class EpochPruneWatcher extends EventEmitter {
21
+ l2BlockSource;
22
+ l1ToL2MessageSource;
23
+ epochCache;
24
+ txProvider;
25
+ checkpointsBuilder;
26
+ log;
27
+ // Store bound function reference for proper listener removal
28
+ boundHandlePruneL2Blocks;
29
+ penalties;
30
+ constructor(l2BlockSource, l1ToL2MessageSource, epochCache, txProvider, checkpointsBuilder, penalties){
31
+ super(), this.l2BlockSource = l2BlockSource, this.l1ToL2MessageSource = l1ToL2MessageSource, this.epochCache = epochCache, this.txProvider = txProvider, this.checkpointsBuilder = checkpointsBuilder, this.log = createLogger('epoch-prune-watcher'), this.boundHandlePruneL2Blocks = this.handlePruneL2Blocks.bind(this);
32
+ this.penalties = pick(penalties, ...EpochPruneWatcherPenaltiesConfigKeys);
33
+ this.log.verbose(`EpochPruneWatcher initialized with penalties: valid epoch pruned=${penalties.slashPrunePenalty} data withholding=${penalties.slashDataWithholdingPenalty}`);
34
+ }
35
+ start() {
36
+ this.l2BlockSource.events.on(L2BlockSourceEvents.L2PruneUnproven, this.boundHandlePruneL2Blocks);
37
+ return Promise.resolve();
38
+ }
39
+ stop() {
40
+ this.l2BlockSource.events.removeListener(L2BlockSourceEvents.L2PruneUnproven, this.boundHandlePruneL2Blocks);
41
+ return Promise.resolve();
42
+ }
43
+ updateConfig(config) {
44
+ this.penalties = merge(this.penalties, pick(config, ...EpochPruneWatcherPenaltiesConfigKeys));
45
+ this.log.verbose('EpochPruneWatcher config updated', this.penalties);
46
+ }
47
+ handlePruneL2Blocks(event) {
48
+ const { blocks, epochNumber } = event;
49
+ void this.processPruneL2Blocks(blocks, epochNumber).catch((err)=>this.log.error('Error processing pruned L2 blocks', err, {
50
+ epochNumber
51
+ }));
52
+ }
53
+ async emitSlashForEpoch(offense, epochNumber) {
54
+ const validators = await this.getValidatorsForEpoch(epochNumber);
55
+ if (validators.length === 0) {
56
+ this.log.warn(`No validators found for epoch ${epochNumber} (cannot slash for ${getOffenseTypeName(offense)})`);
57
+ return;
58
+ }
59
+ const args = this.validatorsToSlashingArgs(validators, offense, epochNumber);
60
+ this.log.verbose(`Created slash for ${getOffenseTypeName(offense)} at epoch ${epochNumber}`, args);
61
+ this.emit(WANT_TO_SLASH_EVENT, args);
62
+ }
63
+ async processPruneL2Blocks(blocks, epochNumber) {
64
+ try {
65
+ const l1Constants = this.epochCache.getL1Constants();
66
+ const epochBlocks = blocks.filter((b)=>getEpochAtSlot(b.header.getSlot(), l1Constants) === epochNumber);
67
+ this.log.info(`Detected chain prune. Validating epoch ${epochNumber} with blocks ${epochBlocks[0]?.number} to ${epochBlocks[epochBlocks.length - 1]?.number}.`, {
68
+ blocks: epochBlocks.map((b)=>b.toBlockInfo())
69
+ });
70
+ await this.validateBlocks(epochBlocks, epochNumber);
71
+ this.log.info(`Pruned epoch ${epochNumber} was valid. Want to slash committee for not having it proven.`);
72
+ await this.emitSlashForEpoch(OffenseType.VALID_EPOCH_PRUNED, epochNumber);
73
+ } catch (error) {
74
+ if (error instanceof TransactionsNotAvailableError) {
75
+ this.log.info(`Data for pruned epoch ${epochNumber} was not available. Will want to slash.`, {
76
+ message: error.message
77
+ });
78
+ await this.emitSlashForEpoch(OffenseType.DATA_WITHHOLDING, epochNumber);
79
+ } else {
80
+ this.log.error(`Error while validating pruned epoch ${epochNumber}. Will not want to slash.`, error);
81
+ }
82
+ }
83
+ }
84
+ async validateBlocks(blocks, epochNumber) {
85
+ if (blocks.length === 0) {
86
+ return;
87
+ }
88
+ // Sort blocks by block number and group by checkpoint
89
+ const sortedBlocks = [
90
+ ...blocks
91
+ ].sort((a, b)=>a.number - b.number);
92
+ const blocksByCheckpoint = chunkBy(sortedBlocks, (b)=>b.checkpointNumber);
93
+ // Get prior checkpoints in the epoch (in case this was a partial prune) to extract the out hashes
94
+ const priorCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(epochNumber)).filter((c)=>c.checkpointNumber < sortedBlocks[0].checkpointNumber).map((c)=>c.checkpointOutHash);
95
+ let previousCheckpointOutHashes = [
96
+ ...priorCheckpointOutHashes
97
+ ];
98
+ const fork = await this.checkpointsBuilder.getFork(BlockNumber(sortedBlocks[0].header.globalVariables.blockNumber - 1));
99
+ try {
100
+ for (const checkpointBlocks of blocksByCheckpoint){
101
+ await this.validateCheckpoint(checkpointBlocks, previousCheckpointOutHashes, fork);
102
+ // Compute checkpoint out hash from all blocks in this checkpoint
103
+ const checkpointOutHash = computeCheckpointOutHash(checkpointBlocks.map((b)=>b.body.txEffects.map((tx)=>tx.l2ToL1Msgs)));
104
+ previousCheckpointOutHashes = [
105
+ ...previousCheckpointOutHashes,
106
+ checkpointOutHash
107
+ ];
108
+ }
109
+ } finally{
110
+ await fork.close();
111
+ }
112
+ }
113
+ async validateCheckpoint(checkpointBlocks, previousCheckpointOutHashes, fork) {
114
+ const checkpointNumber = checkpointBlocks[0].checkpointNumber;
115
+ this.log.debug(`Validating pruned checkpoint ${checkpointNumber} with ${checkpointBlocks.length} blocks`);
116
+ // Get L1ToL2Messages once for the entire checkpoint
117
+ const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
118
+ // Build checkpoint constants from first block's global variables
119
+ const gv = checkpointBlocks[0].header.globalVariables;
120
+ const constants = {
121
+ chainId: gv.chainId,
122
+ version: gv.version,
123
+ slotNumber: gv.slotNumber,
124
+ timestamp: gv.timestamp,
125
+ coinbase: gv.coinbase,
126
+ feeRecipient: gv.feeRecipient,
127
+ gasFees: gv.gasFees
128
+ };
129
+ // Start checkpoint builder once for all blocks in this checkpoint
130
+ const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(checkpointNumber, constants, 0n, l1ToL2Messages, previousCheckpointOutHashes, fork, this.log.getBindings());
131
+ // Validate all blocks in the checkpoint sequentially
132
+ for (const block of checkpointBlocks){
133
+ await this.validateBlockInCheckpoint(block, checkpointBuilder);
134
+ }
135
+ }
136
+ async validateBlockInCheckpoint(blockFromL1, checkpointBuilder) {
137
+ this.log.debug(`Validating pruned block ${blockFromL1.header.globalVariables.blockNumber}`);
138
+ const txHashes = blockFromL1.body.txEffects.map((txEffect)=>txEffect.txHash);
139
+ // We load txs from the mempool directly, since the TxCollector running in the background has already been
140
+ // trying to fetch them from nodes or via reqresp. If we haven't managed to collect them by now,
141
+ // it's likely that they are not available in the network at all.
142
+ const { txs, missingTxs } = await this.txProvider.getAvailableTxs(txHashes);
143
+ if (missingTxs && missingTxs.length > 0) {
144
+ throw new TransactionsNotAvailableError(missingTxs);
145
+ }
146
+ const gv = blockFromL1.header.globalVariables;
147
+ const { block, failedTxs, numTxs } = await checkpointBuilder.buildBlock(txs, gv.blockNumber, gv.timestamp, {});
148
+ if (numTxs !== txs.length) {
149
+ // This should be detected by state mismatch, but this makes it easier to debug.
150
+ throw new ValidatorError(`Built block with ${numTxs} txs, expected ${txs.length}`);
151
+ }
152
+ if (failedTxs.length > 0) {
153
+ throw new ReExFailedTxsError(failedTxs.length);
154
+ }
155
+ if (!block.archive.root.equals(blockFromL1.archive.root)) {
156
+ throw new ReExStateMismatchError(blockFromL1.archive.root, block.archive.root);
157
+ }
158
+ }
159
+ async getValidatorsForEpoch(epochNumber) {
160
+ const { committee } = await this.epochCache.getCommitteeForEpoch(epochNumber);
161
+ if (!committee) {
162
+ this.log.trace(`No committee found for epoch ${epochNumber}`);
163
+ return [];
164
+ }
165
+ return committee;
166
+ }
167
+ validatorsToSlashingArgs(validators, offenseType, epochOrSlot) {
168
+ const penalty = offenseType === OffenseType.DATA_WITHHOLDING ? this.penalties.slashDataWithholdingPenalty : this.penalties.slashPrunePenalty;
169
+ return validators.map((v)=>({
170
+ validator: v,
171
+ amount: penalty,
172
+ offenseType,
173
+ epochOrSlot: BigInt(epochOrSlot)
174
+ }));
175
+ }
176
+ }
package/package.json ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "@aztec/slasher",
3
+ "version": "0.0.1-commit.001888fc",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./dest/index.js",
7
+ "./config": "./dest/config.js"
8
+ },
9
+ "inherits": [
10
+ "../package.common.json",
11
+ "./package.local.json"
12
+ ],
13
+ "scripts": {
14
+ "build": "yarn clean && ../scripts/tsc.sh",
15
+ "build:dev": "../scripts/tsc.sh --watch",
16
+ "clean": "rm -rf ./dest .tsbuildinfo",
17
+ "bb": "node --no-warnings ./dest/bb/index.js",
18
+ "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
19
+ "generate": "./scripts/generate.sh"
20
+ },
21
+ "jest": {
22
+ "moduleNameMapper": {
23
+ "^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
24
+ },
25
+ "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
26
+ "rootDir": "./src",
27
+ "transform": {
28
+ "^.+\\.tsx?$": [
29
+ "@swc/jest",
30
+ {
31
+ "jsc": {
32
+ "parser": {
33
+ "syntax": "typescript",
34
+ "decorators": true
35
+ },
36
+ "transform": {
37
+ "decoratorVersion": "2022-03"
38
+ }
39
+ }
40
+ }
41
+ ]
42
+ },
43
+ "extensionsToTreatAsEsm": [
44
+ ".ts"
45
+ ],
46
+ "reporters": [
47
+ "default"
48
+ ],
49
+ "testTimeout": 120000,
50
+ "setupFiles": [
51
+ "../../foundation/src/jest/setup.mjs"
52
+ ],
53
+ "testEnvironment": "../../foundation/src/jest/env.mjs",
54
+ "setupFilesAfterEnv": [
55
+ "../../foundation/src/jest/setupAfterEnv.mjs"
56
+ ]
57
+ },
58
+ "dependencies": {
59
+ "@aztec/epoch-cache": "0.0.1-commit.001888fc",
60
+ "@aztec/ethereum": "0.0.1-commit.001888fc",
61
+ "@aztec/foundation": "0.0.1-commit.001888fc",
62
+ "@aztec/kv-store": "0.0.1-commit.001888fc",
63
+ "@aztec/l1-artifacts": "0.0.1-commit.001888fc",
64
+ "@aztec/stdlib": "0.0.1-commit.001888fc",
65
+ "@aztec/telemetry-client": "0.0.1-commit.001888fc",
66
+ "source-map-support": "^0.5.21",
67
+ "tslib": "^2.4.0",
68
+ "viem": "npm:@aztec/viem@2.38.2",
69
+ "zod": "^3.23.8"
70
+ },
71
+ "devDependencies": {
72
+ "@aztec/aztec.js": "0.0.1-commit.001888fc",
73
+ "@jest/globals": "^30.0.0",
74
+ "@types/jest": "^30.0.0",
75
+ "@types/node": "^22.15.17",
76
+ "@types/source-map-support": "^0.5.10",
77
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
78
+ "jest": "^30.0.0",
79
+ "jest-mock-extended": "^4.0.0",
80
+ "ts-node": "^10.9.1",
81
+ "typescript": "^5.3.3"
82
+ },
83
+ "files": [
84
+ "dest",
85
+ "src",
86
+ "!*.test.*"
87
+ ],
88
+ "types": "./dest/index.d.ts",
89
+ "engines": {
90
+ "node": ">=20.10"
91
+ }
92
+ }
package/src/config.ts ADDED
@@ -0,0 +1,172 @@
1
+ import type { ConfigMappingsType } from '@aztec/foundation/config';
2
+ import {
3
+ bigintConfigHelper,
4
+ booleanConfigHelper,
5
+ floatConfigHelper,
6
+ numberConfigHelper,
7
+ } from '@aztec/foundation/config';
8
+ import { EthAddress } from '@aztec/foundation/eth-address';
9
+ import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
10
+
11
+ import { slasherDefaultEnv } from './generated/slasher-defaults.js';
12
+
13
+ export type { SlasherConfig };
14
+
15
+ export const DefaultSlasherConfig: SlasherConfig = {
16
+ slashOverridePayload: undefined,
17
+ slashMinPenaltyPercentage: slasherDefaultEnv.SLASH_MIN_PENALTY_PERCENTAGE,
18
+ slashMaxPenaltyPercentage: slasherDefaultEnv.SLASH_MAX_PENALTY_PERCENTAGE,
19
+ slashValidatorsAlways: [], // Empty by default
20
+ slashValidatorsNever: [], // Empty by default
21
+ slashPrunePenalty: BigInt(slasherDefaultEnv.SLASH_PRUNE_PENALTY),
22
+ slashDataWithholdingPenalty: BigInt(slasherDefaultEnv.SLASH_DATA_WITHHOLDING_PENALTY),
23
+ slashInactivityTargetPercentage: slasherDefaultEnv.SLASH_INACTIVITY_TARGET_PERCENTAGE,
24
+ slashInactivityConsecutiveEpochThreshold: slasherDefaultEnv.SLASH_INACTIVITY_CONSECUTIVE_EPOCH_THRESHOLD,
25
+ slashBroadcastedInvalidBlockPenalty: BigInt(slasherDefaultEnv.SLASH_INVALID_BLOCK_PENALTY),
26
+ slashDuplicateProposalPenalty: BigInt(slasherDefaultEnv.SLASH_DUPLICATE_PROPOSAL_PENALTY),
27
+ slashDuplicateAttestationPenalty: BigInt(slasherDefaultEnv.SLASH_DUPLICATE_ATTESTATION_PENALTY),
28
+ slashInactivityPenalty: BigInt(slasherDefaultEnv.SLASH_INACTIVITY_PENALTY),
29
+ slashProposeInvalidAttestationsPenalty: BigInt(slasherDefaultEnv.SLASH_PROPOSE_INVALID_ATTESTATIONS_PENALTY),
30
+ slashAttestDescendantOfInvalidPenalty: BigInt(slasherDefaultEnv.SLASH_ATTEST_DESCENDANT_OF_INVALID_PENALTY),
31
+ slashUnknownPenalty: BigInt(slasherDefaultEnv.SLASH_UNKNOWN_PENALTY),
32
+ slashOffenseExpirationRounds: slasherDefaultEnv.SLASH_OFFENSE_EXPIRATION_ROUNDS,
33
+ slashMaxPayloadSize: slasherDefaultEnv.SLASH_MAX_PAYLOAD_SIZE,
34
+ slashGracePeriodL2Slots: slasherDefaultEnv.SLASH_GRACE_PERIOD_L2_SLOTS,
35
+ slashExecuteRoundsLookBack: slasherDefaultEnv.SLASH_EXECUTE_ROUNDS_LOOK_BACK,
36
+ slashSelfAllowed: false,
37
+ };
38
+
39
+ export const slasherConfigMappings: ConfigMappingsType<SlasherConfig> = {
40
+ slashOverridePayload: {
41
+ env: 'SLASH_OVERRIDE_PAYLOAD',
42
+ description: 'An Ethereum address for a slash payload to vote for unconditionally.',
43
+ parseEnv: (val: string) => (val ? EthAddress.fromString(val) : undefined),
44
+ defaultValue: DefaultSlasherConfig.slashOverridePayload,
45
+ },
46
+ slashMinPenaltyPercentage: {
47
+ env: 'SLASH_MIN_PENALTY_PERCENTAGE',
48
+ description: 'Minimum penalty percentage for slashing offenses (0.1 is 10%).',
49
+ ...floatConfigHelper(DefaultSlasherConfig.slashMinPenaltyPercentage),
50
+ },
51
+ slashMaxPenaltyPercentage: {
52
+ env: 'SLASH_MAX_PENALTY_PERCENTAGE',
53
+ description: 'Maximum penalty percentage for slashing offenses (2.0 is 200%).',
54
+ ...floatConfigHelper(DefaultSlasherConfig.slashMaxPenaltyPercentage),
55
+ },
56
+ slashValidatorsAlways: {
57
+ env: 'SLASH_VALIDATORS_ALWAYS',
58
+ description: 'Comma-separated list of validator addresses that should always be slashed.',
59
+ parseEnv: (val: string) =>
60
+ val
61
+ .split(',')
62
+ .map(addr => addr.trim())
63
+ .filter(addr => addr.length > 0)
64
+ .map(addr => EthAddress.fromString(addr)),
65
+ defaultValue: DefaultSlasherConfig.slashValidatorsAlways,
66
+ },
67
+ slashValidatorsNever: {
68
+ env: 'SLASH_VALIDATORS_NEVER',
69
+ description: 'Comma-separated list of validator addresses that should never be slashed.',
70
+ parseEnv: (val: string) =>
71
+ val
72
+ .split(',')
73
+ .map(addr => addr.trim())
74
+ .filter(addr => addr.length > 0)
75
+ .map(addr => EthAddress.fromString(addr)),
76
+ defaultValue: DefaultSlasherConfig.slashValidatorsNever,
77
+ },
78
+ slashPrunePenalty: {
79
+ env: 'SLASH_PRUNE_PENALTY',
80
+ description: 'Penalty amount for slashing validators of a valid pruned epoch (set to 0 to disable).',
81
+ ...bigintConfigHelper(DefaultSlasherConfig.slashPrunePenalty),
82
+ },
83
+ slashDataWithholdingPenalty: {
84
+ env: 'SLASH_DATA_WITHHOLDING_PENALTY',
85
+ description: 'Penalty amount for slashing validators for data withholding (set to 0 to disable).',
86
+ ...bigintConfigHelper(DefaultSlasherConfig.slashDataWithholdingPenalty),
87
+ },
88
+ slashBroadcastedInvalidBlockPenalty: {
89
+ env: 'SLASH_INVALID_BLOCK_PENALTY',
90
+ description: 'Penalty amount for slashing a validator for an invalid block proposed via p2p.',
91
+ ...bigintConfigHelper(DefaultSlasherConfig.slashBroadcastedInvalidBlockPenalty),
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
+ },
104
+ slashInactivityTargetPercentage: {
105
+ env: 'SLASH_INACTIVITY_TARGET_PERCENTAGE',
106
+ description:
107
+ 'Missed attestation percentage to trigger creation of inactivity slash payload (0, 1]. Must be greater than 0',
108
+ ...floatConfigHelper(DefaultSlasherConfig.slashInactivityTargetPercentage, v => {
109
+ if (v <= 0 || v > 1) {
110
+ throw new RangeError(`SLASH_INACTIVITY_TARGET_PERCENTAGE out of range. Expected (0, 1] got ${v}`);
111
+ }
112
+ }),
113
+ },
114
+ slashInactivityConsecutiveEpochThreshold: {
115
+ env: 'SLASH_INACTIVITY_CONSECUTIVE_EPOCH_THRESHOLD',
116
+ description: 'Number of consecutive epochs a validator must be inactive before slashing (minimum 1).',
117
+ ...numberConfigHelper(DefaultSlasherConfig.slashInactivityConsecutiveEpochThreshold),
118
+ parseEnv: (val: string) => {
119
+ const parsed = parseInt(val, 10);
120
+ if (parsed < 1) {
121
+ throw new RangeError(`SLASH_INACTIVITY_CONSECUTIVE_EPOCH_THRESHOLD must be at least 1 (got ${parsed})`);
122
+ }
123
+ return parsed;
124
+ },
125
+ },
126
+ slashInactivityPenalty: {
127
+ env: 'SLASH_INACTIVITY_PENALTY',
128
+ description: 'Penalty amount for slashing an inactive validator (set to 0 to disable).',
129
+ ...bigintConfigHelper(DefaultSlasherConfig.slashInactivityPenalty),
130
+ },
131
+ slashProposeInvalidAttestationsPenalty: {
132
+ env: 'SLASH_PROPOSE_INVALID_ATTESTATIONS_PENALTY',
133
+ description: 'Penalty amount for slashing a proposer that proposed invalid attestations (set to 0 to disable).',
134
+ ...bigintConfigHelper(DefaultSlasherConfig.slashProposeInvalidAttestationsPenalty),
135
+ },
136
+ slashAttestDescendantOfInvalidPenalty: {
137
+ env: 'SLASH_ATTEST_DESCENDANT_OF_INVALID_PENALTY',
138
+ description:
139
+ 'Penalty amount for slashing a validator that attested to a descendant of an invalid block (set to 0 to disable).',
140
+ ...bigintConfigHelper(DefaultSlasherConfig.slashAttestDescendantOfInvalidPenalty),
141
+ },
142
+ slashUnknownPenalty: {
143
+ env: 'SLASH_UNKNOWN_PENALTY',
144
+ description: 'Penalty amount for slashing a validator for an unknown offense (set to 0 to disable).',
145
+ ...bigintConfigHelper(DefaultSlasherConfig.slashUnknownPenalty),
146
+ },
147
+ slashOffenseExpirationRounds: {
148
+ env: 'SLASH_OFFENSE_EXPIRATION_ROUNDS',
149
+ description: 'Number of rounds after which pending offenses expire.',
150
+ ...numberConfigHelper(DefaultSlasherConfig.slashOffenseExpirationRounds),
151
+ },
152
+ slashMaxPayloadSize: {
153
+ env: 'SLASH_MAX_PAYLOAD_SIZE',
154
+ description: 'Maximum number of offenses to include in a single slash payload.',
155
+ ...numberConfigHelper(DefaultSlasherConfig.slashMaxPayloadSize),
156
+ },
157
+ slashGracePeriodL2Slots: {
158
+ description:
159
+ 'Number of L2 slots after the network upgrade during which slashing offenses are ignored. The upgrade time is determined from the CanonicalRollupUpdated event.',
160
+ env: 'SLASH_GRACE_PERIOD_L2_SLOTS',
161
+ ...numberConfigHelper(DefaultSlasherConfig.slashGracePeriodL2Slots),
162
+ },
163
+ slashExecuteRoundsLookBack: {
164
+ env: 'SLASH_EXECUTE_ROUNDS_LOOK_BACK',
165
+ description: 'How many rounds to look back when searching for a round to execute.',
166
+ ...numberConfigHelper(DefaultSlasherConfig.slashExecuteRoundsLookBack),
167
+ },
168
+ slashSelfAllowed: {
169
+ description: 'Whether to allow slashes to own validators',
170
+ ...booleanConfigHelper(DefaultSlasherConfig.slashSelfAllowed),
171
+ },
172
+ };