From 1125c34ddb4eddddf4dc423482cf72bbba24cdcb Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Sun, 30 Jun 2019 09:34:34 +0200 Subject: [PATCH] Modify loop detection to trigger after >2 iterations --- mythril/analysis/modules/dos.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mythril/analysis/modules/dos.py b/mythril/analysis/modules/dos.py index 14053991..36b9b940 100644 --- a/mythril/analysis/modules/dos.py +++ b/mythril/analysis/modules/dos.py @@ -19,7 +19,7 @@ class VisitsAnnotation(StateAnnotation): def __init__(self) -> None: self.loop_start = None - self.jump_targets = [] # type: List[int] + self.jump_targets = {} # type: Dict[int] def __copy__(self): result = VisitsAnnotation() @@ -76,13 +76,19 @@ class DOS(DetectionModule): annotation = annotations[0] if opcode in ["JUMP", "JUMPI"]: + + if annotation.loop_start is not None: + return [] + target = util.get_concrete_int(state.mstate.stack[-1]) - if annotation.loop_start is None: - if target in annotation.jump_targets: - annotation.loop_start = address - else: - annotation.jump_targets.append(target) + if target in annotation.jump_targets: + annotation.jump_targets[target] += 1 + else: + annotation.jump_targets[target] = 1 + + if annotation.jump_targets[target] > 2: + annotation.loop_start = target elif annotation.loop_start is not None: