Track 9 · What now · lesson 1
Reading production code
30 min
You can write contracts now. The next skill is reading ones you did not write — because that is most of the job, whether you are auditing, integrating, or learning from the best.
Start with Uniswap V2's core pair contract. It is about 350 lines, it has secured billions of dollars for years, and every line is there for a reason you can now work out. It is widely considered some of the best Solidity ever written, and it is short enough to read in an afternoon.
How to read a contract you don't know
Not top to bottom. Follow this order and it goes far faster:
- State variables first. What does this contract remember? That tells you what it fundamentally is before you read a single function.
- The external functions. What can the outside world make it do? These are the entry points, and the whole attack surface.
- Follow the money. Every place value moves in or out. That is where bugs live and where your track 7 instincts earn their keep.
- Then the internals, only as needed to understand the above.
What to notice in Uniswap V2
- The
reserve0/reserve1accounting, and thek = x * yinvariant the whole thing protects. - The reentrancy
lockmodifier — the guard from track 7, in production. - The TWAP accumulators — the manipulation-resistant oracle from track 7's oracle lesson, at their source.
- The deliberate use of
unchecked-style overflow behaviour, with comments explaining exactly why it is safe there.
Predict
When reading an unfamiliar contract, why start with its state variables?
Where to find good code
- OpenZeppelin — the library you have leaned on, and a masterclass in defensive, well-commented Solidity.
- Uniswap, Aave, Compound — the foundational DeFi protocols, all open and audited.
- Solady — hyper-optimised implementations, for when you want to see how far gas can be pushed (and how unreadable that gets).
Check
What's the fastest way to understand what an unfamiliar contract does?
Worth remembering
- Reading contracts you didn't write is most of the real job.
- Uniswap V2's pair contract is ~350 lines of exemplary, readable Solidity — start there.
- Read in order: state, external functions, value flows, then internals as needed.
- You'll recognise reentrancy guards and TWAP oracles from track 7 in production.
- OpenZeppelin, Uniswap, Aave and Solady are the code worth studying.