Skip to content
Business logic Audit finding Intermediate

Permanent freezing of yield due to incorrect reward handling in StakeV2 claim functions

The Zapper contract sends leftover token debt to StakeV2 instead of the user when claiming rewards in a single output token, causing users to permanently lose a portion of their rewards. This happens because users cannot perfectly predict the swap input amount, leaving excess tokens stuck in StakeV2.

merlinboii Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#41280 [SC-High] Permanent freezing of yield due to incorrect reward handling in `StakeV2` claim functions

Submitted on Mar 13th 2025 at 09:39:03 UTC by @merlinboii for Audit Comp | Yeet

Description

Brief/Intro

Users claiming rewards through StakeV2's claim functions: claimRewardsInNative() , claimRewardsInToken0(), claimRewardsInToken1() and claimRewardsInToken(), which are designed to handle reward claims in a single output token (either native, token0, token1, or a whitelisted token) can permanently lose access to a portion of their rewards.

This occurs because the Zapper contract incorrectly sends any remaining token debt to StakeV2 instead of the user who initiated the claim. Since StakeV2 has no mechanism to recover or redistribute these tokens, the lost funds become permanently inaccessible to the user.

Vulnerability Details

This vulnerability stems from a flawed interaction between StakeV2’s claim functions and Zapper’s token return logic when users opt to swap their rewards into a single output token:

  1. In claimRewardsInNative() -> zapOutNative() -> _swapToWBERA(): The remaining token0Debt and token1Debt are transferred to _msgSender(), which is now refer to msg.sender (StakeV2)
Solidity
function _swapToWBERA(
...
) internal returns (uint256 wBeraDebt) {
    if (address(token0) == address(wbera)) {
        wBeraDebt += token0Debt;
        token0Debt = 0;
    } else {
        wBeraDebt += _verifyTokenAndSwap(swapData0, address(token0), address(wbera), address(this));
        token0Debt -= swapData0.inputAmount;
    }

    if (address(token1) == address(wbera)) {
        wBeraDebt += token1Debt;
        token1Debt = 0;
    } else {
        wBeraDebt += _verifyTokenAndSwap(swapData1, address(token1), address(wbera), address(this));
        token1Debt -= swapData1.inputAmount;
    }
    // log yeetBalance
@>  _clearUserDebt(token0, token1, token0Debt, token1Debt, _msgSender());  
}
  1. In claimRewardsInToken0() -> zapOutToToken0(): The remaining token1Debt is transferred to _msgSender(), which is now refer to msg.sender (StakeV2)
Solidity
function zapOutToToken0(
    ...
) public nonReentrant onlyWhitelistedKodiakVaults(unstakeParams.kodiakVault) returns (uint256 totalToken0Out) {
    --- SNIPPED ---
    token1Debt -= swapData.inputAmount;
    token0Debt += _verifyTokenAndSwap(swapData, address(token1), address(token0), address(this));
    _sendERC20Token(token0, receiver, token0Debt);
@>  _sendERC20Token(token1, _msgSender(), token1Debt);
    return (token0Debt);
}
  1. In claimRewardsInToken1() -> zapOutToToken1(): The remaining token0Debt is transferred to _msgSender(), which is now refer to msg.sender (StakeV2)
Solidity
function zapOutToToken1(
    ...
) public nonReentrant onlyWhitelistedKodiakVaults(unstakeParams.kodiakVault) returns (uint256 totalToken1Out) {
    --- SNIPPED ---
    token0Debt -= swapData.inputAmount;
    token1Debt += _verifyTokenAndSwap(swapData, address(token0), address(token1), address(this));
@>  _sendERC20Token(token0, _msgSender(), token0Debt);
    _sendERC20Token(token1, receiver, token1Debt);
    return (token1Debt);
}
  1. In claimRewardsInToken() -> zapOut(): The remaining token0Debt and token1Debt are transferred to _msgSender(), which is now refer to msg.sender (StakeV2)
Solidity
function zapOut(    
    ...
)
public
override
nonReentrant
onlyWhitelistedKodiakVaults(unstakeParams.kodiakVault)
returns (uint256 totalAmountOut)
{
    --- SNIPPED ---
    } else {
        // sent directly to receiver. What is receiver is zapper?
        totalAmountOut += _verifyTokenAndSwap(swap0, address(token0), outputToken, receiver);
        token0Debt -= swap0.inputAmount;
        totalAmountOut += _verifyTokenAndSwap(swap1, address(token1), outputToken, receiver);
        token1Debt -= swap1.inputAmount;
    }
@>  _clearUserDebt(token0, token1, token0Debt, token1Debt, _msgSender());
}
  1. In the StakeV2, there is no logic to handle the remaining token debt, whether after calling the Zapper function or an external function to handle this case.

Impact Details

Users lose access to their full earned rewards when claiming through StakeV2 if they opt to receive a single output token (Native, Token0, Token1, or a whitelisted token) and do not perfectly specify the swap amount.

  1. If the user specifies swapDataX.inputAmount < tokenXDebt (the amount received after removing liquidity from Kodiak), the excess tokenXDebt - swapDataX.inputAmount is sent to StakeV2 instead of the user and users permanently lose access to a portion of their earned rewards.
  2. It is not feasible for users to perfectly predict swapDataX.inputAmount as the remove liquidity function only guarantees slippage protection but cannot provide an exact output amount so users cannot reliably specify an inputAmount that exactly matches tokenXDebt, making some amount of loss inevitable.
Solidity
function _approveAndUnstakeFromKodiakVault(
    IZapper.KodiakVaultUnstakingParams calldata unstakeParams,
    uint256 islandTokenDebt
) internal returns (IERC20, IERC20, uint256, uint256) {
    --- SNIPPED ---
    (uint256 _amount0, uint256 _amount1,) = kodiakStakingRouter.removeLiquidity(
        IKodiakVaultV1(unstakeParams.kodiakVault),
        islandTokenDebt,
@>      unstakeParams.amount0Min,
@>      unstakeParams.amount1Min,
        unstakeParams.receiver
    );

    // require(islandTokenDebt == _liqBurned, "Invalid island token burn amount");
    return (_token0, _token1, _amount0, _amount1);
}

The severity assessment

This issue leads to Permanent Freezing of Unclaimed Yield under the intended functionality of StakeV2’s claiming functions: claimRewardsInNative() , claimRewardsInToken0(), claimRewardsInToken1() and claimRewardsInToken(). The intended functionality of these functions is to return rewards in a single output token, but due to this bug, users permanently lose access to a portion of their rewards.

Although there is a workaround (users can set unstakeParams.receiver != address(this), bypassing the swap and receiving token0 and token1 directly), users may not be aware of this workaround and the default intention behavior encourages using the claim functions, which exposes users to this bug.

A case could be made for Low Severity (Contract fails to deliver promised returns but doesn’t lose value), as the lost yield remains within the contract rather than being drained or stolen, However, because the logic directly impacts user funds (yield) and leads to irreversible loss in most cases, I believe a Medium severity rating is more appropriate.

References

Proof of Concept

Proof of Concept

Use the case claimRewardsInToken0() for example, here's how users can permanently lose their remaining debt equivalent to a portion of their rewards:

Prerequisites

  • User has staked YEET in StakeV2 and earned 500 trifecta vault shares as rewards, which can be redeemed into YEET-WBERA LP tokens
  • Current YEET-WBERA Kodiak Island ratio: 1 YEET = 0.00167 BERA (token0 = YEET, token1 = WBERA)
  • Expected rewards after removing LP: 2,000 YEET + 3.34 WBERA
  • What the user can estimate (but not precisely predict at execution time):
    • The amount of vault shares available for redemption (calculateRewardsEarned()).
    • The amount of YEET and WBERA received from LP removal (from current of Kodiak Island vault state).

Vulnerability Flow

  1. The user intends to claim all rewards as YEET by swapping WBERA to YEET.
Solidity
StakeV2.claimRewardsInToken0(
    500 shares,  // Amount of vault shares to redeem
    IZapper.SingleTokenSwap({
        inputAmount: 3.30 * 1e18,  // User estimates to swap all output WBERA to YEET
        outputQuote: 2,000 * 1e18,  // Quote amount for YEET
        outputMin: 1,995 * 1e18,  // Slippage for YEET
        executor: address(executor),
        path: swapPathData
    }),
    IZapper.KodiakVaultUnstakingParams({
        kodiakVault: address(YEET_BERA_KODIAK_ISLAND),
        amount0Min: 1,995 * 1e18,  // Slippage for YEET
        amount1Min: 3.30 * 1e18,  // Slippage for WBERA
        receiver: address(zapper),  // Opt in swap process
    }),
    redeemParams // the amount to claim will be prepared in `StakeV2._verifyAndPrepareClaim()`
);
  1. The actual amount from Kodiak remove liquidity:
  • YEET received: 2,010 YEET
  • WBERA received: 3.34 WBERA
  • These amounts include LP fees and potential price impact variations.
  1. The swap processes a fixed inputAmount for swapping WBERA to YEET via OBRouter and the given executor:
  • Swap inputAmount: 3.30 WBERA
  • Swap output: 1,995 YEET
  • Balance Zapper after swap:
    • YEET: 2,010 (from LP) + 1,995 (swap output) = 4,005 YEET
    • WBERA: 3.34 (from LP) - 3.30 (swapped) = 0.04 WBERA
  1. Zapper processes to transfer remaining Debt:
  • YEET: 4,005 YEET -> sent to user (receiver)
  • WBERA: 0.04 WBERA -> sent to StakeV2 (_msgSender())

Final State: User's loss 0.04 WBERA and permanently locked in the StakeV2

Additional Note: If the lost amount is in YEET, it will be incorrectly redistributed as extra rewards via: StakeV2.executeRewardDistributionYeet() so this creates unfair rewards distribution, benefiting other claimers.

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

Likely, the Zapper contract uses _msgSender() to send leftover tokens, which resolves to StakeV2 when called from StakeV2, and StakeV2 has no logic to forward or recover these tokens.

Impact

Users permanently lose a portion of their earned rewards when claiming through StakeV2 if they opt for a single output token and cannot perfectly specify the swap amount; the lost tokens remain stuck in StakeV2.

What the attacker needed

User has staked YEET in StakeV2; User claims rewards in a single output token; User cannot perfectly predict swap input amount

The fix

The Zapper should send leftover tokens to the original user (receiver) instead of _msgSender(), or StakeV2 should include logic to forward or credit these tokens to the user.

How it was found

  1. User calls claimRewardsInToken0 with swap inputAmount less than the actual token debt from removing liquidity.
  2. Zapper removes liquidity, receiving token0 and token1 amounts that may differ from estimates.
  3. Zapper swaps only the specified inputAmount, leaving a remainder of token1.
  4. Zapper sends the remaining token1Debt to _msgSender() (StakeV2) instead of the user.
  5. StakeV2 has no mechanism to recover or redistribute these tokens, so they are permanently locked.

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 you claim rewards, the system swaps your tokens into one type you choose. If you guess the swap amount slightly wrong, the leftover tokens are sent to the main contract instead of you, and you can never get them back. This means you lose part of your earned rewards.

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

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.