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/cache.py

23 lines
710 B

import numpy as np
from .encode import encode_contract, load_contracts
def load_cache(infile, model, ext=None, solc='solc'):
cache = dict()
if infile.endswith(".npz"):
with np.load(infile) as data:
array = data['arr_0'][0]
for x,y in array:
cache[x] = y
else:
contracts = load_contracts(infile, ext=ext)
for contract in contracts:
for x,ir in encode_contract(contract, solc=solc).items():
if ir != []:
y = " ".join(ir)
cache[x] = model.get_sentence_vector(y)
return cache
def save_cache(cache, outfile):
np.savez(outfile,[np.array(list(cache.items()))])