@@ -171,6 +171,18 @@ contract HorizonStakingExtension is HorizonStakingBase, IHorizonStakingExtension
171
171
// Validate beneficiary of slashed tokens
172
172
require (beneficiary != address (0 ), "!beneficiary " );
173
173
174
+ // Slashing tokens that are already provisioned would break provision accounting, we need to limit
175
+ // the slash amount. This can be compensated for, by slashing with the main slash function if needed.
176
+ uint256 slashableStake = indexerStake.tokensStaked - indexerStake.tokensProvisioned;
177
+ if (slashableStake == 0 ) {
178
+ emit StakeSlashed (indexer, 0 , 0 , beneficiary);
179
+ return ;
180
+ }
181
+ if (tokens > slashableStake) {
182
+ reward = (reward * slashableStake) / tokens;
183
+ tokens = slashableStake;
184
+ }
185
+
174
186
// Slashing more tokens than freely available (over allocation condition)
175
187
// Unlock locked tokens to avoid the indexer to withdraw them
176
188
uint256 tokensUsed = indexerStake.__DEPRECATED_tokensAllocated + indexerStake.__DEPRECATED_tokensLocked;
@@ -184,18 +196,6 @@ contract HorizonStakingExtension is HorizonStakingBase, IHorizonStakingExtension
184
196
}
185
197
}
186
198
187
- // Slashing tokens that are already provisioned would break provision accounting, we need to limit
188
- // the slash amount. This can be compensated for, by slashing with the main slash function if needed.
189
- uint256 slashableStake = indexerStake.tokensStaked - indexerStake.tokensProvisioned;
190
- if (slashableStake == 0 ) {
191
- emit StakeSlashed (indexer, 0 , 0 , beneficiary);
192
- return ;
193
- }
194
- if (tokens > slashableStake) {
195
- reward = (reward * slashableStake) / tokens;
196
- tokens = slashableStake;
197
- }
198
-
199
199
// Remove tokens to slash from the stake
200
200
indexerStake.tokensStaked = indexerStake.tokensStaked - tokens;
201
201
0 commit comments