Minor improvements in slither-similar:

- Fix import in utils.similarity.encore
- Improve slither-similari help
- Use contract.functions_not_inherited rather than contracts.functions + if function.contract == contract
pull/202/head
Josselin 6 years ago
parent d3f9816999
commit 2047ca6e88
  1. 2
      utils/similarity/__main__.py
  2. 51
      utils/similarity/encode.py

@ -19,7 +19,7 @@ logger = logging.getLogger("Slither-simil")
modes = ["info", "test", "train", "plot"]
def parse_args():
parser = argparse.ArgumentParser(description='Code similarity detection tool')
parser = argparse.ArgumentParser(description='Code similarity detection tool. For usage, see https://github.com/crytic/slither/wiki/Code-Similarity-detector')
parser.add_argument('mode',
help="|".join(modes))

@ -1,19 +1,19 @@
import logging
import os
import sys
from slither import Slither
from slither.slithir.operations import *
from slither.slithir.variables import *
from slither.core.declarations import *
from slither.solc_parsing.declarations.function import *
from slither.core.solidity_types import *
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 *
from slither.core.declarations import Structure, Enum, SolidityVariableComposed, SolidityVariable
from slither.core.solidity_types import ElementaryType, ArrayType, MappingType, UserDefinedType
from slither.slithir.operations import Assignment, Index, Member, Length, Balance, Binary, \
Unary, Condition, NewArray, NewStructure, NewContract, NewElementaryType, \
SolidityCall, Push, Delete, EventCall, LibraryCall, InternalDynamicCall, \
HighLevelCall, LowLevelCall, TypeConversion, Return, Transfer, Send, Unpack, InitArray, InternalCall
from slither.slithir.variables import TemporaryVariable, TupleVariable, Constant, ReferenceVariable
from slither.solc_parsing.declarations.function import FunctionSolc
from slither.solc_parsing.variables.local_variable import LocalVariableSolc
from slither.solc_parsing.variables.local_variable_init_from_tuple import LocalVariableInitFromTupleSolc
from slither.solc_parsing.variables.state_variable import StateVariableSolc
from .cache import load_cache
from crytic_compile.platform.solc import InvalidCompilation
simil_logger = logging.getLogger("Slither-simil")
compiler_logger = logging.getLogger("CryticCompile")
@ -194,25 +194,22 @@ def encode_contract(cfilename, **kwargs):
for contract in slither.contracts:
# Iterate over all the functions
for function in contract.functions:
# Dont explore inherited functions
if function.contract == contract:
for function in contract.functions_not_inherited:
if function.nodes == []:
continue
if function.nodes == []:
continue
x = (cfilename,contract.name,function.name)
x = (cfilename,contract.name,function.name)
r[x] = []
r[x] = []
# 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:
for ir in node.irs:
r[x].append(encode_ir(ir))
# 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:
for ir in node.irs:
r[x].append(encode_ir(ir))
return r

Loading…
Cancel
Save