Apply black

pull/845/head
Dominik Muhs 6 years ago
parent 49ca94c2da
commit a8f61a0f83
  1. 1
      mythril/analysis/modules/base.py
  2. 1
      mythril/analysis/modules/delegatecall.py
  3. 1
      mythril/analysis/modules/dependence_on_predictable_vars.py
  4. 1
      mythril/analysis/modules/deprecated_ops.py
  5. 1
      mythril/analysis/modules/ether_thief.py
  6. 1
      mythril/analysis/modules/exceptions.py
  7. 1
      mythril/analysis/modules/external_calls.py
  8. 1
      mythril/analysis/modules/integer.py
  9. 1
      mythril/analysis/modules/multiple_sends.py
  10. 1
      mythril/analysis/modules/suicide.py
  11. 1
      mythril/analysis/modules/transaction_order_dependence.py
  12. 1
      mythril/analysis/modules/unchecked_retval.py
  13. 5
      mythril/analysis/ops.py
  14. 2
      mythril/analysis/report.py
  15. 1
      mythril/ethereum/evmcontract.py
  16. 6
      mythril/ethereum/interface/rpc/exceptions.py
  17. 7
      mythril/exceptions.py
  18. 1
      mythril/interfaces/epic.py
  19. 3
      mythril/laser/ethereum/cfg.py
  20. 6
      mythril/laser/ethereum/evm_exceptions.py
  21. 1
      mythril/laser/ethereum/keccak.py
  22. 1
      mythril/laser/ethereum/natives.py
  23. 1
      mythril/laser/ethereum/state/annotation.py
  24. 3
      mythril/laser/ethereum/state/calldata.py
  25. 1
      mythril/laser/ethereum/state/memory.py
  26. 1
      mythril/laser/ethereum/strategy/__init__.py
  27. 3
      mythril/laser/ethereum/svm.py
  28. 2
      mythril/laser/smt/array.py
  29. 1
      mythril/mythril.py
  30. 4
      mythril/solidity/soliditycontract.py
  31. 1
      mythril/support/loader.py
  32. 3
      mythril/support/signatures.py

@ -11,6 +11,7 @@ class DetectionModule:
All custom-built detection modules must inherit from this class. All custom-built detection modules must inherit from this class.
""" """
def __init__( def __init__(
self, self,
name: str, name: str,

@ -16,6 +16,7 @@ log = logging.getLogger(__name__)
class DelegateCallModule(DetectionModule): class DelegateCallModule(DetectionModule):
"""This module detects calldata being forwarded using DELEGATECALL.""" """This module detects calldata being forwarded using DELEGATECALL."""
def __init__(self): def __init__(self):
""" """

@ -15,6 +15,7 @@ log = logging.getLogger(__name__)
class PredictableDependenceModule(DetectionModule): class PredictableDependenceModule(DetectionModule):
"""This module detects whether Ether is sent using predictable parameters.""" """This module detects whether Ether is sent using predictable parameters."""
def __init__(self): def __init__(self):
""" """

@ -58,6 +58,7 @@ def _analyze_state(state):
class DeprecatedOperationsModule(DetectionModule): class DeprecatedOperationsModule(DetectionModule):
"""This module checks for the usage of deprecated op codes.""" """This module checks for the usage of deprecated op codes."""
def __init__(self): def __init__(self):
""" """

@ -84,6 +84,7 @@ def _analyze_state(state):
class EtherThief(DetectionModule): class EtherThief(DetectionModule):
"""This module search for cases where Ether can be withdrawn to a user-specified address.""" """This module search for cases where Ether can be withdrawn to a user-specified address."""
def __init__(self): def __init__(self):
""" """

@ -59,6 +59,7 @@ class ReachableExceptionsModule(DetectionModule):
""" """
""" """
def __init__(self): def __init__(self):
""" """

@ -97,6 +97,7 @@ def _analyze_state(state):
class ExternalCalls(DetectionModule): class ExternalCalls(DetectionModule):
"""This module searches for low level calls (e.g. call.value()) that forward all gas to the callee.""" """This module searches for low level calls (e.g. call.value()) that forward all gas to the callee."""
def __init__(self): def __init__(self):
""" """

@ -24,6 +24,7 @@ log = logging.getLogger(__name__)
class IntegerOverflowUnderflowModule(DetectionModule): class IntegerOverflowUnderflowModule(DetectionModule):
"""This module searches for integer over- and underflows.""" """This module searches for integer over- and underflows."""
def __init__(self): def __init__(self):
""" """

@ -7,6 +7,7 @@ from mythril.laser.ethereum.cfg import JumpType
class MultipleSendsModule(DetectionModule): class MultipleSendsModule(DetectionModule):
"""This module checks for multiple sends in a single transaction.""" """This module checks for multiple sends in a single transaction."""
def __init__(self): def __init__(self):
""" """

@ -60,6 +60,7 @@ def _analyze_state(state):
class SuicideModule(DetectionModule): class SuicideModule(DetectionModule):
"""This module checks if the contact can be 'accidentally' killed by anyone.""" """This module checks if the contact can be 'accidentally' killed by anyone."""
def __init__(self): def __init__(self):
super().__init__( super().__init__(
name="Unprotected Suicide", name="Unprotected Suicide",

@ -16,6 +16,7 @@ log = logging.getLogger(__name__)
class TxOrderDependenceModule(DetectionModule): class TxOrderDependenceModule(DetectionModule):
"""This module finds the existence of transaction order dependence.""" """This module finds the existence of transaction order dependence."""
def __init__(self): def __init__(self):
super().__init__( super().__init__(
name="Transaction Order Dependence", name="Transaction Order Dependence",

@ -12,6 +12,7 @@ log = logging.getLogger(__name__)
class UncheckedRetvalModule(DetectionModule): class UncheckedRetvalModule(DetectionModule):
"""A detection module to test whether CALL return value is checked.""" """A detection module to test whether CALL return value is checked."""
def __init__(self): def __init__(self):
super().__init__( super().__init__(
name="Unchecked Return Value", name="Unchecked Return Value",

@ -6,12 +6,14 @@ from mythril.laser.ethereum import util
class VarType(Enum): class VarType(Enum):
"""An enum denoting whether a value is symbolic or concrete.""" """An enum denoting whether a value is symbolic or concrete."""
SYMBOLIC = 1 SYMBOLIC = 1
CONCRETE = 2 CONCRETE = 2
class Variable: class Variable:
"""The representation of a variable with value and type.""" """The representation of a variable with value and type."""
def __init__(self, val, _type): def __init__(self, val, _type):
""" """
@ -43,6 +45,7 @@ def get_variable(i):
class Op: class Op:
"""The base type for operations referencing current node and state.""" """The base type for operations referencing current node and state."""
def __init__(self, node, state, state_index): def __init__(self, node, state, state_index):
""" """
@ -57,6 +60,7 @@ class Op:
class Call(Op): class Call(Op):
"""The representation of a CALL operation.""" """The representation of a CALL operation."""
def __init__( def __init__(
self, self,
node, node,
@ -89,6 +93,7 @@ class Call(Op):
class SStore(Op): class SStore(Op):
"""The respresentation of an SSTORE operation.""" """The respresentation of an SSTORE operation."""
def __init__(self, node, state, state_index, value): def __init__(self, node, state, state_index, value):
super().__init__(node, state, state_index) super().__init__(node, state, state_index)
self.value = value self.value = value

@ -11,6 +11,7 @@ log = logging.getLogger(__name__)
class Issue: class Issue:
"""Representation of an issue and its location.""" """Representation of an issue and its location."""
def __init__( def __init__(
self, self,
contract, contract,
@ -104,6 +105,7 @@ class Issue:
class Report: class Report:
"""A report containing the content of multiple issues.""" """A report containing the content of multiple issues."""
environment = Environment( environment = Environment(
loader=PackageLoader("mythril.analysis"), trim_blocks=True loader=PackageLoader("mythril.analysis"), trim_blocks=True
) )

@ -7,6 +7,7 @@ import re
class EVMContract(persistent.Persistent): class EVMContract(persistent.Persistent):
"""This class represents an address with associated code (Smart Contract).""" """This class represents an address with associated code (Smart Contract)."""
def __init__( def __init__(
self, code="", creation_code="", name="Unknown", enable_online_lookup=False self, code="", creation_code="", name="Unknown", enable_online_lookup=False
): ):

@ -1,25 +1,31 @@
"""This module contains exceptions regarding JSON-RPC communication.""" """This module contains exceptions regarding JSON-RPC communication."""
class EthJsonRpcError(Exception): class EthJsonRpcError(Exception):
"""The JSON-RPC base exception type.""" """The JSON-RPC base exception type."""
pass pass
class ConnectionError(EthJsonRpcError): class ConnectionError(EthJsonRpcError):
"""An RPC exception denoting there was an error in connecting to the RPC instance.""" """An RPC exception denoting there was an error in connecting to the RPC instance."""
pass pass
class BadStatusCodeError(EthJsonRpcError): class BadStatusCodeError(EthJsonRpcError):
"""An RPC exception denoting a bad status code returned by the RPC instance.""" """An RPC exception denoting a bad status code returned by the RPC instance."""
pass pass
class BadJsonError(EthJsonRpcError): class BadJsonError(EthJsonRpcError):
"""An RPC exception denoting that the RPC instance returned a bad JSON object.""" """An RPC exception denoting that the RPC instance returned a bad JSON object."""
pass pass
class BadResponseError(EthJsonRpcError): class BadResponseError(EthJsonRpcError):
"""An RPC exception denoting that the RPC instance returned a bad response.""" """An RPC exception denoting that the RPC instance returned a bad response."""
pass pass

@ -1,30 +1,37 @@
"""This module contains general exceptions used by Mythril.""" """This module contains general exceptions used by Mythril."""
class MythrilBaseException(Exception): class MythrilBaseException(Exception):
"""The Mythril exception base type.""" """The Mythril exception base type."""
pass pass
class CompilerError(MythrilBaseException): class CompilerError(MythrilBaseException):
"""A Mythril exception denoting an error during code compilation.""" """A Mythril exception denoting an error during code compilation."""
pass pass
class UnsatError(MythrilBaseException): class UnsatError(MythrilBaseException):
"""A Mythril exception denoting the unsatisfiability of a series of constraints.""" """A Mythril exception denoting the unsatisfiability of a series of constraints."""
pass pass
class NoContractFoundError(MythrilBaseException): class NoContractFoundError(MythrilBaseException):
"""A Mythril exception denoting that a given contract file was not found.""" """A Mythril exception denoting that a given contract file was not found."""
pass pass
class CriticalError(MythrilBaseException): class CriticalError(MythrilBaseException):
"""A Mythril exception denoting an unknown critical error has been encountered.""" """A Mythril exception denoting an unknown critical error has been encountered."""
pass pass
class AddressNotFoundError(MythrilBaseException): class AddressNotFoundError(MythrilBaseException):
"""A Mythril exception denoting the given smart contract address was not found.""" """A Mythril exception denoting the given smart contract address was not found."""
pass pass

@ -54,6 +54,7 @@ COLOR_ANSI = (
class LolCat(object): class LolCat(object):
"""Cats lel""" """Cats lel"""
def __init__(self, mode=256, output=sys.stdout): def __init__(self, mode=256, output=sys.stdout):
self.mode = mode self.mode = mode
self.output = output self.output = output

@ -8,6 +8,7 @@ gbl_next_uid = 0 # node counter
class JumpType(Enum): class JumpType(Enum):
"""An enum to represent the types of possible JUMP scenarios.""" """An enum to represent the types of possible JUMP scenarios."""
CONDITIONAL = 1 CONDITIONAL = 1
UNCONDITIONAL = 2 UNCONDITIONAL = 2
CALL = 3 CALL = 3
@ -17,6 +18,7 @@ class JumpType(Enum):
class NodeFlags(Flags): class NodeFlags(Flags):
"""A collection of flags to denote the type a call graph node can have.""" """A collection of flags to denote the type a call graph node can have."""
FUNC_ENTRY = 1 FUNC_ENTRY = 1
CALL_RETURN = 2 CALL_RETURN = 2
@ -70,6 +72,7 @@ class Node:
class Edge: class Edge:
"""The respresentation of a call graph edge.""" """The respresentation of a call graph edge."""
def __init__( def __init__(
self, self,
node_from: int, node_from: int,

@ -3,29 +3,35 @@
class VmException(Exception): class VmException(Exception):
"""The base VM exception type.""" """The base VM exception type."""
pass pass
class StackUnderflowException(IndexError, VmException): class StackUnderflowException(IndexError, VmException):
"""A VM exception regarding stack underflows.""" """A VM exception regarding stack underflows."""
pass pass
class StackOverflowException(VmException): class StackOverflowException(VmException):
"""A VM exception regarding stack overflows.""" """A VM exception regarding stack overflows."""
pass pass
class InvalidJumpDestination(VmException): class InvalidJumpDestination(VmException):
"""A VM exception regarding JUMPs to invalid destinations.""" """A VM exception regarding JUMPs to invalid destinations."""
pass pass
class InvalidInstruction(VmException): class InvalidInstruction(VmException):
"""A VM exception denoting an invalid op code has been encountered.""" """A VM exception denoting an invalid op code has been encountered."""
pass pass
class OutOfGasException(VmException): class OutOfGasException(VmException):
"""A VM exception denoting the current execution has run out of gas.""" """A VM exception denoting the current execution has run out of gas."""
pass pass

@ -4,6 +4,7 @@ from mythril.laser.smt import Expression
class KeccakFunctionManager: class KeccakFunctionManager:
"""A keccak function manager for symbolic expressions.""" """A keccak function manager for symbolic expressions."""
def __init__(self): def __init__(self):
""" """

@ -17,6 +17,7 @@ log = logging.getLogger(__name__)
class NativeContractException(Exception): class NativeContractException(Exception):
"""An exception denoting an error during a native call.""" """An exception denoting an error during a native call."""
pass pass

@ -4,6 +4,7 @@ This includes the base StateAnnotation class, as well as an adaption, which will
copied on every new state. copied on every new state.
""" """
class StateAnnotation: class StateAnnotation:
""" """
The StateAnnotation class is used to persist information over traces. This allows modules to reason about traces The StateAnnotation class is used to persist information over traces. This allows modules to reason about traces

@ -110,6 +110,7 @@ class BaseCalldata:
class ConcreteCalldata(BaseCalldata): class ConcreteCalldata(BaseCalldata):
"""A concrete call data representation.""" """A concrete call data representation."""
def __init__(self, tx_id: int, calldata: list): def __init__(self, tx_id: int, calldata: list):
""" """
Initializes the ConcreteCalldata object. Initializes the ConcreteCalldata object.
@ -203,6 +204,7 @@ class BasicConcreteCalldata(BaseCalldata):
class SymbolicCalldata(BaseCalldata): class SymbolicCalldata(BaseCalldata):
"""A class for representing symbolic call data.""" """A class for representing symbolic call data."""
def __init__(self, tx_id: int): def __init__(self, tx_id: int):
"""Initializes the SymbolicCalldata object. """Initializes the SymbolicCalldata object.
@ -253,6 +255,7 @@ class SymbolicCalldata(BaseCalldata):
class BasicSymbolicCalldata(BaseCalldata): class BasicSymbolicCalldata(BaseCalldata):
"""A basic class representing symbolic call data.""" """A basic class representing symbolic call data."""
def __init__(self, tx_id: int): def __init__(self, tx_id: int):
""" """
Initializes the SymbolicCalldata object Initializes the SymbolicCalldata object

@ -15,6 +15,7 @@ from mythril.laser.ethereum import util
class Memory: class Memory:
"""A class representing contract memory with random access.""" """A class representing contract memory with random access."""
def __init__(self): def __init__(self):
""" """

@ -5,6 +5,7 @@ class BasicSearchStrategy(ABC):
""" """
""" """
__slots__ = "work_list", "max_depth" __slots__ = "work_list", "max_depth"
def __init__(self, work_list, max_depth): def __init__(self, work_list, max_depth):

@ -29,6 +29,7 @@ log = logging.getLogger(__name__)
class SVMError(Exception): class SVMError(Exception):
"""An exception denoting an unexpected state in symbolic execution.""" """An exception denoting an unexpected state in symbolic execution."""
pass pass
@ -492,6 +493,7 @@ class LaserEVM:
:param op_code: :param op_code:
:return: :return:
""" """
def hook_decorator(func: Callable): def hook_decorator(func: Callable):
""" """
@ -511,6 +513,7 @@ class LaserEVM:
:param op_code: :param op_code:
:return: :return:
""" """
def hook_decorator(func: Callable): def hook_decorator(func: Callable):
""" """

@ -26,6 +26,7 @@ class BaseArray:
class Array(BaseArray): class Array(BaseArray):
"""A basic symbolic array.""" """A basic symbolic array."""
def __init__(self, name: str, domain: int, value_range: int): def __init__(self, name: str, domain: int, value_range: int):
""" """
Initializes a symbolic array Initializes a symbolic array
@ -40,6 +41,7 @@ class Array(BaseArray):
class K(BaseArray): class K(BaseArray):
"""A basic symbolic array, which can be initialized with a default value.""" """A basic symbolic array, which can be initialized with a default value."""
def __init__(self, domain: int, value_range: int, value: int): def __init__(self, domain: int, value_range: int, value: int):
""" """
Initializes an array with a default value Initializes an array with a default value

@ -322,6 +322,7 @@ class Mythril(object):
:param search: :param search:
""" """
def search_callback(_, address, balance): def search_callback(_, address, balance):
""" """

@ -7,6 +7,7 @@ from mythril.exceptions import NoContractFoundError
class SourceMapping: class SourceMapping:
"""Representation of a source mapping for a Solidity file.""" """Representation of a source mapping for a Solidity file."""
def __init__(self, solidity_file_idx, offset, length, lineno): def __init__(self, solidity_file_idx, offset, length, lineno):
self.solidity_file_idx = solidity_file_idx self.solidity_file_idx = solidity_file_idx
self.offset = offset self.offset = offset
@ -16,6 +17,7 @@ class SourceMapping:
class SolidityFile: class SolidityFile:
"""Representation of a file containing Solidity code.""" """Representation of a file containing Solidity code."""
def __init__(self, filename, data): def __init__(self, filename, data):
self.filename = filename self.filename = filename
self.data = data self.data = data
@ -23,6 +25,7 @@ class SolidityFile:
class SourceCodeInfo: class SourceCodeInfo:
"""Metadata class containing a code reference for a specific file.""" """Metadata class containing a code reference for a specific file."""
def __init__(self, filename, lineno, code): def __init__(self, filename, lineno, code):
self.filename = filename self.filename = filename
self.lineno = lineno self.lineno = lineno
@ -54,6 +57,7 @@ def get_contracts_from_file(input_file, solc_args=None, solc_binary="solc"):
class SolidityContract(EVMContract): class SolidityContract(EVMContract):
"""Representation of a Solidity contract.""" """Representation of a Solidity contract."""
def __init__(self, input_file, name=None, solc_args=None, solc_binary="solc"): def __init__(self, input_file, name=None, solc_args=None, solc_binary="solc"):
data = get_solc_json(input_file, solc_args=solc_args, solc_binary=solc_binary) data = get_solc_json(input_file, solc_args=solc_args, solc_binary=solc_binary)

@ -8,6 +8,7 @@ log = logging.getLogger(__name__)
class DynLoader: class DynLoader:
"""The dynamic loader class.""" """The dynamic loader class."""
def __init__(self, eth, contract_loading=True, storage_loading=True): def __init__(self, eth, contract_loading=True, storage_loading=True):
""" """

@ -26,6 +26,7 @@ def synchronized(sync_lock):
:param f: :param f:
:return: :return:
""" """
@functools.wraps(f) @functools.wraps(f)
def inner_wrapper(*args, **kw): def inner_wrapper(*args, **kw):
""" """
@ -44,6 +45,7 @@ def synchronized(sync_lock):
class Singleton(type): class Singleton(type):
"""A metaclass type implementing the singleton pattern.""" """A metaclass type implementing the singleton pattern."""
_instances = {} _instances = {}
@synchronized(lock) @synchronized(lock)
@ -113,6 +115,7 @@ class SignatureDB(object, metaclass=Singleton):
""" """
""" """
def __init__(self, enable_online_lookup: bool = False, path: str = None) -> None: def __init__(self, enable_online_lookup: bool = False, path: str = None) -> None:
""" """
:param enable_online_lookup: :param enable_online_lookup:

Loading…
Cancel
Save