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-vectors026-pda-seed-collision.md

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

26 — PDA Seed Collision

Severity: 8 | Real: Solana PDA confusion exploits

Two different logical accounts derive to the same PDA because seeds overlap — attacker exploits the collision.

Verification Procedure

Step 1: Catalog all PDA seed patterns

grep -rn --include="*.rs" "seeds = \[" programs/*/src/instructions/
  • Record: Every seed pattern with its account type

Step 2: Seed-concatenation analysis (per program id) PDA derivation hashes seed_0 ‖ seed_1 ‖ … ‖ bump ‖ program_id ‖ "ProgramDerivedAddress" with no separators or length prefixes. Write each PDA type as segments: L(bytes) literal, F(n) fixed width (Pubkey F(32), u64.to_le_bytes() F(8)), V(0..=32) variable/user-controlled. For every pair of types (A, B), including A with itself:

  • aligned literal-vs-literal bytes must agree for a collision; aligned literal-vs-F bytes are satisfiable when that F value is attacker-chosen (an arbitrary non-signer pubkey, a u64 argument);
  • any V segment: can an attacker choose its bytes so the concatenations match? (A Borsh String must be valid UTF-8, so embedding a random victim pubkey is usually impossible; Vec<u8>/[u8; N] have no such limit.)
  • self-collision: two adjacent V segments (("ab","c") vs ("a","bc")) map two entities to one PDA.
rg -n -A1 'seeds\s*=\s*\[' programs/ | rg 'seeds|Account<|AccountLoader<|UncheckedAccount'
rg -n 'seeds\s*=\s*\[\s*[a-z_]+(\.|\s*,)' programs/                       # first seed not a literal
rg -n '#\[instruction\(.*(String|Vec<u8>|&\[u8\])' programs/
  • ✅ PASS: each account type has its own distinct literal first seed, no literal is a byte-prefix of another, and every variable-length seed is last, length-delimited, or hashed to 32 bytes
  • ❌ FAIL: a seeds list without a literal domain prefix, overlapping literals (b"user" vs b"user_stats" followed by a variable seed), or adjacent variable segments with no delimiter

Step 3: Grade by attacker control of the overlapping bytes

  • Squatting only (attacker inits type A at the address a victim's type-B init needs): Low/Medium DoS.
  • Same-type collision (two logical entities of one account type map to one PDA, e.g. the adjacent-V self-collision above): no discriminator or owner check can tell them apart, so grade by what the second entity can do with the first one's account (often High/Critical when it holds funds or authority).
  • Cross-type collision: High/Critical only if a read path skips the discriminator/owner type check (KV-010/027) and the attacker controls the overlapping bytes. A structurally unsafe layout whose overlap needs a victim's key to be valid UTF-8 is "structurally unsafe", not exploitable.
  • Not a finding: distinct literal + fixed-width keys ([b"vault", pool.key()]); PDAs of different program ids (the id is hashed).

Sources: Zellic "The Vulnerabilities You'll Write With Anchor" [paraphrased, cited: https://www.zellic.io/blog/the-vulnerabilities-youll-write-with-anchor].

Step 4: Check bump seed handling

grep -rn --include="*.rs" "bump" programs/*/src/instructions/
  • ✅ PASS: Stored bump is reused via bump = entity.bump (consistent derivation)
  • ⚠️ PARTIAL: Bump re-derived each time (wastes CU but not a security issue)
  • ❌ FAIL: Bump not stored and find_program_address used in instruction (potential inconsistency)

Overall verdict:

  • ✅: Unique prefixes, sufficient variable seeds, stored bumps
  • ⚠️: Unique seeds but bumps re-derived
  • ❌: Shared seed prefixes or insufficient seeds allowing collision

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