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/UncheckedAccounthas a/// CHECK:reason and a real check (key, owner or data). - Authorities are
Signer<'info>and tied to state withhas_oneor 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_accountsvalidated.
PDAs and CPIs
- PDAs derived with
seedsand the canonical, storedbump; 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, andoverflow-checks = truein[profile.release]. (math, overflow)
Before deploying
-
anchor testcovers wrong signer, wrong owner, wrong mint and duplicated accounts for every instruction. -
chain-preflight scan . --report(withcargo audit) clean or explained. - No keypair JSON in the repository. (rule)
- Upgrade authority decided: a multisig, or immutable on purpose.
anchor verifyplanned. - A professional audit for anything that will hold user funds.