ci: Add value-conservation invariant suite for the constant-sum curve#3
Open
hunterinvariants wants to merge 1 commit into
Open
Conversation
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.
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.solsetUp pattern — the constant-sum design intentionally rejects native v4 liquidity ("No v4 Liquidity allowed"), so the standardDeployers.initPoolAndAddLiquidityroute doesn't apply. The suite usesmanager.initialize+hook.addLiquiditydirectly, matching your existing test.What it checks
Two universal value-conservation properties under invariant fuzzing:
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.invariant_callbacks_reject_non_poolmanager— every hook callback reverts unless thePoolManageris the caller. Catches the missing-onlyPoolManagerguard 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
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
.t.sol+ one workflow yaml).Honest framing
custom-curvearchetype where the auto-generator falls back to hand-config — this PR is the worked example.Feel free to close if not useful — no hard feelings.