slither
slither copied to clipboard
Slither fails to detect some constants
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": {}
}
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?
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'
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).