Feat/borrow interest overflow error#135
Merged
Smartdevs17 merged 9 commits intoSmartdevs17:mainfrom Mar 24, 2026
Merged
Conversation
…ests for retries and 4xx; fix Rust CI (fmt/clippy/tests) in stellar-lend
|
@Abidoyesimze is attempting to deploy a commit to the smartdevs17's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@Abidoyesimze Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Summary
Make interest conversion overflow explicit in calculate_interest:
Change return type to Result<i128, BorrowError>.
Convert with to_i128().ok_or(BorrowError::Overflow)? instead of capping to i128::MAX.
Propagate/handle the new error at call sites (borrow, repay, and get_user_debt).
Add tests to validate overflow behavior and keep non-overflow math checks intact.
Motivation
Previously, an I256→i128 conversion overflow would silently clamp to i128::MAX, masking arithmetic errors and potentially distorting accounting. This change makes overflow explicit, preventing silent state corruption.
What’s Changed
stellar-lend/contracts/lending/src/borrow.rs
calculate_interest(...) -> Result<i128, BorrowError>
Use ok_or(BorrowError::Overflow)? on I256→i128 conversion.
Propagate errors in borrow and repay.
Keep get_user_debt non-fallible by ignoring overflow (preserves method signature).
Tests
lending/src/borrow_test.rs: add test_interest_overflow_returns_error.
lending/src/math_safety_test.rs: adapt to Result, keep a non-overflow assertion path.
Acceptance Criteria
Overflow in interest conversion returns BorrowError::Overflow.
Tests verify overflow is surfaced and callers propagate the error correctly.
No panics on overflow.
closes #16