gas-optimization-foundry

Enforces a measurement-first workflow for reducing gas costs in Foundry projects using forge snapshot and diff.

16|4|Updated Mar 22, 2026
One-click install
npx skills add https://github.com/idchain-world/id-agents --skill gas-optimization-foundry
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: gas-optimization-foundry
Source: https://github.com/idchain-world/id-agents/tree/main/configs/agents/foundry-dev/skills/gas-optimization-foundry
Command: npx skills add https://github.com/idchain-world/id-agents --skill gas-optimization-foundry

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Reduces gas costs in Solidity Foundry projects by enforcing a measurement-first workflow that captures before/after diffs to validate gains.

Core Features & Use Cases

  • Enforces a measurement-first approach with forge snapshot, diff, and gas reporting to drive evidence-based optimizations.
  • Guides developers on where to apply optimizations (struct packing, immutables, calldata usage) to reduce gas costs in hot paths.
  • Example: When refactoring a hot function, use the baseline/diff workflow to quantify savings and validate improvements.

Quick Start

Run a baseline with forge snapshot, then iterate with diff and gas-report results to confirm improvements.

Frequently Asked Questions about gas-optimization-foundry

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

FAQPage Schema
How do I measure gas costs in a Foundry project before optimizing Solidity contracts?

To measure gas costs in a Foundry project, run a baseline capture using forge snapshot. This establishes initial gas usage metrics for your Solidity contracts before applying any optimization techniques.

What is the best way to validate gas optimizations when refactoring Solidity hot paths?

The best way to validate gas optimizations is a measurement-first workflow using forge snapshot. Capture a baseline, apply changes like struct packing, then run diff analysis to confirm quantified gas savings.

How does differential gas analysis work with forge snapshot?

Differential gas analysis with forge snapshot works by comparing baseline gas outputs against post-optimization results. This diff workflow quantifies exact savings, ensuring changes yield true gas improvements.

Can I use this measurement-first workflow to optimize Solidity libraries built with Foundry?

Yes, you can use this measurement-first workflow to optimize Solidity libraries built with Foundry. It guides developers through baseline capture and diff analysis specifically for Foundry environments.

When do I need to use struct packing and immutables for gas optimization?

You need struct packing and immutables for gas optimization when targeting hot paths in Solidity contracts. Use baseline measurements to identify these high-cost areas and validate improvements with diff analysis.

Why should I capture a baseline before applying gas optimization techniques in Solidity?

You should capture a baseline before applying gas optimization techniques to ensure evidence-based improvements. Without a baseline forge snapshot, you cannot accurately validate the true impact of your gas optimizations.