move hook logic to be in one place and extend with laser_hook

constantinope-reentrancy-check
Joran Honig 6 years ago
parent b52b30d935
commit d150f382d1
  1. 40
      mythril/laser/ethereum/svm.py

@ -494,6 +494,46 @@ class LaserEVM:
new_node.function_name = environment.active_function_name
def register_hooks(self, hook_type: str, hook_dict: Dict[str, List[Callable]]):
"""
:param hook_type:
:param hook_dict:
"""
if hook_type == "pre":
entrypoint = self.pre_hooks
elif hook_type == "post":
entrypoint = self.post_hooks
else:
raise ValueError(
"Invalid hook type %s. Must be one of {pre, post}", hook_type
)
for op_code, funcs in hook_dict.items():
entrypoint[op_code].extend(funcs)
def register_laser_hooks(self, hook_type: str, hook: Callable):
if hook_type == "add_world_state":
self._add_world_state_hooks.append(hook)
else:
raise NotImplementedError
def laser_hook(self, hook_type: str) -> Callable:
"""Registers the annotated function with register_laser_hooks
:param hook_type:
:return: hook decorator
"""
def hook_decorator(func: Callable):
""" Hook decorator generated by laser_hook
:param func: Decorated function
"""
self.register_laser_hooks(hook_type, func)
return hook_decorator
def _execute_pre_hook(self, op_code: str, global_state: GlobalState) -> None:
"""

Loading…
Cancel
Save