Skip to content
Smart contracts Audit finding Intermediate

transfer() depends on gas consts

The ENS registrar controller uses transfer() to refund excess ether, which forwards only 2300 gas to the recipient's fallback function. If a contract registering a name has a fallback that needs more gas, the refund fails and the whole registration transaction reverts.

rajatbeladiya Follow

Originally disclosed on Code4rena

Submitted by rajatbeladiya, also found by 141345, _Adam, 0x29A, 0xNineDec, alan724, Amithuddar, asutorufos, Aussie_Battlers, berndartmueller, c3phas, cccz, Ch_301, cryptphi, csanuragjain, Dravee, durianSausage, fatherOfBlocks, GimelSec, hake, hyh, IllIllI, Jujic, Limbooo, pashov, RedOneN, Ruhum, scaraven, TomJ, and zzzitron

ETHRegistrarController.sol#L183-L185 ETHRegistrarController.sol#L204

transfer() forwards 2300 gas only, which may not be enough in future if the recipient is a contract and gas costs change. it could break existing contracts functionality.

Proof of Concept

.transfer or .send method, only 2300 gas will be “forwarded” to fallback function. Specifically, the SLOAD instruction, will go from costing 200 gas to 800 gas.

If any smart contract has a functionality of register ens and it has fallback function which is making some state change in contract on ether receive, it could use more than 2300 gas and revert every transaction.

For reference, check out:

Recommended Mitigation Steps

Use .call insted .transfer

 (bool success, ) = msg.sender.call.value(amount)("");
 require(success, "Transfer failed.");

jefflau (ENS) confirmed, but disagreed with severity and commented:

Recommend reducing severity to QA

LSDan (judge) decreased severity to Medium and commented:

I’m downgrading this to Medium. There are external factors required to make this problem occur, but if it does the functionality of the protocol as a whole could be severely impacted.

Arachnid (ENS) commented:

It’s unclear to me how this could be a significant issue. Anyone writing code to register names knows that any excess funds will be returned, and therefore that they need a fallback that consumes minimal gas. Any EVM change that increases the gas of fallback functions would be breaking for a great number of contracts beyond ENS.

LSDan (judge) commented:

It’s unclear to me how this could be a significant issue.

The register functions will fail, consuming a good bit of gas along the way if this occurs. If this were not such a critical piece of functionality I would have considered it QA, but a failure here breaks the protocol.

Anyone writing code to register names knows that any excess funds will be returned, and therefore that they need a fallback that consumes minimal gas. Any EVM change that increases the gas of fallback functions would be breaking for a great number of contracts beyond ENS.

The fact that other contracts will break along with ENS does not invalidate the issue. This is a clearly documented problem that has been known for years (see ref links). There is no reason to introduce more critical contracts to the ecosystem that will fail in this scenario, particularly when it is so easy to avoid.

Arachnid (ENS) commented:

The register functions will fail, consuming a good bit of gas along the way if this occurs. If this were not such a critical piece of functionality I would have considered it QA, but a failure here breaks the protocol.

I think the implied API here is that any contract registering names with the controller must either send the right amount of ether, or have a fallback function that can accept ether. Changes to the consensus layer that invalidate that assumption for a given contract are out-of-scope for ENS.

Sending all remaining gas with the refund increases the threat surface by allowing possible reentrancy etc, which we haven’t examined as a threat model here.


The original report as published on Code4rena, by rajatbeladiya. 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 Solidity's transfer() for refunds, which hard-codes a 2300 gas stipend instead of forwarding enough gas for a contract recipient's fallback.

Impact

A contract that registers an ENS name and has a fallback needing more than 2300 gas would see its registration transaction revert; the judge rated this Medium because external factors are required, and ENS argued the scenario is unlikely and that sending all gas would add reentrancy risk.

What the attacker needed

Recipient is a contract; fallback needs more than 2300 gas; gas costs change or fallback is heavy

The fix

Replace transfer() with a low-level call that forwards gas and check the returned success flag, though ENS noted this increases reentrancy exposure.

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 also runs a small piece of code on the receiving contract called a fallback function. The transfer() method only gives that code a tiny fixed amount of gas (2300), so if the code needs to do anything more than a trivial action it runs out of gas and the whole payment fails. This report says the ENS name registration contract uses transfer() for refunds, so a registering contract with a slightly heavier fallback would make every registration revert.

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 rajatbeladiya

View all

2 more disclosed reports, best first.

More from ENS

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.