slither icon indicating copy to clipboard operation
slither copied to clipboard

[Bug]: lowering of `InitArray` fails

Open Tiko7454 opened this issue 2 years ago • 1 comments

Describe the issue:

The addition of .type on the r.type.type causes another issue on the contract below. (I have removed the try block for a cleaner error message)

https://github.com/crytic/slither/blame/e3dcf1ecd3e9de60da046de471c5663ab637993a/slither/slithir/convert.py#L1954C33-L1954C33

Code example to reproduce the issue:

contract C {
  function f (int x) public returns(int) {
    int h = 1;
    int k = 5;
    int[5] memory arr = [x, C.x, C.y, h - k, h + k];
  }

  int x= 4;
  int y = 5;
}

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: This declaration shadows an existing declaration.
  --> a.sol:11:15:
   |
11 |   function f (int x) public returns(int) {
   |               ^^^^^
Note: The shadowed declaration is here:
  --> a.sol:17:3:
   |
17 |   int x= 4;
   |   ^^^^^^^^

Warning: Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable.
  --> a.sol:11:37:
   |
11 |   function f (int x) public returns(int) {
   |                                     ^^^

Warning: Unused local variable.
  --> a.sol:14:5:
   |
14 |     int[5] memory arr = [x, C.x, C.y, h - k, h + k];
   |     ^^^^^^^^^^^^^^^^^

Warning: Function state mutability can be restricted to pure
 --> a.sol:3:1:
  |
3 | function free_f(uint x, uint y) returns(uint) {
  | ^ (Relevant source part starts here and spans across multiple lines).

Warning: Function state mutability can be restricted to view
  --> a.sol:11:3:
   |
11 |   function f (int x) public returns(int) {
   |   ^ (Relevant source part starts here and spans across multiple lines).


ERROR:ContractSolcParsing:Impossible to generate IR for C.f (a.sol#11-15):
 'str' 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 118, 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 2016, in apply_ir_heuristics
    convert_constant_types(irs)
  File "/home/tigran/Projects/slither/slither/.slither/lib/python3.11/site-packages/slither/slithir/convert.py", line 1954, in convert_constant_types
    if r.type.type.type not in ElementaryTypeInt:
       ^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'type'

Tiko7454 avatar Nov 01 '23 14:11 Tiko7454

This is a regression from https://github.com/crytic/slither/pull/2018

0xalpharush avatar Nov 01 '23 14:11 0xalpharush