crytic-compile
crytic-compile copied to clipboard
[Bug-Candidate]: Foundry repos erroring with `ValueError: <file> does not exist in [ <lots of paths here> ]`
Describe the issue:
I'm seeing an error when running slither .
in two foundry repos (both are currently private or I'd link to them). crytic-compile .
runs successfully, but slither .
exits with:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/slither/__main__.py", line 744, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/usr/local/lib/python3.9/site-packages/slither/__main__.py", line 87, in process_all
) = process_single(compilation, args, detector_classes, printer_classes)
File "/usr/local/lib/python3.9/site-packages/slither/__main__.py", line 70, in process_single
slither = Slither(target, ast_format=ast, **vars(args))
File "/usr/local/lib/python3.9/site-packages/slither/slither.py", line 95, in __init__
parser.parse_top_level_from_loaded_json(ast, path)
File "/usr/local/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 256, in parse_top_level_from_loaded_json
get_imported_scope = self.compilation_unit.get_scope(import_directive.filename)
File "/usr/local/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 "/usr/local/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 199, in filename_lookup
raise ValueError(
ValueError: /path/to/my/project/lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol does not exist in [ <lots of paths here> ]
That IERC20 file does exist at the path shown, but it is not present in the list of files within the brackets. Same error but different file in the second repo where this happens. There are no symbolic links, one repo uses default remappings, and the other has remappings = ["test/=test/"]
in the foundy.toml file
Code example to reproduce the issue:
See above
Version:
Versions:
- slither 0.8.3
- crytic-compile 0.2.3
- macOS 12.3.1
- solc 0.8.13+commit.abaa5c0e.Darwin.appleclang
- forge 0.2.0 (4604a42 2022-05-12T00:08:20.870532+00:00)
Relevant log output:
No response
Hey @mds1. It might be due to https://github.com/foundry-rs/foundry/issues/1646.
A quick workaround is to add a fake contract (contract Fake{}
) in the file listed in the ValueError
. Let me know if that works/does not work.
Ok I found the issue for one of the two repos, which was:
// file: test/utils/DSTestPlus.sol
// The file listed in `ValueError` was this imported DSTest Plus from solmate. It's no longer used,
// so I removed that import and slither now works. So it seems the issue is that no artifacts were
// found for that import, which makes sense since it's unused, but slither still looked for them.
import { DSTestPlus as DSTestPlusSolmate } from "solmate/test/utils/DSTestPlus.sol";
import "forge-std/Test.sol";
// Used to to use the import, at that time we had this:
contract DSTestPlus is Test, DSTestPlusSolmate {
// --- snip ---
}
// But it's now the import is unused, so we currently have this:
contract DSTestPlus is Test {
// --- snip ---
}
I have not yet looked at the second repo but I'll see if it was similar cause.
For the second repo, the error is with import { IERC20 } from "openzeppelin-contracts/contracts/interfaces/IERC20.sol";
. I've removed all unused imports, but still received the error for that file.
Looking at that file, you can see all it does is import another file, so I tried your workaround of adding an empty, fake contract to that file. That got me past the next error.
But it seems like I'm now stuck:
- We have a library called
Math.sol
, but have a dependency that uses OZ'sMath.sol
- We use a dependency that uses OpenZeppelin's
ERC20.sol
, but our contracts uses Solmate'sERC20.sol
These conflicting file/contract names seem to be the issue. If I remove the conflict by renaming our own library, that brings me to the next error of the conflicting ERC20 contracts. solc is able to compile things as expected, so I think slither should also be able to handle these conflicts without renames?
It looks like it's working now after running foundryup -b master
, can you confirm @mds1?
Looks like I'm getting the same error after running slither with the latest foundry master: .../lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol does not exist in [ ... ]
.
I think there were two causes for this error. The first was https://github.com/foundry-rs/foundry/issues/1646 which was previously worked around with contract Fake{}
, and I agree that one is resolved. The other was the conflicting file names which I believe is a separate (but related?) cause