Index of every page on this site: llms.txt
All skills
princedotrs avatar

/solana-program-audit

@586e19e
Run it yourself

Security audit of Solana on-chain programs in Rust: Anchor, native solana-program and Pinocchio. Use to audit or review a Solana program, PR or fix and to find vulnerabilities: missing signer or owner checks, account validation, type cosplay, reinitialization, init front-running, closed-account revival, duplicate accounts, PDA seeds and bumps, arbitrary CPI, CPI return data, remaining_accounts, sysvar and instruction introspection, overflow, rounding, Token-2022 extensions and transfer hooks, oracle, flash-loan and MEV attacks, upgrade authority and governance. Covers DeFi reviews (AMM, lending, perps, staking, bridges, launchpads), PoC exploits, fix patches, re-audits, spec compliance, audit readiness, release gates and audit reports. Trigger on code using anchor_lang, solana_program, pinocchio, #[program], #[derive(Accounts)] or entrypoint!. Not for writing features, off-chain clients or backends, EVM/Solidity, or incident response.

  • 237 files
  • 2 MB
  • Updated 4 weeks ago
  • GitHub
Use this Skill: https://skilld.dev/gh/princedotrs/solana-audit/solana-program-audit

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

checklists21-anchor-specific.md

≈3.9k tokens on demand. Your agent reads this file only when SKILL.md points to it.

21 — Anchor-Specific Checklist (version-dependent semantics)

Domain: On-chain Solana Program (Anchor) Severity if missed: HIGH References: otter-sec/anchor CHANGELOG, footguns.mdx, SECURITY.md and GHSA advisories (Apache-2.0); solana-foundation/solana-dev-skill (MIT); KV-153..KV-158; references/framework-idioms/anchor.md §5/§9/§10 Load when: anchor-lang in any Cargo.toml. Record the resolved version from Cargo.lock first.

Every item below is a single verification step. Mark each [PASS], [FAIL-{severity}], [PARTIAL], or [N/A].


21.1 — Version & advisories

  • AN-001: The resolved anchor-lang/anchor-spl versions (and the deployed build's, if different) are recorded and walked against the KV-158 advisory matrix; every matching row with its pattern present is reported.
  • AN-002: (≥ 1.0.0 and the 1.0 release candidates that include #3878) No untyped Program<'info> / Program<'info, ()> (checks only executable, by design) is used as an invoke target with PDA signer seeds or forwarded user signers; allowlisted via address = or a pinned id where used (KV-154).
  • AN-003: On 1.0.0-rc.3 through 1.0.1 and on 2.0.0-rc.1/rc.2, no Instruction takes its program id from a Program<'info, System> account, no such account is forwarded to a third-party program, and it is not used as an identity proof (GHSA-c6rc-8jpp-2fgc / CVE-2026-45137, also the 1.0 release candidates that include #3878, fixed in 1.0.2: the unit-type shortcut skipped the key check whenever T::id() == Pubkey::default(), which is the System Program id; Anchor's own system_program::* helpers and generated init/realloc are unaffected). <!-- verified: anchor `git diff v1.0.1 v1.0.2 -- lang/src/accounts/program.rs` -->

21.2 — Account types & constraints

  • AN-004: No required gate depends on an Option<…> account being Some; required accounts are enforced with ok_or(..)? (the program's own id encodes None) (KV-157).
  • AN-005: Custom discriminators (≥ 0.31) are non-empty, non-zero, and prefix-free within each namespace (accounts, instructions, events); a cross-type deserialization test exists (KV-156). (The IDL build rejects empty, ambiguous and all-zero discriminators since 0.31.0, #3157/#3159/#3166; lang itself rejects all-zero account discriminators only from 1.2.0, #4645 — builds without the IDL step get no check before 1.2.0.)
  • AN-006: No two instantiations of one generic #[account] type serve different trust roles without a stored, checked type tag (KV-156).
  • AN-007: On ≤ 1.2.1, no account field or constraint expression uses my_key (has_one), my_owner (owner) or actual (address) (KV-155): the generated block binds those names as locals before evaluating the target expression, so the comparison can become a tautology. Fixed after 1.2.1 by #5105 (unreleased as of 2026-10-24). <!-- verified: anchor v1.2.1 lang/syn/src/codegen/accounts/constraints.rs (`let actual = #field.key(); let expected = #addr;`, `let my_key = …; let target_key = #target.key();`, `let my_owner = …; let owner_address = #owner_address;`); origin/master uses `private_ident` -->
  • AN-008: Legacy IDL instructions are absent — on 0.x the deployed build has the no-idl feature active; 1.0.x never generates them (#3798); on ≥ 1.1.0 the #[program(legacy_idl)] argument is absent — or, where they exist, the IDL account exists with governance as its authority (KV-153, OPS-088). <!-- verified: anchor v0.32.1 lang/syn/src/codegen/program/dispatch.rs (`#[cfg(not(feature = "no-idl"))]`); v1.0.0/v1.0.2 have no `legacy_idl`; v1.1.0..v1.2.1 dispatch.rs `Some(args) if args.legacy_idl` -->
  • AN-009: fallback logic is checked against the version's dispatch order. 0.x: instruction discriminators, then IDL_IX_TAG (IDL handler, or IdlInstructionStub under no-idl), then EVENT_IX_TAG, then fallback, so neither tag reaches fallback. 1.x: instruction discriminators, then IDL_IX_TAG only if #[program(legacy_idl)] is set, then EVENT_IX_TAG (handler, or EventInstructionStub without event-cpi), then fallback. On 1.x without legacy_idl, data that starts with IDL_IX_TAG therefore does reach fallback, and fallback must reject it or handle it safely. No custom discriminator is a prefix of either tag, and the event-cpi handler is counted as an entrypoint. <!-- verified: anchor v0.32.1 and v1.2.1 lang/syn/src/codegen/program/dispatch.rs, lang/src/idl.rs, lang/src/event.rs -->
  • AN-010: Duplicate-mutable protection matches the version and type scope: on < 1.0.0 every same-type mut pair has a distinctness check; on ≥ 1.0.0 the framework checks only Account, LazyAccount, InterfaceAccount, Migration (and init_if_needed fields, #4239), so every other type — AccountLoader, UncheckedAccount, AccountInfo, SystemAccount, Signer — plus dup fields, pure init fields (excluded up to 1.2.1) and remaining_accounts is checked by hand (FP-6). Per Anchor's SECURITY.md the duplicate-mutable check is defence-in-depth, not a security boundary (AN-030). <!-- verified: anchor CHANGELOG 1.0.0 (#3946, #4202, #4239); v1.2.1 lang/syn/src/codegen/accounts/try_accounts.rs `generate_duplicate_mutable_checks` (Account | LazyAccount | InterfaceAccount | Migration, `!is_pure_init()`) -->
  • AN-011: For aliasing on < 1.0, the impact analysis uses "last-declared field's copy wins on exit" (anchor.md §10); for AccountLoader aliasing, cached read-then-write patterns are examined.
  • AN-012: Post-CPI .reload() on < 1.0.0 is followed by a manual owner check when the CPI can close/re-create or reassign the account (RE-003).
  • AN-013: LazyAccount (feature lazy-account, 0.31.0–1.1.2; GHSA-6px8-6mw3-4hx4, fixed 1.2.0 by #4784): after a CPI that receives it writable, owner and discriminator are re-verified before unload()-then-load reads.
  • AN-014: InterfaceAccount mint, token account and token program are bound together (token::token_program, mint::token_program); no 1.0.0-rc.1 build uses InterfaceAccount over discriminator-bearing types.
  • AN-015: On ≤ 1.2.1, init_if_needed on a mint with Token-2022 extension constraints (extensions::*) re-checks every declared extension in the handler when the mint already exists (#4845, fixed after 1.2.1, unreleased). The existing-mint path already checks mint authority, freeze authority, decimals and the owning token program; it does not check extensions, so a pre-created mint with a different hook program, permanent delegate, close authority or metadata pointer passes. <!-- verified: anchor v1.2.1 lang/syn/src/codegen/accounts/constraints.rs, `InitKind::Mint` `if #if_needed` branch -->
  • AN-016: On ≤ 1.2.1, no zero field can receive the same account as an init field: within one struct this happens when the init field is declared after the zero field (the zero uniqueness scan only looked backwards); across composite (nested) Accounts structs it happens in any order, because pure init fields were left out of the cross-struct duplicate check (#4871, fixed after 1.2.1, unreleased: init runs first and leaves the account program-owned and zero-filled, which zero then accepts, so two writable typed wrappers bind one buffer). <!-- verified: anchor master commit 035797c6 (#4871) diff of constraints.rs `generate_constraint_zeroed` (`take_while` -> `filter`) and duplicate_mutable_account_keys.rs -->
  • AN-017: Every #[account(zero)] target is bound to its creator (zero, signer, or same-transaction creation) (KV-142).
  • AN-018: Migration<'info, From, To> handlers are one-shot, authority-gated, correctly sized, with the realloc payer = authority; on 1.0.x To::owner() == program_id is verified by hand, because 1.0.x exit silently skipped persisting the migrated data otherwise (fixed by #4706, present in the v1.1.0 tag; 1.1.0 was never published to crates.io, so 1.1.1 is the first published release with the fix). <!-- verified: anchor v1.0.0 vs v1.1.0 lang/src/accounts/migration.rs `fn exit` -->
  • AN-019: AccountLoader::new_unchecked (≥ 1.2.0, #4162), try_from_unchecked, try_deserialize_unchecked and v2 unchecked borrows on user-suppliable accounts have adjacent manual owner + discriminator checks.
  • AN-020: seeds::program / owner = / address = right-hand sides come from pinned accounts (KV-145).
  • AN-021: Closes use close = dst (lamports to dst, assign to System, resize 0; the constraint rejects dst == self with ConstraintClose); manual .close(dst) calls on ≤ 1.2.1 check dst.key() != self.key() themselves (the framework check inside close() arrived after 1.2.1, #5202); one-shot markers are kept rather than closed (FP-2). <!-- verified: anchor v1.2.1 lang/syn/src/codegen/accounts/constraints.rs `generate_constraint_close`, lang/src/common.rs `close` -->
  • AN-022: realloc shrink paths: the generated code moves every lamport above the new rent minimum (lamports() − minimum_balance(new_space)) to realloc::payer, so an account that also holds escrowed SOL or donated lamports is never shrunk with a caller-chosen realloc::payer (PDA-021(d)). <!-- verified: anchor v0.29.0 and v1.2.1 lang/syn/src/codegen/accounts/constraints.rs `generate_constraint_realloc` (shrink branch) -->
  • AN-023: space uses discriminator length + INIT_SPACE for Borsh types (not size_of), #[max_len] limits are enforced before every push, and CPI-created accounts stay ≤ 10,240 bytes (AV-101/AV-102).

Version notes (not items; used by AN-002, AN-003, AN-015 and FP-5).

  • init_if_needed on an existing account. If the account is still owned by the System Program, the constraint creates it. Otherwise it skips creation and checks only the following. For a program #[account] type: the owner, the discriminator, the exact space and rent exemption. For token accounts and ATAs: the token mint, authority and token program (plus the ATA address). For mints: mint authority, freeze_authority, decimals and the token program. On every released anchor-lang up to and including 1.2.1, the extensions::* constraints of an existing Token-2022 mint are not re-checked on that path. The fix (#4845) is in no tag yet (AN-015). The handler body runs again on every call either way.
  • Program<'info, System> key check. On anchor-lang 1.0.0-rc.3 through 1.0.1 and on 2.0.0-rc.1/rc.2, Program<'info, System> checks only executable. The System Program id is the all-zero key, which equals the Pubkey::default() sentinel used for the untyped form. This was fixed in 1.0.2 and is also fixed in 1.2.x. Anchor's own system_program::* helpers still invoke the real System Program, so the gap matters wherever code trusts that account's key: a hand-built Instruction, or an invoke_signed that takes its program id from it (AN-003). An untyped Program<'info> checks only executable by design on ≥ 1.0.0 (AN-002, KV-154).
<!-- verified: anchor v0.31.1 lang/syn/src/codegen/accounts/constraints.rs (`if !#if_needed || actual_owner == system_program::ID` → create, else deserialize + validate); anchor v1.2.1 constraints.rs program-account `if #if_needed` branch checks ConstraintSpace, ConstraintOwner and ConstraintRentExempt after `from_account_info` (owner + discriminator), token and ATA branches check mint / owner / token program (+ ATA address), mint `if #if_needed` branch checks mint_authority/freeze_authority/decimals/token program only, and parser/accounts/constraints.rs L1141 `mint: if !is_init { mint } else { None }` drops the extensions group when `init` is present; fix commits 2bfd1fe0/1355c6f4 "Fix/init if needed mint extensions (#4845)" are contained in no tag (checked through v2.0.0-rc.2) --> <!-- verified: anchor v1.0.0 lang/src/accounts/program.rs (`Program<'info, T = ()>`, unit type skips the key check, #3878); v0.32.1 has no default type parameter and always compares `info.key` with `T::id()`; v1.0.0-rc.3..v1.0.1 and v2.0.0-rc.1/rc.2 use `let is_unit_type = T::id() == Pubkey::default()` (true for `System`); v1.0.2 commit 3eb1fb04 "Improve `Program` generic key checking logic" splits `T: Id` (key + executable) from `()` (executable only); v1.2.0/v1.2.1 have the split impls; anchor v1.0.1 lang/src/system_program.rs helpers build instructions via system_instruction::* (hard-coded id) -->

21.3 — CPI & execution model

  • AN-024: On 1.x (CpiContext::new(program_id: Pubkey, accounts) since 1.0.0, #2762), every CpiContext::new* Pubkey argument is traced: a key from an unchecked account is an arbitrary-CPI sink; a hard-coded Token::id() on an InterfaceAccount path breaks Token-2022 mints (CPI-029).
  • AN-025: On 1.0.x and earlier, cpi::Return<T>::get() consumers verify the returning program id themselves (KV-152); the check (#4411) is in the v1.1.0 tag, but 1.1.0 was never published to crates.io, so 1.1.1 is the first published release with it (where the master CHANGELOG lists it). <!-- verified: anchor v1.0.2 lang/syn/src/codegen/program/cpi.rs (`let (_key, data) = …get_return_data().unwrap()`) vs v1.1.0 lang/src/lib.rs ("CPI return data program_id mismatch") -->
  • AN-026: Accounts mutated in memory are flushed (exit) before a CPI that reads them, and reloaded after a self-CPI that writes them (RE-009/RE-010).
  • AN-027: Account types own their values: no Cell/RefCell/OnceCell holding &'info references, and no AccountInfo lamports/data backing reference replaced with a reference into ctx.accounts (Anchor 1.0 Context lifetimes). Anchor docs/content/docs/footguns.mdx, [verbatim, Apache-2.0, Copyright 2020 Anchor Maintainers]: "Account types used with Context should own their values rather than hold references borrowed from other accounts or handler-local data. Do not replace an AccountInfo's lamports or data backing reference with a reference to a field in ctx.accounts."
  • AN-028: anchor-spl cpi_guard_enable/disable are not accepted as evidence of CPI Guard (wrong owner key fixed by #4322 and the functions deprecated by #4465, both in 1.2.0).
  • AN-029: Anchor v2 (anchor-next) targets: no unpinned git dependency in production (pin tag/rev); every unsafe(dup) has aliasing analysis; custom entrypoints / fast paths re-implement every skipped TryAccounts check (count, duplicate-mut, owner, writable, signer, data length, PDA, address); raw .view() / borrow_unchecked_mut handlers restore the check table and never hold two live &mut to one account; guardrails not disabled without review; const-rent noted as stale-on-rent-change; idl-build not enabled in deployed SBF binaries; wincode-serialised HashMap/HashSet never hashed, signed or byte-compared; floats validated finite (NaN accepted) (references/framework-idioms/anchor-v2.md).
  • AN-030: No dismissal relies only on an Anchor check that Anchor does not treat as a security boundary. Per Anchor's SECURITY.md, the boundary classes are account ownership, discriminator validation, Anchor-enforced signer checks, memory safety and other fundamental framework invariants. Defence-in-depth checks, such as duplicate-mutable detection and IDL-build compile-time checks (bypassed with --no-idl), are not boundaries, so the program must stay safe without them. A bypass of a boundary-class check is a framework bug (KV-158).

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at 586e19e. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 4 weeks ago

README badge

README badge for princedotrs/solana-audit