fix(stake,v17): restore junior_fee_mult_bps lock + tranche-math Kani proofs dropped in v17 convergence - #144
Conversation
…cccrypto#143) The v17-convergence line forked before two main PRs landed and didn't re-incorporate them. Both are absent from v17; restored here. 1. junior_fee_mult_bps governance lock (originally dcccrypto#127): process_admin_set_tranche_config validated the multiplier range but no longer blocked changing it once junior LPs exist. process_accrue_fees reads the multiplier live (no per-epoch snapshot), so a mid-life change re-prices the junior/senior fee split for already-committed junior LPs (admin can pump before AccrueFees to extract an outsized share, or depress to cut promised junior yield). Restore: reject any change when junior_total_lp() > 0; idempotent same-value rewrites still allowed; freely configurable once all juniors exit. 2. Tranche-math Kani proofs (§15, originally part of the dcccrypto#140/dcccrypto#141 coverage): the Kani suite covered only the global path. Restore the 10 tranche harnesses + their u32/u64 mirrors: distribute_loss conservation + junior-first; distribute_fees conservation + no-senior-strands-to-junior; sub-pool C9 guard + first-depositor 1:1; sub-pool round-trip no-profit; senior_balance non-underflow; tranche decomposition. (Tranche proptests already survived.) Verification: cargo build --lib + cargo build-sbf clean; kani crate compiles; the §15 invariants verified exhaustively (405,121 cases) against the v17 production functions out-of-band; cargo kani + cargo test run them in CI. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughRestores two pre-v17 protections: ChangesRestore pre-v17 tranche protections
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
kani-proofs/src/lib.rs (1)
245-251: 💤 Low valueMinor: Proof count discrepancy in header comment.
The comment states "§15 (10 proofs)" but counting the actual harnesses in SECTION 15 yields 9 proofs. Consider updating the comment to reflect the accurate count.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@kani-proofs/src/lib.rs` around lines 245 - 251, The header comment in the KANI PROOFS section states "§15 (10 proofs)" but the actual count of harnesses in SECTION 15 is 9 proofs, creating a discrepancy. Update the proof count referenced in the comment from 10 to 9 to accurately reflect the number of proofs present in that section. This ensures the documentation remains consistent with the actual implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@kani-proofs/src/lib.rs`:
- Around line 245-251: The header comment in the KANI PROOFS section states "§15
(10 proofs)" but the actual count of harnesses in SECTION 15 is 9 proofs,
creating a discrepancy. Update the proof count referenced in the comment from 10
to 9 to accurately reflect the number of proofs present in that section. This
ensures the documentation remains consistent with the actual implementation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e132bc64-de40-4735-ba46-79e67e888a37
📒 Files selected for processing (2)
kani-proofs/src/lib.rssrc/processor.rs
|
Integrated into main via the consolidated PR above (with attribution; verified it doesn't break the admin-set-tranche tests, unlike a sibling guard PR that did). Closes #143. Thanks. |
Closes #143.
What
Restores two protections that existed on pre-v17
mainbut were dropped when thev17-convergenceline forked early (it pre-dated these PRs and didn't re-incorporate them). Both are absent from current v17.1.
junior_fee_mult_bpsgovernance lock (was #127)process_admin_set_tranche_configvalidated the multiplier range but no longer blocked changing it once junior LPs exist. Sinceprocess_accrue_feesreads the multiplier live (no per-epoch snapshot), a mid-life change re-prices the junior/senior fee split for already-committed junior LPs — the admin can pump it right beforeAccrueFeesto capture an outsized share into an admin-held junior position, or depress it to silently cut promised junior yield.Restored guard: reject any change when
junior_total_lp() > 0; idempotent same-value rewrites still succeed; once all juniors exit (junior_total_lp() == 0) the multiplier is freely configurable for the next cohort.2. Tranche-math Kani proofs (§15, was part of #140/#141)
The Kani suite covered only the global
calc_lp_for_deposit/calc_collateral_for_withdraw. Restores the 10 tranche harnesses + their u32/u64 mirrors:distribute_lossconservation + junior-first;distribute_feesconservation + no-senior-strands-to-junior; sub-pool orphaned-value (C9) guard + first-depositor 1:1; sub-pool deposit→withdraw round-trip cannot profit;senior_balancenever underflows; tranche decomposition. (The tranche proptests already survived the convergence; only the formal proofs were missing.)Verification
cargo build --libandcargo build-sbf: clean.kani-proofscrate compiles;cargo kaniruns the proofs in CI.Note
The lock is a verbatim restoration of the previously-reviewed #127; #127 shipped without a unit test (it's a processor-level admin guard), so none was dropped — coverage is the build + the documented attack path + the independent review here.
Summary by CodeRabbit
New Features
Tests