add typecheck for the contracts

pull/287/head
Nikhil Parasaram 7 years ago
parent 4559d5f897
commit d6bc09e2e9
  1. 18
      mythril/laser/ethereum/natives.py
  2. 16
      mythril/laser/ethereum/svm.py

@ -1,10 +1,11 @@
# -*- coding: utf8 -*-
import copy
import hashlib
import coincurve
from py_ecc.secp256k1 import N as secp256k1n
from mythril.laser.ethereum.helper import ALL_BYTES, bytearray_to_int, concrete_int_to_bytes, sha3, zpad
@ -40,7 +41,10 @@ def extract32(data, i):
def ecrecover(data):
data = bytearray(data)
try:
data = bytearray(data)
except TypeError:
return "ecrecover_"+str(data)
message = b''.join(map(lambda x: ALL_BYTES[x], data[0:32]))
v = extract32(data, 32)
r = extract32(data, 64)
@ -56,12 +60,18 @@ def ecrecover(data):
def sha256(data):
data = bytes(data)
try:
data = bytes(data)
except TypeError:
return "sha256_"+str(data)
return hashlib.sha256(data).digest()
def ripemd160(data):
data = bytes(data)
try:
data = bytes(data)
except TypeError:
return "ripemd160_"+str(data)
return 12*[0]+[i for i in hashlib.new('ripemd160', data).digest()]

@ -994,12 +994,14 @@ class LaserEVM:
state.stack.append(ret)
continue
if int(callee_address, 16) < 5 and int(callee_address, 16) > 0:
if 0 < int(callee_address, 16) < 5:
logging.info("Native contract called: " + callee_address)
calldata, calldata_type = self._get_calldata(meminstart, meminsz, state, pad=False)
if calldata == [] and calldata_type == CalldataType.SYMBOLIC:
logging.debug("CALL with symbolic data not supported")
ret = BitVec("retval_" + str(instr['address']), 256)
state.stack.append(ret)
continue
data = natives.native_contracts(int(callee_address, 16 ), calldata)
@ -1008,14 +1010,18 @@ class LaserEVM:
mem_out_sz = memoutsz.as_long()
except AttributeError:
logging.debug("CALL with symbolic start or offset not supported")
ret = BitVec("retval_" + str(instr['address']), 256)
state.stack.append(ret)
continue
state.mem_extend(mem_out_start, mem_out_sz)
for i in range(min(len(data), mem_out_sz)): # If more data is used then it's chopped off
state.memory[mem_out_start+i] = data[i]
try:
for i in range(min(len(data), mem_out_sz)): # If more data is used then it's chopped off
state.memory[mem_out_start+i] = data[i]
except:
state.memory[mem_out_start] = BitVec(data, 256)
state.stack.append(1)
ret = BitVec("retval_" + str(instr['address']), 256)
state.stack.append(ret)
continue
try:

Loading…
Cancel
Save