How ava-labs/subnet-evm works
This project is the Subnet EVM – a standalone Ethereum Virtual Machine implementation designed to run as a subnet within the Avalanche network. It is a simplified and adapted version of Coreth (the C-Chain) that implements a VM for Ethereum smart contracts, with custom modifications (such as configurable fees, merged hardfork behavior, and altered block formats) to operate within the Avalanche ecosystem. The Subnet EVM runs in a separate process and communicates with AvalancheGo via gRPC.
Main Components
• EVM Core Engine – Located in the “core” and “vm” directories, this represents the heart of the virtual machine with modules for block validation, state processing, trie management, transaction processing, and EVM instructions execution.
• APIs and RPC Layer – The “eth”, “rpc”, “internal/ethapi”, and “ethclient” directories implement several API namespaces (eth, personal, txpool, debug) and RPC servers that expose blockchain operations.
• Accounts and Keystore Management – The “accounts” directory contains code for account manipulation, key storage (both secure and plain formats), and helper functions for signing transactions.
• Consensus and Network Communication – Look at the “consensus”, “peer”, “sync”, and “node” directories. These components handle block propagation, peer connection, state synchronization, and chain management.
• Plugins and Precompiles – The “plugin” and “precompile” directories show how the system extends EVM functionality with additional precompile contracts and upgradeable functionality.
• Auxiliary Components – “metrics”, “trie”, “triedb”, “utils”, and “scripts” support logging, metrics collection, testing, building, and other operational features.
• Command Line Tools – The “cmd” directory includes various CLI tools (abigen, evm, simulator, etc.) that support testing, deployment, debugging, and simulation of the network.
Relationships and Data Flow
• That the Accounts subsystem supplies credentials and key management to the Core engine, facilitating transaction signing and verification.
• Consensus and Peer/Networking layers with the Core, noting that block production/validation and state synchronization occur across these modules.
• A communication channel (using gRPC) between the Subnet EVM process and AvalancheGo, highlighting how the Subnet EVM receives block data, configuration changes, or commands.
• Plugins and Precompiles as pluggable modules attached to the VM, indicating that they provide additional functionalities like custom precompiled contracts.
Architectural Patterns and Technologies
• That this is a modular, layered architecture typically seen in blockchain clients.
• That the system separates concerns by isolating state management, execution (EVM), API exposure, and networking.
• Mention the use of Go as the primary language and many conventions from the Ethereum ecosystem (e.g., RLP encoding, Keystore file formats).
• That many of the directories follow an MVC-like separation where the “core” and “vm” are the Model/execution logic, “eth”, “rpc”, and “api” form the Controller/API, and the “cmd” and “cli” tools act as clients or views.