The Ethereum Virtual Machine (EVM)
Smart contracts don't run on any single company's servers — they run inside the Ethereum Virtual Machine, or EVM: a sandboxed, deterministic runtime that every node on the network runs identically. This lesson explains what the EVM actually does, why it needs to be deterministic, and how it prevents runaway computation from stalling the network.
A sandboxed, deterministic runtime. "Sandboxed" means the EVM has no access to anything outside its own defined environment — it cannot read your computer's files, make an arbitrary internet request, or depend on your local system's clock in a way that would differ from another node's. "Deterministic" means that given the same starting state and the same inputs, the EVM always produces exactly the same output, on every node, every time. This isn't an incidental property; it is the entire reason Ethereum's shared state (covered in the previous lesson) can be trusted without trusting any single node. If the EVM's behavior could vary — even slightly, even due to something as subtle as floating-point rounding differences between machines — nodes would disagree about the resulting state, and the network's core guarantee would break. This is part of why Solidity and the EVM avoid floating-point arithmetic entirely, relying instead on fixed-size integers for all calculations.
Executing bytecode one instruction at a time. When a contract is deployed, its compiled bytecode is a sequence of low-level instructions called opcodes — simple operations like "add two numbers," "write a value to storage," "call another contract," or "compare two values." The EVM executes these opcodes one at a time, in order, exactly as a real (if unusually constrained) computer processor would execute machine code. Every opcode is well defined by Ethereum's official specification (the "Yellow Paper" and subsequent Ethereum Improvement Proposals), so there is no ambiguity about what each one does on any node running correct software.
Gas: metering computation so nothing runs forever. Because contract code can, in principle, contain loops or recursive calls, the EVM needs a way to prevent a contract from simply running forever and stalling every node on the network. The solution is gas: every opcode has a defined gas cost, and every transaction specifies a gas limit — the maximum computational "budget" the sender is willing to pay for. As the EVM executes a transaction's opcodes, it deducts gas as it goes; if the gas limit is reached before execution finishes, the transaction halts, any state changes it made are reverted, and the sender still pays for the gas already consumed up to that point. This single mechanism solves two problems at once: it prevents infinite loops from freezing the network, and it makes computation a priced, scarce resource, since someone has to pay (in ETH, covered in Module 3) for every unit of work the network performs on their behalf.
Why "every node re-executes every transaction" matters. Unlike a traditional system where you'd query a central server and simply trust its answer, Ethereum's design means any node can independently re-run the exact same transaction against the exact same starting state and verify, for itself, that the resulting state matches what the rest of the network agreed on. This is the EVM's core contribution to Ethereum's trust model: you don't have to trust any single node's report, because you (or any node you choose) can check the computation yourself.
Worked Example
Consider one concrete opcode-level trade-off that shapes how contracts are actually written: a storage-write opcode (persisting a value to a contract's long-term storage) costs far more gas than a simple arithmetic opcode like addition. This is because writing to storage affects every node's permanent copy of the state, while arithmetic is transient, in-memory computation during execution. This cost difference is precisely why experienced contract developers go out of their way to minimize on-chain storage writes — batching updates, using cheaper data structures, or keeping only the minimum necessary data on-chain — since unnecessary storage writes directly and substantially increase the gas (and therefore ETH) cost of using a contract.
Exercise
Look at a transaction's gas usage breakdown on a block explorer, if the explorer provides one (many show a gas usage chart or a per-call trace for contract interactions). Identify which part of the call consumed the most gas, and write one sentence on why that specific operation might be expensive, using the storage-versus-arithmetic distinction from this lesson as a reference point.
Recap
- The EVM is a sandboxed, deterministic runtime: every node executes the same bytecode the same way, producing identical results, which is what makes Ethereum's state verifiable without trusting any single node.
- Contract bytecode runs as a sequence of low-level opcodes, each with a defined gas cost, and gas limits prevent any transaction from running forever and stalling the network.
- Storage operations are far more expensive in gas than simple computation, which is why well-designed contracts minimize unnecessary on-chain storage writes.
Resources
- Ethereum.org: EVM — official documentation on the sandboxed, deterministic runtime.
- Ethereum Yellow Paper — the formal opcode specification referenced in this lesson.
- evm.codes — an interactive reference for every EVM opcode and its gas cost.