Summary
The function EggHuntGame.searchForEgg()can be called many times.
Vulnerability Details
The function EggHuntGame.searchForEgg()doesn't set the number that a user can call times,causing attacker can call this function any times.
function searchForEgg() external {
require(gameActive, "Game not active");
require(block.timestamp >= startTime, "Game not started yet");
require(block.timestamp <= endTime, "Game ended");
uint256 random = uint256(
keccak256(abi.encodePacked(block.timestamp, block.prevrandao, msg.sender, eggCounter))
) % 100;
if (random < eggFindThreshold) {
eggCounter++;
eggsFound[msg.sender] += 1;
eggNFT.mintEgg(msg.sender, eggCounter);
emit EggFound(msg.sender, eggCounter, eggsFound[msg.sender]);
}
}
Impact
Attacker can call this function any times until finds the egg.
Tools Used
manureview
Proof Of Code
attacker call the function searchForEgg in a loop until find the egg.
address attacker = makeAddr("attacker");
function testsearchforegganytimes() public {
uint256 duration = 200;
game.startGame(duration);
uint256 previousEggCounter = game.eggCounter();
console2.log("previousEggCounter", previousEggCounter);
vm.startPrank(attacker);
while (true){
game.searchForEgg();
if (game.eggCounter() > 0){
break;
}
skip(1);
}
vm.stopPrank();
uint256 attackereggcounter = game.eggsFound(address(attacker));
console2.log("attackereggcounter", attackereggcounter);
}
Recommendations
Set a number a user can call this function to limit the times entering this function