Merge pull request #313 from JoranHonig/features/search_strategy_bfs

Implement breadth first search
pull/317/head
JoranHonig 6 years ago committed by GitHub
commit 88873206d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      mythril/laser/ethereum/strategy/basic.py

@ -27,3 +27,28 @@ class DepthFirstSearchStrategy:
except IndexError: except IndexError:
raise StopIteration() 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()

Loading…
Cancel
Save