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

Potential DoS Attack If Invalid Address Is Inputed in enterRaffle() Function

Summary

Potential DOS attack if invalid address is inputted in enterRaffle() function.

Vulnerability Details

Lack of input validation in the enterRaffle() function could potentially lead to a Denial of Service (DoS) attack.

Impact

An attacker could potentially send an array of invalid addresses to the enterRaffle() function, causing the function to consume all the gas available and prevent other users from interacting with the contract.
This is because the function iterates over the newPlayers array and checks if each address is valid. If an invalid address is encountered, the function will throw an error and consume all the gas available.

Tools Used

Foundry, Remix, PhindAI

Recommendations

In the enterRaffle() function, the contract should check if each address in the newPlayers array is a valid Ethereum address before processing it.
This can be done by using the require statement with the condition:

newPlayers[i] != address(0);

This check ensures that the function does not proceed if any of the addresses provided are invalid.
And below I have written how it can be implemented in the enterRaffle() function:

function enterRaffle(address[] memory newPlayers) public payable {
require(msg.value == entranceFee * newPlayers.length, "PuppyRaffle: Must send enough to enter raffle");
for (uint256 i = 0; i < newPlayers.length; i++) {
require(newPlayers[i] != address(0), "PuppyRaffle: Invalid player address");
bool isDuplicate = false;
for (uint256 j = 0; j < players.length; j++) {
if (players[j] == newPlayers[i]) {
isDuplicate = true;
break;
}
}
if (!isDuplicate) {
players.push(newPlayers[i]);
} else {
emit RaffleEnter(newPlayers);
}
}
}

This will prevent unexpected behaviour and unexpected attacks.

Updates

Lead Judging Commences

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

denial-of-service-in-enter-raffle

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.

Give us feedback!