AirDropper

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

Missing Claim Tracking Allows Unlimited Repeated Airdrop Claims.

Root + Impact

Any address included in the Merkle tree can repeatedly claim its allocation an arbitrary number of times.
Because claims are never marked as consumed, a valid Merkle proof remains usable indefinitely. An attacker can continuously withdraw tokens until the entire airdrop balance is exhausted.
This allows a single whitelisted participant to drain tokens intended for all eligible recipients.

Description

The (https://github.com/CodeHawks-Contests/ai-airdropper/blob/0505d7bebd492739953af3dec4687e6fe27522ea/src/MerkleAirdrop.sol#L30) function verifies Merkle inclusion but does not track whether an address or leaf has already claimed.
https://github.com/CodeHawks-Contests/ai-airdropper/blob/0505d7bebd492739953af3dec4687e6fe27522ea/src/MerkleAirdrop.sol#L34
https://github.com/CodeHawks-Contests/ai-airdropper/blob/0505d7bebd492739953af3dec4687e6fe27522ea/src/MerkleAirdrop.sol#L35
https://github.com/CodeHawks-Contests/ai-airdropper/blob/0505d7bebd492739953af3dec4687e6fe27522ea/src/MerkleAirdrop.sol#L36
https://github.com/CodeHawks-Contests/ai-airdropper/blob/0505d7bebd492739953af3dec4687e6fe27522ea/src/MerkleAirdrop.sol#L39
No state variable exists to prevent reuse of a previously successful proof.
Merkle proofs only prove membership within a dataset.
A successful proof demonstrates:
```text
(account, amount)
belongs to the Merkle tree
```
but does not inherently enforce one-time redemption.
Since the contract does not record claim status, the same proof can be submitted repeatedly.
Each call successfully passes verification and transfers tokens again.
https://github.com/CodeHawks-Contests/ai-airdropper/blob/0505d7bebd492739953af3dec4687e6fe27522ea/src/MerkleAirdrop.sol#L30
https://github.com/CodeHawks-Contests/ai-airdropper/blob/0505d7bebd492739953af3dec4687e6fe27522ea/src/MerkleAirdrop.sol#L34
https://github.com/CodeHawks-Contests/ai-airdropper/blob/0505d7bebd492739953af3dec4687e6fe27522ea/src/MerkleAirdrop.sol#L35
https://github.com/CodeHawks-Contests/ai-airdropper/blob/0505d7bebd492739953af3dec4687e6fe27522ea/src/MerkleAirdrop.sol#L36
https://github.com/CodeHawks-Contests/ai-airdropper/blob/0505d7bebd492739953af3dec4687e6fe27522ea/src/MerkleAirdrop.sol#L39

Risk

Likelihood:

  • Highly likely as there are no obstacles to draining the protocol.

Impact:

Airdrop funded with 1,000,000 tokens
Alice allocation = 25 tokens
Alice repeatedly calls claim()
Contract transfers:
25
25
25
25
...
Eventually entire airdrop reserve is drained.

Proof of Concept

1. Alice is included in the Merkle tree with an allocation of 25 tokens.
2. Alice claims:
```solidity
claim(alice, 25e6, proof);
```
and receives 25 tokens.
3. Alice calls again:
```solidity
claim(alice, 25e6, proof);
```
4. The proof remains valid because the Merkle root has not changed.
5. Another 25 tokens are transferred.
6. Repeat until the contract's token balance is exhausted.
function testUserClaimMultipleTimes() public {
uint256 fees = airdrop.getFee();
uint256 startingBalance = token.balanceOf(user1);
vm.deal(user1, 10e18);
vm.startPrank(user1);
airdrop.claim{ value: fees }(user1, amountToCollectAlice, proof);
vm.stopPrank();
vm.warp(block.timestamp + 7 days);
vm.startPrank(user1);
//vm.expectRevert();
airdrop.claim{ value: fees }(user1, amountToCollectAlice, proof);
vm.stopPrank();
vm.warp(block.timestamp + 1 days);
vm.startPrank(user1);
//vm.expectRevert();
airdrop.claim{ value: fees }(user1, amountToCollectAlice, proof);
vm.stopPrank();
uint256 endingBalance = token.balanceOf(user1);
assertEq(endingBalance - startingBalance, amountToCollectAlice * 3);
}

Recommended Mitigation

Track whether a claim has already been redeemed and enforce if a user already claimed.
Alternatively track leaf consumption: which prevents duplicate claims even if multiple allocations exist for the same address.
mapping(address => bool) public claimed; + add this code
require(!claimed[account], "Already claimed"); + add this code
or
mapping(bytes32 => bool) public claimedLeaf; + add this code
Updates

Lead Judging Commences

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