The withdraw function in the StakingPool contract does not properly validate that the total amount of tokens withdrawn from the pool and strategies matches the requested withdrawal amount. This can lead to users receiving less than the expected amount when withdrawing from the pool if there is insufficient liquidity.
Because the withdraw function first checks the balance of the pool, and if the requested withdrawal amount exceeds the balance, it calls the _withdrawLiquidity function to withdraw the remaining amount from the strategies. However, there is no subsequent check to ensure that the total amount withdrawn from the strategies plus the balance in the pool is sufficient to cover the requested withdrawal amount.
As a result, the function proceeds to burn the tokens from the user's staked balance and transfer the potentially insufficient amount to the receiver, even if the strategies do not have enough funds to cover the remaining withdrawal amount. StakingPool.sol# https://github.com/Cyfrin/2024-09-stakelink/blob/f5824f9ad67058b24a2c08494e51ddd7efdbb90b/contracts/core/StakingPool.sol#L157-L165
Assume the pool has a balance of 100 tokens and the user has a staked balance of 200 tokens.
The user attempts to withdraw 150 tokens.
The withdraw function first checks the pool balance and finds that it is insufficient to cover the withdrawal (100 < 150).
The function then calls _withdrawLiquidity to withdraw the remaining 50 tokens from the strategies.
However, if the strategies only have 30 tokens available, the total amount withdrawn will be 130 tokens (100 from the pool + 30 from the strategies).
The function proceeds to burn 150 tokens from the user's staked balance and transfers the insufficient amount of 130 tokens to the receiver.
As a result, the user receives 130 tokens instead of the expected 150 tokens, experiencing a loss of 20 tokens.
If the pool frequently operates with low liquidity and the strategies do not have sufficient funds to cover withdrawal requests, the bug is more likely to manifest. However, if the pool maintains adequate liquidity and the strategies are well-funded, the chances of encountering this bug may be lower.
Vs Code
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.