WO2021017735A1 - Smart contract formal verification method, electronic apparatus and storage medium - Google Patents

Smart contract formal verification method, electronic apparatus and storage medium Download PDF

Info

Publication number
WO2021017735A1
WO2021017735A1 PCT/CN2020/099478 CN2020099478W WO2021017735A1 WO 2021017735 A1 WO2021017735 A1 WO 2021017735A1 CN 2020099478 W CN2020099478 W CN 2020099478W WO 2021017735 A1 WO2021017735 A1 WO 2021017735A1
Authority
WO
WIPO (PCT)
Prior art keywords
formal verification
smart contract
information
target file
syntax tree
Prior art date
Application number
PCT/CN2020/099478
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 平安科技(深圳)有限公司
Publication of WO2021017735A1 publication Critical patent/WO2021017735A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3604Software analysis for verifying properties of programs
    • G06F11/3608Software analysis for verifying properties of programs using formal methods, e.g. model checking, abstract interpretation
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02PCLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
    • Y02P90/00Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
    • Y02P90/30Computing systems specially adapted for manufacturing

Definitions

  • This application relates to the field of blockchain technology, and in particular to a formal verification method, electronic device and storage medium of a smart contract.
  • the related technology is to directly extract formal verification rule statements from the assembly code of the smart contract, and then perform formal verification based on these rule statements.
  • the source code when the smart contract is converted from source code to assembly code, the source code will be optimized and adjusted, so some logic in the source code, such as the information of the inherited parent class, will be missing.
  • the inventor realizes that the formal verification of smart contracts based on assembly code may cause problems such as missing information and low verification accuracy, which will adversely affect the security of smart contracts.
  • the embodiments of the present application provide a formal verification method, an electronic device, and a storage medium for a smart contract, which help to improve the accuracy of the formal verification of the smart contract and help ensure the security of the smart contract.
  • the first aspect of the embodiments of the present application provides a formal verification method of a smart contract.
  • the formal verification method of the smart contract includes:
  • a second aspect of the embodiments of the present application provides an electronic device, which includes:
  • the compilation module is used to obtain the source code of the smart contract to be verified, compile the source code of the smart contract into an abstract syntax tree, and disassemble the source code of the smart contract to obtain the assembly containing the smart contract
  • the object file of the code
  • a conversion module for converting the information in the abstract syntax tree to the target file
  • the generation module is used to obtain the formal verification method corresponding to the smart contract, and generate a form suitable for the formal verification method based on the assembly code in the target file and the information of the abstract syntax tree in the target file Validation rule statement;
  • the verification module is used to perform formal verification of the smart contract according to the generated rule statement.
  • a third aspect of the embodiments of the present application provides an electronic device, the electronic device includes a memory and a processor, and the processor and the memory are connected to each other, wherein the memory is used to store a computer program, and the computer program Comprising program instructions, the processor is used to execute the program instructions of the memory, wherein:
  • a fourth aspect of the embodiments of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program includes program instructions.
  • the program instructions When executed by a processor, they are used to implement the following step:
  • the embodiment of the application discloses a formal verification method, an electronic device and a storage medium of a smart contract, which can obtain the source code of the smart contract to be verified, compile the source code of the smart contract into an abstract syntax tree, and perform the verification of the smart contract.
  • the variable names, method names, and logical relationships in the smart contract are as inherited The information of the parent class, etc., will be reflected in the abstract syntax tree, so the information of the abstract syntax tree in the target file can make up for the shortcomings of the assembly code of the smart contract to a certain extent.
  • the formal verification rule statement In the case of missing information in some assembly codes, the missing information can be obtained from the information in the language abstract syntax tree, which is conducive to improving the accuracy of the formal verification of the smart contract and ensuring the security of the smart contract.
  • FIG. 1 is a schematic diagram of the hardware structure of an electronic device provided by this application.
  • FIG. 2 is a schematic flow chart of the method for formal verification of smart contracts provided by the first embodiment of this application;
  • FIG. 3 is a schematic diagram of the information of the abstract syntax tree after the information of the abstract syntax tree is transformed into the target file in the first embodiment of the application;
  • FIG. 4 is a schematic structural diagram of an electronic device provided by a second embodiment of this application.
  • FIG. 5 is a schematic structural diagram of an electronic device provided by the third embodiment of this application.
  • Fig. 1 shows a structural block diagram of an electronic device.
  • the method for formal verification of smart contracts provided by the embodiments of the present application can be applied to the electronic device 10 shown in FIG. 1.
  • the electronic device 10 includes but is not limited to: mobile terminals such as smart phones, notebooks, and wearable smart devices, as well as fixed Terminals such as desktop computers and smart TVs, etc.
  • the electronic device 10 includes a memory 101, a storage controller 102, one or more (only one is shown in the figure) processor 103, a peripheral interface 104 and a touch screen 105. These components communicate with each other through one or more communication buses/signal lines 106.
  • FIG. 1 is only for illustration, and it does not limit the structure of the electronic device.
  • the electronic device 10 may also include more or fewer components than shown in FIG. 1 or have a different configuration from that shown in FIG. 1.
  • the components shown in Figure 1 can be implemented by hardware, software or a combination thereof.
  • the memory 101 can be used to store software programs and modules, such as the formal verification method of a smart contract and program instructions/modules corresponding to the electronic device in the embodiment of the present application.
  • the processor 103 runs the software programs and modules stored in the memory 101, In order to perform various functional applications and data processing, for example, to implement the above-mentioned formal verification method for smart contracts.
  • the memory 101 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 101 may further include a memory remotely provided with respect to the processor 103, and these remote memories may be connected to the electronic device 10 via 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 processor 103 and other possible components may access the memory 101 under the control of the memory controller 102.
  • the peripheral interface 104 couples various input/input devices to the CPU and the memory 101.
  • the processor 103 runs various software and instructions in the memory 101 to perform various functions of the electronic device 10 and perform data processing.
  • peripheral interface 104, the processor 103, and the storage controller 102 may be implemented in a single chip. In some other instances, they can be implemented by independent chips.
  • the touch screen 105 simultaneously provides an output and input interface between the electronic device and the user.
  • the touch screen 105 displays video output to the user, and the content of the video output may include text, graphics, video, and any combination thereof.
  • Some output results of the touch screen 105 correspond to some user interface objects.
  • the touch screen 105 also receives input from the user, such as gesture operations such as clicking and sliding of the user, so that the user interface objects can respond to these user inputs.
  • the technology for detecting user input may be based on resistive, capacitive or any other possible touch detection technology.
  • Specific examples of the display unit of the touch screen 105 include, but are not limited to, a liquid crystal display or a light-emitting polymer display.
  • the embodiment of the application proposes a formal verification method for smart contracts, which can improve the quality of formal verification rule statements, and improve the accuracy of formal verification and the security of smart contracts.
  • the formal verification method of the smart contract of this embodiment includes the following steps:
  • Step 201 Obtain the source code of the smart contract to be verified, compile the source code of the smart contract into an abstract syntax tree, and disassemble the source code of the smart contract to obtain a target file containing the assembly code of the smart contract;
  • the abstract syntax tree in this embodiment is a tree representation of the abstract syntax structure of the source code of the smart contract.
  • the abstract syntax tree exists in the form of nodes and is nested layer by layer.
  • compiling the source code of the smart contract into an abstract syntax tree includes: using a preset syntax analyzer to extract keywords or identifiers from the source code of the smart contract, and use each keyword or identifier as a smart contract A node in the abstract syntax tree; according to the position and order of the extracted keywords or identifiers, the hierarchical relationship of the nodes corresponding to the keywords or identifiers is divided, and all the nodes and the relationships between the nodes form the smart contract Abstract syntax tree.
  • the keywords or identifiers after extracting the keywords or identifiers from the source code, it also includes: dividing the keywords or identifiers into different node types.
  • the node types in this embodiment include but are not limited to contract (contract object), function (method object), param, value, return, and other node types.
  • the hierarchical relationship of the nodes corresponding to the keywords or identifiers is divided according to the position and order in which the extracted keywords or identifiers appear. It can be understood that the extracted keywords or identifiers are in the source code of the smart contract. The position and order of appearance, the hierarchical relationship of the nodes corresponding to the keywords or identifiers.
  • the attributes and types of each node of the abstract syntax tree, as well as the relationship between the nodes and the source code information corresponding to the nodes, can be analyzed through the abstract syntax tree get.
  • the target file may be an xSol file.
  • Step 202 Convert the information in the abstract syntax tree to the target file
  • the process of converting the information in the abstract syntax tree to the target file can be understood as a process of copying the value of the abstract syntax tree by the target file.
  • the target file is an xSol file
  • the process of converting the information in the abstract syntax tree to the target file is the process of copying the value of the abstract syntax tree by the xSol object.
  • converting the information in the abstract syntax tree to the target file includes the following steps a and b:
  • Step a Analyze the node type of each node in the abstract syntax tree
  • Step b Copy the information of the nodes in the abstract syntax tree to the target file according to the node type, where in the target file obtained after copying, the information of the nodes of the same type in the abstract syntax tree is located under the corresponding name of the same node type .
  • each node when analyzing the node type of each node of the abstract syntax tree, each node can also be divided according to the node type first. For example, divide nodes of contract type together, divide nodes of function type together, divide nodes of node type together, and so on.
  • FIG. 3 shows the result of converting an abstract syntax tree to an xsol file when the target file is an xsol file.
  • the node type name of the contract object is the contract object in the abstract syntax tree
  • the function object is the function object in the abstract syntax tree
  • the node type name is the node object.
  • Listed below are the node objects in the abstract syntax tree.
  • node types in FIG. 3 are only for illustration, and the number and names of the node types are not limited. In practice, other node types can also exist in the abstract syntax tree.
  • the target file contains not only the assembly code of the smart contract, but also the node information in the abstract syntax tree of the smart contract.
  • the abstract syntax tree contains more information about inherited objects/interfaces than the assembly code.
  • the information of inherited objects/interfaces is more comprehensive, which helps to extract more comprehensive formal verification rules, helps to improve the verification accuracy of the formal verification rules of smart contracts, discovers more vulnerabilities in smart contracts, and improves the security of smart contracts .
  • Step 203 Obtain a formal verification method corresponding to the smart contract, and generate formal verification rule statements suitable for the formal verification method based on the assembly code in the target file and the information of the abstract syntax tree in the target file;
  • Step 204 Perform formal verification of the smart contract according to the generated rule statement.
  • generating a formal verification rule statement suitable for the formal verification method includes steps c-e:
  • Step c Obtain the security requirements of the smart contract, and based on the security requirements and the formal verification method, determine the formal verification rule statements suitable for the formal verification method to be generated;
  • Step d Extract the information needed to generate formal verification rule statements from the information of the abstract syntax tree in the target file and the assembly code;
  • Step e Based on all the extracted information and the formal verification method, a formal verification rule statement suitable for the formal verification method is generated.
  • the formal verification method can be selected according to actual needs, for example, the formal verification method of z3 is selected.
  • the formal verification method of z3 is selected.
  • a formal verification rule statement is generated based on the information in the target file, a form that conforms to z3 is generated The rule statement of the verification framework.
  • the security requirements input by the user can be obtained in real time through some input device such as a microphone or a touch screen, and converted into a smart contract security requirement specification document described in non-natural language.
  • the formal verification rule statements that need to be generated suitable for the formal verification method include: based on the smart contract security requirements specification document and the formal verification method, determine the appropriate form that needs to be generated Formal verification rule statement of the verification method.
  • a locally pre-stored smart contract security requirement specification file can be used.
  • the security requirements specification file of the smart contract in this embodiment may contain descriptions of common security vulnerabilities of smart contracts, in the process of determining the formal verification rule statements suitable for formal verification methods that need to be generated According to the descriptions of these security vulnerabilities, it can be determined that these security vulnerabilities need to be generated and suitable for the formal verification method.
  • extracting the information needed to generate formal verification rule statements from the information of the abstract syntax tree in the target file and the assembly code includes steps f and g:
  • Step f Extract the information for generating formal verification rule statements from the assembly code in the target file
  • Step g If the extracted information is not enough to generate formal verification rule statements, extract the required information from the information of the abstract syntax tree in the target file.
  • extracting information needed to generate formal verification rule statements from the information of the abstract syntax tree in the target file and the assembly code includes steps h and i:
  • Step h Extract the contract object (contract) information needed to generate the formal verification rule statement from the information of the abstract syntax tree in the target file;
  • Step i Extracting from the assembly code in the target file, except for contract information, generate information required for formal verification rule statements.
  • BitVec variable A, 256
  • IF logical judgments
  • formalization can be generated
  • the validation rule statement is simplify(And(p,q,True)).
  • formal verification there are multiple purposes of formal verification in this embodiment, such as detecting ERC20 tokens and detecting fake recharge vulnerabilities, etc.
  • the purpose of formal verification is different, and the rules and sentences called are also different.
  • the advantage of formal verification based on xSol is that there is no need to extract the source code (such as using keywords or regulars), and the location of functions and calling methods can be directly used based on the content of the copied abstract syntax tree .
  • the source code of the smart contract is compiled into assembly code in related technologies, the code will be optimized, and some method names and variable names will be deleted and converted. This processing will bring about variable tracking and analysis.
  • this application can directly use the extractor call trace based on the content of the copied abstract syntax tree to determine whether the variable can be used, and xSol can also directly extract the source code of the node that needs to be used for specific analysis (for example, use the current node as For loop, get the source code of the code block involved directly through the source attribute).
  • the embodiment of the application discloses a formal verification method of a smart contract, which can obtain the source code of the smart contract to be verified, compile the source code of the smart contract into an abstract syntax tree, and disassemble the source code of the smart contract, Obtain the target file containing the assembly code of the smart contract, and convert the information in the abstract syntax tree to the target file; obtain the formal verification method corresponding to the smart contract, based on the assembly code in the target file and the abstract syntax tree in the target file Information, generate formal verification rule statements suitable for formal verification methods.
  • the variable names, method names, and logical relationships in the smart contract such as the information of the inherited parent class, etc.
  • the information of the abstract syntax tree in the target file can make up for the defects of the assembly code of the smart contract to a certain extent.
  • the generated formal verification rule statement some information in the assembly code In the case of missing, the missing information can be obtained from the information of the language abstract syntax tree, the rule statements can be extracted more comprehensively, and the defects caused by optimization after the compilation of different versions of the source code can be reduced, which is conducive to improving the formalization of smart contracts The accuracy of verification and the security of smart contracts are guaranteed.
  • the second embodiment of the present application provides an electronic device.
  • the electronic device includes:
  • the compilation module 401 is used to obtain the source code of the smart contract to be verified, compile the source code of the smart contract into an abstract syntax tree, and disassemble the source code of the smart contract to obtain a target file containing the assembly code of the smart contract;
  • the conversion module 402 is used to convert the information in the abstract syntax tree to the target file
  • the generation module 403 is used to obtain the formal verification method corresponding to the smart contract, and generate formal verification rule statements suitable for the formal verification method based on the assembly code in the target file and the information of the abstract syntax tree in the target file;
  • the verification module 404 is used to perform formal verification of the smart contract according to the generated rule statement.
  • the compiling module 401 is used to extract keywords or identifiers from the source code of the smart contract using a preset syntax analyzer, and use each keyword or identifier as one of the abstract syntax trees of the smart contract Node: According to the location and order of the extracted keywords or identifiers, the hierarchical relationship of the nodes corresponding to the keywords or identifiers is divided, and the abstract syntax tree of the smart contract is formed by all the nodes and the relationships between the nodes.
  • the conversion module 402 is specifically used to analyze the node type of each node in the abstract syntax tree; according to the node type, the information of the nodes in the abstract syntax tree is copied to the target file, wherein, in the target file obtained after copying , The information of the node of the same type in the abstract syntax tree is located under the corresponding name of the same node type.
  • the generation module 403 is used to obtain the security requirements of the smart contract, and based on the security requirements and the formal verification method, determine the formal verification rule statements suitable for the formal verification method to be generated; from the abstract grammar in the target file From the tree information and assembly code, the information needed to generate formal verification rule statements is extracted; based on all the extracted information and the formal verification method, a formal verification rule statement suitable for the formal verification method is generated.
  • the generation module 403 is specifically used to extract information for generating formal verification rule statements from the assembly code in the target file; if the extracted information is not enough to generate formal verification rule statements, abstract from the target file The method of extracting the required information from the information of the syntax tree, and extracting the information needed to generate the formal verification rule statement.
  • the generating module 403 is specifically used to extract the contract object information needed to generate formal verification rule statements from the information of the abstract syntax tree in the target file; extract the contract object information from the assembly code in the target file
  • the method of generating the information required for the formal verification rule statement is to extract the information required for generating the formal verification rule statement.
  • the embodiment of the application discloses an electronic device, which can extract rule statements more comprehensively based on the information of the abstract syntax tree in the target file, reduce the defects caused by optimization after the compilation of different versions of the source code, and is beneficial to improve the smart contract The accuracy of formal verification and the security of smart contracts are guaranteed.
  • FIG. 5 is an electronic device provided by a third embodiment of this application.
  • the electronic device can be used to implement the formal verification method of the smart contract in the embodiment shown in FIG. 2.
  • the electronic device mainly includes:
  • the processor 502 executes the computer program, it implements the formal verification method of the smart contract in the embodiment shown in FIG. 2.
  • the number of processors may be one or more, which is not limited in this embodiment.
  • the memory 501 may be a high-speed random access memory (RAM, Random Access Memory) memory, or a non-volatile memory (non-volatile memory), such as a magnetic disk memory.
  • RAM Random Access Memory
  • non-volatile memory non-volatile memory
  • the memory 501 is used to store executable program elements, and the processor 502 is coupled with the memory 501.
  • an embodiment of the present application also provides a storage medium, which may be the electronic device provided in the foregoing embodiments, and the storage medium may be the memory in the embodiment shown in FIG. 5.
  • the computer-readable storage medium may be non-volatile or volatile.
  • a computer program is stored on the storage medium, and when the program is executed by the processor, the formal verification method of the smart contract in the embodiment shown in FIG. 2 is realized.
  • the computer storage medium may also be a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a RAM, a magnetic disk, or an optical disk and other various media that can store program elements.
  • the electronic device of this embodiment based on the coding process of the assembly code of the software to be detected, the coding characteristics of the detection software can be obtained, making it easier for the deep neural network to find the commonalities between malware, and improving the application’s ability to identify various types of malicious software.
  • the universality of software, the use of deep neural networks to determine whether the software to be detected is malicious software can further ensure effective identification of malicious software.
  • the disclosed device and method may be implemented in other ways.
  • the device embodiments described above are merely illustrative, for example, the division of modules is only a logical function division, and there may be other divisions in actual implementation, for example, multiple modules 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 modules, and may be in electrical, mechanical or other forms.
  • the modules described as separate components may or may not be physically separate, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the objectives of the solutions of the embodiments.
  • each functional module in each embodiment of the present application may be integrated into one processing module, or each module may exist alone physically, or two or more modules may be integrated into one module.
  • the above-mentioned integrated modules can be implemented in the form of hardware or software functional modules.
  • the integrated module is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer readable storage medium.
  • the medium includes a number of instructions to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods in the various embodiments of the present application.
  • the aforementioned readable storage medium includes: U disk, mobile hard disk, ROM, RAM, magnetic disk or optical disk and other media that can store program elements.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

A smart contract formal verification method, an electronic apparatus and a storage medium, capable of compiling source code of a smart contract into an abstract syntax tree and performing disassembly of the smart contract source code, obtaining a target file containing assembly code of the smart contract (201), then converting information in the abstract syntax tree into the target file (202); on the basis of the assembly code and abstract syntax tree information in the target file, generating a formal verification rule statement adapted for a smart contract formal verification method (203), the abstract syntax tree information in the target file being capable of making up for deficiencies in the smart contract assembly code to a certain extent, making extraction of a formal verification rule statement more complete, and helping to improve formal verification accuracy and smart contract security.

Description

一种智能合约的形式化验证方法、电子装置及存储介质Formal verification method, electronic device and storage medium of smart contract
本申请要求于2019年07月31日提交中国专利局、申请号为201910699357.6,发明名称为“一种智能合约的形式化验证方法、电子装置及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of a Chinese patent application filed with the Chinese Patent Office on July 31, 2019, the application number is 201910699357.6, and the invention title is "a method for formal verification of smart contracts, electronic devices and storage media", all of which The content is incorporated in this application by reference.
技术领域Technical field
本申请涉及区块链技术领域,尤其涉及一种智能合约的形式化验证方法、电子装置及存储介质。This application relates to the field of blockchain technology, and in particular to a formal verification method, electronic device and storage medium of a smart contract.
背景技术Background technique
对于智能合约的检测,相关技术中是从智能合约的汇编代码中直接提取形式化验证的规则语句,然后基于这些规则语句进行形式化验证。For smart contract detection, the related technology is to directly extract formal verification rule statements from the assembly code of the smart contract, and then perform formal verification based on these rule statements.
但是智能合约从源代码转换为汇编代码时,对于源代码会进行优化和调整,所以对于源代码中的部分逻辑如继承的父类的信息等会有缺失。发明人意识到,基于汇编代码对智能合约进行形式化验证,可能会出现信息缺失,验证准确度低的问题,对智能合约的安全性保障有不利影响。However, when the smart contract is converted from source code to assembly code, the source code will be optimized and adjusted, so some logic in the source code, such as the information of the inherited parent class, will be missing. The inventor realizes that the formal verification of smart contracts based on assembly code may cause problems such as missing information and low verification accuracy, which will adversely affect the security of smart contracts.
发明内容Summary of the invention
本申请实施例提供一种智能合约的形式化验证方法、电子装置及存储介质,有利于提升智能合约的形式化验证的准确度,有利于保证智能合约的安全性。The embodiments of the present application provide a formal verification method, an electronic device, and a storage medium for a smart contract, which help to improve the accuracy of the formal verification of the smart contract and help ensure the security of the smart contract.
本申请实施例第一方面提供一种智能合约的形式化验证方法,该智能合约的形式化验证方法包括:The first aspect of the embodiments of the present application provides a formal verification method of a smart contract. The formal verification method of the smart contract includes:
获取待验证的智能合约的源代码,将所述智能合约的源代码编译成抽象语法树,以及对所述智能合约的源代码进行反汇编,得到包含所述智能合约的汇编代码的目标文件;Obtaining the source code of the smart contract to be verified, compiling the source code of the smart contract into an abstract syntax tree, and disassembling the source code of the smart contract to obtain a target file containing the assembly code of the smart contract;
将所述抽象语法树中的信息转换至所述目标文件中;Converting the information in the abstract syntax tree to the target file;
获取所述智能合约对应的形式化验证方法,基于所述目标文件中的汇编代码以及所述目标文件中的抽象语法树的信息,生成适于所述形式化验证方法的形式化验证规则语句;Acquiring a formal verification method corresponding to the smart contract, and generating formal verification rule statements suitable for the formal verification method based on the assembly code in the target file and the information of the abstract syntax tree in the target file;
根据生成的所述规则语句,进行所述智能合约的形式化验证。Perform formal verification of the smart contract according to the generated rule statement.
本申请实施例第二方面提供一种电子装置,该电子装置包括:A second aspect of the embodiments of the present application provides an electronic device, which includes:
编译模块,用于获取待验证的智能合约的源代码,将所述智能合约的源代码编译成抽象语法树,以及对所述智能合约的源代码进行反汇编,得到包含所述智能合约的汇编代码的目标文件;The compilation module is used to obtain the source code of the smart contract to be verified, compile the source code of the smart contract into an abstract syntax tree, and disassemble the source code of the smart contract to obtain the assembly containing the smart contract The object file of the code;
转换模块,用于将所述抽象语法树中的信息转换至所述目标文件中;A conversion module for converting the information in the abstract syntax tree to the target file;
生成模块,用于获取所述智能合约对应的形式化验证方法,基于所述目标文件中的汇编代码以及所述目标文件中的抽象语法树的信息,生成适于所述形式化验证方法的形式化验证规则语句;The generation module is used to obtain the formal verification method corresponding to the smart contract, and generate a form suitable for the formal verification method based on the assembly code in the target file and the information of the abstract syntax tree in the target file Validation rule statement;
验证模块,用于根据生成的所述规则语句,进行所述智能合约的形式化验证。The verification module is used to perform formal verification of the smart contract according to the generated rule statement.
本申请实施例第三方面提供一种电子装置,所述电子装置包括存储器和处理器,所述处理器、和所述存储器相互连接,其中,所述存储器用于存储计算机程序,所述计算机程序包括程序指令,所述处理器用于执行所述存储器的所述程序指令,其中:A third aspect of the embodiments of the present application provides an electronic device, the electronic device includes a memory and a processor, and the processor and the memory are connected to each other, wherein the memory is used to store a computer program, and the computer program Comprising program instructions, the processor is used to execute the program instructions of the memory, wherein:
获取待验证的智能合约的源代码,将所述智能合约的源代码编译成抽象语法树,以及对所述智能合约的源代码进行反汇编,得到包含所述智能合约的汇编代码的目标文件;Obtaining the source code of the smart contract to be verified, compiling the source code of the smart contract into an abstract syntax tree, and disassembling the source code of the smart contract to obtain a target file containing the assembly code of the smart contract;
将所述抽象语法树中的信息转换至所述目标文件中;Converting the information in the abstract syntax tree to the target file;
获取所述智能合约对应的形式化验证方法,基于所述目标文件中的汇编代码以及所述目标文件中的抽象语法树的信息,生成适于所述形式化验证方法的形式化验证规则语句;Acquiring a formal verification method corresponding to the smart contract, and generating formal verification rule statements suitable for the formal verification method based on the assembly code in the target file and the information of the abstract syntax tree in the target file;
根据生成的所述规则语句,进行所述智能合约的形式化验证。Perform formal verification of the smart contract according to the generated rule statement.
本申请实施例第四方面提供计算机可读存储介质,其中,所述计算机可读存储介质存储有计算机程序,所述计算机程序包括程序指令,所述程序指令被处理器执行时,用于实现以下步骤:A fourth aspect of the embodiments of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program includes program instructions. When the program instructions are executed by a processor, they are used to implement the following step:
获取待验证的智能合约的源代码,将所述智能合约的源代码编译成抽象语法树,以及对所述智能合约的源代码进行反汇编,得到包含所述智能合约的汇编代码的目标文件;Obtaining the source code of the smart contract to be verified, compiling the source code of the smart contract into an abstract syntax tree, and disassembling the source code of the smart contract to obtain a target file containing the assembly code of the smart contract;
将所述抽象语法树中的信息转换至所述目标文件中;Converting the information in the abstract syntax tree to the target file;
获取所述智能合约对应的形式化验证方法,基于所述目标文件中的汇编代码以及所述目标文件中的抽象语法树的信息,生成适于所述形式化验证方法的形式化验证规则语句;Acquiring a formal verification method corresponding to the smart contract, and generating formal verification rule statements suitable for the formal verification method based on the assembly code in the target file and the information of the abstract syntax tree in the target file;
根据生成的所述规则语句,进行所述智能合约的形式化验证。Perform formal verification of the smart contract according to the generated rule statement.
本申请实施例公开了一种智能合约的形式化验证方法、电子装置和存储介质,可以获取待验证的智能合约的源代码,将智能合约的源代码编译成抽象语法树,以及对智能合约的源代码进行反汇编,得到包含智能合约的汇编代码的目标文件,将抽象语法树中的信息转换至目标文件中;获取智能合约对应的形式化验证方法,基于目标文件中的汇编代码以及目标文件中的抽象语法树的信息,生成适于形式化验证方法的形式化验证规则语句,上述方案中,在生成抽象语法树的过程中,智能合约中的变量名、方法名以及逻辑关系如继承的父类的信息等等,会体现在抽象语法树中,所以目标文件中的抽象语法树的信息,在一定程度上可以弥补智能合约的汇编代码的缺陷,在生成的形式化验证规则语句时,在一些汇编代码的信息缺失的情况下,可以从语抽象语法树的信息中获取缺失的信息,这有利于提升智能合约的形式化验证的准确度以及保证智能合约的安全性。The embodiment of the application discloses a formal verification method, an electronic device and a storage medium of a smart contract, which can obtain the source code of the smart contract to be verified, compile the source code of the smart contract into an abstract syntax tree, and perform the verification of the smart contract. Disassemble the source code to obtain the target file containing the assembly code of the smart contract, and convert the information in the abstract syntax tree to the target file; obtain the formal verification method corresponding to the smart contract, based on the assembly code and the target file in the target file In the above scheme, in the process of generating the abstract syntax tree, the variable names, method names, and logical relationships in the smart contract are as inherited The information of the parent class, etc., will be reflected in the abstract syntax tree, so the information of the abstract syntax tree in the target file can make up for the shortcomings of the assembly code of the smart contract to a certain extent. When generating the formal verification rule statement, In the case of missing information in some assembly codes, the missing information can be obtained from the information in the language abstract syntax tree, which is conducive to improving the accuracy of the formal verification of the smart contract and ensuring the security of the smart contract.
附图说明Description of the drawings
图1为本申请提供的一种电子装置的硬件结构示意图;FIG. 1 is a schematic diagram of the hardware structure of an electronic device provided by this application;
图2为本申请第一实施例提供的智能合约的形式化验证方法的流程示意图;2 is a schematic flow chart of the method for formal verification of smart contracts provided by the first embodiment of this application;
图3为本申请第一实施例中,将抽象语法树的信息转化至目标文件中后,抽象语法树的信息的示意图;3 is a schematic diagram of the information of the abstract syntax tree after the information of the abstract syntax tree is transformed into the target file in the first embodiment of the application;
图4为本申请第二实施例提供的一种电子装置的结构示意图;4 is a schematic structural diagram of an electronic device provided by a second embodiment of this application;
图5为本申请第三实施例提供的一种电子装置的结构示意图。FIG. 5 is a schematic structural diagram of an electronic device provided by the third embodiment of this application.
具体实施方式Detailed ways
为使得本申请的发明目的、特征、优点能够更加的明显和易懂,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而非全部实施例。基于本申请中的实施例,本领域技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。In order to make the purposes, features, and advantages of the present application more obvious and understandable, the technical solutions in the embodiments of the present application will be described clearly and completely in conjunction with the drawings in the embodiments of the present application. Obviously, the description The embodiments are only a part of the embodiments of the present application, but not all the embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative work shall fall within the protection scope of this application.
参照图1,图1示出了一种电子装置的结构框图。本申请实施例提供的智能合约的形式化验证方法可应用于如图1所示的电子装置10中,电子装置10包括但不限于:移动终端如智能手机、笔记本及穿戴智能设备等,以及固定终端如台式电脑及智能电视等等。Referring to Fig. 1, Fig. 1 shows a structural block diagram of an electronic device. The method for formal verification of smart contracts provided by the embodiments of the present application can be applied to the electronic device 10 shown in FIG. 1. The electronic device 10 includes but is not limited to: mobile terminals such as smart phones, notebooks, and wearable smart devices, as well as fixed Terminals such as desktop computers and smart TVs, etc.
如图1所示,电子装置10包括存储器101、存储控制器102,一个或多个(图中仅示出一个)处理器103、外设接口104及触控屏幕105。这些组件通过一条或多条通讯总线/信号线106相互通讯。As shown in FIG. 1, the electronic device 10 includes a memory 101, a storage controller 102, one or more (only one is shown in the figure) processor 103, a peripheral interface 104 and a touch screen 105. These components communicate with each other through one or more communication buses/signal lines 106.
可以理解,图1所示的结构仅为示意,其并不对电子装置的结构造成限定。电子装置10还可包括比图1所示更多或者更少的组件,或者具有与图1所示不同的配置。图1所示 的各组件可以采用硬件、软件或其组合实现。It can be understood that the structure shown in FIG. 1 is only for illustration, and it does not limit the structure of the electronic device. The electronic device 10 may also include more or fewer components than shown in FIG. 1 or have a different configuration from that shown in FIG. 1. The components shown in Figure 1 can be implemented by hardware, software or a combination thereof.
存储器101可用于存储软件程序以及模块,如本申请实施例中的智能合约的形式化验证方法及电子装置对应的程序指令/模块,处理器103通过运行存储在存储器101内的软件程序以及模块,从而执行各种功能应用以及数据处理,例如实现上述的智能合约的形式化验证方法。The memory 101 can be used to store software programs and modules, such as the formal verification method of a smart contract and program instructions/modules corresponding to the electronic device in the embodiment of the present application. The processor 103 runs the software programs and modules stored in the memory 101, In order to perform various functional applications and data processing, for example, to implement the above-mentioned formal verification method for smart contracts.
存储器101可包括高速随机存储器,还可包括非易失性存储器,如一个或者多个磁性存储装置、闪存、或者其他非易失性固态存储器。在一些实例中,存储器101可进一步包括相对于处理器103远程设置的存储器,这些远程存储器可以通过网络连接至电子装置10。上述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。处理器103以及其他可能的组件对存储器101的访问可在存储控制器102的控制下进行。The memory 101 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 101 may further include a memory remotely provided with respect to the processor 103, and these remote memories may be connected to the electronic device 10 via 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 processor 103 and other possible components may access the memory 101 under the control of the memory controller 102.
外设接口104将各种输入/输入装置耦合至CPU以及存储器101。处理器103运行存储器101内的各种软件、指令以执行电子装置10的各种功能以及进行数据处理。The peripheral interface 104 couples various input/input devices to the CPU and the memory 101. The processor 103 runs various software and instructions in the memory 101 to perform various functions of the electronic device 10 and perform data processing.
在一些实施例中,外设接口104,处理器103以及存储控制器102可以在单个芯片中实现。在其他一些实例中,他们可以分别由独立的芯片实现。In some embodiments, the peripheral interface 104, the processor 103, and the storage controller 102 may be implemented in a single chip. In some other instances, they can be implemented by independent chips.
触控屏幕105在电子装置与用户之间同时提供一个输出及输入界面。具体地,触控屏幕105向用户显示视频输出,这些视频输出的内容可包括文字、图形、视频、及其任意组合。触控屏幕105的一些输出结果是对应于一些用户界面对象。触控屏幕105还接收用户的输入,例如用户的点击、滑动等手势操作,以便用户界面对象对这些用户的输入做出响应。检测用户输入的技术可以是基于电阻式、电容式或者其他任意可能的触控检测技术。触控屏幕105显示单元的具体实例包括但并不限于液晶显示器或发光聚合物显示器。The touch screen 105 simultaneously provides an output and input interface between the electronic device and the user. Specifically, the touch screen 105 displays video output to the user, and the content of the video output may include text, graphics, video, and any combination thereof. Some output results of the touch screen 105 correspond to some user interface objects. The touch screen 105 also receives input from the user, such as gesture operations such as clicking and sliding of the user, so that the user interface objects can respond to these user inputs. The technology for detecting user input may be based on resistive, capacitive or any other possible touch detection technology. Specific examples of the display unit of the touch screen 105 include, but are not limited to, a liquid crystal display or a light-emitting polymer display.
基于上述电子装置描述本申请实施例中的智能合约的形式化验证方法。The formal verification method of the smart contract in the embodiment of the present application is described based on the above electronic device.
第一实施例:The first embodiment:
本申请实施例提出了一种智能合约的形式化验证方法,可以提升形式化验证规则语句的质量,以及提升形式化验证的准确度和智能合约的安全性。The embodiment of the application proposes a formal verification method for smart contracts, which can improve the quality of formal verification rule statements, and improve the accuracy of formal verification and the security of smart contracts.
参见图2,本实施例的智能合约的形式化验证方法包括以下步骤:Referring to Fig. 2, the formal verification method of the smart contract of this embodiment includes the following steps:
步骤201、获取待验证的智能合约的源代码,将智能合约的源代码编译成抽象语法树,以及对智能合约的源代码进行反汇编,得到包含智能合约的汇编代码的目标文件;Step 201: Obtain the source code of the smart contract to be verified, compile the source code of the smart contract into an abstract syntax tree, and disassemble the source code of the smart contract to obtain a target file containing the assembly code of the smart contract;
本实施例中的抽象语法树是智能合约的源代码的抽象语法结构的树状表现形式,该抽象语法树是以节点形式存在且层层嵌套的。The abstract syntax tree in this embodiment is a tree representation of the abstract syntax structure of the source code of the smart contract. The abstract syntax tree exists in the form of nodes and is nested layer by layer.
可选的,将智能合约的源代码编译成抽象语法树包括:使用预设的语法分析器对智能合约的源代码做关键词或标识符的提取,将每一个关键词或标识符作为智能合约的抽象语法树中的一个节点;根据提取的关键词或标识符出现的位置和顺序,划分关键词或标识符对应的节点的层级关系,以所有的节点以及节点之间的关系形成智能合约的抽象语法树。Optionally, compiling the source code of the smart contract into an abstract syntax tree includes: using a preset syntax analyzer to extract keywords or identifiers from the source code of the smart contract, and use each keyword or identifier as a smart contract A node in the abstract syntax tree; according to the position and order of the extracted keywords or identifiers, the hierarchical relationship of the nodes corresponding to the keywords or identifiers is divided, and all the nodes and the relationships between the nodes form the smart contract Abstract syntax tree.
其中,在从源代码中提取关键词或标识符后,还包括:将关键词或标识符划分为不同的节点类型。本实施例中的节点类型包括但不限于contract(合约对象)、function(方法对象)、param、value以及return等节点类型。Among them, after extracting the keywords or identifiers from the source code, it also includes: dividing the keywords or identifiers into different node types. The node types in this embodiment include but are not limited to contract (contract object), function (method object), param, value, return, and other node types.
本实施例中,根据提取的关键词或标识符出现的位置和顺序,划分关键词或标识符对应的节点的层级关系,可以理解为根据提取的关键词或标识符在智能合约的源代码中出现的位置和顺序,划分关键词或标识符对应的节点的层级关系。In this embodiment, the hierarchical relationship of the nodes corresponding to the keywords or identifiers is divided according to the position and order in which the extracted keywords or identifiers appear. It can be understood that the extracted keywords or identifiers are in the source code of the smart contract. The position and order of appearance, the hierarchical relationship of the nodes corresponding to the keywords or identifiers.
本实施例中,在将源代码编译成抽象语法树后,对于抽象语法树的各个节点的属性和 类型,以及节点之间的关系和节点对应的源码信息等,可以通过对抽象语法树的分析得到。In this embodiment, after the source code is compiled into an abstract syntax tree, the attributes and types of each node of the abstract syntax tree, as well as the relationship between the nodes and the source code information corresponding to the nodes, can be analyzed through the abstract syntax tree get.
本实施例的一个示例中,目标文件可以是xSol文件。In an example of this embodiment, the target file may be an xSol file.
步骤202、将抽象语法树中的信息转换至目标文件中;Step 202: Convert the information in the abstract syntax tree to the target file;
本实施例中,将抽象语法树中的信息转换至目标文件中的过程,可以理解为目标文件对抽象语法树进行值拷贝的过程。例如,目标文件为xSol文件,将抽象语法树中的信息转换至目标文件中的过程,为xSol对象对抽象语法树进行值拷贝的过程。In this embodiment, the process of converting the information in the abstract syntax tree to the target file can be understood as a process of copying the value of the abstract syntax tree by the target file. For example, the target file is an xSol file, and the process of converting the information in the abstract syntax tree to the target file is the process of copying the value of the abstract syntax tree by the xSol object.
可选的,将抽象语法树中的信息转换至目标文件中包括以下的步骤a和b:Optionally, converting the information in the abstract syntax tree to the target file includes the following steps a and b:
步骤a、分析抽象语法树中各节点的节点类型;Step a: Analyze the node type of each node in the abstract syntax tree;
步骤b、根据节点类型将抽象语法树中的节点的信息拷贝至目标文件中,其中,在拷贝后得到的目标文件中,抽象语法树中相同类型的节点的信息位于对应的同一节点类型名称下。Step b: Copy the information of the nodes in the abstract syntax tree to the target file according to the node type, where in the target file obtained after copying, the information of the nodes of the same type in the abstract syntax tree is located under the corresponding name of the same node type .
其中,在分析抽象语法树的各节点的节点类型时,还可以将各个节点根据节点类型先进行划分。例如将contract类型的节点划分在一起,将function类型的节点划分在一起,以及将node类型的节点划分在一起等等。Among them, when analyzing the node type of each node of the abstract syntax tree, each node can also be divided according to the node type first. For example, divide nodes of contract type together, divide nodes of function type together, divide nodes of node type together, and so on.
例如,参见图3,图3示出了在目标文件为xsol文件时,对一个抽象语法树转换至xsol文件中得到的结果。在图3中,contract对象这一节点类型名称下列出的是抽象语法树中的contract对象,function对象这一节点类型名称下列出的是抽象语法树中的function对象,node对象这一节点类型名称下列出的是抽象语法树中的node对象。For example, see FIG. 3, which shows the result of converting an abstract syntax tree to an xsol file when the target file is an xsol file. In Figure 3, the node type name of the contract object is the contract object in the abstract syntax tree, the function object is the function object in the abstract syntax tree, and the node type name is the node object. Listed below are the node objects in the abstract syntax tree.
当然可以理解的是,图3中的节点类型仅作示例说明,并不限定节点类型的数量和名称。在实际中,抽象语法树中还可以存在其他节点类型。Of course, it can be understood that the node types in FIG. 3 are only for illustration, and the number and names of the node types are not limited. In practice, other node types can also exist in the abstract syntax tree.
本实施例中,基于上述的拷贝,目标文件中不仅包含智能合约的汇编代码,还包含智能合约的抽象语法树中的节点信息,抽象语法树包含的继承对象/接口的信息比汇编代码中的继承对象/接口的信息更全面,有助于提取更加全面的形式化验证规则,有利于提升智能合约的形式化验证规则的验证准确性,发现智能合约的更多漏洞,提升智能合约的安全性。In this embodiment, based on the above copy, the target file contains not only the assembly code of the smart contract, but also the node information in the abstract syntax tree of the smart contract. The abstract syntax tree contains more information about inherited objects/interfaces than the assembly code. The information of inherited objects/interfaces is more comprehensive, which helps to extract more comprehensive formal verification rules, helps to improve the verification accuracy of the formal verification rules of smart contracts, discovers more vulnerabilities in smart contracts, and improves the security of smart contracts .
步骤203、获取智能合约对应的形式化验证方法,基于目标文件中的汇编代码以及目标文件中的抽象语法树的信息,生成适于形式化验证方法的形式化验证规则语句;Step 203: Obtain a formal verification method corresponding to the smart contract, and generate formal verification rule statements suitable for the formal verification method based on the assembly code in the target file and the information of the abstract syntax tree in the target file;
步骤204、根据生成的规则语句,进行智能合约的形式化验证。Step 204: Perform formal verification of the smart contract according to the generated rule statement.
本实施例中,基于目标文件中的汇编代码以及目标文件中的抽象语法树的信息,生成适于形式化验证方法的形式化验证规则语句包括步骤c-e:In this embodiment, based on the assembly code in the target file and the information of the abstract syntax tree in the target file, generating a formal verification rule statement suitable for the formal verification method includes steps c-e:
步骤c、获取智能合约的安全需求,基于安全需求以及形式化验证方法,确定需要生成的适于形式化验证方法的形式化验证规则语句;Step c. Obtain the security requirements of the smart contract, and based on the security requirements and the formal verification method, determine the formal verification rule statements suitable for the formal verification method to be generated;
步骤d、从目标文件中的抽象语法树的信息以及汇编代码中,提取生成形式化验证规则语句需要的信息;Step d. Extract the information needed to generate formal verification rule statements from the information of the abstract syntax tree in the target file and the assembly code;
步骤e、基于提取的所有信息和形式化验证方法,生成适于形式化验证方法的形式化验证规则语句。Step e: Based on all the extracted information and the formal verification method, a formal verification rule statement suitable for the formal verification method is generated.
可选的,对于本实施例而言,可以根据实际需要选择形式化验证方法,例如选择z3的形式化验证方法,在根据目标文件中的信息,生成形式化验证规则语句时,生成符合z3形式化验证框架的规则语句。Optionally, for this embodiment, the formal verification method can be selected according to actual needs, for example, the formal verification method of z3 is selected. When a formal verification rule statement is generated based on the information in the target file, a form that conforms to z3 is generated The rule statement of the verification framework.
在一个示例中,可以通过某种输入装置如麦克风或者触控屏等,实时获取用户输入的安全需求,将其转换为采用非自然语言描述的智能合约安全需求规范文件。对应地,基于安全需求以及形式化验证方法,确定需要生成的适于形式化验证方法的形式化验证规则语句包括:基于智能合约安全需求规范文件以及形式化验证方法,确定需要生成的适于形式化验证方法的形式化验证规则语句。In one example, the security requirements input by the user can be obtained in real time through some input device such as a microphone or a touch screen, and converted into a smart contract security requirement specification document described in non-natural language. Correspondingly, based on the security requirements and formal verification methods, the formal verification rule statements that need to be generated suitable for the formal verification method include: based on the smart contract security requirements specification document and the formal verification method, determine the appropriate form that needs to be generated Formal verification rule statement of the verification method.
在另一个示例中,可以获取本地预存的智能合约安全需求规范文件使用。In another example, a locally pre-stored smart contract security requirement specification file can be used.
可选的,本实施例的安全需求互殴智能合约安全需求规范文件中可以包含对于智能合约的常见安全漏洞的描述,在确定需要生成的适于形式化验证方法的形式化验证规则语句的过程中,可以根据这些安全漏洞的描述,确定检测这些安全漏洞需要生成的,适于形式化验证方法形式化验证规则语句。Optionally, the security requirements specification file of the smart contract in this embodiment may contain descriptions of common security vulnerabilities of smart contracts, in the process of determining the formal verification rule statements suitable for formal verification methods that need to be generated According to the descriptions of these security vulnerabilities, it can be determined that these security vulnerabilities need to be generated and suitable for the formal verification method.
可选的,一个示例中,从目标文件中的抽象语法树的信息以及汇编代码中,提取生成形式化验证规则语句需要的信息包括步骤f和g:Optionally, in an example, extracting the information needed to generate formal verification rule statements from the information of the abstract syntax tree in the target file and the assembly code includes steps f and g:
步骤f、从目标文件中的汇编代码中提取生成形式化验证规则语句的信息;Step f: Extract the information for generating formal verification rule statements from the assembly code in the target file;
步骤g、若提取的信息不足以生成形式化验证规则语句,则从目标文件中的抽象语法树的信息中提取需要的信息。Step g: If the extracted information is not enough to generate formal verification rule statements, extract the required information from the information of the abstract syntax tree in the target file.
可选的,在另一个示例中,从目标文件中的抽象语法树的信息以及汇编代码中,提取生成形式化验证规则语句需要的信息包括步骤h和i:Optionally, in another example, extracting information needed to generate formal verification rule statements from the information of the abstract syntax tree in the target file and the assembly code includes steps h and i:
步骤h、从目标文件中的抽象语法树的信息中提取生成形式化验证规则语句需要的合约对象(contract)信息;Step h: Extract the contract object (contract) information needed to generate the formal verification rule statement from the information of the abstract syntax tree in the target file;
步骤i、从目标文件中的汇编代码中提取除合约对象(contract)信息外,生成形式化验证规则语句需要的信息。Step i: Extracting from the assembly code in the target file, except for contract information, generate information required for formal verification rule statements.
例如:本实施例中,对于变量A的声明节点会根据变量的属性信息生成对应的数据结构:BitVec(变量A,256),对于逻辑判断的如IF(A==B),可以生成形式化验证规则语句为simplify(And(p,q,True))。For example: in this embodiment, the declaration node for variable A will generate the corresponding data structure according to the attribute information of the variable: BitVec (variable A, 256), for logical judgments such as IF (A==B), formalization can be generated The validation rule statement is simplify(And(p,q,True)).
可选的,本实施例中的形式化验证的目的有多种例如检测ERC20代币以及检测假充值漏洞等等,形式化验证的目的不同,调用的规则语句也有不同。Optionally, there are multiple purposes of formal verification in this embodiment, such as detecting ERC20 tokens and detecting fake recharge vulnerabilities, etc. The purpose of formal verification is different, and the rules and sentences called are also different.
本实施例中,基于xSol进行形式化验证的好处在于,不需要再对源代码进行提取(例如使用关键字或正则),可以基于拷贝的抽象语法树的内容直接使用对于函数及调用方法的定位。对于涉及到的变量,相关技术中将智能合约的源代码编译为汇编代码时,会对代码进行优化,会对一些方法名和变量名进行删除转换,这种处理会对变量的跟踪以及分析带来不便,本申请则可以基于拷贝的抽象语法树的内容直接使用提取器调用轨迹来判断变量是否可以用,并且xSol还可以对于需要使用的节点直接提取其源码进行特定的分析(例如利用当前节点为for循环,直接通过source属性获取到其涉及到的代码块源码)。In this embodiment, the advantage of formal verification based on xSol is that there is no need to extract the source code (such as using keywords or regulars), and the location of functions and calling methods can be directly used based on the content of the copied abstract syntax tree . For the variables involved, when the source code of the smart contract is compiled into assembly code in related technologies, the code will be optimized, and some method names and variable names will be deleted and converted. This processing will bring about variable tracking and analysis. Inconvenience, this application can directly use the extractor call trace based on the content of the copied abstract syntax tree to determine whether the variable can be used, and xSol can also directly extract the source code of the node that needs to be used for specific analysis (for example, use the current node as For loop, get the source code of the code block involved directly through the source attribute).
本申请实施例公开了一种智能合约的形式化验证方法,可以获取待验证的智能合约的源代码,将智能合约的源代码编译成抽象语法树,以及对智能合约的源代码进行反汇编,得到包含智能合约的汇编代码的目标文件,将抽象语法树中的信息转换至目标文件中;获取智能合约对应的形式化验证方法,基于目标文件中的汇编代码以及目标文件中的抽象语法树的信息,生成适于形式化验证方法的形式化验证规则语句,上述方案中,在生成抽象语法树的过程中,智能合约中的变量名、方法名以及逻辑关系如继承的父类的信息等等,会体现在抽象语法树中,所以目标文件中的抽象语法树的信息,在一定程度上可以弥补智能合约的汇编代码的缺陷,在生成的形式化验证规则语句时,在一些汇编代码的信息缺失的情况下,可以从语抽象语法树的信息中获取缺失的信息,可以更加全面的提取规则语句,减少了不同版本的源代码编译后优化带来的缺失,有利于提升智能合约的形式化验证的准确度以及保证智能合约的安全性。The embodiment of the application discloses a formal verification method of a smart contract, which can obtain the source code of the smart contract to be verified, compile the source code of the smart contract into an abstract syntax tree, and disassemble the source code of the smart contract, Obtain the target file containing the assembly code of the smart contract, and convert the information in the abstract syntax tree to the target file; obtain the formal verification method corresponding to the smart contract, based on the assembly code in the target file and the abstract syntax tree in the target file Information, generate formal verification rule statements suitable for formal verification methods. In the above scheme, in the process of generating the abstract syntax tree, the variable names, method names, and logical relationships in the smart contract, such as the information of the inherited parent class, etc. , Will be reflected in the abstract syntax tree, so the information of the abstract syntax tree in the target file can make up for the defects of the assembly code of the smart contract to a certain extent. In the generated formal verification rule statement, some information in the assembly code In the case of missing, the missing information can be obtained from the information of the language abstract syntax tree, the rule statements can be extracted more comprehensively, and the defects caused by optimization after the compilation of different versions of the source code can be reduced, which is conducive to improving the formalization of smart contracts The accuracy of verification and the security of smart contracts are guaranteed.
第二实施例:The second embodiment:
本申请第二实施例提供了一种电子装置,参见图4,该电子装置包括:The second embodiment of the present application provides an electronic device. Referring to FIG. 4, the electronic device includes:
编译模块401,用于获取待验证的智能合约的源代码,将智能合约的源代码编译成抽象语法树,以及对智能合约的源代码进行反汇编,得到包含智能合约的汇编代码的目标文件;The compilation module 401 is used to obtain the source code of the smart contract to be verified, compile the source code of the smart contract into an abstract syntax tree, and disassemble the source code of the smart contract to obtain a target file containing the assembly code of the smart contract;
转换模块402,用于将抽象语法树中的信息转换至目标文件中;The conversion module 402 is used to convert the information in the abstract syntax tree to the target file;
生成模块403,用于获取智能合约对应的形式化验证方法,基于目标文件中的汇编代码以及目标文件中的抽象语法树的信息,生成适于形式化验证方法的形式化验证规则语句;The generation module 403 is used to obtain the formal verification method corresponding to the smart contract, and generate formal verification rule statements suitable for the formal verification method based on the assembly code in the target file and the information of the abstract syntax tree in the target file;
验证模块404,用于根据生成的规则语句,进行智能合约的形式化验证。The verification module 404 is used to perform formal verification of the smart contract according to the generated rule statement.
可选的,编译模块401,用于使用预设的语法分析器对智能合约的源代码做关键词或标识符的提取,将每一个关键词或标识符作为智能合约的抽象语法树中的一个节点;根据提取的关键词或标识符出现的位置和顺序,划分关键词或标识符对应的节点的层级关系,以所有的节点以及节点之间的关系形成智能合约的抽象语法树。Optionally, the compiling module 401 is used to extract keywords or identifiers from the source code of the smart contract using a preset syntax analyzer, and use each keyword or identifier as one of the abstract syntax trees of the smart contract Node: According to the location and order of the extracted keywords or identifiers, the hierarchical relationship of the nodes corresponding to the keywords or identifiers is divided, and the abstract syntax tree of the smart contract is formed by all the nodes and the relationships between the nodes.
可选的,转换模块402,具体用于分析抽象语法树中各节点的节点类型;根据节点类型将抽象语法树中的节点的信息拷贝至目标文件中,其中,在拷贝后得到的目标文件中,抽象语法树中相同类型的节点的信息位于对应的同一节点类型名称下。Optionally, the conversion module 402 is specifically used to analyze the node type of each node in the abstract syntax tree; according to the node type, the information of the nodes in the abstract syntax tree is copied to the target file, wherein, in the target file obtained after copying , The information of the node of the same type in the abstract syntax tree is located under the corresponding name of the same node type.
可选的,生成模块403,用于获取智能合约的安全需求,基于安全需求以及形式化验证方法,确定需要生成的适于形式化验证方法的形式化验证规则语句;从目标文件中的抽象语法树的信息以及汇编代码中,提取生成形式化验证规则语句需要的信息;基于提取的所有信息和形式化验证方法,生成适于形式化验证方法的形式化验证规则语句。Optionally, the generation module 403 is used to obtain the security requirements of the smart contract, and based on the security requirements and the formal verification method, determine the formal verification rule statements suitable for the formal verification method to be generated; from the abstract grammar in the target file From the tree information and assembly code, the information needed to generate formal verification rule statements is extracted; based on all the extracted information and the formal verification method, a formal verification rule statement suitable for the formal verification method is generated.
一个示例中,生成模块403,具体用于通过从目标文件中的汇编代码中提取生成形式化验证规则语句的信息;若提取的信息不足以生成形式化验证规则语句,则从目标文件中的抽象语法树的信息中提取需要的信息的方式,提取生成形式化验证规则语句需要的信息。In an example, the generation module 403 is specifically used to extract information for generating formal verification rule statements from the assembly code in the target file; if the extracted information is not enough to generate formal verification rule statements, abstract from the target file The method of extracting the required information from the information of the syntax tree, and extracting the information needed to generate the formal verification rule statement.
另一个示例中,生成模块403,具体用于通过从目标文件中的抽象语法树的信息中提取生成形式化验证规则语句需要的合约对象信息;从目标文件中的汇编代码中提取除合约对象信息外,生成形式化验证规则语句需要的信息的方式,提取生成形式化验证规则语句需要的信息。In another example, the generating module 403 is specifically used to extract the contract object information needed to generate formal verification rule statements from the information of the abstract syntax tree in the target file; extract the contract object information from the assembly code in the target file In addition, the method of generating the information required for the formal verification rule statement is to extract the information required for generating the formal verification rule statement.
本申请实施例公开了一种电子装置,基于目标文件中的抽象语法树的信息,可以更加全面的提取规则语句,减少了不同版本的源代码编译后优化带来的缺失,有利于提升智能合约的形式化验证的准确度以及保证智能合约的安全性。The embodiment of the application discloses an electronic device, which can extract rule statements more comprehensively based on the information of the abstract syntax tree in the target file, reduce the defects caused by optimization after the compilation of different versions of the source code, and is beneficial to improve the smart contract The accuracy of formal verification and the security of smart contracts are guaranteed.
第三实施例:The third embodiment:
请参阅图5,图5为本申请第三实施例提供的一种电子装置。该电子装置可用于实现图2所示实施例中的智能合约的形式化验证方法。如图5所示,该电子装置主要包括:Please refer to FIG. 5. FIG. 5 is an electronic device provided by a third embodiment of this application. The electronic device can be used to implement the formal verification method of the smart contract in the embodiment shown in FIG. 2. As shown in Figure 5, the electronic device mainly includes:
存储器501、处理器502、总线503及存储在存储器501上并可在处理器502上运行的计算机程序,存储器501和处理器502通过总线503连接。处理器502执行该计算机程序时,实现图2所示实施例中的智能合约的形式化验证方法。其中,处理器的数量可以是一个或多个,本实施例对此没有限制。The memory 501, the processor 502, the bus 503, and a computer program stored on the memory 501 and running on the processor 502, the memory 501 and the processor 502 are connected through the bus 503. When the processor 502 executes the computer program, it implements the formal verification method of the smart contract in the embodiment shown in FIG. 2. The number of processors may be one or more, which is not limited in this embodiment.
存储器501可以是高速随机存取记忆体(RAM,Random Access Memory)存储器,也可为非不稳定的存储器(non-volatile memory),例如磁盘存储器。存储器501用于存储可执行程序元素,处理器502与存储器501耦合。The memory 501 may be a high-speed random access memory (RAM, Random Access Memory) memory, or a non-volatile memory (non-volatile memory), such as a magnetic disk memory. The memory 501 is used to store executable program elements, and the processor 502 is coupled with the memory 501.
进一步的,本申请实施例还提供了一种存储介质,该存储介质可以是设置于上述各实施例中的电子装置中,该存储介质可以是前述图5所示实施例中的存储器。其中,所述计算机可读存储介质可以是非易失性,也可以是易失性。Further, an embodiment of the present application also provides a storage medium, which may be the electronic device provided in the foregoing embodiments, and the storage medium may be the memory in the embodiment shown in FIG. 5. Wherein, the computer-readable storage medium may be non-volatile or volatile.
该存储介质上存储有计算机程序,该程序被处理器执行时实现图2所示实施例中的智能合约的形式化验证方法。进一步的,该计算机可存储介质还可以是U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、RAM、磁碟或者光盘等各种可以存储程序元素的介质。A computer program is stored on the storage medium, and when the program is executed by the processor, the formal verification method of the smart contract in the embodiment shown in FIG. 2 is realized. Further, the computer storage medium may also be a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a RAM, a magnetic disk, or an optical disk and other various media that can store program elements.
采用本实施例的电子装置,基于对待检测软件的汇编代码的编码处理,可以得到检测软件的编码特征,使得深度神经网络更容易发现恶意软件之间的共性,提升了本申请对识别各类型恶意软件的普适性,采用深度神经网络判断待检测软件是否为恶意软件,可以进一步保证对恶意软件的有效识别。Using the electronic device of this embodiment, based on the coding process of the assembly code of the software to be detected, the coding characteristics of the detection software can be obtained, making it easier for the deep neural network to find the commonalities between malware, and improving the application’s ability to identify various types of malicious software. The universality of software, the use of deep neural networks to determine whether the software to be detected is malicious software can further ensure effective identification of malicious software.
在本申请所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,模块的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个模块或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或模块的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in this application, it should be understood that the disclosed device and method may be implemented in other ways. For example, the device embodiments described above are merely illustrative, for example, the division of modules is only a logical function division, and there may be other divisions in actual implementation, for example, multiple modules 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 modules, and may be in electrical, mechanical or other forms.
作为分离部件说明的模块可以是或者也可以不是物理上分开的,作为模块显示的部件可以是或者也可以不是物理模块,即可以位于一个地方,或者也可以分布到多个网络模块上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。The modules described as separate components may or may not be physically separate, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the objectives of the solutions of the embodiments.
另外,在本申请各个实施例中的各功能模块可以集成在一个处理模块中,也可以是各个模块单独物理存在,也可以两个或两个以上模块集成在一个模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。In addition, each functional module in each embodiment of the present application may be integrated into one processing module, or each module may exist alone physically, or two or more modules may be integrated into one module. The above-mentioned integrated modules can be implemented in the form of hardware or software functional modules.
集成的模块如果以软件功能模块的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个可读存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例方法的全部或部分步骤。而前述的可读存储介质包括:U盘、移动硬盘、ROM、RAM、磁碟或者光盘等各种可以存储程序元素的介质。If the integrated module is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer readable storage medium. Based on this understanding, the technical solution of this application essentially or the part that contributes to the existing technology or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a readable storage. The medium includes a number of instructions to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods in the various embodiments of the present application. The aforementioned readable storage medium includes: U disk, mobile hard disk, ROM, RAM, magnetic disk or optical disk and other media that can store program elements.
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。The above are only specific implementations of this application, but the protection scope of this application is not limited to this. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed in this application. Should be covered within the scope of protection of this application. Therefore, the protection scope of this application should be subject to the protection scope of the claims.

Claims (20)

  1. 一种智能合约的形式化验证方法,其中,包括:A formal verification method for smart contracts, including:
    获取待验证的智能合约的源代码,将所述智能合约的源代码编译成抽象语法树,以及对所述智能合约的源代码进行反汇编,得到包含所述智能合约的汇编代码的目标文件;Obtaining the source code of the smart contract to be verified, compiling the source code of the smart contract into an abstract syntax tree, and disassembling the source code of the smart contract to obtain a target file containing the assembly code of the smart contract;
    将所述抽象语法树中的信息转换至所述目标文件中;Converting the information in the abstract syntax tree to the target file;
    获取所述智能合约对应的形式化验证方法,基于所述目标文件中的汇编代码以及所述目标文件中的抽象语法树的信息,生成适于所述形式化验证方法的形式化验证规则语句;Acquiring a formal verification method corresponding to the smart contract, and generating formal verification rule statements suitable for the formal verification method based on the assembly code in the target file and the information of the abstract syntax tree in the target file;
    根据生成的所述规则语句,进行所述智能合约的形式化验证。Perform formal verification of the smart contract according to the generated rule statement.
  2. 根据权利要求1所述的智能合约的形式化验证方法,其中,所述将所述智能合约的源代码编译成抽象语法树包括:The method for formal verification of a smart contract according to claim 1, wherein said compiling the source code of the smart contract into an abstract syntax tree comprises:
    使用预设的语法分析器对所述智能合约的源代码做关键词或标识符的提取,将每一个关键词或标识符作为所述智能合约的抽象语法树中的一个节点;Use a preset syntax analyzer to extract keywords or identifiers from the source code of the smart contract, and use each keyword or identifier as a node in the abstract syntax tree of the smart contract;
    根据提取的所述关键词或标识符出现的位置和顺序,划分所述关键词或标识符对应的节点的层级关系,以所有的节点以及节点之间的关系形成所述智能合约的抽象语法树。According to the extracted position and order of the keywords or identifiers, the hierarchical relationship of the nodes corresponding to the keywords or identifiers is divided, and the abstract syntax tree of the smart contract is formed by all the nodes and the relationships between the nodes .
  3. 根据权利要求1所述的智能合约的形式化验证方法,其中,所述将所述抽象语法树中的信息转换至所述目标文件中包括:The method for formal verification of a smart contract according to claim 1, wherein said converting the information in the abstract syntax tree to the target file comprises:
    分析所述抽象语法树中各节点的节点类型;Analyzing the node type of each node in the abstract syntax tree;
    根据所述节点类型将所述抽象语法树中的节点的信息拷贝至所述目标文件中,其中,在拷贝后得到的所述目标文件中,所述抽象语法树中相同类型的节点的信息位于对应的同一节点类型名称下。The information of the nodes in the abstract syntax tree is copied to the target file according to the node type, wherein, in the target file obtained after copying, the information of the nodes of the same type in the abstract syntax tree is located in the target file Corresponding to the same node type name.
  4. 根据权利要求1-3任一项所述的智能合约的形式化验证方法,其中,所述基于所述目标文件中的汇编代码以及所述目标文件中的抽象语法树的信息,生成适于所述形式化验证方法的形式化验证规则语句包括:The method for formal verification of a smart contract according to any one of claims 1-3, wherein the generating is suitable for all based on the assembly code in the target file and the information of the abstract syntax tree in the target file The formal verification rules of the formal verification method include:
    获取所述智能合约的安全需求,基于所述安全需求以及所述形式化验证方法,确定需要生成的适于所述形式化验证方法的形式化验证规则语句;Acquiring the security requirements of the smart contract, and determining the formal verification rule statements suitable for the formal verification method that need to be generated based on the security requirements and the formal verification method;
    从所述目标文件中的抽象语法树的信息以及汇编代码中,提取生成所述形式化验证规则语句需要的信息;Extracting the information needed to generate the formal verification rule statement from the information of the abstract syntax tree in the target file and the assembly code;
    基于提取的所有信息和所述形式化验证方法,生成适于所述形式化验证方法的形式化验证规则语句。Based on all the extracted information and the formal verification method, a formal verification rule sentence suitable for the formal verification method is generated.
  5. 根据权利要求4所述的智能合约的形式化验证方法,其中,所述从所述目标文件中的抽象语法树的信息以及汇编代码中,提取生成所述形式化验证规则语句需要的信息包括:The method for formal verification of a smart contract according to claim 4, wherein said extracting from the information of the abstract syntax tree and the assembly code in the target file the information needed to generate the formal verification rule statement comprises:
    从所述目标文件中的汇编代码中提取生成所述形式化验证规则语句的信息;Extracting the information for generating the formal verification rule statement from the assembly code in the target file;
    若提取的所述信息不足以生成所述形式化验证规则语句,则从所述目标文件中的抽象语法树的信息中提取需要的信息。If the extracted information is not enough to generate the formal verification rule statement, then the required information is extracted from the information of the abstract syntax tree in the target file.
  6. 根据权利要求4所述的智能合约的形式化验证方法,其中,所述从所述目标文件中的抽象语法树的信息以及汇编代码中,提取生成所述形式化验证规则语句需要的信息包括:The method for formal verification of a smart contract according to claim 4, wherein said extracting from the information of the abstract syntax tree and the assembly code in the target file the information needed to generate the formal verification rule statement comprises:
    从所述目标文件中的所述抽象语法树的信息中提取生成所述形式化验证规则语句需要的合约对象信息;Extracting the contract object information needed to generate the formal verification rule statement from the information of the abstract syntax tree in the target file;
    从所述目标文件中的汇编代码中提取除所述合约对象信息外,生成所述形式化验证规则语句需要的信息。In addition to the contract object information, the information needed to generate the formal verification rule statement is extracted from the assembly code in the target file.
  7. 一种电子装置,其中,包括:An electronic device, including:
    编译模块,用于获取待验证的智能合约的源代码,将所述智能合约的源代码编译成抽象语法树,以及对所述智能合约的源代码进行反汇编,得到包含所述智能合约的汇编代码的目标文件;The compilation module is used to obtain the source code of the smart contract to be verified, compile the source code of the smart contract into an abstract syntax tree, and disassemble the source code of the smart contract to obtain the assembly containing the smart contract The object file of the code;
    转换模块,用于将所述抽象语法树中的信息转换至所述目标文件中;A conversion module for converting the information in the abstract syntax tree to the target file;
    生成模块,用于获取所述智能合约对应的形式化验证方法,基于所述目标文件中的汇编代码以及所述目标文件中的抽象语法树的信息,生成适于所述形式化验证方法的形式化验证规则语句;The generation module is used to obtain the formal verification method corresponding to the smart contract, and generate a form suitable for the formal verification method based on the assembly code in the target file and the information of the abstract syntax tree in the target file Validation rule statement;
    验证模块,用于根据生成的所述规则语句,进行所述智能合约的形式化验证。The verification module is used to perform formal verification of the smart contract according to the generated rule statement.
  8. 根据权利要求7所述的电子装置,其中,所述编译模块,用于使用预设的语法分析器对所述智能合约的源代码做关键词或标识符的提取,将每一个关键词或标识符作为所述智能合约的抽象语法树中的一个节点;根据提取的所述关键词或标识符出现的位置和顺序,划分所述关键词或标识符对应的节点的层级关系,以所有的节点以及节点之间的关系形成所述智能合约的抽象语法树。The electronic device according to claim 7, wherein the compiling module is configured to use a preset syntax analyzer to extract keywords or identifiers from the source code of the smart contract, and extract each keyword or identifier Symbol as a node in the abstract syntax tree of the smart contract; according to the extracted position and order of the keywords or identifiers, the hierarchical relationship of the nodes corresponding to the keywords or identifiers is divided, and all nodes And the relationship between nodes forms an abstract syntax tree of the smart contract.
  9. 一种电子装置,其中,所述电子装置包括存储器和处理器,所述处理器、和所述存储器相互连接,其中,所述存储器用于存储计算机程序,所述计算机程序包括程序指令,所述处理器用于执行所述存储器的所述程序指令,其中:An electronic device, wherein the electronic device includes a memory and a processor, the processor and the memory are connected to each other, wherein the memory is used to store a computer program, and the computer program includes program instructions. The processor is configured to execute the program instructions of the memory, wherein:
    获取待验证的智能合约的源代码,将所述智能合约的源代码编译成抽象语法树,以及对所述智能合约的源代码进行反汇编,得到包含所述智能合约的汇编代码的目标文件;Obtaining the source code of the smart contract to be verified, compiling the source code of the smart contract into an abstract syntax tree, and disassembling the source code of the smart contract to obtain a target file containing the assembly code of the smart contract;
    将所述抽象语法树中的信息转换至所述目标文件中;Converting the information in the abstract syntax tree to the target file;
    获取所述智能合约对应的形式化验证方法,基于所述目标文件中的汇编代码以及所述目标文件中的抽象语法树的信息,生成适于所述形式化验证方法的形式化验证规则语句;Acquiring a formal verification method corresponding to the smart contract, and generating formal verification rule statements suitable for the formal verification method based on the assembly code in the target file and the information of the abstract syntax tree in the target file;
    根据生成的所述规则语句,进行所述智能合约的形式化验证。Perform formal verification of the smart contract according to the generated rule statement.
  10. 根据权利要求9所述的电子装置,其中,所述处理器用于:The electronic device according to claim 9, wherein the processor is configured to:
    使用预设的语法分析器对所述智能合约的源代码做关键词或标识符的提取,将每一个关键词或标识符作为所述智能合约的抽象语法树中的一个节点;Use a preset syntax analyzer to extract keywords or identifiers from the source code of the smart contract, and use each keyword or identifier as a node in the abstract syntax tree of the smart contract;
    根据提取的所述关键词或标识符出现的位置和顺序,划分所述关键词或标识符对应的节点的层级关系,以所有的节点以及节点之间的关系形成所述智能合约的抽象语法树。According to the extracted position and order of the keywords or identifiers, the hierarchical relationship of the nodes corresponding to the keywords or identifiers is divided, and the abstract syntax tree of the smart contract is formed by all the nodes and the relationships between the nodes .
  11. 根据权利要求9所述的电子装置,其中,所述处理器用于:The electronic device according to claim 9, wherein the processor is configured to:
    分析所述抽象语法树中各节点的节点类型;Analyzing the node type of each node in the abstract syntax tree;
    根据所述节点类型将所述抽象语法树中的节点的信息拷贝至所述目标文件中,其中,在拷贝后得到的所述目标文件中,所述抽象语法树中相同类型的节点的信息位于对应的同一节点类型名称下。The information of the nodes in the abstract syntax tree is copied to the target file according to the node type, wherein, in the target file obtained after copying, the information of the nodes of the same type in the abstract syntax tree is located in the target file Corresponding to the same node type name.
  12. 根据权利要求9-11任一项所述的电子装置,其中,所述处理器用于:The electronic device according to any one of claims 9-11, wherein the processor is configured to:
    获取所述智能合约的安全需求,基于所述安全需求以及所述形式化验证方法,确定需要生成的适于所述形式化验证方法的形式化验证规则语句;Acquiring the security requirements of the smart contract, and determining the formal verification rule statements suitable for the formal verification method that need to be generated based on the security requirements and the formal verification method;
    从所述目标文件中的抽象语法树的信息以及汇编代码中,提取生成所述形式化验证规则语句需要的信息;Extracting the information needed to generate the formal verification rule statement from the information of the abstract syntax tree in the target file and the assembly code;
    基于提取的所有信息和所述形式化验证方法,生成适于所述形式化验证方法的形式化验证规则语句。Based on all the extracted information and the formal verification method, a formal verification rule sentence suitable for the formal verification method is generated.
  13. 根据权利要求12所述的电子装置,其中,所述处理器用于:The electronic device according to claim 12, wherein the processor is configured to:
    从所述目标文件中的汇编代码中提取生成所述形式化验证规则语句的信息;Extracting the information for generating the formal verification rule statement from the assembly code in the target file;
    若提取的所述信息不足以生成所述形式化验证规则语句,则从所述目标文件中的抽象语法树的信息中提取需要的信息。If the extracted information is not enough to generate the formal verification rule statement, then the required information is extracted from the information of the abstract syntax tree in the target file.
  14. 根据权利要求12所述的电子装置,其中,所述处理器用于:The electronic device according to claim 12, wherein the processor is configured to:
    从所述目标文件中的所述抽象语法树的信息中提取生成所述形式化验证规则语句需要的合约对象信息;Extracting the contract object information needed to generate the formal verification rule statement from the information of the abstract syntax tree in the target file;
    从所述目标文件中的汇编代码中提取除所述合约对象信息外,生成所述形式化验证规 则语句需要的信息。In addition to the contract object information, the information needed to generate the formal verification rule statement is extracted from the assembly code in the target file.
  15. 一种计算机可读存储介质,其中,所述计算机可读存储介质存储有计算机程序,所述计算机程序包括程序指令,所述程序指令被处理器执行时,用于实现以下步骤:A computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, the computer program includes program instructions, and when the program instructions are executed by a processor, they are used to implement the following steps:
    获取待验证的智能合约的源代码,将所述智能合约的源代码编译成抽象语法树,以及对所述智能合约的源代码进行反汇编,得到包含所述智能合约的汇编代码的目标文件;Obtaining the source code of the smart contract to be verified, compiling the source code of the smart contract into an abstract syntax tree, and disassembling the source code of the smart contract to obtain a target file containing the assembly code of the smart contract;
    将所述抽象语法树中的信息转换至所述目标文件中;Converting the information in the abstract syntax tree to the target file;
    获取所述智能合约对应的形式化验证方法,基于所述目标文件中的汇编代码以及所述目标文件中的抽象语法树的信息,生成适于所述形式化验证方法的形式化验证规则语句;Acquiring a formal verification method corresponding to the smart contract, and generating formal verification rule statements suitable for the formal verification method based on the assembly code in the target file and the information of the abstract syntax tree in the target file;
    根据生成的所述规则语句,进行所述智能合约的形式化验证。Perform formal verification of the smart contract according to the generated rule statement.
  16. 根据权利要求15所述的计算机可读存储介质,其中,所述程序指令被处理器执行时,还用于实现以下步骤:The computer-readable storage medium according to claim 15, wherein when the program instructions are executed by the processor, they are further used to implement the following steps:
    使用预设的语法分析器对所述智能合约的源代码做关键词或标识符的提取,将每一个关键词或标识符作为所述智能合约的抽象语法树中的一个节点;Use a preset syntax analyzer to extract keywords or identifiers from the source code of the smart contract, and use each keyword or identifier as a node in the abstract syntax tree of the smart contract;
    根据提取的所述关键词或标识符出现的位置和顺序,划分所述关键词或标识符对应的节点的层级关系,以所有的节点以及节点之间的关系形成所述智能合约的抽象语法树。According to the extracted position and order of the keywords or identifiers, the hierarchical relationship of the nodes corresponding to the keywords or identifiers is divided, and the abstract syntax tree of the smart contract is formed by all the nodes and the relationships between the nodes .
  17. 根据权利要求15所述的计算机可读存储介质,其中,所述程序指令被处理器执行时,还用于实现以下步骤:The computer-readable storage medium according to claim 15, wherein when the program instructions are executed by the processor, they are further used to implement the following steps:
    分析所述抽象语法树中各节点的节点类型;Analyzing the node type of each node in the abstract syntax tree;
    根据所述节点类型将所述抽象语法树中的节点的信息拷贝至所述目标文件中,其中,在拷贝后得到的所述目标文件中,所述抽象语法树中相同类型的节点的信息位于对应的同一节点类型名称下。The information of the nodes in the abstract syntax tree is copied to the target file according to the node type, wherein, in the target file obtained after copying, the information of the nodes of the same type in the abstract syntax tree is located in the target file Corresponding to the same node type name.
  18. 根据权利要求15-17任一项所述的计算机可读存储介质,其中,所述程序指令被处理器执行时,还用于实现以下步骤:The computer-readable storage medium according to any one of claims 15-17, wherein when the program instructions are executed by the processor, they are further used to implement the following steps:
    获取所述智能合约的安全需求,基于所述安全需求以及所述形式化验证方法,确定需要生成的适于所述形式化验证方法的形式化验证规则语句;Acquiring the security requirements of the smart contract, and determining the formal verification rule statements suitable for the formal verification method that need to be generated based on the security requirements and the formal verification method;
    从所述目标文件中的抽象语法树的信息以及汇编代码中,提取生成所述形式化验证规则语句需要的信息;Extracting the information needed to generate the formal verification rule statement from the information of the abstract syntax tree in the target file and the assembly code;
    基于提取的所有信息和所述形式化验证方法,生成适于所述形式化验证方法的形式化验证规则语句。Based on all the extracted information and the formal verification method, a formal verification rule sentence suitable for the formal verification method is generated.
  19. 根据权利要求18所述的计算机可读存储介质,其中,所述程序指令被处理器执行时,还用于实现以下步骤:The computer-readable storage medium according to claim 18, wherein when the program instructions are executed by the processor, they are further used to implement the following steps:
    从所述目标文件中的汇编代码中提取生成所述形式化验证规则语句的信息;Extracting the information for generating the formal verification rule statement from the assembly code in the target file;
    若提取的所述信息不足以生成所述形式化验证规则语句,则从所述目标文件中的抽象语法树的信息中提取需要的信息。If the extracted information is not enough to generate the formal verification rule statement, then the required information is extracted from the information of the abstract syntax tree in the target file.
  20. 根据权利要求18所述的计算机可读存储介质,其中,所述程序指令被处理器执行时,还用于实现以下步骤:The computer-readable storage medium according to claim 18, wherein when the program instructions are executed by the processor, they are further used to implement the following steps:
    从所述目标文件中的所述抽象语法树的信息中提取生成所述形式化验证规则语句需要的合约对象信息;Extracting the contract object information needed to generate the formal verification rule statement from the information of the abstract syntax tree in the target file;
    从所述目标文件中的汇编代码中提取除所述合约对象信息外,生成所述形式化验证规则语句需要的信息。In addition to the contract object information, the information needed to generate the formal verification rule statement is extracted from the assembly code in the target file.
PCT/CN2020/099478 2019-07-31 2020-06-30 Smart contract formal verification method, electronic apparatus and storage medium WO2021017735A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910699357.6A CN110532176B (en) 2019-07-31 2019-07-31 Formal verification method of intelligent contract, electronic device and storage medium
CN201910699357.6 2019-07-31

Publications (1)

Publication Number Publication Date
WO2021017735A1 true WO2021017735A1 (en) 2021-02-04

Family

ID=68661042

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/099478 WO2021017735A1 (en) 2019-07-31 2020-06-30 Smart contract formal verification method, electronic apparatus and storage medium

Country Status (2)

Country Link
CN (1) CN110532176B (en)
WO (1) WO2021017735A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115879945A (en) * 2022-11-03 2023-03-31 北京邮电大学 Intelligent contract read-after-write risk detection method and electronic equipment

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110532176B (en) * 2019-07-31 2024-07-05 平安科技(深圳)有限公司 Formal verification method of intelligent contract, electronic device and storage medium
CN111142871B (en) * 2019-12-24 2023-06-06 杭州安恒信息技术股份有限公司 Front-end page development system, method, equipment and medium
CN111124422B (en) * 2019-12-25 2023-03-10 成都互诚在线科技有限公司 EOS intelligent contract language conversion method based on abstract syntax tree
CN112104709B (en) * 2020-08-28 2022-06-07 腾讯科技(深圳)有限公司 Intelligent contract processing method, device, medium and electronic equipment
CN112100620B (en) * 2020-09-04 2024-02-06 百度在线网络技术(北京)有限公司 Code security detection method, apparatus, device and readable storage medium
CN112215618B (en) * 2020-12-11 2021-02-26 支付宝(杭州)信息技术有限公司 Verification method and device of intelligent contract
CN113342429B (en) * 2021-06-09 2023-08-08 网易(杭州)网络有限公司 Intelligent contract data processing method, intelligent contract data processing device, computer equipment and storage medium
CN113778880B (en) * 2021-09-13 2024-06-25 江苏通付盾区块链科技有限公司 Intelligent contract function verification method and device based on formal verification
CN114297063B (en) * 2021-12-28 2022-09-30 中国科学技术大学 Method and system for automated formal modeling and verification of source code
CN115454475A (en) * 2022-09-14 2022-12-09 蚂蚁区块链科技(上海)有限公司 Method and device for detecting compatibility of contract upgrading

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101814053A (en) * 2010-03-29 2010-08-25 中国人民解放军信息工程大学 Method for discovering binary code vulnerability based on function model
US20140031958A1 (en) * 2012-07-24 2014-01-30 General Electric Company Systems and methods for rule-based control system reliability
CN108985073A (en) * 2018-07-18 2018-12-11 成都链安科技有限公司 A kind of supermatic intelligent forms of contract chemical examination card system and method
CN109063477A (en) * 2018-07-18 2018-12-21 成都链安科技有限公司 A kind of intelligent contract aacode defect detection system and method for automation
CN109753288A (en) * 2019-01-14 2019-05-14 杭州云象网络技术有限公司 A kind of intelligent contract Compilation Method suitable for Formal Verification
WO2019108676A1 (en) * 2017-11-28 2019-06-06 Yale University Systems and methods of formal verification
CN110532176A (en) * 2019-07-31 2019-12-03 平安科技(深圳)有限公司 A kind of formalization verification method, electronic device and the storage medium of intelligence contract

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP4888790B2 (en) * 2008-03-06 2012-02-29 日本電気株式会社 Contract definition function verification apparatus, method and program thereof
CN109375899B (en) * 2018-09-25 2021-08-03 杭州趣链科技有限公司 Method for formally verifying identity intelligent contract
CN109492402A (en) * 2018-10-25 2019-03-19 杭州趣链科技有限公司 A kind of intelligent contract safe evaluating method of rule-based engine
CN109615518A (en) * 2018-12-11 2019-04-12 北京瑞卓喜投科技发展有限公司 A kind of construction method and intelligence contract system of intelligence contract system

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101814053A (en) * 2010-03-29 2010-08-25 中国人民解放军信息工程大学 Method for discovering binary code vulnerability based on function model
US20140031958A1 (en) * 2012-07-24 2014-01-30 General Electric Company Systems and methods for rule-based control system reliability
WO2019108676A1 (en) * 2017-11-28 2019-06-06 Yale University Systems and methods of formal verification
CN108985073A (en) * 2018-07-18 2018-12-11 成都链安科技有限公司 A kind of supermatic intelligent forms of contract chemical examination card system and method
CN109063477A (en) * 2018-07-18 2018-12-21 成都链安科技有限公司 A kind of intelligent contract aacode defect detection system and method for automation
CN109753288A (en) * 2019-01-14 2019-05-14 杭州云象网络技术有限公司 A kind of intelligent contract Compilation Method suitable for Formal Verification
CN110532176A (en) * 2019-07-31 2019-12-03 平安科技(深圳)有限公司 A kind of formalization verification method, electronic device and the storage medium of intelligence contract

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115879945A (en) * 2022-11-03 2023-03-31 北京邮电大学 Intelligent contract read-after-write risk detection method and electronic equipment

Also Published As

Publication number Publication date
CN110532176B (en) 2024-07-05
CN110532176A (en) 2019-12-03

Similar Documents

Publication Publication Date Title
WO2021017735A1 (en) Smart contract formal verification method, electronic apparatus and storage medium
US10990367B2 (en) Application development method, tool, and device, and storage medium
US11379227B2 (en) Extraquery context-aided search intent detection
US10942708B2 (en) Generating web API specification from online documentation
US9361317B2 (en) Method for entity enrichment of digital content to enable advanced search functionality in content management systems
US10102246B2 (en) Natural language consumer segmentation
US10331441B2 (en) Source code mapping through context specific key word indexes and fingerprinting
US10083398B2 (en) Framework for annotated-text search using indexed parallel fields
CN102664925B (en) A kind of method of displaying searching result and device
AU2016204573A1 (en) Common data repository for improving transactional efficiencies of user interactions with a computing device
CN112395843B (en) PHP code-based service processing method, device and medium
CN111414122A (en) Intelligent text processing method and device, electronic equipment and storage medium
US9690862B2 (en) Realtime ingestion via multi-corpus knowledge base with weighting
CN117033249B (en) Test case generation method and device, computer equipment and storage medium
US10503743B2 (en) Integrating search with application analysis
CN114398673A (en) Application compliance detection method and device, storage medium and electronic equipment
JP2021108189A (en) Method for acquiring vulnerability feature, device, and electronic apparatus
CN113778897A (en) Automatic test method, device, equipment and storage medium of interface
US9904674B2 (en) Augmented text search with syntactic information
US20180314683A1 (en) Method and device for processing natural language
CN112947984A (en) Application program development method and device
US11907311B2 (en) Dynamic website characterization for search optimization
US10579696B2 (en) Save session storage space by identifying similar contents and computing difference
WO2024182108A1 (en) Computed values for knowledge graph
CN118377558A (en) Interface calling method, device, equipment, medium and program product

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: 20847453

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: 20847453

Country of ref document: EP

Kind code of ref document: A1