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-vectors128-onchain-floating-point-math.md

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

128 — On-Chain Floating-Point Financial Math

Severity: 5 | Real: Sec3 Huma (powf), Sec3/Carrot f64 exchange rate, Neodyme Streamflow, Halborn Token-2022 f64↔u64 cast

Using f64/f32 in on-chain value computation is unsafe on several independent axes, and auditors keep finding it in fee, interest, exchange-rate, and price math:

  • Non-deterministic rounding. IEEE-754 results depend on evaluation order and can differ across compiler versions / build flags / target math implementations. Two nodes (or a re-audit build) computing the "same" value may round differently, and value that should be conserved is silently created or destroyed.
  • Precision loss at scale. f64 has 52 bits of mantissa; token amounts routinely exceed 2^53. Large balances lose low-order units, so fees/shares/interest computed in float quietly diverge from the true integer amount — exploitable as dust accumulation or as a rounding edge that favors the attacker.
  • Lossy boundary casts. f64 → u64 truncates toward zero (or saturates), and u64 → f64 loses precision on the way in. Every crossing of that boundary in a value path is a place where amounts change unexpectedly.
  • CU blowup. Transcendental ops (powf, powi, sqrt, ln, exp) are expensive and variable-cost on BPF, risking compute-budget exhaustion (see KV-025) and making CU non-deterministic.

The correct approach is fixed-point representation (scaled integers / basis points / a fixed-point crate) with checked integer arithmetic and u128 widening for intermediate a * b / c products — never floating point.

Off-chain code (clients, indexers, display) may use floats freely; this vector is specifically about float entering on-chain value/price/fee/rate computation.

Verification Procedure

Step 1: Find floating-point types and ops in program source

grep -rn --include="*.rs" -E "\bf64\b|\bf32\b|as f64|as f32|\.powf|\.powi|\.sqrt|\.ln\(|\.exp\(|\.floor\(|\.ceil\(|\.round\(" programs/*/src/
  • Record every hit and identify whether it feeds a value, price, fee, interest, exchange-rate, share, or reward computation

Step 2: Classify each usage

grep -rn --include="*.rs" -iE "price|fee|rate|interest|exchange|amount|share|reward|balance|swap|collateral" programs/*/src/
  • ✅ PASS: no float appears in any value path — all financial math uses scaled integers / fixed-point with checked_* and u128 intermediates
  • ❌ FAIL: f64/f32/powf/sqrt/as f64 computes or scales a monetary value (non-deterministic rounding + precision loss + lossy cast)

Step 3: Inspect every f64 ↔ u64 (or f32 ↔ u32) boundary in a value path

  • For each cast crossing float↔integer, confirm it is not on a monetary quantity; a cast on an amount is a finding on its own (truncation/saturation changes the value)
  • ✅ PASS: no float↔integer cast occurs on a value; conversions are integer-only with explicit rounding direction chosen in the protocol's favor
  • ❌ FAIL: a token amount / fee / rate crosses the float↔integer boundary

Overall verdict:

  • ✅: On-chain financial math is entirely fixed-point + checked integers; no f64/f32/transcendental ops or float↔integer casts in any value path
  • ⚠️: Float appears only in a clearly non-value context (e.g., a log/metric) but sits close to value code and risks future misuse
  • ❌: Any on-chain value, price, fee, interest, or exchange-rate is computed or cast through floating point
  • N/A: Program performs no value/price/fee/rate computation

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