audit-infra
Infrastructure-first security audit โ secrets, supply chain, CI/CD, LLM/skill security, OWASP, STRIDE. Complements /audit-solana (program-level)
Security audit for Solana programs (Anchor/native)
> /plugin marketplace add solanabr/solana-ai-kit > /plugin install solana-ai-kit@stbr
How it fires
How this command gets triggered: by you, by Claude, or both.
/audit-solanaContext preview
What this command does when you run it.
Security audit for Solana programs (Anchor/native)
description: "Security audit for Solana programs (Anchor/native)"
You are conducting a security audit for Solana programs. This is CRITICAL - take your time.
echo "๐ Running automated security analysis..."
# Dependency audit (check for known vulnerabilities)
echo " ๐ฆ Checking dependencies..."
cargo audit
# Supply chain security (check for malicious dependencies)
if command -v cargo-geiger >/dev/null 2>&1; then
echo " โข๏ธ Checking unsafe code usage..."
cargo geiger
fi
# Clippy with strict security lints
echo " ๐ Running clippy security lints..."
cargo clippy --all-targets -- \
-W clippy::all \
-W clippy::pedantic \
-W clippy::unwrap_used \
-W clippy::expect_used \
-W clippy::panic \
-W clippy::arithmetic_side_effects \
-D warnings
# Format check
echo " ๐ Checking format..."
cargo fmt --check
# Run full test suite
echo " ๐งช Running tests..."
if [ -f "Anchor.toml" ]; then
anchor build && anchor test
else
cargo build-sbf && cargo test
fi
echo "โ
Automated analysis complete"**CRITICAL**: Every account MUST be validated. Check each instruction:
// โ CORRECT: Validate account owner
if *account.owner != expected_program_id {
return Err(ProgramError::IncorrectProgramId);
}
// โ WRONG: Assuming owner without check// โ CORRECT: Verify signer
if !authority.is_signer {
return Err(ProgramError::MissingRequiredSignature);
}
// โ WRONG: Privileged operation without signer check// โ CORRECT: Use stored canonical bump
let seeds = &[
b"vault",
authority.key.as_ref(),
&[vault.bump], // stored bump
];
// โ WRONG: Recalculating bump or accepting user-provided bump
let (pda, _) = Pubkey::find_program_address(seeds, program_id);Check ALL arithmetic operations:
// โ CORRECT: Checked arithmetic
let total = amount_a
.checked_add(amount_b)
.ok_or(ErrorCode::Overflow)?;
// โ WRONG: Unchecked arithmetic (can panic/overflow)
let total = amount_a + amount_b;**Checklist**:
// โ CORRECT: Check discriminator
if account.data.borrow()[0..8] != User::DISCRIMINATOR {
return Err(ProgramError::InvalidAccountData);
}
// In Anchor, Account<'info, T> does this automatically// โ CORRECT: Zero data AND set closed discriminator let mut data = account.data.borrow_mut(); data.fill(0); data[0..8].copy_from_slice(&CLOSED_ACCOUNT_DISCRIMINATOR); // Anchor's `close` constraint handles this #[account(mut, close = destination)]
// โ CORRECT: Validate program ID
if cpi_program.key() != spl_token::ID {
return Err(ErrorCode::InvalidProgram.into());
}
// โ WRONG: Accepting any program from user
invoke(&instruction, accounts)?;// โ CORRECT: Reload account after CPI transfer_checked(cpi_ctx, amount, mint.decimals)?; ctx.accounts.token_account.reload()?; // โ WRONG: Using stale data after CPI transfer_checked(cpi_ctx, amount, mint.decimals)?; // ... using token_account without reload
// โ CORRECT: Unique prefixes per account type let user_seeds = [b"user_vault", user.key().as_ref()]; let admin_seeds = [b"admin_config", admin.key().as_ref()]; // โ WRONG: Shared PDA space let seeds = [b"vault", key.as_ref()]; // collision possible
Check all cross-program invocations:
For financial operations:
Check for CU waste:
Verify comprehensive test coverage:
# Setup Trident (if not already)
if [ ! -d "trident-tests" ]; then
echo "Setting up Trident fuzz testing..."
trident init
fi
# Run fuzz tests for at least 10 minutes (Trident v0.7+)
echo "๐ Running fuzz tests (10 minutes minimuProduction-ready Claude Code configuration for full-stack Solana development. Combines best practices from multiple sources into an agent-optimized, token-efficient config you can install and adapt to your specific project.
Repo: solanabr/solana-ai-kit
Infrastructure-first security audit โ secrets, supply chain, CI/CD, LLM/skill security, OWASP, STRIDE. Complements /audit-solana (program-level)
Benchmark CU usage and compare against baseline for regression detection