Skip to content

Fix/withdrawal overflow#70

Open
AugistineCreates wants to merge 2 commits into
OrbitChainLabs:mainfrom
AugistineCreates:fix/withdrawal-overflow
Open

Fix/withdrawal overflow#70
AugistineCreates wants to merge 2 commits into
OrbitChainLabs:mainfrom
AugistineCreates:fix/withdrawal-overflow

Conversation

@AugistineCreates

Copy link
Copy Markdown

Ths pr closes #42

Summary

This PR resolves a critical overflow bug in WithdrawalLimits::validate where the sum already_withdrawn + amount could overflow an i128, potentially causing a panic or incorrect validation.

Changes Made

  1. Added checked arithmetic

    • Replaced unchecked addition with checked_add.
    • Returns an explicit anyhow! error if overflow occurs ("Withdrawal arithmetic overflow: already_withdrawn + amount exceeds i128").
  2. Updated error handling

    • Adjusted the error message for total‑cap violations to use the safely‑computed new_total.
  3. Added overflow test

    • New test overflow_error_when_sum_exceeds_i128 verifies that an overflow triggers an error instead of panicking.
    • Uses WithdrawalLimits::new(1, i128::MAX, None) to allow the large amount and provoke overflow.
  4. Documentation

    • Inline comments clarify the purpose of the overflow check.

Impact

  • Prevents runtime panics caused by arithmetic overflow.
  • Improves reliability of withdrawal limit validation, especially in misconfigured deployments with extremely large caps.

Verification

  • Ran cargo test – all existing tests pass, and the new overflow test succeeds.
  • The branch fix/withdrawal-overflow is set as the upstream tracking branch and pushed to GitHub.

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.

[LOW] WithdrawalLimits::validate uses unchecked already_withdrawn + amount (i128 overflow at large caps)

1 participant