Skip to content
Business logic Audit finding Intermediate

Stuck Rewards in StakeV2 Contract Due to Improper Handling of Leftover Tokens

The StakeV2 contract calls Zapper functions that send leftover tokens to the caller (StakeV2) instead of the user, and StakeV2 has no way to recover them. As a result, a portion of user rewards becomes permanently stuck in the contract.

DoD4uFN Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#41640 [SC-High] Stuck Rewards in StakeV2 Contract Due to Improper Handling of Leftover Tokens

Submitted on Mar 17th 2025 at 07:59:42 UTC by @DoD4uFN for Audit Comp | Yeet

Description

Brief/Intro

The StakeV2 contract interacts with the Zapper contract to facilitate reward claiming. However, the zapOut, zapOutToToken0, and zapOutToToken1 functions in Zapper send leftover tokens to both the user and _msgSender(), which in this case is StakeV2. Since StakeV2 has no mechanism to retrieve or use these tokens, they remain stuck in the contract indefinitely. This results in an unintended loss of user rewards and inefficient token management.


Vulnerability Details

The issue arises from how the Zapper contract distributes leftover tokens after executing a reward claim. The zapOutToToken0, zapOutToToken1, and zapOut functions send a portion of the tokens to the receiver (the user) and another portion to _msgSender(), which is StakeV2. However, StakeV2 does not have a function to recover or utilize these tokens, leading to a permanent loss of funds.

Relevant Code Snippet

In StakeV2, the claim functions call zapOut functions from Zapper:

Solidity
uint256 receivedAmount = zapper.zapOutToToken0(msg.sender, swapData, unstakeParams, updatedRedeemParams);

Similarly, in Zapper, the zapOutToToken0 function distributes leftover token1Debt to _msgSender():

Solidity
_sendERC20Token(token1, _msgSender(), token1Debt);

Since _msgSender() is StakeV2, these tokens get stuck in the contract indefinitely.


Impact Details

  • User funds are partially lost: A portion of rewards intended for the user is permanently locked in StakeV2.
  • Contract accumulates unusable tokens: Over time, the contract accumulates stuck tokens, which can affect the efficiency of reward distribution.

This issue could result in significant financial losses depending on the volume of rewards being claimed over time.


References

Zapper:zapOutToToken0Zapper:zapOutToToken1Zapper:zapOut

StakeV2:claimRewardsInToken0StakeV2:claimRewardsInToken1StakeV2:claimRewardsInToken


Recommended Fix

Modify the Zapper contract to ensure that all leftover tokens are returned exclusively to the user, not _msgSender(). Example fix:

Solidity
_sendERC20Token(token1, receiver, token1Debt); // Ensure all tokens go to the receiver

Proof of Concept

Proof of Concept

  1. Deploy StakeV2 and Zapper contracts.
  2. Stake tokens and accumulate rewards.
  3. Call claimRewardsInToken0(), claimRewardsInToken1(), or claimRewardsInToken() with swapData.inputAmount less than tokenXDebt, which leads to tokenXDebt being non-zero.
  4. Observe that part of the tokens sent to _msgSender() (i.e., StakeV2) are never recoverable.
  5. Check the balance of StakeV2—tokens remain stuck indefinitely.

This PoC demonstrates that rewards are not fully transferred to users, leading to locked funds.

The original report as published on Immunefi, by DoD4uFN. 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 sends leftover tokens to _msgSender() (the calling contract) rather than the original user, and StakeV2 lacks a recovery function.

Impact

A portion of user rewards is permanently locked in StakeV2, and the contract accumulates unusable tokens over time.

What the attacker needed

StakeV2 and Zapper deployed; User has staked tokens and earned rewards; swapData.inputAmount less than tokenXDebt

The fix

The Zapper contract should be modified so that all leftover tokens are sent to the user (receiver) instead of _msgSender().

How it was found

  1. Deploy StakeV2 and Zapper contracts.
  2. Stake tokens and accumulate rewards.
  3. Call a claim function with swapData.inputAmount less than tokenXDebt, making tokenXDebt non-zero.
  4. Observe that part of the tokens sent to _msgSender() (StakeV2) are never recoverable.

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 a user claims rewards, a helper contract (Zapper) sometimes has leftover tokens after swapping. It sends those leftovers to whoever called it, which is the staking contract (StakeV2), not the user. Because StakeV2 has no function to move those tokens out, they are lost forever.

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 DoD4uFN

View all

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