Пример #1
0
    def _create_node(
        self, func: Function, counter: int, variable: "Variable", scope: Union[Scope, Function]
    ):
        from slither.core.cfg.node import Node, NodeType
        from slither.core.expressions import (
            AssignmentOperationType,
            AssignmentOperation,
            Identifier,
        )

        # Function uses to create node for state variable declaration statements
        node = Node(NodeType.OTHER_ENTRYPOINT, counter, scope)
        node.set_offset(variable.source_mapping, self.compilation_unit)
        node.set_function(func)
        func.add_node(node)
        assert variable.expression
        expression = AssignmentOperation(
            Identifier(variable),
            variable.expression,
            AssignmentOperationType.ASSIGN,
            variable.type,
        )

        expression.set_offset(variable.source_mapping, self.compilation_unit)
        node.add_expression(expression)
        return node
Пример #2
0
    def _create_node(self, func, counter, variable):
        # Function uses to create node for state variable declaration statements
        node = Node(NodeType.OTHER_ENTRYPOINT, counter)
        node.set_offset(variable.source_mapping, self.slither)
        node.set_function(func)
        func.add_node(node)
        expression = AssignmentOperation(Identifier(variable),
                                         variable.expression,
                                         AssignmentOperationType.ASSIGN,
                                         variable.type)

        node.add_expression(expression)
        return node
def msg_value_in_loop(node: Node, in_loop_counter: int, visited: List[Node],
                      results: List[Node]) -> None:
    if node in visited:
        return
    # shared visited
    visited.append(node)

    if node.type == NodeType.STARTLOOP:
        in_loop_counter += 1
    elif node.type == NodeType.ENDLOOP:
        in_loop_counter -= 1

    for ir in node.all_slithir_operations():
        if in_loop_counter > 0 and SolidityVariableComposed(
                "msg.value") in ir.read:
            results.append(ir.node)
        if isinstance(ir, (InternalCall)):
            msg_value_in_loop(ir.function.entry_point, in_loop_counter,
                              visited, results)

    for son in node.sons:
        msg_value_in_loop(son, in_loop_counter, visited, results)
def delegatecall_in_loop(node: Node, in_loop_counter: int, visited: List[Node],
                         results: List[Node]) -> None:
    if node in visited:
        return
    # shared visited
    visited.append(node)

    if node.type == NodeType.STARTLOOP:
        in_loop_counter += 1
    elif node.type == NodeType.ENDLOOP:
        in_loop_counter -= 1

    for ir in node.all_slithir_operations():
        if (in_loop_counter > 0 and isinstance(ir, (LowLevelCall))
                and ir.function_name == "delegatecall"):
            results.append(ir.node)
        if isinstance(ir, (InternalCall)):
            delegatecall_in_loop(ir.function.entry_point, in_loop_counter,
                                 visited, results)

    for son in node.sons:
        delegatecall_in_loop(son, in_loop_counter, visited, results)
def call_in_loop(node: Node, in_loop_counter: int, visited: List[Node],
                 ret: List[Node]) -> None:
    if node in visited:
        return
    # shared visited
    visited.append(node)

    if node.type == NodeType.STARTLOOP:
        in_loop_counter += 1
    elif node.type == NodeType.ENDLOOP:
        in_loop_counter -= 1

    if in_loop_counter > 0:
        for ir in node.all_slithir_operations():
            if isinstance(ir, (LowLevelCall, HighLevelCall, Send, Transfer)):
                if isinstance(ir, LibraryCall):
                    continue
                ret.append(ir.node)
            if isinstance(ir, (InternalCall)):
                call_in_loop(ir.function.entry_point, in_loop_counter, visited,
                             ret)

    for son in node.sons:
        call_in_loop(son, in_loop_counter, visited, ret)