To calculate variance when variance
function called, data[i] - mean
will cause underflow error when mean is greater than any element. That means this can only work when all elements are equal otherwise every time mean will be greater and this will revert not calculating the variance properly.
We should use absolute difference instead of just subtracting. Since data[i] - mean
can be positive or negative.
https://github.com/Cyfrin/2024-10-swan-dria/blob/main/contracts/libraries/Statistics.sol#L22
Since this function is used in stddev
deviation function which is used in LLMOracleCoordinator::finalizeValidation
function to calculate standard deviation of scores which is very crucial function in finalizing validation process.
Due to this finalizeValidation
will revert whenever all scores are not equal and their mean is between them causing the function in DOS.
To run this test first run forge init --force
command then forge test --mt testVariance
.
This test will pass proving that variance is reverting.
Foundry, Manual Review
Use their absolute difference by subtracting lower value from higher instead of just subtracting mean from data[i].
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.