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

Use custom errors rather than `revert()`/`require()` strings to save deployment gas

Summary

The require are very helpful and easy to understand, but the problem with require statements is that they store a string as an error message. And strings are not much gas optimized.

Solidity v0.8.4 introduces custom errors, a gas-efficient way to explain operation failures. Unlike costly string messages, custom errors are defined using the error statement and can be used in contracts, interfaces, and libraries.

Vulnerability Details

require(msg.value == entranceFee * newPlayers.length, "PuppyRaffle: Must send enough to enter raffle");
https://github.com/Cyfrin/2023-10-Puppy-Raffle/blob/07399f4d02520a2abf6f462c024842e495ca82e4/src/PuppyRaffle.sol#L80
...
require(playerAddress == msg.sender, "PuppyRaffle: Only the player can refund");
require(playerAddress != address(0), "PuppyRaffle: Player already refunded, or is not active");
https://github.com/Cyfrin/2023-10-Puppy-Raffle/blob/07399f4d02520a2abf6f462c024842e495ca82e4/src/PuppyRaffle.sol#L98C1-L99C104

Impact

Inefficient Gas Usage

Tools Used

Manual Review

Recommendations

To make the contract gas optimized we use custom errors within if-else statements or use assembly

Updates

Lead Judging Commences

Hamiltonite Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Other

Support

FAQs

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