Endogenous safe isomer generation method and system based on large language model

Through the endogenous secure isomer generation method based on large language model, the problems of insufficient logical consistency, repair efficiency and vulnerability detection in the prior art are solved, and the functional consistency and endogenous security of isomer codes are improved.

CN119621124APending Publication Date: 2025-03-14STATE GRID SHANDONG ELECTRIC POWER CO +4
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411715506.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-27
Publication Date
2025-03-14

AI Technical Summary

Technical Problem

The existing endogenous secure isomer generation methods have problems such as difficult to guarantee the logical consistency of isomer code, inefficient code repair and generation, and insufficient vulnerability detection and logic coverage.

Method used

The endogenous safe isomer generation method based on the large language model is adopted to form a question-and-answer pair by obtaining error types and repair schemes, establish hierarchical guidance instructions, adjust the code after the error is repaired by the large language model, and optimize the isomer code generation parameters through fuzzy testing to ensure functional consistency and endogenous security.

Benefits of technology

The logical functional consistency of isomer code is achieved, the code repair and generation efficiency is improved, the vulnerability detection and logical coverage is enhanced, and the endogenous security and functional reliability of isomer code are significantly improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119621124A_ABST
    Figure CN119621124A_ABST
Patent Text Reader

Abstract

An endogenous safe isomer generation method based on a large language model comprises the steps that 1, in the code generation process of the large language model, error types and repair schemes corresponding to the error types are obtained to form a plurality of question and answer pairs; establishing a layered guide instruction of each question and answer pair; adjusting the large language model based on the hierarchical guidance instruction to generate an error-repaired code; 2, isomer codes with errors in the compiling process are extracted and fed back to the large language model, and the isomer codes in the large language model are adjusted for the first time to generate parameters; generating a compiled isomer code by using the large language model adjusted for the first time; 3, isomer codes with inconsistent logic functions under different fuzzy test input information are extracted and fed back to the large language model adjusted for the first time, and the isomer codes in the large language model are adjusted for the second time to generate parameters; and generating an isomer code by using the large language model adjusted for the second time to serve as a safe isomer code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the fields of intrinsic security, artificial intelligence and fuzzy testing technology, and more specifically, relates to a method and system for generating intrinsic security isomers based on a large language model. Background Art

[0002] There are inherent security issues in cyberspace that cannot be eliminated, controlled, or thoroughly investigated, such as software and hardware vulnerabilities and backdoors. As a result, unknown threats based on unknown vulnerabilities and unknown backdoors have become a major security challenge in cyberspace. The core idea of ​​inherent security heterogeneity is to heterogeneously implement weak executives in software systems, that is, to enhance the security of the system by building multiple functionally equivalent alternative executives. Such heterogeneous executives can be different software components, algorithms, or protocols, which are functionally equivalent to each other but have differentiated features in implementation.

[0003] With the rapid development of computer technology, software systems are becoming increasingly complex and secure. However, existing technologies face many challenges in addressing the security and functional equivalence issues of software systems. Current methods for generating endogenous secure isomers usually rely on static analysis and traditional testing methods, which have the following main disadvantages:

[0004] The logical consistency of heterogeneous codes is difficult to ensure: Existing heterogeneous code generation methods mostly rely on static rules or single test feedback and lack a dynamic adjustment mechanism, which easily leads to differences in logical functions among different isomers and makes it impossible to effectively achieve functional equivalence. This functional deviation may further cause security risks and reduce the inherent security of the system.

[0005] Inefficient code repair and generation: Traditional methods usually require manual analysis and repair of errors in the code generation process, which is time-consuming, labor-intensive, and prone to introducing additional problems. At the same time, existing technologies often lack effective guidance mechanisms in the code repair process, making it difficult to perform systematic optimization at the syntax, logic, and functional levels, resulting in low code repair efficiency and low quality.

[0006] Insufficient vulnerability detection and logic coverage: Although existing fuzz testing methods can discover some code vulnerabilities, they are limited by the diversity of test cases and path coverage, making it difficult to fully detect potential logic defects and functional vulnerabilities in the code. In particular, in the testing of uncovered paths or abnormal logic branches, traditional methods lack the ability to dynamically generate new test cases, resulting in insufficient detection. Summary of the invention

[0007] In order to solve the deficiencies in the prior art, the present invention provides a method for generating endogenous safe isomers based on a large language model.

[0008] The present invention adopts the following technical solution.

[0009] The first aspect of the present invention provides a method for generating endogenous safe isomers based on a large language model, characterized in that it comprises the following steps:

[0010] Step 1: in the process of generating code from the large language model, the error type and the corresponding repair solution of the error type are obtained to form multiple question-answer pairs; hierarchical guidance instructions for each question-answer pair are established according to the error type, the structure of the code corresponding to the error type, and the logical function of the code corresponding to the error type; the large language model is adjusted based on the hierarchical guidance instructions to generate the error-corrected code;

[0011] Step 2, converting the error-fixed code into heterogeneous codes under different compilation languages; extracting the heterogeneous codes with errors during the compilation process and feeding them back to the large language model to adjust the heterogeneous code generation parameters in the large language model for the first time; using the large language model adjusted for the first time to generate the heterogeneous code that passes the compilation;

[0012] Step 3: Based on the fuzz testing method, extract the heterogeneous codes with inconsistent logical functions under different fuzz testing input information and feed them back to the large language model after the first adjustment, so as to adjust the heterogeneous code generation parameters in the large language model for the second time; use the large language model adjusted for the second time to generate heterogeneous codes as safe heterogeneous codes.

[0013] Preferably, in the process of generating code from a large language model, error types and repair solutions corresponding to the error types are obtained to form multiple question-answer pairs; hierarchical guidance instructions for each question-answer pair are established according to the error type, the structure of the code corresponding to the error type, and the logical function of the code corresponding to the error type; and the large language model is adjusted based on the hierarchical guidance instructions to generate error-corrected code; including:

[0014] Collect error information during code generation;

[0015] The collected error information and corresponding repair solutions are constructed into question-answer pairs, and the large language model is fine-tuned based on these question-answer pairs;

[0016] According to the error types in the question-answer knowledge base, a hierarchical prompt library is established, and different types of prompts are classified according to error categories, code structures, and logical functions to guide the large language model to generate error-fixed code.

[0017] Preferably, the error information in the acquisition code generation process includes:

[0018] For the error types in the code generation process, typical program error information is manually collected and sorted, and corresponding repair solutions are attached;

[0019] With the help of static analysis and dynamic detection security tools, vulnerabilities and anomalies are identified, error information and repair suggestions are collected, and the ability of large language models to identify potential problems is supplemented;

[0020] Capture error type, location, and related context in real time during code execution.

[0021] Preferably, the hierarchical prompt library divides instructions into a basic layer, a structural layer and a functional layer;

[0022] The base layer is used to provide guidance on code syntax, indentation specifications, and naming styles to the large language model through the Prompt library at the initial stage of generation, restricting the syntax and structure of the model-generated code.

[0023] The structure layer is used to define the logical branches and modularization of the code through the Prompt library after completing the basic syntax prompts, including standardized modules for conditional judgment and loop control;

[0024] The functional layer includes algorithm logic and data processing requirements. It is guided by business logic and guides the model to generate code modules that meet the set functions, cover functional semantic requirements, standardize the generated code structure and preset functional logic.

[0025] Preferably, during the generation process, the logic and structure of the repair code are optimized through prompt guidance, and the repaired executable body is converted into an isomer based on the characteristics of different programming languages;

[0026] During the conversion process, the generation strategy is adjusted in combination with code logic analysis and functional requirements to ensure the functional consistency and logical integrity of the heterogeneous structures.

[0027] Preferably, step 2, converting the error-corrected code into isomerous codes under different compiled languages; extracting isomerous codes with errors in the compilation process and feeding them back to the large language model to adjust the isomerous code generation parameters in the large language model for the first time; and using the large language model adjusted for the first time to generate isomerous codes that pass compilation; includes:

[0028] After compiling and checking the feedback, locate the specific erroneous code snippet, and use the corresponding error repair template in the prompt library to make local adjustments and regenerate only the erroneous snippet, thus correcting the local problem while keeping other code parts unaffected.

[0029] After the local fragments are generated, the overall syntax, logic and module consistency of the code are verified through full compilation detection and functional consistency testing, so that the locally adjusted code meets the global functional requirements;

[0030] If new problems are found during global verification, local correction feedback is triggered based on the feedback mechanism, and the model is gradually optimized and regenerated for the parts that have not passed the verification until all code snippets pass the global verification.

[0031] Preferably, the method locates the specific erroneous code fragment after compiling the detection feedback, and only partially adjusts and regenerates the erroneous fragment through the corresponding error repair template in the prompt library, thereby correcting the local problem while keeping other code parts unaffected; including:

[0032] Identify error patterns based on the built prompt library. When the compilation detection feedback returns error information, locate the specific code snippet where the error is located, including functions, logical branches, and variable declarations, and limit the problem to the set area without changing the correct code part.

[0033] The large language model adjusts and regenerates the incorrect fragments pointed out by the feedback according to the repair templates in the prompt library, and applies the corresponding prompt guidance according to the error type, so that the locally generated code can meet the grammatical requirements while maintaining the integrity of the logical structure and not affecting other modules;

[0034] According to the type of local generated feedback, local adjustments are made by automatically selecting the setting instructions in the Prompt library, including errors in data type errors and conditional logic inconsistencies. The local generated Prompt directly applies the corresponding corrections in the template.

[0035] Preferably, after the local fragments are generated, the overall syntax, logic and module consistency of the code are verified through complete compilation detection and functional consistency testing, so that the locally adjusted code meets the global functional requirements; including:

[0036] After the local fragments are generated and replaced, a complete compilation test is performed to verify that the local adjustments do not destroy the overall code consistency by checking the dependencies and variable consistency between modules;

[0037] For functional verification of heterogeneous code, a set of preset functional test cases is used to perform consistency checks on all generated code paths. Functional consistency testing is based on the boundary conditions and random inputs of fuzz testing to fully verify the functionality of the code.

[0038] During the global verification phase, multi-level coverage testing is performed, including syntax, logic, and functional coverage monitoring. The coverage of each layer of verification is recorded to verify whether the generated code meets the syntax requirements and whether the functions are consistent.

[0039] Preferably, step 3, based on a fuzzy testing method, extracting isomeric codes with inconsistent logical functions under different fuzzy testing input information and feeding them back to the large language model after the first adjustment; comprises:

[0040] Construct diverse test inputs for the generated heterogeneous code, including random values, extreme values, boundary conditions, and abnormal inputs, so that the heterogeneous code can run under different inputs to test various logical branches and boundary conditions;

[0041] During the code running process, the execution path and logic branches of the code are monitored in real time through dynamic instrumentation, and the running path and logic branch triggering status of each test are recorded;

[0042] Record the path coverage of each test, analyze the code coverage, and find out the untriggered logic branches and uncovered paths. The path coverage is used to identify functional vulnerabilities and logic defects.

[0043] Based on the results of path coverage analysis, new test cases are automatically generated to test untriggered paths and branches. The functional inconsistencies of heterogeneous codes under different input conditions are recorded, including the specific manifestations and locations of the inconsistencies. The test results are output as feedback information to the large language model after the first adjustment.

[0044] Preferably, in step 3, the isomorphic code generation parameters in the large language model are adjusted for the second time; the isomorphic code is generated using the large language model adjusted for the second time as the safe isomorphic code; including:

[0045] Extract functional inconsistencies from feedback obtained from fuzz testing, including trigger conditions, performance differences, and related code locations;

[0046] The large language model uses the built prompt library to adjust the guidance according to the specific inconsistencies in the feedback information to generate code that meets the functional consistency requirements;

[0047] During the generation process, the large language model adjusts the code logic of the heterogeneous entities based on feedback information, focusing on optimizing the algorithm steps, data flow, and boundary condition processing, so that the heterogeneous entities have consistent functional logic performance;

[0048] After each optimization generation, the functional performance of the isomers is retested. If inconsistencies still exist, the new feedback information is passed back to the model for the next round of generation, and multiple rounds of feedback and optimization are performed;

[0049] After completing multiple rounds of optimization, a final functional consistency verification is performed to confirm that all isomers perform consistently under various input conditions and are functionally equivalent. The verified consistent isomers are used as the final output.

[0050] Preferably, after completing multiple rounds of optimization, a final functional consistency verification is performed to confirm that all isomers perform consistently under various input conditions and are functionally equivalent; including:

[0051] In all test cases, if the path coverage of each isomer reaches the same coverage, the logic is confirmed to be consistent;

[0052] By comparing the output data values ​​and formats under the same input conditions, it is confirmed that all isomers behave consistently in output;

[0053] If all isomers behave the same when encountering extreme values ​​or abnormal inputs, it is confirmed that the processing logic and output results are consistent under boundary conditions;

[0054] If the path coverage is consistent, the output is consistent, and the boundary processing verification is consistent, the isomers are functionally equivalent.

[0055] The second aspect of the present invention provides an endogenous security isomer generation system based on a large language model, comprising: an error repair and guidance module, an isomer generation module and a security optimization module:

[0056] The error repair and guidance module is used to extract the error type and its corresponding repair solution to form multiple question-answer pairs; according to the error type, the structure and logical function of the error code, hierarchical guidance instructions are generated, and the guidance is used to adjust the large language model to generate the code after the error is repaired;

[0057] The isomer generation module is used to convert the repaired code into isomer codes under different compilation languages; extract the isomer codes with errors during the compilation process, feed them back to the large language model, complete the first adjustment to optimize the isomer code generation parameters, and generate isomer codes that pass the compilation;

[0058] The security optimization module is used to detect the logical functions of heterogeneous codes under different input conditions through fuzzy testing, extract heterogeneous codes with inconsistent logical functions and feed them back to the large language model, and generate heterogeneous codes with logical consistency and inherent security after the second adjustment.

[0059] Preferably, the security optimization module includes:

[0060] After obtaining the repaired code, the isomerization generation module converts the repaired code into isomerization codes in multiple programming languages. During the conversion process, the structure, syntax and logical functions of the code need to remain consistent, but the implementation method and expression form of each programming language are different.

[0061] After the code is converted into heterogeneous code, it is input into the corresponding compiler for compilation. If any errors occur, including syntax errors, type mismatches, and compilation dependency issues, the heterogeneous generation module extracts the error information as feedback to the large language model to guide the optimization of the subsequent generation process.

[0062] Based on the error information extracted from the compilation process, the isomer generation module will feed back to the large language model for the first adjustment. The goal of the first adjustment is to optimize the generated isomer code.

[0063] After completing the first adjustment, the large language model will regenerate the heterogeneous code based on the adjusted parameters and input it into the compiler for compilation again. No new compilation errors will occur. The generated heterogeneous code meets the multi-language compilation requirements and passes the verification of the compiler.

[0064] Compared with the prior art, the beneficial effects of the present invention include at least:

[0065] (1) The present invention extracts the inconsistency of the logical functions of the heterogeneous codes under different input conditions through multiple rounds of feedback optimization, and uses it as feedback information to adjust the generation parameters of the large language model; the heterogeneous codes finally generated are made consistent in terms of logical functions, thus avoiding the problem of functional deviation in traditional methods, and significantly enhancing the reliability of the heterogeneous codes in terms of intrinsic security;

[0066] (2) The present invention can perform refined hierarchical processing on the error types in the code generation process through hierarchical guidance based on the hierarchical prompt library, optimize code generation from the grammatical, logical and functional levels, not only improve the accuracy and efficiency of code repair, but also ensure that the repaired code can be quickly converted into functionally consistent heterogeneous code, reducing the inefficiency of manual intervention and traditional manual debugging;

[0067] (3) The present invention generates diversified test inputs and monitors the execution path and logic branches of the code in real time through functional coverage and path optimization based on fuzz testing. Combined with path coverage analysis and automated test case generation, the potential vulnerabilities and logical defects of the code are fully covered, thereby significantly improving the functional reliability and logical integrity of the heterogeneous code. BRIEF DESCRIPTION OF THE DRAWINGS

[0068] Figure 1 It is a diagram of the intrinsically safe heterogeneous working mechanism provided in accordance with an embodiment of the present invention;

[0069] Figure 2 It is a flow chart of generating functionally equivalent heterogeneous codes from a large language model according to an embodiment of the present invention;

[0070] Figure 3It is a schematic diagram of constructing a question-answer pair according to an embodiment of the present invention. DETAILED DESCRIPTION

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

[0072] like Figure 1 As shown, the present invention provides an endogenous secure heterogeneous working mechanism diagram based on a large language model. Starting from the initial code generation, the code is hierarchically guided and repaired through a hierarchical prompt library to gradually improve the logical structure and function of the code; the repaired code is converted into an isomer, and the erroneous code fragment is located through compilation detection, and local adjustments are made in combination with the prompt template to optimize the model parameters, and the isomer code verified by the compilation is generated; then, fuzz testing is used to construct diversified inputs to detect the consistency of the isomer in logical functions, and the inconsistent results are fed back to the large language model to further optimize the generation logic and ensure the functional consistency and security of the isomer; finally, after multiple rounds of feedback and verification, a secure heterogeneous code with complete logical functions and functional equivalence is generated.

[0073] like Figure 2 As shown, Example 1 of the present invention provides a method for generating endogenous safe isomers based on a large language model, comprising the following steps:

[0074] Step 1: in the process of generating code from the large language model, the error type and the corresponding repair solution of the error type are obtained to form multiple question-answer pairs; hierarchical guidance instructions for each question-answer pair are established according to the error type, the structure of the code corresponding to the error type, and the logical function of the code corresponding to the error type; the large language model is adjusted based on the hierarchical guidance instructions to generate the error-corrected code;

[0075] Preferably, in the process of generating code from a large language model, error types and repair solutions corresponding to the error types are obtained to form multiple question-answer pairs; hierarchical guidance instructions for each question-answer pair are established according to the error type, the structure of the code corresponding to the error type, and the logical function of the code corresponding to the error type; and the large language model is adjusted based on the hierarchical guidance instructions to generate error-corrected code; including:

[0076] Collect error information during code generation;

[0077] The collected error information and corresponding repair solutions are constructed into question-answer pairs, and the large language model is fine-tuned based on these question-answer pairs;

[0078] like Figure 3 As shown, according to the error types in the question-answer knowledge base, a hierarchical prompt library is established, and different types of prompts are classified according to error categories, code structures, and logical functions to guide the large language model to generate repair codes;

[0079] During the generation process, the logic and structure of the repair code are optimized through prompt guidance, and the repaired executable body is converted into heterogeneous bodies based on the characteristics of different programming languages;

[0080] During the conversion process, the generation strategy is adjusted in combination with code logic analysis and functional requirements to ensure the functional consistency and logical integrity of the heterogeneous structures.

[0081] Preferably, the error information in the acquisition code generation process includes:

[0082] The present invention adopts three approaches to collect information related to execution body errors as the "Prompt" input of the large language model. (1) Some common program errors and corresponding repair methods are manually collected to build a vulnerability library, which contains various common error types and corresponding solutions; (2) Existing security tools are used to identify errors in software systems, including vulnerabilities and abnormal situations. These security tools use various techniques, such as static analysis and dynamic detection, to discover potential problems in the code. By running these tools, we can collect detailed information about code errors and vulnerabilities, as well as possible repair suggestions; (3) The framework also has the ability to dynamically capture error information generated by the software system during runtime. When an error occurs during the execution of the software system, we can capture the error type, location, and related context information in real time. These error messages can provide important clues about problems that occur during code execution.

[0083] Furthermore, after obtaining abundant error information of the executable body, the present invention constructs question-answer pairs using this information, and uses these question-answer pairs to fine-tune the basic model. At the same time, the prompt is used for fine-tuning during use to make the isomer generation more accurate, thereby guiding the large language model to generate potential repair codes. In addition to generating repair codes, the large language model converts the repaired executable body into isomers of different programming languages, and logically reconstructs the original executable body to eliminate potential vulnerabilities and errors, thereby ensuring that the isomers no longer have the same vulnerabilities.

[0084] Preferably, the hierarchical prompt library divides instructions into a basic layer, a structural layer and a functional layer;

[0085] The base layer is used to provide guidance on code syntax, indentation specifications, and naming styles to the large language model through the Prompt library at the initial stage of generation, restricting the syntax and structure of the model-generated code.

[0086] The structure layer is used to define the logical branches and modularization of the code through the Prompt library after completing the basic syntax prompts, including standardized modules for conditional judgment and loop control;

[0087] The functional layer includes algorithm logic and data processing requirements. It is guided by business logic and guides the model to generate code modules that meet the set functions, cover functional semantic requirements, standardize the generated code structure and preset functional logic.

[0088] Step 2, converting the error-fixed code into heterogeneous codes under different compilation languages; extracting the heterogeneous codes with errors during the compilation process and feeding them back to the large language model to adjust the heterogeneous code generation parameters in the large language model for the first time; using the large language model adjusted for the first time to generate the heterogeneous code that passes the compilation;

[0089] Preferably, step 2, converting the error-corrected code into isomerous codes under different compiled languages; extracting isomerous codes with errors in the compilation process and feeding them back to the large language model to adjust the isomerous code generation parameters in the large language model for the first time; and using the large language model adjusted for the first time to generate isomerous codes that pass compilation; includes:

[0090] After compiling and checking the feedback, locate the specific erroneous code snippet, and use the corresponding error repair template in the prompt library to make local adjustments and regenerate only the erroneous snippet, thus correcting the local problem while keeping other code parts unaffected.

[0091] After the local fragments are generated, the overall syntax, logic and module consistency of the code are verified through full compilation detection and functional consistency testing, so that the locally adjusted code meets the global functional requirements;

[0092] If new problems are found during global verification, local correction feedback is triggered based on the feedback mechanism, and the model is gradually optimized and regenerated for the parts that have not passed the verification until all code snippets pass the global verification.

[0093] Preferably, the method locates the specific erroneous code fragment after compiling the detection feedback, and only partially adjusts and regenerates the erroneous fragment through the corresponding error repair template in the prompt library, thereby correcting the local problem while keeping other code parts unaffected; including:

[0094] Identify error patterns based on the built prompt library. When the compilation detection feedback returns error information, locate the specific code snippet where the error is located, including functions, logical branches, and variable declarations, and limit the problem to the set area without changing the correct code part.

[0095] The large language model adjusts and regenerates the incorrect fragments pointed out by the feedback according to the repair templates in the prompt library, and applies the corresponding prompt guidance according to the error type, so that the locally generated code can meet the grammatical requirements while maintaining the integrity of the logical structure and not affecting other modules;

[0096] According to the type of local generated feedback, local adjustments are made by automatically selecting the setting instructions in the Prompt library, including errors in data type errors and conditional logic inconsistencies. The local generated Prompt directly applies the corresponding corrections in the template.

[0097] Preferably, after the local fragments are generated, the overall syntax, logic and module consistency of the code are verified through complete compilation detection and functional consistency testing, so that the locally adjusted code meets the global functional requirements; including:

[0098] After the local fragments are generated and replaced, a complete compilation test is performed to verify that the local adjustments do not destroy the overall code consistency by checking the dependencies and variable consistency between modules;

[0099] For functional verification of heterogeneous code, a set of preset functional test cases is used to perform consistency checks on all generated code paths. Functional consistency testing is based on the boundary conditions and random inputs of fuzz testing to fully verify the functionality of the code.

[0100] During the global verification phase, multi-level coverage testing is performed, including syntax, logic, and functional coverage monitoring. The coverage of each layer of verification is recorded to verify whether the generated code meets the syntax requirements and whether the functions are consistent.

[0101] Step 3: Based on the fuzz testing method, extract the heterogeneous codes with inconsistent logical functions under different fuzz testing input information and feed them back to the large language model after the first adjustment, so as to adjust the heterogeneous code generation parameters in the large language model for the second time; use the large language model adjusted for the second time to generate heterogeneous codes as safe heterogeneous codes.

[0102] Preferably, step 3, based on a fuzzy testing method, extracting isomeric codes with inconsistent logical functions under different fuzzy testing input information and feeding them back to the large language model after the first adjustment; comprises:

[0103] Construct diverse test inputs for the generated heterogeneous code, including random values, extreme values, boundary conditions, and abnormal inputs, so that the heterogeneous code can run under different inputs to test various logical branches and boundary conditions;

[0104] During the code running process, the execution path and logic branches of the code are monitored in real time through dynamic instrumentation, and the running path and logic branch triggering status of each test are recorded;

[0105] Record the path coverage of each test, analyze the code coverage, and find out the untriggered logic branches and uncovered paths. The path coverage is used to identify functional vulnerabilities and logic defects.

[0106] Based on the results of path coverage analysis, new test cases are automatically generated to test untriggered paths and branches. The functional inconsistencies of heterogeneous codes under different input conditions are recorded, including the specific manifestations and locations of the inconsistencies. The test results are output as feedback information to the large language model after the first adjustment.

[0107] Preferably, in step 3, the isomorphic code generation parameters in the large language model are adjusted for the second time; the isomorphic code is generated using the large language model adjusted for the second time as the safe isomorphic code; including:

[0108] Extract functional inconsistencies from feedback obtained from fuzz testing, including trigger conditions, performance differences, and related code locations;

[0109] The large language model uses the built prompt library to adjust the guidance according to the specific inconsistencies in the feedback information to generate code that meets the functional consistency requirements;

[0110] During the generation process, the large language model adjusts the code logic of the heterogeneous entities based on feedback information, focusing on optimizing the algorithm steps, data flow, and boundary condition processing, so that the heterogeneous entities have consistent functional logic performance;

[0111] After each optimization generation, the functional performance of the isomers is retested. If inconsistencies still exist, the new feedback information is passed back to the model for the next round of generation, and multiple rounds of feedback and optimization are performed;

[0112] After completing multiple rounds of optimization, a final functional consistency verification is performed to confirm that all isomers perform consistently under various input conditions and are functionally equivalent. The verified consistent isomers are used as the final output.

[0113] Preferably, after completing multiple rounds of optimization, a final functional consistency verification is performed to confirm that all isomers perform consistently under various input conditions and are functionally equivalent; including:

[0114] In all test cases, if the path coverage of each isomer reaches the same coverage, the logic is confirmed to be consistent;

[0115] By comparing the output data values ​​and formats under the same input conditions, it is confirmed that all isomers behave consistently in output;

[0116] If all isomers behave the same when encountering extreme values ​​or abnormal inputs, it is confirmed that the processing logic and output results are consistent under boundary conditions;

[0117] If the path coverage is consistent, the output is consistent, and the boundary processing verification is consistent, the isomers are functionally equivalent.

[0118] Example 2 of the present invention provides an endogenous secure isomer generation system based on a large language model, including: an error repair and guidance module, an isomer generation module, and a security optimization module:

[0119] The error repair and guidance module is used to extract the error type and its corresponding repair solution to form multiple question-answer pairs; according to the error type, the structure and logical function of the error code, hierarchical guidance instructions are generated, and the guidance is used to adjust the large language model to generate the code after the error is repaired;

[0120] The isomer generation module is used to convert the repaired code into isomer codes under different compilation languages; extract the isomer codes with errors during the compilation process, feed them back to the large language model, complete the first adjustment to optimize the isomer code generation parameters, and generate isomer codes that pass the compilation;

[0121] The security optimization module is used to detect the logical functions of heterogeneous codes under different input conditions through fuzz testing, extract heterogeneous codes with inconsistent logical functions and feed them back to the large language model. After the second adjustment, heterogeneous codes with consistent logic and inherent security are generated.

[0122] Preferably, the security optimization module includes:

[0123] After obtaining the repaired code, the isomerization generation module converts the repaired code into isomerization codes in multiple programming languages. During the conversion process, the structure, syntax and logical functions of the code need to remain consistent, but the implementation method and expression form of each programming language are different.

[0124] After the code is converted into heterogeneous code, it is input into the corresponding compiler for compilation. If any errors occur, including syntax errors, type mismatches, and compilation dependency issues, the heterogeneous generation module extracts the error information as feedback to the large language model to guide the optimization of the subsequent generation process.

[0125] Based on the error information extracted from the compilation process, the isomer generation module will feed back to the large language model for the first adjustment. The goal of the first adjustment is to optimize the generated isomer code.

[0126] After completing the first adjustment, the large language model will regenerate the heterogeneous code based on the adjusted parameters and input it into the compiler for compilation again. No new compilation errors will occur. The generated heterogeneous code meets the multi-language compilation requirements and passes the verification of the compiler.

[0127] Example 3 of the present invention provides an electronic device:

[0128] The electronic device comprises: a processor; a memory for storing instructions executable by the processor; and the processor is used to execute a method for generating endogenous secure isomers based on a large language model.

[0129] Example 4 of the present invention provides a readable storage medium:

[0130] The computer-readable storage medium includes a stored computer program, wherein when the computer program is executed by a processor, the device where the storage medium is located is controlled to execute a method for generating an intrinsically secure isomer based on a large language model.

[0131] Compared with the prior art, the beneficial effects of the present invention include at least:

[0132] (1) The present invention extracts the inconsistency of the logical functions of the heterogeneous codes under different input conditions through multiple rounds of feedback optimization, and uses it as feedback information to adjust the generation parameters of the large language model; the heterogeneous codes finally generated are made consistent in terms of logical functions, thus avoiding the problem of functional deviation in traditional methods, and significantly enhancing the reliability of the heterogeneous codes in terms of intrinsic security;

[0133] (2) The present invention can perform refined hierarchical processing on the error types in the code generation process through hierarchical guidance based on the hierarchical prompt library, optimize code generation from the grammatical, logical and functional levels, not only improve the accuracy and efficiency of code repair, but also ensure that the repaired code can be quickly converted into functionally consistent heterogeneous code, reducing the inefficiency of manual intervention and traditional manual debugging;

[0134] (3) The present invention generates diversified test inputs and monitors the execution path and logic branches of the code in real time through functional coverage and path optimization based on fuzz testing. Combined with path coverage analysis and automated test case generation, the potential vulnerabilities and logical defects of the code are fully covered, thereby significantly improving the functional reliability and logical integrity of the heterogeneous code. The present disclosure may be a system, method and / or computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present disclosure.

[0135] 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 above embodiments, ordinary technicians in the relevant field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents, and any modifications or equivalent replacements that do not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.

Claims

1. A method for generating endogenous safe isomers based on a large language model, characterized in that: The following steps are involved: Step 1: in the process of generating codes by the large language model, the error type and the repair solution corresponding to the error type are obtained to form multiple question-answer pairs; hierarchical guidance instructions for each question-answer pair are established according to the error type, the structure of the code corresponding to the error type, and the logical function of the code corresponding to the error type; Generate error-fixed code by adjusting the large language model based on hierarchical guidance instructions; Step 2, converting the error-fixed code into isomerous codes in different compilation languages; extract The heterogeneous codes with errors during the compilation process are fed back to the large language model to adjust the heterogeneous code generation parameters in the large language model for the first time; Generate compiled heterogeneous code using the first tuned large language model; Step 3, based on the fuzz testing method, extracting isomorphic codes with inconsistent logical functions under different fuzz testing input information and feeding them back to the large language model after the first adjustment, so as to adjust the isomorphic code generation parameters in the large language model for the second time; The large language model adjusted for the second time is used to generate heterogeneous codes as safe heterogeneous codes.

2. The method for generating endogenous safe isomers based on a large language model according to claim 1, characterized in that: In the process of generating codes by the large language model, the error type and the corresponding repair solution are obtained to form multiple question-answer pairs; hierarchical guidance instructions for each question-answer pair are established according to the error type, the structure of the code corresponding to the error type, and the logical function of the code corresponding to the error type; Generates error-fixed code after adjusting the large language model based on hierarchical guidance instructions; including: Collect error information during code generation; The collected error information and corresponding repair solutions are constructed into question-answer pairs, and the large language model is fine-tuned based on the question-answer pairs. According to the error types in the question-answer knowledge base, a hierarchical prompt library is established, and different types of prompts are classified according to error categories, code structures, and logical functions to guide the large language model to generate error-fixed code.

3. The method for generating endogenous safe isomers based on a large language model according to claim 2, characterized in that: The error information in the acquisition code generation process includes: For the error types in the code generation process, typical program error information is manually collected and sorted, and corresponding repair solutions are attached; With the help of static analysis and dynamic detection security tools, vulnerabilities and anomalies are identified, error information and repair suggestions are collected, and the ability of large language models to identify potential problems is supplemented; Capture error type, location, and related context in real time as code executes.

4. The method for generating endogenous safe isomers based on a large language model according to claim 2, characterized in that: The hierarchical prompt library divides instructions into a basic layer, a structural layer and a functional layer; The base layer is used to provide guidance on code syntax, indentation specifications, and naming styles to the large language model through the Prompt library at the initial stage of generation, restricting the syntax and structure of the model-generated code. The structure layer is used to define the logical branches and modularization of the code through the Prompt library after completing the basic syntax prompts, including standardized modules for conditional judgment and loop control; The functional layer includes algorithm logic and data processing requirements. It is guided by business logic and guides the model to generate code modules that meet the set functions, cover functional semantic requirements, standardize the generated code structure and preset functional logic.

5. The method for generating endogenous safe isomers based on a large language model according to claim 2, characterized in that: During the generation process, the logic and structure of the repair code are optimized through prompt guidance, and the repaired executable body is converted into heterogeneous bodies based on the characteristics of different programming languages; During the conversion process, the generation strategy is adjusted in combination with code logic analysis and functional requirements to ensure the functional consistency and logical integrity of the heterogeneous structures.

6. The method for generating endogenous safe isomers based on a large language model according to claim 1, characterized in that: Step 2: convert the error-fixed code into heterogeneous code under different compilation languages; extract the heterogeneous code with errors in the compilation process and feed it back to the large language model to adjust the heterogeneous code generation parameters in the large language model for the first time; Generates compiled heterogeneous code using the first tuned large language model; including: After compiling and checking the feedback, locate the specific erroneous code snippet, and use the corresponding error repair template in the prompt library to partially adjust and regenerate the erroneous snippet, correcting the local problem while keeping other code parts unaffected; After the local fragments are generated, the overall syntax, logic and module consistency of the code are verified through full compilation detection and functional consistency testing, so that the locally adjusted code meets the global functional requirements; If new problems are found during global verification, local correction feedback is triggered based on the feedback mechanism, and the model is gradually optimized and regenerated for the parts that have not passed the verification until all code snippets pass the global verification.

7. The method for generating endogenous safe isomers based on a large language model according to claim 6, characterized in that: The method locates the specific erroneous code fragment after compiling the detection feedback, and locally adjusts and regenerates the erroneous fragment through the corresponding error repair template in the prompt library, thereby correcting the local problem while keeping other code parts unaffected; including: Identify error patterns based on the built prompt library. When the compilation detection feedback returns error information, locate the specific code snippet where the error is located, including functions, logical branches, and variable declarations, and limit the problem to the set area without changing the correct code part. The large language model adjusts and regenerates the incorrect fragments pointed out by the feedback according to the repair templates in the prompt library, and applies the corresponding prompt guidance according to the error type, so that the locally generated code can meet the grammatical requirements while maintaining the integrity of the logical structure and not affecting other modules; According to the type of local generated feedback, local adjustments are made by automatically selecting the setting instructions in the Prompt library, including errors in data type errors and conditional logic inconsistencies. The local generated Prompt directly applies the corresponding corrections in the template.

8. The method for generating endogenous safe isomers based on a large language model according to claim 6, characterized in that: After the local fragments are generated, the overall syntax, logic and module consistency of the code are verified through complete compilation detection and functional consistency testing, so that the locally adjusted code meets the global functional requirements; including: After the local fragments are generated and replaced, a complete compilation test is performed to verify that the local adjustments do not destroy the overall code consistency by checking the dependencies and variable consistency between modules; For functional verification of heterogeneous code, a set of preset functional test cases is used to perform consistency checks on all generated code paths. Functional consistency testing is based on the boundary conditions and random inputs of fuzz testing to fully verify the functionality of the code. During the global verification phase, multi-level coverage testing is performed, including syntax, logic, and functional coverage monitoring. The coverage of each layer of verification is recorded to verify whether the generated code meets the syntax requirements and whether the functions are consistent.

9. The method for generating endogenous safe isomers based on a large language model according to claim 1, characterized in that: Step 3: Based on the fuzz testing method, extract the isomer codes with inconsistent logical functions under different fuzz testing input information and feed them back to the large language model after the first adjustment; include: Construct diverse test inputs for the generated heterogeneous code, including random values, extreme values, boundary conditions, and abnormal inputs, so that the heterogeneous code can run under different inputs to test various logical branches and boundary conditions; During the code running process, the execution path and logic branches of the code are monitored in real time through dynamic instrumentation, and the running path and logic branch triggering status of each test are recorded; Record the path coverage of each test, analyze the code coverage, and find out the untriggered logic branches and uncovered paths. The path coverage is used to identify functional vulnerabilities and logic defects. Based on the results of path coverage analysis, new test cases are automatically generated to test untriggered paths and branches. The functional inconsistencies of heterogeneous codes under different input conditions are recorded, including the specific manifestations and locations of the inconsistencies. The test results are output as feedback information to the large language model after the first adjustment.

10. The method for generating endogenous safe isomers based on a large language model according to claim 1, characterized in that: In step 3, the isomorphic code generation parameters in the large language model are adjusted for the second time; Generate heterogeneous code using the large language model adjusted for the second time as a safe heterogeneous code; including: Extract functional inconsistencies from feedback obtained from fuzz testing, including trigger conditions, performance differences, and related code locations; The large language model uses the built prompt library to adjust the guidance according to the specific inconsistencies in the feedback information to generate code that meets the functional consistency requirements; During the generation process, the large language model adjusts the code logic of the heterogeneous entities based on feedback information, focusing on optimizing the algorithm steps, data flow, and boundary condition processing, so that the heterogeneous entities have consistent functional logic performance; After each optimization generation, the functional performance of the isomers is retested. If inconsistencies still exist, the new feedback information is passed back to the model for the next round of generation, and multiple rounds of feedback and optimization are performed; After completing multiple rounds of optimization, a final functional consistency verification is performed to confirm that all isomers perform consistently under various input conditions and are functionally equivalent. The verified consistent isomers are used as the final output.

11. The method for generating endogenous safe isomers based on a large language model according to claim 10, characterized in that: After completing multiple rounds of optimization, a final functional consistency verification is performed to confirm that all isomers perform consistently under various input conditions and are functionally equivalent; including: In all test cases, if the path coverage of each isomer reaches the same coverage, the logic is confirmed to be consistent; By comparing the output data values ​​and formats under the same input conditions, it is confirmed that all isomers behave consistently in output; If all isomers behave the same when encountering extreme values ​​or abnormal inputs, it is confirmed that the processing logic and output results are consistent under boundary conditions; If the path coverage is consistent, the output is consistent, and the boundary processing verification is consistent, the isomers are functionally equivalent.

12. An endogenous security isomer generation system based on a large language model, comprising: The error repair and guidance module, the isomer generation module and the security optimization module are characterized by: The error repair and guidance module is used to extract the error type and its corresponding repair solution to form multiple question-answer pairs; according to the error type, the structure and logical function of the error code, hierarchical guidance instructions are generated, and the guidance is used to adjust the large language model to generate the code after the error is repaired; The isomer generation module is used to convert the repaired code into isomer codes under different compilation languages; extract the isomer codes with errors during the compilation process, feed them back to the large language model, complete the first adjustment to optimize the isomer code generation parameters, and generate isomer codes that pass the compilation; The security optimization module is used to detect the logical functions of heterogeneous codes under different input conditions through fuzz testing, extract heterogeneous codes with inconsistent logical functions and feed them back to the large language model. After the second adjustment, heterogeneous codes with consistent logic and inherent security are generated.

Citation Information

Cited By

  • Code repairing method and device, computer program product and electronic equipment

    CN120315746A