Skip to content
Smart contracts Audit finding Intermediate

address.call{value:x}() should be used instead of payable.transfer()

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

__141345__ Follow with IllIllI, Bnke0x0 and 30 others

Originally disclosed on Code4rena

Submitted by 141345, also found by IllIllI, Bnke0x0, SmartSek, d3e4, pashov, Deivitto, bananasboys, joestakey, RedOneN, cryptonue, datapunk, minhquanym, Ch_301, adriro, cccz, peanuts, Tomo, merlin, corerouter, RaymondFam, codexploder, Bnke0x0, KingNFT, carlitox477, Satyam_Sharma, Nyx, 8olidity, cloudjunky, 0xdeadbeef0x, martin, rvierdiiev, and Amithuddar

When withdrawing and refund ETH, the contract uses Solidity’s transfer() function.

Using Solidity’s transfer() function has some notable shortcomings when the withdrawer is a smart contract, which can render ETH deposits impossible to withdraw. Specifically, the withdrawal will inevitably fail when:

  • The withdrawer smart contract does not implement a payable fallback function.
  • The withdrawer smart contract implements a payable fallback function which uses more than 2300 gas units.
  • The withdrawer smart contract implements a payable fallback function which needs less than 2300 gas units but is called through a proxy that raises the call’s gas usage above 2300.

Risks of reentrancy stemming from the use of this function can be mitigated by tightly following the “Check-Effects-Interactions” pattern and using OpenZeppelin Contract’s ReentrancyGuard contract.

Proof of Concept

// Line-of-Credit/contracts/utils/LineLib.sol
48:    payable(receiver).transfer(amount);

References:

The issues with transfer() are outlined here.

For further reference on why using Solidity’s transfer() is no longer recommended, refer to these articles.

Recommended Mitigation Steps

Using low-level call.value(amount) with the corresponding result check or using the OpenZeppelin Address.sendValue is advised, reference.

kibagateaux (Debt DAO) confirmed


The original report as published on Code4rena, by __141345__. 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 code uses Solidity's transfer(), which forwards a fixed 2300 gas stipend, instead of a low-level call with a gas allowance and result check.

Impact

ETH withdrawals and refunds could fail permanently for smart-contract recipients whose fallback needs more than 2300 gas, leaving funds stuck.

What the attacker needed

Recipient is a smart contract; fallback needs more than 2300 gas

The fix

It should be fixed by using a low-level call with a result check or OpenZeppelin's Address.sendValue, while keeping reentrancy protections.

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 runs a small piece of code called a fallback function. The old transfer() method only gives that code a tiny fixed amount of gas, so if the code needs more, the whole payment fails. This means funds can get stuck if the receiver is a contract rather than a normal wallet.

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 __141345__

View all

18 more disclosed reports, best first.

More from Debt DAO 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.