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-langin any Cargo.toml. Record the resolved version fromCargo.lockfirst.
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-splversions (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 onlyexecutable, by design) is used as an invoke target with PDA signer seeds or forwarded user signers; allowlisted viaaddress =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
Instructiontakes its program id from aProgram<'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 wheneverT::id() == Pubkey::default(), which is the System Program id; Anchor's ownsystem_program::*helpers and generatedinit/reallocare 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 beingSome; required accounts are enforced withok_or(..)?(the program's own id encodesNone) (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;
langitself 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) oractual(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-idlfeature 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:
fallbacklogic is checked against the version's dispatch order. 0.x: instruction discriminators, thenIDL_IX_TAG(IDL handler, orIdlInstructionStubunderno-idl), thenEVENT_IX_TAG, thenfallback, so neither tag reachesfallback. 1.x: instruction discriminators, thenIDL_IX_TAGonly if#[program(legacy_idl)]is set, thenEVENT_IX_TAG(handler, orEventInstructionStubwithoutevent-cpi), thenfallback. On 1.x withoutlegacy_idl, data that starts withIDL_IX_TAGtherefore does reachfallback, andfallbackmust reject it or handle it safely. No custom discriminator is a prefix of either tag, and theevent-cpihandler 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
mutpair has a distinctness check; on ≥ 1.0.0 the framework checks onlyAccount,LazyAccount,InterfaceAccount,Migration(andinit_if_neededfields, #4239), so every other type —AccountLoader,UncheckedAccount,AccountInfo,SystemAccount,Signer— plusdupfields, pureinitfields (excluded up to 1.2.1) andremaining_accountsis 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
AccountLoaderaliasing, 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(featurelazy-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 beforeunload()-then-load reads. - AN-014:
InterfaceAccountmint, token account and token program are bound together (token::token_program,mint::token_program); no 1.0.0-rc.1 build usesInterfaceAccountover discriminator-bearing types. - AN-015: On ≤ 1.2.1,
init_if_neededon 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
zerofield can receive the same account as aninitfield: within one struct this happens when theinitfield is declared after thezerofield (thezerouniqueness scan only looked backwards); across composite (nested)Accountsstructs it happens in any order, because pureinitfields were left out of the cross-struct duplicate check (#4871, fixed after 1.2.1, unreleased:initruns first and leaves the account program-owned and zero-filled, whichzerothen 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.xTo::owner() == program_idis verified by hand, because 1.0.xexitsilently 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_uncheckedand 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 todst, assign to System, resize 0; the constraint rejectsdst == selfwithConstraintClose); manual.close(dst)calls on ≤ 1.2.1 checkdst.key() != self.key()themselves (the framework check insideclose()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:
reallocshrink paths: the generated code moves every lamport above the new rent minimum (lamports() − minimum_balance(new_space)) torealloc::payer, so an account that also holds escrowed SOL or donated lamports is never shrunk with a caller-chosenrealloc::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:
spaceuses discriminator length +INIT_SPACEfor Borsh types (notsize_of),#[max_len]limits are enforced before every push, and CPI-created accounts stay ≤ 10,240 bytes (AV-101/AV-102).
<!-- 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) -->Version notes (not items; used by AN-002, AN-003, AN-015 and FP-5).
init_if_neededon 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 exactspaceand rent exemption. For token accounts and ATAs: the tokenmint,authorityand token program (plus the ATA address). For mints: mintauthority,freeze_authority,decimalsand the token program. On every released anchor-lang up to and including 1.2.1, theextensions::*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 onlyexecutable. The System Program id is the all-zero key, which equals thePubkey::default()sentinel used for the untyped form. This was fixed in 1.0.2 and is also fixed in 1.2.x. Anchor's ownsystem_program::*helpers still invoke the real System Program, so the gap matters wherever code trusts that account's key: a hand-builtInstruction, or aninvoke_signedthat takes its program id from it (AN-003). An untypedProgram<'info>checks onlyexecutableby design on ≥ 1.0.0 (AN-002, KV-154).
21.3 — CPI & execution model
- AN-024: On 1.x (
CpiContext::new(program_id: Pubkey, accounts)since 1.0.0, #2762), everyCpiContext::new*Pubkeyargument is traced: a key from an unchecked account is an arbitrary-CPI sink; a hard-codedToken::id()on anInterfaceAccountpath 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/OnceCellholding&'inforeferences, and noAccountInfolamports/data backing reference replaced with a reference intoctx.accounts(Anchor 1.0Contextlifetimes). Anchordocs/content/docs/footguns.mdx, [verbatim, Apache-2.0, Copyright 2020 Anchor Maintainers]: "Account types used withContextshould own their values rather than hold references borrowed from other accounts or handler-local data. Do not replace anAccountInfo's lamports or data backing reference with a reference to a field inctx.accounts." - AN-028:
anchor-splcpi_guard_enable/disableare 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 (pintag/rev); everyunsafe(dup)has aliasing analysis; custom entrypoints / fast paths re-implement every skippedTryAccountscheck (count, duplicate-mut, owner, writable, signer, data length, PDA, address); raw.view()/borrow_unchecked_muthandlers restore the check table and never hold two live&mutto one account;guardrailsnot disabled without review;const-rentnoted as stale-on-rent-change;idl-buildnot enabled in deployed SBF binaries; wincode-serialisedHashMap/HashSetnever 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).