Eggstravaganza

First Flight #37
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: medium
Invalid

Input Validation Gap in setEggFindThreshold

Summary

The setEggFindThreshold function contains an input validation gap that allows the threshold to be set to 0%, which would make it impossible for players to find eggs, potentially leading to an unplayable game state.

Vulnerability Details

The setEggFindThreshold function in the EggHuntGame contract validates that the new threshold value is not greater than 100, but fails to validate that it is greater than 0:

function setEggFindThreshold(uint256 newThreshold) external onlyOwner {
require(newThreshold <= 100, "Threshold must be <= 100");
eggFindThreshold = newThreshold;
}

This allows the contract owner to set the threshold to 0%, which would make the random number generation in the searchForEgg function always fail the condition:

if (random < eggFindThreshold) {
// Mint egg logic
}

When eggFindThreshold is 0, the condition will never be true because any random number from 0-99 will not be less than 0, making it impossible for players to find eggs.

Proof of Concept

  1. Owner calls setEggFindThreshold(0)

  2. Players call searchForEgg() repeatedly

  3. No eggs are ever found because random < 0 will always be false

Impact

Setting the threshold to 0 would result in:

  • Players wasting gas on transactions that can never succeed

  • Game becoming functionally broken

  • Loss of player trust and engagement

Tools Used

Manual Review

Recommendations

Add a lower bound check to the setEggFindThreshold function:

function setEggFindThreshold(uint256 newThreshold) external onlyOwner {
require(newThreshold > 0, "Threshold must be > 0");
require(newThreshold <= 100, "Threshold must be <= 100");
eggFindThreshold = newThreshold;
}
Updates

Lead Judging Commences

m3dython Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.