slither
slither copied to clipboard
[Bug-Candidate]: source_mapping property failing on `assert self.compilation_unit is not None`
Describe the issue:
Slither has tons of amazing properties on objects, and I recently found beeprint to conveniently dump out all property information recursively to aid in understanding the info available to functions/nodes/irs/etc.
Using this on a simple contract pointed out a bug with compilation_unit
not always being initialized for some objects in the Slither objects list.
In this case, it failed when attempting to get information on a return_type
list with object instance(ElementaryType)
's source_mapping
with error assert self.compilation_unit is not None
I also have tests of it failing on instance(Literal)
and instance(TemporaryVariable)
source_mapping
Code example to reproduce the issue:
Contract:
pragma solidity ^0.8.13;
contract printOut {
function a() pure public returns (uint) {
return 1;
}
}
Printer:
from slither.printers.abstract_printer import AbstractPrinter
from beeprint import pp
class Beeprint(AbstractPrinter):
ARGUMENT = "beeprint"
HELP = "Print out all of beeprint found props"
WIKI = "not documented"
def output(self, _filename):
for contract in self.contracts:
functions = [function for function in contract.functions_declared]
for function in functions:
for node in function.nodes:
pp(node) # Just printing out to stdout directly
txt = ""
self.info(txt)
res = self.generate_output(txt)
return res
Version:
0.8.3 on dev
branch
Relevant log output:
instance(Node):
...
_function: instance(FunctionContract):
...
return_type: [
instance(ElementaryType):
_abc_impl: <_abc._abc_data object at 0x7fb28f0cdb80>,
_context: {
'MEMBERS': defaultdict(None, {}),
},
_type: 'uint256',
context: {
'MEMBERS': defaultdict(None, {}),
},
is_dynamic: False,
max: 115792089237316195423570985008687907853269984665640564039457584007913129639935,
min: 0,
name: 'uint256',
references: [],
size: 256,
source_mapping: Traceback (most recent call last):
...
assert self.compilation_unit is not None
AssertionError
Steps to Reproduce
-
pip install beeprint
- save contract to file and add printer to slither
-
slither <contract> --print beeprint &> out.md
- Highly recommend piping output as it's very long
Non-Beeprint reproduction
pragma solidity ^0.8.13;
contract printOut {
function a() pure public returns (uint) {
return 1;
}
}
from slither.printers.abstract_printer import AbstractPrinter
class Beeprint(AbstractPrinter):
ARGUMENT = "beeprint"
HELP = "Print out all of beeprint found props"
WIKI = "not documented"
def output(self, _filename):
txt = ""
for contract in self.contracts:
functions = [function for function in contract.functions_declared]
for function in functions:
for node in function.nodes:
for r_type in node.function.return_type:
print(r_type.source_mapping)
self.info(txt)
res = self.generate_output(txt)
return res
Output:
Traceback (most recent call last):
File "/home/plotchy/code/packages/slither-dev/slither/slither/__main__.py", line 781, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/home/plotchy/code/packages/slither-dev/slither/slither/__main__.py", line 88, in process_all
) = process_single(compilation, args, detector_classes, printer_classes)
File "/home/plotchy/code/packages/slither-dev/slither/slither/__main__.py", line 73, in process_single
return _process(slither, detector_classes, printer_classes)
File "/home/plotchy/code/packages/slither-dev/slither/slither/__main__.py", line 120, in _process
printer_results = slither.run_printers()
File "/home/plotchy/code/packages/slither-dev/slither/slither/slither.py", line 216, in run_printers
return [p.output(self._crytic_compile.target).data for p in self._printers]
File "/home/plotchy/code/packages/slither-dev/slither/slither/slither.py", line 216, in <listcomp>
return [p.output(self._crytic_compile.target).data for p in self._printers]
File "/home/plotchy/code/packages/slither-dev/slither/slither/printers/full/beeprint.py", line 27, in output
print(r_type.source_mapping)
File "/home/plotchy/code/packages/slither-dev/slither/slither/core/source_mapping/source_mapping.py", line 77, in __str__
lines = self._get_lines_str()
File "/home/plotchy/code/packages/slither-dev/slither/slither/core/source_mapping/source_mapping.py", line 63, in _get_lines_str
assert self.compilation_unit is not None
AssertionError
None
Error in h.sol
Traceback (most recent call last):
File "/home/plotchy/code/packages/slither-dev/slither/slither/__main__.py", line 781, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/home/plotchy/code/packages/slither-dev/slither/slither/__main__.py", line 88, in process_all
) = process_single(compilation, args, detector_classes, printer_classes)
File "/home/plotchy/code/packages/slither-dev/slither/slither/__main__.py", line 73, in process_single
return _process(slither, detector_classes, printer_classes)
File "/home/plotchy/code/packages/slither-dev/slither/slither/__main__.py", line 120, in _process
printer_results = slither.run_printers()
File "/home/plotchy/code/packages/slither-dev/slither/slither/slither.py", line 216, in run_printers
return [p.output(self._crytic_compile.target).data for p in self._printers]
File "/home/plotchy/code/packages/slither-dev/slither/slither/slither.py", line 216, in <listcomp>
return [p.output(self._crytic_compile.target).data for p in self._printers]
File "/home/plotchy/code/packages/slither-dev/slither/slither/printers/full/beeprint.py", line 27, in output
print(r_type.source_mapping)
File "/home/plotchy/code/packages/slither-dev/slither/slither/core/source_mapping/source_mapping.py", line 77, in __str__
lines = self._get_lines_str()
File "/home/plotchy/code/packages/slither-dev/slither/slither/core/source_mapping/source_mapping.py", line 63, in _get_lines_str
assert self.compilation_unit is not None
AssertionError