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-vectors012-arithmetic-rounding-exploit.md

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

12 — Arithmetic Rounding Exploit

Severity: 7 | Real: Multiple DeFi rounding exploits, share price manipulation

Division-before-multiplication loses precision — attacker extracts dust per share across millions of operations.

Verification Procedure

Step 1: Find all division operations

grep -rn --include="*.rs" "checked_div\|/ " programs/*/src/instructions/
  • Record: Every division with context

Step 2: Verify multiplication-before-division order

# For each share/price/fee calculation, verify: (a * b) / c, NOT a * (b / c)
# Read the actual code for each financial formula
  • ✅ PASS: Every formula multiplies first, divides last
  • ❌ FAIL: Any formula where division happens before final multiplication (precision loss)

Step 3: Check for rounding direction consistency

# Deposits: round DOWN (fewer shares — favors vault)
# Withdrawals: round DOWN (less assets — favors vault)  
# Fee calculations: round UP (more fees — favors protocol)
  • ✅ PASS: All rounding consistently favors the protocol/vault
  • ❌ FAIL: Any calculation where rounding favors the user (extractable value)

Step 4: Check for u128 intermediate calculations

grep -rn --include="*.rs" "as u128\|u128::from" programs/*/src/instructions/
  • ✅ PASS: Multiplications that could overflow u64 use u128 intermediates
  • ❌ FAIL: Two u64 values multiplied without widening first

Step 5: Round-to-nearest helpers on value paths

rg -n 'try_round_u(64|128)|\.round\(\)|round_half|RoundingMode::(Nearest|HalfUp|HalfEven)|\+ *HALF_WAD|to_imprecise\(' programs/
  • ❌ FAIL: nearest/half-up rounding on any user-value conversion (Neodyme SPL token-lending disclosure: a deposit→redeem round trip returned n+1; fixed by replacing round with floor)
  • Size it as unit value × round trips per transaction (compute-bound when an attacker program loops CPIs) × transactions (AR-071)

Sources: sannykim/solsec → https://neodyme.io/blog/lending_disclosure [paraphrased, cited]; SlowMist best practices README.md "Loss of precision" [https://github.com/slowmist/solana-smart-contract-security-best-practices] (Apache-2.0, attributed to SlowMist).

Overall verdict:

  • ✅: Mul-before-div, consistent rounding direction favoring vault, u128 intermediates
  • ⚠️: Correct order but missing u128 on some calculations
  • ❌: Division before multiplication in financial formulas

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