The function trickOrTreathas nonReentrant modifier , however is possible hack this function by the Cross-Function Reentrancy. By using transferFromor safeTransferFromfunctions from the ERC721 interface.
The trickOrTreat function does not adhere to the Checks-Effects-Interactions (CEI) pattern. While it does use the nonReentrant modifier, it remains vulnerable to cross-function reentrancy attacks. This vulnerability exists because a potential client can also be a smart contract. By exploiting the transferFrom or safeTransferFrom functions. It is possible to drain all NFT tokens owned by the smart contract.
The SpookySwap contract is an ERC721URIStorage and ERC721 type. It includes functions like transferFrom and safeTransferFrom, which can potentially be exploited to drain all NFT tokens from the contract.
To do that potential attacker has to send more ETH than is price for a specific treat. Because at the end of trickOrTreatfunction is if statementwhere is checking msg.value > requiredCostthat msg.value is greater than requiredCost. If it is true then refund msg.sender.call{value: refund}("");.
Please check bellow POC for hack:
TOKEN_ID_FOR_STOLEN- information about size of treatList you can take from size function or nextTokenIdparam.
POC
It is possible to drain all NFT tokens owned by the smart contract.
manual review
Please use Checks-Effects-Interactions (CEI) pattern for trickOrTreat function.
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.