Skip to content
Smart contracts Audit finding Intermediate

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.

Ruhum Follow

Originally disclosed on Code4rena

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.")

bghughes (Rubicon) confirmed


The original report as published on Code4rena, by Ruhum. 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 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.

More by Ruhum

View all

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

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.