Merge branch 'master' of github.com:ConsenSys/mythril

pull/525/head
Bernhard Mueller 6 years ago
commit df6f2f35df
  1. 17
      mythril/laser/ethereum/instructions.py
  2. 5
      mythril/laser/ethereum/state.py
  3. 6
      mythril/laser/ethereum/transaction/symbolic.py
  4. 6
      tests/laser/evm_testsuite/evm_test.py
  5. 4
      tests/laser/transaction/symbolic_test.py

@ -978,7 +978,22 @@ class Instruction:
@instruction
def suicide_(self, global_state):
return []
target = global_state.mstate.stack.pop()
# Often the target of the suicide instruction will be symbolic
# If it isn't then well transfer the balance to the indicated contract
if isinstance(target, BitVecNumRef):
target = '0x' + hex(target.as_long())[-40:]
if isinstance(target, str):
try:
global_state.world_state[target].balance += global_state.environment.active_account.balance
except KeyError:
global_state.world_state.create_account(address=target, balance=global_state.environment.active_account.balance)
global_state.environment.active_account.balance = 0
global_state.environment.active_account.deleted = True
global_state.current_transaction.end(global_state)
@instruction
def revert_(self, global_state):

@ -1,4 +1,5 @@
from z3 import BitVec, BitVecVal, Solver, ExprRef, sat
from mythril.disassembler.disassembly import Disassembly
from copy import copy, deepcopy
from enum import Enum
from random import randint
@ -59,7 +60,7 @@ class Account:
:param concrete_storage: Interpret storage as concrete
"""
self.nonce = 0
self.code = code
self.code = code or Disassembly("")
self.balance = balance if balance else BitVec("balance", 256)
self.storage = Storage(concrete_storage, address=address, dynamic_loader=dynamic_loader)
@ -67,6 +68,8 @@ class Account:
self.address = address
self.contract_name = contract_name
self.deleted = False
def __str__(self):
return str(self.as_dict)

@ -1,4 +1,5 @@
from z3 import BitVec, Extract, Not
from logging import debug
from mythril.disassembler.disassembly import Disassembly
from mythril.laser.ethereum.cfg import Node, Edge, JumpType
@ -6,13 +7,16 @@ from mythril.laser.ethereum.state import CalldataType
from mythril.laser.ethereum.transaction.transaction_models import MessageCallTransaction, ContractCreationTransaction,\
get_next_transaction_id
def execute_message_call(laser_evm, callee_address):
""" Executes a message call transaction from all open states """
open_states = laser_evm.open_states[:]
del laser_evm.open_states[:]
for open_world_state in open_states:
if open_world_state[callee_address].deleted:
debug("Can not execute dead contract, skipping.")
continue
next_transaction_id = get_next_transaction_id()
transaction = MessageCallTransaction(
world_state=open_world_state,

@ -71,12 +71,6 @@ def test_vmtest(test_name: str, pre_condition: dict, action: dict, post_conditio
raise e
# Assert
if 'Suicide' not in test_name:
assert len(laser_evm.open_states) == 1
else:
assert len(laser_evm.open_states) == 0
return
world_state = laser_evm.open_states[0]
for address, details in post_condition.items():

@ -1,7 +1,7 @@
from mythril.laser.ethereum.transaction.symbolic import execute_message_call, execute_contract_creation
from mythril.laser.ethereum.transaction import MessageCallTransaction, ContractCreationTransaction
from mythril.laser.ethereum.svm import LaserEVM
from mythril.laser.ethereum.state import WorldState
from mythril.laser.ethereum.state import WorldState, Account
import unittest.mock as mock
from unittest.mock import MagicMock
@ -20,7 +20,7 @@ def test_execute_message_call(mocked_setup: MagicMock):
laser_evm = LaserEVM({})
world_state = WorldState()
world_state.accounts["address"] = "something"
world_state.accounts["address"] = Account("address")
laser_evm.open_states = [world_state]
laser_evm.exec = MagicMock()

Loading…
Cancel
Save