From 0bdc7ed48e5a4bb165afee238cc7839863b7cf9b Mon Sep 17 00:00:00 2001 From: Dominik Muhs Date: Sat, 15 Dec 2018 13:26:11 +0100 Subject: [PATCH] Optimize imports --- mythril/analysis/callgraph.py | 3 +- .../modules/dependence_on_predictable_vars.py | 11 ++--- mythril/analysis/modules/deprecated_ops.py | 5 ++- mythril/analysis/modules/ether_thief.py | 12 +++--- mythril/analysis/modules/exceptions.py | 8 ++-- mythril/analysis/modules/external_calls.py | 11 ++--- mythril/analysis/modules/integer.py | 16 +++---- mythril/analysis/modules/suicide.py | 5 ++- .../modules/transaction_order_dependence.py | 5 +-- mythril/analysis/ops.py | 3 +- mythril/analysis/security.py | 8 ++-- mythril/analysis/symbolic.py | 9 ++-- mythril/ethereum/evmcontract.py | 8 ++-- .../interface/leveldb/accountindexing.py | 10 +++-- mythril/ethereum/interface/rpc/base_client.py | 2 +- mythril/ethereum/interface/rpc/client.py | 8 ++-- mythril/ethereum/util.py | 13 +++--- mythril/interfaces/cli.py | 12 +++--- mythril/laser/ethereum/call.py | 7 +-- mythril/laser/ethereum/cfg.py | 3 +- mythril/laser/ethereum/instructions.py | 43 ++++++++----------- mythril/laser/ethereum/natives.py | 4 +- mythril/laser/ethereum/state/account.py | 4 +- mythril/laser/ethereum/state/calldata.py | 19 +++++--- mythril/laser/ethereum/state/environment.py | 6 +-- mythril/laser/ethereum/state/memory.py | 12 +++--- mythril/laser/ethereum/strategy/basic.py | 4 +- mythril/laser/ethereum/svm.py | 13 +++--- mythril/laser/ethereum/taint_analysis.py | 7 +-- .../transaction/transaction_models.py | 19 ++++---- mythril/laser/ethereum/util.py | 8 +--- mythril/laser/smt/__init__.py | 8 ++-- mythril/laser/smt/array.py | 3 +- mythril/laser/smt/bitvec.py | 5 ++- mythril/laser/smt/bool.py | 4 +- mythril/laser/smt/solver.py | 2 +- mythril/mythril.py | 29 ++++++------- mythril/support/signatures.py | 13 +++--- mythril/support/truffle.py | 15 ++++--- solidity_examples/suicide.sol | 8 ++-- 40 files changed, 201 insertions(+), 184 deletions(-) diff --git a/mythril/analysis/callgraph.py b/mythril/analysis/callgraph.py index d296c8e4..b02a62fa 100644 --- a/mythril/analysis/callgraph.py +++ b/mythril/analysis/callgraph.py @@ -4,8 +4,9 @@ graphs.""" import re from jinja2 import Environment, PackageLoader, select_autoescape -from mythril.laser.ethereum.svm import NodeFlags from z3 import Z3Exception + +from mythril.laser.ethereum.svm import NodeFlags from mythril.laser.smt import simplify default_opts = { diff --git a/mythril/analysis/modules/dependence_on_predictable_vars.py b/mythril/analysis/modules/dependence_on_predictable_vars.py index 26f80684..c32cf3cb 100644 --- a/mythril/analysis/modules/dependence_on_predictable_vars.py +++ b/mythril/analysis/modules/dependence_on_predictable_vars.py @@ -1,15 +1,16 @@ """This module contains the detection code for predictable variable dependence.""" +import logging import re -from mythril.laser.ethereum.state.global_state import GlobalState -from mythril.analysis.ops import Call, VarType + from mythril.analysis import solver -from mythril.analysis.report import Issue from mythril.analysis.call_helpers import get_call_from_state -from mythril.analysis.swc_data import TIMESTAMP_DEPENDENCE, PREDICTABLE_VARS_DEPENDENCE from mythril.analysis.modules.base import DetectionModule +from mythril.analysis.ops import Call, VarType +from mythril.analysis.report import Issue +from mythril.analysis.swc_data import PREDICTABLE_VARS_DEPENDENCE, TIMESTAMP_DEPENDENCE from mythril.exceptions import UnsatError -import logging +from mythril.laser.ethereum.state.global_state import GlobalState log = logging.getLogger(__name__) diff --git a/mythril/analysis/modules/deprecated_ops.py b/mythril/analysis/modules/deprecated_ops.py index 6a58cfb2..27e5a8be 100644 --- a/mythril/analysis/modules/deprecated_ops.py +++ b/mythril/analysis/modules/deprecated_ops.py @@ -1,9 +1,10 @@ """This module contains the detection code for deprecated op codes.""" +import logging + +from mythril.analysis.modules.base import DetectionModule from mythril.analysis.report import Issue from mythril.analysis.swc_data import DEPRICATED_FUNCTIONS_USAGE -from mythril.analysis.modules.base import DetectionModule from mythril.laser.ethereum.state.global_state import GlobalState -import logging log = logging.getLogger(__name__) diff --git a/mythril/analysis/modules/ether_thief.py b/mythril/analysis/modules/ether_thief.py index 624874c9..0c9b115d 100644 --- a/mythril/analysis/modules/ether_thief.py +++ b/mythril/analysis/modules/ether_thief.py @@ -1,15 +1,15 @@ """This module contains the detection code for unauthorized ether withdrawal.""" -from mythril.analysis.ops import * +import logging +from copy import copy + from mythril.analysis import solver +from mythril.analysis.modules.base import DetectionModule from mythril.analysis.report import Issue from mythril.analysis.swc_data import UNPROTECTED_ETHER_WITHDRAWAL -from mythril.analysis.modules.base import DetectionModule -from mythril.laser.ethereum.state.global_state import GlobalState from mythril.exceptions import UnsatError -from mythril.laser.smt import symbol_factory, UGT, Sum, BVAddNoOverflow -import logging -from copy import copy +from mythril.laser.ethereum.state.global_state import GlobalState +from mythril.laser.smt import UGT, BVAddNoOverflow, Sum, symbol_factory log = logging.getLogger(__name__) diff --git a/mythril/analysis/modules/exceptions.py b/mythril/analysis/modules/exceptions.py index 991c50ca..6404e050 100644 --- a/mythril/analysis/modules/exceptions.py +++ b/mythril/analysis/modules/exceptions.py @@ -1,11 +1,11 @@ """This module contains the detection code for reachable exceptions.""" +import logging + +from mythril.analysis import solver +from mythril.analysis.modules.base import DetectionModule from mythril.analysis.report import Issue from mythril.analysis.swc_data import ASSERT_VIOLATION from mythril.exceptions import UnsatError -from mythril.analysis import solver -from mythril.analysis.modules.base import DetectionModule -import logging - from mythril.laser.ethereum.state.global_state import GlobalState log = logging.getLogger(__name__) diff --git a/mythril/analysis/modules/external_calls.py b/mythril/analysis/modules/external_calls.py index 9f967711..8e316b79 100644 --- a/mythril/analysis/modules/external_calls.py +++ b/mythril/analysis/modules/external_calls.py @@ -1,13 +1,14 @@ """This module contains the detection code for potentially insecure low-level calls.""" -from mythril.analysis.report import Issue +import logging + from mythril.analysis import solver -from mythril.analysis.swc_data import REENTRANCY from mythril.analysis.modules.base import DetectionModule -from mythril.laser.smt import UGT, symbol_factory -from mythril.laser.ethereum.state.global_state import GlobalState +from mythril.analysis.report import Issue +from mythril.analysis.swc_data import REENTRANCY from mythril.exceptions import UnsatError -import logging +from mythril.laser.ethereum.state.global_state import GlobalState +from mythril.laser.smt import UGT, symbol_factory log = logging.getLogger(__name__) diff --git a/mythril/analysis/modules/integer.py b/mythril/analysis/modules/integer.py index ff91bddc..26c5465a 100644 --- a/mythril/analysis/modules/integer.py +++ b/mythril/analysis/modules/integer.py @@ -1,25 +1,23 @@ """This module contains the detection code for integer overflows and underflows.""" +import copy +import logging + from mythril.analysis import solver +from mythril.analysis.modules.base import DetectionModule from mythril.analysis.report import Issue from mythril.analysis.swc_data import INTEGER_OVERFLOW_AND_UNDERFLOW from mythril.exceptions import UnsatError from mythril.laser.ethereum.taint_analysis import TaintRunner -from mythril.analysis.modules.base import DetectionModule - from mythril.laser.smt import ( + BitVec, BVAddNoOverflow, - BVSubNoUnderflow, BVMulNoOverflow, - BitVec, - symbol_factory, + BVSubNoUnderflow, Not, + symbol_factory, ) -import copy -import logging - - log = logging.getLogger(__name__) diff --git a/mythril/analysis/modules/suicide.py b/mythril/analysis/modules/suicide.py index 353be7ee..159fb914 100644 --- a/mythril/analysis/modules/suicide.py +++ b/mythril/analysis/modules/suicide.py @@ -1,10 +1,11 @@ +import logging + from mythril.analysis import solver +from mythril.analysis.modules.base import DetectionModule from mythril.analysis.report import Issue from mythril.analysis.swc_data import UNPROTECTED_SELFDESTRUCT from mythril.exceptions import UnsatError -from mythril.analysis.modules.base import DetectionModule from mythril.laser.ethereum.state.global_state import GlobalState -import logging log = logging.getLogger(__name__) diff --git a/mythril/analysis/modules/transaction_order_dependence.py b/mythril/analysis/modules/transaction_order_dependence.py index 29f228d7..728bbbe2 100644 --- a/mythril/analysis/modules/transaction_order_dependence.py +++ b/mythril/analysis/modules/transaction_order_dependence.py @@ -1,17 +1,16 @@ """This module contains the detection code to find the existence of transaction order dependence.""" +import copy import logging import re -import copy from mythril.analysis import solver +from mythril.analysis.modules.base import DetectionModule from mythril.analysis.ops import * from mythril.analysis.report import Issue from mythril.analysis.swc_data import TX_ORDER_DEPENDENCE -from mythril.analysis.modules.base import DetectionModule from mythril.exceptions import UnsatError - log = logging.getLogger(__name__) diff --git a/mythril/analysis/ops.py b/mythril/analysis/ops.py index a4db24bc..e993b262 100644 --- a/mythril/analysis/ops.py +++ b/mythril/analysis/ops.py @@ -1,8 +1,9 @@ """This module contains various helper methods for dealing with EVM operations.""" -from mythril.laser.smt import simplify from enum import Enum + from mythril.laser.ethereum import util +from mythril.laser.smt import simplify class VarType(Enum): diff --git a/mythril/analysis/security.py b/mythril/analysis/security.py index 746709de..66bc2ead 100644 --- a/mythril/analysis/security.py +++ b/mythril/analysis/security.py @@ -1,11 +1,13 @@ """This module contains functionality for hooking in detection modules and executing them.""" +import importlib.util +import logging +import pkgutil from collections import defaultdict + from ethereum.opcodes import opcodes + from mythril.analysis import modules -import pkgutil -import importlib.util -import logging log = logging.getLogger(__name__) diff --git a/mythril/analysis/symbolic.py b/mythril/analysis/symbolic.py index 64256563..dd4a701a 100644 --- a/mythril/analysis/symbolic.py +++ b/mythril/analysis/symbolic.py @@ -1,17 +1,18 @@ """This module contains a wrapper around LASER for extended analysis purposes.""" +import copy + from mythril.analysis.security import get_detection_module_hooks from mythril.laser.ethereum import svm from mythril.laser.ethereum.state.account import Account -from mythril.solidity.soliditycontract import SolidityContract, EVMContract -import copy -from .ops import get_variable, SStore, Call, VarType from mythril.laser.ethereum.strategy.basic import ( - DepthFirstSearchStrategy, BreadthFirstSearchStrategy, + DepthFirstSearchStrategy, ReturnRandomNaivelyStrategy, ReturnWeightedRandomStrategy, ) +from mythril.solidity.soliditycontract import EVMContract, SolidityContract +from .ops import Call, SStore, VarType, get_variable class SymExecWrapper: diff --git a/mythril/ethereum/evmcontract.py b/mythril/ethereum/evmcontract.py index d401f142..1a9fdbf2 100644 --- a/mythril/ethereum/evmcontract.py +++ b/mythril/ethereum/evmcontract.py @@ -1,10 +1,12 @@ """This module contains the class representing EVM contracts, aka Smart Contracts.""" -from mythril.disassembler.disassembly import Disassembly -from ethereum import utils -import persistent import re +import persistent +from ethereum import utils + +from mythril.disassembler.disassembly import Disassembly + class EVMContract(persistent.Persistent): """This class represents an address with associated code (Smart diff --git a/mythril/ethereum/interface/leveldb/accountindexing.py b/mythril/ethereum/interface/leveldb/accountindexing.py index 45bcefff..e9a45917 100644 --- a/mythril/ethereum/interface/leveldb/accountindexing.py +++ b/mythril/ethereum/interface/leveldb/accountindexing.py @@ -4,13 +4,15 @@ This includes a sedes class for lists, account storage receipts for LevelDB and a class for updating account addresses. """ import logging -from mythril import ethereum import time -from ethereum.messages import Log + import rlp -from rlp.sedes import big_endian_int, binary from ethereum import utils -from ethereum.utils import hash32, address, int256 +from ethereum.messages import Log +from ethereum.utils import address, hash32, int256 +from rlp.sedes import big_endian_int, binary + +from mythril import ethereum from mythril.exceptions import AddressNotFoundError log = logging.getLogger(__name__) diff --git a/mythril/ethereum/interface/rpc/base_client.py b/mythril/ethereum/interface/rpc/base_client.py index 8c8cfddd..a1240502 100644 --- a/mythril/ethereum/interface/rpc/base_client.py +++ b/mythril/ethereum/interface/rpc/base_client.py @@ -5,7 +5,7 @@ This code is adapted from: https://github.com/ConsenSys/ethjsonrpc from abc import abstractmethod -from .constants import BLOCK_TAGS, BLOCK_TAG_LATEST +from .constants import BLOCK_TAG_LATEST, BLOCK_TAGS from .utils import hex_to_dec, validate_block GETH_DEFAULT_RPC_PORT = 8545 diff --git a/mythril/ethereum/interface/rpc/client.py b/mythril/ethereum/interface/rpc/client.py index aa2f120a..8f1269c2 100644 --- a/mythril/ethereum/interface/rpc/client.py +++ b/mythril/ethereum/interface/rpc/client.py @@ -4,16 +4,18 @@ This code is adapted from: https://github.com/ConsenSys/ethjsonrpc """ import json import logging + import requests from requests.adapters import HTTPAdapter from requests.exceptions import ConnectionError as RequestsConnectionError + +from .base_client import BaseClient from .exceptions import ( - ConnectionError, - BadStatusCodeError, BadJsonError, BadResponseError, + BadStatusCodeError, + ConnectionError, ) -from .base_client import BaseClient log = logging.getLogger(__name__) diff --git a/mythril/ethereum/util.py b/mythril/ethereum/util.py index c672a437..db5fd8e1 100644 --- a/mythril/ethereum/util.py +++ b/mythril/ethereum/util.py @@ -1,14 +1,15 @@ """This module contains various utility functions regarding unit conversion and solc integration.""" -from ethereum.abi import encode_abi, encode_int -from ethereum.utils import zpad -from ethereum.abi import method_id -from mythril.exceptions import CompilerError -from subprocess import Popen, PIPE import binascii -import os import json +import os from pathlib import Path +from subprocess import PIPE, Popen + +from ethereum.abi import encode_abi, encode_int, method_id +from ethereum.utils import zpad + +from mythril.exceptions import CompilerError def safe_decode(hex_encoded_string): diff --git a/mythril/interfaces/cli.py b/mythril/interfaces/cli.py index 99ce94c2..c75d1b2f 100644 --- a/mythril/interfaces/cli.py +++ b/mythril/interfaces/cli.py @@ -5,18 +5,20 @@ http://www.github.com/ConsenSys/mythril """ -import logging, coloredlogs +import argparse import json +import logging import os import sys -import argparse -# logging.basicConfig(level=logging.DEBUG) +import coloredlogs -from mythril.exceptions import CriticalError, AddressNotFoundError +import mythril.support.signatures as sigs +from mythril.exceptions import AddressNotFoundError, CriticalError from mythril.mythril import Mythril from mythril.version import VERSION -import mythril.support.signatures as sigs + +# logging.basicConfig(level=logging.DEBUG) log = logging.getLogger(__name__) diff --git a/mythril/laser/ethereum/call.py b/mythril/laser/ethereum/call.py index 226814ef..b01ab4d9 100644 --- a/mythril/laser/ethereum/call.py +++ b/mythril/laser/ethereum/call.py @@ -3,18 +3,19 @@ instructions.py to get the necessary elements from the stack and determine the parameters for the new global state.""" import logging +import re from typing import Union -from mythril.laser.smt import simplify, Expression, symbol_factory + import mythril.laser.ethereum.util as util from mythril.laser.ethereum.state.account import Account from mythril.laser.ethereum.state.calldata import ( CalldataType, - SymbolicCalldata, ConcreteCalldata, + SymbolicCalldata, ) from mythril.laser.ethereum.state.global_state import GlobalState +from mythril.laser.smt import Expression, simplify, symbol_factory from mythril.support.loader import DynLoader -import re """ This module contains the business logic used by Instruction in instructions.py diff --git a/mythril/laser/ethereum/cfg.py b/mythril/laser/ethereum/cfg.py index 576115af..b3cc3c43 100644 --- a/mythril/laser/ethereum/cfg.py +++ b/mythril/laser/ethereum/cfg.py @@ -1,8 +1,9 @@ """This module.""" -from flags import Flags from enum import Enum from typing import Dict +from flags import Flags + gbl_next_uid = 0 # node counter diff --git a/mythril/laser/ethereum/instructions.py b/mythril/laser/ethereum/instructions.py index d81a2de8..8d250dee 100644 --- a/mythril/laser/ethereum/instructions.py +++ b/mythril/laser/ethereum/instructions.py @@ -2,33 +2,11 @@ transitions between them.""" import binascii import logging - from copy import copy, deepcopy from typing import Callable, List, Union -from functools import reduce from ethereum import utils -from mythril.laser.smt import ( - Extract, - Expression, - UDiv, - simplify, - Concat, - ULT, - UGT, - BitVec, - is_true, - is_false, - URem, - SRem, - If, - Bool, - Or, - Not, -) -from mythril.laser.smt import symbol_factory - import mythril.laser.ethereum.natives as natives import mythril.laser.ethereum.util as helper from mythril.laser.ethereum import util @@ -49,9 +27,26 @@ from mythril.laser.ethereum.transaction import ( TransactionStartSignal, ContractCreationTransaction, ) - +from mythril.laser.smt import ( + Extract, + Expression, + UDiv, + simplify, + Concat, + ULT, + UGT, + BitVec, + is_true, + is_false, + URem, + SRem, + If, + Bool, + Or, + Not, +) +from mythril.laser.smt import symbol_factory from mythril.support.loader import DynLoader -from mythril.analysis.solver import get_model log = logging.getLogger(__name__) diff --git a/mythril/laser/ethereum/natives.py b/mythril/laser/ethereum/natives.py index e36d49c2..205e325a 100644 --- a/mythril/laser/ethereum/natives.py +++ b/mythril/laser/ethereum/natives.py @@ -2,14 +2,14 @@ import hashlib import logging -from typing import Union, List +from typing import List, Union 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.state.calldata import BaseCalldata, ConcreteCalldata -from mythril.laser.ethereum.util import bytearray_to_int, sha3, get_concrete_int +from mythril.laser.ethereum.util import bytearray_to_int, sha3 from mythril.laser.smt import Concat, simplify log = logging.getLogger(__name__) diff --git a/mythril/laser/ethereum/state/account.py b/mythril/laser/ethereum/state/account.py index a25b8dee..a5fd1d2d 100644 --- a/mythril/laser/ethereum/state/account.py +++ b/mythril/laser/ethereum/state/account.py @@ -3,12 +3,12 @@ This includes classes representing accounts and their storage. """ -from typing import Dict, Union, Any, KeysView +from typing import Any, Dict, KeysView, Union from z3 import ExprRef -from mythril.laser.smt import symbol_factory from mythril.disassembler.disassembly import Disassembly +from mythril.laser.smt import symbol_factory class Storage: diff --git a/mythril/laser/ethereum/state/calldata.py b/mythril/laser/ethereum/state/calldata.py index 4440cb22..2be3d888 100644 --- a/mythril/laser/ethereum/state/calldata.py +++ b/mythril/laser/ethereum/state/calldata.py @@ -1,16 +1,23 @@ """This module declares classes to represent call data.""" from enum import Enum -from typing import Union, Any - -from mythril.laser.smt import K, Array, If, simplify, Concat, Expression, BitVec - -from mythril.laser.smt import symbol_factory -from mythril.laser.ethereum.util import get_concrete_int +from typing import Any, Union from z3 import Model from z3.z3types import Z3Exception +from mythril.laser.ethereum.util import get_concrete_int +from mythril.laser.smt import ( + Array, + BitVec, + Concat, + Expression, + If, + K, + simplify, + symbol_factory, +) + class CalldataType(Enum): CONCRETE = 1 diff --git a/mythril/laser/ethereum/state/environment.py b/mythril/laser/ethereum/state/environment.py index 7c904fbc..a7686ad2 100644 --- a/mythril/laser/ethereum/state/environment.py +++ b/mythril/laser/ethereum/state/environment.py @@ -2,11 +2,11 @@ environment.""" from typing import Dict -from z3 import ExprRef, BitVecVal +from z3 import ExprRef -from mythril.laser.smt import symbol_factory from mythril.laser.ethereum.state.account import Account -from mythril.laser.ethereum.state.calldata import CalldataType, BaseCalldata +from mythril.laser.ethereum.state.calldata import BaseCalldata, CalldataType +from mythril.laser.smt import symbol_factory class Environment: diff --git a/mythril/laser/ethereum/state/memory.py b/mythril/laser/ethereum/state/memory.py index 74d5c547..a01ae967 100644 --- a/mythril/laser/ethereum/state/memory.py +++ b/mythril/laser/ethereum/state/memory.py @@ -1,16 +1,18 @@ """This module contains a representation of a smart contract's memory.""" from typing import Union + from z3 import Z3Exception + +from mythril.laser.ethereum import util from mythril.laser.smt import ( BitVec, - symbol_factory, - If, - Concat, - simplify, Bool, + Concat, Extract, + If, + simplify, + symbol_factory, ) -from mythril.laser.ethereum import util class Memory: diff --git a/mythril/laser/ethereum/strategy/basic.py b/mythril/laser/ethereum/strategy/basic.py index d46c2c33..6627241c 100644 --- a/mythril/laser/ethereum/strategy/basic.py +++ b/mythril/laser/ethereum/strategy/basic.py @@ -1,7 +1,7 @@ """This module implements basic symbolic execution search strategies.""" -from mythril.laser.ethereum.state.global_state import GlobalState -from typing import List from random import randrange + +from mythril.laser.ethereum.state.global_state import GlobalState from . import BasicSearchStrategy try: diff --git a/mythril/laser/ethereum/svm.py b/mythril/laser/ethereum/svm.py index 30e29039..0bd646c1 100644 --- a/mythril/laser/ethereum/svm.py +++ b/mythril/laser/ethereum/svm.py @@ -4,22 +4,19 @@ from collections import defaultdict from copy import copy from datetime import datetime, timedelta from functools import reduce -from typing import List, Tuple, Union, Callable, Dict +from typing import Callable, Dict, List, Tuple, Union -from mythril.laser.ethereum.cfg import NodeFlags, Node, Edge, JumpType -from mythril.laser.ethereum.evm_exceptions import StackUnderflowException -from mythril.laser.ethereum.evm_exceptions import VmException +from mythril.laser.ethereum.cfg import Edge, JumpType, Node, NodeFlags +from mythril.laser.ethereum.evm_exceptions import StackUnderflowException, VmException from mythril.laser.ethereum.instructions import Instruction from mythril.laser.ethereum.state.account import Account from mythril.laser.ethereum.state.global_state import GlobalState from mythril.laser.ethereum.state.world_state import WorldState from mythril.laser.ethereum.strategy.basic import DepthFirstSearchStrategy from mythril.laser.ethereum.transaction import ( - TransactionStartSignal, - TransactionEndSignal, ContractCreationTransaction, -) -from mythril.laser.ethereum.transaction import ( + TransactionEndSignal, + TransactionStartSignal, execute_contract_creation, execute_message_call, ) diff --git a/mythril/laser/ethereum/taint_analysis.py b/mythril/laser/ethereum/taint_analysis.py index 9645178b..394069b1 100644 --- a/mythril/laser/ethereum/taint_analysis.py +++ b/mythril/laser/ethereum/taint_analysis.py @@ -1,12 +1,13 @@ """This module implements classes needed to perform taint analysis.""" -import logging import copy -from typing import Union, List, Tuple +import logging +from typing import List, Tuple, Union + import mythril.laser.ethereum.util as helper +from mythril.analysis.symbolic import SymExecWrapper from mythril.laser.ethereum.cfg import JumpType, Node from mythril.laser.ethereum.state.environment import Environment from mythril.laser.ethereum.state.global_state import GlobalState -from mythril.analysis.symbolic import SymExecWrapper from mythril.laser.smt import Expression log = logging.getLogger(__name__) diff --git a/mythril/laser/ethereum/transaction/transaction_models.py b/mythril/laser/ethereum/transaction/transaction_models.py index 9ae72f97..d5cfa41b 100644 --- a/mythril/laser/ethereum/transaction/transaction_models.py +++ b/mythril/laser/ethereum/transaction/transaction_models.py @@ -1,21 +1,18 @@ """This module contians the transaction models used throughout LASER's symbolic execution.""" +import array from typing import Union -from mythril.disassembler.disassembly import Disassembly -from mythril.laser.smt import symbol_factory -from mythril.laser.ethereum.state.environment import Environment -from mythril.laser.ethereum.state.calldata import ( - BaseCalldata, - ConcreteCalldata, - SymbolicCalldata, -) +from z3 import ExprRef + +from mythril.disassembler.disassembly import Disassembly from mythril.laser.ethereum.state.account import Account -from mythril.laser.ethereum.state.world_state import WorldState +from mythril.laser.ethereum.state.calldata import BaseCalldata, SymbolicCalldata +from mythril.laser.ethereum.state.environment import Environment from mythril.laser.ethereum.state.global_state import GlobalState -from z3 import ExprRef -import array +from mythril.laser.ethereum.state.world_state import WorldState +from mythril.laser.smt import symbol_factory _next_transaction_id = 0 diff --git a/mythril/laser/ethereum/util.py b/mythril/laser/ethereum/util.py index 3830b219..880e04c4 100644 --- a/mythril/laser/ethereum/util.py +++ b/mythril/laser/ethereum/util.py @@ -1,15 +1,11 @@ """This module contains various utility conversion functions and constants for LASER.""" import re - -from mythril.laser.smt import is_false, is_true, simplify, If, BitVec, Bool, Expression -from mythril.laser.smt import symbol_factory - -import logging -from typing import Union, List, Dict +from typing import Dict, List, Union import sha3 as _sha3 +from mythril.laser.smt import BitVec, Bool, Expression, If, simplify, symbol_factory TT256 = 2 ** 256 TT256M1 = 2 ** 256 - 1 diff --git a/mythril/laser/smt/__init__.py b/mythril/laser/smt/__init__.py index 8c669001..85c72e60 100644 --- a/mythril/laser/smt/__init__.py +++ b/mythril/laser/smt/__init__.py @@ -1,3 +1,6 @@ +import z3 + +from mythril.laser.smt.array import K, Array, BaseArray from mythril.laser.smt.bitvec import ( BitVec, If, @@ -14,13 +17,10 @@ from mythril.laser.smt.bitvec import ( BVMulNoOverflow, BVSubNoUnderflow, ) -from mythril.laser.smt.expression import Expression, simplify from mythril.laser.smt.bool import Bool, is_true, is_false, Or, Not -from mythril.laser.smt.array import K, Array, BaseArray +from mythril.laser.smt.expression import Expression, simplify from mythril.laser.smt.solver import Solver, Optimize -import z3 - class SymbolFactory: """A symbol factory provides a default interface for all the components of diff --git a/mythril/laser/smt/array.py b/mythril/laser/smt/array.py index 1396f5fa..a568ea4c 100644 --- a/mythril/laser/smt/array.py +++ b/mythril/laser/smt/array.py @@ -5,9 +5,10 @@ operations, as well as as a K-array, which can be initialized with default values over a certain range. """ -from mythril.laser.smt.bitvec import BitVec import z3 +from mythril.laser.smt.bitvec import BitVec + class BaseArray: """Base array type, which implements basic store and set operations.""" diff --git a/mythril/laser/smt/bitvec.py b/mythril/laser/smt/bitvec.py index bce44c88..bfbe1c9f 100644 --- a/mythril/laser/smt/bitvec.py +++ b/mythril/laser/smt/bitvec.py @@ -1,11 +1,12 @@ """This module provides classes for an SMT abstraction of bit vectors.""" +from typing import Union + import z3 -from mythril.laser.smt.expression import Expression from mythril.laser.smt.bool import Bool +from mythril.laser.smt.expression import Expression -from typing import Union # fmt: off diff --git a/mythril/laser/smt/bool.py b/mythril/laser/smt/bool.py index aadacda2..ac17caa8 100644 --- a/mythril/laser/smt/bool.py +++ b/mythril/laser/smt/bool.py @@ -1,11 +1,13 @@ """This module provides classes for an SMT abstraction of boolean expressions.""" -import z3 from typing import Union +import z3 + from mythril.laser.smt.expression import Expression + # fmt: off diff --git a/mythril/laser/smt/solver.py b/mythril/laser/smt/solver.py index 8a1d495f..4b973470 100644 --- a/mythril/laser/smt/solver.py +++ b/mythril/laser/smt/solver.py @@ -1,6 +1,6 @@ """This module contains an abstract SMT representation of an SMT solver.""" import z3 -from mythril.laser.smt.bool import Bool + from mythril.laser.smt.expression import Expression diff --git a/mythril/mythril.py b/mythril/mythril.py index d962f7e3..bd42de92 100644 --- a/mythril/mythril.py +++ b/mythril/mythril.py @@ -5,35 +5,34 @@ http://www.github.com/b-mueller/mythril """ +import codecs import logging -import json import os +import platform import re +from configparser import ConfigParser from pathlib import Path +from shutil import copyfile +import solc from ethereum import utils -import codecs from solc.exceptions import SolcError -import solc -from configparser import ConfigParser -import platform -from shutil import copyfile +from mythril.analysis.callgraph import generate_graph +from mythril.analysis.report import Report +from mythril.analysis.security import fire_lasers +from mythril.analysis.symbolic import SymExecWrapper +from mythril.analysis.traceexplore import get_serializable_statespace from mythril.ethereum import util from mythril.ethereum.evmcontract import EVMContract -from mythril.solidity.soliditycontract import SolidityContract, get_contracts_from_file +from mythril.ethereum.interface.leveldb.client import EthLevelDB from mythril.ethereum.interface.rpc.client import EthJsonRpc from mythril.ethereum.interface.rpc.exceptions import ConnectionError +from mythril.exceptions import CompilerError, CriticalError, NoContractFoundError +from mythril.solidity.soliditycontract import SolidityContract, get_contracts_from_file from mythril.support import signatures -from mythril.support.truffle import analyze_truffle_project from mythril.support.loader import DynLoader -from mythril.exceptions import CompilerError, NoContractFoundError, CriticalError -from mythril.analysis.symbolic import SymExecWrapper -from mythril.analysis.callgraph import generate_graph -from mythril.analysis.traceexplore import get_serializable_statespace -from mythril.analysis.security import fire_lasers -from mythril.analysis.report import Report -from mythril.ethereum.interface.leveldb.client import EthLevelDB +from mythril.support.truffle import analyze_truffle_project log = logging.getLogger(__name__) diff --git a/mythril/support/signatures.py b/mythril/support/signatures.py index 7460e0ca..530f0137 100644 --- a/mythril/support/signatures.py +++ b/mythril/support/signatures.py @@ -1,17 +1,16 @@ """The Mythril function signature database.""" -import os -import time +import functools import logging -import sqlite3 import multiprocessing -import functools -from typing import List +import os +import sqlite3 +import time from collections import defaultdict +from subprocess import PIPE, Popen +from typing import List -from subprocess import Popen, PIPE from mythril.exceptions import CompilerError - log = logging.getLogger(__name__) lock = multiprocessing.Lock() diff --git a/mythril/support/truffle.py b/mythril/support/truffle.py index 1841c340..57e101f5 100644 --- a/mythril/support/truffle.py +++ b/mythril/support/truffle.py @@ -1,20 +1,21 @@ """This module contains functionality used to easily analyse Truffle projects.""" +import json +import logging import os -from pathlib import PurePath import re import sys -import json -import logging +from pathlib import PurePath + from ethereum.utils import sha3 -from mythril.ethereum.evmcontract import EVMContract -from mythril.solidity.soliditycontract import SourceMapping + +from mythril.analysis.report import Report from mythril.analysis.security import fire_lasers from mythril.analysis.symbolic import SymExecWrapper -from mythril.analysis.report import Report - from mythril.ethereum import util +from mythril.ethereum.evmcontract import EVMContract from mythril.laser.ethereum.util import get_instruction_index +from mythril.solidity.soliditycontract import SourceMapping log = logging.getLogger(__name__) diff --git a/solidity_examples/suicide.sol b/solidity_examples/suicide.sol index 9e25678c..028ac775 100644 --- a/solidity_examples/suicide.sol +++ b/solidity_examples/suicide.sol @@ -1,10 +1,12 @@ -pragma solidity 0.5.0; +pragma solidity 0.5.1; contract Suicide { function kill(address payable addr) public { - selfdestruct(addr); + if (addr == address(0x0)) { + selfdestruct(addr); + } } -} \ No newline at end of file +}