Skip to content

feat: implement checked safe math for i128 in soroban contracts - #306

Merged
YaronZaki merged 2 commits into
Quantarq:mainfrom
Emelie-Dev:fix/issue-common-math
Jul 28, 2026
Merged

feat: implement checked safe math for i128 in soroban contracts#306
YaronZaki merged 2 commits into
Quantarq:mainfrom
Emelie-Dev:fix/issue-common-math

Conversation

@Emelie-Dev

Copy link
Copy Markdown
Contributor

Title: feat: add checked math for i128 in soroban contracts

Description:
This pull request addresses the silent loss risk associated with unchecked i128 math operations in our Soroban smart contracts.

  • Introduces SafeMathI128 trait wrapping i128 for safe_add, safe_sub, safe_mul, and safe_div.
  • Automatically panics using Soroban's panic_with_error! mapped to explicit mathematical contract errors.
  • Adds property-based testing (via proptest) for fuzzing bounds up to 1 million combinations natively protecting from boundaries overflow/underflow.

Related Issues:

  • Dependencies resolved post #51 architecture.

closes #242

@YaronZaki YaronZaki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@YaronZaki
YaronZaki merged commit 86d906a into Quantarq:main Jul 28, 2026
5 checks passed
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.

Safe fixed-point (i128) math wrappers

2 participants