Skip to content

improve checked consistency - #754

Merged
ozgunozerk merged 1 commit into
mainfrom
checked-math
Jun 24, 2026
Merged

ozgunozerk merged 1 commit into
mainfrom
checked-math

Conversation

@ozgunozerk

@ozgunozerk ozgunozerk commented Jun 24, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #753

PR Checklist

  • Tests
  • Documentation

Summary by CodeRabbit

  • Bug Fixes
    • Improved checked math operations to return None instead of panicking for division overflow cases, including the i128::MIN / -1 edge case.
    • Added coverage for checked floor/ceil division and integer division scenarios to ensure safer behavior on invalid inputs.
    • Clarified internal handling for division-by-zero and overflow conditions in math utilities.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Wad::checked_div_int is updated to use i128::checked_div instead of a manual zero-check with unchecked division, so it now returns None for both division-by-zero and the i128::MIN / -1 overflow case. Comments in checked_div_floor and checked_div_ceil are clarified to describe their respective overflow/zero conditions, and new tests cover the overflow edge case across Wad and i128_fixed_point APIs.

Changes

Checked Division Overflow Handling

Layer / File(s) Summary
Wad::checked_div_int overflow fix and test
packages/contract-utils/src/math/wad.rs, packages/contract-utils/src/math/test/wad.rs
Wad::checked_div_int replaces manual n == 0 guard plus unchecked division with self.0.checked_div(n), returning None on both zero divisor and i128::MIN / -1 overflow; doc comment updated and a new test asserts None for the overflow case.
i128_fixed_point comment clarifications and overflow tests
packages/contract-utils/src/math/i128_fixed_point.rs, packages/contract-utils/src/math/test/i128_fixed_point.rs
Inline comments in checked_div_floor and checked_div_ceil are reworded to specify which overflow and div-by-zero conditions apply per branch; two new tests verify checked_mul_div_floor and checked_mul_div_ceil return None for i128::MIN / -1.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐇 A rabbit once divided wrong,
MIN by negative one — so strong!
Now checked_div returns a None,
No panic fires, the math is done.
Overflow tamed, the warren's safe! 🌿

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR follows the template headers, but it lacks any actual description of the changes or context beyond the issue reference. Add a brief summary of the implementation changes, the problem being fixed, and any relevant context under the description section.
Title check ❓ Inconclusive The title is related to the change, but it's too vague to convey what was actually updated. Rename it to mention the WAD checked-math overflow fix, e.g. "Fix WAD checked division overflow handling".
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The code updates WAD checked division behavior and adds overflow tests, matching the issue's checked-consistency goal.
Out of Scope Changes check ✅ Passed All changes are in WAD checked math comments, overflow handling, and tests, which stay within the issue scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch checked-math

Comment @coderabbitai help to get the list of available commands.

@ozgunozerk
ozgunozerk requested a review from brozorec June 24, 2026 10:37
@ozgunozerk ozgunozerk self-assigned this Jun 24, 2026
@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.64%. Comparing base (031decc) to head (24e2d44).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #754      +/-   ##
==========================================
- Coverage   96.64%   96.64%   -0.01%     
==========================================
  Files          72       72              
  Lines        7610     7607       -3     
==========================================
- Hits         7355     7352       -3     
  Misses        255      255              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ozgunozerk
ozgunozerk merged commit b5065e2 into main Jun 24, 2026
8 checks passed
@ozgunozerk
ozgunozerk deleted the checked-math branch June 24, 2026 12:29
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.

Improve checked consistency for WAD after soroban_sdk support for checked operations

2 participants