[Bug-Candidate]: Fail to scan in a project that supports both Hardhat and Foundry, keeps deleting the `build-info` folder when `slither .` is used
- Dominant language
- Python
- Stars
- 6.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the issue:
I have a project that uses both foundry and hardhat. Slither throws an error whenever I run it `slither .`
I have already upgraded slither with `using python3 -m pip install slither-analyzer -U`
When I run `slither .` it throws this error:
```
'forge clean' running (wd: /home/smartchain/code/audits/2024-04-interest-rate-model-SquilliamX/protocol)
'forge config --json' running
'forge build --build-info --skip */test/** */scripts/** --force' running (wd: /home/smartchain/code/audits/2024-04-interest-rate-model-SquilliamX/protocol)
Traceback (most recent call last):
File "/home/smartchain/.local/bin/slither", line 8, in
sys.exit(main())
File "/home/smartchain/.local/lib/python3.10/site-packages/slither/__main__.py", line 753, in main
main_impl(all_detector_classes=detectors, all_printer_classes=printers)
File "/home/smartchain/.local/lib/python3.10/site-packages/slither/__main__.py", line 859, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/home/smartchain/.local/lib/python3.10/site-packages/slither/__main__.py", line 96, in process_all
compilations = compile_all(target, **vars(args))
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 722, in compile_all
compilations.append(CryticCompile(target, **kwargs))
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 211, in __init__
self._compile(**kwargs)
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 633, in _compile
self._platform.compile(self, **kwargs)
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/platform/foundry.py", line 86, in compile
hardhat_like_parsing(crytic_compile, self._target, build_directory, self._target)
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/platform/hardhat.py", line 52, in hardhat_like_parsing
raise InvalidCompilation(txt)
crytic_compile.platform.exceptions.InvalidCompilation: Compilation failed. Can you run build command?
out/build-info is not a directory.
```
Now i thought this was because of my foundry.toml which is here:
```
[profile.default]
solc_version="0.8.25"
evm_version = "cancun"
optimizer = true
optimizer_runs = 200
revert_strings = "strip"
isolate = true
ffi = true
src = "test"
out = "artifacts/foundry"
script = "scripts"
cache_path = "cache/foundry"
fs_permissions = [{ access = "read", path = "./deployments" }]
verbosity = 3
[fmt]
tab_width = 2
bracket_spacing = true
number_underscore = "thousands"
[profile.production.fuzz]
runs = 66_666
[profile.overkill.fuzz]
runs = 6_666_666
```
and I thought the ``out = "artifacts/foundry" `` line was causing the error, but this is not the case. I changed the `` out = "artifacts/foundry" `` to `out = "out" ` and then ran `forge build` and then `slither .` it still throws an error. Now this error is very weird because when I compile the project with ``forge build``, it creates the out folder with all the data inside of it. But when i run `slither .` right after, it deletes everything in the `out` folder and says it is empty! The error this is:
```
$ slither .
'forge clean' running (wd: /home/smartchain/code/audits/2024-04-interest-rate-model-SquilliamX/protocol)
'forge config --json' running
'forge build --build-info --skip */test/** */scripts/** --force' running (wd: /home/smartchain/code/audits/2024-04-interest-rate-model-SquilliamX/protocol)
Traceback (most recent call last):
File "/home/smartchain/.local/bin/slither", line 8, in
sys.exit(main())
File "/home/smartchain/.local/lib/python3.10/site-packages/slither/__main__.py", line 753, in main
main_impl(all_detector_classes=detectors, all_printer_classes=printers)
File "/home/smartchain/.local/lib/python3.10/site-packages/slither/__main__.py", line 859, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/home/smartchain/.local/lib/python3.10/site-packages/slither/__main__.py", line 96, in process_all
compilations = compile_all(target, **vars(args))
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 722, in compile_all
compilations.append(CryticCompile(target, **kwargs))
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 211, in __init__
self._compile(**kwargs)
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 633, in _compile
self._platform.compile(self, **kwargs)
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/platform/foundry.py", line 86, in compile
hardhat_like_parsing(crytic_compile, self._target, build_directory, self._target)
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/platform/hardhat.py", line 52, in hardhat_like_parsing
raise InvalidCompilation(txt)
crytic_compile.platform.exceptions.InvalidCompilation: Compilation failed. Can you run build command?
out/build-info is not a directory.
```
I searched the issues in the slither repo and I found that i could run this command in my terminal: `` slither . --compile-force-framework hardhat --ignore-compile``
However this throws another error. the error this time is
```
slither . --compile-force-framework hardhat --ignore-compile
Problem deserializing hardhat configuration, using defaults: Expecting value: line 2 column 1 (char 1)
Traceback (most recent call last):
File "/home/smartchain/.local/bin/slither", line 8, in
sys.exit(main())
File "/home/smartchain/.local/lib/python3.10/site-packages/slither/__main__.py", line 753, in main
main_impl(all_detector_classes=detectors, all_printer_classes=printers)
File "/home/smartchain/.local/lib/python3.10/site-packages/slither/__main__.py", line 859, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/home/smartchain/.local/lib/python3.10/site-packages/slither/__main__.py", line 96, in process_all
compilations = compile_all(target, **vars(args))
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 722, in compile_all
compilations.append(CryticCompile(target, **kwargs))
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 211, in __init__
self._compile(**kwargs)
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 633, in _compile
self._platform.compile(self, **kwargs)
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/platform/hardhat.py", line 183, in compile
hardhat_like_parsing(crytic_compile, self._target, build_directory, hardhat_working_dir)
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/platform/hardhat.py", line 52, in hardhat_like_parsing
raise InvalidCompilation(txt)
crytic_compile.platform.exceptions.InvalidCompilation: Compilation failed. Can you run build command?
/home/smartchain/code/audits/2024-04-interest-rate-model-SquilliamX/protocol/artifacts/build-info is not a directory.
```
The last line in the error says artifacts/build-info is not a directory, which is true because in my artifacts folder there is two sub folders, `foundry` and `hardhat` with data inside of each sub-folder. However when I change my foundry.toml to `` out = "artifacts" `` , I run `forge build` and then run `slither . --compile-force-framework hardhat --ignore-compile` , it throws another error:
```
$ slither . --compile-force-framework hardhat --ignore-compile
Problem deserializing hardhat configuration, using defaults: Expecting value: line 2 column 1 (char 1)
Traceback (most recent call last):
File "/home/smartchain/.local/bin/slither", line 8, in
sys.exit(main())
File "/home/smartchain/.local/lib/python3.10/site-packages/slither/__main__.py", line 753, in main
main_impl(all_detector_classes=detectors, all_printer_classes=printers)
File "/home/smartchain/.local/lib/python3.10/site-packages/slither/__main__.py", line 859, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/home/smartchain/.local/lib/python3.10/site-packages/slither/__main__.py", line 96, in process_all
compilations = compile_all(target, **vars(args))
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 722, in compile_all
compilations.append(CryticCompile(target, **kwargs))
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 211, in __init__
self._compile(**kwargs)
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 633, in _compile
self._platform.compile(self, **kwargs)
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/platform/hardhat.py", line 183, in compile
hardhat_like_parsing(crytic_compile, self._target, build_directory, hardhat_working_dir)
File "/home/smartchain/.local/lib/python3.10/site-packages/crytic_compile/platform/hardhat.py", line 52, in hardhat_like_parsing
raise InvalidCompilation(txt)
crytic_compile.platform.exceptions.InvalidCompilation: Compilation failed. Can you run build command?
/home/smartchain/code/audits/2024-04-interest-rate-model-SquilliamX/protocol/artifacts/build-info is not a directory.
```
Now this is very interesting because after I run `forge build` with my `foundry.toml` with `out = "artifacts"` it created the `build-info` folder, but when i run `slither . --compile-force-framework hardhat --ignore-compile` , it deletes the entire `build-info` in my `artifacts` folder.
### Code example to reproduce the issue:
The github repo is here: https://github.com/exactly/protocol
### Version:
0.10.2
Contributor guide
Assessment
This issue has not been assessed yet.