Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
info

GitHub Action

Generate gas diff

v3.4

Generate gas diff

info

Generate gas diff

Easily compare gas reports generated by foundry

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Generate gas diff

uses: Rubilmax/[email protected]

Learn more about this action in Rubilmax/foundry-gas-diff

Choose a version

🔥🛠️ Foundry Gas Diff Reporter

Easily generate & compare gas reports automatically generated by Foundry on each of your Pull Requests!

Live Example

Changes to gas costs

🧾 Summary

Contract Method Avg (+/-) %
PositionsManager supplyLogic
borrowLogic
+849 ❌
+702 ❌
+0.25%
+0.13%
Morpho supply +809 ❌ +0.23%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
PositionsManager 4,546,050 (+14,617) supplyLogic
borrowLogic
737 (0)
148,437 (0)
0.00%
0.00%
365,894 (+849)
542,977 (+702)
+0.25%
+0.13%
383,960 (+995)
438,816 (0)
+0.27%
0.00%
2,121,294 (+304)
1,090,968 (0)
+0.01%
0.00%
500 (0)
292 (0)
Morpho 3,150,242 (0) supply 3,997 (0) 0.00% 371,586 (+809) +0.23% 395,247 (+995) +0.27% 2,125,764 (+304) +0.01% 502 (0)

Getting started

Automatically generate a gas report diff on every PR

Add a workflow (.github/workflows/foundry-gas-diff.yml):

name: Report gas diff

on:
  push:
    branches:
      - main
  pull_request:
    # Optionally configure to run only for specific files. For example:
    # paths:
    # - "src/**"

jobs:
  compare_gas_reports:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      # Add any build steps here. For example:
      - run: forge test --gas-report > gasreport.ansi

      - name: Compare gas reports
        uses: Rubilmax/[email protected]
        with:
          workflowId: foundry-gas-diff.yml # must be the name of the workflow file
          ignore: test/**/* # optionally filter out gas reports from specific paths
        id: gas_diff

      - name: Add gas diff to sticky comment
        uses: marocchino/sticky-pull-request-comment@v2
        with:
          message: ${{ steps.gas_diff.outputs.markdown }}

Options

workflowId {string} (required)

The workflow ID the reference gas report was uploaded from. By default, the reference gas report of next workflow runs are uploaded by this action from the previous workflow runs, thus it should correspond to the ID of the workflow this action is defined in: foundry-gas-diff.yml in the above example.

token {string}

The github token allowing the action to upload and download gas reports generated by foundry.

Defaults to: ${{ github.token }}

report {string}

This should correspond to the path of a file where the output of forge's gas report has been logged. Only necessary when generating multiple gas reports in the same workflow.

Defaults to: gasreport.ansi

report {string}

The title displayed in the markdown output. Can be used to identify multiple gas diffs in the same PR.

Defaults to: Changes to gas cost

ignore {string}

The list of paths from which to ignore gas reports, separated by a comma. This allows to clean out gas diffs from dependency contracts impacted by a change (e.g. Proxies, ERC20, ...).

No default assigned: optional opt-in (Please note that node dependencies are always discarded from gas reports)

match {string}

The list of paths of which only to keep gas reports, separated by a comma. This allows to only display gas diff of specific contracts.

No default assigned: optional opt-in

Status

Status: Experimental

This repository is maintained independently from Foundry and may not work as expected with all versions of forge.