slither fails for specific brownie projects
- Dominant language
- Python
- Stars
- 6.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
I think this is actually a bug in brownie, but I'm not sure.
Brownie doesn't output compilation artifacts for some solidity files. For example, a helper file that only has some free functions. When slither is crawling file imports, it looks for the helper file's compilation artifact and then doesn't find it, so it crashes.
Example repo where slither crashes: https://github.com/UsmannK/slither-brownie-test
Test.sol
```solidity
import { magic_number } from "./Helper.sol";
contract Test {
function test() public pure returns (uint256) {
return magic_number();
}
}
```
Helper.sol
```solidity
function magic_number() pure returns (uint256) {
return 0xdeadbeef;
}
```
Output
```
$ slither .
Brownie v1.19.2 - Python development framework for Ethereum
Project has been compiled. Build artifacts saved at /Users/usmannkhan/Development/brownie-test/build/contracts
Traceback (most recent call last):
File "/Users/usmannkhan/.pyenv/versions/3.10.7/lib/python3.10/site-packages/slither/__main__.py", line 834, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/Users/usmannkhan/.pyenv/versions/3.10.7/lib/python3.10/site-packages/slither/__main__.py", line 98, in process_all
) = process_single(compilation, args, detector_classes, printer_classes)
File "/Users/usmannkhan/.pyenv/versions/3.10.7/lib/python3.10/site-packages/slither/__main__.py", line 76, in process_single
slither = Slither(target, ast_format=ast, **vars(args))
File "/Users/usmannkhan/.pyenv/versions/3.10.7/lib/python3.10/site-packages/slither/slither.py", line 112, in __init__
parser.parse_top_level_from_loaded_json(ast, path)
File "/Users/usmannkhan/.pyenv/versions/3.10.7/lib/python3.10/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 281, in parse_top_level_from_loaded_json
get_imported_scope = self.compilation_unit.get_scope(import_directive.filename)
File "/Users/usmannkhan/.pyenv/versions/3.10.7/lib/python3.10/site-packages/slither/core/compilation_unit.py", line 243, in get_scope
filename = self._crytic_compile_compilation_unit.crytic_compile.filename_lookup(
File "/Users/usmannkhan/.pyenv/versions/3.10.7/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 182, in filename_lookup
raise ValueError(f"{filename} does not exist")
ValueError: contracts/Helper.sol does not exist
Error in .
Traceback (most recent call last):
File "/Users/usmannkhan/.pyenv/versions/3.10.7/lib/python3.10/site-packages/slither/__main__.py", line 834, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/Users/usmannkhan/.pyenv/versions/3.10.7/lib/python3.10/site-packages/slither/__main__.py", line 98, in process_all
) = process_single(compilation, args, detector_classes, printer_classes)
File "/Users/usmannkhan/.pyenv/versions/3.10.7/lib/python3.10/site-packages/slither/__main__.py", line 76, in process_single
slither = Slither(target, ast_format=ast, **vars(args))
File "/Users/usmannkhan/.pyenv/versions/3.10.7/lib/python3.10/site-packages/slither/slither.py", line 112, in __init__
parser.parse_top_level_from_loaded_json(ast, path)
File "/Users/usmannkhan/.pyenv/versions/3.10.7/lib/python3.10/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 281, in parse_top_level_from_loaded_json
get_imported_scope = self.compilation_unit.get_scope(import_directive.filename)
File "/Users/usmannkhan/.pyenv/versions/3.10.7/lib/python3.10/site-packages/slither/core/compilation_unit.py", line 243, in get_scope
filename = self._crytic_compile_compilation_unit.crytic_compile.filename_lookup(
File "/Users/usmannkhan/.pyenv/versions/3.10.7/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 182, in filename_lookup
raise ValueError(f"{filename} does not exist")
ValueError: contracts/Helper.sol does not exist
```
Contributor guide
Assessment
This issue has not been assessed yet.