Arithmetic error breaks functionality of isHappyHorse
within the first 24h after feeding (initializing)
In Solidity, block.timestamp
is a uint256
. If a horse is checked to be happy within the first 24 hours of having been minted, the calculation block.timestamp - HORSE_HAPPY_IF_FED_WITHIN
will result in an arithmetic error. Since the outcome of this calculation would be negative, but uint256
can't be negative, it wraps around, causing the error as per the 0.8.0 Solidity over/underflow prevention update.
The current implementation of the isHappyHorse
function may lead to unexpected behavior and incorrect results when checking the happiness of a horse within the first 24 hours of its creation or feeding due to the arithmetic error.
and run forge test --mt test_calling_IsHappyHorse_within24hFails -vvvvv
Update the comparison condition in the isHappyHorse
function to ensure that the subtraction won't result in a negative value.
This modification ensures that the subtraction won't result in a negative value, preventing potential arithmetic errors, while still maintaining it's intendid functionality.
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.