Liquid Staking

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

VaultControllerStrategy.sol#deposit() will always fail if someone send some tokens to address(this) deliberately

Summary

VaultControllerStrategy.sol#deposit() will always fail if someone send some tokens to address(this) deliberately.

Vulnerability Details

In deposit(), tokens will be transferred from msg.sender to address(this), then those tokens will be deposited to vaults. However, when deposit to vaults, "token.balanceOf(address(this))" is used instead of "_amount". If someone send some tokens to address(this) deliberately, token.balanceOf(address(this)) > amount, then deposited > _amount. "_amount - deposited" will underflow, cause deposit() to revert.

function deposit(uint256 _amount) external onlyStakingPool {
token.safeTransferFrom(msg.sender, address(this), _amount);
(uint256 vaultMinDeposits, uint256 vaultMaxDeposits) = getVaultDepositLimits();
uint256 startIndex = indexOfLastFullVault + 1;
if (vaults[0].getPrincipalDeposits() < vaultMaxDeposits) {
startIndex = 0;
}
uint256 deposited = _depositToVaults(startIndex, token.balanceOf(address(this)), vaultMinDeposits, vaultMaxDeposits);
totalDeposits += deposited;
totalPrincipalDeposits += deposited;
if (deposited != _amount) {
token.safeTransfer(address(stakingPool), _amount - deposited);
}
}

Impact

VaultControllerStrategy.sol#deposit() will always fail if someone send some tokens to address(this) deliberately

Tools Used

manually reviewed

Recommendations

Two modification methods, (1) seems better.

(1)

uint256 deposited = _depositToVaults(startIndex, token.balanceOf(address(this)), vaultMinDeposits, vaultMaxDeposits);

change to

uint256 deposited = _depositToVaults(startIndex, _amount, vaultMinDeposits, vaultMaxDeposits);

(2),

if (deposited != _amount) {
token.safeTransfer(address(stakingPool), _amount - deposited);
}

change to:

if (deposited < _amount) {
token.safeTransfer(address(stakingPool), _amount - deposited);
}

Updates

Lead Judging Commences

inallhonesty Lead Judge
about 1 year ago
inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Out of scope

Support

FAQs

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