diff --git a/utils/similarity/__main__.py b/utils/similarity/__main__.py index c456ae0a9..2e2abd26c 100755 --- a/utils/similarity/__main__.py +++ b/utils/similarity/__main__.py @@ -5,13 +5,11 @@ import logging import sys import traceback import operator -import numpy as np from .info import info from .test import test from .train import train - logging.basicConfig() logger = logging.getLogger("Slither") @@ -19,7 +17,7 @@ slither_simil_usage = "USAGE" # TODO modes = ["info", "test", "train"] def parse_args(): - parser = argparse.ArgumentParser(description='', + parser = argparse.ArgumentParser(description='Code similarity detection tool', usage=slither_simil_usage) parser.add_argument('mode', diff --git a/utils/similarity/encode.py b/utils/similarity/encode.py index 75e022f7a..f6ad95517 100644 --- a/utils/similarity/encode.py +++ b/utils/similarity/encode.py @@ -11,6 +11,8 @@ from slither.solc_parsing.variables.state_variable import * from slither.solc_parsing.variables.local_variable import * from slither.solc_parsing.variables.local_variable_init_from_tuple import * +logger = logging.getLogger("Slither-simil") + def load_contracts(dirname, ext=None): r = [] walk = list(os.walk(dirname)) @@ -121,7 +123,6 @@ def encode_ir(ir): # default else: print(type(ir),"is missing encoding!") - #sys.exit(1) return '' def encode_contract(filename, solc): @@ -131,7 +132,7 @@ def encode_contract(filename, solc): try: slither = Slither(filename, solc=solc) except: - print("Compilation failed") + logger.error("Compilation failed") return r # Iterate over all the contracts @@ -152,17 +153,11 @@ def encode_contract(filename, solc): # Iterate over the nodes of the function for node in function.nodes: - # Print the Solidity expression of the nodes # And the SlithIR operations if node.expression: - - #print('\tSolidity expression: {}'.format(node.expression)) - #print('\tSlithIR:') for ir in node.irs: - #print(ir) r[x].append(encode_ir(ir)) - #print('\t\t\t{}'.format(ir)) return r diff --git a/utils/similarity/info.py b/utils/similarity/info.py index 46625eabd..947d9b40b 100644 --- a/utils/similarity/info.py +++ b/utils/similarity/info.py @@ -6,7 +6,7 @@ from fastText import load_model from .encode import encode_contract logging.basicConfig() -logger = logging.getLogger("Slither") +logger = logging.getLogger("Slither-simil") def info(args): diff --git a/utils/similarity/test.py b/utils/similarity/test.py index 96a6e648e..1ea803546 100755 --- a/utils/similarity/test.py +++ b/utils/similarity/test.py @@ -10,7 +10,7 @@ from .encode import encode_contract, load_contracts from .cache import load_cache, save_cache from .similarity import similarity -logger = logging.getLogger("crytic-pred") +logger = logging.getLogger("Slither-simil") def test(args): @@ -28,6 +28,9 @@ def test(args): sys.exit(-1) irs = encode_contract(filename,solc=solc) + if len(irs) == 0: + sys.exit(-1) + x = "-".join([filename,contract,fname]) y = " ".join(irs[x]) diff --git a/utils/similarity/train.py b/utils/similarity/train.py index 83c7ea8bf..0d99963de 100755 --- a/utils/similarity/train.py +++ b/utils/similarity/train.py @@ -7,7 +7,7 @@ import operator from fastText import train_unsupervised from .encode import encode_contract, load_contracts -logger = logging.getLogger("crytic-pred") +logger = logging.getLogger("Slither-simil") def train(args):