Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: medium
Valid

Unprotected Ether Transfer Vulnerability in selectWinner Function

Summary

The selectWinner function within the provided smart contract contains a vulnerability related to transferring ether to the winning address. This vulnerability arises from not adequately handling scenarios where the recipient might reject the funds, potentially leading to a Denial of Service (DoS) attack on the contract.

Vulnerability Details

The vulnerability is evident in the following line of the selectWinner function:

(bool success,) = winner.call{value: prizePool}("");

By directly transferring ether using the .call method without additional protective measures, the function is exposed to potential failures. If the winner address is a contract that does not have a fallback function (or one that reverts transactions), the call to transfer ether will fail. This failure will cause the require(success, "PuppyRaffle: Failed to send prize pool to winner"); line to revert the entire transaction, making it impossible to select a winner and distribute the prize pool.

Impact

  • DoS Attack: Malicious actors could deliberately enter the raffle using a contract address designed to reject ether, effectively blocking the selectWinner function and preventing any winner from being chosen.

  • Locked Funds: In the scenario where the ether transfer fails repeatedly, the collected ether might become locked within the contract, leading to potential financial losses for participants.

  • Loss of Trust: Continuous failures in selecting winners and distributing prizes can erode trust in the contract and deter future participation.

Tools Used

manual

Recommendations

  • Check Address Type: Before transferring ether, check if the winning address is a contract or externally owned account (EOA). If it's a contract, ensure it has the capability to accept ether.

  • Graceful Error Handling: Instead of reverting the entire transaction if the ether transfer fails, consider implementing a fallback mechanism, such as distributing the prize pool among other participants or adding it to the next raffle's prize pool.

  • Use Pull Payment Mechanism: Instead of pushing payments to winners, adopt a pull payment mechanism. Allow winners to manually withdraw their prizes, providing more control and reducing the risks of failed transactions.

  • Clear Documentation: Ensure that all participants are made aware of the potential risks associated with providing contract addresses that cannot accept ether.

  • Regular Testing: Conduct regular tests and audits, especially after implementing changes to ensure the smooth and secure functioning of the contract.

Updates

Lead Judging Commences

Hamiltonite Lead Judge almost 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

smart contract wallet without fallback/receive will halt the raffle

Support

FAQs

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