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

Not obvious compilation error in Slither #175

Closed
disconnect3d opened this issue Apr 26, 2021 · 2 comments
Closed

Not obvious compilation error in Slither #175

disconnect3d opened this issue Apr 26, 2021 · 2 comments
Labels
bug Something isn't working high-priority

Comments

@disconnect3d
Copy link

Running slither <contract id> when we don't have proper solc version installed via solc-select may result in an unambiguous error of Invalid solc compilation which does not describe what shall we do.

Example:

$ slither 0xB8c77482e45F1F44dE1745F52C74426C631bDD52
Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/crytic_compile/platform/solc.py", line 412, in _run_solc
    ret = json.loads(stdout)
  File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/slither/__main__.py", line 721, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/usr/local/lib/python3.6/dist-packages/slither/__main__.py", line 71, in process_all
    compilations = compile_all(target, **vars(args))
  File "/usr/local/lib/python3.6/dist-packages/crytic_compile/crytic_compile.py", line 1076, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/usr/local/lib/python3.6/dist-packages/crytic_compile/crytic_compile.py", line 137, in __init__
    self._compile(**kwargs)
  File "/usr/local/lib/python3.6/dist-packages/crytic_compile/crytic_compile.py", line 987, in _compile
    self._platform.compile(self, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/crytic_compile/platform/etherscan.py", line 273, in compile
    working_dir=working_dir,
  File "/usr/local/lib/python3.6/dist-packages/crytic_compile/platform/solc.py", line 417, in _run_solc
    raise InvalidCompilation(f"Invalid solc compilation {stderr}")
crytic_compile.platform.exceptions.InvalidCompilation: Invalid solc compilation
ERROR:root:None
ERROR:root:Error in 0xB8c77482e45F1F44dE1745F52C74426C631bDD52
ERROR:root:Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/crytic_compile/platform/solc.py", line 412, in _run_solc
    ret = json.loads(stdout)
  File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/slither/__main__.py", line 721, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/usr/local/lib/python3.6/dist-packages/slither/__main__.py", line 71, in process_all
    compilations = compile_all(target, **vars(args))
  File "/usr/local/lib/python3.6/dist-packages/crytic_compile/crytic_compile.py", line 1076, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/usr/local/lib/python3.6/dist-packages/crytic_compile/crytic_compile.py", line 137, in __init__
    self._compile(**kwargs)
  File "/usr/local/lib/python3.6/dist-packages/crytic_compile/crytic_compile.py", line 987, in _compile
    self._platform.compile(self, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/crytic_compile/platform/etherscan.py", line 273, in compile
    working_dir=working_dir,
  File "/usr/local/lib/python3.6/dist-packages/crytic_compile/platform/solc.py", line 417, in _run_solc
    raise InvalidCompilation(f"Invalid solc compilation {stderr}")
crytic_compile.platform.exceptions.InvalidCompilation: Invalid solc compilation

I investigated that by adding additional prints of stdout/stderr and process.returncode in

stdout, stderr = process.communicate()
stdout, stderr = (stdout.decode(), stderr.decode()) # convert bytestrings to unicode strings
if stderr and (not solc_disable_warnings):
LOGGER.info("Compilation warnings/errors on %s:\n%s", filename, stderr)
try:
ret = json.loads(stdout)

It turns out that the information that solc is not installed is printed out on stdout and so is not passed further to the user:

STDOUT: Version '0.4.12' not installed (set by SOLC_VERSION). Run `solc-select install 0.4.12`.
STDERR:
RETCODE 1

I think we should either make solc-select to print info on stdout, or, make crytic-compile to take such stdout into account, or, make so it respects return code? I didn't check that but shouldn't return code be a good indicator whether the command succeeded?

@disconnect3d disconnect3d added the bug Something isn't working label Apr 26, 2021
@montyly
Copy link
Member

montyly commented May 7, 2021

I think this is a good idea. However, it should be done when we will refactor our solc-select integration to use the new python version (#157)

@0xalpharush
Copy link
Contributor

We improved this in #353

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working high-priority
Projects
None yet
Development

No branches or pull requests

3 participants