Bug: Missing Stake-Weighted Aggregation in Consensus Score Calculation #32
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug: Missing Stake-Weighted Aggregation in Consensus Score Calculation
Summary
The
update_leaderboardfunction incrates/platform-server/src/db/queries.rscalculates consensus scores using a simple arithmetic mean instead of the documented stake-weighted average. This undermines the security model and doesn't match the documented behavior.Severity
High - Security and correctness issue
Location
crates/platform-server/src/db/queries.rsDescription
The consensus score calculation was using a simple arithmetic mean:
However, the README and documentation specify that scores should be aggregated using stake-weighted averaging with outlier detection:
Where:
Impact
Expected Behavior
According to
README.md(lines 254-270):Actual Behavior
The code was calculating a simple arithmetic mean without:
Root Cause
Evaluationstruct doesn't include validator stake informationSolution
Implemented
calculate_stake_weighted_consensus_score()function that:sum(stake * score) / sum(stake)Code Changes
Before
After
Testing Recommendations
Related Documentation
README.mdlines 152-180 (Validator operations)README.mdlines 252-279 (Score Aggregation)AGENTS.mdline 87 (Stake-weighted averaging)Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.