AirDropper

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

claim has no replay protection — the same account/proof can be re-claimed indefinitely, draining the entire airdrop

Description

claim verifies a Merkle proof and transfers the airdrop amount, but it never records that an account has already claimed:

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);
}

There is no s_hasClaimed tracking — and no claimed bitmap, which the Uniswap Merkle-Distributor the contract says it is based on uses precisely to prevent this. The account, amount, and merkleProof are all public and constant, so the same valid tuple can be submitted repeatedly. claim also takes account as a parameter (not msg.sender), so anyone can claim on any eligible address's behalf.

The result: a single eligible leaf can be claimed over and over. Each call transfers another amount of the airdrop token for only the 1e9-wei (1 gwei) fee, until the contract's entire token balance is gone. The 100 USDC meant to be split 25-each among 4 recipients can be drained in full by replaying one address's claim four times (or one address's claim, four times, all to that address).

Risk

Impact: High. Complete drain of the airdrop funds. The core invariant of an airdrop — each eligible address claims its allocation exactly once — is not enforced at all, so the whole pool is stealable.

Likelihood: High. A handful of repeated calls with a public proof, for a negligible per-call fee, callable by anyone.

Proof of Concept

function test_doubleClaimDrainsAirdrop() public {
// airdrop funded with 100e6 (100 USDC); `eligible` has a valid (amount=25e6, proof).
assertEq(token.balanceOf(address(airdrop)), 100e6);
for (uint256 i = 0; i < 4; i++) {
airdrop.claim{value: 1e9}(eligible, 25e6, proof); // SAME proof, replayed 4x
}
// EXPECTED: only the first 25e6 succeeds; the next three revert as already-claimed.
// ACTUAL: all four succeed; 100e6 pulled out, airdrop fully drained.
assertEq(token.balanceOf(eligible), 100e6);
assertEq(token.balanceOf(address(airdrop)), 0);
}

Expected: an eligible address can claim its allocation once. Actual: it can claim endlessly until the pool is empty.

Recommended Mitigation

Record each claim and reject repeats before transferring (checks-effects-interactions):

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();
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; // effects before the interaction
emit Claimed(account, amount);
i_airdropToken.safeTransfer(account, amount);
}

Equivalently, adopt the claimed-bitmap (isClaimed/_setClaimed) pattern from the Uniswap Merkle-Distributor the contract is modeled on.

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!