Skip to content
Business logic Audit finding Advanced

Mean-Based Outlier Detection Vulnerability Allows Single Node to Sabotage Consensus

The outlier detection filter uses the arithmetic mean instead of the median, allowing a single malicious node to skew the mean and standard deviation with an extreme value. This can cause honest values to be marked as outliers, leading to consensus failure or manipulation of the final output.

0xNirix Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-12-seda-protocol-judging/issues/230

Found by

0xNirix

Summary

Using the arithmetic mean instead of median in the standard deviation filter can cause a consensus failure for the entire protocol as a malicious nodes can manipulate the mean/ standard deviation calculation by submitting appropriate values. And if that is not possible based on distribution of values, it can also strategically alter which values are considered part of the consensus set, thereby manipulating the final output value even if later median is used for the final calculation.

Root Cause

The choice to use arithmetic mean in the FilterStdDev.ApplyFilter at https://github.com/sherlock-audit/2024-12-seda-protocol/blob/main/seda-chain/x/tally/types/filters.go#L225 implementation is problematic as it makes the outlier detection mechanism vulnerable to extreme value manipulation. In detectOutliersBigInt(), the code calculates the mean of all values (mean := sum.Div(sum, n)) rather than the median, making the system susceptible to skewing by a single extreme value.

Notably, there is a comment in the code that suggests median should have been used:

Go
// ApplyFilter applies the Standard Deviation Filter and returns an
// outlier list. A reveal is declared an outlier if it deviates from
// the median by more than the sample standard deviation multiplied
// by the given sigma multiplier value.

This comment explicitly states that values should be compared against the median, but the implementation actually compares them against the mean, creating potential for this vulnerability.

Internal Pre-conditions

NA

External Pre-conditions

NA

Attack Path

  1. Honest nodes submit values within a reasonable range
  2. Malicious node submits an extreme value close to the maximum allowed by the data type (e.g., close to maxUint64)
  3. Mean calculation is severely skewed toward the extreme value
  4. Standard deviation calculation is affected
  5. Some honest values are marked as outliers since they deviate significantly from the skewed mean
  6. Consensus check fails as less than 2/3 of nodes are considered non-outliers OR the new mean/median output is incorrect

Impact

The protocol suffers consensus failure, preventing it from finalizing the current round of data aggregation. The attacker gains the ability to block consensus without requiring control of 1/3 of the network, circumventing the protocol's fault tolerance guarantees. More importantly, even when consensus doesn't completely fail, the attacker can strategically manipulate which values are included in the final consensus set. This allows them to shift the final output value (regardless of whether mean or median is used for the final calculation) by selectively excluding honest node contributions that don't align with their desired outcome.

PoC

The vulnerability can be demonstrated using Chebyshev's inequality, which states: P(|X - μ| ≥ kσ) ≤ 1/k² Where:

X is a random variable with mean μ and standard deviation σ k is a positive real number

According to Chebyshev's inequality, up to 1/k² values can be outside k standard deviations from the mean. This means if sigma multiplier (k) is set to 1.5, up to 44% of values can be legitimately outside this range. A malicious node or group of malicious nodes can exploit this in two critical ways: a) They can strategically submit values that push upto 44% of values outside the acceptable range, causing consensus failure since consensus requires 2/3 (or approximately 67%) of nodes to agree. By pushing upto 44% of values outside the range, they ensure that less than the required threshold remains, effectively blocking consensus. b) Alternatively if above is not possible due to distribution, they can selectively target specific honest values to push out of the consensus set while allowing others to remain. This strategic exclusion lets them manipulate the final output value, whether it's calculated as a mean or median, since they've already controlled which values are included in that calculation.

Mitigation

No response

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/sedaprotocol/seda-chain/pull/541

The original report as published on Sherlock, by 0xNirix. 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 outlier detection filter calculates the mean instead of the median, making it vulnerable to skewing by a single extreme value.

Impact

The attacker can block consensus without controlling 1/3 of the network, and even when consensus does not fail, they can manipulate which values are included to shift the final output.

What the attacker needed

Malicious node can submit values; consensus uses standard deviation filter

The fix

The issue was fixed by the protocol team in a pull request.

How it was found

  1. Honest nodes submit values within a reasonable range.
  2. Malicious node submits an extreme value close to the maximum allowed by the data type.
  3. Mean calculation is severely skewed toward the extreme value.
  4. Standard deviation calculation is affected.
  5. Some honest values are marked as outliers since they deviate significantly from the skewed mean.
  6. Consensus check fails as less than 2/3 of nodes are considered non-outliers or the new mean/median output is incorrect.

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.

In many blockchain systems, nodes submit data and the system must agree on a single value. To ignore bad data, it filters out values that are too far from the average. But if the average is easily skewed by one huge number, a single bad node can make good nodes look like outliers. This report shows that using the average instead of the middle value (median) lets one node disrupt agreement.

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 0xNirix

View all

10 more disclosed reports, best first.

More from SEDA Protocol

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.