The Statistics library is used to compute standard deviation as part of the task validation process. This computation is essential, and needed for finalizing task validation in the protocol.
The variance calculation used in the calculation of standard deviation in the Statistics library contains an arithmetic underflow vulnerability. The vulnerable code in the variance()
function looks like this:
When calculating the difference from the mean, the code performs data[i] - mean
without checking if data[i]
is less than mean
. In statistical calculations, it's common and expected for individual data points to be both above and below the mean. When data[i]
is less than the mean, the subtraction will underflow due to Solidity's unsigned integer arithmetic.
This underflow causes the variance()
function to revert, which in turn causes finalizeValidation()
to fail. Since task validation is a core protocol function, this effectively renders the entire protocol unusable.
High. The vulnerability leads to a complete denial of service of the protocol's core functionality, as task validation becomes impossible when the variance calculation reverts.
High. Statistical distributions naturally include values both above and below the mean. It's virtually guaranteed that in any real-world dataset, some values will be below the mean, triggering the underflow condition.
A task is submitted to the protocol
Multiple validators submit their data points: [10, 15, 20] (the score of the validator are in the range : [0e18, 1e18])
The mean is calculated as (10 + 15 + 20) / 3 = 15
During variance calculation:
For data[0] = 10: 10 - 15 causes underflow
Function reverts before completing
Task validation fails due to the revert
Protocol becomes unusable as no tasks can be validated
The variance calculation should be modified to handle differences properly by using signed integer types. Here's a recommended fix:
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.