fix: PERC-8462 — deposit ghost account fix (vault capacity + min initial deposit) - #80
Conversation
…count fix) Upstream d94d064: deposit(), add_user(), add_lp(), and deposit_fee_credits() now validate vault capacity BEFORE any state mutation. Prevents ghost accounts where a slot is allocated but the deposit fails due to vault cap overflow. Changes: - Add MAX_VAULT_TVL constant (10^30) — caps total token balance - deposit(): checked_add + cap check before mutations; min_initial_deposit guard (uses new_account_fee) for zero-capital accounts prevents dust - add_user()/add_lp(): vault cap check before alloc_slot() - deposit_fee_credits(): vault cap check before vault mutation - Vault assignments use pre-validated values (no redundant arithmetic) - 8 new unit tests covering cap boundary, dust rejection, state leak prevention
|
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 5 minutes and 51 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. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ 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 APPROVED — PERC-8462 ghost account fix.
Reviewed: MAX_VAULT_TVL constant, all 4 deposit path protections, min_initial_deposit guard, state immutability on failure.
Key verifications:
- 4 deposit paths protected: add_user, add_lp, deposit, deposit_fee_credits — all check vault capacity BEFORE slot allocation/state mutation ✅
- Pre-computed new_vault: checked_add → compare against MAX_VAULT_TVL → use cached value (no TOCTOU) ✅
- Ghost account prevention: capacity check is BEFORE materialize_at(), so no slot is consumed if cap exceeded ✅
- min_initial_deposit: only enforced on zero-capital accounts (capital == 0 && amount < min_deposit) — subsequent small deposits allowed ✅
- MAX_VAULT_TVL (10^30): generous but safe — prevents u128 overflow in downstream accounting ✅
- State immutability test: explicitly verifies vault, capital, c_tot unchanged on failed deposit ✅
- 8 unit tests: capacity overflow, exact boundary, dust rejection, subsequent dust, add_user/add_lp/fee_credits overflow, no-state-leak ✅
No findings.
Summary
Upstream d94d064 ghost account fix. All vault-touching functions now validate capacity BEFORE any state mutation.
Changes
Tests (8 new, 205 total)
cargo test: 205 passed, 0 failed | clippy clean | fmt clean
Task: PERC-8462 (SYNC-05, P0) | Upstream: d94d064