Christmas Dinner

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

Potentially Unsafe Handling of ERC20 or Ether Transfers

Location

  • Found in src/ChristmasDinner.sol [Line: 235]()

    _to.transfer(refundValue);

Issue
Here, the contract uses .transfer() to send Ether to _to. In most cases, .transfer() is acceptable for Ether, but if this were intended for ERC20 transfers, it would be considered unsafe since many tokens do not consistently return true/false or could behave non-standardly. Although your code indicates you’re already using SafeERC20 for ERC20 tokens, this snippet specifically handles Ether transfer. It is marked here possibly due to confusion between native ETH operations and ERC20 operations.

Impact

  • If the intent was to manage ERC20 transfers using .transfer(), it would be prone to failure if the ERC20 token does not implement the standard transfer logic.

  • For native Ether, .transfer() also imposes a fixed gas stipend of 2300, which might revert if the receiving address includes fallback logic that requires more gas.

Recommendation

  • For ERC20: Always use OpenZeppelin’s SafeERC20.safeTransfer or safeTransferFrom to ensure consistent handling of return values.

  • For Ether: .transfer() is typically fine for simpler scenarios, but consider using .call{value: refundValue}("") if you want to allow the receiver more than 2300 gas (or if there is a risk of revert due to complex fallback code).

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!