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

Loss of Funds Due to Invalid Winner's Address in PuppyRaffle Contract

Summary

The selectWinner function in the provided code is vulnerable to a loss of funds if the randomly selected winner's address has been replaced with address(0) due to a refund.

Vulnerability Details

The vulnerability arises from the selection of a winner using a randomly generated index from the players array. If one or several players have refunded their entrance fees, their addresses are replaced with address(0) in the array. However, there is no verification if the randomly selected winner's address is valid, which can result in the loss of funds.

Impact

If the randomly selected winner's address is address(0) due to a refund, the prize and the associated non-fungible token (NFT) will be sent to address(0), resulting in a loss of funds. This can occur when one or more players have refunded their entrance fees before the winner is selected.

Tools Used

Manual review.

Recommendations

To mitigate this vulnerability, consider implementing the following measures:

  1. Use the _isActivePlayer function to ensure that the randomly selected winner's address is not address(0) before proceeding with the prize distribution.

  2. Implement a mechanism to handle situations where the randomly selected winner's address is invalid, such as selecting an alternative winner or redistributing the prize pool.

Updates

Lead Judging Commences

Hamiltonite Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

zero address can win the raffle

Funds are locked to no one. If someone gets the refund issue, they also got this issue. IMPACT: High Likelihood: High

Support

FAQs

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