Description: The User in the SpookySwap
contract can call trickOrTreat
function to take part in the random game. If the random
number is more than 2
the user will pay the full price of the treat, and the contract mints the treat to the user account. But if the random
number is less than 2
the user will pay half of the price of the treat, and the contract mints the treat to the user account. The random
number equals 2
- the user will pay double the price of the treat.
If the user did not pass the double price amount to the smart contract. The smart contract mint
NFT to itself and the User can top up the balance of the smart contract to get the NFT in the resolveTrick
function. However, the issue is that the resolveTrick
function checks the current price of the treat. So if the admin changes this price between the trickOrTreat
and resolveTrick
function calls, the user will pay a new price for the treat.
Line of code: TrickOrTreat.sol#L124
This behavior can be used by the attacker to manipulate the price of the treat. Or even free mint of NFT. For example, if the admin sets the treat price equal to zero, the user can withdraw already spent funds while calling the resolveTrick
function.
Let's consider the following scenario:
On line number 124 the resolveTrick
function checks the current price of the treat and double it.
If the treat price is equal to zero, the totalPaid
would be more than requiredCost
, and it triggers the if
conditional on the line number 139
The user will receive the full price he already spends in the first call of the trickOrTreat
function.
Proof of Code: Let's proof the following logic with the following test case:
The owner can manipulate the price of the treat.
The user can withdraw already spent funds.
The user can mint NFT for free.
The user can spend more than the initial price of the treat that he won.
Manual code analysis
Foundry for testing
The resolveTrick
function should not check the current price of the treat. The smart contract should also save the price of the treat at the moment of the trickOrTreat
function call.
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.