예제 #1
0
    def analyser(self):
        mapASTSourceToLineNumbers = MapASTSourceToLineNumbers()
        print("\n<<<<<<<<<< Analyser: Control Flow Graph >>>>>>>>>>")

        functionCalls = AnalyseFunctionCall.getAllFunctionCalls()
        for functionCall in functionCalls:
            found = True
            if (functionCall.name is not None):
                logging.debug("functionCall: " + functionCall.name)
                node = functionCall.parent
                while (node.nodeType != "FunctionDefinition"):
                    node = node.parent
                    if (isinstance(node, AST)):
                        found = False
                        break
                if (found):
                    self.controlFlowGraph.append({
                        "callerName":
                        node.name,
                        "calleeName":
                        functionCall.name,
                        "line":
                        str(
                            mapASTSourceToLineNumbers.getLine(
                                int(functionCall.src.split(":", )[0])))
                    })

        for item in self.controlFlowGraph:
            print(item)
예제 #2
0
 def test_functionCall(self):
     parseAST = ParseAST()
     astFD = open("./tests/functionCall.ast", "r")
     parseResults = parseAST.parse(astFD)
     self.assertEqual(parseResults['Counts']['FunctionCallCount'], 1)
     functionCalls = AnalyseFunctionCall.getAllFunctionCalls()
     self.assertEqual(len(functionCalls), 1)
     self.assertEqual(functionCalls[0], "foo")
     astFD.close()
예제 #3
0
 def test_contractName(self):
     parseAST = ParseAST()
     astFD = open("./tests/functionCall.ast", "r")
     parseResults = parseAST.parse(astFD)
     functionCalls = AnalyseFunctionCall.getAllFunctionCalls()
     for item in functionCalls:
         print("Function Call Name: " + item)
     self.assertEqual(len(functionCalls), 1)
     astFD.close()
    def analyser(self):
        mapASTSourceToLineNumbers = MapASTSourceToLineNumbers()
        print("\n<<<<<<<<<< Analyser: Unchecked Selfdestructs >>>>>>>>>>")

        functionCalls = AnalyseFunctionCall.getAllFunctionCalls()
        for functionCall in functionCalls:
            if (functionCall.name == "selfdestruct"):
                print("selfdestruct() at line:" + str(
                    mapASTSourceToLineNumbers.getLine(
                        int(functionCall.src.split(":", )[0]))))
                node = functionCall.parent
                checked = False
                while (node.nodeType != "ContractDefinition"):
                    if (
                            node.nodeType == "IfStatement"
                    ):  # Add check for ifStatementCondition containing ownership check via msg.sender
                        self.statsConditionalCheckedSelfdestructs.append({
                            "line":
                            str(
                                mapASTSourceToLineNumbers.getLine(
                                    int(functionCall.src.split(":", )[0]))),
                            "info":
                            "conditional checked selfdestruct"
                        })
                        print(
                            "selfdestruct likely checked with conditional if()"
                        )
                        checked = True
                        break
                    # Add check for Function Definition containing ownership check in a modifer via msg.sender
                    node = node.parent
                if (checked):
                    continue
                else:
                    self.statsUncheckedSelfdestructs.append({
                        "line":
                        str(
                            mapASTSourceToLineNumbers.getLine(
                                int(functionCall.src.split(":", )[0]))),
                        "info":
                        "Unchecked selfdestruct"
                    })
                    print("Unchecked selfdestruct()")