A from-scratch implementation of the Ethereum Virtual Machine in Python, built as part of the EVM From Scratch project.
This is my personal implementation of the EVM specification, written entirely in Python without relying on existing EVM libraries. The goal is to deeply understand how the EVM works by implementing each opcode and mechanism from first principles.
137 out of 152 tests passing ✓
PUSH0throughPUSH32- Push operationsPOP- Remove from stackDUP1throughDUP16- Duplicate stack itemsSWAP1throughSWAP16- Swap stack items
ADD,SUB,MUL,DIV,MOD- Basic arithmeticADDMOD,MULMOD- Modular arithmeticEXP- ExponentiationSIGNEXTEND- Sign extensionSDIV,SMOD- Signed division and modulo
LT,GT,SLT,SGT- Comparison operationsEQ,ISZERO- Equality checksAND,OR,XOR,NOT- Bitwise operationsSHL,SHR,SAR- Shift operationsBYTE- Byte extraction
MSTORE,MSTORE8- Store to memoryMLOAD- Load from memoryMSIZE- Get memory size
SSTORE- Store to persistent storageSLOAD- Load from storage
JUMP,JUMPI- Jump operationsJUMPDEST- Jump destination markerPC- Program counterSTOP- Halt executionINVALID- Invalid opcode
ADDRESS,CALLER,ORIGIN- Account informationBALANCE,SELFBALANCE- Balance queriesCALLVALUE- ETH value sentGASPRICE,BASEFEE,GASLIMIT- Gas informationCOINBASE,TIMESTAMP,NUMBER- Block informationDIFFICULTY,CHAINID,BLOCKHASH- Chain information
CALLDATALOAD,CALLDATASIZE,CALLDATACOPY- Access call data
CODESIZE,CODECOPY- Contract code accessEXTCODESIZE,EXTCODECOPY,EXTCODEHASH- External code access
LOG0throughLOG4- Event logging
SHA3(KECCAK256) - Hashing
RETURN- Return data from execution
evm-from-scratch/
├── evm.json # Test specifications
├── python/ # Python implementation
│ └── evm.py # Main EVM implementation
└── README.md # This file
# Run all tests
cd python
python evm.py
# Tests are defined in evm.json and automatically executed- Language: Pure Python 3
- Dependencies: None (standard library only)
- Architecture: Single-file implementation for clarity
- Testing: Uses the standardized test suite from evm.json
This implementation follows the Ethereum Yellow Paper specification and draws from:
- EVM Opcodes reference: evm.codes
- Ethereum execution specs
- The original EVM From Scratch challenge materials
Built as part of the EVM From Scratch project by @w1nt3r-eth.