Bid Beasts

First Flight #49
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Impact: low
Likelihood: medium
Invalid

Use of Constant Instead of Immutable Increases Deployment Gas Costs in BidBeastsNFTMarket

Use of Constant Instead of Immutable Increases Deployment Gas Costs in BidBeastsNFTMarket

Description

  • Normally, values that are known only at deployment but remain unchanged afterward should be declared as immutable. This stores them directly in contract storage at deployment time, reducing runtime gas consumption when accessed.

  • In the current implementation of BidBeastsNFTMarket, several parameters are declared as constant instead of immutable. While both prevent reassignment, using constant here results in less optimal gas usage because the compiler embeds the value in multiple places rather than storing it once.

uint256 constant public S_MIN_NFT_PRICE = 0.01 ether; // @> should be immutable
uint256 constant public S_FEE_PERCENTAGE = 5; // @> should be immutable
uint256 constant public S_MIN_BID_INCREMENT_PERCENTAGE = 5; // @> should be immutable

Risk

Likelihood:

  • Every time these constants are referenced, the compiler expands the literal into bytecode instead of a single storage slot reference.

  • As contract size and references grow, deployment costs increase unnecessarily.

Impact:

  • Higher deployment gas cost due to repeated inlining.

  • Increased bytecode size, potentially raising deployment overhead further.

Proof of Concept

// Gas profiling example (simplified):
// Accessing an immutable variable compiles into a single storage read,
// while a constant literal is embedded in multiple call sites.

Recommended Mitigation

Immutable variables must be assigned either at their declaration or inside the constructor. Below is a minimal, practical change: declare the variables as immutable (no inline assignment) and set them in the contract constructor.

- uint256 constant public S_MIN_NFT_PRICE = 0.01 ether;
- uint256 constant public S_FEE_PERCENTAGE = 5;
- uint256 constant public S_MIN_BID_INCREMENT_PERCENTAGE = 5;
+ uint256 public immutable S_MIN_NFT_PRICE;
+ uint256 public immutable S_FEE_PERCENTAGE;
+ uint256 public immutable S_MIN_BID_INCREMENT_PERCENTAGE;
constructor(address _BidBeastsNFT) {
- BBERC721 = BidBeasts(_BidBeastsNFT);
+ BBERC721 = BidBeasts(_BidBeastsNFT);
+ // set deployment-time constants as immutables here
+ S_MIN_NFT_PRICE = 0.01 ether;
+ S_FEE_PERCENTAGE = 5;
+ S_MIN_BID_INCREMENT_PERCENTAGE = 5;
}
Updates

Lead Judging Commences

cryptoghost Lead Judge 2 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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

Give us feedback!