Snowman Merkle Airdrop

AI First Flight #10
Beginner FriendlyFoundrySolidityNFT
EXP
View results
Submission Details
Impact: medium
Likelihood: medium
Invalid

[M-05] SNOW declares 18 decimals but mints raw units: the full price buys 1 wei of token

Root + Impact

Description

  • An ERC20 that declares 18 decimals should mint amounts scaled to those decimals, consistent with how its price is expressed.

  • Snow inherits ERC20 without overriding decimals() (so 18), but buySnow/earnSnow mint amount raw while the price is scaled by 1e18. buySnow(1) charges the full price for 0.000000000000000001 SNOW.

@> constructor(...) ERC20("Snow", "S") { ... } // decimals() == 18
@> s_buyFee = _buyFee * PRECISION; // price scaled by 1e18
...
@> _mint(msg.sender, amount); // but minted raw (1 == 1 wei)

Risk

Likelihood:

  • Every purchase and every earnSnow mints raw units, so the mismatch happens on every interaction with the token.

Impact:

  • The effective price is absurd (full fee per 1 wei of token) and buying a whole token would cost 1e18 times the fee.

  • Wallets, explorers and DEXs format via decimals(), so a legitimate holder shows 0.000000000000000001 SNOW; any integration using 1e18 breaks. Merkle allocations are built from these raw amounts.

Proof of Concept

The test asserts decimals() == 18, yet after buySnow(1) Alice's balance is 1 (i.e. 1 wei of token) - the full fee bought 0.000000000000000001 SNOW.

Verified with Foundry (test_sePagaElPrecioEnteroPorUnWeiDeToken), 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

Pick one convention and apply it consistently - either make the token indivisible, or keep 18 decimals and scale the mint:

+ function decimals() public pure override returns (uint8) { return 0; }
// option A (token is indivisible; matches how the airdrop uses it)
//
// option B: keep 18 decimals and scale the mint:
- _mint(msg.sender, amount);
+ _mint(msg.sender, amount * PRECISION);
Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge about 4 hours ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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

Give us feedback!