Eggstravaganza

First Flight #37
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: low
Invalid

Use Custom Erorrs Instead of require() for Gas Optimization

Summary

The contract currently uses require() statements with string error messages to validate conditions such as access control. While this approach consumes more gas due to string storage and does not leverage solidity's more efficient custom error mechanism

Vulnerability Details

In the mintEgg() function, the contract uses:

require(msg.sender == gameContract, "Unauthorized minter");

This is can be replaced with more gas-efficient method using custom errors:

error EggstravaganzaNFT__UnauthorizedMinter();
function mintEgg(address to, uint256 tokenId) external returns (bool) {
//require(msg.sender == gameContract, "Unauthorized minter");
if(msg.sender != gameContract){
revert EggstravaganzaNFT__UnauthorizedMinter();
}
_mint(to, tokenId);
totalSupply += 1;
return true;
}

Impact

  • Gas Optimization

  • Improved Clarity

  • Best Practice Alignment

Tools Used

  • Manual code review

  • Solidity recommendation on custom errors

Recommendations

Replace all require('condtion', 'error messages') pattern with if(!condition) {revert CustomError()}

Updates

Lead Judging Commences

m3dython Lead Judge 3 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Gas optimization

Strategy to save gas and minimize transaction costs

Support

FAQs

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