Skip to content
Business logic Audit finding Intermediate

Theft of User Funds in executeRewardDistributionYeet During Vesting Period

The reward-distribution function treats tokens held for users in the unstaking vesting period as excess rewards, because the accumulated-rewards calculation subtracts only totalSupply from the contract balance. A manager could therefore distribute those user tokens to the zapper, leaving users unable to withdraw after the vesting period.

testnate Follow

Originally disclosed on Immunefi

Critical View original
  • Disclosed after under an hour

#42345 [SC-Critical] Theft of User Funds in executeRewardDistributionYeet During Vesting Period

Submitted on Mar 23rd 2025 at 06:16:35 UTC by @testnate for Audit Comp | Yeet

Description

Brief/Intro

The executeRewardDistributionYeet function allows managers to distribute tokens that belong to users who have initiated the unstaking process but are still in the vesting period. This can lead to theft of users' funds, as demonstrated in the test case test_fundsLostDuringVestingPeriod. When users call startUnstake, their tokens are put into a vesting period but remain in the contract, where they're incorrectly counted as available rewards that managers can distribute.

Vulnerability Details

The issue occurs due to how accumulatedDeptRewardsYeet calculates "accumulated rewards":

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

This calculation assumes that any tokens in the contract beyond the totalSupply are excess rewards. However, this is incorrect because it also includes tokens that are in vesting periods from users who have called startUnstake.

The vulnerability sequence:

  1. When a user calls startUnstake:
SOL
function startUnstake(uint256 unStakeAmount) external {
    // ...
    balanceOf[msg.sender] -= unStakeAmount;
    totalSupply -= unStakeAmount;
    // ...
    vestings[msg.sender].push(Vesting(unStakeAmount, start, end));
    // ...
}

Their tokens are removed from balanceOf and totalSupply, but remain in the contract, marked only by a vestings struct.

  1. executeRewardDistributionYeet can then distribute these tokens:
SOL
function executeRewardDistributionYeet(
    IZapper.SingleTokenSwap calldata swap,
    IZapper.KodiakVaultStakingParams calldata stakingParams,
    IZapper.VaultDepositParams calldata vaultParams
) external onlyManager nonReentrant {
    uint256 accRevToken0 = accumulatedDeptRewardsYeet();
    // ...
    stakingToken.approve(address(zapper), accRevToken0);
    // ...
    // Calls to zapper that send the tokens
}

A malicious or careless manager can distribute tokens that actually belong to users in the vesting period, causing them to permanently lose these funds.

Impact Details

This is a critical vulnerability that allows managers to steal or accidentally distribute users' funds:

  • Loss of User Funds: Users who have called startUnstake can lose 100% of their tokens in the vesting period if a manager calls executeRewardDistributionYeet.
  • Scale of Impact: The issue affects all users who enter the vesting period through startUnstake. Since the vesting period is 10 days long, this creates a large window where users' funds are at risk.
  • No Recovery Mechanism: Once tokens are sent to the zapper, there's no way for users to recover them. When they attempt to call unstake after the vesting period, the transaction fails due to insufficient token balance in the contract.

This is particularly problematic because users reasonably expect their tokens to be returned after the vesting period, but this vulnerability breaks this fundamental contract guarantee.

Proof of Concept

Proof of Concept

Add this contract in StakeV2.test.sol

SOL
contract StartUnstakeVulnerabilityTest is Test, StakeV2_BaseTest {
    address user;
    KodiakVaultV1 kodiakVault;

    function setUp() public override {
        super.setUp();

        // Setup test user
        user = makeAddr("User");
        token.mint(user, 100 ether);

        // Setup KodiakVault for zapper
        kodiakVault = new KodiakVaultV1(token, wbera);

        // Configure zapper
        mockZapper.setReturnValues(1 ether, 1 ether);
    }

    function test_fundsLostDuringVestingPeriod() public {
        // 1. User stakes tokens
        vm.startPrank(user);
        token.approve(address(stakeV2), 50 ether);
        stakeV2.stake(50 ether);
        vm.stopPrank();

        // 2. User starts unstaking (enters vesting period)
        vm.prank(user);
        stakeV2.startUnstake(50 ether);

        // 3. Verify contract state after startUnstake
        assertEq(stakeV2.balanceOf(user), 0 ether, "User should have 0 ether still staked");
        assertEq(stakeV2.totalSupply(), 0 ether, "Total supply should be 0 ether");
        assertEq(token.balanceOf(address(stakeV2)), 50 ether, "Contract should hold all 50 ether of tokens");

        // 4. Check that unstaking tokens are counted as "rewards"
        assertEq(stakeV2.accumulatedDeptRewardsYeet(), 50 ether, "Unstaking tokens incorrectly counted as rewards");

        // 5. Manager executes reward distribution using the unstaking tokens
        stakeV2.executeRewardDistributionYeet(
            IZapper.SingleTokenSwap(50 ether, 0, 0, address(0), ""),
            IZapper.KodiakVaultStakingParams(address(kodiakVault), 0, 0, 0, 0, 0, address(0)),
            IZapper.VaultDepositParams(address(0), address(0), 0)
        );

        // 6. Verify tokens were sent to zapper (permanently lost to the user)
        assertEq(token.balanceOf(address(stakeV2)), 0 ether, "Contract should now hold only 0 ether");
        assertEq(token.balanceOf(address(mockZapper)), 50 ether, "Zapper should have received 50 ether");

        // 7. Fast forward past vesting period
        vm.warp(block.timestamp + 10 days + 1);

        // 8. User attempts to unstake but it fails due to missing tokens
        vm.startPrank(user);
        vm.expectRevert();
        stakeV2.unstake(0);
        vm.stopPrank();
    }
}

Run forge test --use 0.8.20 -vvv --mt test_fundsLostDuringVestingPeriod

The original report as published on Immunefi, by testnate. 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 accumulated-rewards calculation subtracts only totalSupply from the contract balance, so tokens held for users in the vesting period are counted as distributable rewards.

Impact

Users who start unstaking could lose all of their tokens in the vesting period if a manager calls the distribution function, and there is no recovery mechanism once the tokens reach the zapper.

What the attacker needed

Manager role; user has started unstaking; user is within 10-day vesting period

The fix

The accumulated-rewards calculation should exclude tokens held for users in the vesting period, for example by tracking vesting balances separately and subtracting them.

How it was found

  1. A user stakes tokens in the contract.
  2. The user calls startUnstake, which removes the amount from their balance and totalSupply but leaves the tokens in the contract as a vesting entry.
  3. The accumulated-rewards view returns the full unstaking amount as if it were spare rewards.
  4. A manager calls executeRewardDistributionYeet, which approves and sends those tokens to the zapper.
  5. After the vesting period the user's unstake call reverts because the contract no longer holds the tokens.

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 unstake, their tokens stay in the contract for a waiting period (the vesting period) before they can be collected. The contract works out how many spare tokens it can hand out as rewards by comparing its token balance with the total staked amount, so the waiting tokens look like spare rewards. A manager can then send those waiting tokens away, and the user cannot get them back.

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