slither icon indicating copy to clipboard operation
slither copied to clipboard

Slither fails to detect some constants

Open gustavo-grieco opened this issue 5 years ago • 5 comments

The Echidna printer in Slither fails to detect some constants, for instance:

contract C {
  uint x = 1;
}

won't be detected:

$ slither --print echidna small.sol
...
INFO:Printers:{
    "payable": {},
    "timestamp": {},
    "block_number": {},
    "msg_sender": {},
    "msg_gas": {},
    "assert": {},
    "constant_functions": {},
    "constants_used": {},
    "constants_used_in_binary": {},
    "functions_relations": {
        "C": {}
    },
    "constructors": {},
    "have_external_calls": {},
    "call_a_parameter": {},
    "use_balance": {}
}

gustavo-grieco avatar Apr 28 '20 16:04 gustavo-grieco

Currently the printer reports the constants where they are used, so if a constant is not used it is not reported.

Do you need it to be reported in a constants_all field?

montyly avatar Apr 28 '20 16:04 montyly

Perhaps constants could be useful for external calls? Are they considered used?

contract A {
  uint public x = 123;
}

contract C {
  function f(A a) public returns (bool) {
    if (a.x() == 1)
      return true;
    return false;
  }
}

however..

  File "/home/g/.local/lib/python3.6/site-packages/slither_analyzer-0.6.12-py3.6.egg/slither/__main__.py", line 606, in main_impl
    printer_classes)
  File "/home/g/.local/lib/python3.6/site-packages/slither_analyzer-0.6.12-py3.6.egg/slither/__main__.py", line 68, in process_all
    compilation, args, detector_classes, printer_classes)
  File "/home/g/.local/lib/python3.6/site-packages/slither_analyzer-0.6.12-py3.6.egg/slither/__main__.py", line 57, in process_single
    return _process(slither, detector_classes, printer_classes)
  File "/home/g/.local/lib/python3.6/site-packages/slither_analyzer-0.6.12-py3.6.egg/slither/__main__.py", line 95, in _process
    printer_results = slither.run_printers()
  File "/home/g/.local/lib/python3.6/site-packages/slither_analyzer-0.6.12-py3.6.egg/slither/slither.py", line 170, in run_printers
    return [p.output(self.filename).data for p in self._printers]
  File "/home/g/.local/lib/python3.6/site-packages/slither_analyzer-0.6.12-py3.6.egg/slither/slither.py", line 170, in <listcomp>
    return [p.output(self.filename).data for p in self._printers]
  File "/home/g/.local/lib/python3.6/site-packages/slither_analyzer-0.6.12-py3.6.egg/slither/printers/guidance/echidna.py", line 318, in output
    call_parameters = _call_a_parameter(self.slither)
  File "/home/g/.local/lib/python3.6/site-packages/slither_analyzer-0.6.12-py3.6.egg/slither/printers/guidance/echidna.py", line 270, in _call_a_parameter
    "signature": _get_name(ir.function)
  File "/home/g/.local/lib/python3.6/site-packages/slither_analyzer-0.6.12-py3.6.egg/slither/printers/guidance/echidna.py", line 24, in _get_name
    if f.is_fallback or f.is_receive:
AttributeError: 'StateVariableSolc' object has no attribute 'is_fallback'

gustavo-grieco avatar Apr 28 '20 16:04 gustavo-grieco

Also, for the following contract

contract C {
    function foo() public view returns (uint) {
        return uint(-1);
    }
}

the echidna printer will return

[...]
    "constants_used": {
        "C": {
            "foo()": [
                [{
                    "value": "0",
                    "type": "uint256"
                }],
                [{
                    "value": "1",
                    "type": "uint256"
                }]
            ]
        }
    },
[...]

Seems that the uint(-1) is interpreted as uint(1).

hacker-DOM avatar Apr 07 '21 11:04 hacker-DOM