Ethereum Virtual Machine (EVM)
The Ethereum Virtual Machine (EVM) is a decentralized virtual environment that operates as the runtime environment for all smart contracts on the Ethereum blockchain. It enables Ethereum nodes to execute smart contracts, using "gas" to measure the computational effort required for operations, ensuring efficient resource allocation and network security. The EVM is also designed to be a sandboxed environment, ensuring that the execution of smart contracts is secure, deterministic, and isolated from the underlying network.
Ledger to State Machine
Blockchains like Bitcoin are often described as "distributed ledgers," where the ledger records all transactions in a secure and tamper-evident manner. This ledger is maintained collectively by a network of nodes and follows strict consensus rules that determine what changes are valid and how new entries can be added.
While Ethereum has its own cryptocurrency (ether), its key innovation is support for smart contracts — self-executing programs stored on the blockchain. To enable this, Ethereum operates not just as a distributed ledger, but as a "distributed state machine". This means it maintains a global state that includes account balances and contract data, which can change with each new block according to predefined rules set by the EVM.
State Transition
The EVM behaves like a mathematical function that takes in an input and produces a deterministic output.
Y(S, T)= S'
Where:
- S is the current state
- T is a new set of valid transactions
- S' is the new state
State
In the context of Ethereum, the state is a modified modified Merkle Patricia Trie (MPT), which keeps all accounts linked by hashes and reducible to a single root hash stored on the blockchain.
Transaction
Transactions are cryptographically signed instructions from accounts. There are two types of transactions: those which result in message calls and those which result in contract creation.
EVM Instructions

The EVM uses a stack-based architecture, in which it uses a stack to hold and manipulate data during execution.
Stack Machine
The EVM uses a stack that can hold up to 1024 items, each 256-bits (32 bytes) wide, reason being that this aligns with the 256-bit cryptography like Keccak-256 hashes and secp256k1 signatures.
When EVM runs code, it pushes/pops data onto this stack for all operations — no registers, no heap. For example, to add two numbers, EVM pushes both to the stack, then runs the ADD
opcode which pops the two values, adds them, and pushes the result back.
Transient Memory
During a transaction, EVM uses a temporary memory (RAM-like) to store data for the duration of the transaction. It is byte-addressable, like a big array, but not persistent — it disappears when the execution ends.
Storage
Contracts, however, are saved between transactions. This storage is implemented as a Merkle Patricia Trie. It is word-addressable (stores 256-bit words) and is linked to the contract’s account in the global Ethereum state. For example, if a contract sets x = 42 in its code, that’s written to storage, so x still equals 42 the next time you interact with the contract.
Bytecodes & Opcodes
Smart contracts are compiled to EVM bytecode — a list of opcodes (instructions) like:
- Basic operations: ADD, SUB, MUL, AND, XOR
- Blockchain-specific operations: ADDRESS (get current contract’s address), BALANCE, BLOCKHASH
These opcodes manipulate the stack and read/write from memory or storage as needed.
Key Features
Decentralized & Deterministic Execution
Ethereum is a decentralized blockchain platform, meaning it is not controlled by any single entity. Instead, it is maintained by a global network of nodes—computers that run Ethereum client software, validate transactions, and help secure the network through consensus mechanisms like proof of stake. These nodes work together to maintain a shared, immutable ledger and execute smart contracts.
EVM guarantees deterministic execution of smart contracts, meaning that the output of the smart contract is the same for all participants in the network. This determinism is pivotal for establishing consensus among all nodes, assuring uniform agreement on the blockchain's state.
Opcode System & Stack-based
The EVM operates using a low-level opcode system, where each opcode represents a specific instruction such as arithmetic operations, data storage and retrieval, conditional branching, or contract interaction. These opcodes form the basic building blocks of all smart contract execution on Ethereum
The EVM follows a stack-based execution model, meaning that all data manipulation is performed using a last-in, first-out (LIFO) stack. Values are pushed onto the stack, and opcodes execute by popping operands from it, performing the operation, and pushing the result back. This design allows for efficient, deterministic execution without the need for registers or a traditional CPU architecture.
Smart Contract Execution
Smart contracts on Ethereum are programs written in high-level languages like Solidity or Vyper, which are compiled into EVM bytecode. When a user sends a transaction to a smart contract, the bytecode is executed on the Ethereum Virtual Machine (EVM). The EVM processes this code in a deterministic manner, using the stack, memory, and storage to handle computations and data persistence. Execution flow is controlled by EVM opcodes, which perform actions such as arithmetic, conditional branching, data manipulation, and external contract calls. The outcome of execution can include state changes, event emissions, and returning data to the caller.
Gas System
To prevent abuse and ensure fair resource allocation, Ethereum uses a gas system to meter computation and storage. Every operation executed on the EVM, including opcodes, memory usage, and storage writes, consumes a predefined amount of gas. Users must specify a gas limit and gas price when submitting a transaction. If the transaction runs out of gas during execution, it fails and all state changes are reverted, but the gas spent is not refunded. This mechanism ensures that contracts execute efficiently and discourages infinite loops or excessively resource-intensive operations. Gas fees are paid in ETH, and after Ethereum’s transition to proof of stake, a portion of the gas fee is burned, reducing ETH supply over time.