The buyPresent
function in SantasList.sol
, intended for trading SantaTokens for an NFT, contains a critical flaw. It allows an exploiter to burn tokens from any address and receive an NFT in return, without the consent of the token holder. Additionally, the function does not align with the intended trade value as specified in the contest details.
The vulnerability arises from how the buyPresent
function is implemented. It accepts an address presentReceiver
parameter and burns SantaTokens from this address, but the NFT is minted to the caller of the function, not necessarily to presentReceiver
. This discrepancy allows an exploiter to target any address holding SantaTokens, burn their tokens, and receive the corresponding NFT, effectively stealing the NFT without trading their own tokens. Furthermore, the function burns 1e18 SantaTokens (from SantasToken's burn function), which is inconsistent with the intended trade value of 2e18 as outlined in the contest details.
This vulnerability has severe implications:
It allows unauthorized burning of SantaTokens from any address without their consent.
It enables exploiters to unjustly acquire NFTs, thereby compromising the integrity of the token exchange system.
Manual Code Review
To address these vulnerabilities, the following changes are recommended:
Modify the buyPresent function to only allow token holders to trade their own SantaTokens for NFTs. This can be achieved by using msg.sender as the address for both burning tokens and minting NFTs.
Adjust the token burn quantity to align with the intended trade value of 2e18 SantaTokens.
Proposed update to the buyPresent function:
Proposed update to the burn function (SantaToken.sol
):
Current implementation allows a malicious actor to burn someone else's tokens as the burn function doesn't actually check for approvals.
This line indicates that the intended cost of presents for naughty people should be 2e18: https://github.com/Cyfrin/2023-11-Santas-List/blob/6627a6387adab89ae2ba2e82b38296723261c08a/src/SantasList.sol#L87 PURCHASE_PRESENT_COST should be implemented to enforce the cost of presents.
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.