In LinearDistributionIntervalDecrease
the _calculateFullPeriodReward
carries out calculation that can result in underflow due to subtracting with a larger value that will gives negative number and as a result will underflow.
Lets consider the value for variable ip
In the above expression, the term 15 * 5 evaluates to 75, and subtracting this from 20 - 10 results in -65
. Since negative value cannot be assign to uint256, the compiler throws an error.
Running a simple test clearly gives compiler error :
In Solidity, perform arithmetic operations involving negative numbers, the result can be a negative number, which cannot be assigned to a uint256 because unsigned integers cannot represent negative values.
This will cause the method to revert due to underflow.
To fix the problem of underflow as a result of negative number is to ensure that the expression does not evaluate to a negative number.
The recommendation to avoid the error is to rearrange the terms so that the subtraction happens on result of multiplied value that will be greater and would prevent the result from being negative.
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.