The RAACNFT
contract’s mint()
function calls _safeMint()
, which invokes onERC721Received
when sending the NFT to a contract address. Because onERC721Received
is an external callback, malicious contracts can use this hook to re-enter the mint()
function (or other vulnerable state-changing functions). Under specific conditions, this can lead to double spends, duplicated refunds, or other unintended state modifications if the logic in mint()
is not protected.
Entry Point: The _safeMint()
function triggers a callback (onERC721Received
) on the recipient contract if it’s not an externally owned account (EOA).
Reentrancy: During this callback, the malicious recipient contract can re-invoke mint()
(or other methods), potentially exploiting intermediate states (e.g., partially updated variables, incomplete refunds) to gain additional benefits.
Limited Safeguards: The code does not currently employ a nonReentrant
modifier or an equivalent mechanism, leaving it open to reentrancy.
Double Minting or Double Refund: Attackers could attempt to mint more than once, or receive multiple refunds if the contract’s state logic is not properly updated before the callback.
State Manipulation: Partial updates in the mint()
function might be exploited, leading to inaccurate balances or unexpected token distributions.
Financial & Logic Risks: Depending on the severity of the reentered logic, attackers could obtain extra NFTs, hijack or inflate refunds, or otherwise disrupt the expected behavior of the system.
Use a Reentrancy Guard
Apply nonReentrant
(e.g., from OpenZeppelin’s ReentrancyGuard
) to the mint()
function, preventing nested calls during execution.
Checks-Effects-Interactions
Update contract state fully (e.g., finalize user balances, deduct refunds) before making external calls (_safeMint
).
Consider Restricting _safeMint
If your use case permits, consider using _mint()
or restricting the NFT recipient to EOAs only. Reducing or disallowing contract recipients minimizes reentrancy vectors.
Comprehensive Testing
Implement unit tests and fuzz testing that simulate malicious onERC721Received
callbacks to confirm the fix.
With these measures, the contract can better protect itself against reentrancy attacks initiated through ERC721’s safe transfer hooks.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
View preliminary resultsAppeals are being carefully reviewed by our judges.
The contest is complete and the rewards are being distributed.