* The `selectWinner()` function checks `players.length >= 4` to ensure there are enough players, but doesn't verify that there are actually 4 active (non-zero) players.
* When players refund, their slots are set to `address(0)` but remain in the array. The length check passes even if all players have refunded, leading to selection of `address(0)` as the winner.
```solidity:125:130:src/PuppyRaffle.sol
function selectWinner() external {
require(block.timestamp >= raffleStartTime + raffleDuration, "PuppyRaffle: Raffle not over");
require(players.length >= 4, "PuppyRaffle: Need at least 4 players");
uint256 winnerIndex =
uint256(keccak256(abi.encodePacked(msg.sender, block.timestamp, block.difficulty))) % players.length;
address winner = players[winnerIndex];
```
Likelihood:
* This occurs whenever players have refunded before `selectWinner()` is called
* Refunds are allowed until the raffle ends, making this scenario common
* The check `players.length >= 4` passes even when all entries are `address(0)`
Impact:
* Winner can be `address(0)`, causing prize pool to be burned
* NFT minted to `address(0)` is effectively burned
* The check is misleading - it says "need 4 players" but might only have refunded slots
* Funds are permanently lost
## 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.