crytic / slither-action

GNU Affero General Public License v3.0
124 stars 18 forks source link

Slither cant read project / target #46

Closed distributedstatemachine closed 1 year ago

distributedstatemachine commented 1 year ago

Slither keeps error even though I am pointing it to the right directory

Here is what my project lay out is :

khalani-monorepo$ tree -L 3
.
├── LICENSE
├── README.md
├── package.json
└── solidity
    ├── balancer
    │   └── vault
    └── khalani-core
        ├── README.md
        ├── broadcast
        ├── foundry.toml
        ├── hardhat.config.js
        ├── lib
        ├── package-lock.json
        ├── package.json
        ├── script
        ├── slither.config.json
        ├── src
        ├── test
        └── yarn.lock

Here is what my yaml looks like:

      - name: Run Slither core
        uses: crytic/slither-action@main
        continue-on-error: true
        id: slither
        with:
          target: "solidity/khalani-core/src"
          slither-config: "solidity/khalani-core/slither.config.json"
          sarif: results.sarif

and the error:

[-] Slither config provided: solidity/khalani-core/slither.config.json
Traceback (most recent call last):
  File "/opt/slither/lib/python3.9/site-packages/slither/__main__.py", line 826, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/opt/slither/lib/python3.9/site-packages/slither/__main__.py", line 86, in process_all
    compilations = compile_all(target, **vars(args))
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 658, in compile_all
    compilations.append(CryticCompile(filename, **kwargs))
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 117, in __init__
    self._compile(**kwargs)
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 548, in _compile
    self._platform.compile(self, **kwargs)
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 154, in compile
    targets_json = _get_targets_json(compilation_unit, self._target, **kwargs)
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 276, in _get_targets_json
    return _run_solc(
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 468, in _run_solc
    raise InvalidCompilation(f"{filename} does not exist (are you in the correct directory?)")
crytic_compile.platform.exceptions.InvalidCompilation: solidity/khalani-core/src does not exist (are you in the correct directory?)
Error in solidity/khalani-core/src
Traceback (most recent call last):
  File "/opt/slither/lib/python3.9/site-packages/slither/__main__.py", line [82](https://github.com/tvl-labs/khalani-monorepo/actions/runs/3766477151/jobs/6403028175#step:7:83)6, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/opt/slither/lib/python3.9/site-packages/slither/__main__.py", line 86, in process_all
    compilations = compile_all(target, **vars(args))
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 658, in compile_all
    compilations.append(CryticCompile(filename, **kwargs))
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 117, in __init__
    self._compile(**kwargs)
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 548, in _compile
    self._platform.compile(self, **kwargs)
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 154, in compile
    targets_json = _get_targets_json(compilation_unit, self._target, **kwargs)
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 276, in _get_targets_json
    return _run_solc(
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 468, in _run_solc
    raise InvalidCompilation(f"{filename} does not exist (are you in the correct directory?)")
crytic_compile.platform.exceptions.InvalidCompilation: solidity/khalani-core/src does not exist (are you in the correct directory?)
elopez commented 1 year ago

Hi @samtvlabs, thanks for the report! Judging by the project structure you posted, you likely want to set target: "solidity/khalani-core" to make the slither action build and analyze your project using one of hardhat or foundry (you can force one or the other using the compile_force_framework option in the config file)

If you pass another folder (e.g. src) it must have solidity files in there (i.e. not on sub-folders) and you'll have to deal with any potential remappings manually. If there's no solidity files you'll get the "does not exist" error.

distributedstatemachine commented 1 year ago

Thanks this worked, but back to the original error that sent me down the rabbit hole. I have also tried setting the node version to 16 in the pipeline

[-] Slither config provided: solidity/khalani-core/slither.config.json
'npx hardhat compile --force' running

npm WARN exec The following package was not found and will be installed: hardhat@2.12.4
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'hardhat@2.12.4',
npm WARN EBADENGINE   required: { node: '^14.0.0 || ^16.0.0 || ^18.0.0' },
npm WARN EBADENGINE   current: { node: 'v19.3.0', npm: '9.2.0' }
npm WARN EBADENGINE }
You are using a version of Node.js that is not supported by Hardhat, and it may work incorrectly, or not work at all.

Please, make sure you are using a supported version of Node.js.

To learn more about which versions of Node.js are supported go to https://hardhat.org/nodejs-versions
Error HH12: Trying to use a non-local installation of Hardhat, which is not supported.
Please install Hardhat locally using npm or Yarn, and try again.
HardhatError: HH12: Trying to use a non-local installation of Hardhat, which is not supported.
Please install Hardhat locally using npm or Yarn, and try again.
    at main (/github/home/.npm/_npx/ef9ef3f50c7d7dc1/node_modules/hardhat/src/internal/cli/cli.ts:175:13)

Here is a copy of my slither.config.json

{
    "filter_paths": "lib, lib/openzeppelin-contracts/,",
    "detectors_to_exclude": "timestamp,naming-convention,pragma,solc-version,uninitialized-local,constable-states,unused-return",
    "solc_remaps": [
        "@ensdomains/=node_modules/@ensdomains/",
        "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
        "@openzeppelin/contracts/-upgradeable=lib/openzeppelin-contracts-upgradeable/contracts/",
        "hardhat/=node_modules/hardhat/",
        "@balancer-labs/=node_modules/@balancer-labs/",
        "ds-test/=lib/forge-std/lib/ds-test/src/",
        "forge-std/=lib/forge-std/src/",
        "hardhat/=node_modules/hardhat/",
        "@hyperlane-xyz/core=lib/hyperlane-monorepo/solidity/",
        "@sgn-v2-contracts=lib/sgn-v2-contracts/contracts/"
    ]
}
distributedstatemachine commented 1 year ago

I had a hardhat config file in in the folder. Thanks for your help and happy holidays!