fix: skip fee accrual in AccrueFees when no LP holders exist - #85
fix: skip fee accrual in AccrueFees when no LP holders exist#850x-SquidSol wants to merge 1 commit into
Conversation
When total_lp_supply == 0 (no depositors), accruing fees into total_fees_earned creates pool_value > 0 while lp_supply remains 0. The first-depositor guard in calc_lp_for_deposit requires BOTH to be 0 (1:1 pricing), so any positive pool_value with zero LP supply causes every deposit to return None — permanently locking the pool. An attacker can trigger this by sending a single token directly to the vault before the first deposit, then calling AccrueFees. The cost is one token; the result is a permanently un-depositable trading pool. Fix: add `&& pool.total_lp_supply > 0` to the fee accrual condition. Surplus vault balance is silently ignored when there are no LP holders (it will be picked up once deposits begin). 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 4 minutes and 46 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 — Skip fee accrual when no LP holders exist. Prevents division by zero / phantom fee accumulation. Security APPROVED ✅
dcccrypto
left a comment
There was a problem hiding this comment.
🛡️ Security APPROVED. Prevents permanent pool lock via direct vault token transfer before first deposit. When total_lp_supply==0, accruing fees would make pool_value>0 and block all future deposits (calc_lp_for_deposit first-depositor check fails). Guard is correct and minimal.
|
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
total_lp_supply == 0(no depositors yet), accruing fees setstotal_fees_earned > 0while lp supply is still 0calc_lp_for_depositrequires bothtotal_lp_supply == 0 AND total_pool_value == 0to grant 1:1 pricing; any positivepool_valuewith zero LP causes every deposit call to returnNoneAccrueFees→total_fees_earned = 1→ all future deposits blocked permanently. Cost: 1 token&& pool.total_lp_supply > 0; surplus vault balance is ignored when there are no LP holders (it will be naturally recaptured after the first deposit)Test plan
cargo testpasses (57/57)