test(luvi): fuzz targets with G as the oracle, invariant spec

🔎 Visual review of ed50a232: explainer, review flags and prompts to ask an AI about the change

What

Test-only. Adds native Go fuzz targets that use the synth-aware LUVI index G as an oracle, plus a written spec of the LUVI invariants. Consensus code is untouched.

  • FuzzLuviPoolOps (x/thorchain/luvi_fuzz_test.go): runs random sequences of symmetric and asymmetric adds, withdrawals, RUNE↔️asset swaps, synth mints and burns (single swaps and same-pool double swaps) and donations through the real handlers and swapper. Each op runs in its own cache context. After every op it checks that:
    • nothing panicked;
    • a failed op left state unchanged;
    • luvicheck.Monitor saw no G drop and the LP-unit ledger still balances;
    • no pool is depleted while units are still outstanding;
    • swaps move G only by rounding. For same-pool double swaps this is also checked at the intermediate price, rebuilt from the first swap event.
    • Five seed corpora are in testdata/fuzz/FuzzLuviPoolOps/.
  • FuzzLuviTracker (x/thorchain/types/type_luvi_fuzz_test.go): pure math on random state sequences up to 1e38 units, including deep synth overhang. It checks determinism, exact stationary steps, reversibility (synth round trip), price neutrality, dG == dQ for free synths, and the LUVI* and classic LUVI identities.
  • luvi_fuzz_findings_test.go pins two things the fuzzer found. Neither is live on mainnet: VirtualMultSynthsBasisPoints = 10,000 there, and synth minting and burning are switched off by mimir.
    1. With a virtual depth multiplier above 1 (mocknet uses 2), synth swaps are not G-neutral.
    2. Repeated deposits into a pool in overhang overflow calculatePoolUnits and panic.
  • docs/concepts/luvi-invariant.md states the invariant for each operation. It is linked from docs/SUMMARY.md.
  • handler_test.go: the new setupManagerWith takes any test type (*check.C or testing.TB), so fuzz targets can share the gocheck fixture. setupManagerForTest behaves as before.

How it relates to the other luvi-guards splits

odin/luvi-guards was split into self-contained MRs. This one depends on none of the others, and none of them depend on it:

Split Branch MR
Overflow fix + overhang add guard odin/luvi-guards-overhang !5295 (merged)
LUVI guard, per-pool G accumulator, luvi_loss events odin/luvi-guards-migration / -reward (base commit) not opened yet
LUVI gate on store migrations odin/luvi-guards-migration not opened yet
Reward allocation check odin/luvi-guards-reward not opened yet
Fair LP unit value on pool queries odin/luvi-guards-fairprice not opened yet
Fuzz targets + invariant spec odin/luvi-guards-fuzz this MR

This MR conflicts with !5295 (merged) when both land. TestLuviFindingOverhangAddOverflowPanics pins today's behaviour on develop: the overflow panic. !5295 (merged) fixes that panic, so whichever of the two MRs merges second has to flip the test to the parent's "fixed" version (commit 5eba3e5ffb on odin/luvi-guards). The fixed version checks that the overhang guard rejects the deposit, and that with LUVIOverhangGuard=0 the deposit returns errPoolUnitsOverflow instead of panicking. That commit is left out of this branch because it needs !5295 (merged)'s symbols.

Test plan

  • go test -tags=mocknet ./x/thorchain/... ./test/luvicheck/...
  • go test -tags=mocknet ./x/thorchain/ -run XXX -fuzz FuzzLuviPoolOps -fuzztime 60s: no failures
  • go test -tags=mocknet ./x/thorchain/types/ -run XXX -fuzz FuzzLuviTracker -fuzztime 60s: no failures
  • make lint-ci
  • CI green

🤖 Generated with Claude Code

Edited by Huginn Ai

Merge request reports

Loading
Loading