Puppy Raffle

AI First Flight #1
Beginner FriendlyFoundrySolidityNFT
EXP
View results
Submission Details
Impact: low
Likelihood: low
Invalid

Prize Calculation Skewed by Inactive (Refunded) Players

Root + Impact

Description

Normal behavior:
When a winner is selected, the prize amount should be derived solely from funds contributed by currently active, non-refunded players.

The players array is used as the canonical source of participant data, and its size is implicitly treated as the number of tickets sold.

Issue:
When a player calls refund(), their slot in the players array is set to address(0) but the array length is never reduced.

Later, selectWinner() calculates the prize using:

uint256 totalAmountCollected = players.length * entranceFee;

This calculation counts refunded (inactive) players, even though their ETH has already been returned.

As a result, the prize amount no longer reflects the real economic state of the raffle.

// @> players.length includes refunded players (address(0))
uint256 totalAmountCollected = players.length * entranceFee;

Risk

Likelihood:

  • Reason 1: Refunds are part of normal protocol usage.

  • Reason 2: Refunded players are never removed from the players array.

Impact:

  • Impact 1: Prize calculation becomes economically inaccurate.

  • Impact 2: Raffle outcomes deviate from intended fairness.

⚠️ No direct fund theft occurs, which is why this is LOW severity.

Proof of Concept

Scenario:

3 players enter the raffle
2 players call refund()
players.length == 3
Only 1 player actually paid

Result:

totalAmountCollected = 3 * entranceFee; // incorrect
actual ETH available = 1 * entranceFee;

Prize math is skewed, but execution does not revert.

Recommended Mitigation

Track the number of active players explicitly, or remove refunded players from the array.

- uint256 totalAmountCollected = players.length * entranceFee;
+ uint256 totalAmountCollected = activePlayerCount * entranceFee;

Or remove players using swap-and-pop on refund.

Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge 1 day ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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

Give us feedback!