The enterRaffle function iterates through an array of new players but fails to implement a sanity check to ensure the addresses are valid.
A user or a flawed frontend could accidentally pass address(0) into the players array.
If address(0) is drawn as the winner during selectWinner, the contract will attempt to send the 80% Ether prize pool and mint the NFT to the zero address.
This permanently burns the NFT and traps the Ether, making it unrecoverable for the protocol and the users.
1. Arrange The test simulates a user (spider) preparing a batch of participants to enter the raffle. An array of 6 addresses is constructed in memory. The first 5 slots are filled with legitimate user addresses (spider, alice, bob, dan, eli), but the final slot at index 5 is explicitly set to the zero address (address(0)).
2. Act The user calls the enterRaffle function and funds the transaction with 6 Ether (1 Ether per player) to cover the entrance fees. After the transaction executes, the test checks the actual Ether balance of the PuppyRaffle contract to see if it processed the entries.
3. Assert The test successfully asserts that the contract's balance is exactly 6 Ether. This mathematically proves that the enterRaffle function did not revert when it encountered address(0). Instead, it blindly accepted the zero address as a valid player, took the entrance fee, and stored address(0) in the active players state array.
To prevent the zero address from entering the raffle, you must implement a strict input validation check inside the enterRaffle function. By adding a require statement within the loop that processes newPlayers, the contract will immediately revert any transaction attempting to register address(0). This ensures that no NFTs or prize funds can ever be permanently burned or trapped.
Update the enterRaffle function to include the zero-address check right before pushing the new player to the state array:
## 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.