Remove 'address' field from contract objects

pull/62/merge
Bernhard Mueller 7 years ago
parent 993164e6df
commit eba8f05492
  1. 12
      myth
  2. 15
      mythril/analysis/symbolic.py
  3. 10
      mythril/ether/ethcontract.py
  4. 4
      mythril/ether/soliditycontract.py
  5. 3
      mythril/ether/util.py

12
myth

@ -4,7 +4,7 @@
http://www.github.com/b-mueller/mythril
"""
from mythril.ether import evm, util
from mythril.ether import util
from mythril.ether.contractstorage import get_persistent_storage
from mythril.ether.ethcontract import ETHContract
from mythril.ether.soliditycontract import SolidityContract
@ -246,7 +246,7 @@ if args.search or args.init_db:
contracts = []
if (args.code):
contracts.append(ETHContract(args.code, name="MAIN", address=util.get_indexed_address(0)))
contracts.append(ETHContract(args.code, name="MAIN"))
# Get bytecode from a contract address
@ -266,7 +266,7 @@ elif (args.address):
except ConnectionError as e:
exitWithError(args.outform, "Could not connect to RPC server. Make sure that your node is running and that RPC parameters are set correctly.")
contracts.append(ETHContract(code, name=args.address, address=args.address))
contracts.append(ETHContract(code, name=args.address))
# Compile Solidity source file(s)
@ -275,8 +275,6 @@ elif (len(args.solidity_file)):
if(args.graph and len(args.solidity_file) > 1):
exitWithError(args.outform, "Cannot generate call graphs from multiple input files. Please do it one at a time.")
idx = 0
for file in args.solidity_file:
if ":" in file:
@ -288,10 +286,8 @@ elif (len(args.solidity_file)):
try:
signatures.add_signatures_from_file(file, sigs) # Parse file for new function signatures
print(util.get_indexed_address(idx))
contract = SolidityContract(file, contract_name, util.get_indexed_address(idx))
idx += 1
contract = SolidityContract(file, contract_name)
logging.info("Analyzing contract %s:%s" % (file, contract.name))

@ -1,9 +1,7 @@
from mythril.analysis import solver
from mythril.exceptions import UnsatError
from mythril import ether
from laser.ethereum import svm
import copy
from .ops import *
import logging
class StateSpace:
@ -16,13 +14,18 @@ class StateSpace:
self.accounts = {}
idx = 0
for contract in contracts:
self.accounts[contract.address] = svm.Account(contract.address, contract.get_disassembly(), contract.name)
address = ether.util.get_indexed_address(idx)
self.accounts[address] = svm.Account(address, contract.get_disassembly(), contract.name)
idx += 1
self.laser = svm.LaserEVM(self.accounts, dynamic_loader=dynloader, max_depth=max_depth)
self.laser.sym_exec(contracts[0].address)
self.laser.sym_exec(ether.util.get_indexed_address(0))
# self.modules = modules
self.nodes = self.laser.nodes
self.edges = self.laser.edges
@ -72,8 +75,6 @@ class StateSpace:
self.sstors[str(index)] = [SStore(self.nodes[key], instruction['address'], value)]
'''
def find_storage_write(self, index):
# Find a an unconstrained SSTOR that writes to storage index "index"

@ -6,11 +6,10 @@ import re
class ETHContract(persistent.Persistent):
def __init__(self, code, creation_code="", name="", address=""):
def __init__(self, code, creation_code="", name=""):
self.creation_code = creation_code
self.name = name
self.address = address
# Workaround: We currently do not support compile-time linking.
# Dynamic contract addresses of the format __[contract-name]_____________ are replaced with a generic address
@ -19,7 +18,6 @@ class ETHContract(persistent.Persistent):
self.code = code
def as_dict(self):
return {
@ -30,7 +28,6 @@ class ETHContract(persistent.Persistent):
'disassembly': self.get_disassembly()
}
def get_xrefs(self):
instruction_list = Disassembly(self.code).instruction_list
@ -48,17 +45,14 @@ class ETHContract(persistent.Persistent):
return xrefs
def get_disassembly(self):
return Disassembly(self.code)
def get_easm(self):
return Disassembly(self.code).get_easm()
def matches_expression(self, expression):
easm_code = self.get_easm()
@ -105,7 +99,7 @@ class InstanceList(persistent.Persistent):
self.balances = []
pass
def add(self, address, balance = 0):
def add(self, address, balance=0):
self.addresses.append(address)
self.balances.append(balance)
self._p_changed = True

@ -20,7 +20,7 @@ class SolidityFile:
class SolidityContract(ETHContract):
def __init__(self, input_file, contract_name=None, address=""):
def __init__(self, input_file, contract_name=None):
data = get_solc_json(input_file)
@ -81,4 +81,4 @@ class SolidityContract(ETHContract):
self.mappings.append(SourceMapping(idx, offset, length, lineno))
super().__init__(self.code, self.creation_code, name, address)
super().__init__(self.code, self.creation_code, name)

@ -5,7 +5,6 @@ from mythril.exceptions import CompilerError
from subprocess import Popen, PIPE
import binascii
import os
import re
import json
@ -51,10 +50,10 @@ def get_random_address():
def get_indexed_address(index):
return "0x" + (hex(index)[2:] * 40)
def solc_exists(version):
solc_binary = os.path.join(os.environ['HOME'], ".py-solc/solc-v" + version, "bin/solc")
if os.path.exists(solc_binary):
return True
else:
return False
Loading…
Cancel
Save