<< All versions

Skill v1.0.0

currentLLM-judged scan90/100
utsavsavani08/rain-skill-main/solana-anchor
──Details
PublishedOctober 24, 2026 at 08:38 AM
Content Hashsha256:ecfcc82321c95c72...
Git SHA5cedb39dde43
──Files
Files (1 file, 3.7 KB)
SKILL.md3.7 KBactive
SKILL.md · 90 lines · 3.7 KB

version: "1.0.0" name: solana-anchor description: Solana program development with the Anchor framework (Rust). Use when building Solana programs, working with Anchor.toml, accounts, PDAs, CPIs, or SPL tokens, or on requests mentioning Solana, Anchor, SPL, or program. Covers the account model, PDAs, security pitfalls, and Anchor tests. Cross-links rust-pro. allowed-tools: Read, Write, Edit, Glob, Grep, Bash


You build Solana programs with Anchor. Solana's model is fundamentally different from EVM: programs are stateless and operate on accounts passed into each instruction — most Solana bugs are missing account validation.

Use this skill when

  • Building/editing Solana programs (Rust, Anchor) or Anchor.toml projects
  • Working with PDAs, CPIs, SPL tokens
  • Reviewing a Solana program for the common account-validation pitfalls

Load rust-pro alongside this for idiomatic Rust.

Mental model

  • Programs are stateless. State lives in accounts the caller passes in. The program must validate every account it's given.
  • PDAs (Program Derived Addresses): deterministic addresses owned by the program, derived from seeds + bump. Used for program-controlled state and signing (invoke_signed).
  • CPI (Cross-Program Invocation): calling another program (e.g., the SPL Token program) from yours.
  • Rent: accounts must be rent-exempt (hold enough lamports) or they're purged.

Anchor program skeleton

rust
use anchor_lang::prelude::*;
declare_id!("Fg6PaFpoGXkYsidMpWxqSWY...");
#[program]
pub mod vault {
use super::*;
pub fn deposit(ctx: Context<Deposit>, amount: u64) -> Result<()> {
require!(amount > 0, VaultError::ZeroAmount);
let vault = &mut ctx.accounts.vault;
vault.total = vault.total.checked_add(amount).ok_or(VaultError::Overflow)?;
Ok(())
}
}
#[derive(Accounts)]
pub struct Deposit<'info> {
#[account(mut, seeds = [b"vault", authority.key().as_ref()], bump)]
pub vault: Account<'info, Vault>,
#[account(mut)]
pub authority: Signer<'info>,
pub system_program: Program<'info, System>,
}
#[account]
pub struct Vault { pub authority: Pubkey, pub total: u64 }
#[error_code]
pub enum VaultError { #[msg("amount is zero")] ZeroAmount, #[msg("overflow")] Overflow }

Security pitfalls (Solana-specific — check every one)

PitfallFix
Missing signer checkRequire Signer<'info> on accounts that must authorize
Missing owner checkUse typed Account<'info, T> (Anchor checks program ownership) — don't use raw AccountInfo without manual checks
Account substitution / confused deputyConstrain accounts with seeds/has_one/constraint; verify relationships
PDA bump not canonicalUse Anchor's bump (canonical) — don't accept a user-supplied bump
Arithmetic overflowchecked_add/checked_sub (Rust release builds wrap silently otherwise)
Unvalidated CPI targetVerify the program id you CPI into (e.g., the real SPL Token program)
Account reinit / type confusionUse init/init_if_needed carefully; validate discriminator

SPL tokens

Use anchor_spl::token (or token-2022) for mint/transfer via CPI; never reimplement token logic. Validate the mint and token account owner.

Testing

bash
anchor build
anchor test # spins a local validator, runs TS tests

Write tests for: each instruction's success path, every require!/error, and unauthorized-signer / wrong-account attempts.

Anti-patterns

  • ❌ Raw AccountInfo without owner/signer validation
  • ❌ Trusting any account address passed in without constraints
  • ❌ Plain +/- on balances (use checked math)
  • ❌ Accepting a user-supplied PDA bump
  • ❌ CPI into an unvalidated program id
All versions