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]: The system cannot find the file specified - that exists #1426

Closed
majorisgit opened this issue Oct 14, 2022 · 5 comments
Closed
Labels
bug-candidate Bugs reports that are not yet confirmed

Comments

@majorisgit
Copy link

Describe the issue:

crytic_compile.platform.exceptions.InvalidCompilation: [WinError 2] The system cannot find the file specified
File clearly exists.

I tried command line and VS code addon. Both fail with same error.

Code example to reproduce the issue:

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

contract smallTestContract{
address public contractOwner;
address public contractAddress = address(this);

constructor () payable {
    contractOwner = msg.sender;
}


modifier onlyOwner (){
    require(msg.sender == contractOwner, "Only the contract owner can execute.");
    _;
}

function endContract (address payable addr) public onlyOwner {
    selfdestruct(addr);
}

}

Version:

D:\project\contract>slither --version
0.9.0

Relevant log output:

Directory of D:\project\contract

10/14/2022  11:07 AM    <DIR>          .
10/14/2022  11:07 AM    <DIR>          ..
08/19/2022  07:01 AM             3,735 First.sol
09/16/2022  05:59 PM               516 Small_TestContract.sol
               2 File(s)         4,251 bytes
               2 Dir(s)  262,996,754,432 bytes free

D:\project\contract>
D:\project\contract>slither Small_TestContract.sol
Traceback (most recent call last):
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\platform\solc.py", line 370, in get_version
    with subprocess.Popen(
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 969, in __init__        
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1438, in _execute_child 
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\slither\__main__.py", line 826, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\slither\__main__.py", line 86, 
in process_all
    compilations = compile_all(target, **vars(args))
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\crytic_compile.py", line 637, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\crytic_compile.py", line 117, in __init__
    self._compile(**kwargs)
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\crytic_compile.py", line 548, in _compile
    self._platform.compile(self, **kwargs)
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\platform\solc.py", line 154, in compile
    targets_json = _get_targets_json(compilation_unit, self._target, **kwargs)
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\platform\solc.py", line 276, in _get_targets_json
    return _run_solc(
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\platform\solc.py", line 474, in _run_solc
    compiler="solc", version=get_version(solc, env), optimized=is_optimized(solc_arguments)
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\platform\solc.py", line 385, in get_version
    raise InvalidCompilation(error)
crytic_compile.platform.exceptions.InvalidCompilation: [WinError 2] The system cannot find the file specified     
Error in Small_TestContract.sol
Traceback (most recent call last):
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\platform\solc.py", line 370, in get_version
    with subprocess.Popen(
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 969, in __init__        
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1438, in _execute_child 
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\slither\__main__.py", line 826, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\slither\__main__.py", line 86, 
in process_all
    compilations = compile_all(target, **vars(args))
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\crytic_compile.py", line 637, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\crytic_compile.py", line 117, in __init__
    self._compile(**kwargs)
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\crytic_compile.py", line 548, in _compile
    self._platform.compile(self, **kwargs)
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\platform\solc.py", line 154, in compile
    targets_json = _get_targets_json(compilation_unit, self._target, **kwargs)
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\platform\solc.py", line 276, in _get_targets_json
    return _run_solc(
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\platform\solc.py", line 474, in _run_solc
    compiler="solc", version=get_version(solc, env), optimized=is_optimized(solc_arguments)
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\platform\solc.py", line 385, in get_version
    raise InvalidCompilation(error)
crytic_compile.platform.exceptions.InvalidCompilation: [WinError 2] The system cannot find the file specified     


D:\project\contract>
@majorisgit majorisgit added the bug-candidate Bugs reports that are not yet confirmed label Oct 14, 2022
@elopez
Copy link
Member

elopez commented Oct 14, 2022

Hi @majorisgit, thanks for the report! I see the error is occurring when executing solc - you need to install a solidity compiler in your system.

Traceback (most recent call last):
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\platform\solc.py", line 370, in get_version
    with subprocess.Popen(
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 969, in __init__        
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1438, in _execute_child 
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

I'd suggest installing solc-select and using that to manage the solc installations

pip3 install solc-select
solc-select use 0.8.17 --always-install
slither Small_TestContract.sol

@majorisgit
Copy link
Author

I tried them, now it works on command line. But VS code extension is still failing.

Command line -

D:\project>slither contract/Small_TestContract.sol

Pragma version>=0.8.0<0.9.0 (contract/Small_TestContract.sol#3) is too complex
Reference: https://github.com/crytic/slither/wiki/Detector-Documentation#incorrect-versions-of-solidity

Contract smallTestContract (contract/Small_TestContract.sol#5-23) is not in CapWords
Reference: https://github.com/crytic/slither/wiki/Detector-Documentation#conformance-to-solidity-naming-conventions
contract/Small_TestContract.sol analyzed (1 contracts with 81 detectors), 2 result(s) found

D:\project>

VS code extension -

Slither: Solidity static analysis framework by Trail of Bits
Using slither version: 0.9.0
Refreshing explorer...
Loaded 0 issues, displaying 0
⸻ Starting analysis ⸻
Error: Error in workspace "d:\project":
Traceback (most recent call last):
File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\slither_main_.py", line 826, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\slither_main_.py", line 86, in process_all
compilations = compile_all(target, **vars(args))
File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\crytic_compile.py", line 658, in compile_all
compilations.append(CryticCompile(filename, **kwargs))
File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\crytic_compile.py", line 117, in init
self._compile(**kwargs)
File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\crytic_compile.py", line 548, in _compile
self._platform.compile(self, **kwargs)
File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\platform\solc.py", line 154, in compile
targets_json = _get_targets_json(compilation_unit, self._target, **kwargs)
File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\platform\solc.py", line 276, in _get_targets_json
return _run_solc(
File "C:\Users\user001\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\platform\solc.py", line 468, in _run_solc
raise InvalidCompilation(f"{filename} does not exist (are you in the correct directory?)")
crytic_compile.platform.exceptions.InvalidCompilation: . does not exist (are you in the correct directory?)

Analysis: 0 succeeded, 1 failed, 0 skipped
Refreshing explorer...
Loaded 0 issues, displaying 0

@elopez
Copy link
Member

elopez commented Oct 15, 2022

Note that you are testing different things, the first one (command line) is running slither against a single file, while the latter (extension) is analyzing a folder. Going by the error message in the second case, it looks like the folder does not contain a project using a supported framework (eg hardhat), nor solidity (.sol) files in it. Slither will not look for files recursively in other directories in this "plain solc with a folder" mode, so that's why you get this error.

@majorisgit
Copy link
Author

Thank you. That was correct, I placed one .sol file in the root folder for test and the extension worked.
How do I make it search for .sol files in a specific folder?

@elopez
Copy link
Member

elopez commented Oct 15, 2022

I'm not too familiar with the vscode extension, but I see there's an issue open for it requesting the feature, so it might not be possible right now: crytic/contract-explorer#23

If you can use a compilation framework for your project (eg hardhat, foundry, etc) so that building with the framework from the root folder works, that could be a way to get it working in the meantime, as slither will not be looking for files but running the framework build instead. Another option could be looking into running slither manually with the --sarif Slither option, and then reviewing the results with the VSCode SARIF viewer extension from Microsoft.

@elopez elopez closed this as completed Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-candidate Bugs reports that are not yet confirmed
Projects
None yet
Development

No branches or pull requests

2 participants