Snowman Merkle Airdrop

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

Global s_earnTimer in Snow.sol allows any user or buyer to permanently deny free Snow token minting to all other participants

Root + Impact

Description

Snow.earnSnow() allows any address to mint 1 Snow token for free, but enforces a one-week cooldown to prevent spam. The cooldown is intended to be per-user. However, the implementation uses a single shared timestamp:

// @> Single global timer — NOT per-user
uint256 private s_earnTimer;
function earnSnow() external canFarmSnow {
if (s_earnTimer != 0 && block.timestamp < (s_earnTimer + 1 weeks)) {
revert S__Timer();
}
_mint(msg.sender, 1);
// @> Overwrites the timer for EVERY user in the protocol
s_earnTimer = block.timestamp;
}
function buySnow(uint256 amount) external payable canFarmSnow {
// ... payment logic ...
// @> A purchase ALSO resets the free-earn timer for everyone
s_earnTimer = block.timestamp;
emit SnowBought(msg.sender, amount);
}

Risk

Likelihood:

  • The bug manifests every time any user calls earnSnow() or buySnow(), which is the normal operation of the contract. It is always active.

  • A deliberate griefer can maintain a script that calls earnSnow() (minting 1 token to themselves) once per week at the start of each window, perpetually locking everyone else out.

  • Organic traffic alone will cause this — if Alice earns at Monday 9am and Bob tries at Monday 11am, Bob is locked for another week even though he hasn't earned yet.

Impact:

  • The "free weekly earning" feature is functionally broken for any protocol with more than one active user.

  • Users who rely on free earning to accumulate Snow tokens for the airdrop are locked out, forcing them to pay ETH/WETH to participate.

  • A malicious actor can perform a griefing denial-of-service against all free earners at minimal cost (one earnSnow() tx per week costs only gas).

Proof of Concept

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {Test} from "forge-std/Test.sol";
import {Snow} from "../src/Snow.sol";
import {DeploySnow} from "../script/DeploySnow.s.sol";
contract GlobalTimerGriefPoC is Test {
Snow snow;
function setUp() public {
DeploySnow deployer = new DeploySnow();
snow = deployer.run();
}
function testGlobalTimerLocksAllUsers() public {
address alice = makeAddr("alice");
address bob = makeAddr("bob");
address carol = makeAddr("carol");
// Alice earns legitimately at t=0
vm.prank(alice);
snow.earnSnow();
assertEq(snow.balanceOf(alice), 1);
// Bob and Carol try to earn immediately after — both are locked
// even though THEY have never earned before
vm.prank(bob);
vm.expectRevert(Snow.S__Timer.selector);
snow.earnSnow();
vm.prank(carol);
vm.expectRevert(Snow.S__Timer.selector);
snow.earnSnow();
// One week passes, Bob earns — now Carol is locked again
vm.warp(block.timestamp + 1 weeks);
vm.prank(bob);
snow.earnSnow();
vm.prank(carol);
vm.expectRevert(Snow.S__Timer.selector); // Still locked because Bob reset it
snow.earnSnow();
}
function testBuySnowLocksAllFreeEarners() public {
address buyer = makeAddr("buyer");
address earner = makeAddr("earner");
// First earn to set the timer
vm.prank(earner);
snow.earnSnow();
// One week passes
vm.warp(block.timestamp + 1 weeks);
// A buyer purchases Snow tokens — this resets the earn timer
deal(buyer, 100 ether);
vm.prank(buyer);
snow.buySnow{value: snow.s_buyFee()}(1);
// Earner tries to earn — locked for another week because of buyer's purchase
vm.prank(earner);
vm.expectRevert(Snow.S__Timer.selector);
snow.earnSnow();
}
}

Recommended Mitigation

Replace the global s_earnTimer with a per-user mapping. Also remove the s_earnTimer write from buySnow(), since purchases should not affect the free-earn schedule:

// Before:
uint256 private s_earnTimer;
// After:
mapping(address => uint256) private s_earnTimers;
function earnSnow() external canFarmSnow {
// @> Check and update only the caller's own timer
if (s_earnTimers[msg.sender] != 0 &&
block.timestamp < s_earnTimers[msg.sender] + 1 weeks) {
revert S__Timer();
}
_mint(msg.sender, 1);
s_earnTimers[msg.sender] = block.timestamp;
emit SnowEarned(msg.sender, 1);
}
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);
}
// @> Removed s_earnTimer write — purchases should not affect free-earn cooldowns
emit SnowBought(msg.sender, amount);
}
Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge about 6 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!