`call()` should be used instead of `transfer()` on an address payable
The smart contract uses the deprecated transfer() function to send Ether, which forwards a fixed 2300 gas. This can cause transactions to fail if the recipient is a contract that requires more gas, such as a multisig wallet or a proxy.
virtualfact Follow with Nyx, 0x4non and 11 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-11-dodo-judging/issues/5
Found by
virtualfact, Nyx, 0x4non, 8olidity, 0xNazgul, yixxas, pashov, rvierdiiev, Bnke0x0, sach1r0, Tomo, defsec, ElKu, ak1
Summary
Vulnerability Detail
The transfer() and send() functions forward a fixed amount of 2300 gas. Historically, it has often been recommended to use these functions for value transfers to guard against reentrancy attacks. However, the gas cost of EVM instructions may change significantly during hard forks which may break already deployed contract systems that make fixed assumptions about gas costs. For example. EIP 1884 broke several existing smart contracts due to a cost increase of the SLOAD instruction.
Impact
The use of the deprecated transfer() function for an address will inevitably make the transaction fail when:
- The claimer smart contract does not implement a payable function.
- The claimer smart contract does implement a payable fallback which uses more than 2300 gas unit.
- The claimer smart contract implements a payable fallback function that needs less than 2300 gas units but is called through proxy, raising the call's gas usage above 2300.
- Additionally, using higher than 2300 gas might be mandatory for some multisig wallets.
Code Snippet
DODORouteProxy.sol#L152 payable(routeFeeReceiver).transfer(restAmount);
DODORouteProxy.sol#L489 payable(msg.sender).transfer(receiveAmount);
UniversalERC20.sol#L29 to.transfer(amount);
Tool used
Manual Review
Recommendation
Use call() instead of transfer(), but be sure to respect the CEI pattern and/or add re-entrancy guards, as several hacks already happened in the past due to this recommendation not being fully understood.
More info on; https://swcregistry.io/docs/SWC-134
Discussion
Attens1423
https://github.com/DODOEX/dodo-route-contract/pull/5
aktech297
Though the changes look pretty straight forward, i would suggest to include test cases for re-entrency to all types swaps.
hrishibhat
Based on comments & discussions with the Senior: The fix looks good, additionally Senior suggests adding necessary re-reentrancy protection to relevant swap functions.
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 transfer() instead of call() for Ether transfers, which hardcodes a 2300 gas stipend that can be insufficient for contract recipients.
What the attacker needed
Recipient is a contract; recipient's fallback needs >2300 gas
The fix
The fix was to replace transfer() with call() and add reentrancy protection to the relevant swap functions.
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 using transfer(), it only gives the recipient a tiny fixed amount of gas (2300) to run any code. If the recipient is a contract that needs more gas to accept the payment, the whole transaction fails. The report recommends using call() instead, which forwards more gas, but warns to add reentrancy guards to stay safe.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.