2020-01-13 15:14:18 +00:00
|
|
|
#!/usr/bin/env python3
|
2017-03-22 19:19:57 +00:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import glob
|
|
|
|
import subprocess
|
|
|
|
import json
|
|
|
|
|
2020-01-15 13:21:33 +00:00
|
|
|
SOLC_BIN = sys.argv[1]
|
2020-02-14 16:03:48 +00:00
|
|
|
REPORT_FILE = open("report.txt", mode="w", encoding='utf8', newline='\n')
|
2017-03-22 19:19:57 +00:00
|
|
|
|
2020-05-27 09:12:40 +00:00
|
|
|
def removeSMT(source):
|
|
|
|
return source.replace('pragma experimental SMTChecker;', '')
|
|
|
|
|
2017-03-22 19:56:44 +00:00
|
|
|
for optimize in [False, True]:
|
|
|
|
for f in sorted(glob.glob("*.sol")):
|
2019-03-04 15:19:34 +00:00
|
|
|
sources = {}
|
2020-05-27 09:12:40 +00:00
|
|
|
sources[f] = {'content': removeSMT(open(f, mode='r', encoding='utf8').read())}
|
2020-01-15 13:21:33 +00:00
|
|
|
input_json = {
|
2019-03-04 15:19:34 +00:00
|
|
|
'language': 'Solidity',
|
|
|
|
'sources': sources,
|
|
|
|
'settings': {
|
|
|
|
'optimizer': {
|
|
|
|
'enabled': optimize
|
|
|
|
},
|
2020-01-15 13:21:33 +00:00
|
|
|
'outputSelection': {'*': {'*': ['evm.bytecode.object', 'metadata']}}
|
2019-03-04 15:19:34 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-15 13:21:33 +00:00
|
|
|
args = [SOLC_BIN, '--standard-json']
|
2017-03-22 19:56:44 +00:00
|
|
|
if optimize:
|
|
|
|
args += ['--optimize']
|
2019-03-04 15:19:34 +00:00
|
|
|
proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
2020-01-20 10:20:18 +00:00
|
|
|
(out, err) = proc.communicate(json.dumps(input_json).encode('utf-8'))
|
2017-03-22 19:56:44 +00:00
|
|
|
try:
|
2020-01-20 10:20:18 +00:00
|
|
|
result = json.loads(out.decode('utf-8').strip())
|
2019-03-04 15:19:34 +00:00
|
|
|
for filename in sorted(result['contracts'].keys()):
|
|
|
|
for contractName in sorted(result['contracts'][filename].keys()):
|
|
|
|
contractData = result['contracts'][filename][contractName]
|
|
|
|
if 'evm' in contractData and 'bytecode' in contractData['evm']:
|
2020-02-03 10:44:28 +00:00
|
|
|
REPORT_FILE.write(filename + ':' + contractName + ' ' +
|
|
|
|
contractData['evm']['bytecode']['object'] + '\n')
|
2019-03-04 15:19:34 +00:00
|
|
|
else:
|
2020-01-15 13:21:33 +00:00
|
|
|
REPORT_FILE.write(filename + ':' + contractName + ' NO BYTECODE\n')
|
|
|
|
REPORT_FILE.write(filename + ':' + contractName + ' ' + contractData['metadata'] + '\n')
|
2019-03-04 15:19:34 +00:00
|
|
|
except KeyError:
|
2020-01-15 13:21:33 +00:00
|
|
|
REPORT_FILE.write(f + ": ERROR\n")
|