diff --git a/mythril/analysis/modules/base.py b/mythril/analysis/modules/base.py index d7075109..13b2df81 100644 --- a/mythril/analysis/modules/base.py +++ b/mythril/analysis/modules/base.py @@ -49,12 +49,28 @@ class DetectionModule: """ self._issues = [] - def execute(self, statespace): + def execute(self, statespace) -> list: """The entry point for execution, which is being called by Mythril. :param statespace: :return: """ + + log.debug("Entering analysis module: {}".format(self.__class__.__name__)) + + issues = self._execute(statespace) + + log.debug("Exiting analysis module: {}".format(self.__class__.__name__)) + + return issues + + def _execute(self, statespace): + """The entry point for execution, which is being called by Mythril. + + :param statespace: + :return: + """ + raise NotImplementedError() def __repr__(self) -> str: diff --git a/mythril/analysis/modules/delegatecall.py b/mythril/analysis/modules/delegatecall.py index aeb3e06f..6a0c7449 100644 --- a/mythril/analysis/modules/delegatecall.py +++ b/mythril/analysis/modules/delegatecall.py @@ -12,7 +12,6 @@ from mythril.exceptions import UnsatError from mythril.laser.ethereum.state.annotation import StateAnnotation from mythril.laser.ethereum.state.global_state import GlobalState from mythril.laser.smt import symbol_factory, UGT -from mythril.laser.smt import symbol_factory, UGT log = logging.getLogger(__name__) @@ -80,13 +79,12 @@ class DelegateCallModule(DetectionModule): pre_hooks=["DELEGATECALL", "RETURN", "STOP"], ) - def execute(self, state: GlobalState) -> list: + def _execute(self, state: GlobalState) -> list: """ :param state: :return: """ - log.debug("Executing module: DELEGATE_CALL") self._issues.extend(_analyze_states(state)) return self.issues diff --git a/mythril/analysis/modules/dependence_on_predictable_vars.py b/mythril/analysis/modules/dependence_on_predictable_vars.py index a8c7ac75..937f2b7b 100644 --- a/mythril/analysis/modules/dependence_on_predictable_vars.py +++ b/mythril/analysis/modules/dependence_on_predictable_vars.py @@ -64,15 +64,13 @@ class PredictableDependenceModule(DetectionModule): post_hooks=["BLOCKHASH"] + predictable_ops, ) - def execute(self, state: GlobalState) -> list: + def _execute(self, state: GlobalState) -> list: """ :param state: :return: """ - log.debug("Executing module: DEPENDENCE_ON_PREDICTABLE_VARS") - self._issues.extend(_analyze_states(state)) return self.issues diff --git a/mythril/analysis/modules/deprecated_ops.py b/mythril/analysis/modules/deprecated_ops.py index 6e8adacc..f4703cd9 100644 --- a/mythril/analysis/modules/deprecated_ops.py +++ b/mythril/analysis/modules/deprecated_ops.py @@ -76,7 +76,7 @@ class DeprecatedOperationsModule(DetectionModule): pre_hooks=["ORIGIN", "CALLCODE"], ) - def execute(self, state: GlobalState): + def _execute(self, state: GlobalState): """ :param state: diff --git a/mythril/analysis/modules/dos.py b/mythril/analysis/modules/dos.py index c4a089f3..9614ba95 100644 --- a/mythril/analysis/modules/dos.py +++ b/mythril/analysis/modules/dos.py @@ -43,13 +43,12 @@ class DOS(DetectionModule): """Keeps track of how often jump destinations are reached.""" self._jumpdest_count = {} # type: Dict[object, dict] - def execute(self, state: GlobalState) -> None: + def _execute(self, state: GlobalState) -> None: """ :param state: :return: """ - log.debug("Executing module: DOS") self._issues.extend(self._analyze_states(state)) diff --git a/mythril/analysis/modules/ether_thief.py b/mythril/analysis/modules/ether_thief.py index d382ca07..0ab17d42 100644 --- a/mythril/analysis/modules/ether_thief.py +++ b/mythril/analysis/modules/ether_thief.py @@ -51,7 +51,7 @@ class EtherThief(DetectionModule): super().reset_module() self._cache_addresses = {} - def execute(self, state: GlobalState): + def _execute(self, state: GlobalState): """ :param state: diff --git a/mythril/analysis/modules/exceptions.py b/mythril/analysis/modules/exceptions.py index 8eaf6400..23740f9c 100644 --- a/mythril/analysis/modules/exceptions.py +++ b/mythril/analysis/modules/exceptions.py @@ -72,7 +72,7 @@ class ReachableExceptionsModule(DetectionModule): pre_hooks=["ASSERT_FAIL"], ) - def execute(self, state: GlobalState) -> list: + def _execute(self, state: GlobalState) -> list: """ :param state: diff --git a/mythril/analysis/modules/external_calls.py b/mythril/analysis/modules/external_calls.py index e24470a6..6bc26687 100644 --- a/mythril/analysis/modules/external_calls.py +++ b/mythril/analysis/modules/external_calls.py @@ -137,7 +137,7 @@ class ExternalCalls(DetectionModule): pre_hooks=["CALL"], ) - def execute(self, state: GlobalState): + def _execute(self, state: GlobalState): """ :param state: diff --git a/mythril/analysis/modules/integer.py b/mythril/analysis/modules/integer.py index 43f57c96..773e8173 100644 --- a/mythril/analysis/modules/integer.py +++ b/mythril/analysis/modules/integer.py @@ -84,7 +84,7 @@ class IntegerOverflowUnderflowModule(DetectionModule): self._overflow_cache = {} self._underflow_cache = {} - def execute(self, state: GlobalState): + def _execute(self, state: GlobalState): """Executes analysis module for integer underflow and integer overflow. :param state: Statespace to analyse diff --git a/mythril/analysis/modules/multiple_sends.py b/mythril/analysis/modules/multiple_sends.py index 6b09db77..60ef35ff 100644 --- a/mythril/analysis/modules/multiple_sends.py +++ b/mythril/analysis/modules/multiple_sends.py @@ -43,7 +43,7 @@ class MultipleSendsModule(DetectionModule): ], ) - def execute(self, state: GlobalState): + def _execute(self, state: GlobalState): self._issues.extend(_analyze_state(state)) return self.issues diff --git a/mythril/analysis/modules/state_change_external_calls.py b/mythril/analysis/modules/state_change_external_calls.py index 6a394009..107a3633 100644 --- a/mythril/analysis/modules/state_change_external_calls.py +++ b/mythril/analysis/modules/state_change_external_calls.py @@ -84,7 +84,7 @@ class StateChange(DetectionModule): ], ) - def execute(self, state: GlobalState): + def _execute(self, state: GlobalState): self._issues.extend(self._analyze_state(state)) return self.issues diff --git a/mythril/analysis/modules/suicide.py b/mythril/analysis/modules/suicide.py index 62bc3e00..009e0503 100644 --- a/mythril/analysis/modules/suicide.py +++ b/mythril/analysis/modules/suicide.py @@ -37,7 +37,7 @@ class SuicideModule(DetectionModule): super().reset_module() self._cache_address = {} - def execute(self, state: GlobalState): + def _execute(self, state: GlobalState): """ :param state: diff --git a/mythril/analysis/modules/unchecked_retval.py b/mythril/analysis/modules/unchecked_retval.py index 45fdceec..b88be6df 100644 --- a/mythril/analysis/modules/unchecked_retval.py +++ b/mythril/analysis/modules/unchecked_retval.py @@ -49,7 +49,7 @@ class UncheckedRetvalModule(DetectionModule): post_hooks=["CALL", "DELEGATECALL", "STATICCALL", "CALLCODE"], ) - def execute(self, state: GlobalState) -> list: + def _execute(self, state: GlobalState) -> list: """ :param state: diff --git a/mythril/analysis/security.py b/mythril/analysis/security.py index abacf49a..71f0a516 100644 --- a/mythril/analysis/security.py +++ b/mythril/analysis/security.py @@ -52,6 +52,10 @@ def get_detection_modules(entrypoint, include_modules=()): :param include_modules: :return: """ + + module = importlib.import_module("mythril.analysis.modules.base") + module.log.setLevel(log.level) + include_modules = list(include_modules) _modules = [] @@ -62,12 +66,14 @@ def get_detection_modules(entrypoint, include_modules=()): module = importlib.import_module( "mythril.analysis.modules." + module_name ) + module.log.setLevel(log.level) if module.detector.entrypoint == entrypoint: _modules.append(module) else: for module_name in include_modules: module = importlib.import_module("mythril.analysis.modules." + module_name) if module.__name__ != "base" and module.detector.entrypoint == entrypoint: + module.log.setLevel(log.level) _modules.append(module) log.info("Found %s detection modules", len(_modules)) diff --git a/mythril/interfaces/cli.py b/mythril/interfaces/cli.py index 0fbbab7e..ad2d79c7 100644 --- a/mythril/interfaces/cli.py +++ b/mythril/interfaces/cli.py @@ -24,8 +24,6 @@ from mythril.mythril import ( ) from mythril.version import VERSION -# logging.basicConfig(level=logging.DEBUG) - log = logging.getLogger(__name__)