Improve complex, external, suicidal

pull/72/head
Josselin 6 years ago
parent eb2c2a560a
commit 30c76ffa41
  1. 11
      slither/detectors/functions/complex_function.py
  2. 13
      slither/detectors/functions/external_function.py
  3. 13
      slither/detectors/functions/suicidal.py

@ -91,18 +91,19 @@ class ComplexFunction(AbstractDetector):
func, cause = issue.values() func, cause = issue.values()
func_name = func.name func_name = func.name
txt = "Complex function in {} Contract: {}, Function: {}" txt = "Complex function in {}\n\t- {}.{} ({})\n"
if cause == self.CAUSE_EXTERNAL_CALL: 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: if cause == self.CAUSE_CYCLOMATIC:
txt += ", Reason: High number of branches" txt += "\t- Reason: High number of branches"
if cause == self.CAUSE_STATE_VARS: 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, info = txt.format(self.filename,
contract.name, contract.name,
func_name) func_name,
func.source_mapping_str)
self.log(info) self.log(info)
results.append({'vuln': 'ComplexFunc', results.append({'vuln': 'ComplexFunc',

@ -56,15 +56,14 @@ class ExternalFunction(AbstractDetector):
for func in [f for f in contract.functions if f.visibility == 'public' and\ for func in [f for f in contract.functions if f.visibility == 'public' and\
not f in public_function_calls and\ not f in public_function_calls and\
not f.is_constructor]: not f.is_constructor]:
func_name = func.name txt = "{}.{} ({}) should be declared external"
txt = "Public function in {} Contract: {}, Function: {} should be declared external" info = txt.format(func.contract.name,
info = txt.format(self.filename, func.name,
contract.name, func.source_mapping_str)
func_name)
self.log(info) self.log(info)
results.append({'vuln': 'ExternalFunc', results.append({'vuln': 'ExternalFunc',
'sourceMapping': func.source_mapping, 'sourceMapping': func.source_mapping,
'filename': self.filename, 'filename': self.filename,
'contract': contract.name, 'contract': func.contract.name,
'func': func_name}) 'func': func.name})
return results return results

@ -12,7 +12,7 @@ class Suicidal(AbstractDetector):
""" """
ARGUMENT = 'suicidal' ARGUMENT = 'suicidal'
HELP = 'Suicidal functions' HELP = 'Functions allowing anyone to destruct the contract'
IMPACT = DetectorClassification.HIGH IMPACT = DetectorClassification.HIGH
CONFIDENCE = DetectorClassification.HIGH CONFIDENCE = DetectorClassification.HIGH
@ -54,12 +54,11 @@ class Suicidal(AbstractDetector):
for c in self.contracts: for c in self.contracts:
functions = self.detect_suicidal(c) functions = self.detect_suicidal(c)
for func in functions: for func in functions:
func_name = func.name
txt = "Suicidal function in {} Contract: {}, Function: {}" txt = "{}.{} ({}) allows anyone to destruct the contract"
info = txt.format(self.filename, info = txt.format(func.contract.name,
c.name, func.name,
func_name) func.source_mapping_str)
self.log(info) self.log(info)
@ -67,6 +66,6 @@ class Suicidal(AbstractDetector):
'sourceMapping': func.source_mapping, 'sourceMapping': func.source_mapping,
'filename': self.filename, 'filename': self.filename,
'contract': c.name, 'contract': c.name,
'func': func_name}) 'func': func.name})
return results return results

Loading…
Cancel
Save