slither icon indicating copy to clipboard operation
slither copied to clipboard

[Bug]: Misinterpreting function arguments when the called function is overloaded

Open Tiko7454 opened this issue 2 years ago • 0 comments

Describe the issue:

In the code below there is a call from function g to function f of the contract A. Slither gets the first argument of the call and misinterprets it. Slither expects List[Variable] but another thing, it throws an exception and refuses to convert to slithir. I've printed the argument list (arguments) from _find_function_from_parameter of slither/slithir/convert.py. I got [[0, <slither.core.variables.local_variable.LocalVariable object at 0x7fe4b3e0f990>]]. (in the log the line numbers can differ because of the prints added by me) (I have removed the try block for a cleaner error message)

Code example to reproduce the issue:

contract A {
    function f(uint256[2] calldata arr) external {}
    function f(uint256[4] calldata arr) external {}
}

contract C {
    function g(A a, uint256 num) public {
        a.f([0, num]);
    }
}

Version:

0.10.0

Relevant log output:

'solc --version' running
'solc a.sol --combined-json abi,ast,bin,bin-runtime,srcmap,srcmap-runtime,userdoc,devdoc,hashes,compact-format --allow-paths .,/home/tigran/Projects/slither/slither' running
Compilation warnings/errors on a.sol:
Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> a.sol

Warning: Source file does not specify required compiler version! Consider adding "pragma solidity ^0.8.7;"
--> a.sol

ERROR:ContractSolcParsing:Impossible to generate IR for C.g (a.sol#7-9):
 'list' object has no attribute 'type'
Traceback (most recent call last):
  File "/home/tigran/Projects/slither/slither/.slither/bin/slither", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/__main__.py", line 727, in main
    main_impl(all_detector_classes=detectors, all_printer_classes=printers)
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/__main__.py", line 833, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/__main__.py", line 107, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/__main__.py", line 80, in process_single
    slither = Slither(target, ast_format=ast, **vars(args))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/slither.py", line 144, in __init__
    self._init_parsing_and_analyses(kwargs.get("skip_analyze", False))
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/slither.py", line 164, in _init_parsing_and_analyses
    raise e
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/slither.py", line 160, in _init_parsing_and_analyses
    parser.analyze_contracts()
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 539, in analyze_contracts
    self._convert_to_slithir()
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 750, in _convert_to_slithir
    func.generate_slithir_and_analyze()
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/core/declarations/function.py", line 1786, in generate_slithir_and_analyze
    node.slithir_generation()
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/core/cfg/node.py", line 716, in slithir_generation
    self._irs = convert_expression(expression, self)  # type:ignore
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/slithir/convert.py", line 119, in convert_expression
    result = apply_ir_heuristics(result, node, is_solidity)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/slithir/convert.py", line 2017, in apply_ir_heuristics
    irs = propagate_type_and_convert_call(irs, node)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/slithir/convert.py", line 536, in propagate_type_and_convert_call
    new_ins = propagate_types(ins, node)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/slithir/convert.py", line 645, in propagate_types
    return convert_type_of_high_and_internal_level_call(ir, t_type)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/slithir/convert.py", line 1752, in convert_type_of_high_and_internal_level_call
    func = _find_function_from_parameter(ir.arguments, candidates, False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/slithir/convert.py", line 232, in _find_function_from_parameter
    arg_type = arg.type
               ^^^^^^^^
AttributeError: 'list' object has no attribute 'type'

Tiko7454 avatar Nov 01 '23 12:11 Tiko7454