From 899b46b75d3d422ea0affb1e5b928f1532117c9d Mon Sep 17 00:00:00 2001 From: David Pokora Date: Wed, 8 May 2019 00:47:25 -0400 Subject: [PATCH] Split constable-states and erc20-indexed findings into separate results --- .../erc20/unindexed_event_parameters.py | 17 +++++++++-------- .../variables/possible_const_state_variables.py | 10 +++++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/slither/detectors/erc20/unindexed_event_parameters.py b/slither/detectors/erc20/unindexed_event_parameters.py index c64a7681a..2f987f3c2 100644 --- a/slither/detectors/erc20/unindexed_event_parameters.py +++ b/slither/detectors/erc20/unindexed_event_parameters.py @@ -72,14 +72,15 @@ In this case, Transfer and Approval events should have the 'indexed' keyword on for c in self.contracts: unindexed_params = self.detect_erc20_unindexed_event_params(c) if unindexed_params: - info = "{} ({}) does not mark important ERC20 parameters as 'indexed':\n" - info = info.format(c.name, c.source_mapping_str) + # Add each problematic event definition to our result list for (event, parameter) in unindexed_params: - info += "\t-{} ({}) does not index parameter '{}'\n".format(event.name, event.source_mapping_str, parameter.name) - - # Add the events to the JSON (note: we do not add the params/vars as they have no source mapping). - json = self.generate_json_result(info) - self.add_functions_to_json([event for event, _ in unindexed_params], json) - results.append(json) + info = "ERC20 event {}.{} ({}) does not index parameter '{}'\n".format(c.name, event.name, event.source_mapping_str, parameter.name) + + # Add the events to the JSON (note: we do not add the params/vars as they have no source mapping). + json = self.generate_json_result(info) + self.add_function_to_json(event, json, { + "parameter_name": parameter.name + }) + results.append(json) return results diff --git a/slither/detectors/variables/possible_const_state_variables.py b/slither/detectors/variables/possible_const_state_variables.py index 7e726be46..9e03634a4 100644 --- a/slither/detectors/variables/possible_const_state_variables.py +++ b/slither/detectors/variables/possible_const_state_variables.py @@ -67,7 +67,6 @@ class ConstCandidateStateVars(AbstractDetector): """ Detect state variables that could be const """ results = [] - all_info = '' all_variables = [c.state_variables for c in self.slither.contracts] all_variables = set([item for sublist in all_variables for item in sublist]) @@ -84,13 +83,14 @@ class ConstCandidateStateVars(AbstractDetector): if (not v in all_variables_written) and self._constant_initial_expression(v)] # Order for deterministic results constable_variables = sorted(constable_variables, key=lambda x: x.canonical_name) + + # Create a result for each finding for v in constable_variables: info = "{}.{} should be constant ({})\n".format(v.contract.name, v.name, v.source_mapping_str) - all_info += info - if all_info != '': - json = self.generate_json_result(all_info) - self.add_variables_to_json(constable_variables, json) + json = self.generate_json_result(info) + self.add_variable_to_json(v, json) results.append(json) + return results