When players refund, their address in the players array is set to address(0). The selectWinner() function does not validate that the selected winner is not address(0), which causes the transaction to revert when attempting to send ETH to the zero address, permanently locking the raffle.
Describe the normal behavior in one or more sentences:
A legitimate active player should be selected as the winner when selectWinner() is called
The winner should receive the prize pool (80% of total funds) and be minted an NFT
Explain the specific issue or problem in one or more sentences:
The refund() function sets players[playerIndex] = address(0) when a player refunds
The selectWinner() function randomly selects an index from the players array without checking if that address is address(0)
If address(0) is selected, the call to send ETH fails, causing the entire transaction to revert and permanently locking the raffle
Likelihood:
Reason 1: Occurs whenever a refunded player's slot is randomly selected
Reason 2: Probability increases with each refund (if 1 out of 4 players refunds, there is a 25% chance)
Impact:
Impact 1: Raffle becomes permanently locked, preventing winner selection and trapping all funds
Impact 2: All participants lose their entrance fees as funds cannot be recovered without contract upgrade
Place the following test in test/AuditTest.t.sol:
Run with: forge test --mt testSelectWinnerAddress0 -vv
Add validation to ensure the winner is not address(0):
## 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.