From 56cc9f22a4aa04e9afe54ef8f81d3ba16b1d0cc5 Mon Sep 17 00:00:00 2001 From: Alexander Remie Date: Mon, 5 Nov 2018 19:15:55 +0100 Subject: [PATCH] undo sorting of detectors output --- slither/detectors/attributes/constant_pragma.py | 2 +- slither/detectors/attributes/locked_ether.py | 4 ++-- slither/detectors/attributes/old_solc.py | 2 +- slither/detectors/examples/backdoor.py | 4 ++-- slither/detectors/functions/arbitrary_send.py | 4 ++-- slither/detectors/functions/external_function.py | 4 ++-- slither/detectors/functions/suicidal.py | 4 ++-- .../naming_convention/naming_convention.py | 16 ++++++++-------- slither/detectors/operations/low_level_calls.py | 4 ++-- slither/detectors/reentrancy/reentrancy.py | 2 +- .../detectors/shadowing/shadowing_functions.py | 4 ++-- slither/detectors/statements/assembly.py | 4 ++-- slither/detectors/statements/tx_origin.py | 4 ++-- .../variables/possible_const_state_variables.py | 4 ++-- .../variables/uninitialized_state_variables.py | 4 ++-- .../variables/uninitialized_storage_variables.py | 2 +- .../variables/unused_state_variables.py | 2 +- 17 files changed, 35 insertions(+), 35 deletions(-) diff --git a/slither/detectors/attributes/constant_pragma.py b/slither/detectors/attributes/constant_pragma.py index 763f3d04a..7a1e272c0 100644 --- a/slither/detectors/attributes/constant_pragma.py +++ b/slither/detectors/attributes/constant_pragma.py @@ -19,7 +19,7 @@ class ConstantPragma(AbstractDetector): results = [] pragma = self.slither.pragma_directives versions = [p.version for p in pragma] - versions = sorted(list(set(versions))) + versions = list(set(versions)) if len(versions) > 1: info = "Different version of Solidity used in {}: {}".format(self.filename, versions) diff --git a/slither/detectors/attributes/locked_ether.py b/slither/detectors/attributes/locked_ether.py index c0ea08953..682224f02 100644 --- a/slither/detectors/attributes/locked_ether.py +++ b/slither/detectors/attributes/locked_ether.py @@ -38,10 +38,10 @@ class LockedEther(AbstractDetector): def detect(self): 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(): 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 self.do_no_send_ether(contract): txt = "Contract locked ether in {}, Contract {}, Functions {}" diff --git a/slither/detectors/attributes/old_solc.py b/slither/detectors/attributes/old_solc.py index b733ba1a7..a14a1df50 100644 --- a/slither/detectors/attributes/old_solc.py +++ b/slither/detectors/attributes/old_solc.py @@ -21,7 +21,7 @@ class OldSolc(AbstractDetector): pragma = self.slither.pragma_directives versions = [p.version for p in pragma] 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']] if old_pragma: diff --git a/slither/detectors/examples/backdoor.py b/slither/detectors/examples/backdoor.py index 1543e70f6..9e29724f9 100644 --- a/slither/detectors/examples/backdoor.py +++ b/slither/detectors/examples/backdoor.py @@ -14,9 +14,9 @@ class Backdoor(AbstractDetector): def detect(self): 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 - for f in sorted(contract.functions, key=lambda x: x.name): + for f in contract.functions: if 'backdoor' in f.name: # Info to be printed info = 'Backdoor function found in {}.{}'.format(contract.name, f.name) diff --git a/slither/detectors/functions/arbitrary_send.py b/slither/detectors/functions/arbitrary_send.py index 594c6ce78..88d9be7c7 100644 --- a/slither/detectors/functions/arbitrary_send.py +++ b/slither/detectors/functions/arbitrary_send.py @@ -94,9 +94,9 @@ class ArbitrarySend(AbstractDetector): taint = SolidityVariableComposed('msg.sender') 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) - for (func, nodes) in sorted(arbitrary_send, key=lambda v: v[0].name): + for (func, nodes) in arbitrary_send: func_name = func.name calls_str = [str(node.expression) for node in nodes] diff --git a/slither/detectors/functions/external_function.py b/slither/detectors/functions/external_function.py index c5d860201..99ffe40fe 100644 --- a/slither/detectors/functions/external_function.py +++ b/slither/detectors/functions/external_function.py @@ -46,14 +46,14 @@ class ExternalFunction(AbstractDetector): 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): continue func_list = self.detect_functions_called(contract) 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.is_constructor]: func_name = func.name diff --git a/slither/detectors/functions/suicidal.py b/slither/detectors/functions/suicidal.py index 156aa569f..41b6f9bc5 100644 --- a/slither/detectors/functions/suicidal.py +++ b/slither/detectors/functions/suicidal.py @@ -51,9 +51,9 @@ class Suicidal(AbstractDetector): """ Detect the suicidal functions """ results = [] - for c in sorted(self.contracts, key=lambda c: c.name): + for c in self.contracts: functions = self.detect_suicidal(c) - for func in sorted(functions, key=lambda x: x.name): + for func in functions: func_name = func.name txt = "Suicidal function in {} Contract: {}, Function: {}" diff --git a/slither/detectors/naming_convention/naming_convention.py b/slither/detectors/naming_convention/naming_convention.py index 36d928983..f3312c1f0 100644 --- a/slither/detectors/naming_convention/naming_convention.py +++ b/slither/detectors/naming_convention/naming_convention.py @@ -42,7 +42,7 @@ class NamingConvention(AbstractDetector): def detect(self): 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): info = "Contract '{}' is not in CapWords".format(contract.name) @@ -53,7 +53,7 @@ class NamingConvention(AbstractDetector): 'contract': contract.name, 'sourceMapping': contract.source_mapping}) - for struct in sorted(contract.structures, key=lambda x: x.name): + for struct in contract.structures: if struct.contract != contract: continue @@ -67,7 +67,7 @@ class NamingConvention(AbstractDetector): 'struct': struct.name, 'sourceMapping': struct.source_mapping}) - for event in sorted(contract.events, key=lambda x: x.name): + for event in contract.events: if event.contract != contract: continue @@ -81,7 +81,7 @@ class NamingConvention(AbstractDetector): 'event': event.name, 'sourceMapping': event.source_mapping}) - for func in sorted(contract.functions, key=lambda x: x.name): + for func in contract.functions: if func.contract != contract: continue @@ -95,7 +95,7 @@ class NamingConvention(AbstractDetector): 'function': func.name, '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: correct_naming = self.is_mixed_case(argument.name) else: @@ -112,7 +112,7 @@ class NamingConvention(AbstractDetector): 'argument': argument.name, '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: continue @@ -158,7 +158,7 @@ class NamingConvention(AbstractDetector): 'variable': var.name, 'sourceMapping': var.source_mapping}) - for enum in sorted(contract.enums, key=lambda x: x.name): + for enum in contract.enums: if enum.contract != contract: continue @@ -172,7 +172,7 @@ class NamingConvention(AbstractDetector): 'enum': enum.name, 'sourceMapping': enum.source_mapping}) - for modifier in sorted(contract.modifiers, key=lambda x: x.name): + for modifier in contract.modifiers: if modifier.contract != contract: continue diff --git a/slither/detectors/operations/low_level_calls.py b/slither/detectors/operations/low_level_calls.py index 11ce2c89b..ec0f546a7 100644 --- a/slither/detectors/operations/low_level_calls.py +++ b/slither/detectors/operations/low_level_calls.py @@ -39,9 +39,9 @@ class LowLevelCalls(AbstractDetector): """ Detect the functions that use low level calls """ results = [] - for c in sorted(self.contracts, key=lambda c: c.name): + for c in self.contracts: 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 info = "Low level call in %s, Contract: %s, Function: %s" % (self.filename, c.name, diff --git a/slither/detectors/reentrancy/reentrancy.py b/slither/detectors/reentrancy/reentrancy.py index 15325feb2..e5c9966a7 100644 --- a/slither/detectors/reentrancy/reentrancy.py +++ b/slither/detectors/reentrancy/reentrancy.py @@ -176,7 +176,7 @@ class Reentrancy(AbstractDetector): 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)])) 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)])) diff --git a/slither/detectors/shadowing/shadowing_functions.py b/slither/detectors/shadowing/shadowing_functions.py index cecdc4b57..60d9677df 100644 --- a/slither/detectors/shadowing/shadowing_functions.py +++ b/slither/detectors/shadowing/shadowing_functions.py @@ -37,10 +37,10 @@ class ShadowingFunctionsDetection(AbstractDetector): """ results = [] - for c in sorted(self.contracts, key=lambda c: c.name): + for c in self.contracts: shadowing = self.detect_shadowing(c) 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, 'filename': self.filename, 'contractShadower': c.name, diff --git a/slither/detectors/statements/assembly.py b/slither/detectors/statements/assembly.py index 85ffbe934..93e9ea598 100644 --- a/slither/detectors/statements/assembly.py +++ b/slither/detectors/statements/assembly.py @@ -39,9 +39,9 @@ class Assembly(AbstractDetector): """ Detect the functions that use inline assembly """ results = [] - for c in sorted(self.contracts, key=lambda c: c.name): + for c in self.contracts: 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 info = "Assembly in %s, Contract: %s, Function: %s" % (self.filename, c.name, diff --git a/slither/detectors/statements/tx_origin.py b/slither/detectors/statements/tx_origin.py index fe2f5dc53..f5c474f8f 100644 --- a/slither/detectors/statements/tx_origin.py +++ b/slither/detectors/statements/tx_origin.py @@ -45,9 +45,9 @@ class TxOrigin(AbstractDetector): """ Detect the functions that use tx.origin in a conditional node """ results = [] - for c in sorted(self.contracts, key=lambda c: c.name): + for c in self.contracts: 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 info = "tx.origin in %s, Contract: %s, Function: %s" % (self.filename, c.name, diff --git a/slither/detectors/variables/possible_const_state_variables.py b/slither/detectors/variables/possible_const_state_variables.py index 4bcb0f3f4..e19a389d1 100644 --- a/slither/detectors/variables/possible_const_state_variables.py +++ b/slither/detectors/variables/possible_const_state_variables.py @@ -54,12 +54,12 @@ class ConstCandidateStateVars(AbstractDetector): """ Detect state variables that could be const """ 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) if const_candidates: 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) for contract, variables in variables_by_contract.items(): diff --git a/slither/detectors/variables/uninitialized_state_variables.py b/slither/detectors/variables/uninitialized_state_variables.py index 17abb4a28..86f54b048 100644 --- a/slither/detectors/variables/uninitialized_state_variables.py +++ b/slither/detectors/variables/uninitialized_state_variables.py @@ -69,9 +69,9 @@ class UninitializedStateVarsDetection(AbstractDetector): dict: [contract name] = set(state variable uninitialized) """ 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) - 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 + \ "Contract: %s, Variable: %s, Used in %s" % (c.name, str(variable), diff --git a/slither/detectors/variables/uninitialized_storage_variables.py b/slither/detectors/variables/uninitialized_storage_variables.py index eef4ef4d6..37201b33c 100644 --- a/slither/detectors/variables/uninitialized_storage_variables.py +++ b/slither/detectors/variables/uninitialized_storage_variables.py @@ -79,7 +79,7 @@ class UninitializedStorageVars(AbstractDetector): function.entry_point.context[self.key] = uninitialized_storage_variables 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 info = "Uninitialized storage variables in %s, " % self.filename + \ diff --git a/slither/detectors/variables/unused_state_variables.py b/slither/detectors/variables/unused_state_variables.py index c9ec84c03..5be36163e 100644 --- a/slither/detectors/variables/unused_state_variables.py +++ b/slither/detectors/variables/unused_state_variables.py @@ -30,7 +30,7 @@ class UnusedStateVars(AbstractDetector): """ Detect unused state variables """ 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) if unusedVars: unusedVarsName = [v.name for v in unusedVars]