Liquid Staking

Stakelink
DeFiHardhatOracle
50,000 USDC
View results
Submission Details
Severity: medium
Invalid

Front-Running Vulnerability in deposit Function Leading to Denial of Service (DoS)

Summary

The deposit function in the provided Solidity code is vulnerable to a front-running attack. Malicious actors can exploit this by transferring tokens to the contract, inflating the balance and causing the function to revert, leading to a Denial of Service (DoS).

Vulnerability Details

https://github.com/Cyfrin/2024-09-stakelink/blob/main/contracts/core/StakingPool.sol#L111-L132

The vulnerability is exploited due to a check in the last part of the deposit function to assess if deposit was properly carried out and all intended assets were apppropiately deposited. The check however has a downside as it can be exploited by a malicous actor. The malicious actor can make a direct transfer to the contract, thereby inflating the contract balance and since the check expects the ending balance to be equal to the starting balance, the intending deposit by a legtimate user becomes unsuccessful.

Below is the function, check at the latter end of the function can be exploited by a malcious actor to cause Dos for legitmate stakers

function deposit(
address _account,
uint256 _amount,
bytes[] calldata _data//data not validated
) external onlyPriorityPool {
require(strategies.length > 0, "Must be > 0 strategies to stake");
uint256 startingBalance = token.balanceOf(address(this));
if (_amount > 0) {
token.safeTransferFrom(msg.sender, address(this), _amount);
_depositLiquidity(_data);
_mint(_account, _amount);
totalStaked += _amount;
} else {
_depositLiquidity(_data);
}
uint256 endingBalance = token.balanceOf(address(this));
if (endingBalance > startingBalance && endingBalance > unusedDepositLimit)
revert InvalidDeposit();/
}

Impact

medium

Tools Used

manual review

Recommendations

Protocol should remove or modify the "endingBalance > startingBalance" check

Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.