Static Analyzer for Solidity
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
slither/utils/similarity/info.py

55 lines
1.4 KiB

import logging
import sys
import os.path
import traceback
from fastText import load_model
from .encode import parse_target, encode_contract
logging.basicConfig()
6 years ago
logger = logging.getLogger("Slither-simil")
def info(args):
try:
model = args.model
if os.path.isfile(model):
model = load_model(model)
else:
model = None
filename = args.filename
contract, fname = parse_target(args.fname)
solc = args.solc
if filename is None and contract is None and fname is None:
logger.info("%s uses the following words:",args.model)
for word in model.get_words():
logger.info(word)
sys.exit(0)
if filename is None or contract is None or fname is None:
logger.error('The encode mode requires filename, contract and fname parameters.')
sys.exit(-1)
irs = encode_contract(filename, **vars(args))
if len(irs) == 0:
sys.exit(-1)
x = (filename,contract,fname)
y = " ".join(irs[x])
print("Function {} in contract {} is encoded as:".format(fname, contract))
print(y)
if model is not None:
fvector = model.get_sentence_vector(y)
print(fvector)
except Exception:
logger.error('Error in %s' % args.filename)
logger.error(traceback.format_exc())
sys.exit(-1)