fixes + logger

pull/202/head
ggrieco-tob 6 years ago
parent 43fa9c73df
commit 32f2f6f0d1
  1. 4
      utils/similarity/__main__.py
  2. 11
      utils/similarity/encode.py
  3. 2
      utils/similarity/info.py
  4. 5
      utils/similarity/test.py
  5. 2
      utils/similarity/train.py

@ -5,13 +5,11 @@ import logging
import sys import sys
import traceback import traceback
import operator import operator
import numpy as np
from .info import info from .info import info
from .test import test from .test import test
from .train import train from .train import train
logging.basicConfig() logging.basicConfig()
logger = logging.getLogger("Slither") logger = logging.getLogger("Slither")
@ -19,7 +17,7 @@ slither_simil_usage = "USAGE" # TODO
modes = ["info", "test", "train"] modes = ["info", "test", "train"]
def parse_args(): def parse_args():
parser = argparse.ArgumentParser(description='', parser = argparse.ArgumentParser(description='Code similarity detection tool',
usage=slither_simil_usage) usage=slither_simil_usage)
parser.add_argument('mode', parser.add_argument('mode',

@ -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 import *
from slither.solc_parsing.variables.local_variable_init_from_tuple import * from slither.solc_parsing.variables.local_variable_init_from_tuple import *
logger = logging.getLogger("Slither-simil")
def load_contracts(dirname, ext=None): def load_contracts(dirname, ext=None):
r = [] r = []
walk = list(os.walk(dirname)) walk = list(os.walk(dirname))
@ -121,7 +123,6 @@ def encode_ir(ir):
# default # default
else: else:
print(type(ir),"is missing encoding!") print(type(ir),"is missing encoding!")
#sys.exit(1)
return '' return ''
def encode_contract(filename, solc): def encode_contract(filename, solc):
@ -131,7 +132,7 @@ def encode_contract(filename, solc):
try: try:
slither = Slither(filename, solc=solc) slither = Slither(filename, solc=solc)
except: except:
print("Compilation failed") logger.error("Compilation failed")
return r return r
# Iterate over all the contracts # Iterate over all the contracts
@ -152,17 +153,11 @@ def encode_contract(filename, solc):
# Iterate over the nodes of the function # Iterate over the nodes of the function
for node in function.nodes: for node in function.nodes:
# Print the Solidity expression of the nodes # Print the Solidity expression of the nodes
# And the SlithIR operations # And the SlithIR operations
if node.expression: if node.expression:
#print('\tSolidity expression: {}'.format(node.expression))
#print('\tSlithIR:')
for ir in node.irs: for ir in node.irs:
#print(ir)
r[x].append(encode_ir(ir)) r[x].append(encode_ir(ir))
#print('\t\t\t{}'.format(ir))
return r return r

@ -6,7 +6,7 @@ from fastText import load_model
from .encode import encode_contract from .encode import encode_contract
logging.basicConfig() logging.basicConfig()
logger = logging.getLogger("Slither") logger = logging.getLogger("Slither-simil")
def info(args): def info(args):

@ -10,7 +10,7 @@ from .encode import encode_contract, load_contracts
from .cache import load_cache, save_cache from .cache import load_cache, save_cache
from .similarity import similarity from .similarity import similarity
logger = logging.getLogger("crytic-pred") logger = logging.getLogger("Slither-simil")
def test(args): def test(args):
@ -28,6 +28,9 @@ def test(args):
sys.exit(-1) sys.exit(-1)
irs = encode_contract(filename,solc=solc) irs = encode_contract(filename,solc=solc)
if len(irs) == 0:
sys.exit(-1)
x = "-".join([filename,contract,fname]) x = "-".join([filename,contract,fname])
y = " ".join(irs[x]) y = " ".join(irs[x])

@ -7,7 +7,7 @@ import operator
from fastText import train_unsupervised from fastText import train_unsupervised
from .encode import encode_contract, load_contracts from .encode import encode_contract, load_contracts
logger = logging.getLogger("crytic-pred") logger = logging.getLogger("Slither-simil")
def train(args): def train(args):

Loading…
Cancel
Save