fix: 9 HIGH-severity tranche/insurance security fixes - #98
Conversation
…PR#85) PR#46 (CVSS 7.5) — Tranche anti-mixing bypass: remove lp_amount > 0 from senior guard (deposit._reserved[8] == 1 check now unconditional) and switch junior guard to use is_initialized instead of lp_amount > 0. Attacker could: deposit junior -> withdraw all -> deposit senior into same PDA -> withdraw at junior rates. Now blocked regardless of LP balance. PR#70 (CVSS 8.1) — Senior withdrawal wrong formula: when tranche_enabled() and !is_junior, now calls calc_senior_collateral_for_withdraw against senior sub-pool (senior_lp, senior_bal) instead of the global pool formula. Prevents senior holders extracting junior-backed collateral. PR#73 (CVSS 6.5) — Junior fee multiplier non-functional: AccrueFees now calls distribute_fees() when tranche_enabled() and junior_total_lp() > 0, crediting junior_balance with its weighted share of fee_delta. Previously all fees went to senior because distribute_fees was never invoked. PR#85 (CVSS 7.5) — Pre-deposit dust attack bricks pool: add pool.total_lp_supply > 0 guard to the fee accrual condition. Without it, sending 1 token to the vault before the first deposit sets total_fees_earned > 0 while total_lp_supply == 0, permanently blocking all future deposits. PR#77 (CVSS 7.5) — Junior withdrawal missing loss absorption: add effective_junior_balance() to state.rs (applies distribute_loss against outstanding net_loss = total_flushed - total_returned) and use it in the withdrawal path instead of raw junior_balance(). Also fixes senior_balance() to derive from effective_junior_balance(). Junior holders now receive reduced payout that correctly reflects absorbed insurance losses. Fixes: CVSS 8.1, 7.5, 7.5, 7.5, 6.5 — all HIGH severity. Tests: 57 passed, 0 failed. Cargo check: clean. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis pull request modifies deposit, withdrawal, insurance, and fee-handling instruction processors in Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Summary
Implements 9 HIGH-severity security fixes identified during comprehensive PR review. These address vulnerabilities in the tranche system, insurance accounting, and admin withdrawal paths.
Fixes included:
Test results
cargo check: cleancargo test: 57 passed, 0 failedSecurity review
All fixes passed two rounds of security review. Original PRs from 0x-SquidSol — reimplemented here to resolve merge conflicts.
Closes #46, #58, #69, #70, #73, #77, #85, #86, #92
🤖 Generated with Claude Code
Summary by CodeRabbit