solidity-gas-optimization

Reviews and refactors Solidity smart contracts to reduce EVM gas consumption.

1|Updated Sep 4, 2025
One-click install
npx skills add https://github.com/FuzzysTodd/The-Nexus-Protocol-Token-DAO --skill solidity-gas-optimization-fuzzystodd
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: solidity-gas-optimization
Source: https://github.com/FuzzysTodd/The-Nexus-Protocol-Token-DAO/tree/main/skills/solidity-gas-optimization
Command: npx skills add https://github.com/FuzzysTodd/The-Nexus-Protocol-Token-DAO --skill solidity-gas-optimization-fuzzystodd

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Solidity contracts often waste gas through inefficient storage writes, redundant reads, unpacked structs, and suboptimal compiler patterns, driving up deployment and transaction costs for users. This Skill provides a structured checklist of 80+ techniques to audit and refactor contracts for lower gas usage. ## Core Features & Use Cases - Storage Optimization: Avoid zero-to-one writes, cache storage reads, pack slots and structs, and use constant/immutable variables to eliminate expensive SLOADs and SSTOREs. - Compiler & Assembly Tuning: Apply unchecked math, named returns, branchless operations, and targeted inline assembly for hot paths. - Design-Level Savings: Evaluate architectural alternatives like ERC1155 vs ERC721, UUPS vs Transparent proxies, merkle trees vs ECDSA signatures, and multicall batching. - Use Case: A developer preparing for a Code4rena audit hands over an AMM contract; the Skill walks through storage, calldata, cross-contract, and deployment references to produce a prioritized list of gas savings with tradeoffs. ## Quick Start Review my Solidity contract for gas optimization opportunities and list the highest-impact changes with estimated savings.

Frequently Asked Questions about solidity-gas-optimization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce gas costs in a Solidity smart contract?▼

Start with storage optimizations: avoid zero-to-one writes, cache storage variables read more than once, pack structs and slots, and use constant or immutable for never-updated values. Then review loops, requires, and cross-contract calls, benchmarking each change with forge test --gas-report.

What are the biggest gas savings in Solidity?▼

The largest wins come from avoiding zero-to-non-zero storage writes (up to 17,100 gas saved), packing storage slots (20,000+ gas per avoided slot), caching redundant storage reads, and using custom errors instead of require strings. Design-level changes like ERC1155 or multicall batching can save even more.

Is inline assembly worth it for gas optimization?▼

Inline assembly saves gas in specific cases like reverts, external calls, and branchless math, but it removes compiler safety checks such as extcodesize verification and memory pointer management. Use it only after Solidity-level techniques, and always benchmark both versions.

Does uint8 use less gas than uint256 in Solidity?▼

No, smaller integer types do not save gas on operations because the EVM works in 32-byte words and the compiler inserts masking operations. Small types only save gas when two or more of them pack into the same storage slot.

Are gas optimization tricks the same across Solidity versions?▼

No, many tricks are version-dependent. For example, external vs public and != 0 vs > 0 no longer differ in modern compilers, and Solidity 0.8.22 auto-optimizes for-loops. The --via-ir flag can also invert results, so always benchmark on your target version.

When should I not apply gas optimizations?▼

Avoid aggressive optimization for rarely-called admin functions where readability matters more, and never use contest-grade techniques like encoding data in msg.value or ignoring send() return values in production code. These introduce loss-of-funds and correctness risks.