Skip to content

fix: add zero-division guards in math.rs and share conversion - #193

Open
BABAT-CODE wants to merge 2 commits into
cocor-tech:masterfrom
BABAT-CODE:fix/zero-division-guard
Open

fix: add zero-division guards in math.rs and share conversion#193
BABAT-CODE wants to merge 2 commits into
cocor-tech:masterfrom
BABAT-CODE:fix/zero-division-guard

Conversation

@BABAT-CODE

Copy link
Copy Markdown
Contributor
  • 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

closes #114

- 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
@oraimoitel

Copy link
Copy Markdown
Contributor

You did nothing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: add invariant tests for circle state transitions

2 participants