def detect_deprecation_in_expression(self, expression):
        """ Detects if an expression makes use of any deprecated standards.

        Returns:
            list of tuple: (detecting_signature, original_text, recommended_text)"""
        # Perform analysis on this expression
        export = ExportValues(expression)
        export_values = export.result()

        # Define our results list
        results = []

        # Check if there is usage of any deprecated solidity variables or functions
        for dep_var in self.DEPRECATED_SOLIDITY_VARIABLE:
            if SolidityVariableComposed(dep_var[0]) in export_values:
                results.append(dep_var)
        for dep_func in self.DEPRECATED_SOLIDITY_FUNCTIONS:
            if SolidityFunction(dep_func[0]) in export_values:
                results.append(dep_func)

        return results
Exemple #2
0
 def _parse_modifier(self, modifier):
     m = parse_expression(modifier, self)
     self._expression_modifiers.append(m)
     for m in ExportValues(m).result():
         if isinstance(m, Function):
             entry_point = self._new_node(NodeType.OTHER_ENTRYPOINT, modifier['src'])
             node = self._new_node(NodeType.EXPRESSION, modifier['src'])
             node.add_unparsed_expression(modifier)
             link_nodes(entry_point, node)
             self._modifiers.append(ModifierStatements(modifier=m,
                                                       entry_point=entry_point,
                                                       nodes=[entry_point, node]))
         elif isinstance(m, Contract):
             entry_point = self._new_node(NodeType.OTHER_ENTRYPOINT, modifier['src'])
             node = self._new_node(NodeType.EXPRESSION, modifier['src'])
             node.add_unparsed_expression(modifier)
             link_nodes(entry_point, node)
             self._explicit_base_constructor_calls.append(ModifierStatements(modifier=m,
                                                                             entry_point=entry_point,
                                                                             nodes=[entry_point, node]))
    def detect_unused(self, contract):
        if contract.is_signature_only():
            return None
        # Get all the variables read in all the functions and modifiers

        all_functions = (contract.all_functions_called + contract.modifiers)
        variables_used = [x.state_variables_read + x.state_variables_written for x in
                          all_functions]

        array_candidates = [x.variables for x in all_functions]
        array_candidates = [i for sl in array_candidates for i in sl] + contract.state_variables
        array_candidates = [x.type.length for x in array_candidates if isinstance(x.type, ArrayType) and x.type.length]
        array_candidates = [ExportValues(x).result() for x in array_candidates]
        array_candidates = [i for sl in array_candidates for i in sl]
        array_candidates = [v for v in array_candidates if isinstance(v, StateVariable)]

        # Flat list
        variables_used = [item for sublist in variables_used for item in sublist]
        variables_used = list(set(variables_used + array_candidates))
        # Return the variables unused that are not public
        return [x for x in contract.variables if
                x not in variables_used and x.visibility != 'public']
Exemple #4
0
    def _parse_modifier(self, modifier):
        m = parse_expression(modifier, self)
        self._expression_modifiers.append(m)

        # Do not parse modifier nodes for interfaces
        if not self._is_implemented:
            return

        for m in ExportValues(m).result():
            if isinstance(m, Function):
                node = self._new_node(NodeType.EXPRESSION, modifier['src'])
                node.add_unparsed_expression(modifier)
                # The latest entry point is the entry point, or the latest modifier call
                if self._modifiers:
                    latest_entry_point = self._modifiers[-1].nodes[-1]
                else:
                    latest_entry_point = self.entry_point
                insert_node(latest_entry_point, node)
                self._modifiers.append(
                    ModifierStatements(modifier=m,
                                       entry_point=latest_entry_point,
                                       nodes=[latest_entry_point, node]))

            elif isinstance(m, Contract):
                node = self._new_node(NodeType.EXPRESSION, modifier['src'])
                node.add_unparsed_expression(modifier)
                # The latest entry point is the entry point, or the latest constructor call
                if self._explicit_base_constructor_calls:
                    latest_entry_point = self._explicit_base_constructor_calls[
                        -1].nodes[-1]
                else:
                    latest_entry_point = self.entry_point
                insert_node(latest_entry_point, node)
                self._explicit_base_constructor_calls.append(
                    ModifierStatements(modifier=m,
                                       entry_point=latest_entry_point,
                                       nodes=[latest_entry_point, node]))
Exemple #5
0
 def _parse_modifier(self, modifier):
     m = parse_expression(modifier, self)
     self._expression_modifiers.append(m)
     self._modifiers += [
         m for m in ExportValues(m).result() if isinstance(m, Function)
     ]