From c428df83ee0f9a626566d23882a01464e97852f2 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 12 Oct 2018 14:46:49 -0400 Subject: [PATCH] more calldata fixes including natives --- mythril/analysis/modules/ether_send.py | 2 +- mythril/laser/ethereum/instructions.py | 15 ++++++++++++--- mythril/laser/ethereum/state.py | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/mythril/analysis/modules/ether_send.py b/mythril/analysis/modules/ether_send.py index 783bfb71..9289b269 100644 --- a/mythril/analysis/modules/ether_send.py +++ b/mythril/analysis/modules/ether_send.py @@ -112,7 +112,7 @@ def execute(statespace): model = solver.get_model(node.constraints) pretty_model = solver.pretty_print_model(model) - logging.debug(pretty_model) + logging.debug('[ETHER_SEND]\n' + pretty_model) debug = "SOLVER OUTPUT:\n" + pretty_model diff --git a/mythril/laser/ethereum/instructions.py b/mythril/laser/ethereum/instructions.py index 02e9ffcf..8d72e26d 100644 --- a/mythril/laser/ethereum/instructions.py +++ b/mythril/laser/ethereum/instructions.py @@ -13,7 +13,7 @@ from mythril.laser.ethereum.call import get_call_parameters from mythril.laser.ethereum.evm_exceptions import VmException, StackUnderflowException, InvalidJumpDestination, \ InvalidInstruction from mythril.laser.ethereum.keccak import KeccakFunctionManager -from mythril.laser.ethereum.state import GlobalState, CalldataType +from mythril.laser.ethereum.state import GlobalState, CalldataType, Calldata from mythril.laser.ethereum.transaction import MessageCallTransaction, TransactionStartSignal, \ ContractCreationTransaction @@ -1030,8 +1030,17 @@ class Instruction: return [global_state] - for i in range(min(len(data), mem_out_sz)): # If more data is used then it's chopped off - global_state.mstate.memory[mem_out_start + i] = data[i] + if type(data) == Calldata: # identity() returns calldata + new_memory = [] + for i in range(mem_out_sz): + new_memory.append(data[i]) + + for i in range(0, len(new_memory), 32): + global_state.mstate.memory[mem_out_start + i] = simplify(Concat(new_memory[i:i+32])) + + else: + for i in range(min(len(data), mem_out_sz)): # If more data is used then it's chopped off + global_state.mstate.memory[mem_out_start + i] = data[i] # TODO: maybe use BitVec here constrained to 1 return [global_state] diff --git a/mythril/laser/ethereum/state.py b/mythril/laser/ethereum/state.py index 186b2534..8cdbebfe 100644 --- a/mythril/laser/ethereum/state.py +++ b/mythril/laser/ethereum/state.py @@ -27,7 +27,7 @@ class Calldata: concrete_calldata.sort(key=lambda x: x[0].as_long() if type(x) == list else -1) result = [] arr_index = 1 - for i in range(0, concrete_calldata[len(concrete_calldata)-1][0].as_long()+1): + for i in range(concrete_calldata[len(concrete_calldata)-1][0].as_long()+1): if concrete_calldata[arr_index][0].as_long() == i: result.append(concrete_calldata[arr_index][1].as_long()) arr_index += 1