crytic / crytic/crytic-compile

crytic_compile.platform.exceptions.InvalidCompilation: Unknown file

Open
#572 12 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
197
Forks
97
PR merge metrics
No merged PRs in 30d

Description

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:

```yaml
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/slither-action@v0.4.0
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:

```yaml
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:

```json
{
"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.

Contributor guide

Open the contributing guide

Research direction

Start with .github/workflows/slither.yml in core-v1 and the calling CI.yml in peripheral-v1, then inspect slither.config.json and the reported contracts/interfaces/callbacks/ITransferValidator.sol path. Reproduce the reusable-workflow run with the submodule layout and determine why crytic-compile receives that file; done means the peripheral workflow completes without the Unknown file error.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions, python, solidity
Domain
build-system, ci-cd, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.