Puppy Raffle

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

Gas griefing due to underflow in players.length loop in enterRaffle()

Root + Impact

Description

  • in the enterRaffle() method, there is a duplicates check for input param address[], using a loop-through the array.

  • due to solidity version 0.7.6, and the implementation of the loop, mentioned below, passing an empty array would underflow the players.length to = 2^256-1 thus forcing an infinite loop which would spend all the gas and revert the transaction.

    for (uint256 i = 0; i < players.length - 1; i++)
for (uint256 i = 0; i < players.length - 1; i++)// Root cause in the codebase with @> marks to highlight the relevant section

Risk

Likelihood:

  • As per the implementation, the enterRaffle() method has public visibility and anyone could pass the empty array, even without spending any ETH, as the method calculates the fee based on the array length. Calls to the method are not restricted by anything


Impact:

  • Calls with an empty array would lead to gas griefing, rendering a base functionality of the protocol unusable.


Proof of Concept

Recommended Mitigation

- remove this code for (uint256 i = 0; i < players.length - 1; i++)
+ add this code for (uint256 i = 0; i < players.length ; i++)
Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge 16 days 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!