@aztec/slasher 0.0.1-fake-c83136db25

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 (82) hide show
  1. package/README.md +218 -0
  2. package/dest/config.d.ts +6 -0
  3. package/dest/config.d.ts.map +1 -0
  4. package/dest/config.js +134 -0
  5. package/dest/empire_slasher_client.d.ts +189 -0
  6. package/dest/empire_slasher_client.d.ts.map +1 -0
  7. package/dest/empire_slasher_client.js +572 -0
  8. package/dest/factory/create_facade.d.ts +15 -0
  9. package/dest/factory/create_facade.d.ts.map +1 -0
  10. package/dest/factory/create_facade.js +23 -0
  11. package/dest/factory/create_implementation.d.ts +17 -0
  12. package/dest/factory/create_implementation.d.ts.map +1 -0
  13. package/dest/factory/create_implementation.js +73 -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/index.d.ts +11 -0
  21. package/dest/index.d.ts.map +1 -0
  22. package/dest/index.js +10 -0
  23. package/dest/null_slasher_client.d.ts +16 -0
  24. package/dest/null_slasher_client.d.ts.map +1 -0
  25. package/dest/null_slasher_client.js +33 -0
  26. package/dest/slash_offenses_collector.d.ts +45 -0
  27. package/dest/slash_offenses_collector.d.ts.map +1 -0
  28. package/dest/slash_offenses_collector.js +94 -0
  29. package/dest/slash_round_monitor.d.ts +29 -0
  30. package/dest/slash_round_monitor.d.ts.map +1 -0
  31. package/dest/slash_round_monitor.js +52 -0
  32. package/dest/slasher_client_facade.d.ts +43 -0
  33. package/dest/slasher_client_facade.d.ts.map +1 -0
  34. package/dest/slasher_client_facade.js +76 -0
  35. package/dest/slasher_client_interface.d.ts +38 -0
  36. package/dest/slasher_client_interface.d.ts.map +1 -0
  37. package/dest/slasher_client_interface.js +4 -0
  38. package/dest/stores/offenses_store.d.ts +37 -0
  39. package/dest/stores/offenses_store.d.ts.map +1 -0
  40. package/dest/stores/offenses_store.js +105 -0
  41. package/dest/stores/payloads_store.d.ts +29 -0
  42. package/dest/stores/payloads_store.d.ts.map +1 -0
  43. package/dest/stores/payloads_store.js +125 -0
  44. package/dest/stores/schema_version.d.ts +2 -0
  45. package/dest/stores/schema_version.d.ts.map +1 -0
  46. package/dest/stores/schema_version.js +1 -0
  47. package/dest/tally_slasher_client.d.ts +129 -0
  48. package/dest/tally_slasher_client.d.ts.map +1 -0
  49. package/dest/tally_slasher_client.js +349 -0
  50. package/dest/test/dummy_watcher.d.ts +11 -0
  51. package/dest/test/dummy_watcher.d.ts.map +1 -0
  52. package/dest/test/dummy_watcher.js +14 -0
  53. package/dest/watcher.d.ts +21 -0
  54. package/dest/watcher.d.ts.map +1 -0
  55. package/dest/watcher.js +1 -0
  56. package/dest/watchers/attestations_block_watcher.d.ts +33 -0
  57. package/dest/watchers/attestations_block_watcher.d.ts.map +1 -0
  58. package/dest/watchers/attestations_block_watcher.js +135 -0
  59. package/dest/watchers/epoch_prune_watcher.d.ts +37 -0
  60. package/dest/watchers/epoch_prune_watcher.d.ts.map +1 -0
  61. package/dest/watchers/epoch_prune_watcher.js +135 -0
  62. package/package.json +89 -0
  63. package/src/config.ts +157 -0
  64. package/src/empire_slasher_client.ts +656 -0
  65. package/src/factory/create_facade.ts +52 -0
  66. package/src/factory/create_implementation.ts +159 -0
  67. package/src/factory/get_settings.ts +58 -0
  68. package/src/factory/index.ts +2 -0
  69. package/src/index.ts +10 -0
  70. package/src/null_slasher_client.ts +40 -0
  71. package/src/slash_offenses_collector.ts +118 -0
  72. package/src/slash_round_monitor.ts +61 -0
  73. package/src/slasher_client_facade.ts +100 -0
  74. package/src/slasher_client_interface.ts +45 -0
  75. package/src/stores/offenses_store.ts +145 -0
  76. package/src/stores/payloads_store.ts +146 -0
  77. package/src/stores/schema_version.ts +1 -0
  78. package/src/tally_slasher_client.ts +436 -0
  79. package/src/test/dummy_watcher.ts +21 -0
  80. package/src/watcher.ts +27 -0
  81. package/src/watchers/attestations_block_watcher.ts +180 -0
  82. package/src/watchers/epoch_prune_watcher.ts +192 -0
package/README.md ADDED
@@ -0,0 +1,218 @@
1
+ # Slasher
2
+
3
+ ## Overview
4
+
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 from a given past round should be slashed (eg round N votes to slash the validators from round N-2). 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
+ - Requires a slash offset to vote on validators from past rounds
32
+ - Requires quorum to execute slashing
33
+ - L1 contract determines which offenses reach consensus
34
+ - Execution happens after a delay period for review
35
+ - Slash payloads can be vetoed during the execution delay period
36
+
37
+ ### Empire Model
38
+
39
+ _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._
40
+
41
+ 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.
42
+
43
+ Key characteristics:
44
+ - Fixed payloads containing multiple offenses
45
+ - Payload scoring system for selection
46
+ - Requires agreement on payload contents (main reason why it was dropped in favor of the Tally model)
47
+
48
+ ## Architecture
49
+
50
+ ### Core Components
51
+
52
+ #### SlasherClientInterface
53
+ Common interface implemented by both tally and empire clients. Provides methods for:
54
+ - `getProposerActions()`: Returns actions for the current proposer
55
+ - `gatherOffensesForRound()`: Collects offenses for a specific round
56
+
57
+ #### SlashOffensesCollector
58
+ Collects slashable offenses from watchers and stores them in the offenses store. Features:
59
+ - Subscribes to `WANT_TO_SLASH_EVENT` from watchers
60
+ - Manages offense lifecycle and automatic expiration
61
+
62
+ #### SlasherOffensesStore
63
+ Persistent storage for offenses. Tracks:
64
+ - Pending offenses awaiting slashing
65
+ - Executed offenses to prevent double slashing
66
+ - Round-based offense organization
67
+ - Automatic expiration of old offenses based on configurable rounds
68
+
69
+ #### SlashRoundMonitor
70
+ Monitors slashing rounds and triggers actions on round transitions:
71
+ - Tracks current round based on L2 slots
72
+ - Emits events when rounds change
73
+
74
+ #### ProposerSlashAction
75
+ Actions returned by the slasher client to the SequencerPublisher:
76
+ - `vote-offenses`: Vote on validator offenses (tally model)
77
+ - `execute-slash`: Execute slashing for a round that reached quorum (tally model)
78
+ - `create-empire-payload`: Create a new slash payload (empire model)
79
+ - `vote-empire-payload`: Vote for an existing payload (empire model)
80
+ - `execute-empire-payload`: Execute a payload with sufficient votes (empire model)
81
+
82
+ ### Integration Flow
83
+
84
+ 1. **Offense Detection**: Watchers monitor the network and emit `WANT_TO_SLASH_EVENT` when they detect violations
85
+ 2. **Offense Collection**: SlashOffensesCollector receives events and stores offenses in SlasherOffensesStore
86
+ 3. **Action Generation**: When a validator is proposer, the slasher client generates ProposerSlashActions
87
+ 4. **Action Execution**: SequencerPublisher receives actions and executes them on L1
88
+ 5. **Round Monitoring**: SlashRoundMonitor tracks rounds and triggers execution when conditions are met
89
+
90
+ ## Vetoing
91
+
92
+ The slashing system includes a veto mechanism that allows designated vetoers to block slash payloads during the execution delay period. When a slash payload is ready for execution, the system first checks if it has been vetoed before proceeding.
93
+
94
+ Key features:
95
+ - Slash payloads can be vetoed by authorized addresses on the L1 slasher contract
96
+ - Veto checks are performed automatically before execution attempts
97
+ - The veto mechanism provides a safety valve for incorrectly proposed slashes
98
+
99
+ ## Slashable Offenses
100
+
101
+ List of all slashable offenses in the system:
102
+
103
+ ### DATA_WITHHOLDING
104
+ **Description**: The data required for proving an epoch was not made publicly available.
105
+ **Detection**: EpochPruneWatcher detects when an epoch cannot be proven due to missing data.
106
+ **Target**: Committee members of the affected epoch.
107
+ **Time Unit**: Epoch-based offense.
108
+
109
+ ### VALID_EPOCH_PRUNED
110
+ **Description**: An epoch was not successfully proven within the proof submission window.
111
+ **Detection**: EpochPruneWatcher monitors epochs that expire without valid proofs.
112
+ **Target**: Committee members of the unpruned epoch.
113
+ **Time Unit**: Epoch-based offense.
114
+
115
+ ### INACTIVITY
116
+ **Description**: A proposer failed to attest or propose blocks during their assigned slots.
117
+ **Detection**: Sentinel tracks validator performance and identifies validators who miss attestations beyond threshold.
118
+ **Target**: Individual inactive validator.
119
+ **Time Unit**: Epoch-based offense.
120
+
121
+ ### BROADCASTED_INVALID_BLOCK_PROPOSAL
122
+ **Description**: A proposer broadcast an invalid block proposal over the p2p network.
123
+ **Detection**: Validators detect invalid proposals during attestation validation.
124
+ **Target**: Proposer who broadcast the invalid block.
125
+ **Time Unit**: Slot-based offense.
126
+
127
+ ### PROPOSED_INSUFFICIENT_ATTESTATIONS
128
+ **Description**: A proposer submitted a block to L1 without sufficient committee attestations.
129
+ **Detection**: AttestationsBlockWatcher checks L1 blocks for attestation count.
130
+ **Target**: Block proposer.
131
+ **Time Unit**: Slot-based offense.
132
+
133
+ ### PROPOSED_INCORRECT_ATTESTATIONS
134
+ **Description**: A proposer submitted a block to L1 with signatures from non-committee members.
135
+ **Detection**: AttestationsBlockWatcher validates attestation signatures against committee membership.
136
+ **Target**: Block proposer.
137
+ **Time Unit**: Slot-based offense.
138
+
139
+ ### ATTESTED_DESCENDANT_OF_INVALID
140
+ **Description**: A committee member attested to a block built on top of an invalid ancestor.
141
+ **Detection**: AttestationsBlockWatcher tracks invalid blocks and their descendants.
142
+ **Target**: Committee members who attested to the descendant block.
143
+ **Time Unit**: Slot-based offense.
144
+
145
+ ## Configuration
146
+
147
+ ### L1 System Settings (L1ContractsConfig)
148
+ These settings are deployed with the L1 contracts and apply system-wide to the protocol:
149
+
150
+ - `slashingQuorumSize`: Votes required to slash (defaults to half the validators in a round, plus one)
151
+ - `slashingRoundSizeInEpochs`: Number of epochs per slashing round
152
+ - `slashingOffsetInRounds`: How many rounds to look back for offenses (tally model)
153
+ - `slashingExecutionDelayInRounds`: Rounds to wait before execution
154
+ - `slashingLifetimeInRounds`: Maximum age of executable rounds
155
+ - `slashingAmounts`: Valid values for each individual slash (tally model)
156
+
157
+ Considerations:
158
+
159
+ - The `slashingQuorumSize` should be more than half and less than the total number of validators in a round, so that we require a majority to slash. The number of validators in a round is the committee size times the number of epochs in a round.
160
+ - The bigger a `slashingRoundSizeInEpochs`, the bigger the upper bound on the quorum size. This increases security, as we need more validators to agree before slashing. However, it also makes slashing slower, and more expensive to execute in terms of gas in the tally model.
161
+ - The `slashingOffsetInRounds` is required because the validators in a given slashing round must vote for _past_ offenses. Otherwise, if someone commits an offense near the end of a round, they can get away with their offense without the validators being able to collect enough votes to slash them. The offset needs to be big enough so that all offenses are discoverable, so this value should be strictly greater than the proof submission window in order to be able to slash for epoch prunes or data withholding.
162
+ - The `slashingExecutionDelayInRounds` allows vetoers to stop an invalid slash. This should be large enough to give vetoers time to act, but strictly smaller than the validator exit window, so an offender cannot escape before they are slashed. It should also be small enough so that an offender that would be kicked out does not get picked up to be a committee member again before their slash is executed. In other words, if a validator commits a serious enough offense that we want them out of the validator set as soon as possible, the execution delay should not allow them to be chosen to participate in another committee.
163
+
164
+ ### Local Node Configuration (SlasherConfig)
165
+
166
+ These settings are configured locally on each validator node:
167
+
168
+ - `slashGracePeriodL2Slots`: Number of initial L2 slots where slashing is disabled
169
+ - `slashOffenseExpirationRounds`: Number of rounds after which pending offenses expire
170
+ - `slashValidatorsAlways`: Array of validator addresses that should always be slashed
171
+ - `slashValidatorsNever`: Array of validator addresses that should never be slashed (own validator addresses are automatically added to this list)
172
+ - `slashInactivityTargetPercentage`: Percentage of misses during an epoch to be slashed for INACTIVITY
173
+ - `slashInactivityConsecutiveEpochThreshold`: How many consecutive inactive epochs are needed to trigger an INACTIVITY slash on a validator
174
+ - `slashPrunePenalty`: Penalty for VALID_EPOCH_PRUNED
175
+ - `slashDataWithholdingPenalty`: Penalty for DATA_WITHHOLDING
176
+ - `slashInactivityPenalty`: Penalty for INACTIVITY
177
+ - `slashBroadcastedInvalidBlockPenalty`: Penalty for BROADCASTED_INVALID_BLOCK_PROPOSAL
178
+ - `slashProposeInvalidAttestationsPenalty`: Penalty for PROPOSED_INSUFFICIENT_ATTESTATIONS and PROPOSED_INCORRECT_ATTESTATIONS
179
+ - `slashAttestDescendantOfInvalidPenalty`: Penalty for ATTESTED_DESCENDANT_OF_INVALID
180
+ - `slashUnknownPenalty`: Default penalty for unknown offense types
181
+ - `slashMaxPayloadSize`: Maximum size of slash payloads (empire model)
182
+ - `slashMinPenaltyPercentage`: Agree to slashes if they are at least this percentage of the configured penalty (empire model)
183
+ - `slashMaxPenaltyPercentage`: Agree to slashes if they are at most this percentage of the configured penalty (empire model)
184
+
185
+ Considerations:
186
+
187
+ - All penalties should map to one of the `slashingAmounts`. A penalty lower than the smallest slashing amount will not be executable, and a penalty greater than the maximum will be capped at the maximum value.
188
+ - The `slashOffenseExpirationRounds` should be strictly larger than the `slashingOffsetInRounds`. This can be a relatively large value, as it's used only for data store cleanup.
189
+
190
+ ## Offenses In-Depth
191
+
192
+ Details about specific offenses in the system:
193
+
194
+ ### Inactivity
195
+
196
+ Inactivity slashing is one of the most critical, since it allows purging validators that are not fulfilling their duties, which could potentially bring the chain to a halt. This slashing must be aggressive enough to balance out the rate of the entry queue, in case the queue is filled with inactive validators. Furthermore, if enough inactive validators join the system, it may become impossible to gather enough quorum to pass any governance proposal.
197
+
198
+ Inactivity slashing is handled by the `Sentinel` which monitors performance of all validators slot-by-slot. After each slot, the sentinel assigns one of the following to the block proposer for the slot:
199
+ - `block-mined` if the block was added to L1
200
+ - `block-proposed` if the block received at least one attestation, but didn't make it to L1
201
+ - `block-missed` if the block received no attestations (note that we cannot rely on the P2P proposal alone since it may be invalid, unless we reexecute it)
202
+
203
+ And assigns one of the following to each validator:
204
+ - `attestation-sent` if there was a `block-proposed` or `block-mined` and an attestation from this validator was seen on either on L1 or on the P2P network
205
+ - `attestation-missed` if there was a `block-proposed` or `block-mined` but no attestation was seen
206
+ - none if the slot was a `block-missed`
207
+
208
+ Once an epoch is proven, the sentinel computes the _proven performance_ for the epoch for each validator. Note that we wait until the epoch is proven so we know that the data for all blocks in the epoch was available, and validators who did not attest were effectively inactive. Then, for each validator such that:
209
+
210
+ ```
211
+ total_failures = count(block-missed) + count(attestation-missed)
212
+ total = count(block-*) + count(attestation-*)
213
+ total_failures / total >= slash_inactivity_target_percentage
214
+ ```
215
+
216
+ They are voted to be slashed for inactivity. Note that, if `slashInactivityConsecutiveEpochThreshold` is greater than one, we first check if the above is true for the last `threshold` times the given validator was part of a committee, and only then trigger the offense.
217
+
218
+
@@ -0,0 +1,6 @@
1
+ import type { ConfigMappingsType } from '@aztec/foundation/config';
2
+ import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
3
+ export type { SlasherConfig };
4
+ export declare const DefaultSlasherConfig: SlasherConfig;
5
+ export declare const slasherConfigMappings: ConfigMappingsType<SlasherConfig>;
6
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,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,aAoBlC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,kBAAkB,CAAC,aAAa,CAyHnE,CAAC"}
package/dest/config.js ADDED
@@ -0,0 +1,134 @@
1
+ import { DefaultL1ContractsConfig } from '@aztec/ethereum';
2
+ import { bigintConfigHelper, booleanConfigHelper, floatConfigHelper, numberConfigHelper } from '@aztec/foundation/config';
3
+ import { EthAddress } from '@aztec/foundation/eth-address';
4
+ export const DefaultSlasherConfig = {
5
+ slashOverridePayload: undefined,
6
+ slashMinPenaltyPercentage: 0.5,
7
+ slashMaxPenaltyPercentage: 2.0,
8
+ slashValidatorsAlways: [],
9
+ slashValidatorsNever: [],
10
+ slashPrunePenalty: DefaultL1ContractsConfig.slashAmountSmall,
11
+ slashDataWithholdingPenalty: DefaultL1ContractsConfig.slashAmountSmall,
12
+ slashInactivityTargetPercentage: 0.9,
13
+ slashInactivityConsecutiveEpochThreshold: 1,
14
+ slashBroadcastedInvalidBlockPenalty: DefaultL1ContractsConfig.slashAmountSmall,
15
+ slashInactivityPenalty: DefaultL1ContractsConfig.slashAmountSmall,
16
+ slashProposeInvalidAttestationsPenalty: DefaultL1ContractsConfig.slashAmountSmall,
17
+ slashAttestDescendantOfInvalidPenalty: DefaultL1ContractsConfig.slashAmountSmall,
18
+ slashUnknownPenalty: DefaultL1ContractsConfig.slashAmountSmall,
19
+ slashOffenseExpirationRounds: 4,
20
+ slashMaxPayloadSize: 50,
21
+ slashGracePeriodL2Slots: 0,
22
+ slashExecuteRoundsLookBack: 4,
23
+ slashSelfAllowed: false
24
+ };
25
+ export const slasherConfigMappings = {
26
+ slashOverridePayload: {
27
+ env: 'SLASH_OVERRIDE_PAYLOAD',
28
+ description: 'An Ethereum address for a slash payload to vote for unconditionally.',
29
+ parseEnv: (val)=>val ? EthAddress.fromString(val) : undefined,
30
+ defaultValue: DefaultSlasherConfig.slashOverridePayload
31
+ },
32
+ slashMinPenaltyPercentage: {
33
+ env: 'SLASH_MIN_PENALTY_PERCENTAGE',
34
+ description: 'Minimum penalty percentage for slashing offenses (0.1 is 10%).',
35
+ ...floatConfigHelper(DefaultSlasherConfig.slashMinPenaltyPercentage)
36
+ },
37
+ slashMaxPenaltyPercentage: {
38
+ env: 'SLASH_MAX_PENALTY_PERCENTAGE',
39
+ description: 'Maximum penalty percentage for slashing offenses (2.0 is 200%).',
40
+ ...floatConfigHelper(DefaultSlasherConfig.slashMaxPenaltyPercentage)
41
+ },
42
+ slashValidatorsAlways: {
43
+ env: 'SLASH_VALIDATORS_ALWAYS',
44
+ description: 'Comma-separated list of validator addresses that should always be slashed.',
45
+ parseEnv: (val)=>val.split(',').map((addr)=>addr.trim()).filter((addr)=>addr.length > 0).map((addr)=>EthAddress.fromString(addr)),
46
+ defaultValue: DefaultSlasherConfig.slashValidatorsAlways
47
+ },
48
+ slashValidatorsNever: {
49
+ env: 'SLASH_VALIDATORS_NEVER',
50
+ description: 'Comma-separated list of validator addresses that should never be slashed.',
51
+ parseEnv: (val)=>val.split(',').map((addr)=>addr.trim()).filter((addr)=>addr.length > 0).map((addr)=>EthAddress.fromString(addr)),
52
+ defaultValue: DefaultSlasherConfig.slashValidatorsNever
53
+ },
54
+ slashPrunePenalty: {
55
+ env: 'SLASH_PRUNE_PENALTY',
56
+ description: 'Penalty amount for slashing validators of a valid pruned epoch (set to 0 to disable).',
57
+ ...bigintConfigHelper(DefaultSlasherConfig.slashPrunePenalty)
58
+ },
59
+ slashDataWithholdingPenalty: {
60
+ env: 'SLASH_DATA_WITHHOLDING_PENALTY',
61
+ description: 'Penalty amount for slashing validators for data withholding (set to 0 to disable).',
62
+ ...bigintConfigHelper(DefaultSlasherConfig.slashDataWithholdingPenalty)
63
+ },
64
+ slashBroadcastedInvalidBlockPenalty: {
65
+ env: 'SLASH_INVALID_BLOCK_PENALTY',
66
+ description: 'Penalty amount for slashing a validator for an invalid block proposed via p2p.',
67
+ ...bigintConfigHelper(DefaultSlasherConfig.slashBroadcastedInvalidBlockPenalty)
68
+ },
69
+ slashInactivityTargetPercentage: {
70
+ env: 'SLASH_INACTIVITY_TARGET_PERCENTAGE',
71
+ description: 'Missed attestation percentage to trigger creation of inactivity slash payload (0, 1]. Must be greater than 0',
72
+ ...floatConfigHelper(DefaultSlasherConfig.slashInactivityTargetPercentage, (v)=>{
73
+ if (v <= 0 || v > 1) {
74
+ throw new RangeError(`SLASH_INACTIVITY_TARGET_PERCENTAGE out of range. Expected (0, 1] got ${v}`);
75
+ }
76
+ })
77
+ },
78
+ slashInactivityConsecutiveEpochThreshold: {
79
+ env: 'SLASH_INACTIVITY_CONSECUTIVE_EPOCH_THRESHOLD',
80
+ description: 'Number of consecutive epochs a validator must be inactive before slashing (minimum 1).',
81
+ ...numberConfigHelper(DefaultSlasherConfig.slashInactivityConsecutiveEpochThreshold),
82
+ parseEnv: (val)=>{
83
+ const parsed = parseInt(val, 10);
84
+ if (parsed < 1) {
85
+ throw new RangeError(`SLASH_INACTIVITY_CONSECUTIVE_EPOCH_THRESHOLD must be at least 1 (got ${parsed})`);
86
+ }
87
+ return parsed;
88
+ }
89
+ },
90
+ slashInactivityPenalty: {
91
+ env: 'SLASH_INACTIVITY_PENALTY',
92
+ description: 'Penalty amount for slashing an inactive validator (set to 0 to disable).',
93
+ ...bigintConfigHelper(DefaultSlasherConfig.slashInactivityPenalty)
94
+ },
95
+ slashProposeInvalidAttestationsPenalty: {
96
+ env: 'SLASH_PROPOSE_INVALID_ATTESTATIONS_PENALTY',
97
+ description: 'Penalty amount for slashing a proposer that proposed invalid attestations (set to 0 to disable).',
98
+ ...bigintConfigHelper(DefaultSlasherConfig.slashProposeInvalidAttestationsPenalty)
99
+ },
100
+ slashAttestDescendantOfInvalidPenalty: {
101
+ env: 'SLASH_ATTEST_DESCENDANT_OF_INVALID_PENALTY',
102
+ description: 'Penalty amount for slashing a validator that attested to a descendant of an invalid block (set to 0 to disable).',
103
+ ...bigintConfigHelper(DefaultSlasherConfig.slashAttestDescendantOfInvalidPenalty)
104
+ },
105
+ slashUnknownPenalty: {
106
+ env: 'SLASH_UNKNOWN_PENALTY',
107
+ description: 'Penalty amount for slashing a validator for an unknown offense (set to 0 to disable).',
108
+ ...bigintConfigHelper(DefaultSlasherConfig.slashUnknownPenalty)
109
+ },
110
+ slashOffenseExpirationRounds: {
111
+ env: 'SLASH_OFFENSE_EXPIRATION_ROUNDS',
112
+ description: 'Number of rounds after which pending offenses expire.',
113
+ ...numberConfigHelper(DefaultSlasherConfig.slashOffenseExpirationRounds)
114
+ },
115
+ slashMaxPayloadSize: {
116
+ env: 'SLASH_MAX_PAYLOAD_SIZE',
117
+ description: 'Maximum number of offenses to include in a single slash payload.',
118
+ ...numberConfigHelper(DefaultSlasherConfig.slashMaxPayloadSize)
119
+ },
120
+ slashGracePeriodL2Slots: {
121
+ description: 'Number of L2 slots to wait before considering a slashing offense expired.',
122
+ env: 'SLASH_GRACE_PERIOD_L2_SLOTS',
123
+ ...numberConfigHelper(DefaultSlasherConfig.slashGracePeriodL2Slots)
124
+ },
125
+ slashExecuteRoundsLookBack: {
126
+ env: 'SLASH_EXECUTE_ROUNDS_LOOK_BACK',
127
+ description: 'How many rounds to look back when searching for a round to execute.',
128
+ ...numberConfigHelper(DefaultSlasherConfig.slashExecuteRoundsLookBack)
129
+ },
130
+ slashSelfAllowed: {
131
+ description: 'Whether to allow slashes to own validators',
132
+ ...booleanConfigHelper(DefaultSlasherConfig.slashSelfAllowed)
133
+ }
134
+ };
@@ -0,0 +1,189 @@
1
+ import { EmpireSlashingProposerContract, RollupContract, SlasherContract } 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 slasher;
88
+ private rollup;
89
+ private dateProvider;
90
+ private offensesStore;
91
+ private payloadsStore;
92
+ private log;
93
+ protected executablePayloads: PayloadWithRound[];
94
+ private unwatchCallbacks;
95
+ private overridePayloadActive;
96
+ private offensesCollector;
97
+ private roundMonitor;
98
+ constructor(config: EmpireSlasherConfig, settings: EmpireSlasherSettings, slashFactoryContract: SlashFactoryContract, slashingProposer: EmpireSlashingProposerContract, slasher: SlasherContract, rollup: RollupContract, watchers: Watcher[], dateProvider: DateProvider, offensesStore: SlasherOffensesStore, payloadsStore: SlasherPayloadsStore, log?: import("@aztec/foundation/log").Logger);
99
+ start(): Promise<void>;
100
+ /**
101
+ * Allows consumers to stop the instance of the slasher client.
102
+ * 'ready' will now return 'false' and the running promise that keeps the client synced is interrupted.
103
+ */
104
+ stop(): Promise<void>;
105
+ /** Returns the current config */
106
+ getConfig(): EmpireSlasherConfig;
107
+ /**
108
+ * Update the config of the slasher client
109
+ * @param config - The new config
110
+ */
111
+ updateConfig(config: Partial<SlasherConfig>): void;
112
+ getSlashPayloads(): Promise<SlashPayloadRound[]>;
113
+ /**
114
+ * Triggered on a time basis when we enter a new slashing round.
115
+ * Clears expired payloads and offenses from stores.
116
+ */
117
+ protected handleNewRound(round: bigint): Promise<void>;
118
+ /**
119
+ * Called when we see a PayloadSubmittable event on the SlashProposer.
120
+ * Adds the proposal to the list of executable ones.
121
+ */
122
+ protected handleProposalExecutable(payloadAddress: EthAddress, round: bigint): Promise<void>;
123
+ /**
124
+ * Called when we see a PayloadSubmitted event on the SlashProposer.
125
+ * Removes the proposal from the list of executable ones.
126
+ */
127
+ protected handleProposalExecuted(payload: EthAddress, round: bigint): Promise<void>;
128
+ /**
129
+ * Called when we see a SignalCast event on the SlashProposer.
130
+ * Adds a vote for the given payload in the round.
131
+ * Retrieves the proposal if we have not seen it before.
132
+ */
133
+ protected handleProposalSignalled(payloadAddress: EthAddress, round: bigint, signaller: EthAddress): Promise<void>;
134
+ /**
135
+ * Create a slash payload for the given round from pending offenses
136
+ * @param round - The round to create the payload for, defaults to the current round
137
+ * @returns The payload data or undefined if no offenses to slash
138
+ */
139
+ gatherOffensesForRound(round?: bigint): Promise<Offense[]>;
140
+ /** Returns all pending offenses stored */
141
+ getPendingOffenses(): Promise<Offense[]>;
142
+ /** Get uncontroversial offenses that are expected to be present on the given round. */
143
+ protected getPendingUncontroversialOffensesForRound(round: bigint): Promise<Offense[]>;
144
+ /**
145
+ * Calculate score for a slash payload, bumping the votes by one, so we get the score as if we voted for it.
146
+ * @param payload - The payload to score
147
+ * @param votes - Number of votes the payload has received
148
+ * @returns The score for the payload
149
+ */
150
+ protected calculatePayloadScore(payload: Pick<SlashPayloadRound, 'votes' | 'slashes'>): bigint;
151
+ /**
152
+ * Get the actions the proposer should take for slashing
153
+ * @param slotNumber - The current slot number
154
+ * @returns The actions to take
155
+ */
156
+ getProposerActions(slotNumber: bigint): Promise<ProposerSlashAction[]>;
157
+ /** Returns an execute payload action if there are any payloads ready to be executed */
158
+ protected getExecutePayloadAction(slotNumber: bigint): Promise<ProposerSlashAction | undefined>;
159
+ /** Returns a vote or create payload action based on payload scoring */
160
+ protected getProposePayloadActions(slotNumber: bigint): Promise<ProposerSlashAction[]>;
161
+ /**
162
+ * Check if we agree with a payload:
163
+ * - We must agree with every offense in the payload
164
+ * - All uncontroversial offenses from past rounds must be included
165
+ * - Payload must be below maximum size
166
+ * - Slash amounts must be within acceptable ranges
167
+ */
168
+ protected agreeWithPayload(payload: SlashPayload, round: bigint, cachedUncontroversialOffenses?: Offense[]): Promise<boolean>;
169
+ /**
170
+ * Returns whether the given offense can be included in the given round.
171
+ * Depends on the offense round range and whether we include offenses from past rounds.
172
+ */
173
+ private isOffenseForRound;
174
+ /**
175
+ * Returns the range (inclusive) of rounds in which we could expect an offense to be found.
176
+ * Lower bound is determined by all offenses that should have been captured before the start of a round,
177
+ * which depends on the offense type (eg INACTIVITY is captured once an epoch ends, DATA_WITHHOLDING is
178
+ * captured after the epoch proof submission window for the epoch for which the data was withheld).
179
+ * Upper bound is determined by the expiration rounds for an offense, which is a config setting.
180
+ */
181
+ private getRoundRangeForOffense;
182
+ /** Returns the acceptable range for slash amount given a set of offenses. */
183
+ private getSlashAmountValidRange;
184
+ /** Get minimum acceptable amount for an offense type */
185
+ private getMinAmountForOffense;
186
+ /** Get maximum acceptable amount for an offense type */
187
+ private getMaxAmountForOffense;
188
+ }
189
+ //# 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,cAAc,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlG,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,EAQvB,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,oBAAo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