Skip to content

fix: PERC-8462 — deposit ghost account fix (vault capacity + min initial deposit) - #80

Merged
dcccrypto merged 1 commit into
masterfrom
feature/PERC-8462-deposit-ghost-fix
Apr 4, 2026
Merged

fix: PERC-8462 — deposit ghost account fix (vault capacity + min initial deposit)#80
dcccrypto merged 1 commit into
masterfrom
feature/PERC-8462-deposit-ghost-fix

Conversation

@dcccrypto

Copy link
Copy Markdown
Owner

Summary

Upstream d94d064 ghost account fix. All vault-touching functions now validate capacity BEFORE any state mutation.

Changes

  • MAX_VAULT_TVL constant (10^30) — caps total token balance
  • deposit(): checked_add + cap check before any mutations; min_initial_deposit guard for zero-capital accounts
  • add_user() / add_lp(): vault cap check before alloc_slot()
  • deposit_fee_credits(): vault cap check before vault mutation

Tests (8 new, 205 total)

cargo test: 205 passed, 0 failed | clippy clean | fmt clean

Task: PERC-8462 (SYNC-05, P0) | Upstream: d94d064

…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
@coderabbitai

coderabbitai Bot commented Apr 4, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@dcccrypto has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 51 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a14fac10-4810-4819-9a32-5ced154c9d78

📥 Commits

Reviewing files that changed from the base of the PR and between d295712 and 32008a5.

📒 Files selected for processing (2)
  • src/percolator.rs
  • tests/unit_tests.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/PERC-8462-deposit-ghost-fix

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dcccrypto dcccrypto left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@dcccrypto
dcccrypto merged commit 40b4634 into master Apr 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant