fix: include total_returned in FlushToInsurance available-balance guard - #92
Conversation
The available-to-flush calculation was:
total_deposited - total_withdrawn - total_flushed
It omitted + total_returned. After AdminWithdrawInsurance is called,
total_returned grows (tokens re-enter the vault), but total_flushed is not
reduced. The old formula therefore:
- Reports too-low available capacity (preventing valid flushes after a
partial insurance return).
- Underflows with Err(Overflow) if total_returned pushes the net below
what the subtraction can represent, permanently blocking FlushToInsurance
even when the vault holds real tokens.
Fix: add .checked_add(pool.total_returned) to mirror the formula used by
total_pool_value(), which correctly accounts for all four counters.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 16 minutes and 2 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ✨ 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 — Include total_returned in FlushToInsurance available-balance guard. Prevents flushing more than available. Security APPROVED ✅
dcccrypto
left a comment
There was a problem hiding this comment.
🛡️ Security APPROVED. Includes total_returned in flush available balance calculation. Original formula omitted returned tokens, causing false InsufficientFunds after AdminWithdrawInsurance. Now matches total_pool_value() accounting.
|
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
process_flush_to_insurancecomputed the available-to-flush balance as:but omitted
+ total_returned.Impact
After
AdminWithdrawInsuranceruns (incrementingtotal_returned), the vault physically holds those returned tokens again, but the old formula still subtracted the fulltotal_flushedwithout adding backtotal_returned. This causes:total_flushed > total_deposited - total_withdrawnafter a partial return cycle,checked_subreturnsNone→Err(Overflow), permanently blockingFlushToInsuranceeven though the vault is solvent.A pool that has completed one flush+return cycle can never re-flush insurance capital without triggering this error, locking the admin out of a core operational action.
Fix
Add
.checked_add(pool.total_returned)to match the formula already used bytotal_pool_value():Test plan
cargo testpasses (57 tests)🤖 Generated with Claude Code