Protocol will not benefit from slashing mechanism when remaining penalty bigger than minThreshold
When an operator's share is less than the penalty amount, the settlement function calls slashValidatorSD, which slashes only the minimum threshold amount of SD tokens rather than the full remaining penalty. This means the protocol may not recover the full penalty through the subsequent auction.
co0nan Follow with Co0nan and 0xWaitress
Originally disclosed on Code4rena
Submitted by Co0nan, also found by Co0nan and 0xWaitress
During the withdraw process, the function settleFunds() get called. This function first calculates the operatorShare and the penaltyAmount. If the operatorShare < penaltyAmount, the function calls slashValidatorSD in order to slash the operator and start new auction to cover the loss.
The issue here, is slashValidatorSD determines the amount to be reduced based on the smallest value between operators current SD balance and the poolThreshold.minThreshold. In this case, where the operatorShare(1ETH) is too small than the penaltyAmount(10ETH) the system should reduce an equivalent amount to cover the remaining ETH (9ETH_). However, the function choose the smallest value which could end up being 4e17. In such cases, the protocol will not favor because starting a new auction with SD amount = 4e17 will not end up with a 9ETH in exchange.
Proof of Concept
- Implementation of
settleFunds:
https://github.com/code-423n4/2023-06-stader/blob/main/contracts/ValidatorWithdrawalVault.sol#L54
function settleFunds() external override {
uint8 poolId = VaultProxy(payable(address(this))).poolId();
uint256 validatorId = VaultProxy(payable(address(this))).id();
IStaderConfig staderConfig = VaultProxy(payable(address(this))).staderConfig();
address nodeRegistry = IPoolUtils(staderConfig.getPoolUtils()).getNodeRegistry(poolId);
if (msg.sender != nodeRegistry) {
revert CallerNotNodeRegistryContract();
}
(uint256 userSharePrelim, uint256 operatorShare, uint256 protocolShare) = calculateValidatorWithdrawalShare();
uint256 penaltyAmount = getUpdatedPenaltyAmount(poolId, validatorId, staderConfig);
if (operatorShare < penaltyAmount) {
ISDCollateral(staderConfig.getSDCollateral()).slashValidatorSD(validatorId, poolId);
penaltyAmount = operatorShare;
}
uint256 userShare = userSharePrelim + penaltyAmount;
operatorShare = operatorShare - penaltyAmount;
// Final settlement
vaultSettleStatus = true;
IPenalty(staderConfig.getPenaltyContract()).markValidatorSettled(poolId, validatorId);
IStaderStakePoolManager(staderConfig.getStakePoolManager()).receiveWithdrawVaultUserShare{value: userShare}();
UtilLib.sendValue(payable(staderConfig.getStaderTreasury()), protocolShare);
IOperatorRewardsCollector(staderConfig.getOperatorRewardsCollector()).depositFor{value: operatorShare}(
getOperatorAddress(poolId, validatorId, staderConfig)
);
emit SettledFunds(userShare, operatorShare, protocolShare);
}
- Let’s suppose
operatorShareis 1 ETH,penaltyAmountis 5ETH. In this case, the function will enter theIfcondition on L67.
https://github.com/code-423n4/2023-06-stader/blob/main/contracts/ValidatorWithdrawalVault.sol#L67
ISDCollateral(staderConfig.getSDCollateral()).slashValidatorSD(validatorId, poolId);
- Implementation of
slashValidatorSDandslashSD.
https://github.com/code-423n4/2023-06-stader/blob/main/contracts/SDCollateral.sol#L78
function slashValidatorSD(uint256 _validatorId, uint8 _poolId) external override nonReentrant {
address operator = UtilLib.getOperatorForValidSender(_poolId, _validatorId, msg.sender, staderConfig);
isPoolThresholdValid(_poolId);
PoolThresholdInfo storage poolThreshold = poolThresholdbyPoolId[_poolId];
uint256 sdToSlash = convertETHToSD(poolThreshold.minThreshold);
slashSD(operator, sdToSlash);
}
/// @notice used to slash operator SD, incase of operator default
/// @dev do provide SD approval to auction contract using `maxApproveSD()`
/// @param _operator which operator SD collateral to slash
/// @param _sdToSlash amount of SD to slash
function slashSD(address _operator, uint256 _sdToSlash) internal {
uint256 sdBalance = operatorSDBalance[_operator];
uint256 sdSlashed = Math.min(_sdToSlash, sdBalance);
if (sdSlashed == 0) {
return;
}
operatorSDBalance[_operator] -= sdSlashed;
IAuction(staderConfig.getAuctionContract()).createLot(sdSlashed);
emit SDSlashed(_operator, staderConfig.getAuctionContract(), sdSlashed);
}
- As you can see, on line 82, the function gets the
minThresholdand passes it toslashSD. - On line 92, it selects the smallest value between the current balance of the operator and the
minThreshold:
uint256 sdSlashed = Math.min(_sdToSlash, sdBalance);
- If the
minThreshold< remaining penalty, which is 4 ETH in this case, the function simply ignores that and reduces the operator amount with ”minThreshold” instead. In this case, it’s < current SD balance. - The function then starts new auction with the smallest value.
https://github.com/code-423n4/2023-06-stader/blob/main/contracts/SDCollateral.sol#L97
operatorSDBalance[_operator] -= sdSlashed;
IAuction(staderConfig.getAuctionContract()).createLot(sdSlashed);
Despite how much the user should pay, the auction will start with the min value and the penaltyAmount will not be paid in full.
Recommended Mitigation Steps
The function shouldn’t use minThreshold. It should catch the remaining penalty (difference between operatorShare and penaltyAmount) and use it to calculate the required SD amount to be slashed.
Assessed type
Context
manoj9april (Stader) acknowledged and commented:
This update is slated for a future release.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the slashValidatorSD function uses the pool's minThreshold as the slash amount instead of calculating the SD needed to cover the remaining penalty.
Impact
The protocol may not recover the full penalty amount because the auction starts with only the minimum threshold SD, which may not cover the remaining loss.
What the attacker needed
OperatorShare < penaltyAmount; minThreshold < remaining penalty
The fix
The function should calculate the SD amount needed to cover the remaining penalty (difference between operatorShare and penaltyAmount) instead of using minThreshold.
How it was found
- During withdrawal, settleFunds calculates operatorShare and penaltyAmount.
- If operatorShare is less than penaltyAmount, it calls slashValidatorSD.
- slashValidatorSD converts minThreshold to SD and calls slashSD.
- slashSD slashes the minimum of that SD amount and the operator's balance, then starts an auction with the slashed amount.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In this system, operators put up a collateral token called SD. If an operator misbehaves, the protocol can take some of that collateral to cover losses. The bug is that when the loss is bigger than the operator's share, the code only takes a small fixed minimum amount of collateral instead of enough to cover the whole loss, so the protocol may not get all its money back.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.