EVM deep dive
Understanding the ins and outs of the EVM is crucial for building highly optimized applications as each operation executed by the EVM has a gas cost attached to it and users have to pay the price for executing functions within the applications that they use. There is a compromise between readability and code optimizations however, which needs to be taken into consideration. Sometimes using techniques like bitshifting and bitmapping (Hacker’s Delight is a good book that talks about bit manipulation techniques in detail) can have a negative impact on readability and thus security, as other contributors and auditors may not be able to wrap their heads around these complex optimizations or it would simply take too much time for them to do so. For code that actually goes into production, each project needs to asses how much do they want to optimize their code for gas savings over readability. Security usually comes first, however there are still a set of well-known good practices that will allow you to save some gas. If you end up using gas optimization techniques it is also advised to document them well with comments inside of your Solidity contracts. Another important point is that as these technologies scale and developers are less constrained by the virtual machine executing smart contract bytecode, the needs for optimizations becomes less important along with the fact that the compilers converting static code to machine code are getting better and better at optimizing code for performance and low costs. As technologies like L2s and data availability layers become mainstream we also may see an emergence of new VM architectures that experiment with new designs that do not require developers to work with low-level optimizations as they will be highly performant and scalable.
For a comprehensive EVM deepdive, I suggest these resources:
- The EVM Handbook
- EVM development starter kit
- Read Chapter 13 (EVM) of The Ethereum Book
- Read Femboy Capital’s Playdate with the EVM
- Go over OpenZeppelin’s series on Deconstructing smart contracts
- Read Analyzing smart contracts by Elvira Albert (very math heavy)
- Read over TakeNobu’s slides on how the EVM works (visualized)
- Go over design patterns section
- Go over the exemplary good codebases at the beginning of the Solidity section
- Follow gas optimizoors like @transmission11 for gas alpha
- Get used to going to lookup gas costs for different OPCODE operations at EVM Codes
- Check out the EVM execution specs
- Learn to use Foundry well
- Bonus resources in comments of this Twitter thread
Special thanks to @0x_doggie and @freddycoen from whose threads I extrapolated these resources.
You might wanna go through Nick’s Posts and Jean’s Solidity articles