Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Part 4 — EVM Mastery: Yul & Assembly

Prerequisites: Parts 1-3 completed

Goal: Go from reading assembly snippets to writing production-grade Yul — understand the machine underneath every DeFi protocol.

Why This Part Exists

Throughout Parts 1-3, you’ve encountered assembly in production code: mulDiv internals, proxy delegatecall forwarding, Solady’s gas optimizations, Uniswap’s FullMath. You could read it, roughly. Now you’ll learn to write it.

Assembly fluency is the single biggest differentiator for senior DeFi roles. Most candidates can write Solidity. Very few understand the machine underneath.

Module Overview

ModuleTopicWhat You’ll Learn
1EVM FundamentalsStack machine, opcodes, gas model, execution context
2Memory & Calldatamload/mstore, free memory pointer, calldataload, ABI encoding by hand
3Storage Deep Divesload/sstore, slot computation, mapping/array layout, storage packing
4Control Flow & Functionsif/switch/for in Yul, internal functions, function selector dispatch
5External Callscall/staticcall/delegatecall in assembly, returndata handling, error propagation
6Gas Optimization PatternsWhy Solady is faster, bitmap tricks, when assembly is worth it vs overkill
7Reading Production AssemblyAnalyzing Uniswap, OpenZeppelin, Solady — from an audit perspective
8Pure Yul ContractsObject notation, constructor vs runtime, deploying full contracts in Yul
9CapstoneReimplement a core DeFi primitive in Yul

Learning Arc

Understand the machine (M1-M3)
    → Write assembly (M4-M5)
        → Optimize (M6)
            → Read real code (M7)
                → Build from scratch (M8-M9)

By the End of Part 4

You will be able to:

  • Read any inline assembly block in production DeFi code
  • Write gas-optimized assembly for performance-critical paths
  • Understand why specific opcodes are chosen and their gas implications
  • Build and deploy pure Yul contracts
  • Analyze assembly from an auditor’s perspective
  • Present assembly work confidently in interviews

Navigation: Previous: Part 3