crytic / crytic-compile

Abstraction layer for smart contract build systems
GNU Affero General Public License v3.0
157 stars 84 forks source link

TypeError: sequence item 0: expected str instance, dict found when running Slither #579

Open lawnmowerdeadman opened 2 weeks ago

lawnmowerdeadman commented 2 weeks ago

Describe the bug

Slither fails to compile contracts with the following error: TypeError: sequence item 0: expected str instance, dict found

Expected behavior

Slither should compile the contracts without errors.

Environment

To Reproduce

Steps to reproduce the behavior:

  1. Activate the virtual environment.
  2. Install Slither.
  3. Run Slither on the contract.

Additional context

slither.config.json content: { "solc": { "version": "0.8.28", "args": ["-I", "/path/to/project/node_modules"] } }

elopez commented 2 weeks ago

Hi, thanks for the report! can you provide a sample contract/project that triggers this issue? The full error trace and message you get on the console would be useful as well to triage this problem.

lawnmowerdeadman commented 2 weeks ago

I'm sorry if there are any parts that are difficult to understand because I don't have much knowledge. If there is anything missing in the submission, please let me know. I will provide it as much as I can with my skills.

## Describe the bug

Slither fails to compile contracts with the following error:

TypeError: sequence item 0: expected str instance, dict found


## Expected behavior

Slither should compile the contracts without errors.

## Environment

- **Slither version:** 0.10.4
- **crytic-compile version:** 0.3.7
- **solc version:** 0.8.28+commit.7893614a.Linux.g++
- **Python version:** 3.11.10
- **Operating system:** Ubuntu on WSL

## To Reproduce

Steps to reproduce the behavior:

1. Activate the virtual environment.
2. Install Slither and dependencies.
3. Run Slither on the sample contract.

## Sample Project

Attached is a sample project that triggers the issue. You can find the Solidity contract in `contracts/SampleContract.sol`.

## Error Trace

(slither-env-3.11) myuser@DESKTOP-XXXX:/mnt/c/Users/XXXX/Desktop/my-arbitrage-project/slither-sample$ slither contracts/SampleContract.sol Traceback (most recent call last): File "/mnt/c/Users/XXXX/Desktop/my-arbitrage-project/slither/slither-env-3.11/bin/slither", line 8, in sys.exit(main()) ^^^^^^ File "/mnt/c/Users/XXXX/Desktop/my-arbitrage-project/slither/slither-env-3.11/lib/python3.11/site-packages/slither/main.py", line 776, in main main_impl(all_detector_classes=detectors, all_printer_classes=printers) File "/mnt/c/Users/XXXX/Desktop/my-arbitrage-project/slither/slither-env-3.11/lib/python3.11/site-packages/slither/main.py", line 882, in main_impl ) = process_all(filename, args, detector_classes, printer_classes) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/Users/XXXX/Desktop/my-arbitrage-project/slither/slither-env-3.11/lib/python3.11/site-packages/slither/main.py", line 96, in process_all compilations = compile_all(target, vars(args)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/Users/XXXX/Desktop/my-arbitrage-project/slither/slither-env-3.11/lib/python3.11/site-packages/crytic_compile/crytic_compile.py", line 722, in compile_all compilations.append(CryticCompile(target, kwargs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/Users/XXXX/Desktop/my-arbitrage-project/slither/slither-env-3.11/lib/python3.11/site-packages/crytic_compile/crytic_compile.py", line 211, in init self._compile(kwargs) File "/mnt/c/Users/XXXX/Desktop/my-arbitrage-project/slither/slither-env-3.11/lib/python3.11/site-packages/crytic_compile/crytic_compile.py", line 633, in _compile self._platform.compile(self, kwargs) File "/mnt/c/Users/XXXX/Desktop/my-arbitrage-project/slither/slither-env-3.11/lib/python3.11/site-packages/crytic_compile/platform/solc.py", line 151, in compile targets_json = _get_targets_json(compilation_unit, self._target, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/Users/XXXX/Desktop/my-arbitrage-project/slither/slither-env-3.11/lib/python3.11/site-packages/crytic_compile/platform/solc.py", line 280, in _get_targets_json return _run_solc( ^^^^^^^^^^ File "/mnt/c/Users/XXXX/Desktop/my-arbitrage-project/slither/slither-env-3.11/lib/python3.11/site-packages/crytic_compile/platform/solc.py", line 497, in _run_solc compiler="solc", version=get_version(solc, env), optimized=is_optimized(solc_arguments) ^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/c/Users/XXXX/Desktop/my-arbitrage-project/slither/slither-env-3.11/lib/python3.11/site-packages/crytic_compile/platform/solc.py", line 378, in get_version " ".join(cmd), ^^^^^^^^^^^^^ TypeError: sequence item 0: expected str instance, dict found

## Project Directory Structure

Attempted to retrieve directory structure using `tree -L 2`, but the command is not installed. Below is the output:

(slither-env-3.11) myuser@DESKTOP-XXXX:/mnt/c/Users/XXXX/Desktop/my-arbitrage-project/slither-sample$ tree -L 2 Command 'tree' not found, but can be installed with: sudo snap install tree # version 2.1.3+pkg-5852, or sudo apt install tree # version 2.1.1-2 See 'snap info tree' for additional versions.

## Additional Context

`slither.config.json` content:

```json
{
  "solc": {
    "version": "0.8.28",
    "args": ["-I", "node_modules"]
  }
}

slither-sample.zip

elopez commented 2 weeks ago

Hi again! Your slither config file is invalid, the "solc" option only takes a string (a path to a solc binary). You probably want something more like the following instead:

{
  "solc_solcs_select": "0.8.28",
  "solc_remaps": [ "@openzeppelin/=node_modules/@openzeppelin/", "@uniswap/=node_modules/@uniswap/" ]
}

You'll see it doesn't work still even after correcting the config file; it seems there's issues on your code that you'll need to fix (e.g. your contract imports "@openzeppelin/contracts/security/ReentrancyGuard.sol" but that file doesn't exist, the file might have been moved?)

lawnmowerdeadman commented 2 weeks ago

Thanks! I'll give it a try and let you know the results later!