A verification method and system for hybrid programming language programs against quantum-resistant cryptography
Patent Information
- Application Number
- CN202511550217.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-28
- Publication Date
- 2026-08-18
- Estimated Expiration
- 2045-10-28
AI Technical Summary
[0007]为解决现有形式化验证工具因缺乏某些功能特性和量子特性而无法有效验证量子密码与抗量子密码协议安全性的技术问题,本发明设计了一种混合编程语言,用于验证密码协议程序
本发明建立了统一的语法框架,为量子密码与抗量子密码的形式化验证提供了统一的表达框架。其中,统一的类型系统可以简化对量子操作的类型检查。例如,通过确保被测量子变量的类型与存储结果的经典变量的类型之间的一致性来验证量子测量是否有效。分层级的语句语法一方面统一了语法结构,简化了用户在编写代码时的复杂度;另一方面也便于精准解析程序的语义。例如,当经典变量赋值语句嵌套在量子条件语句中时,该语句会被识别为电路级语句。从语义层面来看,需要先存储
的临时值,在量子条件语句块执行完毕后再恢复该值。
Smart Images

Figure CN121478618B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer programming and security technology, and in particular to a design and formal verification method and system for a hybrid programming language used in cryptographic program development. Background Technology
[0002] In recent years, with the rapid development of quantum computing, quantum programming has become a highly anticipated research field. Cryptography, as a core application area of quantum programming, has seen the proposal of numerous quantum cryptographic protocols and quantum-resistant cryptographic protocols. However, the design and analysis of these protocols need to address various counterintuitive quantum effects, and the ever-increasing complexity of these protocols makes their security and correctness verification increasingly complex and prone to errors. Against this backdrop, formal verification, as a technical approach that can effectively prevent potential defects in the analysis and verification process, is becoming increasingly important.
[0003] In the field of quantum programming, numerous fundamental formal verification tools have been developed, with their core languages primarily designed for writing quantum algorithms or quantum circuits. In the fields of quantum cryptography and quantum-resistant cryptography, the qrhl-tool, based on the quantum relation Hall logic, has been developed and used to reason about the relational properties between two quantum programs. The EasyPQC tool, an extension of the classical cryptographic protocol formal verification tool EasyCrypt, focuses on proving quantum-resistant security.
[0004] Formal verification tools all have a reliable logical core, typically supported by a theorem prover logic system. Then, to verify a program, its semantics need to be formalized, which requires defining the syntax and semantics of the programming language within the proof helper. Finally, interactive proofs are performed using the theorem prover, or automated proofs are achieved using a solver based on the derived constraints.
[0005] Rocq, the interactive proof helper, is an interactive theorem prover that functions as both a formal verification tool and a functional programming language. Users can write mathematical definitions, algorithms, and logical propositions in a formal language and interactively construct rigorous mathematical proofs with the helper. Rocq relies on its type system to ensure consistency between the program and the proof, thereby checking the validity of the proof steps and ensuring the correctness of the completed proof.
[0006] The main problems with existing technologies are as follows: Firstly, the core languages of fundamental formal verification tools applied in the field of quantum programming are primarily designed for writing quantum algorithms or quantum circuits, lacking cryptographic features such as modeling unspecified adversaries, thus failing to fully meet the requirements for cryptographic security proofs. Secondly, formal verification techniques in the fields of quantum cryptography and quantum-resistant cryptography only support reasoning for finite quantum properties and are not fundamental verification frameworks. Therefore, this invention designs a hybrid programming language and develops a fundamental formal verification tool for verifying quantum cryptography and quantum-resistant cryptographic protocols based on the interactive proof assistant Rocq. Summary of the Invention
[0007] To address the technical problem that existing formal verification tools lack certain functional and quantum properties, thus hindering their ability to effectively verify the security of quantum cryptography and quantum-resistant cryptographic protocols, this invention designs a hybrid programming language for verifying cryptographic protocol programs. This language integrates classical programming features while introducing quantum-specific structures such as quantum control flow and quantum measurement. Based on this hybrid programming language, fundamental formal verification tools have been developed, enabling the complete and accurate description and automated verification of the security of complex cryptographic protocols, significantly improving the reliability and efficiency of verification.
[0008] The technical solution adopted in this invention is as follows: A verification method for hybrid programming language programs resistant to quantum cryptography includes the following steps: In Rocq, input the cryptographic protocol program to be verified based on a hybrid programming language; We formally model subroutines in cryptographic protocol programs using modular systems, and describe classical and quantum program behaviors in cryptographic protocol programs based on a unified syntax framework of a hybrid programming language. For programs written based on a unified syntax framework and module system, type checking and syntax checking of the program are automated through the Rocq-elpi plugin; For programs that pass type and syntax checks, the semantics of the program are generated according to the syntax in a unified syntax framework. According to the syntactic formalization description in the unified grammatical framework, the properties of the protocol that need to be proven; Establish inference rules based on program rewriting on the basis of grammar within a unified grammatical framework; By leveraging inference rules based on program rewriting and program semantics, and employing Rocq's own proof strategy, we can interactively prove the formally described protocol properties within Rocq.
[0009] Furthermore, the unified syntax framework includes a unified type system and a hierarchical statement syntax.
[0010] Furthermore, the unified type system adopts a unified type definition for classical or quantum variables, as shown below: in, Indicates the variable type; Indicates an integer type; Indicates a Boolean type; It is a paired type; express An array type of quantum variables or classical variables; Indicates application to The unitary operator type of a quantum variable.
[0011] Furthermore, the hierarchical statement syntax classifies program statements into three levels: classical statements, circuit statements, and hybrid statements. Classical statements involve only classical variables and exhibit classical computational behavior. Circuit statements include quantum control flow statements and unitary transformation operation statements, which can be compiled as part of a quantum circuit. Hybrid statements involve both classical and quantum variables. The three levels follow the upward compatibility principle of "classical < circuit < hybrid". If a nested sub-statement belongs to a lower-level statement, then the level of the statement containing the sub-statement is greater than or equal to the level of the sub-statement.
[0012] Furthermore, the module system includes module types and modules; a module type represents a collection of modules with a series of abstract properties, and its definition includes declarations of functions; a module, as an instance of a module type, contains definitions of functions and variables, and can inherit from multiple module types.
[0013] Furthermore, Rocq uses the Record structure mechanism to define base modules as types within Rocq. Base modules are considered abstract definitions of all module instances, used to standardize the definition structure of module instances; all module instances are then accessed through... The mechanism is defined as instance variables of the type represented by the base module, through... The structural mechanism defines each specific module type as a type in Rocq, through... The mechanism declares a module instance as a canonical instance of the module type it inherits from.
[0014] Furthermore, the type checking algorithm takes the abstract syntax tree of the module instance and its initial type environment as input, recursively traverses the abstract syntax tree, and verifies the type of each expression; the syntax checking takes the abstract syntax tree of the module instance and the module type inherited by the module instance as input, recursively traverses the abstract syntax tree, and checks whether the function of each module instance meets the function declaration and calling permission requirements of the module type inherited by the module instance.
[0015] A verification system for hybrid programming language programs resistant to quantum cryptography, comprising: The input unit is used to input the cryptographic protocol program to be verified in Rocq based on a hybrid programming language; Subroutine modeling unit, used to formally model subroutines in a cryptographic protocol program through a modular system; Program behavior description unit, used to describe classical and quantum program behavior in cryptographic protocol programs based on a unified syntax framework of hybrid programming languages; The checking unit is used to automatically perform type and syntax checks on programs written based on the unified syntax framework and module system through the Rocq-elpi plugin; The program semantics generation unit is used to generate program semantics based on the syntax in a unified syntax framework for programs that have passed type checking and syntax checking. Protocol property description unit, used to formally describe the protocol properties that need to be proven according to the syntactic framework of a unified syntax framework; The reasoning rule building unit is used to establish reasoning rules based on program rewriting within a unified grammatical framework. The interactive proof unit is used to interactively prove the properties of formally described protocols in Rocq using Rocq's own proof strategy, based on the inference rules and semantics of the program rewritten.
[0016] The beneficial effects of this invention are as follows: This invention establishes a unified syntactic framework, providing a consistent expression framework for the formal verification of quantum cryptography and quantum-resistant cryptography. The unified type system simplifies type checking of quantum operations. For example, the validity of a quantum measurement can be verified by ensuring consistency between the type of the measured sub-variable and the type of the classical variable storing the result. The hierarchical statement syntax unifies the syntactic structure, simplifying the complexity for users when writing code; it also facilitates precise semantic parsing of the program. For example, when a classical variable assignment statement... When nested within a quantum conditional statement, the statement is recognized as a circuit-level statement. From a semantic perspective, it needs to be stored first. The temporary value is restored after the quantum conditional statement block has finished executing.
[0017] The modular system of this invention enables the writing of multi-party protocols in cryptographic protocols. Large protocols can be reused through module types, and modules can effectively express the procedural behavior of cryptographic protocols. Furthermore, modules, as variables in the interactive proof assistant Rocq, can be used to prove procedural properties, and thus to perform formal verification on a subset of modules that meet specific conditions. Attached Figure Description
[0018] Figure 1 This is a flowchart of a verification method for a hybrid programming language program designed to resist quantum cryptography.
[0019] Figure 2 This is a module type structure diagram.
[0020] Figure 3 This is a block diagram of a verification system for a hybrid programming language program designed to resist quantum cryptography. Detailed Implementation
[0021] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to specific embodiments and accompanying drawings.
[0022] Key aspects of this invention include: 1) Unified Syntax Framework: This invention designs a unified syntax framework for hybrid programming languages, including a unified type system and hierarchical statement syntax, for integrating classical and quantum programming paradigms. This unified syntax framework provides a consistent framework for the formal verification of quantum cryptography and quantum-resistant cryptographic protocols, serving as the cornerstone of any further verification techniques.
[0023] 2) Module System: This invention designs a module system for unspecified programs in the interactive proof assistant Rocq, including the definition and implementation of module types and modules, for writing multi-party protocols in cryptography, and can define a specific subset of programs as module types.
[0024] The present invention provides a verification method for hybrid programming language programs resistant to quantum cryptography, the overall process of which is as follows: Figure 1 As shown, it includes the following steps: Step 1: The user inputs the cryptographic protocol program to be verified in Rocq based on the hybrid programming language of this invention.
[0025] Step 2: Formal model the subroutines in the cryptographic protocol program (multi-party cryptographic protocol) in Step 1 through a modular system, and describe the classical and quantum program behaviors in the cryptographic protocol program based on a unified syntax framework of a hybrid programming language.
[0026] Step 3: For the programs written in Step 2 based on the unified syntax framework and module system, the Rocq-elpi plugin is used to automatically perform type checking and syntax checking of the programs.
[0027] Step 4: For programs that pass the type and syntax checks in Step 3, generate their corresponding semantics based on the syntax in the unified syntax framework.
[0028] Step 5: The user describes the protocol properties that need to be proven based on the syntactic formalization of the unified syntactic framework in Step 2.
[0029] Step 6: Establish inference rules based on program rewriting within the unified grammatical framework.
[0030] Step 7: Using the inference rules based on program rewriting established in Step 6 and the semantics of the program generated in Step 4, the user interactively proves the protocol properties formally described in Step 5 within Rocq using Rocq's own proof strategy. During the interactive proof process, the Rocq kernel verifies the correctness of the proof. If the proof fails the Rocq kernel's verification, it terminates and returns an error message. The key points and inventive aspects of the program flow will be explained in detail below.
[0031] 1. A unified grammatical framework Existing formal verification tools for quantum programming languages primarily target quantum algorithms or circuit design in their core syntax, lacking support for classical-quantum hybrid programming scenarios. This leads to significant difficulties in type checking and semantic formalization when writing cryptographic protocols that require complex classical control flow and quantum operations, due to the syntactic separation between classical and quantum operations.
[0032] This invention designs a hybrid programming language and provides a unified syntax framework that integrates classical and quantum programming paradigms. This unified syntax framework includes a unified type system and a hierarchical statement syntax.
[0033] 1) A unified type system During variable declaration or initialization, variables are explicitly designated as either classical or quantum variables. This invention uses a unified type to define these two types of variables, as shown below: in, Indicates the variable type; Indicates an integer type; Indicates a Boolean type; It is a paired type, representing a binary tuple of two types; express An array type of quantum variables or classical variables; Indicates application to The unitary operator type of a quantum variable. For a quantum variable, its state space and the value range of a classical type are uniformly formalized in Hilbert space. Therefore, this invention can represent classical and quantum variables respectively through a unified type and the way it is declared at the time of definition. The formal definition of the type is achieved in Rocq through... This is achieved through structural mechanisms.
[0034] 2) Hierarchical statement syntax This invention classifies program statements into three levels: classical statements, circuit statements, and hybrid statements. Classical statements involve only classical variables and exhibit classical computational behavior; circuit statements include quantum control flow statements and unitary transformation operation statements, which can be compiled as part of a quantum circuit; hybrid statements involve both classical and quantum variables and include quantum operations such as quantum measurement and quantum assignment.
[0035] The statement hierarchy is automatically inferred from the types of variables involved and the hierarchy of substatements. Specifically, following the upward compatibility principle of "classical < circuit < hybrid," if a nested substatement is a lower-level statement, then the hierarchy of the statement containing that substatement should be greater than or equal to the hierarchy of that substatement. This allows higher-level statements to naturally encapsulate lower-level statements. Formal definitions of statements in Rocq are achieved through... The automatic inference of statement levels is achieved through a structural mechanism, which uses recursive functions in Rocq to make judgments layer by layer.
[0036] 2. Modular System The module system comprises module types and modules. A module type represents a collection of modules with a set of abstract properties, and its definition includes declarations of functions. A module, as an instance of a module type, contains definitions of functions and variables; it can inherit from multiple module types and also act as an instance of those module types. In Rocq, the module system is implemented as follows: Figure 2 As shown.
[0037] In Rocq, the Record struct mechanism defines base modules as types within Rocq. Base modules are considered abstract definitions of all module instances, used to standardize the definition structure of a module instance (a specific module) and describe which components it should contain. Since variables in Rocq cannot belong to multiple types, all module instances are defined using... The mechanism is defined as instance variables of the type represented by the base module. Each module instance contains function definitions, variable definitions, and module parameters that take other modules as arguments. Simultaneously, through... The structural mechanism defines each specific module type as a type in Rocq.
[0038] To establish the inheritance relationship between module types and module instances, through The mechanism declares module instances as canonical instances of the module types they inherit from. This allows type inference systems to automatically infer that a module instance belongs to a particular module type, thus enabling theorems written for module types to be directly applied to specific module instances.
[0039] Furthermore, for a module to inherit from a module type, its function definitions must include functions declared in the module type, and the function definitions must also meet the function call permission requirements specified in the module type's function declarations. These syntactic rules are categorized as properties of module types, and are passed through... When binding the mechanism to module type and module, the corresponding theorem is automatically generated through the Rocq-elpi plugin and the user is required to provide verification.
[0040] The module type definition includes a field indicating the type as the base module. Using the Coercion type conversion mechanism, the module type can be automatically treated as the base module when needed. This allows the module type to be passed as a parameter to other parameterized modules.
[0041] 3. Type checking and syntax checking In Rocq, type checking and syntax checking for mixed programming languages are implemented using recursive functions. The type checking algorithm takes the abstract syntax tree (AST) of a module instance and its initial type environment as input. Its function is to recursively traverse the AST and verify the type of each expression. If all expressions pass the type check, the algorithm outputs a correct message. If a type error is found, an error message and its location are output. The specific execution logic follows the syntax rules of the mixed programming language. Syntax checking takes the AST of a module instance and the module types inherited by the module instance as input. Its function is to recursively traverse the AST and check whether the functions of each module instance satisfy the function declaration and calling permission requirements of the inherited module types. If all functions pass the syntax check, the algorithm outputs a correct message; otherwise, it outputs an error message.
[0042] 4. For programs that pass type and syntax checks, generate corresponding semantics based on the syntax within the unified syntax framework. Based on a unified grammatical framework, Rocq defines small-step and large-step semantics for each grammatical construct to describe the program's behavior and effects during execution. For small-step semantics, Rocq uses inductive types to describe the changes in a single execution step. For large-step semantics, Rocq uses recursive functions to represent the result of program execution. The recursive function takes an initial state and a program statement as input and outputs the program's state after executing that statement. This semantic mechanism constitutes a formal model of program behavior, supporting property verification and equivalence reasoning.
[0043] 5. Based on the syntactic formal description within the unified grammatical framework, the properties of the protocols that need to be proven. Based on a unified grammatical framework, the protocol properties that need to be proven are described in Rocq as functions of type Prop. These functions take grammatical elements such as program functions and modules as input and output a proposition representing the condition that the grammar should satisfy. Thus, each property is defined as a logical term relating to the grammatical object.
[0044] 6. Establish inference rules based on program rewriting within a unified grammatical framework. In Rocq, inference rules based on program rewriting are formalized as Prop-type relations defined by several inductive structural mechanisms. Each rewriting rule is represented by a constructor, and each constructor is a grammatical inference rule that specifies under what conditions a grammatically represented program can be replaced by another program. For each inference rule, its semantic correctness is represented as a Lemma or Theorem in Rocq, and the semantic correctness is interactively proven in Rocq based on the semantics generated in step 4.
[0045] The Rocq-elpi plugin used in the above method of the present invention Structural mechanism, Record structural mechanism mechanism, The mechanism and Coercion type conversion mechanism can be implemented using existing technologies.
[0046] Another embodiment of the present invention provides a verification system for hybrid programming language programs resistant to quantum cryptography, such as... Figure 3 As shown, it includes: The input unit is used to input the cryptographic protocol program to be verified in Rocq based on a hybrid programming language; Subroutine modeling unit, used to formally model subroutines in a cryptographic protocol program through a modular system; Program behavior description unit, used to describe classical and quantum program behavior in cryptographic protocol programs based on a unified syntax framework of hybrid programming languages; The checking unit is used to automatically perform type and syntax checks on programs written based on the unified syntax framework and module system through the Rocq-elpi plugin; The program semantics generation unit is used to generate program semantics based on the syntax in a unified syntax framework for programs that have passed type checking and syntax checking. Protocol property description unit, used to formally describe the protocol properties that need to be proven according to the syntactic framework of a unified syntax framework; The reasoning rule building unit is used to establish reasoning rules based on program rewriting within a unified grammatical framework. The interactive proof unit is used to interactively prove the properties of formally described protocols in Rocq using Rocq's own proof strategy, based on the inference rules and semantics of the program rewritten.
[0047] The above division into units is merely illustrative. In practical applications, the functions described above can be assigned to different functional units as needed to complete all or part of the functions described in the aforementioned method. The specific working process of each unit can be found in the corresponding process in the aforementioned method embodiments.
[0048] Another embodiment of the present invention provides a computer device (computer, server, etc.) including a memory and a processor, the memory storing a computer program configured to be executed by the processor, the computer program including instructions for performing steps of the method of the present invention.
[0049] Another embodiment of the present invention provides a computer-readable storage medium (such as ROM / RAM, disk, optical disk) that stores a computer program, which, when executed by a computer, implements the steps of the method of the present invention.
[0050] Another embodiment of the present invention provides a computer program product, the computer program product including a computer program, which, when executed by a computer, implements the steps of the method of the present invention.
[0051] The specific embodiments of the present invention disclosed above are intended to help understand the content of the present invention and to implement it accordingly. Those skilled in the art will understand that various substitutions, changes, and modifications are possible without departing from the spirit and scope of the present invention. The present invention should not be limited to the content disclosed in the embodiments of this specification; the scope of protection of the present invention is defined by the claims.
Claims
1. A method for verifying a hybrid programming language program oriented to quantum-resistant cryptography, characterized by, Includes the following steps: In Rocq, input the cryptographic protocol program to be verified based on a hybrid programming language; We formally model subroutines in cryptographic protocol programs using modular systems, and describe classical and quantum program behaviors in cryptographic protocol programs based on a unified syntax framework of a hybrid programming language. For programs written based on a unified syntax framework and module system, type checking and syntax checking of the program are automated through the Rocq-elpi plugin; For programs that pass type and syntax checks, the semantics of the program are generated according to the syntax in a unified syntax framework. According to the syntactic formalization description in the unified grammatical framework, the properties of the protocol that need to be proven; Establish inference rules based on program rewriting on the basis of grammar within a unified grammatical framework; By using inference rules based on program rewriting and the semantics of the program, and employing Rocq’s own proof strategy, we can interactively prove the properties of formally described protocols in Rocq. The unified syntax framework includes a unified type system and a hierarchical statement syntax; The module system includes module types and modules; a module type represents a collection of modules with a series of abstract properties, and its definition includes declarations of functions; a module, as an instance of a module type, contains definitions of functions and variables, and can inherit from multiple module types. The type check takes the abstract syntax tree of the module instance and its initial type environment as input, recursively traverses the abstract syntax tree, and verifies the type of each expression. The syntax check takes the abstract syntax tree of the module instance and the module type inherited by the module instance as input, and recursively traverses the abstract syntax tree to check whether the functions of each module instance meet the requirements of function declaration and calling permissions of the module type inherited by the module instance.
2. The method of claim 1, wherein, The unified type system adopts a unified type definition for classical or quantum variables, as shown below: wherein, represents a variable type; represents an integer type; represents a Boolean type; is a pair type; represents an array type of quantum variables or classical variables; represents an application of a unitary operator to a quantum variable.
3. The method according to claim 1, characterized in that, The hierarchical statement syntax classifies program statements into three levels: classic statements, circuit statements, and mixed statements; classic statements only involve classic variables and exhibit classic computational behavior. Circuit statements contain quantum control flow statements and unitary transformation operation statements, which can be compiled as a whole into a quantum circuit; hybrid statements involve both classical and quantum variables. The three levels follow the upward compatibility principle of "classical < circuit < hybrid". If a nested sub-statement belongs to a lower level statement, then the level of the statement containing the sub-statement is greater than or equal to the level of the sub-statement.
4. The method according to claim 1, characterized in that, In Rocq, the Record struct mechanism is used to define base modules as types within Rocq. Base modules are considered abstract definitions of all module instances, used to standardize the definition structure of module instances; all module instances are then accessed through... The mechanism is defined as instance variables of the type represented by the base module, through... The structural mechanism defines each specific module type as a type in Rocq, through... The mechanism declares a module instance as a canonical instance of the module type it inherits from.
5. A verification system for a quantum-resistant hybrid programming language program employing the method described in any one of claims 1 to 4, characterized in that, include: The input unit is used to input the cryptographic protocol program to be verified in Rocq based on a hybrid programming language; Subroutine modeling unit, used to formally model subroutines in a cryptographic protocol program through a modular system; Program behavior description unit, used to describe classical and quantum program behavior in cryptographic protocol programs based on a unified syntax framework of hybrid programming languages; The checking unit is used to automatically perform type and syntax checks on programs written based on the unified syntax framework and module system through the Rocq-elpi plugin; The program semantics generation unit is used to generate program semantics based on the syntax in a unified syntax framework for programs that have passed type checking and syntax checking. Protocol property description unit, used to formally describe the protocol properties that need to be proven according to the syntactic framework of a unified syntax framework; The reasoning rule building unit is used to establish reasoning rules based on program rewriting within a unified grammatical framework. The interactive proof unit is used to interactively prove the properties of formally described protocols in Rocq using Rocq's own proof strategy, based on the inference rules and semantics of the program rewritten.
6. A computer device, characterized in that, It includes a memory and a processor, the memory storing a computer program configured to be executed by the processor, the computer program including instructions for performing the method of any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, which, when executed by a computer, implements the method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Code static verification and dynamic execution method based on rewriting logic
CN118821153A
High-credibility structure of synchronous modeling language code generator and formalized verification method of high-credibility structure
CN120610714A