mirror of https://github.com/crytic/slither
commit
ed4eadaf60
@ -0,0 +1,55 @@ |
||||
--- |
||||
body: |
||||
- |
||||
attributes: |
||||
value: | |
||||
Please check the issues tab to avoid duplicates. |
||||
Thanks for taking the time to fill out this bug report! |
||||
type: markdown |
||||
- |
||||
attributes: |
||||
label: "What operating system are you using?" |
||||
id: os |
||||
type: textarea |
||||
validations: |
||||
required: true |
||||
- |
||||
attributes: |
||||
label: "How did you install slither?" |
||||
description: | |
||||
For example, using git or python's pip. |
||||
id: install-method |
||||
type: textarea |
||||
validations: |
||||
required: true |
||||
- type: dropdown |
||||
id: python |
||||
attributes: |
||||
label: Do you have python added to your $PATH? |
||||
multiple: true |
||||
options: |
||||
- "Yes" |
||||
- "No" |
||||
- "Not sure" |
||||
- type: dropdown |
||||
id: solc |
||||
attributes: |
||||
label: Do you have solc-select installed? |
||||
multiple: true |
||||
options: |
||||
- "Yes" |
||||
- "No" |
||||
- |
||||
attributes: |
||||
description: | |
||||
Please copy and paste any relevant log output. This |
||||
will be automatically formatted into code, so no need for backticks. |
||||
render: shell |
||||
label: "Output of running `slither-doctor .`:" |
||||
id: logs |
||||
type: textarea |
||||
description: "Get help troubleshooting slither installation" |
||||
labels: |
||||
- installation-help |
||||
name: "Trouble with Installing Slither" |
||||
title: "[Installation-Help]: " |
@ -1,17 +1,18 @@ |
||||
from typing import TYPE_CHECKING |
||||
from typing import TYPE_CHECKING, Union |
||||
|
||||
if TYPE_CHECKING: |
||||
from slither.core.expressions.expression import Expression |
||||
from slither.slithir.operations import Operation |
||||
|
||||
|
||||
class ChildExpression: |
||||
def __init__(self): |
||||
def __init__(self) -> None: |
||||
super().__init__() |
||||
self._expression = None |
||||
|
||||
def set_expression(self, expression: "Expression"): |
||||
def set_expression(self, expression: Union["Expression", "Operation"]) -> None: |
||||
self._expression = expression |
||||
|
||||
@property |
||||
def expression(self) -> "Expression": |
||||
def expression(self) -> Union["Expression", "Operation"]: |
||||
return self._expression |
||||
|
@ -0,0 +1,2 @@ |
||||
from .state_variable import StateVariable |
||||
from .variable import Variable |
@ -0,0 +1,50 @@ |
||||
from typing import List, Tuple |
||||
|
||||
from slither.core.declarations import Function |
||||
from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification |
||||
from slither.utils.code_complexity import compute_cyclomatic_complexity |
||||
from slither.utils.output import Output |
||||
|
||||
|
||||
def _check_for_high_cc(high_cc_functions: List[Tuple[Function, int]], f: Function) -> None: |
||||
cc = compute_cyclomatic_complexity(f) |
||||
if cc > 11: |
||||
high_cc_functions.append((f, cc)) |
||||
|
||||
|
||||
class CyclomaticComplexity(AbstractDetector): |
||||
""" |
||||
Detects functions with high (> 11) cyclomatic complexity. |
||||
""" |
||||
|
||||
ARGUMENT = "cyclomatic-complexity" |
||||
HELP = "Detects functions with high (> 11) cyclomatic complexity" |
||||
IMPACT = DetectorClassification.INFORMATIONAL |
||||
CONFIDENCE = DetectorClassification.HIGH |
||||
|
||||
WIKI = "https://github.com/crytic/slither/wiki/Detector-Documentation#cyclomatic-complexity" |
||||
|
||||
WIKI_TITLE = "Cyclomatic complexity" |
||||
WIKI_DESCRIPTION = "Detects functions with high (> 11) cyclomatic complexity." |
||||
WIKI_EXPLOIT_SCENARIO = "" |
||||
WIKI_RECOMMENDATION = ( |
||||
"Reduce cyclomatic complexity by splitting the function into several smaller subroutines." |
||||
) |
||||
|
||||
def _detect(self) -> List[Output]: |
||||
results = [] |
||||
high_cc_functions: List[Tuple[Function, int]] = [] |
||||
|
||||
f: Function |
||||
for c in self.compilation_unit.contracts: |
||||
for f in c.functions_declared: |
||||
_check_for_high_cc(high_cc_functions, f) |
||||
|
||||
for f in self.compilation_unit.functions_top_level: |
||||
_check_for_high_cc(high_cc_functions, f) |
||||
|
||||
for f, cc in high_cc_functions: |
||||
info = [f, f" has a high cyclomatic complexity ({cc}).\n"] |
||||
res = self.generate_result(info) |
||||
results.append(res) |
||||
return results |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue