ERC721 Reentrancy
The ERC721 Reentrancy vulnerability refers to the potential for a reentrancy attack in the mintNFT
function. This function is marked as nonReentrant
, which is intended to prevent reentrancy attacks. However, the function calls an external contract onlyValidShortRecord
before it updates the state s.nftMapping[s.tokenIdCounter]
and short.tokenId
.
In a reentrancy attack, a malicious contract could be called as the onlyValidShortRecord
, and it could in turn call mintNFT
again before the first call to mintNFT
has finished. This could result in the same token being minted multiple times, potentially leading to unexpected behavior or a breach of the contract's intended logic.
Manual
To resolve the ERC721 Reentrancy issue, you should follow the Checks-Effects-Interactions pattern in your smart contract. This pattern recommends that you should make any state changes in your contract before calling external contracts.
Here's how you can modify the mintNFT
function:
This way, even if a reentrancy attack is attempted, the state changes have already been made, and the attack will not result in any unexpected behavior.
Additionally, you should also consider using the OpenZeppelin's ReentrancyGuard
contract, which provides a modifier to protect against reentrancy attacks.
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.