From 42ebc3bd51b697f803e170db0c7531a9d1eaeda8 Mon Sep 17 00:00:00 2001 From: Joran Honig Date: Fri, 29 Mar 2019 13:45:11 +0100 Subject: [PATCH] add instruction evaluate wrappers to the svm --- mythril/laser/ethereum/svm.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mythril/laser/ethereum/svm.py b/mythril/laser/ethereum/svm.py index 56e4b948..251e8c3c 100644 --- a/mythril/laser/ethereum/svm.py +++ b/mythril/laser/ethereum/svm.py @@ -97,9 +97,12 @@ class LaserEVM: self._add_world_state_hooks = [] # type: List[Callable] self._execute_state_hooks = [] # type: List[Callable] + self._start_sym_exec_hooks = [] # type: List[Callable] self._stop_sym_exec_hooks = [] # type: List[Callable] + self._instruction_evaluate_wrappers = [] # type: List[Callable] + self.iprof = InstructionProfiler() if enable_iprof else None log.info("LASER EVM initialized with dynamic loader: " + str(dynamic_loader)) @@ -285,9 +288,15 @@ class LaserEVM: self._execute_pre_hook(op_code, global_state) try: self._measure_coverage(global_state) - new_global_states = Instruction( + + instruction = Instruction( op_code, self.dynamic_loader, self.iprof - ).evaluate(global_state) + ) + evaluate_function = instruction.evaluate + for wrapping_function in self._instruction_evaluate_wrappers: + evaluate_function = wrapping_function(evaluate_function) + + new_global_states = evaluate_function(global_state) except VmException as e: transaction, return_global_state = global_state.transaction_stack.pop() @@ -532,6 +541,9 @@ class LaserEVM: "Invalid hook type %s. Must be one of {add_world_state}", hook_type ) + def register_instruction_evaluate_wrapper(self, function: Callable) -> None: + self._instruction_evaluate_wrappers.append(function) + def laser_hook(self, hook_type: str) -> Callable: """Registers the annotated function with register_laser_hooks