fix: validate negative TAO amounts in staking#7
fix: validate negative TAO amounts in staking#7OpenSourceSoul wants to merge 1 commit intoone-covenant:mainfrom
Conversation
Prevent negative TAO amounts from causing u64 overflow when converted to RAO. Previously, a negative value like -1.0 would produce a massive u64 value (close to u64::MAX) due to how floating point to integer conversion works in Rust. Changes: - Add validation in new_tao() to reject negative amounts - Return Result type instead of Self for error handling - Update docstring examples to use unwrap() - Add tests for negative amount rejection and zero amount handling
WalkthroughThe Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
|
hi! @distributedstatemachine check please |
Problem
StakeParams::new_tao()accepted negative TAO amounts without validation. When a negative f64 is cast to u64, it produces a massive value (close to u64::MAX), causing incorrect staking amounts.Solution
new_tao()Result<Self, BittensorError>for proper error handlingChanges
bittensor-rs/src/extrinsics/staking.rs: 48 insertions, 20 deletionsThis prevents users from accidentally staking massive amounts when passing negative values.
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.