A security checklist for Solana programs

Twelve bug classes that keep showing up in Solana audits, from missing signer and owner checks to arbitrary CPIs, account revival and overflow, each with the Anchor code that stops it.

On this page
  1. Most exploits are missing checks
  2. The checklist
  3. Past the checklist

Most exploits are missing checks

The runtime enforces two hard rules: only an account's owner program can change its data, and only signed accounts count as signers. Everything else is the program's job. The caller chooses every account passed to an instruction, so most Solana exploits aren't clever maths. They are a program trusting an account it didn't check.

I built this list from public audit reports, the Sealevel attacks examples and Anchor's documentation. Each item is the bug and the fix. The constraints used here are explained in Anchor account constraints.

The checklist

1. Missing signer check

Bug: the instruction acts for authority without checking authority signed. Any public key works.

Fix: type it Signer<'info> and tie it to the account it controls.

#[account(mut, has_one = authority)]
pub vault: Account<'info, Vault>,
pub authority: Signer<'info>,

2. Missing owner check

Bug: the program reads an account without checking which program owns it. An attacker creates an account owned by their own program, filled with whatever bytes they like.

Fix: Account<'info, T>, which checks the owner, or an explicit owner = constraint on unchecked accounts.

3. Missing relationship check

Bug: vault and authority are each checked, but nothing says this authority controls this vault. An attacker signs with their own key and passes in your vault.

Fix: has_one, a constraint, or seeds that include the authority.

4. Type confusion

Bug: two account types have compatible layouts and the program deserialises one as the other.

Fix: a discriminator on every account type. Anchor's #[account] writes 8 bytes and Account<T> checks them. Native programs need their own type tag.

5. Non-canonical bumps

Bug: the program accepts any bump the caller sends, so one set of seeds maps to several addresses and "one account per user" no longer holds.

Fix: derive with find_program_address at creation, store the bump, check against it. Anchor's seeds and bump do this. Details in program derived addresses.

6. Arbitrary CPI

Bug: the program invokes whatever program account the caller passed, for example a "token program" that is the attacker's.

Fix: type the target Program<'info, Token> (or Interface<'info, TokenInterface>), which checks the address, or check the key before invoking.

7. Reinitialisation

Bug: the initialise instruction runs again on an existing account and resets its authority to the caller.

Fix: init, which fails if the account exists. With init_if_needed, check in the handler that the account isn't set up already.

8. Revival after close

Bug: the program closes an account by moving its lamports out but leaves the data and owner. Later in the same transaction another instruction tops it back up to rent exemption and it's live again.

Fix: Anchor's close = destination, which also returns the account to the System Program and zeroes its size.

9. Duplicate mutable accounts

Bug: the instruction takes from and to as separate mutable accounts. Passing the same one twice double-counts a balance or skips a check.

Fix: constraint = from.key() != to.key().

10. Overflow and rounding

Bug: u64 arithmetic wraps in release builds unless overflow checks are on. Division that rounds the wrong way can be repeated to drain value a lamport at a time.

Fix: overflow-checks = true in [profile.release], checked_add and checked_mul, multiply before dividing, and round in the protocol's favour: down when paying out, up when charging.

let shares = amount
    .checked_mul(pool.total_shares)
    .and_then(|x| x.checked_div(pool.total_assets))
    .ok_or(PoolError::MathOverflow)?; // rounds down: the pool keeps the dust

11. Unchecked sysvars and remaining_accounts

Bug: the program reads Clock or Instructions from an account the caller passed, without checking its address. Nothing in remaining_accounts gets Anchor's checks.

Fix: Sysvar<'info, Clock> or Clock::get(), and check every remaining account by hand: owner, address, discriminator.

12. Token assumptions

Bug: the program assumes the amount sent is the amount received, or that every mint behaves like a classic SPL token. Token-2022 mints can carry transfer fees, transfer hooks and freeze authorities.

Fix: decide which mints and extensions are supported and check them. Compare balances before and after a transfer instead of trusting the requested amount. Use transfer_checked, which also verifies mint and decimals.

Past the checklist

Checks stop known bugs. They don't prove a design is safe. What I'm adding to my own process:

  • Every constraint gets an attack test. Pass the wrong account, expect the right error. A constraint without a failing test is one refactor from disappearing.
  • Fuzz the maths. Property tests on share and price calculations find rounding paths nobody thought of.
  • Lock down upgrades. An upgradeable program is as safe as its upgrade authority. Multisig it, and make the program immutable once it's stable.
  • Read real audits. Public reports from Solana audit firms are the best free material on what goes wrong.

I'll add to the list as I find new classes.