[Bug-Candidate]: crytic_compile.platform.exceptions.InvalidCompilation: Unknown file
Describe the issue:
I got this error while running slither.
'forge clean' running (wd: /home/joelkrusala/workspace/octant-strategy-foundry-mix)
'forge config --json' running
'forge build --build-info --skip */test/** */script/** --force' running (wd: /home/joelkrusala/workspace/octant-strategy-foundry-mix)
Traceback (most recent call last):
File "/home/joelkrusala/anaconda3/bin/slither", line 8, in <module>
sys.exit(main())
File "/home/joelkrusala/anaconda3/lib/python3.8/site-packages/slither/__main__.py", line 776, in main
main_impl(all_detector_classes=detectors, all_printer_classes=printers)
File "/home/joelkrusala/anaconda3/lib/python3.8/site-packages/slither/__main__.py", line 882, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/home/joelkrusala/anaconda3/lib/python3.8/site-packages/slither/__main__.py", line 96, in process_all
compilations = compile_all(target, **vars(args))
File "/home/joelkrusala/anaconda3/lib/python3.8/site-packages/crytic_compile/crytic_compile.py", line 722, in compile_all
compilations.append(CryticCompile(target, **kwargs))
File "/home/joelkrusala/anaconda3/lib/python3.8/site-packages/crytic_compile/crytic_compile.py", line 211, in __init__
self._compile(**kwargs)
File "/home/joelkrusala/anaconda3/lib/python3.8/site-packages/crytic_compile/crytic_compile.py", line 633, in _compile
self._platform.compile(self, **kwargs)
File "/home/joelkrusala/anaconda3/lib/python3.8/site-packages/crytic_compile/platform/foundry.py", line 86, in compile
hardhat_like_parsing(crytic_compile, self._target, build_directory, self._target)
File "/home/joelkrusala/anaconda3/lib/python3.8/site-packages/crytic_compile/platform/hardhat.py", line 97, in hardhat_like_parsing
path = convert_filename(
File "/home/joelkrusala/anaconda3/lib/python3.8/site-packages/crytic_compile/utils/naming.py", line 169, in convert_filename
filename = _verify_filename_existence(filename, cwd)
File "/home/joelkrusala/anaconda3/lib/python3.8/site-packages/crytic_compile/utils/naming.py", line 119, in _verify_filename_existence
raise InvalidCompilation(f"Unknown file: {filename}")
crytic_compile.platform.exceptions.InvalidCompilation: Unknown file: src/errors.sol
Also CI is failing with this error
Traceback (most recent call last):
File "/opt/slither/bin/slither", line 8, in <module>
sys.exit(main())
File "/opt/slither/lib/python3.9/site-packages/slither/__main__.py", line 776, in main
main_impl(all_detector_classes=detectors, all_printer_classes=printers)
File "/opt/slither/lib/python3.9/site-packages/slither/__main__.py", line 882, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/opt/slither/lib/python3.9/site-packages/slither/__main__.py", line 96, in process_all
compilations = compile_all(target, **vars(args))
File "/opt/slither/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 722, in compile_all
compilations.append(CryticCompile(target, **kwargs))
File "/opt/slither/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 211, in __init__
self._compile(**kwargs)
File "/opt/slither/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 633, in _compile
self._platform.compile(self, **kwargs)
File "/opt/slither/lib/python3.9/site-packages/crytic_compile/platform/foundry.py", line 86, in compile
hardhat_like_parsing(crytic_compile, self._target, build_directory, self._target)
File "/opt/slither/lib/python3.9/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.
Code example to reproduce the issue:
- name: Slither analysis
uses: crytic/[email protected]
with:
fail-on: "high"
slither-config: slither.config.json
ignore-compile: true
Version:
0.10.4
Relevant log output:
Hi, can you share the codebase causing this? Otherwise it's difficult to debug it
https://github.com/golemfoundation/octant-strategy-foundry-mix
It contains private git submodule
I cannot reproduce the issue. I'm running slither . and it works.
https://github.com/golemfoundation/octant-strategy-foundry-mix/tree/joel/osu-354-obx-create-a-yield-bearing-strategy
Please try this branch, but as I mentioned it contains private git submodule
I see. I can't check it given that it's private and cannot build but it could be the same issue as in foundry-rs/foundry#572 and https://github.com/foundry-rs/compilers/issues/246. Basically check if in the build-info there is a file multiple times with different paths. In this case it should be about the src/errors.sol file.
Thanks for your advice, I already checked them, but can't find solution there. So could you explain what was the problem there?
The problem is in foundry generating multiple paths for the same file in the artifacts leading to crytic-compile crashing. It's an issue in foundry and for what i know there is not a real solution, you could try to move around the file or the way you import it but i'm not sure. To check if you are affected you should follow the description in the open foundry issue and see if you have multiple src/errors.sol paths.
4a4dadc8e1f19b972069963e7e7a45e2.json Sorry for rushing a bit, could you check please?
Yes it's that issue. If you look under ["output"]["sources"] and search for src/errors.sol you will see there are two:
- lib/octant-v2-core/src/errors.sol with "id" 22
- src/errors.sol with "id" 48 and empty AST
How can I handle this issue? there is no solution?