DeFiFoundry
20,000 USDC
View results
Submission Details
Severity: medium
Invalid

`unstakeAll` is susceptible to DOS due to unbounded loop

Summary

unstakeAll contains a for loop which is unbounded as there could be n number of active deposits

Vulnerability Details

unstakeAll takes all the active deposits done by the user in all epochs and passes through them in a for loop which can easily lead to a situation when the block gas limit is maxed out due to which DOS.

function unstakeAll()
external
checkEpochRollover
redeemPendingRewards
returns (uint256 totalStakedAmount)
{
uint256[] memory activeDeposits = getActiveDeposits(msg.sender);
if (activeDeposits.length == 0) revert NoActiveDeposit();
for (uint16 i = 0; i < activeDeposits.length; i++) {
uint16 epoch = uint16(activeDeposits[i]);
DepositReceipt storage dr = deposits[msg.sender][epoch];
if (dr.epoch == 0 || currentEpoch - epoch <= lockCycle) continue;
totalStakedAmount += dr.staked;
// no vested staked and stake is 0 then delete the deposit
if (dr.vestedStaked == 0) {
delete deposits[msg.sender][epoch];
_activeDeposits[msg.sender].remove(epoch);
} else {
// still have vested staked, then only delete the staked
dr.staked = 0;
}
}

Impact

DOS

Tools Used

Manual review

Recommendations

It can be fixed by adding a parameter for the number of rounds to consider.

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.