Skip to content

Commit

Permalink
Add transaction plugins for summary search strategy (#1705)
Browse files Browse the repository at this point in the history
* Add transaction plugins for summary search strategy

* Add transaction plugins for summary search strategy
  • Loading branch information
norhh committed Nov 11, 2022
1 parent e18dec4 commit f585497
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions mythril/laser/ethereum/svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,17 @@ def __init__(
self.edges: List[Edge] = []

self.time: datetime = None
self.executed_transactions: bool = False

self.pre_hooks: DefaultDict[str, List[Callable]] = defaultdict(list)
self.post_hooks: DefaultDict[str, List[Callable]] = defaultdict(list)

self._add_world_state_hooks: List[Callable] = []
self._execute_state_hooks: List[Callable] = []

self._start_exec_trans_hooks: List[Callable] = []
self._stop_exec_trans_hooks: List[Callable] = []

self._start_sym_trans_hooks: List[Callable] = []
self._stop_sym_trans_hooks: List[Callable] = []

Expand All @@ -121,6 +125,8 @@ def __init__(
self.instr_pre_hook[op] = []
self.instr_post_hook[op] = []
self.hook_type_map = {
"start_execute_transactions": self._start_exec_trans_hooks,
"stop_execute_transactions": self._stop_exec_trans_hooks,
"add_world_state": self._add_world_state_hooks,
"execute_state": self._execute_state_hooks,
"start_sym_exec": self._start_sym_exec_hooks,
Expand Down Expand Up @@ -170,7 +176,7 @@ def sym_exec(
if pre_configuration_mode:
self.open_states = [world_state]
log.info("Starting message call transaction to {}".format(target_address))
self._execute_transactions(symbol_factory.BitVecVal(target_address, 256))
self.execute_transactions(symbol_factory.BitVecVal(target_address, 256))

elif scratch_mode:
log.info("Starting contract creation transaction")
Expand All @@ -191,7 +197,7 @@ def sym_exec(
"Check whether the bytecode is indeed the creation code, otherwise use the --bin-runtime flag"
)

self._execute_transactions(created_account.address)
self.execute_transactions(created_account.address)

log.info("Finished symbolic execution")
if self.requires_statespace:
Expand All @@ -205,6 +211,22 @@ def sym_exec(
for hook in self._stop_sym_exec_hooks:
hook()

def execute_transactions(self, address) -> None:
"""This function helps runs plugins that can order transactions.
Such plugins should set self.executed_transactions as True after its execution
:param address: Address of the contract
:return: None
"""
for hook in self._start_exec_trans_hooks:
hook()

if self.executed_transactions is False:
self._execute_transactions(address)

for hook in self._stop_exec_trans_hooks:
hook()

def _execute_transactions(self, address):
"""This function executes multiple transactions on the address
Expand Down Expand Up @@ -246,6 +268,8 @@ def _execute_transactions(self, address):
for hook in self._stop_sym_trans_hooks:
hook()

self.executed_transactions = True

def _check_create_termination(self) -> bool:
if len(self.open_states) != 0:
return (
Expand Down

0 comments on commit f585497

Please sign in to comment.