diff --git a/utils/similarity/__main__.py b/utils/similarity/__main__.py index dc4d9da6a..239b68b62 100755 --- a/utils/similarity/__main__.py +++ b/utils/similarity/__main__.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)) diff --git a/utils/similarity/encode.py b/utils/similarity/encode.py index 6c9f4700a..a9334a253 100644 --- a/utils/similarity/encode.py +++ b/utils/similarity/encode.py @@ -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