Swap.sol implements potentially dangerous transfer
The Swap contract uses Solidity's transfer() to send Ether, which forwards only a fixed gas stipend. If the recipient is a contract with a fallback that needs more gas or lacks a payable fallback, the Ether transfer fails and funds may be stuck or undelivered.
Originally disclosed on Code4rena
Submitted by elprofesor, also found by WatchPug, Koustre, cmichel, JMukesh, and pauliax
Impact
The use of transfer() in Swap.sol may have unintended outcomes on the eth being sent to the receiver. Eth may be irretrievable or undelivered if the msg.sender or feeRecipient is a smart contract. Funds can potentially be lost if;
- The smart contract fails to implement the payable fallback function
- The fallback function uses more than 2300 gas units
The latter situation may occur in the instance of gas cost changes. The impact would mean that any contracts receiving funds would potentially be unable to retrieve funds from the swap.
Proof of Concept
This issue directly impacts the following lines of code:
Examples of similar issues ranked as medium can be found here and here, just search for ‘M04’. A detailed explanation of why relying on payable().transfer() may result in unexpected loss of eth can be found here
Tools Used
Manual review
Recommended Mitigation Steps
Re-entrancy has been accounted for in all functions that reference Solidity's transfer() . This has been done by using a re-entrancy guard, therefore, we can rely on msg.sender.call.value(amount)` or using the OpenZeppelin Address.sendValue library
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
Impact
Ether could be irretrievable or undelivered if the sender or fee recipient is a smart contract that cannot accept the transfer under the fixed gas stipend.
What the attacker needed
Recipient is a smart contract; fallback needs >2300 gas or is missing
The fix
The report recommends replacing transfer() with a call that forwards gas or using OpenZeppelin's Address.sendValue library, noting that re-entrancy is already guarded.
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. The transfer() function only gives that code a tiny fixed amount of gas, so if the receiver needs more gas or has no way to accept Ether, the payment fails. This can leave Ether stuck in the sending contract or prevent the intended recipient from getting paid.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.