Skip to content

fix(rust): propagate math errors instead of masking with unwrap_or(ZERO) - #167

Merged
johngrantuk merged 10 commits into
rust-fix-1from
rust-fix-2
Aug 12, 2026
Merged

fix(rust): propagate math errors instead of masking with unwrap_or(ZERO)#167
johngrantuk merged 10 commits into
rust-fix-1from
rust-fix-2

Conversation

@johngrantuk

Copy link
Copy Markdown
Member

Reported issue:

.unwrap_or(U256::ZERO) converts failure into a plausible-looking value

Root 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 in reclammv2_math.rs,
the rest spread across buffers, LBP, QuantAMM and hooks. Two problems compound:

  • It is mostly dead code. mul_down_fixed and mul_up_fixed are declared -> Result<_, PoolError> but have no failing branch — they always return Ok. So the unwrap_or never fires
    and gives false reassurance.
  • Where a helper can fail, zero is the worst possible substitute. Zero is a legal value that
    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 infallible
helpers a non-Result signature or make them actually detect overflow.

@johngrantuk
johngrantuk merged commit b8f08fb into rust-fix-1 Aug 12, 2026
3 checks passed
@johngrantuk
johngrantuk deleted the rust-fix-2 branch August 12, 2026 08:29
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.

1 participant