From aa40583f1dad0b60dbc135abc64e5350530a7d6e Mon Sep 17 00:00:00 2001 From: Alexander Arlt Date: Sat, 19 Dec 2020 14:48:38 -0500 Subject: [PATCH] [ewasm] add ewasm bytecode compare support. --- .circleci/config.yml | 16 ++++-- scripts/bytecodecompare/prepare_report.py | 67 +++++++++++++---------- 2 files changed, 49 insertions(+), 34 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f0de464ab..739bbdc12 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -902,7 +902,9 @@ jobs: - checkout - attach_workspace: at: build - - run: scripts/bytecodecompare/storebytecode.sh && cp -v report.txt bytecode-report-ubuntu.txt + - run: + no_output_timeout: 60m + command: scripts/bytecodecompare/storebytecode.sh && cp -v report.txt bytecode-report-ubuntu.txt - store_artifacts: path: report.txt - persist_to_workspace: @@ -919,7 +921,9 @@ jobs: - checkout - attach_workspace: at: . - - run: scripts/bytecodecompare/storebytecode.sh && cp -v report.txt bytecode-report-osx.txt + - run: + no_output_timeout: 60m + command: scripts/bytecodecompare/storebytecode.sh && cp -v report.txt bytecode-report-osx.txt - store_artifacts: path: report.txt - persist_to_workspace: @@ -936,7 +940,9 @@ jobs: - attach_workspace: at: build - run: python scripts\isolate_tests.py test\ - - run: python scripts\bytecodecompare\prepare_report.py build\solc\Release\solc.exe + - run: + no_output_timeout: 60m + command: python scripts\bytecodecompare\prepare_report.py build\solc\Release\solc.exe - run: cp report.txt bytecode-report-windows.txt - store_artifacts: path: report.txt @@ -954,7 +960,9 @@ jobs: - checkout - attach_workspace: at: emscripten_build/libsolc - - run: scripts/bytecodecompare/storebytecode.sh && cp -v report.txt bytecode-report-emscripten.txt + - run: + no_output_timeout: 60m + command: scripts/bytecodecompare/storebytecode.sh && cp -v report.txt bytecode-report-emscripten.txt - store_artifacts: path: report.txt - persist_to_workspace: diff --git a/scripts/bytecodecompare/prepare_report.py b/scripts/bytecodecompare/prepare_report.py index 2697b940b..3e2890806 100755 --- a/scripts/bytecodecompare/prepare_report.py +++ b/scripts/bytecodecompare/prepare_report.py @@ -10,34 +10,41 @@ REPORT_FILE = open("report.txt", mode="w", encoding='utf8', newline='\n') for optimize in [False, True]: for f in sorted(glob.glob("*.sol")): - sources = {} - sources[f] = {'content': open(f, mode='r', encoding='utf8').read()} - input_json = { - 'language': 'Solidity', - 'sources': sources, - 'settings': { - 'optimizer': { - 'enabled': optimize - }, - 'outputSelection': {'*': {'*': ['evm.bytecode.object', 'metadata']}}, - 'modelChecker': { "engine": 'none' } + for output_type in [['evm.bytecode.object', 'metadata'], ['ewasm.wast', 'ewasm.wasm', 'metadata']]: + sources = {} + sources[f] = {'content': open(f, mode='r', encoding='utf8').read()} + input_json = { + 'language': 'Solidity', + 'sources': sources, + 'settings': { + 'optimizer': { + 'enabled': optimize + }, + 'outputSelection': {'*': {'*': output_type}}, + 'modelChecker': {"engine": 'none'} + } } - } - args = [SOLC_BIN, '--standard-json'] - if optimize: - args += ['--optimize'] - proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - (out, err) = proc.communicate(json.dumps(input_json).encode('utf-8')) - try: - result = json.loads(out.decode('utf-8').strip()) - 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']: - REPORT_FILE.write(filename + ':' + contractName + ' ' + - contractData['evm']['bytecode']['object'] + '\n') - else: - REPORT_FILE.write(filename + ':' + contractName + ' NO BYTECODE\n') - REPORT_FILE.write(filename + ':' + contractName + ' ' + contractData['metadata'] + '\n') - except KeyError: - REPORT_FILE.write(f + ": ERROR\n") + args = [SOLC_BIN, '--standard-json'] + if optimize: + args += ['--optimize'] + proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (out, err) = proc.communicate(json.dumps(input_json).encode('utf-8')) + try: + result = json.loads(out.decode('utf-8').strip()) + for filename in sorted(result['contracts'].keys()): + for contractName in sorted(result['contracts'][filename].keys()): + outputType = "" + if 'ewasm.wast' in output_type: + outputType = "(ewasm)" + contractData = result['contracts'][filename][contractName] + if 'evm' in contractData and 'bytecode' in contractData['evm']: + REPORT_FILE.write(filename + ':' + contractName + ' ' + + contractData['evm']['bytecode']['object'] + '\n') + elif 'ewasm' in contractData and 'wasm' in contractData['ewasm']: + REPORT_FILE.write(filename + ':' + contractName + outputType + + contractData['ewasm']['wasm'] + '\n') + else: + REPORT_FILE.write(filename + ':' + contractName + outputType + ' NO BYTECODE\n') + REPORT_FILE.write(filename + ':' + contractName + outputType + ' ' + contractData['metadata'] + '\n') + except KeyError: + REPORT_FILE.write(f + ": ERROR\n")