fix: ctoken create mint cpi context address tree check#2039
Conversation
WalkthroughThis PR removes a zero-copy CPI context deserialization path from the system program, adds an explicit Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–25 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
0c6cc51 to
06b6f1d
Compare
06b6f1d to
1aaae1e
Compare
There was a problem hiding this comment.
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 ofwrite_to_cpi_contextparameter.The new
write_to_cpi_contextparameter 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 == 1when 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
📒 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.rssdk-libs/compressed-token-sdk/src/instructions/mint_action/instruction.rsanchor-programs/system/src/cpi_context_account.rsprograms/compressed-token/program/src/mint_action/processor.rsprograms/compressed-token/program/tests/mint_action.rsprograms/compressed-token/program/src/mint_action/queue_indices.rsprogram-tests/compressed-token-test/tests/mint/cpi_context.rsprograms/compressed-token/program/src/mint_action/actions/create_mint.rsprograms/compressed-token/program/tests/queue_indices.rsprograms/compressed-token/anchor/src/lib.rsprogram-tests/compressed-token-test/src/lib.rsprogram-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.rssdk-libs/compressed-token-sdk/src/instructions/mint_action/instruction.rsanchor-programs/system/src/cpi_context_account.rsprograms/compressed-token/program/src/mint_action/processor.rsprograms/compressed-token/program/tests/mint_action.rsprograms/compressed-token/program/src/mint_action/queue_indices.rsprogram-tests/compressed-token-test/tests/mint/cpi_context.rsprograms/compressed-token/program/src/mint_action/actions/create_mint.rsprograms/compressed-token/program/tests/queue_indices.rsprograms/compressed-token/anchor/src/lib.rsprogram-tests/compressed-token-test/src/lib.rsprogram-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.rssdk-libs/compressed-token-sdk/src/instructions/mint_action/instruction.rsanchor-programs/system/src/cpi_context_account.rsprograms/compressed-token/program/src/mint_action/processor.rsprograms/compressed-token/program/tests/mint_action.rsprogram-tests/compressed-token-test/tests/mint/cpi_context.rsprograms/compressed-token/program/src/mint_action/actions/create_mint.rsprograms/compressed-token/program/tests/queue_indices.rsprograms/compressed-token/anchor/src/lib.rsprogram-tests/compressed-token-test/src/lib.rsprogram-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.rssdk-libs/compressed-token-sdk/src/instructions/mint_action/instruction.rsanchor-programs/system/src/cpi_context_account.rsprograms/compressed-token/program/src/mint_action/processor.rsprograms/compressed-token/program/tests/mint_action.rsprogram-tests/compressed-token-test/tests/mint/cpi_context.rsprograms/compressed-token/program/src/mint_action/actions/create_mint.rsprograms/compressed-token/program/tests/queue_indices.rsprogram-tests/compressed-token-test/src/lib.rsprograms/compressed-token/program/Cargo.tomlprogram-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.rsprograms/compressed-token/program/tests/mint_action.rsprogram-tests/compressed-token-test/Cargo.tomlprogram-tests/compressed-token-test/tests/mint/cpi_context.rsprograms/compressed-token/program/tests/queue_indices.rsprogram-tests/compressed-token-test/src/lib.rsprograms/compressed-token/program/Cargo.tomlprogram-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.rssdk-libs/compressed-token-sdk/src/instructions/mint_action/instruction.rsanchor-programs/system/src/cpi_context_account.rsprograms/compressed-token/program/src/mint_action/processor.rsprograms/compressed-token/program/tests/mint_action.rsprogram-tests/compressed-token-test/tests/mint/cpi_context.rsprograms/compressed-token/program/src/mint_action/actions/create_mint.rsprogram-tests/compressed-token-test/src/lib.rsprograms/compressed-token/program/Cargo.tomlprogram-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.rsanchor-programs/system/src/cpi_context_account.rsprograms/compressed-token/program/src/mint_action/processor.rsprograms/compressed-token/program/tests/mint_action.rsprogram-tests/compressed-token-test/Cargo.tomlprograms/compressed-token/program/src/mint_action/actions/create_mint.rsprograms/compressed-token/program/tests/queue_indices.rsprograms/compressed-token/anchor/src/lib.rsprogram-tests/compressed-token-test/src/lib.rsprograms/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.rsanchor-programs/system/src/cpi_context_account.rsprograms/compressed-token/program/tests/mint_action.rsprogram-tests/compressed-token-test/Cargo.tomlprograms/compressed-token/program/src/mint_action/actions/create_mint.rsprograms/compressed-token/program/tests/queue_indices.rsprograms/compressed-token/anchor/src/lib.rsprogram-tests/compressed-token-test/src/lib.rsprograms/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.rsprograms/compressed-token/program/tests/mint_action.rsprograms/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.rsprograms/compressed-token/program/src/mint_action/processor.rsprograms/compressed-token/program/tests/mint_action.rsprograms/compressed-token/program/src/mint_action/queue_indices.rsprogram-tests/compressed-token-test/tests/mint/cpi_context.rsprograms/compressed-token/program/src/mint_action/actions/create_mint.rsprograms/compressed-token/program/tests/queue_indices.rsprograms/compressed-token/anchor/src/lib.rsprogram-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.rsprograms/compressed-token/program/src/mint_action/processor.rsprogram-tests/compressed-token-test/tests/mint/cpi_context.rsprograms/compressed-token/program/src/mint_action/actions/create_mint.rsprograms/compressed-token/program/tests/queue_indices.rsprogram-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.rsprograms/compressed-token/program/src/mint_action/processor.rsprograms/compressed-token/program/src/mint_action/actions/create_mint.rsprograms/compressed-token/program/tests/queue_indices.rsprogram-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.rsprograms/compressed-token/program/src/mint_action/processor.rsprogram-tests/compressed-token-test/tests/mint/cpi_context.rsprograms/compressed-token/program/src/mint_action/actions/create_mint.rsprograms/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.rsprograms/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.rsprograms/compressed-token/program/src/mint_action/actions/create_mint.rsprogram-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.rsprograms/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.rsprogram-tests/compressed-token-test/tests/mint/cpi_context.rsprograms/compressed-token/program/src/mint_action/actions/create_mint.rsprograms/compressed-token/program/tests/queue_indices.rsprogram-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.rsprogram-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.rsprogram-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.rsprogram-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.tomlprograms/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.rsprograms/compressed-token/program/tests/queue_indices.rsprograms/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.rsprograms/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.rsprograms/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
keccakandsha256features (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 theanchorfeature 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_contextfrom CPI context flags (first_set_context || set_context) when present, and passesfalsewhen no CPI context exists, aligning with the updatedQueueIndices::newsignature.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
MintActionInvalidCpiContextForCreateMinterror 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_contextflag is properly forwarded fromaccounts_configtoQueueIndices::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_treesandaddress_tree_pubkeywithCMINT_ADDRESS_TREEaligns with the newCpiContextstructure 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_contexthelper correctly initializes the newaddress_tree_pubkeyfield withCMINT_ADDRESS_TREE, ensuring test compatibility with the updatedCpiContextstructure.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
Defaultimplementation properly initializes all fields, including the newaddress_tree_pubkeyfield withCMINT_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_pubkeyfield was added to a#[repr(C)]zero-copy struct, which changes the memory layout. However, this is not a breaking change in practice because:
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.
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.No account state affected: The system program maintains separate
CpiContextAccountstructures 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_addressand 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:
- Checks that
address_tree_pubkeymatchesCMINT_ADDRESS_TREE- Derives the expected compressed mint address
- 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
extensionsisSome. Mints without extensions (passingextensions: None) skip the entire validation block entirely and are permitted. The code correctly allows:
extensions: None→ validation skipped, passesextensions: Some([single_extension])→ validation passesextensions: Some([])orSome([ext1, ext2])→ validation fails (correctly rejects)The existing tests in the repository already use
extensions: Noneand 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:
- CPI context account is created with data
- Account is owned by light system program
- 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_pubkeyresults in error code 105 (MintActionInvalidCpiContextAddressTreePubkey). This validates the check added increate_mint.rsat 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 increate_mint.rsat 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 inqueue_indices.rsat 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:
- Maps remaining_accounts to AccountMeta preserving writable/signer flags
- Passes through raw instruction bytes without modification
- Uses simple
invokewithout signer seeds (appropriate for test wrapper)Good minimal test harness design.
Fixes:
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)CMINT_ADDRESS_TREEin SDK to prevent users from specifying arbitrary address treesTests:
MintActionInvalidCompressedMintAddress,MintActionInvalidCpiContextAddressTreePubkey,MintActionInvalidCpiContextForCreateMintMintActionInvalidCpiContextForCreateMint