The selectWinner function can select address(0) as the winner when a player has been refunded. This causes the prize pool to be sent to address(0) and permanently lost, while the NFT is also minted to address(0), making both unrecoverable.
When a player calls refund, their slot in the players array is set to address(0) instead of being removed. The selectWinner function uses players.length to calculate the winner index, which includes these zero-address slots. If the random selection picks a zero-address slot, the prize is sent to address(0) and lost forever.
This creates a critical issue: users who paid to enter the raffle lose their chance to win, and the prize pool is permanently destroyed.
File: src/PuppyRaffle.sol (lines 127-130, 140)
Severity: High
Likelihood: Medium
Impact: High
❌ Prize pool sent to address(0) and lost forever
❌ NFT minted to address(0) (unrecoverable)
❌ Users lose their potential winnings
❌ Requires any refund before winner selection
Scenario: A player refunds their ticket, leaving address(0) in the players array. The random selection then picks this zero-address slot as the winner.
Test Output:
What This Proves:
✅ Winner can be address(0) after refund
✅ Prize pool is lost forever
✅ NFT minted to address(0)
Skip zero-address slots when selecting winner:
Alternative (Better): Remove refunded players from the array:
Why This Fixes It:
✅ Zero-address slots are skipped during winner selection
✅ Prize is always sent to a valid player
✅ No funds lost to address(0)
CWE-672: Operation on a Resource after Expiration or Release
SWC-114: Transaction Order Dependence
## Description In the `selectWinner` function, when a player has refunded and their address is replaced with address(0), the prize money may be sent to address(0), resulting in fund loss. ## Vulnerability Details In the `refund` function if a user wants to refund his money then he will be given his money back and his address in the array will be replaced with `address(0)`. So lets say `Alice` entered in the raffle and later decided to refund her money then her address in the `player` array will be replaced with `address(0)`. And lets consider that her index in the array is `7th` so currently there is `address(0)` at `7th index`, so when `selectWinner` function will be called there isn't any kind of check that this 7th index can't be the winner so if this `7th` index will be declared as winner then all the prize will be sent to him which will actually lost as it will be sent to `address(0)` ## Impact Loss of funds if they are sent to address(0), posing a financial risk. ## Recommendations Implement additional checks in the `selectWinner` function to ensure that prize money is not sent to `address(0)`
The contest is live. Earn rewards by submitting a finding.
Submissions are being reviewed by our AI judge. Results will be available in a few minutes.
View all submissionsThe contest is complete and the rewards are being distributed.