From df3ece031a6717de8167f3759b1bfff61eb5c92a Mon Sep 17 00:00:00 2001 From: ananas-block Date: Sun, 7 Dec 2025 01:06:20 +0000 Subject: [PATCH 1/4] fix: panic on unknown extension types in CToken equality check --- .../src/state/ctoken/zero_copy.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs b/program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs index 8460abb1ed..71bcd44816 100644 --- a/program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs +++ b/program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs @@ -380,7 +380,23 @@ impl PartialEq for ZCToken<'_> { } } } - _ => return false, // Different extension types + // Mismatched known extension types (e.g., Compressible vs TokenMetadata) + ( + crate::state::extensions::ZExtensionStruct::Compressible(_), + crate::state::extensions::ExtensionStruct::TokenMetadata(_), + ) + | ( + crate::state::extensions::ZExtensionStruct::TokenMetadata(_), + crate::state::extensions::ExtensionStruct::Compressible(_), + ) => return false, + // Unknown or unhandled extension types should panic to surface bugs early + (zc_ext, regular_ext) => { + panic!( + "Unknown extension type comparison: ZCToken extension {:?} vs CToken extension {:?}", + std::mem::discriminant(zc_ext), + std::mem::discriminant(regular_ext) + ); + } } } } From 3753035bea4227cc7f49acb97a20c4e9c05c82b6 Mon Sep 17 00:00:00 2001 From: ananas-block Date: Sun, 7 Dec 2025 14:45:45 +0000 Subject: [PATCH 2/4] chore: gate panicking partial eq behind test-only feature --- program-libs/ctoken-interface/Cargo.toml | 3 ++- program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/program-libs/ctoken-interface/Cargo.toml b/program-libs/ctoken-interface/Cargo.toml index 95075d141d..c3aaec94c9 100644 --- a/program-libs/ctoken-interface/Cargo.toml +++ b/program-libs/ctoken-interface/Cargo.toml @@ -7,6 +7,7 @@ edition = { workspace = true } anchor = ["light-compressed-account/anchor", "dep:anchor-lang", "light-compressible/anchor"] solana = ["dep:solana-program-error", "dep:solana-sysvar", "solana-msg"] default = [] +test-only = [] profile-program = [] profile-heap = ["dep:light-heap"] poseidon = ["light-hasher/poseidon"] @@ -49,7 +50,7 @@ light-account-checks = { workspace = true, features = [ "solana", ] } spl-token-metadata-interface = "0.6.0" -light-ctoken-interface = { workspace = true, features = ["poseidon"] } +light-ctoken-interface = { workspace = true, features = ["poseidon", "test-only"] } light-hasher = { workspace = true, features = ["keccak", "sha256"] } [lints.rust.unexpected_cfgs] diff --git a/program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs b/program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs index 71bcd44816..f0642b4966 100644 --- a/program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs +++ b/program-libs/ctoken-interface/src/state/ctoken/zero_copy.rs @@ -231,6 +231,7 @@ impl<'a> Deref for ZCToken<'a> { } } +#[cfg(feature = "test-only")] impl PartialEq for ZCToken<'_> { fn eq(&self, other: &CToken) -> bool { // Compare basic fields @@ -408,6 +409,7 @@ impl PartialEq for ZCToken<'_> { } } +#[cfg(feature = "test-only")] impl PartialEq> for CToken { fn eq(&self, other: &ZCToken<'_>) -> bool { other.eq(self) From 923c22108b5f974d12117ebd0e402a906ba8925d Mon Sep 17 00:00:00 2001 From: ananas-block Date: Sun, 7 Dec 2025 17:21:15 +0000 Subject: [PATCH 3/4] commit cargo lock --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index 759d6fe626..e7702d77e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3770,6 +3770,7 @@ dependencies = [ "light-array-map", "light-compressed-account", "light-compressible", + "light-ctoken-interface", "light-hasher", "light-heap", "light-macros", From dc71616a9fde340899e79a3c3fc01847696e3f4c Mon Sep 17 00:00:00 2001 From: ananas-block Date: Sun, 7 Dec 2025 17:33:07 +0000 Subject: [PATCH 4/4] fix: light-test-utils --- program-tests/utils/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/program-tests/utils/Cargo.toml b/program-tests/utils/Cargo.toml index 75220fea43..699a7d3103 100644 --- a/program-tests/utils/Cargo.toml +++ b/program-tests/utils/Cargo.toml @@ -21,7 +21,7 @@ solana-sdk = { workspace = true } thiserror = { workspace = true } account-compression = { workspace = true, features = ["cpi"] } light-compressed-token = { workspace = true, features = ["cpi"] } -light-ctoken-interface = { workspace = true } +light-ctoken-interface = { workspace = true, features = ["test-only"] } light-system-program-anchor = { workspace = true, features = ["cpi"] } light-registry = { workspace = true, features = ["cpi"] } spl-token = { workspace = true, features = ["no-entrypoint"] }