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

TotalStaked and totalVestedStaked are not decreased when unstaking or unstakingVested immediately

Summary

TotalStaked and totalVestedStaked are not decreased when unstaking or unstakingVested immediately. TotalStake and totalVestedStaked remain unchanged but it should change.

Vulnerability Details

In unstake()::FjordStaking.sol and unstakeVested()::FjordStaking.sol, there is no decrease of totalStaked (nor totalVestedStaked) which represents the total amount that is staked (and the total amount vested that is staked for totalVestedStaked).

Here is the code for unstake()::FjordStaking.sol:

...
//EFFECT
dr.staked -= _amount;
if (currentEpoch != _epoch) {
totalStaked -= _amount;
userData[msg.sender].totalStaked -= _amount;
} else {
// unstake immediately
newStaked -= _amount;
// here <-- no decreasing of totalStaked
}
...

https://github.com/Cyfrin/2024-08-fjord/blob/main/src/FjordStaking.sol#L473-L476


Here is the code for unstakeVested()::FjordStaking.sol:

...
dr.vestedStaked -= amount;
if (currentEpoch != data.epoch) {
totalStaked -= amount;
totalVestedStaked -= amount;
userData[streamOwner].totalStaked -= amount;
} else {
// unstake immediately
newStaked -= amount;
newVestedStaked -= amount;
// here <-- no decreasing of totalStaked
// here <-- no decreasing of totalVestedStaked
}
...

https://github.com/Cyfrin/2024-08-fjord/blob/main/src/FjordStaking.sol#L534-L538

Impact

Wrong calculation of totalStaked and totalVestedStaked could break the protocol.

Tools Used

Github, VisualCode, Foundry.

Recommendations

Add a decrease of totalStaked and totalVestedStaked by the _amount when unstake() and unstakeVested() to keep a good track of the total amount staked and vested staked.

Updates

Lead Judging Commences

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

Support

FAQs

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