Use call() instead of transfer() when transferring ETH in RubiconRouter
The RubiconRouter contract uses transfer() to send ETH, which forwards only 2300 gas to the recipient. If the recipient is a contract that needs more gas, the transfer fails, potentially locking funds or breaking functionality.
Submitted by Ruhum, also found by cccz, kenzo, xiaoming90, SmartSek, 0x1f8b, IllIllI, GimelSec, kenta, joestakey, berndartmueller, JMukesh, PP1004, Dravee, gzeon, shenwilly, sorrynotsorry, and z3s
https://github.com/code-423n4/2022-05-rubicon/blob/main/contracts/RubiconRouter.sol#L356
https://github.com/code-423n4/2022-05-rubicon/blob/main/contracts/RubiconRouter.sol#L374
https://github.com/code-423n4/2022-05-rubicon/blob/main/contracts/RubiconRouter.sol#L434
https://github.com/code-423n4/2022-05-rubicon/blob/main/contracts/RubiconRouter.sol#L451
https://github.com/code-423n4/2022-05-rubicon/blob/main/contracts/RubiconRouter.sol#L491
https://github.com/code-423n4/2022-05-rubicon/blob/main/contracts/RubiconRouter.sol#L548
Impact
When transferring ETH, use call() instead of transfer().
The transfer() function only allows the recipient to use 2300 gas. If the recipient uses more than that, transfers will fail. In the future gas costs might change increasing the likelihood of that happening.
Keep in mind that call() introduces the risk of reentrancy. But, as long as the router follows the checks effects interactions pattern it should be fine. It’s not supposed to hold any tokens anyway.
Proof of Concept
See the linked code snippets above.
Recommended Mitigation Steps
Replace transfer() calls with call(). Keep in mind to check whether the call was successful by validating the return value:
(bool success, ) = msg.sender.call{value: amount}("");
require(success, "Transfer failed.")
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 use of transfer() instead of call() for ETH transfers, which imposes a fixed gas stipend that may be insufficient for some recipients.
Impact
Transfers to contracts requiring more than 2300 gas could fail, potentially causing loss of funds or denial of service for certain recipients.
What the attacker needed
Recipient is a contract needing >2300 gas
The fix
Replace transfer() calls with call() and check the return value to ensure success, while following the checks-effects-interactions pattern to avoid reentrancy.
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.
When a smart contract sends Ether to another contract, it can specify how much gas (computational effort) the recipient gets to run its code. The transfer() function gives only a tiny fixed amount (2300 gas), which may not be enough for some recipients, causing the payment to fail. Using call() instead lets the sender specify gas and check success, but requires care to avoid reentrancy attacks.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.