fix(pair): reject zero and dust-floor belief_price in check_max_spread #1238

Merged
PlasticDigits merged 2 commits from issue/1230 into main 2026-09-12 02:45:14 +00:00

Summary

  • check_max_spread rejects zero and dust-floor belief_price with typed InvalidBeliefPrice (no Decimal div-by-zero panic, no silent L9 skip).
  • G8 treats only a strictly positive belief as a usable floor; Some(0) is not a skip of min_return.
  • Pair execute, HybridSimulation (zero / reciprocal underflow), frontend swap() serializer, L9/integrators/skills, and make verify-issue-1230.

Fixes #1230

Acceptance

  • AC1. belief_price = 0 is a typed contract error, not a panic.
  • AC2. Dust-floor belief (offer * (1/bp) == 0) errors even at max_spread = 1.
  • AC3. Legal belief happy path (commission-in-actual, hybrid belief shortfall) unchanged.
  • AC4. belief_price: None pool-only / hybrid no-belief cases unchanged.
  • AC5. HybridSimulation with belief_price = 0 is a query error, not a VM panic.
  • AC6. L9 / integrators / skills state strictly positive + expected_return >= 1.
  • AC7. Invalid belief does not satisfy G8; min_return remains independent when belief is absent.

Test plan

  • make verify-issue-1230 (13/13, includes retest)
  • dex-common max_spread (zero, reciprocal underflow, dust floor, commission)
  • pair multitest test_swap_belief_price_*
  • Reviewer: confirm dust-floor still errors at 100% max_spread
  • Ops follow-up (not this PR): pair wasm store + migrate
## Summary - `check_max_spread` rejects zero and dust-floor `belief_price` with typed `InvalidBeliefPrice` (no Decimal div-by-zero panic, no silent L9 skip). - G8 treats only a strictly positive belief as a usable floor; `Some(0)` is not a skip of `min_return`. - Pair execute, HybridSimulation (zero / reciprocal underflow), frontend `swap()` serializer, L9/integrators/skills, and `make verify-issue-1230`. Fixes #1230 ## Acceptance - [x] AC1. `belief_price = 0` is a typed contract error, not a panic. - [x] AC2. Dust-floor belief (`offer * (1/bp) == 0`) errors even at `max_spread = 1`. - [x] AC3. Legal belief happy path (commission-in-actual, hybrid belief shortfall) unchanged. - [x] AC4. `belief_price: None` pool-only / hybrid no-belief cases unchanged. - [x] AC5. HybridSimulation with `belief_price = 0` is a query error, not a VM panic. - [x] AC6. L9 / integrators / skills state strictly positive + `expected_return >= 1`. - [x] AC7. Invalid belief does not satisfy G8; `min_return` remains independent when belief is absent. ## Test plan - [x] `make verify-issue-1230` (13/13, includes retest) - [x] dex-common `max_spread` (zero, reciprocal underflow, dust floor, commission) - [x] pair multitest `test_swap_belief_price_*` - [ ] Reviewer: confirm dust-floor still errors at 100% max_spread - [ ] Ops follow-up (not this PR): pair wasm store + migrate
Zero belief_price now returns typed InvalidBeliefPrice instead of a Decimal
div-by-zero panic. Dust-floor belief (expected_return floors to 0) fail-closes
L9 instead of skipping the shortfall check and the material-pool floor.
G8 counts only a usable belief as the slippage floor.
Author
Owner

drain skip: hard-blocked (needs-human / high-risk / human topic); remaining continue

drain skip: hard-blocked (needs-human / high-risk / human topic); remaining continue
Merge origin/main into issue/1230 for PR #1238
All checks were successful
ci/woodpecker/pr/woodpecker gitleaks tracked-tree scan passed locally
6595046666
PlasticDigits deleted branch issue/1230 2026-09-12 02:45:14 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
code/cl8y-dex-terraclassic!1238
No description provided.