If an innocent user has called approve
for Santa to spend their tokens so they can then buy an NFT, a malicious actor can immediately call buyProduct
passing in the innocent user, which will burn the innocent user's tokens, but mint the NFT to the malicious actor. This is because the msg.sender
in buyProduct
is the malicious actor, which gets forwarded to _mintAndIncrement
, minting the NFT to the msg.sender
which is the malicious actor.
Add this test to the test suite.
Users loss of funds (santaTokens) and the malicious actor gets the NFT instead of them.
Manual Review
You could check that the msg.sender
is the presentReceiver
but that defeats the purpose of buying a present on behalf of someone else. To keep in the spirit of the buyPresent
function, rather than relying on msg.sender
, pass in presentReceiver
and forward this to the mint functionality.
However, this doesn't fix all aspects of griefing. You may want to have a whitelist for buyers. For example, if Alice calls approve but then changes her mind and doesn't want to burn her tokens for an NFT, a malicious actor can still call buyProduct
which will burn her tokens and mint her an NFT, even if she had changed her mind because the approval was already set.
By having a mapping whitelist of approved buyers for a specific address like Alice, this prevents unwanted forceful purchases after approval. We can add a check that the caller of buyProduct
is whitelisted, and then create two functions to give Alice the ability to set and revoke approval of buyers for her.
Current implementation allows a malicious actor to burn someone else's tokens as the burn function doesn't actually check for approvals.
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.