Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Solidity gas diff [SLT-259] #3181

Merged
merged 17 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 43 additions & 27 deletions .github/workflows/solidity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ jobs:
env:
VERCEL_PROJECT_ID: ${{ steps.project_id.outputs.VERCEL_PROJECT_ID}}


cancel-outdated:
name: Cancel Outdated Jobs
runs-on: ubuntu-latest
Expand All @@ -130,6 +129,9 @@ jobs:
fail-fast: false
matrix:
package: ${{ fromJson(needs.changes.outputs.packages) }}
# Slither is irrelevant for solidity-devops, as it only contains devops scripts rather than deployed contracts
exclude:
- package: solidity-devops
permissions:
# always required
security-events: write
Expand All @@ -138,40 +140,34 @@ jobs:
contents: read
steps:
- name: Checkout repository
if: ${{ matrix.package != 'solidity-devops' }}
uses: actions/checkout@v4
with:
fetch-depth: 2
submodules: 'recursive'

- name: Setup NodeJS
if: ${{ matrix.package != 'solidity-devops' }}
uses: ./.github/actions/setup-nodejs

- name: Install Foundry
if: ${{ matrix.package != 'solidity-devops' }}
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

# TODO: find a flag for this
- name: Delete Untested Files
if: ${{ matrix.package != 'solidity-devops' }}
working-directory: './packages/${{matrix.package}}'
run: |
rm -rf test/ || true
rm -rf script/ || true

- name: Build Contracts
if: ${{ matrix.package != 'solidity-devops' }}
# TODO: unforunately, as of now concurrency needs to be 1 since if multiple instances of forge try to install the same version
# of solc at the same time, we get "text file busy" errors. See https://github.com/synapsecns/sanguine/actions/runs/8457116792/job/23168392860?pr=2234
# for an example.
run: |
npx lerna exec npm run build:slither --concurrency=1

- name: Run Slither
if: ${{ matrix.package != 'solidity-devops' }}
uses: crytic/slither-action@v0.3.0
continue-on-error: true
id: slither
Expand All @@ -183,7 +179,7 @@ jobs:
solc-version: 0.8.17

- name: Upload SARIF file
if: ${{!github.event.repository.private && matrix.package != 'solidity-devops'}}
if: ${{!github.event.repository.private}}
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ./results.sarif
Expand All @@ -199,28 +195,29 @@ jobs:
package: ${{ fromJson(needs.changes.outputs.packages) }}
steps:
- uses: actions/checkout@v4
if: ${{ matrix.package != 'solidity-devops' }}
with:
submodules: recursive

- name: Setup Node JS
if: ${{ matrix.package != 'solidity-devops' }}
uses: ./.github/actions/setup-nodejs

- name: Installing dependencies
if: ${{ matrix.package != 'solidity-devops' }}
run: yarn install --immutable

- name: Install Foundry
if: ${{ matrix.package != 'solidity-devops' }}
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Foundry Tests
working-directory: './packages/${{matrix.package}}'
run: forge test -vvv

# We skip only the coverage steps for solidity-devops before we establish a good coverage there
- name: Run Foundry Coverage
if: ${{ matrix.package != 'solidity-devops' }}
working-directory: './packages/${{matrix.package}}'
run: forge coverage -vvv --report lcov --report summary >> $GITHUB_STEP_SUMMARY
run: forge coverage --report lcov --report summary >> $GITHUB_STEP_SUMMARY

- name: Send Coverage (Codecov)
if: ${{ matrix.package != 'solidity-devops' }}
Expand All @@ -236,39 +233,59 @@ jobs:
attempt_limit: 5
attempt_delay: 30000


snapshot:
gas-diff:
runs-on: ubuntu-latest
name: Foundry Gas Snapshot
name: Foundry Gas Diff
if: ${{ needs.changes.outputs.package_count > 0 }}
needs: changes
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.changes.outputs.packages) }}
# Gas diff is irrelevant for solidity-devops, as it only contains devops scripts rather than deployed contracts
exclude:
- package: solidity-devops
steps:
- uses: actions/checkout@v4
if: ${{ matrix.package != 'solidity-devops' }}
with:
submodules: recursive

- name: Setup Node JS
if: ${{ matrix.package != 'solidity-devops' }}
uses: ./.github/actions/setup-nodejs

- name: Installing dependencies
if: ${{ matrix.package != 'solidity-devops' }}
run: yarn install --immutable

- name: Install Foundry
if: ${{ matrix.package != 'solidity-devops' }}
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Run snapshot
if: ${{ matrix.package != 'solidity-devops' }}

# TODO: consider defining a package-specific script for this
- name: Run tests and generate gas report
working-directory: './packages/${{matrix.package}}'
run: forge snapshot >> $GITHUB_STEP_SUMMARY
# Excluding tests with reverts to get accurate average gas cost estimates
run: forge test --nmt "(fail|revert)" --gas-report > "../../gas-report-${{ matrix.package }}.ansi"
env:
# make fuzzing semi-deterministic to avoid noisy gas cost estimation
# due to non-deterministic fuzzing (but still use pseudo-random fuzzing seeds)
FOUNDRY_FUZZ_SEED: 0x${{ github.event.pull_request.base.sha || github.sha }}

- name: Compare gas reports
uses: Rubilmax/foundry-gas-diff@v3.18
# TODO: define some options?
with:
report: 'gas-report-${{ matrix.package }}.ansi'
id: gas_diff

- name: Add gas diff to sticky comment
if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
# delete the comment in case changes no longer impact gas costs
delete: ${{ !steps.gas_diff.outputs.markdown }}
message: ${{ steps.gas_diff.outputs.markdown }}

size-check:
name: Foundry Size Check
runs-on: ubuntu-latest
Expand All @@ -278,25 +295,24 @@ jobs:
fail-fast: false
matrix:
package: ${{ fromJson(needs.changes.outputs.packages) }}
# Size check is irrelevant for solidity-devops, as it only contains devops scripts rather than deployed contracts
exclude:
- package: solidity-devops
steps:
- uses: actions/checkout@v4
if: ${{ matrix.package != 'solidity-devops' }}
with:
submodules: recursive

- name: Setup Node JS
if: ${{ matrix.package != 'solidity-devops' }}
uses: ./.github/actions/setup-nodejs

- name: Install Foundry
if: ${{ matrix.package != 'solidity-devops' }}
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

# This will run https://book.getfoundry.sh/reference/forge/forge-build#build-options
- name: Run forge build --sizes
if: ${{ matrix.package != 'solidity-devops' }}
run: |
forge build --sizes
working-directory: './packages/${{matrix.package}}'
1 change: 1 addition & 0 deletions packages/contracts-rfq/contracts/FastBridgeV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {IFastBridge} from "./interfaces/IFastBridge.sol";
import {IFastBridgeV2} from "./interfaces/IFastBridgeV2.sol";
import {IFastBridgeV2Errors} from "./interfaces/IFastBridgeV2Errors.sol";

/// @notice FastBridgeV2 is a contract for bridging tokens across chains.
contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors {
using SafeERC20 for IERC20;
using UniversalTokenLib for address;
Expand Down
Loading