The collectPresent function in the SantasList smart contract is vulnerable to an exploit that allows users to collect multiple presents. This is due to the function's reliance on the balanceOf method to check if a user has already collected a present. Users can circumvent this check by transferring their collected NFT to another account and then collecting additional presents.
In the SantasList contract, the collectPresent function checks if an address has already collected a present by verifying the balance of NFTs owned by the user. However, this check does not account for the possibility of users transferring their NFTs to another address after collection. Consequently, a user can repeatedly collect presents by continuously transferring NFTs to different addresses, thus bypassing the intended one-present-per-address limit.
Below is a POC of how a user can exploit this:
It could lead to an excessive minting of NFTs, devaluation of the NFTs, and potential exploitation of the SantaToken economy. Moreover, it violates the fairness of the system, as some users may gain multiple presents while others adhere to the intended single-collection rule.
Foundry
Manual code review
Introduce a mapping in the SantasList contract that maps each address to a boolean value. This mapping should track whether an address has already collected a present. When a user collects a present, their address should be marked as true in this mapping, preventing them from collecting presents more than once, regardless of their NFT balance.
Relying on balanceOf > 0 in collectPresent() allows the msg.sender to send their present to another address and then collect again.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.