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 aPubkey(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 aPubkey(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::IDorProgram<'info, Token> - CPI-004: Every CPI to System Program — the system_program account is validated as
system_program::IDorProgram<'info, System> - CPI-005: Every CPI to Associated Token Program — validated as
associated_token::IDor typedProgram<'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
UncheckedAccountas 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 whereInstruction.program_idcomes 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 onematcharm, 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 fromprogram_id, not from which account is missing inaccount_infos(FP-7). - CPI-029: For every
CpiContext::new*whose program is not a typedProgram<'info, T>/Interface, open the wrapper's source for the pinned version.anchor_spl::token::*hardcodesspl_token::ID(not a finding).anchor_spl::token_2022/token_interfacehelpers pass the context's program (ctx.programon 0.x,ctx.program_idon 1.x) to thespl_token_2022builders, 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. Thetoken_2022_extensionshelpers take the program from an account field (ctx.accounts.token_program_idorctx.accounts.program_id), not from the context's program. The extension-instruction helpers are safe because their builders accept Token-2022 only. Exception: thetoken_metadata_*andtoken_group_*helpers build throughspl_token_metadata_interface/spl_token_group_interface, whose builders accept any program id (those interfaces are meant to be implemented by any program). An unconstrainedprogram_idaccount there is an arbitrary-CPI finding when signer seeds or user signers are forwarded. Anchor-generatedcpi::anddeclare_program!clients put the context's program id into theInstructionunchecked (ctx.program.key()on 0.x,ctx.program_idon 1.x): a finding unless that id is a constant or comes from a typedProgram<'info, T>(on 1.0.0–1.0.1 notProgram<'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 onlyexecutable) 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 toProgram<'info, System>: the System program id equalsPubkey::default(), which those versions treat as "any program", so its key is unchecked. That matters when the code builds anInstructionfrom its key; theanchor_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::transferCPI —fromaccount is the expected source (vault or user account) - CPI-012:
token::transferCPI —toaccount is the expected destination (not attacker-controlled) - CPI-013:
token::transferCPI —authorityis the correct PDA or signer - CPI-014:
token::transferCPI —amountis calculated correctly and matches expected value - CPI-015:
token::mint_toCPI —mintis 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_toCPI —tois the beneficiary's token account for that mint (owner and mint both bound) - CPI-017:
token::mint_toCPI —authorityis the program PDA that holds the mint authority - CPI-018:
token::mint_toCPI —amountmatches calculated shares (not attacker-controlled) - CPI-019:
token::burnCPI —fromis the token account of the user whose balance is being redeemed - CPI-020:
token::burnCPI —authorityis that user, as a signer (they authorized the burn), or a delegate they approved - CPI-021:
token::burnCPI —amountmatches the intended burn amount - CPI-022:
token::close_accountCPI —destinationis constrained to known recipients (the program PDA, the account's user, or the treasury) - CPI-023:
token::close_accountCPI —authorityis the correct entity - CPI-024:
token::close_accountCPI — the closed account is NOT the main vault (catastrophic if vault is closed) - CPI-025:
system_program::transferCPI — source and destination are validated. Thefromof a SystemTransfermust 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::approveCPI — delegate and amount are validated, not granting unlimited approval - CPI-027:
token::revokeCPI — 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::transfersigned by the PDA, which always fails becausefrommust 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_idequals the just-invoked, pinned callee.Noneis 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 generatedcpi::Return<T>::get()(and thedeclare_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 rawsol_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/AccountInfoarrays, seed slices) are built only from validated accounts, their lengths match, andis_signer/is_writableare never more than intended. - CPI-036:
get_processed_sibling_instructionresults 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_checkedof 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 assertsdelegate.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
approvereplaces 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
Resultfrominvoke/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 builtInstructionis 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
initand 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 aninit+seedsderivation runs too late, because the derivation fails first intry_accounts. An oversized seed in a single instruction only fails the caller's own transaction (Informational).MAX_SEEDS = 16includes the bump, sofind_program_addresstakes 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 = ownerwithowner: Signer, or the seed derived from theSigner. 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, nativefind_program_address(seeds, X)) takesXfrom a pinned program (Program<'info, T>oraddress = 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(..).1comparison, 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 fromctx.bumps/find_program_addressat aninitthat usedseeds+ barebump. A stored canonical bump used withcreate_program_addressis the recommended pattern, not a finding (KV-104).
4.4 — invoke_signed Safety
- PDA-014: Every
invoke_signedcall 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_signedmatches the stored bump (not a different bump) - PDA-017:
invoke_signedis used (not bareinvoke) when a PDA is the authority. A bareinvokefails loudly and reverts the transaction: the runtime returnsPrivilegeEscalation("signer privilege escalated") when the instruction marks the PDA as a signer, and the callee returnsMissingRequiredSignaturewhen 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
invokewhere it should useinvoke_signed(missing PDA signing) - PDA-019: The instruction data passed to
invoke_signedcannot 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:
reallocsafety — 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) anyrealloc(new_len, false)(orAccountInfo::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), Anchorrealloc::zero = trueon a grow-after-shrink, or an explicitdata[old_len..new_len].fill(0)); (b) therealloctarget 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, andrealloc::payer/the lamport top-up is the requester, with the size bounded by aMAX_LENconstant; FAIL: afalse/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 mostMAX_PERMITTED_DATA_INCREASE= 10,240 bytes over its length at the start of the instruction (AnchorreallocreturnsAccountReallocExceedsLimitabove it; AV-043). (d) On a shrink, Anchor'srealloccredits all lamports above the new rent minimum torealloc::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
TransferHookextension — is the hook program checked against an allowlist AND are its requiredremaining_accountsresolved and forwarded on everytransfer_checkedCPI? (PASS: hook program allowlisted + extra accounts resolved viaspl_transfer_hook_interfaceand appended to the CPI; FAIL: hook program unvalidated (arbitrary CPI target) orremaining_accountsomitted so the transfer reverts / silently fails. (adapted from safe-solana-builder shared-base §23.1)) - EXT-013: Are custodied mints inspected for
PermanentDelegate, uncontrolledFreezeAuthority, andMintCloseAuthority, and rejected unless the mint is on a trusted allowlist? (PASS:get_extension::<...>()read at init/registration;PermanentDelegate(vault clawback), externalFreezeAuthority(withdrawal DoS), andMintCloseAuthority(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.amountAFTERreload()− BEFORE) rather than the declaredamount? (PASS:transfer_checked+ delta-based credit with checked_sub, so transfer-fee mints are accounted correctly; FAIL: legacytoken::transfer(breaks on Token-2022) or credits the requestedamountignoring 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 forInterfaceAccount/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 forLazyAccount::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 aninvoke/invoke_signedto a composed or user-supplied program, the caller recordssigner.lamports()and bounds the post-call drain. (PASS: pre-CPI lamports snapshot taken and achecked_subpost-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
assignmid-CPI to steal an account's owner. After any CPI touching a relied-upon account, the caller re-assertsaccount.owner == expected. (PASS: owner re-checked after the CPI — Anchor.reload()covers ONLY accounts Anchor itself reloads, so native/Pinocchio/raw-invokepaths 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 withexit(&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:
- Unexpected account kind: uninitialized, owned by another program, executable, Token-2022 where SPL Token was assumed?
- 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?
- Zero / max / empty:
amount == 0,u64::MAX, emptyremaining_accounts, emptyVec, zero-length seed string. - 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.
- Sentinel flowing into an SPL operation (
NATIVE_MINTintotransfer_checked, a lamport path receiving a real mint)? - 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?
- 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).