TwentyOne

First Flight #29
Beginner FriendlyGameFiFoundrySolidity
100 EXP
View results
Submission Details
Severity: low
Invalid

Unsafe Ether Transfers May Lead to Unexpected Behavior

Root Cause

The contract uses transfer for sending Ether to players:

payable(player).transfer(2 ether); // Transfer the prize to the player

Using transfer is unsafe because it forwards a fixed amount of 2300 gas, which may not be sufficient if the recipient is a contract with a fallback or receive function requiring more gas.

Impact

If the recipient address is a contract that needs more than 2300 gas units to process the incoming Ether, the transfer will fail, potentially causing the transaction to revert. This can prevent players from receiving their winnings and disrupt the game's functionality.

Recommendations

  • Use call Instead of transfer: Replace transfer with call to forward all available gas and handle failures gracefully:

    (bool success, ) = player.call{value: 2 ether}("");
    require(success, "Transfer failed");
  • Reentrancy Protection: Implement reentrancy guards to protect against potential reentrancy attacks when using call.

  • Check Transfer Success: Always check the return value of the call to ensure the transfer was successful.

Updates

Lead Judging Commences

inallhonesty Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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