Code vulnerability detection large model construction method, device and electronic device

By reducing the accuracy of symbolic calculation algorithms and using noise transfer matrices, combined with large language model training, the problem of difficulty in balancing computational complexity and vulnerability detection effects in the existing technology is solved, and vulnerability detection with high accuracy and interpretability is achieved.

CN118171291BActive Publication Date: 2024-09-20PEKING UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410595002.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-14
Publication Date
2024-09-20
Estimated Expiration
2044-05-14

AI Technical Summary

Technical Problem

Existing code vulnerability detection methods are difficult to take into account the vulnerability detection effect when reducing computational complexity, and the training process based on deep learning models is uninterpretable.

Method used

By reducing the accuracy of the preset symbol calculation algorithm, the noise transfer matrix process is used to reduce the computational complexity, and a large language model is trained based on the initial vulnerability detection results and the noise transfer matrix to ensure the accuracy and interpretability of vulnerability detection.

Benefits of technology

It achieves vulnerability detection that maintains high accuracy while reducing computational complexity, and the training process is interpretable.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118171291B
    Figure CN118171291B
Patent Text Reader

Abstract

The present invention provides a method, device and electronic device for constructing a large model for code vulnerability detection, and relates to the field of computer technology. The method includes: performing a first round of training on an initial large language model based on vulnerability repair information to obtain a first large language model; optimizing the first large language model based on a reward function to obtain a second large language model; analyzing a value dependency graph corresponding to each preset code to determine an initial vulnerability detection result corresponding to the preset code; determining a noise transfer matrix from the initial vulnerability detection result to the vulnerability labeling result based on the initial vulnerability detection result and the vulnerability labeling result corresponding to the preset code; generating second prompt words corresponding to each preset code based on the initial vulnerability detection result and the noise transfer matrix corresponding to each preset code, and training the second large language model based on each second prompt word to obtain a target large language model. The technical solution of the present invention can reduce the complexity of calculation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, device and electronic device for constructing a large model for code vulnerability detection. Background Art

[0002] Code vulnerability detection is an important part of ensuring software security.

[0003] Existing code vulnerability detection methods include vulnerability detection methods based on symbolic execution technology and vulnerability detection methods based on deep learning models. The vulnerability detection method based on symbolic execution technology replaces code input with symbolic variables, the driver simulates the code execution process, collects the execution path constraint set, solves the constraint set through the solver, and finally finds code vulnerabilities. The vulnerability detection method based on deep learning models first constructs a vulnerability detection dataset, and then trains the deep learning model based on the vulnerability detection dataset, and detects code vulnerabilities through the trained deep learning model.

[0004] When vulnerability detection methods based on symbolic execution technology are needed for accurate vulnerability detection, the computational complexity is high; if the computational complexity is reduced, it is difficult to obtain an accurate solution, resulting in poor vulnerability detection results. In vulnerability detection methods based on deep learning models, the process of training deep learning models is unexplainable. Summary of the invention

[0005] The present invention provides a method, device and electronic device for constructing a large model for code vulnerability detection, which is used to solve the defects in the prior art that it is difficult to simultaneously reduce the computational complexity and improve the vulnerability detection effect, or that the difficulty of verifying and analyzing the vulnerability detection results is increased. The technical solution of the present invention can reduce the accuracy of the preset symbol calculation algorithm to reduce the computational complexity, and through the subsequent process of determining the noise transfer matrix, while reducing the computational complexity, ensure that the target large language model has a high accuracy rate for vulnerability detection. And because the target large language model is obtained by training based on the initial vulnerability detection results and the noise transfer matrix corresponding to each preset code, its training process is interpretable.

[0006] The present invention provides a method for constructing a large model for code vulnerability detection, comprising:

[0007] Generate a first prompt word based on the vulnerability repair information in the preset code submission information, and perform a first round of training on the initial large language model based on the first prompt word to obtain a first large language model; the vulnerability repair information includes: code before the vulnerability repair, code after the vulnerability repair, and vulnerability repair description information;

[0008] Iteratively optimizing the first largest language model based on a reward function corresponding to the first largest language model to obtain a second largest language model, wherein the reward function is determined based on the preset code submission information;

[0009] For each preset code, a value dependency graph corresponding to the preset code is analyzed by a preset symbol calculation algorithm to determine an initial vulnerability detection result corresponding to the preset code;

[0010] For each of the preset codes, based on the initial vulnerability detection result and the vulnerability annotation result corresponding to the preset code, determine a noise transfer matrix from the initial vulnerability detection result to the vulnerability annotation result through the second largest language model;

[0011] Based on the initial vulnerability detection results and the noise transfer matrix corresponding to each of the preset codes, the second prompt words corresponding to each of the preset codes are generated, and the second large language model is trained based on each of the second prompt words to obtain the target large language model.

[0012] According to a method for constructing a large model for code vulnerability detection provided by the present invention, the first large language model is iteratively optimized based on a reward function corresponding to the first large language model to obtain a second large language model, including:

[0013] Training an initial classification model based on the historical modification records in the preset code submission information to obtain a reward model, wherein the historical modification records include the vulnerability repair information;

[0014] The first largest language model is iteratively optimized using the reward model as a reward function to obtain a second largest language model.

[0015] According to a method for constructing a large model for code vulnerability detection provided by the present invention, the initial classification model is trained based on the historical modification records in the preset code submission information to obtain a reward model, including:

[0016] Acquire a preset number of historical modification records of codes in the preset code submission information, wherein each modification record in the historical modification records is arranged in chronological order;

[0017] Based on the historical modification records of the preset number of codes, the initial classification model is trained to obtain the reward model.

[0018] According to a method for constructing a large model for code vulnerability detection provided by the present invention, the value dependency graph corresponding to the preset code is analyzed by a preset symbol calculation algorithm to determine an initial vulnerability detection result corresponding to the preset code, including:

[0019] Constructing a value dependency graph corresponding to the preset code based on the variables and selection statements in the preset code;

[0020] The value dependency graph is statically analyzed based on the preset symbolic calculation algorithm to determine an initial vulnerability detection result corresponding to the preset code.

[0021] According to a method for constructing a large model for code vulnerability detection provided by the present invention, the method of constructing a value dependency graph corresponding to the preset code based on variables and selection statements in the preset code includes:

[0022] Determine a definition node set based on definition symbols corresponding to each of the variables, and determine a use node set based on values ​​corresponding to each of the variables;

[0023] Determine a mapping relationship from the definition node set to the use node set;

[0024] Determine the guard constraint expression corresponding to the mapping relationship based on each of the selection statements;

[0025] Determine a selection statement set based on each of the selection statements;

[0026] A value dependency graph corresponding to the preset code is constructed based on the definition node set, the use node set, the mapping relationship, the guard constraint expression and the selection statement set.

[0027] According to a method for constructing a code vulnerability detection large model provided by the present invention, the second large language model is trained based on each of the second prompt words to obtain a target large language model, including:

[0028] The second large language model is iteratively trained based on each of the second prompt words, and the parameters of the second large language model are optimized based on a cross entropy loss function to obtain the target large language model.

[0029] The present invention also provides a device for constructing a large model for code vulnerability detection, comprising:

[0030] A training module, configured to generate a first prompt word based on vulnerability repair information in preset code submission information, and perform a first round of training on an initial large language model based on the first prompt word to obtain a first large language model; the vulnerability repair information includes: code before the vulnerability repair, code after the vulnerability repair, and vulnerability repair description information;

[0031] an optimization module, configured to iteratively optimize the first largest language model based on a reward function corresponding to the first largest language model to obtain a second largest language model, wherein the reward function is determined based on the preset code submission information;

[0032] An analysis module, for analyzing a value dependency graph corresponding to each preset code by a preset symbol calculation algorithm, and determining an initial vulnerability detection result corresponding to the preset code;

[0033] A determination module, configured to determine, for each of the preset codes, a noise transfer matrix from the initial vulnerability detection result to the vulnerability annotation result through the second largest language model based on the initial vulnerability detection result and the vulnerability annotation result corresponding to the preset code;

[0034] A generation module is used to generate second prompt words corresponding to each of the preset codes based on the initial vulnerability detection results and the noise transfer matrix corresponding to each of the preset codes, and train the second large language model based on each of the second prompt words to obtain a target large language model.

[0035] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method for constructing a large model for code vulnerability detection as described above is implemented.

[0036] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the method for constructing a large model for code vulnerability detection as described in any of the above is implemented.

[0037] The present invention also provides a computer program product, including a computer program, which, when executed by a processor, implements any of the above-mentioned methods for constructing a large model for code vulnerability detection.

[0038] The method, device and electronic device for constructing a large model for code vulnerability detection provided by the present invention generate a first prompt word based on the vulnerability repair information in the preset code submission information, and then perform a first round of training on the initial large language model based on the first prompt word to obtain the first large language model. The first large language model is further iteratively optimized based on the reward function corresponding to the first large language model to obtain the second large language model. Then, for each preset code, the value dependency graph corresponding to the preset code is analyzed by a preset symbol calculation algorithm to determine the initial vulnerability detection result corresponding to the preset code. Further, for each preset code, based on the initial vulnerability detection result and the vulnerability annotation result corresponding to the preset code, the noise transfer matrix from the initial vulnerability detection result to the vulnerability annotation result is determined by the second large language model. Finally, based on the initial vulnerability detection result and the noise transfer matrix corresponding to each preset code, the second prompt word corresponding to each preset code is generated, and the second large language model is trained based on each second prompt word to obtain the target large language model. The technical solution of the present invention can reduce the accuracy of the preset symbol calculation algorithm to reduce the computational complexity, and through the subsequent process of determining the noise transfer matrix, the target large language model is guaranteed to have a high accuracy rate for vulnerability detection while reducing the computational complexity. And because the target large language model is obtained by training based on the initial vulnerability detection results and noise transfer matrices corresponding to each preset code, its training process is explainable. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0040] Figure 1 It is a flowchart of a method for building a large model for code vulnerability detection provided by an embodiment of the present invention;

[0041] Figure 2 It is a structural diagram of a device for building a large model for code vulnerability detection provided by an embodiment of the present invention;

[0042] Figure 3 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0043] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0044] In view of the problems in the prior art, the present invention provides a method for constructing a large model for code vulnerability detection. Figure 1 : is a flow chart of a method for constructing a large model for code vulnerability detection provided by an embodiment of the present invention, such as Figure 1 As shown, the method for building a large model for code vulnerability detection includes the following steps:

[0045] Step 110: Generate a first prompt word based on the vulnerability repair information in the preset code submission information, perform a first round of training on the initial large language model based on the first prompt word, and obtain a first large language model; the vulnerability repair information includes: code before vulnerability repair, code after vulnerability repair, and vulnerability repair description information.

[0046] Specifically, the preset code submission information may be obtained in advance from the open source code community, and the first prompt word may be generated based on the vulnerability repair information in the preset code submission information. The vulnerability repair information may include the code before the vulnerability repair, the code after the vulnerability repair, and the vulnerability repair description information, and the vulnerability repair description information may include one or more of the information such as the vulnerability type, the vulnerability impact range, and the method of repairing the vulnerability. And the vulnerability repair information may include multiple groups of repair information, wherein a group of repair information may be the repair information corresponding to a modification of a certain code, and a group of repair information may generate a group of prompt words correspondingly, and the generated prompt words may be, for example, the splicing of the code before the vulnerability repair, the code after the vulnerability repair, and the vulnerability repair description information, and all prompt words corresponding to all repair information may constitute the first prompt word. After the first prompt word is generated, all the prompt words in the first prompt word may be sequentially input into the initial large language model to perform a first round of training on the initial large language model to obtain the first large language model. The initial large language model may be, for example, a Wenxin large model, or other large language models, and the embodiment of the present invention is not specifically limited here.

[0047] Step 120: iteratively optimize the first largest language model based on a reward function corresponding to the first largest language model to obtain a second largest language model, wherein the reward function is determined based on the preset code submission information.

[0048] In one embodiment, the iteratively optimizing the first largest language model based on the reward function corresponding to the first largest language model to obtain the second largest language model includes:

[0049] Training an initial classification model based on the historical modification records in the preset code submission information to obtain a reward model, wherein the historical modification records include the vulnerability repair information;

[0050] The first largest language model is iteratively optimized using the reward model as a reward function to obtain a second largest language model.

[0051] Specifically, the initial classification model can be trained based on the historical modification records in the preset code submission information to obtain a reward model. The reward model can then be used as a reward function to iteratively optimize the first language model to obtain an optimized second language model. For example, the code can be input into the first language model to obtain the output detection result of the first language model, and then the output detection result of the first language model can be input into the reward model to obtain the output result of the reward model, and the first language model can be optimized based on the output result of the reward model.

[0052] It is easy to understand that the historical modification record is used to train the initial classification model to obtain a reward model, and the reward model is used to optimize the first language model. Therefore, the historical modification record needs to include the vulnerability repair information in the preset code submission information used to generate the first prompt word. The historical modification record can also include other vulnerability repair information, code refactoring information, new function addition information and function deletion information.

[0053] In the above embodiment, the initial classification model is trained based on the historical modification records in the preset code submission information to obtain a reward model, and then the reward model is used as a reward function to iteratively optimize the first language model to obtain a second language model. The obtained second language model can better understand the low-level semantics of the code.

[0054] In one embodiment, the training of the initial classification model based on the historical modification records in the preset code submission information to obtain the reward model includes:

[0055] Acquire a preset number of historical modification records of codes in the preset code submission information, wherein each modification record in the historical modification records is arranged in chronological order;

[0056] Based on the historical modification records of the preset number of codes, the initial classification model is trained to obtain the reward model.

[0057] Specifically, the historical modification records of a preset number of codes in the preset code submission information can be obtained. It is easy to understand that the historical modification records of the preset number of codes need to include the vulnerability repair information in the preset code submission information that generates the first prompt word. The preset number can be set as needed, and the embodiment of the present invention does not make specific limitations here. Each modification record in the historical modification record is arranged in chronological order. For example, each modification record in the historical modification record of code A can be: repairing the vulnerability at a at 18:18 on August 8, 2023, repairing the vulnerability at b at 20:20 on August 9, 2023, and repairing the vulnerability at c at 16:16 on August 15, 2023... Further, the initial classification model can be trained based on the historical modification records of the preset number of codes to obtain a reward model.

[0058] In the above embodiment, the initial classification model is trained based on the historical modification records in the preset code submission information to obtain a reward model, which lays a foundation for the subsequent iterative optimization of the first language model.

[0059] Step 130: For each preset code, a value dependency graph corresponding to the preset code is analyzed by a preset symbol calculation algorithm to determine an initial vulnerability detection result corresponding to the preset code.

[0060] In one embodiment, analyzing the value dependency graph corresponding to the preset code by a preset symbol calculation algorithm to determine the initial vulnerability detection result corresponding to the preset code includes:

[0061] Constructing a value dependency graph corresponding to the preset code based on the variables and selection statements in the preset code;

[0062] The value dependency graph is statically analyzed based on the preset symbolic calculation algorithm to determine an initial vulnerability detection result corresponding to the preset code.

[0063] Specifically, for each preset code, a value dependency graph corresponding to the preset code can be constructed based on the variables and selection statements in the preset code, and then the value dependency graph can be statically analyzed based on the preset symbolic calculation algorithm to determine the initial vulnerability detection result corresponding to the preset code. A value dependency graph (VDG) is a graphical representation of code that stores the definition and use of variables through nodes, and stores the dependencies and dependency reachability conditions between nodes through directed edges. The preset symbolic calculation algorithm can be a symbolic calculation algorithm based on the value dependency graph.

[0064] In the above embodiment, a value dependency graph corresponding to the preset code is constructed based on the variables and selection statements in the preset code, and the value dependency graph is statically analyzed based on the preset symbol calculation algorithm to determine the initial vulnerability detection result corresponding to the preset code. The initial vulnerability detection result does not require high precision, so the computational complexity of static analysis of the value dependency graph can be reduced, thereby reducing the computational complexity of the method of the present invention.

[0065] In one embodiment, constructing a value dependency graph corresponding to the preset code based on variables and selection statements in the preset code includes:

[0066] Determine a definition node set based on definition symbols corresponding to each of the variables, and determine a use node set based on values ​​corresponding to each of the variables;

[0067] Determine a mapping relationship from the definition node set to the use node set;

[0068] Determine the guard constraint expression corresponding to the mapping relationship based on each of the selection statements;

[0069] Determine a selection statement set based on each of the selection statements;

[0070] A value dependency graph corresponding to the preset code is constructed based on the definition node set, the use node set, the mapping relationship, the guard constraint expression and the selection statement set.

[0071] Specifically, the definition node set can be determined based on the definition symbols corresponding to each variable in the preset code. , the definition node in the definition node can be, for example, or You can also determine the node set to use based on the values ​​corresponding to each variable in the preset code. The use node in the use node set reads the value of the definition node. The form of the use node can be, for example, Or call the function .

[0072] We can further determine the mapping relationship between the definition node set and the use node set. , mapping relationship Characterization , and the mapping also reflects the variable Definition of nodes to variables The dependency relationship between nodes. You can also determine the guard constraint expression corresponding to the mapping relationship based on the selection statement , the guard constraint expression may include Boolean constants, Boolean variables and logical operators. Among them, the Boolean variable represents a selection statement. For example, the guard constraint expression can be obtained from the selection statement of the CFG (Control flow graph) and annotated on the mapping relationship to express the reach relationship between two VFG (value flow graph) nodes.

[0073] Further, the selection statement set can be determined based on each selection statement in the preset code. , where the selection statement can be in the form of if, switch, while, for and do-while, etc.

[0074] Finally, we can define a node collection based on , Use node collection , mapping relationship , Guard constraint expression and a collection of select statements Construct a value dependency graph corresponding to the preset code .

[0075] In the above embodiment, a definition node set, a usage node set, a mapping relationship, a guard constraint expression and a selection statement set are constructed based on the variables and selection statements in the preset code, and then a value dependency graph corresponding to the preset code is constructed, which lays a foundation for subsequent static analysis of the value dependency graph and determination of the initial vulnerability detection results corresponding to the preset code.

[0076] Step 140: For each of the preset codes, based on the initial vulnerability detection results and vulnerability annotation results corresponding to the preset codes, determine a noise transfer matrix from the initial vulnerability detection results to the vulnerability annotation results through the second largest language model.

[0077] Specifically, for each preset code, the initial vulnerability detection result and vulnerability annotation result corresponding to the preset code can be input into the second largest language model, and then the noise transfer matrix from the initial vulnerability detection result output by the second largest language model to the vulnerability annotation result can be obtained, and the noise transfer matrix represents the transition probability from the initial vulnerability detection result to the vulnerability annotation result. It is easy to understand that the vulnerability annotation result is determined in advance by annotation for the preset code, reflecting the accurate vulnerability result.

[0078] Step 150: Generate second prompt words corresponding to each of the preset codes based on the initial vulnerability detection results and the noise transfer matrix corresponding to each of the preset codes, and train the second large language model based on each of the second prompt words to obtain a target large language model.

[0079] Specifically, the second prompt words corresponding to each preset code can be generated based on the initial vulnerability detection results and noise transfer matrices corresponding to each preset code. The second prompt words can be, for example, in the following form: "Possible vulnerabilities are: {initial vulnerability detection results}, and the transfer matrix is: {noise transfer matrix}". Then, the second large language model can be trained based on each second prompt word to obtain the target large language model.

[0080] Optionally, after obtaining the target large language model, the target code can be input into the target large language model to obtain the target detection result output by the target large language model, and the target detection result at least includes the vulnerability location in the target code. The target detection result can also include one or more of the vulnerability type in the target code, the vulnerability impact range, the method for repairing the vulnerability, and the target code after the vulnerability is repaired, etc., which are not specifically limited in the embodiments of the present invention.

[0081] In one embodiment, the training of the second large language model based on each of the second prompt words to obtain a target large language model includes:

[0082] The second large language model is iteratively trained based on each of the second prompt words, and the parameters of the second large language model are optimized based on a cross entropy loss function to obtain the target large language model.

[0083] Specifically, the second largest language model can be iteratively trained based on each second prompt word and the label corresponding to each second prompt word, and the parameters of the second largest language model can be optimized based on the cross entropy loss function to obtain the target large language model. The cross entropy loss function can characterize the difference between the true probability distribution and the predicted probability distribution. The smaller the cross entropy value, the better the vulnerability detection effect of the target large language model. The label corresponding to the second prompt word is predetermined, and the label at least includes the vulnerability location in the preset code. The label can also include one or more of the vulnerability type in the preset code, the scope of vulnerability impact, the method of repairing the vulnerability, and the preset code after repairing the vulnerability.

[0084] In the above embodiment, the second large language model is trained based on each second prompt word to obtain a target large language model. On the basis of obtaining the target large language model, the target code is input into the target large language model to obtain the target detection result output by the target large language model.

[0085] The method for constructing a large model for code vulnerability detection provided by the present invention generates a first prompt word based on the vulnerability repair information in the preset code submission information, and then performs a first round of training on the initial large language model based on the first prompt word to obtain the first large language model. The first large language model is further iteratively optimized based on the reward function corresponding to the first large language model to obtain the second large language model. Then, for each preset code, the value dependency graph corresponding to the preset code is analyzed by a preset symbol calculation algorithm to determine the initial vulnerability detection result corresponding to the preset code. Further, for each preset code, based on the initial vulnerability detection result and the vulnerability annotation result corresponding to the preset code, the noise transfer matrix from the initial vulnerability detection result to the vulnerability annotation result is determined by the second large language model. Finally, based on the initial vulnerability detection result and the noise transfer matrix corresponding to each preset code, the second prompt word corresponding to each preset code is generated, and the second large language model is trained based on each second prompt word to obtain the target large language model. The technical solution of the present invention can reduce the accuracy of the preset symbol calculation algorithm to reduce the computational complexity, and through the subsequent process of determining the noise transfer matrix, the target large language model is guaranteed to have a high accuracy rate for vulnerability detection while reducing the computational complexity. And because the target large language model is obtained by training based on the initial vulnerability detection results and noise transfer matrices corresponding to each preset code, its training process is explainable.

[0086] The following is a description of the code vulnerability detection large model construction device provided by the present invention. The code vulnerability detection large model construction device described below and the code vulnerability detection large model construction method described above can be referenced to each other.

[0087] Figure 2 is a schematic diagram of the structure of a device for constructing a large model for code vulnerability detection provided by an embodiment of the present invention. Figure 2 As shown, the code vulnerability detection large model building device 200 includes:

[0088] The training module 210 is used to generate a first prompt word based on the vulnerability repair information in the preset code submission information, and perform a first round of training on the initial large language model based on the first prompt word to obtain a first large language model; the vulnerability repair information includes: code before the vulnerability repair, code after the vulnerability repair, and vulnerability repair description information;

[0089] An optimization module 220, configured to iteratively optimize the first largest language model based on a reward function corresponding to the first largest language model to obtain a second largest language model, wherein the reward function is determined based on the preset code submission information;

[0090] The analysis module 230 is used to analyze the value dependency graph corresponding to each preset code by using a preset symbol calculation algorithm to determine the initial vulnerability detection result corresponding to the preset code;

[0091] A determination module 240 is used to determine, for each of the preset codes, a noise transfer matrix from the initial vulnerability detection result to the vulnerability annotation result through the second largest language model based on the initial vulnerability detection result and the vulnerability annotation result corresponding to the preset code;

[0092] The generation module 250 is used to generate the second prompt words corresponding to each of the preset codes based on the initial vulnerability detection results and the noise transfer matrix corresponding to each of the preset codes, and train the second large language model based on each of the second prompt words to obtain the target large language model.

[0093] In one embodiment, the optimization module 220 is specifically used to:

[0094] Training an initial classification model based on the historical modification records in the preset code submission information to obtain a reward model, wherein the historical modification records include the vulnerability repair information;

[0095] The first largest language model is iteratively optimized using the reward model as a reward function to obtain a second largest language model.

[0096] In one embodiment, the optimization module 220 is further configured to:

[0097] Acquire a preset number of historical modification records of codes in the preset code submission information, wherein each modification record in the historical modification records is arranged in chronological order;

[0098] Based on the historical modification records of the preset number of codes, the initial classification model is trained to obtain the reward model.

[0099] In one embodiment, the analysis module 230 is specifically used to:

[0100] Constructing a value dependency graph corresponding to the preset code based on the variables and selection statements in the preset code;

[0101] The value dependency graph is statically analyzed based on the preset symbolic calculation algorithm to determine an initial vulnerability detection result corresponding to the preset code.

[0102] In one embodiment, the analysis module 230 is further configured to:

[0103] Determine a definition node set based on definition symbols corresponding to each of the variables, and determine a use node set based on values ​​corresponding to each of the variables;

[0104] Determine a mapping relationship from the definition node set to the use node set;

[0105] Determine the guard constraint expression corresponding to the mapping relationship based on each of the selection statements;

[0106] Determine a selection statement set based on each of the selection statements;

[0107] A value dependency graph corresponding to the preset code is constructed based on the definition node set, the use node set, the mapping relationship, the guard constraint expression and the selection statement set.

[0108] In one embodiment, the generating module 250 is specifically used for:

[0109] The second large language model is iteratively trained based on each of the second prompt words, and the parameters of the second large language model are optimized based on a cross entropy loss function to obtain the target large language model.

[0110] The code vulnerability detection large model construction device provided by the present invention generates a first prompt word based on the vulnerability repair information in the preset code submission information, and then performs a first round of training on the initial large language model based on the first prompt word to obtain the first large language model. The first large language model is further iteratively optimized based on the reward function corresponding to the first large language model to obtain the second large language model. Then, for each preset code, the value dependency graph corresponding to the preset code is analyzed by a preset symbol calculation algorithm to determine the initial vulnerability detection result corresponding to the preset code. Further, for each preset code, based on the initial vulnerability detection result and the vulnerability annotation result corresponding to the preset code, the noise transfer matrix from the initial vulnerability detection result to the vulnerability annotation result is determined by the second large language model. Finally, based on the initial vulnerability detection result and the noise transfer matrix corresponding to each preset code, the second prompt word corresponding to each preset code is generated, and the second large language model is trained based on each second prompt word to obtain the target large language model. The technical solution of the present invention can reduce the accuracy of the preset symbol calculation algorithm to reduce the computational complexity, and through the subsequent process of determining the noise transfer matrix, the computational complexity is reduced while ensuring that the target large language model has a high accuracy rate for vulnerability detection. And because the target large language model is obtained by training based on the initial vulnerability detection results and noise transfer matrices corresponding to each preset code, its training process is explainable.

[0111] Figure 3 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 3As shown, the electronic device may include: a processor 310, a communication interface 320, a memory 330 and a communication bus 340, wherein the processor 310, the communication interface 320 and the memory 330 communicate with each other through the communication bus 340. The processor 310 may call the logic instructions in the memory 330 to execute the code vulnerability detection large model construction method, which includes:

[0112] Generate a first prompt word based on the vulnerability repair information in the preset code submission information, and perform a first round of training on the initial large language model based on the first prompt word to obtain a first large language model; the vulnerability repair information includes: code before the vulnerability repair, code after the vulnerability repair, and vulnerability repair description information;

[0113] Iteratively optimizing the first largest language model based on a reward function corresponding to the first largest language model to obtain a second largest language model, wherein the reward function is determined based on the preset code submission information;

[0114] For each preset code, a value dependency graph corresponding to the preset code is analyzed by a preset symbol calculation algorithm to determine an initial vulnerability detection result corresponding to the preset code;

[0115] For each of the preset codes, based on the initial vulnerability detection result and the vulnerability annotation result corresponding to the preset code, determine a noise transfer matrix from the initial vulnerability detection result to the vulnerability annotation result through the second largest language model;

[0116] Based on the initial vulnerability detection results and the noise transfer matrix corresponding to each of the preset codes, the second prompt words corresponding to each of the preset codes are generated, and the second large language model is trained based on each of the second prompt words to obtain the target large language model.

[0117] In addition, the logic instructions in the above-mentioned memory 330 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.

[0118] On the other hand, the present invention further provides a computer program product, the computer program product includes a computer program, the computer program can be stored on a non-transitory computer-readable storage medium, when the computer program is executed by a processor, the computer can execute the code vulnerability detection large model construction method provided by the above methods, the method includes:

[0119] Generate a first prompt word based on the vulnerability repair information in the preset code submission information, and perform a first round of training on the initial large language model based on the first prompt word to obtain a first large language model; the vulnerability repair information includes: code before the vulnerability repair, code after the vulnerability repair, and vulnerability repair description information;

[0120] Iteratively optimizing the first largest language model based on a reward function corresponding to the first largest language model to obtain a second largest language model, wherein the reward function is determined based on the preset code submission information;

[0121] For each preset code, a value dependency graph corresponding to the preset code is analyzed by a preset symbol calculation algorithm to determine an initial vulnerability detection result corresponding to the preset code;

[0122] For each of the preset codes, based on the initial vulnerability detection result and the vulnerability annotation result corresponding to the preset code, determine a noise transfer matrix from the initial vulnerability detection result to the vulnerability annotation result through the second largest language model;

[0123] Based on the initial vulnerability detection results and the noise transfer matrix corresponding to each of the preset codes, the second prompt words corresponding to each of the preset codes are generated, and the second large language model is trained based on each of the second prompt words to obtain the target large language model.

[0124] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the computer program is executed by a processor to execute the code vulnerability detection large model construction method provided by the above methods, the method comprising:

[0125] Generate a first prompt word based on the vulnerability repair information in the preset code submission information, and perform a first round of training on the initial large language model based on the first prompt word to obtain a first large language model; the vulnerability repair information includes: code before the vulnerability repair, code after the vulnerability repair, and vulnerability repair description information;

[0126] Iteratively optimizing the first largest language model based on a reward function corresponding to the first largest language model to obtain a second largest language model, wherein the reward function is determined based on the preset code submission information;

[0127] For each preset code, a value dependency graph corresponding to the preset code is analyzed by a preset symbol calculation algorithm to determine an initial vulnerability detection result corresponding to the preset code;

[0128] For each of the preset codes, based on the initial vulnerability detection result and the vulnerability annotation result corresponding to the preset code, determine a noise transfer matrix from the initial vulnerability detection result to the vulnerability annotation result through the second largest language model;

[0129] Based on the initial vulnerability detection results and the noise transfer matrix corresponding to each of the preset codes, the second prompt words corresponding to each of the preset codes are generated, and the second large language model is trained based on each of the second prompt words to obtain the target large language model.

[0130] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0131] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0132] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for constructing a large model for code vulnerability detection, characterized in that: include: Generate a first prompt word based on the vulnerability repair information in the preset code submission information, and perform a first round of training on the initial large language model based on the first prompt word to obtain a first large language model; The vulnerability repair information includes: code before the vulnerability repair, code after the vulnerability repair, and vulnerability repair description information; Iteratively optimizing the first largest language model based on a reward function corresponding to the first largest language model to obtain a second largest language model, wherein the reward function is determined based on the preset code submission information; For each preset code, a value dependency graph corresponding to the preset code is analyzed by a preset symbol calculation algorithm to determine an initial vulnerability detection result corresponding to the preset code; For each of the preset codes, based on the initial vulnerability detection result and the vulnerability annotation result corresponding to the preset code, a noise transfer matrix from the initial vulnerability detection result to the vulnerability annotation result is determined by the second largest language model, wherein the noise transfer matrix represents a transition probability from the initial vulnerability detection result to the vulnerability annotation result; Based on the initial vulnerability detection results and the noise transfer matrix corresponding to each of the preset codes, the second prompt words corresponding to each of the preset codes are generated, and the second large language model is trained based on each of the second prompt words to obtain the target large language model.

2. The method for constructing a large model for code vulnerability detection according to claim 1, characterized in that: The iteratively optimizing the first largest language model based on the reward function corresponding to the first largest language model to obtain a second largest language model includes: Training an initial classification model based on the historical modification records in the preset code submission information to obtain a reward model, wherein the historical modification records include the vulnerability repair information; The first largest language model is iteratively optimized using the reward model as a reward function to obtain a second largest language model.

3. The method for constructing a large model for code vulnerability detection according to claim 2, characterized in that: The training of the initial classification model based on the historical modification records in the preset code submission information to obtain the reward model includes: Obtaining a preset number of historical modification records of codes in the preset code submission information, wherein each modification record in the historical modification record is arranged in chronological order; Based on the historical modification records of the preset number of codes, the initial classification model is trained to obtain the reward model.

4. The method for constructing a large model for code vulnerability detection according to claim 1, characterized in that: The analyzing the value dependency graph corresponding to the preset code by using a preset symbol calculation algorithm to determine the initial vulnerability detection result corresponding to the preset code includes: Constructing a value dependency graph corresponding to the preset code based on the variables and selection statements in the preset code; The value dependency graph is statically analyzed based on the preset symbolic calculation algorithm to determine an initial vulnerability detection result corresponding to the preset code.

5. The method for constructing a large model for code vulnerability detection according to claim 4, characterized in that: The step of constructing a value dependency graph corresponding to the preset code based on the variables and selection statements in the preset code includes: Determine a definition node set based on definition symbols corresponding to each of the variables, and determine a use node set based on values ​​corresponding to each of the variables; Determine a mapping relationship from the definition node set to the use node set; Determine the guard constraint expression corresponding to the mapping relationship based on each of the selection statements; Determine a selection statement set based on each of the selection statements; A value dependency graph corresponding to the preset code is constructed based on the definition node set, the use node set, the mapping relationship, the guard constraint expression and the selection statement set.

6. The method for constructing a large model for code vulnerability detection according to any one of claims 1 to 5, characterized in that: The step of training the second large language model based on each of the second prompt words to obtain a target large language model includes: The second large language model is iteratively trained based on each of the second prompt words, and the parameters of the second large language model are optimized based on a cross entropy loss function to obtain the target large language model.

7. A device for constructing a large model for code vulnerability detection, characterized in that: include: A training module, configured to generate a first prompt word based on vulnerability repair information in preset code submission information, and perform a first round of training on an initial large language model based on the first prompt word to obtain a first large language model; The vulnerability repair information includes: code before the vulnerability repair, code after the vulnerability repair, and vulnerability repair description information; an optimization module, configured to iteratively optimize the first largest language model based on a reward function corresponding to the first largest language model to obtain a second largest language model, wherein the reward function is determined based on the preset code submission information; An analysis module, for analyzing a value dependency graph corresponding to each preset code by a preset symbol calculation algorithm, and determining an initial vulnerability detection result corresponding to the preset code; a determination module, configured to determine, for each of the preset codes, a noise transfer matrix from the initial vulnerability detection result to the vulnerability annotation result through the second largest language model based on the initial vulnerability detection result and the vulnerability annotation result corresponding to the preset code, wherein the noise transfer matrix represents a transfer probability from the initial vulnerability detection result to the vulnerability annotation result; A generation module is used to generate second prompt words corresponding to each of the preset codes based on the initial vulnerability detection results and the noise transfer matrix corresponding to each of the preset codes, and train the second large language model based on each of the second prompt words to obtain a target large language model.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the method for constructing a large model for code vulnerability detection as described in any one of claims 1 to 6 is implemented.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for constructing a large model for code vulnerability detection as described in any one of claims 1 to 6 is implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method for constructing a large model for code vulnerability detection as described in any one of claims 1 to 6 is implemented.