gas-optimization

gas-optimization is a skill for Claude Code, Codex from ccashwell/evm-cortex. It costs 51 tokens per session (1,475 once invoked), scanned A, original, MIT.

A collection of ways to reduce the amount of gas used by Solidity smart contracts. Gas is the fee paid for computation and storage on an Ethereum-compatible blockchain.

In plain words
What is it for?
Use it when reviewing gas-critical code, deployment cost, function execution, storage layout, calldata, custom errors, batching, and compiler settings.
Why use it?
It helps lower deployment and transaction costs, especially on frequently used or data-heavy contract paths. It also shows how to measure changes before adopting them.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it when reviewing gas-critical code, deployment cost, function execution, storage layout, calldata, custom errors, batching, and compiler settings.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/ccashwell/evm-cortex/gas-optimization
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add ccashwell/evm-cortex --skill gas-optimization
Clone the repo
git clone --depth 1 https://github.com/ccashwell/evm-cortex

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for gas-optimization

README.md
[![agentmods](https://agentmods.dev/badge/skills/ccashwell/evm-cortex/gas-optimization/github.svg)](https://agentmods.dev/skills/ccashwell/evm-cortex/gas-optimization)
Your own site
<a href="https://agentmods.dev/skills/ccashwell/evm-cortex/gas-optimization"><img src="https://agentmods.dev/badge/skills/ccashwell/evm-cortex/gas-optimization/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for gas-optimization

Your own site · 80×15
<a href="https://agentmods.dev/skills/ccashwell/evm-cortex/gas-optimization"><img src="https://agentmods.dev/badge/skills/ccashwell/evm-cortex/gas-optimization.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 51 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,475 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00051 $0.01475
Opus 5.5 $0.00020 $0.00590
Sonnet 5.5 $0.00010 $0.00295
Haiku 4.5 $0.00005 $0.00147

Measured 1mo ago against content hash 1e551f1acaa3, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

gas-optimization scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/gas-optimization/SKILL.md · 218 lines

How it starts

The opening of the file, as written. The whole thing — 218 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Gas Optimization

Measure First

Never optimize blindly. Use forge snapshots and gas reports.

# 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").

// 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.

// 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

// 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).

// 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; }
}

Read the full file on GitHub · 218 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 218 lines · 51 tokens per session scan A 1e551f1acaa3

Subscribe to this mod's changes

gas-optimization is a skill published in the GitHub repository ccashwell/evm-cortex (131 stars, last pushed 17d ago), licensed MIT. It adds 51 tokens to every session and 1,475 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.