fix: reject FlushToInsurance on trading LP pools (pool_mode == 1) - #69
fix: reject FlushToInsurance on trading LP pools (pool_mode == 1)#690x-SquidSol wants to merge 1 commit into
Conversation
FlushToInsurance moves collateral from the stake vault to the wrapper insurance fund via CPI TopUpInsurance. This operation is designed for insurance LP pools (mode 0) where the vault buffer and insurance fund are the same conceptual reserve. For trading LP pools (mode 1), flushing creates a permanent accounting inconsistency: 1. total_flushed increases but AccrueFees computes pool_value as: total_deposited - total_withdrawn + total_fees_earned (does NOT subtract total_flushed) 2. The actual vault balance drops below the accounting-derived pool_value, so AccrueFees would never report fees (current_balance < pool_value always) after even a small flush. 3. LP holders can no longer withdraw their full share, as the vault lacks sufficient collateral even though pool_value says otherwise. Adds pool_mode == 0 check before the vault-balance guard. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughA pool mode precondition was added to the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 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 |
dcccrypto
left a comment
There was a problem hiding this comment.
Security review — Rejects FlushToInsurance on trading LP pools (pool_mode == 1). Prevents insurance drain from wrong pool type. Security APPROVED ✅
|
Superseded by PR#95 (merged) and PR#96 (omnibus test coverage). All changes in this PR are already in master. Closing as part of PERC-8433 cleanup. |
|
Implemented in PR #98 and merged to master. Thank you for identifying this vulnerability — the fix was applied based on your diff after two rounds of security review. |
Summary
FlushToInsurancemoves collateral from the stake vault to the wrapper insurance fund. This is designed for insurance LP pools (mode 0) only.On trading LP pools (mode 1),
AccrueFeescomputespool_value = total_deposited - total_withdrawn + total_fees_earnedwithout subtractingtotal_flushed. After any flush,current_vault_balance < pool_valuepermanently, stopping all fee accrual and breaking withdrawals.Adds
pool_mode == 0guard before vault-balance check.Test plan
InvalidPoolModeon mode-1 poolSummary by CodeRabbit