Christmas Dinner

First Flight #31
Beginner FriendlyFoundrySolidity
100 EXP
View results
Submission Details
Severity: medium
Valid

Refunding of ether might fail with insufficient gas

Summary

The _refundETH function might fail if we end up using more than 2300 gas, we also do not check if the balance of the user is non zero.

Vulnerability Details

When we use the transfer method to send ether the transaction fails and reverts if it needs to use more than 2300 gas. This would mean if the destination is another contract and their fallback of recive methods have complex logic we might not be able to refund our ethers from the contract.

function _refundETH(address payable _to) internal {
uint256 refundValue = etherBalance[_to];
_to.transfer(refundValue);
etherBalance[_to] = 0;
}

Impact

We can't refund ethers if transfer calls fails with unsufficent gas.

Tools Used

  • Manual review

Recommendations

Change the transfer with call that forward all available gas and handle the success/failure explicitly

function _refundETH(address payable _to) internal {
(bool success, ) = _to.call{value: refundValue}("");
require(success, "Ether transfer failed");
etherBalance[_to] = 0;
}
Updates

Lead Judging Commences

0xtimefliez Lead Judge about 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

transfer instead of call

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!