There is no verification of msg.value
in the trickOrTreat function, allowing users to send any amount of Ether, including zero
, when calling this function.
A critical vulnerability exists in the trickOrTreat
function that allows users to exploit the system for significant financial gain. There are two possible scenarious how missing check can be exploited.
Here's how this exploit could work:
A malicious user can repeatedly call the trickOrTreat
function, paying only for gas fees but sending zero Ether.
This allows them to accumulate multiple trick attempts at minimal cost.
Eventually, one of these attempts will trigger the trick event, enabling the user to call the resolveTrick
function and obtain an NFT.
Some might argue that this isn't profitable because the NFT would be purchased at double the price. However, this overlooks a sophisticated strategy that exploits market dynamics:
Initially, the NFT might be priced at 2 Ether.
Over time, as often happens in the NFT market, the value could increase dramatically, potentially reaching 20 Ether.
The malicious user then takes advantage of this price discrepancy: he/she rebuys the rarest and most expensive NFT from the contract for 4 Ether (double the original price).
By doing so, they realize a profit of 16 Ether per NFT (20 Ether current value minus 4 Ether purchase price).
Here's how this exploit could work:
A malicious user can repeatedly call the trickOrTreat
function, sending only half of the NFT's price while waiting for the treat event
to be triggered.
If the treat event
occurs, the user successfully acquires the desired NFT at half price
, realizing an immediate 50% discount on the purchase.
If the trick or treat event
is not triggered, instead the function reverts
, returning the user's Ether. In this case, the malicious actor only loses the gas fees
associated with the transaction.
Given these favorable odds, there's little disincentive for users to repeatedly attempt this strategy. Certainly there is a chance that user will get trick event
but why not try to secure a 50% discount?
Missing msg.value
check creates several potential vulnerabilities that could be exploited by malicious users. For instance, it may enable someone to purchase an NFT at half price
or even obtain one for zero
Ether.
Manual code analysis.
To mitigate this issue, it would be advisable to add a check
in the trickOrTreat function to ensure that msg.value
meets certain criteria, such as being equal to or greater than a predetermined price for the NFT. This would prevent users from exploiting the lack of validation to obtain NFTs at reduced or zero cost.
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.