Agent skill

Gas Optimization

by ccashwell in ccashwell/evm-cortex

Gas optimization patterns for Solidity smart contracts. An agent skill from ccashwell/evm-cortex.

MITAuto-check passedBackend & APIs

Install Gas Optimization

skills CLI
$ npx skills add ccashwell/evm-cortex --skill gas-optimization -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install ccashwell/evm-cortex gas-optimization --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/ccashwell/evm-cortex.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/gas-optimization .claude/skills/gas-optimization && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
gas-optimization
GitHub stars
131
Token cost
~1.5k tokens
SKILL.md length
273 words
Files
1
Skills in repo
89
Repo updated
First seen
Licence
MIT

At a glance

Gas optimization patterns for Solidity smart contracts. An agent skill from ccashwell/evm-cortex.

  • Optimizing contract deployment cost
  • SKILL.md covers Measure First, Custom Errors Over Require…, Calldata vs Memory and Immutable and Constant, plus 11 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Runtime gas usage

What it does

Gas Optimization is an agent skill from ccashwell/evm-cortex. Gas optimization patterns for Solidity smart contracts. Use when optimizing contract deployment cost, runtime gas usage, or reviewing gas-critical paths. Covers calldata vs memory, immutable/constant, unchecked blocks, storage packing, batch operations, and custom errors.

Its SKILL.md is about 1.5k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Backend & APIs, covering Smart contracts. It works with Solidity. The repository describes itself as: Ethereum protocol engineering squad for AI coding assistants. The licence is MIT.

When your agent uses it

  • Optimizing contract deployment cost
  • Runtime gas usage
  • Reviewing gas-critical paths

Example prompts

  • “/gas-optimization”

What it can do on your machine

Read from SKILL.md and the folder at commit f8f3301. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are solidity and bash).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Gas Optimization loads about 1.5k tokens when it runs. Until then it costs about 72 tokens; SKILL.md has 273 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~72
When it runs · the whole SKILL.md, loaded when a task matches
~1.5k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from ccashwell/evm-cortex at commit f8f3301, republished under its MIT licence (© ccashwell). 273 words, ~1,538 tokens.

Download SKILL.mdSave it as .claude/skills/gas-optimization/SKILL.md (or your agent's skills folder).
name
gas-optimization
description
Gas optimization patterns for Solidity smart contracts. Use when optimizing contract deployment cost, runtime gas usage, or reviewing gas-critical paths. Covers calldata vs memory, immutable/constant, unchecked blocks, storage packing, batch operations, and custom errors.

Gas Optimization

Measure First

Never optimize blindly. Use forge snapshots and gas reports.

bash
# Gas report for all tests
forge test --gas-report

# Snapshot to compare before/after
forge snapshot
# ...make changes...
forge snapshot --diff

Custom Errors Over Require Strings

Custom errors save ~50 gas on deployment and ~200 gas per revert vs require("string").

solidity
// BAD: ~24,000 gas on revert (stores string in bytecode + memory)
require(amount > 0, "Amount must be greater than zero");

// GOOD: ~24 gas for error selector encoding
error ZeroAmount();
if (amount == 0) revert ZeroAmount();

Calldata vs Memory

Use calldata for read-only external function parameters. Avoids copying to memory.

solidity
// BAD: copies entire array to memory (~3 gas per byte + allocation)
function processOrders(Order[] memory orders) external { ... }

// GOOD: reads directly from calldata
function processOrders(Order[] calldata orders) external { ... }

// Gas savings scale with input size:
// 100 bytes: ~600 gas saved
// 1KB:       ~6,000 gas saved
// 10KB:      ~60,000 gas saved

Immutable and Constant

solidity
// constant: compile-time value, inlined everywhere. 0 gas for SLOAD.
uint256 public constant MAX_SUPPLY = 10_000;
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name)");

// immutable: set once in constructor, stored in bytecode. 0 gas for SLOAD.
address public immutable FACTORY;
uint256 public immutable DEPLOYMENT_TIMESTAMP;

constructor(address factory) {
    FACTORY = factory;
    DEPLOYMENT_TIMESTAMP = block.timestamp;
}

// Regular storage variable: 2,100 gas (cold) or 100 gas (warm) per SLOAD
address public admin; // avoid if value never changes after deployment

Unchecked Arithmetic

When overflow is impossible (e.g., loop counters bounded by array length), use unchecked to skip overflow checks (~40 gas per operation).

solidity
// BAD: overflow checks on every increment
for (uint256 i = 0; i < arr.length; i++) { ... }

// GOOD: i cannot overflow (bounded by array length, which fits in uint256)
for (uint256 i; i < arr.length;) {
    // process arr[i]
    unchecked { ++i; }
}

Cache Storage Reads

Every SLOAD costs 2,100 gas (cold) or 100 gas (warm). Cache values read more than once.

solidity
// BAD: 3 SLOADs for totalSupply
function distribute() external {
    if (totalSupply == 0) revert NoSupply();           // SLOAD 1
    uint256 perToken = rewards / totalSupply;           // SLOAD 2
    emit Distributed(perToken, totalSupply);            // SLOAD 3
}

// GOOD: 1 SLOAD, cached in memory
function distribute() external {
    uint256 supply = totalSupply;                       // SLOAD 1 (cached)
    if (supply == 0) revert NoSupply();
    uint256 perToken = rewards / supply;
    emit Distributed(perToken, supply);
}

Storage Packing

Pack related variables into single 32-byte slots. See storage-layout skill for details.

solidity
// BAD: 3 slots
uint256 amount;     // slot 0
address user;       // slot 1
bool active;        // slot 2

// GOOD: 2 slots
uint256 amount;     // slot 0
address user;       // slot 1 (20 bytes)
bool active;        // slot 1 (packed, +1 byte)

Writing to packed slots together in one transaction saves ~20,000 gas (avoids separate SSTORE).

Short-Circuit Evaluation

Put cheap checks first in && / || chains.

solidity
// BAD: expensive SLOAD first
if (balances[msg.sender] > minBalance && isWhitelisted) { ... }

// GOOD: cheap check first, SLOAD only if needed
if (isWhitelisted && balances[msg.sender] > minBalance) { ... }

Batch Operations

Amortize fixed overhead (21,000 base gas, cold SLOADs) across multiple operations.

solidity
function batchTransfer(
    IERC20 token,
    address[] calldata recipients,
    uint256[] calldata amounts
) external {
    uint256 len = recipients.length;
    if (len != amounts.length) revert ArrayLengthMismatch();

    for (uint256 i; i < len;) {
        token.safeTransfer(recipients[i], amounts[i]);
        unchecked { ++i; }
    }
}

Avoid Redundant Zero Initialization

The EVM initializes all values to zero. Explicit zero assignment wastes gas.

solidity
// BAD: redundant zero init
uint256 counter = 0;
bool flag = false;

// GOOD: default is already zero/false
uint256 counter;
bool flag;

Use Bytes32 Over String for Short Constants

solidity
// BAD: dynamic string requires more gas
string public constant NAME = "MyToken";

// GOOD: fixed-size, cheaper to read
bytes32 public constant NAME = "MyToken";

Precompute Keccak256 Hashes

solidity
// BAD: computed at runtime every call
function hasRole(string memory role) external view {
    bytes32 hash = keccak256(abi.encodePacked(role));
    ...
}

// GOOD: precomputed constant
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");

Function Ordering by Selector

The Solidity dispatcher checks function selectors in order. Frequently called functions with lower selectors dispatch faster. Not worth manual optimization unless the contract has 50+ external functions.

Gas Optimization Checklist

OptimizationTypical Savings
Custom errors vs require strings~200 gas/revert
calldata vs memory~600+ gas/call
immutable vs storage~2,100 gas/read
Unchecked loop increment~40 gas/iteration
Cache storage reads~100-2,100 gas/read
Storage packing~20,000 gas/write
++i vs i++~5 gas/iteration
Zero-init removal~3 gas/variable

When NOT to Optimize

  • Readability loss outweighs savings for admin-only / rare-path functions
  • One-time setup functions (constructors, initializers)
  • Gas savings under 100 gas in non-hot paths
  • Assembly tricks without measured benchmarks

© ccashwell, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/gas-optimization of ccashwell/evm-cortex.

Open the folder on GitHubat commit f8f3301

Compare with similar skills

Gas Optimization next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Gas Optimization compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Gas Optimization this skillccashwell/evm-cortex131—~1.5kAutomated safety check: PassMIT
Fizz Convertpashov/skills1.2k2 repos~3.7kAutomated safety check: PassMIT
Feynman Auditor0xiehnnkta/nemesis-auditor2441 repos~11kAutomated safety check: PassMIT
Smart Contract Auditgreatpie/smart-contract-audit-skill101—~1.1kAutomated safety check: PassNone
RadarAuditware/radar154—~2.1kAutomated safety check: PassGPL-3.0
Solidity AuditorGabson0x/bountyforge443—~3.7kAutomated safety check: PassNone

Similar skills

  • Fizz Convert

    pashov/skills

    Convert English-language properties in PROPERTIES.md (produced by the Fizz skill) into Solidity assertions inside the existing fuzz harness, then flip their checkboxes.

    1.2k GitHub starsUsed in 2 repos~3.7k tokens
    Backend & APIsAuto-check passed
  • Feynman Auditor

    0xiehnnkta/nemesis-auditor

    Deep business logic bug finder using the Feynman technique. An agent skill from 0xiehnnkta/nemesis-auditor.

    244 GitHub starsUsed in 1 repo~11k tokens
    Backend & APIsAuto-check passed
  • Smart Contract Audit

    greatpie/smart-contract-audit-skill

    Script-backed, out-of-box auditing workflow for Solidity/EVM repositories based on EVMbench detect/patch/exploit methodology.

    101 GitHub stars~1.1k tokensUpdated 7 mo ago
    Backend & APIsAuto-check passed
  • Radar

    Auditware/radar

    Use radar for smart contract security analysis, AST generation, and detection template development.

    154 GitHub stars~2.1k tokensUpdated 1 mo ago
    Backend & APIsAuto-check passed
  • Solidity Auditor

    Gabson0x/bountyforge

    Security audit of Solidity code while you develop. An agent skill from Gabson0x/bountyforge.

    443 GitHub stars~3.7k tokensUpdated 21 days ago
    Backend & APIsAuto-check passed
  • Add Explorer

    lidofinance/diffyscan

    Adds or repairs Diffyscan explorer API routing and response adapters for a new host, chain or payload format.

    142 GitHub stars~1k tokensUpdated yesterday
    Backend & APIsAuto-check passed

More from ccashwell/evm-cortex

All 89 skills in this repo
  • Xray Pre Audit

    ccashwell/evm-cortex

    A skill your agent uses when preparing for a security audit, performing reconnaissance on a new codebase, or creating a protocol overview.

    131 GitHub stars~25k tokensUpdated 8 days ago
    Auto-check passed
  • Aave Integration

    ccashwell/evm-cortex

    A skill your agent uses when integrating with Aave V3 for lending, borrowing, flash loans, or building on top of Aave markets.

    131 GitHub stars~1.3k tokensUpdated 8 days ago
    Auto-check passed
  • Access Control Patterns

    ccashwell/evm-cortex

    Access control design patterns for Solidity protocols. An agent skill from ccashwell/evm-cortex.

    131 GitHub stars~1.8k tokensUpdated 8 days ago
    Auto-check passed
  • Anvil Patterns

    ccashwell/evm-cortex

    A skill your agent uses when running a local Ethereum node with Anvil.

    131 GitHub stars~1.3k tokensUpdated 8 days ago
    Auto-check passed
  • Audit Breadth Scan

    ccashwell/evm-cortex

    A skill your agent uses when performing systematic breadth-first review of all contracts during a security audit.

    131 GitHub stars~1.4k tokensUpdated 8 days ago
    Auto-check passed
  • Audit Depth Analysis

    ccashwell/evm-cortex

    A skill your agent uses when performing deep analysis of specific findings or high-risk areas during a security audit.

    131 GitHub stars~1.6k tokensUpdated 8 days ago
    Auto-check passed

Works with

Categories

Questions about Gas Optimization

What does Gas Optimization do?

Gas optimization patterns for Solidity smart contracts. An agent skill from ccashwell/evm-cortex. Gas Optimization is an agent skill from ccashwell/evm-cortex. Gas optimization patterns for Solidity smart contracts.

When should I use Gas Optimization?

Gas Optimization fits situations like: optimizing contract deployment cost; runtime gas usage; reviewing gas-critical paths.

How do I install Gas Optimization in Claude Code?

Run `npx skills add ccashwell/evm-cortex --skill gas-optimization -a claude-code`. Or copy the skill folder (skills/gas-optimization in ccashwell/evm-cortex) into .claude/skills/gas-optimization in your project. Claude Code loads it when a task matches its description.

How do I install Gas Optimization in Codex?

Run `npx skills add ccashwell/evm-cortex --skill gas-optimization -a codex`. Or copy the skill folder (skills/gas-optimization in ccashwell/evm-cortex) into .agents/skills/gas-optimization in your project. Codex loads it when a task matches its description.

Can I use Gas Optimization in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add ccashwell/evm-cortex --skill gas-optimization -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/gas-optimization, .gemini/skills/gas-optimization, .github/skills/gas-optimization and .opencode/skills/gas-optimization in your project.

What does Gas Optimization need to run?

SKILL.md names no scripts, command-line tools or credentials: Gas Optimization is instructions for the agent only.

Does Gas Optimization access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Gas Optimization safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Gas Optimization use?

Gas Optimization is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Gas Optimization use?

About 1.5k tokens (SKILL.md is roughly 6.2k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Gas Optimization?

Skills that share tags, products or a category with Gas Optimization: Fizz Convert (pashov/skills, 1.2k stars), Feynman Auditor (0xiehnnkta/nemesis-auditor, 244 stars), Smart Contract Audit (greatpie/smart-contract-audit-skill, 101 stars) and Radar (Auditware/radar, 154 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Gas Optimization?

ccashwell (a GitHub user) maintains it in ccashwell/evm-cortex, which has 131 GitHub stars. The repository holds 89 skills in this directory. The repository was last updated on September 30, 2026.

Source: ccashwell/evm-cortex on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.