From eb963d38fde46d39e91b4be14a68263b869d35d7 Mon Sep 17 00:00:00 2001 From: Joran Honig Date: Thu, 5 Jul 2018 12:16:18 +0200 Subject: [PATCH] Implement depth first search --- mythril/laser/ethereum/strategy/basic.py | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/mythril/laser/ethereum/strategy/basic.py b/mythril/laser/ethereum/strategy/basic.py index 754cd3ef..33dca443 100644 --- a/mythril/laser/ethereum/strategy/basic.py +++ b/mythril/laser/ethereum/strategy/basic.py @@ -27,3 +27,28 @@ class DepthFirstSearchStrategy: except IndexError: raise StopIteration() + +class BreadthFirstSearchStrategy: + """ + Implements a breadth first search strategy + I.E. Execute all states of a "level" before continuing + """ + def __init__(self, work_list, max_depth): + self.work_list = work_list + self.max_depth = max_depth + + def __iter__(self): + return self + + def __next__(self): + """ Picks the next state to execute """ + try: + # This strategies assumes that new states are appended at the end of the work_list + # By taking the first element we effectively pick the "oldest" states, which amounts to bfs + global_state = self.work_list.pop(0) + if global_state.mstate.depth >= self.max_depth: + return self.__next__() + return global_state + except IndexError: + raise StopIteration() +