Dria

Swan
NFTHardhat
21,000 USDC
View results
Submission Details
Severity: high
Valid

Underflow in std deviation calculation

Summary

The variance function in the Statistics.sol contract is susceptible to underflow. This will break the LLMOracleCoordinator contract, breaking the validation process.

Vulnerability Details

The variance function in the Statistics.sol contract is used to calculate the variance of a dataset. It calculates the mean, and then the difference from the mean.

mean = avg(data);
uint256 sum = 0;
for (uint256 i = 0; i < data.length; i++) {
uint256 diff = data[i] - mean;
sum += diff * diff;
}

The issue is that the diff is calculated as data[i] - sum, all of which are uint256 values. Thus this can lead to a situation where the data is lower than the mean, in which case this will be negative and will thus revert since its uint256.

So the stddev function, which calls the variance function will revert in such a situation, breaking the oracle validation process. This will prevent the LLM agents from finalizing the validation.

Impact

The stddev function will revert with any real dataset, since any differences in the values will evaluate to a negative result, resulting in an underflow. This also breaks the LLM agent validation process.

Tools Used

Manual Review

Recommendations

Use int256 for calculating the difference

Updates

Lead Judging Commences

inallhonesty Lead Judge 12 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Underflow in computing variance

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.