Skip to content

feat: add gas benchmarks to CI#170

Merged
iap merged 7 commits into
devfrom
feat/add-gas-benchmarks
May 19, 2026
Merged

feat: add gas benchmarks to CI#170
iap merged 7 commits into
devfrom
feat/add-gas-benchmarks

Conversation

@iap

@iap iap commented May 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds gas snapshot tracking to catch gas regressions early.

Changes

  • Gas snapshot baseline: 158 test gas measurements
  • Makefile targets:
    • make gas-snapshot: generate new snapshot
    • make gas-check: verify against baseline
  • CI integration: gas check runs after tests

Benefits

  • Catch gas regressions before merge
  • Track gas usage over time
  • Prevent accidental gas increases

Verification

cd contracts
make gas-snapshot  # Generate baseline
make gas-check     # Verify (should pass)

Risk

Low - adds monitoring only, no code changes.

Related

iap added 3 commits May 19, 2026 15:11
- Generated with forge snapshot
- 158 test gas measurements
- Baseline for tracking gas regressions
- make gas-snapshot: generate new snapshot
- make gas-check: verify against baseline
- Runs after tests in contracts-unit-invariant job
- Fails CI if gas usage increases significantly
- Addresses #164
@iap iap requested a review from a team as a code owner May 19, 2026 08:14
@github-actions

github-actions Bot commented May 19, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@greptile-apps

greptile-apps Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a forge snapshot-based gas regression guard to the Contracts CI, committing a 148-test baseline and two new Makefile targets (gas-snapshot / gas-check). It also removes .nvmrc and pnpm-workspace.yaml (both were single-entry/root-only files) and updates CONTRIBUTING.md to reflect mise as the sole Node.js version manager.

  • Gas snapshot baseline (contracts/.gas-snapshot): 148 unit/e2e measurements captured by forge snapshot, with invariant and integration tests excluded via --nmp \"test/{invariant,integration}/**\".
  • Makefile targets: gas-snapshot generates the baseline; gas-check re-runs the same filtered test set against the stored baseline with a 2% tolerance, failing if any test regresses beyond that threshold.
  • CI step: make gas-check is appended to the contracts-unit-invariant job, gating downstream jobs on no gas regressions.

Confidence Score: 5/5

Safe to merge — the change is purely additive monitoring with no contract or production logic touched.

The PR only adds a committed gas baseline, two Makefile targets, and a CI step that reads that baseline. No contract code, deployment scripts, or critical configuration is modified. The unrelated file removals (.nvmrc, pnpm-workspace.yaml) are safe: the lockfile has a single root importer with no workspace-protocol dependencies, and Node version management is already handled by .mise.toml.

No files require special attention. The known non-determinism concern in contracts/.gas-snapshot (fuzz test mean varying across seeds) and the missing trailing newline were both raised in prior review threads.

Important Files Changed

Filename Overview
.github/workflows/contracts-ci.yml Appends a single make gas-check step to the contracts-unit-invariant job; straightforward addition with no structural changes to the workflow.
contracts/Makefile Adds gas-snapshot and gas-check targets using forge snapshot; invariant and integration tests correctly excluded via --nmp; fuzz seed non-determinism and tolerance edge-case noted in prior threads.
contracts/.gas-snapshot New 148-test baseline snapshot; missing trailing newline flagged in prior review thread.
CONTRIBUTING.md Updates Node.js tooling references: removes .nvmrc mention, makes mise the primary version manager — consistent with the .nvmrc deletion.
.nvmrc Deleted; Node 22 version pin is now carried solely by .mise.toml, consistent with CONTRIBUTING.md update.
pnpm-workspace.yaml Deleted; file only declared packages: [.] (root only), matching the lockfile's single root importer — safe to remove with no workspace-protocol dependencies present.

Sequence Diagram

sequenceDiagram
    participant CI as GitHub Actions
    participant FT as forge test -vv
    participant PL as make test-production-lock
    participant GC as make gas-check
    participant SN as .gas-snapshot

    CI->>FT: Run deterministic test suite (all tests)
    FT-->>CI: Pass / Fail

    CI->>PL: Run production lock invariants
    PL-->>CI: Pass / Fail

    CI->>GC: "forge snapshot --check --snap .gas-snapshot --tolerance 2 --nmp test/{invariant,integration}/**"
    GC->>SN: Read baseline measurements
    SN-->>GC: 148 gas entries
    GC->>GC: Re-run unit/e2e tests, measure gas
    GC->>GC: Compare each test within 2% tolerance
    GC-->>CI: Pass (within tolerance) / Fail (regression detected)
Loading

Reviews (4): Last reviewed commit: "docs: update CONTRIBUTING.md for mise-on..." | Re-trigger Greptile

Comment thread contracts/Makefile Outdated
Comment thread contracts/.gas-snapshot
iap added 2 commits May 19, 2026 18:49
Gas usage varies slightly between local and CI environments.
300 gas difference (~0.06%) is acceptable variance.
Increased tolerance from 1% to 2% to prevent false failures.
Invariant tests have non-deterministic gas usage due to fuzzing,
causing CI failures. Exclude them from gas snapshots to track only
deterministic unit/e2e test gas usage.

- Update Makefile to use --nmp flag for invariant/integration exclusion
- Regenerate .gas-snapshot with 147 measurements (was 159)
- Gas check now stable across CI runs
Comment thread contracts/Makefile
iap added 2 commits May 19, 2026 19:46
- Remove .nvmrc: mise (.mise.toml) manages Node version
- Remove pnpm-workspace.yaml: single-package project doesn't need it
- Node version pinned to 22 in .mise.toml
@iap iap merged commit 564df78 into dev May 19, 2026
20 checks passed
@iap iap deleted the feat/add-gas-benchmarks branch May 19, 2026 13:00
iap added a commit that referenced this pull request May 19, 2026
…172)

- Fix: Remove outdated .nvmrc reference in README (now using mise)
- Fix: Update PoseidonT3.sol Solidity version from ^0.8.24 to ^0.8.25
- Docs: Update CHANGELOG with recent merged PRs (#170, #169, #168, #163)
- Refactor: Move documentation to docs/ directory for better organization
- Update README links to reflect new docs/ structure
iap added a commit that referenced this pull request May 19, 2026
…#173)

* chore: fix typo, bug, update docs, and reorganize project structure

- Fix: Remove outdated .nvmrc reference in README (now using mise)
- Fix: Update PoseidonT3.sol Solidity version from ^0.8.24 to ^0.8.25
- Docs: Update CHANGELOG with recent merged PRs (#170, #169, #168, #163)
- Refactor: Move documentation to docs/ directory for better organization
  - CONTRIBUTING.md -> docs/CONTRIBUTING.md
  - BRANCHING.md -> docs/BRANCHING.md
  - DEPLOYMENT.md -> docs/DEPLOYMENT.md
  - TROUBLESHOOTING.md -> docs/TROUBLESHOOTING.md
  - Copy THREAT_MODEL.md, KNOWN_ISSUES.md, ARCHITECTURE.md to docs/
- Update README links to reflect new docs/ structure

* chore(contracts): set EVM version to paris for OP Stack compatibility

- Add evm_version = "paris" to foundry.toml
- Ensures bytecode compatibility with Optimism Superchain
- Paris is the EVM version used by OP Mainnet and OP Sepolia
- All 148 tests pass with Paris EVM

* chore: update gas snapshot for paris EVM version

Gas costs increased by ~3-5% after switching to paris EVM target.
This is expected behavior for OP Stack compatibility.
iap added a commit that referenced this pull request May 20, 2026
…174)

* chore: fix typo, bug, update docs, and reorganize project structure

- Fix: Remove outdated .nvmrc reference in README (now using mise)
- Fix: Update PoseidonT3.sol Solidity version from ^0.8.24 to ^0.8.25
- Docs: Update CHANGELOG with recent merged PRs (#170, #169, #168, #163)
- Refactor: Move documentation to docs/ directory for better organization
  - CONTRIBUTING.md -> docs/CONTRIBUTING.md
  - BRANCHING.md -> docs/BRANCHING.md
  - DEPLOYMENT.md -> docs/DEPLOYMENT.md
  - TROUBLESHOOTING.md -> docs/TROUBLESHOOTING.md
  - Copy THREAT_MODEL.md, KNOWN_ISSUES.md, ARCHITECTURE.md to docs/
- Update README links to reflect new docs/ structure

* chore(contracts): set EVM version to paris for OP Stack compatibility

- Add evm_version = "paris" to foundry.toml
- Ensures bytecode compatibility with Optimism Superchain
- Paris is the EVM version used by OP Mainnet and OP Sepolia
- All 148 tests pass with Paris EVM

* refactor(deps): replace createx with direct openzeppelin dependency

- Install OpenZeppelin v5.1.0 as direct git submodule
- Remove createx dependency (only used for nested OZ)
- Remove unused DeployUtils.sol library
- Update remappings: @openzeppelin/=lib/openzeppelin-contracts/
- Consolidate all remappings to foundry.toml
- Remove root remappings.txt to avoid conflicts
- Add forge-std/ remapping for completeness
- Clean forge cache and verify build

Benefits:
- Smaller dependency tree (3 deps instead of 4)
- Direct control over OpenZeppelin version
- No nested dependencies
- Single source of truth for remappings

Verified:
- forge build: success
- forge test: 159 tests passed

* fix(docs): use consistent MAINNET_RPC variable in deployment guide

Address CodeRabbit feedback: line 488 used generic $RPC instead of
$MAINNET_RPC. Since this is in the Mainnet Deployment section and
the previous line uses $MAINNET_RPC, update for consistency.
@trade trade deleted a comment from coderabbitai Bot May 25, 2026
iap added a commit that referenced this pull request Jun 2, 2026
* feat: add initial gas snapshot baseline

- Generated with forge snapshot
- 158 test gas measurements
- Baseline for tracking gas regressions

* feat: add gas snapshot targets to Makefile

- make gas-snapshot: generate new snapshot
- make gas-check: verify against baseline

* ci: add gas snapshot check to workflow

- Runs after tests in contracts-unit-invariant job
- Fails CI if gas usage increases significantly
- Addresses #164

* fix: increase gas check tolerance to 2%

Gas usage varies slightly between local and CI environments.
300 gas difference (~0.06%) is acceptable variance.
Increased tolerance from 1% to 2% to prevent false failures.

* fix: exclude invariant tests from gas snapshots

Invariant tests have non-deterministic gas usage due to fuzzing,
causing CI failures. Exclude them from gas snapshots to track only
deterministic unit/e2e test gas usage.

- Update Makefile to use --nmp flag for invariant/integration exclusion
- Regenerate .gas-snapshot with 147 measurements (was 159)
- Gas check now stable across CI runs

* chore: remove .nvmrc and pnpm-workspace.yaml

- Remove .nvmrc: mise (.mise.toml) manages Node version
- Remove pnpm-workspace.yaml: single-package project doesn't need it
- Node version pinned to 22 in .mise.toml

* docs: update CONTRIBUTING.md for mise-only setup
iap added a commit that referenced this pull request Jun 2, 2026
…172)

- Fix: Remove outdated .nvmrc reference in README (now using mise)
- Fix: Update PoseidonT3.sol Solidity version from ^0.8.24 to ^0.8.25
- Docs: Update CHANGELOG with recent merged PRs (#170, #169, #168, #163)
- Refactor: Move documentation to docs/ directory for better organization
- Update README links to reflect new docs/ structure
iap added a commit that referenced this pull request Jun 2, 2026
…#173)

* chore: fix typo, bug, update docs, and reorganize project structure

- Fix: Remove outdated .nvmrc reference in README (now using mise)
- Fix: Update PoseidonT3.sol Solidity version from ^0.8.24 to ^0.8.25
- Docs: Update CHANGELOG with recent merged PRs (#170, #169, #168, #163)
- Refactor: Move documentation to docs/ directory for better organization
  - CONTRIBUTING.md -> docs/CONTRIBUTING.md
  - BRANCHING.md -> docs/BRANCHING.md
  - DEPLOYMENT.md -> docs/DEPLOYMENT.md
  - TROUBLESHOOTING.md -> docs/TROUBLESHOOTING.md
  - Copy THREAT_MODEL.md, KNOWN_ISSUES.md, ARCHITECTURE.md to docs/
- Update README links to reflect new docs/ structure

* chore(contracts): set EVM version to paris for OP Stack compatibility

- Add evm_version = "paris" to foundry.toml
- Ensures bytecode compatibility with Optimism Superchain
- Paris is the EVM version used by OP Mainnet and OP Sepolia
- All 148 tests pass with Paris EVM

* chore: update gas snapshot for paris EVM version

Gas costs increased by ~3-5% after switching to paris EVM target.
This is expected behavior for OP Stack compatibility.
iap added a commit that referenced this pull request Jun 2, 2026
…174)

* chore: fix typo, bug, update docs, and reorganize project structure

- Fix: Remove outdated .nvmrc reference in README (now using mise)
- Fix: Update PoseidonT3.sol Solidity version from ^0.8.24 to ^0.8.25
- Docs: Update CHANGELOG with recent merged PRs (#170, #169, #168, #163)
- Refactor: Move documentation to docs/ directory for better organization
  - CONTRIBUTING.md -> docs/CONTRIBUTING.md
  - BRANCHING.md -> docs/BRANCHING.md
  - DEPLOYMENT.md -> docs/DEPLOYMENT.md
  - TROUBLESHOOTING.md -> docs/TROUBLESHOOTING.md
  - Copy THREAT_MODEL.md, KNOWN_ISSUES.md, ARCHITECTURE.md to docs/
- Update README links to reflect new docs/ structure

* chore(contracts): set EVM version to paris for OP Stack compatibility

- Add evm_version = "paris" to foundry.toml
- Ensures bytecode compatibility with Optimism Superchain
- Paris is the EVM version used by OP Mainnet and OP Sepolia
- All 148 tests pass with Paris EVM

* refactor(deps): replace createx with direct openzeppelin dependency

- Install OpenZeppelin v5.1.0 as direct git submodule
- Remove createx dependency (only used for nested OZ)
- Remove unused DeployUtils.sol library
- Update remappings: @openzeppelin/=lib/openzeppelin-contracts/
- Consolidate all remappings to foundry.toml
- Remove root remappings.txt to avoid conflicts
- Add forge-std/ remapping for completeness
- Clean forge cache and verify build

Benefits:
- Smaller dependency tree (3 deps instead of 4)
- Direct control over OpenZeppelin version
- No nested dependencies
- Single source of truth for remappings

Verified:
- forge build: success
- forge test: 159 tests passed

* fix(docs): use consistent MAINNET_RPC variable in deployment guide

Address CodeRabbit feedback: line 488 used generic $RPC instead of
$MAINNET_RPC. Since this is in the Mainnet Deployment section and
the previous line uses $MAINNET_RPC, update for consistency.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add gas benchmarks to CI

1 participant