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.

known-vectors106-account-revival-zombie-after-close.md

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

106 — Account Revival / Zombie After Close

Severity: 8 | Real: Solana close-account revival class (incomplete close → reuse of stale state)

Closing an account safely requires, in the same instruction: transfer ALL lamports out, assign the account to the System Program, and resize/realloc(0) — modern Anchor close = dst does exactly this (since 0.26.0; the CLOSED_ACCOUNT_DISCRIMINATOR constant was removed in 0.30.0; FP-2). Older Anchor (sentinel era, ≤ 0.25) wrote [255;8] and left the owner unchanged. <!-- verified: anchor v0.25.0 vs v0.26.0 lang/src/common.rs close(); CLOSED_ACCOUNT_DISCRIMINATOR present in v0.29.0 lang/src/lib.rs, absent in v0.30.0 --> An incomplete close — manual lamport transfer without reassigning the owner and truncating the data, or leaving the account funded above rent-exemption — leaves a "zombie": the account still exists and can be deserialized later in the same transaction (or refunded by an attacker to survive GC), exposing stale balances/positions. Combined with init_if_needed, a closed account can be "revived" with attacker-favorable stale data.

Verification Procedure

Step 1: Find all account closes

grep -rn --include="*.rs" -E "close = |close_account|\.close\(|CLOSED_ACCOUNT_DISCRIMINATOR|\*\*lamports|try_borrow_mut_lamports" programs/
  • Separate Anchor close = dest (safe) from manual lamport-draining closes (review each)

Step 2: Manual closes do all three steps

rg -n '\*\*\s*[A-Za-z_][\w.()]*\.lamports\.borrow_mut\(\)\s*=\s*0\b|try_borrow_mut_lamports|sub_lamports\(|set_lamports\(0\)' programs/
rg -n '\.assign\(|resize\(0|realloc\(0|CLOSED_ACCOUNT_DISCRIMINATOR|force_defund' programs/
  • ✅ PASS: drain + assign(&system_program::ID) + resize(0) in one instruction, dst != acct; on sentinel-era code, a permissionless defund path exists for sentinel-marked accounts
  • ❌ FAIL: lamports drained (or data zero-filled) but owner left as the program — a refunded account survives as program-owned; if any instruction initializes that type via #[account(zero)], the zero-filled account is re-initializable with attacker fields (KV-142)

Step 3: No stale access after close in the same transaction

grep -rn --include="*.rs" -E "init_if_needed" programs/
  • ✅ PASS: A closed account cannot be re-read or init_if_needed-revived with stale fields later in the tx
  • ❌ FAIL: Subsequent instruction/CPI can read or re-init the closed account

Step 4: Revival via lamport refund

  • For PDAs that gate a one-time action (claims, withdrawals): confirm that re-funding the closed address with lamports cannot resurrect stale "unclaimed" state
  • ✅ PASS: State is re-derived/re-checked against authoritative source; refund cannot revive a claim
  • ❌ FAIL: Re-funded address re-enables a completed action

Step 5: Closed markers and families

  • ❌ FAIL: a one-shot marker PDA (claim receipt, nonce, vote record) is closed rather than kept, with seeds the same user can re-derive — init re-creates it with default fields and re-enables the action ("a closed marker equals an absent marker")
  • ❌ FAIL: other state still references the closed account by key, or children seeded by it revive when the parent is re-created (KV-175)
  • PoC: one transaction [claim_and_close(entry), system_transfer(attacker → entry, rent)], then try the re-creation path separately

Sources: coral-xyz/sealevel-attacks (repo programs/9-closing-accounts), crytic/solana-lints lints/insecure_account_close, Solana Foundation course content/courses/program-security/closing-accounts.md [paraphrased, cited]; qedgen/solana-skills skills/qedgen-auditor/references/known-non-findings.md Anchor close entry (MIT, Copyright (c) 2025 QEDGen); Sealevel Sentinel (stantheman0128/sealevel-sentinel) src/detectors/closing-accounts.ts (MIT, Copyright (c) 2026 Stan (stantheman0128)); workersio/skills plugins/solana-audit/skills/solana-audit/references/account-closure-vulnerability.md (PR #9 tree, MIT, Copyright (c) 2026 workers.io), version facts corrected against otter-sec/anchor CHANGELOG #2169, #2726.

Overall verdict:

  • ✅: All closes use Anchor close or a complete manual pattern (fully drained + assigned to System + resized to 0); no stale re-read/re-init
  • ⚠️: Closes are safe but init_if_needed present without a revival guard
  • ❌: Manual close leaves deserializable data, or refund can revive stale state
  • N/A: Program never closes accounts

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