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

enterRaffle function vulnerable to DoS

Summary

The function enterRaffle checks for duplicates by looping through the players storage variable. This will require more gas as the array grows and potentially exceeding block gas limit.

Vulnerability Details

enterRaffle function vulnerable to DoS attack by increasing the players storage variable size

Impact

No new players can enter the raffle until a winner is selected and the players storage variable cleared.

Tools Used

  • Foundry

  • Slither

Recommendations

  • Add a mapping storage variable that maps a player's address to it's active status.

uint256 public immutable entranceFee;
address[] public players;
+ // mapping to check if player is part of the current raffle
+ mapping(address => bool) playerToIsActive;
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++) {
+ address newPlayer = newPlayers[i];
+ // Check for duplicates
+ require(!playerToIsActive[newPlayer], "PuppyRaffle: Duplicate player");
players.push(newPlayer);
+ playerToIsActive[newPlayer] = true;
}
- // Check for duplicates
- for (uint256 i = 0; i < players.length - 1; i++) {
- for (uint256 j = i + 1; j < players.length; j++) {
- require(players[i] != players[j], "PuppyRaffle: Duplicate player");
- }
- }
emit RaffleEnter(newPlayers);
}

Note: Additional logic is required to reset player active status when a winner is selected.

Updates

Lead Judging Commences

Hamiltonite Lead Judge over 1 year 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.