slither icon indicating copy to clipboard operation
slither copied to clipboard

[Bug-Candidate]: Problems with Slither on projects with several compiler versions

Open ndkirillov opened this issue 2 years ago • 6 comments

Describe the issue:

A problem with Slither when running it on projects with several compiler versions specified in config file. Every time I run into issues with python inside slither (issue like this for example: RecursionError: maximum recursion depth exceeded while calling a Python object). Does Slither support several compiler version projects or that is not the case of issues?

Code example to reproduce the issue:

  solidity: {
    compilers: [
      {
        version: '0.7.6',
      },
      {
        version: '0.8.2',
      },
    ],

Version:

0.8.2

Relevant log output:

{ "success": false, "error": "Traceback (most recent call last):\n File "/home/nd/.local/lib/python3.8/site-packages/slither/main.py", line 743, in main_impl\n ) = process_all(filename, args, detector_classes, printer_classes)\n File "/home/nd/.local/lib/python3.8/site-packages/slither/main.py", line 84, in process_all\n ) = process_single(compilation, args, detector_classes, printer_classes)\n File "/home/nd/.local/lib/python3.8/site-packages/slither/main.py", line 67, in process_single\n slither = Slither(target, ast_format=ast, **vars(args))\n File "/home/nd/.local/lib/python3.8/site-packages/slither/slither.py", line 120, in init\n parser.parse_contracts()\n File "/home/nd/.local/lib/python3.8/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 435, in parse_contracts\n self._analyze_third_part(contracts_to_be_analyzed, libraries)\n File "/home/nd/.local/lib/python3.8/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 541, in _analyze_third_part\n self._analyze_variables_modifiers_functions(contract)\n File "/home/nd/.local/lib/python3.8/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 614, in _analyze_variables_modifiers_functions\n contract.analyze_content_functions()\n File "/home/nd/.local/lib/python3.8/site-packages/slither/solc_parsing/declarations/contract.py", line 378, in analyze_content_functions\n function_parser.analyze_content()\n File "/home/nd/.local/lib/python3.8/site-packages/slither/solc_parsing/declarations/function.py", line 282, in analyze_content\n self._parse_cfg(body)\n File "/home/nd/.local/lib/python3.8/site-packages/slither/solc_parsing/declarations/function.py", line 1071, in _parse_cfg\n self._remove_incorrect_edges()\n File "/home/nd/.local/lib/python3.8/site-packages/slither/solc_parsing/declarations/function.py", line 1275, in _remove_incorrect_edges\n self._fix_try(node)\n File "/home/nd/.local/lib/python3.8/site-packages/slither/solc_parsing/declarations/function.py", line 1150, in _fix_try\n self._fix_catch(son, end_node)\n File "/home/nd/.local/lib/python3.8/site-packages/slither/solc_parsing/declarations/function.py", line 1158, in _fix_catch\n self._fix_catch(son, end_node)\n File "/home/nd/.local/lib/python3.8/site-packages/slither/solc_parsing/declarations/function.py", line 1158, in _fix_catch\n self._fix_catch(son, end_node)\n File "/home/nd/.local/lib/python3.8/site-packages/slither/solc_parsing/declarations/function.py", line 1158, in _fix_catch\n self._fix_catch(son, end_node)\n [Previous line repeated 1480 more times]\n File "/home/nd/.local/lib/python3.8/site-packages/slither/solc_parsing/declarations/function.py", line 1153, in _fix_catch\n if not node.sons:\n File "/home/nd/.local/lib/python3.8/site-packages/slither/core/cfg/node.py", line 667, in sons\n return list(self._sons)\nRecursionError: maximum recursion depth exceeded while calling a Python object\n", "results": {} }

ndkirillov avatar Mar 29 '22 11:03 ndkirillov

Yes, slither uses whichever compilation framework you are using, and many support mixing compiler versions. For instance, hardhat will produce the necessary artifacts and slither will use them. Can you try npx hardhat compile && slither . --ignore-compile if you're using hardhat? If that doesn't work, it might be a different issue and it'd help if you can share code.

0xalpharush avatar Mar 29 '22 13:03 0xalpharush

I'm using 0.8.14 only in my hardhat.config file and getting the same RecursionError: maximum recursion depth with and without running npx hardhat compile && slither . --ignore-compile

File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/slither/__main__.py", line 744, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/slither/__main__.py", line 87, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/slither/__main__.py", line 70, in process_single
    slither = Slither(target, ast_format=ast, **vars(args))
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/slither/slither.py", line 118, in __init__
    parser.parse_contracts()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 489, in parse_contracts
    self._analyze_third_part(contracts_to_be_analyzed, libraries)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 596, in _analyze_third_part
    self._analyze_variables_modifiers_functions(contract)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 669, in _analyze_variables_modifiers_functions
    contract.analyze_content_functions()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/slither/solc_parsing/declarations/contract.py", line 404, in analyze_content_functions
    function_parser.analyze_content()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/slither/solc_parsing/declarations/function.py", line 282, in analyze_content
    self._parse_cfg(body)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/slither/solc_parsing/declarations/function.py", line 1071, in _parse_cfg
    self._remove_incorrect_edges()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/slither/solc_parsing/declarations/function.py", line 1275, in _remove_incorrect_edges
    self._fix_try(node)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/slither/solc_parsing/declarations/function.py", line 1150, in _fix_try
    self._fix_catch(son, end_node)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/slither/solc_parsing/declarations/function.py", line 1158, in _fix_catch
    self._fix_catch(son, end_node)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/slither/solc_parsing/declarations/function.py", line 1158, in _fix_catch
    self._fix_catch(son, end_node)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/slither/solc_parsing/declarations/function.py", line 1158, in _fix_catch
    self._fix_catch(son, end_node)
  [Previous line repeated 1481 more times]
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/slither/solc_parsing/declarations/function.py", line 1153, in _fix_catch
    if not node.sons:
RecursionError: maximum recursion depth exceeded

trojanMcAfee avatar Aug 02 '22 18:08 trojanMcAfee

This is the part where the issue is happening: https://github.com/crytic/slither/blob/db703d82f4876e30f1ca10fb78d85b4dd4c31ec1/slither/solc_parsing/declarations/function.py#L1145-L1158

trojanMcAfee avatar Aug 04 '22 10:08 trojanMcAfee

Can you share code please?

0xalpharush avatar Aug 04 '22 13:08 0xalpharush

Run slither in this contract. The issue is being caused by the try/catch blocks @0xalpharush

trojanMcAfee avatar Aug 04 '22 13:08 trojanMcAfee

If you remove the blocks from that contract and the others where there are some, slither runs fine

trojanMcAfee avatar Aug 04 '22 13:08 trojanMcAfee

Seems like even if you exclude the contract with try/catch via slither.config.json, slither encounters this issue.

penandlim avatar Jan 19 '23 01:01 penandlim

I am seeing this issue even with --ignore-compile in a Foundry repo.

$ slither --version
0.9.2

0xmichalis avatar Mar 09 '23 12:03 0xmichalis