black formatting

pull/615/head
Nathan 6 years ago
parent 8ddb48933c
commit 73bdbfd150
  1. 4
      mythril/analysis/modules/dependence_on_predictable_vars.py
  2. 2
      mythril/analysis/modules/ether_send.py
  3. 2
      mythril/analysis/solver.py
  4. 15
      mythril/laser/ethereum/call.py
  5. 4
      mythril/laser/ethereum/instructions.py
  6. 43
      mythril/laser/ethereum/state.py
  7. 2
      mythril/laser/ethereum/transaction/concolic.py
  8. 1
      mythril/laser/ethereum/transaction/symbolic.py
  9. 14
      mythril/laser/ethereum/transaction/transaction_models.py

@ -158,7 +158,9 @@ def solve(call):
logging.debug("[DEPENDENCE_ON_PREDICTABLE_VARS] MODEL: " + str(model))
pretty_model = solver.pretty_print_model(model)
logging.debug("[DEPENDENCE_ON_PREDICTABLE_VARS] main model: \n%s" % pretty_model)
logging.debug(
"[DEPENDENCE_ON_PREDICTABLE_VARS] main model: \n%s" % pretty_model
)
return True
except UnsatError:

@ -138,7 +138,7 @@ def execute(statespace):
model = solver.get_model(node.constraints)
pretty_model = solver.pretty_print_model(model)
logging.debug('[ETHER_SEND]\n' + pretty_model)
logging.debug("[ETHER_SEND]\n" + pretty_model)
debug = "SOLVER OUTPUT:\n" + pretty_model

@ -24,7 +24,7 @@ def pretty_print_model(model):
for d in model.decls():
if type(model[d]) == FuncInterp:
condition = model[d].as_list()
ret += ("%s: %s\n" % (d.name(), condition))
ret += "%s: %s\n" % (d.name(), condition)
continue
try:

@ -147,11 +147,15 @@ def get_call_data(global_state, memory_start, memory_size, pad=True):
:return: Tuple containing: call_data array from memory or empty array if symbolic, type found
"""
state = global_state.mstate
transaction_id = '{}_internalcall'.format(global_state.current_transaction.id)
transaction_id = "{}_internalcall".format(global_state.current_transaction.id)
try:
# TODO: This only allows for either fully concrete or fully symbolic calldata.
# Improve management of memory and callata to support a mix between both types.
calldata_from_mem = state.memory[util.get_concrete_int(memory_start):util.get_concrete_int(memory_start + memory_size)]
calldata_from_mem = state.memory[
util.get_concrete_int(memory_start) : util.get_concrete_int(
memory_start + memory_size
)
]
i = 0
starting_calldata = []
while i < len(calldata_from_mem):
@ -164,15 +168,12 @@ def get_call_data(global_state, memory_start, memory_size, pad=True):
starting_calldata.append(Extract(j + 7, j, elem))
i += 1
call_data = Calldata(
transaction_id,
starting_calldata
)
call_data = Calldata(transaction_id, starting_calldata)
call_data_type = CalldataType.CONCRETE
logging.debug("Calldata: " + str(call_data))
except TypeError:
logging.info("Unsupported symbolic calldata offset")
call_data_type = CalldataType.SYMBOLIC
call_data = Calldata('{}_internalcall'.format(transaction_id))
call_data = Calldata("{}_internalcall".format(transaction_id))
return call_data, call_data_type

@ -500,7 +500,9 @@ class Instruction:
new_memory = []
for i in range(size):
new_memory.append(environment.calldata[i_data])
i_data = i_data + 1 if isinstance(i_data, int) else simplify(i_data + 1)
i_data = (
i_data + 1 if isinstance(i_data, int) else simplify(i_data + 1)
)
for i in range(0, len(new_memory), 32):
state.memory[i + mstart] = simplify(Concat(new_memory[i : i + 32]))

@ -1,4 +1,20 @@
from z3 import BitVec, BitVecVal, BitVecRef, BitVecNumRef, BitVecSort, Solver, ExprRef, Concat, sat, simplify, Array, ForAll, Solver, UGT, Implies
from z3 import (
BitVec,
BitVecVal,
BitVecRef,
BitVecNumRef,
BitVecSort,
Solver,
ExprRef,
Concat,
sat,
simplify,
Array,
ForAll,
Solver,
UGT,
Implies,
)
from z3.z3types import Z3Exception
from mythril.disassembler.disassembly import Disassembly
from copy import copy, deepcopy
@ -11,10 +27,12 @@ from mythril.laser.ethereum.evm_exceptions import (
StackUnderflowException,
)
class CalldataType(Enum):
CONCRETE = 1
SYMBOLIC = 2
class Calldata:
"""
Calldata class representing the calldata of a transaction
@ -32,8 +50,10 @@ class Calldata:
self.calldatasize = BitVecVal(len(starting_calldata), 256)
self.concrete = True
else:
self._calldata = Array('{}_calldata'.format(self.tx_id), BitVecSort(256), BitVecSort(8))
self.calldatasize = BitVec('{}_calldatasize'.format(self.tx_id), 256)
self._calldata = Array(
"{}_calldata".format(self.tx_id), BitVecSort(256), BitVecSort(8)
)
self.calldatasize = BitVec("{}_calldatasize".format(self.tx_id), 256)
self.concrete = False
self.starting_calldata = starting_calldata or []
@ -50,14 +70,18 @@ class Calldata:
self._calldata.append(calldata_byte)
constraints.append(self.calldatasize == len(self.starting_calldata))
else:
x = BitVec('x', 256)
constraints.append(ForAll(x, Implies(self[x] != 0, UGT(self.calldatasize, x))))
x = BitVec("x", 256)
constraints.append(
ForAll(x, Implies(self[x] != 0, UGT(self.calldatasize, x)))
)
return constraints
def concretized(self, model):
result = []
for i in range(get_concrete_int(model.eval(self.calldatasize, model_completion=True))):
for i in range(
get_concrete_int(model.eval(self.calldatasize, model_completion=True))
):
result.append(get_concrete_int(model.eval(self[i], model_completion=True)))
return result
@ -68,7 +92,11 @@ class Calldata:
def __getitem__(self, item):
if isinstance(item, slice):
try:
current_index = item.start if isinstance(item.start, BitVecRef) else BitVecVal(item.start, 256)
current_index = (
item.start
if isinstance(item.start, BitVecRef)
else BitVecVal(item.start, 256)
)
dataparts = []
while simplify(current_index != item.stop):
dataparts.append(self[current_index])
@ -86,6 +114,7 @@ class Calldata:
else:
return self._calldata[item]
class Storage:
"""
Storage class represents the storage of an Account

@ -10,7 +10,7 @@ from mythril.laser.ethereum.state import (
CalldataType,
Account,
WorldState,
Calldata
Calldata,
)
from mythril.disassembler.disassembly import Disassembly
from mythril.laser.ethereum.cfg import Node, Edge, JumpType

@ -10,6 +10,7 @@ from mythril.laser.ethereum.transaction.transaction_models import (
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[:]

@ -31,6 +31,7 @@ class TransactionStartSignal(Exception):
class MessageCallTransaction:
""" Transaction object models an transaction"""
def __init__(
self,
world_state,
@ -42,7 +43,7 @@ class MessageCallTransaction:
call_value=None,
origin=None,
call_data_type=None,
code=None
code=None,
):
assert isinstance(world_state, WorldState)
self.id = identifier or get_next_transaction_id()
@ -90,7 +91,9 @@ class MessageCallTransaction:
global_state = GlobalState(self.world_state, environment, None)
global_state.environment.active_function_name = "fallback"
global_state.mstate.constraints.extend(global_state.environment.calldata.constraints)
global_state.mstate.constraints.extend(
global_state.environment.calldata.constraints
)
return global_state
@ -101,6 +104,7 @@ class MessageCallTransaction:
class ContractCreationTransaction:
""" Transaction object models an transaction"""
def __init__(
self,
world_state,
@ -145,7 +149,11 @@ class ContractCreationTransaction:
else call_data_type
)
self.call_data = Calldata(self.id, call_data) if not isinstance(call_data, Calldata) else call_data
self.call_data = (
Calldata(self.id, call_data)
if not isinstance(call_data, Calldata)
else call_data
)
self.origin = origin
self.code = code
self.return_data = None

Loading…
Cancel
Save