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

Incorrect Equality in `PuppyRaffle::enterRaffle` Leads to Difficulty in Participation

Summary

The use of strict equalities in enterRaffle may make it challenging for players to participate in the raffle.

Vulnerability Details

When a player attempts to call enterRaffle with msg.value higher or lower than entranceFee * newPlayers.length, the protocol reverts with a "PuppyRaffle: Must send enough to enter raffle" error.

function enterRaffle(address[] memory newPlayers) public payable {
- require(msg.value == entranceFee * newPlayers.length, "PuppyRaffle: Must send enough to enter raffle");
// ...
}

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 "testCantEnterWithMoreThanEntranceFee"

Code

function testCantEnterWithMoreThanEntranceFee() public {
address[] memory players = new address[](1);
players[0] = playerOne;
vm.expectRevert("PuppyRaffle: Must send enough to enter raffle");
puppyRaffle.enterRaffle{value: entranceFee + 10}(players);
}

Note that the test passes even though the caller sends more than enough to enter the raffle.

Impact

Creates a Poor User Experience: The current strict equality check can frustrate potential players, leading to a poor user experience. PuppyRaffle may miss out on potential revenue as frustrated players give up on participating.

Tools Used

  • Foundry

Recommendations

Change the strict equality == to a more flexible option >=. The modified function should look like this:

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
Validated
Assigned finding tags:

greifers-send-money-to-contract-to-block-withdrawfees

Support

FAQs

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

Give us feedback!