AirDropper

AI First Flight #5
Beginner FriendlyDeFiFoundry
EXP
View results
Submission Details
Severity: high
Valid

claim() has no s_hasClaimed guard, allowing any eligible address to drain the entire airdrop by claiming repeatedly

Root + Impact

Description

  • MerkleAirdrop.claim() verifies a Merkle proof and transfers the allocated tokens to the claimant. Each eligible address is meant to claim exactly once.

  • The contract never records that an address has already claimed. There is no s_hasClaimed mapping, no per-address flag, and no revert for a repeat call. Any eligible address with a valid Merkle proof can call claim() an unlimited number of times — each call pays the 1 gwei fee and receives another full allocation — until the contract's token balance is exhausted.

// src/MerkleAirdrop.sol — claim()
function claim(address account, uint256 amount, bytes32[] calldata merkleProof) external payable {
if (msg.value != FEE) { revert MerkleAirdrop__InvalidFeeAmount(); }
bytes32 leaf = keccak256(bytes.concat(keccak256(abi.encode(account, amount))));
if (!MerkleProof.verify(merkleProof, i_merkleRoot, leaf)) { revert MerkleAirdrop__InvalidProof(); }
// @> no s_hasClaimed[account] check — same proof works unlimited times
emit Claimed(account, amount);
i_airdropToken.safeTransfer(account, amount);
}

Risk

Likelihood:

  • The proof for a given (account, amount) pair is permanently valid. Any eligible user can re-submit it immediately after their first successful claim with no cooldown.

  • All 4 eligible addresses (25 USDC each, 100 USDC total pool) can exploit this in the same transaction block.

Impact:

  • A single eligible address drains the full 100 USDC airdrop pool, leaving all other recipients with nothing.

  • The protocol's 1 gwei fee does not deter the attack — draining 100 USDC in exchange for a few thousand gwei is overwhelmingly profitable.

Proof of Concept

Alice is in the Merkle tree for 25 USDC. She calls claim() four times in sequence with the same valid proof, draining the entire 100 USDC pool.

function testDoubleClaim() public {
uint256 startBal = token.balanceOf(address(airdrop));
// Alice claims four times with the same valid proof
for (uint256 i = 0; i < startBal / ALICE_AMOUNT; i++) {
vm.prank(alice);
airdrop.claim{value: FEE}(alice, ALICE_AMOUNT, aliceProof);
}
// Contract is fully drained
assertEq(token.balanceOf(address(airdrop)), 0);
assertEq(token.balanceOf(alice), startBal);
}

The loop completes without reverting, leaving zero USDC for the other three eligible addresses.

Recommended Mitigation

Add a s_hasClaimed mapping and revert if the account has already claimed:

+ mapping(address => bool) private s_hasClaimed;
+ error MerkleAirdrop__AlreadyClaimed();
function claim(address account, uint256 amount, bytes32[] calldata merkleProof) external payable {
if (msg.value != FEE) { revert MerkleAirdrop__InvalidFeeAmount(); }
+ if (s_hasClaimed[account]) { revert MerkleAirdrop__AlreadyClaimed(); }
bytes32 leaf = keccak256(bytes.concat(keccak256(abi.encode(account, amount))));
if (!MerkleProof.verify(merkleProof, i_merkleRoot, leaf)) { revert MerkleAirdrop__InvalidProof(); }
+ s_hasClaimed[account] = true;
emit Claimed(account, amount);
i_airdropToken.safeTransfer(account, amount);
}
Updates

Lead Judging Commences

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

[H-02] Eligible users can claim their airdrop amounts over and over again, draining the contract

## Description A user eligible for the airdrop can verify themselves as being part of the merkle tree and claim their airdrop amount. However, there is no mechanism enabled to track the users who have already claimed their airdrop, and the merkle tree is still composed of the same user. This allows users to drain the `MerkleAirdrop` contract by calling the `MerkleAirdrop::claim()` function over and over again. ## Impact **Severity: High**<br/>**Likelihood: High** A malicious user can call the `MerkleAirdrop::claim()` function over and over again until the contract is drained of all its funds. This also means that other users won't be able to claim their airdrop amounts. ## Proof of Code Add the following test to `./test/MerkleAirdrop.t.sol`, ```javascript function testClaimAirdropOverAndOverAgain() public { vm.deal(collectorOne, airdrop.getFee() * 4); for (uint8 i = 0; i < 4; i++) { vm.prank(collectorOne); airdrop.claim{ value: airdrop.getFee() }(collectorOne, amountToCollect, proof); } assertEq(token.balanceOf(collectorOne), 100e6); } ``` The test passes, and the malicious user has drained the contract of all its funds. ## Recommended Mitigation Use a mapping to store the addresses that have claimed their airdrop amounts. Check and update this mapping each time a user tries to claim their airdrop amount. ```diff contract MerkleAirdrop is Ownable { using SafeERC20 for IERC20; error MerkleAirdrop__InvalidFeeAmount(); error MerkleAirdrop__InvalidProof(); error MerkleAirdrop__TransferFailed(); + error MerkleAirdrop__AlreadyClaimed(); uint256 private constant FEE = 1e9; IERC20 private immutable i_airdropToken; bytes32 private immutable i_merkleRoot; + mapping(address user => bool claimed) private s_hasClaimed; ... function claim(address account, uint256 amount, bytes32[] calldata merkleProof) external payable { + if (s_hasClaimed[account]) revert MerkleAirdrop__AlreadyClaimed(); if (msg.value != FEE) { revert MerkleAirdrop__InvalidFeeAmount(); } bytes32 leaf = keccak256(bytes.concat(keccak256(abi.encode(account, amount)))); if (!MerkleProof.verify(merkleProof, i_merkleRoot, leaf)) { revert MerkleAirdrop__InvalidProof(); } + s_hasClaimed[account] = true; emit Claimed(account, amount); i_airdropToken.safeTransfer(account, amount); } ``` Now, let's unit test the changes, ```javascript function testCannotClaimAirdropMoreThanOnceAnymore() public { vm.deal(collectorOne, airdrop.getFee() * 2); vm.prank(collectorOne); airdrop.claim{ value: airdrop.getFee() }(collectorOne, amountToCollect, proof); vm.prank(collectorOne); airdrop.claim{ value: airdrop.getFee() }(collectorOne, amountToCollect, proof); } ``` The test correctly fails, with the following logs, ```shell Failing tests: Encountered 1 failing test in test/MerkleAirdropTest.t.sol:MerkleAirdropTest [FAIL. Reason: MerkleAirdrop__AlreadyClaimed()] testCannotClaimAirdropMoreThanOnceAnymore() (gas: 96751) ```

Support

FAQs

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

Give us feedback!