Snowman Merkle Airdrop

AI First Flight #10
Beginner FriendlyFoundrySolidityNFT
EXP
View results
Submission Details
Severity: low
Valid

s_earnTimer is global state — any user's earn/buy action blocks all other users from earning for one week

Root + Impact

Description

  • The earnSnow function enforces a one-week cooldown using s_earnTimer, but this variable is a single uint256 shared across all users. Both earnSnow() and buySnow() update this timer. When any user earns or buys Snow, the cooldown resets for everyone, preventing all other users from calling earnSnow() for another week.

// Root cause in Snow.sol lines 92-99 and line 87
uint256 private s_earnTimer; // @> Single global variable, not per-user
function earnSnow() external canFarmSnow {
if (s_earnTimer != 0 && block.timestamp < (s_earnTimer + 1 weeks)) {
revert S__Timer(); // @> Reverts based on GLOBAL timer, not per-user
}
_mint(msg.sender, 1);
s_earnTimer = block.timestamp; // @> Resets timer for ALL users
}
function buySnow(uint256 amount) external payable canFarmSnow {
// ...
s_earnTimer = block.timestamp; // @> buySnow ALSO resets the global timer
}

Risk

Likelihood:

  • This occurs every time any user calls earnSnow() or buySnow() — standard protocol usage triggers this for all other users.

  • A malicious actor can intentionally DoS earnSnow() by calling buySnow(1) repeatedly, resetting the global timer for the cost of one Snow token purchase.

Impact:

  • Most users will never be able to call earnSnow() because the global timer is perpetually reset by other users' activity.

  • The "earn for free once a week" mechanism is effectively broken for any protocol with more than one active user.

Proof of Concept

This test shows that after Alice successfully calls earnSnow(), Bob is immediately blocked from earning despite never having earned before. Alice's call updated s_earnTimer to block.timestamp, and Bob's call checks the same global s_earnTimer, causing it to revert with S__Timer(). In a per-user design, Bob's call would succeed since he has his own independent cooldown.

function testM01_GlobalTimerBlocksAllUsers() public {
// Alice earns Snow — succeeds
vm.prank(alice);
snow.earnSnow();
// Bob tries to earn Snow immediately after — REVERTS
// Bob has never earned before, but Alice's earn reset the global timer
vm.prank(bob);
vm.expectRevert();
snow.earnSnow(); // Fails because Alice's action reset the global s_earnTimer
}

Recommended Mitigation

Replace the single s_earnTimer variable with a mapping(address => uint256) so each user tracks their own independent cooldown. Also remove the s_earnTimer update from buySnow(), since purchasing tokens should not affect the weekly free-earn cooldown — these are separate mechanisms.

- uint256 private s_earnTimer;
+ mapping(address => uint256) private s_earnTimers;
function earnSnow() external canFarmSnow {
- if (s_earnTimer != 0 && block.timestamp < (s_earnTimer + 1 weeks)) {
+ if (s_earnTimers[msg.sender] != 0 && block.timestamp < (s_earnTimers[msg.sender] + 1 weeks)) {
revert S__Timer();
}
_mint(msg.sender, 1);
- s_earnTimer = block.timestamp;
+ s_earnTimers[msg.sender] = block.timestamp;
}
function buySnow(uint256 amount) external payable canFarmSnow {
// ... minting logic ...
- s_earnTimer = block.timestamp;
+ // Remove: buying should not affect earn cooldowns
}
Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge about 4 hours ago
Submission Judgement Published
Validated
Assigned finding tags:

[L-02] Global Timer Reset in Snow::buySnow Denies Free Claims for All Users

## Description: The `Snow::buySnow` function contains a critical flaw where it resets a global timer `(s_earnTimer)` to the current block timestamp on every invocation. This timer controls eligibility for free token claims via `Snow::earnSnow()`, which requires 1 week to pass since the last timer reset. As a result: Any token purchase `(via buySnow)` blocks all free claims for all users for 7 days Malicious actors can permanently suppress free claims with micro-transactions Contradicts protocol documentation promising **"free weekly claims per user"** ## Impact: * **Complete Denial-of-Service:** Free claim mechanism becomes unusable * **Broken Protocol Incentives:** Undermines core user acquisition strategy * **Economic Damage:** Eliminates promised free distribution channel * **Reputation Harm:** Users perceive protocol as dishonest ```solidity 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)); _mint(msg.sender, amount); } @> s_earnTimer = block.timestamp; emit SnowBought(msg.sender, amount); } ``` ## Risk **Likelihood**: • Triggered by normal protocol usage (any purchase) • Requires only one transaction every 7 days to maintain blockage • Incentivized attack (low-cost disruption) **Impact**: • Permanent suppression of core protocol feature • Loss of user trust and adoption • Violates documented tokenomics ## Proof of Concept **Attack Scenario:** Permanent Free Claim Suppression * Attacker calls **buySnow(1)** with minimum payment * **s\_earnTimer** sets to current timestamp (T0) * All **earnSnow()** calls revert for **next 7 days** * On day 6, attacker repeats **buySnow(1)** * New timer reset (T1 = T0+6 days) * Free claims blocked until **T1+7 days (total 13 days)** * Repeat step **4 every 6 days → permanent blockage** **Test Case:** ```solidity // Day 0: Deploy contract snow = new Snow(...); // s_earnTimer = 0 // UserA claims successfully snow.earnSnow(); // Success (first claim always allowed) // Day 1: UserB buys 1 token snow.buySnow(1); // Resets global timer to day 1 // Day 2: UserA attempts claim snow.earnSnow(); // Reverts! Requires day 1+7 = day 8 // Day 7: UserC buys 1 token (day 7 < day 1+7) snow.buySnow(1); // Resets timer to day 7 // Day 8: UserA retries snow.earnSnow(); // Still reverts! Now requires day 7+7 = day 14 ``` ## Recommended Mitigation **Step 1:** Remove Global Timer Reset from `buySnow` ```diff function buySnow(uint256 amount) external payable canFarmSnow { // ... existing payment logic ... - s_earnTimer = block.timestamp; emit SnowBought(msg.sender, amount); } ``` **Step 2:** Implement Per-User Timer in `earnSnow` ```solidity // Add new state variable mapping(address => uint256) private s_lastClaimTime; function earnSnow() external canFarmSnow { // Check per-user timer instead of global if (s_lastClaimTime[msg.sender] != 0 && block.timestamp < s_lastClaimTime[msg.sender] + 1 weeks ) { revert S__Timer(); } _mint(msg.sender, 1); s_lastClaimTime[msg.sender] = block.timestamp; // Update user-specific timer emit SnowEarned(msg.sender, 1); // Add missing event } ``` **Step 3:** Initialize First Claim (Constructor) ```solidity constructor(...) { // Initialize with current timestamp to prevent immediate claims s_lastClaimTime[address(0)] = block.timestamp; } ```

Support

FAQs

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

Give us feedback!