The deposit function has an if-else block that checks if _amount is greater than 0. If it is, the function transfers tokens from the user to the contract, calls _depositLiquidity, mints liquid tokens to the user, and increases totalStaked by the deposited amount. However, if _amount is 0, the function skips the token transfer and directly calls _depositLiquidity without any further checks.
The _depositLiquidity function (StakingPool.sol) deposits available tokens from the contract's balance into strategies. When called with _amount = 0, it can still deposit tokens that are already in the contract's balance, leading to an increase in totalStaked without any actual deposit from the user. https://github.com/Cyfrin/2024-09-stakelink/blob/f5824f9ad67058b24a2c08494e51ddd7efdbb90b/contracts/core/StakingPool.sol#L111-L127
This bug could affect users by incorrectly inflating the totalStaked variable, which represents the total amount of tokens staked in the pool. The contract's staked token balance will not match the actual tokens deposited by users.
This vulnerability allows the totalStaked variable to be incorrectly increased when the _amount parameter is zero. This happens because the function does not properly handle the case when _amount is zero and still calls the _depositLiquidity function, which can deposit tokens from the contract's balance into strategies, leading to an unintended increase in totalStaked.
StakingPool.sol:111-127# https://github.com/Cyfrin/2024-09-stakelink/blob/f5824f9ad67058b24a2c08494e51ddd7efdbb90b/contracts/core/StakingPool.sol#L111-L127
The vulnerability is in the else block of the deposit function. When _amount is 0, it calls _depositLiquidity(_data) without any checks, allowing deposits from the contract's balance even though no tokens were transferred from the user.
StakingPool.sol:477-389# https://github.com/Cyfrin/2024-09-stakelink/blob/f5824f9ad67058b24a2c08494e51ddd7efdbb90b/contracts/core/StakingPool.sol#L477-L489
The _depositLiquidity function is called by the vulnerable else block in the deposit function. It deposits tokens from the contract's balance (token.balanceOf(address(this))) into strategies without checking if the tokens were actually transferred from the user. This leads to an incorrect increase in totalStaked.
These two parts of the code are connected and contribute to the vulnerability that allows
totalStakedto be increased without actual user deposits when_amountis 0 in thedepositfunction.
The totalStaked variable, which represents the total amount of tokens staked in the pool, can be artificially inflated without corresponding user deposits. This leads to discrepancies between the actual staked tokens and the recorded totalStaked value.
If the StakingPool contract distributes rewards based on the totalStaked value, users who didn't actually deposit tokens may receive undeserved rewards, while users who genuinely staked tokens may receive less than their fair share.
Vs
Handle the case when _amount is zero.
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.