# Lean software that verifies Ethereum contracts without failures

> Lean combines a functional language and mathematical proofs with a minimal kernel. We explain how it helps verify Ethereum contracts before deploying them.
> By José Maldonado · Ethereum · 2026-10-10

There are programs where a small error costs little and is fixed with a quick update without drama. Ethereum contracts do not belong to that group, because they handle real money and once deployed they are difficult to change. Lean was born for that kind of critical software, as a functional language and open source code proof assistant that checks every claim with a minimal core, according to [lean-lang.org](https://lean-lang.org/). Its stable version 4.33.1 arrived on August 21, 2026, with thirteen years of development since its appearance in 2013.

The name Lean may sound like an academic tool, but its use already goes beyond classrooms and mathematics departments. Its Mathlib library brings together around half a million lines of formalized code and supports projects such as perfectoid spaces and the liquid tensor challenge. Ethereum has adopted it as a cross-cutting piece to verify post-quantum cryptography and compilers, with a project of 20 million over three years for its zero-knowledge virtual machine, as detailed by [pq.ethereum.org](https://pq.ethereum.org/). That double life as a language and as a verifier explains its current moment.

The central idea fits in one sentence without technicalities before going into details in the following sections. You write a program and at the same time you write a mathematical proof that the program does what it promises. The system checks the proof automatically and only accepts the code when every step is proven. If the proof fails, compilation fails and the error does not reach the mainnet or the users.

## What is Lean and why is it not just another language?

Lean combines strict functional programming with dependent types to program and to prove theorems. You can use it to write normal applications with ahead-of-time compilation to native code and garbage collection without long pauses. You can also use it to express mathematical properties and ask the machine to check them step by step. This combination distinguishes it from classic assistants focused only on logic.

Its architecture relies on a small kernel that only checks already-built proof terms. Tactics and elaboration can have errors without breaking the guarantee, because the kernel rejects any malformed proof. There are also independent checkers that validate proofs without needing to trust the entire implementation. That design reduces the trusted base to a minimal, auditable component.

The project started in 2013 at the hands of Leonardo de Moura and today it is supported by the nonprofit organization Lean FRO. The Lean 4 version, published in 2021, rewrote the system in Lean itself and added hygienic macros and class resolution with tables. It works on Linux, macOS and Windows on x86 and ARM, which makes it easy to test the same project on your laptop and on your server without strange adjustments, with an Apache 2.0 license and code on GitHub. Its current reference is version 4.35 in the manual, with the stable 4.33.1 from August as the common base for teams.

*   Functional language for writing efficient and maintainable programs as a team
*   Proof assistant to demonstrate that the code meets its specification
*   Minimal kernel that only accepts well-formed proofs and rejects the rest

This double nature allows a workflow that other languages do not offer without external tools. The same file contains the executable implementation and the logical specification in the form of propositions. The programmer proves the equivalence with interactive tactics and automation. The compiler generates fast binaries after erasing the proofs from the execution path.

**[The 10 biggest crypto hacks in history](https://observatorioblockchain.com/ciberseguridad/los-10-hackeos-cripto-mas-grandes-de-la-historia/)**

## How does Lean prove that a program is correct?

The basic mechanism uses tactics that transform goals into subtasks until every case is closed. You write a theorem as a proposition about your function and apply steps such as induction or simplification. Each tactic produces an explicit term in the foundational theory that the kernel checks. If a step is incorrect, the system flags it in the editor with an immediate response.

A classic example is the proof that there are infinitely many prime numbers from the factorial. You define the notion of primality and show that any number greater than one has a prime divisor. You construct the factorial number plus one and extract its prime factor with the help of previous lemmas. The grind tactic closes many routine steps without manual intervention and leaves high-level decisions to the human.

The same pattern applies to software with state and effects controlled through monads. You model the contract state as a structure with storage and maps, and you describe each operation as a transition between states. You specify invariants such as that the total supply matches the sum of balances. You prove that each function preserves those invariants for any input within the supported fragment.

Modern automation combines search with strict checking so as not to lose guarantees. The grind tactic implements SMT-style reasoning inside Lean itself and designed for dependent theory. External procedures can suggest steps, but they only enter if the kernel accepts them. This balance between automatic help and minimal review sustains large projects without collapsing trust in every change.

*   Interactive tactics that divide a large goal into steps reviewable by the kernel
*   Grind automation that closes routine cases without constant manual intervention
*   Independent checkers that validate proofs without trusting the entire system

## Where does Lean fit into Ethereum's security?

Ethereum needs strong guarantees on three fronts that already use Lean in different ways. The first is post-quantum cryptography, with schemes and aggregation that must behave exactly as mathematics defines. The second is contract compilers, where a translation error can drain funds as happened with 50 million in July 2023. The third is the contracts themselves, with business logic that must respect its specification for any input.

The Foundation's snarkification team, led by Alex Hicks, funds formal verification of primitives for concise proofs. Those components support the hash signature aggregation that will enable post-quantum consensus with thousands of validators. Each verified primitive reduces the risk that an aggressive optimization introduces a silent failure. The work is coordinated with weekly devnets and with more than ten client teams.

Use in Ethereum

What is proven

Why it matters in 2026

Post-quantum cryptography

Correct primitives and aggregation

Supports future consensus

Yul to EVM compilers

Bytecode preserves semantics

Prevents translation failures

Contracts in Lean

Code respects its specification

Protects user funds

The developer documentation links these efforts with the security roadmap, as summarized by the [security page](https://ethereum.org/roadmap/security/). It is part of a cross-cutting tool that advances with the rest of the arcs. Formal verification appears alongside fast finality, privacy, state and zero-knowledge virtual machine. Each arc uses proofs where the cost of an error justifies the effort of demonstrating.

Experience with Lean in mathematics helps to understand its scale in critical software. Mathlib contains non-trivial schemes and objects with hundreds of contributors and continuous review. That culture of shared library transfers to compiler specifications and contract models. The result is less trusted code and more reusable proofs across European projects.

[This is how Ethereum's quantum security will be according to Thomas Coratger](https://observatorioblockchain.com/en/blockchain/ethereum-quantum-resistance-thomas-coratger/)

## What do you need to start without getting lost?

The entry point depends on your profile and your goal in the coming weeks. If you program and want to learn the language, the book Functional Programming in Lean covers the basics without requiring prior functional experience. If you are interested in theorem proving, Theorem Proving in Lean teaches dependent theory with guided examples. If you come from mathematics, Mathematics in Lean shows formalization with the Mathlib library step by step.

Installation uses the elan manager, similar to rustup in the Rust world, with a toolchain fixed per project. The recommended editor is VS Code with the Lean extension for continuous response as you write. Projects are compiled with lake and dependencies are pinned by version to reproduce results. The whole workflow works on the three main systems without strange steps for a current developer.

The first useful exercise is to prove a small property of a function you already understand well. Define sum or factorial and prove that the result is always positive for valid inputs. Use grind to close routine cases and observe how the system asks you for intermediate lemmas. That short cycle teaches you to divide a large goal into checkable steps without initial frustration.

*   Functional book for programmers coming from other common languages
*   Proof book to understand tactics and dependent theory calmly
*   Mathematics book to formalize with Mathlib and classic examples

The leap to contracts also requires understanding the state model of the Ethereum virtual machine. Tools such as Verity or solidity lean allow writing the contract in Lean and compiling to deployable artifacts. Each contract includes implementation and specification plus proofs that bind both sides. The complete workflow is explained in the next article in this series with examples and figures.

## What Lean changes for European software

Lean changes the usual question about software quality at a decisive point for Europe. It is no longer enough to test some cases and rely on manual review by a tired team. Now you can demand a machine-checked proof for the properties that really matter in money and data. That demand fits banking, industry and administration operating under strict regulation.

The cost exists and it is worth acknowledging it without embellishment as of October 2026. Writing clear specifications takes time and proving invariants requires thinking through each edge case calmly. The learning curve of dependent types slows down teams accustomed to unit tests at first. The return comes when an aggressive change is accepted because the theorem still stands and not because of the intuition of a rushed reviewer.

The practical leap for European teams is to combine Lean with human review and classic tests in the same delivery. Unit tests capture fast regressions during daily development at low cost. Manual review provides business context that no theorem expresses by itself. Lean adds the mathematical guarantee for the core that handles funds and critical permissions.

Europe's bet on verification fits with Ethereum's roadmap toward 2029 and with the pressure on custodians. Each verified compiler reduces systemic risk for thousands of contracts at once. Each verified contract protects users who cannot audit code on their own. Between both layers, Lean stops being an academic curiosity and becomes silent infrastructure that supports real funds.

[Everything you can do with Etherscan's AI for smart contracts](https://observatorioblockchain.com/inteligencia-artificial/lo-que-puedes-hacer-con-la-ia-de-etherscan-para-smart-contracts/)
