Code annotation inconsistency detection method based on large model and related device thereof
Through the large-model-based code annotation inconsistency detection method, combined with text cleaning, mixed prompt binary classification and BiLSTM neural network, the semantic ambiguity problem in code annotation detection is solved, more accurate annotation consistency recognition is achieved, and the security of smart contracts is improved.
Patent Information
- Application Number
- CN202510556683.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-29
- Publication Date
- 2025-08-01
AI Technical Summary
Existing code annotation detection methods cannot accurately match the annotation text, and there are semantic ambiguity, resulting in misjudgment.
The code annotation inconsistency detection method based on large models is used to identify consistently through text cleaning, labeling, mixing prompt binary classification, extracting relevant source code snippets, fine-tuning pre-trained models and BiLSTM neural networks to avoid semantic ambiguity.
Improve the accuracy of code annotation detection, avoid misjudgment, and enhance the reliability of smart contracts.
Smart Images

Figure CN120408619A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of blockchain, and particularly to a method and related device for detecting inconsistent code annotations based on a large model. Background Art
[0002] Smart contracts are usually written in high-level programming languages, and then these high-level language codes are compiled into bytecodes that can be recognized and executed by virtual machines. After a smart contract is deployed on the blockchain, generally it cannot be modified and will execute automatically according to the pre-set logic without being able to be stopped midway. This is determined by the immutable and decentralized characteristics of the blockchain. Given that smart contracts often involve financial assets, have high liquidity, and transactions are irreversible once executed, developers will design specific constraint conditions in the code to reduce the risk of being attacked. Annotations in smart contracts can provide security guidance, especially in key aspects such as access control. Inconsistencies between annotations and code may cause misunderstandings for developers or auditors, thereby reducing the reliability of smart contracts.
[0003] The code annotation detection method based on semantic patterns cannot accurately match annotation texts. At the same time, some entities in the annotations have semantic ambiguities and are prone to misjudgment when performing similarity analysis with code facts. Summary of the Invention
[0004] The present invention provides a method and related device for detecting inconsistent code annotations based on a large model, which are used to solve the technical problems that existing code annotation detection methods cannot accurately match annotation texts and some entities in the annotations have semantic ambiguities and are prone to misjudgment when performing similarity analysis with code facts.
[0005] In view of this, the first aspect of the present invention provides a method for detecting inconsistent code annotations based on a large model, including:
[0006] Extract code annotations from the smart contract dataset and perform text cleaning on the code annotations;
[0007] Annotate code annotations of the target type;
[0008] Perform binary classification on the code annotations of the target type based on hybrid prompts, mark the code annotations belonging to the target type as 1, and mark the code annotations not belonging to the target type as 0;
[0009] Obtain the corresponding functions of the code annotations of the target type, and extract relevant source code fragments based on the corresponding functions;
[0010] Store the relevant information of the code comments of the target type as a set of tuples. The relevant information of the code comments of the target type includes the contract address, the code comments of the target type, the function name of the code comments of the target type, and the relevant source code of the code comments of the target type.
[0011] Perform consistency recognition based on the annotation-code pairs of the tuples.
[0012] Fine-tune the pre-trained code generation model with the annotation-code pairs that are identified as consistent based on the annotation-code consistency recognition result. The output result of the pre-trained code generation model is the context embedding vector.
[0013] Input the context embedding vector output by the pre-trained code generation model into the BiLSTM neural network model for inconsistent classification to obtain the code comment inconsistency detection result.
[0014] Optionally, the pre-trained code generation model is CodeT5 or CodeBERT.
[0015] Optionally, the code comments of the target type are permission-related code comments.
[0016] Optionally, obtain the corresponding function of the code comments of the target type, and extract the relevant source code fragments based on the corresponding function, including:
[0017] Convert the contract code into an abstract syntax tree, and obtain the start position and end position of the implementation function from the function list of the abstract syntax tree of the contract where the code comments of the target type are located;
[0018] Extract the source code fragment of the implementation function from the source code based on the start position and end position of the implementation function;
[0019] Extract the source code fragments of the calling function and the modifier function from the source code according to the calling function node and the modifier function node of the implementation function in the abstract syntax tree.
[0020] Optionally, perform text cleaning on the code comments, including:
[0021] Filter out irrelevant sentences in the code comments;
[0022] Remove the stop words in the natural language toolkit stop word list and supplement the required characters.
[0023] The second aspect of the present invention provides a code comment inconsistency detection device based on a large model, including: [[ID=S40]]
[0024] A code comment extraction module, configured to extract code comments from the smart contract dataset and perform text cleaning on the code comments;
[0025] Annotation module for annotating code comments of the target type;
[0026] Hybrid prompt binary classification module for binary classifying code comments of the target type based on hybrid prompts, marking code comments belonging to the target type as 1 and those not belonging to the target type as 0;
[0027] Function code extraction module for obtaining the corresponding function of the code comment of the target type and extracting relevant source code snippets based on the corresponding function;
[0028] Storage module for storing relevant information of code comments of the target type as a set of tuples, where the relevant information of code comments of the target type includes contract address, code comments of the target type, function name of the code comments of the target type, and relevant source code of the code comments of the target type;
[0029] Consistency recognition module for performing consistency recognition on annotation-code pairs based on the tuples;
[0030] Fine-tuning module for fine-tuning the pre-trained code generation model with annotation-code pairs whose annotation-code consistency recognition results are consistent. The output result of the pre-trained code generation model is the context embedding vector;
[0031] Result output module for inputting the context embedding vector output by the pre-trained code generation model into the BiLSTM neural network model for inconsistent classification to obtain the code comment inconsistency detection result.
[0032] Optionally, the function code extraction module is specifically used for:
[0033] Converting the contract code into an abstract syntax tree, and obtaining the start position and end position of the implementation function from the function list of the abstract syntax tree of the contract where the code comment of the target type is located;
[0034] Based on the start position and end position of the implementation function, extracting the source code snippet of the implementation function from the source code;
[0035] According to the call function node and modifier function node of the implementation function in the abstract syntax tree, extracting the source code snippets of the call function and modifier function from the source code.
[0036] Optionally, the pre-trained code generation model is CodeT5 or CodeBERT.
[0037] Optionally, the code comments of the target type are permission-related code comments.
[0038] Optionally, the code comment extraction module is specifically used for:
[0039] Extract code comments from the smart contract dataset;
[0040] Filter out irrelevant sentences in the code comments;
[0041] Remove stop words in the natural language toolkit stop word list and supplement necessary characters.
[0042] The third aspect of the present invention provides a device for detecting code comment inconsistencies based on a large model, the device includes a processor and a memory:
[0043] The memory is used to store program code and transmit the program code to the processor;
[0044] The processor is used to execute any of the methods for detecting code comment inconsistencies based on a large model described in the first aspect according to the instructions in the program code.
[0045] The fourth aspect of the present invention provides a computer-readable storage medium, the computer-readable storage medium is used to store program code, and the program code is used to execute any of the methods for detecting code comment inconsistencies based on a large model described in the first aspect.
[0046] From the above technical solutions, it can be seen that the method for detecting code comment inconsistencies based on a large model provided by the present invention has the following advantages:
[0047] The method for detecting code comment inconsistencies based on a large model provided by the present invention combines a binary classification method with hybrid prompts to screen code comments of target types in smart contracts, can better identify based on semantics rather than syntactic forms, then extract the corresponding functions of the code comments of the target type, obtain the source code fragments related to the corresponding functions to perform consistency identification on the annotation-code pairs. After fine-tuning the pre-trained code generation model with the annotation-code pairs whose consistency identification results are consistent, the pre-trained code generation model learns the association between annotations and code to obtain the code comment inconsistency detection result, avoiding the ambiguity problem, and solving the technical problem that the existing code comment detection methods cannot accurately match the annotation text and are prone to misjudgment when performing similarity analysis with the code facts due to semantic ambiguity of some annotation entities. Description of the Drawings
[0048] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required to be used in the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, other related drawings can be obtained based on these drawings without creative efforts.
[0049] Figure 1Schematic flowchart of a method for detecting inconsistent code annotations based on a large model provided in an embodiment of the present invention;
[0050] Figure 2 Method framework diagram for binary classification based on hybrid prompts provided in an embodiment of the present invention;
[0051] Figure 3 Overall process block diagram of a method for detecting inconsistent code annotations based on a large model provided in an embodiment of the present invention;
[0052] Figure 4 Schematic structural diagram of a device for detecting inconsistent code annotations based on a large model provided in an embodiment of the present invention;
[0053] Figure 5 Schematic structural diagram of a device for detecting inconsistent code annotations based on a large model provided in an embodiment of the present invention. Detailed implementation manners
[0054] In order to enable those skilled in the art to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0055] For ease of understanding, please refer to Figure 1 , the present invention provides an embodiment of a method for detecting inconsistent code annotations based on a large model, including:
[0056] Step 101: Extract code annotations from the smart contract dataset and perform text cleaning on the code annotations.
[0057] It should be noted that in the embodiment of the present invention, code annotations are first extracted from the sorted smart contract dataset. For the collected code annotations, irrelevant information is removed through text cleaning, which helps to reduce noise data and facilitates subsequent analysis. Finally, a series of line records containing contract addresses, function names, and annotations can be obtained.
[0058] In a smart contract, single-line comments start with " / / ", while multi-line comments start with " / **" and end with "* / ", and each line starts with the "*" symbol. According to the comment format, different regular strategies are used to extract them respectively, and the comments at the same position (for example, the same function, the same contract, and the same code statement) are concatenated into one line. At the same time, a function-level comment is selected through a lexical parser, which can associate the function with its corresponding comment based on the position where the function is located.
[0059] For text cleaning, on the one hand, irrelevant sentences, including calculation formulas, meaningless patterns, file paths, version settings, etc., will be filtered; on the other hand, stop words in the Natural Language Toolkit (NLTK) stop word list and unimportant characters, including comment symbols and NatSpec tags (e.g., @param, @dev, and @notice), will be removed.
[0060] Step 102: Annotate the code comments of the target type.
[0061] It should be noted that the target type of the code comments is first clarified. In the embodiments of the present invention, the target type of the code comments is code comments related to permissions. The code comments are annotated according to whether they are related to permissions. For example, comments that specify function call permissions such as "Allow owner to execute this function" will be annotated as 1. Since some permission subjects (such as "user" and "everyone") are of general significance, this situation is regarded as having no specific permissions, and other comments that are obviously not related to permissions are annotated as 0.
[0062] Step 103: Perform binary classification on the code comments of the target type based on the mixed prompt, mark the code comments belonging to the target type as 1, and mark the code comments not belonging to the target type as 0.
[0063] It should be noted that the core of prompt learning is to establish a mapping function. For any input text x, x is transformed into a new form x'.
[0064]
[0065] This method transforms the downstream task into a modeling problem of the language model. In the few-shot or even zero-shot scenario, prompt learning can utilize the existing knowledge and generalization ability of the language model, and by designing appropriate prompts to guide the model to generate outputs that meet the task requirements, thereby achieving better performance. The methods for constructing the form of prompt learning are divided into two ways: manual and automated.
[0066] Manually constructing a prompt template means that researchers manually design a fill-in-the-blank prompt template and efficiently complete the downstream task based on the prior knowledge mastered by the pre-trained model. This method can generate a large number of different templates, which have different effects on the performance of the model, and must be selected through continuous experiments.
[0067] Automated construction prompt templates are divided into discrete and continuous types. The discrete method generates multiple prompt templates through a target pre-trained language model, presented in the form of discrete strings. The continuous method allows non-natural language forms and uses the model to learn to generate continuous prompts to predict hidden characters and the labels of prediction samples.
[0068] Hard templates have defects such as high cost, poor flexibility, and unstable effects. To achieve a higher classification accuracy than hard templates and traditional fine-tuning methods, in the embodiments of the present invention, predefined hard templates containing domain-specific expertise are transformed into mixed templates, and the text classification task is regarded as a masked language problem. As Figure 2 shown, the mixed template contains continuous tokens and discrete tokens, where the discrete tokens are fixed natural language texts, equivalent to "initialization points", and the continuous tokens are vector representations, propagated and optimized during training and fixed during inference. The present invention uses two construction strategies for continuous tokens.
[0069] The SOFTEN construction strategy treats the tokens in the hard template as continuously optimizable. Keeping words such as "permission" and "classify" in the hard template without optimization can effectively alleviate the problem of catastrophic forgetting in language model fine-tuning.
[0070] The LINK construction strategy concatenates continuously optimizable tokens to the original hard template and initializes the additional continuous tokens using a random initialization method.
[0071] Step 104: Obtain the corresponding function of the code annotation of the target type, and extract relevant source code fragments based on the corresponding function.
[0072] It should be noted that for the code comments of each target type, compilation techniques are used to extract the matching implementation functions and the functions and modifier functions they call. Specifically, the compilation tool converts the contract code into an abstract syntax tree to access the relevant AST (Abstract Syntax Tree) nodes. First, the start and end positions of the function are obtained from the function list of the abstract syntax tree of the contract where the comment is located, and then the implementation function is extracted from the source code. According to the call function nodes and modifier function nodes of the function in the abstract syntax tree, the relevant source code fragments are extracted in the same way. The AST is a tree-like representation of the abstract syntax structure of the source code, showing the hierarchy and logical relationships of the code in the form of a tree. When the program performs operations such as analyzing, transforming, and optimizing the code, it is much easier to directly process the AST than the original text. During the process of generating the AST, lexical analysis is first performed on the source code to break it down into individual lexical units, such as variables, keywords, operators, etc. Then, these lexical units are organized into a tree structure according to the grammar rules. Each node in the tree represents a grammar structure or a lexical unit, and the relationships between the nodes reflect the grammar rules and logical order of the code.
[0073] Step 105: Store the relevant information of the code comments of the target type as a set of tuples. The relevant information of the code comments of the target type includes the contract address, the code comments of the target type, the function name of the code comments of the target type, and the relevant source code of the code comments of the target type.
[0074] It should be noted that the relevant information is stored as a set of tuples, and the form of each tuple is (ct, p, f, cd), where ct is the contract address, p is the permission comment, f is the function name of the comment, and cd is the relevant code of the comment.
[0075] Step 106: Perform consistency identification on the annotation-code pairs based on the tuples.
[0076] It should be noted that the consistency identification of the annotation-code pair is whether the annotation and the code correspond and are consistent. The annotation-code pair is labeled according to whether it is consistent in the distribution of the code comments of the target type. The result of the label depends on whether the conditional statement in the function or modifier contains a consistent caller check, or whether restrictions are made using the Roles array of the Solidity module library. If it is consistent, it is labeled as 0, otherwise it is labeled as 1.
[0077] Step 107: Fine-tune the pre-trained code generation model with the annotation-code pairs whose consistency identification results are consistent. The output result of the pre-trained code generation model is the context embedding vector.
[0078] It should be noted that by inputting a sequence in the form of "[CLS] Code annotation of the target type [SEP] Implementation code [EOS]" to fine-tune the pre-trained code generation model, this task can quickly adapt to the knowledge of the pre-trained model to learn the code semantics of annotations, function structures, and the relationships between them, and finally output context embedding vectors. Based on the analysis and processing of the pre-trained code generation model, various forms of permission code constraints can be covered. Fine-tuning means further training the model with supervised data on the basis of the pre-trained BERT model according to specific downstream tasks (such as text classification, named entity recognition, question answering systems, etc.). Taking the text classification task as an example, the pre-trained BERT model already has a good understanding of the general features of language. During fine-tuning, task-related text data is input into the BERT model to obtain the feature representation of the text, and then by adding one or more layers adapted to the downstream task (such as a fully connected layer), the parameters of the model are adjusted so that it can better complete specific tasks, such as determining whether the text belongs to a certain category.
[0079] In one embodiment, the pre-trained code generation model is CodeT5 or CodeBERT. CodeT5 is a model built based on the encoder-decoder Transformer architecture. CodeT5 adopts a new token-aware objective. In code processing, identifiers (such as variable names, function names, etc.) carry important semantic information. Through this new objective, the model can effectively distinguish whether a code token is an identifier, thereby better understanding the structure and semantics of the code. CodeT5 utilizes a dual-generation task and uses annotated code pairs to improve the alignment between natural language and programming language. BERT (Bidirectional Encoder Representations from Transformers) is a multi-layer bidirectional encoder built based on the Transformer architecture. The multi-head self-attention mechanism in Transformer enables the model to consider information at different positions in the input sequence simultaneously, thus achieving bidirectional context understanding. The BERT model mainly has two pre-training tasks, namely masked language model and next sentence prediction. During the pre-training stage, BERT uses a large-scale unsupervised corpus, and the Wikipedia corpus is one of the commonly used training data sources. An important advantage of BERT is that it can be fine-tuned for specific downstream tasks, such as text classification, named entity recognition, question answering systems, etc.
[0080] Step 108: Input the context embedding vector output by the pre-trained code generation model into the BiLSTM neural network model for inconsistent classification to obtain the code annotation inconsistency detection result.
[0081] It should be noted that after the above processing, the obtained context embedding vectors are input into the BiLSTM neural network model, and the BiLSTM layer is used for inconsistency classification, and finally the code comment inconsistency detection results are output. When traditional recurrent neural networks (RNNs) process long sequences, they face the problems of vanishing gradients or exploding gradients, making it difficult to capture long-term dependencies in the sequences. Long short-term memory (LSTM), as a special type of RNN, introduces a memory cell (cell state) and a gating mechanism. The memory cell saves and transmits information throughout the sequence processing, and the gating mechanism consists of an update gate, a forget gate, and an output gate. Through the coordinated work of these three gates, the LSTM can flexibly control the state of the memory cell and the flow of information. The bidirectional long short-term memory network (BiLSTM) is an extension based on the LSTM. It runs two independent LSTM networks at each time step and utilizes both the past and future information of the sequence.
[0082] The embodiment of the present invention processes based on the prompting learning method of the large language model, and extracts permission-related annotations without being restricted by semantic templates.
[0083] The overall process block diagram of the code comment inconsistency detection method based on the large model provided in the embodiment of the present invention is as Figure 3 shown. Generally, it is divided into two stages. In the first stage, data collection and permission annotation recognition are completed. It is identified whether the code comment is of the type to be inspected, and permission-related annotations can be extracted without being restricted by semantic templates. Specifically, the code comments in the smart contract are preprocessed, and the preprocessing includes text cleaning, deleting and marking duplicate data. Then, a hybrid prompting method is used to classify the preprocessed annotations according to whether they are permission-related. In the second stage, the consistency between the annotations and the code is checked. Through compilation technology, the code file is parsed into an abstract syntax tree (AST) to extract codes such as matching functions, called functions, and modifiers; then a code structure tree with call relationships is constructed and connected to the code comments of the corresponding target type; based on the structure tree of the function call relationships, the complex code implementations in the permission problems can be extracted, and the semantic similarity between the annotations and the code can be analyzed, enhancing interpretability. Finally, the context embedding vectors are obtained by using the training code generation model, and the BiLSTM is used to determine whether the code and the annotations are consistent, completing the detection of the inconsistency between the permission annotations and the code.
[0084] The method for detecting inconsistent code comments based on a large model provided by the present invention combines a binary classification method with hybrid prompts to screen the code comments of the target type in the smart contract, can better identify based on semantics rather than syntactic form, then extract the corresponding functions of the code comments of the target type, obtain the source code fragments related to the corresponding functions to perform consistency identification on the annotation-code pairs. After fine-tuning the pre-trained code generation model with the annotation-code pairs whose consistency identification results are consistent, the pre-trained code generation model learns the association between the annotations and the code, and obtains the code comment inconsistent detection result, avoiding the ambiguity problem and solving the technical problems that the existing code comment detection methods cannot accurately match the annotation text and are prone to misjudgment when performing similarity analysis with the code facts due to semantic ambiguity of some entities in the annotations.
[0085] For ease of understanding, please refer to Figure 4 , an embodiment of a device for detecting inconsistent code comments based on a large model provided in the present invention includes:
[0086] A code comment extraction module, configured to extract code comments from the smart contract dataset and perform text cleaning on the code comments;
[0087] A labeling module, configured to label the code comments of the target type;
[0088] A hybrid prompt binary classification module, configured to perform binary classification on the code comments of the target type based on the hybrid prompts, mark the code comments belonging to the target type as 1, and mark the code comments not belonging to the target type as 0;
[0089] A function code extraction module, configured to obtain the corresponding functions of the code comments of the target type and extract the relevant source code fragments based on the corresponding functions;
[0090] A storage module, configured to store the relevant information of the code comments of the target type as a group of tuples, and the relevant information of the code comments of the target type includes the contract address, the code comments of the target type, the function name of the code comments of the target type, and the relevant source code of the code comments of the target type;
[0091] A consistency identification module, configured to perform consistency identification on the annotation-code pairs based on the tuples;
[0092] A fine-tuning module, configured to fine-tune the pre-trained code generation model with the annotation-code pairs whose annotation-code consistency identification results are consistent, and the output result of the pre-trained code generation model is the context embedding vector;
[0093] A result output module, configured to input the context embedding vector output by the pre-trained code generation model into the BiLSTM neural network model for inconsistent classification to obtain the code comment inconsistent detection result.
[0094] In one embodiment, the function code extraction module is specifically configured to:
[0095] Convert the contract code into an abstract syntax tree, and obtain the start position and end position of the implementation function from the function list of the abstract syntax tree of the contract where the code comment of the target type is located;
[0096] Extract the source code fragment of the implementation function from the source code based on the start position and end position of the implementation function;
[0097] Extract the source code fragments of the calling function and the modifier function from the source code according to the calling function node and the modifier function node of the implementation function in the abstract syntax tree.
[0098] In one embodiment, the pre-trained code generation model is CodeT5 or CodeBERT.
[0099] In one embodiment, the code comment of the target type is a code comment related to permissions.
[0100] In one embodiment, the code comment extraction module is specifically configured to:
[0101] Extract code comments from the smart contract dataset;
[0102] Filter out irrelevant sentences in the code comments;
[0103] Remove the stop words in the natural language toolkit stop word list and supplement the required characters.
[0104] For ease of understanding, please refer to Figure 5 , an embodiment of a code comment inconsistency detection device based on a large model is provided in the present invention. The device includes a processor and a memory:
[0105] The memory is used to store program code and transmit the program code to the processor;
[0106] The processor is configured to execute any one of the code comment inconsistency detection methods in the embodiments of the code comment inconsistency detection methods based on a large model provided in the present invention according to the instructions in the program code.
[0107] An embodiment of a computer-readable storage medium is also provided in the present invention. The computer-readable storage medium is used to store program code, and the program code is used to execute any one of the code comment inconsistency detection methods in the embodiments of the permission vulnerability detection methods based on a large model provided in the present invention.
[0108] The privilege vulnerability detection device, equipment, and computer-readable storage medium provided in the present invention are all used to execute the privilege vulnerability detection method based on a large model provided in the present invention. Their principles and achieved technical effects are the same as those of the privilege vulnerability detection method based on a large model provided in the present invention, and will not be elaborated here.
[0109] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for detecting inconsistent code comments based on a large model, characterized in that, Including: Extract code comments from the smart contract dataset and clean the text of the code comments; Annotate the code comments of the target type; Perform binary classification on the code comments of the target type based on mixed prompts, mark the code comments belonging to the target type as 1, and mark the code comments not belonging to the target type as 0; Obtain the corresponding functions of the code comments of the target type, and extract relevant source code fragments based on the corresponding functions; Store the relevant information of the code comments of the target type as a set of tuples. The relevant information of the code comments of the target type includes contract address, code comments of the target type, function name of the code comments of the target type, and relevant source code of the code comments of the target type; Perform consistency identification on the annotation-code pairs based on the tuples; Fine-tune the pre-trained code generation model with the annotation-code pairs whose consistency identification results are consistent. The output result of the pre-trained code generation model is the context embedding vector; Input the context embedding vector output by the pre-trained code generation model into the BiLSTM neural network model for inconsistent classification to obtain the code comment inconsistency detection result.
2. The method for detecting inconsistent code annotations based on a large model according to claim 1, wherein The pre-trained code generation model is CodeT5 or CodeBERT.
3. The method for detecting inconsistent code annotations based on a large model according to claim 1, wherein The code comments of the target type are permission-related code comments.
4. The method for detecting inconsistent code annotations based on a large model according to claim 1, characterized in that Obtain the corresponding functions of the code comments of the target type, and extract relevant source code fragments based on the corresponding functions, including: Convert the contract code into an abstract syntax tree, and obtain the start position and end position of the implementation function from the function list of the abstract syntax tree of the contract where the code comments of the target type are located; Extract the source code fragment of the implementation function from the source code based on the start position and end position of the implementation function; Extract the source code fragments of the calling function and the modifier function from the source code according to the calling function node and the modifier function node of the implementation function in the abstract syntax tree.
5. The method for detecting inconsistent code annotations based on a large model according to claim 1, wherein Clean the text of the code comments, including: Filter out irrelevant sentences in the code comments; Remove the stop words in the natural language toolkit stop word list and supplement the required characters.
6. An apparatus for detecting inconsistent code comments based on a large model, characterized in that, Including: Code comment extraction module, used to extract code comments from the smart contract dataset and clean the text of the code comments; Annotation module, used to annotate the code comments of the target type; Mixed prompt binary classification module, used to perform binary classification on the code comments of the target type based on mixed prompts, mark the code comments belonging to the target type as 1, and mark the code comments not belonging to the target type as 0; Function code extraction module, used to obtain the corresponding functions of the code comments of the target type and extract relevant source code fragments based on the corresponding functions; Storage module, used to store the relevant information of the code comments of the target type as a set of tuples. The relevant information of the code comments of the target type includes contract address, code comments of the target type, function name of the code comments of the target type, and relevant source code of the code comments of the target type; Consistency identification module, used to perform consistency identification on the annotation-code pairs based on the tuples; A fine-tuning module, which is used to fine-tune a pre-trained code generation model for the input annotation-code pairs with consistent annotation-code consistency recognition results, and the output result of the pre-trained code generation model is a context embedding vector; A result output module, which is used to input the context embedding vector output by the pre-trained code generation model into a BiLSTM neural network model for inconsistent classification to obtain a code annotation inconsistency detection result.
7. The code comment inconsistency detection device based on a large model according to claim 6, wherein The function code extraction module is specifically used for: Converting the contract code into an abstract syntax tree, and obtaining the start position and end position of the implementation function from the function list of the abstract syntax tree of the contract where the code annotation of the target type is located; Based on the start position and end position of the implementation function, extracting the source code fragment of the implementation function from the source code; According to the call function node and modifier function node of the implementation function in the abstract syntax tree, extracting the source code fragments of the call function and modifier function from the source code.
8. The code annotation inconsistency detection device based on a large model according to claim 6, wherein The pre-trained code generation model is CodeT5 or CodeBERT.
9. An apparatus for detecting inconsistent code comments based on a large model, characterized in that, The device includes a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is used to execute the large model-based code annotation inconsistency detection method according to any one of claims 1-5 based on the instructions in the program code.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store program code, and the program code is used to execute the large model-based code annotation inconsistency detection method according to any one of claims 1-5.