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

slither fails to resolve imports in dependency due to issue in foundry #2483

Open
alphastorm opened this issue Jun 12, 2024 · 2 comments
Open

Comments

@alphastorm
Copy link

alphastorm commented Jun 12, 2024

Describe the issue:

forge is able to compile the contracts and run the test successfully, but slither fails to resolve the imports in the dependency even when the --ignore-compile flag is passed.

Code example to reproduce the issue:

Repo: https://github.com/alphastorm/slither-import-breaking

Steps:

  • forge init a new repo
  • forge install euler-xyz/euler-price-oracle
  • add euler-price-oracle/=lib/euler-price-oracle/ to remappings.txt
  • add this import to Counter.sol: import { BaseAdapter, Errors, IPriceOracle } from "euler-price-oracle/src/adapter/BaseAdapter.sol";

Version:

0.10.3

Relevant log output:

    ~/Dev/slither-import-breaking    master  forge test                                                                                                 ✔  cove-contracts-boosties 3.9.17   01:59:22 PM 
[⠊] Compiling...
[⠃] Compiling 28 files with Solc 0.8.23
[⠊] Solc 0.8.23 finished in 869.49ms
Compiler run successful!

Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 31154, ~: 31310)
[PASS] test_Increment() (gas: 31325)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 11.80ms (6.66ms CPU time)

Ran 1 test suite in 119.02ms (11.80ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)
    ~/Dev/slither-import-breaking    master  forge clean                                                                                                ✔  cove-contracts-boosties 3.9.17   01:59:26 PM 
    ~/Dev/slither-import-breaking    master  forge build --build-info --skip '*/test/**' '*/script/**'                                                  ✔  cove-contracts-boosties 3.9.17   01:59:29 PM 
[⠊] Compiling...
[⠒] Compiling 5 files with Solc 0.8.23
[⠢] Solc 0.8.23 finished in 20.93ms
Compiler run successful!
    ~/Dev/slither-import-breaking    master  slither --version                                                                                          ✔  cove-contracts-boosties 3.9.17   01:59:33 PM 
0.10.3
    ~/Dev/slither-import-breaking    master  slither . --ignore-compile                                                                                 ✔  cove-contracts-boosties 3.9.17   01:59:38 PM 
--ignore-compile used, if something goes wrong, consider removing the ignore compile flag
Traceback (most recent call last):
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/bin/slither", line 8, in <module>
    sys.exit(main())
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/lib/python3.9/site-packages/slither/__main__.py", line 782, in main
    main_impl(all_detector_classes=detectors, all_printer_classes=printers)
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/lib/python3.9/site-packages/slither/__main__.py", line 888, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/lib/python3.9/site-packages/slither/__main__.py", line 113, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/lib/python3.9/site-packages/slither/__main__.py", line 80, in process_single
    slither = Slither(target, ast_format=ast, **vars(args))
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/lib/python3.9/site-packages/slither/slither.py", line 156, in __init__
    sol_parser.parse_top_level_items(ast, path)
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 326, in parse_top_level_items
    get_imported_scope = self.compilation_unit.get_scope(import_directive.filename)
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/lib/python3.9/site-packages/slither/core/compilation_unit.py", line 282, in get_scope
    filename = self._crytic_compile_compilation_unit.crytic_compile.filename_lookup(
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 283, in filename_lookup
    raise ValueError(f"{filename} does not exist")
ValueError: src/interfaces/IPriceOracle.sol does not exist
    ~/Dev/slither-import-breaking    master  slither .                                                                                                1 ✘  cove-contracts-boosties 3.9.17   01:59:43 PM 
'forge clean' running (wd: /Users/srs/Development/slither-import-breaking)
'forge config --json' running
'forge build --build-info --skip */test/** */script/** --force' running (wd: /Users/srs/Development/slither-import-breaking)
Traceback (most recent call last):
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/bin/slither", line 8, in <module>
    sys.exit(main())
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/lib/python3.9/site-packages/slither/__main__.py", line 782, in main
    main_impl(all_detector_classes=detectors, all_printer_classes=printers)
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/lib/python3.9/site-packages/slither/__main__.py", line 888, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/lib/python3.9/site-packages/slither/__main__.py", line 113, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/lib/python3.9/site-packages/slither/__main__.py", line 80, in process_single
    slither = Slither(target, ast_format=ast, **vars(args))
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/lib/python3.9/site-packages/slither/slither.py", line 156, in __init__
    sol_parser.parse_top_level_items(ast, path)
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 326, in parse_top_level_items
    get_imported_scope = self.compilation_unit.get_scope(import_directive.filename)
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/lib/python3.9/site-packages/slither/core/compilation_unit.py", line 282, in get_scope
    filename = self._crytic_compile_compilation_unit.crytic_compile.filename_lookup(
  File "/Users/srs/.pyenv/versions/cove-contracts-boosties/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 283, in filename_lookup
    raise ValueError(f"{filename} does not exist")
ValueError: src/interfaces/IPriceOracle.sol does not exist
@alphastorm alphastorm added the bug-candidate Bugs reports that are not yet confirmed label Jun 12, 2024
@DarkaMaul
Copy link
Contributor

Hi - thanks for your report.

I was able to reproduce the problem on my end.

It appears the problem comes from the {build_id}.json file:

While the input sources map in the document is correct :

 "input": {
    "language": "Solidity",
    "sources": {
      "lib/euler-price-oracle/src/adapter/BaseAdapter.sol": ... ,
      "lib/euler-price-oracle/src/interfaces/IPriceOracle.sol": ...,
      "lib/euler-price-oracle/src/lib/Errors.sol": ... , 
      "lib/forge-std/src/interfaces/IERC20.sol": ... ,
      "src/Counter.sol": ...
    },

The output/sources contains two more files whose ast are empty :

  "output": {
    "sources": {
      "lib/euler-price-oracle/src/adapter/BaseAdapter.sol": ...,
      "lib/euler-price-oracle/src/interfaces/IPriceOracle.sol": ...,
      "lib/euler-price-oracle/src/lib/Errors.sol": ...,
      "lib/forge-std/src/interfaces/IERC20.sol": ...,
      "src/Counter.sol":  ...,
      "src/interfaces/IPriceOracle.sol": {
        "id": 5,
        "ast": {}
      },
      "src/lib/Errors.sol": {
        "id": 6,
        "ast": {}
      }

Since those two files do not exist, slither fails to perform its analysis.

Remaining questions :

  • How the compiler deal with this ?
  • How to solve the problem within slither (or in crytic compile).

@0xalpharush
Copy link
Contributor

I believe this is the same issue as reported in #1622 and blocked on an issue in Foundry foundry-rs/foundry#7591

@0xalpharush 0xalpharush changed the title [Bug-Candidate]: slither fails to resolve imports in dependency slither fails to resolve imports in dependency due to issue in foundry Jun 24, 2024
@0xalpharush 0xalpharush removed the bug-candidate Bugs reports that are not yet confirmed label Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants