Code formatting

pull/62/merge
Bernhard Mueller 7 years ago
parent bc158420c0
commit 975823fec9
  1. 32
      myth
  2. 5
      mythril/analysis/symbolic.py
  3. 4
      mythril/ether/soliditycontract.py

32
myth

@ -160,7 +160,7 @@ if args.truffle:
if args.solv: if args.solv:
version = args.solv version = args.solv
#tried converting input to semver, seemed not necessary so just slicing for now # tried converting input to semver, seemed not necessary so just slicing for now
if version == str(solc.main.get_solc_version())[:6]: if version == str(solc.main.get_solc_version())[:6]:
logging.info('Given version matches installed version') logging.info('Given version matches installed version')
try: try:
@ -267,14 +267,14 @@ elif (args.address):
except ConnectionError as e: 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.") 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, address=args.address))
# Compile Solidity source file(s) # Compile Solidity source file(s)
elif (len(args.solidity_file)): elif (len(args.solidity_file)):
if(args.graph and len(args.solidity_file) > 1): 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.") exitWithError(args.outform, "Cannot generate call graphs from multiple input files. Please do it one at a time.")
for file in args.solidity_file: for file in args.solidity_file:
@ -283,10 +283,10 @@ elif (len(args.solidity_file)):
else: else:
contract_name = None contract_name = None
file = file.replace("~", str(Path.home())) # Expand user path file = file.replace("~", str(Path.home())) # Expand user path
try: try:
signatures.add_signatures_from_file(file, sigs) # Parse file for new function signatures signatures.add_signatures_from_file(file, sigs) # Parse file for new function signatures
contract = SolidityContract(file, contract_name) contract = SolidityContract(file, contract_name)
logging.info("Analyzing contract %s:%s" % (file, contract.name)) logging.info("Analyzing contract %s:%s" % (file, contract.name))
@ -298,7 +298,7 @@ elif (len(args.solidity_file)):
logging.info("The file " + file + " does not contain a compilable contract.") logging.info("The file " + file + " does not contain a compilable contract.")
except FileNotFoundError: except FileNotFoundError:
exitWithError(args.outform, "Input file not found: " + file) exitWithError(args.outform, "Input file not found: " + file)
# Save updated function signatures # Save updated function signatures
with open(signatures_file, 'w') as f: with open(signatures_file, 'w') as f:
@ -324,7 +324,7 @@ if args.storage:
if len(params) >= 2 and len(params) <= 3: if len(params) >= 2 and len(params) <= 3:
length = int(params[1]) length = int(params[1])
if len(params) == 3: if len(params) == 3:
if re.match("array",params[2]): if re.match("array", params[2]):
array = 1 array = 1
if len(params) >= 4: if len(params) >= 4:
exitWithError(args.outform, "Invalid number of parameters.") exitWithError(args.outform, "Invalid number of parameters.")
@ -335,7 +335,6 @@ if args.storage:
position_formated = str(position).zfill(64) position_formated = str(position).zfill(64)
position = int(Web3.sha3(position_formated),16) position = int(Web3.sha3(position_formated),16)
try: try:
if length == 1: if length == 1:
print("{}: ".format(position) + eth.eth_getStorageAt(args.address, position)); print("{}: ".format(position) + eth.eth_getStorageAt(args.address, position));
@ -390,14 +389,13 @@ elif (args.graph) or (args.fire_lasers):
for contract in contracts: for contract in contracts:
# try: try:
if (args.dynld): if (args.dynld):
states = StateSpace([contract], dynloader=DynLoader(eth), max_depth=args.max_depth) states = StateSpace([contract], dynloader=DynLoader(eth), max_depth=args.max_depth)
else: else:
states = StateSpace([contract], max_depth=args.max_depth) states = StateSpace([contract], max_depth=args.max_depth)
# except Exception as e: except Exception as e:
# exitWithError(args.outform, "Symbolic exection error: " + str(e)) exitWithError(args.outform, "Symbolic exection error: " + str(e))
issues = fire_lasers(states) issues = fire_lasers(states)
@ -408,7 +406,7 @@ elif (args.graph) or (args.fire_lasers):
if (type(contract) == SolidityContract): if (type(contract) == SolidityContract):
disassembly = contract.get_disassembly() disassembly = contract.get_disassembly()
for issue in issues: for issue in issues:
if (issue.pc): if (issue.pc):

@ -11,8 +11,8 @@ class StateSpace:
''' '''
Symbolic EVM wrapper Symbolic EVM wrapper
''' '''
def __init__(self, contracts, dynloader = None, max_depth = 12): def __init__(self, contracts, dynloader=None, max_depth=12):
self.accounts = {} self.accounts = {}
@ -92,4 +92,3 @@ class StateSpace:
return None return None
except KeyError: except KeyError:
return None return None

@ -20,7 +20,7 @@ class SolidityFile:
class SolidityContract(ETHContract): class SolidityContract(ETHContract):
def __init__(self, input_file, contract_name = None): def __init__(self, input_file, contract_name=None):
data = get_solc_json(input_file) data = get_solc_json(input_file)
@ -73,7 +73,7 @@ class SolidityContract(ETHContract):
if len(mapping) > 1 and len(mapping[1]) > 0: if len(mapping) > 1 and len(mapping[1]) > 0:
length = int(mapping[1]) length = int(mapping[1])
if len(mapping) > 2 and len(mapping[2]) > 0: if len(mapping) > 2 and len(mapping[2]) > 0:
idx = int(mapping[2]) idx = int(mapping[2])

Loading…
Cancel
Save