Location : contracts/libraries/Statistics.sol
Problem: Solidity only supports integer division, which truncates any fractional part. When calculating the mean (sum / data.length
), this results in precision loss, especially noticeable in arrays where the true mean is a non-integer.
Recommendation: If higher precision is necessary, consider scaling the sum before division or using a fixed-point library to approximate decimal precision. Otherwise, document this limitation clearly.
Tools used: Github and VSC
POC:
Expected Outcome: avgResult
will yield 1 instead of the true mean of 1.333, demonstrating precision loss due to truncation.
Impact: Results in approximations rather than exact values, which might affect statistical calculations relying on high precision, particularly when working with small datasets or when calculating thresholds based on mean or variance.
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.