“How can I quickly understand protocol X?” is one of the most common questions I get.
Reading code written by strangers is never easy. Protocols are only getting more complex so it feels like our ability to comprehend them can slip away if we don't stay up to date.
But reading and understanding smart contracts written by other developers can also be highly educational.
It can help you discover everything from high-level design patterns to low-level programming ideas.
As a Python developer, you may not need to read the code of the dependencies you interact with, often understanding the API is enough.
This is not the case if you are a smart contract developer.
Adding a library dependency like OpenZeppelin or using a protocol like Uniswap? You are inheriting the security surface of the third-party code and should understand it well.
This doesn't have to be a boring exercise of reading the code line-by-line, however.
In this newsletter, I’ll explain 7 other ways of quickly understanding how a protocol works.
1. Watch a Video Explainer
YouTube is a great starting point when learning about a new protocol. Videos can help you understand both how the protocol is seen by the end-users and by its developers.
You can progress by starting with 5-10 minute videos introducing how to use a protocol all the way to 1 hour protocol deep-dives or podcast interviews from the developers.
Over the past couple of years, we have seen steady growth of web3 content on YouTube and most popular protocols now have dedicated explanations in this format.
My favorite channel: https://www.youtube.com/@SolidityFridays.
2. Interact with the Protocol
To truly understand the intricacies of a smart contract protocol, it is essential to gain hands-on experience by interacting with it.
The first and best step is usually to use a testnet account or a DeFi simulator, such as https://defi.instadapp.io.
By doing so, you can safely explore and experiment with the protocol's various features without risking real assets.
It can also be helpful to look at competing protocols and consider any differences (e.g., comparing the UX of fixed-rate or variable-rate lending protocols).
3. Read the Whitepaper
While this can be a time-consuming step, reading the Whitepaper can be helpful in both understanding the overall goals and assumptions going into a protocol design.
The Whitepaper will also reference concepts that are prerequisite to fully grasping the project.
For example, if you are looking to study Balancer, it is important to understand Uniswap V1 first as Balancer can be seen as a continuation of the 2-asset constant product market maker idea.
Another related concept is the idea of protocol simulations. Some protocols provide Python notebooks that illustrate the relevant concepts. Reading the simplified implementation in Python can be easier than going through a gas-optimized Solidity codebase.
4. Study Other Resources
The majority of widely recognized cryptocurrency protocols feature a dedicated resource hub, typically referred to as "awesome-X", with X representing the protocol's name.
These hubs provide an extensive collection of educational materials, such as articles, multimedia content, and programming examples that can help you get up to speed more quickly.
It is not uncommon to find these resources integrated into the official project documentation hosted on the protocol's website, or shared and discussed within the project's Discord community.
For instance, Uniswap V3, a prominent decentralized exchange, maintains an "awesome" repository that can be accessed via the following link: https://github.com/GammaStrategies/awesome-uniswap-v3#guides.
5. Use a Visual Inspector
When attempting to better understand a complex protocol, it's advisable to employ a visual inspection tool, such as Surya, which enables you to clearly visualize the major components and their interactions.
By using Surya or a similar tool, you'll gain valuable insights into how the elements within the system work together and influence each other.
As a starting point, try the control flow graph, the inheritance graph, and the describe report.
6. Explore Transactions
Users interact with a protocol via transactions. By exploring the most common transaction flows, you can quickly identify the steps, code files and dependencies that matter the most.
To do this, start by selecting a transaction and navigating to Etherscan or an equivalent block explorer.
There are several aspects of the transaction that you could consider exploring:
Identify the precise function that was called during the transaction, as well as the arguments that were used. To access this information, click on "Click to see More", followed by "Decode Input Data". This will reveal the function call and its parameters if the source code is available,
Investigate the state changes that occurred as a result of the transaction. Understanding these changes can provide valuable insights into the effects of the transaction on the underlying system.
For an even more in-depth analysis, consider utilizing a transaction debugger, such as Tenderly or EthTxInfo.
These tools allow you to look at a transaction at stack trace level and Tenderly even allows you to show what code files are referenced during execution.
They are far from a beginner's crutch. Even the best security brains in this space like samczsun use debuggers and tracers.
7. Join the Community
Last but not least, diving into Discord or wherever the protocol community is based can build understanding on how a protocol is used right now.
Moreover, the community can often help by answering more specific questions that arise during your research.
Whether you are an auditor or developer, understanding third-party code bases is an essential part of being in this space and doesn't have to be boring.
Use these steps in sequence or even better – use them in a loop as Chris Dior recommends:
There is nothing that can truly replace reading the code line-by-line but using the above techniques to prepare will speed up that process and make it much more enjoyable.
Need help building a crypto product?
→ Twitter: Follow me for more frequent & casual insights on the crypto industry.
→ 1:1 Coaching: I help Seed stage crypto Founders design & ship highly-technical crypto products with proven systems. Book a free discovery call to see if I can help.
Respond to this e-mail if you have any feedback or questions.
an exercise could be building a discord events bot -- something fun that I did.
you hit a lot of the points you mention
- interacting with the protocol
- finding and understanding transactions to track
- interaction with the team when you run into questions