From 66ec7de153d336582dc1dd7c3510d7784efb17e9 Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Tue, 21 May 2019 19:06:19 +0200 Subject: [PATCH] Make code nicer: --- .../modules/dependence_on_predictable_vars.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/mythril/analysis/modules/dependence_on_predictable_vars.py b/mythril/analysis/modules/dependence_on_predictable_vars.py index d2dbdcd1..a8c7ac75 100644 --- a/mythril/analysis/modules/dependence_on_predictable_vars.py +++ b/mythril/analysis/modules/dependence_on_predictable_vars.py @@ -10,6 +10,7 @@ from mythril.laser.smt import ULT, symbol_factory from mythril.analysis.swc_data import TIMESTAMP_DEPENDENCE, WEAK_RANDOMNESS from mythril.laser.ethereum.state.global_state import GlobalState from mythril.laser.ethereum.state.annotation import StateAnnotation +from typing import cast, List import traceback log = logging.getLogger(__name__) @@ -151,6 +152,7 @@ def _analyze_states(state: GlobalState) -> list: state.get_current_instruction()["address"], ) ) + break elif opcode == "BLOCKHASH": @@ -181,13 +183,15 @@ def _analyze_states(state: GlobalState) -> list: if opcode == "BLOCKHASH": # if we're in the post hook of a BLOCKHASH op, check if an old block number was used to create it. - for annotation in state.annotations: + annotations = cast( + List[OldBlockNumberUsedAnnotation], + list(state.get_annotations(OldBlockNumberUsedAnnotation)), + ) - if isinstance(annotation, OldBlockNumberUsedAnnotation): - state.mstate.stack[-1].annotate( - PredictableValueAnnotation("block hash of a previous block") - ) - break + if len(annotations): + state.mstate.stack[-1].annotate( + PredictableValueAnnotation("block hash of a previous block") + ) else: # Always create an annotation when COINBASE, GASLIMIT, TIMESTAMP or NUMBER is executed.