Snowman Merkle Airdrop

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

A single global `s_earnTimer` blocks weekly Snow farming for all users, and `buySnow(0)` lets an attacker reset it for free

Root + Impact

Description

  • The protocol documents that Snow "can be earned for free once a week", meaning one free mint per user per week.

  • s_earnTimer is a single contract-wide slot, and both earnSnow and buySnow overwrite it with block.timestamp, so whoever acts first locks the cooldown for everybody. Total free mints are capped at roughly 12 across the whole 12-week farming period rather than 12 per user.

  • buySnow(0) costs nothing: with msg.value == 0 the check msg.value == s_buyFee * amount is 0 == 0, so it takes the ETH branch, mints zero tokens, and still resets the shared timer.

uint256 private s_earnTimer; //@> one global slot shared by every user
function buySnow(uint256 amount) external payable canFarmSnow {
if (msg.value == (s_buyFee * amount)) { //@> amount = 0 makes this 0 == 0, a free call
_mint(msg.sender, amount);
} else { ... }
s_earnTimer = block.timestamp; //@> a purchase resets everyone's earn cooldown
}
function earnSnow() external canFarmSnow {
if (s_earnTimer != 0 && block.timestamp < (s_earnTimer + 1 weeks)) {
revert S__Timer(); //@> reverts for users who have never earned
}
_mint(msg.sender, 1);
s_earnTimer = block.timestamp;
}

Risk

Likelihood:

  • No attacker is needed for the base case: any honest user who earns or buys Snow blocks every other user for 7 days, so the protocol sits in this state almost all the time.

  • Deliberate griefing costs only gas. An attacker calls buySnow(0) shortly before each weekly window closes and keeps free farming shut for the entire 12-week period.

Impact:

  • Free weekly farming, an advertised core feature, is unusable for essentially all users: instead of one mint per user per week, the contract allows about 12 free mints in total across all users.

  • Users shut out of free farming must buy Snow at s_buyFee per unit, so a griefer turns a free feature into a paid one and can deny eligibility to users who need Snow to claim.

Proof of Concept

Save as test/Sub5.t.sol and run forge test --match-path test/Sub5.t.sol -vv. The first test shows an honest earn locking out a user who never earned; the second shows the free buySnow(0) reset.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {Test} from "forge-std/Test.sol";
import {Snow} from "../src/Snow.sol";
import {Snowman} from "../src/Snowman.sol";
import {SnowmanAirdrop} from "../src/SnowmanAirdrop.sol";
import {MockWETH} from "../src/mock/MockWETH.sol";
import {Helper} from "../script/Helper.s.sol";
contract Sub5GlobalTimer is Test {
Snow snow;
Snowman nft;
SnowmanAirdrop airdrop;
MockWETH weth;
address alice = makeAddr("alice");
address bob = makeAddr("bob");
address attacker = makeAddr("attacker");
function setUp() public {
Helper helper = new Helper();
(airdrop, snow, nft, weth) = helper.run();
}
function test_OneUsersEarnBlocksEveryoneElse() public {
vm.warp(block.timestamp + 1 weeks); // cooldown expired
vm.prank(alice);
snow.earnSnow(); // alice earns her weekly Snow
// Bob has never earned this week, yet he is locked out.
vm.prank(bob);
vm.expectRevert(Snow.S__Timer.selector);
snow.earnSnow();
}
function test_ZeroAmountBuyResetsTimerForFree() public {
vm.warp(block.timestamp + 1 weeks); // cooldown expired, bob may earn
uint256 balBefore = attacker.balance;
vm.prank(attacker);
snow.buySnow(0); // 0 == s_buyFee * 0 -> free, mints nothing
assertEq(snow.balanceOf(attacker), 0);
assertEq(attacker.balance, balBefore); // attacker paid nothing but gas
// Every other user is locked out for another week.
vm.prank(bob);
vm.expectRevert(Snow.S__Timer.selector);
snow.earnSnow();
}
}

Output:

Ran 2 tests for test/Sub5.t.sol:Sub5GlobalTimer
[PASS] test_OneUsersEarnBlocksEveryoneElse() (gas: 42297)
[PASS] test_ZeroAmountBuyResetsTimerForFree() (gas: 46967)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 8.60ms (253.69µs CPU time)

Recommended Mitigation

Track the cooldown per user, stop buySnow from touching it, and reject zero-amount purchases.

- uint256 private s_earnTimer;
+ mapping(address => uint256) private s_earnTimer;
function buySnow(uint256 amount) external payable canFarmSnow {
+ if (amount == 0) revert S__ZeroValue();
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);
}
function earnSnow() external canFarmSnow {
- if (s_earnTimer != 0 && block.timestamp < (s_earnTimer + 1 weeks)) {
+ if (s_earnTimer[msg.sender] != 0 && block.timestamp < (s_earnTimer[msg.sender] + 1 weeks)) {
revert S__Timer();
}
_mint(msg.sender, 1);
- s_earnTimer = block.timestamp;
+ s_earnTimer[msg.sender] = block.timestamp;
}
Updates

Lead Judging Commences

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