Learn Ethereum: EVM
Week 3 Assignment 1

One day I decided to solve a problem that was plaguing us at work. I wanted to make something to streamline our resources and make it easier for use to do our job. I figured that there had to be something online for us to use. I fell down a rabbit hole and I loved it. So much so that I ended up building the solution myself.
Task 1: Register
If you haven’t already, register for this cohort by joining our Discord.
Task 2: Vocabulary
Prepare by familiarizing yourself with these key terms. I’ve broken them down into simple analogies to help you out! Be sure to take the quiz at the end when you are ready.
Key Terms for Ethereum Virtual Machine (EVM)
Ethereum Virtual Machine (EVM)
Definition: A decentralized virtual environment that runs smart contracts and ensures consistency across all Ethereum nodes.
Analogy: Think of the EVM as the operating system of Ethereum, like Windows or macOS for your computer, but it's spread across a network and runs programs (smart contracts) securely and consistently.
Smart Contracts
Definition: Self-executing agreements with the terms written into code, which are stored and run on the blockchain.
Analogy: Smart contracts are like vending machines—you insert money (input), and the machine automatically delivers your snack (output) without needing a human to oversee it.
State
Definition: The current condition of Ethereum, including all account balances, contracts, and data.
Analogy: Think of the state like a massive ledger or game save file—it tracks all player progress and changes (transactions) as they occur.
Merkle Patricia Trie
Definition: A data structure used to organize and verify Ethereum's state efficiently, linking all accounts and contracts with cryptographic hashes.
Analogy: Picture this as a tree where each leaf holds an account's data, and every branch leads back to a single root. It compresses all this information into a single, easy-to-check hash.
Stack Machine
Definition: A computational model that processes instructions by stacking data items and executing them in order.
Analogy: Imagine a stack of plates—each time you need to process something, you stack it on top or pull from the top. The EVM works by stacking and executing commands in a similar way.
State Transition Function
Definition: A mathematical function that, when given a valid state and transactions, produces a new state.
Analogy: This is like a factory where raw materials (initial state) go in, are processed (through transactions), and come out as finished products (new state).
Bytecode
Definition: The compiled version of smart contract code that the EVM executes.
Analogy: Bytecode is like the machine language your computer understands. Just as apps run on your computer after being compiled into code, smart contracts run on the EVM after being turned into bytecode.
EVM Opcode
Definition: Basic operations that the EVM can execute, such as ADD, SUB, and XOR, or blockchain-specific tasks like checking balances.
Analogy: OpCodes are like the commands you give to a robot. You can tell it to "pick up," "move," or "put down" items, and similarly, the EVM executes these specific actions.
EVM Implementation
Definition: Different versions of the EVM written in various programming languages, all following the same core rules.
Analogy: Just like there are different web browsers (Chrome, Firefox, Safari) but they all interpret websites the same way, different EVM implementations allow Ethereum to function consistently across different environments.
Task 3.1: Overview of the EVM
The EVM is like the "brain" of Ethereum, ensuring all nodes execute code in the same way. It runs smart contracts, which are like digital agreements that execute automatically, based on rules. To ensure this process is efficient and secure, it uses "gas," similar to how a car uses fuel to drive. Gas measures how much computational work is needed for each action on the blockchain.
Ethereum's distributed state machine
Ethereum is more than just a ledger, which simply tracks money like a bank book. It's a "distributed state machine," meaning it can change its state based on certain inputs. The state includes not just account balances but all kinds of data. Think of it as a giant machine that evolves with each new block of data, following specific rules, like how a video game evolves as the player progresses through levels.
The EVM processes inputs (like transactions) and outputs a new, updated state. This works like a function in math: if you give it a valid input, it will always give you the same result. For example, if you start with a valid blockchain state and feed it a set of transactions, the EVM updates the state accordingly.
Ethereum’s state is a large data structure known as the "Merkle Patricia Trie." It's like a massive tree that connects all accounts using cryptographic hashes. These hashes can be traced back to a single root, simplifying complex data into one identifiable piece, like compressing a large file into a smaller one.
The EVM works as a stack machine, similar to a conveyor belt where each item is stacked on top of the other. It processes commands (opCodes) like ADD (to add), SUB (to subtract), and other blockchain-specific ones like BALANCE (to check an account’s balance) . It uses temporary memory to perform actions, but only the important stuff is stored permanently in the global state.
Task 3.2: Read the docs
Read the official "Ethereum Virtual Machine (EVM)" section here.
After reading, you can take this comprehension quiz to test your understanding.
Task 4: Answer Discussion Questions
Now, it’s time to talk about what we’ve learned. You can answer the discussion questions here.
In what ways does the EVM's use of "gas" impact how developers write smart contracts?
How does Ethereum's approach as a "distributed state machine" differ from other blockchain models, like Bitcoin's ledger approach? What advantages does this give Ethereum in terms of functionality?
Why is it important for the EVM to have multiple implementations in different programming languages, and what challenges might this pose?





