๐Ÿ›ก๏ธ Safe Solana Builder

March 22, 2026 ยท View on GitHub

The first Claude skill for writing production-grade, security-first Solana programs.

Built by a Solana security researcher, for Solana developers โ€” so your code arrives at audit already hardened.


What Is This?

Safe Solana Builder is a security skill system you can load into AI coding workflows (Claude / Cursor) so Frank Castle's Solana security knowledge is applied before writing a single line of code.

This is not a prompt. It is a layered reference architecture that forces Claude to:

  • Select the right framework (Anchor, Native Rust, or Pinocchio) and load the matching security ruleset
  • Choose a testing approach (LiteSVM or framework default) and load the matching test patterns
  • Assess the program's risk level (๐ŸŸข Low / ๐ŸŸก Medium / ๐Ÿ”ด Critical) before touching the keyboard
  • Apply a curated set of security rules drawn from real audit findings โ€” CPIs, PDAs, account validation, arithmetic, Token-2022, and more
  • Deliver a full project scaffold โ€” not just lib.rs
  • Generate a test file skeleton with security edge cases pre-identified
  • Output a security checklist documenting every rule applied and every known limitation

Every program this skill produces has a first layer of protection baked in before it reaches an auditor.


Why It Exists

Most AI-generated Solana code is a liability.

Missing ownership checks. Non-canonical bumps. Stale data used after CPIs. No duplicate account guards. No checked arithmetic. It compiles, it looks right, and it fails on mainnet.

The Cyfrin team built a skill like this for Solidity. Nobody built one for Solana โ€” until now.


What It Produces

For every program request, the skill outputs:

OutputDescription
Full project scaffoldAnchor.toml, Cargo.toml, proper folder structure โ€” ready to anchor build or cargo build-sbf
lib.rsComplete, compilable program with inline security comments
Test fileLiteSVM or framework-default โ€” happy path tests implemented + security edge case tests scaffolded with TODO bodies
security-checklist.mdEvery rule applied, every assumption made, every known limitation flagged

Skill Structure

safe-solana-builder/
โ”œโ”€โ”€ SKILL.md                        โ† Orchestrator: workflow, risk assessment, output format
โ”œโ”€โ”€ references/
โ”‚   โ”œโ”€โ”€ shared-base.md              โ† Framework-agnostic rules (PDAs, CPIs, arithmetic, Token-2022...)
โ”‚   โ”œโ”€โ”€ anchor.md                   โ† Anchor-specific: constraints, account types, reload(), close...
โ”‚   โ”œโ”€โ”€ native-rust.md              โ† Native Rust: manual validation sequence, invoke, deserialization...
โ”‚   โ”œโ”€โ”€ pinocchio.md                โ† Pinocchio: zero-copy patterns, bytemuck, wincode, CPI, Shank IDL...
โ”‚   โ””โ”€โ”€ litesvm.md                  โ† LiteSVM: test setup, sysvar control, CU profiling, account injection...
โ””โ”€โ”€ examples/
    โ””โ”€โ”€ nft-whitelist-mint/
        โ”œโ”€โ”€ lib.rs                  โ† Full Anchor NFT whitelist mint program
        โ””โ”€โ”€ security-checklist.md  โ† 31-rule checklist for the example

Reference Coverage

The reference files cover:

Shared Base (framework-agnostic)

  • Account & identity validation (signer, owner, discriminator, reinitialization)
  • PDA security (canonical bumps, sharing prevention, seed collision)
  • Arithmetic safety (checked math, multiply-before-divide, slippage)
  • Duplicate mutable account attacks
  • Full CPI safety surface (arbitrary CPI, stale reload, signer pass-through, SOL drain, post-CPI ownership)
  • Account lifecycle (rent, closing, anti-revival, sysvar verification)
  • Token-2022 compatibility
  • Transaction model safety
  • Safe Rust patterns

Anchor-specific

  • Account type selection (Account<T> vs UncheckedAccount vs Interface)
  • Constraint patterns (has_one, seeds+bump, init vs init_if_needed, close, realloc)
  • reload() after CPI โ€” non-negotiable
  • token_interface::transfer_checked for Token-2022 compatibility
  • CPI construction, signer seeds, program ID validation
  • #[error_code] custom errors

Native Rust-specific

  • The 6-step mandatory validation sequence (key โ†’ owner โ†’ signer โ†’ writable โ†’ discriminator โ†’ data)
  • Borsh deserialization patterns and length pre-checks
  • PDA derivation: find_program_address at init, create_program_address on reuse
  • invoke vs invoke_signed patterns
  • Manual post-CPI data refresh
  • Account creation via System Program CPI
  • Manual 3-step safe account close
  • Custom error enum with ProgramError conversion

Pinocchio-specific (new)

  • Zero-copy account definitions with bytemuck (Pod + Zeroable, explicit _padding, 8-byte alignment)
  • Account validation via TryFrom pattern and validation macros
  • wincode for instruction data serialization โ€” SchemaWrite/SchemaRead derives, zero-copy deserialization for #[repr(C)] structs, Pod<T> foreign type adapter, compact-u16 / ShortVec length encoding
  • bytemuck vs wincode decision rule: bytemuck for on-chain account state, wincode for instruction data
  • CPI via pinocchio-system and pinocchio-token typed helpers
  • IDL generation with Shank + Codama
  • Entrypoint selection by CU cost (no_allocator!, lazy_entrypoint!, entrypoint!)
  • Pinocchio-specific build errors and toolchain notes

LiteSVM testing (new)

  • In-process VM โ€” no validator, no async runtime, fastest test loop available
  • setup() pattern, send_tx() helper with expire_blockhash(), TransactionMetadata fields
  • Devnet account injection via svm.set_account() + RPC client
  • Token setup with litesvm-token (CreateMint, CreateAssociatedTokenAccount, MintTo)
  • Full sysvar control: time travel (Clock), slot warping, rent reads
  • CU profiling with CU_RESULTS static and zz_cu_summary test
  • Simulation (dry-run without state commit)
  • Framework-specific patterns: Anchor (InstructionData/ToAccountMetas) and Native/Pinocchio (manual discriminator encoding)
  • 12-item LiteSVM security test checklist
  • Common errors table (GLIBC, BlockhashNotFound, missing SO, etc.)

How to Install

Claude Setup

  1. Download safe-solana-builder.skill from the Releases page
  2. In Claude.ai, go to Settings โ†’ Skills
  3. Upload the .skill file
  4. The skill activates automatically whenever you ask Claude to write a Solana program

Cursor IDE Support

Cursor does not natively support .skill files, but the same system works by loading this repository as a context rule source.

  1. Clone the repository into Cursor's skills directory:
mkdir -p ~/.cursor/skills
git clone https://github.com/Frankcastleauditor/safe-solana-builder.git ~/.cursor/skills/safe_solana_builder
  1. Restart Cursor
  2. Reference the skill in your prompt:
Use the safe_solana_builder skill.

Build a secure Solana program using Anchor.

Trigger Phrases

The skill fires on any of the following:

  • "Write a Solana program that..."
  • "Build an Anchor program for..."
  • "Create a native Rust Solana contract..."
  • "Scaffold a Solana program..."
  • "Help me write a program that does X on Solana"

Roadmap

This skill is under active development. Planned expansions:

  • Native Rust example program (staking vault)
  • Additional reference sources: SPL Token-2022 extension security, Metaplex deep-dive, oracle manipulation patterns
  • Anchor v0.31+ specific patterns
  • Invariant testing guidance (Trident, Fuzz)
  • Common DeFi pattern references: AMM, lending, bonding curves

The reference files are the living core of this skill. Every new vulnerability source, audit finding, or best practice I encounter gets distilled and added. The skill grows with the threat landscape.


About the Author

Hi there ๐Ÿ‘‹ I'm Frank Castle

๐Ÿ›ก๏ธ Smart Contract Security Researcher specializing in Solana (Anchor) and Rust-based ecosystems.

I help protocols ship safer smart contracts by identifying critical vulnerabilities, validating everything related to DeFi and blockchain, and for Solana reviewing CPI / PDA / token-account security boundaries / and any custom logic.


๐Ÿ” Focus Areas

  • Solana Program Security: Anchor, PDAs, CPI, account validation, rent/DoS patterns
  • SPL / Token-2022 Security: extensions, mint assumptions, transfer hooks, authority models
  • DeFi Security: AMMs, vaults, staking, bonding curves, fee mechanisms
  • Rust Security: state machines, invariants, edge cases, unsafe patterns

๐Ÿ† Highlights

  • 70+ Rust audits, 50+ Solana audits
  • 250+ Critical/High severity vulnerabilities identified
  • Top placements in competitive audits:
    • ๐Ÿฅˆ 2nd place โ€” HydraDX Omnipool (Code4rena)
    • ๐Ÿ… 4th place โ€” Centrifuge (Cantina)


๐Ÿงพ Writeups & Content


๐Ÿ“ซ Contact


โญ If you're building on Solana and want a security review, feel free to reach out.


License

MIT โ€” use it, fork it, build on it. If you add something valuable, consider contributing it back.


Safe Solana Builder โ€” first layer of protection, before the auditor ever sees your code.