fix: add zero-division guards in math.rs and share conversion - #193
Open
BABAT-CODE wants to merge 2 commits into
Open
fix: add zero-division guards in math.rs and share conversion#193BABAT-CODE wants to merge 2 commits into
BABAT-CODE wants to merge 2 commits into
Conversation
- Add safe_div_u128() with explicit zero-denominator guard - Add safe_mul_u128() for overflow-safe u128 multiplication - Add shares_to_amount(pool, member_shares, total_shares) helper that returns DivisionByZero when total_shares == 0 instead of panicking — guards the rounding edge case in vault/pool payouts - Replace unsafe (net_u.saturating_mul(w)/total_weighted) in trigger_payout with math::shares_to_amount to propagate the error cleanly instead of panicking the contract - Add comprehensive unit tests for all new helpers (happy path, zero denominator, overflow, single-member full-pool, etc.) Fixes: HIGH security issue — division by zero in share conversion could permanently lock funds if total_shares hits zero
Contributor
|
You did nothing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes: HIGH security issue — division by zero in share conversion
could permanently lock funds if total_shares hits zero
closes #114