A vulnerability exists in the variance()
function where an underflow
can occur if any element
in the data
array is smaller than the calculated mean
. This results in a revert
due to Solidity’s checked arithmetic introduced in versions ^0.8.0
and above, which does not permit underflows
in unsigned integers (uint256
).
The function calculates variance
by iterating through an array data
and computing the squared difference between each element
and the mean
.
However, when an element
in data is less than the mean
, the subtraction operation leads to an underflow
, causing a revert.
Scenario:
Consider an array with values such as data = [2, 5, 4, 9]
.
Mean is calculated as 20/4 = 5
When iterating over the array, for data[0] = 2
, the difference 2 - 5
results in a negative
value.
This underflow
causes an immediate revert
, halting execution.
The underflow
vulnerability in the variance function causes reverts
if any value in data is less than the mean, effectively making the function unreliable.
Manual Review
Use absolute difference:
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.