The EggHuntGame
contract suffers from a potential integer overflow when setting the endTime
variable. Specifically, when calculating the endTime
by adding a specified game duration to block.timestamp
, a substantial duration could cause an overflow.
The endTime
is set as follows:
If duration
is large enough, adding it to block.timestamp
could cause the resulting endTime
to exceed the maximum value allowed for a uint256
(i.e., type(uint256).max
), causing an overflow.
This vulnerability has two potential attack vectors:
Denial of Service (DoS) Attack: By providing an extremely large duration
, an attacker could prevent the game from starting due to the overflow condition, effectively locking the game contract in a state where no game can be initiated.
Unexpected Game End Conditions: If this overflow occurs, it might result in an incorrect or impossibly large endTime
, making it difficult or impossible to end the game.
Below is a PoC demonstrating the overflow vulnerability when setting the endTime
with a dangerously large duration:
Maximum uint256
Value: We use type(uint256).max
to obtain the largest possible uint256
value.
Dangerous Duration Calculation: By calculating the dangerousDuration
as maxUint - block.timestamp + 1
, we ensure that adding this duration to block.timestamp
will cause an overflow, as the result exceeds the uint256
max value.
Expecting a Revert: The test expects the transaction to revert due to the arithmetic overflow (Panic(uint256) 0x11
).
This vulnerability can lead to several issues:
An attacker can exploit this vulnerability by providing an extremely large duration
, causing the endTime
calculation to overflow. This prevents the game from starting, as the contract will revert with an overflow error.
This can effectively lock out the game functionality, preventing any new game sessions from being initiated.
endTime
ValuesIf the overflow occurs without immediate detection (e.g., through insufficient input validation), the game might end prematurely or the endTime
could become an enormous future value, leading to unpredictable game behavior.
This can confuse players and impact game dynamics, as they might not be able to predict when the game will end or whether the game is active.
The game's core functionality relies on accurate time tracking for game sessions. Overflow vulnerabilities like this one undermine the contract's reliability and stability, particularly for players who rely on fair game durations and session timelines.
To prevent the endTime
overflow, we recommend the following fixes:
endTime
Before setting the endTime
, ensure that adding the duration
to block.timestamp
does not cause an overflow. This can be done by checking if the duration
is small enough to avoid exceeding the maximum uint256
value.
Instead of allowing any arbitrary duration
, limit it to a maximum acceptable value. This would prevent durations that are so large they could cause overflows while still allowing flexibility for typical game durations.
The potential overflow in the endTime
calculation can disrupt the normal operation of the game, either by preventing it from starting or by creating erroneous game end conditions. By validating durations before adding them to block.timestamp
or introducing a maximum allowable duration, this vulnerability can be mitigated, ensuring a more secure and predictable game experience.
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.