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-vectors014-account-reinitialization.md

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

14 — Account Reinitialization

Severity: 8 | Real: Multiple Solana programs overwritten by reinit

Account can be initialized twice — attacker overwrites legitimate data.

Verification Procedure

Step 1: Find all account initialization

grep -rn --include="*.rs" "init,\|init_if_needed" programs/*/src/instructions/
  • Record: Every init account

Step 2: Check for init_if_needed (dangerous)

grep -rn --include="*.rs" "init_if_needed" programs/*/src/instructions/
  • ✅ PASS: Zero uses of init_if_needed
  • ⚠️ PARTIAL: init_if_needed used but with additional validation (checked that re-initializing is safe behavior)
  • ❌ FAIL: init_if_needed used without checking if the data would be overwritten

Step 3: Verify init constraint prevents reinit

# Anchor's init constraint automatically prevents reinitialization
# Verify all state accounts use `init` (not manual init)
grep -rn --include="*.rs" "#\[account(init" programs/*/src/instructions/
  • ✅ PASS: All accounts use Anchor's init constraint (automatic reinit prevention)
  • ❌ FAIL: Manual initialization without checking if account already exists

Step 4: Check for manual AccountInfo initialization

grep -rn --include="*.rs" "serialize\|try_borrow_mut_data\|data\.borrow_mut" programs/*/src/instructions/
  • If found: verify there's a check that the account is empty/uninitialized before writing
  • ✅ PASS: Manual initialization checks that the type tag / is_initialized flag / all discriminator bytes are still zero before the write, sets the flag in the same write, and the owner is this program; for client-allocated accounts use #[account(zero)] (with signer or same-transaction creation — KV-142). data_len() == 0 is valid only as an existence check when the handler itself creates the account by CPI.
  • ❌ FAIL: guard uses data_len() == 0 on a pre-allocated account; guard polarity is inverted (if !state.is_initialized { return Err } blocks the first init and permits re-init); flag never set; only a "second call fails" test exists (FV-098)

Sources: coral-xyz/sealevel-attacks (repo programs/4-initialization) [paraphrased, cited]; sannykim/solsec → Solens and JonLu Candy Machine write-ups [paraphrased, cited: https://medium.com/@solens_io/smashing-the-candy-machine-for-fun-and-profit-a3bcc58d6c30 , https://jonlu.ca/posts/candy-machine].

Overall verdict:

  • ✅: All init uses Anchor init constraint, no init_if_needed, no manual serialization
  • ⚠️: Some init_if_needed with adequate safeguards
  • ❌: Accounts can be reinitialized, overwriting existing data

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