Remove math.sqrt from ballot calculation#191
Conversation
WalkthroughThis PR removes unsafe math.Sqrt usage from the oracle ballot standard deviation calculation. The StandardDeviation function is refactored to use variance.ApproxSqrt() with error handling instead of the manual float parsing and math.Sqrt approach. Unused imports (fmt, math, strconv) are removed from the ballot.go file. The corresponding test case is updated to use tolerance-based assertions with a delta of 2e-7 instead of exact equality checks. Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
🔇 Additional comments (3)
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 removes the unsafe usage of Go's standard library math.Sqrt function in the oracle ballot standard deviation calculation, replacing it with the Cosmos SDK's built-in ApproxSqrt() method. This addresses issue #188 and improves the safety and determinism of the calculation.
Key changes:
- Replaced float conversion and
math.SqrtwithApproxSqrt()in the standard deviation calculation - Updated the test to use tolerance-based comparison appropriate for the approximation function
- Added changelog entry documenting the fix
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 | Replaced unsafe math.Sqrt with SDK's ApproxSqrt() method for calculating standard deviation |
| x/oracle/types/ballot_test.go | Updated test to use tolerance-based comparison instead of exact equality to accommodate the approximation |
| CHANGELOG.md | Added entry documenting the removal of unsafe math.Sqrt usage |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
This removes the unsafe math.sqrt from ballot calculation.
This solves issue #188
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Tests are passing