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.

checklists04-program-cpi-pda.md

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

04 — CPI & PDA Safety Checklist

Domain: On-chain Solana Program
Severity if missed: CRITICAL
References: Neodyme "Arbitrary Signed Program Invocation", Sealevel Attacks, QEDGen CPI properties

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


4.1 — CPI Target Validation

  • CPI-001: Every CpiContext::new() first argument is a Pubkey (Anchor 1.0), NOT .to_account_info() (Anchor 0.x pattern) (1.x only; on 0.x the first argument is an AccountInfo, so check the field's type instead; see CPI-029). <!-- verified: anchor v1.0.0 lang/src/context.rs CpiContext::new(program_id: Pubkey, ..); v0.32.1 CpiContext::new(program: AccountInfo, ..) -->
  • CPI-002: Every CpiContext::new_with_signer() first argument is a Pubkey (Anchor 1.0) (1.x only; on 0.x the first argument is an AccountInfo, so check the field's type instead; see CPI-029).
  • CPI-003: Every CPI to SPL Token Program — the token_program account is validated as spl_token::ID or Program<'info, Token>
  • CPI-004: Every CPI to System Program — the system_program account is validated as system_program::ID or Program<'info, System>
  • CPI-005: Every CPI to Associated Token Program — validated as associated_token::ID or typed Program<'info, AssociatedToken>
  • CPI-006: Every CPI to a DEX aggregator (Jupiter, etc.) — program ID is validated via require_keys_eq! against hardcoded known ID
  • CPI-007: Every CPI to Metaplex — program ID validated against hardcoded metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s
  • CPI-008: No CPI uses an UncheckedAccount as the program to invoke — the program account MUST be validated
  • CPI-009: If remaining_accounts are passed through to a CPI, the target program ID is still validated
  • CPI-010: For invoke_signed (raw Solana CPI), the program_id in the Instruction is validated before invocation
  • CPI-028: For every invoke/invoke_signed, record where Instruction.program_id comes from: a constant, an SPL builder that validates it, or an alias that a dominating equality check pins to a constant on every control-flow path before the call. A check in one match arm, a check after the call, or a check on a different alias than the one put into the instruction does not count. Identify the callee from program_id, not from which account is missing in account_infos (FP-7).
  • CPI-029: For every CpiContext::new* whose program is not a typed Program<'info, T>/Interface, open the wrapper's source for the pinned version. anchor_spl::token::* hardcodes spl_token::ID (not a finding). anchor_spl::token_2022/token_interface helpers pass the context's program (ctx.program on 0.x, ctx.program_id on 1.x) to the spl_token_2022 builders, which reject any id other than SPL Token or Token-2022 (extension builders accept Token-2022 only). That is not an arbitrary-CPI finding, but check that the code does not assume one specific token program. The token_2022_extensions helpers take the program from an account field (ctx.accounts.token_program_id or ctx.accounts.program_id), not from the context's program. The extension-instruction helpers are safe because their builders accept Token-2022 only. Exception: the token_metadata_* and token_group_* helpers build through spl_token_metadata_interface / spl_token_group_interface, whose builders accept any program id (those interfaces are meant to be implemented by any program). An unconstrained program_id account there is an arbitrary-CPI finding when signer seeds or user signers are forwarded. Anchor-generated cpi:: and declare_program! clients put the context's program id into the Instruction unchecked (ctx.program.key() on 0.x, ctx.program_id on 1.x): a finding unless that id is a constant or comes from a typed Program<'info, T> (on 1.0.0–1.0.1 not Program<'info, System>, CPI-030) or an address-constrained account. <!-- verified: anchor v0.26.0/v0.29.0/v0.32.1/v1.0.0 spl/src/token.rs (&spl_token::ID), spl/src/token_2022.rs (ctx.program.key / &ctx.program_id); token-2022 interface/src/lib.rs check_spl_token_program_account / check_program_account, every interface/src/instruction.rs builder calls one of them; anchor v0.30.1/v0.32.1/v1.0.0/v1.2.1 spl/src/token_2022_extensions/{token_metadata,token_group}.rs pass ctx.accounts.(token_)program_id.key to non-validating interface builders (no `?`); anchor v0.29.0 cpi.rs program_id: ctx.program.key(), v1.0.2 program_id: ctx.program_id -->
  • CPI-030: No untyped Program<'info> (it checks only executable) is an invoke target that receives PDA signer seeds or forwarded user signers. On Anchor 1.0.0–1.0.1 (and the 1.0.0 release candidates) the same applies to Program<'info, System>: the System program id equals Pubkey::default(), which those versions treat as "any program", so its key is unchecked. That matters when the code builds an Instruction from its key; the anchor_lang::system_program::* helpers hardcode the System id and are unaffected (KV-154). <!-- verified: anchor v1.0.0/v1.0.1 lang/src/accounts/program.rs is_unit_type = T::id() == Pubkey::default(); fixed in v1.0.2 (3eb1fb04) -->
  • CPI-041: PDA signer privilege is never extended to a caller-chosen or untrusted upgradeable callee. The callee holds the PDA's signer privilege for the whole CPI and can pass it to nested CPIs, which makes it a confused deputy over every asset the PDA controls.

4.2 — CPI Parameter Validation

  • CPI-011: token::transfer CPI — from account is the expected source (vault or user account)
  • CPI-012: token::transfer CPI — to account is the expected destination (not attacker-controlled)
  • CPI-013: token::transfer CPI — authority is the correct PDA or signer
  • CPI-014: token::transfer CPI — amount is calculated correctly and matches expected value
  • CPI-015: token::mint_to CPI — mint is the program's own mint for this flow (for example a share, LP or receipt mint), bound by seeds or a stored key, not an attacker-supplied mint
  • CPI-016: token::mint_to CPI — to is the beneficiary's token account for that mint (owner and mint both bound)
  • CPI-017: token::mint_to CPI — authority is the program PDA that holds the mint authority
  • CPI-018: token::mint_to CPI — amount matches calculated shares (not attacker-controlled)
  • CPI-019: token::burn CPI — from is the token account of the user whose balance is being redeemed
  • CPI-020: token::burn CPI — authority is that user, as a signer (they authorized the burn), or a delegate they approved
  • CPI-021: token::burn CPI — amount matches the intended burn amount
  • CPI-022: token::close_account CPI — destination is constrained to known recipients (the program PDA, the account's user, or the treasury)
  • CPI-023: token::close_account CPI — authority is the correct entity
  • CPI-024: token::close_account CPI — the closed account is NOT the main vault (catastrophic if vault is closed)
  • CPI-025: system_program::transfer CPI — source and destination are validated. The from of a System Transfer must be System-owned and carry no data; see CPI-031. <!-- verified: agave system program transfer_verified rejects `from` with data ("Transfer: `from` must not carry data") -->
  • CPI-026: token::approve CPI — delegate and amount are validated, not granting unlimited approval
  • CPI-027: token::revoke CPI — actually revokes the correct delegation
  • CPI-031: SOL held by a program-owned account is paid out by a direct lamport debit by the owning program, preserving rent exemption. It is never paid by a system_program::transfer signed by the PDA, which always fails because from must be System-owned and carry no data. A withdrawal that depends on such a transfer is a locked-funds finding (High when it is the only exit).
  • CPI-032: After direct lamport edits, the next CPI receives either all or none of the changed accounts (precisely: the changed accounts it receives must net to zero). Passing an unbalanced subset makes the runtime see a non-zero lamport delta when the CPI is pushed, and it fails with UnbalancedInstruction (runtime balance rule, FP-16). The failure is deterministic, so a value-moving path that always passes an unbalanced subset can never succeed: report it as locked funds or DoS when it is the only exit, not as a harmless revert. <!-- verified: agave v3.0.0 transaction-context/src/lib.rs push(): `!instruction_stack.is_empty() && accounts.get_lamports_delta() != 0` -> UnbalancedInstruction (only accounts synced into the CPI count); program-runtime/src/invoke_context.rs test case UnbalancedPush. In v2.1.0 the same rule is a caller-instruction lamport-sum comparison in sdk/src/transaction_context.rs TransactionContext::push -->
  • CPI-033: Return data is consumed only after checking that the returned program_id equals the just-invoked, pinned callee. None is an error (not 0/default). Length and format are validated before decoding, values are bounded (0, u64::MAX), and the ordering/uniqueness of returned vectors is validated. Anchor's generated cpi::Return<T>::get() (and the declare_program! equivalent) verifies the program id only from 1.1.0 (#4411, #4624; on 1.2.x as well). That check compares against the id the CPI was sent to (ctx.program_id), so it pins nothing when that id is itself caller-chosen (CPI-029). It panics on mismatch or missing data rather than returning an error. On 1.1.0+ get() reads a snapshot taken right after the CPI. get_unchecked() skips the id check and reads the live return-data buffer. On ≤ 1.0.x, get() ignores the id and also reads the live buffer, so any CPI made between the call and .get() replaces the value (KV-152). <!-- verified: anchor v1.0.2 lang/syn/src/codegen/program/cpi.rs Return::get ignores key; v1.1.0 Return::get -> CpiReturnData::get(expected_program_id), snapshot taken via CpiReturnData::snapshot() right after invoke_signed, panic!() on mismatch, unwrap on None; get_unchecked calls live get_return_data(); same in lang/attribute/program/src/declare_program/mods/cpi.rs (commits 256da610 #4411 and 751d05c3 #4624 tagged v1.1.0+) -->
  • CPI-034: Every invoke_unchecked/invoke_signed_unchecked, Pinocchio unchecked CPI or raw sol_invoke_signed_* call has a written justification. No data/lamports borrow of a passed account (including bytemuck/zero-copy views) is alive across it, and views are re-derived after it (KV-182).
  • CPI-035: Hand-assembled CPI structures (AccountMeta/AccountInfo arrays, seed slices) are built only from validated accounts, their lengths match, and is_signer/is_writable are never more than intended.
  • CPI-036: get_processed_sibling_instruction results are treated as hints. They are completed instructions at the same stack height under the same parent, newest first. They carry the program id, data and metas, but not their effects (balances actually moved, accounts created, fees withheld). Consumers decode the sibling fully (discriminator, mint, destination, authority, amount) and prefer a balance-delta check. For Token-2022 fee/hook mints, the requested amount differs from the received amount.
  • CPI-037: After any approve/approve_checked of a delegate on a program-owned token account for an external pull, the handler approves the exact amount and revokes after the CPI. It then reloads and asserts delegate.is_none() && delegated_amount == 0, or it moves the exact amount into a per-operation account. PDA signer privilege is lent only to a pinned, trusted program (KV-165).
  • CPI-038: SPL approve replaces the delegated amount; it does not add to it. Two approvals to the same delegate in one batch/CPI sequence leave only the second. Confirm whether additivity was intended. <!-- verified: solana-program/token program/src/processor.rs process_approve sets delegated_amount = amount -->
  • CPI-039: No Result from invoke/invoke_signed, an SPL instruction builder, an Anchor CPI helper, a serializer write-back or a sysvar getter is discarded (let _ =, .ok();, unwrap_or_default()) on a value-moving or state-persisting path. Every built Instruction is actually invoked (KV-150).
  • CPI-040: The boundary enumeration in §4.7 is complete for every CPI and account boundary.

4.3 — PDA Derivation Safety

  • PDA-001: Every PDA is derived using all required seed components — no missing seeds that could cause collision
  • PDA-002: Each top-level object PDA (pool, market, vault, fund) has seeds that include its creator or another uniqueness key plus any name or index, for example [b"pool", creator.key(), name.as_bytes()], and all of them are present in every derivation
  • PDA-003: For each PDA in the program, list its seeds and verify all present in derivation
  • PDA-004: Verify PDA seed order is consistent between init and all subsequent references
  • PDA-005: Vault/treasury PDA seeds include parent account key — verify present
  • PDA-006: Mint PDA seeds include parent account key — verify present
  • PDA-007: Attestation/oracle PDA seeds include parent account key — verify present
  • PDA-008: Access-control PDA seeds (whitelist, role, permission) include parent account key — verify present
  • PDA-009: All custom PDAs above — verify seeds match in both derivation and usage (no mismatch between init and later references)
  • PDA-010: Bump seeds are stored on first derivation and reused — not re-derived each time (saves compute + prevents bump mismatch)
  • PDA-011: No PDA seed uses user-controlled variable-length data without length prefix (could cause seed collision). Apply the full seed-concatenation procedure in KV-026: a distinct literal first seed per account type, no literal that is a prefix of another, variable-length seeds last, and those seeds length-delimited or hashed.
  • PDA-012: User-chosen names or strings in PDA seeds — is there a max length? Can two objects have names that collide after truncation? A user string that one instruction stores and a later instruction uses as a seed (especially on an exit/withdraw path) is length-checked (≤ 32 bytes) where it is first accepted, or hashed to 32 bytes. A require!(name.len() <= 32) in the same handler as an init + seeds derivation runs too late, because the derivation fails first in try_accounts. An oversized seed in a single instruction only fails the caller's own transaction (Informational). MAX_SEEDS = 16 includes the bump, so find_program_address takes at most 15 user seeds.
  • PDA-013: PDA seeds do not include mutable state that could change (would orphan the PDA)
  • PDA-023: Every PDA whose seeds reference the PDA's own stored fields (seeds = [b"vault", vault.owner.as_ref()]) binds the privileged actor to that field: has_one = owner with owner: Signer, or the seed derived from the Signer. For gating objects anyone can create (factions, pools, markets, guardian sets), the gate pins the intended instance through stored or global state. Checking only that the object "is genuine" is not enough (KV-144).
  • PDA-024: A foreign-program PDA (seeds::program = X, native find_program_address(seeds, X)) takes X from a pinned program (Program<'info, T> or address = X::ID). Derivations never use an account's self-reported owner (create_program_address(seeds, acct.owner)) (KV-145).
  • PDA-025: Bump provenance: classify the last seed passed to create_program_address. An instruction argument without a later == find_program_address(..).1 comparison, or a field of a Borsh-decoded instruction struct, is a non-canonical-bump finding with a ceiling of High, scored by what the alternative address lets an attacker do (Rule 1). A field of an account is safe only if it was written from ctx.bumps/find_program_address at an init that used seeds + bare bump. A stored canonical bump used with create_program_address is the recommended pattern, not a finding (KV-104).

4.4 — invoke_signed Safety

  • PDA-014: Every invoke_signed call uses the correct signer seeds for the PDA authority
  • PDA-015: Signer seeds array matches the PDA derivation exactly (same order, same components)
  • PDA-016: Bump seed in invoke_signed matches the stored bump (not a different bump)
  • PDA-017: invoke_signed is used (not bare invoke) when a PDA is the authority. A bare invoke fails loudly and reverts the transaction: the runtime returns PrivilegeEscalation ("signer privilege escalated") when the instruction marks the PDA as a signer, and the callee returns MissingRequiredSignature when it does not. On a path that is the only way out of an account, that is locked funds or DoS, not a silent failure. <!-- verified: agave v4.3.2 program-runtime/src/invoke_context.rs prepare_next_cpi_instruction (`signer privilege escalated` → InstructionError::PrivilegeEscalation; tests run_native_invoke_signed_test without seeds) -->
  • PDA-018: No instruction uses invoke where it should use invoke_signed (missing PDA signing)
  • PDA-019: The instruction data passed to invoke_signed cannot be manipulated by the caller to change the operation
  • PDA-020: For Jupiter CPI, the instruction data is either fully constructed by the program or validated
  • PDA-021: realloc safety — grown bytes are zero-initialized AND the rent for the added space is not funded by the program/vault at an attacker-chosen size. Two sub-checks: (a) any realloc(new_len, false) (or AccountInfo::realloc(_, false)) that grows an account leaves the newly-added bytes NON-zeroed, so stale or attacker-influenced heap contents are later read as valid state — grows must zero-init the new region (realloc(new_len, true), Anchor realloc::zero = true on a grow-after-shrink, or an explicit data[old_len..new_len].fill(0)); (b) the realloc target length is attacker-controlled AND the added rent is paid by the program or a program-owned vault (realloc::payer = <program PDA / vault>) rather than by the requester — an attacker repeatedly grows accounts to drain the vault's rent reserve. (PASS: every grow zero-inits the new bytes, and realloc::payer/the lamport top-up is the requester, with the size bounded by a MAX_LEN constant; FAIL: a false/non-zeroing grow whose new bytes are later deserialized, or a program/vault-funded realloc at a caller-chosen size — rent-exhaustion drain. Grep: grep -rn --include="*.rs" -iE "realloc\(" programs/) (c) Growth per account per instruction is at most MAX_PERMITTED_DATA_INCREASE = 10,240 bytes over its length at the start of the instruction (Anchor realloc returns AccountReallocExceedsLimit above it; AV-043). (d) On a shrink, Anchor's realloc credits all lamports above the new rent minimum to realloc::payer. Accounts that escrow SOL in their own lamports, or that receive donations, must not be shrinkable with an arbitrary payer. Refund only the released rent to the recorded original payer, or keep SOL value in a separate data-less PDA that is never resized (anchor.md §5, AN-022). <!-- verified: anchor v1.0.0 and v1.2.1 lang/syn/src/codegen/accounts/constraints.rs generate_constraint_realloc (shrink branch moves lamports() - minimum_balance(new_space) to payer) -->
  • PDA-022: Every signing PDA is unique to the asset set it guards. Write down three things for each one: its authority domain (every token/lamport account it controls), its seed scope (global constant / mint / pool / user) and its binding path (the constraint that ties the state account supplying the seeds to this vault and destination). FAIL: the seeds are built only from shared values (a constant, a mint, a program-wide config) while an untrusted or permissionlessly creatable state account names the vault the PDA moves funds from. Test question: can an attacker create their own pool/position/escrow today whose seeds make the same PDA sign for someone else's vault? (KV-143)

4.5 — External CPI Safety (Jupiter, Metaplex, etc.)

  • EXT-001: Jupiter swap CPI — the fund PDA is the authority (signed with invoke_signed)
  • EXT-002: Jupiter swap CPI — slippage is enforced (either by Jupiter's internal mechanism or by post-CPI balance check)
  • EXT-003: Jupiter swap CPI — returned token account belongs to the fund PDA
  • EXT-004: Jupiter swap CPI — remaining_accounts are passed correctly
  • EXT-005: After Jupiter CPI — verify fund balances changed as expected (post-condition check)
  • EXT-006: Jupiter program ID is validated against known address each time
  • EXT-007: Metaplex CPI (if used) — metadata account derived correctly
  • EXT-008: Metaplex CPI (if used) — program ID validated
  • EXT-009: Protocol CPI (whitelisted programs) — program is in the whitelist before invocation
  • EXT-010: Protocol CPI — whitelist is owned by the program and linked to the fund
  • EXT-011: No CPI allows the called program to callback into this program with escalated privileges

Token-2022 / Extensions

Grep hints:

grep -rn --include="*.rs" -iE "transfer_hook|TransferHook|permanent_delegate|PermanentDelegate|freeze_authority|FreezeAuthority|close_authority|MintCloseAuthority|get_extension|transfer_checked|remaining_accounts" programs/
  • EXT-012: If a custodied mint carries a TransferHook extension — is the hook program checked against an allowlist AND are its required remaining_accounts resolved and forwarded on every transfer_checked CPI? (PASS: hook program allowlisted + extra accounts resolved via spl_transfer_hook_interface and appended to the CPI; FAIL: hook program unvalidated (arbitrary CPI target) or remaining_accounts omitted so the transfer reverts / silently fails. (adapted from safe-solana-builder shared-base §23.1))
  • EXT-013: Are custodied mints inspected for PermanentDelegate, uncontrolled FreezeAuthority, and MintCloseAuthority, and rejected unless the mint is on a trusted allowlist? (PASS: get_extension::<...>() read at init/registration; PermanentDelegate (vault clawback), external FreezeAuthority (withdrawal DoS), and MintCloseAuthority (address recycle) all rejected or the mint is explicitly trusted; FAIL: extensions never read — a hostile mint authority can seize, freeze, or recycle the vault. (adapted from safe-solana-builder shared-base §23.1))
  • EXT-014: Does ALL token movement use transfer_checked (mint + decimals supplied) and credit accounting via a balance delta (vault.amount AFTER reload() − BEFORE) rather than the declared amount? (PASS: transfer_checked + delta-based credit with checked_sub, so transfer-fee mints are accounted correctly; FAIL: legacy token::transfer (breaks on Token-2022) or credits the requested amount ignoring the fee. (adapted from safe-solana-builder shared-base §21.6 / §23.1))
  • EXT-015: If the program creates a mint, does it claim/initialize that mint's Metaplex (or Token-2022) metadata atomically at init, with update authority set to the program or a program-owned PDA — rather than leaving it unclaimed (and attacker-ownable) or stale? (PASS: metadata created in the same flow that creates the mint, update authority = program/PDA, and closed/reset when the mint is retired so it cannot go stale on re-use; FAIL: metadata left unclaimed → an attacker front-runs and sets name/URI/authority, or old metadata is not closed and reappears on a later re-mint/re-burn. Evidence: Zenith MetaDAO, Accretion, OtterSec Orca stale-metadata-on-reburn)

4.6 — CPI Reentrancy & Composability

  • RE-001: State mutations happen BEFORE external CPIs (checks-effects-interactions pattern)
  • RE-002: If state is read after CPI, it's re-loaded (not using stale pre-CPI data)
  • RE-003: Account reload after CPI uses .reload(). On Anchor ≥ 1.0.0, reload() re-checks the owner and the discriminator. On ≤ 0.32 it only re-deserializes: the discriminator for Anchor #[account] types, and for InterfaceAccount/anchor_spl token types only that the bytes unpack, with no owner check. So on < 1.0, after a CPI that can close/re-create or reassign the account, re-check the owner by hand. Do the same for LazyAccount::unload() on < 1.2.0 (#4784). <!-- verified: anchor v0.29.0/v0.32.1 lang/src/accounts/account.rs reload() = try_deserialize only; v1.0.0 adds owner check; LazyAccount::unload re-runs try_from only from v1.2.0 (f170d119, #4784) -->
  • RE-004: No CPI grants approval to an external program that could re-enter
  • RE-005: Flash loan resistance: could an attacker borrow tokens, deposit, inflate NAV, and withdraw in one transaction?
  • RE-006: CPI callee SOL-spend guard — Solana has no msg.value, so a callee can spend SOL from ANY signing account passed into a CPI (not just an explicit "amount" argument). Before an invoke/invoke_signed to a composed or user-supplied program, the caller records signer.lamports() and bounds the post-call drain. (PASS: pre-CPI lamports snapshot taken and a checked_sub post-CPI asserts the drain is within an expected bound; FAIL: a signing account is handed to an external CPI with no lamport accounting — the callee can siphon its full balance. (adapted from safe-solana-builder shared-base §5.4))
  • RE-007: Post-CPI ownership re-verification — an attacker-controlled callee can invoke System assign mid-CPI to steal an account's owner. After any CPI touching a relied-upon account, the caller re-asserts account.owner == expected. (PASS: owner re-checked after the CPI — Anchor .reload() covers ONLY accounts Anchor itself reloads, so native/Pinocchio/raw-invoke paths re-check the owner manually; FAIL: account owner trusted from before the CPI, or .reload() assumed to cover a raw-invoke account it never touched. (adapted from safe-solana-builder shared-base §5.5))
  • RE-008: No self-CPI through a caller-chosen program id. Executors of stored or caller-supplied instructions (multisig, DAO, routers, flash-loan receivers) reject program_id == crate::ID (or explicitly allow-list self calls), and write their effects (executed = true) before the CPI.
  • RE-009: Before any CPI whose callee reads an Anchor Account<T> that was changed in memory (hooks, oracle adapters, sibling programs, self-CPI), the account is flushed with exit(&crate::ID)?. Otherwise the callee sees the last serialized state.
  • RE-010: After a self-CPI (A→A) that writes an account the outer handler also holds, the outer handler reloads before writing. Otherwise the outer exit() overwrites the inner write (lost update / double spend).

4.7 — Boundary Enumeration (run until no boundary is left)

Step 1 — list every boundary: each invoke/invoke_signed/CpiContext::new*; each account whose owner or program comes from the caller (UncheckedAccount, AccountInfo, Interface, untyped Program); each Option<Account<…>>; each remaining_accounts iteration; each instruction-data / try_from_slice / zero-copy load(); each get_return_data(); each lamport move; each branch on a sentinel (NATIVE_MINT, Pubkey::default(), u64::MAX).

Step 2 — ask the same questions at each:

  1. Unexpected account kind: uninitialized, owned by another program, executable, Token-2022 where SPL Token was assumed?
  2. Non-standard token behaviour: TransferFee (received < sent; EXT-014), hook (extra CPI and accounts), confidential, NonTransferable, default-frozen, PermanentDelegate, MemoTransfer on the destination. Does the code use the requested amount or the measured delta?
  3. Zero / max / empty: amount == 0, u64::MAX, empty remaining_accounts, empty Vec, zero-length seed string.
  4. Return data: are the setter's program id and the length checked? The runtime resets return data to empty at the start of every invocation, including each CPI. So after A→B→C, if only C sets data, A reads it with C's program id.
  5. Sentinel flowing into an SPL operation (NATIVE_MINT into transfer_checked, a lamport path receiving a real mint)?
  6. Callee-controlled program or accounts: can the callee use the PDA signer privilege it receives (and pass it to nested CPIs) on other assets the PDA controls?
  7. Unbounded caller-supplied fee, bonus or slippage parameter?

Step 3 — native-SOL questions: Are lamports measured (before/after) or assumed from amount? Is equality between an amount argument and the lamport transfer enforced? Is the fee taken on the native branch as on the SPL branch? Is excess SOL refunded, or stranded in a PDA with no sweep?

Discipline: each finding names the boundary, the assumption the code makes about it, and the actual behaviour under the corner case. Without all three it is a LEAD.

<!-- verified Q4: agave v3.0.0 program-runtime/src/invoke_context.rs process_executable_chain sets return data to (program_id, empty) before each instruction -->

Sources: Trail of Bits skills plugins/building-secure-contracts/skills/solana-vulnerability-scanner/resources/VULNERABILITY_PATTERNS.md (corrected), not-so-smart-contracts solana/arbitrary_cpi [paraphrased, CC-BY-SA-4.0 / AGPL-3.0, cited: https://github.com/crytic/building-secure-contracts/tree/master/not-so-smart-contracts/solana/arbitrary_cpi]; crytic/solana-lints lints/bump_seed_canonicalization and lints/arbitrary_cpi [paraphrased, cited]; Solana Foundation course content/courses/program-security/arbitrary-cpi.md, pda-sharing.md and bump-seed-canonicalization.md [paraphrased, cited]; Neodyme "Common Pitfalls", "Arbitrary signed program invocation" section [paraphrased, cited: https://neodyme.io/en/blog/solana_common_pitfalls]; PlamenTSV/plamen agents/skills/solana/external-precondition-audit/SKILL.md (return data) and prompts/solana/phase4b-scanner-templates.md (MIT, Copyright (c) 2025-2026 Plamen Contributors); otter-sec/anchor lang/src/accounts/program.rs and lang/src/lib.rs Return<T> (Apache-2.0); OtterSec "Solana: jumping around in the VM" (CPI gadget) and "Solana: an auditor's introduction" [paraphrased, cited: https://osec.io/blog/2023-12-11-jumping-around-in-the-vm ; https://osec.io/blog/solana-security-intro]; solana-foundation/solana-dev-skill skills/solana-dev/references/security.md ("Self-Reentrancy (A → A)", "Stale Account State Around CPIs") and skills/solana-dev/references/programs/design-patterns.md (MIT, Copyright (c) 2026); sanbir/solana-auditor-skills solana-auditor/references/attack-vectors/attack-vectors-2.md V34, corrected (MIT, Copyright (c) 2024 AI Skills Contributors); SlowMist best practices README.md "Error not handled" (Apache-2.0, attributed to SlowMist); pashov/skills solidity-auditor/references/hacking-agents/boundary-agent.md and solidity-auditor/references/hacking-agents/execution-trace-agent.md (residual delegate) (MIT, Copyright (c) 2024 AI Skills Contributors) (corrected: Q4/Q6 and the PDA-signer advice); coral-xyz/sealevel-attacks programs/8-pda-sharing [paraphrased, cited]; Ackee-Blockchain Solana-Auditors-Bootcamp Lesson-6/pda-privileges and Capture-the-Flag/level-4 [paraphrased, cited: https://github.com/Ackee-Blockchain/Solana-Auditors-Bootcamp/tree/master]; Sealevel Sentinel (stantheman0128/sealevel-sentinel) src/detectors/arbitrary-cpi.ts and src/detectors/pda-sharing.ts (MIT, Copyright (c) 2026 Stan (stantheman0128)) (corrected); original analysis (seed length and count limits); franpersanchez/solana-audits-skill skill/references/official-basis.md (MIT, Copyright (c) 2026 Fran Pérez); original analysis. Version facts re-verified against solana-foundation/anchor tags v0.29.0–v1.2.1 (Apache-2.0).

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