Snowman Merkle Airdrop

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

Magic Number Usage Reduces Code Readability and Maintainability in Snow.sol::earnSnow

Root + Impact

Root: The earnSnow function uses a hardcoded magic number 1 when minting Snow tokens (_mint(msg.sender, 1)), without defining it as a named constant to clarify its purpose and allow for easy modification.

Impact: Code becomes less maintainable and harder to understand, making future updates or modifications to the earning reward amount more error-prone and requiring changes in multiple locations if the reward structure needs adjustment.

Description

  • Normal Behavior: Constants representing business logic values should be defined as named variables to improve code readability and maintainability.

  • Specific Issue: The hardcoded value 1 in the mint operation lacks context about why this specific amount is chosen and makes it difficult to modify the reward structure without hunting through the codebase for all instances.

Risk

Likelihood: Medium

  • Magic numbers impact every development cycle when code needs to be reviewed, modified, or audited

  • Future protocol updates or reward adjustments will require developers to identify and change hardcoded values

Impact: Low

  • Reduced Maintainability: Future changes to earning rewards require manual code inspection rather than simple constant updates

  • Poor Code Clarity: Developers and auditors must infer the meaning of hardcoded values without explicit documentation

Recommended Mitigation

Replace the magic number with a named constant to improve code readability and maintainability.

// Add constant at the top of contract with other constants
+ uint256 constant WEEKLY_EARN_AMOUNT = 1;
function earnSnow() external canFarmSnow {
if (s_earnTimer != 0 && block.timestamp < (s_earnTimer + 1 weeks)) {
revert S__Timer();
}
- _mint(msg.sender, 1);
+ _mint(msg.sender, WEEKLY_EARN_AMOUNT);
s_earnTimer = block.timestamp;
}
Updates

Lead Judging Commences

yeahchibyke Lead Judge 5 months ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

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