WO2020227883A1 - Data processing method, device, and system - Google Patents

Data processing method, device, and system Download PDF

Info

Publication number
WO2020227883A1
WO2020227883A1 PCT/CN2019/086594 CN2019086594W WO2020227883A1 WO 2020227883 A1 WO2020227883 A1 WO 2020227883A1 CN 2019086594 W CN2019086594 W CN 2019086594W WO 2020227883 A1 WO2020227883 A1 WO 2020227883A1
Authority
WO
WIPO (PCT)
Prior art keywords
code data
intermediate code
data
processing
llvm
Prior art date
Application number
PCT/CN2019/086594
Other languages
French (fr)
Chinese (zh)
Inventor
王嘉兴
李升林
陈元丰
Original Assignee
云图有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 云图有限公司 filed Critical 云图有限公司
Priority to PCT/CN2019/086594 priority Critical patent/WO2020227883A1/en
Publication of WO2020227883A1 publication Critical patent/WO2020227883A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation

Definitions

  • the present invention relates to the field of computer data processing technology, in particular, to a data processing method, device and system.
  • circuit compilers are usually used to convert calculations into logic circuits, but circuit compilers generally correspond to a specific source code writing language. If you need to support other high-level languages, you can only redevelop a new compiler.
  • current circuit compilers can only implement common grammars and lack operations such as error checking and compilation optimization.
  • advanced cryptographic protocol algorithms are usually very complex, and grammatical restrictions, error checking, and lack of compilation and optimization will make the overall system's operating accuracy and efficiency not guaranteed. Therefore, the technical field urgently needs a simpler and more efficient method for processing cryptographic data.
  • the purpose of the embodiments of this specification is to provide a data processing method, device, and system, which can more simply and efficiently compile the source code data of a cryptographic algorithm into R1CS data.
  • a data processing method including:
  • the performing static single assignment processing without jump to the initial LLVM intermediate code data includes:
  • the performing control flow elimination processing on the first intermediate code data includes:
  • the jump sentence in the second intermediate code data is removed to obtain processed intermediate code data.
  • the performing function inlining and static single assignment processing on the initial LLVM intermediate code data includes:
  • the conversion processing on the processed intermediate code data includes:
  • the processed intermediate code data is converted to obtain R1CS data.
  • an embodiment of this specification also provides a data processing device, which includes:
  • the data compilation module is used to compile the source code data of the cryptographic protocol algorithm to be processed based on the LLVM compiler to obtain the initial LLVM intermediate code data;
  • the single assignment processing module is used to perform static single assignment processing without jumping on the initial LLVM intermediate code data to obtain processed intermediate code data;
  • the data conversion module is used to perform conversion processing on the processed intermediate code data to obtain R1CS data.
  • the single assignment processing module includes:
  • the single assignment processing unit is configured to perform function inlining and static single assignment processing on the initial LLVM intermediate code data to obtain the first intermediate code data;
  • the control flow elimination unit is configured to perform control flow elimination processing on the first intermediate code data to obtain processed intermediate code data.
  • the conversion module includes:
  • the conversion unit is used to convert the processed intermediate code data based on the constraint generation algorithm to obtain R1CS data.
  • the embodiments of the present specification also provide a data processing device, including a processor and a memory for storing executable instructions of the processor, the instructions being executed by the processor include the following steps:
  • the embodiments of this specification also provide a data processing system.
  • the data compilation system includes at least one processor and a memory storing computer-executable instructions.
  • the processor executes the instructions, any one of the above embodiments is implemented. The steps of the method.
  • the data processing method, device and system provided by one or more embodiments of this specification can compile the source code data of the cryptographic protocol algorithm to be processed by using the LLVM compiler, and then further optimize the intermediate code data obtained by the compilation, and then The R1CS data is obtained based on the optimized intermediate code data.
  • the LLVM compiler can support algorithm compilation in any language, and can implement error checking and code optimization, which can greatly improve the ease of writing algorithm source code data and the efficiency of compilation processing.
  • the embodiment of this specification further optimizes the intermediate code data compiled by the LLVM compiler, so that the optimized intermediate code data can adapt to the R1CS form required by the cryptographic algorithm, so as to implement complex complex data more simply and efficiently. Conversion of logic calculations to R1CS.
  • FIG. 1 is a schematic flowchart of an embodiment of a data processing method provided in this specification
  • FIG. 2 is a schematic diagram of the control flow of LLVM intermediate code data in an embodiment provided in this specification
  • FIG. 3 is a schematic diagram of a data processing flow in another embodiment provided in this specification.
  • FIG. 4 is a schematic diagram of the module structure of an embodiment of a data processing device provided in this specification.
  • Fig. 5 is a schematic structural diagram of a server according to an exemplary embodiment of the present specification.
  • circuit compiler is usually used to convert calculations into logic circuits.
  • algorithm source code writing language corresponding to the circuit compiler is relatively simple, the supported language syntax is limited, it cannot meet the complex logic calculation, and the conversion efficiency is low.
  • the embodiment of this specification provides a data processing method, which can compile the source code data of the cryptographic protocol algorithm to be processed by using the LLVM compiler, and then further optimize the intermediate code data obtained by the compilation, and then optimize the processing based on The following intermediate code data obtains R1CS data.
  • the LLVM compiler can support algorithm compilation in any language, and can implement error checking and code optimization, which can greatly improve the ease of writing algorithm source code data and the efficiency of compilation processing.
  • the embodiment of this specification further optimizes the intermediate code data compiled by the LLVM compiler, so that the optimized intermediate code data can adapt to the logic circuit or R1CS form required by the cryptographic algorithm, so as to achieve simple and efficient implementation Conversion of complex logic calculations to logic circuits or R1CS.
  • Fig. 1 is a schematic flowchart of an embodiment of the data processing method provided in this specification.
  • this specification provides method operation steps or device structures as shown in the following embodiments or drawings, the method or device may include more or fewer operation steps after partial combination based on conventional or no creative labor. Or modular unit.
  • steps or structures where there is no necessary causal relationship logically the execution order of these steps or the module structure of the device is not limited to the execution order or module structure shown in the embodiments of this specification or the drawings.
  • the described method or module structure is applied to an actual device, server or terminal product, it can be executed sequentially or in parallel according to the method or module structure shown in the embodiments or drawings (for example, parallel processor or multi-threaded processing). Environment, even including distributed processing, server cluster implementation environment).
  • the method may include:
  • the source code data of the cryptographic protocol algorithm to be processed can be obtained.
  • the cryptographic protocol algorithm source code data may include cryptographic algorithm source code data in any form, such as corresponding algorithm source code data based on zero-knowledge proof, verifiable calculation, and the like.
  • Figure 2 shows a schematic diagram of the process of conversion from calculation to final zero-knowledge proof in zk-SNARK. Computation in Figure 2 means calculation, Algebraic Circuit means logic circuit, R1CS means first-order constraint system, and QAP means secondary algorithm problem.
  • the generation language of the source code data of the cryptographic protocol algorithm in the embodiment of this specification is not limited, and the language type of the source code can be selected according to actual needs.
  • a variety of mainstream high-level languages C, C++, Java, etc. can be used.
  • the algorithm source code data can be compiled based on the LLVM (Low Level Virtual Machine) compiler.
  • the LLVM compiler can perform operations such as lexical analysis, syntax analysis, semantic analysis, and optimization of the algorithm source code data to generate initial LLVM intermediate code (LLVM IR) data.
  • the initial LLVM intermediate code data can be further subjected to static single assignment processing without jump, so that the processed intermediate code data format meets the requirements of the cryptographic form.
  • the static single assignment processing without jump may include eliminating multiple assignments, function calls, statement jumps and other operations in the initial LLVM intermediate code data to obtain intermediate code data in the form of static single assignment without jump.
  • the algorithm source code data can be converted into static single assignment form during LLVM compilation, it only converts the static single assignment form of some simple algorithm source code data.
  • the converted intermediate code data still contains multiple assignments and function calls for the same variable. , Sentence jump and other operations, and these operations are difficult to convert to the circuit or R1CS form required by cryptographic algorithms.
  • the processed intermediate code data format can be made more consistent with the requirements of cryptographic forms, and The efficiency of subsequent processing.
  • the initial LLVM intermediate code data may be subjected to function inlining and static single assignment processing to obtain the first intermediate code data; the first intermediate code data may be eliminated control flow processing to obtain processing After the intermediate code data.
  • the intermediate code data containing only the main function is obtained, and then, on this basis, multiple assignments of the same variable in the main function are converted into a single assignment, which can be more efficient Accurately eliminate all multiple assignments in the intermediate code data.
  • the performing function inlining and static single assignment processing on the initial LLVM intermediate code data may include:
  • the sub-functions of the initial LLVM intermediate code data can be inlined into the main function first to eliminate function calls in the intermediate code data. Then, you can further put all global variables into the main function, and convert multiple assignments of global variables into single assignments of multiple variables.
  • the loop can be expanded, and constant folding can be eliminated, and jumps can be eliminated initially.
  • the constant folding elimination is to evaluate the constant calculation, replace the expression with the value, and put it into the constant table. You can use scalar substitution to eliminate class and structure variables.
  • the switch statement can be further converted into a jump statement (Br statement), and multiple return statements (Return statements) can be combined into one Return statement. After that, you can further convert the memory read and write instructions into a static single assignment form.
  • the static single assignment processing of the intermediate code data can be realized more accurately and completely.
  • jump processing can be eliminated initially. Further, by preliminarily converting the switch statement that controls the flow of the node into the Br jump statement, the subsequent jump elimination processing can be further facilitated.
  • the intermediate code data can be converted into the following form: there is only one main function, and there are multiple basic blocks in the main function.
  • the final instruction of the last basic block is a Return statement
  • the final instruction of other basic blocks is a Br jump instruction.
  • the Br jump instruction can be a conditional jump instruction or an unconditional jump instruction.
  • the other instructions in the basic block are only arithmetic operations, bitwise operations, comparison operations, select instructions (Select instructions) and Phi instructions.
  • the Br instruction may include a conditional jump instruction or an unconditional jump instruction.
  • the conditional jump instruction may refer to an instruction to jump from a current node to a preset node under certain preset conditions.
  • the transfer instruction refers to an instruction to jump from the current node to the preset node without any conditions.
  • the Phi instruction is an instruction used to determine the node executed before the current node in the data for the static single assignment form, so as to use the value of the previously executed node to process the current node. After multiple assignments of the same variable are converted into a single assignment form of multiple variables, a node may correspond to multiple nodes before.
  • the Phi instruction can be used to determine the previous node corresponding to the current node in the control flow to use this The value of the previous node is processed by the current node.
  • the first intermediate code data can be further processed to eliminate control flow, eliminate Phi statements and jump statements in the first intermediate code data, and convert to a static single assignment form without jumps, so that the processed intermediate code
  • the data can be directly used in the circuit or R1CS format required by the cryptographic protocol.
  • the Phi instruction in the first intermediate code data may be further converted into a selection instruction to obtain the second intermediate code data
  • the jump sentence in the second intermediate code data is removed to obtain processed intermediate code data.
  • any Phi instruction in the first intermediate code data it can be converted into several Select instructions to eliminate the Phi instruction.
  • the execution order and mode between the nodes can be directly connected through the Select instruction.
  • the initial LLVM intermediate code data can be processed through the following steps to obtain intermediate code data in the form of static single assignment without jump:
  • Class and structure variables use scalar replacement to eliminate
  • Control flow Combine all basic blocks into one basic block.
  • Steps 1)-7) can be implemented with reference to the above-mentioned scheme, which will not be repeated here.
  • Fig. 2 shows a schematic diagram of the control flow corresponding to the intermediate code data processed through the above steps 1)-7). With reference to Fig. 2, the control flow elimination processing is further explained.
  • the first intermediate code data obtained through steps 1)-7) is:
  • the basic blocks before bb4 can have bb2 and bb3.
  • bb4 performs subsequent processing based on the data of the basic block bb2, and if the value of %r4 is 43, then bb4 is performed based on the data of the basic block bb3 Follow-up processing.
  • the basic block before the basic block bb6 also contains multiple basic blocks, which also correspond to the Phi instruction.
  • the %r6 in the Phi instruction can be assigned a value of 1, 2, %r4, or 5 according to the previous basic block.
  • Step 1 Convert each Phi instruction into several Select instructions.
  • InsertSelect(bb3,phi) returns the corresponding value 43 of bb3 in the phi statement
  • InsertSelect(bb1,phi) calls InsertSelect(bb2,phi), returns 42,
  • InsertSelect(bb0,phi) calls InsertSelect(bb1,phi) to get 42, call InsertSelect(bb3,phi) to get 43, create Select statement Select(%cond0,42,43), and replace phi statement.
  • the basic block bb6 is also processed in the above manner. After the execution is completed, the corresponding intermediate code data is:
  • the finally obtained intermediate code data can be more adapted to the needs of cryptographic protocol data processing.
  • the subsequent processing can be further improved. The simplicity and efficiency.
  • S206 Perform conversion processing on the processed intermediate code data to obtain R1CS data.
  • the logic circuit data or data in the form of R1CS can be further obtained based on the above-mentioned processed intermediate code data conversion.
  • the processed intermediate code data may be converted into logic circuit data first, and then further converted into data in the form of R1CS.
  • FIG. 3 shows a flowchart of the conversion of cryptographic calculation algorithm source code data into R1CS data based on the LLVM compiler in the solutions provided by the foregoing embodiments.
  • the processed intermediate code data may be converted based on a constraint generation algorithm to obtain R1CS data.
  • the conversion processing of the processed intermediate code data based on the constraint generation algorithm may include: processing each arithmetic instruction in the intermediate code data by adding constraints, so as to be configured to be represented by only addition and multiplication form.
  • the packing constraint is a constraint processing method of splitting an n-digit number into n 1-digit numbers, or combining n 1-digit arrays into an n-digit number.
  • d is the remainder
  • c is the quotient
  • the greater than and greater than or equal constraints refer to the subsequent content.
  • d is the remainder
  • c is the quotient
  • the greater than and greater than or equal constraints refer to the subsequent content.
  • c can be any number, so the second constraint is needed, aux is set to any value, and c must be 1;
  • c can be any number
  • aux can be set to any value
  • c must be 0;
  • c When a ⁇ b, according to the first constraint, c must be equal to 1, and aux is set to the multiplicative inverse of a-b, so that the second constraint is also valid.
  • %cond has only 1 digit, and only has two values of 0 or 1;
  • the Select command can be converted into the following constraint form:
  • xor is a bitwise exclusive OR operation. Packing is used to separate the 32-bit a and b into 32 variables, and each pair of variables is ANDed, and the relationship between a i , b i and c i is restricted, and then Packing is used to 32 c i are merged into c variable;
  • the intermediate code data directly compiled by the LLVM compiler may not be directly converted into a logic circuit or R1CS data.
  • the intermediate code data is further optimized. . Therefore, by using the solutions provided by the various embodiments of this specification, the compilation processing of the source code data of the cryptographic algorithm into the R1CS data can be realized simply and efficiently.
  • the data processing method provided by one or more embodiments of this specification can compile the source code data of the cryptographic protocol algorithm to be processed by using the LLVM compiler, and then further optimize the intermediate code data obtained by the compilation, and then based on the optimized processing R1CS data is obtained from the intermediate code data.
  • the LLVM compiler can support algorithm compilation in any language, and can implement error checking and code optimization, which can greatly improve the ease of writing algorithm source code data and the efficiency of compilation processing.
  • the embodiment of this specification further further optimizes the intermediate code data obtained by the LLVM compiler, so that the optimized intermediate code data can adapt to the R1CS form required by the cryptographic algorithm, so as to implement complex logic simply and efficiently. Calculate the conversion process to R1CS.
  • one or more embodiments of this specification also provide a data processing device.
  • the described devices may include systems, software (applications), modules, components, servers, etc. that use the methods described in the embodiments of this specification, combined with necessary implementation hardware devices.
  • the devices in one or more embodiments provided in the embodiments of this specification are as described in the following embodiments. Since the implementation scheme of the device to solve the problem is similar to the method, the implementation of the specific device in the embodiment of this specification can refer to the implementation of the foregoing method, and the repetition will not be repeated.
  • the term “unit” or “module” can be a combination of software and/or hardware that implements predetermined functions.
  • FIG. 4 shows a schematic diagram of the module structure of an embodiment of a data processing device provided in the specification. As shown in FIG. 4, the device may include:
  • the data compiling module 102 can be used to compile the cryptographic protocol algorithm source code data to be processed based on the LLVM compiler to obtain initial LLVM intermediate code data;
  • the single assignment processing module 104 may be used to perform static single assignment processing without jumps on the initial LLVM intermediate code data to obtain processed intermediate code data;
  • the data conversion module 106 may be used to perform conversion processing on the processed intermediate code data to obtain R1CS data.
  • the single assignment processing module 104 may include:
  • the single assignment processing unit may be used to perform function inlining and static single assignment processing on the initial LLVM intermediate code data to obtain the first intermediate code data;
  • the control flow elimination unit may be used to perform control flow elimination processing on the first intermediate code data to obtain processed intermediate code data.
  • control flow elimination unit may include:
  • the instruction conversion subunit can be used to convert the Phi instruction in the first intermediate code data into a selection instruction to obtain the second intermediate code data;
  • the sentence merging subunit can be used to remove the jump sentence in the second intermediate code data to obtain processed intermediate code data.
  • the conversion module 106 may include:
  • the conversion unit may be used to perform conversion processing on the processed intermediate code data based on the constraint generation algorithm to obtain R1CS data.
  • the above-mentioned device may also include other implementation manners according to the description of the method embodiment.
  • specific implementation manners reference may be made to the description of the related method embodiments, which will not be repeated here.
  • the data processing device can compile the source code data of the cryptographic protocol algorithm to be processed by using the LLVM compiler, and then further optimize the intermediate code data obtained by the compilation, and then based on the optimized processing R1CS data is obtained from the intermediate code data.
  • the LLVM compiler can support algorithm compilation in any language, and can implement error checking and code optimization, which can greatly improve the ease of writing algorithm source code data and the efficiency of compilation processing.
  • the embodiment of this specification further further optimizes the intermediate code data obtained by the LLVM compiler, so that the optimized intermediate code data can adapt to the R1CS form required by the cryptographic algorithm, so as to implement complex logic simply and efficiently. Calculate the conversion to R1CS.
  • this specification also provides a data processing device including a processor and a memory storing executable instructions of the processor. When the instructions are executed by the processor, the implementation includes the following steps:
  • the storage medium may include a physical device for storing information, and the information is usually digitized and then stored in an electric, magnetic, or optical medium.
  • the storage medium may include: devices that use electrical energy to store information, such as various types of memory, such as RAM, ROM, etc.; devices that use magnetic energy to store information, such as hard disks, floppy disks, magnetic tapes, magnetic core memory, bubble memory, U disk; a device that uses optical means to store information, such as CD or DVD.
  • devices that use electrical energy to store information such as various types of memory, such as RAM, ROM, etc.
  • devices that use magnetic energy to store information such as hard disks, floppy disks, magnetic tapes, magnetic core memory, bubble memory, U disk
  • a device that uses optical means to store information such as CD or DVD.
  • quantum memory graphene memory, and so on.
  • the above-mentioned device may also include other implementation manners according to the description of the method embodiment.
  • specific implementation manners reference may be made to the description of the related method embodiments, which will not be repeated here.
  • FIG. 5 is a hardware structure block diagram of a data processing server to which the embodiment of this specification is applied.
  • the server 10 may include one or more (only one is shown in the figure) processor 20 (the processor 20 may include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA), The memory 30 for storing data, and the transmission module 40 for communication functions.
  • the server 10 may also include more or fewer components than shown in FIG. 5, for example, may also include other processing hardware, such as a database or multi-level cache, GPU, or have a configuration different from that shown in FIG.
  • the memory 30 may be used to store software programs and modules of application software, such as program instructions/modules corresponding to the search method in the embodiment of the present invention.
  • the processor 20 executes various functions by running the software programs and modules stored in the memory 30 Application and data processing.
  • the memory 30 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory.
  • the memory 30 may further include a memory remotely provided with respect to the processor 20, and these remote memories may be connected to the computer terminal through a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
  • the transmission module 40 is used to receive or send data via a network.
  • the above-mentioned specific examples of the network may include a wireless network provided by a communication provider of a computer terminal.
  • the transmission module 40 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station to communicate with the Internet.
  • the transmission module 40 may be a radio frequency (RF) module, which is used to communicate with the Internet in a wireless manner.
  • RF radio frequency
  • the data processing device described in the above embodiment can compile the source code data of the cryptographic protocol algorithm to be processed by using the LLVM compiler, and then further optimize the intermediate code data obtained by the compilation, and then based on the optimized intermediate code data Obtain R1CS data.
  • the LLVM compiler can support algorithm compilation in any language, and can implement error checking and code optimization, which can greatly improve the ease of writing algorithm source code data and the efficiency of compilation processing.
  • the embodiment of this specification further further optimizes the intermediate code data obtained by the LLVM compiler, so that the optimized intermediate code data can adapt to the R1CS form required by the cryptographic algorithm, so as to implement complex logic simply and efficiently. Calculate the conversion process to R1CS.
  • This specification also provides a data processing system, which can be a separate data processing system or can be applied to multiple computer data processing systems.
  • the system can be a single server, or it can include server clusters, systems (including distributed systems), software (applications), and one or more of the methods described in this specification or one or more embodiments of the device.
  • the data processing system may include at least one processor and a memory storing computer-executable instructions.
  • the processor implements the steps of the method in any one or more of the foregoing embodiments when the processor executes the instructions.
  • the data processing system described in the above embodiment can compile the source code data of the cryptographic protocol algorithm to be processed by using the LLVM compiler, and then further optimize the intermediate code data obtained by the compilation, and then based on the optimized intermediate code data Obtain R1CS data.
  • the LLVM compiler can support algorithm compilation in any language, and can implement error checking and code optimization, which can greatly improve the ease of writing algorithm source code data and the efficiency of compilation processing.
  • the embodiment of this specification further further optimizes the intermediate code data obtained by the LLVM compiler, so that the optimized intermediate code data can adapt to the R1CS form required by the cryptographic algorithm, so as to implement complex logic simply and efficiently. Calculate the conversion process to R1CS.
  • the device or system described above in this specification may also include other implementation manners based on the description of the related method embodiments.
  • specific implementation manners refer to the description of the method embodiments, which will not be repeated here.
  • the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments.
  • the description is relatively simple, and for related parts, please refer to the part of the description of the method embodiments.
  • the embodiment of this specification is not limited to the standard data model/template. Or the situation described in the embodiment of this specification. Certain industry standards or implementations described in custom methods or examples with slight modifications can also achieve the same, equivalent or similar implementation effects of the foregoing examples, or predictable implementation effects after modification. The examples obtained by applying these modified or deformed data acquisition, storage, judgment, processing methods, etc., may still fall within the scope of the optional implementation solutions of this specification.
  • a typical implementation device is a computer.
  • the computer may be, for example, a personal computer, a laptop computer, a vehicle-mounted human-computer interaction device, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, and a tablet.
  • Computers, wearable devices, or any combination of these devices may be specifically implemented by computer chips or entities, or implemented by products with certain functions.
  • the computer may be, for example, a personal computer, a laptop computer, a vehicle-mounted human-computer interaction device, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, and a tablet.
  • the functions are divided into various modules and described separately.
  • the function of each module can be realized in the same one or more software and/or hardware, or the module that realizes the same function can be realized by a combination of multiple sub-modules or sub-units, etc. .
  • the device embodiments described above are merely illustrative, for example, the division of the units is only a logical function division, and there may be other divisions in actual implementation, for example, multiple units or components can be combined or integrated To another system, or some features can be ignored, or not implemented.
  • the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection through some interfaces, devices or units, and may be in electrical, mechanical or other forms.
  • controllers in addition to implementing the controller in a purely computer-readable program code manner, it is entirely possible to program the method steps to make the controller use logic gates, switches, application specific integrated circuits, programmable logic controllers and embedded The same function can be realized in the form of a microcontroller, etc. Therefore, such a controller can be regarded as a hardware component, and the devices included in the controller for realizing various functions can also be regarded as a structure within the hardware component. Or even, the device for realizing various functions can be regarded as both a software module for realizing the method and a structure within a hardware component.
  • These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing equipment to work in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including the instruction device.
  • the device implements the functions specified in one process or multiple processes in the flowchart and/or one block or multiple blocks in the block diagram.
  • These computer program instructions can also be loaded on a computer or other programmable data processing equipment, so that a series of operation steps are executed on the computer or other programmable equipment to produce computer-implemented processing, so as to execute on the computer or other programmable equipment.
  • the instructions provide steps for implementing functions specified in a flow or multiple flows in the flowchart and/or a block or multiple blocks in the block diagram.
  • the computing device includes one or more processors (CPU), input/output interfaces, network interfaces, and memory.
  • processors CPU
  • input/output interfaces network interfaces
  • memory volatile and non-volatile memory
  • one or more embodiments of this specification can be provided as a method, a system, or a computer program product. Therefore, one or more embodiments of this specification may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, one or more embodiments of this specification may adopt a computer program implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes. The form of the product.
  • computer-usable storage media including but not limited to disk storage, CD-ROM, optical storage, etc.
  • One or more embodiments of this specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules.
  • program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types.
  • One or more embodiments of this specification can also be practiced in distributed computing environments. In these distributed computing environments, tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.

Abstract

A data processing method, device, and system, the method comprising: on the basis of an LLVM compiler, compiling cryptographic protocol algorithm source code data to be processed, and acquiring initial LLVM intermediate code data (S202); performing no-jump static single assignment processing on the initial LLVM intermediate code data, and acquiring processed intermediate code data (S204); and converting the processed intermediate code data to acquire R1CS data (S206). Thus, the compiling processing of cryptographic algorithm source code data to R1CS data may be achieved more simply and efficiently.

Description

一种数据处理方法、装置及系统Data processing method, device and system 技术领域Technical field
本发明涉及计算机数据处理技术领域,特别地,涉及一种数据处理方法、装置及系统。The present invention relates to the field of computer data processing technology, in particular, to a data processing method, device and system.
背景技术Background technique
随着近年来区块链技术的发展,零知识证明和可验证计算得到广泛的关注和使用。目前主流的零知识算法通常不能直接用于解决计算问题,必须先把计算问题转换成正确的“形式”来处理,这种形式叫做QAP(quadratic arithmetic problem)。具体实现时,一般需要先把计算转换为逻辑电路,然后再转化成R1CS(rank-1 constraint system,一阶约束系统),进一步利用R1CS生成QAP。With the development of blockchain technology in recent years, zero-knowledge proofs and verifiable calculations have received widespread attention and use. The current mainstream zero-knowledge algorithms are usually not directly used to solve computational problems. The computational problems must be converted into the correct "form" for processing. This form is called QAP (quadratic arithmetic problem). In specific implementation, it is generally necessary to convert calculations into logic circuits first, and then into R1CS (rank-1 constraint system), and then use R1CS to generate QAP.
目前通常利用电路编译器将计算转换为逻辑电路,但电路编译器一般都对应一种特定的源码编写语言,如果需要支持其它高级语言,只能重新开发新的编译器。且目前的电路编译器只能实现常见的语法,并缺少错误检查、编译优化等操作。而高级的密码学协议算法通常非常复杂,语法限制以及错误检查、编译优化的缺失等会使得整体系统的运行准确性以及效率得不到保证。因此,本技术领域亟需一种更加简单高效的密码学数据处理方法。At present, circuit compilers are usually used to convert calculations into logic circuits, but circuit compilers generally correspond to a specific source code writing language. If you need to support other high-level languages, you can only redevelop a new compiler. In addition, current circuit compilers can only implement common grammars and lack operations such as error checking and compilation optimization. However, advanced cryptographic protocol algorithms are usually very complex, and grammatical restrictions, error checking, and lack of compilation and optimization will make the overall system's operating accuracy and efficiency not guaranteed. Therefore, the technical field urgently needs a simpler and more efficient method for processing cryptographic data.
发明内容Summary of the invention
本说明书实施例的目的在于提供一种数据处理方法、装置及系统,可以更加简单高效的实现密码学算法源码数据向R1CS数据的编译处理。The purpose of the embodiments of this specification is to provide a data processing method, device, and system, which can more simply and efficiently compile the source code data of a cryptographic algorithm into R1CS data.
本说明书提供一种数据处理方法、装置及系统是包括如下方式实现的:This specification provides a data processing method, device and system which are implemented in the following ways:
一种数据处理方法,包括:A data processing method, including:
基于LLVM编译器对待处理的密码协议算法源码数据进行编译,获得初始LLVM中间码数据;Compile the source code data of the cryptographic protocol algorithm to be processed based on the LLVM compiler to obtain the initial LLVM intermediate code data;
对所述初始LLVM中间码数据进行无跳转的静态单赋值处理,获得处理后的中间码数据;Performing static single assignment processing without jump on the initial LLVM intermediate code data to obtain processed intermediate code data;
对所述处理后的中间码数据进行转换处理,获得R1CS数据。Perform conversion processing on the processed intermediate code data to obtain R1CS data.
本说明书提供的所述方法的另一个实施例中,所述对所述初始LLVM中间码数据进行无跳转的静态单赋值处理,包括:In another embodiment of the method provided in this specification, the performing static single assignment processing without jump to the initial LLVM intermediate code data includes:
对所述初始LLVM中间码数据进行函数内联及静态单赋值处理,获得第一中间码数据;Performing function inlining and static single assignment processing on the initial LLVM intermediate code data to obtain the first intermediate code data;
对所述第一中间码数据进行消除控制流处理,获得处理后的中间码数据。Performing elimination control flow processing on the first intermediate code data to obtain processed intermediate code data.
本说明书提供的所述方法的另一个实施例中,所述对所述第一中间码数据进行消除控制流处理,包括:In another embodiment of the method provided in this specification, the performing control flow elimination processing on the first intermediate code data includes:
将所述第一中间码数据中的Phi指令转换为选择指令,获得第二中间码数据;Converting the Phi instruction in the first intermediate code data into a selection instruction to obtain the second intermediate code data;
将所述第二中间码数据中的跳转语句移除,获得处理后的中间码数据。The jump sentence in the second intermediate code data is removed to obtain processed intermediate code data.
本说明书提供的所述方法的另一个实施例中,所述对所述初始LLVM中间码数据进行函数内联及静态单赋值处理,包括:In another embodiment of the method provided in this specification, the performing function inlining and static single assignment processing on the initial LLVM intermediate code data includes:
将所述初始LLVM中间码数据的子函数内联到主函数中,并将全局变量放入所述主函数中;Inlining the sub-functions of the initial LLVM intermediate code data into the main function, and putting global variables into the main function;
对所述主函数进行循环展开和常量折叠消除,以及,将所述主函数中的类和结构体变量使用标量替换消除;Performing loop expansion and constant folding elimination on the main function, and replacing and eliminating class and structure variables in the main function with scalar;
将所述主函数中的Switch跳转语句转换为跳转语句,并将多条返回语句合并为一条返回语句;Convert the Switch jump statement in the main function into a jump statement, and merge multiple return statements into one return statement;
将所述主函数中的同一变量的多次赋值转换为多个变量的单次赋值。Converting multiple assignments of the same variable in the main function into single assignments of multiple variables.
本说明书提供的所述方法的另一个实施例中,所述对所述处理后的中间码数据进行转换处理,包括:In another embodiment of the method provided in this specification, the conversion processing on the processed intermediate code data includes:
基于约束生成算法对处理后的中间码数据进行转换处理,获得R1CS数据。Based on the constraint generation algorithm, the processed intermediate code data is converted to obtain R1CS data.
另一方面,本说明书实施例还提供一种数据处理装置,所述装置包括:On the other hand, an embodiment of this specification also provides a data processing device, which includes:
数据编译模块,用于基于LLVM编译器对待处理的密码协议算法源码数据进行编译,获得初始LLVM中间码数据;The data compilation module is used to compile the source code data of the cryptographic protocol algorithm to be processed based on the LLVM compiler to obtain the initial LLVM intermediate code data;
单赋值处理模块,用于对所述初始LLVM中间码数据进行无跳转的静态单赋值处理,获得处理后的中间码数据;The single assignment processing module is used to perform static single assignment processing without jumping on the initial LLVM intermediate code data to obtain processed intermediate code data;
数据转换模块,用于对所述处理后的中间码数据进行转换处理,获得R1CS数据。The data conversion module is used to perform conversion processing on the processed intermediate code data to obtain R1CS data.
本说明书提供的所述装置的另一个实施例中,所述单赋值处理模块包括:In another embodiment of the device provided in this specification, the single assignment processing module includes:
单赋值处理单元,用于对所述初始LLVM中间码数据进行函数内联及静态单赋值处理,获得第一中间码数据;The single assignment processing unit is configured to perform function inlining and static single assignment processing on the initial LLVM intermediate code data to obtain the first intermediate code data;
控制流消除单元,用于对所述第一中间码数据进行消除控制流处理,获得处理后的中间码数据。The control flow elimination unit is configured to perform control flow elimination processing on the first intermediate code data to obtain processed intermediate code data.
本说明书提供的所述装置的另一个实施例中,所述转换模块包括:In another embodiment of the device provided in this specification, the conversion module includes:
转换单元,用于基于约束生成算法对处理后的中间码数据进行转换处理,获得R1CS数据。The conversion unit is used to convert the processed intermediate code data based on the constraint generation algorithm to obtain R1CS data.
另一方面,本说明书实施例还提供一种数据处理设备,包括处理器及用于存储处理器可执行指令的存储器,所述指令被所述处理器执行时实现包括以下步骤:On the other hand, the embodiments of the present specification also provide a data processing device, including a processor and a memory for storing executable instructions of the processor, the instructions being executed by the processor include the following steps:
基于LLVM编译器对待处理的密码协议算法源码数据进行编译,获得初始LLVM中间码数据;Compile the source code data of the cryptographic protocol algorithm to be processed based on the LLVM compiler to obtain the initial LLVM intermediate code data;
对所述初始LLVM中间码数据进行无跳转的静态单赋值处理,获得处理后的中间码数据;Performing static single assignment processing without jump on the initial LLVM intermediate code data to obtain processed intermediate code data;
对所述处理后的中间码数据进行转换处理,获得R1CS数据。Perform conversion processing on the processed intermediate code data to obtain R1CS data.
另一方面,本说明书实施例还提供一种数据处理系统,所述数据编译系统包括至少一个处理器以及存储计算机可执行指令的存储器,所述处理器执行所述指令时实现上述任意一个实施例所述方法的步骤。On the other hand, the embodiments of this specification also provide a data processing system. The data compilation system includes at least one processor and a memory storing computer-executable instructions. When the processor executes the instructions, any one of the above embodiments is implemented. The steps of the method.
本说明书一个或多个实施例提供的数据处理方法、装置及系统,可以通过利用LLVM编译器来编译待处理的密码协议算法源码数据,然后,进一步对编译获得的中间码数据进行优化处理,进而基于优化处理后的中间码数据获得R1CS数据。LLVM编译器可以支持任意语言的算法编译,且可以实现错误检查以及代码优化等处理,从而可以大幅度提高算法源码数据编写的简便性以及编译处理的高效性。同时,本说明书实施例还进一步对LLVM编译器编译获得的中间码数据进行进一步优化处理,以使得优化后的中间码数据可以适应密码学算法所需要的R1CS形式,从而更加简单高效的实现复杂的逻辑计算向R1CS的转换处理。The data processing method, device and system provided by one or more embodiments of this specification can compile the source code data of the cryptographic protocol algorithm to be processed by using the LLVM compiler, and then further optimize the intermediate code data obtained by the compilation, and then The R1CS data is obtained based on the optimized intermediate code data. The LLVM compiler can support algorithm compilation in any language, and can implement error checking and code optimization, which can greatly improve the ease of writing algorithm source code data and the efficiency of compilation processing. At the same time, the embodiment of this specification further optimizes the intermediate code data compiled by the LLVM compiler, so that the optimized intermediate code data can adapt to the R1CS form required by the cryptographic algorithm, so as to implement complex complex data more simply and efficiently. Conversion of logic calculations to R1CS.
附图说明Description of the drawings
为了更清楚地说明本说明书实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅 仅是本说明书中记载的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。在附图中:In order to more clearly explain the technical solutions in the embodiments of this specification or the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only These are some embodiments described in this specification. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative labor. In the attached picture:
图1为本说明书提供的一种数据处理方法实施例的流程示意图;FIG. 1 is a schematic flowchart of an embodiment of a data processing method provided in this specification;
图2为本说明书提供的一个实施例中的LLVM中间码数据的控制流示意图;2 is a schematic diagram of the control flow of LLVM intermediate code data in an embodiment provided in this specification;
图3为本说明书提供的另一个实施例中的数据处理的流程示意图;3 is a schematic diagram of a data processing flow in another embodiment provided in this specification;
图4为本说明书提供的一种数据处理装置实施例的模块结构示意图;4 is a schematic diagram of the module structure of an embodiment of a data processing device provided in this specification;
图5为根据本说明书的一个示例性实施例的服务器的示意结构图。Fig. 5 is a schematic structural diagram of a server according to an exemplary embodiment of the present specification.
具体实施方式Detailed ways
为了使本技术领域的人员更好地理解本说明书中的技术方案,下面将结合本说明书一个或多个实施例中的附图,对本说明书一个或多个实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅是说明书一部分实施例,而不是全部的实施例。基于说明书一个或多个实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都应当属于本说明书实施例方案保护的范围。In order to enable those skilled in the art to better understand the technical solutions in this specification, the following will make clear and complete the technical solutions in one or more embodiments of this specification in conjunction with the drawings in one or more embodiments of this specification. It is obvious that the described embodiments are only a part of the embodiments in the specification, rather than all the embodiments. Based on one or more embodiments of the specification, all other embodiments obtained by a person of ordinary skill in the art without creative work shall fall within the protection scope of the embodiment scheme of this specification.
随着近年来区块链技术的发展,零知识证明和可验证计算得到广泛的关注和使用。目前主流的零知识算法通常不能直接用于解决计算问题,必须先把计算问题转换成正确的“形式”来处理,这种形式叫做QAP(quadratic arithmetic problem)。具体实现时,一般需要先把计算转换为逻辑电路,然后再转化成R1CS(rank-1constraint system,一阶约束系统),进一步利用R1CS生成QAP。R1CS是一个由三向量组(a,b,c)组成的序列,R1CS有个解向量s,s必须满足s·a*s·b-s·c=0,符号“·”表示向量的内积运算。With the development of blockchain technology in recent years, zero-knowledge proofs and verifiable calculations have received widespread attention and use. The current mainstream zero-knowledge algorithms are usually not directly used to solve computational problems. The computational problems must be converted into the correct "form" for processing. This form is called QAP (quadratic arithmetic problem). In specific implementation, it is generally necessary to convert the calculation into a logic circuit first, and then into an R1CS (rank-1 constraint system, first-order constraint system), and further use R1CS to generate QAP. R1CS is a sequence composed of three vector groups (a, b, c), R1CS has a solution vector s, s must satisfy s·a*s·bs·c=0, and the symbol "·" represents the inner product operation of the vector .
目前通常采用电路编译器将计算转换成逻辑电路的方式。但电路编译器对应的算法源码编写语言较为单一,支持的语言语法有限,不能满足复杂的逻辑计算,且转换效率较低。Currently, a circuit compiler is usually used to convert calculations into logic circuits. However, the algorithm source code writing language corresponding to the circuit compiler is relatively simple, the supported language syntax is limited, it cannot meet the complex logic calculation, and the conversion efficiency is low.
相应的,本说明书实施例提供了一种数据处理方法,可以通过利用LLVM编译器来编译待处理的密码协议算法源码数据,然后,进一步对编译获得的中间码数据进行优化处理,进而基于优化处理后的中间码数据获得R1CS数据。LLVM编译器可以支持任意语言的算法编译,且可以实现错误检查以及代码优化等处理,从而可以大幅度提高算法源码数据编写的简便性以及编译处理的高效性。同时,本说明书实施例还 进一步对LLVM编译器编译获得的中间码数据进行进一步优化处理,以使得优化后的中间码数据可以适应密码学算法所需要的逻辑电路或R1CS形式,从而简单高效的实现复杂的逻辑计算向逻辑电路或R1CS的转换处理。Correspondingly, the embodiment of this specification provides a data processing method, which can compile the source code data of the cryptographic protocol algorithm to be processed by using the LLVM compiler, and then further optimize the intermediate code data obtained by the compilation, and then optimize the processing based on The following intermediate code data obtains R1CS data. The LLVM compiler can support algorithm compilation in any language, and can implement error checking and code optimization, which can greatly improve the ease of writing algorithm source code data and the efficiency of compilation processing. At the same time, the embodiment of this specification further optimizes the intermediate code data compiled by the LLVM compiler, so that the optimized intermediate code data can adapt to the logic circuit or R1CS form required by the cryptographic algorithm, so as to achieve simple and efficient implementation Conversion of complex logic calculations to logic circuits or R1CS.
图1是本说明书提供的所述一种数据处理方法实施例流程示意图。虽然本说明书提供了如下述实施例或附图所示的方法操作步骤或装置结构,但基于常规或者无需创造性的劳动在所述方法或装置中可以包括更多或者部分合并后更少的操作步骤或模块单元。在逻辑性上不存在必要因果关系的步骤或结构中,这些步骤的执行顺序或装置的模块结构不限于本说明书实施例或附图所示的执行顺序或模块结构。所述的方法或模块结构的在实际中的装置、服务器或终端产品应用时,可以按照实施例或者附图所示的方法或模块结构进行顺序执行或者并行执行(例如并行处理器或者多线程处理的环境、甚至包括分布式处理、服务器集群的实施环境)。Fig. 1 is a schematic flowchart of an embodiment of the data processing method provided in this specification. Although this specification provides method operation steps or device structures as shown in the following embodiments or drawings, the method or device may include more or fewer operation steps after partial combination based on conventional or no creative labor. Or modular unit. In steps or structures where there is no necessary causal relationship logically, the execution order of these steps or the module structure of the device is not limited to the execution order or module structure shown in the embodiments of this specification or the drawings. When the described method or module structure is applied to an actual device, server or terminal product, it can be executed sequentially or in parallel according to the method or module structure shown in the embodiments or drawings (for example, parallel processor or multi-threaded processing). Environment, even including distributed processing, server cluster implementation environment).
具体的一个实施例如图1所示,本说明书提供的数据处理方法的一个实施例中,所述方法可以包括:A specific embodiment is shown in Fig. 1. In an embodiment of the data processing method provided in this specification, the method may include:
S202:基于LLVM编译器对待处理的算法源码数据进行编译,获得LLVM中间码数据。S202: Compile the algorithm source code data to be processed based on the LLVM compiler to obtain LLVM intermediate code data.
可以获取待处理的密码协议算法源码数据。所述密码协议算法源码数据可以包括任意形式下的密码学算法源码数据,如基于零知识证明、可验证计算等对应的算法源码数据。图2表示zk-SNARK中计算转换为最终零知识证明的流程示意图。图2中的Computation表示计算、Algebraic Circuit表示逻辑电路、R1CS表示一阶约束系统,QAP表示二次算法问题。The source code data of the cryptographic protocol algorithm to be processed can be obtained. The cryptographic protocol algorithm source code data may include cryptographic algorithm source code data in any form, such as corresponding algorithm source code data based on zero-knowledge proof, verifiable calculation, and the like. Figure 2 shows a schematic diagram of the process of conversion from calculation to final zero-knowledge proof in zk-SNARK. Computation in Figure 2 means calculation, Algebraic Circuit means logic circuit, R1CS means first-order constraint system, and QAP means secondary algorithm problem.
本说明书实施例中的密码协议算法源码数据的生成语言不受限制,可以根据实际需要选择生成源码的语言类型。如可以采用多种主流的高级语言C、C++、Java等。The generation language of the source code data of the cryptographic protocol algorithm in the embodiment of this specification is not limited, and the language type of the source code can be selected according to actual needs. For example, a variety of mainstream high-level languages C, C++, Java, etc. can be used.
然后,可以基于LLVM(Low Level Virtual Machine,底层虚拟机)编译器对算法源码数据进行编译。LLVM编译器可以对算法源码数据词法分析、语法分析、语义分析、执行优化等操作,生成初始LLVM中间码(LLVM IR)数据。Then, the algorithm source code data can be compiled based on the LLVM (Low Level Virtual Machine) compiler. The LLVM compiler can perform operations such as lexical analysis, syntax analysis, semantic analysis, and optimization of the algorithm source code data to generate initial LLVM intermediate code (LLVM IR) data.
S204:对所述初始LLVM中间码数据进行无跳转的静态单赋值处理,获得处理后的中间码数据。S204: Perform static single assignment processing without jump on the initial LLVM intermediate code data to obtain processed intermediate code data.
可以进一步对初始LLVM中间码数据进行无跳转的静态单赋值处理,以使得处理后的中间码数据格式符合密码学形式的要求。所述无跳转的静态单赋值处理可以包 括消除初始LLVM中间码数据中的多次赋值、函数调用、语句跳转等操作,以获得没有跳转的静态单赋值形式的中间码数据。The initial LLVM intermediate code data can be further subjected to static single assignment processing without jump, so that the processed intermediate code data format meets the requirements of the cryptographic form. The static single assignment processing without jump may include eliminating multiple assignments, function calls, statement jumps and other operations in the initial LLVM intermediate code data to obtain intermediate code data in the form of static single assignment without jump.
LLVM编译过程中虽然可以将部分算法源码数据转换成静态单赋值形式,但仅仅为一些简单算法源码数据的静态单赋值形式转换,转换后的中间码数据仍含有同一变量的多次赋值、函数调用、语句跳转等操作,而这些操作难于转换为密码学算法需要的电路或R1CS形式。本说明书实施例中,通过进一步消除初始LLVM中间码数据中的同一变量的多次赋值、函数调用、语句跳转等操作,可以使得处理后的中间码数据格式更符合密码学形式的要求,提高后续处理的效率。Although part of the algorithm source code data can be converted into static single assignment form during LLVM compilation, it only converts the static single assignment form of some simple algorithm source code data. The converted intermediate code data still contains multiple assignments and function calls for the same variable. , Sentence jump and other operations, and these operations are difficult to convert to the circuit or R1CS form required by cryptographic algorithms. In the embodiment of this specification, by further eliminating multiple assignments, function calls, statement jumps and other operations of the same variable in the initial LLVM intermediate code data, the processed intermediate code data format can be made more consistent with the requirements of cryptographic forms, and The efficiency of subsequent processing.
本说明书的一个实施例中,可以对所述初始LLVM中间码数据进行函数内联及静态单赋值处理,获得第一中间码数据;对所述第一中间码数据进行消除控制流处理,获得处理后的中间码数据。In an embodiment of this specification, the initial LLVM intermediate code data may be subjected to function inlining and static single assignment processing to obtain the first intermediate code data; the first intermediate code data may be eliminated control flow processing to obtain processing After the intermediate code data.
可以先对初始LLVM中间码数据进行函数内联处理,将所有的子函数内联到主函数中,以消除函数调用。然后,可以对函数内联处理后的中间码数据进行静态单赋值处理,将同一变量的多次赋值转换为单次赋值,获得第一中间码数据。You can inline the initial LLVM intermediate code data first, and inline all the sub-functions into the main function to eliminate function calls. Then, static single assignment processing can be performed on the intermediate code data after the function inline processing, and multiple assignments of the same variable can be converted into a single assignment to obtain the first intermediate code data.
通过先将子函数全部内联到主函数中,获得仅仅包含主函数的中间码数据,然后,在此基础上再对主函数内的同一变量的多次赋值转换为单次赋值,可以更加高效准确的消除中间码数据中的全部多次赋值。By first inlining all the sub-functions into the main function, the intermediate code data containing only the main function is obtained, and then, on this basis, multiple assignments of the same variable in the main function are converted into a single assignment, which can be more efficient Accurately eliminate all multiple assignments in the intermediate code data.
本说明书的一个或者多个实施例中,所述对所述初始LLVM中间码数据进行函数内联及静态单赋值处理可以包括:In one or more embodiments of this specification, the performing function inlining and static single assignment processing on the initial LLVM intermediate code data may include:
将所述初始LLVM中间码数据的子函数内联到主函数中,并将全局变量放入所述主函数中;Inlining the sub-functions of the initial LLVM intermediate code data into the main function, and putting global variables into the main function;
对所述主函数进行循环展开和常量折叠消除,以及,将所述主函数中的类和结构体变量使用标量替换消除;Performing loop expansion and constant folding elimination on the main function, and replacing and eliminating class and structure variables in the main function with scalar;
将所述主函数中的Switch跳转语句转换为跳转语句,并将多条返回语句合并为一条返回语句;Convert the Switch jump statement in the main function into a jump statement, and merge multiple return statements into one return statement;
将所述主函数中的同一变量的多次赋值转换为多个变量的单次赋值。Converting multiple assignments of the same variable in the main function into single assignments of multiple variables.
可以先将所述初始LLVM中间码数据的子函数内联到主函数中,消除中间码数据中的函数调用。然后,可以进一步将所有全局变量放入主函数中,将全局变量的多次赋值转换为多个变量的单次赋值。The sub-functions of the initial LLVM intermediate code data can be inlined into the main function first to eliminate function calls in the intermediate code data. Then, you can further put all global variables into the main function, and convert multiple assignments of global variables into single assignments of multiple variables.
进一步的,可以将循环进行展开,并将常量折叠消除,初步消除跳转。所述常量折叠消除为将常量计算求值,用值来代替表达式,放入常量表。对类和结构体变量可以使用标量替换消除。可以进一步将switch语句转换为跳转语句(Br语句),将多条返回语句(Return语句)合并为一条Return语句。之后,还可以进一步将内存读写指令也转换为静态单赋值形式。Further, the loop can be expanded, and constant folding can be eliminated, and jumps can be eliminated initially. The constant folding elimination is to evaluate the constant calculation, replace the expression with the value, and put it into the constant table. You can use scalar substitution to eliminate class and structure variables. The switch statement can be further converted into a jump statement (Br statement), and multiple return statements (Return statements) can be combined into one Return statement. After that, you can further convert the memory read and write instructions into a static single assignment form.
通过上述处理,可以更加准确彻底的实现对中间码数据的静态单赋值处理。同时还可以初步消除跳转处理。进一步的,通过初步将控制节点流转的switch语句转换为Br跳转语句,可以进一步方便后续跳转消除处理。Through the above processing, the static single assignment processing of the intermediate code data can be realized more accurately and completely. At the same time, jump processing can be eliminated initially. Further, by preliminarily converting the switch statement that controls the flow of the node into the Br jump statement, the subsequent jump elimination processing can be further facilitated.
完成上述处理后,中间码数据可以被转换如下形式:只有一个主函数,主函数内有多个基本块。相应的,最后一个基本块的终结指令为Return语句,其他基本块的终结指令为Br跳转指令,相应的,Br跳转指令可以为有条件跳转指令或无条件跳转指令。基本块内的其他指令只有算术运算、按位运算、比较运算、选择指令(Select指令)和Phi指令。After completing the above processing, the intermediate code data can be converted into the following form: there is only one main function, and there are multiple basic blocks in the main function. Correspondingly, the final instruction of the last basic block is a Return statement, and the final instruction of other basic blocks is a Br jump instruction. Correspondingly, the Br jump instruction can be a conditional jump instruction or an unconditional jump instruction. The other instructions in the basic block are only arithmetic operations, bitwise operations, comparison operations, select instructions (Select instructions) and Phi instructions.
所述Br指令可以包括有条件跳转指令或无条件跳转指令,所述有条件跳转指令可以是指在满足一定预设条件下由当前节点跳转至预设节点的指令,所述无条件跳转指令是指在不附带条件的情况下由当前节点跳转至预设节点的指令。The Br instruction may include a conditional jump instruction or an unconditional jump instruction. The conditional jump instruction may refer to an instruction to jump from a current node to a preset node under certain preset conditions. The transfer instruction refers to an instruction to jump from the current node to the preset node without any conditions.
所述Phi指令为静态单赋值形式对于的数据中用于确定当前节点之前执行的节点的指令,以利用之前执行的节点的值进行当前节点的处理。将同一变量的多次赋值被转换为多个变量的单次赋值形式后,一个节点之前可能对应有多个节点,可以通过Phi指令来确定控制流中当前节点对应的前一节点,以利用该前一节点的值进行当前节点的处理。The Phi instruction is an instruction used to determine the node executed before the current node in the data for the static single assignment form, so as to use the value of the previously executed node to process the current node. After multiple assignments of the same variable are converted into a single assignment form of multiple variables, a node may correspond to multiple nodes before. The Phi instruction can be used to determine the previous node corresponding to the current node in the control flow to use this The value of the previous node is processed by the current node.
然后,可以进一步对所述第一中间码数据进行消除控制流处理,消除第一中间码数据中的Phi语句及跳转语句,转换为没有跳转的静态单赋值形式,使得处理后的中间码数据可以直接用于密码学协议需要的电路或R1CS形式。Then, the first intermediate code data can be further processed to eliminate control flow, eliminate Phi statements and jump statements in the first intermediate code data, and convert to a static single assignment form without jumps, so that the processed intermediate code The data can be directly used in the circuit or R1CS format required by the cryptographic protocol.
本说明书的一个实施例中,可以进一步将所述第一中间码数据中的Phi指令转换为选择指令,获得第二中间码数据;In an embodiment of this specification, the Phi instruction in the first intermediate code data may be further converted into a selection instruction to obtain the second intermediate code data;
将所述第二中间码数据中的跳转语句移除,获得处理后的中间码数据。The jump sentence in the second intermediate code data is removed to obtain processed intermediate code data.
对于第一中间码数据中的任意一个Phi指令,可以将其转换为若干条Select指令,以消除Phi指令,消除Phi指令后,各节点之间的执行顺序及方式可以直接通过Select 指令进行连接。相应的,整个中间码数据执行过程中无需再通过跳转指令确定执行顺序及方式,将各节点之间的跳转指令移除即可。从而利用上述实施例的方案,简单高效的实现了中间码数据中跳转指令的消除处理,获得没有跳转的静态单赋值形式的中间码数据。For any Phi instruction in the first intermediate code data, it can be converted into several Select instructions to eliminate the Phi instruction. After the Phi instruction is eliminated, the execution order and mode between the nodes can be directly connected through the Select instruction. Correspondingly, during the entire intermediate code data execution process, it is no longer necessary to determine the execution sequence and method through jump instructions, and just remove the jump instructions between nodes. Therefore, by using the solution of the foregoing embodiment, the elimination processing of the jump instruction in the intermediate code data is simply and efficiently realized, and the intermediate code data in the form of static single assignment without jump is obtained.
本说明书提供一个应用场景实例中,可以通过下述步骤对初始LLVM中间码数据进行处理,以获得没有跳转的静态单赋值形式的中间码数据:This manual provides an example of an application scenario. The initial LLVM intermediate code data can be processed through the following steps to obtain intermediate code data in the form of static single assignment without jump:
1)函数调用:把所有函数内联到主函数中;1) Function call: inline all functions into the main function;
2)全局变量:把所有函数内联后,把所有全局变量放进主函数中;2) Global variables: After all functions are inlined, put all global variables into the main function;
3)循环:使用循环展开和常量折叠消除;3) Loop: use loop expansion and constant folding to eliminate;
4)类和结构体变量:使用标量替换消除;4) Class and structure variables: use scalar replacement to eliminate;
5)switch跳转语句:降解为Br跳转语句;5) Switch jump statement: degraded into Br jump statement;
6)多条Return语句:合并为一条Return语句;6) Multiple Return statements: merge into one Return statement;
7)内存读写:转换为SSA形式;7) Memory read and write: converted to SSA format;
8)控制流:把所有基本块合并为一个基本块。8) Control flow: Combine all basic blocks into one basic block.
步骤1)-7)可以参考上述方案实施,这里不做赘述。图2表示经过上述步骤1)-7)处理后的中间码数据对应的控制流示意图,参考图2,对控制流消除处理做进一步说明。假设,经过步骤1)-7)获得的第一中间码数据为:Steps 1)-7) can be implemented with reference to the above-mentioned scheme, which will not be repeated here. Fig. 2 shows a schematic diagram of the control flow corresponding to the intermediate code data processed through the above steps 1)-7). With reference to Fig. 2, the control flow elimination processing is further explained. Suppose that the first intermediate code data obtained through steps 1)-7) is:
Figure PCTCN2019086594-appb-000001
Figure PCTCN2019086594-appb-000001
由图2可知,以基本块bb4为例,bb4之前的基本块可以有bb2和bb3,相应的,bb4对应的控制流数据中包含有Phi指令::%r4=phi i32[42,%bb2],[43,%bb3]。如果控制流从基本块bb2跳转到bb4,%r4被赋值为42,如果控制流从bb3跳转到bb4,%r4被赋值位43。从而,通过Phi指令可以确定bb4待执行的值,如果%r4的值为42,则bb4基于基本块bb2的数据进行后续处理,如果%r4的值为43,则bb4基于基本块bb3的数据进行后续处理。It can be seen from Figure 2 that taking the basic block bb4 as an example, the basic blocks before bb4 can have bb2 and bb3. Correspondingly, the control flow data corresponding to bb4 contains the Phi instruction: %r4=phi i32[42,%bb2] ,[43,%bb3]. If the control flow jumps from the basic block bb2 to bb4, %r4 is assigned the value 42, and if the control flow jumps from bb3 to bb4, the %r4 is assigned bit 43. Therefore, the value of bb4 to be executed can be determined through the Phi instruction. If the value of %r4 is 42, then bb4 performs subsequent processing based on the data of the basic block bb2, and if the value of %r4 is 43, then bb4 is performed based on the data of the basic block bb3 Follow-up processing.
同理,基本块bb6之前的基本块也包含多个,也对应有Phi指令,Phi指令中的%r6根据前一个基本块可以被赋值为1、2、%r4或5。Similarly, the basic block before the basic block bb6 also contains multiple basic blocks, which also correspond to the Phi instruction. The %r6 in the Phi instruction can be assigned a value of 1, 2, %r4, or 5 according to the previous basic block.
对于上述控制流,可以通过下述方式进行消除Br指令和Phi指令:For the above control flow, the Br instruction and Phi instruction can be eliminated in the following ways:
第一步:将每一个Phi指令转换为若干条Select指令。Step 1: Convert each Phi instruction into several Select instructions.
以含有Phi指令的基本块bb4为例进行说明:Take the basic block bb4 containing the Phi instruction as an example:
首先,找到含有Phi指令的基本块bb4,并找到bb4的控制结点(前必经结点)bb0,从bb4开始反向遍历,找到所有可达bb4的基本块bb0、bb1、bb2、bb3。First, find the basic block bb4 containing the Phi instruction, and find the control node of bb4 (the node must be passed before) bb0, and traverse backward from bb4 to find all the basic blocks bb0, bb1, bb2, and bb3 that can reach bb4.
执行下述操作将bb4对应的Phi指令转换为Select指令:Perform the following operations to convert the Phi instruction corresponding to bb4 into a Select instruction:
Figure PCTCN2019086594-appb-000002
Figure PCTCN2019086594-appb-000002
在上述运行过程中:During the above operation:
InsertSelect(bb3,phi)返回phi语句中bb3的对应值43,InsertSelect(bb3,phi) returns the corresponding value 43 of bb3 in the phi statement,
InsertSelect(bb2,phi)返回42,InsertSelect(bb2,phi) returns 42,
InsertSelect(bb1,phi)调用InsertSelect(bb2,phi),返回42,InsertSelect(bb1,phi) calls InsertSelect(bb2,phi), returns 42,
InsertSelect(bb0,phi)调用InsertSelect(bb1,phi)得到42,调用InsertSelect(bb3,phi)得到43,创建Select语句Select(%cond0,42,43),并替换掉phi语句。InsertSelect(bb0,phi) calls InsertSelect(bb1,phi) to get 42, call InsertSelect(bb3,phi) to get 43, create Select statement Select(%cond0,42,43), and replace phi statement.
处理完成后,bb4对应的phi语句“%r4=phi i32[42,%bb2],[43,%bb3]”被替换为Select语句“%r4.bb0=select i1%cond0,i32 42,i32 43”。After the processing is completed, the phi sentence "%r4=phi i32[42,%bb2],[43,%bb3]" corresponding to bb4 is replaced with the Select sentence "%r4.bb0=select i1%cond0,i32 42,i32 43 ".
对基本块bb6也依照上述方式进行处理,执行完成后,对应的中间码数据为:The basic block bb6 is also processed in the above manner. After the execution is completed, the corresponding intermediate code data is:
Figure PCTCN2019086594-appb-000003
Figure PCTCN2019086594-appb-000003
最后,把所有Br语句移除,并把其它语句移到一个基本块中,完成控制流消除处理。相应的,完成控制流消除处理后的中间码数据变成如下形式:Finally, remove all Br statements and move other statements to a basic block to complete the control flow elimination process. Correspondingly, the intermediate code data after completing the control flow elimination processing becomes the following form:
Figure PCTCN2019086594-appb-000004
Figure PCTCN2019086594-appb-000004
本说明书上述实施例中,通过对LLVM中间码数据进行进一步优化处理,可以使得最终获得的中间码数据更适应于密码学协议数据处理的需要,同时,通过上述优化处理,还可以进一步提高后续处理的简便性以及效率。In the above-mentioned embodiments of this specification, by further optimizing the LLVM intermediate code data, the finally obtained intermediate code data can be more adapted to the needs of cryptographic protocol data processing. At the same time, through the above optimization processing, the subsequent processing can be further improved. The simplicity and efficiency.
S206:对所述处理后的中间码数据进行转换处理,获得R1CS数据。S206: Perform conversion processing on the processed intermediate code data to obtain R1CS data.
可以进一步基于上述处理后的中间码数据转换获得逻辑电路数据或者R1CS形式的数据。一些实施方式中,可先将处理后的中间码数据转换为逻辑电路数据,然后,再进一步转换为R1CS形式的数据。The logic circuit data or data in the form of R1CS can be further obtained based on the above-mentioned processed intermediate code data conversion. In some embodiments, the processed intermediate code data may be converted into logic circuit data first, and then further converted into data in the form of R1CS.
图3表示上述各个实施例提供的方案基于LLVM编译器对密码学计算算法源码数据转换为R1CS数据的流程图。如图3所示,优选的,本说明书的一个实施例中,可以基于约束生成算法对所述处理后的中间码数据进行转换处理,获得R1CS数据。FIG. 3 shows a flowchart of the conversion of cryptographic calculation algorithm source code data into R1CS data based on the LLVM compiler in the solutions provided by the foregoing embodiments. As shown in FIG. 3, preferably, in an embodiment of this specification, the processed intermediate code data may be converted based on a constraint generation algorithm to obtain R1CS data.
所述基于约束生成算法对所述处理后的中间码数据进行转换处理可以包括:将中间码数据中的每一种运算指令通过增加约束的方式进行处理,以构造成仅用加法和乘法表示的形式。通过将中间码数据中的指令直接构造成仅用加法和乘法表示的形式,获得R1CS形式的数据,可以避免利用逻辑电路数据获得R1CS数据的繁琐步骤,进而提高数据处理的效率以及简便性。The conversion processing of the processed intermediate code data based on the constraint generation algorithm may include: processing each arithmetic instruction in the intermediate code data by adding constraints, so as to be configured to be represented by only addition and multiplication form. By directly constructing the instructions in the intermediate code data into a form that only uses addition and multiplication to obtain R1CS data, the cumbersome steps of obtaining R1CS data using logic circuit data can be avoided, and the efficiency and simplicity of data processing can be improved.
下面以一些基本的LLVM指令为例,说明如何将LLVM IR转换为仅用加法和乘法表示的R1CS:The following takes some basic LLVM instructions as examples to illustrate how to convert LLVM IR to R1CS that only uses addition and multiplication:
1.Packing约束1. Packing constraints
为了处理按位运算,需要把一个多位的变量展开成多个一位的变量,或者把多个一位的变量合并成多位的变量,使用Packing约束可以保证多个变量是一个变量的按位展开,即:In order to deal with bitwise operations, you need to expand a multi-bit variable into multiple one-bit variables, or combine multiple one-bit variables into a multi-bit variable. Using Packing constraints can ensure that multiple variables are a variable Bit expansion, namely:
Figure PCTCN2019086594-appb-000005
Figure PCTCN2019086594-appb-000005
2 i可以用乘法或直接用加法表示,另外约束每个c i都是1或者0,则可以保证c和每个c i的关系。 2 i can be expressed by multiplication or directly by addition. In addition, by restricting each c i to be 1 or 0, the relationship between c and each c i can be guaranteed.
其中,所述Packing约束为将一个n位的数拆成n个1位的数,或者将n个1位的数组合成一个n位的数的约束处理方式。Wherein, the packing constraint is a constraint processing method of splitting an n-digit number into n 1-digit numbers, or combining n 1-digit arrays into an n-digit number.
2.大于比较2. Greater than comparison
%c=icmp sgt i32%a,%b%C=icmp sgt i32%a,%b
计算b-a,使用Packing取得差值的符号位(最高位);Calculate b-a and use Packing to get the sign bit (the highest bit) of the difference;
当a大于b,符号位等于1;When a is greater than b, the sign bit is equal to 1;
当a不大于b,符号位等于0。When a is not greater than b, the sign bit is equal to 0.
3.大于等于比较3. Greater than or equal to comparison
%c=icmp sge i32%a,%b%C=icmp sge i32%a,%b
使用大于比较,将结果存入gt;Use greater than comparison and store the result in gt;
使用等于比较,将结果存入eq;Use equal comparison and store the result in eq;
再加上约束。Plus constraints.
4.Add指令4.Add instruction
%c=add i32%a,i32%b%C=add i32%a,i32%b
可以表示为以下约束:It can be expressed as the following constraints:
c=(a+b)×1。c=(a+b)×1.
5.Mul指令5.Mul instruction
%c=mul i32%a,i32%b%C=mul i32%a,i32%b
可以表示为以下约束:It can be expressed as the following constraints:
c=a×b。c=a×b.
6.Sub指令6.Sub instruction
%c=sub i32%a,i32%b%C=sub i32%a,i32%b
可以表示为以下约束:It can be expressed as the following constraints:
c=(a-b)×1。c=(a-b)×1.
7.Div指令7.Div instruction
%c=div i32%a,i32%b%C=div i32%a,i32%b
可以表示为以下约束:It can be expressed as the following constraints:
Figure PCTCN2019086594-appb-000006
Figure PCTCN2019086594-appb-000006
其中,d为余数,c为商,大于和大于等于约束参考后序内容进行。Among them, d is the remainder, c is the quotient, and the greater than and greater than or equal constraints refer to the subsequent content.
8.Rem指令8.Rem instruction
%d=rem i32%a,i32%b%D=rem i32%a,i32%b
可以表示为以下约束:It can be expressed as the following constraints:
Figure PCTCN2019086594-appb-000007
Figure PCTCN2019086594-appb-000007
其中,d为余数,c为商,大于和大于等于约束参考后序内容进行。Among them, d is the remainder, c is the quotient, and the greater than and greater than or equal constraints refer to the subsequent content.
9.等于比较9. Equal comparison
%c=icmp eq i32%a,%b%C=icmp eq i32%a,%b
可以表示为以下约束:It can be expressed as the following constraints:
Figure PCTCN2019086594-appb-000008
Figure PCTCN2019086594-appb-000008
当a=b时,按照第一条约束,c可以为任意的数,所以需要第二条约束,aux设置为任意值,可以约束c必须为1;When a=b, according to the first constraint, c can be any number, so the second constraint is needed, aux is set to any value, and c must be 1;
当a≠b时,按照第一条约束,c必须等于0,aux设置为a-b的乘法逆元,令第二条约束也成立。When a≠b, according to the first constraint, c must be equal to 0, and aux is set to the multiplicative inverse of a-b, so that the second constraint also holds.
10.不等于比较10. Not equal to comparison
%c=icmp ne i32%a,%b%C=icmp ne i32%a,%b
添加约束:Add constraints:
Figure PCTCN2019086594-appb-000009
Figure PCTCN2019086594-appb-000009
当a=b时,按照第一条约束,c可以为任何数,按照第二条约束,aux可以设置为任意值,c必须为0;When a=b, according to the first constraint, c can be any number, according to the second constraint, aux can be set to any value, and c must be 0;
当a≠b时,按照第一条约束,c必须等于1,aux设置为a-b的乘法逆元,令第二条约束也成立。When a≠b, according to the first constraint, c must be equal to 1, and aux is set to the multiplicative inverse of a-b, so that the second constraint is also valid.
11.Select指令11.Select instruction
%c=select i1%cond,i32%a,i32%b%C=select i1%cond,i32%a,i32%b
其中,%cond只有1位,只有0或1两种取值;Among them, %cond has only 1 digit, and only has two values of 0 or 1;
Select指令可以转换为下面的约束形式:The Select command can be converted into the following constraint form:
c=cond×a+(1+(-1×cond))×b。c=cond×a+(1+(-1×cond))×b.
12.And指令12.And instruction
%c=and i32%a,%b%C=and i32%a,%b
and是按位与运算,需要用Packing把32位的a和b分别拆成32个变量,对每对变量进行与运算,并约束a i、b i、c i的关系,再用Packing把32个c i合并成c变量; and a bitwise AND, needed to Packing 32 bits a and b are split into 32 variables for each of the operational variables, constraints and a i, b i, c i, and then the 32 Packing Ci merge into c variable;
每个变量的约束为:The constraints of each variable are:
c i=a i+b ic i =a i +b i .
13.Or指令13.Or instruction
%c=or i32%a,%b%C=or i32%a,%b
or是按位或运算,需要用Packing把32位的a和b分别拆成32个变量,对每对变量进行与运算,并约束a i、b i、c i的关系,再用Packing把32个c i合并成c变量; or is the bitwise OR operation, need to 32 Packing of a and b are split into 32 variables for each of the operational variables, constraints and a i, b i, c i, and then the 32 Packing Ci merge into c variable;
每个变量的约束为:The constraints of each variable are:
a i×b i=a i+b i-c ia i ×b i =a i +b i -c i .
14.xor指令14.xor instruction
%c=xor i32%a,%b%C=xor i32%a,%b
xor是按位异或运算,需要用Packing把32位的a和b分别拆成32个变量,对每对变量进行与运算,并约束a i、b i、c i的关系,再用Packing把32个c i合并成c变量; xor is a bitwise exclusive OR operation. Packing is used to separate the 32-bit a and b into 32 variables, and each pair of variables is ANDed, and the relationship between a i , b i and c i is restricted, and then Packing is used to 32 c i are merged into c variable;
每个变量的约束为使用不等于约束来实现。The constraints of each variable are implemented using unequal constraints.
本说明书上述各个实施例,通过基于LLVM编译器来进行密码学计算算法源码的编译,可以使得算法源码编写时语言类型不再受限,开发者可以根据自身需求选择多种主流的开发语言进行相应算法的编写,提高了算法编写的简便性。In each of the above-mentioned embodiments of this specification, by compiling the source code of cryptographic calculation algorithms based on the LLVM compiler, the language type when writing the algorithm source code is no longer limited, and developers can choose a variety of mainstream development languages according to their own needs. The writing of algorithms improves the simplicity of algorithm writing.
同时,对于因密码学算法的复杂性,LLVM编译器直接编译后的中间码数据可能无法直接转换成逻辑电路或者R1CS数据的问题,本说明书实施例中还进一步对中间码数据进行了相关优化处理。从而,利用本说明书各个实施例提供的方案,可以简单高效的实现密码学算法源码数据向R1CS数据的编译处理。At the same time, due to the complexity of the cryptographic algorithm, the intermediate code data directly compiled by the LLVM compiler may not be directly converted into a logic circuit or R1CS data. In the embodiment of this specification, the intermediate code data is further optimized. . Therefore, by using the solutions provided by the various embodiments of this specification, the compilation processing of the source code data of the cryptographic algorithm into the R1CS data can be realized simply and efficiently.
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。具体的可 以参照前述相关处理相关实施例的描述,在此不做一一赘述。The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. For details, reference may be made to the description of the foregoing related processing related embodiments, which will not be repeated here.
上述对本说明书特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。The foregoing describes specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims may be performed in a different order than in the embodiments and still achieve desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or sequential order shown to achieve the desired result. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
本说明书一个或多个实施例提供的数据处理方法,可以通过利用LLVM编译器来编译待处理的密码协议算法源码数据,然后,进一步对编译获得的中间码数据进行优化处理,进而基于优化处理后的中间码数据获得R1CS数据。LLVM编译器可以支持任意语言的算法编译,且可以实现错误检查以及代码优化等处理,从而可以大幅度提高算法源码数据编写的简便性以及编译处理的高效性。同时,本说明书实施例还进一步对LLVM编译器编译获得的中间码数据进行进一步优化处理,以使得优化后的中间码数据可以适应密码学算法所需要的R1CS形式,从而简单高效的实现复杂的逻辑计算向R1CS的转换处理。The data processing method provided by one or more embodiments of this specification can compile the source code data of the cryptographic protocol algorithm to be processed by using the LLVM compiler, and then further optimize the intermediate code data obtained by the compilation, and then based on the optimized processing R1CS data is obtained from the intermediate code data. The LLVM compiler can support algorithm compilation in any language, and can implement error checking and code optimization, which can greatly improve the ease of writing algorithm source code data and the efficiency of compilation processing. At the same time, the embodiment of this specification further further optimizes the intermediate code data obtained by the LLVM compiler, so that the optimized intermediate code data can adapt to the R1CS form required by the cryptographic algorithm, so as to implement complex logic simply and efficiently. Calculate the conversion process to R1CS.
基于上述所述的数据处理方法,本说明书一个或多个实施例还提供一种数据处理装置。所述的装置可以包括使用了本说明书实施例所述方法的系统、软件(应用)、模块、组件、服务器等并结合必要的实施硬件的装置。基于同一创新构思,本说明书实施例提供的一个或多个实施例中的装置如下面的实施例所述。由于装置解决问题的实现方案与方法相似,因此本说明书实施例具体的装置的实施可以参见前述方法的实施,重复之处不再赘述。以下所使用的,术语“单元”或者“模块”可以实现预定功能的软件和/或硬件的组合。尽管以下实施例所描述的装置较佳地以软件来实现,但是硬件,或者软件和硬件的组合的实现也是可能并被构想的。具体的,图4表示说明书提供的一种数据处理装置实施例的模块结构示意图,如图4所示,所述装置可以包括:Based on the data processing method described above, one or more embodiments of this specification also provide a data processing device. The described devices may include systems, software (applications), modules, components, servers, etc. that use the methods described in the embodiments of this specification, combined with necessary implementation hardware devices. Based on the same innovative concept, the devices in one or more embodiments provided in the embodiments of this specification are as described in the following embodiments. Since the implementation scheme of the device to solve the problem is similar to the method, the implementation of the specific device in the embodiment of this specification can refer to the implementation of the foregoing method, and the repetition will not be repeated. As used below, the term "unit" or "module" can be a combination of software and/or hardware that implements predetermined functions. Although the devices described in the following embodiments are preferably implemented by software, hardware or a combination of software and hardware is also possible and conceived. Specifically, FIG. 4 shows a schematic diagram of the module structure of an embodiment of a data processing device provided in the specification. As shown in FIG. 4, the device may include:
数据编译模块102,可以用于基于LLVM编译器对待处理的密码协议算法源码数据进行编译,获得初始LLVM中间码数据;The data compiling module 102 can be used to compile the cryptographic protocol algorithm source code data to be processed based on the LLVM compiler to obtain initial LLVM intermediate code data;
单赋值处理模块104,可以用于对所述初始LLVM中间码数据进行无跳转的静态单赋值处理,获得处理后的中间码数据;The single assignment processing module 104 may be used to perform static single assignment processing without jumps on the initial LLVM intermediate code data to obtain processed intermediate code data;
数据转换模块106,可以用于对所述处理后的中间码数据进行转换处理,获得 R1CS数据。The data conversion module 106 may be used to perform conversion processing on the processed intermediate code data to obtain R1CS data.
本说明书的一个实施例中,所述单赋值处理模块104可以包括:In an embodiment of this specification, the single assignment processing module 104 may include:
单赋值处理单元,可以用于对所述初始LLVM中间码数据进行函数内联及静态单赋值处理,获得第一中间码数据;The single assignment processing unit may be used to perform function inlining and static single assignment processing on the initial LLVM intermediate code data to obtain the first intermediate code data;
控制流消除单元,可以用于对所述第一中间码数据进行消除控制流处理,获得处理后的中间码数据。The control flow elimination unit may be used to perform control flow elimination processing on the first intermediate code data to obtain processed intermediate code data.
本说明书的一个实施例中,所述控制流消除单元可以包括:In an embodiment of this specification, the control flow elimination unit may include:
指令转换子单元,可以用于将所述第一中间码数据中的Phi指令转换为选择指令,获得第二中间码数据;The instruction conversion subunit can be used to convert the Phi instruction in the first intermediate code data into a selection instruction to obtain the second intermediate code data;
语句合并子单元,可以用于将所述第二中间码数据中的跳转语句移除,获得处理后的中间码数据。The sentence merging subunit can be used to remove the jump sentence in the second intermediate code data to obtain processed intermediate code data.
本说明书的一个实施例中,所述转换模块106可以包括:In an embodiment of this specification, the conversion module 106 may include:
转换单元,可以用于基于约束生成算法对处理后的中间码数据进行转换处理,获得R1CS数据。The conversion unit may be used to perform conversion processing on the processed intermediate code data based on the constraint generation algorithm to obtain R1CS data.
需要说明的,上述所述的装置根据方法实施例的描述还可以包括其他的实施方式。具体的实现方式可以参照相关方法实施例的描述,在此不作一一赘述。It should be noted that the above-mentioned device may also include other implementation manners according to the description of the method embodiment. For specific implementation manners, reference may be made to the description of the related method embodiments, which will not be repeated here.
本说明书一个或多个实施例提供的数据处理装置,可以通过利用LLVM编译器来编译待处理的密码协议算法源码数据,然后,进一步对编译获得的中间码数据进行优化处理,进而基于优化处理后的中间码数据获得R1CS数据。LLVM编译器可以支持任意语言的算法编译,且可以实现错误检查以及代码优化等处理,从而可以大幅度提高算法源码数据编写的简便性以及编译处理的高效性。同时,本说明书实施例还进一步对LLVM编译器编译获得的中间码数据进行进一步优化处理,以使得优化后的中间码数据可以适应密码学算法所需要的R1CS形式,从而简单高效的实现复杂的逻辑计算向R1CS的转换。The data processing device provided by one or more embodiments of this specification can compile the source code data of the cryptographic protocol algorithm to be processed by using the LLVM compiler, and then further optimize the intermediate code data obtained by the compilation, and then based on the optimized processing R1CS data is obtained from the intermediate code data. The LLVM compiler can support algorithm compilation in any language, and can implement error checking and code optimization, which can greatly improve the ease of writing algorithm source code data and the efficiency of compilation processing. At the same time, the embodiment of this specification further further optimizes the intermediate code data obtained by the LLVM compiler, so that the optimized intermediate code data can adapt to the R1CS form required by the cryptographic algorithm, so as to implement complex logic simply and efficiently. Calculate the conversion to R1CS.
本说明书提供的上述实施例所述的方法或装置可以通过计算机程序实现业务逻辑并记录在存储介质上,所述的存储介质可以计算机读取并执行,实现本说明书实施例所描述方案的效果。因此,本说明书还提供一种数据处理设备,包括处理器及存储处理器可执行指令的存储器,所述指令被所述处理器执行时实现包括以下步骤:The method or device described in the foregoing embodiment provided in this specification can implement business logic through a computer program and record it on a storage medium, and the storage medium can be read and executed by a computer to achieve the effects of the solution described in the embodiment of this specification. Therefore, this specification also provides a data processing device including a processor and a memory storing executable instructions of the processor. When the instructions are executed by the processor, the implementation includes the following steps:
基于LLVM编译器对待处理的密码协议算法源码数据进行编译,获得初始LLVM 中间码数据;Compile the source code data of the cryptographic protocol algorithm to be processed based on the LLVM compiler to obtain the initial LLVM intermediate code data;
对所述初始LLVM中间码数据进行无跳转的静态单赋值处理,获得处理后的中间码数据;Performing static single assignment processing without jump on the initial LLVM intermediate code data to obtain processed intermediate code data;
对所述处理后的中间码数据进行转换处理,获得R1CS数据。Perform conversion processing on the processed intermediate code data to obtain R1CS data.
所述存储介质可以包括用于存储信息的物理装置,通常是将信息数字化后再以利用电、磁或者光学等方式的媒体加以存储。所述存储介质有可以包括:利用电能方式存储信息的装置如,各式存储器,如RAM、ROM等;利用磁能方式存储信息的装置如,硬盘、软盘、磁带、磁芯存储器、磁泡存储器、U盘;利用光学方式存储信息的装置如,CD或DVD。当然,还有其他方式的可读存储介质,例如量子存储器、石墨烯存储器等等。The storage medium may include a physical device for storing information, and the information is usually digitized and then stored in an electric, magnetic, or optical medium. The storage medium may include: devices that use electrical energy to store information, such as various types of memory, such as RAM, ROM, etc.; devices that use magnetic energy to store information, such as hard disks, floppy disks, magnetic tapes, magnetic core memory, bubble memory, U disk; a device that uses optical means to store information, such as CD or DVD. Of course, there are other ways of readable storage media, such as quantum memory, graphene memory, and so on.
需要说明的,上述所述的设备根据方法实施例的描述还可以包括其他的实施方式。具体的实现方式可以参照相关方法实施例的描述,在此不作一一赘述。It should be noted that the above-mentioned device may also include other implementation manners according to the description of the method embodiment. For specific implementation manners, reference may be made to the description of the related method embodiments, which will not be repeated here.
本说明书实施例所提供的方法实施例可以在移动终端、计算机终端、服务器或者类似的运算装置中执行。以运行在服务器上为例,图5是应用本说明书实施例的数据处理服务器的硬件结构框图。如图5所示,服务器10可以包括一个或多个(图中仅示出一个)处理器20(处理器20可以包括但不限于微处理器MCU或可编程逻辑器件FPGA等的处理装置)、用于存储数据的存储器30、以及用于通信功能的传输模块40。本邻域普通技术人员可以理解,图5所示的结构仅为示意,其并不对上述电子装置的结构造成限定。例如,服务器10还可包括比图5中所示更多或者更少的组件,例如还可以包括其他的处理硬件,如数据库或多级缓存、GPU,或者具有与图5所示不同的配置。The method embodiments provided in the embodiments of this specification can be executed in a mobile terminal, a computer terminal, a server or a similar computing device. Taking running on a server as an example, FIG. 5 is a hardware structure block diagram of a data processing server to which the embodiment of this specification is applied. As shown in FIG. 5, the server 10 may include one or more (only one is shown in the figure) processor 20 (the processor 20 may include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA), The memory 30 for storing data, and the transmission module 40 for communication functions. Those of ordinary skill in the neighborhood can understand that the structure shown in FIG. 5 is only for illustration, and does not limit the structure of the above electronic device. For example, the server 10 may also include more or fewer components than shown in FIG. 5, for example, may also include other processing hardware, such as a database or multi-level cache, GPU, or have a configuration different from that shown in FIG.
存储器30可用于存储应用软件的软件程序以及模块,如本发明实施例中的搜索方法对应的程序指令/模块,处理器20通过运行存储在存储器30内的软件程序以及模块,从而执行各种功能应用以及数据处理。存储器30可包括高速随机存储器,还可包括非易失性存储器,如一个或者多个磁性存储装置、闪存、或者其他非易失性固态存储器。在一些实例中,存储器30可进一步包括相对于处理器20远程设置的存储器,这些远程存储器可以通过网络连接至计算机终端。上述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。The memory 30 may be used to store software programs and modules of application software, such as program instructions/modules corresponding to the search method in the embodiment of the present invention. The processor 20 executes various functions by running the software programs and modules stored in the memory 30 Application and data processing. The memory 30 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 30 may further include a memory remotely provided with respect to the processor 20, and these remote memories may be connected to the computer terminal through a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
传输模块40用于经由一个网络接收或者发送数据。上述的网络具体实例可包括 计算机终端的通信供应商提供的无线网络。在一个实例中,传输模块40包括一个网络适配器(Network Interface Controller,NIC),其可通过基站与其他网络设备相连从而可与互联网进行通讯。在一个实例中,传输模块40可以为射频(Radio Frequency,RF)模块,其用于通过无线方式与互联网进行通讯。The transmission module 40 is used to receive or send data via a network. The above-mentioned specific examples of the network may include a wireless network provided by a communication provider of a computer terminal. In an example, the transmission module 40 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station to communicate with the Internet. In an example, the transmission module 40 may be a radio frequency (RF) module, which is used to communicate with the Internet in a wireless manner.
上述实施例所述的数据处理设备,可以通过利用LLVM编译器来编译待处理的密码协议算法源码数据,然后,进一步对编译获得的中间码数据进行优化处理,进而基于优化处理后的中间码数据获得R1CS数据。LLVM编译器可以支持任意语言的算法编译,且可以实现错误检查以及代码优化等处理,从而可以大幅度提高算法源码数据编写的简便性以及编译处理的高效性。同时,本说明书实施例还进一步对LLVM编译器编译获得的中间码数据进行进一步优化处理,以使得优化后的中间码数据可以适应密码学算法所需要的R1CS形式,从而简单高效的实现复杂的逻辑计算向R1CS的转换处理。The data processing device described in the above embodiment can compile the source code data of the cryptographic protocol algorithm to be processed by using the LLVM compiler, and then further optimize the intermediate code data obtained by the compilation, and then based on the optimized intermediate code data Obtain R1CS data. The LLVM compiler can support algorithm compilation in any language, and can implement error checking and code optimization, which can greatly improve the ease of writing algorithm source code data and the efficiency of compilation processing. At the same time, the embodiment of this specification further further optimizes the intermediate code data obtained by the LLVM compiler, so that the optimized intermediate code data can adapt to the R1CS form required by the cryptographic algorithm, so as to implement complex logic simply and efficiently. Calculate the conversion process to R1CS.
本说明书还提供一种数据处理系统,所述系统可以为单独的数据处理系统,也可以应用在多种计算机数据处理系统中。所述的系统可以为单独的服务器,也可以包括使用了本说明书的一个或多个所述方法或一个或多个实施例装置的服务器集群、系统(包括分布式系统)、软件(应用)、实际操作装置、逻辑门电路装置、量子计算机等并结合必要的实施硬件的终端装置。所述数据处理系统可以包括至少一个处理器以及存储计算机可执行指令的存储器,所述处理器执行所述指令时实现上述任意一个或者多个实施例中所述方法的步骤。This specification also provides a data processing system, which can be a separate data processing system or can be applied to multiple computer data processing systems. The system can be a single server, or it can include server clusters, systems (including distributed systems), software (applications), and one or more of the methods described in this specification or one or more embodiments of the device. The actual operation device, logic gate circuit device, quantum computer, etc., combined with the terminal device necessary to implement the hardware. The data processing system may include at least one processor and a memory storing computer-executable instructions. The processor implements the steps of the method in any one or more of the foregoing embodiments when the processor executes the instructions.
需要说明的,上述所述的系统根据方法或者装置实施例的描述还可以包括其他的实施方式,具体的实现方式可以参照相关方法实施例的描述,在此不作一一赘述。It should be noted that the above-mentioned system may also include other implementation manners based on the description of the method or device embodiment. For the specific implementation manner, reference may be made to the description of the relevant method embodiment, which will not be repeated here.
上述实施例所述的数据处理系统,可以通过利用LLVM编译器来编译待处理的密码协议算法源码数据,然后,进一步对编译获得的中间码数据进行优化处理,进而基于优化处理后的中间码数据获得R1CS数据。LLVM编译器可以支持任意语言的算法编译,且可以实现错误检查以及代码优化等处理,从而可以大幅度提高算法源码数据编写的简便性以及编译处理的高效性。同时,本说明书实施例还进一步对LLVM编译器编译获得的中间码数据进行进一步优化处理,以使得优化后的中间码数据可以适应密码学算法所需要的R1CS形式,从而简单高效的实现复杂的逻辑计算向R1CS的转换处理。The data processing system described in the above embodiment can compile the source code data of the cryptographic protocol algorithm to be processed by using the LLVM compiler, and then further optimize the intermediate code data obtained by the compilation, and then based on the optimized intermediate code data Obtain R1CS data. The LLVM compiler can support algorithm compilation in any language, and can implement error checking and code optimization, which can greatly improve the ease of writing algorithm source code data and the efficiency of compilation processing. At the same time, the embodiment of this specification further further optimizes the intermediate code data obtained by the LLVM compiler, so that the optimized intermediate code data can adapt to the R1CS form required by the cryptographic algorithm, so as to implement complex logic simply and efficiently. Calculate the conversion process to R1CS.
需要说明的是,本说明书上述所述的装置或者系统根据相关方法实施例的描述还可以包括其他的实施方式,具体的实现方式可以参照方法实施例的描述,在此不作一一赘述。本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于硬件+程序类、存储介质+程序实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。It should be noted that the device or system described above in this specification may also include other implementation manners based on the description of the related method embodiments. For specific implementation manners, refer to the description of the method embodiments, which will not be repeated here. The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, as for the hardware+program and storage medium+program embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and for related parts, please refer to the part of the description of the method embodiments.
尽管本说明书实施例内容中提到的循环展开、常量折叠消除等获取、定义、交互、计算、判断等操作和数据描述,但是,本说明书实施例并不局限于必须是符合标准数据模型/模板或本说明书实施例所描述的情况。某些行业标准或者使用自定义方式或实施例描述的实施基础上略加修改后的实施方案也可以实现上述实施例相同、等同或相近、或变形后可预料的实施效果。应用这些修改或变形后的数据获取、存储、判断、处理方式等获取的实施例,仍然可以属于本说明书的可选实施方案范围之内。Although the acquisition, definition, interaction, calculation, judgment and other operations and data descriptions mentioned in the content of the embodiment of this specification, such as loop expansion and constant folding elimination, etc., the embodiment of this specification is not limited to the standard data model/template. Or the situation described in the embodiment of this specification. Certain industry standards or implementations described in custom methods or examples with slight modifications can also achieve the same, equivalent or similar implementation effects of the foregoing examples, or predictable implementation effects after modification. The examples obtained by applying these modified or deformed data acquisition, storage, judgment, processing methods, etc., may still fall within the scope of the optional implementation solutions of this specification.
上述对本说明书特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。The foregoing describes specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims may be performed in a different order than in the embodiments and still achieve desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or sequential order shown to achieve the desired result. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机。具体的,计算机例如可以为个人计算机、膝上型计算机、车载人机交互设备、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任何设备的组合。The systems, devices, modules, or units illustrated in the above embodiments may be specifically implemented by computer chips or entities, or implemented by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a vehicle-mounted human-computer interaction device, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, and a tablet. Computers, wearable devices, or any combination of these devices.
为了描述的方便,描述以上装置时以功能分为各种模块分别描述。当然,在实施本说明书一个或多个时可以把各模块的功能在同一个或多个软件和/或硬件中实现,也可以将实现同一功能的模块由多个子模块或子单元的组合实现等。以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以 是电性,机械或其它的形式。For the convenience of description, when describing the above device, the functions are divided into various modules and described separately. Of course, when implementing one or more of this specification, the function of each module can be realized in the same one or more software and/or hardware, or the module that realizes the same function can be realized by a combination of multiple sub-modules or sub-units, etc. . The device embodiments described above are merely illustrative, for example, the division of the units is only a logical function division, and there may be other divisions in actual implementation, for example, multiple units or components can be combined or integrated To another system, or some features can be ignored, or not implemented. In addition, the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection through some interfaces, devices or units, and may be in electrical, mechanical or other forms.
本领域技术人员也知道,除了以纯计算机可读程序代码方式实现控制器以外,完全可以通过将方法步骤进行逻辑编程来使得控制器以逻辑门、开关、专用集成电路、可编程逻辑控制器和嵌入微控制器等的形式来实现相同功能。因此这种控制器可以被认为是一种硬件部件,而对其内部包括的用于实现各种功能的装置也可以视为硬件部件内的结构。或者甚至,可以将用于实现各种功能的装置视为既可以是实现方法的软件模块又可以是硬件部件内的结构。Those skilled in the art also know that in addition to implementing the controller in a purely computer-readable program code manner, it is entirely possible to program the method steps to make the controller use logic gates, switches, application specific integrated circuits, programmable logic controllers and embedded The same function can be realized in the form of a microcontroller, etc. Therefore, such a controller can be regarded as a hardware component, and the devices included in the controller for realizing various functions can also be regarded as a structure within the hardware component. Or even, the device for realizing various functions can be regarded as both a software module for realizing the method and a structure within a hardware component.
本发明是参照根据本发明实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。The present invention is described with reference to flowcharts and/or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and/or block in the flowchart and/or block diagram, and the combination of processes and/or blocks in the flowchart and/or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing equipment to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing equipment are generated It is a device that realizes the functions specified in one process or multiple processes in the flowchart and/or one block or multiple blocks in the block diagram.
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing equipment to work in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including the instruction device. The device implements the functions specified in one process or multiple processes in the flowchart and/or one block or multiple blocks in the block diagram.
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions can also be loaded on a computer or other programmable data processing equipment, so that a series of operation steps are executed on the computer or other programmable equipment to produce computer-implemented processing, so as to execute on the computer or other programmable equipment. The instructions provide steps for implementing functions specified in a flow or multiple flows in the flowchart and/or a block or multiple blocks in the block diagram.
在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。In a typical configuration, the computing device includes one or more processors (CPU), input/output interfaces, network interfaces, and memory.
还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法或者设备中还存在另外的相同要素。It should also be noted that the terms "include", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, product or equipment including a series of elements not only includes those elements, but also includes Other elements that are not explicitly listed, or include elements inherent to this process, method, commodity, or equipment. If there are no more restrictions, the element defined by the sentence "including a..." does not exclude the existence of other same elements in the process, method, or device that includes the element.
本领域技术人员应明白,本说明书一个或多个实施例可提供为方法、系统或计算机程序产品。因此,本说明书一个或多个实施例可采用完全硬件实施例、完全软件实施例或结合软件和硬件方面的实施例的形式。而且,本说明书一个或多个实施例可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art should understand that one or more embodiments of this specification can be provided as a method, a system, or a computer program product. Therefore, one or more embodiments of this specification may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, one or more embodiments of this specification may adopt a computer program implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes. The form of the product.
本说明书一个或多个实施例可以在由计算机执行的计算机可执行指令的一般上下文中描述,例如程序模块。一般地,程序模块包括执行特定任务或实现特定抽象数据类型的例程、程序、对象、组件、数据结构等等。也可以在分布式计算环境中实践本本说明书一个或多个实施例,在这些分布式计算环境中,由通过通信网络而被连接的远程处理设备来执行任务。在分布式计算环境中,程序模块可以位于包括存储设备在内的本地和远程计算机存储介质中。One or more embodiments of this specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. One or more embodiments of this specification can also be practiced in distributed computing environments. In these distributed computing environments, tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。在本说明书的描述中,参考术语“一个实施例”、“一些实施例”、“示例”、“具体示例”、或“一些示例”等的描述意指结合该实施例或示例描述的具体特征、结构、材料或者特点包含于本说明书的至少一个实施例或示例中。在本说明书中,对上述术语的示意性表述并不必须针对的是相同的实施例或示例。而且,描述的具体特征、结构、材料或者特点可以在任一个或多个实施例或示例中以合适的方式结合。此外,在不相互矛盾的情况下,本领域的技术人员可以将本说明书中描述的不同实施例或示例以及不同实施例或示例的特征进行结合和组合。The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, as for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and for related parts, please refer to the part of the description of the method embodiment. In the description of this specification, descriptions with reference to the terms "one embodiment", "some embodiments", "examples", "specific examples", or "some examples" etc. mean specific features described in conjunction with the embodiment or example , Structure, materials or features are included in at least one embodiment or example in this specification. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the described specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art can combine and combine the different embodiments or examples and the characteristics of the different embodiments or examples described in this specification without contradicting each other.
以上所述仅为本说明书的实施例而已,并不用于限制本说明书。对于本领域技术人员来说,本说明书可以有各种更改和变化。凡在本说明书的精神和原理之内所作的任何修改、等同替换、改进等,均应包含在本说明书的权利要求范围之内。The above descriptions are only examples of this specification and are not intended to limit this specification. For those skilled in the art, this specification can have various modifications and changes. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this specification shall be included in the scope of the claims of this specification.

Claims (10)

  1. 一种数据处理方法,其特征在于,包括:A data processing method, characterized by comprising:
    基于LLVM编译器对待处理的密码协议算法源码数据进行编译,获得初始LLVM中间码数据;Compile the source code data of the cryptographic protocol algorithm to be processed based on the LLVM compiler to obtain the initial LLVM intermediate code data;
    对所述初始LLVM中间码数据进行无跳转的静态单赋值处理,获得处理后的中间码数据;Performing static single assignment processing without jump on the initial LLVM intermediate code data to obtain processed intermediate code data;
    对所述处理后的中间码数据进行转换处理,获得R1CS数据。Perform conversion processing on the processed intermediate code data to obtain R1CS data.
  2. 根据权利要求1所述的方法,其特征在于,所述对所述初始LLVM中间码数据进行无跳转的静态单赋值处理,包括:The method according to claim 1, wherein the performing static single assignment processing without jump to the initial LLVM intermediate code data comprises:
    对所述初始LLVM中间码数据进行函数内联及静态单赋值处理,获得第一中间码数据;Performing function inlining and static single assignment processing on the initial LLVM intermediate code data to obtain the first intermediate code data;
    对所述第一中间码数据进行消除控制流处理,获得处理后的中间码数据。Performing elimination control flow processing on the first intermediate code data to obtain processed intermediate code data.
  3. 根据权利要求2所述的方法,其特征在于,所述对所述第一中间码数据进行消除控制流处理,包括:The method according to claim 2, wherein the performing control flow elimination processing on the first intermediate code data comprises:
    将所述第一中间码数据中的Phi指令转换为选择指令,获得第二中间码数据;Converting the Phi instruction in the first intermediate code data into a selection instruction to obtain the second intermediate code data;
    将所述第二中间码数据中的跳转语句移除,获得处理后的中间码数据。The jump sentence in the second intermediate code data is removed to obtain processed intermediate code data.
  4. 根据权利要求2所述的方法,其特征在于,所述对所述初始LLVM中间码数据进行函数内联及静态单赋值处理,包括:The method according to claim 2, wherein the performing function inlining and static single assignment processing on the initial LLVM intermediate code data comprises:
    将所述初始LLVM中间码数据的子函数内联到主函数中,并将全局变量放入所述主函数中;Inlining the sub-functions of the initial LLVM intermediate code data into the main function, and putting global variables into the main function;
    对所述主函数进行循环展开和常量折叠消除,以及,将所述主函数中的类和结构体变量使用标量替换消除;Performing loop expansion and constant folding elimination on the main function, and replacing and eliminating class and structure variables in the main function with scalar;
    将所述主函数中的Switch跳转语句转换为跳转语句,并将多条返回语句合并为一条返回语句;Convert the Switch jump statement in the main function into a jump statement, and merge multiple return statements into one return statement;
    将所述主函数中的同一变量的多次赋值转换为多个变量的单次赋值。Converting multiple assignments of the same variable in the main function into single assignments of multiple variables.
  5. 根据权利要求1-4任一项所述的方法,其特征在于,所述对所述处理后的中间码数据进行转换处理,包括:The method according to any one of claims 1 to 4, wherein the conversion processing on the processed intermediate code data comprises:
    基于约束生成算法对处理后的中间码数据进行转换处理,获得R1CS数据。Based on the constraint generation algorithm, the processed intermediate code data is converted to obtain R1CS data.
  6. 一种数据处理装置,其特征在于,所述装置包括:A data processing device, characterized in that the device includes:
    数据编译模块,用于基于LLVM编译器对待处理的密码协议算法源码数据进行编译,获得初始LLVM中间码数据;The data compilation module is used to compile the source code data of the cryptographic protocol algorithm to be processed based on the LLVM compiler to obtain the initial LLVM intermediate code data;
    单赋值处理模块,用于对所述初始LLVM中间码数据进行无跳转的静态单赋值处理,获得处理后的中间码数据;The single assignment processing module is used to perform static single assignment processing without jumping on the initial LLVM intermediate code data to obtain processed intermediate code data;
    数据转换模块,用于对所述处理后的中间码数据进行转换处理,获得R1CS数据。The data conversion module is used to perform conversion processing on the processed intermediate code data to obtain R1CS data.
  7. 根据权利要求6所述的装置,其特征在于,所述单赋值处理模块包括:The device according to claim 6, wherein the single assignment processing module comprises:
    单赋值处理单元,用于对所述初始LLVM中间码数据进行函数内联及静态单赋值处理,获得第一中间码数据;The single assignment processing unit is configured to perform function inlining and static single assignment processing on the initial LLVM intermediate code data to obtain the first intermediate code data;
    控制流消除单元,用于对所述第一中间码数据进行消除控制流处理,获得处理后的中间码数据。The control flow elimination unit is configured to perform control flow elimination processing on the first intermediate code data to obtain processed intermediate code data.
  8. 根据权利要求6所述的装置,其特征在于,所述转换模块包括:The device according to claim 6, wherein the conversion module comprises:
    转换单元,用于基于约束生成算法对处理后的中间码数据进行转换处理,获得R1CS数据。The conversion unit is used to convert the processed intermediate code data based on the constraint generation algorithm to obtain R1CS data.
  9. 一种数据处理设备,其特征在于,包括处理器及用于存储处理器可执行指令的存储器,所述指令被所述处理器执行时实现包括以下步骤:A data processing device is characterized in that it comprises a processor and a memory for storing executable instructions of the processor, and the implementation of the instructions when executed by the processor includes the following steps:
    基于LLVM编译器对待处理的密码协议算法源码数据进行编译,获得初始LLVM中间码数据;Compile the source code data of the cryptographic protocol algorithm to be processed based on the LLVM compiler to obtain the initial LLVM intermediate code data;
    对所述初始LLVM中间码数据进行无跳转的静态单赋值处理,获得处理后的中间码数据;Performing static single assignment processing without jump on the initial LLVM intermediate code data to obtain processed intermediate code data;
    对所述处理后的中间码数据进行转换处理,获得R1CS数据。Perform conversion processing on the processed intermediate code data to obtain R1CS data.
  10. 一种数据处理系统,其特征在于,所述数据编译系统包括至少一个处理器以及存储计算机可执行指令的存储器,所述处理器执行所述指令时实现所述权利要求1-5任一项所述方法的步骤。A data processing system, characterized in that the data compilation system includes at least one processor and a memory storing computer executable instructions, and when the processor executes the instructions, the instructions described in any of claims 1-5 The steps of the method.
PCT/CN2019/086594 2019-05-13 2019-05-13 Data processing method, device, and system WO2020227883A1 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
PCT/CN2019/086594 WO2020227883A1 (en) 2019-05-13 2019-05-13 Data processing method, device, and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2019/086594 WO2020227883A1 (en) 2019-05-13 2019-05-13 Data processing method, device, and system

Publications (1)

Publication Number Publication Date
WO2020227883A1 true WO2020227883A1 (en) 2020-11-19

Family

ID=73289737

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/086594 WO2020227883A1 (en) 2019-05-13 2019-05-13 Data processing method, device, and system

Country Status (1)

Country Link
WO (1) WO2020227883A1 (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8789032B1 (en) * 2009-02-27 2014-07-22 Google Inc. Feedback-directed inter-procedural optimization
CN106354630A (en) * 2016-08-23 2017-01-25 电子科技大学 Software defect detecting method based on dynamic symbolic execution
CN108804332A (en) * 2018-06-14 2018-11-13 南京大学 A kind of c program memory overflow intellectualized detection method based on machine learning
CN109471732A (en) * 2018-11-22 2019-03-15 山东大学 A kind of data distributing method towards CPU-FPGA heterogeneous multi-core system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8789032B1 (en) * 2009-02-27 2014-07-22 Google Inc. Feedback-directed inter-procedural optimization
CN106354630A (en) * 2016-08-23 2017-01-25 电子科技大学 Software defect detecting method based on dynamic symbolic execution
CN108804332A (en) * 2018-06-14 2018-11-13 南京大学 A kind of c program memory overflow intellectualized detection method based on machine learning
CN109471732A (en) * 2018-11-22 2019-03-15 山东大学 A kind of data distributing method towards CPU-FPGA heterogeneous multi-core system

Similar Documents

Publication Publication Date Title
US11106437B2 (en) Lookup table optimization for programming languages that target synchronous digital circuits
Itoko et al. Quantum circuit compilers using gate commutation rules
EP3912074B1 (en) Generating a synchronous digital circuit from a source code construct defining a function call
CN103838626A (en) Data processing device and method for processing serial tasks
CN113302616A (en) Generating synchronous digital circuits from source code constructs mapped to circuit implementations
JP2021517301A (en) Stochastic rounding logic
CN112200713A (en) Business data processing method, device and equipment in federated learning
CN109086126B (en) Task scheduling processing method and device, server, client and electronic equipment
CN112199416A (en) Data rule generation method and device
US20160139901A1 (en) Systems, methods, and computer programs for performing runtime auto parallelization of application code
CN112463159A (en) Compiling method, compiling device, electronic equipment and storage medium
CN110333867B (en) Multiparty secure computing data processing method, device and system
CN110209397B (en) Data processing method, device and system
WO2020227883A1 (en) Data processing method, device, and system
Falk et al. A rule-based static dataflow clustering algorithm for efficient embedded software synthesis
EP3906470B1 (en) Techniques for scheduling instructions in compiling source code
WO2020211074A1 (en) Multi-party secure computing data processing method, apparatus and system
JP6897213B2 (en) Code generator, code generator and code generator
CN113760380A (en) Method, device, equipment and storage medium for determining running code of network model
Ingole et al. Instruction set design for elementary set in tensilica xtensa
Li et al. Transformer-Lite: High-efficiency Deployment of Large Language Models on Mobile Phone GPUs
CN115469931B (en) Instruction optimization method, device, system, equipment and medium of loop program
CN117075912B (en) Method for program language conversion, compiling method and related equipment
CN115951936B (en) Chip adaptation method, device, equipment and medium of vectorization compiler
CN108170957B (en) Method and system for generating data control flow diagram and integrated circuit design method

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19928473

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19928473

Country of ref document: EP

Kind code of ref document: A1