Christmas Dinner

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

Use `call()` instead of `transfer()`

Summary

ChristmasDinner::_refundETH uses transfer() function to send ethers from contract to the user. However, it is not recommened to use it.

Vulnerability Details

The transfer function is not recommended for sending native token due to its, 2300 gas unit limit. Instead, call can be used to circumvent the gas limit.

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

Impact

transfer() uses a fixed amount of gas, which can result in revert.

Tools Used

Manual, VSCode

Recommendations

Use call() instead of transfer()

function _refundETH(address payable _to) internal {
uint256 refundValue = etherBalance[_to];
- _to.transfer(refundValue);
+ (bool success,) = to.call{value: refundValue}("");
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!