The Ethereum Virtual Machine (EVM) is the stack-based computation engine that processes smart contracts and state changes in the Ethereum network. The EVM is Turing-complete, meaning it can perform any computational operation given sufficient resources. It functions as a decentralized computer that executes bytecode across thousands of distributed nodes, maintaining a consistent state across the entire system.
EVM compatibility means a blockchain can run the Ethereum Virtual Machine, execute Ethereum smart contracts, and support Ethereum applications with minimal code modifications. This allows for easier development and deployment of decentralized applications (dApps) across other blockchain networks.
EVM compatibility connects blockchain networks through shared standards, allowing them to use the same tools, applications, and development practices. Many blockchain platforms have adopted EVM compatibility to work with Ethereum's existing tools and applications, benefiting users and developers.
Users can:
Developers can:
EVM-compatible platforms include both Layer 2 solutions and L1 blockchains.
Among base layer (L1) EVM-compatible blockchains:
Smart contracts must be converted to a format the EVM can understand: bytecode. This conversion process, called compilation, transforms code written in languages like Solidity into simple instructions (opcodes) that the EVM executes. Each node in the Ethereum network runs this bytecode with uniform execution, ensuring consistent results across the network, with each operation consuming a specific amount of gas.
The EVM uses gas to measure computational effort and prevent infinite loops. Every operation costs a specific amount of gas, which must be paid in ETH (in wei). This mechanism:
The EVM updates the state of all accounts and smart contracts on Ethereum. This includes:
The EVM utilizes several data storage locations, each serving different purposes:
Read-write locations:
Read-only locations:
Calldata
: Contains function parameters and external call data. The first 4 bytes represent the function selector (method identifier), followed by the encoded parameters. Bytecode
: The compiled smart contract code itself.All these data locations use 32-byte (256-bit) words, chosen to optimize Ethereum's cryptographic operations. Gas costs vary significantly among these types, with persistent storage being the most expensive and stack operations being the least.
Opcodes are the fundamental instructions that the EVM reads and executes. Common categories include:
ADD
, SUB
, MUL
)AND
, OR
, NOT
)SLOAD
, SSTORE
)JUMP
, CALL
)CALLER
, CALLVALUE
)
Smart contracts can be written in high-level EVM-compatible languages, primarily Solidity and Vyper. More specialized languages like Yul exist for low-level optimization.
When deploying a smart contract: