crytic / slither

Static Analyzer for Solidity and Vyper
https://blog.trailofbits.com/2018/10/19/slither-a-solidity-static-analysis-framework/
GNU Affero General Public License v3.0
5.33k stars 967 forks source link

CC cannot find file and Slither cannot find top-level enum for truffle, but it's okay in hardhat #909

Closed hacker-DOM closed 7 months ago

hacker-DOM commented 3 years ago

I am having trouble running Slither on the following codebase: https://github.com/rocket-pool/rocketpool/tree/a65b203cf99c7a991c2d85a7468a97bfb5dbba31. I will try to describe the steps leading to the unexpected behavior:

git clone https://github.com/rocket-pool/rocketpool
cd rocketpool
git checkout a65b203cf99c7a991c2d85a7468a97bfb5dbba31
npm i

At this point, running npm ls truffle yields └── truffle@5.4.2, so if we run slither ., we will hit CC#209.

First attempt at a solution

slither . --truffle-version truffle@5.4.2

This yield console output corresponding to a successful compilation but an unhandled exception in Slither, the last few lines of which are:

Traceback (most recent call last):
  File "/Users/dteiml/projects/trailofbits/slither/slither/__main__.py", line 732, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/Users/dteiml/projects/trailofbits/slither/slither/__main__.py", line 72, in process_all
    compilations = compile_all(target, **vars(args))
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/crytic_compile-0.2.0-py3.9.egg/crytic_compile/crytic_compile.py", line 489, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/crytic_compile-0.2.0-py3.9.egg/crytic_compile/crytic_compile.py", line 109, in __init__
    self._compile(**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/crytic_compile-0.2.0-py3.9.egg/crytic_compile/crytic_compile.py", line 417, in _compile
    self._platform.compile(self, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/crytic_compile-0.2.0-py3.9.egg/crytic_compile/platform/truffle.py", line 223, in compile
    raise InvalidCompilation(txt)
crytic_compile.platform.exceptions.InvalidCompilation: Unknown file: project:/contracts/interface/util/AddressSetStorageInterface.sol
Consider removing the build/contracts content (rm build/contracts/*)

(even though build was empty before running this command)

Second attempt at solution

npm i truffle@5.1.51
slither .

This also yields a successful compilation with an exception in Slither; the last few lines are

  File "/Users/dteiml/projects/trailofbits/slither/slither/solc_parsing/declarations/function.py", line 278, in analyze_params
    self._parse_params(params)
  File "/Users/dteiml/projects/trailofbits/slither/slither/solc_parsing/declarations/function.py", line 1191, in _parse_params
    local_var = self._add_param(param)
  File "/Users/dteiml/projects/trailofbits/slither/slither/solc_parsing/declarations/function.py", line 1170, in _add_param
    local_var_parser.analyze(self)
  File "/Users/dteiml/projects/trailofbits/slither/slither/solc_parsing/variables/variable_declaration.py", line 181, in analyze
    self._variable.type = parse_type(self._elem_to_parse, caller_context)
  File "/Users/dteiml/projects/trailofbits/slither/slither/solc_parsing/solidity_types/type_parsing.py", line 319, in parse_type
    array_type = parse_type(t["baseType"], next_context)
  File "/Users/dteiml/projects/trailofbits/slither/slither/solc_parsing/solidity_types/type_parsing.py", line 277, in parse_type
    return _find_from_type_name(
  File "/Users/dteiml/projects/trailofbits/slither/slither/solc_parsing/solidity_types/type_parsing.py", line 189, in _find_from_type_name
    raise ParsingError("Type not found " + str(name))
slither.solc_parsing.exceptions.ParsingError: Type not found enum SettingType
ERROR:root:Error:
ERROR:root:Type not found enum SettingType
ERROR:root:Please report an issue to https://github.com/crytic/slither/issues

Fwiw, npm i hardhat and an appropriate config file leads[1] to a successful execution. Sill it's unexpected that Slither throws in the case of truffle even after a successful compilation.

hardhat.config.js:

module.exports = {
    solidity: {
      version: "0.7.6",
      settings: {
        optimizer: {
          enabled: true,
          runs: 1600
        }
      }
    },
  };
montyly commented 3 years ago

I think it's because of https://github.com/crytic/crytic-compile/issues/199.

You can either downgrade truffle, or use crytic-compile from master

Cosmonauta426 commented 3 years ago

"slither.solc_parsing.exceptions.ParsingError: Type not found enum EnumName"

i have the same issue, any fix? i try downgrade and upgrade the truffle but the issue persist