Solidus fork of NethermindEth/EVMYulLean (pinned EVM/Yul semantics for the verified compiler)
  • Lean 73.7%
  • Python 17.5%
  • Yul 7%
  • C 1.1%
  • Solidity 0.6%
  • Other 0.1%
Find a file
History 2026-06-07 22:43:54 -07:00
.github/workflows add CI - WIP testing 2025-03-24 11:56:50 +01:00
Conform Update deprecated order classes for Lean 4.28 2026-06-05 01:36:48 +02:00
EthereumTests@08839f54eb implement FFI 2025-03-05 14:24:55 +01:00
EvmYul Make RETURNDATACOPY bounds-aware in raw semantics 2026-06-07 22:43:54 -07:00
.gitignore implement phasing, improve UX 2025-03-14 16:03:39 +01:00
.gitmodules force HTTPS on gitmodules for the CI 2025-03-24 14:30:20 +01:00
EvmYul.lean remove debug misc 2025-03-20 16:52:58 +01:00
lake-manifest.json Migrate EVMYulLean to Lean 4.28 2026-06-03 13:44:28 +02:00
lakefile.lean Migrate EVMYulLean to Lean 4.28 2026-06-03 13:44:28 +02:00
lean-toolchain Migrate EVMYulLean to Lean 4.28 2026-06-03 13:44:28 +02:00
license.txt Initial commit 2024-07-18 17:18:59 +02:00
openssl.cnf FFI for keccak256 2025-03-07 12:12:04 +01:00
README.md Make Yul SELFDESTRUCT halt execution 2026-05-15 14:08:56 -07:00
shell.nix Find libssl path for rip precompiled contract 2025-04-07 18:21:19 +03:00
SpongeHash.lean Initial commit 2024-07-18 17:18:59 +02:00

This repository contains a formal model of the EVM and Yul in Lean 4. Where applicable, the underlying EVM primops are used directly by the Yul model.

Everything here is work in progress and is subject to change therefore.

Requirements

  • Python packages: coincurve, typing-extensions, pycryptodome, eth-typing, py-ecc

Project structure

Primops

The Operation describing all of the primitive operations:

EvmYul/Operations.lean

The semantic function primCall associated with the ADT:

EvmYul/Yul/PrimOps.lean

EVM

The model of the EVM state EVM.State:

EvmYul/EVM/State.lean

The semantic function step:

EvmYul/EVM/Semantics.lean

Yul

The ADT Stmt mutually defined with Expr and FunctionDefinition describing Yul:

EvmYul/Yul/Ast.lean

The model of the Yul state YUL.State:

EvmYul/Yul/State.lean

The semantic function exec mutually defined with eval (and some misc. functions):

EvmYul/Yul/Interpreter.lean

Conformance testing

A git submodule with EVM conformance tests is in:

EthereumTests/

The test running infrastructure can be found in:

Conform/

To execute conformance tests, make sure the EthereumTests directory is the appropriate git submodule and run:

lake test -- <NUM_THREADS> 2> out_discard.txt

where <NUM_THREADS> is the number of threads running conformance tests in parallel. Note that the default is 1. We recommend redirecting stderr into a file to not pollute the output.

Yul semantics tests

To execute the Yul semantics tests run:

lake exe yulSemanticsTests

These tests are defined in EvmYul/Yul/YulSemanticsTests/Main.lean.

Limitations of the Yul semantics

Fallback function from receiving ether

  • We do not run a the fallback function of a smart contract when it receives ether, such as being a recipient of ether in a SELFDESTRUCT of another contract.

Gas

  • We do not model gas in the Yul semantics, no fee is deducted.

Create

  • We do not model create or create2 because Yul code is not stored as bytecode, and so we cannot properly model create or create2 without some mechanism for correctly decompiling bytecode into Yul code, so we do not model this.
  • This case is caught by the the _ in the match statement in EVMYul/Semantics.lean and returns default.
  • Instead of creating contracts, they should be manually included in the modelled blockchain state, in the accountMap. See EvmYul/Yul/YulSemanticsTests/README.md for more information on how to include custom Solidity contracts in the modelled blockchain state.

EXTCODESIZE

  • Not modelled, the current semantics raise an error. Solidity checks extcodesize and so generated Yul will not be able to call other contracts without removing or editing these extcodesize checks (manually).
  • In the EvmYul/Yul/YulSemanticsTests.lean we manually changed let _1 := extcodesize( 2) to let _1 := 1 in fun_testStoreAndRetrieveExternal.
  • We also do not model EXTCODEHASH, EXTCODECOPY, CODECOPY, CODESIZE for similar reasons to not modelling EXTCODESIZE.
  • These cases are caught by the the _ in the match statement in EVMYul/Semantics.lean and return default.

SELFDESTRUCT

  • Yul SELFDESTRUCT halts execution after applying the modelled account and substate effects. The semantics for SELFDESTRUCT still have limitations, such as not triggering the fallback function in a contract that is the recipient of the ether from the contract the self-destructs. We may remove the semantics for SELFDESTRUCT once its status changes from deprecated to not being supported.