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_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',

@ -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

@ -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

Loading…
Cancel
Save