Snowman Merkle Airdrop

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

[M-02] Malformed EIP-712 typehash: signatures produced by any standard wallet are rejected

Root + Impact

Description

Description

  • The contract inherits EIP712 and states its signatures are EIP-712 compliant, so a standard wallet signing the SnowmanClaim struct should produce a digest the contract accepts.

  • The MESSAGE_TYPEHASH string is malformed: addres is missing a d, and it contains spaces that EIP-712's canonical encodeType forbids. Any wallet using eth_signTypedData_v4 derives a different typehash, so a correct EIP-712 signature is rejected with SA__InvalidSignature.

@> bytes32 private constant MESSAGE_TYPEHASH =
@> keccak256("SnowmanClaim(addres receiver, uint256 amount)");
// canonical: "SnowmanClaim(address receiver,uint256 amount)"
// ^ missing 'd' ^ no spaces allowed

Risk

Likelihood:

  • Any user signing through a standard wallet (MetaMask, ethers, viem, Safe) produces a digest that does not match the contract's.

  • It is not universal only because the project's own frontend could replicate the wrong typehash via getMessageHash; external integrations break.

Impact:

  • The claim-by-signature flow - the whole point of the meta-transaction design - is unusable for anyone signing with standard tooling.

  • Third-party integrations and smart-contract signers cannot participate.

Proof of Concept

The test builds the EIP-712 digest exactly as a standard wallet would (canonical encodeType plus the contract's domain separator), signs it, and calls claimSnowman; the call reverts with SA__InvalidSignature. As a control, signing the contract's own malformed digest succeeds - so only someone replicating the typo can claim.

Verified with Foundry (test_unaFirmaEip712CorrectaEsRechazadaPorElContrato), 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 {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";
/// @notice Dos fallos que nacen de la misma raíz: la elegibilidad se calcula sobre estado
/// MUTABLE (`balanceOf` en vivo) y el typehash EIP-712 no es el canónico.
contract GriefYTypehashTest is Test {
Snow snow;
Snowman nft;
SnowmanAirdrop airdrop;
MockWETH weth;
Helper deployer;
bytes32[] AL_PROOF = [
bytes32(0xf99782cec890699d4947528f9884acaca174602bb028a66d0870534acf241c52),
bytes32(0xbc5a8a0aad4a65155abf53bb707aa6d66b11b220ecb672f7832c05613dba82af),
bytes32(0x971653456742d62534a5d7594745c292dda6a75c69c43a6a6249523f26e0cac1)
];
address alice;
uint256 alKey;
address atacante;
function setUp() public {
deployer = new Helper();
(airdrop, snow, nft, weth) = deployer.run();
(alice, alKey) = makeAddrAndKey("alice");
atacante = makeAddr("atacante");
}
/// [M] Cualquiera puede impedir que un beneficiario legítimo reclame, enviándole 1 wei
/// de SNOW: el leaf se deriva de `balanceOf(receiver)`, así que al cambiar el balance la
/// hoja deja de estar en el árbol y la prueba se vuelve inválida.
function test_polvoDeSnowBloqueaElClaimDeUnBeneficiarioLegitimo() public {
// alice podría reclamar sin problema: comprobamos la firma ANTES del ataque
bytes32 digestLimpio = airdrop.getMessageHash(alice);
(uint8 v0, bytes32 r0, bytes32 s0) = vm.sign(alKey, digestLimpio);
uint256 snapshot = vm.snapshotState();
vm.prank(alice);
snow.approve(address(airdrop), 1);
airdrop.claimSnowman(alice, AL_PROOF, v0, r0, s0);
assertEq(nft.balanceOf(alice), 1, "sin ataque, alice reclama sin problema");
vm.revertToState(snapshot);
// --- el ataque: 1 unidad de SNOW no solicitada ---
uint256 fee = snow.s_buyFee();
vm.deal(atacante, 10 ether);
vm.startPrank(atacante);
snow.buySnow{value: fee}(1);
snow.transfer(alice, 1); // polvo
vm.stopPrank();
assertEq(snow.balanceOf(alice), 2, "alice tiene 1 de mas, sin haberlo pedido");
// La firma antigua ya no vale (el digest depende del balance) y la nueva tampoco
// sirve: el leaf calculado es keccak(alice, 2) y ese no esta en el arbol.
bytes32 digestSucio = airdrop.getMessageHash(alice);
assertTrue(digestLimpio != digestSucio, "el digest cambia con el balance");
(uint8 v, bytes32 r, bytes32 s) = vm.sign(alKey, digestSucio);
vm.prank(alice);
snow.approve(address(airdrop), 2);
vm.expectRevert(); // SA__InvalidProof
airdrop.claimSnowman(alice, AL_PROOF, v, r, s);
assertEq(nft.balanceOf(alice), 0, "alice se queda sin su airdrop");
console2.log("coste del ataque (wei):", fee);
}
/// [M] Una wallet real (MetaMask, ethers, viem) construye el digest EIP-712 a partir del
/// struct, usando el `encodeType` CANÓNICO. Aquí se reproduce exactamente ese cálculo y se
/// comprueba que el contrato RECHAZA la firma resultante: el flujo de firma es inservible
/// fuera de los tests del propio proyecto, que llaman a `getMessageHash()` y por tanto
/// heredan el typehash equivocado en vez de detectarlo.
function test_unaFirmaEip712CorrectaEsRechazadaPorElContrato() public {
uint256 amount = snow.balanceOf(alice);
assertEq(amount, 1, "alice es beneficiaria");
// --- lo que hace una wallet estandar: encodeType canonico, sin espacios ---
bytes32 typehashCanonico = keccak256("SnowmanClaim(address receiver,uint256 amount)");
bytes32 structHash = keccak256(abi.encode(typehashCanonico, alice, amount));
// dominio EIP-712 del contrato: name "Snowman Airdrop", version "1"
bytes32 domainSeparator = keccak256(
abi.encode(
keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
),
keccak256(bytes("Snowman Airdrop")),
keccak256(bytes("1")),
block.chainid,
address(airdrop)
)
);
bytes32 digestDeWallet = keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
// el digest que calcula el contrato NO coincide con el de la wallet
bytes32 digestDelContrato = airdrop.getMessageHash(alice);
assertTrue(digestDeWallet != digestDelContrato, "los digests divergen");
// alice firma correctamente segun el estandar... y aun asi no puede reclamar
(uint8 v, bytes32 r, bytes32 s) = vm.sign(alKey, digestDeWallet);
vm.prank(alice);
snow.approve(address(airdrop), amount);
vm.expectRevert(); // SA__InvalidSignature
airdrop.claimSnowman(alice, AL_PROOF, v, r, s);
assertEq(nft.balanceOf(alice), 0, "firma valida segun EIP-712 y rechazada igualmente");
// control: firmando el digest ERRONEO del contrato si funciona
(uint8 v2, bytes32 r2, bytes32 s2) = vm.sign(alKey, digestDelContrato);
airdrop.claimSnowman(alice, AL_PROOF, v2, r2, s2);
assertEq(nft.balanceOf(alice), 1, "solo cuela quien replica el typehash mal escrito");
}
}

Recommended Mitigation

Fix the typehash string to the canonical EIP-712 encodeType (correct spelling, no spaces):

- keccak256("SnowmanClaim(addres receiver, uint256 amount)");
+ keccak256("SnowmanClaim(address receiver,uint256 amount)");

Add a test that builds the signature from the struct (not via getMessageHash) so a future typehash drift fails in CI.

Updates

Lead Judging Commences

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

[H-02] Unconsistent `MESSAGE_TYPEHASH` with standart EIP-712 declaration on contract `SnowmanAirdrop`

# Root + Impact ## Description * Little typo on `MESSAGE_TYPEHASH` Declaration on `SnowmanAirdrop` contract ```Solidity // src/SnowmanAirdrop.sol 49: bytes32 private constant MESSAGE_TYPEHASH = keccak256("SnowmanClaim(addres receiver, uint256 amount)"); ``` **Impact**: * `function claimSnowman` never be `TRUE` condition ## Proof of Concept Applying this function at the end of /test/TestSnowmanAirdrop.t.sol to know what the correct and wrong digest output HASH. Ran with command: `forge test --match-test testFrontendSignatureVerification -vvvv` ```Solidity function testFrontendSignatureVerification() public { // Setup Alice for the test vm.startPrank(alice); snow.approve(address(airdrop), 1); vm.stopPrank(); // Simulate frontend using the correct format bytes32 FRONTEND_MESSAGE_TYPEHASH = keccak256("SnowmanClaim(address receiver, uint256 amount)"); // Domain separator used by frontend (per EIP-712) bytes32 DOMAIN_SEPARATOR = keccak256( abi.encode( keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"), keccak256("Snowman Airdrop"), keccak256("1"), block.chainid, address(airdrop) ) ); // Get Alice's token amount uint256 amount = snow.balanceOf(alice); // Frontend creates hash using the correct format bytes32 structHash = keccak256( abi.encode( FRONTEND_MESSAGE_TYPEHASH, alice, amount ) ); // Frontend creates the final digest (per EIP-712) bytes32 frontendDigest = keccak256( abi.encodePacked( "\x19\x01", DOMAIN_SEPARATOR, structHash ) ); // Alice signs the digest created by the frontend (uint8 v, bytes32 r, bytes32 s) = vm.sign(alKey, frontendDigest); // Digest created by the contract (with typo) bytes32 contractDigest = airdrop.getMessageHash(alice); // Display both digests for comparison console2.log("Frontend Digest (correct format):"); console2.logBytes32(frontendDigest); console2.log("Contract Digest (with typo):"); console2.logBytes32(contractDigest); // Compare the digests - they should differ due to the typo assertFalse( frontendDigest == contractDigest, "Digests should differ due to typo in MESSAGE_TYPEHASH" ); // Attempt to claim with the signature - should fail vm.prank(satoshi); vm.expectRevert(SnowmanAirdrop.SA__InvalidSignature.selector); airdrop.claimSnowman(alice, AL_PROOF, v, r, s); assertEq(nft.balanceOf(alice), 0); } ``` ## Recommended Mitigation on contract `SnowmanAirdrop` Line 49 applying this: ```diff - bytes32 private constant MESSAGE_TYPEHASH = keccak256("SnowmanClaim(addres receiver, uint256 amount)"); + bytes32 private constant MESSAGE_TYPEHASH = keccak256("SnowmanClaim(address receiver, uint256 amount)"); ```

Support

FAQs

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

Give us feedback!