From 29fe8354015230988ac7b343c08ca9574a04880a Mon Sep 17 00:00:00 2001 From: Nikhil Parasaram Date: Sat, 8 Dec 2018 11:49:29 +0530 Subject: [PATCH] Add type hints to functions in the predictable vars module and the call helpers --- mythril/analysis/call_helpers.py | 7 +++++-- .../modules/dependence_on_predictable_vars.py | 11 ++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/mythril/analysis/call_helpers.py b/mythril/analysis/call_helpers.py index f4a54f61..2e7a56dd 100644 --- a/mythril/analysis/call_helpers.py +++ b/mythril/analysis/call_helpers.py @@ -1,7 +1,10 @@ +from typing import Union + from mythril.analysis.ops import VarType, Call, get_variable +from mythril.laser.ethereum.state.global_state import GlobalState -def get_call_from_state(state): +def get_call_from_state(state: GlobalState) -> Union[Call, None]: instruction = state.get_current_instruction() op = instruction["opcode"] @@ -20,7 +23,7 @@ def get_call_from_state(state): ) if to.type == VarType.CONCRETE and to.val < 5: - return + return None if meminstart.type == VarType.CONCRETE and meminsz.type == VarType.CONCRETE: return Call( diff --git a/mythril/analysis/modules/dependence_on_predictable_vars.py b/mythril/analysis/modules/dependence_on_predictable_vars.py index 8fea57ec..fa3cc5e3 100644 --- a/mythril/analysis/modules/dependence_on_predictable_vars.py +++ b/mythril/analysis/modules/dependence_on_predictable_vars.py @@ -1,5 +1,6 @@ import re -from mythril.analysis.ops import VarType +from mythril.laser.ethereum.state.global_state import GlobalState +from mythril.analysis.ops import Call, VarType from mythril.analysis import solver from mythril.analysis.report import Issue from mythril.analysis.call_helpers import get_call_from_state @@ -25,10 +26,10 @@ class PredictableDependenceModule(DetectionModule): self._issues = [] @property - def issues(self): + def issues(self) -> list: return self._issues - def execute(self, state): + def execute(self, state: GlobalState) -> list: self._issues.extend(_analyze_states(state)) return self.issues @@ -36,7 +37,7 @@ class PredictableDependenceModule(DetectionModule): detector = PredictableDependenceModule() -def _analyze_states(state): +def _analyze_states(state: GlobalState) -> list: issues = [] call = get_call_from_state(state) if call is None: @@ -177,7 +178,7 @@ def _analyze_states(state): return issues -def solve(call): +def solve(call: Call) -> bool: try: model = solver.get_model(call.node.constraints) logging.debug("[DEPENDENCE_ON_PREDICTABLE_VARS] MODEL: " + str(model))