Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: high
Valid

enterRaffle() function does not check for zero addresses which will lead to miss calculations

Summary

In PuppyRaffle.sol:: enterRaffle() there is no check for zero addresses input, that can cause the protocol to fail or miss-function.

Vulnerability Details

PuppyRaffle.sol:: enterRaffle() function is responsible for entering new players into the raffle. It's expected to have a check that there is no "0" address among those new addresses for the game to be correct and fair, yet, there is not.

Impact

First issue with having zero address as an input is that the contract is checking for the entrance fees

msg.value == entranceFee * newPlayers.length

if a zero address was submitted by mistake then this equality will always be false and the function will revert.

Second issue:Assuming there was enough value for fees and the array registered, there is a problem that the totalAmount and prizePool are calculated according to the array length which now includes empty slots mis-leading the calculations and may cause the protocol to fail if there is no balance to cover the prize.

uint256 totalAmountCollected = players.length * entranceFee;
uint256 prizePool = (totalAmountCollected * 80) / 100;
uint256 fee = (totalAmountCollected * 20) / 100;

Tools Used

Manual review

Recommendations

Add this check to enterraffle()

- for (uint256 i = 0; i < newPlayers.length; i++) {
players.push(newPlayers[i]);
}
+ for (uint256 i = 0; i < newPlayers.length; i++) {
if(newPlayers[I]!= address(0)
players.push(newPlayers[i]);
}
Updates

Lead Judging Commences

Hamiltonite Lead Judge almost 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

zero address can win the raffle

Funds are locked to no one. If someone gets the refund issue, they also got this issue. IMPACT: High Likelihood: High

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.