fix(rust): propagate math errors instead of masking with unwrap_or(ZERO) - #167
Merged
Conversation
rust: Align remaining Result<_, String> APIs to PoolError
rust: No panic when current time < last for quant and reclamm
Fix `stable_math::compute_invariant` panics on a zero balance
rust: Renamed → to make clear it returns the fee in the token's raw…
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.
Reported issue:
.unwrap_or(U256::ZERO)converts failure into a plausible-looking valueRoot cause behind most of finding 1, and worth a crate-wide pass.
The crate uses this fallback in 46 places — 16 in
reclamm_math.rs, 15 inreclammv2_math.rs,the rest spread across buffers, LBP, QuantAMM and hooks. Two problems compound:
mul_down_fixedandmul_up_fixedare declared-> Result<_, PoolError>but have no failing branch — they always returnOk. So theunwrap_ornever firesand gives false reassurance.
flows straight into the divisions and subtractions listed above, so a computation that could not
be performed becomes a panic several frames later instead of an error at the point of failure.
Suggested fix: propagate with
?rather than substituting zero; and either give the infalliblehelpers a non-
Resultsignature or make them actually detect overflow.