@aztec/slasher 2.0.0-nightly.20250821 → 2.0.0-nightly.20250823

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 (68) hide show
  1. package/README.md +143 -2
  2. package/dest/config.d.ts +0 -19
  3. package/dest/config.d.ts.map +1 -1
  4. package/dest/config.js +37 -16
  5. package/dest/empire_slasher_client.d.ts +192 -0
  6. package/dest/empire_slasher_client.d.ts.map +1 -0
  7. package/dest/empire_slasher_client.js +605 -0
  8. package/dest/factory.d.ts +21 -0
  9. package/dest/factory.d.ts.map +1 -0
  10. package/dest/factory.js +95 -0
  11. package/dest/index.d.ts +8 -3
  12. package/dest/index.d.ts.map +1 -1
  13. package/dest/index.js +8 -3
  14. package/dest/slash_offenses_collector.d.ts +43 -0
  15. package/dest/slash_offenses_collector.d.ts.map +1 -0
  16. package/dest/slash_offenses_collector.js +86 -0
  17. package/dest/slash_round_monitor.d.ts +28 -0
  18. package/dest/slash_round_monitor.d.ts.map +1 -0
  19. package/dest/slash_round_monitor.js +52 -0
  20. package/dest/slasher_client_facade.d.ts +43 -0
  21. package/dest/slasher_client_facade.d.ts.map +1 -0
  22. package/dest/slasher_client_facade.js +75 -0
  23. package/dest/slasher_client_interface.d.ts +38 -0
  24. package/dest/slasher_client_interface.d.ts.map +1 -0
  25. package/dest/slasher_client_interface.js +4 -0
  26. package/dest/stores/offenses_store.d.ts +33 -0
  27. package/dest/stores/offenses_store.d.ts.map +1 -0
  28. package/dest/stores/offenses_store.js +66 -0
  29. package/dest/stores/payloads_store.d.ts +22 -0
  30. package/dest/stores/payloads_store.d.ts.map +1 -0
  31. package/dest/stores/payloads_store.js +90 -0
  32. package/dest/stores/schema_version.d.ts +2 -0
  33. package/dest/stores/schema_version.d.ts.map +1 -0
  34. package/dest/stores/schema_version.js +1 -0
  35. package/dest/tally_slasher_client.d.ts +117 -0
  36. package/dest/tally_slasher_client.d.ts.map +1 -0
  37. package/dest/tally_slasher_client.js +223 -0
  38. package/dest/watcher.d.ts +19 -0
  39. package/dest/watcher.d.ts.map +1 -0
  40. package/dest/watcher.js +1 -0
  41. package/dest/{attestations_block_watcher.d.ts → watchers/attestations_block_watcher.d.ts} +3 -7
  42. package/dest/watchers/attestations_block_watcher.d.ts.map +1 -0
  43. package/dest/{attestations_block_watcher.js → watchers/attestations_block_watcher.js} +10 -54
  44. package/dest/{epoch_prune_watcher.d.ts → watchers/epoch_prune_watcher.d.ts} +2 -8
  45. package/dest/watchers/epoch_prune_watcher.d.ts.map +1 -0
  46. package/dest/{epoch_prune_watcher.js → watchers/epoch_prune_watcher.js} +11 -36
  47. package/package.json +9 -8
  48. package/src/config.ts +36 -41
  49. package/src/empire_slasher_client.ts +684 -0
  50. package/src/factory.ts +211 -0
  51. package/src/index.ts +8 -3
  52. package/src/slash_offenses_collector.ts +107 -0
  53. package/src/slash_round_monitor.ts +64 -0
  54. package/src/slasher_client_facade.ts +99 -0
  55. package/src/slasher_client_interface.ts +45 -0
  56. package/src/stores/offenses_store.ts +98 -0
  57. package/src/stores/payloads_store.ts +101 -0
  58. package/src/stores/schema_version.ts +1 -0
  59. package/src/tally_slasher_client.ts +292 -0
  60. package/src/watcher.ts +24 -0
  61. package/src/{attestations_block_watcher.ts → watchers/attestations_block_watcher.ts} +16 -67
  62. package/src/{epoch_prune_watcher.ts → watchers/epoch_prune_watcher.ts} +14 -40
  63. package/dest/attestations_block_watcher.d.ts.map +0 -1
  64. package/dest/epoch_prune_watcher.d.ts.map +0 -1
  65. package/dest/slasher_client.d.ts +0 -158
  66. package/dest/slasher_client.d.ts.map +0 -1
  67. package/dest/slasher_client.js +0 -442
  68. package/src/slasher_client.ts +0 -532
package/README.md CHANGED
@@ -1,5 +1,146 @@
1
1
  # Slasher
2
2
 
3
- We slashin.
3
+ ## Overview
4
4
 
5
- See [slasher_client.ts](./src/slasher_client.ts) for more details.
5
+ The slasher module implements validator slashing for the Aztec network. Slashing punishes validators who misbehave or are inactive by reducing their stake. This mechanism ensures network security and liveness.
6
+
7
+ ## Usage
8
+
9
+ The slasher is integrated into the Aztec node and activates when:
10
+ 1. The node is configured as a validator
11
+ 2. The validator is selected as proposer for a slot
12
+ 3. Slashable offenses have been detected
13
+
14
+ No manual intervention is required for normal operation. The slasher client handles:
15
+ - Monitoring for offenses
16
+ - Generating appropriate slash actions
17
+ - Coordinating with the SequencerPublisher for L1 execution
18
+
19
+ ## Slashing Models
20
+
21
+ The system supports two slashing models:
22
+
23
+ ### Tally Model
24
+
25
+ _This is the model currently in use._
26
+
27
+ The tally model uses consensus-based voting where proposers vote on individual validator offenses. Time is divided into rounds, and during each round, proposers submit votes indicating which validators should be slashed. Votes are encoded as bytes where each validator's vote is represented by 2 bits indicating the slash amount (0-3 slash units) for each validator. The L1 contract tallies votes and slashes validators that reach quorum.
28
+
29
+ Key characteristics:
30
+ - Proposers vote directly on validator offenses
31
+ - Uses a slash offset to vote on validators from past rounds (e.g., round N votes on round N-2)
32
+ - Requires quorum to execute slashing
33
+ - L1 contract determines which offenses reach consensus
34
+ - Execution happens after a delay period for review
35
+
36
+ ### Empire Model
37
+
38
+ _This model was developed during an earlier iteration and later modified, but never tested in a real network. It remains in the code in case we decide to switch from the tally model in the future._
39
+
40
+ The empire model piggybacks on the empire governance system and uses fixed slash payloads that are created and voted on. Proposers aggregate pending offenses and create payloads containing multiple offenses, or vote for existing payloads. The payload with the highest score (based on total offenses, votes received, and round progress) gets executed.
41
+
42
+ Key characteristics:
43
+ - Fixed payloads containing multiple offenses
44
+ - Payload scoring system for selection
45
+ - Requires agreement on payload contents (main reason why it was dropped in favor of the Tally model)
46
+
47
+ ## Architecture
48
+
49
+ ### Core Components
50
+
51
+ #### SlasherClientInterface
52
+ Common interface implemented by both tally and empire clients. Provides methods for:
53
+ - `getProposerActions()`: Returns actions for the current proposer
54
+ - `gatherOffensesForRound()`: Collects offenses for a specific round
55
+
56
+ #### SlashOffensesCollector
57
+ Collects slashable offenses from watchers and stores them in the offenses store. Features:
58
+ - Subscribes to `WANT_TO_SLASH_EVENT` from watchers
59
+ - Manages offense lifecycle and expiration
60
+
61
+ #### SlasherOffensesStore
62
+ Persistent storage for offenses. Tracks:
63
+ - Pending offenses awaiting slashing
64
+ - Executed offenses to prevent double slashing
65
+ - Round-based offense organization
66
+
67
+ #### SlashRoundMonitor
68
+ Monitors slashing rounds and triggers actions on round transitions:
69
+ - Tracks current round based on L2 slots
70
+ - Emits events when rounds change
71
+
72
+ #### ProposerSlashAction
73
+ Actions returned by the slasher client to the SequencerPublisher:
74
+ - `vote-offenses`: Vote on validator offenses (tally model)
75
+ - `execute-slash`: Execute slashing for a round that reached quorum (tally model)
76
+ - `create-empire-payload`: Create a new slash payload (empire model)
77
+ - `vote-empire-payload`: Vote for an existing payload (empire model)
78
+ - `execute-empire-payload`: Execute a payload with sufficient votes (empire model)
79
+
80
+ ### Integration Flow
81
+
82
+ 1. **Offense Detection**: Watchers monitor the network and emit `WANT_TO_SLASH_EVENT` when they detect violations
83
+ 2. **Offense Collection**: SlashOffensesCollector receives events and stores offenses in SlasherOffensesStore
84
+ 3. **Action Generation**: When a validator is proposer, the slasher client generates ProposerSlashActions
85
+ 4. **Action Execution**: SequencerPublisher receives actions and executes them on L1
86
+ 5. **Round Monitoring**: SlashRoundMonitor tracks rounds and triggers execution when conditions are met
87
+
88
+ ## Slashable Offenses
89
+
90
+ ### DATA_WITHHOLDING
91
+ **Description**: The data required for proving an epoch was not made publicly available.
92
+ **Detection**: EpochPruneWatcher detects when an epoch cannot be proven due to missing data.
93
+ **Target**: Committee members of the affected epoch.
94
+ **Time Unit**: Epoch-based offense.
95
+
96
+ ### VALID_EPOCH_PRUNED
97
+ **Description**: An epoch was not successfully proven within the proof submission window.
98
+ **Detection**: EpochPruneWatcher monitors epochs that expire without valid proofs.
99
+ **Target**: Committee members of the unpruned epoch.
100
+ **Time Unit**: Epoch-based offense.
101
+
102
+ ### INACTIVITY
103
+ **Description**: A proposer failed to attest or propose blocks during their assigned slots.
104
+ **Detection**: Sentinel tracks validator performance and identifies validators who miss attestations beyond threshold.
105
+ **Target**: Individual inactive validator.
106
+ **Time Unit**: Epoch-based offense.
107
+
108
+ ### BROADCASTED_INVALID_BLOCK_PROPOSAL
109
+ **Description**: A proposer broadcast an invalid block proposal over the p2p network.
110
+ **Detection**: Validators detect invalid proposals during attestation validation.
111
+ **Target**: Proposer who broadcast the invalid block.
112
+ **Time Unit**: Slot-based offense.
113
+ **Note**: Currently not actively monitored in production.
114
+
115
+ ### PROPOSED_INSUFFICIENT_ATTESTATIONS
116
+ **Description**: A proposer submitted a block to L1 without sufficient committee attestations.
117
+ **Detection**: AttestationsBlockWatcher checks L1 blocks for attestation count.
118
+ **Target**: Block proposer.
119
+ **Time Unit**: Slot-based offense.
120
+
121
+ ### PROPOSED_INCORRECT_ATTESTATIONS
122
+ **Description**: A proposer submitted a block to L1 with signatures from non-committee members.
123
+ **Detection**: AttestationsBlockWatcher validates attestation signatures against committee membership.
124
+ **Target**: Block proposer.
125
+ **Time Unit**: Slot-based offense.
126
+
127
+ ### ATTESTED_DESCENDANT_OF_INVALID
128
+ **Description**: A committee member attested to a block built on top of an invalid ancestor.
129
+ **Detection**: AttestationsBlockWatcher tracks invalid blocks and their descendants.
130
+ **Target**: Committee members who attested to the descendant block.
131
+ **Time Unit**: Slot-based offense.
132
+
133
+ ## Configuration
134
+
135
+ ### Slasher Configuration
136
+ - `slashGracePeriodL2Slots`: Number of initial L2 slots where slashing is disabled
137
+ - `slashMaxPayloadSize`: Maximum size of slash payloads (empire model)
138
+ - `slashingRoundSize`: Number of slots per slashing round
139
+ - `slashingQuorumSize`: Votes required to slash (tally model)
140
+ - `slashingOffsetInRounds`: How many rounds to look back for offenses (tally model)
141
+ - `slashingExecutionDelayInRounds`: Rounds to wait before execution
142
+ - `slashingLifetimeInRounds`: Maximum age of executable rounds
143
+ - `slashingUnit`: Base slashing amount per unit
144
+
145
+ ### Environment Variables
146
+ - `SLASHER_CLIENT_TYPE`: Select between 'tally' or 'empire' (default: 'tally')
package/dest/config.d.ts CHANGED
@@ -1,25 +1,6 @@
1
1
  import type { ConfigMappingsType } from '@aztec/foundation/config';
2
- import { EthAddress } from '@aztec/foundation/eth-address';
3
- import type { TypedEventEmitter } from '@aztec/foundation/types';
4
2
  import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
5
- import { Offense } from '@aztec/stdlib/slashing';
6
3
  export type { SlasherConfig };
7
- export declare const WANT_TO_SLASH_EVENT: "wantToSlash";
8
- export interface WantToSlashArgs {
9
- validator: EthAddress;
10
- amount: bigint;
11
- offense: Offense;
12
- }
13
- export interface WatcherEventMap {
14
- [WANT_TO_SLASH_EVENT]: (args: WantToSlashArgs[]) => void;
15
- }
16
- export type WatcherEmitter = TypedEventEmitter<WatcherEventMap>;
17
- export type CheckSlashFn = (args: WantToSlashArgs) => Promise<boolean>;
18
- export type Watcher = WatcherEmitter & {
19
- shouldSlash: CheckSlashFn;
20
- start?: () => Promise<void>;
21
- stop?: () => Promise<void>;
22
- };
23
4
  export declare const DefaultSlasherConfig: SlasherConfig;
24
5
  export declare const slasherConfigMappings: ConfigMappingsType<SlasherConfig>;
25
6
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AASnE,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B,eAAO,MAAM,mBAAmB,EAAG,aAAsB,CAAC;AAE1D,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,UAAU,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB;AAGD,MAAM,WAAW,eAAe;IAC9B,CAAC,mBAAmB,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;CAC1D;AAED,MAAM,MAAM,cAAc,GAAG,iBAAiB,CAAC,eAAe,CAAC,CAAC;AAEhE,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAEvE,MAAM,MAAM,OAAO,GAAG,cAAc,GAAG;IACrC,WAAW,EAAE,YAAY,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,aAoBlC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,kBAAkB,CAAC,aAAa,CAyGnE,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAQnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAErE,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B,eAAO,MAAM,oBAAoB,EAAE,aAwBlC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,kBAAkB,CAAC,aAAa,CA4HnE,CAAC"}
package/dest/config.js CHANGED
@@ -1,16 +1,14 @@
1
- import { NULL_KEY } from '@aztec/ethereum';
2
- import { SecretValue, bigintConfigHelper, booleanConfigHelper, floatConfigHelper, numberConfigHelper, secretValueConfigHelper } from '@aztec/foundation/config';
1
+ import { bigintConfigHelper, booleanConfigHelper, floatConfigHelper, numberConfigHelper } from '@aztec/foundation/config';
3
2
  import { EthAddress } from '@aztec/foundation/eth-address';
4
- export const WANT_TO_SLASH_EVENT = 'wantToSlash';
5
3
  export const DefaultSlasherConfig = {
6
4
  slashPayloadTtlSeconds: 60 * 60 * 24,
7
5
  slashOverridePayload: undefined,
8
6
  slashPruneEnabled: true,
9
7
  slashPrunePenalty: 1n,
10
8
  slashPruneMaxPenalty: 100n,
11
- slashInvalidBlockEnabled: true,
12
- slashInvalidBlockPenalty: 1n,
13
- slashInvalidBlockMaxPenalty: 100n,
9
+ slashBroadcastedInvalidBlockEnabled: true,
10
+ slashBroadcastedInvalidBlockPenalty: 1n,
11
+ slashBroadcastedInvalidBlockMaxPenalty: 100n,
14
12
  slashInactivityEnabled: true,
15
13
  slashInactivityCreateTargetPercentage: 0.9,
16
14
  slashInactivitySignalTargetPercentage: 0.6,
@@ -20,8 +18,12 @@ export const DefaultSlasherConfig = {
20
18
  slashProposeInvalidAttestationsMaxPenalty: 100n,
21
19
  slashAttestDescendantOfInvalidPenalty: 1n,
22
20
  slashAttestDescendantOfInvalidMaxPenalty: 100n,
21
+ slashUnknownPenalty: 1n,
22
+ slashUnknownMaxPenalty: 100n,
23
23
  slashProposerRoundPollingIntervalSeconds: 12,
24
- slasherPrivateKey: new SecretValue(undefined)
24
+ slashOffenseExpirationRounds: 4,
25
+ slashMaxPayloadSize: 50,
26
+ slashGracePeriodL2Slots: 0
25
27
  };
26
28
  export const slasherConfigMappings = {
27
29
  slashPayloadTtlSeconds: {
@@ -50,20 +52,20 @@ export const slasherConfigMappings = {
50
52
  description: 'Maximum penalty amount for slashing validators of a pruned epoch.',
51
53
  ...bigintConfigHelper(DefaultSlasherConfig.slashPruneMaxPenalty)
52
54
  },
53
- slashInvalidBlockEnabled: {
55
+ slashBroadcastedInvalidBlockEnabled: {
54
56
  env: 'SLASH_INVALID_BLOCK_ENABLED',
55
57
  description: 'Enable creation of slash payloads for invalid blocks.',
56
- ...booleanConfigHelper(DefaultSlasherConfig.slashInvalidBlockEnabled)
58
+ ...booleanConfigHelper(DefaultSlasherConfig.slashBroadcastedInvalidBlockEnabled)
57
59
  },
58
- slashInvalidBlockPenalty: {
60
+ slashBroadcastedInvalidBlockPenalty: {
59
61
  env: 'SLASH_INVALID_BLOCK_PENALTY',
60
62
  description: 'Penalty amount for slashing a validator for an invalid block.',
61
- ...bigintConfigHelper(DefaultSlasherConfig.slashInvalidBlockPenalty)
63
+ ...bigintConfigHelper(DefaultSlasherConfig.slashBroadcastedInvalidBlockPenalty)
62
64
  },
63
- slashInvalidBlockMaxPenalty: {
65
+ slashBroadcastedInvalidBlockMaxPenalty: {
64
66
  env: 'SLASH_INVALID_BLOCK_MAX_PENALTY',
65
67
  description: 'Maximum penalty amount for slashing a validator for an invalid block.',
66
- ...bigintConfigHelper(DefaultSlasherConfig.slashInvalidBlockMaxPenalty)
68
+ ...bigintConfigHelper(DefaultSlasherConfig.slashBroadcastedInvalidBlockMaxPenalty)
67
69
  },
68
70
  slashInactivityEnabled: {
69
71
  env: 'SLASH_INACTIVITY_ENABLED',
@@ -118,12 +120,31 @@ export const slasherConfigMappings = {
118
120
  description: 'Maximum penalty amount for slashing a validator that attested to a descendant of an invalid block.',
119
121
  ...bigintConfigHelper(DefaultSlasherConfig.slashAttestDescendantOfInvalidMaxPenalty)
120
122
  },
123
+ slashUnknownPenalty: {
124
+ env: 'SLASH_UNKNOWN_PENALTY',
125
+ description: 'Penalty amount for slashing a validator for an unknown offense.',
126
+ ...bigintConfigHelper(DefaultSlasherConfig.slashUnknownPenalty)
127
+ },
128
+ slashUnknownMaxPenalty: {
129
+ env: 'SLASH_UNKNOWN_MAX_PENALTY',
130
+ description: 'Maximum penalty amount for slashing a validator for an unknown offense.',
131
+ ...bigintConfigHelper(DefaultSlasherConfig.slashUnknownMaxPenalty)
132
+ },
121
133
  slashProposerRoundPollingIntervalSeconds: {
122
134
  description: 'Polling interval for slashing proposer round in seconds.',
123
135
  ...numberConfigHelper(DefaultSlasherConfig.slashProposerRoundPollingIntervalSeconds)
124
136
  },
125
- slasherPrivateKey: {
126
- description: 'Private key used for creating slash payloads.',
127
- ...secretValueConfigHelper((val)=>val ? `0x${val.replace('0x', '')}` : NULL_KEY)
137
+ slashOffenseExpirationRounds: {
138
+ description: 'Number of rounds after which pending offenses expire.',
139
+ ...numberConfigHelper(DefaultSlasherConfig.slashOffenseExpirationRounds)
140
+ },
141
+ slashMaxPayloadSize: {
142
+ description: 'Maximum number of offenses to include in a single slash payload.',
143
+ ...numberConfigHelper(DefaultSlasherConfig.slashMaxPayloadSize)
144
+ },
145
+ slashGracePeriodL2Slots: {
146
+ description: 'Number of L2 slots to wait before considering a slashing offense expired.',
147
+ env: 'SLASH_GRACE_PERIOD_L2_SLOTS',
148
+ ...numberConfigHelper(DefaultSlasherConfig.slashGracePeriodL2Slots)
128
149
  }
129
150
  };
@@ -0,0 +1,192 @@
1
+ import { EmpireSlashingProposerContract } from '@aztec/ethereum';
2
+ import { EthAddress } from '@aztec/foundation/eth-address';
3
+ import type { DateProvider } from '@aztec/foundation/timer';
4
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
5
+ import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
6
+ import { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
7
+ import { type Offense, type ProposerSlashAction, type ProposerSlashActionProvider, type SlashPayload, type SlashPayloadRound } from '@aztec/stdlib/slashing';
8
+ import { type SlashOffensesCollectorSettings } from './slash_offenses_collector.js';
9
+ import type { SlasherClientInterface } from './slasher_client_interface.js';
10
+ import type { SlasherOffensesStore } from './stores/offenses_store.js';
11
+ import type { SlasherPayloadsStore } from './stores/payloads_store.js';
12
+ import type { Watcher } from './watcher.js';
13
+ /** Used to track executable payloads for each round */
14
+ export type PayloadWithRound = {
15
+ payload: EthAddress;
16
+ round: bigint;
17
+ };
18
+ /** Node configuration for the empire slasher */
19
+ export type EmpireSlasherConfig = SlasherConfig;
20
+ /** Settings used in the empire slasher client, loaded from the L1 contracts during initialization */
21
+ export type EmpireSlasherSettings = {
22
+ slashingExecutionDelayInRounds: number;
23
+ slashingPayloadLifetimeInRounds: number;
24
+ slashingRoundSize: number;
25
+ slashingQuorumSize: number;
26
+ } & Pick<L1RollupConstants, 'epochDuration' | 'proofSubmissionEpochs' | 'l1GenesisTime' | 'slotDuration' | 'l1StartBlock' | 'ethereumSlotDuration'> & SlashOffensesCollectorSettings;
27
+ /**
28
+ * The Empire Slasher client is responsible for managing slashable offenses and slash payloads
29
+ * using the Empire slashing model where fixed payloads are created and voted on.
30
+ *
31
+ * The client subscribes to several slash watchers that emit offenses and tracks them. When the slasher is the
32
+ * proposer, it aggregates pending offenses from previous rounds and creates slash payloads, or votes for previous
33
+ * slash payloads.
34
+ * Voting is handled by the sequencer publisher, the slasher client does not interact with L1 directly.
35
+ * The client also monitors slash payloads created by other nodes, and executes them when they become submittable.
36
+ *
37
+ * Payload creation and selection
38
+ * - At each L2 slot in a slashing round, the proposer for that L2 slot may vote for an existing slashing payload or
39
+ * create one of their own. Note that anyone can create a slash payload on L1, but nodes will only follow payloads
40
+ * from proposers; we could enforce this on L1, but we do not want to make any changes there if we can avoid it.
41
+ * - If it is the first L2 slot in the slashing round, there is nothing to vote for, so the proposer creates a slash
42
+ * payload and votes for it.
43
+ * - On their turn, each proposer computes a score for each payload in the round. This score is a function of the
44
+ * total offences slashed, how many votes it has received so far, and how far into the round we are. The score for a
45
+ * payload is zero if the proposer disagrees with it (see "agreement" below).
46
+ * - The proposer also computes the score for the payload they would create. If the resulting score is higher than
47
+ * any existing payload, it creates the payload. Otherwise, it votes for the one with the highest score.
48
+ *
49
+ * Collecting offences
50
+ * - Whenever a node spots a slashable offence, they store it and add it to a local collection of "pending
51
+ * offences". When a proposer needs to create a slash payload, they include all pending offences from previous
52
+ * rounds. This means an offence is **only slashable in the next round it happened** (or a future one).
53
+ * - Each offence also carries an epoch or block identifier, so we can differentiate two offences of the same kind by
54
+ * the same validator.
55
+ * - When a slash payload is flagged as executable (as in it got enough votes to be executed), nodes remove all
56
+ * slashed offences in the payload from their collection of pending offences.
57
+ * - Pending offences expire after a configurable time. This is to minimize divergences. For instance, a validator
58
+ * that has to be slashed due to inactivity 50 epochs ago will only be considered for slashing by nodes that were
59
+ * online 50 epochs ago. We propose using the validator exit window as expiration time, any value higher means that
60
+ * we may try slashing validators that have exited the set already.
61
+ *
62
+ * Agreement and scoring
63
+ * - A proposer will *agree* with a slash payload if it *agrees* with every offence in the payload, all
64
+ * *uncontroversial* offences from the past round are included, and it is below a configurable maximum size.
65
+ * - An *uncontroversial* offence is one where every node agrees that a slash is in order, regardless of any p2p
66
+ * network partitions. The only uncontroversial offence we have now is "proposing a block on L1 with invalid
67
+ * attestations".
68
+ * - A proposer will *agree* with a given offence if it is present in its list of "pending offences", and the
69
+ * slashing amount is within a configurable min-max range.
70
+ * - Slash payloads need a maximum size to ensure they can don't exceed the maximum L1 gas per tx when executed.
71
+ * This is configurable but depends on the L1 contracts implementation. When creating a payload, if there are too
72
+ * many pending offences to fit, proposers favor the offences with the highest slashing amount first, tie-breaking by
73
+ * choosing the most recent ones.
74
+ * - The scoring function will boost proposals with more agreed slashes, as well as proposals with more votes, and
75
+ * will disincentivize the creation of new proposals as the end of the round nears. This function will NOT be
76
+ * enforced on L1.
77
+ *
78
+ * Execution
79
+ * - Once a slash payload becomes executable, the next proposer is expected to execute it. If they don't, the
80
+ * following does, and so on. No gas rebate is given.
81
+ */
82
+ export declare class EmpireSlasherClient implements ProposerSlashActionProvider, SlasherClientInterface {
83
+ private config;
84
+ private settings;
85
+ private slashFactoryContract;
86
+ private slashingProposer;
87
+ private rollupAddress;
88
+ private dateProvider;
89
+ private offensesStore;
90
+ private payloadsStore;
91
+ private log;
92
+ protected executablePayloads: PayloadWithRound[];
93
+ private unwatchCallbacks;
94
+ private overridePayloadActive;
95
+ private offensesCollector;
96
+ private roundMonitor;
97
+ constructor(config: EmpireSlasherConfig, settings: EmpireSlasherSettings, slashFactoryContract: SlashFactoryContract, slashingProposer: EmpireSlashingProposerContract, rollupAddress: EthAddress, watchers: Watcher[], dateProvider: DateProvider, offensesStore: SlasherOffensesStore, payloadsStore: SlasherPayloadsStore, log?: import("@aztec/foundation/log").Logger);
98
+ start(): Promise<void>;
99
+ /**
100
+ * Allows consumers to stop the instance of the slasher client.
101
+ * 'ready' will now return 'false' and the running promise that keeps the client synced is interrupted.
102
+ */
103
+ stop(): Promise<void>;
104
+ /** Returns the current config */
105
+ getConfig(): EmpireSlasherConfig;
106
+ /**
107
+ * Update the config of the slasher client
108
+ * @param config - The new config
109
+ */
110
+ updateConfig(config: Partial<SlasherConfig>): void;
111
+ getSlashPayloads(): Promise<SlashPayloadRound[]>;
112
+ /**
113
+ * Triggered on a time basis when we enter a new slashing round.
114
+ * Clears expired payloads and offenses from stores.
115
+ */
116
+ protected handleNewRound(round: bigint): Promise<void>;
117
+ /**
118
+ * Called when we see a PayloadSubmittable event on the SlashProposer.
119
+ * Adds the proposal to the list of executable ones.
120
+ */
121
+ protected handleProposalExecutable(payloadAddress: EthAddress, round: bigint): Promise<void>;
122
+ /**
123
+ * Called when we see a PayloadSubmitted event on the SlashProposer.
124
+ * Removes the proposal from the list of executable ones.
125
+ */
126
+ protected handleProposalExecuted(payload: EthAddress, round: bigint): Promise<void>;
127
+ /**
128
+ * Called when we see a SignalCast event on the SlashProposer.
129
+ * Adds a vote for the given payload in the round.
130
+ * Retrieves the proposal if we have not seen it before.
131
+ */
132
+ protected handleProposalSignalled(payloadAddress: EthAddress, round: bigint, signaller: EthAddress): Promise<void>;
133
+ /**
134
+ * Create a slash payload for the given round from pending offenses
135
+ * @param round - The round to create the payload for, defaults to the current round
136
+ * @returns The payload data or undefined if no offenses to slash
137
+ */
138
+ gatherOffensesForRound(round?: bigint): Promise<Offense[]>;
139
+ /** Returns all pending offenses stored */
140
+ getPendingOffenses(): Promise<Offense[]>;
141
+ /** Get uncontroversial offenses that are expected to be present on the given round. */
142
+ protected getPendingUncontroversialOffensesForRound(round: bigint): Promise<Offense[]>;
143
+ /**
144
+ * Calculate score for a slash payload, bumping the votes by one, so we get the score as if we voted for it.
145
+ * @param payload - The payload to score
146
+ * @param votes - Number of votes the payload has received
147
+ * @returns The score for the payload
148
+ */
149
+ protected calculatePayloadScore(payload: Pick<SlashPayloadRound, 'votes' | 'slashes'>): bigint;
150
+ /**
151
+ * Get the actions the proposer should take for slashing
152
+ * @param slotNumber - The current slot number
153
+ * @returns The actions to take
154
+ */
155
+ getProposerActions(slotNumber: bigint): Promise<ProposerSlashAction[]>;
156
+ /** Returns an execute payload action if there are any payloads ready to be executed */
157
+ protected getExecutePayloadAction(slotNumber: bigint): Promise<ProposerSlashAction | undefined>;
158
+ /** Returns a vote or create payload action based on payload scoring */
159
+ protected getProposePayloadActions(slotNumber: bigint): Promise<ProposerSlashAction[]>;
160
+ /**
161
+ * Check if we agree with a payload:
162
+ * - We must agree with every offense in the payload
163
+ * - All uncontroversial offenses from past rounds must be included
164
+ * - Payload must be below maximum size
165
+ * - Slash amounts must be within acceptable ranges
166
+ */
167
+ protected agreeWithPayload(payload: SlashPayload, round: bigint, cachedUncontroversialOffenses?: Offense[]): Promise<boolean>;
168
+ /**
169
+ * Returns whether the given offense can be included in the given round.
170
+ * Depends on the offense round range and whether we include offenses from past rounds.
171
+ */
172
+ private isOffenseForRound;
173
+ /**
174
+ * Returns the range (inclusive) of rounds in which we could expect an offense to be found.
175
+ * Lower bound is determined by all offenses that should have been captured before the start of a round,
176
+ * which depends on the offense type (eg INACTIVITY is captured once an epoch ends, DATA_WITHHOLDING is
177
+ * captured after the epoch proof submission window for the epoch for which the data was withheld).
178
+ * Upper bound is determined by the expiration rounds for an offense, which is a config setting.
179
+ */
180
+ private getRoundRangeForOffense;
181
+ /** Returns the acceptable range for slash amount given a set of offenses. */
182
+ private getSlashAmountValidRange;
183
+ /**
184
+ * Get minimum acceptable amount for an offense type
185
+ */
186
+ private getMinAmountForOffense;
187
+ /**
188
+ * Get maximum acceptable amount for an offense type
189
+ */
190
+ private getMaxAmountForOffense;
191
+ }
192
+ //# sourceMappingURL=empire_slasher_client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"empire_slasher_client.d.ts","sourceRoot":"","sources":["../src/empire_slasher_client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAC;AAGjE,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAG3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EACL,KAAK,OAAO,EAGZ,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,EAChC,KAAK,YAAY,EACjB,KAAK,iBAAiB,EAOvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAA0B,KAAK,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAE5G,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,uDAAuD;AACvD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,gDAAgD;AAChD,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC;AAEhD,qGAAqG;AACrG,MAAM,MAAM,qBAAqB,GAAG;IAClC,8BAA8B,EAAE,MAAM,CAAC;IACvC,+BAA+B,EAAE,MAAM,CAAC;IACxC,iBAAiB,EAAE,MAAM,CAAC;IAC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