Skip to content

test(math): add value-conservation proptests for slip-fee and swap-mirror paths - #1518

Open
chiliec wants to merge 1 commit into
galacticcouncil:masterfrom
chiliec:test/stableswap-omnipool-conservation-proptests
Open

test(math): add value-conservation proptests for slip-fee and swap-mirror paths#1518
chiliec wants to merge 1 commit into
galacticcouncil:masterfrom
chiliec:test/stableswap-omnipool-conservation-proptests

Conversation

@chiliec

@chiliec chiliec commented Aug 27, 2026

Copy link
Copy Markdown

What

Adds value-conservation proptests for two hydra-dx-math paths that the existing randomized suite does not currently cover. Test-only — no production code is changed.

Why

While reviewing the math crate I noticed the omnipool slip-fee trade paths are exercised only by fixed numeric unit tests: every proptest in omnipool/invariants.rs passes slip = None, so the randomized per-pool k-conservation check that the no-slip paths are held to (new_reserve * new_hub_reserve >= old_reserve * old_hub_reserve) never runs against a slip trade. The hub-asset (LRNA) conservation of slip trades likewise had no property test.

Changes

  • omnipool/slip_invariants.rs (5 proptests):
    • sell/buy with a non-zero slip fee preserve the per-asset invariant new_reserve * new_hub >= old_reserve * old_hub (the same check omnipool/invariants.rs applies to no-slip trades).
    • slip trades conserve the hub asset: hub_in == hub_out + protocol_fee — the property that guards against LRNA mint/burn across a slip trade.
    • The harness (asset_state, assert_asset_invariant) is copied verbatim from omnipool/invariants.rs so tolerance/rounding semantics match exactly.
  • stableswap/tests/swap_mirror.rs (3 proptests):
    • a swap and its curve-priced mirror do not net a profit for the trader (round-trip is non-positive), asserting rounding always favours the pool.
    • add-then-withdraw of one asset does not net a profit.

Verification

All new tests pass at 4000 proptest cases; the full hydra-dx-math suite is green (399 passed) and cargo fmt is clean. Everything I found holds — these tests document and lock in the existing (correct) conservation behaviour, they do not fix a bug.

First-time contributor here — happy to adjust scope, naming, or the harness placement to match your conventions. Also open to contract / full-time work if useful.

…rror paths

The omnipool slip-fee trade paths (introduced with the dynamic slip fee)
are currently exercised only by fixed numeric unit tests — every proptest
in omnipool/invariants.rs passes slip = None, so the randomized per-pool
k-conservation check (new_reserve * new_hub >= old_reserve * old_hub) that
the no-slip paths are held to never runs against a slip trade.

This adds two proptest modules that close that coverage gap:

- omnipool/slip_invariants.rs (5 tests): sell/buy with a non-zero slip fee
  preserve the per-asset invariant, and slip trades conserve the hub asset
  (hub_in == hub_out + protocol_fee) — the property that guards against
  LRNA mint/burn.
- stableswap/tests/swap_mirror.rs (3 tests): a swap and its mirror do not
  net a profit (round-trip is non-positive for the trader), and
  add-then-withdraw of one asset does not net a profit — both asserting the
  rounding always favours the pool.

All new tests pass at 4000 proptest cases. No production code is changed;
this is test coverage only.
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