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

Flaw in Refund Logic and Potential Selection of 0 Address as Winner

Vulnerability Details

The refund function sets the address of a player who has requested a refund to the zero address (0x0) instead of removing it from the players array. This poses a risk in the selectWinner function, which could mistakenly select the zero address as a winner.

function refund(uint256 playerIndex) public {
// ... (omitted code for brevity)
players[playerIndex] = address(0);
// ... (omitted code for brevity)
}

In the selectWinner function, the winner is randomly selected from the players array, which could include these zero addresses:

function selectWinner() external {
// ... (omitted code for brevity)
address winner = players[winnerIndex];
// ... (omitted code for brevity)
}

Impact

  • Potential Loss of Prize Pool: If a zero address is selected as a winner, the prize pool is sent to an inaccessible address, resulting in a loss of funds.

  • Reduced Trust in Raffle Integrity: The possibility of a non-participant (zero address) winning can undermine the integrity and fairness of the raffle.

  • Inefficient Use of Resources: Maintaining zero addresses in the players array leads to wastage of storage space and unnecessary processing during winner selection.

Recommendations

  • Remove Refunded Players from Array: Instead of setting a player's address to zero, remove the player from the players array upon a successful refund.

  • Implement Checks in Winner Selection: Add additional checks in the selectWinner function to ensure that the selected winner is not a zero address. If a zero address is selected, the function should repeat the selection process or skip to the next valid address.

Updates

Lead Judging Commences

Hamiltonite Lead Judge about 2 years 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.

Give us feedback!