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.
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);
}
- Let
sharesbe equal to the contracts WETH balance. - The malicious
targetPoolcontract returns thewethAddressas the underlying token on line 480. targetPoolreturns the max uint256 value for its balanceOf function to pass the require condition on line 483 for any value of shares.- The transferFrom on line 486 does not have to do anything and its withdraw function should return the WETH balance of
RubiconRouter.sol. - The
RubiconRouter.solcontract will then withdraw ETH equal to thewithdrawWETHamount, which should be equal to the contract’s WETH balance. - The caller of the
withdrawForETHfunction 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.
Will keep this as medium severity because of the pre-requisite of users accidentally sending ETH to the router contract.
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
- Set shares equal to the router's WETH balance.
- Deploy a malicious targetPool that returns wethAddress as its underlying token.
- Make targetPool.balanceOf return the maximum uint256 value to pass the balance check.
- Implement transferFrom to do nothing and withdraw to return the router's WETH balance.
- 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.