#41559 [SC-Critical] Incorrect Calculation of Accumulated Rewards Due to Unstaked Tokens

Submitted on Mar 16th 2025 at 14:53:39 UTC by @aksoy for Audit Comp | Yeet

  • Report ID: #41559

  • Report Type: Smart Contract

  • Report severity: Critical

  • Target: https://github.com/immunefi-team/audit-comp-yeet/blob/main/src/StakeV2.sol

  • Impacts:

    • Permanent freezing of funds

Description

Brief/Intro

The accumulatedDeptRewardsYeet function incorrectly calculates the accumulated rewards by not accounting for unstaked tokens that are still in the contract. This discrepancy arises because totalSupply is reduced when users initiate unstaking, but the tokens remain in the contract until the vesting period ends. As a result, the function may return an inflated reward amount, leading to excessive distribution in executeRewardDistributionYeet, which could ultimately deplete user funds and prevent some users from unstaking their tokens.

Vulnerability Details

The vulnerability lies in the accumulatedDeptRewardsYeet function. stakingToken.balanceOf(address(this)) returns the total balance of staking tokens held by the contract, while totalSupply represents the total amount of staked tokens. However, totalSupply is reduced immediately when a user initiates unstaking via the startUnstake function, but the tokens are not transferred out of the contract until the vesting period ends. This means that stakingToken.balanceOf(address(this)) will still include the unstaked tokens, leading to an overestimation of the accumulated rewards.

    function accumulatedDeptRewardsYeet() public view returns (uint256) {
        return stakingToken.balanceOf(address(this)) - totalSupply;
    }

    function startUnstake(uint256 unStakeAmount) external {
        uint256 amount = balanceOf[msg.sender];
        require(amount >= unStakeAmount, "Insufficient balance");
        balanceOf[msg.sender] -= unStakeAmount;
        totalSupply -= unStakeAmount;
    }

Impact Details

The contract could distribute more rewards than it actually has, leading to a depletion of funds. Users who unstake later may find that there are insufficient tokens in the contract to cover their unstaking requests.

References

https://github.com/immunefi-team/audit-comp-yeet/blob/da15231cdefd8f385fcdb85c27258b5f0d0cc270/src/StakeV2.sol#L149

Proof of Concept

Proof of Concept

Was this helpful?