Implementation of a depth first search search strategy

pull/312/head
Joran Honig 6 years ago
parent 631ebe07b7
commit 5c0e65b2d8
  1. 0
      mythril/laser/ethereum/strategy/__init__.py
  2. 17
      mythril/laser/ethereum/strategy/basic.py
  3. 13
      mythril/laser/ethereum/svm.py

@ -0,0 +1,17 @@
class DepthFirstSearchStrategy:
def __init__(self, content, max_depth):
self.content = content
self.max_depth = max_depth
def __iter__(self):
return self
def __next__(self):
try:
global_state = self.content.pop(0)
if global_state.mstate.depth >= self.max_depth:
return self.__next__()
return global_state
except IndexError:
raise StopIteration()

@ -3,6 +3,7 @@ import logging
from mythril.laser.ethereum.state import GlobalState, Environment, CalldataType, Account
from mythril.laser.ethereum.instructions import Instruction
from mythril.laser.ethereum.cfg import NodeFlags, Node, Edge, JumpType
from mythril.laser.ethereum.strategy.basic import DepthFirstSearchStrategy
TT256 = 2 ** 256
TT256M1 = 2 ** 256 - 1
@ -31,7 +32,7 @@ class LaserEVM:
self.dynamic_loader = dynamic_loader
self.work_list = []
self.max_depth = max_depth
self.strategy = DepthFirstSearchStrategy(self.work_list, max_depth)
logging.info("LASER EVM initialized with dynamic loader: " + str(dynamic_loader))
@ -57,20 +58,14 @@ class LaserEVM:
initial_node.states.append(global_state)
# Empty the work_list before starting an execution
self.work_list = [global_state]
self.work_list.append(global_state)
self._sym_exec()
logging.info("Execution complete")
logging.info("%d nodes, %d edges, %d total states", len(self.nodes), len(self.edges), self.total_states)
def _sym_exec(self):
while True:
try:
global_state = self.work_list.pop(0)
if global_state.mstate.depth >= self.max_depth: continue
except IndexError:
return
for global_state in self.strategy:
try:
new_states, op_code = self.execute_state(global_state)
except NotImplementedError:

Loading…
Cancel
Save