fix: Unweighted Oracle Standard Deviation Inflates Reward Band#354
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
WalkthroughThe oracle module's Estimated code review effort: 2 (Simple) | ~10 minutes Changes
Sequence Diagram(s)Not applicable. Related issues: None specified. Related PRs: None specified. Suggested labels: bug, oracle Suggested reviewers: None specified. Poem 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR fixes oracle reward-band inflation caused by calculating ballot standard deviation using an unweighted variance (and dividing by vote count) while the median is stake-weighted. The updated calculation weights each squared deviation by validator power and divides by total voting power, aligning dispersion with the stake-weighted median.
Changes:
- Update
ExchangeRateBallot.StandardDeviationto compute a stake-weighted variance (power-weighted squared deviations / total power). - Add a safeguard returning zero deviation when total ballot power is zero.
- Update the standard deviation unit test to assert the new stake-weighted result.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| x/oracle/types/ballot.go | Switch standard deviation computation to power-weighted variance and divide by total voting power. |
| x/oracle/types/ballot_test.go | Update expected standard deviation value to match the new stake-weighted calculation. |
| CHANGELOG.md | Document the oracle standard deviation fix in the Unreleased “Fixed” section. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
The oracle picks a "median" price weighted by validator stake, but it measured how spread out the votes were without using stake and divided by the number of votes instead of total stake. Because of that mismatch, a few small validators could submit way off prices to make the spread look bigger, which widened the "acceptable" range and let bad votes still count as correct.
The fix weights each vote by its stake when measuring the spread, and divides by total stake so the spread now matches the stake-weighted median.
Type of change
How Has This Been Tested?
go test -tags=test ./x/oracle/...PR Checklist:
make lint-fix