Skip to content
DoS Audit finding Intermediate

Usage of deprecated transfer() can result in revert

The withdrawPayments() function uses transfer() to send Ether, which forwards a fixed 2300 gas stipend. If the recipient is a contract whose fallback or receive function needs more gas, or is called via a proxy, the transfer reverts and the owner cannot withdraw fees.

Lambda Follow with cccz, yixxas and 11 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-09-harpie-judging/tree/main/007-M

Found by

Lambda, cccz, yixxas, Waze, IEatBabyCarrots, pashov, 0xSmartContract, JohnSmith, Tomo, CodingNameKiki, sach1r0, IllIllI, csanuragjain, gogo

Summary

The function withdrawPayments() is used by the Owners to withdraw the fees.

Vulnerability Detail

transfer() uses a fixed amount of gas, which was used to prevent reentrancy. However this limit your protocol to interact with others contracts that need more than that to process the transaction.

Specifically, the withdrawal will inevitably fail when: 1.The withdrawer smart contract does not implement a payable fallback function. 2.The withdrawer smart contract implements a payable fallback function which uses more than 2300 gas units. 3.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.

Impact

transfer() uses a fixed amount of gas, which can result in revert. https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/

Code Snippet

https://github.com/Harpieio/contracts/blob/97083d7ce8ae9d85e29a139b1e981464ff92b89e/contracts/Vault.sol#L159 https://github.com/Harpieio/contracts/blob/97083d7ce8ae9d85e29a139b1e981464ff92b89e/contracts/Vault.sol#L156-L160

Tool used

Manual Review

Recommendation

Use call instead of transfer(). Example: (bool succeeded, ) = _to.call{value: _amount}(""); require(succeeded, "Transfer failed.");

Lead Senior Watson

Fair considering recipient may be a contract with custom logic for receive(). But this is definitely recoverable if the fee recipient wasn't able to receive funds.

Harpie Team

Moved to .call. Fix here.

Lead Senior Watson

Confirmed fix.

The original report as published on Sherlock, by Lambda. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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() method, which forwards a fixed 2300 gas stipend, instead of call() which allows specifying gas.

What the attacker needed

Recipient is a contract needing >2300 gas; or recipient is a proxy contract

The fix

The fix was to replace transfer() with call() and check the success boolean.

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 receiving contract a tiny fixed amount of gas (2300 units) to run its code. If the receiver needs more gas than that, the send fails and the whole withdrawal reverts. This means the owner's fees can get stuck if the recipient is a contract with any non-trivial logic.

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.

More by Lambda

View all

64 more disclosed reports, best first.

More from Harpie

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.