Byont-Ventures / smart-contract-analysis-tools

0 stars 1 forks source link

Running slither causes compiler error #39

Closed jasperverbeet closed 1 year ago

jasperverbeet commented 1 year ago

Issue

When attempting to run Slither with the ghcr.io/byont-ventures/analysis-toolbox:latest image, the following error occurs:

Warning: This is a pre-release compiler version, please do not use it in production.
Error: Source file requires different compiler version (current compiler is 0.8.17-develop.2022.12.9+commit.8df45f5f.Linux.g++) - note that nightly builds are considered to be strictly less than the released version
It appears that there is a mismatch between the version of the Solidity compiler that is being used and the version that is required by the source file.

An example implementation can be found at https://github.com/Byont-Ventures/metaseum/pull/13.

Steps to reproduce

Expected behavior

Slither should run successfully and produce the expected output.

Actual behavior

Slither produces the above error message and the following stack trace:

=================================================================
Pulling latest ghcr.io/byont-ventures/analysis-toolbox:latest
=================================================================

=================================================================
Run Slither
=================================================================

WARNING: The requested image's platform (linux/arm64) does not match the detected host platform (linux/amd64) and no specific platform was requested
Compilation warnings/errors on src/AquariumDeParis.sol:
Warning: This is a pre-release compiler version, please do not use it in production.

Error: Source file requires different compiler version (current compiler is 0.8.17-develop.2022.12.9+commit.8df45f5f.Linux.g++) - note that nightly builds are considered to be strictly less than the released version
 --> src/AquariumDeParis.sol:2:1:
  |
2 | pragma solidity ^0.8.17;
  | ^^^^^^^^^^^^^^^^^^^^^^^^

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/crytic_compile/platform/solc.py", line 544, in _run_solc
    ret: Dict = json.loads(stdout)
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, 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.8/dist-packages/slither/__main__.py", line 826, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/usr/local/lib/python3.8/dist-packages/slither/__main__.py", line 86, in process_all
    compilations = compile_all(target, **vars(args))
  File "/usr/local/lib/python3.8/dist-packages/crytic_compile/crytic_compile.py", line 637, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/usr/local/lib/python3.8/dist-packages/crytic_compile/crytic_compile.py", line 117, in __init__
    self._compile(**kwargs)
  File "/usr/local/lib/python3.8/dist-packages/crytic_compile/crytic_compile.py", line 548, in _compile
    self._platform.compile(self, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/crytic_compile/platform/solc.py", line 154, in compile
    targets_json = _get_targets_json(compilation_unit, self._target, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/crytic_compile/platform/solc.py", line 276, in _get_targets_json
    return _run_solc(
  File "/usr/local/lib/python3.8/dist-packages/crytic_compile/platform/solc.py", line 548, in _run_solc
    raise InvalidCompilation(f"Invalid solc compilation {stderr}")
crytic_compile.platform.exceptions.InvalidCompilation: Invalid solc compilation Warning: This is a pre-release compiler version, please do not use it in production.

Error: Source file requires different compiler version (current compiler is 0.8.17-develop.2022.12.9+commit.8df45f5f.Linux.g++) - note that nightly builds are considered to be strictly less than the released version
 --> src/AquariumDeParis.sol:2:1:
  |
2 | pragma solidity ^0.8.17;
  | ^^^^^^^^^^^^^^^^^^^^^^^^

Error in src/AquariumDeParis.sol
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/crytic_compile/platform/solc.py", line 544, in _run_solc
    ret: Dict = json.loads(stdout)
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, 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.8/dist-packages/slither/__main__.py", line 826, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/usr/local/lib/python3.8/dist-packages/slither/__main__.py", line 86, in process_all
    compilations = compile_all(target, **vars(args))
  File "/usr/local/lib/python3.8/dist-packages/crytic_compile/crytic_compile.py", line 637, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/usr/local/lib/python3.8/dist-packages/crytic_compile/crytic_compile.py", line 117, in __init__
    self._compile(**kwargs)
  File "/usr/local/lib/python3.8/dist-packages/crytic_compile/crytic_compile.py", line 548, in _compile
    self._platform.compile(self, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/crytic_compile/platform/solc.py", line 154, in compile
    targets_json = _get_targets_json(compilation_unit, self._target, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/crytic_compile/platform/solc.py", line 276, in _get_targets_json
    return _run_solc(
  File "/usr/local/lib/python3.8/dist-packages/crytic_compile/platform/solc.py", line 548, in _run_solc
    raise InvalidCompilation(f"Invalid solc compilation {stderr}")
crytic_compile.platform.exceptions.InvalidCompilation: Invalid solc compilation Warning: This is a pre-release compiler version, please do not use it in production.

Error: Source file requires different compiler version (current compiler is 0.8.17-develop.2022.12.9+commit.8df45f5f.Linux.g++) - note that nightly builds are considered to be strictly less than the released version
 --> src/AquariumDeParis.sol:2:1:
  |
2 | pragma solidity ^0.8.17;
  | ^^^^^^^^^^^^^^^^^^^^^^^^
enzoevers commented 1 year ago

The problem seems that when building solc from source, it will build a develop version by default.

The reason I didn't notice this was because the example contracts I'm testing on still require solc ^0.8.13.

To fix this I need to create an empty file prerelease.txt in the solidity source folder before building (found here the same problem)

Will create a fix for this soon.