Skip to content

ci: Add value-conservation invariant suite for the constant-sum curve#3

Open
hunterinvariants wants to merge 1 commit into
saucepoint:mainfrom
hunterinvariants:add-value-conservation-invariants
Open

ci: Add value-conservation invariant suite for the constant-sum curve#3
hunterinvariants wants to merge 1 commit into
saucepoint:mainfrom
hunterinvariants:add-value-conservation-invariants

Conversation

@hunterinvariants
Copy link
Copy Markdown

What this adds

A value-conservation invariant suite (test/CounterHunterInvariant.t.sol) for the constant-sum hook, plus a CI workflow that re-runs it on every PR.

Hand-configured to mirror your Counter.t.sol setUp pattern — the constant-sum design intentionally rejects native v4 liquidity ("No v4 Liquidity allowed"), so the standard Deployers.initPoolAndAddLiquidity route doesn't apply. The suite uses manager.initialize + hook.addLiquidity directly, matching your existing test.

What it checks

Two universal value-conservation properties under invariant fuzzing:

  1. invariant_no_free_swap_round_trip — a 0→1→0 round-trip can't return more than it spent. For a 1:1 constant-sum curve, this is the math claim under randomized inputs.
  2. invariant_callbacks_reject_non_poolmanager — every hook callback reverts unless the PoolManager is the caller. Catches the missing-onlyPoolManager guard class.

LP-side invariants (LP add/remove can't profit, LP can always withdraw) don't apply to a hook-managed liquidity model and were dropped from this suite.

Verbatim verdict on this hook

Ran 1 test suite in 136.26s -- 2 passed, 0 failed, 0 skipped
HUNTER_MAX_SWAP_RT_DELTA: 0

Across 12,800 randomized 0→1→0 round-trips at 64 runs × 200 depth, the maximum swapper-extractable margin was 0 wei. The constant-sum curve is round-trip-conservative under fuzz at the wei level.

Cost

  • Two files (one .t.sol + one workflow yaml).
  • ~140 s of CI per PR.
  • Opt-in. Deleting the workflow removes the gate.

Honest framing

  • Fuzzing, not proof — not a full audit. It checks the value-conservation thesis; it doesn't replace human review of the accounting logic.
  • The invariant suite is part of Hunter, a generic regression gate for v4 hooks. Hunter's auto-generator handles standard archetypes; the constant-sum case is a custom-curve archetype where the auto-generator falls back to hand-config — this PR is the worked example.
  • MIT, free, no telemetry, no strings.

Feel free to close if not useful — no hard feelings.

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