The SpookySwap
contract is an ERC721 NFT contract that allows users to participate in a "Trick or Treat" feature. Users can call the trickOrTreat
function to purchase a "treat" NFT at a cost in ETH.
The random number generation relies on insecure and manipulable sources — specifically block.timestamp
, msg.sender
, nextTokenId
, and block.prevrandao
. These values can be predicted or influenced by miners and users, allowing an attacker to manipulate the outcome of the random number generation.
The contract's method of generating randomness is insecure and can be manipulated by attackers. The random number generation relies on predictable and controllable variables, allowing malicious users to influence the outcome in their favor. This vulnerability enables attackers to consistently obtain NFTs at half price or avoid paying double price, leading to unfair advantages and potential financial losses for the contract owner.
The random number is generated using the following code snippet in the trickOrTreat
function:
The vulnerability allows attackers to manipulate the randomness in the SpookySwap
contract, giving them an unfair advantage over other users. By manipulating the random number, attackers can increase their chances of getting the treat at half price, reducing revenue for the contract owner. Attackers can prevent scenarios where they have to pay double price, ensuring they never overpay. Contract owner will get reduced revenue from sales due to attackers paying less than intended.
Manual review
To securely generate randomness, it is recommended to use an external oracle or a verifiable random function (VRF), such as Chainlink VRF. This provides a tamper-proof source of randomness that cannot be predicted or manipulated by users or miners.
It's written in the README: "We're aware of the pseudorandom nature of the current implementation. This will be replaced with Chainlink VRF in later builds." This is a known issue.
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.