Skip to content

fix: ctoken cpi context#1870

Merged
ananas-block merged 2 commits intomainfrom
jorrit/fix-ctoken-cpi-context
Jul 15, 2025
Merged

fix: ctoken cpi context#1870
ananas-block merged 2 commits intomainfrom
jorrit/fix-ctoken-cpi-context

Conversation

@ananas-block
Copy link
Contributor

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

Summary by CodeRabbit

  • New Features

    • Added validation to prevent certain CPI context flags from being used with burn, compress, decompress, and transfer operations.
    • Introduced a specific error message when invalid CPI context usage is detected.
  • Documentation

    • Added clarifying comments explaining why CPI context checks are omitted for delegation and freeze/thaw operations.
  • Tests

    • Updated tests to verify correct error handling when invalid CPI context flags are used.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 15, 2025

Walkthrough

A CPI context validation step was added to burn, compress, and transfer operations in the compressed-token program, ensuring certain context flags are not used. Comments clarify why similar checks are omitted from delegation and freeze/thaw operations. Related tests were updated to expect and assert the new error code when the validation fails.

Changes

File(s) Change Summary
programs/compressed-token/src/lib.rs Added CPI context validation to transfer; introduced check_cpi_context helper and new error code.
programs/compressed-token/src/burn.rs, programs/compressed-token/src/process_compress_spl_token_account.rs Added CPI context validation step to burn and compress SPL token account logic.
programs/compressed-token/src/delegation.rs, programs/compressed-token/src/freeze.rs Added comments explaining why CPI context checks are omitted in delegation and freeze/thaw.
program-tests/system-cpi-test/tests/test.rs Modified test to expect and assert the new CPI context error on burn; removed post-burn state assertions.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Program
    participant CPIContext

    User->>Program: Invoke burn/transfer/compress instruction
    Program->>CPIContext: Validate CPI context flags
    alt Invalid context flags
        CPIContext-->>Program: Return CpiContextSetNotUsable error
        Program-->>User: Error (CpiContextSetNotUsable)
    else Valid or unused context
        CPIContext-->>Program: Validation passes
        Program->>Program: Continue with operation
        Program-->>User: Success
    end
Loading

Poem

In the warren of code, a new check appears,
For CPI context, the logic now steers.
No sneaky flags in burn or compress,
The tests all assert, and errors address.
With comments as carrots, the doc grows clear—
A rabbit’s delight, the code’s hopping this year! 🥕


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5490ea1 and 1877eba.

📒 Files selected for processing (6)
  • program-tests/system-cpi-test/tests/test.rs (2 hunks)
  • programs/compressed-token/src/burn.rs (1 hunks)
  • programs/compressed-token/src/delegation.rs (2 hunks)
  • programs/compressed-token/src/freeze.rs (1 hunks)
  • programs/compressed-token/src/lib.rs (2 hunks)
  • programs/compressed-token/src/process_compress_spl_token_account.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
programs/compressed-token/src/burn.rs (1)
programs/compressed-token/src/lib.rs (1)
  • check_cpi_context (289-296)
programs/compressed-token/src/process_compress_spl_token_account.rs (1)
programs/compressed-token/src/lib.rs (1)
  • check_cpi_context (289-296)
programs/compressed-token/src/lib.rs (2)
program-libs/compressed-account/src/instruction_data/with_readonly.rs (1)
  • cpi_context (297-307)
js/stateless.js/src/state/types.ts (1)
  • CompressedCpiContext (353-368)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: lint
  • GitHub Check: system-programs (system-cpi-test-v2-other, ["cargo-test-sbf -p system-cpi-v2-test -- --skip funct...
  • GitHub Check: system-programs (system-cpi-test-v2-event, ["cargo-test-sbf -p system-cpi-v2-test -- event::parse"])
  • GitHub Check: system-programs (light-registry, ["cargo-test-sbf -p registry-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 (system-cpi-test-v2-functional, ["cargo-test-sbf -p system-cpi-v2-test -- functio...
  • GitHub Check: system-programs (account-compression, ["cargo-test-sbf -p account-compression-test"])
  • GitHub Check: system-programs (light-compressed-token, ["cargo-test-sbf -p compressed-token-test"])
  • GitHub Check: system-programs (light-system-program, ["cargo-test-sbf -p system-test"])
  • GitHub Check: Forester e2e test
  • GitHub Check: Test program-libs-fast
  • GitHub Check: Test program-libs-slow
  • GitHub Check: Test batched-merkle-tree-simulate
  • GitHub Check: Test concurrent-merkle-tree
  • GitHub Check: Test sdk-libs
  • GitHub Check: cli-v2
  • GitHub Check: stateless-js-v1
  • GitHub Check: cli-v1
  • GitHub Check: stateless-js-v2
🔇 Additional comments (9)
programs/compressed-token/src/freeze.rs (1)

45-45: Good documentation of design decision.

The comment clearly explains why CPI context validation is omitted for freeze/thaw operations, providing valuable context for future maintainers.

programs/compressed-token/src/delegation.rs (2)

52-52: Good documentation of design rationale.

The comment clearly explains why CPI context validation is omitted for delegation operations, maintaining consistency with the overall design approach.


187-187: Consistent documentation across delegation functions.

The comment in process_revoke matches the one in process_approve, providing clear rationale for omitting CPI context validation.

programs/compressed-token/src/process_compress_spl_token_account.rs (1)

18-18: Appropriate CPI context validation placement.

The early validation ensures fail-fast behavior and uses the centralized check_cpi_context function for consistency across the codebase.

programs/compressed-token/src/burn.rs (1)

39-39: Proper CPI context validation implementation.

The validation is correctly placed early in the function for fail-fast behavior and maintains consistency by using the centralized check_cpi_context function.

program-tests/system-cpi-test/tests/test.rs (1)

1390-1407: LGTM: Test properly validates new CPI context validation.

The test change correctly expects the CpiContextSetNotUsable error when performing burn operations with CPI context, which aligns with the new validation logic introduced in the program.

programs/compressed-token/src/lib.rs (3)

151-154: LGTM: Conditional CPI context validation is correctly implemented.

The validation appropriately only applies when compress_or_decompress_amount.is_some(), ensuring CPI context restrictions are enforced only for operations that modify Solana account state.


283-285: LGTM: Error code is well-defined and descriptive.

The error message clearly explains that CPI context set/first_set flags are not usable with burn, compression, or decompression operations.


287-296: LGTM: Helper function correctly validates CPI context usage.

The function properly:

  • Handles the None case by returning Ok(())
  • Checks both set_context and first_set_context flags with OR logic
  • Returns the appropriate error when validation fails
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.

@ananas-block ananas-block merged commit aad94a4 into main Jul 15, 2025
30 of 31 checks passed
@ananas-block ananas-block deleted the jorrit/fix-ctoken-cpi-context branch July 15, 2025 14:45
ananas-block added a commit that referenced this pull request Jul 16, 2025
* fix: check cpi context account

* fix tests
@coderabbitai coderabbitai bot mentioned this pull request Sep 21, 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