Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: low
Invalid

Lack of Input Validation in `enterRaffle`

Summary

The enterRaffle function does not perform thorough input validation. It only checks if the value sent matches the entrance fee. This could potentially allow attackers to abuse the function.

Vulnerability Details

Here is the existing 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++) {
players.push(newPlayers[i]);
}
// 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);
}

The function currently checks whether the total value sent is equal to the entrance fee multiplied by the number of new players. While this guards against incorrect payments, it lacks input validation for the addresses in the newPlayers array. An attacker could potentially abuse the function by sending arbitrary or malicious addresses.

Impact

Failure to perform proper input validation may lead to unexpected and undesired behavior within the contract. This could enable attackers to manipulate the function and potentially harm the integrity of the raffle.

Tools Used

Manual

Recommendations

To improve the input validation it would be a good step if:

  1. Validating that the addresses in the newPlayers array are not empty addresses.

  2. Ensuring that the addresses in the newPlayers array are unique, preventing duplicate entries.

To mitigate this issue, it is recommended to add input validation to the enterRaffle function. Here's an updated version of the function that includes these checks:

function enterRaffle(address[] memory newPlayers) public payable {
require(msg.value == entranceFee * newPlayers.length, "PuppyRaffle: Must send enough to enter raffle");
// Validate input addresses
for (uint256 i = 0; i < newPlayers.length; i++) {
require(newPlayers[i] != address(0), "PuppyRaffle: Invalid player address");
require(_isActivePlayer(newPlayers[i]) == false, "PuppyRaffle: Duplicate player");
}
for (uint256 i = 0; i < newPlayers.length; i++) {
players.push(newPlayers[i]);
}
emit RaffleEnter(newPlayers);
}

function first validates that the addresses in the newPlayers array are not empty (address(0)) and then checks if the addresses are not already in the players array to prevent duplicates. This improved input validation helps ensure the correctness and security of the enterRaffle function.

Updates

Lead Judging Commences

Hamiltonite Lead Judge almost 2 years ago
Submission Judgement Published
Invalidated
Reason: User input validation

Support

FAQs

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