Virtual Machine (VM)
۱۴۰۵/۱/۲۷
Virtual machine (VM) in the blockchain sense is the sandboxed execution environment that runs smart contract code deterministically on every node in the network. Every full node independently executes the same bytecode against the same inputs and must arrive at the same state — without that determinism, consensus would be impossible.
This is different from a system virtual machine like VMware or VirtualBox, which emulates a whole computer. A blockchain VM is closer to the Java Virtual Machine: a narrow interpreter for a specific bytecode, with no filesystem, no network, and no non-deterministic operations.
Why blockchains need a VM
Running native code would be fast but unsafe: a bug or an intentional infinite loop in a contract could crash every node at once. A VM provides:
- Sandboxing — contract code cannot read files, open sockets, or call the host OS
- Determinism — same input, same output, on every node and every hardware
- Metering — each operation costs gas; when gas runs out, execution halts, preventing denial-of-service
- Portability — the same bytecode runs on any implementation of the VM spec
EVM (Ethereum Virtual Machine)
The EVM is the most widely used blockchain VM. It's a stack-based machine with a 256-bit word size, designed to match the size of cryptographic primitives like Keccak-256 hashes.
- Solidity or Vyper compiles to EVM bytecode
- Every opcode has a gas cost; complex ones (SSTORE, CALL, keccak) cost more
- EVM-compatible chains (Polygon, Arbitrum, Optimism, BNB Chain, Avalanche C-Chain, Base) run the same bytecode unmodified, which is why tools like MetaMask and Hardhat work across all of them
SVM (Solana Virtual Machine)
Solana's VM is based on eBPF (extended Berkeley Packet Filter), originally a Linux kernel technology, adapted as sBPF. Contracts are written in Rust or C and compiled to sBPF bytecode.
- Sealevel — Solana's parallel runtime — executes non-overlapping transactions simultaneously, using account access lists declared up front
- Register-based (unlike EVM's stack-based design), closer to physical CPU architecture
WASM-based VMs
WebAssembly (WASM) is a portable bytecode originally designed for browsers, increasingly adopted as a blockchain VM target. Chains using WASM VMs include NEAR, Polkadot (via the Substrate pallet-contracts runtime), Cosmos CosmWasm, and Internet Computer.
WASM is language-agnostic — developers can use Rust, C++, AssemblyScript, or Go — and benefits from a mature tooling ecosystem outside crypto.
Layer-2 VMs
Rollups inherit or extend existing VMs:
- Optimism, Arbitrum, Base — EVM-equivalent
- zkSync Era — EVM-compatible via a custom zkEVM
- Starknet — runs the Cairo VM, purpose-built for STARK proofs
- Scroll, Polygon zkEVM, Linea — bytecode-level EVM-equivalent zkEVMs
