Skip to content

fix: system program add signer mut account check#1808

Merged
sergeytimoshin merged 3 commits intomainfrom
jorrit/fix-add-signer-mut-account-check
Jun 15, 2025
Merged

fix: system program add signer mut account check#1808
sergeytimoshin merged 3 commits intomainfrom
jorrit/fix-add-signer-mut-account-check

Conversation

@ananas-block
Copy link
Contributor

@ananas-block ananas-block commented Jun 15, 2025

Summary by CodeRabbit

  • New Features

    • Added a check to ensure accounts are writable before proceeding with certain operations.
    • Enforced mutability requirement for fee payer accounts during transactions.
  • Bug Fixes

    • Improved validation for fee payer accounts by requiring mutability.
    • Corrected error handling for writable account checks.
  • Tests

    • Introduced new tests to verify the behavior of the writable account check for different backends.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 15, 2025

Walkthrough

A new function, check_mut, was introduced to verify account mutability, and corresponding tests were added. The check_fee_payer logic was updated to require the fee payer account to be mutable, using the new function. The validation of the authority account in instruction invocation was changed to explicitly check signer status instead of using check_fee_payer. Import statements were adjusted accordingly, with no changes to public interfaces.

Changes

File(s) Change Summary
program-libs/account-checks/src/checks.rs Added check_mut function to check if an account is writable, refactored check_account_info_mut to use it.
program-libs/account-checks/tests/tests.rs Added test_check_mut to test check_mut for both Solana and Pinocchio backends; corrected error variant in tests.
programs/system/src/accounts/account_checks.rs Updated imports; modified check_fee_payer to require fee payer account mutability using check_mut.
programs/system/src/invoke/instruction.rs Changed authority account validation: replaced check_fee_payer usage with explicit signer check and error handling.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant AccountChecks
    participant AccountInfo

    Caller->>AccountChecks: check_mut(account_info)
    AccountChecks->>AccountInfo: is_writable()
    alt Account is writable
        AccountChecks-->>Caller: Ok(())
    else Account is not writable
        AccountChecks-->>Caller: Err(AccountNotMutable)
    end
Loading
sequenceDiagram
    participant SystemProgram
    participant AccountChecks
    participant FeePayerAccount

    SystemProgram->>AccountChecks: check_fee_payer(fee_payer)
    AccountChecks->>FeePayerAccount: is_signer()
    AccountChecks->>AccountChecks: check_mut(fee_payer)
    alt Fee payer is signer and mutable
        AccountChecks-->>SystemProgram: Ok(fee_payer)
    else
        AccountChecks-->>SystemProgram: Err(...)
    end
Loading
sequenceDiagram
    participant Instruction
    participant AccountIterator
    participant AccountChecks

    Instruction->>AccountIterator: next_account_info()
    alt account exists
        Instruction->>AccountChecks: check_signer(authority)
        AccountChecks-->>Instruction: Ok or Err(ProgramError)
    else
        Instruction-->>Instruction: Err(NotEnoughAccountKeys)
    end
Loading

Possibly related PRs

Suggested reviewers

  • sergeytimoshin
  • SwenSchaeferjohann

Poem

🐇 Hop along the code we go,
Where accounts must change and flow.
A check for mutability shines bright,
Fee payers now must write just right.
Signers stand firm, no keys astray,
Safe and sound, we code away! ✨🐰

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
programs/system/src/accounts/account_checks.rs (1)

14-18: Use ? consistently instead of manual map_err

Throughout the module most helpers rely on ? and the existing From<AccountError> for ProgramError impl (e.g. check_non_mut(authority)?;).
Inside check_fee_payer the new mutability check still uses an explicit map_err. Streamline for readability:

-    check_signer(fee_payer).map_err(ProgramError::from)?;
-    check_mut(fee_payer).map_err(ProgramError::from)?;
+    check_signer(fee_payer)?;
+    check_mut(fee_payer)?;

No behavior change, just cleaner code.

program-libs/account-checks/tests/tests.rs (1)

301-342: Good addition – but reconsider the heavy feature gate

The new test_check_mut thoroughly validates both success & failure paths – nice work.
However, the entire file is #![cfg(all(feature = "solana", feature = "pinocchio"))], meaning none of these tests run unless both back-ends are enabled simultaneously. That’s uncommon and may hide regressions when only one backend is compiled.

Consider:

  1. Moving the check_mut tests to an always-compiled file, using #[cfg(feature = "...")] inside each case (as you already do), or
  2. Relaxing the top-level gate to any(...).

This will maximise test coverage in CI configurations that build a single backend.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da6459d and c8b2fd6.

📒 Files selected for processing (3)
  • program-libs/account-checks/src/checks.rs (1 hunks)
  • program-libs/account-checks/tests/tests.rs (1 hunks)
  • programs/system/src/accounts/account_checks.rs (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
programs/system/src/accounts/account_checks.rs (1)
program-libs/account-checks/src/checks.rs (2)
  • check_mut (124-129)
  • check_signer (117-122)
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: system-programs (random-e2e-test, ["cargo-test-sbf -p e2e-test"])
  • GitHub Check: system-programs (system-cpi-test-v2, ["cargo-test-sbf -p system-cpi-v2-test"])
  • GitHub Check: system-programs (light-compressed-token, ["cargo-test-sbf -p compressed-token-test"])
  • GitHub Check: system-programs (system-cpi-test, ["cargo-test-sbf -p system-cpi-test"])
  • GitHub Check: system-programs (light-registry, ["cargo-test-sbf -p registry-test"])
  • GitHub Check: system-programs (account-compression, ["cargo-test-sbf -p account-compression-test"])
  • GitHub Check: system-programs (light-system-program, ["cargo-test-sbf -p system-test"])
  • GitHub Check: test-double-registration
  • GitHub Check: Test program-libs
  • GitHub Check: test-state-batched
  • GitHub Check: test-state-photon-batched
  • GitHub Check: test-e2e
  • GitHub Check: Test concurrent-merkle-tree
  • GitHub Check: test-2-foresters
  • GitHub Check: test-address-batched
  • GitHub Check: Test sdk-libs
  • GitHub Check: lint
  • GitHub Check: stateless-js

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
programs/system/src/invoke/instruction.rs (1)

50-52: Propagate the error directly instead of re-mapping it

check_signer already returns a ProgramError (or something that implements Into<ProgramError>).
The extra map_err(ProgramError::from) is therefore redundant and slightly obscures intent.

-let authority = accounts.next().ok_or(ProgramError::NotEnoughAccountKeys)?;
-check_signer(authority).map_err(ProgramError::from)?;
+let authority = accounts.next().ok_or(ProgramError::NotEnoughAccountKeys)?;
+check_signer(authority)?;

This keeps the happy path clean and removes one level of allocation in the error-path.
Please double-check the return type of check_signer; if it is already Result<(), ProgramError> (as is typical for the helper), this refactor is safe.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8b2fd6 and 5bc72d5.

📒 Files selected for processing (4)
  • program-libs/account-checks/src/checks.rs (2 hunks)
  • program-libs/account-checks/tests/tests.rs (3 hunks)
  • programs/system/src/accounts/account_checks.rs (2 hunks)
  • programs/system/src/invoke/instruction.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • programs/system/src/accounts/account_checks.rs
  • program-libs/account-checks/tests/tests.rs
  • program-libs/account-checks/src/checks.rs
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: Test sdk-libs
  • GitHub Check: Test program-libs
  • GitHub Check: Test concurrent-merkle-tree
  • GitHub Check: system-programs (system-cpi-test-v2, ["cargo-test-sbf -p system-cpi-v2-test"])
  • GitHub Check: system-programs (random-e2e-test, ["cargo-test-sbf -p e2e-test"])
  • GitHub Check: system-programs (system-cpi-test, ["cargo-test-sbf -p system-cpi-test"])
  • GitHub Check: system-programs (light-compressed-token, ["cargo-test-sbf -p compressed-token-test"])
  • GitHub Check: system-programs (account-compression, ["cargo-test-sbf -p account-compression-test"])
  • GitHub Check: system-programs (light-registry, ["cargo-test-sbf -p registry-test"])
  • GitHub Check: lint
  • GitHub Check: system-programs (light-system-program, ["cargo-test-sbf -p system-test"])
  • GitHub Check: stateless-js
  • GitHub Check: test-double-registration
  • GitHub Check: test-2-foresters
  • GitHub Check: test-state-photon-batched
  • GitHub Check: test-e2e
  • GitHub Check: test-state-batched
  • GitHub Check: test-address-batched
🔇 Additional comments (1)
programs/system/src/invoke/instruction.rs (1)

47-47: Confirm that check_fee_payer still validates signer status

With the new mutability requirement introduced in this PR, make sure check_fee_payer continues to enforce that the fee-payer is also a signer.
Silent removal of that check would leave the transaction relying on the runtime’s implicit fee-payer rule, which is not guaranteed during CPI.

@sergeytimoshin sergeytimoshin merged commit e9c6594 into main Jun 15, 2025
33 of 34 checks passed
@sergeytimoshin sergeytimoshin deleted the jorrit/fix-add-signer-mut-account-check branch June 15, 2025 19:58
@coderabbitai coderabbitai bot mentioned this pull request Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants