Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: medium
Invalid

SantasList:buyPresent() allows recipient to receive NFT even if they already own one

Summary

SantasList:buyPresent() allows recipient to receive NFT even if they already own one

Vulnerability Details

There is no check in SantasList:buyPresent() to ensure that the receipient already does not own a Santa NFT

Impact

Medium

PoC

The Foundry test below will fail with current code as the transaction does not revert if the recipient already owns the NFT...

function testBuyPresentRecipientAlreadyOwns() public {
vm.startPrank(santa);
santasList.checkList(user, SantasList.Status.EXTRA_NICE);
santasList.checkTwice(user, SantasList.Status.EXTRA_NICE);
vm.stopPrank();
vm.warp(santasList.CHRISTMAS_2023_BLOCK_TIME() + 1);
vm.startPrank(user);
santaToken.approve(address(santasList), 1e18);
santasList.collectPresent();
vm.expectRevert();
santasList.buyPresent(user);
vm.stopPrank();
}

Tools Used

Visual Studio Code, Foundry

Recommendations

Change SantasList:buyPresent() to have a check for recipient already owning the NFT and revert if they do...

function buyPresent(address presentReceiver) external {
if ((balanceOf(presentReceiver) > 0)) {
revert SantasList__AlreadyCollected();
}
i_santaToken.burn(presentReceiver);
_mintAndIncrement();
}
Updates

Lead Judging Commences

inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

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