To align the buyPresent
and _mintAndIncrement
function with the intended logic (https://github.com/Cyfrin/2023-11-Santas-List/blob/6627a6387adab89ae2ba2e82b38296723261c08a/src/SantasList.sol#L168C1-L171C8
) that the caller (not the present receiver) pays for the present with their SantaToken, we would need to modify the function to burn the tokens from the caller's balance instead of the present receiver's balance. Additionally, we would need to ensure that the caller has approved the SantasList contract to spend the PURCHASED_PRESENT_COST amount of SantaToken.
Here's how we can modify the buyPresent function:
Import ERC20Burnable.sol from Openzeppelin:
Modify buyPresent():
In the modified function, burnFrom
is used instead of burn
. The burnFrom function is typically part of an ERC20 token's implementation and allows a contract to burn tokens from a user's balance, provided that the user has set an appropriate allowance for the contract.
The burnFrom function should check that the SantasList contract has been approved by the caller to spend at least PURCHASED_PRESENT_COST amount of SantaToken. If the allowance is less than the cost, the burnFrom function should revert.
The _mintAndIncrement function should also be modified to accept an address parameter so that the NFT can be minted directly to the presentReceiver:
With these changes, the buyPresent function will correctly implement the logic described in the comment, requiring users to approve the SantasList contract to spend their SantaToken before they can call buyPresent. The caller will be the one paying for the present, and the NFT will be minted to the specified presentReceiver.
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.