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.24k stars 956 forks source link

[Bug]: ERROR:SlitherSolcParsing: Failed to convert IR to SSA for EnumerableSetLib contract. #2470

Open cb-elileers opened 3 months ago

cb-elileers commented 3 months ago

Describe the issue:

We're inheriting EnumerableSetLib from Solady and there's an issue generating SlithIR.

It does a lot of nasty assembly optimizations, but it would be nice to still be able to run Slither against our project.

Code example to reproduce the issue:

https://github.com/Vectorized/solady/blob/main/src/utils/EnumerableSetLib.sol

Version:

0.10.2

Relevant log output:

slither contracts --solc-disable-warnings --filter-paths "lib/|test/|"
'forge clean' running (wd: /Users/eli/Documents/Projects/audits/PROJECT_NAME/contracts)
'forge config --json' running
'forge build --build-info --skip */test/** */script/** --force' running (wd: /Users/eli/Documents/Projects/audits/PROJECT_NAME/contracts)
ERROR:SlitherSolcParsing:
Failed to convert IR to SSA for EnumerableSetLib contract. Please open an issue https://github.com/crytic/slither/issues.

Traceback (most recent call last):
  File "/Users/eli/.pyenv/versions/3.12.2/bin/slither", line 33, in <module>
    sys.exit(load_entry_point('slither-analyzer', 'console_scripts', 'slither')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/__main__.py", line 753, in main
    main_impl(all_detector_classes=detectors, all_printer_classes=printers)
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/__main__.py", line 859, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/__main__.py", line 107, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/__main__.py", line 80, in process_single
    slither = Slither(target, ast_format=ast, **vars(args))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/slither.py", line 199, in __init__
    self._init_parsing_and_analyses(kwargs.get("skip_analyze", False))
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/slither.py", line 219, in _init_parsing_and_analyses
    raise e
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/slither.py", line 215, in _init_parsing_and_analyses
    parser.analyze_contracts()
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 593, in analyze_contracts
    self._convert_to_slithir()
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 834, in _convert_to_slithir
    raise e
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 829, in _convert_to_slithir
    contract.convert_expression_to_slithir_ssa()
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/core/declarations/contract.py", line 1579, in convert_expression_to_slithir_ssa
    func.generate_slithir_ssa(all_ssa_state_variables_instances)
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/core/declarations/function_contract.py", line 140, in generate_slithir_ssa
    add_ssa_ir(self, all_ssa_state_variables_instances)
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/slithir/utils/ssa.py", line 206, in add_ssa_ir
    fix_phi_rvalues_and_storage_ref(
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/slithir/utils/ssa.py", line 526, in fix_phi_rvalues_and_storage_ref
    fix_phi_rvalues_and_storage_ref(
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/slithir/utils/ssa.py", line 526, in fix_phi_rvalues_and_storage_ref
    fix_phi_rvalues_and_storage_ref(
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/slithir/utils/ssa.py", line 526, in fix_phi_rvalues_and_storage_ref
    fix_phi_rvalues_and_storage_ref(
  [Previous line repeated 18 more times]
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/slithir/utils/ssa.py", line 497, in fix_phi_rvalues_and_storage_ref
    last_name(dst, ir.lvalue, init_local_variables_instances) for dst in ir.nodes
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/slithir/utils/ssa.py", line 363, in last_name
    assert candidates
AssertionError
0xalpharush commented 3 months ago

We are working to improve our support Yul to handle this case. In the meantime, you can use --skip-assembly to avoid hitting this error (at least it worked in a case which I believe is the same here https://github.com/crytic/slither/issues/2160)

strollinghome commented 1 month ago

We are working to improve our support Yul to handle this case. In the meantime, you can use --skip-assembly to avoid hitting this error (at least it worked in a case which I believe is the same here #2160)

@0xalpharush Having a similar issue with a different file, and --skip-assembly is not resolving it. Any idea what it could be?

stdStorageSafe

ERROR:SlitherSolcParsing:
Failed to convert IR to SSA for stdStorageSafe contract. Please open an issue https://github.com/crytic/slither/issues.

Traceback (most recent call last):
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/__main__.py", line 814, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/__main__.py", line 102, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/__main__.py", line 80, in process_single
    slither = Slither(target, ast_format=ast, **vars(args))
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/slither.py", line 135, in __init__
    self._init_parsing_and_analyses(kwargs.get("skip_analyze", False))
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/slither.py", line 155, in _init_parsing_and_analyses
    raise e
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/slither.py", line 151, in _init_parsing_and_analyses
    parser.analyze_contracts()
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 541, in analyze_contracts
    self._convert_to_slithir()
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 774, in _convert_to_slithir
    raise e
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 769, in _convert_to_slithir
    contract.convert_expression_to_slithir_ssa()
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/core/declarations/contract.py", line 1502, in convert_expression_to_slithir_ssa
    func.generate_slithir_ssa(all_ssa_state_variables_instances)
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/core/declarations/function_contract.py", line 134, in generate_slithir_ssa
    compute_dominance_frontier(self.nodes)
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/core/dominators/utils.py", line 98, in compute_dominance_frontier
    assert runner.immediate_dominator
AssertionError
ERROR:root:Error in .
ERROR:root:Traceback (most recent call last):
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/__main__.py", line 814, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/__main__.py", line 102, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/__main__.py", line 80, in process_single
    slither = Slither(target, ast_format=ast, **vars(args))
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/slither.py", line 135, in __init__
    self._init_parsing_and_analyses(kwargs.get("skip_analyze", False))
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/slither.py", line 155, in _init_parsing_and_analyses
    raise e
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/slither.py", line 151, in _init_parsing_and_analyses
    parser.analyze_contracts()
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 541, in analyze_contracts
    self._convert_to_slithir()
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 774, in _convert_to_slithir
    raise e
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 769, in _convert_to_slithir
    contract.convert_expression_to_slithir_ssa()
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/core/declarations/contract.py", line 1502, in convert_expression_to_slithir_ssa
    func.generate_slithir_ssa(all_ssa_state_variables_instances)
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/core/declarations/function_contract.py", line 134, in generate_slithir_ssa
    compute_dominance_frontier(self.nodes)
  File "/Users/carlosflores/Library/Python/3.9/lib/python/site-packages/slither/core/dominators/utils.py", line 98, in compute_dominance_frontier
    assert runner.immediate_dominator
AssertionError
0xalpharush commented 1 month ago

@strollinghome Are you on the latest version of Slither?

strollinghome commented 1 month ago

@0xalpharush works now; I was on an older version.

DamirS09 commented 4 weeks ago

Error in slither

Hi i have version slither --0.10.3 windows

when i use command:

slither . --detect unused-import

**I get error** 

'forge clean' running (wd: C:\Users\user\Desktop\project\project)
'forge config --json' running
'forge build --build-info --skip */test/** */script/** --force' running (wd: C:\Users\user\Desktop\project\project)
ERROR:SlitherSolcParsing:
Failed to convert IR to SSA for project contract. Please open an issue https://github.com/crytic/slither/issues.

Traceback (most recent call last):
 assert candidates
AssertionError

and when i use this command

slither . --skip-assembly --detect "unused-import"

i did not get information about unused imports

slither . --skip-assembly --detect "unused-import"

'forge clean' running (wd: C:\Users\user\Desktop\project\project)
'forge config --json' running
'forge build --build-info --skip */test/** */script/** --force' running (wd: C:\Users\user\Desktop\project\project)
INFO:Slither:. analyzed (37 contracts with 1 detectors), 0 result(s) found