Skip to content

crytic_compile.platform.exceptions.InvalidCompilation: Unknown file #572

Open
@Uhan19

Description

@Uhan19

Hi team,

running into some issues when I am reusing a slither workflow from one of my solidity repos (core-v1) in another repo (peripheral-v1). Core-v1 repo is submodule in the Peripheral-v1, lib/core-v1. The slither analysis passes in CI on the core-v1 repo, however it fails when the workflow is being called by the peripheral CI workflow. Here is the error:

crytic_compile.platform.exceptions.InvalidCompilation: Unknown file: contracts/interfaces/callbacks/ITransferValidator.sol

ITransferValidator.sol is a file in the core-v1 repo, and it is not used or imported in the peripheral-v1 repo, so I am not sure why slither is trying to compile this file.

here is my slither.yml in core-v1:

name: Slither Analysis

on:
  workflow_call:
    secrets:
      PAT_TOKEN:
        required: false
    inputs:
      cache-path:
        default: |
          cache
          out
        required: false
        type: 'string'

      restore-cache:
        default: true
        required: false
        type: 'boolean'

      target:
        default: '.'
        required: false
        type: 'string'

jobs:
  analyze:
    runs-on: ubuntu-latest
    steps:
      - name: 'Check out the repo'
        uses: 'actions/checkout@v4'
        with:
          fetch-depth: 0
          submodules: recursive
          token: ${{ secrets.PAT_TOKEN || github.token }}

      # - name: 'Restore the cached build'
      #   if: ${{ inputs.restore-cache }}
      #   uses: 'actions/cache/restore@v4'
      #   with:
      #     fail-on-cache-miss: true
      #     key: 'build-${{ github.sha }}'
      #     path: ${{ inputs.cache-path }}

      - name: 'Install Foundry'
        uses: 'foundry-rs/foundry-toolchain@v1'

      - name: Initialize Forge
        run: |
          forge --version
          forge config
          forge install --quiet ## suppress git logs

      - name: 'Compile contracts'
        run: |
          forge clean
          forge config --json
          forge build --build-info --skip */test/** */script/** --force

      - name: 'List directories'
        run: ls -la contracts/

      - name: Run Slither Static Analysis
        env:
          TERM: xterm-color
        uses: crytic/[email protected]
        id: slither
        with:
          slither-version: 'dev'
          fail-on: 'low'
          target: ${{ inputs.target }}
          slither-config: slither.config.json
          ignore-compile: true

      - name: 'Add summary'
        run: |
          echo "### Slither Analysis result" >> $GITHUB_STEP_SUMMARY
          echo "Passed" >> $GITHUB_STEP_SUMMARY

      - name: 'Add summary'
        run: |
          echo "### Slither Analysis" >> $GITHUB_STEP_SUMMARY
          echo "Passed" >> $GITHUB_STEP_SUMMARY

and this is the calling workflow CI.yml in the Peripheral-v1 repo:

name: CI # Think about changing this name or remove it.

concurrency:
  cancel-in-progress: true
  group: ${{ github.workflow }}-${{ github.ref }}

on:
  push:
    branches:
      - master
  pull_request:
  release:
    types: [published]
  workflow_dispatch:

env:
  FOUNDRY_PROFILE: ci
  FACTORY_ADDRESS: '0xC427715e2428A5a99fDC0159A61b9F6ea875Eb39'

jobs:
  format:
    name: 'Run format'
    runs-on: ubuntu-latest
    steps:
      - name: check out repository
        uses: actions/checkout@v4
      - name: Format
        uses: Ammalgam-Protocol/core-v1/.github/actions/format@feature/ci-pat-token-permissions

  build:
    name: 'Run build'
    secrets: inherit
    uses: Ammalgam-Protocol/core-v1/.github/workflows/build.yml@feature/ci-pat-token-permissions

  test:
    name: 'Run tests'
    needs: ['format', 'build']
    secrets: inherit
    uses: Ammalgam-Protocol/core-v1/.github/workflows/test.yml@feature/ci-pat-token-permissions

  coverage:
    name: 'Run coverage'
    needs: ['format', 'build']
    secrets:
      CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
      PAT_TOKEN: ${{ secrets.PAT_TOKEN || github.token }}
    uses: Ammalgam-Protocol/core-v1/.github/workflows/coverage.yml@feature/ci-pat-token-permissions

  slither:
    name: 'Run slither'
    needs: ['format', 'build']
    secrets: inherit
    uses: Ammalgam-Protocol/core-v1/.github/workflows/slither.yml@feature/ci-pat-token-permissions
    with:
      target: ./

  old:
    needs: ['build', 'test']
    strategy:
      fail-fast: true

    name: Ammalgam peripheral-v1
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
          submodules: recursive
          token: ${{ secrets.PAT_TOKEN }}

      - name: Install Foundry
        uses: foundry-rs/foundry-toolchain@v1
        with:
          version: nightly

      - name: Test Fork Deploy
        env:
          LOCAL: 0
          MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }}
          MNEMONIC: ${{ secrets.MNEMONIC }}

        run: |
          forge script script/LocalForkDeploy.s.sol -vvvv --skip-simulation --fork-url $MAINNET_RPC_URL
        id: deploy

      - name: Test SEPOLIA Deploy
        env:
          SEPOLIA_RPC_URL: ${{ secrets.SEPOLIA_RPC_URL }}
          MNEMONIC: ${{ secrets.MNEMONIC }}
        run: forge script script/TestnetDeploy.s.sol --rpc-url $SEPOLIA_RPC_URL -vvvv

I also have added slither.config.json in both repos:

{
  "filter_paths": "lib|test|script"
}

I had thought that perhaps I needed to define the targets for slither to run and perhaps it was running in the run context or root level, but after adding a step to list the directories, I could see that the file structure is as I expected. I also commented out the cache restore and build the contracts as part of the slither workflow, however this did not resolve the issue either. Would love some input in terms of why the compiler is reading a file in the submodule when it should've been filtered out. Please let me know if I can provide any additional information. Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions