Skip to content

locallaunchsc-cloud/solana-dev-skills / program-audit

solana-program-audit

Verified

Use this skill when the user wants to audit a Solana or Anchor program for security vulnerabilities — account validation, PDA safety, arithmetic, CPI risks, reinit attacks, and authority confusion. Includes a checklist and the most common bug classes.

references/vulnerability-checklist.md

View on GitHub
# Solana Program Vulnerability Checklist

A comprehensive pre-mainnet checklist. Walk top to bottom for every instruction. Each item is phrased as a yes/no question — a "no" is a finding.

## 1. Signer & Authority Validation

- [ ] **Does every state-mutating instruction require at least one `Signer<'info>` (or equivalent `is_signer` check on raw accounts)?** Without a signer, anyone can call the instruction.
- [ ] **Is the signer's pubkey bound to an authority field on a trusted account (via `has_one`, explicit `require_keys_eq!`, or PDA seeds)?** A signer is meaningless unless tied to a permission stored somewhere.
- [ ] **For multi-signer instructions, is each signer independently checked against its own role?** Combined checks can mask one missing role.
- [ ] **Are upgrade authority, admin keys, and treasury authorities behind a multisig (Squads V4 / V3) or governance?** Single-key authorities are a self-destruct button.
- [ ] **Are authority handoffs two-step (propose + accept)?** One-step transfers to a typo'd address are unrecoverable.
- [ ] **Does the program reject the zero pubkey (`Pubkey::default()`) as an authority?** Many bugs let `Pubkey::default()` slip through, granting de-facto open access.

## 2. Account Ownership

- [ ] **Is every `AccountInfo` / `UncheckedAccount` explicitly owner-checked or constrained with `#[account(owner = ...)]`?** Raw accounts bypass Anchor's owner check.
- [ ] **For SPL token accounts deserialized manually, is the owner verified to be `spl_token::ID` (or Token-2022 where applicable)?** `unpack` succeeds on any 165-byte buffer.
- [ ] **For mints, is the owner verified to be `spl_token::ID`?** A "mint" owned by an attacker's program is just a struct with no supply guarantees.
- [ ] **Is each `UncheckedAccount` paired with a `/// CHECK:` comment explaining the off-band validation?** Anchor requires this; the comment forces auditor attention.

## 3. Account Discriminator & Type Safety

- [ ] **Does every state account use `#[account]` (which adds an 8-byte discriminator) rather than a raw byte buffer?** Without a discriminator, an attacker can deserialize a `Vault` as a `Config`.
- [ ] **When manually deserializing, is the discriminator checked before reading fields?** Anchor's `Account<'info, T>` does this; manual code must replicate it.
- [ ] **Are closed accounts marked with the closed-account discriminator (`[0xff; 8]`)?** Otherwise they can be revived and reused.

## 4. PDA Validation

- [ ] **For every PDA, are the seeds bound to a trusted root (program ID, a verified account's key, or a constant)?** PDAs derived from purely user-supplied seeds prove nothing.
- [ ] **Is the canonical bump stored at init and read back on later use (`bump = account.bump`)?** Accepting a caller-supplied bump enables non-canonical PDA confusion.
- [ ] **When using `create_program_address` directly, is the bump verified to be canonical (or stored)?** Non-canonical PDAs can collide with attacker-controlled keys.
- [ ] **Are PDA seeds chosen to make collisions impossible across instruction types?** `[user]` vs `[user, b"order"]` — the prefix must distinguish account kinds.
- [ ] **For PDAs scoped per-user, does the program actually want per-user state (not global)?** A common bug is using a per-user PDA where a singleton was intended.

## 5. Account Relationship Invariants

- [ ] **Does every cross-account reference use `has_one` or an explicit `require_keys_eq!` to bind accounts back to a trusted root?** The Cashio class.
- [ ] **For token accounts, are `token::mint` and `token::authority` constraints used?** Anchor verifies the mint and owner fields automatically.
- [ ] **Are mint accounts checked for the expected decimals?** Decimals are mutable on Token-2022; price math may assume a value.
- [ ] **Is the `payer` on `init` always a `Signer`?** Otherwise the program drains rent from an account whose owner didn't consent.

## 6. Initialization & Re-initialization

- [ ] **Is `init_if_needed` avoided unless strictly required?** Prefer separate `init` / `update` instructions.
- [ ] **If `init_if_needed` is used, does the "existing" branch enforce the original owner / authority?** Otherwise it's a reinit takeover.
- [ ] **Does init validate that no field is left in a dangerous default state (zero authority, zero bump)?**
- [ ] **Is `space` correct and conservative (allows future growth via `realloc` if needed)?** Wrong space breaks reads or wastes rent.

## 7. Account Closing

- [ ] **Are accounts closed via Anchor's `close = recipient` constraint?** This zeros the discriminator and drains lamports atomically.
- [ ] **If closed manually, is the data zeroed AND the discriminator set to `[0xff; 8]` AND lamports drained?** Skipping any step enables reuse.
- [ ] **Is the lamport recipient validated (`has_one = recipient` or signer check)?** Otherwise rent can be redirected.

## 8. CPI Safety

- [ ] **Is the target program ID constrained (`Program<'info, T>`, `address = ...`, or explicit pubkey check)?** Unchecked CPIs let attackers swap in a lookalike program.
- [ ] **Are `invoke_signed` seeds limited to PDAs this program legitimately controls?** Over-broad seeds = forgery.
- [ ] **Are returned values from CPIs validated (e.g. price feed staleness, oracle confidence)?** Trusting CPI output is trusting the called program.
- [ ] **For Token CPIs, is the source account's authority field verified to be a PDA of this program (when transferring out of vault)?**
- [ ] **Does the program handle CPI failure cleanly (no partial state mutation before the CPI)?** Inconsistent state survives the revert.

## 9. Arithmetic & Numerics

- [ ] **Is every `+ - * /` on user-controlled values `checked_*` or `saturating_*`?** Plain ops can overflow silently in release.
- [ ] **Are intermediate multiplications widened (`as u128`) before division?** `(a * b) / c` overflows `u64` for moderate inputs.
- [ ] **Is division-before-multiplication avoided to prevent precision loss?** `(a / b) * c` rounds down twice.
- [ ] **Is fixed-point math used for prices, shares, or fees (e.g. `spl-math::Decimal`, `fixed`)?** Float is forbidden on Solana but ad-hoc integer math is just as error-prone.
- [ ] **Are conversions narrowed safely (`u128 -> u64` via `try_into()`)?** A silent `as u64` truncates.
- [ ] **Is rounding direction explicit and aligned with the protocol (rounding against the user for deposits, in their favor for withdrawals)?** Round-trip rounding asymmetries are how attackers extract value.

## 10. Randomness & Time

- [ ] **Is on-chain randomness sourced from a VRF (Switchboard / ORAO) or commit-reveal?** Slot/blockhash/timestamp are unsafe.
- [ ] **For timeouts and deadlines, is `Clock::get()?.unix_timestamp` validated against sane bounds?** A misconfigured validator can return surprising values, and timestamps are loosely monotonic.
- [ ] **Is the freshness of any external data (oracles) checked against the current slot?** Stale prices are an attack vector.

## 11. Token Handling

- [ ] **Does the program handle Token-2022 extensions where relevant (transfer fees, hooks, non-transferable, confidential)?** Token-2022 changes invariants silently.
- [ ] **Are token amounts validated to be > 0 where zero would cause issues (zero-share mint, etc.)?**
- [ ] **Is the fee paid on transfer accounted for separately from the requested amount?** Token-2022 transfer fees can leave less than expected.
- [ ] **Is the program resilient to the token mint freeze authority freezing user accounts mid-flow?**

## 12. Reentrancy & Atomicity

- [ ] **Does the program avoid state changes that could be exploited by a CPI callback (rare on Solana but possible via re-entrant programs)?**
- [ ] **Are state mutations ordered to satisfy the checks-effects-interactions pattern?** Mutate state, then CPI.
- [ ] **Are loop iterations bounded by a compile-time constant or a small, validated runtime input?** Compute budget exhaustion is a DoS class.

## 13. Build, Verification & Operations

- [ ] **Is the deployed program byte-identical to a reproducible build (`solana-verify`)?** An audit on different source than what's deployed is theater.
- [ ] **Is `cargo audit` clean (no known-vulnerable deps)?**
- [ ] **Is `overflow-checks = true` set in the release profile (defense in depth, not a substitute for `checked_*`)?**
- [ ] **Is the program's upgrade authority either a multisig, a buffer (immutable for a planned period), or revoked?**
- [ ] **Is the IDL published and consistent with the deployed binary (`anchor idl fetch`)?** Mismatched IDLs cause client-side bugs that look like contract bugs.

## 14. Misc / Catch-all

- [ ] **Does every error path return a typed error (not `panic!`, not `unwrap()`)?** Panics in entrypoints are ugly and sometimes exploitable.
- [ ] **Are admin-only instructions gated by a constant-time check on a trusted authority field, not a runtime string compare?**
- [ ] **Have you run the program through Sec3 X-ray (or successor) and resolved or accepted every finding?**
- [ ] **Has the program been tested with `solana-program-test` for the full attack surface, including attacker-controlled accounts?**
- [ ] **Has the program been fuzz-tested with `trdelnik-fuzz` or `honggfuzz` on the highest-value instructions?**
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall