Smart contract summary generation method and system based on large language model and semantic enhancement

By generating abstract syntax trees, extracting code semantic information and converting them into function callback diagrams, the problem of poor quality of smart contract summary generation is solved, and high-quality smart contract code summary generation is realized, supporting safer smart contract development and maintain.

CN118939267BActive Publication Date: 2025-02-18HAINAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410980531.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-22
Publication Date
2025-02-18
Estimated Expiration
2044-07-22

AI Technical Summary

Technical Problem

The existing smart contract summary generation method has poor quality, especially due to insufficient information 'hints' and control flow information contained in the improvement, which makes it difficult for large language models to accurately understand the function callback tree and the generated code summary quality Not high.

Method used

By obtaining the source code of the smart contract, an abstract syntax tree is generated, the code semantic information is extracted, and the code is converted into a function callback diagram, which is saved in the code sample database. Then, determine the target code snippet, find the closest code semantic information and function callback diagram, enter it into a large language model, and generate a high-quality code summary.

Benefits of technology

Improve the quality of smart contract code summary generated by large language models, and enable developers to quickly understand the code, thereby achieving safer smart contracts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118939267B_ABST
    Figure CN118939267B_ABST
Patent Text Reader

Abstract

The present invention relates to a method and system for generating a summary of a smart contract based on a large language model and semantic enhancement. The method comprises: parsing the source code of a smart contract to generate an abstract syntax tree, extracting code semantic information, converting the contract function node of the abstract syntax tree into a function callback graph, and using the code semantic information extracted by the large language model and the callback information in the function callback graph to realize the generation of a high-quality smart contract code summary. By learning and understanding the semantic information and callback information of the smart contract function, the large language model can accurately understand and infer the deep semantic information of the code to generate a high-quality smart contract code summary, which not only effectively solves the limitations of semantic understanding in the prior art, but also supports the use of the multimodal capabilities of the large language model to extract, understand, and infer the callback information of the function callback graph, thereby improving the large language model's ability to understand the code callback structure.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of blockchain technology, and in particular to a method, system, computer device and readable storage medium for generating a smart contract summary based on a large language model and semantic enhancement. Background Art

[0002] Smart contracts are self-executable programs that run on blockchain systems. Smart contracts will automatically perform specific operations, such as transferring money or querying records, only when certain conditions are met. Although smart contracts have the advantages of being self-executable and open and transparent, they also face some key challenges. Due to the immutability of the blockchain system, smart contracts deployed on the blockchain cannot be modified, which makes the maintenance and testing of smart contracts extremely difficult. In the prior art, methods for automatically generating smart contract code summaries are generally divided into methods based on deep learning models, methods based on pre-trained natural language processing models, and large language models, such as the MMTrans tool, CodeT5+ model, and GPT-4o model. Although large language models such as GPT-4o and Gemini-1.5-pro have made great progress in automatically generating smart contract code summaries, they still have limitations, which are specifically manifested as follows: Limited by "hints" with insufficient information: the code semantic information provided in the zero-sample "hint" is not sufficient to support the large language model to generate code summaries based on semantic reasoning. This is because the "hint" does not contain the key hidden information in the provided code snippet; Limited by the control flow information contained in the boost: the large language model uses few-sample or zero-sample learning "hints" to generate code summaries. However, plain text "hints" often cannot accurately express the function callback information in the code snippet. This limitation challenges the ability of the large language model to understand the function callback tree, resulting in the generated code summary of low quality.

[0003] Therefore, traditional smart contract summary generation methods suffer from the problem of poor quality. Summary of the invention

[0004] Based on this, in order to solve the above technical problems, a method and system for generating smart contract summaries based on a large language model and semantic enhancement are provided, which can improve the quality of smart contract code summaries generated by large language models; it can be applied to the development and maintenance stages of smart contracts to help developers quickly understand the code capabilities, thereby achieving safer smart contracts.

[0005] A method for generating a smart contract summary based on a large language model and semantic enhancement, the method comprising:

[0006] Obtaining the smart contract source code, parsing the smart contract source code, and generating an abstract syntax tree;

[0007] Extracting code semantic information in the smart contract source code from the abstract syntax tree;

[0008] Traversing the abstract syntax tree, converting the smart contract source code into a function callback graph, and saving the function callback graph and the code semantic information in a code sample database;

[0009] Determine a target code segment, and search the code sample database for target code semantic information and a target function callback graph that are closest to the target code segment;

[0010] The source code of the target code snippet, the target code semantic information, and the target function callback graph are input into a large language model, and the data output by the large language model is parsed to obtain and output a summary corresponding to the target code snippet.

[0011] In one embodiment, the smart contract source code is parsed to generate an abstract syntax tree, including:

[0012] The solidity_parser tool is used to parse the smart contract source code, and the smart contract or function in the smart contract source code is used as the root node, the statement or expression is used as the internal node, and the variable and constant basic elements are used as the leaf nodes.

[0013] In one of the embodiments, the code semantic information includes: contract member variables, contract type, contract function, function name, function declaration, inline function, and function callback.

[0014] In one embodiment, traversing the abstract syntax tree to convert the smart contract source code into a function callback graph includes:

[0015] Traversing each contract node in the abstract syntax tree, traversing the function node in each contract node, and traversing the function callback node in each function node;

[0016] After traversing all the function callback nodes, a function callback tree is obtained;

[0017] Traversing each of the function callback nodes in the function callback tree to obtain callback information corresponding to each of the function callback nodes;

[0018] A vectorless function callback graph is obtained based on the callback information.

[0019] In one embodiment, the method further comprises:

[0020] Use graphviz to describe the callback information corresponding to the function callback node;

[0021] The function callback node after describing the callback information is saved in an unordered sequence of non-repeating elements;

[0022] Each of the function callback nodes in the function callback tree is traversed, and node search is performed in the non-repeating element sequence until the function callback tree is completely traversed to obtain a vectorless function callback graph.

[0023] In one embodiment, the determining of the target code snippet and searching the code sample database for target code semantic information and target function callback graph closest to the target code snippet include:

[0024] Vectorizing the target code fragment to obtain an input matching vector;

[0025] Read all function codes in the code sample database, and convert each function code into a function code vector list;

[0026] Matching the input matching vector with the function code vector list, and outputting a target number corresponding to the function code vector closest to the input matching vector;

[0027] The target code semantic information and the target function callback graph are read from the code sample database according to the target number.

[0028] In one embodiment, the training process of the large language model includes:

[0029] Determine sample code semantic information and sample function callback graph, and input the sample code semantic information and sample function callback graph into a large language model;

[0030] The target code semantic information and the target function callback graph are used as learning objects to adjust the parameters in the large language model.

[0031] A smart contract summary generation system based on a large language model and semantic enhancement, the system comprising:

[0032] An abstract syntax tree generation module is used to obtain the smart contract source code, parse the smart contract source code, and generate an abstract syntax tree;

[0033] An information extraction module, used to extract code semantic information in the smart contract source code from the abstract syntax tree;

[0034] A data storage module, used to traverse the abstract syntax tree, convert the smart contract source code into a function callback graph, and save the function callback graph and the code semantic information in a code sample database;

[0035] A search module, used to determine a target code segment, and search the code sample database for target code semantic information and a target function callback graph that are closest to the target code segment;

[0036] The summary generation module is used to input the source code of the target code fragment, the target code semantic information, and the target function callback graph into the large language model, parse the data output by the large language model, obtain the summary corresponding to the target code fragment, and output it.

[0037] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:

[0038] Obtaining the smart contract source code, parsing the smart contract source code, and generating an abstract syntax tree;

[0039] Extracting code semantic information in the smart contract source code from the abstract syntax tree;

[0040] Traversing the abstract syntax tree, converting the smart contract source code into a function callback graph, and saving the function callback graph and the code semantic information in a code sample database;

[0041] Determine a target code segment, and search the code sample database for target code semantic information and a target function callback graph that are closest to the target code segment;

[0042] The source code of the target code snippet, the target code semantic information, and the target function callback graph are input into a large language model, and the data output by the large language model is parsed to obtain and output a summary corresponding to the target code snippet.

[0043] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps:

[0044] Obtaining the smart contract source code, parsing the smart contract source code, and generating an abstract syntax tree;

[0045] Extracting code semantic information in the smart contract source code from the abstract syntax tree;

[0046] Traversing the abstract syntax tree, converting the smart contract source code into a function callback graph, and saving the function callback graph and the code semantic information in a code sample database;

[0047] Determine a target code segment, and search the code sample database for target code semantic information and a target function callback graph that are closest to the target code segment;

[0048] The source code of the target code snippet, the target code semantic information, and the target function callback graph are input into a large language model, and the data output by the large language model is parsed to obtain and output a summary corresponding to the target code snippet.

[0049] The above-mentioned smart contract summary generation method, system, computer device and readable storage medium based on large language model and semantic enhancement, by applying large language model and semantic analysis technology to automatically generate smart contract code summary, the large language model can accurately understand and infer the deep semantic information of the code by learning and understanding the semantic information and callback information of the smart contract function, thereby generating high-quality smart contract code summary. It not only effectively solves the limitations of semantic understanding in the prior art, but also supports the use of the multimodal capabilities of the large language model to extract, understand, and infer the callback information of the function callback graph, which greatly improves the large language model's ability to understand the code callback structure. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] Figure 1 An application environment diagram of a method for generating a smart contract summary based on a large language model and semantic enhancement in one embodiment;

[0051] Figure 2 A flowchart of a method for generating a smart contract summary based on a large language model and semantic enhancement in one embodiment;

[0052] Figure 3 is a schematic diagram of semantic information extraction in one embodiment;

[0053] Figure 4 A schematic diagram of generating a function callback graph in one embodiment;

[0054] Figure 5 A schematic diagram of a semantically enhanced “prompt” in one embodiment;

[0055] Figure 6 A structural block diagram of a smart contract summary generation system based on a large language model and semantic enhancement in one embodiment;

[0056] Figure 7 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0057] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0058] The method for generating a smart contract summary based on a large language model and semantic enhancement provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Figure 1 As shown, the application environment includes a computer device 110. The computer device 110 can obtain the smart contract source code, parse the smart contract source code, and generate an abstract syntax tree; the computer device 110 can extract the code semantic information in the smart contract source code from the abstract syntax tree; the computer device 110 can traverse the abstract syntax tree, convert the smart contract source code into a function callback graph, and save the function callback graph and code semantic information in a code sample database; the computer device 110 can determine the target code fragment, and search the code sample database for the target code semantic information and the target function callback graph closest to the target code fragment; the computer device 110 can input the source code, target code semantic information, and target function callback graph of the target code fragment into the large language model, parse the data output by the large language model, obtain the summary corresponding to the target code fragment, and output it. Among them, the computer device 110 can be, but not limited to, various personal computers, laptops, smart phones, robots, tablet computers and other devices.

[0059] In one embodiment, Figure 2 As shown, a method for generating a smart contract summary based on a large language model and semantic enhancement is provided, comprising the following steps:

[0060] Step 202: Obtain the smart contract source code, parse the smart contract source code, and generate an abstract syntax tree.

[0061] Specifically, in one embodiment, a method for generating a smart contract summary based on a large language model and semantic enhancement may also include a process of generating an abstract syntax tree, the specific process including: using the solidity_parser tool to parse the smart contract source code, taking the smart contract or function in the smart contract source code as the root node, taking the statement or expression as the internal node, and taking the variable and constant basic elements as the leaf nodes.

[0062] Among them, the computer device can parse the Solidity smart contract source code into a complete abstract syntax tree through the third-party library solidity_parser tool in Python. The generated abstract syntax tree is a tree structure representation of the source code. The root node of the tree represents the entire smart contract or function, each internal node represents a statement or expression, and the leaf node represents a variable, constant or other basic element. By generating an abstract syntax tree, the semantic relationship between program elements can be effectively encapsulated, so as to better understand and operate the program logic.

[0063] Step 204: extract code semantic information in the smart contract source code from the abstract syntax tree.

[0064] In one embodiment, the code semantic information may include: contract member variables, contract type, contract function, function name, function declaration, inline function, and function callback.

[0065] Among them, Figure 3 As shown, the computer device can extract code semantic information such as contract member variables, function declarations, inline functions, and function callbacks by traversing the abstract syntax tree. Specifically, in this embodiment, the computer device can extract seven types of information related to code semantics from the abstract syntax tree, including contract member variables, contract types, contract functions, function names, function declarations, inline functions, and function callbacks. Contract member variables include all variable and constant declaration nodes of the contract; contract types include all contract declaration types; contract functions include all function nodes in the contract; function names include function name nodes; function declarations include all function declaration nodes; inline functions include code blocks for calling functions inside functions; and function callbacks include all callback nodes of functions.

[0066] like Figure 3 As shown in the figure, extracting code semantic information plays a vital role in the deep understanding of code semantics by large language models. These semantic information helps large language models understand the core semantics of the code and generate higher quality code summaries. Specifically, the accuracy of semantic information is crucial for generating code summaries, and in the task of automatically generating code summaries, different types of nodes contain different semantic information.

[0067] The functions of each code semantic information are as follows: Contract member variables: global variables defined in smart contracts, which are used globally in functions; Contract type: expresses the construction type of the contract and the contract constructor, which contains the construction information of the contract start; Contract function: functions defined and used in the contract, including external call functions and internal functions; Function name: declares the purpose and naming rules of the function; Function declaration, while function and method declaration nodes can represent the functions and operations of smart contracts; Inner function: Inner function represents other functions called inside a function, which can enrich the calling information of the function; Function callback: Function callback represents the functions contained in all callback nodes in a function node, which can represent the primary callback structure of the function.

[0068] In this embodiment, in addition to extracting code semantic information, node attributes are also retained, defined as a tuple (Nid, Ncn, Nct, Ncv, Ncc, Nfn, Nfv, Nfc, Nfi), where Nid represents the smart contract id, Ncn represents the smart contract name, Nct represents the type of the smart contract, Ncv represents the member variables of the smart contract, Ncc represents the constructor of the smart contract, Nfn represents the function name, Nfv represents the function declaration, Nfc represents the function code, and Nfi represents the inline function code. These attributes provide a direct representation of the data, facilitate efficient operations and ensure invariance.

[0069] Step 206, traverse the abstract syntax tree, convert the smart contract source code into a function callback graph, and save the function callback graph and code semantic information in the code sample database.

[0070] In one embodiment, a method for generating a smart contract summary based on a large language model and semantic enhancement is provided, which may also include a process of generating a function callback graph, the specific process including: traversing each contract node in an abstract syntax tree, traversing the function nodes in each contract node, and traversing the function callback nodes in each function node; after traversing each function callback node, a function callback tree is obtained; each function callback node in the function callback tree is traversed to obtain callback information corresponding to each function callback node; and a vectorless function callback graph is obtained based on the callback information.

[0071] Specifically, in one embodiment, a computer device can use graphviz to describe the callback information corresponding to a function callback node; save the function callback node after describing the callback information in an unordered sequence of non-repeating elements; traverse each function callback node in the function callback tree, and perform node search in the non-repeating element sequence until the function callback tree is traversed to obtain a vectorless function callback graph.

[0072] like Figure 4 As shown, in the process of generating a function callback graph, the specific process may include constructing a primary function callback tree, constructing a complete function callback tree, and generating a function callback graph. Among them:

[0073] The construction of the primary function callback tree includes: when constructing the primary function callback tree, starting from the root node of the abstract syntax tree, traversing each contract node in depth first, then traversing the function nodes in the contract node, and then traversing the function callback nodes of each function node, this process is recursive until the entire abstract syntax tree is traversed; finally, the function callback node information is saved in the dictionary set in the order of contract name → function name → callback function name → callback function node, and the primary function callback tree is completed. The construction of the primary function callback tree can provide the function callback information of each function in the abstract syntax tree, so as to clearly express the callback ownership of each function.

[0074] The construction of a complete function callback tree includes: for each function callback node of the primary function callback tree constructed using depth-first traversal, the name of the next callback function is obtained from the function callback node. If the function name is at the function node position corresponding to the primary function callback tree, the function callback node at that position is taken out and spliced ​​behind the node where the function name is located. If the function callback node does not have the name of the next callback function, this node is skipped to access the next node until the entire tree of function callback nodes is traversed, and finally a complete function callback tree is obtained.

[0075] The generation of the function callback graph includes: using a method library called graphviz to draw a vectorless function callback graph, traversing each function callback node of the complete function callback tree, using graphviz to describe the callback information of each function callback node, and saving the visited nodes into an unordered sequence of non-repeating elements. If the currently visited node already appears in the sequence, skip this node and visit the next node until the entire function callback tree is traversed, and finally a vectorless function callback graph is obtained.

[0076] Step 208: determine the target code segment, and search the code sample database for target code semantic information and target function callback graph that are closest to the target code segment.

[0077] In one embodiment, a method for generating a smart contract summary based on a large language model and semantic enhancement may also include a process of finding the closest semantic information and function callback graph, and the specific process includes: vectorizing the target code fragment to obtain an input matching vector; reading all function codes in a code sample database, and converting each function code into a function code vector list; matching the input matching vector with the function code vector list, and outputting a target number corresponding to the function code vector closest to the input matching vector; and reading the target code semantic information and the target function callback graph from the code sample database according to the target number.

[0078] Specifically, when performing semantic matching, the computer device can vectorize the target text code as the input matching vector of sentence_transformers; read the codes of all functions in the code sample warehouse and convert them into a list of function code vectors as a semantic matching reference sample of sentence_transformers; finally, after semantic matching in terms of semantics, syntax, etc., the sentence_transformers model outputs the numbers of the n code snippets in the warehouse that are most semantically matched with the target code, and finally reads the corresponding code semantic information and function callback graph according to the numbers.

[0079] That is, the computer device can use the fine-tuned sentence_transformers model to match n code learning samples. The sentence_transformers mode is a type of Sbert model, which is a lightweight model that can calculate the similarity of two sentences based on semantics. First, sentence_transformers encodes the sentences that need to calculate semantic similarity to obtain the vector representation of the sentences, and then uses the cos_sin function of sentence_transformers to calculate the cosine similarity between the two sentence vectors. The closer the value is to 1, the more similar the two sentences are in semantics, and the closer the value is to 0, the less similar they are.

[0080] Step 210, input the source code of the target code snippet, the target code semantic information, and the target function callback graph into the large language model, parse the data output by the large language model, obtain the summary corresponding to the target code snippet, and output it.

[0081] In one embodiment, the training process of the large language model may include: determining sample code semantic information and sample function callback graph, and inputting the sample code semantic information and sample function callback graph into the large language model; taking target code semantic information and target function callback graph as learning objects, and adjusting parameters in the large language model.

[0082] The n samples that are semantically closest to the target code are used as the few-sample learning objects of the large language model. By learning the function semantic information and function callback graph in the n samples and the summary corresponding to the sample function, a summary similar to the learning sample is finally generated after understanding and reasoning the semantic information and function callback graph of the target code.

[0083] In this embodiment, sample learning and speech enhancement methods are used to enhance the large language model's understanding of code semantics. The large language model can enhance its reasoning ability and output similar results by learning samples in the "prompt", such as Figure 5As shown, the sample contains the semantic information of the code and the function callback diagram.

[0084] In this embodiment, the return result of the large language model can be parsed using the agreed JSON format, and finally a summary of the target code snippet is output to the user interface.

[0085] It should be understood that, although the various steps in the above-mentioned flow chart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the above-mentioned flow chart may include a plurality of sub-steps or a plurality of stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0086] In one embodiment, in order to verify the effect of a smart contract summary generation method based on a large language model and semantic enhancement proposed in this application, the following experiment is conducted:

[0087] Extensive experiments are conducted on a dataset containing 14,790 <method, comment> pairs. These methods come from the smart contract dataset on github, which contains more than 40,000 real Ethereum smart contracts. The average token length and comment length of the training set, test set, and validation set in the dataset are shown in the following table:

[0088]

[0089] In order to verify the performance of the framework, a smart contract summary generation method based on a large language model and semantic enhancement proposed in this application is compared with several most advanced methods for automatically generating code summaries. First, the method of this application is compared with the CodeBert model: CodeBert is a bimodal pre-trained model for natural language (NL) and programming language (PL), which is pre-trained using masked language modeling (MLM) and replacement tag detection (RTD) tasks; secondly, it is compared with the more advanced CodeT5 model: CodeT5 is a unified pre-trained encoder-decoder transformer model with excellent performance in understanding tasks and generation tasks; finally, it is compared with the most advanced CodeT5+ model, which is a new encoder-decoder series code-based large language model designed for a wide range of code understanding and generation tasks. It adopts a "shallow encoder and deep decoder" architecture, which significantly reduces the number of trainable parameters for effective tuning. The experimental results are shown in the following table:

[0090]

[0091] As shown in the table above, compared with CodeBert, CodeT5, and CodeT5+, the proposed framework of this application method outperforms the other three methods in all four key evaluation indicators. Among them, the BLEU-4 score is 37.53%, the METEOR score is 52.54%, the Rouge-L score is 56.97%, and the BLEURT score is 63.44%. The framework proposed by this application method obtained a BLEURT score of 63.44%, indicating that the generated summary is closer to the semantics of the real-world summary.

[0092] Therefore, the smart contract summary generation method based on a large language model and semantic enhancement proposed in this application can effectively improve the quality of the smart contract code summary generated by the large language model; it can be applied to the development and maintenance stages of smart contracts to help developers quickly understand the code and thus achieve safer smart contracts.

[0093] In one embodiment, Figure 6 As shown, a smart contract summary generation system based on a large language model and semantic enhancement is provided, including: an abstract syntax tree generation module 610, an information extraction module 620, a data storage module 630, a search module 640 and a summary generation module 650, wherein:

[0094] An abstract syntax tree generation module 610 is used to obtain the smart contract source code, parse the smart contract source code, and generate an abstract syntax tree;

[0095] An information extraction module 620 is used to extract code semantic information in the smart contract source code from the abstract syntax tree;

[0096] The data storage module 630 is used to traverse the abstract syntax tree, convert the smart contract source code into a function callback graph, and save the function callback graph and code semantic information in the code sample database;

[0097] A search module 640 is used to determine a target code segment and search for target code semantic information and a target function callback graph closest to the target code segment in a code sample database;

[0098] The summary generation module 650 is used to input the source code, target code semantic information, and target function callback graph of the target code snippet into the large language model, parse the data output by the large language model, obtain the summary corresponding to the target code snippet, and output it.

[0099] In one embodiment, the abstract syntax tree generation module 610 is also used to parse the smart contract source code using the solidity_parser tool, taking the smart contract or function in the smart contract source code as the root node, the statement or expression as the internal node, and the variable and constant basic elements as the leaf nodes.

[0100] In one embodiment, the code semantic information includes: contract member variables, contract type, contract function, function name, function declaration, inline function, and function callback.

[0101] In one embodiment, the data storage module 630 is also used to traverse each contract node in the abstract syntax tree, traverse the function nodes in each contract node, and traverse the function callback nodes in each function node; after traversing each function callback node, a function callback tree is obtained; each function callback node in the function callback tree is traversed to obtain the callback information corresponding to each function callback node; and a vectorless function callback graph is obtained based on the callback information.

[0102] In one embodiment, the data storage module 630 is also used to use graphviz to describe the callback information corresponding to the function callback node; save the function callback node after describing the callback information in an unordered sequence of non-repeating elements; traverse each function callback node in the function callback tree, and perform node search in the sequence of non-repeating elements until the function callback tree is traversed to obtain a vectorless function callback graph.

[0103] In one embodiment, the search module 640 is also used to vectorize the target code fragment to obtain an input matching vector; read all function codes in the code sample database, and convert each function code into a function code vector list; match the input matching vector with the function code vector list, and output the target number corresponding to the function code vector closest to the input matching vector; read the target code semantic information and the target function callback graph from the code sample database according to the target number.

[0104] In one embodiment, a large language model training module is also included, which is used to determine sample code semantic information and sample function callback graph, and input the sample code semantic information and sample function callback graph into the large language model; the target code semantic information and target function callback graph are used as learning objects to adjust the parameters in the large language model.

[0105] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 7As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for generating a smart contract summary based on a large language model and semantic enhancement is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a key, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.

[0106] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0107] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the steps of a method for generating a smart contract summary based on a large language model and semantic enhancement are implemented.

[0108] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of a method for generating a smart contract summary based on a large language model and semantic enhancement are implemented.

[0109] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0110] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0111] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.

Claims

1. A method for generating smart contract summaries based on a large language model and semantic enhancement, characterized in that: The method comprises: Obtaining the smart contract source code, parsing the smart contract source code, and generating an abstract syntax tree; Extracting code semantic information in the smart contract source code from the abstract syntax tree; Traversing the abstract syntax tree, converting the smart contract source code into a function callback graph, and saving the function callback graph and the code semantic information in a code sample database; Determine a target code segment, and search the code sample database for target code semantic information and a target function callback graph that are closest to the target code segment; The source code of the target code snippet, the target code semantic information, and the target function callback graph are input into a large language model, and the data output by the large language model is parsed to obtain and output a summary corresponding to the target code snippet.

2. The method for generating a smart contract summary based on a large language model and semantic enhancement according to claim 1, characterized in that: Parse the smart contract source code to generate an abstract syntax tree, including: The solidity_parser tool is used to parse the smart contract source code, and the smart contract or function in the smart contract source code is used as the root node, the statement or expression is used as the internal node, and the variable and constant basic elements are used as the leaf nodes.

3. The method for generating a smart contract summary based on a large language model and semantic enhancement according to claim 1, characterized in that: The code semantic information includes: contract member variables, contract type, contract function, function name, function declaration, inline function, and function callback.

4. The method for generating a smart contract summary based on a large language model and semantic enhancement according to claim 1, characterized in that: The traversing the abstract syntax tree to convert the smart contract source code into a function callback graph includes: Traversing each contract node in the abstract syntax tree, traversing the function node in each contract node, and traversing the function callback node in each function node; After traversing all the function callback nodes, a function callback tree is obtained; Traversing each of the function callback nodes in the function callback tree to obtain callback information corresponding to each of the function callback nodes; A vectorless function callback graph is obtained based on the callback information.

5. The method for generating a smart contract summary based on a large language model and semantic enhancement according to claim 4, characterized in that: The method further comprises: Use graphviz to describe the callback information corresponding to the function callback node; The function callback node after describing the callback information is saved in an unordered sequence of non-repeating elements; Each of the function callback nodes in the function callback tree is traversed, and node search is performed in the non-repeating element sequence until the function callback tree is completely traversed to obtain a vectorless function callback graph.

6. The method for generating a smart contract summary based on a large language model and semantic enhancement according to claim 1, characterized in that: The determining of the target code snippet and searching the code sample database for target code semantic information and a target function callback graph closest to the target code snippet include: Vectorizing the target code fragment to obtain an input matching vector; Read all function codes in the code sample database, and convert each function code into a function code vector list; Matching the input matching vector with the function code vector list, and outputting a target number corresponding to the function code vector closest to the input matching vector; The target code semantic information and the target function callback graph are read from the code sample database according to the target number.

7. The method for generating a smart contract summary based on a large language model and semantic enhancement according to claim 1, characterized in that: The training process of the large language model includes: Determine sample code semantic information and sample function callback graph, and input the sample code semantic information and sample function callback graph into a large language model; The target code semantic information and the target function callback graph are used as learning objects to adjust the parameters in the large language model.

8. A smart contract summary generation system based on a large language model and semantic enhancement, characterized in that: The system comprises: An abstract syntax tree generation module is used to obtain the smart contract source code, parse the smart contract source code, and generate an abstract syntax tree; An information extraction module, used to extract code semantic information in the smart contract source code from the abstract syntax tree; A data storage module, used to traverse the abstract syntax tree, convert the smart contract source code into a function callback graph, and save the function callback graph and the code semantic information in a code sample database; A search module, used to determine a target code segment, and search the code sample database for target code semantic information and a target function callback graph that are closest to the target code segment; The summary generation module is used to input the source code of the target code fragment, the target code semantic information, and the target function callback graph into the large language model, parse the data output by the large language model, obtain the summary corresponding to the target code fragment, and output it.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.