# solana-program-security-audit

> Account-validation-first security audit method for native and Anchor Solana programs.

solana-program-security-audit is a paid AI agent skill on Agensi by BanditXBT, in Security. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $4.2 (one-time purchase)
- Creator: [BanditXBT](https://www.agensi.io/creators/banditxbt)
- Category: [Security](https://www.agensi.io/skills/security)
- Version: 1.0
- Last updated: 2026-11-21
- Security: scan passed (2026-11-21); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/solana-program-security-audit
- Tags: security, web3-crypto, code-quality-review

## About this skill

Solana programs receive **every account from the caller**. The core question for each instruction: *could an attacker pass a different account than I assume?* Most critical bugs are missing validation, not clever math.

1. **Scope & invariants.** List instructions, account types, authorities, and 5-10 invariants (e.g., "vault token balance ≥ Σ user deposits", "only `admin` can change config", "a position cannot be opened under initial margin").
2. **Per-instruction account table.** For each account: writable? signer? expected owner program? expected address/PDA seeds? expected type/discriminator? relationship to other accounts (`has_one`-style)? Anything not pinned down is a finding candidate.
3. **Manual pass by bug class** (below), then write a failing test per suspected bug (see `solana-testing-fuzzing`).
4. **Report** with exploit transaction sketch (which fake accounts, in what order), impact, and fix.

- **Missing signer check:** authority accounts must be `Signer` (Anchor) or `is_signer` verified. A pubkey match alone is not authorization.
- **Missing owner check:** deserialized data from an account not owned by the expected program can be forged. Check `account.owner == expected_program_id` (Anchor `Account<T>` does this; `UncheckedAccount`/`AccountInfo` does not).
- **Type cosplay / discriminator:** two account types with the same layout can be substituted. Require 8-byte (Anchor) or custom discriminators checked on deserialize.
- **PDA validation:** derive and compare against the passed address; use the **canonical bump** (from `find_program_address`), store it, and never accept user-supplied bumps. Seeds must be collision-free (include type prefix, separators/fixed-length fields; avoid concatenating two variable-length seeds).
- **Arbitrary CPI:** verify the callee program ID before `invoke`/`invoke_signed` (e.g., token program, your own program). Passing an attacker program lets it receive your signer privileges. Beware CPI depth limit (4) and that `invoke_signed` extends PDA signer authority to the callee.
- **Account relationship/substitution:** token account's `mint`/`owner` match the expected mint/authority; vault belongs to this pool; oracle account matches the market's stored feed (Cashio, Mar 2022: unvalidated collateral account chain let attacker mint with worthless collateral).
- **Duplicate mutable accounts:** the same account passed twice under different names can bypass invariants (e.g., source == destination). Add explicit inequality constraints.
- **`remaining_accounts`:** unchecked by Anchor's constraints; validate every element manually.
- **Reinitialization / init-if-needed:** an already-initialized account re-initialized resets state or steals authority; `init_if_needed` needs explicit guards. Pre-funded or pre-created PDAs can DoS `init` (griefing): handle accounts that already hold lamports.
- **Closing accounts:** zero data, transfer all lamports, and reassign to the system program (Anchor `close =` does this). In-tx "revival": after close, an account can be refunded within the same tx and reused if the discriminator isn't invalidated.
- **Arithmetic:** release builds **do not** check overflow unless `overflow-checks = true` in `[profile.release]`; use `checked_*`/`saturating_*` deliberately, avoid unsafe `as` casts (truncation), watch rounding direction (round against the user), and precision loss with mixed decimals.
- **Sysvar spoofing:** read sysvars via `Clock::get()` etc. If an instruction takes a sysvar *account*, verify its address. Wormhole's Feb 2022 loss stemmed from an unchecked instructions-sysvar account (`load_instruction_at` vs. `load_instruction_at_checked`).
- **Stale data after CPI:** account data changes during CPI are not auto-reflected in already-deserialized structs; call `reload()` (Anchor) before reading.
- **Realloc & rent:** rent-exempt minimum maintained after realloc; max growth per instruction is 10 KiB; zero-init new bytes.
- **CPI return data & introspection:** `get_return_data` returns `(program_id, data)`: verify the program ID matches the callee you invoked, since any program in the call stack can set return data. Treat instruction-sysvar introspection (e.g., verifying a sibling signature instruction) as security-critical: check program ID, index, and that the verified message matches what you act on.
- **PDA signer scope:** a PDA's `invoke_signed` authority is usable by any code path in your program that knows the seeds; ensure no instruction lets a caller choose seeds/accounts that make your PDA sign for an unintended action (e.g., authority PDA shared across all pools).
- **Authority & state hygiene:** two-step authority handover, no `Pubkey::default()` authorities, no writable config accounts without owner and PDA checks, and explicit handling of closed/uninitialized accounts passed as inputs.
- **Token handling:** token program ID checks, Token-2022 extensions (see `spl-token-2022-security`), freeze/mint authority assumptions, decimals.
- **Upgrade authority & admin keys:** who can change the program or config, and can they steal funds? (see `solana-deploy-upgrade-ops`).
- **Oracles:** see `solana-oracle-risk-review`.
- **Economic/MEV:** sandwiching via Jito-style bundles, front-running initialization, slippage/deadline checks, liquidation races.
- **DoS:** unbounded `Vec` growth, compute exhaustion in loops, account-lock contention on one hot account.

`[SEV] Title — file:line` · Fake-account exploit sequence · Impact (funds at risk) · PoC test · Fix. End with invariants verified, tools run (`cargo clippy`, `cargo audit`, `cargo geiger`/review of `unsafe`, `anchor build` warnings), and areas not reviewed. Never claim "no bugs"; state coverage.

## Requires

- Rust
- Optional: Solana CLI
- Optional: Anchor

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the solana-program-security-audit skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### What does solana-program-security-audit do?

Account-validation-first security audit method for native and Anchor Solana programs.

### Which AI agents support solana-program-security-audit?

This skill uses the open SKILL.md standard. Use it through an MCP-compatible agent connected to Agensi, and check the compatibility information on this page for confirmed agents and required capabilities.

### How do I use solana-program-security-audit?

Connect your AI agent to Agensi through MCP, then ask it to use solana-program-security-audit on your task. Your agent loads the latest approved version each time. Paid skills require a purchase or active subscription. Skill files are not available for download; your licence does not allow you to save, copy or export any part of a skill.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
