Skip to content
Smart contracts Audit finding Intermediate

Use of payable.transfer() Might Render ETH Impossible to Withdraw

The smart contracts use Solidity's transfer() to send ETH, which forwards only a fixed small amount of gas. If a recipient is a smart contract whose fallback needs more gas, the transfer fails and the ETH becomes stuck.

RaymondFam Follow with ajtra, AkshaySrivastav and 42 others

Originally disclosed on Code4rena

Submitted by RaymondFam, also found by ajtra, AkshaySrivastav, JC, asgeir, pashov, cryptonue, carrotsmuggler, fs0c, karanctf, jonatascm, Tutturu, ladboy233, Awesome, pauliax, Rahoz, bin2chen, shark, supernova, 141345, simon135, lumoswiz, zaskoh, 0xdeadbeef0x, ajtra, hansfriese, yellowBirdy, cccz, CRYP70, dic0de, Bnke0x0, tourist, ahmedov, Parth, ahmedov, obront, chaduke, zapaz, HollaDieWaldfee, btk, rvierdiiev, martin, 0xhacksmithh, fatherOfBlocks, and aviggiano

https://github.com/code-423n4/2022-12-escher/blob/main/src/minters/LPDA.sol#L105

https://github.com/code-423n4/2022-12-escher/blob/main/src/minters/LPDA.sol#L85-L86

https://github.com/code-423n4/2022-12-escher/blob/main/src/minters/FixedPrice.sol#L109

https://github.com/code-423n4/2022-12-escher/blob/main/src/minters/OpenEdition.sol#L92

Impact

The protocol uses Solidity’s transfer() when transferring ETH to the recipients. This has some notable shortcomings when the recipient is a smart contract, which can render ETH impossible to transfer. Specifically, the transfer will inevitably fail when the smart contract:

  • does not implement a payable fallback function, or
  • implements a payable fallback function which would incur more than 2300 gas units, or
  • implements a payable fallback function incurring less than 2300 gas units but is called through a proxy that raises the call’s gas usage above 2300.

Proof of Concept

File: LPDA.sol

85:            ISaleFactory(factory).feeReceiver().transfer(fee);
86:            temp.saleReceiver.transfer(totalSale - fee);

105:        payable(msg.sender).transfer(owed);

File: FixedPrice.sol#L109

109:        ISaleFactory(factory).feeReceiver().transfer(address(this).balance / 20);

File: OpenEdition.sol#L92

92:        ISaleFactory(factory).feeReceiver().transfer(address(this).balance / 20);

Issues pertaining to the use of transfer() in the code blocks above may be referenced further via:

Recommended Mitigation Steps

Using call with its returned boolean checked in combination with re-entrancy guard is highly recommended after December 2019.

For instance, line 105 in LPDA.sol may be refactored as follows:

- payable(msg.sender).transfer(owed);
+ (bool success, ) = payable(msg.sender).call{ value: owed }('');
+ require(success, " Transfer of ETH Failed");

Alternatively, Address.sendValue() available in OpenZeppelin Contract’s Address library can be used to transfer the Ether without being limited to 2300 gas units.

And again, in either of the above measures adopted, the risks of re-entrancy stemming from the use of this function can be mitigated by tightly following the “Check-effects-interactions” pattern and/or using OpenZeppelin Contract’s ReentrancyGuard contract.

mehtaculous (Escher) confirmed and commented:

Agree with severity. Solution would be to attempt to transfer ETH, and if that is unsuccessful, transfer WETH instead.


The original report as published on Code4rena, by RaymondFam. 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() instead of call with a gas stipend that is too low for some recipients.

Impact

ETH transfers to smart contract recipients could fail, potentially locking funds in the contracts.

What the attacker needed

Recipient is a smart contract; recipient's fallback needs >2300 gas

The fix

The report recommends using call with a success check and a re-entrancy guard, or OpenZeppelin's Address.sendValue, and the project confirmed a fix by attempting ETH transfer and falling back to WETH.

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, the receiving contract can run code. The transfer() function only gives that code a tiny fixed amount of gas, so if the code needs more, the whole payment fails. This can leave funds stuck in the sending contract.

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 RaymondFam

View all

18 more disclosed reports, best first.

More from Escher contest

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.