solidity-gas-optimization

Installation
SKILL.md

Solidity Gas Optimization

A reference toolkit of 80+ techniques for reducing gas consumption in Solidity contracts. Use it as a checklist when reviewing or refactoring code, and as an explainer when the user asks why a particular pattern is cheaper.

Core mindset

Before applying any technique, internalize these principles. They matter more than memorizing tricks.

Gas optimizations are not universal

Many "tricks" are context-dependent. The Solidity compiler is unpredictable — a transformation that looks like it should save gas can cost more in practice because of how the optimizer or stack scheduler reacts. The classic example: inverting an if/else to avoid a negation seems cheaper, but often isn't. Always benchmark both versions of any optimization rather than applying it on faith. Use Foundry's forge test --gas-report or similar tooling.

Some techniques behave differently under the --via-ir compiler flag than under the legacy pipeline. If the project uses via-ir, retest accordingly.

Readability vs. savings is a tradeoff

Most gas optimizations make code harder to read, harder to audit, and easier to break during future edits. A subjective judgment is always required: is saving 200 gas worth obscuring the intent? For one-shot admin functions called rarely, almost never. For a hot inner loop in an AMM, often yes. Mention this tradeoff to the user when suggesting aggressive optimizations.

Some areas are out of scope here

Installs
4
GitHub Stars
1
First Seen
Oct 26, 2026