exp/orderbook: reject negative inputs in exp/orderbook/pools.go#5906
Merged
tamirms merged 2 commits intostellar:mainfrom Feb 18, 2026
Merged
exp/orderbook: reject negative inputs in exp/orderbook/pools.go#5906tamirms merged 2 commits intostellar:mainfrom
tamirms merged 2 commits intostellar:mainfrom
Conversation
…ation Negative xdr.Int64 values wrap to large uint64 values when cast, which would distort liquidity pool payout calculations. Add explicit checks to reject negative reserveA, reserveB, and received/disbursed before the uint64 conversion, consistent with the existing feeBips validation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds defense-in-depth input validation to liquidity pool calculation functions to prevent negative xdr.Int64 values from wrapping to large uint64 values during conversion. While pool reserves and pathfinding calls should never provide negative inputs in practice, this change adds an important safety check to prevent potential issues from int64-to-uint64 conversion wraparound.
Changes:
- Added negative input validation to
CalculatePoolPayoutandCalculatePoolExpectationfunctions - Added comprehensive test coverage for negative input scenarios including edge cases like
math.MinInt64
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| exp/orderbook/pools.go | Added negative input validation checks for reserveA, reserveB, received/disbursed parameters in both CalculatePoolPayout and CalculatePoolExpectation functions |
| exp/orderbook/pools_test.go | Added comprehensive test cases verifying that negative inputs are properly rejected for both pool calculation functions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
leighmcculloch
approved these changes
Feb 18, 2026
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.
PR Checklist
PR Structure
otherwise).
services/friendbot, orallordocif the changes are broad or impact manypackages.
Thoroughness
.mdfiles, etc... affected by this change). Take a look in the
docsfolder for a given service,like this one.
Release planning
CHANGELOG.mdwithin the component folder structure. For example, if I changed horizon, then I updated (services/horizon/CHANGELOG.md. I add a new line item describing the change and reference to this PR. If I don't update a CHANGELOG, I acknowledge this PR's change may not be mentioned in future release notes.semver, or if it's mainly a patch change. The PR is targeted at the next
release branch if it's not a patch change.
What
Negative xdr.Int64 values wrap to large uint64 values when cast, which would distort liquidity pool payout calculations. Add explicit checks to reject negative reserveA, reserveB, and received/disbursed before the uint64 conversion, consistent with the existing feeBips validation.
Why
This is just a defense in depth validation because the function can never be called with negative inputs (pool reserves are always >= 0 ) and path finding will always call the functions with valid inputs.
Known limitations
[N/A]