Skip to content
Smart contracts Audit finding Intermediate

Users emergency withdrawing will lose all past accrued rewards

In the GaugeV2 contract, calling emergencyWithdraw() after emergency mode is activated does not first checkpoint the caller's accrued rewards, so the user's balance drops to zero and their previously earned but unrecorded rewards are lost. Those reward tokens remain stuck in the contract permanently.

Huntoor Follow with ayden, dee24 and 4 others

Originally disclosed on Code4rena

Submitted by Huntoor, also found by ayden, dee24, kimnoic, Nyxaris, Olami978355, rayss

This issue was also found by V12.

https://github.com/code-423n4/2025-10-hybra-finance/blob/6299bfbc089158221e5c645d4aaceceea474f5be/ve33/contracts/GaugeV2.sol#L270-L281

Summary

in the GaugeV2 contract, if the contract was emergency activated, users calling emergencyWithdraw() will lose all past accrued rewards that didn’t have updateReward() called on it previously

for a user to earn rewards, he gets his mappings updated here

    modifier updateReward(address account) {
        rewardPerTokenStored = rewardPerToken();
        lastUpdateTime = lastTimeRewardApplicable();
        if (account != address(0)) {
            rewards[account] = earned(account);
            userRewardPerTokenPaid[account] = rewardPerTokenStored;
        }
        _;
    }

as we see above, rewards mapping is registered as the return data from earned(), and when we look at it we see

    function earned(address account) public view returns (uint256) {
        return rewards[account] + _balanceOf(account) * (rewardPerToken() - userRewardPerTokenPaid[account]) / 1e18;  
    }

we see that it returns old rewards + current balance of the user multiplied by the rewardPerToken (abstractly)

so what happen will be as follows:

  1. User stake 100e18 tokens
  2. emergency activated
  3. he had already earnt before the emergency 10e18 tokens not registered on his rewards mapping since he didn’t call deposit/withdraw/getRewards to update his rewards
  4. call emergencyWithdraw and his balance now is 0.
  5. now earned() function return 0 rewards since his balance is 0 * rewardPerToken = 0

also the left-off rewards tokens are stuck in the contract forever.

Impact: Loss of rewards for users and stuck reward tokens in the contract

Recommended mitigation steps

Add the updateReward modifier to the emergencyWithdraw() call

Proof of concept

paste in ve33/test/C4PoC.t.sol

    function test_emergencyWithdraw_strandsRewardsAndBurnsUserAccrual()
        external
    {
        vm.startPrank(address(this));

        // Use HYBR both as staking TOKEN and rewardToken for simplicity
        // We have HYBR minted to this test from setup_InitMinter()
        uint256 initialHybr = hybr.balanceOf(address(this));
        assertGt(initialHybr, 0, "expected HYBR from initial mint");

        // Deploy GaugeV2
        GaugeV2 gauge = new GaugeV2(
            address(hybr),
            address(rewardHybr),
            address(votingEscrow),
            address(hybr),
            address(this),
            address(0),
            address(0),
            false
        );

        // Stake HYBR
        uint256 stakeAmount = 100 ether;
        hybr.approve(address(gauge), type(uint256).max);
        gauge.deposit(stakeAmount);

        // Fund rewards
        uint256 rewardAmount = 1_000 ether;
        hybr.approve(address(gauge), rewardAmount);
        gauge.notifyRewardAmount(address(hybr), rewardAmount);

        // Accrue some rewards
        vm.warp(block.timestamp + 7 days / 14);

        uint256 accruedBefore = gauge.earned(address(this));
        assertGt(
            accruedBefore,
            0,
            "accrued must be > 0 before emergencyWithdraw"
        );

        // Enable emergency and withdraw
        gauge.activateEmergencyMode();
        gauge.emergencyWithdraw();

uint256 accruedAfter = gauge.earned(address(this));
        assertEq(
            accruedAfter,
            0,
            "accrued should be zero after emergencyWithdraw"
        );

uint256 stuckRewards = hybr.balanceOf(address(gauge));
        assertGt(stuckRewards, 0, "reward tokens remain stuck in gauge");

        vm.stopPrank();
    }

Hybra Finance disputed this finding.


The original report as published on Code4rena, by Huntoor. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 emergencyWithdraw() function lacks the updateReward modifier, so the user's earned rewards are never written to the rewards mapping before their balance is zeroed.

Impact

Users lose all rewards accrued before the emergency withdrawal, and those reward tokens are stuck in the contract forever; the project disputed the finding.

What the attacker needed

Emergency mode activated; user has unclaimed accrued rewards; user calls emergencyWithdraw()

How it was found

  1. Stake tokens in the gauge.
  2. Activate emergency mode on the gauge.
  3. Accrue rewards over time without calling deposit, withdraw or getRewards.
  4. Call emergencyWithdraw(), which sets the user's balance to zero.
  5. Observe that earned() now returns zero and reward tokens remain stuck in the contract.

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 staking contract keeps track of how many reward tokens each person has earned. Normally that running total is only saved when the person deposits, withdraws or claims. If they use the emergency exit instead, the contract forgets to save the total first, and because their staked balance becomes zero the calculation now returns nothing. So they walk away with their stake but lose the rewards they had already built up.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Huntoor

View all

1 more disclosed report, best first.

More from Hybra Finance

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.