Skip to content
Business logic Audit finding Intermediate

withdrawETH() in GiantPoolBase don’t call _distributeETHRewardsToUserForToken() or _onWithdraw() which would make users to lose their remaining rewards

The withdrawETH function burns the user's LP tokens without first distributing any unclaimed ETH rewards, so a user who withdraws all their LP tokens loses those rewards. An attacker could not gain anything, but any user withdrawing would forfeit their remaining rewards.

unforgiven Follow with 0x4non

Originally disclosed on Code4rena

Submitted by unforgiven, also found by 0x4non

https://github.com/code-423n4/2022-11-stakehouse/blob/4b6828e9c807f2f7c569e6d721ca1289f7cf7112/contracts/liquid-staking/GiantPoolBase.sol#L50-L64 https://github.com/code-423n4/2022-11-stakehouse/blob/4b6828e9c807f2f7c569e6d721ca1289f7cf7112/contracts/liquid-staking/GiantMevAndFeesPool.sol#L180-L193

Function _distributeETHRewardsToUserForToken() is used to distribute remaining reward of user and it’s called in _onWithdraw() of GiantMevAndFeesPool. but function withdrawETH() in GiantPoolBase don’t call either of them and burn user giant LP token balance so if user withdraw his funds and has some remaining ETH rewards he would lose those rewards because his balance set to zero.

Proof of Concept

This is withdrawETH() code in GiantPoolBase:

    /// @notice Allow a user to chose to burn their LP tokens for ETH only if the requested amount is idle and available from the contract
    /// @param _amount of LP tokens user is burning in exchange for same amount of ETH
    function withdrawETH(uint256 _amount) external nonReentrant {
        require(_amount >= MIN_STAKING_AMOUNT, "Invalid amount");
        require(lpTokenETH.balanceOf(msg.sender) >= _amount, "Invalid balance");
        require(idleETH >= _amount, "Come back later or withdraw less ETH");

        idleETH -= _amount;

        lpTokenETH.burn(msg.sender, _amount);
        (bool success,) = msg.sender.call{value: _amount}("");
        require(success, "Failed to transfer ETH");

        emit LPBurnedForETH(msg.sender, _amount);
    }

As you can see it burn user lpTokenETH balance and don’t call either _distributeETHRewardsToUserForToken() or _onWithdraw(). and in function claimRewards() uses lpTokenETH.balanceOf(msg.sender) to calculate user rewards so if user balance get to 0 user won’t get the remaining rewards. These are steps that this bug happens:

  1. user1 deposit 10 ETH into the giant pool and claimed[user1][lpTokenETH] is 20 and accumulatedETHPerLPShare is 2.
  2. some time passes and accumulatedETHPerLPShare set to 3.
  3. user1 unclaimed rewards are 10 * 3 - 20 = 10 ETH.
  4. user1 withdraw his 10 ETH by calling withdrawETH(10) and contract set lpTokenETH balance of user1 to 0 and transfer 10 ETH to user.
  5. now if user1 calls claimRewards() he would get 0 reward as his lpTokenETH balance is 0.

so users lose their unclaimed rewards by withdrawing their funds.

Tools Used

VIM

Recommended Mitigation Steps

User’s unclaimed funds should be calculated and transferred before any actions that change user’s balance.

vince0656 (Stakehouse) confirmed


The original report as published on Code4rena, by unforgiven. 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 withdrawETH function burns the user's LP tokens without calling the reward distribution logic that other withdrawal paths use.

Impact

Users who withdraw their LP tokens lose any unclaimed ETH rewards, as the reward calculation later sees a zero balance.

What the attacker needed

User has unclaimed ETH rewards; user withdraws all LP tokens via withdrawETH

The fix

The withdrawETH function should calculate and transfer any unclaimed rewards before burning the user's LP tokens.

How it was found

  1. User deposits ETH into the giant pool, setting their LP token balance and reward checkpoint.
  2. Over time the accumulated reward per LP share increases.
  3. User calls withdrawETH with the full LP token amount.
  4. The contract burns the LP tokens and transfers the ETH, leaving the user's LP balance at zero.
  5. When the user later calls claimRewards, the reward calculation uses the now-zero LP balance and returns nothing.

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.

In this system, users deposit ETH and receive LP tokens that represent their share. Rewards are paid based on how many LP tokens you hold. The withdraw function destroys your LP tokens without first paying out any rewards you have earned but not yet claimed, so those rewards are lost.

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 unforgiven

View all

50 more disclosed reports, best first.

More from LSD Network - Stakehouse contest

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.