Virtual Machine

The Ethereum Virtual Machine (EVM) is a Turing-complete, stack-based virtual machine that executes smart contracts on the Ethereum blockchain.

A virtual machine (VM) is a software-based emulation of a physical computer system. It operates as a self-contained environment that runs its own operating system (guest OS) and applications, independent of the underlying hardware (host machine). Virtualization technology allows multiple VMs to run concurrently on a single physical host, each with its own virtualized hardware resources such as CPU, memory, storage, and network interfaces. This abstraction is managed by a hypervisor, which is a layer of software (Type 1 runs directly on hardware, Type 2 runs on top of a host OS) responsible for creating, running, and managing the VMs. VMs provide numerous benefits, including hardware independence, allowing applications to run on different hardware configurations without modification; resource isolation, preventing issues in one VM from affecting others or the host; and efficient resource utilization, by consolidating multiple workloads onto fewer physical servers. They are widely used for server consolidation, testing and development environments, disaster recovery, running legacy applications, and creating isolated security sandboxes. Trade-offs include performance overhead compared to bare-metal execution due to the hypervisor layer, and the need for sufficient host resources to support multiple VMs effectively. Managing VM lifecycles, storage, and networking also requires specialized expertise.

        graph LR
  Center["Virtual Machine"]:::main
  Rel_hypervisor["hypervisor"]:::related -.-> Center
  click Rel_hypervisor "/terms/hypervisor"
  Rel_virtualization["virtualization"]:::related -.-> Center
  click Rel_virtualization "/terms/virtualization"
  classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
  classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
  classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
  classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
  linkStyle default stroke:#4b5563,stroke-width:2px;

      

🧒 Explain Like I'm 5

The EVM is like the engine inside the [Ethereum](/en/terms/ethereum) computer. It reads special instructions (bytecode) from [smart contracts](/en/terms/smart-contracts) and performs the actions, like a chef following a recipe step-by-step. Every step costs a little [bit](/en/terms/bit) of 'gas' money to make sure the cooking doesn't take forever.

🤓 Expert Deep Dive

A virtual machine operates through a hypervisor, which can be Type 1 (bare-metal, e.g., VMware ESXi, Xen) or Type 2 (hosted, e.g., VMware Workstation, VirtualBox). The hypervisor manages and allocates physical resources (CPU, RAM, storage, network interfaces) to the guest VMs.

CPU Virtualization: This is achieved through techniques like binary translation or hardware-assisted virtualization (Intel VT-x, AMD-V). In binary translation, sensitive instructions that modify system state are trapped and emulated by the hypervisor. Hardware-assisted virtualization offloads much of this to the CPU, allowing guest code to run directly on the host hardware for most operations, with the hypervisor only intervening for specific privileged instructions or transitions. The Extended Page Tables (EPT) by Intel and Rapid Virtualization Indexing (RVI) by AMD are crucial for efficient memory management, mapping guest physical addresses to host physical addresses.

Memory Virtualization: The hypervisor maintains a mapping between the guest VM's physical memory addresses and the host's physical memory addresses. This involves managing page tables, often using techniques like Shadow Page Tables (in older systems) or EPT/RVI for direct hardware support, significantly reducing overhead.

I/O Virtualization: Devices are virtualized. For storage, this often involves using virtual disk formats (e.g., VMDK, VHD) that are presented as block devices to the guest OS. Network I/O can be handled by virtual network interface cards (vNICs) connected to virtual switches within the hypervisor, which then bridge to the physical network. Technologies like SR-IOV (Single Root I/O Virtualization) allow VMs to bypass the hypervisor for direct access to physical NICs, drastically improving network performance.

Security and Isolation: VMs provide strong isolation. Each VM has its own kernel, memory space, and emulated hardware, preventing processes in one VM from directly accessing or affecting another. The hypervisor acts as a mediator and enforcer of these boundaries.

📚 Sources