The function variance()
in Statistics.sol subtracts the average from each number in the array but the type is uint, because of that the function will revert unless all numbers are the same
The function variance()
does a subtraction by iterating on every number on the array and subtracting by the average that was previously calculated
The problem is that uint does not support negative values, because of that all subtractions that result in a negative amount will revert, and since it is the average of the numbers in the array, it will revert if the average is bigger than one of the numbers of the array, because of that, the only case it will not revert is if all numbers in the array are equal, and that is unlikely to happen.
This function is called in the finalizeValidation()
function, which is called in the end of the validate()
function, because of that, almost all calls to validate()
will revert, for this reason I believe it is a high.
Install foundry, create a file in a subfolder in the test folder, and paste this:
All calls to stddev()
and variance()
will revert as expected. The 1e50 limit is to avoid overflows that will fail the test.
Foundry
Cast to int256 when calculating, the multiplication by itself will make the number always positive afterwards:
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.