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.
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:
- https://docs.soliditylang.org/en/v0.8.15/security-considerations.html?highlight=transfer#sending-and-receiving-ether
- https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/
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.
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.
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.
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.
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.