The RareSkills Book of Solidity Gas Optimization: 80+ Tips

Jeffrey Scholz
48 min readOct 13, 2023

Gas optimization in Ethereum is re-writing Solidity code to accomplish the same business logic while consuming fewer gas units in the Ethereum Virtual Machine (EVM).

Clocking in at over 11,000 words, not including source code, this article is the most complete treatment of gas optimization available.

To fully understand the tricks in this tutorial, you’ll need to understand how the EVM works, which you can learn by taking our Gas Optimization Course, Yul Course, and practicing Huff Puzzles.

However, if you simply want to know what areas of the code to target for possible gas optimizations, this article gives you a lot of areas to look.

Authorship

RareSkills researchers Michael Amadi (LinkedIn, Twitter) and Jesse Raymond (LinkedIn, Twitter) significantly contributed to this work.

Gas optimization tricks do not always work

Some gas optimization tricks only work in a certain context. For example, intuitively, it would seem that

if (!cond) {
// branch False
}
else {
// branch True
}

is less efficient than

if (cond) {
// branch True
}
else {
// branch False
}

--

--