crytic / crytic/slither

case sensitivity for foundry projects causes file to not be found

Open
#1,421 6 comments 1 reaction 0 assignees View on GitHub
documentation
Dominant language
Python
Stars
6.4k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

### Describe the issue:

Slither is unable to locate a library in my Foundry-based Solidity project.

```
% slither .
'forge build --extra-output abi --extra-output userdoc --extra-output devdoc --extra-output evm.methodIdentifiers --force' running
Compiling 110 files with 0.8.16
Solc 0.8.16 finished in 7.36s
Compiler run successful (with warnings)
...snip...
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.10/site-packages/slither/__main__.py", line 826, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/opt/homebrew/lib/python3.10/site-packages/slither/__main__.py", line 97, in process_all
) = process_single(compilation, args, detector_classes, printer_classes)
File "/opt/homebrew/lib/python3.10/site-packages/slither/__main__.py", line 75, in process_single
slither = Slither(target, ast_format=ast, **vars(args))
File "/opt/homebrew/lib/python3.10/site-packages/slither/slither.py", line 102, in __init__
parser.parse_top_level_from_loaded_json(ast, path)
File "/opt/homebrew/lib/python3.10/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 "/opt/homebrew/lib/python3.10/site-packages/slither/core/compilation_unit.py", line 231, in get_scope
filename = self._crytic_compile_compilation_unit.crytic_compile.filename_lookup(
File "/opt/homebrew/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 199, in filename_lookup
raise ValueError(
ValueError: lib/forge-std/src/Console.sol does not exist in ['/Users/redacted/Documents/GitHub/redacted/lib/openzeppelin-contracts/contracts/access/AccessControl.sol', '/Users/redacted/Documents/GitHub/redacted/lib/openzeppelin-contracts/contracts/access/AccessControl.sol', '/Users/redacted/Documents/GitHub/redacted/lib/openzeppelin-contracts-upgradeable/contracts/security/ReentrancyGuardUpgradeable.sol' ...snip ...

...snip....
Error in .
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.10/site-packages/slither/__main__.py", line 826, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/opt/homebrew/lib/python3.10/site-packages/slither/__main__.py", line 97, in process_all
) = process_single(compilation, args, detector_classes, printer_classes)
File "/opt/homebrew/lib/python3.10/site-packages/slither/__main__.py", line 75, in process_single
slither = Slither(target, ast_format=ast, **vars(args))
File "/opt/homebrew/lib/python3.10/site-packages/slither/slither.py", line 102, in __init__
parser.parse_top_level_from_loaded_json(ast, path)
File "/opt/homebrew/lib/python3.10/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 "/opt/homebrew/lib/python3.10/site-packages/slither/core/compilation_unit.py", line 231, in get_scope
filename = self._crytic_compile_compilation_unit.crytic_compile.filename_lookup(
File "/opt/homebrew/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 199, in filename_lookup
raise ValueError(
ValueError: lib/forge-std/src/Console.sol does not exist in ['/Users/redacted/Documents/GitHub/redacted/lib/openzeppelin-contracts/contracts/access/AccessControl.sol', '/Users/redacted/Documents/GitHub/redacted/lib/openzeppelin-contracts/contracts/access/AccessControl.sol', '/Users/redacted/Documents/GitHub/redacted/lib/openzeppelin-contracts-upgradeable/contracts/security/ReentrancyGuardUpgradeable.sol ...snip...
```

### Code example to reproduce the issue:

Console.sol is referenced in the following source files:

contracts/redacted/contracts/governance/ClaimPool.sol:
```
//SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "forge-std/Console.sol";
...snip...
function isEligible(address _address) public view returns (bool) {
console.log("Checking eligibility of", _address);
...snip...
function hasClaimed(address _address) public view returns (bool) {
console.log("Checking if address has claimed", _address);
...snip...
function claimTokens() public {
console.log("redacted %s", msg.sender);
console.log("%s redacted %s", claimAmount, msg.sender);
...snip...
```

contracts/redacted/contracts/governance/ClaimPoolX.sol:
```
//SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.9;

import "forge-std/Console.sol";
...snip...
constructor(address _tokenAddress, address forwarder) {
console.log("Deploying the claim pool", _tokenAddress);
...snip...
```

foundry.toml:
```
[profile.default]
solc = "0.8.16"
libs = ["node_modules", "lib"]
verbosity = 3
fs_permissions = [{ access = "write", path = "./packages"}]
```

Console can be found in:
lib/forge-std/src/console.sol:
```
/ SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

library console {
....snip...
```

N.B. There seems to be a case mismatch involved `Console.sol` vs `console.sol` but it doesn't prevent Foundry from compiling; not sure if relevant.

### Version:

0.9.0

### Relevant log output:

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with slither/solc_parsing/slither_compilation_unit_solc.py at the import lookup around line 256 and slither/core/compilation_unit.py around line 231, then inspect crytic_compile's filename_lookup shown in the traceback. Reproduce with the provided Foundry layout and the Console.sol versus console.sol mismatch. Done means Slither can resolve the imported library without the reported ValueError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, solidity
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.