Refactor code (#1577)

* clean up code

* Update lolcat
pull/1581/head
Nikhil Parasaram 3 years ago committed by GitHub
parent c72ac81de1
commit 965513f239
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      mythril/analysis/call_helpers.py
  2. 2
      mythril/analysis/module/modules/dependence_on_origin.py
  3. 2
      mythril/analysis/module/modules/dependence_on_predictable_vars.py
  4. 2
      mythril/analysis/report.py
  5. 1
      mythril/analysis/solver.py
  6. 4
      mythril/analysis/symbolic.py
  7. 1
      mythril/ethereum/util.py
  8. 7
      mythril/exceptions.py
  9. 1
      mythril/interfaces/cli.py
  10. 42
      mythril/interfaces/epic.py
  11. 4
      mythril/laser/ethereum/call.py
  12. 2
      mythril/laser/ethereum/function_managers/exponent_function_manager.py
  13. 2
      mythril/laser/ethereum/function_managers/keccak_function_manager.py
  14. 2
      mythril/laser/ethereum/instruction_data.py
  15. 24
      mythril/laser/ethereum/instructions.py
  16. 1
      mythril/laser/ethereum/state/calldata.py
  17. 1
      mythril/laser/ethereum/state/world_state.py
  18. 4
      mythril/laser/ethereum/svm.py
  19. 1
      mythril/laser/ethereum/transaction/transaction_models.py
  20. 1
      mythril/laser/plugin/builder.py
  21. 2
      mythril/laser/plugin/plugins/benchmark.py
  22. 2
      mythril/laser/smt/bool.py
  23. 1
      mythril/mythril/mythril_analyzer.py
  24. 1
      mythril/mythril/mythril_config.py
  25. 3
      mythril/mythril/mythril_disassembler.py
  26. 2
      mythril/plugin/interface.py
  27. 3
      mythril/plugin/loader.py
  28. 2
      mythril/support/opcodes.py
  29. 3
      mythril/support/signatures.py

@ -19,7 +19,7 @@ def get_call_from_state(state: GlobalState) -> Union[Call, None]:
stack = state.mstate.stack
if op in ("CALL", "CALLCODE"):
gas, to, value, meminstart, meminsz, memoutstart, memoutsz = (
gas, to, value, meminstart, meminsz, _, _ = (
get_variable(stack[-1]),
get_variable(stack[-2]),
get_variable(stack[-3]),
@ -47,7 +47,7 @@ def get_call_from_state(state: GlobalState) -> Union[Call, None]:
return Call(state.node, state, None, op, to, gas, value)
else:
gas, to, meminstart, meminsz, memoutstart, memoutsz = (
gas, to, meminstart, meminsz, _, _ = (
get_variable(stack[-1]),
get_variable(stack[-2]),
get_variable(stack[-3]),

@ -46,7 +46,7 @@ class TxOrigin(DetectionModule):
self.issues.extend(issues)
@staticmethod
def _analyze_state(state: GlobalState) -> list:
def _analyze_state(state: GlobalState) -> List[Issue]:
"""
:param state:

@ -60,7 +60,7 @@ class PredictableVariables(DetectionModule):
self.issues.extend(issues)
@staticmethod
def _analyze_state(state: GlobalState) -> list:
def _analyze_state(state: GlobalState) -> List[Issue]:
"""
:param state:

@ -273,7 +273,7 @@ class Report:
# Setup issues
_issues = []
for key, issue in self.issues.items():
for _, issue in self.issues.items():
idx = self.source.get_source_index(issue.bytecode_hash)
try:

@ -7,7 +7,6 @@ from z3 import FuncInterp
from mythril.exceptions import UnsatError
from mythril.laser.ethereum.function_managers import (
exponent_function_manager,
keccak_function_manager,
)

@ -238,7 +238,7 @@ class SymExecWrapper:
stack = state.mstate.stack
if op in ("CALL", "CALLCODE"):
gas, to, value, meminstart, meminsz, memoutstart, memoutsz = (
gas, to, value, meminstart, meminsz, _, _ = (
get_variable(stack[-1]),
get_variable(stack[-2]),
get_variable(stack[-3]),
@ -286,7 +286,7 @@ class SymExecWrapper:
)
)
else:
gas, to, meminstart, meminsz, memoutstart, memoutsz = (
gas, to, meminstart, meminsz, _, _ = (
get_variable(stack[-1]),
get_variable(stack[-2]),
get_variable(stack[-3]),

@ -17,7 +17,6 @@ from semantic_version import Version
if sys.version_info[1] >= 6:
import solcx
from solcx.exceptions import SolcNotInstalled
log = logging.getLogger(__name__)

@ -34,13 +34,6 @@ class CriticalError(MythrilBaseException):
pass
class AddressNotFoundError(MythrilBaseException):
"""A Mythril exception denoting the given smart contract address was not
found."""
pass
class DetectorNotFoundError(MythrilBaseException):
"""A Mythril exception denoting attempted usage of a non-existant
detection module."""

@ -17,7 +17,6 @@ import traceback
import mythril.support.signatures as sigs
from argparse import ArgumentParser, Namespace, RawTextHelpFormatter
from mythril.exceptions import (
AddressNotFoundError,
DetectorNotFoundError,
CriticalError,
)

@ -16,6 +16,7 @@ import random
import re
import sys
import time
import argparse
PY3 = sys.version_info >= (3,)
@ -165,7 +166,7 @@ class LolCat(object):
if not s:
return
for i in range(1, options.duration):
for _ in range(1, options.duration):
self.output.write("\x1b[%dD" % (len(s),))
self.output.flush()
options.os += options.spread
@ -208,30 +209,29 @@ def detect_mode(term_hint="xterm-256color"):
def run():
"""Main entry point."""
import optparse
parser = optparse.OptionParser(usage=r"%prog [<options>] [file ...]")
parser.add_option(
"-p", "--spread", type="float", default=3.0, help="Rainbow spread"
parser = argparse.ArgumentParser(usage=r"%prog [<options>] [file ...]")
parser.add_argument(
"-p", "--spread", type=float, default=3.0, help="Rainbow spread"
)
parser.add_option(
"-F", "--freq", type="float", default=0.1, help="Rainbow frequency"
parser.add_argument(
"-F", "--freq", type=float, default=0.1, help="Rainbow frequency"
)
parser.add_option("-S", "--seed", type="int", default=0, help="Rainbow seed")
parser.add_option(
parser.add_argument("-S", "--seed", type=int, default=0, help="Rainbow seed")
parser.add_argument(
"-a",
"--animate",
action="store_true",
default=False,
help="Enable psychedelics",
)
parser.add_option(
"-d", "--duration", type="int", default=12, help="Animation duration"
parser.add_argument(
"-d", "--duration", type=int, default=12, help="Animation duration"
)
parser.add_option(
"-s", "--speed", type="float", default=20.0, help="Animation speed"
parser.add_argument(
"-s", "--speed", type=float, default=20.0, help="Animation speed"
)
parser.add_option(
parser.add_argument(
"-f",
"--force",
action="store_true",
@ -239,17 +239,17 @@ def run():
help="Force colour even when stdout is not a tty",
)
parser.add_option(
parser.add_argument(
"-3", action="store_const", dest="mode", const=8, help="Force 3 bit colour mode"
)
parser.add_option(
parser.add_argument(
"-4",
action="store_const",
dest="mode",
const=16,
help="Force 4 bit colour mode",
)
parser.add_option(
parser.add_argument(
"-8",
action="store_const",
dest="mode",
@ -257,21 +257,19 @@ def run():
help="Force 8 bit colour mode",
)
parser.add_option(
parser.add_argument(
"-c",
"--charset-py2",
default="utf-8",
help="Manually set a charset to convert from, for python 2.7",
)
options, args = parser.parse_args()
options = parser.parse_args()
options.os = random.randint(0, 256) if options.seed == 0 else options.seed
options.mode = options.mode or detect_mode()
lolcat = LolCat(mode=options.mode)
if not args:
args = ["-"]
args = ["-"]
for filename in args:
if filename == "-":

@ -4,7 +4,7 @@ parameters for the new global state."""
import logging
import re
from typing import Union, List, cast, Callable, Optional
from typing import Union, List, cast, Optional
from eth.constants import GAS_CALLSTIPEND
import mythril.laser.ethereum.util as util
@ -18,7 +18,7 @@ from mythril.laser.ethereum.state.calldata import (
ConcreteCalldata,
)
from mythril.laser.ethereum.state.global_state import GlobalState
from mythril.laser.smt import BitVec, is_true, If
from mythril.laser.smt import BitVec, If
from mythril.laser.smt import simplify, Expression, symbol_factory
from mythril.support.loader import DynLoader

@ -1,5 +1,5 @@
import logging
from typing import Dict, List, Optional, Tuple
from typing import Tuple
from mythril.laser.smt import And, BitVec, Bool, Function, URem, symbol_factory

@ -99,7 +99,7 @@ class KeccakFunctionManager:
:return: Tuple of keccak and the condition it should satisfy
"""
length = data.size()
func, inverse = self.get_function(length)
func, _ = self.get_function(length)
if data.symbolic is False:
concrete_hash = self.find_concrete_keccak(data)

@ -1,5 +1,5 @@
from eth._utils.numeric import ceil32
from typing import Callable, Dict, Tuple, Union
from typing import Tuple
from mythril.support.opcodes import OPCODES, STACK, GAS
from eth.constants import (
GAS_ECRECOVER,

@ -8,7 +8,6 @@ from typing import cast, Callable, List, Union
from mythril.laser.smt import (
Extract,
Expression,
Function,
UDiv,
simplify,
Concat,
@ -16,7 +15,6 @@ from mythril.laser.smt import (
UGT,
BitVec,
is_false,
is_true,
URem,
SRem,
If,
@ -1705,9 +1703,9 @@ class Instruction:
"""
# TODO: implement me
state = global_state.mstate
dpth = int(self.op_code[3:])
depth = int(self.op_code[3:])
state.stack.pop(), state.stack.pop()
log_data = [state.stack.pop() for _ in range(dpth)]
_ = [state.stack.pop() for _ in range(depth)]
# Not supported
return [global_state]
@ -2117,10 +2115,10 @@ class Instruction:
memory_out_size, memory_out_offset = global_state.mstate.stack[-7:-5]
try:
(
callee_address,
_,
_,
value,
_,
_,
_,
memory_out_offset,
memory_out_size,
@ -2261,10 +2259,10 @@ class Instruction:
try:
(
callee_address,
_,
_,
value,
_,
_,
_,
memory_out_offset,
memory_out_size,
@ -2405,11 +2403,11 @@ class Instruction:
try:
with_value = function_name != "staticcall"
(
callee_address,
callee_account,
call_data,
value,
gas,
_,
_,
_,
_,
_,
memory_out_offset,
memory_out_size,
) = get_call_parameters(global_state, self.dynamic_loader, with_value)

@ -2,7 +2,6 @@
from typing import cast, Union, Tuple, List
from enum import Enum
from typing import Any, Union
from z3 import Model

@ -6,7 +6,6 @@ from eth._utils.address import generate_contract_address
from mythril.support.loader import DynLoader
from mythril.laser.smt import symbol_factory, Array, BitVec
from mythril.disassembler.disassembly import Disassembly
from mythril.laser.ethereum.state.account import Account
from mythril.laser.ethereum.state.annotation import StateAnnotation
from mythril.laser.ethereum.state.constraints import Constraints

@ -11,7 +11,7 @@ from mythril.laser.execution_info import ExecutionInfo
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.instructions import Instruction, transfer_ether
from mythril.laser.ethereum.instructions import Instruction
from mythril.laser.ethereum.instruction_data import get_required_stack_elements
from mythril.laser.plugin.signals import PluginSkipWorldState, PluginSkipState
from mythril.laser.ethereum.state.global_state import GlobalState
@ -287,7 +287,7 @@ class LaserEVM:
def handle_vm_exception(
self, global_state: GlobalState, op_code: str, error_msg: str
) -> List[GlobalState]:
transaction, return_global_state = global_state.transaction_stack.pop()
_, return_global_state = global_state.transaction_stack.pop()
if return_global_state is None:
# In this case we don't put an unmodified world state in the open_states list Since in the case of an

@ -1,7 +1,6 @@
"""This module contians the transaction models used throughout LASER's symbolic
execution."""
import array
from copy import deepcopy
from z3 import ExprRef
from typing import Union, Optional

@ -1,7 +1,6 @@
from mythril.laser.plugin.interface import LaserPlugin
from abc import ABC, abstractmethod
from typing import Optional
class PluginBuilder(ABC):

@ -83,7 +83,7 @@ class BenchmarkPlugin(LaserPlugin):
def _write_to_graph(self):
"""Write the coverage results to a graph"""
traces = []
for byte_code, trace_data in self.coverage.items():
for _, trace_data in self.coverage.items():
traces += [list(trace_data.keys()), list(trace_data.values()), "r--"]
plt.plot(*traces)

@ -1,7 +1,7 @@
"""This module provides classes for an SMT abstraction of boolean
expressions."""
from typing import Union, cast, List, Set
from typing import Union, cast, Set
import z3

@ -5,7 +5,6 @@ import logging
import traceback
from typing import Optional, List
from mythril.laser.ethereum.iprof import InstructionProfiler
from . import MythrilDisassembler
from mythril.support.source_support import Source
from mythril.support.loader import DynLoader

@ -1,7 +1,6 @@
import codecs
import logging
import os
import platform
import re
from pathlib import Path

@ -3,7 +3,6 @@ import re
import solc
import sys
import os
import platform
from mythril.support.support_utils import sha3, zpad
from typing import List, Tuple, Optional
@ -17,8 +16,6 @@ from mythril.ethereum.interface.rpc.exceptions import ConnectionError
from mythril.solidity.soliditycontract import SolidityContract, get_contracts_from_file
from eth_utils import int_to_big_endian
if sys.version_info[1] >= 6:
import solcx
log = logging.getLogger(__name__)

@ -1,4 +1,4 @@
from abc import ABC, abstractmethod
from abc import ABC
from mythril.laser.plugin.builder import PluginBuilder as LaserPluginBuilder

@ -1,11 +1,10 @@
from mythril.analysis.module import DetectionModule
from mythril.plugin.interface import MythrilCLIPlugin, MythrilPlugin, MythrilLaserPlugin
from mythril.plugin.interface import MythrilPlugin, MythrilLaserPlugin
from mythril.plugin.discovery import PluginDiscovery
from mythril.support.support_utils import Singleton
from mythril.analysis.module.loader import ModuleLoader
from mythril.laser.plugin.builder import PluginBuilder as LaserPluginBuilder
from mythril.laser.plugin.loader import LaserPluginLoader
from typing import Dict
import logging

@ -1,4 +1,4 @@
from typing import Dict, Tuple, Union
from typing import Dict
Z_OPERATOR_TUPLE = (0, 1)

@ -1,17 +1,14 @@
"""The Mythril function signature database."""
import functools
import json
import logging
import multiprocessing
import os
import sqlite3
import time
from collections import defaultdict
from subprocess import PIPE, Popen
from typing import List, Set, DefaultDict, Dict
from mythril.ethereum.util import get_solc_json
from mythril.exceptions import CompilerError
log = logging.getLogger(__name__)

Loading…
Cancel
Save