Anchor security checklist

Most Solana exploits come from accounts the program didn't validate. Check each instruction's accounts struct against this list.

Accounts and signers

  • Typed accounts (Account<'info, T>, Signer<'info>, Program<'info, T>, InterfaceAccount) wherever possible. (rule)
  • Every AccountInfo / UncheckedAccount has a /// CHECK: reason and a real check (key, owner or data).
  • Authorities are Signer<'info> and tied to state with has_one or a constraint. (rule)
  • Raw account data is only read after an owner check (or through Account<'info, T>). (rule)
  • Token accounts constrained by mint and authority; duplicate mutable accounts considered; remaining_accounts validated.

PDAs and CPIs

  • PDAs derived with seeds and the canonical, stored bump; no caller-supplied bumps.
  • CPIs go through Program<'info, T> or an explicit program-id check. (rule)
  • PDA signer seeds are only used for that PDA's own authority; accounts reloaded after CPIs that change them.

Lifecycle and math

  • No init_if_needed, or state checks that prevent re-initialization. (rule)
  • Accounts closed with close = destination, not by draining lamports. (rule)
  • checked_* arithmetic on amounts, and overflow-checks = true in [profile.release]. (math, overflow)

Before deploying

  • anchor test covers wrong signer, wrong owner, wrong mint and duplicated accounts for every instruction.
  • chain-preflight scan . --report (with cargo audit) clean or explained.
  • No keypair JSON in the repository. (rule)
  • Upgrade authority decided: a multisig, or immutable on purpose. anchor verify planned.
  • A professional audit for anything that will hold user funds.