Skip to content
Business logic Audit finding Intermediate

incorrect condition for the iterative update of Equation 34

The code's loop condition for iterative gradient descent uses a strict greater-than comparison, so it stops when the maximum gradient equals the threshold, whereas the whitepaper requires continuing until the value is less than 0.001. This leads to incorrect computation of the listening coefficient.

volodya Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-06-allora-judging/issues/26

Found by

volodya

Summary

incorrect condition for the iterative update of Equation 34

Vulnerability Detail

According to whitepaper, iterative process should be done until value would not be less 0.001 < 0.001

But in the code it will stop at 0.001maxGradientThreshold

Go
	for maxGradient.Gt(maxGradientThreshold) && i < gradientDescentMaxIters {
		copy(oldCoefficients, coefficients)

rewards/rewards_internal.go#L457

Impact

Incorrect computation for listening coefficient.

Code Snippet

Tool used

Manual Review

Recommendation

Diff
-	for maxGradient.Gt(maxGradientThreshold) && i < gradientDescentMaxIters {
+	for maxGradient.Gte(maxGradientThreshold) && i < gradientDescentMaxIters {
		copy(oldCoefficients, coefficients)

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/allora-network/allora-chain/pull/450

The original report as published on Sherlock, by volodya. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The loop condition uses `>` instead of `>=`, causing the iteration to stop when the gradient equals the threshold rather than continuing until it is strictly less than the threshold.

Impact

The listening coefficient is computed incorrectly, which could affect reward calculations.

What the attacker needed

None

The fix

The condition was changed from `>` to `>=` to match the whitepaper, and the protocol team fixed this issue.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This is a smart contract audit finding about a loop that repeats a calculation until a value gets small enough. The code stops one step too early because it checks if the value is greater than a threshold instead of greater than or equal to it, so the final result is slightly off.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by volodya

View all

11 more disclosed reports, best first.

More from Allora

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.