Skip to content
Smart contracts Audit finding Intermediate

Unstaked tokens incorrectly counted as rewards during vesting period

An accounting error in the StakeV2 contract causes tokens that are in the vesting period after unstaking to be counted as available rewards. When the manager distributes rewards, these vesting tokens are paid out, leaving the contract unable to cover other stakers' principal.

merlinboii Follow

Originally disclosed on Immunefi

Critical View original
  • Disclosed after under an hour

#41521 [SC-Critical] Unstaked tokens incorrectly counted as rewards during vesting period

Submitted on Mar 16th 2025 at 07:55:16 UTC by @merlinboii for Audit Comp | Yeet

Description

Brief/Intro

An accounting error in StakeV2 causes unstaked tokens in vesting to be incorrectly counted as rewards. This could lead to unintended loss of funds for stakers and potential insolvency for the protocol.

Vulnerability Details

The accumulatedDeptRewardsYeet() function does not account for unstaked tokens during the vesting period:

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

Since totalSupply is reduced immediately for the unstakeAmount at startUnstake(), while the unstaked amount remains in the contract during vesting, accumulatedDeptRewardsYeet() mistakenly includes this unstaked amount as part of the rewards. Consequently, when executeRewardDistributionYeet() is called, these mistakenly counted rewards are distributed to stakers, leading to an unintended loss of funds.

Solidity
function startUnstake(uint256 unStakeAmount) external {
    --- SNIPPED ---

    balanceOf[msg.sender] -= unStakeAmount;
@>  totalSupply -= unStakeAmount;

    uint256 start = block.timestamp;
    uint256 end = start + VESTING_PERIOD;
    vestings[msg.sender].push(Vesting(unStakeAmount, start, end));
    stakedTimes[msg.sender]++;  
    emit VestingStarted(msg.sender, unStakeAmount, vestings[msg.sender].length - 1);
}

Impact Details

Consider the following scenario:
0. Users A and B each stake 100e18 YEET
- Contract State:
- YEET.balance(StakeV2): 200e18
- totalSupply: 200e18
- Real rewards: 0

  1. B starts unstaking 100e18 YEET
    • Contract State:
      • YEET.balance(StakeV2): 200e18 (unchanged)
      • totalSupply: 100e18 (reduced by B's unstake)
      • Tokens in vesting: 100e18 (B's unstaking amount)
  2. Manager Distributes "Rewards":
    • accumulatedDeptRewardsYeet() returns: 200e18 - 100e18 = 100e18
    • These rewards (actually B's vesting tokens) are distributed
    • Contract State:
      • YEET.balance(StakeV2): 100e18
      • totalSupply: 100e18
      • Tokens distributed as "rewards": 100e18
  3. B finalizes unstake at vesting period ends and withdraws their 100e18 YEET
    • Final Contract State:
      • YEET.balance(StakeV2): 0
      • totalSupply: 100e18 (A's stake)
      • Result: A's stake becomes unbacked by tokens

This scenario demonstrates the following impacts:

  1. User A suffers a complete loss of their 100e18 YEET stake as they cannot unstake due to insufficient contract balance
  2. The protocol becomes technically insolvent as it owes User A 100e18 YEET but has 0 balance
  3. The lack of vesting token tracking allows the manager to unknowingly distribute vesting tokens as rewards through accumulatedDeptRewardsYeet(), creating a HIGH likelihood.

The severity assessment

This issue qualifies as Direct theft of any user funds because:

  1. Stakers lose their entire principal investment
  2. The loss occurs while funds are at-rest in the staking contract
  3. The vulnerability allows one user (B) to profit at the expense of another (A)

References

https://github.com/immunefi-team/audit-comp-yeet/blob/main/src/StakeV2.sol#L247-L262\\ https://github.com/immunefi-team/audit-comp-yeet/blob/main/src/StakeV2.sol#L148-L150

Proof of Concept

Proof of Concept

  1. Users A and B each stake 100e18 YEET
    • Contract State:
      • YEET.balance(StakeV2): 200e18
      • totalSupply: 200e18
      • Real rewards: 0
  2. B starts unstaking 100e18 YEET
    • Contract State:
      • YEET.balance(StakeV2): 200e18 (unchanged)
      • totalSupply: 100e18 (reduced by B's unstake)
      • Tokens in vesting: 100e18 (B's unstaking amount)
  3. Manager Distributes "Rewards":
    • accumulatedDeptRewardsYeet() returns: 200e18 - 100e18 = 100e18
    • These rewards (actually B's vesting tokens) are distributed
    • Contract State:
      • YEET.balance(StakeV2): 100e18
      • totalSupply: 100e18
      • Tokens distributed as "rewards": 100e18
  4. B finalizes unstake at vesting period ends and withdraws their 100e18 YEET
    • Final Contract State:
      • YEET.balance(StakeV2): 0
      • totalSupply: 100e18 (A's stake)
      • Result: A's stake becomes unbacked by tokens

The original report as published on Immunefi, by merlinboii. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The reward calculation uses the contract's token balance minus totalSupply, but totalSupply is reduced immediately on unstake while the tokens remain in the contract during vesting, so vesting tokens are treated as rewards.

Impact

The remaining staker's principal becomes unbacked and cannot be withdrawn, making the protocol insolvent; the report states this could lead to unintended loss of funds for stakers.

What the attacker needed

At least two stakers; one staker starts unstaking; manager distributes rewards during vesting

The fix

The contract should track tokens that are in vesting separately and exclude them from the reward calculation, for example by subtracting the total vesting amount from the contract balance before computing rewards.

How it was found

  1. Two users each stake 100e18 YEET, so the contract holds 200e18 and totalSupply is 200e18.
  2. One user starts unstaking 100e18 YEET; totalSupply drops to 100e18 but the contract balance stays at 200e18.
  3. The manager calls the reward distribution, and accumulatedDeptRewardsYeet returns 100e18, which is paid out as rewards.
  4. The unstaking user withdraws their 100e18 after vesting, leaving the contract with 0 balance while totalSupply is still 100e18.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When someone unstakes, their tokens are locked for a while before they can withdraw them. The contract still holds those tokens but no longer counts them as part of the total staked supply. The reward calculation subtracts the total supply from the contract's token balance, so the locked tokens look like extra rewards. If the manager distributes rewards at that moment, those locked tokens get paid out to stakers, and the contract no longer has enough tokens to let everyone withdraw.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by merlinboii

View all

9 more disclosed reports, best first.

More from Yeet

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.