Formalized verification method and device based on intelligent model interaction
By using a formal verification method based on intelligent model interaction, and generating security assertions using large language models and thought chain templates, the formal verification process is simplified, the professional knowledge requirements are reduced, and the verification efficiency and interpretability are improved. This method is applicable to critical software in multiple fields.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA ACADEMY OF INFORMATION & COMM
- Filing Date
- 2025-12-18
- Publication Date
- 2026-05-15
AI Technical Summary
Existing formal verification methods have high technical barriers and high professional requirements, making it difficult to achieve formal verification quickly and efficiently.
A formal verification method based on intelligent model interaction is adopted. The preprocessed source code for inserting security assertions is generated by a large language model. Combined with thought chain templates and semantic analysis prompt word templates, the professional knowledge requirements are reduced and the verification process is simplified.
It reduces the professional knowledge requirements for formal verification, improves verification efficiency and interpretability, can quickly identify high-risk paths and provide optimization suggestions, and is suitable for formal verification of critical software in multiple fields.
Smart Images

Figure CN122046360A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer data processing technology, and more particularly to a formal verification method and apparatus based on intelligent model interaction. Background Technology
[0002] Formal verification is an advanced security technique that describes and verifies computer hardware and software systems based on rigorous mathematical foundations. Its core comprises two parts: formal specification and formal verification techniques. Formal specification uses formal semantics (including operational semantics, algebraic semantics, denotational semantics, axiomatic semantics, etc.) and formal models (such as Event-B, automata, Petri nets, CSP, etc.) to accurately model the semantics and behavior of program code, forming formal specifications of security requirements. Formal verification techniques transform program analysis and verification problems into mathematical judgment problems, solving them using techniques such as theorem provers (automatic / interactive), model checking, abstract interpretation, and symbolic execution to verify whether the code under test meets security requirements.
[0003] In practical applications, formal verification methods are strongly recommended or mandated for high-level security certifications. They effectively reduce design and implementation defects in critical source code (such as kernel memory management), ensuring software functions as expected. However, they place extremely high demands on the expertise of testers. For example, testers need to possess code reading, mathematical modeling, and logical deduction skills, requiring a knowledge base far exceeding that of traditional security testing. Taking C language code verification as an example, testers must expand the program path through symbolic execution, transform the code semantics into first-order logical formulas and generate conjunctive normal form, and then use tools such as SMT solvers for verification. This presents a high technical barrier.
[0004] In summary, there is an urgent need for a technical solution that can overcome the above-mentioned shortcomings, lower the technical threshold, and achieve formal verification quickly, efficiently, reasonably, and accurately. Summary of the Invention
[0005] To address the problems existing in the prior art, this invention proposes a formal verification method and apparatus based on intelligent model interaction.
[0006] In a first aspect of this invention, a formal verification method based on intelligent model interaction is proposed, the method comprising:
[0007] The system receives security constraints input by testers in natural language and generates a user security attribute constraint file based on these constraints.
[0008] Based on the user security attribute constraint file, a source code preprocessing request is generated using a mind chain template; wherein, the source code preprocessing request includes at least multi-dimensional information such as preprocessing objectives, code function description, code text to be processed, mind chain prompts, and format requirements;
[0009] Based on the source code preprocessing request and the source code to be verified, preprocessed source code with inserted security assertions is generated through large language model inference.
[0010] Formal verification is performed on the preprocessed source code, and intermediate files are generated during the formal verification process.
[0011] Based on the intermediate file, the semantic analysis prompt word template is used for analysis, and natural language prompts corresponding to the optimization direction are output to the testers.
[0012] In a second aspect of the present invention, a formal verification apparatus based on intelligent model interaction is proposed, the apparatus comprising:
[0013] The user security attribute constraint module is used to receive security constraint conditions input by testers in natural language, and generate a user security attribute constraint file based on the security constraint conditions.
[0014] The Mind Chain Template Module is used to generate a source code preprocessing request based on the user security attribute constraint file using a Mind Chain Template; wherein, the source code preprocessing request includes at least multi-dimensional information such as preprocessing target, code function description, code text to be processed, mind chain prompts, and format requirements;
[0015] The large language model code preprocessing module is used to generate preprocessed source code with inserted security assertions by reasoning through the large language model based on the source code preprocessing request and the source code to be verified.
[0016] The model checking module is used to perform formal verification on the preprocessed source code and generate intermediate files during the formal verification process.
[0017] The large language model process analysis module is used to analyze the intermediate file based on the semantic analysis prompt word template and output natural language prompts corresponding to the optimization direction to the testers.
[0018] In a third aspect of the present invention, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement a formal verification method based on intelligent model interaction.
[0019] In a fourth aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing a computer program, which, when executed by a processor, implements a formal verification method based on intelligent model interaction.
[0020] In a fifth aspect of the present invention, a computer program product is proposed, the computer program product comprising a computer program that, when executed by a processor, implements a formal verification method based on intelligent model interaction.
[0021] The formal verification method and apparatus based on intelligent model interaction proposed in this invention constructs a formal verification interaction framework with a large model as the intermediate medium. It combines a security attribute preprocessing template based on thought chain and a semantic analysis prompt word template based on context learning. This ensures the determinism and verifiability of formal verification while significantly expanding its natural language processing capabilities and reducing the professional knowledge requirements for testers. Simultaneously, it guides the large model to accurately generate preprocessing code containing security assertions, quickly identifies high-risk paths, and provides optimization prompts such as bounded expansion values. This effectively simplifies the verification process, improves verification efficiency and interpretability, and also possesses good scenario generalization capabilities, adapting to the formal verification needs of key software in multiple domains, providing strong technical support for computer technology scenarios. Attached Figure Description
[0022] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0023] Figure 1 This is a schematic diagram of a formal verification method based on intelligent model interaction according to an embodiment of the present invention.
[0024] Figure 2 This is a schematic diagram of the architecture of a formal verification device based on intelligent model interaction according to an embodiment of the present invention.
[0025] Figure 3 This is a schematic diagram of a formal verification process based on intelligent model interaction, according to the first specific embodiment of the present invention.
[0026] Figure 4 This is a schematic diagram of the system architecture of the second specific embodiment of the present invention.
[0027] Figure 5 This is a schematic diagram of a computer device structure according to an embodiment of the present invention. Detailed Implementation
[0028] The principles and spirit of the invention will now be described with reference to several exemplary embodiments. It should be understood that these embodiments are given merely to enable those skilled in the art to better understand and implement the invention, and are not intended to limit the scope of the invention in any way. Rather, these embodiments are provided to make this disclosure more thorough and complete, and to fully convey the scope of this disclosure to those skilled in the art.
[0029] Those skilled in the art will recognize that embodiments of the present invention can be implemented as a system, apparatus, device, method, or computer program product. Therefore, this disclosure can be specifically implemented in the following forms: entirely hardware, entirely software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.
[0030] According to an embodiment of the present invention, a formal verification method and apparatus based on intelligent model interaction is proposed, which relates to the field of computer data processing technology.
[0031] The principles and spirit of the present invention will be explained in detail below with reference to several representative embodiments.
[0032] Figure 1 This is a schematic diagram of a formal verification method based on intelligent model interaction according to an embodiment of the present invention. Figure 1 As shown, the method includes:
[0033] S101: Receive security constraints input by the tester in natural language, and generate a user security attribute constraint file based on the security constraints;
[0034] S102, Based on the user security attribute constraint file, a source code preprocessing request is generated using a mind chain template; wherein, the source code preprocessing request includes at least multi-dimensional information such as preprocessing target, code function description, code text to be processed, mind chain prompts, and format requirements;
[0035] S103, Based on the source code preprocessing request and the source code to be verified, generate preprocessed source code with inserted security assertions through large language model reasoning;
[0036] S104, Perform formal verification on the preprocessed source code, and generate intermediate files during the formal verification process;
[0037] S105, Based on the intermediate file, perform analysis based on the semantic analysis prompt word template, and output natural language prompts corresponding to the optimization direction to the testers.
[0038] To provide a clearer explanation of the formal verification method based on intelligent model interaction, each step will be described in detail below.
[0039] In one embodiment, for S101, the security constraints input by the tester in natural language are received, and a user security attribute constraint file is generated based on the security constraints.
[0040] The security constraints include information from multiple dimensions, including functional descriptions, security attribute constraints, and domain knowledge.
[0041] The functional description is used to describe the functional name and description of the code under test; the security attribute constraints are used to describe the security constraints that the code under test needs to satisfy; and the domain knowledge is used to provide technical knowledge of the domain to which the code under test belongs.
[0042] The test code uses natural language to describe security constraints, including array out-of-bounds errors and memory leaks, clearly defining the security constraints that the code under test must meet. These constraints include three dimensions: functional description, security attribute constraints, and domain knowledge. Testers write user-defined security attribute constraints according to these three dimensions, based on the formal verification objectives they need to achieve. The functional description describes the code's function name and description, while the security attribute constraints describe the requirements of the security constraints.
[0043] In one embodiment, for S102, a source code preprocessing request is generated using a mind chain template based on the user security attribute constraint file; wherein the source code preprocessing request includes at least multi-dimensional information such as preprocessing target, code function description, code text to be processed, mind chain prompts, and format requirements.
[0044] Specifically, a code preprocessing template is constructed based on the thinking chain technology to generate a source code preprocessing request. The thinking chain template includes at least an array out-of-bounds preprocessing template and a memory leak preprocessing template.
[0045] The array out-of-bounds preprocessing template is used to guide the large language model to perform boundary checks, null pointer checks, memory region checks, type alignment checks, and determine the insertion position of the safety assertion.
[0046] The memory leak preprocessing template is used to guide the large language model to establish a reference count variable, increase the reference count during memory allocation operations, decrease the reference count during memory release operations, and determine the insertion position of the safety assertion for reference count value detection.
[0047] To better handle user security attribute constraints described in natural language, a thought chain is used to design prompt word templates for array out-of-bounds errors and memory leaks. Further, in step S103, security assertions are inserted into the C language source code program to be verified using the large language model code preprocessing step, forming a C language source code program containing user security attribute constraints, which is then formally verified in step S104.
[0048] In practical applications, the thought chain template includes code preprocessing templates for array out-of-bounds errors and memory leaks. These three types of templates describe the detailed safety constraints that need to be set for out-of-bounds checks and memory leaks, respectively. The thought chain technology guides the large model to generate and insert safety assertions in specific directions for formal verification (S104). The specific content consists of five dimensions: preprocessing objectives, code function descriptions, code text to be processed, thought chain prompts, and format requirements. The preprocessing objectives describe different formal verification categories such as array out-of-bounds errors and memory leaks. The code function description represents the code function name and description. The code text to be processed sets the C language source code to be formally verified. The thought chain prompts provide step-by-step thinking steps, guiding the large language model to generate and insert safety constraint assertions. The format mainly describes information such as programming language style and template division.
[0049] In one embodiment, for S103, based on the source code preprocessing request and the source code to be verified, preprocessed source code with inserted security assertions is generated through large language model inference.
[0050] By parsing the program semantics of the source code to be verified, a security assertion that conforms to the security constraints is inserted at a preset location, while maintaining the original program structure of the source code to be verified.
[0051] It accepts thought chain template input, performs large language model reasoning, and generates C language source code programs containing user security attribute constraints.
[0052] In practical applications, preprocessed code is generated through logical reasoning. The big oracle model can adopt a general big model; the preprocessed code is formally verified by S104.
[0053] In one embodiment, for S104, formal verification is performed on the preprocessed source code, and intermediate files are generated during the formal verification process.
[0054] The preprocessed source code is parsed to generate an abstract syntax tree and a control flow graph. The program path is expanded through symbolic execution, and the path constraints are transformed into satisfiability problems for solution, generating intermediate files. The intermediate files include at least an abstract syntax tree visualization file.
[0055] Furthermore, the method also includes:
[0056] Upon receiving the optimization selection instruction from the tester, if the optimization selection instruction is to perform optimization, the system will first explore the execution path that meets the preset risk conditions and call the large language model for optimization analysis, outputting optimization prompts with bounded expansion values; if the optimization selection instruction is not to perform optimization, the system will expand all execution paths of the program according to the original path.
[0057] Specifically, the preprocessed C language source code program is received, a control flow graph is generated by parsing the AST syntax tree, a large language model is called for optimization analysis, all execution paths of the program are expanded using symbolic execution, and the path is checked for compliance with user security attribute constraints by solving the SAT problem.
[0058] In one embodiment, for S105, based on the intermediate file, analysis is performed based on the semantic analysis prompt word template, and natural language prompts corresponding to the optimization direction are output to the tester.
[0059] The semantic analysis prompt template includes information from multiple dimensions, including analysis purpose, background knowledge, source code text, intermediate files to be processed, context learning prompts, and format requirements.
[0060] Specifically, it receives process files such as abstract syntax tree (SVG) files, symbolic execution trajectory logs, first-order logical constraint lists, and intermediate representations. It analyzes these files based on semantic prompt word templates and provides optimization suggestions such as high-risk path exploration and bounded expansion numerical settings.
[0061] To provide testers with an intuitive understanding of formal verification and optimization hints, we use context-based semantic analysis hint word templates to guide large language models in reasoning to generate optimization hints such as high-risk path exploration and bounded expansion.
[0062] It should be noted that although the operation of the method of the present invention has been described in a specific order in the above embodiments and figures, this does not require or imply that the operations must be performed in that specific order, or that all the operations shown must be performed to achieve the desired result. Additionally or alternatively, certain steps may be omitted, multiple steps may be combined into one step, and / or one step may be broken down into multiple steps.
[0063] After introducing the method of exemplary embodiments of the present invention, the following references are made. Figure 2 This paper introduces a formal verification device based on intelligent model interaction according to an exemplary embodiment of the present invention.
[0064] The implementation of the formal verification apparatus based on intelligent model interaction can refer to the implementation of the above method, and the repeated parts will not be described again. The terms "module" or "unit" used below can be a combination of software and / or hardware that implements a predetermined function. Although the apparatus described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0065] Based on the same inventive concept, this invention also proposes a formal verification device based on intelligent model interaction, such as... Figure 2 As shown, the device includes:
[0066] User security attribute constraint module 210 is used to receive security constraint conditions input by testers in natural language, and generate user security attribute constraint files based on the security constraint conditions.
[0067] The mind chain template module 220 is used to generate a source code preprocessing request based on the user security attribute constraint file using the mind chain template; wherein, the source code preprocessing request includes at least multi-dimensional information such as preprocessing target, code function description, code text to be processed, mind chain prompts, and format requirements;
[0068] The large language model code preprocessing module 230 is used to generate preprocessed source code with inserted security assertions by reasoning through the large language model based on the source code preprocessing request and the source code to be verified.
[0069] The model checking module 240 is used to perform formal verification on the preprocessed source code and generate intermediate files during the formal verification process.
[0070] The large language model process analysis module 250 is used to analyze the intermediate file based on the semantic analysis prompt word template and output natural language prompts corresponding to the optimization direction to the testers.
[0071] It should be noted that although several modules of the formal verification apparatus based on intelligent model interaction have been mentioned in the detailed description above, this division is merely exemplary and not mandatory. In fact, according to embodiments of the present invention, the features and functions of two or more modules described above can be embodied in one module. Conversely, the features and functions of one module described above can be further divided and embodied by multiple modules. Specific Implementation Example 1:
[0073] refer to Figure 3 This is a schematic diagram of the formal verification process based on intelligent model interaction in the first specific embodiment of the present invention. Figure 3 As shown, the specific methods include:
[0074] S301, the user security attribute constraint module helps testers describe security constraints such as array out-of-bounds and memory leaks in natural language, and form a custom security constraint file;
[0075] S302, the thought chain template generates a large language model code preprocessing command request based on five dimensions of prompt words, and sends the request to the large language model code preprocessing module to generate a new source code program containing security assertions by utilizing the security constraint condition file and the source code program to be tested.
[0076] S303 generates a fuzzy test seed generation command request for the large language model based on five dimensions of prompt words, and sends the request to the large language model code preprocessing module.
[0077] S304, the large language model code preprocessing module accepts the request, parses the semantics of the source code program to be tested one by one, inserts security assertions that meet the security constraints, and sends the newly generated code to the model checking module.
[0078] S305, the model checking module uses AST syntax tree parsing to generate a control flow graph, calls the large language model process analysis module for optimization analysis, and provides optimization prompts for high-risk path exploration and bounded expansion numerical settings.
[0079] In S306, testers gain an intuitive understanding of the formal verification based on the prompts and choose whether to perform optimization verification. If so, the optimization path prioritizes exploring high-risk execution paths and sets bounded expansion values according to the optimization prompts; otherwise, all execution paths of the program are expanded according to the original path. Finally, the SAT problem-solving process is used to check whether the path meets the user's security attribute constraints. Specific Implementation Example 2:
[0081] This article will take a formal verification system based on intelligent model interaction as an example for detailed explanation, and refer to... Figure 4 This is a schematic diagram of the system architecture relationship in the second specific embodiment of the present invention. Figure 4 As shown, the specific architecture is as follows:
[0082] The user security attribute constraint module serves as the entry point for testers to interact with the system. It receives security constraint requirements described by testers in natural language and outputs structured security constraint files.
[0083] The thought chain template module communicates with the user security attribute constraint module, receives the security constraint file output by it, generates a source code preprocessing command request adapted to the large model, and sends it to the large language model code preprocessing module.
[0084] Input the source code to be verified into the Mind Chain Template module;
[0085] The large language model code preprocessing module communicates with the mind chain template module and the model checking module respectively. After receiving the preprocessing command request, it generates new source code containing security assertions and passes it to the model checking module.
[0086] The model checking module, as the core verification module, communicates with the large language model code preprocessing module and the large language model process analysis module respectively, executes the formal verification process, receives optimization prompts and provides feedback on the verification results;
[0087] The large language model process analysis module communicates with the model checking module, receives intermediate files during the verification process, generates optimization suggestions, and provides feedback to the model checking module and testers.
[0088] In one specific embodiment, the user security attribute constraint module is used to clarify the security constraint requirements of the code under test. Testers do not need to have professional formal verification knowledge. They only need to write the constraint content in natural language according to the three dimensions of functional description, security attribute constraints, and domain knowledge to generate the user security attribute constraint file.
[0089] Taking the verification of the page state consistency check function of the memory management system (the code under test is written in C language and implemented based on the buddy system) as an example, the security constraint file written by the testers is as follows:
[0090] Function Description: This code module is the page state consistency check function of the memory management system. It is mainly used to verify the state of the memory management module (page ev_page_t in the buddy system), count statistics, and the correctness of the free list. The core function is to traverse the memory region (mem_reg) and memory zone (mem_zone), count the number of pages in different states, and cross-validate with the records in the free list to ensure the consistency of the internal state of memory management.
[0091] User security attribute constraints: 1. If this code uses an array, there should be no array out-of-bounds errors; 2. If this code performs boundary checks, there should be no arithmetic overflows; 3. If pointer operations are used, there should be no memory leaks.
[0092] Domain knowledge: The Buddy System is an efficient memory management algorithm, mainly used for the allocation and reclamation of physical memory pages in the operating system. Its core idea is to manage memory blocks (called "page blocks") with a fixed size of powers of 2 through a recursive splitting and merging mechanism, so as to achieve fast allocation and fragmentation control.
[0093] After receiving the above input, it is automatically formatted into a structured file to provide standardized input for the subsequent mind chain template module.
[0094] In one specific embodiment, the mind chain template module includes dedicated code preprocessing templates for array out-of-bounds errors, memory leaks, etc. Each type of template consists of five dimensions: preprocessing target, background knowledge, code text to be processed, mind chain prompts, and format requirements. The mind chain technology guides the large model to accurately insert security assertions.
[0095] Taking array out-of-bounds and memory leak verification as examples, the specific configuration of the mind chain template is as follows:
[0096] Preprocessing objective: Insert security assertions into the C language source code to be tested, making it contain checks for array out-of-bounds access and memory leaks, so that the model checking module can perform formal verification.
[0097] Background knowledge: Fill in the functional description, domain knowledge and security attribute constraints output by the user security attribute constraint module (i.e., the relevant description and constraint requirements of the memory management system mentioned above);
[0098] Code to be processed: Enter the C language source code to be formally verified (marked as needtoverifiedCode).
[0099] Mind chain prompts:
[0100] The thought process for preprocessing array out-of-bounds errors is as follows: First, refer to background knowledge and source code functionality to analyze and mark arrays, pointers, and memory variables in the source code. Second, to ensure that all array access indices are within the legal range, determine the specific locations in the source code where boundary checks, null pointer checks, memory region checks, and type alignment checks need to be performed. Third, based on user security attribute requirements, add security assertions in the appropriate locations to implement the above checks. Fourth, combine source code functionality and comments to precisely determine the check range and values of the security assertions.
[0101] Memory leak preprocessing thought process: First, analyze and mark arrays and pointers in the source code, referring to background knowledge and source code functionality. Second, identify memory allocation and deallocation operations in the source code. Third, add a reference count variable inside each function; increment the reference count during memory allocation and decrement it during memory deallocation. Fourth, determine the insertion points for safety assertions to check reference count values and ensure all allocated resources are correctly released. Fifth, optimize the insertion of safety assertions based on user security attribute requirements. Sixth, utilize source code functionality and comments to precisely determine the scope and value of safety assertion checks.
[0102] Formatting requirements: Maintain the original C language programming style, do not modify the source code structure, and only perform the operation of adding security assertions.
[0103] Based on the above template, this module generates a large language model code preprocessing command request, clearly informing the large model preprocessing objectives, basis, and format specifications, ensuring that the generated code meets the verification requirements.
[0104] In one specific embodiment, the large language model code preprocessing module adopts a general large model. After receiving the preprocessing command request sent by the mind chain template module, it performs the following operations:
[0105] Analyze the semantics of the source code to be processed in the request, and combine background knowledge and user security attribute constraints to understand the functional logic and key points of security verification of the code;
[0106] Guided by the thought chain prompts, reason step by step about the insertion location and specific content of security assertions: For array out-of-bounds verification, insert an index validity check assertion before array access; for memory leak verification, initialize the reference count at memory allocation and decrement the count and insert an assertion at memory release.
[0107] Generate new C source code containing security assertions, ensuring correct syntax and complete structure, without changing the original functional logic, and only adding security check statements;
[0108] The newly generated source code is sent to the model checking module as input for formal verification.
[0109] In one specific embodiment, the model checking module is the core execution unit of formal verification. After receiving the new source code output by the large language model code preprocessing module, it performs verification. The specific steps are as follows:
[0110] AST syntax tree parsing: The new source code is parsed using an Abstract Syntax Tree (AST) to generate an AST syntax tree SVG file, which clearly presents the syntax structure, function call relationships, and loop and branch logic of the code;
[0111] Optimization analysis request sending: Send the AST syntax tree SVG file, symbolic execution trajectory log, first-order logic constraint list and intermediate representation and other process files to the large language model process analysis module to request the generation of optimization suggestions.
[0112] Verify path expansion: Receive optimization suggestions (such as high-risk path identifiers and bounded expansion values) from the large language model flow analysis module, and combine these with the testers' optimization selection to execute path expansion. The processing method is as follows:
[0113] If the tester chooses to optimize the verification, they should prioritize exploring high-risk paths (such as string copying paths without length checks) and set bounded expansion values as prompted (such as setting the expansion value of nested loops to N*M, where N and M are array dimensions).
[0114] If you choose not to optimize, the program will proceed according to its original logic, expanding all execution paths.
[0115] SAT problem solving: The semantics of each execution path are transformed into a first-order logical formula through symbolic execution technology, generating a conjunctive normal form (CNF). The SAT solver is then called to determine whether the formula is satisfied: if it is satisfied, it indicates that the path satisfies the security constraints; if it is not satisfied, there is a security vulnerability, and the location and cause of the vulnerability are recorded.
[0116] In one specific embodiment, the large language model process analysis module, based on the semantic analysis prompt word template learned from context learning, receives the process file sent by the model checking module and generates optimization prompts, as specifically implemented as follows:
[0117] Analysis objective: To analyze the intermediate SVG syntax tree (AST) file, identify potential high-risk paths, and provide bounded expansion value hints for loop structures to guide the formal verification process.
[0118] Background knowledge; fill in the code function description and domain knowledge (memory management system page state consistency check function, buddy system principle) in the user security attribute constraint module 100.
[0119] Source code text; fill in the new C language source code generated by the large language model code preprocessing module 200;
[0120] The SVG intermediate file to be processed; the AST syntax tree SVG file generated by the model checking module 300;
[0121] Contextual learning prompts; includes C language code examples (such as high-risk cases like unsafe loop exits, branches lacking safety checks, and improper handling of abnormal data flow), CFG control flow explanations, and bounded expansion analysis content (explicit loop boundary constants, array size loops, loop dependencies, recursion depth analysis, and switch-case number analysis).
[0122] Formatting requirements: The language style should be simple and concise, using a step-by-step analysis and chart-based format to explain the prompts, with an SVG document explanation appended at the end.
[0123] The specific mechanisms for semantic analysis and suggestion generation include:
[0124] High-risk path identification: By combining high-risk features in context learning prompts, we analyze the loop structure, branch path and data flow in the AST syntax tree SVG file to identify high-risk paths such as unsafe loop exits, string operations without length checks, and unclosed file I / O. For example, we mark "the strcpy operation in the function process_input does not perform input length checks, which poses a risk of array out-of-bounds errors".
[0125] Bounded numerical expansion: Based on the semantic analysis of the code, the loop boundary is analyzed. For explicit constant loops, the constant is directly used as the expansion value. For nested loops, the product N*M is calculated as the expansion value. For recursive functions, the recursion depth is determined according to the recursion termination condition.
[0126] Optimization prompts and feedback: The identified high-risk path list and bounded expansion numerical suggestions are fed back to the model inspection module and presented to the testers in natural language to help them intuitively understand the key points of verification.
[0127] The main improvements in this application are: 1) A formal verification interaction framework based on a large model. From user security attribute constraints to large language model preprocessing, to calling formal verification tools, and then interacting with the large language model process analysis, the entire verification process is optimized. 2) A thought chain template. Utilizing five dimensions—preprocessing objectives, background knowledge, code text to be processed, thought chain prompts, and format requirements—and thought chain methods targeting array out-of-bounds errors and memory leaks, the framework improves the comprehensive understanding of C language code semantics, functionality, and specific user security attribute constraints within the large language model, generating preprocessed code and accelerating the formal verification process. 3) A semantic analysis prompt template based on context learning. Utilizing six dimensions—analysis purpose, background knowledge, source code text, intermediate SVG files to be processed, context learning prompts, and format requirements—and context learning prompts designed for high-risk path analysis and bounded expansion numerical settings, the framework effectively guides the direction of formal verification and reduces its complexity.
[0128] Compared to existing technologies, this application offers at least the following technical advantages: 1) It provides a formal verification interaction framework based on a large model, using the large model as an intermediary between testers and formal verification tools. On one hand, it interacts with testers in natural language, allowing testers to describe user security attribute constraints, obtain intuitive explanations of key formal verification processes, and adjust the optimization direction of formal verification (such as high-risk path exploration and bounded expansion numerical settings). On the other hand, it calls formal verification tools to perform specific model checks and obtain key verification process information. This framework ensures the determinism and verifiability of formal verification while expanding the natural language processing capabilities of formal verification, improving the interpretability of the verification process, and reducing the professional knowledge requirements of testers for formal verification. 2) Utilizing a mind-chain-based security attribute preprocessing template guides the large language model to comprehensively generate preprocessed code containing multiple security assertions, such as array out-of-bounds and memory overflow, by combining information such as C language code semantics, functionality, and specific user security attribute constraints. This simplifies and accelerates the formal verification process. For example, formal verification tools can initially determine whether the tested code has security risks such as array out-of-bounds and memory overflow simply by checking whether the newly added assertions are satisfied. 3) Context-learning-based semantic analysis prompt word templates fully leverage the powerful semantic understanding and reasoning capabilities of the large language model, effectively optimizing the formal verification process. Simultaneously, it provides a tester interface that interacts in natural language, improving the efficiency and interpretability of the verification process. Furthermore, it offers testers richer and easier-to-understand verification process information.
[0129] Based on the aforementioned inventive concept, such as Figure 5 As shown, the present invention also proposes a computer device 500, including a memory 510, a processor 520, and a computer program 530 stored in the memory 510 and executable on the processor 520. When the processor 520 executes the computer program 530, it implements the aforementioned formal verification method based on intelligent model interaction.
[0130] Based on the aforementioned inventive concept, the present invention proposes a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the aforementioned formal verification method based on intelligent model interaction.
[0131] Based on the aforementioned inventive concept, this invention proposes a computer program product, which includes a computer program that, when executed by a processor, implements a formal verification method based on intelligent model interaction.
[0132] The formal verification method and apparatus based on intelligent model interaction proposed in this invention constructs a formal verification interaction framework with a large model as the intermediate medium. It combines a security attribute preprocessing template based on thought chain and a semantic analysis prompt word template based on context learning. This ensures the determinism and verifiability of formal verification while significantly expanding its natural language processing capabilities and reducing the professional knowledge requirements for testers. Simultaneously, it guides the large model to accurately generate preprocessing code containing security assertions, quickly identifies high-risk paths, and provides optimization prompts such as bounded expansion values. This effectively simplifies the verification process, improves verification efficiency and interpretability, and also possesses good scenario generalization capabilities, adapting to the formal verification needs of key software in multiple domains, providing strong technical support for computer technology scenarios.
[0133] The acquisition, storage, use, and processing of data in this application all comply with relevant laws and regulations.
[0134] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0135] This invention is described with reference to flowchart illustrations and / or block diagrams of methods and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0136] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0137] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0138] Finally, it should be noted that the above-described embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A formal verification method based on intelligent model interaction, characterized in that, The method includes: The system receives security constraints input by testers in natural language and generates a user security attribute constraint file based on these constraints. Based on the user security attribute constraint file, a source code preprocessing request is generated using a mind chain template; wherein, the source code preprocessing request includes at least multi-dimensional information such as preprocessing objectives, code function description, code text to be processed, mind chain prompts, and format requirements; Based on the source code preprocessing request and the source code to be verified, preprocessed source code with inserted security assertions is generated through large language model inference. Formal verification is performed on the preprocessed source code, and intermediate files are generated during the formal verification process. Based on the intermediate file, the semantic analysis prompt word template is used for analysis, and natural language prompts corresponding to the optimization direction are output to the testers.
2. The formal verification method based on intelligent model interaction according to claim 1, characterized in that, The security constraints include information from multiple dimensions, including functional descriptions, security attribute constraints, and domain knowledge. The functional description is used to describe the functional name and description of the code under test; the security attribute constraints are used to describe the security constraints that the code under test needs to satisfy; and the domain knowledge is used to provide technical knowledge of the domain to which the code under test belongs.
3. The formal verification method based on intelligent model interaction according to claim 1, characterized in that, Based on the user security attribute constraint file, a source code preprocessing request is generated using the mind chain template, including: Based on the MindChain technology, code preprocessing templates are constructed to generate source code preprocessing requests. The MindChain templates include at least array out-of-bounds preprocessing templates and memory leak preprocessing templates. The array out-of-bounds preprocessing template is used to guide the large language model to perform boundary checks, null pointer checks, memory region checks, type alignment checks, and determine the insertion position of the safety assertion. The memory leak preprocessing template is used to guide the large language model to establish a reference count variable, increase the reference count during memory allocation operations, decrease the reference count during memory release operations, and determine the insertion position of the safety assertion for reference count value detection.
4. The formal verification method based on intelligent model interaction according to claim 1, characterized in that, Based on the source code preprocessing request and the source code to be verified, preprocessed source code with inserted security assertions is generated through large language model inference, including: By parsing the program semantics of the source code to be verified, a security assertion that conforms to the security constraints is inserted at a preset location, while maintaining the original program structure of the source code to be verified.
5. The formal verification method based on intelligent model interaction according to claim 1, characterized in that, Formal verification is performed on the preprocessed source code, and intermediate files are generated during the formal verification process, including: The preprocessed source code is parsed to generate an abstract syntax tree and a control flow graph. The program path is expanded through symbolic execution, and the path constraints are transformed into satisfiability problems for solution, generating intermediate files. The intermediate files include at least an abstract syntax tree visualization file.
6. The formal verification method based on intelligent model interaction according to claim 5, characterized in that, The method also includes: Upon receiving the optimization selection instruction from the tester, if the optimization selection instruction is to perform optimization, the system will first explore the execution path that meets the preset risk conditions and call the large language model for optimization analysis, outputting optimization prompts with bounded expansion values; if the optimization selection instruction is not to perform optimization, the system will expand all execution paths of the program according to the original path.
7. The formal verification method based on intelligent model interaction according to claim 1, characterized in that, The semantic analysis prompt template includes information from multiple dimensions, including analysis purpose, background knowledge, source code text, intermediate files to be processed, context learning prompts, and format requirements.
8. A formal verification device based on intelligent model interaction, characterized in that, The device includes: The user security attribute constraint module is used to receive security constraint conditions input by testers in natural language, and generate a user security attribute constraint file based on the security constraint conditions. The Mind Chain Template Module is used to generate a source code preprocessing request based on the user security attribute constraint file using a Mind Chain Template; wherein, the source code preprocessing request includes at least multi-dimensional information such as preprocessing target, code function description, code text to be processed, mind chain prompts, and format requirements; The large language model code preprocessing module is used to generate preprocessed source code with inserted security assertions by reasoning through the large language model based on the source code preprocessing request and the source code to be verified. The model checking module is used to perform formal verification on the preprocessed source code and generate intermediate files during the formal verification process. The large language model process analysis module is used to analyze the intermediate file based on the semantic analysis prompt word template and output natural language prompts corresponding to the optimization direction to the testers.
9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method of any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method of any one of claims 1 to 7.