Snowman Merkle Airdrop

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

[M-03] Global farming cooldown: one user blocks `earnSnow` for everyone else indefinitely

Root + Impact

Description

  • Each user should be able to earn 1 SNOW for free once per week; the weekly cooldown is meant to be per account.

  • s_earnTimer is a single global storage variable rather than a per-user mapping, and buySnow() also writes it. So whoever farms (or buys) first pushes the one-week cooldown onto everybody, and an attacker can keep resetting it forever.

@> uint256 private s_earnTimer; // global, not a per-user mapping
function earnSnow() external canFarmSnow {
@> if (s_earnTimer != 0 && block.timestamp < (s_earnTimer + 1 weeks)) revert S__Timer();
_mint(msg.sender, 1);
@> s_earnTimer = block.timestamp; // moves the timer for EVERYONE
}
function buySnow(uint256 amount) external payable canFarmSnow {
@> ... s_earnTimer = block.timestamp; // buying also resets it
}

Risk

Likelihood:

  • Any account calls earnSnow or buySnow and the global timer blocks all others for a week.

  • An attacker buys 1 SNOW as each weekly window opens and keeps earnSnow frozen for the whole 12-week farming period, for cents.

Impact:

  • The free way to obtain SNOW - and therefore airdrop eligibility for anyone unwilling to pay - is unusable.

  • Farming degenerates into a gas race that favors bots.

Proof of Concept

The test shows Bob and Carol - who never farmed - receive S__Timer immediately after Alice farms once, and that an attacker buying 1 SNOW as each weekly window opens keeps Alice from ever farming across four consecutive weeks.

Verified with Foundry (test_elCooldownEsGlobalYBloqueaAlRestoDeUsuarios, test_unAtacantePuedeCongelarElFarmingIndefinidamente), forge test passing:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {Test, console2} from "forge-std/Test.sol";
import {Snow} from "../src/Snow.sol";
import {DeploySnow} from "../script/DeploySnow.s.sol";
import {MockWETH} from "../src/mock/MockWETH.sol";
contract SnowFarmingYPagoTest is Test {
Snow snow;
DeploySnow deployer;
MockWETH weth;
uint256 FEE;
address alice = makeAddr("alice");
address bob = makeAddr("bob");
address carol = makeAddr("carol");
address atacante = makeAddr("atacante");
function setUp() public {
deployer = new DeploySnow();
snow = deployer.run();
weth = deployer.weth();
FEE = deployer.FEE();
}
/// [M] `s_earnTimer` es UNA variable global, no un cooldown por usuario: en cuanto alguien
/// usa `earnSnow()`, TODOS los demas quedan bloqueados una semana aunque no hayan farmeado
/// nunca. El farming pasa a ser una carrera de uno contra todos.
function test_elCooldownEsGlobalYBloqueaAlRestoDeUsuarios() public {
vm.prank(alice);
snow.earnSnow();
assertEq(snow.balanceOf(alice), 1, "alice farmea");
// bob y carol no han farmeado JAMAS, y aun asi no pueden
vm.prank(bob);
vm.expectRevert(); // S__Timer
snow.earnSnow();
vm.prank(carol);
vm.expectRevert(); // S__Timer
snow.earnSnow();
assertEq(snow.balanceOf(bob), 0, "bob bloqueado por la accion de otro");
assertEq(snow.balanceOf(carol), 0, "carol tambien");
}
/// [M] Peor: `buySnow()` tambien escribe `s_earnTimer`, asi que cualquiera puede reiniciar
/// el reloj a voluntad y dejar `earnSnow()` inutilizable PARA SIEMPRE, comprando de vez en
/// cuando. El farming gratuito deja de existir para todo el mundo.
function test_unAtacantePuedeCongelarElFarmingIndefinidamente() public {
vm.deal(atacante, 100 ether);
for (uint256 semana = 1; semana <= 4; semana++) {
vm.warp(block.timestamp + 1 weeks + 1);
// el atacante compra 1 SNOW justo antes de que se abra la ventana
vm.prank(atacante);
snow.buySnow{value: FEE}(1);
// ...y con eso reinicia el reloj de TODOS
vm.prank(alice);
vm.expectRevert(); // S__Timer
snow.earnSnow();
}
assertEq(snow.balanceOf(alice), 0, "alice nunca consigue farmear");
console2.log("coste del bloqueo por semana (wei):", FEE);
}
/// [L/M] Si `msg.value` no es EXACTAMENTE el precio, el contrato cobra el total en WETH y
/// ademas se queda el ETH enviado, sin acreditarlo ni devolverlo. Un usuario que se pase o
/// se quede corto paga dos veces.
function test_elEthEnviadoQueNoCuadraSePierde() public {
uint256 precio = FEE; // 1 SNOW
weth.mint(alice, precio);
vm.deal(alice, precio);
uint256 ethAntes = alice.balance;
vm.startPrank(alice);
weth.approve(address(snow), precio);
// alice se queda corta por 1 wei: cae en la rama del WETH
snow.buySnow{value: precio - 1}(1);
vm.stopPrank();
assertEq(snow.balanceOf(alice), 1, "recibe su SNOW");
assertEq(weth.balanceOf(alice), 0, "ha pagado el precio COMPLETO en WETH");
assertEq(alice.balance, ethAntes - (precio - 1), "y encima ha perdido el ETH enviado");
assertEq(address(snow).balance, precio - 1, "el ETH se queda atrapado en el contrato");
console2.log("pagado en WETH:", precio);
console2.log("ETH perdido ademas:", precio - 1);
}
/// [M] SNOW declara 18 decimales (hereda de ERC20 sin sobrescribir `decimals()`), pero
/// `buySnow`/`earnSnow` mintean `amount` en CRUDO. Con `amount = 1` el usuario paga el
/// precio entero por 1 wei de token: 0,000000000000000001 SNOW.
function test_sePagaElPrecioEnteroPorUnWeiDeToken() public {
assertEq(snow.decimals(), 18, "el token declara 18 decimales");
vm.deal(alice, FEE);
vm.prank(alice);
snow.buySnow{value: FEE}(1);
assertEq(snow.balanceOf(alice), 1, "recibe 1 WEI de SNOW, no 1 SNOW");
assertLt(snow.balanceOf(alice), 1e18, "muy lejos de un token entero");
console2.log("ETH pagado: ", FEE);
console2.log("SNOW recibido (wei): ", snow.balanceOf(alice));
console2.log("hacen falta 1e18 wei para 1 SNOW entero -> coste real: FEE * 1e18");
}
}

Recommended Mitigation

Make the cooldown per-user with a mapping, and stop buySnow from writing it:

- uint256 private s_earnTimer;
+ mapping(address => uint256) private s_earnTimer;
function earnSnow() external canFarmSnow {
- if (s_earnTimer != 0 && block.timestamp < (s_earnTimer + 1 weeks)) revert S__Timer();
+ 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;
}
// and remove the s_earnTimer write from buySnow()
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!