When a player refunds, refund() sets their slot to address(0) but does not shrink the array — players.length is unchanged and the refunded ETH has already left the contract.
selectWinner() derives the payout from players.length * entranceFee and selects winner = players[winnerIndex]. After refunds, players.length overstates the funds actually held, so prizePool + fee is computed against money that is no longer there; and winnerIndex can land on a zeroed slot, sending the prize to address(0).
Likelihood:
Occurs in any round where at least one player refunds before selectWinner() is called — a normal, intended user action.
Occurs as a payout-to-zero whenever the pseudo-random index lands on a refunded slot.
Impact:
The computed prize and fee exceed the ETH actually collected, so the winner transfer can pull from accumulated fees / other rounds' balance, or revert and stall the draw.
If a zeroed slot is selected, the prize ETH is sent to address(0) and is irrecoverable, and the NFT mint to address(0) reverts, stalling the raffle.
The following test enters four players, refunds one, and shows the contract balance drops to 3 ETH while selectWinner() still computes the pot from the unchanged players.length of 4 — and players[0] is now address(0), so it can be selected as winner.
Account for active players and the real balance rather than the raw array length, and skip zeroed slots when selecting a winner. A cleaner refactor removes players from the array on refund (swap-and-pop) so length stays accurate:
## 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.