Due to faulty unsigned math in Statistics.sol variance() - calling variance() or stddev() have a high likelihood of causing an underflow panic.
variance() function in Statistics has a flaw due to the following subtraction:
This means that any time the "mean" output from avg() exceeds any of the used elements in the data array - the output will fall below 0 and cause uint256 to underflow. And because the main goal of Statistics library is to calculation deviation, as soon as there is going to be one, the function will have a high likelihood of failure.
Statistics is used only in finalizeValidation() and the problem can be avoided if:
validation disabled or only one validator choosen for the task
all validator scores do not deviate from each other by more than 1 (there are minor exceptions if most elements are low and equal example: 1, 1, 1, 3 - avg will be 1 and not underflow)
But anything else than the above conditions and the calculations will underflow. This will cause the last oracle to unable to finalizeValidation - loss of gas and
the buyerAgent will not be able to get a getBestResponse due the task never reaching "Completed" status - loss of fees.
Manual review + hardhat tests
Test is a modified "LLMOracleCoordinator.test.ts" - describe("With validation"). Simply replace dummy scores from exactly the same, to any larger deviating ones
As the tests depend on eachother, they will start failing at:
The stack trace of that test looks like this:
We can see it starts at Statistics.sol:22 which is the exact line of the "mean" subtraction.
Take into account that for some elements it can be negative - add explicit handling. Example solution:
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.