Inside Statistics.sol
there is a statistic library for uint256 arrays, numbers are treat as fixed-precision floats. Inside this library stddev
function responsible to compute the standard deviation of the data. This computes variance, and takes the square root. Inside this square root function there is problem.
This takes a uint256 as input and returns a uint256. But because of decimal deviation the return value will be 9 decimal places rather than 18. This will cause the validators and generators to receive incorrect rewards or none at all.
Description
The LLMOracleCoordinator::finalizeValidation
function uses Statistics.stddev
to calculate the standard deviation of scores, which is then used to determine if validator and generator scores fall within the "valid" range. Due to the precision loss, the calculated standard deviation is much smaller than expected, often causing validators and generators to receive incorrect scores or none at all.
Inside Statistics::sqrt
library devidating x/z will return 1 decimal place because both has 18 decimal places. This will cause the square root function to return a value with 9 decimal place less than the actual value. Because of this will return a so little number compared to other scores which has 18 decimal places validators and generators will receive none or incorrect rewards because of wrong computation.
Impact
Inaccurate Standard Deviations in statistical calculations, causing validators and generators to receive incorrect scores.
Reward Distribution Errors due to misinterpretation of valid scores, potentially penalizing valid results or rewarding incorrect ones.
Protocol Integrity issues as a result of systematic errors in calculations and reward allocation, leading to participant dissatisfaction and potential financial discrepancies.
Proof of Concepts
Put this example in to remix ide. Deploy it locally and call the function with the input of 4e18. You will get the output of 2e9 which is incorrect.It should be 2e18.
Recommended mitigation
Use a div function to avoid the precision loss.
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.