The mintEgg() function in the EggstravaganzaNFT contract is vulnerable to a classic reentrancy attack. The function updates totalSupply after calling the external _mint() function, which can trigger a reentrant call to mintEgg() via onERC721Received() if the recipient is a contract. This allows a malicious contract to mint multiple NFTs in a single transaction, bypassing supply tracking.
Since _mint() calls onERC721Received() if to is a contract, and this happens before totalSupply is updated, a malicious receiver can re-enter mintEgg() and mint unlimited tokens before the state update occurs.
A malicious contract was deployed with a custom onERC721Received() function that calls back into mintEgg() during the receive hook:
• An attacker can mint multiple NFTs in a single transaction.
• Total supply tracking becomes inaccurate.
• Potentially breaks rarity mechanics or rewards tied to unique token counts.
• Can be used to farm eggs unfairly or spam the system.
• Manual code review
• Foundry tests to simulate reentrant minting
Update the mintEgg() function to increment totalSupply before the _mint() call to prevent reentrancy:
Additionally:
• Consider using ReentrancyGuard for further protection.
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.