Skip to content

Conversation

@ananas-block
Copy link
Contributor

@ananas-block ananas-block commented Nov 6, 2025

Fixes:

  • Added three validation checks to ensure compressed mints can only be created in the designated CMINT_ADDRESS_TREE:
    a. Address tree pubkey validation - Verify CPI context uses correct address tree (error 6105: MintActionInvalidCpiContextAddressTreePubkey)
    b. Compressed address derivation check - Validate derived address matches provided address (error 6104: MintActionInvalidCompressedMintAddress)
    c. Execute mode tree index check - Ensure in_tree_index is 1 when executing from CPI context (error 6106: MintActionInvalidCpiContextForCreateMint)
  • Hardcoded CMINT_ADDRESS_TREE in SDK to prevent users from specifying arbitrary address trees

Tests:

  • Created minimal CPI wrapper test program for testing CPI context paths
  • Added failing integration tests for validation errors MintActionInvalidCompressedMintAddress, MintActionInvalidCpiContextAddressTreePubkey, MintActionInvalidCpiContextForCreateMint
  • Added unit test for error MintActionInvalidCpiContextForCreateMint

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 6, 2025

Walkthrough

This PR removes a zero-copy CPI context deserialization path from the system program, adds an explicit address_tree_pubkey field to CpiContext, introduces CPI-context validation for mint creation (address tree and compressed-mint checks, in-tree index rules), adds related error codes, and adds tests and test harness changes to validate the new flow.

Changes

Cohort / File(s) Summary
Zero-copy CPI context removal
anchor-programs/system/src/cpi_context_account.rs
Removes ZCpiContextAccount2<'a> and deserialize_cpi_context_account and consolidates InstructionDataInvokeCpi import path.
CpiContext struct enhancement
program-libs/ctoken-types/src/instructions/mint_action/cpi_context.rs
Adds address_tree_pubkey: [u8; 32] field, removes derived Default, and implements Default to initialize the field to CMINT_ADDRESS_TREE.
Test program harness
program-tests/compressed-token-test/Cargo.toml
program-tests/compressed-token-test/src/lib.rs
program-tests/compressed-token-test/tests/mint.rs
Adjusts test crate dependencies/default features; adds wrapper program MintActionCpiWrapper and two entry points to route CPI-invocation bytes to the compressed-token program; includes CPI-context test module.
Comprehensive CPI context tests
program-tests/compressed-token-test/tests/mint/cpi_context.rs
New integration tests for CPI write/execute paths, invalid address-tree pubkey, invalid compressed-mint address, and invalid in-tree index for create_mint.
Error codes
programs/compressed-token/anchor/src/lib.rs
Adds three new ErrorCode variants: MintActionInvalidCompressedMintAddress, MintActionInvalidCpiContextForCreateMint, MintActionInvalidCpiContextAddressTreePubkey.
Mint action validation logic
programs/compressed-token/program/src/mint_action/actions/create_mint.rs
Adds CPI-context checks: verify address_tree_pubkey == CMINT_ADDRESS_TREE, derive expected compressed-mint address and compare to provided compressed address, tighten extension validation, and use Pubkey comparisons.
Processor / QueueIndices updates
programs/compressed-token/program/src/mint_action/processor.rs
programs/compressed-token/program/src/mint_action/queue_indices.rs
Passes new write_to_cpi_context flag into QueueIndices::new; QueueIndices::new signature gains write_to_cpi_context: bool and enforces in_tree_index == 1 for execute-mode create_mint when not writing to CPI context.
Mint action tests
programs/compressed-token/program/tests/mint_action.rs
programs/compressed-token/program/tests/queue_indices.rs
Initialize CpiContext.address_tree_pubkey in test fixtures; update CPI-context execute-mode index values and add test_queue_indices_invalid_address_tree_index.
SDK instruction initialization
sdk-libs/compressed-token-sdk/src/instructions/mint_action/instruction.rs
Explicitly sets read_only_address_trees and address_tree_pubkey: CMINT_ADDRESS_TREE in MintActionInputsCpiWrite::new_create_mint.
Dev dependency for tests
programs/compressed-token/program/Cargo.toml
Adds light-compressed-account to [dev-dependencies] with features ["keccak","sha256"].

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant TestWrapper as Wrapper Program
    participant Compressed as Compressed-Token
    participant LightSys as Light System

    Client->>TestWrapper: write_to_cpi_context_mint_action(inputs)
    TestWrapper->>Compressed: invoke CPI (write mode, remaining_accounts)
    Compressed->>LightSys: create CPI context account (write)
    LightSys-->>Compressed: CPI context account created
    Compressed-->>TestWrapper: return success

    Client->>TestWrapper: execute_cpi_context_mint_action(inputs)
    TestWrapper->>Compressed: invoke CPI (execute mode, remaining_accounts)
    Compressed->>Compressed: validate address_tree_pubkey == CMINT_ADDRESS_TREE
    Compressed->>Compressed: derive expected compressed_mint and compare
    alt invalid address tree or compressed mint
        Compressed-->>TestWrapper: return error (new ErrorCode)
    else valid
        Compressed->>LightSys: execute compressed mint
        LightSys-->>Compressed: success
        Compressed-->>TestWrapper: return success
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–25 minutes

  • Pay special attention to:
    • programs/compressed-token/program/src/mint_action/actions/create_mint.rs — derivation and comparison logic for compressed mint and correct error mapping.
    • programs/compressed-token/program/src/mint_action/queue_indices.rs — signature change and new in-tree index constraint interaction with other queue logic.
    • program-tests/compressed-token-test/tests/mint/cpi_context.rs — test correctness for positive and negative CPI-context scenarios.

Possibly related PRs

Suggested reviewers

  • sergeytimoshin
  • SwenSchaeferjohann

Poem

🐇 I hopped from zero-copy lanes,

planted pubkeys, checked the plains;
trees and mints now verified,
indices set, no sneaky stride;
CPI paths tidy, tests in bloom — hooray! 🌸

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: ctoken create mint cpi context address tree check' accurately describes the main change: adding validation for the address tree pubkey in CPI context for create mint operations.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jorrit/fix-ctoken-create-mint-cpi-context-address-tree-check

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@ananas-block ananas-block force-pushed the jorrit/fix-ctoken-create-mint-cpi-context-address-tree-check branch from 0c6cc51 to 06b6f1d Compare November 6, 2025 20:34
@ananas-block ananas-block force-pushed the jorrit/fix-ctoken-create-mint-cpi-context-address-tree-check branch from 06b6f1d to 1aaae1e Compare November 6, 2025 20:40
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 (3)
program-tests/compressed-token-test/Cargo.toml (1)

22-22: Duplicate dependency: light-sdk declared in both [dependencies] and [dev-dependencies].

Line 22 declares light-sdk = { workspace = true, features = ["anchor"] } in [dependencies], and Line 36 repeats the same declaration in [dev-dependencies]. Since dev-dependencies inherit from dependencies, this duplication is redundant and should be cleaned up.

Apply this change to remove the redundant declaration:

 [dev-dependencies]
 light-compressed-token = { workspace = true }
 light-system-program-anchor = { workspace = true }
 account-compression = { workspace = true }
 light-compressed-account = { workspace = true, features = ["std"] }
 light-batched-merkle-tree = { workspace = true }
 light-registry = { workspace = true }
 solana-sdk = { workspace = true }
 solana-system-interface = { workspace = true, features = ["bincode"] }

 forester-utils = { workspace = true }
 light-client = { workspace = true, features = ["devenv"] }
-light-sdk = { workspace = true, features = ["anchor"] }
 light-verifier = { workspace = true }

Also applies to: 36-36

programs/compressed-token/program/src/mint_action/queue_indices.rs (2)

22-22: Document the purpose of write_to_cpi_context parameter.

The new write_to_cpi_context parameter controls validation behavior but lacks documentation explaining when it should be true vs false and what "writing to CPI context" means in this context.

Consider adding a doc comment:

     pub fn new(
         cpi_context: Option<&ZCpiContext<'_>>,
         create_mint: bool,
         tokens_out_queue_exists: bool,
         queue_keys_match: bool,
+        /// Whether the CPI context is being written in this transaction.
+        /// When false during create_mint with CPI context, enforces in_tree_index == 1.
         write_to_cpi_context: bool,
     ) -> Result<QueueIndices, ErrorCode> {

27-30: Clarify the tree index constraint rationale.

The validation enforces in_tree_index == 1 when executing (not writing) CPI context for create_mint, but the comment on line 27 doesn't explain why this constraint exists or what would happen if a different index were used.

Consider enhancing the comment to explain the constraint:

-                // if executing with cpi context address tree index must be 1.
+                // When executing (not writing) CPI context for create_mint, the address tree
+                // must be at index 1 in the accounts array because [reason].
                 if !write_to_cpi_context && ctx.in_tree_index != 1 {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 170db77 and 1aaae1e.

📒 Files selected for processing (14)
  • anchor-programs/system/src/cpi_context_account.rs (1 hunks)
  • program-libs/ctoken-types/src/instructions/mint_action/cpi_context.rs (2 hunks)
  • program-tests/compressed-token-test/Cargo.toml (1 hunks)
  • program-tests/compressed-token-test/src/lib.rs (1 hunks)
  • program-tests/compressed-token-test/tests/mint.rs (1 hunks)
  • program-tests/compressed-token-test/tests/mint/cpi_context.rs (1 hunks)
  • programs/compressed-token/anchor/src/lib.rs (1 hunks)
  • programs/compressed-token/program/Cargo.toml (1 hunks)
  • programs/compressed-token/program/src/mint_action/actions/create_mint.rs (4 hunks)
  • programs/compressed-token/program/src/mint_action/processor.rs (1 hunks)
  • programs/compressed-token/program/src/mint_action/queue_indices.rs (1 hunks)
  • programs/compressed-token/program/tests/mint_action.rs (2 hunks)
  • programs/compressed-token/program/tests/queue_indices.rs (5 hunks)
  • sdk-libs/compressed-token-sdk/src/instructions/mint_action/instruction.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (36)
📓 Common learnings
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/**/*.rs : CPI processing functions must derive PDA signer seeds as [CPI_AUTHORITY_PDA_SEED, bump] and use CpiContext::new_with_signer with cpi_authority as the authority account and mapped target accounts.
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/*.rs : Context structs for wrapper instructions must include standard accounts: optional registered_forester_pda (mut), authority Signer, cpi_authority with seeds/bump for CPI_AUTHORITY_PDA_SEED, registered_program_pda, target program handle, log_wrapper, and mutable target_account.
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/*.rs : Each new operation module must define an Anchor context struct (e.g., NewOperationContext) with required accounts and a process_<operation> function that prepares signer seeds, maps accounts to the target program, and executes the CPI.
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/**/*.rs : Pass the data Vec<u8> through unchanged from the wrapper to the target program CPI; the target program performs deserialization.
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/*.rs : Context structs for wrapper instructions must include standard accounts: optional registered_forester_pda (mut), authority Signer, cpi_authority with seeds/bump for CPI_AUTHORITY_PDA_SEED, registered_program_pda, target program handle, log_wrapper, and mutable target_account.

Applied to files:

  • program-libs/ctoken-types/src/instructions/mint_action/cpi_context.rs
  • sdk-libs/compressed-token-sdk/src/instructions/mint_action/instruction.rs
  • anchor-programs/system/src/cpi_context_account.rs
  • programs/compressed-token/program/src/mint_action/processor.rs
  • programs/compressed-token/program/tests/mint_action.rs
  • programs/compressed-token/program/src/mint_action/queue_indices.rs
  • program-tests/compressed-token-test/tests/mint/cpi_context.rs
  • programs/compressed-token/program/src/mint_action/actions/create_mint.rs
  • programs/compressed-token/program/tests/queue_indices.rs
  • programs/compressed-token/anchor/src/lib.rs
  • program-tests/compressed-token-test/src/lib.rs
  • program-tests/compressed-token-test/tests/mint.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/**/*.rs : CPI processing functions must derive PDA signer seeds as [CPI_AUTHORITY_PDA_SEED, bump] and use CpiContext::new_with_signer with cpi_authority as the authority account and mapped target accounts.

Applied to files:

  • program-libs/ctoken-types/src/instructions/mint_action/cpi_context.rs
  • sdk-libs/compressed-token-sdk/src/instructions/mint_action/instruction.rs
  • anchor-programs/system/src/cpi_context_account.rs
  • programs/compressed-token/program/src/mint_action/processor.rs
  • programs/compressed-token/program/tests/mint_action.rs
  • programs/compressed-token/program/src/mint_action/queue_indices.rs
  • program-tests/compressed-token-test/tests/mint/cpi_context.rs
  • programs/compressed-token/program/src/mint_action/actions/create_mint.rs
  • programs/compressed-token/program/tests/queue_indices.rs
  • programs/compressed-token/anchor/src/lib.rs
  • program-tests/compressed-token-test/src/lib.rs
  • program-tests/compressed-token-test/tests/mint.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/*.rs : Each new operation module must define an Anchor context struct (e.g., NewOperationContext) with required accounts and a process_<operation> function that prepares signer seeds, maps accounts to the target program, and executes the CPI.

Applied to files:

  • program-libs/ctoken-types/src/instructions/mint_action/cpi_context.rs
  • sdk-libs/compressed-token-sdk/src/instructions/mint_action/instruction.rs
  • anchor-programs/system/src/cpi_context_account.rs
  • programs/compressed-token/program/src/mint_action/processor.rs
  • programs/compressed-token/program/tests/mint_action.rs
  • program-tests/compressed-token-test/tests/mint/cpi_context.rs
  • programs/compressed-token/program/src/mint_action/actions/create_mint.rs
  • programs/compressed-token/program/tests/queue_indices.rs
  • programs/compressed-token/anchor/src/lib.rs
  • program-tests/compressed-token-test/src/lib.rs
  • program-tests/compressed-token-test/tests/mint.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/mod.rs : Export each new operation module by adding pub mod <operation>; and re-export with pub use <operation>::*.

Applied to files:

  • program-libs/ctoken-types/src/instructions/mint_action/cpi_context.rs
  • sdk-libs/compressed-token-sdk/src/instructions/mint_action/instruction.rs
  • anchor-programs/system/src/cpi_context_account.rs
  • programs/compressed-token/program/src/mint_action/processor.rs
  • programs/compressed-token/program/tests/mint_action.rs
  • program-tests/compressed-token-test/tests/mint/cpi_context.rs
  • programs/compressed-token/program/src/mint_action/actions/create_mint.rs
  • programs/compressed-token/program/tests/queue_indices.rs
  • program-tests/compressed-token-test/src/lib.rs
  • programs/compressed-token/program/Cargo.toml
  • program-tests/compressed-token-test/tests/mint.rs
📚 Learning: 2025-10-16T06:33:55.362Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:55.362Z
Learning: Applies to programs/compressed-token/program/program-libs/ctoken-types/** : Define all state and instruction data structures in the light-ctoken-types crate (program-libs/ctoken-types), including state/, instructions/, and state/extensions/

Applied to files:

  • program-libs/ctoken-types/src/instructions/mint_action/cpi_context.rs
  • programs/compressed-token/program/tests/mint_action.rs
  • program-tests/compressed-token-test/Cargo.toml
  • program-tests/compressed-token-test/tests/mint/cpi_context.rs
  • programs/compressed-token/program/tests/queue_indices.rs
  • program-tests/compressed-token-test/src/lib.rs
  • programs/compressed-token/program/Cargo.toml
  • program-tests/compressed-token-test/tests/mint.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/**/*.rs : Pass the data Vec<u8> through unchanged from the wrapper to the target program CPI; the target program performs deserialization.

Applied to files:

  • program-libs/ctoken-types/src/instructions/mint_action/cpi_context.rs
  • sdk-libs/compressed-token-sdk/src/instructions/mint_action/instruction.rs
  • anchor-programs/system/src/cpi_context_account.rs
  • programs/compressed-token/program/src/mint_action/processor.rs
  • programs/compressed-token/program/tests/mint_action.rs
  • program-tests/compressed-token-test/tests/mint/cpi_context.rs
  • programs/compressed-token/program/src/mint_action/actions/create_mint.rs
  • program-tests/compressed-token-test/src/lib.rs
  • programs/compressed-token/program/Cargo.toml
  • program-tests/compressed-token-test/tests/mint.rs
📚 Learning: 2025-10-16T06:33:19.426Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:19.426Z
Learning: Applies to program-libs/compressible/src/config.rs : Ensure serialization compatibility across Anchor, Pinocchio, and Borsh for core account types used by dependent programs

Applied to files:

  • program-libs/ctoken-types/src/instructions/mint_action/cpi_context.rs
  • anchor-programs/system/src/cpi_context_account.rs
  • programs/compressed-token/program/src/mint_action/processor.rs
  • programs/compressed-token/program/tests/mint_action.rs
  • program-tests/compressed-token-test/Cargo.toml
  • programs/compressed-token/program/src/mint_action/actions/create_mint.rs
  • programs/compressed-token/program/tests/queue_indices.rs
  • programs/compressed-token/anchor/src/lib.rs
  • program-tests/compressed-token-test/src/lib.rs
  • programs/compressed-token/program/Cargo.toml
📚 Learning: 2025-10-16T06:33:19.426Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:19.426Z
Learning: Applies to program-libs/compressible/src/config.rs : Maintain CompressibleConfig account structure with Anchor/Borsh/Pod (Pinocchio/Pod) serialization and related state validation methods (validate_active, validate_not_inactive) in src/config.rs

Applied to files:

  • program-libs/ctoken-types/src/instructions/mint_action/cpi_context.rs
  • anchor-programs/system/src/cpi_context_account.rs
  • programs/compressed-token/program/tests/mint_action.rs
  • program-tests/compressed-token-test/Cargo.toml
  • programs/compressed-token/program/src/mint_action/actions/create_mint.rs
  • programs/compressed-token/program/tests/queue_indices.rs
  • programs/compressed-token/anchor/src/lib.rs
  • program-tests/compressed-token-test/src/lib.rs
  • programs/compressed-token/program/Cargo.toml
📚 Learning: 2025-10-16T06:33:19.426Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:19.426Z
Learning: Applies to program-libs/compressible/src/config.rs : Provide default initialization for the CToken V1 config in CompressibleConfig

Applied to files:

  • program-libs/ctoken-types/src/instructions/mint_action/cpi_context.rs
  • programs/compressed-token/program/tests/mint_action.rs
  • programs/compressed-token/program/Cargo.toml
📚 Learning: 2025-10-15T03:46:03.556Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/docs/instructions/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:03.556Z
Learning: Applies to programs/compressed-token/program/docs/instructions/instructions/MINT_ACTION.md : Document Mint operations and compressed mint management (9 actions) in instructions/MINT_ACTION.md

Applied to files:

  • sdk-libs/compressed-token-sdk/src/instructions/mint_action/instruction.rs
  • programs/compressed-token/program/src/mint_action/processor.rs
  • programs/compressed-token/program/tests/mint_action.rs
  • programs/compressed-token/program/src/mint_action/queue_indices.rs
  • program-tests/compressed-token-test/tests/mint/cpi_context.rs
  • programs/compressed-token/program/src/mint_action/actions/create_mint.rs
  • programs/compressed-token/program/tests/queue_indices.rs
  • programs/compressed-token/anchor/src/lib.rs
  • program-tests/compressed-token-test/src/lib.rs
📚 Learning: 2025-10-16T06:33:55.362Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:55.362Z
Learning: Applies to programs/compressed-token/program/src/create_token_account.rs : Create Token Account instruction must validate that the config state is ACTIVE only

Applied to files:

  • sdk-libs/compressed-token-sdk/src/instructions/mint_action/instruction.rs
  • programs/compressed-token/program/src/mint_action/processor.rs
  • program-tests/compressed-token-test/tests/mint/cpi_context.rs
  • programs/compressed-token/program/src/mint_action/actions/create_mint.rs
  • programs/compressed-token/program/tests/queue_indices.rs
  • program-tests/compressed-token-test/src/lib.rs
📚 Learning: 2025-10-15T03:46:03.556Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/docs/instructions/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:03.556Z
Learning: Applies to programs/compressed-token/program/docs/instructions/instructions/{CREATE_TOKEN_ACCOUNT,MINT_ACTION,TRANSFER2,CLAIM,CLOSE_TOKEN_ACCOUNT,DECOMPRESSED_TRANSFER,WITHDRAW_FUNDING_POOL}.md : Every instruction description must include sections: path, description, instruction_data, Accounts, instruction logic and checks, Errors

Applied to files:

  • sdk-libs/compressed-token-sdk/src/instructions/mint_action/instruction.rs
  • programs/compressed-token/program/src/mint_action/processor.rs
  • programs/compressed-token/program/src/mint_action/actions/create_mint.rs
  • programs/compressed-token/program/tests/queue_indices.rs
  • program-tests/compressed-token-test/src/lib.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/!(account_info)/**/*.rs : Use AccountInfoTrait for runtime-agnostic account handling; avoid direct solana-program or pinocchio AccountInfo in general logic

Applied to files:

  • anchor-programs/system/src/cpi_context_account.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/lib.rs : Wrapper instruction handlers must: (1) load the target account metadata; (2) call check_forester with correct authority, target, forester PDA (optional), and computed work_units; (3) delegate via a CPI using a PDA signer.

Applied to files:

  • anchor-programs/system/src/cpi_context_account.rs
  • programs/compressed-token/program/src/mint_action/processor.rs
  • program-tests/compressed-token-test/tests/mint/cpi_context.rs
  • programs/compressed-token/program/src/mint_action/actions/create_mint.rs
  • programs/compressed-token/program/tests/queue_indices.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/account_info/account_info_trait.rs : Ensure the crate compiles with no features enabled by keeping trait definitions free of SDK-specific dependencies

Applied to files:

  • anchor-programs/system/src/cpi_context_account.rs
  • programs/compressed-token/program/Cargo.toml
📚 Learning: 2025-10-15T03:46:03.556Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/docs/instructions/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:03.556Z
Learning: Applies to programs/compressed-token/program/docs/instructions/instructions/DECOMPRESSED_TRANSFER.md : Document SPL-compatible transfers between decompressed accounts in instructions/DECOMPRESSED_TRANSFER.md

Applied to files:

  • anchor-programs/system/src/cpi_context_account.rs
  • programs/compressed-token/program/src/mint_action/actions/create_mint.rs
  • program-tests/compressed-token-test/src/lib.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/lib.rs : Load accounts according to type before check_forester: batched via BatchedMerkleTreeAccount::type_from_account_info(); regular via ctx.accounts.account.load()?.metadata; use custom deserialization when required.

Applied to files:

  • anchor-programs/system/src/cpi_context_account.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/account_info/{solana.rs,pinocchio.rs,test_account_info.rs} : Provide SDK-specific AccountInfoTrait implementations in account_info/{solana.rs,pinocchio.rs,test_account_info.rs}

Applied to files:

  • anchor-programs/system/src/cpi_context_account.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/**/*.rs : On account initialization, call account_info_init to set the 8-byte discriminator

Applied to files:

  • anchor-programs/system/src/cpi_context_account.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/account_info/test_account_info.rs : Use the mock AccountInfo implementation under the test-only feature for unit tests

Applied to files:

  • anchor-programs/system/src/cpi_context_account.rs
  • programs/compressed-token/program/Cargo.toml
📚 Learning: 2025-10-16T06:33:55.362Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:55.362Z
Learning: Applies to programs/compressed-token/program/src/create_associated_token_account.rs : Create Associated Token Account instruction must validate that the config state is ACTIVE only

Applied to files:

  • programs/compressed-token/program/src/mint_action/processor.rs
  • program-tests/compressed-token-test/tests/mint/cpi_context.rs
  • programs/compressed-token/program/src/mint_action/actions/create_mint.rs
  • programs/compressed-token/program/tests/queue_indices.rs
  • program-tests/compressed-token-test/src/lib.rs
📚 Learning: 2025-10-16T06:33:55.362Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:55.362Z
Learning: Applies to programs/compressed-token/program/src/withdraw_funding_pool.rs : Withdraw Funding Pool instruction must validate that the config state is not INACTIVE (active or deprecated allowed)

Applied to files:

  • programs/compressed-token/program/src/mint_action/processor.rs
  • program-tests/compressed-token-test/tests/mint/cpi_context.rs
📚 Learning: 2025-10-15T03:46:03.556Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/docs/instructions/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:03.556Z
Learning: Applies to programs/compressed-token/program/docs/instructions/instructions/CREATE_TOKEN_ACCOUNT.md : Document Create Token Account & Associated Token Account instructions in instructions/CREATE_TOKEN_ACCOUNT.md

Applied to files:

  • programs/compressed-token/program/src/mint_action/processor.rs
  • program-tests/compressed-token-test/src/lib.rs
📚 Learning: 2025-10-15T03:45:40.038Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/docs/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:45:40.038Z
Learning: Applies to programs/compressed-token/program/docs/**/instructions/CREATE_TOKEN_ACCOUNT.md : Provide CREATE_TOKEN_ACCOUNT.md in the instructions/ directory documenting create token account and associated token account instructions

Applied to files:

  • programs/compressed-token/program/src/mint_action/processor.rs
  • program-tests/compressed-token-test/src/lib.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/**/Cargo.toml : Define features solana, pinocchio, and test-only in Cargo.toml; default build should enable none

Applied to files:

  • program-tests/compressed-token-test/Cargo.toml
  • programs/compressed-token/program/Cargo.toml
📚 Learning: 2025-10-15T03:46:43.242Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-tests/sdk-token-test/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:43.242Z
Learning: Applies to sdk-tests/sdk-token-test/**/tests/**/*.rs : Every test should only contain functional integration tests

Applied to files:

  • program-tests/compressed-token-test/tests/mint/cpi_context.rs
📚 Learning: 2025-10-16T06:33:55.362Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:55.362Z
Learning: Applies to programs/compressed-token/program/programs/compressed-token/anchor/src/lib.rs : Define all program-specific error codes in anchor_compressed_token::ErrorCode in programs/compressed-token/anchor/src/lib.rs; return errors as ProgramError::Custom(error_code as u32)

Applied to files:

  • programs/compressed-token/program/src/mint_action/actions/create_mint.rs
  • programs/compressed-token/program/tests/queue_indices.rs
  • programs/compressed-token/anchor/src/lib.rs
📚 Learning: 2025-10-16T06:33:19.426Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:19.426Z
Learning: Applies to program-libs/compressible/src/config.rs : Provide PDA derivation helpers (derive_pda, derive_v1_config_pda) in src/config.rs for CompressibleConfig

Applied to files:

  • programs/compressed-token/program/src/mint_action/actions/create_mint.rs
📚 Learning: 2025-10-16T06:33:19.426Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:19.426Z
Learning: Applies to program-libs/compressible/src/error.rs : Define error types with numeric codes in the 19xxx range and propagate hasher errors in the 7xxx range; include ProgramError conversions (Anchor, Pinocchio, Solana) in src/error.rs

Applied to files:

  • programs/compressed-token/program/tests/queue_indices.rs
  • programs/compressed-token/anchor/src/lib.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/error.rs : Maintain stable mapping of AccountError to ProgramError, including Pinocchio code mapping (1–11), in error.rs

Applied to files:

  • programs/compressed-token/anchor/src/lib.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/**/*.rs : Return AccountError variants (codes 12006–12021) and rely on automatic ProgramError conversions; avoid returning raw ProgramError directly

Applied to files:

  • programs/compressed-token/anchor/src/lib.rs
📚 Learning: 2025-10-16T06:33:55.362Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:55.362Z
Learning: Applies to programs/compressed-token/program/docs/ACCOUNTS.md : Account documentation must include: description, discriminator, state layout, serialization example, hashing (only for compressed accounts), derivation (only for PDAs), and associated instructions

Applied to files:

  • program-tests/compressed-token-test/src/lib.rs
  • programs/compressed-token/program/Cargo.toml
📚 Learning: 2025-10-15T03:45:40.038Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/docs/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:45:40.038Z
Learning: Applies to programs/compressed-token/program/docs/**/ACCOUNTS.md : Maintain ACCOUNTS.md with complete account layouts and data structures

Applied to files:

  • programs/compressed-token/program/Cargo.toml
📚 Learning: 2025-10-15T03:46:03.556Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/docs/instructions/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:03.556Z
Learning: Applies to programs/compressed-token/program/docs/instructions/**/ACCOUNTS.md : Provide complete account layouts and data structures in ACCOUNTS.md

Applied to files:

  • programs/compressed-token/program/Cargo.toml
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/account_info/{solana.rs,pinocchio.rs,test_account_info.rs} : Gate SDK-specific implementations with #[cfg(feature = "solana"|"pinocchio"|"test-only")]

Applied to files:

  • programs/compressed-token/program/Cargo.toml
🧬 Code graph analysis (6)
anchor-programs/system/src/cpi_context_account.rs (1)
programs/system/src/lib.rs (1)
  • invoke_cpi (118-136)
programs/compressed-token/program/src/mint_action/queue_indices.rs (1)
sdk-tests/sdk-token-test/tests/pda_ctoken.rs (1)
  • create_mint (186-352)
program-tests/compressed-token-test/tests/mint/cpi_context.rs (2)
sdk-libs/compressed-token-sdk/src/instructions/mint_action/instruction.rs (2)
  • create_mint_action_cpi (257-446)
  • mint_action_cpi_write (644-812)
sdk-libs/program-test/src/utils/assert.rs (1)
  • assert_rpc_error (7-144)
programs/compressed-token/program/src/mint_action/actions/create_mint.rs (1)
program-libs/array-map/src/lib.rs (1)
  • pubkey_eq (171-181)
programs/compressed-token/program/tests/queue_indices.rs (2)
programs/compressed-token/program/src/mint_action/queue_indices.rs (1)
  • new (17-76)
program-libs/ctoken-types/src/instructions/mint_action/cpi_context.rs (1)
  • default (25-37)
program-tests/compressed-token-test/src/lib.rs (1)
sdk-libs/macros/src/program.rs (1)
  • program (290-301)
⏰ 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). (21)
  • GitHub Check: stateless-js-v2
  • GitHub Check: programs (account-compression-and-registry, ["cargo-test-sbf -p account-compression-test", "cargo...
  • GitHub Check: programs (light-system-program-compression, ["cargo-test-sbf -p system-test -- test_with_compress...
  • GitHub Check: programs (system-cpi-test-v2-functional-account-infos, ["cargo-test-sbf -p system-cpi-v2-test -- ...
  • GitHub Check: programs (compressed-token-and-e2e, ["cargo-test-sbf -p compressed-token-test --test v1", "cargo-...
  • GitHub Check: programs (light-system-program-address, ["cargo-test-sbf -p system-test -- test_with_address", "c...
  • GitHub Check: programs (compressed-token-batched-tree, ["cargo-test-sbf -p compressed-token-test -- test_transf...
  • GitHub Check: programs (system-cpi-test-v2-functional-read-only, ["cargo-test-sbf -p system-cpi-v2-test -- func...
  • GitHub Check: programs (system-cpi-test, ["cargo-test-sbf -p system-cpi-test", "cargo test -p light-system-prog...
  • GitHub Check: system-programs (native, ["cargo-test-sbf -p sdk-native-test", "cargo-test-sbf -p sdk-v1-native-t...
  • GitHub Check: system-programs (token test, ["cargo-test-sbf -p sdk-token-test"])
  • GitHub Check: system-programs (anchor & pinocchio, ["cargo-test-sbf -p sdk-anchor-test", "cargo-test-sbf -p sdk...
  • GitHub Check: Test program-libs-slow
  • GitHub Check: system-programs (sdk-libs, light-sdk-macros light-sdk light-program-test light-client light-compr...
  • GitHub Check: Test batched-merkle-tree-simulate
  • GitHub Check: Test program-libs-fast
  • GitHub Check: Forester e2e test
  • GitHub Check: cli-v1
  • GitHub Check: cli-v2
  • GitHub Check: lint
  • GitHub Check: stateless-js-v1
🔇 Additional comments (21)
programs/compressed-token/program/Cargo.toml (1)

80-80: Test-dependency addition aligns with PR objectives.

The dev-dependency addition with ["keccak", "sha256"] features aligns well with the PR's address tree validation work. Having different feature sets for the production dependency (line 49, ["anchor"]) versus test-only usage is a valid pattern in Rust.

Verify that the test code actually uses these keccak and sha256 features (not visible in this file). Additionally, confirm there are no conflicting feature requirements between the production and dev-dependency configurations by checking if tests need the anchor feature as well.

anchor-programs/system/src/cpi_context_account.rs (1)

3-3: LGTM: Import simplification.

The consolidation to a single import path improves clarity.

programs/compressed-token/program/tests/queue_indices.rs (2)

256-256: LGTM: Correct parameter mapping for write_to_cpi_context.

The logic correctly computes write_to_cpi_context from CPI context flags (first_set_context || set_context) when present, and passes false when no CPI context exists, aligning with the updated QueueIndices::new signature.

Also applies to: 264-264


280-351: LGTM: Comprehensive test coverage for address tree index validation.

The new test validates both the error path (in_tree_index != 1 in execute mode) and success path (in_tree_index == 1), ensuring the MintActionInvalidCpiContextForCreateMint error is correctly raised when validation fails.

program-tests/compressed-token-test/tests/mint.rs (1)

5-6: LGTM: Module addition for CPI context tests.

The new module declaration properly integrates the CPI context test suite into the mint test structure.

programs/compressed-token/program/src/mint_action/processor.rs (1)

71-71: LGTM: Correct parameter forwarding.

The write_to_cpi_context flag is properly forwarded from accounts_config to QueueIndices::new, enabling CPI-context validation logic introduced in this PR.

sdk-libs/compressed-token-sdk/src/instructions/mint_action/instruction.rs (1)

511-512: LGTM: Explicit CPI context field initialization.

The explicit initialization of read_only_address_trees and address_tree_pubkey with CMINT_ADDRESS_TREE aligns with the new CpiContext structure and improves code clarity.

programs/compressed-token/program/tests/mint_action.rs (1)

19-19: LGTM: Test data generator updated for new CpiContext field.

The random_cpi_context helper correctly initializes the new address_tree_pubkey field with CMINT_ADDRESS_TREE, ensuring test compatibility with the updated CpiContext structure.

Also applies to: 142-142

programs/compressed-token/anchor/src/lib.rs (1)

419-424: LGTM: New error codes for CPI-context validation.

The three new error variants provide clear, specific error messages for CPI-context validation scenarios introduced in this PR:

  • Compressed mint address derivation failures
  • Invalid CPI context during mint creation
  • Address tree pubkey mismatches
program-libs/ctoken-types/src/instructions/mint_action/cpi_context.rs (2)

24-38: LGTM! Default implementation is correct.

The Default implementation properly initializes all fields, including the new address_tree_pubkey field with CMINT_ADDRESS_TREE. This ensures correct default behavior for CPI context mint operations.


21-22: CpiContext field addition is correctly implemented—no action required.

The address_tree_pubkey field was added to a #[repr(C)] zero-copy struct, which changes the memory layout. However, this is not a breaking change in practice because:

  1. CpiContext is ephemeral instruction data, not persistent on-chain storage. It's serialized/deserialized only for the duration of instruction execution, never retrieved from stored accounts.

  2. All callers updated correctly: Builder methods either explicitly set address_tree_pubkey: light_ctoken_types::CMINT_ADDRESS_TREE (e.g., line 512) or safely use ..Default::default() (e.g., line 537), which was added in the same commit and correctly initializes the field.

  3. No account state affected: The system program maintains separate CpiContextAccount structures with versioning (V1/V2 discriminators); this change only affects the mint action instruction data.

programs/compressed-token/program/src/mint_action/actions/create_mint.rs (3)

26-43: LGTM! Improved PDA derivation and validation.

The change to use create_program_address and convert to bytes afterward is more explicit and maintains proper validation. The direct byte comparison at line 40 is correct since both sides are now [u8; 32].


44-65: Well-implemented CPI context validation.

The added validation correctly:

  1. Checks that address_tree_pubkey matches CMINT_ADDRESS_TREE
  2. Derives the expected compressed mint address
  3. Validates it matches the provided address

This prevents invalid address tree usage and ensures address derivation correctness when CPI context is used.


106-112: No breaking change — review comment is incorrect.

The validation only applies when extensions is Some. Mints without extensions (passing extensions: None) skip the entire validation block entirely and are permitted. The code correctly allows:

  • extensions: None → validation skipped, passes
  • extensions: Some([single_extension]) → validation passes
  • extensions: Some([]) or Some([ext1, ext2]) → validation fails (correctly rejects)

The existing tests in the repository already use extensions: None and will continue to work.

Likely an incorrect or invalid review comment.

program-tests/compressed-token-test/tests/mint/cpi_context.rs (5)

36-108: Well-structured test setup helper.

The test_setup() function properly initializes the test environment and constructs reusable test inputs. Good separation of concerns.


110-192: Comprehensive happy path test.

The test correctly verifies:

  1. CPI context account is created with data
  2. Account is owned by light system program
  3. No on-chain compressed mint exists in write mode

Good coverage of the write-to-CPI-context flow.


194-247: Proper validation of address tree check.

Test correctly verifies that an invalid address_tree_pubkey results in error code 105 (MintActionInvalidCpiContextAddressTreePubkey). This validates the check added in create_mint.rs at line 52.


249-303: Proper validation of compressed address check.

Test correctly verifies that an invalid compressed address results in error code 103 (MintActionInvalidCompressedMintAddress). This validates the check added in create_mint.rs at line 61.


305-387: Proper validation of tree index constraint.

Test correctly verifies that an invalid in_tree_index (5 instead of 1) in execute mode results in error code 104 (MintActionInvalidCpiContextForCreateMint). This validates the check added in queue_indices.rs at line 28.

program-tests/compressed-token-test/src/lib.rs (2)

15-29: Clean wrapper design with good code reuse.

Both wrapper functions appropriately delegate to the shared implementation. The minimal validation is correct for a test harness program.


42-70: Well-implemented CPI passthrough for testing.

The shared implementation correctly:

  1. Maps remaining_accounts to AccountMeta preserving writable/signer flags
  2. Passes through raw instruction bytes without modification
  3. Uses simple invoke without signer seeds (appropriate for test wrapper)

Good minimal test harness design.

Copy link
Contributor

@SwenSchaeferjohann SwenSchaeferjohann left a comment

Choose a reason for hiding this comment

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

lgtm

@ananas-block ananas-block merged commit b274635 into main Nov 7, 2025
39 of 41 checks passed
@ananas-block ananas-block deleted the jorrit/fix-ctoken-create-mint-cpi-context-address-tree-check branch November 7, 2025 22:31
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.

3 participants