sherlock-audit / 2024-08-saffron-finance-judging

9 stars 5 forks source link

Abhan1041 - Incorrect calculation in `getCalculateVariableWithdrawStateWithStakingBalance` function #128

Open sherlock-admin4 opened 1 month ago

sherlock-admin4 commented 1 month ago

Abhan1041

Medium

Incorrect calculation in getCalculateVariableWithdrawStateWithStakingBalance function

Summary

getCalculateVariableWithdrawStateWithStakingBalance function is using wrong variable for fixedETHDeposits which leads to incorrect calculation.

Vulnerability Detail

getCalculateVariableWithdrawStateWithStakingBalance function is implemented for variable users who wants to know how much yield is accrued for them from staking balance. So that variable users can know their earnings from staking balance at present.

For calculating variable users yield getCalculateVariableWithdrawStateWithStakingBalance function gets total earnings generated from staking in LIDO. For that they get current staking balance in lidoStETHBalance variable and fixed eth deposit in fixedETHDeposits variable and then deducting them to get earnings.

function getCalculateVariableWithdrawStateWithStakingBalance(address user) public view returns (uint256) {
    uint256 lidoStETHBalance = stakingBalance();
    uint256 fixedETHDeposits = fixedETHDepositTokenTotalSupply;
    require(lidoStETHBalance > fixedETHDeposits, "LBL");
    uint256 totalEarnings = (lidoStETHBalance - fixedETHDeposits) + withdrawnStakingEarnings + totalProtocolFee;
    ...
  }

The problem occurs because they get fixedETHDeposits from variable called fixedETHDepositTokenTotalSupply. Because this variable is tracking fixed deposits till vault starts. If any fixed deposit user withdraw his eth after vault has started then it will be not deducted in fixedETHDepositTokenTotalSupply variable which leads to incorrect calculation.

function getCalculateVariableWithdrawStateWithStakingBalance(address user) public view returns (uint256) {
    ...
@>  uint256 fixedETHDeposits = fixedETHDepositTokenTotalSupply;
    ...
  }

Vulnerability Flow:

Impact

Variable user cannot get correct amount to withdraw from staking earnings.

Code Snippet

https://github.com/sherlock-audit/2024-08-saffron-finance/blob/38dd9c8436db341c331f1b14545770c1766fc0ee/lido-fiv/contracts/LidoVault.sol#L880C3-L896C4

Tool used

Manual Review

Recommendation

Use updated values for fixedETHDeposits to calculate total earnings.