From 12d0013095f8a49f7b13e7c9e31249d6fdaf37d0 Mon Sep 17 00:00:00 2001 From: Josselin Date: Fri, 26 Oct 2018 18:41:33 +0100 Subject: [PATCH] UninitializedStateVarsDetection: dont report unused variables SlithIr Printer: printer modifiers IRs SlithIR: fix missing condition conversion --- .../variables/uninitialized_state_variables.py | 12 +++++++++++- slither/printers/summary/slithir.py | 10 ++++++++++ slither/slithir/convert.py | 6 ++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/slither/detectors/variables/uninitialized_state_variables.py b/slither/detectors/variables/uninitialized_state_variables.py index a7c6111ba..427e3ad4a 100644 --- a/slither/detectors/variables/uninitialized_state_variables.py +++ b/slither/detectors/variables/uninitialized_state_variables.py @@ -45,10 +45,20 @@ class UninitializedStateVarsDetection(AbstractDetector): return ret + @staticmethod + def read_variables(contract): + ret = [] + for f in contract.all_functions_called + contract.modifiers: + ret += f.state_variables_read + return ret + def detect_uninitialized(self, contract): written_variables = self.written_variables(contract) + read_variables = self.read_variables(contract) return [(variable, contract.get_functions_reading_from_variable(variable)) - for variable in contract.state_variables if variable not in written_variables and not variable.expression] + for variable in contract.state_variables if variable not in written_variables and\ + not variable.expression and\ + variable in read_variables] def detect(self): """ Detect uninitialized state variables diff --git a/slither/printers/summary/slithir.py b/slither/printers/summary/slithir.py index 755dfd169..d48d3bf87 100644 --- a/slither/printers/summary/slithir.py +++ b/slither/printers/summary/slithir.py @@ -29,4 +29,14 @@ class PrinterSlithIR(AbstractPrinter): print('\t\tIRs:') for ir in node.irs: print('\t\t\t{}'.format(ir)) + for modifier in contract.modifiers: + if modifier.contract == contract: + print('\tModifier {}'.format(modifier.full_name)) + for node in modifier.nodes: + print(node) + if node.expression: + print('\t\tExpression: {}'.format(node.expression)) + print('\t\tIRs:') + for ir in node.irs: + print('\t\t\t{}'.format(ir)) self.info(txt) diff --git a/slither/slithir/convert.py b/slither/slithir/convert.py index 8e90c256c..ecffadfdd 100644 --- a/slither/slithir/convert.py +++ b/slither/slithir/convert.py @@ -636,6 +636,12 @@ def convert_expression(expression, node): if isinstance(expression, Identifier) and node.type == NodeType.RETURN: result = [Return(expression.value)] return result + if isinstance(expression, Literal) and node.type in [NodeType.IF, NodeType.IFLOOP]: + result = [Condition(Constant(expression.value))] + return result + if isinstance(expression, Identifier) and node.type in [NodeType.IF, NodeType.IFLOOP]: + result = [Condition(expression.value)] + return result visitor = ExpressionToSlithIR(expression) result = visitor.result()