Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug-Candidate]: crytic_compile.platform.exceptions.InvalidCompilation: Unknown file #585

Open
unionmini opened this issue Jan 16, 2025 · 10 comments

Comments

@unionmini
Copy link

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:

@smonicas smonicas transferred this issue from crytic/slither Jan 20, 2025
@smonicas
Copy link
Collaborator

Hi, can you share the codebase causing this? Otherwise it's difficult to debug it

@unionmini
Copy link
Author

https://github.com/golemfoundation/octant-strategy-foundry-mix

It contains private git submodule

@smonicas
Copy link
Collaborator

I cannot reproduce the issue. I'm running slither . and it works.

@unionmini
Copy link
Author

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

@smonicas
Copy link
Collaborator

I see. I can't check it given that it's private and cannot build but it could be the same issue as in #572 and foundry-rs/foundry#7591. 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.

@unionmini
Copy link
Author

Thanks for your advice, I already checked them, but can't find solution there.
So could you explain what was the problem there?

@smonicas
Copy link
Collaborator

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.

@unionmini
Copy link
Author

4a4dadc8e1f19b972069963e7e7a45e2.json
Sorry for rushing a bit, could you check please?

@smonicas
Copy link
Collaborator

smonicas commented Jan 20, 2025

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

@unionmini
Copy link
Author

How can I handle this issue? there is no solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants