Puppy Raffle

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

Use of require With Revert String Is More Gas-Expensive Than Custom Errors

Root + Impact

Description

  • The function uses a require statement with a revert string to validate the ETH value sent:

// Root cause in the codebase with @> marks to highlight the relevant section
require(
msg.value == entranceFee * newPlayers.length,
"PuppyRaffle: Must send enough to enter raffle"
);

Risk

Likelihood:

  • Higher gas consumption
    Revert strings increase bytecode size and consume more gas during execution compared to custom errors.

Reduced efficiency at scale
In functions that may be called frequently or by many users, this pattern results in unnecessary cumulative gas overhead.

Impact:

  • Reason 1
    This code path is executed every time users attempt to enter the raffle, making the gas inefficiency consistently observable.

Reason 2
The pattern is present in production logic rather than tests or scripts, meaning it directly affects end users.

Proof of Concept

Compared to a custom error, this approach embeds the revert string in the contract bytecode, increasing gas costs.

// Current implementation
require(
msg.value == entranceFee * newPlayers.length,
"PuppyRaffle: Must send enough to enter raffle"
);

Recommended Mitigation

This approach significantly reduces deployment size and runtime gas costs while preserving clear error semantics.

- remove this code
require(
msg.value == entranceFee * newPlayers.length,
"PuppyRaffle: Must send enough to enter raffle"
);
+ add this code
error PuppyRaffle__InvalidEntranceFee();
if (msg.value != entranceFee * newPlayers.length) {
revert PuppyRaffle__InvalidEntranceFee();
}
Updates

Lead Judging Commences

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