← Articles
Lean 4 for Solana: what formal verification gives you that tests and audits don't logo
solana

Lean 4 for Solana: what formal verification gives you that tests and audits don't

· NOV 27, 2026 ·
Read
Share
LinkedIn

Tests check the inputs you thought of. Audits check what a reviewer has time to read. A proof checks every input. Here is what Lean 4 can and cannot do for a Solana program today, who is building the tooling (all of it new and unaudited), and a five-step path a small team can follow without a research lab.

devrels.xyz/a/408

Tests check the inputs you thought of. Audits check what a reviewer has time to read. A proof checks every input. That is the pitch for formal verification, and it is why a handful of Solana teams started using the Lean 4 proof assistant this year.

This article covers what Lean is, what already exists for Solana, what a small team can realistically prove, and where the trust gaps stay open. Most of the work below is new, experimental and unaudited. Read it as a map of early work, not a set of recommendations.

What Lean 4 is

Lean is a proof assistant and a functional programming language in one. Leonardo de Moura started it at Microsoft Research in 2013. In 2023 he and Sebastian Ullrich founded the Lean Focused Research Organization (FRO), a nonprofit that now drives the language. De Moura is its chief architect. You write a definition, state a theorem about it, and Lean's small kernel checks the proof. If the kernel accepts it, the theorem holds for all inputs.

Two facts matter for builders:

  • Mathlib. Lean's community maths library has about 142,000 definitions and 297,000 theorems from 772 contributors. You do not need it for program logic. You need it when the maths gets hard. AWS's SampCert, a verified differential-privacy library used in AWS Clean Rooms, leans on it heavily.
  • Industry use. AWS models its Cedar authorization language in Lean. The Lean model is about ten times smaller than the Rust code, and AWS runs millions of random inputs through both and compares outputs. Microsoft verifies Rust cryptography in SymCrypt with Lean.

What exists for Solana today

We could not confirm any Lean project from Anza. Anza's formal verification work that we could find is different. Its security-audits repository lists Certora formal verification reports for p-token (May 2026) and p-ata (October 2026), and Anza amplified Harmonic's Aristotle announcement. Anza's own post on p-token says the proof target is equivalence with SPL Token for every input.

Here is what we did find, grouped by what it verifies.

Lean models of the VM and bytecode.

  • qedsvm (QEDGen) is a Lean 4 model of the Solana VM. It works on the compiled .so, the artifact mainnet runs. A separate Rust executor is diff-tested against Mollusk and Agave. A tool called qedlift emits Lean theorems about selected bytecode paths. Its own README warns that running the executor is not verification.
  • lean-svm compiles Lean 4 programs directly to sBPF and has a README that lists proofs such as lamport conservation. It was created on 25 November 2026, so it is days old, and its README marks it as educational, research-only and not audited. LEMMA is a separate, equally new toolkit built on top of it. Treat all three as early work to read and learn from, not as production tools. Whatever the tool, a proof is about a model, so you still need evidence that the model matches the binary.

Other provers.

  • A 2025 OOPSLA paper gives a complete Isabelle/HOL semantics of all 116 sBPF opcodes, checked against Solana's Rust interpreter. The code is in the CertSBF repository.
  • Certora's Solana Prover lifts sBPF bytecode and checks rules with SMT solvers. That finds compiler-introduced bugs too.
  • OtterSec used the Kani model checker on the Squads multisig, and says the runtime environment and cost of computation are the hard parts.
  • Runtime Verification's Kompass gives a K Framework semantics of Rust MIR for Solana programs.
  • Harmonic's Aristotle compiles Rust to Lean and uses AI to propose proofs. On Manifest's unchanged Rust it proved 28 properties and found two bugs. It assumes the token and system programs behave and does not bound compute units. We already cover the tool in our Aristotle article.

Ethereum as a comparison. Nethermind's EVMYulLean models the EVM and Yul in Lean and passes 22,330 of 22,332 Cancun execution tests. It does not model gas. Ethereum researchers are also formalising the Lean consensus spec. They report the same lesson: a formal spec is only more than one more opinion once it passes the shared test corpus.

How this compares with seL4 and CertiKOS

Neither is a Lean project. seL4 used Isabelle/HOL and CertiKOS used Coq. Both are useful scale checks.

  • seL4. The 2009 proof covered about 8,700 lines of C. It needed about 200,000 lines of proof script and about 20 person-years, of which 11 were seL4-specific. By 2015 the proof files had grown to about 500,000 lines.
  • CertiKOS (mC2). A 6,500-line kernel needed about 50,000 lines of Coq proof script plus about 40,000 lines of supporting definitions. The concurrency proof took under two person-years.

Both proved functional correctness of a small, stable kernel with a dedicated research team. A Solana program is small too, but a team does not need to prove everything. The takeaway is to prove narrow properties, not full correctness.

A small Lean example

This model has accounts as key and lamport pairs. A transfer checks the signer, debits, and credits with a 64-bit overflow check. Two theorems say a successful transfer conserves total lamports and was signed by the source. The code compiled on Lean 4.36.0 with no Mathlib. Lean reports that the conservation theorem uses only the standard axioms propext and Quot.sound.

text
/-- A toy ledger: (account key, lamports) pairs. -/
abbrev Ledger := List (Nat × Nat)

def total : Ledger → Nat
  | [] => 0
  | (_, b) :: rest => b + total rest

def u64Max : Nat := 2 ^ 64

/-- Apply `f` to the balance of account `k`. Fails if `k` is missing or `f` fails. -/
def adjust (k : Nat) (f : Nat → Option Nat) : Ledger → Option Ledger
  | [] => none
  | (k', b) :: rest =>
    if k' = k then (f b).map fun b' => (k', b') :: rest
    else (adjust k f rest).map fun r => (k', b) :: r

def debit (amt : Nat) (b : Nat) : Option Nat :=
  if amt ≤ b then some (b - amt) else none

def credit (amt : Nat) (b : Nat) : Option Nat :=
  if b + amt < u64Max then some (b + amt) else none

/-- Transfer `amt` from `src` to `dst`. `signer` must be `src`. -/
def transfer (signer src dst amt : Nat) (l : Ledger) : Option Ledger :=
  if signer = src then
    (adjust src (debit amt) l).bind fun l1 => adjust dst (credit amt) l1
  else none

theorem adjust_total (k : Nat) (f : Nat → Option Nat) :
    ∀ (l l' : Ledger), adjust k f l = some l' →
      ∃ b b', f b = some b' ∧ total l' + b = total l + b'
  | [], _, h => by simp [adjust] at h
  | (k', b) :: rest, l', h => by
    by_cases hk : k' = k
    · simp only [adjust, hk, ite_true] at h
      cases hf : f b with
      | none => simp [hf] at h
      | some b' =>
        simp [hf] at h
        subst h
        exact ⟨b, b', hf, by simp [total]; omega⟩
    · simp only [adjust, hk, ite_false] at h
      cases hr : adjust k f rest with
      | none => simp [hr] at h
      | some r =>
        simp [hr] at h
        subst h
        obtain ⟨c, c', hc, heq⟩ := adjust_total k f rest r hr
        exact ⟨c, c', hc, by simp [total]; omega⟩

/-- Conservation: a successful transfer never creates or destroys lamports. -/
theorem transfer_conserves (signer src dst amt : Nat) (l l' : Ledger)
    (h : transfer signer src dst amt l = some l') : total l' = total l := by
  unfold transfer at h
  split at h
  · cases h1 : adjust src (debit amt) l with
    | none => simp [h1] at h
    | some l1 =>
      simp [h1] at h
      obtain ⟨b, b', hb, e1⟩ := adjust_total _ _ l l1 h1
      obtain ⟨c, c', hc, e2⟩ := adjust_total _ _ l1 l' h
      unfold debit at hb
      unfold credit at hc
      split at hb <;> simp at hb
      split at hc <;> simp at hc
      omega
  · simp at h

/-- Authorization: a successful transfer was signed by the source account. -/
theorem transfer_needs_signer (signer src dst amt : Nat) (l l' : Ledger)
    (h : transfer signer src dst amt l = some l') : signer = src := by
  unfold transfer at h
  split at h
  · assumption
  · simp at h

Note that the conservation proof holds even if src and dst are the same account. A test suite often misses that case. A proof cannot skip it.

A Lean RPC client is easy by comparison. Lean has a JSON library, but we found no HTTP client in the 4.36 standard library. It only has server modules. The snippet below builds the JSON-RPC body in Lean and uses curl for transport. It ran against mainnet and returned the balance of the System Program account. Community packages such as LeanRPC exist, but we did not test them.

text
import Lean.Data.Json
open Lean

/-- Build a JSON-RPC 2.0 request body. -/
def rpcRequest (id : Nat) (method : String) (params : Json) : Json :=
  Json.mkObj [("jsonrpc", "2.0"), ("id", id), ("method", method), ("params", params)]

/-- POST a JSON body with curl. Returns the raw response text. -/
def post (url : String) (body : Json) : IO String := do
  let out ← IO.Process.output
    { cmd := "curl", args := #["-sS", "-X", "POST", "-H", "Content-Type: application/json",
                               "-d", body.compress, url] }
  if out.exitCode != 0 then throw (IO.userError out.stderr)
  return out.stdout

/-- getBalance: returns lamports. -/
def getBalance (url pubkey : String) : IO Nat := do
  let resp ← post url (rpcRequest 1 "getBalance" (Json.arr #[pubkey]))
  let j ← IO.ofExcept (Json.parse resp)
  IO.ofExcept (j.getObjValAs? Json "result" >>= (·.getObjValAs? Nat "value"))

def main : IO Unit := do
  let n ← getBalance "https://api.mainnet-beta.solana.com" "11111111111111111111111111111111"
  IO.println s!"System program lamports: {n}"

Be honest about the value here. A Lean client is a fun exercise. The value is in the specs.

A realistic path for a small team

  1. Pick one program and one property. Start with conservation, authorization or no-overflow. Skip full correctness.
  2. Write the spec as a state machine in Lean. Keep it short and readable. Cedar's model is ten times smaller than its code for this reason.
  3. Prove the invariants. Set a rule that CI fails on sorry and on custom axioms.
  4. Connect the model to the code. Pick the weakest link that fits your risk:
    • Differential testing. Generate vectors from the Lean model and replay them against your program in Mollusk or LiteSVM. Cedar does this, and LEMMA's README describes the same approach.
    • Rust extraction. Charon and Aeneas translate safe Rust into a Lean model. Microsoft used them on SymCrypt, where 237,000 lines of Lean cover 16,700 lines of Rust. Hax now uses the same pipeline for its Lean backend. Aeneas targets safe Rust, so unsafe-heavy or Pinocchio-style code may not fit.
    • Bytecode. Use qedsvm or Certora when you need to reason about what actually runs.
  5. Keep it alive. Re-run proofs on every commit. A proof of last month's code is worth little.

Costs and limits

  • Proof effort. SymCrypt's proof is roughly fourteen lines of Lean for each line of Rust. Expect your first proof to take longer than your first program.
  • Spec bugs. A proof of the wrong property is still a proof. SymCrypt's own readme says reviewers must still ask whether it is the right specification and the right properties.
  • Trusted computing base. You still trust the Lean kernel, the Rust compiler, the extraction tool, the runtime, the syscalls and the SPL programs your code calls. Both Aristotle's Manifest work and the lean_solana library assume the token program is correct.
  • Drift. Code changes faster than proofs. Budget time for it.
  • Compute units. Most proofs say nothing about cost. qedsvm is an exception for the paths it lifts.

Checklist

  • One property written in plain English before any Lean
  • Spec reviewed by someone who did not write it
  • Proof builds in CI with no sorry and no custom axioms
  • Differential tests tie the model to the real program
  • A list of what you trust and did not prove
  • An audit still booked

Conclusion

Lean will not replace tests or audits. It gives you one thing they cannot: a statement that holds for every input, checked by a small kernel. For Solana, that tooling is weeks old and mostly unaudited. A small team can still get value today by proving one narrow invariant and tying it to the code with differential tests. Start small, write down your trust assumptions, and keep the audit.

Sources

Keep reading

Get new articles in your inbox

Technical deep-dives on Solana tooling, infrastructure, and ecosystem. No noise.

solanaleanformal-verificationsbpfsecurityrustverification

DevRels · November 27, 2026

Lean 4 for Solana: what formal verification gives you that tests and audits don't | devrels.xyz