Add type hints to functions in the predictable vars module and the call helpers

pull/803/head
Nikhil Parasaram 6 years ago
parent c603b4fa7c
commit 29fe835401
  1. 7
      mythril/analysis/call_helpers.py
  2. 11
      mythril/analysis/modules/dependence_on_predictable_vars.py

@ -1,7 +1,10 @@
from typing import Union
from mythril.analysis.ops import VarType, Call, get_variable 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() instruction = state.get_current_instruction()
op = instruction["opcode"] op = instruction["opcode"]
@ -20,7 +23,7 @@ def get_call_from_state(state):
) )
if to.type == VarType.CONCRETE and to.val < 5: if to.type == VarType.CONCRETE and to.val < 5:
return return None
if meminstart.type == VarType.CONCRETE and meminsz.type == VarType.CONCRETE: if meminstart.type == VarType.CONCRETE and meminsz.type == VarType.CONCRETE:
return Call( return Call(

@ -1,5 +1,6 @@
import re 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 import solver
from mythril.analysis.report import Issue from mythril.analysis.report import Issue
from mythril.analysis.call_helpers import get_call_from_state from mythril.analysis.call_helpers import get_call_from_state
@ -25,10 +26,10 @@ class PredictableDependenceModule(DetectionModule):
self._issues = [] self._issues = []
@property @property
def issues(self): def issues(self) -> list:
return self._issues return self._issues
def execute(self, state): def execute(self, state: GlobalState) -> list:
self._issues.extend(_analyze_states(state)) self._issues.extend(_analyze_states(state))
return self.issues return self.issues
@ -36,7 +37,7 @@ class PredictableDependenceModule(DetectionModule):
detector = PredictableDependenceModule() detector = PredictableDependenceModule()
def _analyze_states(state): def _analyze_states(state: GlobalState) -> list:
issues = [] issues = []
call = get_call_from_state(state) call = get_call_from_state(state)
if call is None: if call is None:
@ -177,7 +178,7 @@ def _analyze_states(state):
return issues return issues
def solve(call): def solve(call: Call) -> bool:
try: try:
model = solver.get_model(call.node.constraints) model = solver.get_model(call.node.constraints)
logging.debug("[DEPENDENCE_ON_PREDICTABLE_VARS] MODEL: " + str(model)) logging.debug("[DEPENDENCE_ON_PREDICTABLE_VARS] MODEL: " + str(model))

Loading…
Cancel
Save