From c9f6f8b2f31ccdbd648827fd18368c94803b6605 Mon Sep 17 00:00:00 2001 From: Nathan Date: Wed, 31 Oct 2018 15:04:20 -0400 Subject: [PATCH] update natives.py to reflect calldata fixes --- mythril/laser/ethereum/natives.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/mythril/laser/ethereum/natives.py b/mythril/laser/ethereum/natives.py index 3091c963..bb741929 100644 --- a/mythril/laser/ethereum/natives.py +++ b/mythril/laser/ethereum/natives.py @@ -1,6 +1,5 @@ # -*- coding: utf8 -*- -import copy import hashlib import logging @@ -8,7 +7,8 @@ from ethereum.utils import ecrecover_to_pub from py_ecc.secp256k1 import N as secp256k1n from rlp.utils import ALL_BYTES -from mythril.laser.ethereum.util import bytearray_to_int, sha3 +from mythril.laser.ethereum.util import bytearray_to_int, sha3, get_concrete_int +from z3 import Concat, simplify class NativeContractException(Exception): @@ -70,7 +70,16 @@ def ripemd160(data): def identity(data): - return copy.copy(data) + # Group up into an array of 32 byte words instead + # of an array of bytes. If saved to memory, 32 byte + # words are currently needed, but a correct memory + # implementation would be byte indexed for the most + # part. + return data + result = [] + for i in range(0, len(data), 32): + result.append(simplify(Concat(data[i : i + 32]))) + return result def native_contracts(address, data): @@ -79,4 +88,11 @@ def native_contracts(address, data): """ functions = (ecrecover, sha256, ripemd160, identity) - return functions[address - 1](data.starting_calldata) + + try: + data = [get_concrete_int(e) for e in data._calldata] + except TypeError: + # Symbolic calldata + data = data._calldata + + return functions[address - 1](data)