Skip to content
Business logic Audit finding Intermediate

Permanent Lock of User Funds in StakeV2 Due to Incorrect token Debt Handling

When a user claims rewards in native tokens with custom swap data, any leftover token debt is returned to the StakeV2 contract rather than the user, because the Zapper sees StakeV2 as the caller. The user's tokens are then permanently locked in StakeV2 with no way to withdraw them.

Bluedragon Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#41875 [SC-High] Permanent Lock of User Funds in StakeV2 Due to Incorrect token Debt Handling

Submitted on Mar 19th 2025 at 03:17:58 UTC by @Bluedragon for Audit Comp | Yeet

Description

Summary:

When users claim rewards in native tokens using the claimRewardsInNative function in the StakeV2 contract, any remaining token debt (e.g., token0Debt or token1Debt) from the Zapper contract is sent back to the StakeV2 contract instead of the user. This occurs because the msg.sender in the context of Zapper contract is StakeV2, not the actual user. As a result, users lose access to their funds, and the tokens are permanently locked in the StakeV2 contract.

Vulnerability Details:

The issue arises in the claimRewardsInNative function of the StakeV2 contract. When a user claims rewards, the zapOutNative function in the Zapper contract is called. If there is any remaining token debt (e.g., token0Debt or token1Debt), the Zapper contract uses the _clearUserDebt function to send these tokens back to the msg.sender. However, since the msg.sender in this context is the StakeV2 contract, the tokens are sent to StakeV2 instead of the user. This results in the loss of user funds, as the tokens are permanently locked in the StakeV2 contract.

List Of Affected Functions:

  • StakeV2::claimRewardsInNative
  • StakeV2::claimRewardsInToken0
  • StakeV2::claimRewardsInToken1
  • StakeV2::claimRewardsInToken

Impact:

  • Loss of User Funds: Users lose access to their tokens (e.g., token0 or token1) when claiming rewards in other tokens with custom swap data. These tokens are permanently locked in the StakeV2 contract.
  • Permanent Lock of Tokens: Tokens sent to the StakeV2 contract cannot be recovered, as there is no mechanism to withdraw them.

Reference Code Snippet:

Proof of Concept

Proof of Concept:

  1. Scenario:
    • User bluedragon has 600e18 rewards in the StakeV2 contract.
    • bluedragon wants to withdraw these rewards in native BERA and uses the claimRewardsInNative function.
    • As custom swap data can be used for claiming rewards, bluedragon provides custom swap data to convert 300e18 of the rewards to BERA and the remaining 300e18 to token0 (e.g., USDbr). [Assuming 1 BERA = 6 USDbr.]
    • The claimRewardsInNative function calls the zapOutNative function in the Zapper contract.
    • The Zapper contract swaps 300e18 of the rewards to BERA and 300e18 to token0 (USDbr).
    • After the swap, the Zapper contract has 50e18 WBERA (converted to BERA) and 300e18 USDbr.
    • The Zapper contract sends 50e18 BERA to bluedragon.
    • The remaining 300e18 USDbr is sent to the StakeV2 contract via the _clearUserDebt function, as the msg.sender is StakeV2.
  2. Issue:
    • The 300e18 USDbr send to the StakeV2 contract is permanently locked, and bluedragon loses access to these funds.

The original report as published on Immunefi, by Bluedragon. 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 refunds leftover token debt to msg.sender, which is the StakeV2 contract during a claim, instead of the original user.

Impact

Users could permanently lose the leftover token portion of their claimed rewards, as those tokens are locked in StakeV2 with no recovery mechanism.

What the attacker needed

User has claimable rewards; user supplies custom swap data

The fix

The refund of leftover token debt should be sent to the original user rather than to msg.sender, or StakeV2 should forward the returned tokens to the user.

How it was found

  1. A user with rewards calls claimRewardsInNative and supplies custom swap data splitting the rewards between native BERA and token0.
  2. StakeV2 calls zapOutNative on the Zapper contract.
  3. The Zapper swaps part of the rewards to BERA and part to token0.
  4. The Zapper sends the BERA portion to the user.
  5. The remaining token0 is sent to StakeV2 through _clearUserDebt because msg.sender is StakeV2.
  6. The token0 stays locked in StakeV2 and the user cannot recover it.

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.

A user earns rewards in a staking contract and asks to cash them out, partly as the native coin and partly as another token. The helper contract that does the swap sends the leftover other token back to whoever called it, which is the staking contract, not the person. Since the staking contract has no way to pay that token out, it is stuck there 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 Bluedragon

View all

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