Skip to content

case sensitivity for foundry projects causes file to not be found #1421

Open
@kristovatlas

Description

@kristovatlas

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions