Problem Statement
Currently, we're removing explicit gas tests from our codebase because they're brittle and require constant maintenance. However, we still need visibility into gas usage changes to catch performance regressions and track optimization improvements.
Proposed Solution
Integrate forge snapshot into our CI/CD workflow to automatically track and report gas usage changes on every pull request.
Implementation Goals
- Automatic Gas Tracking: Run
forge snapshot on every PR to capture current gas usage
- Comparison Reports: Compare gas usage against the base branch
- PR Comments: Post detailed gas comparison as a comment on each PR
- Visual Feedback: Show gas increases/decreases with clear indicators (🔴 ↑ / 🟢 ↓)
- Non-blocking: Gas changes should be informative but not block PR merging
Technical Requirements
Core Features
Nice-to-Have Features
Expected Output Example
The bot should post a comment like:
📊 Gas Report
Comparing gas usage between main and feature-branch (commit abc123)
| Contract |
Function |
Before |
After |
Change |
| LibOwner |
transferOwnership() |
19,099 |
18,950 |
🟢 -149 (-0.78%) |
| LibOwner |
owner() |
7,486 |
7,486 |
⚪ 0 (0.00%) |
| AccessControlFacet |
grantRole() |
41,349 |
42,100 |
🔴 +751 (+1.82%) |
| AccessControlFacet |
revokeRole() |
12,947 |
12,947 |
⚪ 0 (0.00%) |
Summary:
- Total functions analyzed: 127
- Improved: 15 functions (🟢 -2,341 gas total)
- Regressed: 8 functions (🔴 +1,892 gas total)
- Unchanged: 104 functions
- Net change: 🟢 -449 gas (-0.35%)
View detailed report
[Full gas snapshot diff]
Implementation Steps
-
Create .gas-snapshot baseline file
- Run
forge snapshot on main branch
- Commit the snapshot file (or store as artifact)
-
Create GitHub Actions workflow
- Trigger on
pull_request events
- Check out both base and head branches
- Generate snapshots for both
- Run comparison and format output
- Post/update PR comment
-
Add forge snapshot configuration
- Configure snapshot options in
foundry.toml
- Set appropriate filters to exclude test contracts
- Define snapshot check tolerances
-
Documentation
- Add section to README about gas tracking
- Document how to run snapshots locally
- Explain how to interpret the reports
Benefits
- Automatic Tracking: No manual intervention needed
- Visibility: Clear view of performance impact for every change
- Historical Context: Can track gas optimization progress over time
- No Maintenance: Unlike explicit gas tests, snapshots auto-update
- Team Awareness: Everyone sees gas impact before merging
Acceptance Criteria
References
Priority
High - This will provide immediate value by:
- Replacing our removed gas tests with better visibility
- Preventing performance regressions
- Highlighting optimization opportunities
- Improving PR review quality
Problem Statement
Currently, we're removing explicit gas tests from our codebase because they're brittle and require constant maintenance. However, we still need visibility into gas usage changes to catch performance regressions and track optimization improvements.
Proposed Solution
Integrate
forge snapshotinto our CI/CD workflow to automatically track and report gas usage changes on every pull request.Implementation Goals
forge snapshoton every PR to capture current gas usageTechnical Requirements
Core Features
Nice-to-Have Features
Expected Output Example
The bot should post a comment like:
📊 Gas Report
Comparing gas usage between
mainandfeature-branch(commit abc123)Summary:
View detailed report
[Full gas snapshot diff]
Implementation Steps
Create
.gas-snapshotbaseline fileforge snapshoton main branchCreate GitHub Actions workflow
pull_requesteventsAdd forge snapshot configuration
foundry.tomlDocumentation
Benefits
Acceptance Criteria
References
Priority
High - This will provide immediate value by: