Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: high
Valid

Any arbitrary address can claim love tokens everyday, without even matching up with a soulmate.

Summary

Airdrop::claim function allows any malicious user to claim LoveToken everyday, since there is no requirement for the callers of the function to have a soulmate.

Vulnerability Details

Add the following to the AirdropTest.t.sol file:

function testAnyoneCanClaim() public {
address user = makeAddr("user");
vm.warp(block.timestamp + 1 days);
vm.startPrank(user);
airdropContract.claim();
vm.warp(block.timestamp + 1 days);
airdropContract.claim();
vm.warp(block.timestamp + 1 days);
airdropContract.claim();
vm.stopPrank();
assert(loveToken.balanceOf(user) == 3e18);
}

Impact

High: Any address can directly steal tokens from aidrop vault's funds.

Tools Used

Manual Review, Foundry

Recommendations

Add a check in Airdrop::claim function, that checks if the caller of the function has a soulmate:

function claim() public {
+ if (soulmateContract.soulmateOf(msg.sender) == address(0)) revert();
// No LoveToken for people who don't love their soulmates anymore.
if (soulmateContract.isDivorced()) revert Airdrop__CoupleIsDivorced();
// Calculating since how long soulmates are reunited
uint256 numberOfDaysInCouple = (block.timestamp -
soulmateContract.idToCreationTimestamp(
soulmateContract.ownerToId(msg.sender)
)) / daysInSecond;
uint256 amountAlreadyClaimed = _claimedBy[msg.sender];
if (
amountAlreadyClaimed >=
numberOfDaysInCouple * 10 ** loveToken.decimals()
) revert Airdrop__PreviousTokenAlreadyClaimed();
uint256 tokenAmountToDistribute = (numberOfDaysInCouple *
10 ** loveToken.decimals()) - amountAlreadyClaimed;
// Dust collector
if (
tokenAmountToDistribute >=
loveToken.balanceOf(address(airdropVault))
) {
tokenAmountToDistribute = loveToken.balanceOf(
address(airdropVault)
);
}
_claimedBy[msg.sender] += tokenAmountToDistribute;
emit TokenClaimed(msg.sender, tokenAmountToDistribute);
loveToken.transferFrom(
address(airdropVault),
msg.sender,
tokenAmountToDistribute
);
}
Updates

Lead Judging Commences

0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

finding-claim-airdrop-without-owning-NFT

High severity, This issue is separated from the flawed `isDivorced()` check presented in issue #168 as even if that is fixed, if ownership is not checked, isDivorced would still default to false and allow bypass to claim airdrops by posing as tokenId 0 in turn resulting in this [important check for token claim is bypassed.](https://github.com/Cyfrin/2024-02-soulmate/blob/b3f9227942ffd5c443ce6bccaa980fea0304c38f/src/Airdrop.sol#L61-L66). #220 is the most comprehensive issue as it correctly recognizes both issues existing within the same function.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.