AirDropper

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

claim() never records that an allocation was claimed, so the same proof can drain the entire airdrop

Root + Impact

claim() verifies the caller's Merkle proof and transfers the tokens, but it never records that the (account, amount) pair has already claimed. There is no claimed mapping, bitmap, or any other replay protection anywhere in the contract. The exact same account, amount, and proof can therefore be submitted again and again, and every call pays out the full amount again for the price of the trivial 1e9 wei fee, until the contract's token balance is empty. The contract is funded with exactly 100 USDC for four people; the first eligible allocation, replayed four times, takes all of it, and the other three eligible users get nothing.

Description

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); // pays out every time; nothing marks the claim as used
}

Two compounding details: proofs are public data (they are generated by makeMerkle.js and must be distributed to users), and claim takes account as a free parameter, so literally anyone can fire the repeat claims, the tokens just keep landing on the eligible account. The distributor this contract is based on (Uniswap's MerkleDistributor) prevents exactly this with a claimed bitmap; that mechanism is missing here.

Risk

Likelihood: High - the attack needs only the public proof of any one eligible user and 1e9 wei per call; it can be executed by the eligible user or by any third party, immediately after deployment and funding.
Impact: High - the entire airdrop balance (100 USDC, the whole distribution) can be drained through a single allocation, leaving nothing for the remaining eligible users. The distribution fails completely.

Proof of Concept

Verified with Foundry (test passes), using the repository's own test root and proof for collector 0x20F41376c713072937eb02Be70ee1eD0D639966C (25 USDC): the same claim is executed four times, twice by the eligible user and twice by an unrelated stranger, and the eligible account ends up holding all 100 USDC while the airdrop contract is empty.

function test_SameProofDrainsWholeAirdrop() public {
// airdrop funded with 4 * 25 USDC, as in the Deploy script
vm.startPrank(collectorOne);
airdrop.claim{value: fee}(collectorOne, amountToCollect, proof);
airdrop.claim{value: fee}(collectorOne, amountToCollect, proof); // second payout, same proof
vm.stopPrank();
vm.startPrank(stranger); // proofs are public: anyone can replay them
airdrop.claim{value: fee}(collectorOne, amountToCollect, proof);
airdrop.claim{value: fee}(collectorOne, amountToCollect, proof);
vm.stopPrank();
assertEq(token.balanceOf(collectorOne), amountToSend); // all 100 USDC
assertEq(token.balanceOf(address(airdrop)), 0); // drained
}

Recommended Mitigation

Track claims and reject repeats, e.g. a mapping keyed by account (each account appears once in this tree):

+ mapping(address account => bool claimed) private s_hasClaimed;
...
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!