crytic / crytic/slither

[Bug-Candidate]: Running Slither on a multi solc versions project

Open
#2,651 0 comments 0 reactions 0 assignees View on GitHub
bug-candidate
Dominant language
Python
Stars
6.4k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

### Describe the issue:

I am running slither as part of a gitlab pipeline which manage several versions from 0.5.0 to 0.8.28 using solc-select.
It iterates through all smart contracts and set solc globally before each slither call.
slither gets the evm-version from the toml but finds 'auto_detect_solc = true' which then default to '--evm-version: cancun'. Creating a mismatch in between the solc and the evm-version during slither execution.

I tried setting the evm-version like so: '--solc-args "--evm-version london"', without success.

### Code example to reproduce the issue:

#!/bin/bash
export PATH="/root/.foundry/bin:${PATH}"

solc-select install 0.5.0
solc-select install 0.8.17

solc-select use 0.8.17

slither my_contract.sol \
--solc-args "--evm-version $EVM_VERSION" \

### Version:

0.10.4

### Relevant log output:

```shell
Switched global version to 0.8.8
-> Slither on ./apps/NFT/contracts/contract.sol (Solc: 0.8.8 at /root/.crytic/bin/solc / EVM: london)
'forge config --json' running
Could not detect solc version from Foundry config. Falling back to system version...
'solc --version' running
'solc @chainlink/contracts/=dependencies/@chainlink-contracts-1.3.0/ @gnosis.pm/safe-contracts/=dependencies/@gnosis-pm-safe-contracts-1.3.0/ @gnosis.pm/zodiac/=dependencies/gnosisguild-zodiac-4.0.5/ @openzeppelin-contracts/=dependencies/@openzeppelin-contracts-4.9.3/ @openzeppelin/contracts-upgradeable/=dependencies/@openzeppelin-contracts-upgradeable-4.9.3/ openzeppelin-contracts-upgradeable/=dependencies/@openzeppelin-contracts-upgradeable-4.9.3/ @openzeppelin/contracts/=dependencies/@openzeppelin-contracts-4.9.3/ @rari-capital/solmate/=dependencies/solmate-6.8.0/ @safe-global/safe-contracts/=dependencies/safe-global-safe-smart-account-1.4.1-3/ forge-std/=dependencies/forge-std-1.9.4/src/ operator-filter-registry/=dependencies/projectopensea-operator-filter-registry-1.4.2/ @chainlink-contracts-1.3.0/=dependencies/@chainlink-contracts-1.3.0/src/ @gnosis-pm-safe-contracts-1.3.0/=dependencies/@gnosis-pm-safe-contracts-1.3.0/contracts/ @openzeppelin-contracts-4.9.3/=dependencies/@openzeppelin-contracts-4.9.3/ @openzeppelin-contracts-upgradeable-4.9.3/=dependencies/@openzeppelin-contracts-upgradeable-4.9.3/ @openzeppelin-contracts-upgradeable-5.2.0/=dependencies/@openzeppelin-contracts-upgradeable-5.2.0/ forge-std-1.9.4/=dependencies/forge-std-1.9.4/src/ gnosisguild-zodiac-4.0.5/=dependencies/gnosisguild-zodiac-4.0.5/contracts/ projectopensea-operator-filter-registry-1.4.2/=dependencies/projectopensea-operator-filter-registry-1.4.2/src/ safe-global-safe-smart-account-1.4.1-3/=dependencies/safe-global-safe-smart-account-1.4.1-3/ solmate-6.8.0/=dependencies/solmate-6.8.0/src/ --combined-json abi,ast,bin,bin-runtime,srcmap,srcmap-runtime,userdoc,devdoc,hashes,compact-format --optimize --optimize-runs 200 --evm-version cancun --allow-paths .,~/apps/NFT/contracts' running
Compilation warnings/errors on ./apps/NFT/contracts/contract.sol:
Invalid option for --evm-version: cancun
Traceback (most recent call last):
File "/root/.crytic/lib/python3.10/site-packages/crytic_compile/platform/solc.py", line 582, in _run_solc
ret: Dict = json.loads(stdout)
File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.10/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 "/root/.crytic/bin/slither", line 8, in
sys.exit(main())
File "/root/.crytic/lib/python3.10/site-packages/slither/__main__.py", line 776, in main
main_impl(all_detector_classes=detectors, all_printer_classes=printers)
File "/root/.crytic/lib/python3.10/site-packages/slither/__main__.py", line 882, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/root/.crytic/lib/python3.10/site-packages/slither/__main__.py", line 96, in process_all
compilations = compile_all(target, **vars(args))
File "/root/.crytic/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 722, in compile_all
compilations.append(CryticCompile(target, **kwargs))
File "/root/.crytic/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 211, in __init__
self._compile(**kwargs)
File "/root/.crytic/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 633, in _compile
self._platform.compile(self, **kwargs)
File "/root/.crytic/lib/python3.10/site-packages/crytic_compile/platform/solc.py", line 151, in compile
targets_json = _get_targets_json(compilation_unit, self._target, **kwargs)
File "/root/.crytic/lib/python3.10/site-packages/crytic_compile/platform/solc.py", line 280, in _get_targets_json
return _run_solc(
File "/root/.crytic/lib/python3.10/site-packages/crytic_compile/platform/solc.py", line 586, in _run_solc
raise InvalidCompilation(f"Invalid solc compilation {stderr}")
crytic_compile.platform.exceptions.InvalidCompilation: Invalid solc compilation Invalid option for --evm-version: cancun
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the shown slither my_contract.sol invocation with solc 0.8.17, then inspect crytic_compile/platform/solc.py, especially _get_targets_json and _run_solc, using the traceback as entry points. Done means a selected compiler that does not support Cancun is invoked with a compatible EVM version and the multi-version workflow completes without the reported InvalidCompilation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, solidity
Domain
compilers, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.