Dria

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

Score Validation Breaks Due to Mean Minus Standard Deviation Underflow

Relevant Context

The LLMOracleCoordinator contract implements a validation scoring system where validators provide scores for generated responses. The final validation process in finalizeValidation() uses statistical measures (mean and standard deviation) to determine which scores are valid and which validators/generators should be rewarded.

Finding Description

In the finalizeValidation() function, there is a critical underflow risk when calculating the lower bound for valid scores using the formula score >= _mean - _stddev. The standard deviation can be larger than the mean in cases of high data variability or outliers, which would cause this calculation to underflow.

The validation logic assumes that standard deviation will always be smaller than the mean, but this is mathematically incorrect. For example, consider a set of validation scores [1, 1, 1, 97]:

  • Mean = 25

  • Variance = ((1-25)² + (1-25)² + (1-25)² + (97-25)²) / 4 = 1,800

  • Standard deviation = √1,800 ≈ 42.4

In this case, _mean - _stddev would be 25 - 42.4, causing an arithmetic underflow in Solidity since unsigned integers cannot be negative.

Impact Explanation

High. An underflow in the score validation calculation would cause the transaction to revert, making it impossible to complete the validation process for tasks with high score variability. This effectively breaks the core functionality of the protocol for certain valid input scenarios.

Likelihood Explanation

Medium. While most normal validation scenarios might have scores within a reasonable range, the conditions leading to this underflow are not exotic. They can occur naturally when:

  1. Validators strongly disagree on quality

  2. There are outlier scores

  3. The score distribution is skewed

Recommendation

Modify the score validation logic to handle cases where standard deviation exceeds the mean.

Updates

Lead Judging Commences

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

Underflow in `LLMOracleCoordinator::validate`

Support

FAQs

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