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

Nested loop checks can lead to a Denial of Service attack

Summary

The nested loop checking for duplicate players in the PuppyRaffle::enterRaffle function can potentially lead to a Denial of Service attack

Vulnerability Details

If the players array becomes too large, the gas required to execute this function could exceed the block gas limit

Impact

This limitation can prevent legitimate users from participating in the raffle

Tools Used

Foundry

Recommendations

Instead of checking arrays in a nested loop, we should use a mapping to check for duplicates when entering the raffle.

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++) {
if(!playerParticipating[newPlayers[i]]){
players.push(newPlayers[i]);
playerParticipating[newPlayers[i]] = true;
}else{
revert("PuppyRaffle: Duplicate player");
}
}
emit RaffleEnter(newPlayers);
}
Updates

Lead Judging Commences

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

denial-of-service-in-enter-raffle

Support

FAQs

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

Give us feedback!