From 30c76ffa41cfb5b174fbc9b2516f49ffc35e14b7 Mon Sep 17 00:00:00 2001 From: Josselin Date: Tue, 30 Oct 2018 15:56:09 +0100 Subject: [PATCH] Improve complex, external, suicidal --- slither/detectors/functions/complex_function.py | 13 +++++++------ slither/detectors/functions/external_function.py | 13 ++++++------- slither/detectors/functions/suicidal.py | 13 ++++++------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/slither/detectors/functions/complex_function.py b/slither/detectors/functions/complex_function.py index 355f1865b..f2521ad57 100644 --- a/slither/detectors/functions/complex_function.py +++ b/slither/detectors/functions/complex_function.py @@ -90,19 +90,20 @@ class ComplexFunction(AbstractDetector): for issue in issues: func, cause = issue.values() func_name = func.name - - txt = "Complex function in {} Contract: {}, Function: {}" + + txt = "Complex function in {}\n\t- {}.{} ({})\n" if cause == self.CAUSE_EXTERNAL_CALL: - txt += ", Reason: High number of external calls" + txt += "\t- Reason: High number of external calls" if cause == self.CAUSE_CYCLOMATIC: - txt += ", Reason: High number of branches" + txt += "\t- Reason: High number of branches" if cause == self.CAUSE_STATE_VARS: - txt += ", Reason: High number of modified state variables" + txt += "\t- Reason: High number of modified state variables" info = txt.format(self.filename, contract.name, - func_name) + func_name, + func.source_mapping_str) self.log(info) results.append({'vuln': 'ComplexFunc', diff --git a/slither/detectors/functions/external_function.py b/slither/detectors/functions/external_function.py index 99ffe40fe..929414c71 100644 --- a/slither/detectors/functions/external_function.py +++ b/slither/detectors/functions/external_function.py @@ -56,15 +56,14 @@ class ExternalFunction(AbstractDetector): for func in [f for f in contract.functions if f.visibility == 'public' and\ not f in public_function_calls and\ not f.is_constructor]: - func_name = func.name - txt = "Public function in {} Contract: {}, Function: {} should be declared external" - info = txt.format(self.filename, - contract.name, - func_name) + txt = "{}.{} ({}) should be declared external" + info = txt.format(func.contract.name, + func.name, + func.source_mapping_str) self.log(info) results.append({'vuln': 'ExternalFunc', 'sourceMapping': func.source_mapping, 'filename': self.filename, - 'contract': contract.name, - 'func': func_name}) + 'contract': func.contract.name, + 'func': func.name}) return results diff --git a/slither/detectors/functions/suicidal.py b/slither/detectors/functions/suicidal.py index 41b6f9bc5..8cc21cefe 100644 --- a/slither/detectors/functions/suicidal.py +++ b/slither/detectors/functions/suicidal.py @@ -12,7 +12,7 @@ class Suicidal(AbstractDetector): """ ARGUMENT = 'suicidal' - HELP = 'Suicidal functions' + HELP = 'Functions allowing anyone to destruct the contract' IMPACT = DetectorClassification.HIGH CONFIDENCE = DetectorClassification.HIGH @@ -54,12 +54,11 @@ class Suicidal(AbstractDetector): for c in self.contracts: functions = self.detect_suicidal(c) for func in functions: - func_name = func.name - txt = "Suicidal function in {} Contract: {}, Function: {}" - info = txt.format(self.filename, - c.name, - func_name) + txt = "{}.{} ({}) allows anyone to destruct the contract" + info = txt.format(func.contract.name, + func.name, + func.source_mapping_str) self.log(info) @@ -67,6 +66,6 @@ class Suicidal(AbstractDetector): 'sourceMapping': func.source_mapping, 'filename': self.filename, 'contract': c.name, - 'func': func_name}) + 'func': func.name}) return results