Tool 04 · Analysis · Free
Gas Optimization Analyzer
Twelve rules that find real gas waste, each with an estimated saving and an honest note about whether the optimisation risks changing behaviour. Because a “gas optimisation” that alters semantics is a bug, not a saving.
At a glance
Gas Optimization Analyzer
Run it
Press ⌘/Ctrl + Enter to analyse.
How it works
What this tool does, and what it can't.
The analyser parses your state variables and functions, then applies twelve rules ranked by how much they actually save. The top of that list is almost always the same: a state variable that is never reassigned outside the constructor should be immutable, which removes a 2,100-gas cold storage read from every single call that touches it.
Estimates use post-Berlin (EIP-2929) costs: 20,000 gas for a zero-to-non-zero SSTORE, 2,900 for non-zero to non-zero, 2,100 for a cold SLOAD, 100 for a warm one, and roughly 200 gas per byte of deployed bytecode.
Two rules matter beyond gas. An unbounded loop over a user-growable array is a denial-of-service vector, not just an expense — it is flagged as a security finding too. And a storage struct pointer swapped to memory silently discards writes, which is why that rule carries a correctness warning rather than a simple recommendation.
Marking constructor-set variables immutable and compile-time literals constant. Both are inlined into bytecode, so reads cost no storage access at all. In a contract that reads an address or a fee on every call, this is usually worth more than every other optimisation combined.
Yes, on both axes. Revert strings are stored in the runtime bytecode, so a 30-character message adds roughly 6,000 gas to deployment and makes the contract larger against the 24KB limit. A custom error carries a 4-byte selector instead, and gives callers structured data they can decode.
Since Solidity 0.8.22 the compiler removes the overflow check on loop counters automatically, so an explicit unchecked block is no longer needed for that case. Elsewhere, keep unchecked minimal, comment the invariant that makes it safe, and cover it with fuzz tests.
About five gas per iteration. Worth doing in a hot loop, not worth a pull request on its own. Take the storage and immutable wins first — they are two orders of magnitude larger.
It can. Every one of these transformations changes the code, and some change behaviour if applied without care — particularly the storage to memory switch and anything inside unchecked. Readability is a security property; do not trade it for five gas.
Beyond automation
No tool reads your specification. We do.
The findings that drain protocols come from state assumptions, economic design and cross-contract interaction — none of which a scanner sees. Free scoping in under two working days.