Snowman Merkle Airdrop

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

Gas Optimization Issue + Increased Transaction Costs

Root + Impact

Description

  • The i_weth variable in Snow.sol is declared as a regular state variable despite following the i_ naming convention for immutable variables and being set only in the constructor.

  • The i_weth variable should be declared as immutable since it's only set once in the constructor and never modified, allowing the compiler to optimize gas usage by embedding the value directly in the bytecode.


// Root cause in the codebase with @> marks to highlight the relevant section
// @> Should be immutable for gas optimization
IERC20 i_weth;
constructor(address _weth, uint256 _buyFee, address _collector) ERC20("Snow", "S") Ownable(msg.sender) {
// ... validation code ...
i_weth = IERC20(_weth); // Only set once
// ... rest of constructor ...
}

Risk

Likelihood:

  • Occurs on every function call that accesses the i_weth variable

  • Affects buySnow() and collectFee() functions which are core protocol operations

Impact:

  • Increased gas costs for users calling buySnow() (extra SLOAD operation ~2100 gas)

  • Increased gas costs for collector calling collectFee()

  • Unnecessary storage slot usage increasing deployment costs

Proof of Concept

This shows the implementation costing more gas:

// Current implementation costs more gas
function buySnow(uint256 amount) external payable canFarmSnow {
if (msg.value == (s_buyFee * amount)) {
_mint(msg.sender, amount);
} else {
i_weth.safeTransferFrom(msg.sender, address(this), (s_buyFee * amount)); // SLOAD ~2100 gas
_mint(msg.sender, amount);
}
// ... rest of function
}

Recommended Mitigation

declare it immutable, this would help optimize gas and save money

- remove this code
+ add this code
- IERC20 i_weth;
+ IERC20 immutable i_weth;
Updates

Lead Judging Commences

yeahchibyke Lead Judge 5 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.