Skip to content
Smart contracts Audit finding Advanced

Reentrancy vulnerability in GiantMevAndFeesPool.withdrawETH

The withdrawETH function in GiantMevAndFeesPool calls an external contract before updating the idleETH balance, allowing a reentrant call to claimRewards that inflates rewards. An attacker could exploit this to receive more rewards than deserved.

cccz Follow

Originally disclosed on Code4rena

Submitted by cccz

GiantMevAndFeesPool.withdrawETH calls lpTokenETH.burn, then GiantMevAndFeesPool.beforeTokenTransfer, followed by a call to _distributeETHRewardsToUserForToken sends ETH to the user, which allows the user to call any function in the fallback. While GiantMevAndFeesPool.withdrawETH has the nonReentrant modifier, GiantMevAndFeesPool.claimRewards does not have the nonReentrant modifier. When GiantMevAndFeesPool.claimRewards is called in GiantMevAndFeesPool.withdrawETH, the idleETH is reduced but the ETH is not yet sent to the user, which increases totalRewardsReceived and accumulatedETHPerLPShare, thus making the user receive more rewards when calling GiantMevAndFeesPool.claimRewards.

Proof of Concept

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

Recommended Mitigation Steps

Change to

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);
+  idleETH -= _amount;

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

    emit LPBurnedForETH(msg.sender, _amount);
}

vince0656 (Stakehouse) confirmed


The original report as published on Code4rena, by cccz. 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 state variable idleETH is updated after the external call, violating the checks-effects-interactions pattern, and claimRewards lacks a reentrancy guard.

Impact

The user could receive more rewards than they are entitled to.

What the attacker needed

User has LP tokens; Contract has idleETH

How it was found

  1. Call withdrawETH with a valid amount.
  2. During the ETH transfer, reenter claimRewards.
  3. Observe increased rewards due to inflated idleETH.

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.

This is a reentrancy bug in a smart contract. When a contract sends Ether to a user, the user's contract can run code that calls back into the original contract before the first function finishes. Here, the withdraw function updates a balance after sending Ether, so the user can call claimRewards in between and get extra rewards.

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 cccz

View all

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

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.