Description
`EggHuntGame::eggFindThreshold` is the percentage chance for hunting the egg. but there is missing check for setting the threshold value. It can be set to `zero`, as the result no player can hunt the egg and get nft. due to the logic in `searchForEgg` function.
```javascript
@> if (random < eggFindThreshold) {
```
as the result of that, no random value exist so that it can be less than zero for `uint256`.
Impact
No one is able to get egg or nft anytime will compromise the protocol.
Proof of Concept
Add this test into `EggHuntGameTest.t.sol` file.
```javascript
function testSetEggFindThresholdCanBeZero() public {
// Only the owner should be able to set the egg find threshold.
vm.prank(alice);
vm.expectRevert(abi.encodeWithSelector(OwnableUnauthorizedAccount.selector, alice));
game.setEggFindThreshold(50);
// Setting a threshold above 100 should revert.
vm.expectRevert("Threshold must be <= 100");
game.setEggFindThreshold(101);
// Valid change by the owner.
game.setEggFindThreshold(0);
assertEq(game.eggFindThreshold(), 0);
}
```
Recommendations
The protocol should implement the check to check the value of threshold.
Add this code into `EggHuntGame::setEggFindThreshold` function.
```diff
+ function setEggFindThreshold(uint256 newThreshold) external onlyOwner {
+ require(newThreshold <= 100 && newThreshold > 9, "Threshold must be <= 100 and > 9");
```
As we are calculating random number by taking modular operation with `100`, The number we get for random will be of `two digits`, So there is no meaning of setting the value less than `ten`.