Skip to content
Business logic Audit finding Intermediate

withdrawForETH could be used to drain the WETH in RubiconRouter.sol

The withdrawForETH function in RubiconRouter.sol trusts any contract implementing IBathToken to report its underlying token and balance, allowing a malicious pool to fake these values. An attacker could then withdraw the router's entire WETH balance as ETH without providing any WETH.

dipp Follow

Originally disclosed on Code4rena

Submitted by dipp, also found by 0x1f8b, csanuragjain, and pedroais

In the withdrawForETH function in RubiconRouter.sol, the targetPool may be any contract that implements the IBathToken interface and returns wethAddress as its underlying token. The withdrawnWETH amount could be set to the RubiconRouter.sol contract’s WETH balance so that the contract’s entire WETH balance is withdrawn, as long as the tagetPool does not transfer any WETH to RubiconRouter.sol. The caller of the withdrawForETH function would then receive the withdraw amount.

Proof of Concept

    function withdrawForETH(uint256 shares, address targetPool)
        external
        payable
        returns (uint256 withdrawnWETH)
    {
        IERC20 target = IBathToken(targetPool).underlyingToken();
        require(target == ERC20(wethAddress), "target pool not weth pool");
        require(
            IBathToken(targetPool).balanceOf(msg.sender) >= shares,
            "don't own enough shares"
        );
        IBathToken(targetPool).transferFrom(msg.sender, address(this), shares);
        withdrawnWETH = IBathToken(targetPool).withdraw(shares);
        WETH9(wethAddress).withdraw(withdrawnWETH);

        //Send back withdrawn native eth to sender
        msg.sender.transfer(withdrawnWETH);
    }
  1. Let shares be equal to the contracts WETH balance.
  2. The malicious targetPool contract returns the wethAddress as the underlying token on line 480.
  3. targetPool returns the max uint256 value for its balanceOf function to pass the require condition on line 483 for any value of shares.
  4. The transferFrom on line 486 does not have to do anything and its withdraw function should return the WETH balance of RubiconRouter.sol.
  5. The RubiconRouter.sol contract will then withdraw ETH equal to the withdrawWETH amount, which should be equal to the contract’s WETH balance.
  6. The caller of the withdrawForETH function receives the withdraw ETH without providing any WETH.

Recommended Mitigation Steps

Check the contract’s WETH balance before the caller is supposed to send the WETH and after the WETH is sent to confirm the contract has received enough WETH from the caller.

bghughes (Rubicon) confirmed

HickupHH3 (judge) commented:

Will keep this as medium severity because of the pre-requisite of users accidentally sending ETH to the router contract.


The original report as published on Code4rena, by dipp. 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 function does not verify that the targetPool is a legitimate pool or that the router actually received WETH from the caller before sending ETH.

Impact

An attacker could drain the router's entire WETH balance, but only if the router holds WETH, which the judge notes requires users to accidentally send ETH to the contract.

What the attacker needed

Router holds WETH (users accidentally sent ETH)

The fix

The contract should check its WETH balance before and after the caller is supposed to send WETH, to confirm it received enough WETH from the caller.

How it was found

  1. Set shares equal to the router's WETH balance.
  2. Deploy a malicious targetPool that returns wethAddress as its underlying token.
  3. Make targetPool.balanceOf return the maximum uint256 value to pass the balance check.
  4. Implement transferFrom to do nothing and withdraw to return the router's WETH balance.
  5. Call withdrawForETH; the router unwraps WETH and sends ETH to the caller.

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 smart contract bug where a function that lets users swap pool shares for ETH trusts whatever pool contract they point it at. A malicious pool can lie about its token and balance, tricking the router into giving away its own WETH as ETH. The attacker gets free ETH, and the router loses its funds.

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 dipp

View all

5 more disclosed reports, best first.

More from Rubicon v2

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.