Skip to content
Back to Knowledge Base

Ethereum & The EVM

Bitcoin proved that value could be decentralized. Ethereum extended this to computation. The Ethereum Virtual Machine (EVM) is the distributed computing environment where all smart contracts live and execute.

1. The World Computer

The EVM is often described as a "World Computer." It is a quasi-Turing-complete state machine that exists on thousands of nodes simultaneously. "Quasi" is a critical distinction: unlike your laptop, EVM execution is bounded by Gas to prevent infinite loops (The Halting Problem).

The State Transition Function

Y(S, T) = S'

Given an existing State (S) and a new Transaction (T), the Ethereum State Transition Function (Y) produces a new State (S'). This transition is deterministic; every node in the world must agree on the exact result S'.

2. EVM Architecture: Data Locations

When a smart contract executes, it has access to three distinct types of data storage. Understanding the cost difference between them is vital for optimization.

Stack

Volatile (Cheap)

Last-in, First-out (LIFO) container for up to 1024 256-bit values. Most opcodes (ADD, SUB) work directly here. It is wiped after execution.

Memory

Volatile (Expensive)

Linear, expandable byte array. Used for complex structures like strings or arrays during execution. It scales quadratically in cost and is wiped after execution.

Storage

Permanent (Very Expensive)

A massive Merkle-Patricia Trie that persists on the blockchain. Writing here (SSTORE) is the most expensive operation (20k+ gas) because every node must store it forever.

3. From Code to Machine

The EVM does not understand Solidity. It understands Bytecode.

When you compile a contract, it turns into a string of hex bytes (e.g., 0x60806040...). During execution, the EVM reads these bytes one by one as Opcodes.

  • 0x60 PUSH1 (Place value on stack)
  • 0x01 ADD (Add top two stack items)
  • 0x55 SSTORE (Save to permanent storage)
// Solidity uint a = 1; uint b = 2; uint c = a + b; // EVM Assembly (Conceptual) PUSH1 0x01 PUSH1 0x02 ADD // Result (0x03) is now on Application Stack

4. Why Gas Exists

Gas is not just a fee; it is a unit of computational effort. It decouples the market price of ETH from the cost of computing.

The Infinite Loop Risk

Without gas, a malicious user could deploy a contract that loops forever while(true) {}. If validators ran this, the entire network would freeze.

The Solution

Every instruction implies a cost. The sender prepays a "Gas Limit." The EVM deducts gas as it runs opcodes. If the counter hits zero, Out of Gas triggers, and the transaction reverts immediately.

5. EVM Compatibility

The EVM standard has become the de-facto operating system of Web3. "EVM Equivalence" means a chain can run Ethereum smart contracts without modification.

Ethereum
Optimism
Arbitrum
Polygon
Base
BSC
Avalanche C-Chain
Gnosis

Common Questions

Do I compile to machine code?

No. You compile to Bytecode. The EVM interprets this bytecode. It acts as a virtualization layer between your smart contract and the actual server hardware.

Can smart contracts call each other?

Yes. This is called a 'Message Call'. Contract A can call Contract B. However, Contract A must pay the gas for Contract B's execution.

Where is the state stored?

The 'World State' is stored in a Merkle-Patricia Trie structure. The root hash of this trie is included in every block header, ensuring cryptographic proof of the entire network's data integrity.