- Describe the EVM as a deterministic, stack-based state machine.
- Distinguish stack, memory, storage and calldata.
- Read simple opcodes and explain how gas is charged for them.
- Explain the ABI, function selectors and EVM-compatible chains.
What is the EVM?
- Deterministic: the same transaction on the same state produces exactly the same result on every node.
- Isolated (sandboxed): contract code cannot access the node’s files, network or clock directly.
- Metered: every instruction costs gas, so execution always terminates (Chapter 12).
- Stack-based with a word size of 256 bits, which suits Keccak-256 hashes and elliptic-curve arithmetic.
Where Data Lives in the EVM
| Area | Description | Lifetime | Cost |
|---|---|---|---|
| Stack | Holds operands for instructions; up to 1,024 items of 256 bits. | During one execution | Cheapest |
| Memory | Byte-addressed, expandable scratch space. | During one call | Cheap, grows with size |
| Storage | Persistent key–value store of 256-bit slots belonging to the contract. | Permanent (on-chain) | Most expensive |
| Calldata | Read-only input data of the transaction or call. | During one call | Cheap to read |
| Code | The contract’s immutable bytecode. | Permanent | Paid at deployment |
| Logs | Event data written to receipts; readable off-chain, not by contracts. | Permanent (in receipts) | Cheaper than storage |
Opcodes and Bytecode
Compilers such as solc (Solidity) and Vyper translate source code into bytecode – a sequence of one-byte opcodes and their data.
| Opcode | Hex | Action |
|---|---|---|
| ADD | 0x01 | Pop two values, push their sum. |
| MUL | 0x02 | Pop two values, push their product. |
| KECCAK256 | 0x20 | Hash a region of memory. |
| CALLDATALOAD | 0x35 | Read 32 bytes of input data. |
| MSTORE | 0x52 | Write a word to memory. |
| SLOAD / SSTORE | 0x54 / 0x55 | Read / write contract storage. |
| PUSH1 | 0x60 | Push a one-byte constant onto the stack. |
| CALL | 0xF1 | Call another contract or send ETH. |
| RETURN / REVERT | 0xF3 / 0xFD | End execution returning data / undo state changes. |
Example: the bytecode 60 03 60 05 01 means PUSH1 3, PUSH1 5, ADD – leaving 8 on the stack.
ABI and Function Selectors
- The ABI (Application Binary Interface) defines how to encode function calls and decode return values and events.
- The first 4 bytes of a call’s data are the function selector = first 4 bytes of Keccak-256 of the function signature. For example,
transfer(address,uint256)→0xa9059cbbandbalanceOf(address)→0x70a08231. - Arguments follow, each padded to 32 bytes.
- Contracts call each other with
CALL, read-onlySTATICCALL, orDELEGATECALL(runs another contract’s code in the caller’s storage – the basis of proxy upgrade patterns).
EVM-Compatible Chains
Many blockchains and Layer-2 networks run the EVM, so the same Solidity contracts, wallets and tools work on them with little or no change. Examples include Layer-2 rollups such as Arbitrum, Optimism and Base, and other networks such as BNB Smart Chain, Polygon PoS and Avalanche C-Chain. This shared standard is a major reason for Ethereum’s large developer ecosystem.
Key Takeaways
- The EVM is a deterministic, sandboxed, 256-bit stack machine replicated on every node.
- Storage is permanent and costly; memory, stack and calldata are temporary and cheaper.
- Calls are ABI-encoded: 4-byte selector + 32-byte padded arguments.
Question / Answer (15 questions)
MCQ Test : Check Your Understanding (5 questions)
Select an option and press Check Answer, or answer all questions and press Submit Test to see your score. Each answer comes with an explanation.
Bibliography/References
The notes, questions and MCQs on this page are original explanations written for this course. The works listed below were consulted and are cited for attribution and further reading. Product names, logos and trademarks belong to their respective owners. Short quotations, where used, are marked and attributed.
- ethereum.org. (n.d.). Ethereum Virtual Machine (EVM). Ethereum Developer Documentation. https://ethereum.org/en/developers/docs/evm/
- ethereum.org. (n.d.). Opcodes for the EVM. Ethereum Developer Documentation. https://ethereum.org/en/developers/docs/evm/opcodes/
- Wood, G. Ethereum: A Secure Decentralised Generalised Transaction Ledger (Ethereum Yellow Paper). https://ethereum.github.io/yellowpaper/paper.pdf
- Crytic (Trail of Bits). (n.d.). evm-opcodes: Ethereum VM (EVM) opcodes and instruction reference. GitHub. https://github.com/crytic/evm-opcodes
- Solidity Team. (n.d.). Solidity Documentation. https://docs.soliditylang.org/
- Antonopoulos, A. M., & Wood, G. (2018). Mastering Ethereum: Building Smart Contracts and DApps. O’Reilly Media.