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

`unstakeAll` doesn't unstake current epoch stakes

Impact

  1. Broken core functionality

  2. Function does not work as designed

  3. Users who want to unstake may have their funds locked

Summary

The unstakeAll function does not unstake current epoch stakes.

Vulnerability Details

The unstakeAll function, as the name suggests, should unstake all available rewards.

However, this function only unstakes stakes that were made lockCycle epochs ago, even though any stake in the current epoch is instantly redeemable.

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;
}
}

This will cause users to not actually unstake all of their assets, but only the old stakes.

Example:

  1. A user has 3 different stakes, all of which have passed the lock period and can be unstaked.

  2. He stakes at the beginning of the epoch.

  3. Near the end of the epoch, he wants to unstake all his assets, so he calls unstakeAll.

  4. The function only unstakes his 3 previous deposits, not touching the one he made at the beginning of this epoch.

  5. Now the user needs to wait to get his stake unlocked.

The user will become dissatisfied and may never use the protocol again.

Root Cause

The unstakeAll function is missing the functionality to unstake current epoch stakes.

Tools Used

Manual review

Recommendations

Add the functionality for unstakeAll to unstake tokens that were staked this epoch.

Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

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