From f4e17265edeb8400143c78bb40b6d8f6a28661ba Mon Sep 17 00:00:00 2001 From: a1 agent Date: Tue, 23 Jun 2026 00:31:18 +0000 Subject: [PATCH] =?UTF-8?q?fix(move):=20block=20opens=20into=20an=20alread?= =?UTF-8?q?y-rugged=20round=20=E2=80=94=20post-rug=20ride=20drain=20(v4.27?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The rug is the ENTIRE house edge: the touch payout against ±barriers over a full round is player-positive WITHOUT it (touch ~79% vs ~57% break-even — −37.67% house edge no-rug per simulate_v4_house_edge.py). A round rugs at most once; after RugFiredV4 fires at segment R the round has ZERO remaining rug risk. But open_segment_ride_v4 had NO guard against opening into a rugged round, and decide_settlement routes only pre-rug rides (entry <= rugged_seg) to EXPIRED_LOSS — so a ride opened at entry > R settles on the rug-free path and keeps the full touch upside: positive player EV. An attacker watches the public RugFiredV4 event and opens max-stake post-rug (~45% of rounds qualify, ~+$1.50/ride), draining the vault. Breaks NO single-tx invariant (conservation/idempotency/double-pay all hold) — a probabilistic mispricing the correctness suite can't catch. Found by a fresh economic/MEV adversarial audit pass. Fix: assert !is_rugged(market) in open_segment_ride_v4, right after ensure_round_current (which clears the live rugged_at_segment on a round-roll, so opens resume next round). The round is HALTED after a rug; the frontend already refuses post-rug opens, so this closes the direct-MoveCall / modified-client bypass. + regression test open_into_an_already_rugged_round_aborts (real post-rug open → EMarketRugged). Reframed post_rug_open_keeps_its_win (was mislabeled an "honest" bet) to document it AS the exploit the guard prevents + decide_settlement boundary defense-in-depth. Suite 696/696. Awaits the v4.27 deploy (publisher keys) to go live, alongside #683/#694/#733. Co-Authored-By: Claude Opus 4.8 (1M context) --- move/sources/segment_market_v4.move | 14 +++++++ move/tests/segment_market_v4_tests.move | 52 +++++++++++++++++++++---- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/move/sources/segment_market_v4.move b/move/sources/segment_market_v4.move index 0151f1e..0b32e66 100644 --- a/move/sources/segment_market_v4.move +++ b/move/sources/segment_market_v4.move @@ -117,6 +117,9 @@ const EArchiveAlreadyRecorded: u64 = 24; /// the live rugged state with a fresh `option::none()` which is unsafe /// mid-round. Re-disable would need its own entry. const ERugAlreadyEnabled: u64 = 25; +/// open_segment_ride_v4 refused: this round already rugged (MARKET HALT). Opening +/// post-rug would settle on the rug-free, player-positive path — a vault drain. +const EMarketRugged: u64 = 26; // === Settlement kinds === (unchanged from v3) const SETTLEMENT_OPEN: u8 = 0; @@ -881,6 +884,17 @@ public fun open_segment_ride_v4( assert!(market.vault_id == object::id(vault), EWrongMarket); // 2. Lazy-roll the round if needed ensure_round_current(market); + // 2b. Refuse opens into an ALREADY-RUGGED round. The rug is the ENTIRE house + // edge — the touch payout against ±barriers over a full round is player-positive + // WITHOUT it (touch ~79% vs ~57% break-even). A round rugs at most once; after + // RugFiredV4 fires there is ZERO remaining rug risk, and a ride opened at + // entry_segment > rugged_seg settles on the rug-free path (it isn't <= rugged_seg, + // so decide_settlement won't route it to EXPIRED_LOSS) — carrying positive player + // EV: a vault drain an attacker triggers by watching RugFiredV4. The round is + // HALTED after a rug; opens resume next round (ensure_round_current clears + // rugged_at_segment on the roll). The frontend already blocks this; this closes + // the direct-MoveCall / modified-client bypass. + assert!(!is_rugged(market), EMarketRugged); // 3. (v4: NO open-window assert — every segment in the round is open) // 4. Stake range assert!( diff --git a/move/tests/segment_market_v4_tests.move b/move/tests/segment_market_v4_tests.move index 370e260..0aa64ff 100644 --- a/move/tests/segment_market_v4_tests.move +++ b/move/tests/segment_market_v4_tests.move @@ -601,13 +601,51 @@ fun rugged_ride_cannot_escape_via_in_round_touch_held_cross_round() { sc.end(); } -/// Regression (v4.27) — the durable rug read must NOT over-rug: a ride opened -/// AFTER the rug segment (entry > rug_seg) is an honest post-rug bet and keeps -/// its win, even with the durable history present and even closing cross-round. -/// Complement to `rugged_ride_cannot_escape_via_in_round_touch_held_cross_round` -/// (entry ≤ rug_seg → rugged); together they pin the entry boundary under the -/// durable read. Here the rug fired at segment 2 but the ride opened at segment -/// 5 (> 2), touches in-round, and is closed cross-round → TOUCH_WIN. +/// CRITICAL (v4.27 economic audit) — opening into an ALREADY-RUGGED round must +/// abort. The rug is the ENTIRE house edge; once it has fired this round there is +/// ZERO remaining rug risk, so a ride opened at entry > rug_seg settles rug-free +/// and the touch bet is player-positive (payout > escrow) — a vault drain an +/// attacker triggers by watching RugFiredV4 and opening max-stake post-rug. +/// `open_segment_ride_v4` guards this with `EMarketRugged`. +#[test] +#[expected_failure(abort_code = sm4::EMarketRugged, location = wick::segment_market_v4)] +fun open_into_an_already_rugged_round_aborts() { + let mut sc = ts::begin(ALICE); + let (mut vault, vcap, mut market, bots, bcap, upo_obj, pcap, wts, wcap, pool, scap, clk) = + mk_full_world(&mut sc); + sm4::enable_rug(&mut market, 150); + let seed = mint_sui(10_000_000_000, &mut sc); + mv::test_deposit_ride_escrow(&mut vault, seed); + + // Round 0 has ALREADY rugged at segment 2 — the live `rugged_at_segment` flag + // is set, exactly as roll_rug sets it when segment 2 records. The attacker now + // opens at entry 5 (> 2): a post-rug bet carrying the full touch upside with + // NO rug downside. The open MUST abort EMarketRugged. + sm4::test_only_bump_segment_index(&mut market, 5); + sm4::test_only_set_rugged_at_segment(&mut market, 2); + + let stake = 1_000u64; + let r = sm4::open_segment_ride_v4( + &mut market, &mut vault, &bots, + stake, mint_sui(stake * ROUND_DURATION, &mut sc), &clk, sc.ctx(), + ); // ← aborts EMarketRugged + + // Unreached. + sm4::test_only_destroy_ride(r); + teardown_world(vault, vcap, market, bots, bcap, upo_obj, pcap, wts, wcap, pool, scap, clk); + sc.end(); +} + +/// Defense-in-depth complement to the guard above — `decide_settlement`'s durable +/// read is EXACT at the entry boundary. This constructs a post-rug ride +/// ARTIFICIALLY (the rug is recorded into the durable history AFTER the open, so +/// `is_rugged` is false at open and the EMarketRugged guard doesn't fire) purely +/// to pin that a ride at entry > rug_seg is NOT over-rugged by the settlement +/// math: it settles on its true outcome (here an in-round touch → TOUCH_WIN), not +/// a false EXPIRED_LOSS. The open guard — not this path — is what blocks the drain +/// in production; its mirror +/// `rugged_ride_cannot_escape_via_in_round_touch_held_cross_round` +/// (entry ≤ rug_seg → rugged) pins the other side. #[test] fun post_rug_open_keeps_its_win_under_the_durable_read() { let mut sc = ts::begin(ALICE);