fix: resolve tranche accounting bugs, gate validation issues, and token owner check omissions - #225
Conversation
…and discriminators
📝 WalkthroughWalkthroughAdds ChangesJunior Tranche Accessor and Insurance Accounting Fixes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/processor.rs (1)
1293-1296: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick winUnmigrated raw
_reserved[8]access.This full-withdrawal reset path still uses direct byte access instead of the new accessor. For consistency with the PR's stated goal of replacing all raw
_reserved[8]accesses:♻️ Suggested fix
if deposit_mut.lp_amount == 0 { deposit_mut.is_initialized = 0; - deposit_mut._reserved[8] = 0; + deposit_mut.set_junior_deposit(false); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/processor.rs` around lines 1293 - 1296, In the full-withdrawal reset path within the conditional block where deposit_mut.lp_amount equals zero, replace the direct raw byte access assignment to deposit_mut._reserved[8] = 0 with the new accessor method that was introduced in this PR for setting reserved values. Search the codebase for other instances of this accessor method to ensure consistency in how reserved fields are being accessed and modified throughout the deposit mutation logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.gitignore:
- Around line 7-8: The `*.md` pattern in .gitignore is too broad and will
exclude all markdown files in the repository, including critical documentation
files currently tracked such as README.md, .github/pull_request_template.md, and
files in the docs/ directory. Either remove this pattern entirely from the
.gitignore file if no generated markdown files need to be ignored, or replace it
with a more specific path-based glob pattern such as `dist/**/*.md` or
`target/**/*.md` to only target generated markdown artifacts in specific
directories.
---
Nitpick comments:
In `@src/processor.rs`:
- Around line 1293-1296: In the full-withdrawal reset path within the
conditional block where deposit_mut.lp_amount equals zero, replace the direct
raw byte access assignment to deposit_mut._reserved[8] = 0 with the new accessor
method that was introduced in this PR for setting reserved values. Search the
codebase for other instances of this accessor method to ensure consistency in
how reserved fields are being accessed and modified throughout the deposit
mutation logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ced50dd2-6aac-4f3f-9f1a-9ab236a28a65
📒 Files selected for processing (3)
.gitignoresrc/processor.rssrc/state.rs
| *.md | ||
|
|
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# List all tracked .md files to understand what would be ignored
git ls-files '*.md'Repository: dcccrypto/percolator-stake
Length of output: 229
Remove *.md from .gitignore or narrow the pattern to specific directories.
Adding *.md to .gitignore will exclude critical documentation files currently tracked in the repository: README.md, .github/pull_request_template.md, and all files in docs/ (ARCHITECTURE.md, AUDIT.md, KANI-DEEP-ANALYSIS.md, KANI-PROOF-ANALYSIS.md, WRAPPER-HARDENING.md).
Either remove this pattern or replace it with a path-specific glob if targeting only generated markdown artifacts (e.g., dist/**/*.md or target/**/*.md).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.gitignore around lines 7 - 8, The `*.md` pattern in .gitignore is too broad
and will exclude all markdown files in the repository, including critical
documentation files currently tracked such as README.md,
.github/pull_request_template.md, and files in the docs/ directory. Either
remove this pattern entirely from the .gitignore file if no generated markdown
files need to be ignored, or replace it with a more specific path-based glob
pattern such as `dist/**/*.md` or `target/**/*.md` to only target generated
markdown artifacts in specific directories.
1. Account for
realized_junior_lossinReturnInsuranceCappool.realized_junior_loss()to the calculation ofoutstandingrecovery capacity inprocess_return_insurance. This ensures that paper-forfeited junior losses (bookkeeping settlements) do not artificially lower the physical recovery limit, preventing a shortfall in the vault that could later cause senior LP withdrawals to fail.2. Invariant Guard for
junior_balancein Fee Accrualaccrue_fees_innerto verify thatjunior_balancedoes not exceedtotal_pool_value(). If the invariant is violated, the transaction rejects cleanly rather than corrupting pool state and bricking senior tranche deposits/withdrawals.3. Factor
realized_junior_lossinto theDepositJuniorGatetotal_flushed - (total_returned - realized_junior_loss)) rather than rawtotal_flushed > total_returned. This prevents paper-only junior forfeitures from prematurely reopening junior deposits during an unresolved physical insurance loss.4. SPL Token Owner Check on Vault in
ReturnInsurancespl_tokenbefore performing CPI transfers inprocess_return_insurance, standardizing defense-in-depth security checks with other vault-touching instructions.5. Named Accessors for
StakeDepositTranche Flagsis_junior_deposit()andset_junior_deposit()toStakeDepositto wrap the raw_reserved[8]byte access. Replaced all raw index accesses inprocessor.rswith these accessors to guarantee layout changes won't silently corrupt tranche-mixing validations.Summary by CodeRabbit
Bug Fixes
Security
Chores