Summary
A security vulnerability was identified in the searchForEgg() function where an external call to the NFT contract's mintEgg function could potentially lead to unintended behavior or state inconsistencies. While the contract follows the Checks-Effects-Interactions pattern, the external dependency on the NFT contract introduces risks that need to be addressed.
Vulnerability Details
Location: EggHuntGame.sol, searchForEgg() function
Risk Level: Medium
Description: The contract makes an external call to eggNFT.mintEgg(msg.sender, eggCounter) after updating local state, which could be affected by unexpected behavior in the NFT contract.
Root Cause
The vulnerability stems from the external dependency on the NFT contract's behavior. While the current implementation properly updates state before making the external call, there are several potential risks:
The NFT contract could have its own vulnerabilities
The mint operation could fail unexpectedly
State inconsistencies could occur if the mint fails
The NFT contract might have reentrancy vulnerabilities
Impact
If exploited, this vulnerability could lead to:
Inconsistent game state
Failed egg minting operations
Potential loss of funds
Tools Used
Foundry
Solidity compiler
Ethers.js for testing utilities
Secure Implementation with Error Handling
This implementation adds proper error handling for the external call to mintEgg. It uses the low-level call syntax to capture both the success status and return data, ensuring that any failure in the NFT contract is properly handled and doesn't leave the game contract in an inconsistent state
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.