Skip to content
Business logic Audit finding Intermediate

StakeV2::accumulatedDeptRewardsYeet fails to account for pending vesting withdrawals which could cause contract insolvency

The reward-distribution accounting function computes excess tokens as the contract's token balance minus total supply, but total supply is reduced when a user starts an unstake vesting while the tokens stay in the contract. A manager could therefore treat those pending withdrawal tokens as excess rewards and reinvest them, leaving the contract unable to pay out vesting claims.

kmm Follow

Originally disclosed on Immunefi

Critical View original
  • Disclosed after under an hour

#42152 [SC-Critical] `StakeV2::accumulatedDeptRewardsYeet` fails to account for pending vesting withdrawals which could cause contract insolvency

Submitted on Mar 21st 2025 at 10:34:08 UTC by @kmm for Audit Comp | Yeet

Description

Brief/Intro

The StakeV2::accumulatedDeptRewardsYeet function does not account tokens that are currently getting vested, which could cause the manager to user those funds to mint vault shares. Causing insolvency in the redeeming of staking tokens.

Vulnerability Details

The function StakeV2::executeRewardDistributionYeet, is used to convert excess Yeet amount, into vault shares to distribute to the stakeholders.

The amount is validated against StakeV2::accumulatedDeptRewardsYeet.

Solidity
    function executeRewardDistributionYeet(
        IZapper.SingleTokenSwap calldata swap,
        IZapper.KodiakVaultStakingParams calldata stakingParams,
        IZapper.VaultDepositParams calldata vaultParams
    ) external onlyManager nonReentrant {
        uint256 accRevToken0 = accumulatedDeptRewardsYeet();
        require(accRevToken0 > 0, "No rewards to distribute");
        require(swap.inputAmount <= accRevToken0, "Insufficient rewards to distribute"); //@review
Solidity
    function accumulatedDeptRewardsYeet() public view returns (uint256) {
        //@audit - `totalSupply` is reduced when creating an unstake escrow, which could cause user funds to be acumulated as debt?
        return stakingToken.balanceOf(address(this)) - totalSupply;
    }

When users want to withdraw they must create a request via StakeV2::startUnstake.

Solidity
function startUnstake(uint256 unStakeAmount) external {
        require(unStakeAmount > 0, "Amount must be greater than 0");
        require(stakedTimes[msg.sender] < STAKING_LIMIT, "Amount must be less then the STAKING_LIMIT constant"); // DOS protection https://github.com/Enigma-Dark/Yeet/issues/12
        _updateRewards(msg.sender);
        uint256 amount = balanceOf[msg.sender];
        require(amount >= unStakeAmount, "Insufficient balance");

        balanceOf[msg.sender] -= unStakeAmount;
        totalSupply -= unStakeAmount; //@review - Total Supply is deducted

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

Within the function totalSupply is deducted but the tokens are not sent anywhere and the vesting for the user starts.

In this situation the manager is completely allowed to use these tokens, and cause insolvency and loss of funds for a lot of users.

References

Proof of Concept

Proof of Concept

  1. totalSupply is 1000, balanceOf is 1001
  2. User creates a unstake vesting for 500 tokens
    • totalSupply=500
  3. The manager is not aware of this and thinks there are 501 excess tokens
  4. The manager reinvests them bringing balanceOf=500, totalSupply=500
  5. The user after that claims his vesting, bringing balanceOf=0, totalSupply=500.
  6. Users cannot withdraw due to insufficientBalance
  7. The manager can no longer reinvest, due to underflow in accumulatedDeptRewardsYeet

The original report as published on Immunefi, by kmm. 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

Likely the excess-rewards calculation subtracts total supply from the token balance without excluding tokens reserved for pending vesting withdrawals.

Impact

Pending vesting tokens could be spent as rewards, causing protocol insolvency and preventing users from withdrawing their staked tokens.

What the attacker needed

Manager role acts on the excess; a user has a pending vesting withdrawal

The fix

The excess-rewards calculation should subtract the total amount still owed to pending vesting withdrawals, not just total supply.

How it was found

  1. The contract holds 1000 total supply against a balance of 1001 tokens.
  2. A user starts an unstake vesting for 500 tokens, which lowers total supply to 500 while the tokens remain.
  3. The manager sees 501 tokens as excess rewards.
  4. The manager reinvests them, bringing the balance down to 500.
  5. The user claims the vesting, leaving a balance of 0 against a total supply of 500.
  6. Other users cannot withdraw, and the manager cannot reinvest because the calculation underflows.

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 asks to withdraw, the contract lowers its recorded total of owed shares but keeps the actual tokens in place until the withdrawal finishes. The contract's idea of 'spare' tokens is just real balance minus that recorded total, so the pending withdrawal tokens look spare. A manager could then spend them as rewards, and later the withdrawing user cannot be paid.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by kmm

View all

2 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.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.