LLMSkillHub
mirroredCopied from PlamenTSV/plamen under MIT. PlamenTSV has not claimed this page, and is not affiliated with LLM SkillHub.

plamentsv / token-2022-extensions

Trigger Pattern TOKEN_2022 flag detected (token_2022/spl_token_2022/transfer_checked usage) - Inject Into Breadth agents, depth agents

0
SKILL.md
5.7 KB

TOKEN2022EXTENSIONS Skill

Trigger Pattern: TOKEN2022 flag detected (token2022/spltoken2022/transfer_checked usage)
Inject Into: Breadth agents, depth agents
Finding prefix: [T22-N]
Rules referenced: S9, R3, R11

For every token mint the program interacts with that may use Token-2022:

1. Extension Inventory

For each mint:

MintToken ProgramExtensions DetectedExtension Impact
{mint}token / token-2022{list: TransferFee, TransferHook, PermanentDelegate, MintCloseAuthority, DefaultAccountState, etc.}{brief per-extension impact}

Detection: Check if program uses spl_token_2022 or token_2022 imports. Check mint account data length (Token-2022 mints are larger due to extension data).

2. Extension Allowlist

Does the program explicitly check which extensions are supported?

CheckPresent?LocationMissing Extensions Handled?
Extension allowlist / blocklistYES/NO{line}{what happens with unsupported extension}

Attack (S9): Program designed for basic SPL Token interacts with Token-2022 mint that has unexpected extensions (e.g., PermanentDelegate). Program doesn't check → extension silently affects behavior.
Defense: Explicitly check mint extensions and reject unsupported ones.

3. Permanent Delegate Risk

For each mint with PermanentDelegate extension:

MintPermanent DelegateTrust LevelVault Drain ScenarioMitigation
{mint}{delegate pubkey}{trusted/untrusted/unknown}{can delegate drain vault?}{what prevents it}

Attack: Permanent delegate can transfer tokens FROM any token account of that mint, without the account owner's approval. If protocol holds tokens of a PermanentDelegate mint → delegate can drain them at any time.

4. Transfer Hook Analysis

For each mint with TransferHook extension:

MintHook ProgramHook Verified?CU Budget ImpactRecursion Risk?
{mint}{program_id}YES/NO{estimated CU}YES/NO

Risks:

  • Hook program can consume significant CU, causing transactions to fail
  • Hook program can revert, blocking all transfers of this token
  • Hook program may have its own CPI chain, adding depth
  • Hook may read additional accounts not provided by the caller

5. Transfer Fee Accounting

For each mint with TransferFeeConfig:

MintFee RateFee Accounted in Protocol Math?Amount Received < Amount Sent?
{mint}{bps}YES/NO{if NO: accounting mismatch}

Attack: Protocol calculates expected amounts without deducting transfer fee → accounting mismatch, potential insolvency.
Pattern: transfer_checked returns the gross amount. The net amount received is gross - fee. Protocol must use net amount in accounting.

6. CPI Guard Handling

For transfers through delegation (CPI transfers):

Transfer TypeUses CPI?CPI Guard Enabled on Mint?Transfer Works?
{type}YES/NOYES/NO/Unknown{if CPI Guard + delegation: may fail}

CPI Guard: When enabled, prevents token account delegates from transferring via CPI. Programs that rely on delegated transfers via CPI will fail silently.

7. Default Account State

For mints with DefaultAccountState extension:

MintDefault StateProtocol Handles Frozen?Impact
{mint}Frozen / InitializedYES/NO{if frozen: new token accounts start frozen, need thaw}

8. Mint Existence Verification (MintCloseAuthority)

For mints with MintCloseAuthority extension:

MintClose AuthorityChecked Before Read?Impact if Mint Closed
{mint}{authority}YES/NO{if NO: reading zeroed data, incorrect decimals/supply}

Attack: Mint with MintCloseAuthority can be closed (if supply == 0). Protocol reads closed mint → gets zeroed data → decimals = 0, incorrect calculations.

Finding Template

**ID**: [T22-N]
**Severity**: [PermanentDelegate drain = Critical, transfer fee mismatch = High, CPI Guard = Medium]
**Step Execution**: ✓1,2,3,4,5,6,7,8 | ✗(reasons) | ?(uncertain)
**Rules Applied**: [S9:✓, R3:✓, R11:✓/✗]
**Location**: program/src/{file}.rs:LineN
**Title**: Token-2022 [extension] in [context] enables [attack]
**Description**: [Specific extension vulnerability with data flow]
**Impact**: [Fund drain / accounting mismatch / DoS]

Step Execution Checklist (MANDATORY)

SectionRequiredCompleted?Notes
1. Extension InventoryYES✓/✗/?For every mint
2. Extension AllowlistYES✓/✗/?Explicit check present?
3. Permanent Delegate RiskIF PermanentDelegate✓/✗(N/A)/?Vault drain scenario
4. Transfer Hook AnalysisIF TransferHook✓/✗(N/A)/?CU + revert risk
5. Transfer Fee AccountingIF TransferFee✓/✗(N/A)/?Net vs gross
6. CPI Guard HandlingIF delegated CPI transfers✓/✗(N/A)/?Delegation + CPI Guard
7. Default Account StateIF DefaultAccountState✓/✗(N/A)/?Frozen by default
8. Mint Existence VerificationIF MintCloseAuthority✓/✗(N/A)/?Closed mint reads