Fix PDA derivation using global pda instead of delegatedAccount#150
Fix PDA derivation using global pda instead of delegatedAccount#150Meesut0 wants to merge 1 commit intomagicblock-labs:mainfrom
pda instead of delegatedAccount#150Conversation
Fix incorrect PDA derivation in helper instruction builders. The functions `createCommitAccountInstruction`, `createFinalizeInstruction`, and `createUndelegateInstruction` accept a `delegatedAccount` parameter but were deriving PDAs from a global `pda` variable instead. This could lead to incorrect PDA computation if these helpers are called with a delegated account different from the global `pda`. This change replaces `pda` with the provided `delegatedAccount` when deriving: - commit state PDA - commit record PDA - delegation record PDA - delegation metadata PDA - undelegate buffer PDA This makes the helpers consistent with their function signatures and ensures correct PDA derivation.
📝 WalkthroughWalkthroughThis change modifies the test-delegation.ts integration test file to align PDA derivations with the ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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 Tip You can validate your CodeRabbit configuration file in your editor.If your editor has YAML language server, you can enable auto-completion and validation by adding |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/integration/tests/test-delegation.ts (1)
441-441:⚠️ Potential issue | 🟠 MajorMark validator writable in commit and finalize helpers.
The
createCommitAccountInstructionhelper at line 441 calls theCommitStateinstruction (discriminator 1), which performs active lamport transfers FROM the validator to the commit state account. The validator account must be marked writable.Similarly,
createFinalizeInstructionat line 477 should be updated to mark validator writable for consistency with the corresponding Rust instruction builders (dlp-api/src/instruction_builder/commit_finalize.rs), which explicitly mark the validator as writable.Suggested patch
@@ - { pubkey: validator, isSigner: true, isWritable: false }, + { pubkey: validator, isSigner: true, isWritable: true }, @@ - { pubkey: validator, isSigner: true, isWritable: false }, + { pubkey: validator, isSigner: true, isWritable: true },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/integration/tests/test-delegation.ts` at line 441, The helper functions createCommitAccountInstruction and createFinalizeInstruction currently mark the validator account as isWritable: false but the on-chain CommitState (discriminator 1) and corresponding finalize instruction transfer lamports from the validator, so update both helpers to mark the validator account as writable (set isWritable: true) where the validator is passed in (reference symbols createCommitAccountInstruction, createFinalizeInstruction and the validator account tuple { pubkey: validator, ... }) to match the Rust instruction builders in commit_finalize.rs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@tests/integration/tests/test-delegation.ts`:
- Line 441: The helper functions createCommitAccountInstruction and
createFinalizeInstruction currently mark the validator account as isWritable:
false but the on-chain CommitState (discriminator 1) and corresponding finalize
instruction transfer lamports from the validator, so update both helpers to mark
the validator account as writable (set isWritable: true) where the validator is
passed in (reference symbols createCommitAccountInstruction,
createFinalizeInstruction and the validator account tuple { pubkey: validator,
... }) to match the Rust instruction builders in commit_finalize.rs.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: ff27bb1d-2dcf-40ff-8505-4a74f6d9bd5e
📒 Files selected for processing (1)
tests/integration/tests/test-delegation.ts
Helper instruction builders derived PDAs from a global
pdavariableinstead of the provided
delegatedAccountparameter.This could produce incorrect PDA addresses if the helpers are called with
a delegated account different from the global
pda.This change updates the PDA derivation to use
delegatedAccount.Summary by CodeRabbit