22 — Token-2022 Checklist (integrator and transfer-hook author)
Domain: On-chain Solana Program Severity if missed: HIGH References: references/methodologies/token-2022.md; Neodyme Token-2022 article and audit (cited, paraphrased); solana-foundation/solana-dev-skill (MIT); beriktassuly/solana-audit-skill (MIT) Load when:
token_2022·spl_token_2022·TokenInterface·InterfaceAccount·transfer_hook·spl_transfer_hook_interfaceComplements (does not repeat) T1–T12 in token-2022.md and EXT-012..015 in checklist 04.
Every item below is a single verification step. Mark each [PASS], [FAIL-{severity}], [PARTIAL], or [N/A].
22.1 — Policy & combinations
- TK-001: Every extension that can affect value, authority, liveness, display or close behaviour has exactly one policy — supported / rejected / residual risk — with evidence and residual-risk columns (token-2022.md §13).
- TK-002: Fee + hook on the same transfer is handled (delta accounting and hook rules); no code assumes TransferHook × TransferFee is impossible (token-2022.md §3).
- TK-003: "Pay exactly X net" paths use the inverse-fee helper (
calculate_inverse_epoch_fee) andtransfer_checked_with_feeas an assertion, notcalculate_fee(x)added to x. - TK-004: Fees are computed at use time from
get_epoch_fee(Clock::get()?.epoch); no cached bps, no direct read ofnewer_transfer_fee; quote-to-settle paths carry slippage bounds.
22.2 — CPI Guard
- TK-005: User-funded pulls work for users with CPI Guard enabled: the user signs a top-level
Approveto a program PDA, the program transfers as delegate and verifies the delta; no flow forwards the owner's signature into a Token-2022 transfer/burn CPI. - TK-006: Protocol vaults use
ImmutableOwner; no requirement relies on CPI Guard on PDA-owned vaults (a PDA cannot enable it). - TK-007: No security argument relies on CPI Guard against a Token-2022 build older than the ND-ANZ-LO-01 fix (an owner that approved itself as delegate,
Approve(delegate = owner), bypassed the guard), e.g. vendored binaries in test validators or forks; current Token-2022 rejects owner-signed transfers in CPI even when the owner is also the delegate or permanent delegate. <!-- verified: token-2022 HEAD program/src/processor.rs (CpiGuardTransferBlocked when the authority is the owner, lock_cpi and in_cpi) -->
22.3 — Close paths & payouts
- TK-008: Before closing a token account of a fee mint, withheld fees are harvested (
anchor_spl::token_2022_extensions::harvest_withheld_tokens_to_mintor thespl_token_2022_interface::extension::transfer_fee::instruction::harvest_withheld_tokens_to_mintbuilder, also reachable asspl_token_2022::extension::transfer_fee::instruction::…in the program crate), or the close is best-effort / a separate crank (KV-168). <!-- verified: anchor v1.2.1 spl/src/token_2022_extensions/{mod.rs,transfer_fee.rs}; token-2022 HEAD interface/src/extension/transfer_fee/mod.rs `TransferFeeAmount::closable` --> - TK-009: Close paths handle non-zero
ConfidentialTransferAccountpending/available balances andConfidentialTransferFeeAmount(each has aclosable()check); the confidential withheld-fee harvest to the mint can be turned off by the confidential fee authority (DisableHarvestToMintsetsharvest_to_mint_enabled = false, and the harvest then fails withHarvestToMintDisabled), so a close path must not depend on that harvest. <!-- verified: token-2022 HEAD program/src/extension/confidential_transfer_fee/processor.rs --> - TK-010: Closes sweep the live balance after
reload()withtransfer_checked(not a recorded amount, not uncheckedtransfer, which Token-2022 rejects withMintRequiredForTransferwhenever the source carriesTransferFeeAmount,TransferHookAccountorPausableAccount). <!-- verified: token-2022 HEAD program/src/processor.rs process_transfer, no-mint branch --> - TK-011: Payouts to user accounts are pull-based; where push is unavoidable, a Memo CPI immediately precedes each transfer to a
MemoTransferdestination (same stack height). - TK-012: No batch distribution/settlement/liquidation pushes to N recipient-controlled accounts in one instruction (KV-169).
22.4 — Mint lifecycle & identity
- TK-013: Mints with
MintCloseAuthorityare refused, or every use checks account-vs-mint extension consistency and the vault is program-created at a PDA (KV-166). - TK-014: A mint-registry fingerprint (if used) hashes
u16::from(ext)values (ExtensionTypeis#[repr(u16)]withIntoPrimitive) excludingTokenMetadata/TokenGroup/TokenGroupMember, includes rotatable authority keys (hook program id, permanent delegate, freeze authority), and is re-validated on every deposit/swap/transfer path. - TK-015: The
TransferHook.program_idis re-checked against the allowlist on every transfer path, not only at registration (the hook authority can swap it). - TK-016: A later
DefaultAccountState::UpdatetoFrozen(freeze authority) is handled: vault/recipient accounts created afterwards start frozen, surfaced as a clean error (T5). - TK-017: Token account vs mint vs multisig are classified by typed unpack after the owner check, never by length (
165/82/355; a T22 length that would equal 355 is padded by 2 bytes,size_of::<ExtensionType>());PodStateWithExtensions/StateWithExtensionsunpack errors are handled, notunwrap()ed (error clarity). - TK-018: Protocols that tolerate permanent-delegate mints reconcile stored totals with balances and handle
vault.amount < recorded_totaland== 0without division by zero, underflow or socialising one user's loss onto others. - TK-019: Confidential receive paths tolerate
MaximumPendingBalanceCreditCounterExceeded; owners/keepers apply pending balances on a schedule; settlement does not require pushing confidential credits into adversary-saturable accounts. <!-- verified: token-2022 HEAD interface/src/error.rs `MaximumPendingBalanceCreditCounterExceeded` --> - TK-020: Automated apply-then-withdraw confidential flows batch or delay so single credits are not linkable, or the privacy limitation is documented.
- TK-021: Pushes tolerate recipients that disabled confidential or non-confidential credits (
DisableConfidentialCredits/DisableNonConfidentialCredits). - TK-022: Accounts lacking an account extension the current mint requires (
TransferHookAccount,TransferFeeAmount,PausableAccount) are rejected before value moves: an orphan source can use the mint-lessTransferinstruction to skip fee, hook and pause, because Token-2022 decides whether the mint is required from the source account's extensions (KV-166). - TK-023: For
Pausablemints, pause guarantees are not assumed to cover pre-existing accounts withoutPausableAccount. - TK-024: The negative-test set exists: wrong token program variant; unsupported extension mix; fee mint with net < requested; hook mint with an unapproved hook; memo-required destination without memo; default-frozen source/destination; permanent delegate present; close with withheld fees present — each proving rejection before state mutation.
22.5 — If the audited program IS a transfer hook (KV-167)
- HOOK-01: The mint is one the hook serves, validated against config in a PDA keyed by the mint.
- HOOK-02: Source and destination have
TransferHookAccount.transferring == true, read viaStateWithExtensions::<Account>::unpack+get_extension::<TransferHookAccount>(), and are owned by Token-2022. - HOOK-03:
source.mint == destination.mint == mint. - HOOK-04 (optional, trade-off): the top-level instruction is Token-2022 (
get_instruction_relative(0, ..), sysvar address-pinned) — rejects all composable transfers; documented if used. - HOOK-05: The extra-account-metas PDA is
[b"extra-account-metas", mint]under the hook program; only the intended authority can initialise/update it; every trusted extra account is re-validated (owner, seeds, discriminator), never trusted by position. - HOOK-06: No privilege assumptions: the four core accounts arrive read-only and non-signer; extras keep the
is_signer/is_writableset in theirExtraAccountMeta; a hook that always errors bricks the mint, and the hook authority can swap programs.