Skip to content

Commit 3c8d55d

Browse files
tilo-14claude
andcommitted
Fix AccountData docs and add SPL token program validation
- Fix account-comparison/CLAUDE.md: Replace incorrect fixed byte offsets with Size column since String is variable-length in Borsh serialization - Add SPL Token program ID validation in compressed-claim processor before CPI to prevent invalid program substitution Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 27b4ade commit 3c8d55d

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

account-comparison/CLAUDE.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ programs/account-comparison/tests/
2323

2424
### AccountData (Solana PDA)
2525

26-
| Field | Type | Offset |
27-
|-------|------|--------|
28-
| discriminator | `[u8; 8]` | 0..8 |
29-
| user | `Pubkey` | 8..40 |
30-
| name | `String` | 40..168 |
31-
| data | `[u8; 128]` | 168..232 |
26+
| Field | Type | Size |
27+
|-------|------|------|
28+
| discriminator | `[u8; 8]` | 8 bytes |
29+
| user | `Pubkey` | 32 bytes |
30+
| name | `String` | 4 + name_len (max 60 chars) |
31+
| data | `[u8; 128]` | 128 bytes |
3232

3333
- **Seeds**: `["account", user.key()]`
3434
- **Discriminator**: 8 bytes, SHA256("account:AccountData")[0..8]
35-
- **Space**: 232 bytes
35+
- **Space**: 232 bytes. String uses Borsh serialization (4-byte length prefix + variable content).
3636

3737
### CompressedAccountData (LightAccount)
3838

airdrop-implementations/compressed-claim/program/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ light-ctoken-sdk = { version = "0.2", features = ["v1"] }
2121
thiserror = "2.0.11"
2222
borsh = "0.10.0"
2323
light-sdk = { version = "0.17" }
24+
spl-token = { version = "5.0.0", features = ["no-entrypoint"] }
2425

2526
[dev-dependencies]
2627
solana-sdk = "2.3"
2728
light-program-test = { version = "0.17", features = ["v2"] }
2829
light-client = { version = "0.17", features = ["v2"] }
2930
tokio = "1.4"
30-
spl-token = { version = "5.0.0", features = ["no-entrypoint"] }
3131

3232
[lib]
3333
crate-type = ["cdylib", "lib"]

airdrop-implementations/compressed-claim/program/src/processor.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ fn process_claim(accounts: &[AccountInfo], ix_data: ClaimIxData) -> ProgramResul
7171
ctoken_program_info.key.log();
7272
return Err(ProgramError::InvalidArgument);
7373
}
74+
// CHECK:
75+
if token_program_info.key != &spl_token::ID {
76+
msg!("Invalid SPL token program.");
77+
token_program_info.key.log();
78+
return Err(ProgramError::InvalidArgument);
79+
}
7480
let compressed_token_account = CTokenAccount::new(
7581
mint,
7682
associated_airdrop_pda_info.key.clone(),

0 commit comments

Comments
 (0)