Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slither crashes when specifying array size as constant expression #144

Closed
Xenomega opened this issue Jan 17, 2019 · 1 comment
Closed

Slither crashes when specifying array size as constant expression #144

Xenomega opened this issue Jan 17, 2019 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Xenomega
Copy link
Member

The following contract will cause slither to throw an error:

contract C {
  uint constant x = 100;
  uint constant y = 10;
  function f(uint[x / y] z) public  {
    // the input parameter in this function is problematic
  }
}

The issue is that array sizes can be specified by a literal or constant expression, and slither seems to fail to initialize arrays via constant expressions (tested with +, *, / )

Stack trace:

ERROR:root:Traceback (most recent call last):
  File "c:\users\vyper\documents\github\slither\slither\__main__.py", line 278, in main_impl
    (results_tmp, number_contracts_tmp) = process(filename, args, detector_classes, printer_classes)
  File "c:\users\vyper\documents\github\slither\slither\__main__.py", line 40, in process
    slither = Slither(filename, args.solc, args.disable_solc_warnings, args.solc_args, ast)
  File "c:\users\vyper\documents\github\slither\slither\slither.py", line 41, in __init__
    self._analyze_contracts()
  File "c:\users\vyper\documents\github\slither\slither\solc_parsing\slitherSolc.py", line 210, in _analyze_contracts
    self._analyze_third_part(contracts_to_be_analyzed, libraries)
  File "c:\users\vyper\documents\github\slither\slither\solc_parsing\slitherSolc.py", line 294, in _analyze_third_part
    self._analyze_variables_modifiers_functions(contract)
  File "c:\users\vyper\documents\github\slither\slither\solc_parsing\slitherSolc.py", line 329, in _analyze_variables_modifiers_functions
    contract.analyze_params_functions()
  File "c:\users\vyper\documents\github\slither\slither\solc_parsing\declarations\contract.py", line 348, in analyze_params_functions
    self._functions[function.full_name] = function
  File "c:\users\vyper\documents\github\slither\slither\core\declarations\function.py", line 358, in full_name
    name, parameters, _ = self.signature
  File "c:\users\vyper\documents\github\slither\slither\core\declarations\function.py", line 341, in signature
    return self.name, [str(x.type) for x in self.parameters], [str(x.type) for x in self.returns]
  File "c:\users\vyper\documents\github\slither\slither\core\declarations\function.py", line 341, in <listcomp>
    return self.name, [str(x.type) for x in self.parameters], [str(x.type) for x in self.returns]
  File "c:\users\vyper\documents\github\slither\slither\core\solidity_types\array_type.py", line 25, in __str__
    if isinstance(self._length.value, Variable) and self._length.value.is_constant:
AttributeError: 'BinaryOperation' object has no attribute 'value'
@montyly montyly added the bug Something isn't working label Jan 17, 2019
@montyly montyly self-assigned this Jan 17, 2019
@montyly
Copy link
Member

montyly commented Jan 18, 2019

Note: solving this issue requires building an expression visitor that evaluates simple expressions.

That should be easy using the visitor expression module https://github.com/trailofbits/slither/tree/master/slither/visitors/expression

@montyly montyly added this to the 0.6.0 milestone Jan 28, 2019
@montyly montyly closed this as completed in 6c2923f Feb 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants