Beispiel #1
0
    def get_callee_src_pairs(self, c_name):
        node = self.contracts["contractsByName"][c_name]
        walker = AstWalker()
        nodes = []
        if node:
            list_of_attributes = [{
                "attributes": {
                    "member_name": "delegatecall"
                }
            }, {
                "attributes": {
                    "member_name": "call"
                }
            }, {
                "attributes": {
                    "member_name": "callcode"
                }
            }]
            walker.walk(node, list_of_attributes, nodes)

        callee_src_pairs = []
        for node in nodes:
            if "children" in node and node["children"]:
                type_of_first_child = node["children"][0]["attributes"]["type"]
                if type_of_first_child.split(" ")[0] == "contract":
                    contract = type_of_first_child.split(" ")[1]
                    contract_path = self._find_contract_path(
                        self.contracts["contractsByName"].keys(), contract)
                    callee_src_pairs.append((contract_path, node["src"]))
        return callee_src_pairs
Beispiel #2
0
 def extract_func_call_definitions(self, c_name):
     node = self.contracts["contractsByName"][c_name]
     walker = AstWalker()
     nodes = []
     if node:
         walker.walk(node, "FunctionCall", nodes)
     return nodes
Beispiel #3
0
 def extract_func_call_definitions(self, c_name):
     node = self.contracts["contractsByName"][c_name]
     walker = AstWalker()
     nodes = []
     if node:
         walker.walk(node, {"name":  "FunctionCall"}, nodes)
     return nodes
Beispiel #4
0
 def extract_contract_definitions(self, sourcesList):
     ret = {
         "contractsById": {},
         "contractsByName": {},
         "sourcesByContract": {}
     }
     walker = AstWalker()
     for k in sourcesList:
         nodes = []
         walker.walk(sourcesList[k]["AST"], "ContractDefinition", nodes)
         for node in nodes:
             ret["contractsById"][node["id"]] = node
             ret["sourcesByContract"][node["id"]] = k
             ret["contractsByName"][k + ':' + node["attributes"]["name"]] = node
     return ret
Beispiel #5
0
    def get_func_name_to_params(self, c_name):
        node = self.contracts['contractsByName'][c_name]
        walker = AstWalker()
        func_def_nodes = []
        if node:
            walker.walk(node, {'name': 'FunctionDefinition'}, func_def_nodes)

        func_name_to_params = {}
        for func_def_node in func_def_nodes:
            func_name = func_def_node['attributes']['name']
            params_nodes = []
            walker.walk(func_def_node, {'name': 'ParameterList'}, params_nodes)

            params_node = params_nodes[0]
            param_nodes = []
            walker.walk(params_node, {'name': 'VariableDeclaration'},
                        param_nodes)

            for param_node in param_nodes:
                var_name = param_node['attributes']['name']
                type_name = param_node['children'][0]['name']
                if type_name == 'ArrayTypeName':
                    literal_nodes = []
                    walker.walk(param_node, {'name': 'Literal'}, literal_nodes)
                    if literal_nodes:
                        array_size = int(
                            literal_nodes[0]['attributes']['value'])
                    else:
                        array_size = 1
                    param = {
                        'name': var_name,
                        'type': type_name,
                        'value': array_size
                    }
                elif type_name == 'ElementaryTypeName':
                    param = {'name': var_name, 'type': type_name}
                else:
                    param = {'name': var_name, 'type': type_name}

                if func_name not in func_name_to_params:
                    func_name_to_params[func_name] = [param]
                else:
                    func_name_to_params[func_name].append(param)
        return func_name_to_params
Beispiel #6
0
 def extract_contract_definitions(self, sourcesList):
     ret = {
         "contractsById": {},
         "contractsByName": {},
         "sourcesByContract": {}
     }
     walker = AstWalker()
     for k in sourcesList:
         if self.input_type == "solidity":
             ast = sourcesList[k]["AST"]
         else:
             ast = sourcesList[k]["legacyAST"]
         nodes = []
         walker.walk(ast, "ContractDefinition", nodes)
         for node in nodes:
             ret["contractsById"][node["id"]] = node
             ret["sourcesByContract"][node["id"]] = k
             ret["contractsByName"][k + ':' + node["attributes"]["name"]] = node
     return ret
Beispiel #7
0
 def extract_contract_definitions(self, sourcesList):
     ret = {
         "contractsById": {},
         "contractsByName": {},
         "sourcesByContract": {}
     }
     walker = AstWalker()
     for k in sourcesList:
         if self.input_type == "solidity":
             ast = sourcesList[k]["AST"]
         else:
             ast = sourcesList[k]["legacyAST"]
         nodes = []
         walker.walk(ast, {"name": "ContractDefinition"}, nodes)
         for node in nodes:
             ret["contractsById"][node["id"]] = node
             ret["sourcesByContract"][node["id"]] = k
             ret["contractsByName"][k + ':' + node["attributes"]["name"]] = node
     return ret
Beispiel #8
0
    def get_callee_src_pairs(self, c_name):
        node = self.contracts["contractsByName"][c_name]
        walker = AstWalker()
        nodes = []
        if node:
            list_of_attributes = [
                {"attributes": {"member_name": "delegatecall"}},
                {"attributes": {"member_name": "call"}},
                {"attributes": {"member_name": "callcode"}}
            ]
            walker.walk(node, list_of_attributes, nodes)

        callee_src_pairs = []
        for node in nodes:
            if "children" in node and node["children"]:
                type_of_first_child = node["children"][0]["attributes"]["type"]
                if type_of_first_child.split(" ")[0] == "contract":
                    contract = type_of_first_child.split(" ")[1]
                    contract_path = self._find_contract_path(self.contracts["contractsByName"].keys(), contract)
                    callee_src_pairs.append((contract_path, node["src"]))
        return callee_src_pairs
Beispiel #9
0
    def get_func_name_to_params(self, c_name):
        node = self.contracts['contractsByName'][c_name]
        walker = AstWalker()
        func_def_nodes = []
        if node:
            walker.walk(node, {'name': 'FunctionDefinition'}, func_def_nodes)

        func_name_to_params = {}
        for func_def_node in func_def_nodes:
            func_name = func_def_node['attributes']['name']
            params_nodes = []
            walker.walk(func_def_node, {'name': 'ParameterList'}, params_nodes)

            params_node = params_nodes[0]
            param_nodes = []
            walker.walk(params_node, {'name': 'VariableDeclaration'}, param_nodes)

            for param_node in param_nodes:
                var_name = param_node['attributes']['name']
                type_name = param_node['children'][0]['name']
                if type_name == 'ArrayTypeName':
                    literal_nodes = []
                    walker.walk(param_node, {'name': 'Literal'}, literal_nodes)
                    if literal_nodes:
                        array_size = int(literal_nodes[0]['attributes']['value'])
                    else:
                        array_size = 1
                    param = {'name': var_name, 'type': type_name, 'value': array_size}
                elif type_name == 'ElementaryTypeName':
                    param = {'name': var_name, 'type': type_name}
                else:
                    param = {'name': var_name, 'type': type_name}

                if func_name not in func_name_to_params:
                    func_name_to_params[func_name] = [param]
                else:
                    func_name_to_params[func_name].append(param)
        return func_name_to_params