Merge branch 'master' into bugfix/contract_name

pull/469/head
JoranHonig 6 years ago committed by GitHub
commit 89c39cd408
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      mythril/analysis/symbolic.py
  2. 2
      mythril/laser/ethereum/call.py
  3. 21
      mythril/laser/ethereum/state.py
  4. 5
      mythril/laser/ethereum/svm.py
  5. 5
      mythril/laser/ethereum/transaction/symbolic.py

@ -24,7 +24,7 @@ class SymExecWrapper:
else:
raise ValueError("Invalid strategy argument supplied")
account = Account(address, contract.disassembly, contract_name=contract.name)
account = Account(address, contract.disassembly, dynamic_loader=dynloader, contract_name=contract.name)
self.accounts = {address: account}

@ -106,7 +106,7 @@ def get_callee_account(global_state, callee_address, dynamic_loader):
raise ValueError()
logging.info("Dependency loaded: " + callee_address)
callee_account = Account(callee_address, code, callee_address)
callee_account = Account(callee_address, code, callee_address, dynamic_loader=dynamic_loader)
accounts[callee_address] = callee_account
return callee_account

@ -13,19 +13,26 @@ class Storage:
"""
Storage class represents the storage of an Account
"""
def __init__(self, concrete=False):
def __init__(self, concrete=False, address=None, dynamic_loader=None):
"""
Constructor for Storage
:param concrete: bool indicating whether to interpret uninitialized storage as concrete versus symbolic
"""
self._storage = {}
self.concrete = concrete
self.dynld = dynamic_loader
self.address = address
def __getitem__(self, item):
try:
return self._storage[item]
except KeyError:
pass
if self.address and int(self.address[2:], 16) != 0 and self.dynld:
try:
self._storage[item] = int(self.dynld.read_storage(contract_address=self.address, index=int(item)), 16)
return self._storage[item]
except ValueError:
pass
if self.concrete:
return 0
self._storage[item] = BitVec("storage_" + str(item), 256)
@ -39,7 +46,8 @@ class Account:
"""
Account class representing ethereum accounts
"""
def __init__(self, address, code=None, contract_name="unknown", balance=None, concrete_storage=False):
def __init__(self, address, code=None, contract_name="unknown", balance=None, concrete_storage=False,
dynamic_loader=None):
"""
Constructor for account
:param address: Address of the account
@ -51,7 +59,7 @@ class Account:
self.nonce = 0
self.code = code
self.balance = balance if balance else BitVec("balance", 256)
self.storage = Storage(concrete_storage)
self.storage = Storage(concrete_storage, address=address, dynamic_loader=dynamic_loader)
# Metadata
self.address = address
@ -227,16 +235,17 @@ class WorldState:
new_world_state.node = self.node
return new_world_state
def create_account(self, balance=0, address=None, concrete_storage=False):
def create_account(self, balance=0, address=None, concrete_storage=False, dynamic_loader=None):
"""
Create non-contract account
:param address: The account's address
:param balance: Initial balance for the account
:param concrete_storage: Interpret account storage as concrete
:param dynamic_loader: used for dynamically loading storage from the block chain
:return: The new account
"""
address = address if address else self._generate_new_address()
new_account = Account(address, balance=balance, concrete_storage=concrete_storage)
new_account = Account(address, balance=balance, dynamic_loader=dynamic_loader, concrete_storage=concrete_storage)
self._put_account(new_account)
return new_account

@ -7,8 +7,8 @@ from mythril.laser.ethereum.cfg import NodeFlags, Node, Edge, JumpType
from mythril.laser.ethereum.strategy.basic import DepthFirstSearchStrategy
from datetime import datetime, timedelta
from copy import copy
from functools import reduce
from mythril.laser.ethereum.transaction import execute_contract_creation, execute_message_call
from functools import reduce
TT256 = 2 ** 256
TT256M1 = 2 ** 256 - 1
@ -74,7 +74,7 @@ class LaserEVM:
logging.info("Finished contract creation, found {} open states".format(len(self.open_states)))
if len(self.open_states) == 0:
print("No contract was created during the execution of contract creation "
"Try to increase the resouces for creation exection (max-depth or create_timeout)")
"Try to increase the resources for creation exection (max-depth or create_timeout)")
# Reset code coverage
self.coverage = {}
@ -266,3 +266,4 @@ class LaserEVM:
return function
return hook_decorator

@ -1,6 +1,6 @@
from mythril.laser.ethereum.transaction.transaction_models import MessageCallTransaction, ContractCreationTransaction
from z3 import BitVec
from mythril.laser.ethereum.state import GlobalState, Environment, CalldataType, Account, WorldState
from mythril.laser.ethereum.state import CalldataType
from mythril.disassembler.disassembly import Disassembly
from mythril.laser.ethereum.cfg import Node, Edge, JumpType
@ -31,11 +31,10 @@ def execute_contract_creation(laser_evm, contract_initialization_code, contract_
open_states = laser_evm.open_states[:]
del laser_evm.open_states[:]
new_account = laser_evm.world_state.create_account(0, concrete_storage=True)
new_account = laser_evm.world_state.create_account(0, concrete_storage=True, dynamic_loader=None)
if contract_name:
new_account.contract_name = contract_name
for open_world_state in open_states:
transaction = ContractCreationTransaction(
open_world_state,

Loading…
Cancel
Save