def analyser(self):
        mapASTSourceToLineNumbers = MapASTSourceToLineNumbers()
        print("\n<<<<<<<<<< Analyser: Exceptions >>>>>>>>>>")

        requires = AnalyseFunctionCall.getAllRequires()
        print("Number of require(): " + str(len(requires)))
        for require in requires:
            print("require() " + " at line:" + str(
                mapASTSourceToLineNumbers.getLine(
                    int(require.src.split(":", )[0]))))
            self.statsRequires.append({
                "line":
                str(
                    mapASTSourceToLineNumbers.getLine(
                        int(require.src.split(":", )[0]))),
                "info":
                "require"
            })

        asserts = AnalyseFunctionCall.getAllAsserts()
        print("Number of assert(): " + str(len(asserts)))
        for _assert in asserts:
            print("assert() " + " at line:" + str(
                mapASTSourceToLineNumbers.getLine(
                    int(_assert.src.split(":", )[0]))))
            self.statsAsserts.append({
                "line":
                str(
                    mapASTSourceToLineNumbers.getLine(
                        int(_assert.src.split(":", )[0]))),
                "info":
                "assert"
            })

        reverts = AnalyseFunctionCall.getAllReverts()
        print("Number of revert(): " + str(len(reverts)))
        for revert in reverts:
            print("revert() " + " at line:" + str(
                mapASTSourceToLineNumbers.getLine(
                    int(revert.src.split(":", )[0]))))
            self.statsReverts.append({
                "line":
                str(
                    mapASTSourceToLineNumbers.getLine(
                        int(revert.src.split(":", )[0]))),
                "info":
                "revert"
            })
예제 #2
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)
예제 #3
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()
예제 #4
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()
예제 #5
0
 def test_selfDestruct(self):
     parseAST = ParseAST()
     astFD = open(self.testPath+".ast","r")
     parseResults = parseAST.parse(astFD)
     self.assertEqual(parseResults['Counts']['FunctionCallCount'], 2)
     functionCalls = AnalyseFunctionCall.getAllFunctionCallNames()
     self.assertEqual(len(functionCalls), 2)
     self.assertEqual(functionCalls[0],"selfdestruct")
     self.assertEqual(functionCalls[1],"selfdestruct")
     astFD.close()
예제 #6
0
 def test_exceptions(self):
     parseAST = ParseAST()
     astFD = open(self.testPath+".ast","r")
     parseResults = parseAST.parse(astFD)
     self.assertEqual(parseResults['Counts']['FunctionCallCount'], 3)
     functionCallNames = AnalyseFunctionCall.getAllFunctionCallNames()
     self.assertEqual(len(functionCallNames), 3)
     self.assertIn("assert", functionCallNames)
     self.assertIn("require", functionCallNames)
     self.assertIn("revert", functionCallNames)
     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()")