A critical price manipulation vulnerability has been identified in the SpookyTreats NFT contract. The vulnerability allows the contract owner to maliciously manipulate the price of an NFT after a user has initiated a purchase on the trickOrTreat()
before they complete it, forcing the user to pay significantly more than the original price to receive their NFT.
The vulnerability exists in the interaction between trickOrTreat()
and resolveTrick()
functions, specifically when a "trick" scenario occurs. The issue arises because:
When a user gets "tricked" (1/1000 chance), they initially pay a portion of the total cost
The NFT is minted to the contract and marked as pending
The contract stores:
The pending NFT owner (pendingNFTs
mapping)
The amount already paid (pendingNFTsAmountPaid
mapping)
The treat name (tokenIdToTreatName
mapping)
However, the contract does not store the original price of the treat
When resolveTrick()
is called, it calculates the required cost using the current price: uint256 requiredCost = treat.cost * 2;
// Double price
The owner can call setTreatCost()
to change the price between the initial purchase and resolution:
The vulnerability has severe implications:
Financial Loss: Users can be forced to pay significantly more than the advertised price
Trapped Funds: Users who cannot afford the manipulated price lose their initial payment
Manual code review
Proof of Concept code demonstrates that:
Initial treat cost: 0.1 ETH
User pays: 0.12 ETH initially
Owner increases price to 1 ETH
User must pay an additional 1.88 ETH (total 2 ETH) to receive their NFT
Result: User pays 20x more than the original price
The following Foundry test will show that the owner can manipulate the price of the NFT
Store the Original Price of the NFT
Only the owner has the rights to change the cost of the treat. Therefore it is assumed that the owner will not change the cost of the pending NFTs. The owner role is trusted.
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.