Skip to content

fix: panic on unknown extension types in CToken equality check#2106

Merged
ananas-block merged 5 commits intomainfrom
jorrit/fix-l04-unknown-extension-panic
Dec 7, 2025
Merged

fix: panic on unknown extension types in CToken equality check#2106
ananas-block merged 5 commits intomainfrom
jorrit/fix-l04-unknown-extension-panic

Conversation

@ananas-block
Copy link
Contributor

@ananas-block ananas-block commented Dec 7, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved token-type comparison accuracy across varied token configurations.
    • Enhanced robustness by surfacing mismatched or unsupported token extension combinations earlier.
  • Chores

    • Added a development-only "test-only" feature to enable extended cross-type test comparisons for token state validation and updated dev-dependency feature flags.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 7, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock and included by none
  • program-tests/utils/Cargo.toml is excluded by none and included by none

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Adds test-only cross-type PartialEq implementations between ZCToken and CToken with explicit, field-by-field comparisons for core fields and known extension pairs, returning false for mismatched known types and panicking on unknown extension combinations; also adds a test-only Cargo feature and enables it for a dev-dependency.

Changes

Cohort / File(s) Change Summary
ZCToken ↔ CToken equality impls
program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs
Added #[cfg(feature = "test-only")] impl PartialEq<CToken> for ZCToken<'_> and reciprocal impl PartialEq<ZCToken<'_>> for CToken; perform detailed, field-by-field comparisons for core fields and known extension pairs (Compressible vs Compressible, TokenMetadata vs TokenMetadata); return false for mismatched known extension types and panic! on unknown/unhandled extension combinations.
Cargo feature and dev-deps
program-libs/ctoken-interface/Cargo.toml
Introduced new feature test-only; updated dev-dependency light-ctoken-interface to enable features ["poseidon", "test-only"].

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review zero_copy.rs equality branches for exhaustive coverage of extension variants and correct handling of Option fields (delegate, close_authority).
  • Confirm the panic branch is intentionally used to surface developer errors and is acceptable in test-only code.
  • Verify Cargo feature gating is limited to tests and doesn't affect production builds.

Possibly related PRs

Suggested labels

ai-review

Suggested reviewers

  • sergeytimoshin
  • SwenSchaeferjohann

Poem

Tiny impls line up fields with care,
Known extensions paired and checked with flair.
Tests wear a flag, a quiet little key,
Panic for the strange — caught early we see. 🎭

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 70.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding panic handling for unknown extension types in CToken equality checks, which is the core of the modifications.

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff145bd and df3ece0.

📒 Files selected for processing (1)
  • program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
program-libs/**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

Unit tests in program-libs must not depend on light-test-utils; tests requiring light-test-utils must be located in program-tests/

Files:

  • program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs
🧠 Learnings (11)
📓 Common learnings
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-tests/sdk-ctoken-test/README.md:0-0
Timestamp: 2025-12-07T00:45:07.921Z
Learning: Applies to sdk-tests/sdk-ctoken-test/**/*.rs : Use the builder pattern from `light-ctoken-sdk::ctoken` module for CPI operations in native Solana programs
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-12-06T00:49:21.983Z
Learning: Applies to program-libs/compressible/src/error.rs : Error types must use numeric codes in the 19xxx range for CToken-specific errors
📚 Learning: 2025-11-24T17:54:20.982Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/zero-copy-derive/README.md:0-0
Timestamp: 2025-11-24T17:54:20.982Z
Learning: Applies to program-libs/zero-copy-derive/**/*.rs : Apply #[derive(ZeroCopyEq)] macro to structs to derive PartialEq comparing ZeroCopy representation with original struct

Applied to files:

  • program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs
📚 Learning: 2025-12-06T00:49:21.983Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-12-06T00:49:21.983Z
Learning: Applies to program-libs/compressible/src/error.rs : Error types must use numeric codes in the 19xxx range for CToken-specific errors

Applied to files:

  • program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs
📚 Learning: 2025-12-06T00:49:37.752Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-12-06T00:49:37.752Z
Learning: Applies to programs/compressed-token/program/**/create_*token_account*.rs : CToken account layout is the same as SPL tokens but implements a custom Compressible extension

Applied to files:

  • program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs
📚 Learning: 2025-12-06T00:49:37.752Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-12-06T00:49:37.752Z
Learning: Applies to programs/compressed-token/program/**/mint_action/*.rs : Compressed mint accounts support one extension: TokenMetadata

Applied to files:

  • program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs
📚 Learning: 2025-12-06T00:49:21.983Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-12-06T00:49:21.983Z
Learning: Applies to program-libs/compressible/src/config.rs : Implement default initialization for CToken V1 config in CompressibleConfig structure

Applied to files:

  • program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs
📚 Learning: 2025-11-24T17:54:20.982Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/zero-copy-derive/README.md:0-0
Timestamp: 2025-11-24T17:54:20.982Z
Learning: Applies to program-libs/zero-copy-derive/**/*.rs : Boolean types are converted to u8 in zero-copy structs for alignment and serialization

Applied to files:

  • program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs
📚 Learning: 2025-11-24T17:55:17.323Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-libs/macros/src/compressible/README.md:0-0
Timestamp: 2025-11-24T17:55:17.323Z
Learning: Applies to sdk-libs/macros/src/compressible/**/instructions.rs : Compress/decompress instruction handlers and context struct generation should be implemented in `instructions.rs`, with compress using PDA-only and decompress supporting full PDA + ctoken

Applied to files:

  • program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs
📚 Learning: 2025-12-06T00:49:37.752Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-12-06T00:49:37.752Z
Learning: Applies to programs/compressed-token/program/**/ctoken_transfer.rs : CTokenTransfer instruction is SPL-compatible and transfers between decompressed accounts only

Applied to files:

  • program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs
📚 Learning: 2025-12-06T00:49:37.752Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-12-06T00:49:37.752Z
Learning: Applies to programs/compressed-token/program/program-libs/ctoken-types/src/{state,instructions}/**/*.rs : All program state and instruction data structures must be defined in the program-libs/ctoken-types crate (light-ctoken-interface) under state/ and instructions/ directories to allow SDKs to import types without pulling in program dependencies

Applied to files:

  • program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs
📚 Learning: 2025-11-24T17:55:17.323Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-libs/macros/src/compressible/README.md:0-0
Timestamp: 2025-11-24T17:55:17.323Z
Learning: Applies to sdk-libs/macros/src/compressible/**/decompress_context.rs : Decompression trait implementation (`DecompressContext`) with account accessors, PDA/token separation logic, and token processing delegation should be in `decompress_context.rs`

Applied to files:

  • program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs

@ananas-block ananas-block merged commit 3f662d9 into main Dec 7, 2025
30 checks passed
@ananas-block ananas-block deleted the jorrit/fix-l04-unknown-extension-panic branch December 7, 2025 19:35
@coderabbitai coderabbitai bot mentioned this pull request Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants