From 9e3a63944e5253aec14c8425495f603cbc999333 Mon Sep 17 00:00:00 2001 From: a1 agent Date: Mon, 22 Jun 2026 21:14:15 +0000 Subject: [PATCH] =?UTF-8?q?test(move):=20assert=20staking=20=CE=A3claims?= =?UTF-8?q?=20=E2=89=A4=20=CE=A3deposited=20(reward=20conservation)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The staking-pool audit verified via a 20k-trial fuzz that stakers can never collectively claim more than was deposited (accrue floors the per-share delta but banks the full amount into pending, so truncation strands dust — never over-pays), but no committed test asserted Σclaims ≤ Σdeposited directly. Pin it: a 2:1 stake split + an odd dividend (so the per-share division leaves a remainder), both stakers claim, assert the sum ≤ deposited. Closes the last coverage gap the audit campaign flagged (after touch_below #735 and WICK supply #741). Passes; no source change. Co-Authored-By: Claude Opus 4.8 (1M context) --- move/tests/wick_staking_tests.move | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/move/tests/wick_staking_tests.move b/move/tests/wick_staking_tests.move index ef21aa3..33f228a 100644 --- a/move/tests/wick_staking_tests.move +++ b/move/tests/wick_staking_tests.move @@ -910,3 +910,50 @@ fun cannot_set_insurance_to_zero() { clk.destroy_for_testing(); sc.end(); } + +#[test] +/// Conservation: stakers can NEVER collectively claim more than was deposited. +/// The staking audit verified this via a 20k-trial fuzz (accrue floors the +/// per-share delta but banks the FULL amount into pending, so truncation only +/// strands dust — never over-pays), but no committed test asserted +/// Σclaims ≤ Σdeposited directly. Pin it with a 2:1 stake split + an odd +/// dividend so the per-share division leaves a remainder (the dust path). +fun claims_never_exceed_deposited_dividends() { + let mut sc = ts::begin(ALICE); + let (mut pool, scap, mut ts_, tcap, clk) = init_state(&mut sc); + + ws::test_record_loss(&mut pool, BOB, 1_000_000_000_000); + ws::test_record_loss(&mut pool, CAROL, 1_000_000_000_000); + + // 2:1 stakes — the split has a remainder (3 doesn't divide an odd deposit). + let bob_wick = mint_wick_to(&mut ts_, BOB, 2_000_000, &clk, &mut sc); + sc.next_tx(BOB); + let mut bob_receipt = ws::stake(&mut pool, bob_wick, &clk, sc.ctx()); + + let carol_wick = mint_wick_to(&mut ts_, CAROL, 1_000_000, &clk, &mut sc); + sc.next_tx(CAROL); + let mut carol_receipt = ws::stake(&mut pool, carol_wick, &clk, sc.ctx()); + + let deposited = 1_000_001; // odd → can't be split exactly across 3M stake + ws::accrue_dividends(&mut pool, fee_balance(deposited, &mut sc)); + + sc.next_tx(BOB); + let bob_coin = ws::claim_dividends(&mut bob_receipt, &mut pool, sc.ctx()); + sc.next_tx(CAROL); + let carol_coin = ws::claim_dividends(&mut carol_receipt, &mut pool, sc.ctx()); + + // The load-bearing invariant: Σclaims ≤ Σdeposited (the rest is dust stranded + // in pending, claimable on a later accrue — never minted out of thin air). + assert!(bob_coin.value() + carol_coin.value() <= deposited, 0); + + test_utils::destroy(bob_coin); + test_utils::destroy(carol_coin); + test_utils::destroy(bob_receipt); + test_utils::destroy(carol_receipt); + test_utils::destroy(pool); + test_utils::destroy(scap); + test_utils::destroy(ts_); + test_utils::destroy(tcap); + clk.destroy_for_testing(); + sc.end(); +}