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

Empty Array Input in `PuppyRaffle::enterRaffle` Leads to a Denial of Service

Summary

The absence of sufficient input validation in the enterRaffle function allows it to receive an empty array, resulting in a denial of service when the function is invoked with an empty array.

Vulnerability Details

When the enterRaffle function is called with an empty array, it encounters an underflow issue when calculating players.length - 1 within the for loop that checks for duplicate entries. This can lead to running out of gas while checking for duplicates.

function enterRaffle(address[] memory newPlayers) public payable {
- // No empty array check
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);
}

Proof of Concept

The provided test demonstrates the validity and severity of this vulnerability.

How to Run the Test

Requirements:

  • Install Foundry.

  • Clone the project codebase into your local workspace.

Step-by-step Guide to Run the Test:

  1. Ensure the above requirements are met.

  2. Copy the test below and add it to PuppyRaffleTest.t.sol tests.

  3. Execute the following command in your terminal to run the test:

forge test --match-test "testDoSVulnerability"

Code

function testDoSVulnerability() public {
address[] memory players;
vm.expectRevert("PuppyRaffle: Must send enough to enter raffle");
puppyRaffle.enterRaffle(players);
}

Note that the test freezes.

Impact

Functionality Disruption: An empty array input to the enterRaffle function can lead to a denial of service, partially disabling the protocol.

Tools Used

  • Foundry

Recommendations

Add a require statement to check for empty array inputs and revert if an empty array is provided. The modified function should look like this:
Also use the latest solidity version.

function enterRaffle(address[] memory newPlayers) public payable {
+ require(newPlayers.length > 0, "Empty arrays not allowed!")
require(msg.value == entranceFee * newPlayers.length, "PuppyRaffle: Must send enough to enter raffle");
// ...
}
Updates

Lead Judging Commences

Hamiltonite Lead Judge about 2 years ago
Submission Judgement Published
Invalidated
Reason: Other

Support

FAQs

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

Give us feedback!