crytic / slither

Static Analyzer for Solidity and Vyper
https://blog.trailofbits.com/2018/10/19/slither-a-solidity-static-analysis-framework/
GNU Affero General Public License v3.0
5.33k stars 967 forks source link

[Bug-Candidate]: Cannot get a descriptive error message #1865

Closed gagiuntoli closed 7 months ago

gagiuntoli commented 1 year ago

Describe the issue:

I am trying to run slither in a Foundry project and it is failing without providing me any descriptive reason:

$ slither . --compile-force-framework foundry --foundry-out-directory=$PWD/foundry/out                                                                   
'forge clean' running (wd: /home/guido/workspace/ubet/blockchain/evm)                                                                                                                                      
'forge build --build-info --force' running                                                                                                                                                                 
Compiling 111 files with 0.8.17                                                                                                                                                                            
Solc 0.8.17 finished in 12.09s                                                                                                                                                                             
Compiler run successful                                                                                                                                                                                    

Traceback (most recent call last):                                                                                                                                                                         
  File "/home/guido/.local/pipx/venvs/slither-analyzer/lib/python3.9/site-packages/slither/__main__.py", line 834, in main_impl                                                                            
    ) = process_all(filename, args, detector_classes, printer_classes)                                                                                                                                     
  File "/home/guido/.local/pipx/venvs/slither-analyzer/lib/python3.9/site-packages/slither/__main__.py", line 98, in process_all                                                                           
    ) = process_single(compilation, args, detector_classes, printer_classes)                                                                                                                               
  File "/home/guido/.local/pipx/venvs/slither-analyzer/lib/python3.9/site-packages/slither/__main__.py", line 76, in process_single                                                                        
    slither = Slither(target, ast_format=ast, **vars(args))                                                                                                                                                
  File "/home/guido/.local/pipx/venvs/slither-analyzer/lib/python3.9/site-packages/slither/slither.py", line 133, in __init__                                                                              
    self._init_parsing_and_analyses(kwargs.get("skip_analyze", False))                                                                                                                                     
  File "/home/guido/.local/pipx/venvs/slither-analyzer/lib/python3.9/site-packages/slither/slither.py", line 153, in _init_parsing_and_analyses                                                            
    raise e                                       
  File "/home/guido/.local/pipx/venvs/slither-analyzer/lib/python3.9/site-packages/slither/slither.py", line 149, in _init_parsing_and_analyses
    parser.analyze_contracts()
  File "/home/guido/.local/pipx/venvs/slither-analyzer/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 529, in analyze_contracts
    self._convert_to_slithir()
  File "/home/guido/.local/pipx/venvs/slither-analyzer/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 754, in _convert_to_slithir
    func.generate_slithir_ssa({})
  File "/home/guido/.local/pipx/venvs/slither-analyzer/lib/python3.9/site-packages/slither/core/declarations/function_top_level.py", line 93, in generate_slithir_ssa
    add_ssa_ir(self, all_ssa_state_variables_instances)
  File "/home/guido/.local/pipx/venvs/slither-analyzer/lib/python3.9/site-packages/slither/slithir/utils/ssa.py", line 181, in add_ssa_ir
    generate_ssa_irs(                             
  File "/home/guido/.local/pipx/venvs/slither-analyzer/lib/python3.9/site-packages/slither/slithir/utils/ssa.py", line 296, in generate_ssa_irs
    generate_ssa_irs(                             
  File "/home/guido/.local/pipx/venvs/slither-analyzer/lib/python3.9/site-packages/slither/slithir/utils/ssa.py", line 296, in generate_ssa_irs
    generate_ssa_irs(                             
  File "/home/guido/.local/pipx/venvs/slither-analyzer/lib/python3.9/site-packages/slither/slithir/utils/ssa.py", line 293, in generate_ssa_irs
    new_ir.lvalue.add_refers_to(new_ir.rvalue)
  File "/home/guido/.local/pipx/venvs/slither-analyzer/lib/python3.9/site-packages/slither/slithir/variables/local_variable.py", line 66, in add_refers_to
    assert isinstance(variable, (SlithIRVariable, TemporaryVariable))
AssertionError                                    
Error in . 

Code example to reproduce the issue:

It is a Foundry project with the following folder structure:

root -contracts -nested folders with the Solidity files
-foundry.toml
-foundry
-out
-etc.

Version:

0.9.2

Relevant log output:

No response

0xalpharush commented 1 year ago

Would you be able to try version 0.9.3 and if the issue still persists share a link to a github repo of your code please?

gagiuntoli commented 1 year ago

Well, it is a bit embarrassing. I had and old slither.config.json file with references to hardhat (from when the project used Hardhat). Even though I think Slither should be able to inform any inconsistency in the configuration.

gagiuntoli commented 1 year ago

I realized it was not only that. The foundry test were the ones making Slither to fail. Let me prepare a small minimal example to reproduce this error.