Summary
the ( mean - generationDeviationFactor * stddev ) will revert if the value of mean is less than generationDeviationFactor * stddev.
Vulnerability Details
In the LLMOracleCoordinator::finalizevalidation
the if check will revert in certain condition.
if the value of mean is less than generationDeviationFactor * stddev than it will revert.
https://github.com/Cyfrin/2024-10-swan-dria/blob/c8686b199daadcef3161980022e12b66a5304f8e/contracts/llm/LLMOracleCoordinator.sol#L368
if (generationScores[g_i] >= mean - generationDeviationFactor * stddev) {
_increaseAllowance(responses[taskId][g_i].responder, task.generatorFee);
}
Impact
the transaction will revert in certain condition cause the improper working of function.
Tools Used
manual review
Recommendations
calculate the absolute diff and store it in diff variable and then compare:-
https://github.com/Cyfrin/2024-10-swan-dria/blob/c8686b199daadcef3161980022e12b66a5304f8e/contracts/llm/LLMOracleCoordinator.sol#L368
- if (generationScores[g_i] >= mean - generationDeviationFactor * stddev) {
- _increaseAllowance(responses[taskId][g_i].responder, task.generatorFee);
- }
+uint256 threshold = mean >= generationDeviationFactor * stddev
+ ? mean - generationDeviationFactor * stddev
+ : generationDeviationFactor * stddev - mean;
+ if (generationScores[g_i] >= threshold) {
+ _increaseAllowance(responses[taskId][g_i].responder, task.generatorFee);
+ }