AirDropper

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

Missing already-claimed check in MerkleAirdrop::claim lets an eligible address claim repeatedly and drain the entire airdrop

Description

MerkleAirdrop::claim gates a claim on only two things: the caller paying the exact FEE, and a valid Merkle proof for the (account, amount) leaf. It never records that an address has already claimed — there is no hasClaimed mapping and no check against one — and the same leaf always produces the same valid proof.

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();
}
emit Claimed(account, amount);
@> i_airdropToken.safeTransfer(account, amount); // no replay protection
}

Because nothing marks account as having claimed, any eligible address can call claim repeatedly with the same proof, receiving amount tokens on every call until the contract's token balance is exhausted.

Risk

Likelihood: High

  • Every eligible address already holds a valid proof for its own leaf and can re-submit it any number of times; the only cost is the 1 gwei FEE per call.

  • No special timing, ordering, or privileged access is required.

Impact: High

  • The first eligible claimer to act can withdraw the entire airdrop token balance (100 USDC in the deployed configuration), not just their 25 USDC allocation.

  • This steals the funds allocated to the other eligible recipients and breaks the core invariant that each address receives its allocation exactly once (total distributed <= total funded).

Proof of Concept

Add the following test to test/MerkleAirdropTest.t.sol. It reuses the existing setUp, proof, and collectorOne. collectorOne is entitled to 25 USDC once, but claims four times and walks away with the full 100 USDC pool, leaving nothing for the other three eligible users.

function testDoubleClaimDrainsAirdrop() public {
uint256 fee = airdrop.getFee();
// collectorOne is only entitled to `amountToCollect` (25 USDC) a single time
vm.deal(collectorOne, fee * 4);
vm.startPrank(collectorOne);
airdrop.claim{value: fee}(collectorOne, amountToCollect, proof);
airdrop.claim{value: fee}(collectorOne, amountToCollect, proof);
airdrop.claim{value: fee}(collectorOne, amountToCollect, proof);
airdrop.claim{value: fee}(collectorOne, amountToCollect, proof);
vm.stopPrank();
// Stole the entire pool (4 x 25 = 100 USDC) instead of 25
assertEq(token.balanceOf(collectorOne), amountToCollect * 4);
// Airdrop contract is fully drained
assertEq(token.balanceOf(address(airdrop)), 0);
}

Run with forge test --mt testDoubleClaimDrainsAirdrop; it passes, confirming the drain.

Recommended Mitigation

Record each successful claim and reject any repeat, so a given eligible address is paid exactly once no matter how many times its proof is replayed.

Add a mapping(address => bool) s_hasClaimed, check it up front, and set it before the external token transfer (checks-effects-interactions), reverting with a dedicated error when it is already set:

+ error MerkleAirdrop__AlreadyClaimed();
+
+ mapping(address => bool) private s_hasClaimed;
+
function claim(address account, uint256 amount, bytes32[] calldata merkleProof) external payable {
if (msg.value != FEE) {
revert MerkleAirdrop__InvalidFeeAmount();
}
+ // Reject any address that has already been paid.
+ 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();
}
+ // Effects before interactions: mark claimed prior to the transfer so a repeated
+ // or re-entrant call cannot pass this check a second time.
+ s_hasClaimed[account] = true;
emit Claimed(account, amount);
i_airdropToken.safeTransfer(account, amount);
}

Two properties make this correct: the guard is keyed on account (the leaf beneficiary), not msg.sender, so a third party cannot bypass it by relaying the same proof from different addresses; and the flag is written before the transfer, so even a token with a transfer hook cannot re-enter claim and pass the check again. After the fix, testDoubleClaimDrainsAirdrop reverts on the second claim with MerkleAirdrop__AlreadyClaimed, while each of the four eligible users can still claim their 25 USDC exactly once.

Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge about 2 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!