The statistics calculations relied upon in Dria are vulnerable to precision loss through integer truncation. In some cases, these precision losses are iteratively amplified.
The Statistics library exports a number of operations which are susceptible to precision loss:
The implementation of the average calculation is nearly identical to what we would expect to see in an environment which supports floating point arithmetic.
However, the EVM does not provide a Floating Point Unit (FPU).
In this regard, applying the division operator can result in data truncation, demonstrated by the following toy example:
In practicality, we'd expect (100 + 105 + 102) / 3 to equal 102.333333333. Depending upon the magnitude of values provided via data, precision losses could result in detrimental outcomes.
Even if the precision loss in avg were small, the implementation of variance conspires to magnify these:
Here, we can see that even a small initial precision losses in the avg function will be amplified proportionally to the length ofdata, since this error is taken into account for the square of diff.
We can also see that a final round of precision loss is also applied before returning the result.
Loss of precision resulting in incorrect consensus outcomes.
Manual Review
Broadly, we recommend applying decimal precision when making statistics calculations, i.e.:
However, for Dria we contend that prb-math would be especially beneficial, due to its optimization for scientific calculations:
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.