crytic / crytic/crytic-compile

ValueError from `filename_lookup` resolving an import path (truffle platform)

Open
#245 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
197
Forks
97
PR merge metrics
No merged PRs in 30d

Description

The `CryticCompile.filename_looup` crashes when resolving import directives.

Reproducer:
[test-filename-lookup-error.zip](https://github.com/crytic/crytic-compile/files/8182615/test-filename-lookup-error.zip)

Contents:
```
.
└── subdir
├── contracts
│   ├── Context.sol
│   └── Test.sol
└── truffle-config.js
```

Since `filename_looup` is used only by slither, slither is used to reproduce.
Run `slither subdir` and it crashes with following error:
```
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.9/site-packages/slither/__main__.py", line 743, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/opt/homebrew/lib/python3.9/site-packages/slither/__main__.py", line 84, in process_all
) = process_single(compilation, args, detector_classes, printer_classes)
File "/opt/homebrew/lib/python3.9/site-packages/slither/__main__.py", line 67, in process_single
slither = Slither(target, ast_format=ast, **vars(args))
File "/opt/homebrew/lib/python3.9/site-packages/slither/slither.py", line 97, in __init__
parser.parse_top_level_from_loaded_json(ast, path)
File "/opt/homebrew/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 224, in parse_top_level_from_loaded_json
get_imported_scope = self.compilation_unit.get_scope(import_directive.filename)
File "/opt/homebrew/lib/python3.9/site-packages/slither/core/compilation_unit.py", line 231, in get_scope
filename = self._crytic_compile_compilation_unit.crytic_compile.filename_lookup(
File "/opt/homebrew/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 199, in filename_lookup
raise ValueError(
ValueError: contracts/Context.sol does not exist in ['subdir/contracts/Context.sol', 'subdir/contracts/Context.sol', 'subdir/contracts/Test.sol', 'subdir/contracts/Test.sol']
```

On the other hand, if you run slither under the subdir directory as `slither .`, slither runs without any crashes.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.