fix(native): bind native market writes to PerpMarket discriminator - #2205
fix(native): bind native market writes to PerpMarket discriminator#2205SashaMIT wants to merge 2 commits into
Conversation
Native [0xFF;4] handlers write fixed offsets into accounts[0] without checking it is a PerpMarket. Owner/length alone is not enough. Reuse the same discriminator check as PerpMarketMap before mutably borrowing the market in mm-oracle and amm-spread native paths. Co-authored-by: Cursor <cursoragent@cursor.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughNative MM oracle and AMM spread update paths now validate account lists and PerpMarket account data before accessing raw market data. ChangesNative market validation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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
🤖 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 `@programs/drift/src/instructions/admin.rs`:
- Around line 5030-5035: Update the account validation immediately before the
indexing in the AMM spread native path to require at least two accounts,
replacing the non-empty check while preserving the existing market-account
validation through require_account_is_perp_market. This must ensure accounts[1]
is only accessed when accounts.len() >= 2 and return the instruction error
instead of panicking for shorter input.
🪄 Autofix
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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: d1ae0f71-1493-4953-95c6-228db54d4bc4
📒 Files selected for processing (1)
programs/drift/src/instructions/admin.rs
Avoid OOB panic on one-account amm-spread native calls; return assert with clear message instead. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Addressed CodeRabbit nit: |
Summary
The native
[0xFF;4]handlers (handle_update_mm_oracle_native,handle_update_amm_spread_adjustment_native) write fixed byte offsets intoaccounts[0]without verifying that account is aPerpMarket.Community #2110 adds owner/min-len (and Clock) checks; #2204 binds the State PDA for the kill-switch bit. This PR is additive: before the mutable borrow, require program ownership,
PerpMarket::SIZE, andPerpMarket::discriminator()— the same pattern used inPerpMarketMap.Test plan
Made with Cursor
Summary by CodeRabbit