Snowman Merkle Airdrop

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

Medium Bug Report: No Double-Claim Prevention in claimSnowman()

## Summary
The `claimSnowman()` function sets `s_hasClaimedSnowman[receiver] = true` after a successful claim, but **never checks this mapping before processing the claim**. This allows a user to claim multiple times by re-acquiring the exact same Snow token balance and reusing the same Merkle proof and signature.
---
## Vulnerable Code
```solidity
// SnowmanAirdrop.sol:69-99
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; // <-- Set but never checked
emit SnowmanClaimedSuccessfully(receiver, amount);
i_snowman.mintSnowman(receiver, amount);
}
```
---
## Impact
- **Double claiming:** A user can claim NFTs multiple times by re-acquiring the same Snow balance.
- **Same signature reuse:** The Merkle proof and signature remain valid because they're based on `(receiver, amount)` — if the amount is the same, the leaf is the same.
- **Inflated NFT supply:** Users can claim more NFTs than they're entitled to, breaking the 1:1 ratio with staked Snow.
- **Unfair distribution:** Early claimers can hoard NFTs while latecomers get nothing.
---
## Proof of Concept
```solidity
// Scenario: User claims twice with same amount
// Step 1: User has 100 Snow tokens, calls claimSnowman()
// - Proof validates leaf = keccak256(abi.encode(user, 100))
// - Signature validates
// - 100 Snow transferred to contract (burned)
// - 100 NFTs minted to user
// - s_hasClaimedSnowman[user] = true
snowmanAirdrop.claimSnowman(user, proof, v, r, s);
// Step 2: User buys 100 more Snow tokens (or receives from another address)
snow.buySnow{value: cost}(100); // User now has 100 Snow again
// Step 3: User calls claimSnowman() AGAIN
// - Same proof validates (leaf = keccak256(abi.encode(user, 100)))
// - Same signature validates
// - 100 Snow transferred to contract
// - 100 MORE NFTs minted to user!
// - s_hasClaimedSnowman[user] = true (already was, no check prevents this)
snowmanAirdrop.claimSnowman(user, proof, v, r, s);
// Result: User claimed 200 NFTs total for the price of 200 Snow
// But the Merkle tree only allocated 100 NFTs to this user
// Extra 100 NFTs came from other users' allocations
```
**Attack scenario:**
1. User claims with 100 Snow → gets 100 NFTs, Snow burned
2. User buys/receives 100 more Snow
3. User claims again with same proof → gets 100 MORE NFTs
4. Repeat indefinitely to drain the airdrop pool
---
## Recommended Fix
Add a check at the beginning of `claimSnowman()` to prevent double claiming:
```solidity
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();
}
// ADD THIS CHECK:
if (s_hasClaimedSnowman[receiver]) {
revert SA__AlreadyClaimed(); // or similar error
}
// ... rest of function
}
```
This ensures each address can only claim once, regardless of how many times they acquire the same Snow balance.
---
## References
- [Reentrancy and Double-Spending in Smart Contracts](https://consensys.github.io/smart-contract-best-practices/attacks/reentrancy/)
Updates

Lead Judging Commences

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

[L-01] Missing Claim Status Check Allows Multiple Claims in SnowmanAirdrop.sol::claimSnowman

# Root + Impact &#x20; **Root:** The [`claimSnowman`](https://github.com/CodeHawks-Contests/2025-06-snowman-merkle-airdrop/blob/b63f391444e69240f176a14a577c78cb85e4cf71/src/SnowmanAirdrop.sol#L44) function updates `s_hasClaimedSnowman[receiver] = true` but never checks if the user has already claimed before processing the claim, allowing users to claim multiple times if they acquire more Snow tokens. **Impact:** Users can bypass the intended one-time airdrop limit by claiming, acquiring more Snow tokens, and claiming again, breaking the airdrop distribution model and allowing unlimited NFT minting for eligible users. ## Description * **Normal Behavior:** Airdrop mechanisms should enforce one claim per eligible user to ensure fair distribution and prevent abuse of the reward system. * **Specific Issue:** The function sets the claim status to true after processing but never validates if `s_hasClaimedSnowman[receiver]` is already true at the beginning, allowing users to claim multiple times as long as they have Snow tokens and valid proofs. ## Risk **Likelihood**: Medium * Users need to acquire additional Snow tokens between claims, which requires time and effort * Users must maintain their merkle proof validity across multiple claims * Attack requires understanding of the missing validation check **Impact**: High * **Airdrop Abuse**: Users can claim far more NFTs than intended by the distribution mechanism * **Unfair Distribution**: Some users receive multiple rewards while others may receive none * **Economic Manipulation**: Breaks the intended scarcity and distribution model of the NFT collection ## Proof of Concept Add the following test to TestSnowMan.t.sol  ```Solidity function testMultipleClaimsAllowed() public { // Alice claims her first NFT vm.prank(alice); snow.approve(address(airdrop), 1); bytes32 aliceDigest = airdrop.getMessageHash(alice); (uint8 v, bytes32 r, bytes32 s) = vm.sign(alKey, aliceDigest); vm.prank(alice); airdrop.claimSnowman(alice, AL_PROOF, v, r, s); assert(nft.balanceOf(alice) == 1); assert(airdrop.getClaimStatus(alice) == true); // Alice acquires more Snow tokens (wait for timer and earn again) vm.warp(block.timestamp + 1 weeks); vm.prank(alice); snow.earnSnow(); // Alice can claim AGAIN with new Snow tokens! vm.prank(alice); snow.approve(address(airdrop), 1); bytes32 aliceDigest2 = airdrop.getMessageHash(alice); (uint8 v2, bytes32 r2, bytes32 s2) = vm.sign(alKey, aliceDigest2); vm.prank(alice); airdrop.claimSnowman(alice, AL_PROOF, v2, r2, s2); // Second claim succeeds! assert(nft.balanceOf(alice) == 2); // Alice now has 2 NFTs } ``` ## Recommended Mitigation **Add a claim status check at the beginning of the function** to prevent users from claiming multiple times. ```diff // Add new error + error SA__AlreadyClaimed(); function claimSnowman(address receiver, bytes32[] calldata merkleProof, uint8 v, bytes32 r, bytes32 s) external nonReentrant { + if (s_hasClaimedSnowman[receiver]) { + revert SA__AlreadyClaimed(); + } + if (receiver == address(0)) { revert SA__ZeroAddress(); } // Rest of function logic... s_hasClaimedSnowman[receiver] = true; } ```

Support

FAQs

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

Give us feedback!