Skip to content

Commit 8e07001

Browse files
committed
fix: ensure legacy slash unlocks correct amount
Signed-off-by: Tomás Migone <[email protected]>
1 parent 927af0d commit 8e07001

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

packages/horizon/contracts/staking/HorizonStakingExtension.sol

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,18 @@ contract HorizonStakingExtension is HorizonStakingBase, IHorizonStakingExtension
171171
// Validate beneficiary of slashed tokens
172172
require(beneficiary != address(0), "!beneficiary");
173173

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+
174186
// Slashing more tokens than freely available (over allocation condition)
175187
// Unlock locked tokens to avoid the indexer to withdraw them
176188
uint256 tokensUsed = indexerStake.__DEPRECATED_tokensAllocated + indexerStake.__DEPRECATED_tokensLocked;
@@ -184,18 +196,6 @@ contract HorizonStakingExtension is HorizonStakingBase, IHorizonStakingExtension
184196
}
185197
}
186198

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-
199199
// Remove tokens to slash from the stake
200200
indexerStake.tokensStaked = indexerStake.tokensStaked - tokens;
201201

0 commit comments

Comments
 (0)