Skip to content
KhomDevPublic

About

Rugproof: from Rust basics to code that can't be rugged. A free Solana security path in 5 guides: Rust, accounts & PDAs, Anchor internals, auditing, and real exploits (Wormhole, Cashio, Mango…) with vulnerable-vs-fixed code.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Rugproof: Rust → Solana → Exploits

Rugproof

From Rust basics to code that can't be rugged.
A free, open Solana security path in five guides: Rust, the Solana account model, Anchor, auditing, and real-world exploits.

CI Code: MIT Text: CC BY 4.0

Animated terminal banner: cargo run --bin rugproof


Most Solana security material assumes you already read Rust fluently and already think in accounts, signers and PDAs. Rugproof doesn't. It starts with the Rust you actually need, shows every Solana concept as the code it really is, takes Anchor apart macro by macro, walks into the Agave runtime, and ends with the bug classes and real incidents behind most Solana losses.

One rule runs through all five guides: if a check isn't written somewhere, it doesn't exist. You learn to find where each check lives, or to prove that it's missing.

The path

flowchart LR
    R["00 · Rust Fundamentals<br/>+ cargo exercises"] --> A["01 · Solana Foundations<br/>account model as code"]
    A --> B["02 · Anchor Deep-Dive<br/>what every macro generates"]
    B --> C["03 · Security Deep-Dive<br/>core programs, verification, runtime"]
    C --> D["04 · Advanced Security<br/>bug classes + incidents + capstone"]
Loading

Each idea has one home. Later guides link back instead of teaching it again. 00 is Rust and Rust-level security. 01 is the account model as code, a native program, a first Anchor port, tokens, and the proof-of-check test pattern. 02 is Anchor. 03 is runtime invariants, the core programs, read-only verification (explorers and the CLI), CPI privilege flow, reading live protocols, and Agave. 04 is the bug-class catalogue, sourced incidents, the full audit checklist, and a capstone due-diligence report.

Every guide starts with a Prerequisites / This file covers / This file does not cover block and ends with previous/next links, so you can always see where you are.

# Guide This file covers — you'll be able to… Suggested time
00 Rust Fundamentals for Solana Developers Read and write the Rust Solana code relies on: ownership, lifetimes, traits, Result + thiserror, iterators, Rc<RefCell<…>>, Borsh. Then the Rust security lens: overflow, panics as DoS, truncating casts, rounding, decoder bugs, SBF limits, unsafe, supply chain, security clippy lints, property tests and fuzzing. Graded Cargo exercises, plus spot-the-red-flag drills 1–2 weeks
01 Solana Foundations: Rust and Solana Concepts in Code See transactions, accounts and PDAs as structs (Rust itself stays in 00); write a native vault by hand; port it to Anchor; write your first proof-of-check test in LiteSVM; practise a first read-only look at official programs 4–6 weeks with exercises
02 Anchor Framework Deep-Dive Read an Anchor program as the code it expands into: instruction lifecycle, every account type and constraint, CPIs, zero-copy, Token-2022, IDLs, 14 Anchor-specific bug patterns. Eight exercises, from a red-flag Accounts struct to a staking pool 2–3 weeks
03 Solana Security Deep-Dive: From Account Model to Agave Runtime Recite the runtime's account-model invariants; know what the core programs check and what they don't; verify upgrade authority, mint/freeze/fee/hook switches and LP holders with explorers and the CLI; trace privilege flow through CPIs; read an AMM, a lending market and a perp DEX; follow a transaction through Agave. Eight exercises 8–12 weeks
04 Advanced Solana Security and Real-World Exploits Spot 16 bug classes with a short, annotated vulnerable snippet next to the fix; explain Wormhole, Cashio, Crema, Nirvana, Mango, Solend, Raydium, Slope and Loopscale in account-model terms (every figure sourced); run the full audit checklist; write a capstone due-diligence report 2–4 weeks

Already fluent in Rust? Skim 00 and do its Level 3–4 exercises. Already shipping Anchor programs? Start at 03, then 04.

Who it's for

  • Developers moving from EVM to Solana who want to think like an auditor
  • Bug-bounty hunters and auditors who keep missing Solana findings because the account model doesn't feel native yet
  • Rust beginners who want Solana as their first serious project
  • Solana developers who want to stop shipping the bugs in guide 04

Run the exercises

Every guide has a clearly headed Exercises section (eight graded items in 02–04; 00 and 01 have a longer levelled set). Hints and answers are in collapsible blocks. Every guide also ships a runnable Cargo workspace in exercises/: practice functions with a deep test suite (unit, property-based, adversarial, integration), plus a capstone where you spot the bug and then fix it.

Guide In the guide Runnable workspace Capstone (two planted bugs each)
00 14. Exercises: fill in a real crate, spot red flags 00-rust-fundamentals Points ledger: wrapping arithmetic, truncating cast
01 Exercises: account model, official programs, native vault, Anchor port 01-solana-foundations Treasury: missing signer check, missing owner check
02 Exercises: incomplete Accounts struct, staking pool 02-anchor-deep-dive Airdrop: non-canonical PDA bump, missing has_one
03 Exercises: core-program invariants, explorer checks, pool audit 03-solana-security-deep-dive Share vault: arbitrary CPI, substituted token account
04 Exercises: incident quiz, token checklist, due-diligence report 04-advanced-security-and-exploits Lending market: spot-price oracle, limit ignores existing debt

The workspaces need only Rust. This repo pins 1.95.0 in rust-toolchain.toml (rustup installs it when you enter the directory; leave your global rustup default alone). No validator, wallet or network:

git clone https://github.com/KhomDev/rugproof.git
cd rugproof/exercises/01-solana-foundations   # or any 0N-* folder

cargo test -p starter            # your work: fails until you replace the todo!()s
cargo test -p starter l1_        # one level at a time
cargo test -p solutions          # reference answers: all green
cargo test -p capstone           # exploit_* tests fail until you find and fix the bugs
cargo test -p capstone-solution  # the patched capstone: all green

The stubs you fill in are in starter/src/lib.rs. The full test suite is in starter/tests/exercises.rs and the same tests run against solutions/, so a green starter means your answers hold up against the same attacks as the reference ones. cargo test from inside starter/ or solutions/ also works. In each capstone, every exploit_* test plays the attacker locally against a toy program, and CI checks that each one really fails on the flawed version.

Windows setup

Rust 1.85+ is required because some crates.io dependencies use edition 2024. A global rustup default of 1.79 will fail to parse those manifests; the pinned rust-toolchain.toml is what selects 1.95.0 in this repo.

Pick one linker. You do not need both.

  • Visual Studio Build Tools (the usual MSVC target): install Build Tools with the Desktop development with C++ workload so link.exe is on the path. Then cargo test uses the default x86_64-pc-windows-msvc host.

  • No Visual Studio: install MSYS2 and the UCRT64 toolchain (pacman -S mingw-w64-ucrt-x86_64-gcc). Add C:\msys64\ucrt64\bin to your User PATH (so gcc and dlltool are visible in a new PowerShell window), then in this clone only:

    rustup toolchain install 1.95.0-x86_64-pc-windows-gnu
    rustup override set 1.95.0-x86_64-pc-windows-gnu

    The override is local to this checkout and is not committed. Open a new terminal after changing PATH.

Guides 01–04 also tell you what to install (Solana/Agave CLI, Anchor, LiteSVM) when a task needs the real toolchain. Vulnerable snippets are for detection: don't deploy them. Only run tests against programs you wrote, or against public educational repos the guide names.

How to read the confidence tags

Guides 01–03 tag claims so you know how much to trust them:

  • [Certain]: spec-level, or read directly in the source
  • [Likely]: strong evidence, but may drift between versions
  • [Guessing]: the author's inference; verify before relying on it

Solana moves fast. These guides track Anchor 1.x (with notes on 0.29–0.32), Agave master and the p-token Token program as of November 2026. Always check the version your target actually uses (Cargo.lock, feature gates) before writing a finding.

Contributing

Found an error, a broken example, or something out of date? Issues and PRs are welcome. See CONTRIBUTING.md. Corrections with a source link (docs page, source line, SIMD, post-mortem) get merged fastest.

License

  • Guide text (the .md guides and images): CC BY 4.0. Share and adapt with attribution.
  • Code (exercises, workflows and code snippets): MIT.

This split keeps the code freely reusable in any project while asking for credit when the writing is reused.

Disclaimer

Rugproof is educational material. It is not an audit, not legal or financial advice, and no guarantee that code following it is secure. Vulnerable examples are deliberately broken: don't deploy them. Only test exploits against code you own or programs whose bug-bounty terms allow it. Incident write-ups summarize the cited public sources; where a source reports allegations (for example a regulator's complaint), the guide says so.

Credits

Written by KhomDev, with AI assistance for research and drafting; every incident fact is checked against the linked source.

Built on the work of the Solana, Anza, Anchor and audit communities, especially sealevel-attacks, the Anchor docs, the Agave source, and the security teams whose public post-mortems and analyses are cited in guide 04.

About

Rugproof: from Rust basics to code that can't be rugged. A free Solana security path in 5 guides: Rust, accounts & PDAs, Anchor internals, auditing, and real exploits (Wormhole, Cashio, Mango…) with vulnerable-vs-fixed code.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages