Merge pull request #50 from step21/solv

Solc versioning
pull/53/head
Bernhard Mueller 7 years ago committed by GitHub
commit dc70715b0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 42
      myth
  2. 7
      mythril/ether/util.py
  3. 1
      requirements.txt
  4. 3
      setup.py

42
myth

@ -22,6 +22,8 @@ from web3 import Web3
from ethereum import utils from ethereum import utils
from pathlib import Path from pathlib import Path
from json.decoder import JSONDecodeError from json.decoder import JSONDecodeError
from solc.exceptions import SolcError
import solc
import logging import logging
import json import json
import sys import sys
@ -64,6 +66,7 @@ utilities.add_argument('-d', '--disassemble', action='store_true', help='print
utilities.add_argument('--xrefs', action='store_true', help='get xrefs from a contract') utilities.add_argument('--xrefs', action='store_true', help='get xrefs from a contract')
utilities.add_argument('--hash', help='calculate function signature hash', metavar='SIGNATURE') utilities.add_argument('--hash', help='calculate function signature hash', metavar='SIGNATURE')
utilities.add_argument('--storage', help='read state variables from storage index, use with -a', metavar='INDEX,NUM_SLOTS,[array]') utilities.add_argument('--storage', help='read state variables from storage index, use with -a', metavar='INDEX,NUM_SLOTS,[array]')
utilities.add_argument('--solv', help='specify solidity compiler version. If not present, will try to install it (Experimental)', metavar='SOLV')
options = parser.add_argument_group('options') options = parser.add_argument_group('options')
options.add_argument('--sync-all', action='store_true', help='Also sync contracts with zero balance') options.add_argument('--sync-all', action='store_true', help='Also sync contracts with zero balance')
@ -87,12 +90,6 @@ try:
except KeyError: except KeyError:
mythril_dir = os.path.join(os.path.expanduser('~'), ".mythril") mythril_dir = os.path.join(os.path.expanduser('~'), ".mythril")
try:
solc_binary = os.environ['SOLC']
except KeyError:
solc_binary = 'solc'
# Initialize data directry and singature database # Initialize data directry and singature database
if not os.path.exists(mythril_dir): if not os.path.exists(mythril_dir):
@ -148,6 +145,39 @@ if args.truffle:
sys.exit() sys.exit()
# Figure out solc binary and version
# Only proper versions are supported. No nightlies, commits etc (such as available in remix)
if args.solv:
version = args.solv
#tried converting input to semver, seemed not necessary so just slicing for now
if version == str(solc.main.get_solc_version())[:6]:
print('Given version matches installed version')
try:
solc_binary = os.environ['SOLC']
except KeyError:
solc_binary = 'solc'
else:
if util.solc_exists(version):
print('Given version is already installed')
solc_binary = os.path.join(os.environ['HOME'], ".py-solc/solc-v" + version, "bin/solc")
print("Setting the compiler to " + str(solc_binary))
else:
try:
solc.install_solc('v' + version)
solc_binary = os.path.join(os.environ['HOME'], ".py-solc/solc-v" + version, "bin/solc")
print("Setting the compiler to " + str(solc_binary))
except SolcError:
exitWithError("There was an error when trying to install the specified solc version")
else:
if not args.solv:
try:
solc_binary = os.environ['SOLC']
except KeyError:
try:
solc_binary = 'solc'
except:
exitWithError('No solidity compiler found, please make sure it is installed or specify it manually.')
# Establish RPC/IPC connection if necessary # Establish RPC/IPC connection if necessary

@ -64,3 +64,10 @@ def get_random_address():
def get_indexed_address(index): def get_indexed_address(index):
return "0x" + (hex(index)[2:] * 40) 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

@ -5,3 +5,4 @@ web3
laser-ethereum==0.4.2 laser-ethereum==0.4.2
requests requests
BTrees BTrees
py-solc

@ -293,7 +293,8 @@ setup(
'z3-solver>=4.5', 'z3-solver>=4.5',
'laser-ethereum==0.4.2', 'laser-ethereum==0.4.2',
'requests', 'requests',
'BTrees' 'BTrees',
'py-solc'
], ],
python_requires='>=3.5', python_requires='>=3.5',

Loading…
Cancel
Save