undo sorting of detectors output

pull/67/head
Alexander Remie 6 years ago
parent 4ee0434a84
commit 56cc9f22a4
  1. 2
      slither/detectors/attributes/constant_pragma.py
  2. 4
      slither/detectors/attributes/locked_ether.py
  3. 2
      slither/detectors/attributes/old_solc.py
  4. 4
      slither/detectors/examples/backdoor.py
  5. 4
      slither/detectors/functions/arbitrary_send.py
  6. 4
      slither/detectors/functions/external_function.py
  7. 4
      slither/detectors/functions/suicidal.py
  8. 16
      slither/detectors/naming_convention/naming_convention.py
  9. 4
      slither/detectors/operations/low_level_calls.py
  10. 2
      slither/detectors/reentrancy/reentrancy.py
  11. 4
      slither/detectors/shadowing/shadowing_functions.py
  12. 4
      slither/detectors/statements/assembly.py
  13. 4
      slither/detectors/statements/tx_origin.py
  14. 4
      slither/detectors/variables/possible_const_state_variables.py
  15. 4
      slither/detectors/variables/uninitialized_state_variables.py
  16. 2
      slither/detectors/variables/uninitialized_storage_variables.py
  17. 2
      slither/detectors/variables/unused_state_variables.py

@ -19,7 +19,7 @@ class ConstantPragma(AbstractDetector):
results = [] results = []
pragma = self.slither.pragma_directives pragma = self.slither.pragma_directives
versions = [p.version for p in pragma] versions = [p.version for p in pragma]
versions = sorted(list(set(versions))) versions = list(set(versions))
if len(versions) > 1: if len(versions) > 1:
info = "Different version of Solidity used in {}: {}".format(self.filename, versions) info = "Different version of Solidity used in {}: {}".format(self.filename, versions)

@ -38,10 +38,10 @@ class LockedEther(AbstractDetector):
def detect(self): def detect(self):
results = [] results = []
for contract in sorted(self.slither.contracts_derived, key=lambda c: c.name): for contract in self.slither.contracts_derived:
if contract.is_signature_only(): if contract.is_signature_only():
continue continue
funcs_payable = [function for function in sorted(contract.functions, key=lambda x: x.name) if function.payable] funcs_payable = [function for function in contract.functions if function.payable]
if funcs_payable: if funcs_payable:
if self.do_no_send_ether(contract): if self.do_no_send_ether(contract):
txt = "Contract locked ether in {}, Contract {}, Functions {}" txt = "Contract locked ether in {}, Contract {}, Functions {}"

@ -21,7 +21,7 @@ class OldSolc(AbstractDetector):
pragma = self.slither.pragma_directives pragma = self.slither.pragma_directives
versions = [p.version for p in pragma] versions = [p.version for p in pragma]
versions = [p.replace('solidity', '').replace('^', '') for p in versions] versions = [p.replace('solidity', '').replace('^', '') for p in versions]
versions = sorted(list(set(versions))) versions = list(set(versions))
old_pragma = [p for p in versions if p not in ['0.4.23', '0.4.24']] old_pragma = [p for p in versions if p not in ['0.4.23', '0.4.24']]
if old_pragma: if old_pragma:

@ -14,9 +14,9 @@ class Backdoor(AbstractDetector):
def detect(self): def detect(self):
ret = [] ret = []
for contract in sorted(self.slither.contracts_derived, key=lambda c: c.name): for contract in self.slither.contracts_derived:
# Check if a function has 'backdoor' in its name # Check if a function has 'backdoor' in its name
for f in sorted(contract.functions, key=lambda x: x.name): for f in contract.functions:
if 'backdoor' in f.name: if 'backdoor' in f.name:
# Info to be printed # Info to be printed
info = 'Backdoor function found in {}.{}'.format(contract.name, f.name) info = 'Backdoor function found in {}.{}'.format(contract.name, f.name)

@ -94,9 +94,9 @@ class ArbitrarySend(AbstractDetector):
taint = SolidityVariableComposed('msg.sender') taint = SolidityVariableComposed('msg.sender')
run_taint_variable(self.slither, taint) run_taint_variable(self.slither, taint)
for c in sorted(self.contracts, key=lambda c: c.name): for c in self.contracts:
arbitrary_send = self.detect_arbitrary_send(c) arbitrary_send = self.detect_arbitrary_send(c)
for (func, nodes) in sorted(arbitrary_send, key=lambda v: v[0].name): for (func, nodes) in arbitrary_send:
func_name = func.name func_name = func.name
calls_str = [str(node.expression) for node in nodes] calls_str = [str(node.expression) for node in nodes]

@ -46,14 +46,14 @@ class ExternalFunction(AbstractDetector):
public_function_calls = [] public_function_calls = []
for contract in sorted(self.slither.contracts_derived, key=lambda c: c.name): for contract in self.slither.contracts_derived:
if self._contains_internal_dynamic_call(contract): if self._contains_internal_dynamic_call(contract):
continue continue
func_list = self.detect_functions_called(contract) func_list = self.detect_functions_called(contract)
public_function_calls.extend(func_list) public_function_calls.extend(func_list)
for func in [f for f in sorted(contract.functions, key=lambda x: x.name) if f.visibility == 'public' and\ for func in [f for f in contract.functions if f.visibility == 'public' and\
not f in public_function_calls and\ not f in public_function_calls and\
not f.is_constructor]: not f.is_constructor]:
func_name = func.name func_name = func.name

@ -51,9 +51,9 @@ class Suicidal(AbstractDetector):
""" Detect the suicidal functions """ Detect the suicidal functions
""" """
results = [] results = []
for c in sorted(self.contracts, key=lambda c: c.name): for c in self.contracts:
functions = self.detect_suicidal(c) functions = self.detect_suicidal(c)
for func in sorted(functions, key=lambda x: x.name): for func in functions:
func_name = func.name func_name = func.name
txt = "Suicidal function in {} Contract: {}, Function: {}" txt = "Suicidal function in {} Contract: {}, Function: {}"

@ -42,7 +42,7 @@ class NamingConvention(AbstractDetector):
def detect(self): def detect(self):
results = [] results = []
for contract in sorted(self.contracts, key=lambda c: c.name): for contract in self.contracts:
if not self.is_cap_words(contract.name): if not self.is_cap_words(contract.name):
info = "Contract '{}' is not in CapWords".format(contract.name) info = "Contract '{}' is not in CapWords".format(contract.name)
@ -53,7 +53,7 @@ class NamingConvention(AbstractDetector):
'contract': contract.name, 'contract': contract.name,
'sourceMapping': contract.source_mapping}) 'sourceMapping': contract.source_mapping})
for struct in sorted(contract.structures, key=lambda x: x.name): for struct in contract.structures:
if struct.contract != contract: if struct.contract != contract:
continue continue
@ -67,7 +67,7 @@ class NamingConvention(AbstractDetector):
'struct': struct.name, 'struct': struct.name,
'sourceMapping': struct.source_mapping}) 'sourceMapping': struct.source_mapping})
for event in sorted(contract.events, key=lambda x: x.name): for event in contract.events:
if event.contract != contract: if event.contract != contract:
continue continue
@ -81,7 +81,7 @@ class NamingConvention(AbstractDetector):
'event': event.name, 'event': event.name,
'sourceMapping': event.source_mapping}) 'sourceMapping': event.source_mapping})
for func in sorted(contract.functions, key=lambda x: x.name): for func in contract.functions:
if func.contract != contract: if func.contract != contract:
continue continue
@ -95,7 +95,7 @@ class NamingConvention(AbstractDetector):
'function': func.name, 'function': func.name,
'sourceMapping': func.source_mapping}) 'sourceMapping': func.source_mapping})
for argument in sorted(func.parameters, key=lambda x: x.name): for argument in func.parameters:
if argument in func.variables_read_or_written: if argument in func.variables_read_or_written:
correct_naming = self.is_mixed_case(argument.name) correct_naming = self.is_mixed_case(argument.name)
else: else:
@ -112,7 +112,7 @@ class NamingConvention(AbstractDetector):
'argument': argument.name, 'argument': argument.name,
'sourceMapping': argument.source_mapping}) 'sourceMapping': argument.source_mapping})
for var in sorted(contract.state_variables, key=lambda x: x.name): for var in contract.state_variables:
if var.contract != contract: if var.contract != contract:
continue continue
@ -158,7 +158,7 @@ class NamingConvention(AbstractDetector):
'variable': var.name, 'variable': var.name,
'sourceMapping': var.source_mapping}) 'sourceMapping': var.source_mapping})
for enum in sorted(contract.enums, key=lambda x: x.name): for enum in contract.enums:
if enum.contract != contract: if enum.contract != contract:
continue continue
@ -172,7 +172,7 @@ class NamingConvention(AbstractDetector):
'enum': enum.name, 'enum': enum.name,
'sourceMapping': enum.source_mapping}) 'sourceMapping': enum.source_mapping})
for modifier in sorted(contract.modifiers, key=lambda x: x.name): for modifier in contract.modifiers:
if modifier.contract != contract: if modifier.contract != contract:
continue continue

@ -39,9 +39,9 @@ class LowLevelCalls(AbstractDetector):
""" Detect the functions that use low level calls """ Detect the functions that use low level calls
""" """
results = [] results = []
for c in sorted(self.contracts, key=lambda c: c.name): for c in self.contracts:
values = self.detect_low_level_calls(c) values = self.detect_low_level_calls(c)
for func, nodes in sorted(values, key=lambda v: v[0].name): for func, nodes in values:
func_name = func.name func_name = func.name
info = "Low level call in %s, Contract: %s, Function: %s" % (self.filename, info = "Low level call in %s, Contract: %s, Function: %s" % (self.filename,
c.name, c.name,

@ -176,7 +176,7 @@ class Reentrancy(AbstractDetector):
results = [] results = []
for (contract, func, calls, send_eth), varsWritten in sorted(self.result.items(), key=lambda x: (x[0][0], x[0][1], str(list(x[0][2])) )): for (contract, func, calls, send_eth), varsWritten in self.result.items():
varsWritten_str = list(set([str(x) for x in list(varsWritten)])) varsWritten_str = list(set([str(x) for x in list(varsWritten)]))
calls_str = list(set([str(x.expression) for x in list(calls)])) calls_str = list(set([str(x.expression) for x in list(calls)]))
send_eth_str = list(set([str(x.expression) for x in list(send_eth)])) send_eth_str = list(set([str(x.expression) for x in list(send_eth)]))

@ -37,10 +37,10 @@ class ShadowingFunctionsDetection(AbstractDetector):
""" """
results = [] results = []
for c in sorted(self.contracts, key=lambda c: c.name): for c in self.contracts:
shadowing = self.detect_shadowing(c) shadowing = self.detect_shadowing(c)
if shadowing: if shadowing:
for contract, funcs in sorted(shadowing.items(), key=lambda x: (x[0].name, str(list(x[1])))): for contract, funcs in shadowing.items():
results.append({'vuln': self.vuln_name, results.append({'vuln': self.vuln_name,
'filename': self.filename, 'filename': self.filename,
'contractShadower': c.name, 'contractShadower': c.name,

@ -39,9 +39,9 @@ class Assembly(AbstractDetector):
""" Detect the functions that use inline assembly """ Detect the functions that use inline assembly
""" """
results = [] results = []
for c in sorted(self.contracts, key=lambda c: c.name): for c in self.contracts:
values = self.detect_assembly(c) values = self.detect_assembly(c)
for func, nodes in sorted(values, key=lambda v: v[0].name): for func, nodes in values:
func_name = func.name func_name = func.name
info = "Assembly in %s, Contract: %s, Function: %s" % (self.filename, info = "Assembly in %s, Contract: %s, Function: %s" % (self.filename,
c.name, c.name,

@ -45,9 +45,9 @@ class TxOrigin(AbstractDetector):
""" Detect the functions that use tx.origin in a conditional node """ Detect the functions that use tx.origin in a conditional node
""" """
results = [] results = []
for c in sorted(self.contracts, key=lambda c: c.name): for c in self.contracts:
values = self.detect_tx_origin(c) values = self.detect_tx_origin(c)
for func, nodes in sorted(values, key=lambda v: v[0].name): for func, nodes in values:
func_name = func.name func_name = func.name
info = "tx.origin in %s, Contract: %s, Function: %s" % (self.filename, info = "tx.origin in %s, Contract: %s, Function: %s" % (self.filename,
c.name, c.name,

@ -54,12 +54,12 @@ class ConstCandidateStateVars(AbstractDetector):
""" Detect state variables that could be const """ Detect state variables that could be const
""" """
results = [] results = []
for c in sorted(self.slither.contracts_derived, key=lambda c: c.name): for c in self.slither.contracts_derived:
const_candidates = self.detect_const_candidates(c) const_candidates = self.detect_const_candidates(c)
if const_candidates: if const_candidates:
variables_by_contract = defaultdict(list) variables_by_contract = defaultdict(list)
for state_var in sorted(const_candidates, key=lambda x: (x.contract.name, x.name)): for state_var in const_candidates:
variables_by_contract[state_var.contract.name].append(state_var) variables_by_contract[state_var.contract.name].append(state_var)
for contract, variables in variables_by_contract.items(): for contract, variables in variables_by_contract.items():

@ -69,9 +69,9 @@ class UninitializedStateVarsDetection(AbstractDetector):
dict: [contract name] = set(state variable uninitialized) dict: [contract name] = set(state variable uninitialized)
""" """
results = [] results = []
for c in sorted(self.slither.contracts_derived, key=lambda c: c.name): for c in self.slither.contracts_derived:
ret = self.detect_uninitialized(c) ret = self.detect_uninitialized(c)
for variable, functions in sorted(ret, key=lambda r: str(r[0])): for variable, functions in ret:
info = "Uninitialized state variable in %s, " % self.filename + \ info = "Uninitialized state variable in %s, " % self.filename + \
"Contract: %s, Variable: %s, Used in %s" % (c.name, "Contract: %s, Variable: %s, Used in %s" % (c.name,
str(variable), str(variable),

@ -79,7 +79,7 @@ class UninitializedStorageVars(AbstractDetector):
function.entry_point.context[self.key] = uninitialized_storage_variables function.entry_point.context[self.key] = uninitialized_storage_variables
self._detect_uninitialized(function, function.entry_point, []) self._detect_uninitialized(function, function.entry_point, [])
for(function, uninitialized_storage_variable) in sorted(self.results, key=lambda r: (r[0].contract.name, r[0].name, r[1].name)): for(function, uninitialized_storage_variable) in self.results:
var_name = uninitialized_storage_variable.name var_name = uninitialized_storage_variable.name
info = "Uninitialized storage variables in %s, " % self.filename + \ info = "Uninitialized storage variables in %s, " % self.filename + \

@ -30,7 +30,7 @@ class UnusedStateVars(AbstractDetector):
""" Detect unused state variables """ Detect unused state variables
""" """
results = [] results = []
for c in sorted(self.slither.contracts_derived, key=lambda c: c.name): for c in self.slither.contracts_derived:
unusedVars = self.detect_unused(c) unusedVars = self.detect_unused(c)
if unusedVars: if unusedVars:
unusedVarsName = [v.name for v in unusedVars] unusedVarsName = [v.name for v in unusedVars]

Loading…
Cancel
Save