WO2024001929A1 - 智能合约漏洞检测方法、装置和设备 - Google Patents

智能合约漏洞检测方法、装置和设备 Download PDF

Info

Publication number
WO2024001929A1
WO2024001929A1 PCT/CN2023/102025 CN2023102025W WO2024001929A1 WO 2024001929 A1 WO2024001929 A1 WO 2024001929A1 CN 2023102025 W CN2023102025 W CN 2023102025W WO 2024001929 A1 WO2024001929 A1 WO 2024001929A1
Authority
WO
WIPO (PCT)
Prior art keywords
formal
smart contract
formalized
execution
initial state
Prior art date
Application number
PCT/CN2023/102025
Other languages
English (en)
French (fr)
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 WO2024001929A1 publication Critical patent/WO2024001929A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/50Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
    • G06F21/57Certifying or maintaining trusted computer platforms, e.g. secure boots or power-downs, version controls, system software checks, secure updates or assessing vulnerabilities
    • G06F21/577Assessing vulnerabilities and evaluating computer system security
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/10Protecting distributed programs or content, e.g. vending or licensing of copyrighted material ; Digital rights management [DRM]
    • G06F21/12Protecting executable software
    • G06F21/14Protecting executable software against software analysis or reverse engineering, e.g. by obfuscation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/50Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
    • G06F21/55Detecting local intrusion or implementing counter-measures
    • G06F21/56Computer malware detection or handling, e.g. anti-virus arrangements
    • G06F21/566Dynamic detection, i.e. detection performed at run-time, e.g. emulation, suspicious activities

Definitions

  • the present disclosure relates to the field of blockchain technology, and in particular to smart contract vulnerability detection methods, devices and equipment.
  • Blockchain is a new application model of computer technology such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm.
  • Blockchain is a technology that uses a decentralized consensus mechanism to maintain a complete, distributed, and non-tamperable ledger database. It allows participants in the blockchain to achieve a unified process without establishing a trust relationship.
  • smart contracts are written in digital form.
  • a smart contract is a set of commitments defined in digital form, including an agreement on which contract participants can execute these commitments.
  • the combination of smart contracts and blockchain technology can make the entire process of storage, reading, and execution of the ledger system transparent, traceable, and non-tamperable.
  • a state machine system is built using the blockchain’s own consensus algorithm, allowing smart contracts to run efficiently.
  • some embodiments of the present disclosure provide a smart contract vulnerability detection method, which is applied to a virtual machine server, including: obtaining formal deployment information of the smart contract, where the formal deployment information includes a formal initial state and a formal behavior list,
  • the formal behavior list includes the initialization execution function and behavior function of the smart contract; based on the formal initial state, execute the initialization execution function and behavior function included in the formal behavior list to obtain the execution result of the smart contract; according to the formal specification library of the smart contract Detect the execution results of smart contracts and obtain vulnerability detection results.
  • the formal specification library includes the formal specifications of smart contracts.
  • the execution result of the smart contract is detected according to the formal specification library of the smart contract to obtain the vulnerability detection results, including: for each behavioral function, the detection is based on the formal initial state, and the initialization execution function and the execution of the behavioral function are executed. Whether the result conforms to the formal specification; if so, associate the execution result with the formal initial state, and include the execution result as a new formal initial state if the execution result is not included in the formal deployment information. In the formal deployment information; if it does not match, an error message will be reported.
  • the method further includes: establishing a directed graph, the directed graph including The node corresponding to the initial state, and the two nodes with an associated relationship are connected by directed edges. If it is consistent, the execution result will be associated with the formal initial state, including: if it is consistent, check whether there is a node corresponding to the execution result in the directed graph. If it exists, set the directed direction pointing from the initialization state to the node. If the edge does not exist, the execution result is added to the directed graph, and a directed edge pointing from the initialization state to the node corresponding to the execution result is set.
  • the formal deployment information includes a plurality of formal initial states.
  • the method also includes: determining an execution queue according to a plurality of formal initial states, wherein the execution queue includes a formal initial state among the plurality of formal initial states that conforms to the formal specification.
  • executing the initialization execution function and behavior function included in the formalized behavior list includes: based on each formalized initial state in the execution queue, executing the initialization execution function and behavior function included in the formalized behavior list.
  • the method further includes: determining a customized formal specification of the smart contract based on the requirement information of the smart contract; and adding the customized formal specification to the formal specification library.
  • the formal specification library also includes a universal specification for representing the formal specification of each smart contract in the plurality of smart contracts. After adding the custom formal specification to the formal specification library, the method also includes replacing the generic specification with the custom formal specification of the smart contract.
  • obtaining the formal deployment information of the smart contract includes: obtaining the smart contract; and parsing the smart contract to obtain the formal initial state and the formal behavior list.
  • the smart contract is stored in the electronic device, and the virtual machine server and the electronic device are communicatively connected.
  • Obtain smart contracts including: Obtain smart contracts from electronic devices.
  • each of the plurality of formalized initial states conforms to the formal specification, or a portion of the plurality of formalized initial states conforms to the formal specification.
  • the virtual machine server is configured with a data repository. After obtaining the formal deployment information of the smart contract, the method further includes: storing the formal deployment information of the smart contract in the data repository.
  • the initialization execution function is used to initialize the virtual machine server.
  • behavioral functions are used to represent trading rules when trading between different accounts.
  • a smart contract vulnerability detection device which is applied to a virtual machine server and includes: an acquisition module configured to obtain formal deployment information of the smart contract, where the formal deployment information includes formal initialization List of states and formal behaviors, formal behaviors
  • the list includes the initialization execution function and behavior function of the smart contract;
  • the execution module is configured to execute the initialization execution function and behavior function included in the formal behavior list based on the formalized initial state to obtain the execution result of the smart contract;
  • the detection module is It is configured to detect the execution result of the smart contract according to the formal specification library of the smart contract and obtain the vulnerability detection result, where the formal specification library includes the formal specification of the smart contract.
  • some embodiments of the present disclosure provide an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor. When executed by the processor, the computer program implements the first aspect Smart contract vulnerability detection method.
  • some embodiments of the present disclosure provide a computer-readable storage medium.
  • a computer program is stored on the computer-readable storage medium. When executed by a processor, the computer program implements the smart contract vulnerability detection method of the first aspect.
  • Figure 1 is a schematic diagram of an application scenario of a smart contract vulnerability detection method according to one or more embodiments
  • Figure 2 is a schematic flow chart of a smart contract vulnerability detection method according to one or more embodiments
  • Figure 3 is a schematic diagram of a formal behavior list according to one or more embodiments.
  • Figure 4 is a schematic flow chart of another smart contract vulnerability detection method according to one or more embodiments.
  • Figure 5 is a schematic diagram of a directed graph according to one or more embodiments.
  • Figure 6 is a schematic diagram of another directed graph according to one or more embodiments.
  • Figure 7 is a schematic flow chart of another smart contract vulnerability detection method according to one or more embodiments.
  • Figure 8 is a schematic flow chart of another smart contract vulnerability detection method according to one or more embodiments.
  • Figure 9 is a schematic structural diagram of a smart contract vulnerability detection device according to one or more embodiments.
  • Figure 10 is a schematic structural diagram of an electronic device according to one or more embodiments.
  • Smart contract vulnerability detection methods There are two main smart contract vulnerability detection methods that are usually used. One is to extract the inherent operating rules of the existing vulnerabilities and write them into the software, and use the software to detect smart contract vulnerabilities. The other is manual detection through manual viewing. Smart contract logic determines whether there are loopholes.
  • the first method is mostly used to detect discovered vulnerabilities, with limited detection capabilities and low detection accuracy.
  • the second method is very inefficient, and the detection accuracy is limited by the ability of the detection personnel.
  • Some embodiments of the present disclosure apply a virtual machine (or virtual machine server) to perform smart contract vulnerability detection.
  • a smart contract vulnerability detection method includes: the virtual machine first obtains the formal deployment information of the smart contract, and then performs the initialization execution included in the formal behavior list based on the formal initial state included in the formal deployment information. function and behavior function to obtain the execution result of the smart contract, and then detect the execution result of the smart contract according to the formal specification library of the smart contract. Get vulnerability detection results.
  • the vulnerability detection results can indicate whether there are vulnerabilities in the actual operation of the smart contract. Both known and unknown vulnerability types can be detected, so the vulnerability detection accuracy of smart contracts is high.
  • the initialization execution function is executed to verify whether the execution results of all cases are compliant (such as whether they comply with the formal specifications), making the vulnerability detection results of the smart contract more complete and further improving Detection accuracy.
  • the smart contract vulnerability detection method involved in some embodiments of the present disclosure applies formal verification methods to smart contract vulnerability detection.
  • Formal verification methods use mathematical formulas, theorems and systems to verify the functional correctness and security properties of a system. Compared with traditional detection methods, formal verification methods can find inconsistencies between targets and system descriptions. Therefore, using formal verification methods to verify smart contracts can effectively test the security of smart contracts and detect whether there are loopholes in smart contracts.
  • the execution subject of the smart contract vulnerability detection method may be a computer with a virtual machine program deployed, a server, and other electronic devices with data processing capabilities.
  • the server can be a single server, or it can be a server cluster composed of multiple servers. In some implementations, the server cluster may also be a distributed cluster. Furthermore, there is no restriction on the execution subject of the smart contract vulnerability detection method.
  • the following introduction takes the execution subject as a server with a virtual machine deployed as an example.
  • the execution subject of the smart contract vulnerability detection method involved in some embodiments of the present disclosure may be a virtual machine. server.
  • the virtual machine server may be deployed with multiple virtual machines (or virtual machine clusters), and the virtual machine cluster includes at least one virtual machine.
  • the virtual machine can obtain the source code of the smart contract (also known as smart contract or smart contract code).
  • the source code of the smart contract may include functions (such as transfer functions) used to implement transactions between account A and account B and agreed upon transaction rules between account A and account B.
  • the virtual machine can obtain the formal deployment information of the smart contract, and then based on the formal initial state included in the formal deployment information, execute the initialization execution function and behavior function included in the formal behavior list to obtain the execution result of the smart contract, and then based on the smart contract
  • the formal specification library of the contract detects the execution results of the smart contract and obtains the vulnerability detection results.
  • the vulnerability detection results can indicate whether there are vulnerabilities in the actual operation of the smart contract. Both known and unknown vulnerability types can be detected, so the vulnerability detection accuracy of smart contracts is high.
  • the execution subject of the smart contract vulnerability detection method involved in some embodiments of the present disclosure may be a virtual machine server. Running smart contracts directly through the virtual machine server eliminates the need to use proprietary languages for logical conversion of smart contracts, which can lower the threshold for smart contract vulnerability detection.
  • Figure 2 shows a schematic flowchart of a smart contract vulnerability detection method provided by an embodiment of the present disclosure. As shown in Figure 2, the method is executed by a virtual machine (or virtual machine server), and the method may include the following steps.
  • a virtual machine or virtual machine server
  • Step 210 Obtain the formal deployment information of the smart contract.
  • Formal deployment information includes formalized initial states and formalized behavior lists.
  • the formal behavior list includes the initialization execution function and behavior function of the smart contract.
  • formal deployment information can be obtained by parsing the code of the smart contract. For example, you can input the code of a smart contract into a smart contract parser, and the smart contract parser parses the smart contract to obtain a formalized initial state and a formalized behavior list.
  • the smart contract parser can determine the function list that can be called externally and the corresponding parameter list based on the function definition of the smart contract, obtain the formal initial state and the formal behavior list, and the initialization execution function and behavior in the formal behavior list.
  • the function is used to deploy smart contracts in the virtual machine and obtain all formal deployment information.
  • the formal behavior list can be shown in Figure 3.
  • the formal initial state may include: Account A has 100 yuan, and Account B has 0 yuan.
  • the initialization execution function included in the formal behavior list can be: payment function.
  • the payment function has two parameters: target account and transfer amount.
  • the execution rule of this payment function is that the transfer amount is an integer, and the transfer amount ranges from 0 to 255.
  • the formal behavior list includes the following initialization execution functions: A transfers 1 yuan to B, A transfers 100 yuan to B, A transfers 255 yuan to B, and so on.
  • the virtual machine can obtain the smart contract from the electronic device storing the smart contract through communication connection, physical connection, etc., and then parse the smart contract through the smart contract parser to obtain the formalized form. Deployment information.
  • an electronic device deployed with a smart contract can parse the smart contract through a smart contract parser to obtain the formalized initial state and formalized behavior list.
  • the virtual machine can obtain the formalized initial state and formalized behavior list from the electronic device. Behavior list, and use the obtained formal initial state and formal behavior list as formal deployment information.
  • the virtual machine server in Figure 1 can deploy the formal deployment information in the local data repository to obtain the formal deployment information of the smart contract locally, which can reduce the power consumption caused by the virtual machine parsing the smart contract. and processing complexity.
  • the formal initial state may be one or more, and is not limited.
  • Formal deployment information can include all formalized initial states obtained by parsing smart contracts, or can include part of all formalized initial states obtained by parsing smart contracts, such as including all formalized initial states that comply with formal specifications.
  • the formalized initial state that is, the formalized initial state that is screened out for compliance, is used to perform the methods involved in some embodiments of the present disclosure. In some examples, the process of screening out compliant formalized initial states may be described with reference to the embodiment corresponding to FIG. 8 below.
  • Step 220 Based on the formalized initial state, execute the initialization execution function and the behavior function included in the formalized behavior list to obtain the execution result of the smart contract.
  • the execution results of smart contracts include the execution results obtained by executing the initialization execution function. Combined with the example in step 210, initialize the target account in the execution function.
  • the execution result of the smart contract can be: Account A has 90 yuan, and Account B has 10 yuan.
  • the initialization execution function and the behavior function included in the formal behavior list are executed based on the formal initial state
  • the initialization execution function is first executed based on the formal initial state to realize the initialization of the virtual machine, and then in the initialized virtual machine Execute the behavior function to get the execution result of the smart contract.
  • Step 230 Detect the execution result of the smart contract according to the formal specification library of the smart contract to obtain the vulnerability detection result.
  • the formal specification library includes formal specifications for smart contracts. This formal specification is used to describe the requirements that the state of a smart contract should meet, including general specifications and customized formal specifications.
  • General specifications refer to the requirements that all smart contracts need to meet. For example, the sum of the balances of all accounts remains unchanged during the execution of the smart contract, the account balance cannot be negative, the range of integer values is determined, etc.
  • Customized formal specifications refer to the specifications that the currently verified smart contract needs to comply with, for example, the range within which the integer value of the current smart contract should fall.
  • the implementation of the formal specification library can be described in the embodiment corresponding to Figure 7 below.
  • customized formal specifications have a higher priority than general specifications, and for the same constraints, the customized formal specifications shall prevail.
  • the customized formal specification constrains the integer value range to be 0 to 255, while the integer value range determined by the general specification is 0 to 1023, then the 0 to 255 of the customized formal specification shall prevail during the formal verification process.
  • the formal deployment information of the smart contract is first obtained, and then based on the formal initial state included in the formal deployment information, the initialization execution function and the behavior function included in the formal behavior list are executed to obtain the execution result of the smart contract. , and then detect the execution results of the smart contract based on the formal specification library of the smart contract to obtain the vulnerability detection results.
  • the vulnerability detection results can It indicates whether there are vulnerabilities in the actual operation of smart contracts. Both known and unknown vulnerability types can be detected, so the vulnerability detection accuracy of smart contracts can be higher.
  • step 230 the execution result of the smart contract is detected according to the formal specification library of the smart contract.
  • Obtaining the vulnerability detection result may include the following steps 2301 to 2303.
  • Step 2301 For each behavioral function, check whether the execution results of the initialization execution function and the behavioral function comply with the formal specification based on the formalized initial state. If it is consistent, step 2302 is executed; otherwise, if it is not consistent, step 2303 is executed.
  • the formal initial state may include: Account A has 100 yuan, and Account B has 0 yuan.
  • the initialization execution function included in the formal behavior list can be: payment function.
  • the payment function has two parameters: target account and transfer amount.
  • the execution rule of this payment function is that the transfer amount is an integer, and the transfer amount ranges from 0 to 255.
  • Step 2302 Establish an association between the execution result and the formalized initial state, and if the execution result is not included in the formalized deployment information, include the execution result in the formalized deployment information as a new formalized initial state.
  • an association is established between the execution result and the formalized initial state, which can be used to trace the corresponding relationship between the function execution result and the formalized initial state.
  • the execution result is included in the formal deployment information as a new formal initial state, and the new formal initial state can be used to deploy to the virtual machine.
  • Formal specification verification It can improve the possibility of the formalized initial state covering various transaction situations when smart contracts are executed, thereby reducing possible omissions during smart contract detection and improving smart contract detection accuracy.
  • some embodiments of the present disclosure can also show the correlation between the execution result and the formalized initial state through a directed graph.
  • the process illustrated using a directed graph is as follows.
  • a directed graph is established.
  • Building a directed graph can replace the formal initial state building directed graph described by including formal deployment information based on smart contracts.
  • the directed graph includes nodes corresponding to the formalized initial state, and two nodes that are associated are connected by directed edges.
  • establishing an association between the execution result and the formalized initial state may include: if it is consistent, check whether there is a node corresponding to the execution result in the directed graph, and if so, set the point from the initialization state to the node. If the directed edge does not exist, the execution result is added to the directed graph, and a directed edge pointing from the initialization state to the node corresponding to the execution result is set.
  • Figure 5 shows an initially established directed graph.
  • the directed graph can be shown in Figure 5, including three formal initial states of A, B and C. A and B are associated, A and C are associated, and B and C are not associated.
  • the execution result D that is associated with C is added to the directed graph, and the resulting directed graph can be as shown in Figure 6.
  • the correlation between the formalized initial state and the execution result is represented by a directed graph, which can facilitate intuitive display of the corresponding relationship between the execution result and the formalized initial state.
  • Step 2303 Report error information.
  • the execution results of each formalized initial state under each initialization execution function can be checked, the compliant execution results are associated with the formalized initial state, and the non-compliant execution results are reported.
  • the execution results of each formalized initial state under each initialization execution function can be checked, the compliant execution results are associated with the formalized initial state, and the non-compliant execution results are reported.
  • the non-compliant execution results are reported.
  • the execution results of each formalized initial state under each initialization execution function can be checked, the compliant execution results are associated with the formalized initial state, and the non-compliant execution results are reported.
  • the formal specification can be customized to verify the smart contract.
  • the method may also include steps 240 to 250.
  • Step 240 Determine the customized formal specification of the smart contract based on the demand information of the smart contract.
  • the customized formal specifications of the smart contract can be determined based on the demand information of the smart contract. For example, if the smart contract stipulates the transaction rules for account A and account B, and the requirement information of the smart contract is that the total amount between accounts does not exceed 3,000, then the corresponding customized formal specification can be: A+B ⁇ 3000.
  • Step 250 Add the customized formal specification to the formal specification library, so that when executing step 230, the customized formal specification is obtained from the formal specification library, and the execution result of the smart contract is detected to obtain vulnerabilities based on the customized formal specification of the smart contract. Test results.
  • Formal specification library is a type of database used to store formal specifications. It can store formal specifications. In some embodiments of the present disclosure, customized formal specifications are added to the formal specification library, so that the formal specification library can be used to directly call the formal specifications. In addition, custom formal specifications in the formal specification library can meet customization needs.
  • the method in order to improve execution efficiency, before executing step 220, it is also necessary to screen the initialization formal state in the formal deployment information of the smart contract to screen out a valid (or compliant) formal initial state. , thus avoiding the problem of low execution efficiency caused by processing invalid formal initial states.
  • the method is as shown in Figure 8.
  • the formal deployment information includes multiple formal initial states.
  • the method may also include:
  • Step 260 Determine the execution queue according to multiple formalized initial states.
  • the execution queue includes multiple formal initial states that comply with the formal specification.
  • the deployment order of the formal initial states in the virtual machine can be determined through the execution queue to avoid missing the deployment of the formal initial states.
  • step 220: based on the formalized initial state, execute the initialization execution function and the behavior function included in the formalized behavior list may include: based on each formalized initial state in the execution queue, execute the initialized execution function included in the formalized behavior list. Initialize execution functions and behavior functions.
  • each formalized initial state in the execution queue is traversed, and the initialization execution function and behavior function included in the formalized behavior list are executed accordingly, which can improve the ability of the formalized initial state to cover various transaction situations during smart contract execution. possibility, thereby reducing possible omissions during smart contract detection and improving smart contract detection accuracy.
  • the formal initial states in the execution queue are all formal initial states that comply with the formal specifications. Only the initialization execution function is executed for the valid formal initial states, which can avoid processing the invalid formal initial states and causing low execution efficiency. The problem.
  • the method may also include: when there is no formal initial state in the execution queue that is the same as the execution result, Add the execution results to the execution queue as a new formalized initial state.
  • the execution queue does not have the same formalized initial state as the execution result, the execution result is added to the execution queue as a new formalized initial state,
  • the new formalized initial state can be deployed into a virtual machine to perform formal specification verification on the execution results obtained after executing the initialization execution function based on the new formalized initial state. It can improve the possibility that the formalized initial state can cover various transaction situations when smart contracts are executed, thereby reducing possible omissions during smart contract detection and improving smart contract detection accuracy.
  • the above method can be executed based on the execution queue Q and the directed graph G.
  • the process of executing the above method based on the execution queue Q and the directed graph G may include the following steps:
  • step 1 Obtain the formal deployment information of the smart contract, and use the formal detection tool to check whether the formal initialization state meets the formal specifications. If not, an error will be reported directly; if it is met, proceed to step 2. That is, through step 1, the formal initial state included in the formal deployment information is screened to obtain a compliant formal initial state, and the compliant formal initial state is placed in the execution queue Q.
  • the formal initialization state can be one or multiple.
  • each formalized initial state can be subject to vulnerability detection.
  • the execution result is included in the formal deployment information as a new formal initial state, and the new formal initial state can be used to deploy to the virtual machine.
  • Formal specification verification It can improve the possibility of the formalized initial state covering various transaction situations when smart contracts are executed, thereby reducing possible omissions during smart contract detection and improving smart contract detection accuracy.
  • FIGS 1 to 8 describe the smart contract vulnerability detection method.
  • the smart contract vulnerability detection device includes hardware structures and/or software modules that perform corresponding functions.
  • the smart contract vulnerability detection method can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is performed by hardware or computer software driving the hardware depends on the specific application and design constraints of the technical solution. Skilled artisans may implement the described functionality using different methods for each specific application, but such implementations should not be considered to be beyond the scope of some embodiments of the present disclosure.
  • Some embodiments of the present disclosure can exemplarily divide the smart contract vulnerability detection device into functional modules according to the above method.
  • the smart contract vulnerability detection device can be divided into functional modules corresponding to each function, or two or more functions can be integrated into one processing module.
  • the above integrated modules can be implemented in the form of hardware or software function modules. It should be noted that the division of modules in some embodiments of the present disclosure is schematic and is only a logical function division. In actual implementation, there may be other division methods.
  • Figure 9 shows a schematic structural diagram of a smart contract vulnerability detection device according to one or more embodiments.
  • the device may include: an acquisition module 910, used to acquire the formal deployment information of the smart contract.
  • Formal deployment information includes formalized initial states and formalized behavior lists.
  • the formal behavior list includes the initialization execution function and behavior function of the smart contract.
  • the execution module 920 is used to execute the initialization execution function and the behavior function included in the formal behavior list based on the formal initial state to obtain the execution result of the smart contract.
  • the execution results of smart contracts include the execution results obtained by executing the initialization execution function.
  • the detection module 930 is used to detect the execution result of the smart contract according to the formal specification library of the smart contract and obtain the vulnerability detection result.
  • the formal specification library includes formal specifications for smart contracts.
  • the formal deployment information of the smart contract is first obtained, and then based on the formal initial state included in the formal deployment information, the initialization included in the formal behavior list is executed. Execute the function and behavior function to obtain the execution result of the smart contract, and then detect the execution result of the smart contract according to the formal specification library of the smart contract to obtain the vulnerability detection result.
  • the vulnerability detection results can indicate whether there are vulnerabilities in the actual operation of the smart contract. Both known and unknown vulnerability types can be detected.
  • the vulnerability detection accuracy of smart contracts is high.
  • the detection module 930 is configured to: for each behavioral function, detect whether the execution results of the initialization execution function and the behavioral function comply with the formal specification based on the formalized initial state. If consistent, the execution result is associated with the formal initial state, and if the execution result is not included in the formal deployment information, the execution result is included in the formal deployment information as a new formal initial state. If it does not match, an error message will be reported.
  • the apparatus further includes a build module.
  • the build module is configured to build directed graphs.
  • the directed graph includes nodes corresponding to the formalized initial state, and two nodes that are associated are connected by directed edges.
  • the detection module 930 is configured to: if it matches, check whether there is a node corresponding to the execution result in the directed graph; if it exists, set a directed edge pointing from the initialization state to the node; if it does not exist, add the execution result to In the directed graph, a directed edge pointing from the initialization state to the node corresponding to the execution result is also set.
  • the formal deployment information includes a plurality of formal initial states.
  • the device also includes a determination module.
  • the determination module is configured to determine an execution queue based on a plurality of formalized initial states.
  • the execution queue includes multiple formal initial states that comply with the formal specification.
  • the execution module 920 is configured to: execute the initialization execution function and the behavior function included in the formal behavior list based on each formalized initial state in the execution queue.
  • the apparatus further includes a determining module and an adding module.
  • the determination module is configured to determine a customized formal specification of the smart contract based on the requirement information of the smart contract.
  • the add module is configured to add custom formal specifications to the formal specification library.
  • the formal specification library also includes a universal specification for representing the formal specification of each smart contract in the plurality of smart contracts.
  • the device also includes replacement modules.
  • the replacement module is configured to replace the generic specification with a custom formal specification of the smart contract.
  • the acquisition module is configured to: acquire the smart contract, and parse the smart contract to obtain the formalized initial state and the formalized behavior list.
  • the smart contract is stored in the electronic device, and the virtual machine server and the electronic device are communicatively connected.
  • the acquisition module is configured to: acquire the smart contract from the electronic device.
  • each of the plurality of formalized initial states conforms to the formal specification, or a portion of the plurality of formalized initial states conforms to the formal specification.
  • the virtual machine server is configured with a data repository.
  • the device After obtaining the formal deployment information of the smart contract, the device also includes a storage module.
  • the storage module is configured to store the formal deployment information of the smart contract in the data repository.
  • the initialization execution function is used to initialize the virtual machine server.
  • behavioral functions are used to represent trading rules when trading between different accounts.
  • the formal deployment information of the smart contract is first obtained, and then based on the formal initial state included in the formal deployment information, the initialization execution function and the behavior function included in the formal behavior list are executed to obtain the execution result of the smart contract. , and then detect the execution results of the smart contract based on the formal specification library of the smart contract to obtain the vulnerability detection results.
  • the vulnerability detection results can indicate whether there are vulnerabilities in the actual operation of the smart contract. Both known and unknown vulnerability types can be detected.
  • the vulnerability detection accuracy of smart contracts is high.
  • Figure 10 shows a schematic structural diagram of an electronic device according to one or more embodiments.
  • the device may include a processor 101 and a memory 102 storing computer program instructions.
  • the processor 101 may include a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits that may be configured to implement some embodiments of the present disclosure.
  • CPU central processing unit
  • ASIC application specific integrated circuit
  • Memory 102 may include mass storage for data or instructions.
  • the memory 102 may include a hard disk drive (HDD), a floppy disk drive, flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a Universal Serial Bus (USB) drive or two or more A combination of many of the above.
  • memory 102 may include removable or non-removable (or fixed) media, or memory 102 may be non-volatile solid-state memory.
  • the memory 102 may be internal or external to the integrated gateway disaster recovery device.
  • the memory 102 may be a read-only memory (Read Only Memory, ROM).
  • ROM Read Only Memory
  • the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (EEPROM), an electrically rewritable ROM (EAROM), or flash memory, or both.
  • PROM programmable ROM
  • EPROM erasable PROM
  • EEPROM electrically erasable PROM
  • EAROM electrically rewritable ROM
  • the processor 101 is configured to read and execute the computer program instructions stored in the memory 102 to implement the method in the embodiment shown in Figure 2 and achieve the corresponding technical effects achieved by executing the method in the example shown in Figure 2. For the sake of concise description I won’t go into details here.
  • the electronic device may also include a communication interface 103 and a bus 110 .
  • the processor 101, the memory 102, and the communication interface 103 are connected through the bus 110 and complete communication with each other.
  • the communication interface 103 is mainly used to implement communication between modules, devices, units and/or equipment in some embodiments of the present disclosure.
  • Bus 110 may include hardware, software, or both, coupling components of the online data traffic metering device to one another.
  • the bus may include Accelerated Graphics Port (AGP) or other graphics bus, Enhanced Industry Standard Architecture (EISA) bus, Front Side Bus (FSB), Ultra Transmission (Hyper Transport, HT) interconnect, Industry Standard Architecture (ISA) bus, infinite bandwidth interconnect, low pin count (LPC) bus, memory bus, Micro Channel Architecture (MCA) bus, peripheral component interconnect (PCI) bus, PCI-Express (PCI-X) bus, Serial Advanced Technology Attachment (SATA) bus, Video Electronics Standards Association Local (VLB) bus or other suitable bus, or two or more of these combination.
  • bus 110 may include one or more buses. Although some embodiments of the present disclosure describe and illustrate a specific bus, any suitable bus or interconnection is contemplated as a substitution.
  • the electronic device can execute the smart contract vulnerability detection method in some embodiments of the present disclosure, thereby achieving the corresponding technical effects of the smart contract vulnerability detection method described in Figure 2.
  • some embodiments of the present disclosure may provide a computer-readable storage medium (for example, a non-transitory computer-readable storage medium).
  • Computer program instructions are stored on the computer-readable storage medium, and when executed by the processor, the computer program instructions implement any of the smart contract vulnerability detection methods in the above embodiments.
  • a computer-readable storage medium may include a hard disk drive (HDD), a floppy disk drive, flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a Universal Serial Bus (USB) drive or both.
  • HDD hard disk drive
  • floppy disk drive flash memory
  • optical disk an optical disk
  • magneto-optical disk a magnetic tape
  • USB Universal Serial Bus
  • the computer-readable storage medium may include removable or non-removable (or fixed) media, or the computer-readable storage medium may be non-volatile solid-state memory.
  • the computer-readable storage medium may be internal or external to the comprehensive gateway disaster recovery device.
  • some embodiments of the present disclosure also provide a computer program product.
  • the computer program product When the computer program product is run on a computer, the computer implements the smart contract vulnerability detection method in the above embodiments.
  • the disclosed devices and methods can be implemented in other ways.
  • the device embodiments described above are only illustrative.
  • the division of modules or units is only a logical function division.
  • there may be other division methods for example, multiple units or components may be combined or can be integrated into another device, or some features can be ignored, or not implemented.
  • the coupling or direct coupling or communication connection between each other shown or discussed may be through some interfaces, and the indirect coupling or communication connection of the devices or units may be in electrical, mechanical or other forms.
  • a unit described as a separate component may or may not be physically separate.
  • a component shown as a unit may be one physical unit or multiple physical units, that is, it may be located in one place, or it may be distributed to multiple different places. Some or all of the units may be selected according to actual needs to implement some embodiments of the present disclosure.
  • each functional unit in various embodiments of the present disclosure may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit.
  • the above integrated units can be implemented in the form of hardware or software functional units.
  • Integrated units may be stored in a readable storage medium if they are implemented in the form of software functional units and sold or used as independent products. Based on this understanding, the technical solutions of some embodiments of the present disclosure may be embodied in essence or all or part of the technical solutions in the form of a software product.
  • the software product is stored in a storage medium and includes a number of instructions to enable a device. (It can be a microcontroller, a chip, etc.) or a processor (processor) to execute all or part of the steps of the methods described in various embodiments of the present disclosure.
  • the aforementioned storage media include: U disk, mobile hard disk, ROM, RAM, magnetic disk or optical disk and other media that can store program codes.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Health & Medical Sciences (AREA)
  • Computing Systems (AREA)
  • General Health & Medical Sciences (AREA)
  • Virology (AREA)
  • Multimedia (AREA)
  • Technology Law (AREA)
  • Debugging And Monitoring (AREA)
  • Stored Programmes (AREA)

Abstract

一种智能合约漏洞检测方法包括:获取智能合约的形式化部署信息,其中形式化部署信息包括形式化初始状态以及形式化行为列表,形式化行为列表包括智能合约的初始化执行函数和行为函数;基于形式化初始状态,执行形式化行为列表包括的初始化执行函数和行为函数,得到智能合约的执行结果;根据智能合约的形式化规范库检测智能合约的执行结果,得到漏洞检测结果,该形式化规范库包括智能合约的形式化规范。该方法涉及区块链技术领域,可提高对智能合约进行漏洞检测的检测精度。

Description

智能合约漏洞检测方法、装置和设备
本申请要求于2022年06月27日提交的、申请号为202210736727.0的中国专利申请的优先权,其全部内容通过引用结合在本文中。
技术领域
本公开涉及区块链技术领域,尤其涉及智能合约漏洞检测方法、装置和设备。
背景技术
区块链是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。区块链是使用去中心化共识机制去维护一个完整的、分布式的、不可篡改的账本数据库的技术,它能够让区块链中的参与者在无需建立信任关系的前提下实现一个统一的账本系统。在区块链中,以数字化的形式写入智能合约,一个智能合约是一套以数字形式定义的承诺,包括合约参与方可以在上面执行这些承诺的协议。智能合约和区块链技术的特性相结合,可以使得账本系统的存储、读取、执行整个过程透明可追踪、不可篡改。同时,由区块链自带的共识算法构建出一套状态机系统,使得智能合约能够高效地运行。
发明内容
一方面,本公开一些实施例提供一种智能合约漏洞检测方法,应用于虚拟机服务器,包括:获取智能合约的形式化部署信息,其中形式化部署信息包括形式化初始状态以及形式化行为列表,形式化行为列表包括智能合约的初始化执行函数和行为函数;基于形式化初始状态,执行形式化行为列表包括的初始化执行函数和行为函数,得到智能合约的执行结果;根据智能合约的形式化规范库检测智能合约的执行结果,得到漏洞检测结果,其中形式化规范库包括智能合约的形式化规范。
在一些实施例中,根据智能合约的形式化规范库检测智能合约的执行结果,得到漏洞检测结果,包括:对于每个行为函数,检测基于形式化初始状态,执行初始化执行函数和行为函数的执行结果是否符合形式化规范;若符合,则将执行结果与形式化初始状态建立关联关系,以及在执行结果未包括在形式化部署信息中的情况下,将执行结果作为新的形式化初始状态包括在形式化部署信息中;若不符合,则上报错误信息。
在一些实施例中,该方法还包括:建立有向图,有向图包括与形式化初 始状态对应的节点,存在关联关系的两个节点用有向边连接。若符合,则将执行结果作为与形式化初始状态建立关联关系,包括:若符合,则查看有向图中是否存在与执行结果对应的节点,若存在,则设置从初始化状态指向节点的有向边,若不存在,则将执行结果添加到有向图中,同时设置从初始化状态指向执行结果对应的节点的有向边。
在一些实施例中,形式化部署信息包括多个形式化初始状态。该方法还包括:根据多个形式化初始状态确定执行队列,其中执行队列包括多个形式化初始状态中符合形式化规范的形式化初始状态。基于形式化初始状态,执行形式化行为列表包括的初始化执行函数和行为函数,包括:基于执行队列中的每一个形式化初始状态,执行形式化行为列表包括的初始化执行函数和行为函数。
在一些实施例中,该方法还包括:根据智能合约的需求信息确定智能合约的定制形式化规范;将定制形式化规范添加到形式化规范库中。
在一些实施例中,形式化规范库还包括通用规范,通用规范用于表示多个智能合约中的每个智能合约的形式化规范。将定制形式化规范添加到形式化规范库中之后,该方法还包括:将通用规范替换为智能合约的定制形式化规范。
在一些实施例中,获取智能合约的形式化部署信息,包括:获取智能合约;以及对智能合约进行解析,得到形式化初始状态以及形式化行为列表。
在一些实施例中,智能合约存储于电子设备中,虚拟机服务器和电子设备之间通信连接。获取智能合约,包括:获取来自于电子设备的智能合约。
在一些实施例中,多个形式化初始状态中的每个形式化初始状态符合形式化规范,或者,多个形式化初始状态中的部分形式化初始状态符合形式化规范。
在一些实施例中,虚拟机服务器配置有数据存储库。获取智能合约的形式化部署信息之后,该方法还包括:将智能合约的形式化部署信息存储在数据存储库中。
在一些实施例中,初始化执行函数用于对虚拟机服务器进行初始化。
在一些实施例中,行为函数用于表示不同账户之间进行交易时的交易规则。
另一方面,本公开一些实施例提供一种智能合约漏洞检测装置,应用于虚拟机服务器,包括:获取模块,被配置为获取智能合约的形式化部署信息,其中形式化部署信息包括形式化初始状态以及形式化行为列表,形式化行为 列表包括智能合约的初始化执行函数和行为函数;执行模块,被配置为基于形式化初始状态,执行形式化行为列表包括的初始化执行函数和行为函数,得到智能合约的执行结果;以及检测模块,被配置为根据智能合约的形式化规范库检测智能合约的执行结果,得到漏洞检测结果,其中形式化规范库包括智能合约的形式化规范。
另一方面,本公开一些实施例提供一种电子设备,包括:存储器,处理器及存储在存储器上并可在处理器上运行的计算机程序,计算机程序在被处理器执行时实现如第一方面的智能合约漏洞检测方法。
另一方面,本公开一些实施例提供一种计算机可读存储介质,计算机可读存储介质上存储有计算机程序,计算机程序在被处理器执行时实现如第一方面的智能合约漏洞检测方法。
附图说明
图1为根据一个或多个实施例的一种智能合约漏洞检测方法的应用场景示意图;
图2为根据一个或多个实施例的一种智能合约漏洞检测方法的流程示意图;
图3为根据一个或多个实施例的一种形式化行为列表的示意图;
图4为根据一个或多个实施例的另一种智能合约漏洞检测方法的流程示意图;
图5为根据一个或多个实施例的一种有向图示意图;
图6为根据一个或多个实施例的另一种有向图示意图;
图7为根据一个或多个实施例的另一种智能合约漏洞检测方法的流程示意图;
图8为根据一个或多个实施例的另一种智能合约漏洞检测方法的流程示意图;
图9为根据一个或多个实施例的一种智能合约漏洞检测装置的结构示意图;
图10为根据一个或多个实施例的一种电子设备的结构示意图。
具体实施方式
下面将详细描述本公开的各个方面的特征和示例性实施例。为了使本公开面临的技术问题、采用的技术方案及优点更加清楚明白,以下结合附图及具体实施例,对本公开进行进一步详细描述。应理解,此处所描述的具体实 施例仅被配置为解释本公开,并不被配置为限定本公开。对于本领域技术人员来说,本公开可以在不需要这些具体细节中的一些细节的情况下实施。下面对实施例的描述仅仅是为了通过示出本公开的示例来提供对本公开更好的理解。
需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序;也不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”的特征可以明示或者隐含地包括一个或者更多个该特征。在本实施例的描述中,除非另有说明,“多个”的含义是两个或两个以上。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。
此外,说明书和/或权利要求中所使用的术语“一(a或an)”将被解释为表示“至少一个”。
通常主要采用的智能合约漏洞检测方法有两种,一种是将已出现的漏洞提取出固有的运行规则编写到软件中,使用软件进行智能合约漏洞检测,另一种是人工检测,通过人工查看智能合约逻辑,判断是否存在漏洞。但是第一种方法多用于检测已发现的漏洞,检测能力有限,检测精度较低。第二种方法效率很低,且检测精度受限于检测人员能力。
综上所述,通常采用的智能合约漏洞检测方法精度较低。
为了解决上述技术问题,且考虑到智能合约运行在虚拟机中时,会根据虚拟机的运行规则适应性改变运行逻辑,可能导致运行过程中出现意料外的漏洞。本公开一些实施例应用虚拟机(或者称为虚拟机服务器)进行智能合约漏洞检测。
相应地,提供一种智能合约漏洞检测方法,该方法包括:虚拟机首先获取智能合约的形式化部署信息,然后基于形式化部署信息包括的形式化初始状态,执行形式化行为列表包括的初始化执行函数和行为函数,得到智能合约的执行结果,再根据智能合约的形式化规范库检测智能合约的执行结果, 得到漏洞检测结果。该漏洞检测结果能够表征智能合约在实际运行时是否存在漏洞,无论是已知漏洞类型还是未知漏洞类型均可以检测出,因此智能合约的漏洞检测精度较高。
此外,对于智能合约的每个形式化初始状态,均执行初始化执行函数,验证所有案例的执行结果是否合规(比如是否符合形式化规范),使得智能合约的漏洞检测结果更完善,可进一步提高检测精度。
本公开一些实施例涉及的智能合约漏洞检测方法将形式化验证方法运用到智能合约漏洞检测中。形式化验证方法是使用数学的公式、定理和系统来验证一个系统的功能正确性和安全属性。与传统检测方法相比,形式化验证方法可以发现目标与系统描述的不一致性问题。因此使用形式化验证方法来验证智能合约,可以有效的检验智能合约的安全性,检测智能合约是否存在漏洞。
本公开一些实施例提供的智能合约漏洞检测方法的执行主体可以是部署了虚拟机程序的计算机、服务器等具有数据处理能力的电子设备。服务器可以是单独的一个服务器,或者,也可以是由多个服务器构成的服务器集群。部分实施方式中,服务器集群还可以是分布式集群。进一步地,对该智能合约漏洞检测方法的执行主体不作限制。下面以执行主体为部署有虚拟机的服务器为例进行介绍。
参照图1,为根据一个或多个实施例的一种智能合约漏洞检测方法的应用场景示意图,如图1所示,本公开一些实施例涉及的智能合约漏洞检测方法的执行主体可以是虚拟机服务器。该虚拟机服务器可以部署有多个虚拟机(或者称为虚拟机集群)的服务器,该虚拟机集群包括至少一台虚拟机。该虚拟机能够获取到智能合约的源代码(或者称为智能合约或者智能合约代码)。例如,该智能合约的源代码可以包括用于实现账户A和账户B之间交易的函数(比如转账函数)以及约定账户A和账户B之间的交易规则。
该虚拟机可以获取智能合约的形式化部署信息,然后基于形式化部署信息包括的形式化初始状态,执行形式化行为列表包括的初始化执行函数和行为函数,得到智能合约的执行结果,再根据智能合约的形式化规范库检测智能合约的执行结果,得到漏洞检测结果。该漏洞检测结果能够表征智能合约在实际运行时是否存在漏洞,无论是已知漏洞类型还是未知漏洞类型均可以检测出,因此智能合约的漏洞检测精度较高。
本公开一些实施例涉及的智能合约漏洞检测方法的执行主体可以为虚拟机服务器。通过虚拟机服务器直接运行智能合约,不需要使用专有语言进行智能合约的逻辑转换,可降低智能合约漏洞检测门槛。
图2示出了本公开一个实施例提供的智能合约漏洞检测方法的流程示意图。如图2所示,该方法由虚拟机(或者称为虚拟机服务器)执行,该方法可以包括以下步骤。
步骤210,获取智能合约的形式化部署信息。
形式化部署信息包括形式化初始状态以及形式化行为列表。形式化行为列表包括智能合约的初始化执行函数和行为函数。初始化执行函数可以有一个,能够用来根据形式化初始状态对部署智能合约的虚拟机进行初始化,行为函数可以有多个,分别在初始化后的虚拟机中执行智能合约的各个功能。
本公开一些实施例中,形式化部署信息可以通过解析智能合约的代码而得到。比如可以将智能合约的代码输入智能合约解析器,智能合约解析器解析智能合约得到形式化初始状态以及形式化行为列表。例如,智能合约解析器可以根据智能合约的函数定义,确定可被外部调用的函数列表以及对应的参数列表,得到形式化初始状态以及形式化行为列表,形式化行为列表中的初始化执行函数和行为函数用来在虚拟机中部署智能合约,进而得到全部的形式化部署信息。形式化行为列表可以如图3所示。
在一些示例中,形式化初始状态可以包括:账户A有100元,账户B有0元。形式化行为列表包括的初始化执行函数可以是:付款函数。该付款函数的参数有两个:目标账户和转账金额。并且,该付款函数的执行规则为转账金额为整数,且转账金额取值范围为0到255。比如形式化行为列表包含以下初始化执行函数:A给B转1元、A给B转100元、A给B转255元等等。
一种可能的方式中,结合图1,虚拟机可以从存储有智能合约的电子设备上通过通信连接,物理连接等方式获取到智能合约,然后通过智能合约解析器解析智能合约即可得到形式化部署信息。又一种可能的方式中,部署有智能合约的电子设备可以通过智能合约解析器解析智能合约得到形式化初始状态以及形式化行为列表,虚拟机可以从该电子设备获取形式化初始状态以及形式化行为列表,并将获取到的形式化初始状态以及形式化行为列表作为形式化部署信息。进一步的,图1中的虚拟机服务器可以将形式化部署信息部署在本地的数据存储库中,以便从本地获取智能合约的形式化部署信息,如此可降低虚拟机解析智能合约带来的功率消耗以及处理复杂度。
需要说明的是,本公开一些实施例中,形式化初始状态可以是一个或者多个,不予限制。形式化部署信息可以包括解析智能合约得到的所有形式化初始状态,也可以包括解析智能合约得到的所有形式化初始状态中的部分形式化初始状态,比如包括所有形式化初始状态中符合形式化规范的形式化初始状态,即筛查出合规的形式化初始状态执行本公开一些实施例涉及的方法。在一些示例中,筛查出合规的形式化初始状态的过程可以参照下述图8对应的实施例中所述。
步骤220,基于形式化初始状态,执行形式化行为列表包括的初始化执行函数和行为函数,得到智能合约的执行结果。
智能合约的执行结果包括执行初始化执行函数得到的执行结果。结合步骤210中的示例,初始化执行函数中的目标账户。
例如,智能合约的执行结果可以是:账户A有90元,账户B有10元。
进一步地,再基于形式化初始状态执行形式化行为列表包括的初始化执行函数和行为函数时,首先基于形式化初始状态执行初始化执行函数,以实现虚拟机的初始化,再于初始化后的虚拟机中执行行为函数,即可得到智能合约的执行结果。
步骤230,根据智能合约的形式化规范库检测智能合约的执行结果,得到漏洞检测结果。
形式化规范库包括智能合约的形式化规范。该形式化规范用来描述智能合约的状态应该满足的要求,包括通用规范和定制形式化规范。通用规范是指所有智能合约都需要符合的要求,例如,智能合约执行过程中所有账户的余额之和不变,账户余额不能为负值,确定整数取值范围等。定制形式化规范是指当前验证的智能合约需要遵守的规范,例如,当前智能合约整数取值应属的范围。例如,形式化规范库的实现方式可以参照下述图7对应的实施例中所述。
本公开一些实施例中,定制形式化规范的优先级高于通用规范,对于相同的约束以定制形式化规范为准。例如定制形式化规范约束了整数取值范围是0到255,而通用规范确定的整数取值范围是0到1023,则形式化验证过程中以定制形式化规范的0到255为准。
本公开一些实施例中,首先获取智能合约的形式化部署信息,然后基于形式化部署信息包括的形式化初始状态,执行形式化行为列表包括的初始化执行函数和行为函数,得到智能合约的执行结果,再根据智能合约的形式化规范库检测智能合约的执行结果,得到漏洞检测结果。该漏洞检测结果能够 表征智能合约在实际运行时是否存在漏洞,无论是已知漏洞类型还是未知漏洞类型均可以检测出,因此智能合约的漏洞检测精度可较高。
在一些实施例中,如图4所示,步骤230中根据智能合约的形式化规范库检测智能合约的执行结果,得到漏洞检测结果可以包括下述步骤2301-步骤2303。
步骤2301,对于每个行为函数,检测基于形式化初始状态,执行初始化执行函数和行为函数的执行结果是否符合形式化规范。若符合,则执行步骤2302,反之,若不符合,则执行步骤2303。
通过比对形式化规范与执行结果即可确定执行结果是否符合形式化规范。
在一些示例中,形式化初始状态可以包括:账户A有100元,账户B有0元。形式化行为列表包括的初始化执行函数可以是:付款函数。该付款函数的参数有两个:目标账户和转账金额。该付款函数的执行规则为转账金额为整数,且转账金额取值范围为0到255。形式化规范为:账户总金额不变即总金额为100,账户余额不能为负,则形式化规范表示为A+B=100∩A≥0∩B≥0。
在执行转账函数时,由于转账金额取值范围为0到255,因此会依次执行A给B转账0元、A给B转1元、……、A给B转账255元。对于每一次转账函数的执行结果,均确定执行结果是否符合形式化规范。
例如,执行结果为账户A有10元,账户B有100元,A+B=110,大于100,则执行结果不符合形式化规范。
步骤2302,将执行结果与形式化初始状态建立关联关系,以及在执行结果未包括在形式化部署信息中的情况下,将执行结果作为新的形式化初始状态包括在形式化部署信息中。
本公开一些实施例中,将执行结果与形式化初始状态建立关联关系,可用于溯源函数执行结果与形式化初始状态的对应关系。在执行结果未包括在形式化部署信息中的情况下,将执行结果作为新的形式化初始状态包括在形式化部署信息中,新的形式化初始状态又可以用于部署到虚拟机中,进行形式化规范验证。可提高形式化初始状态覆盖智能合约执行时各种交易情况的可能性,进而减少智能合约检测过程中可能出现的遗漏,提高智能合约检测精度。
进一步地,为了更直观的溯源函数执行结果与形式化初始状态的对应关系,本公开一些实施例还可以通过有向图的方式示出执行结果与形式化初始状态之间的关联关系。在一些示例中,采用有向图示出的过程如下。
在执行步骤230之前或者步骤210之前,建立有向图。
建立有向图可以替换描述为基于智能合约的形式化部署信息包括的形式化初始状态建立有向图。有向图包括与形式化初始状态对应的节点,存在关联关系的两个节点用有向边连接。
进一步地,步骤2302中将执行结果作为与形式化初始状态建立关联关系,可以包括:若符合,则查看有向图中是否存在与执行结果对应的节点,若存在,则设置从初始化状态指向节点的有向边,若不存在,则将执行结果添加到有向图中,同时设置从初始化状态指向执行结果对应的节点的有向边。
在一些示例中,图5为初始建立的一个有向图。有向图可以如图5所示,包括A、B和C三个形式化初始状态,A与B存在关联关系,A与C存在关联关系,B与C不存在关联关系。
参照图5所示有向图,在该有向图中添加了与C存在关联关系的执行结果D,得到的有向图可以如图6所示。
本公开一些实施例中,通过有向图表征形式化初始状态与执行结果的关联关系,可便于直观展示执行结果与形式化初始状态的对应关系。
步骤2303,上报错误信息。
本公开一些实施例中,在初始化执行函数的执行结果是不符合形式化规范的情况下,上报错误信息,可及时示警智能合约存在的问题。
基于图4所示方法,可以查验每个形式化初始状态在每个初始化执行函数下的执行结果,将合规的执行结果与形式化初始状态建立关联关系,将不合规的执行结果上报,以便溯源合规的函数执行结果与形式化初始状态的对应关系,以及及时示警智能合约中存在的不合规到的函数执行结果。
在一些实施例中,为了满足定制化需求,可以定制形式规范用来验证智能合约,如图7所示,执行步骤230之前,该方法还可以包括步骤240-步骤250。
步骤240,根据智能合约的需求信息确定智能合约的定制形式化规范。
不同的智能合约具备不同的需求信息,根据智能合约的需求信息可确定智能合约的定制形式化规范。例如,智能合约约定了账户A和账户B的交易规则,智能合约的需求信息为账户之间的金额总和不超过3000,则相应确定出的定制形式化规范可以是:A+B<3000。
由于形式化验证是执行所有可能的案例进行验证,因此为了降低形式化验证的花费时间,在实际运行过程中,可以根据实际需求使用定制形式化规范替换通用形式化规范,以降低可能出现的案例数量。
步骤250,将定制形式化规范添加到形式化规范库中,以便执行步骤230时,从形式化规范库中获取定制形式化规范,根据智能合约的定制形式化规范检测智能合约的执行结果得到漏洞检测结果。
形式化规范库是用于存储形式化规范的一类数据库,可存储形式化规范。本公开一些实施例中,将定制形式化规范添加到形式化规范库中,便于应用形式化规范库直接调用形式化规范。此外,形式化规范库中的定制形式化规范可以满足定制化需求。
在一些实施例中,为提高执行效率,在执行步骤220之前,还需要对智能合约的形式化部署信息中的初始化形式状态进行筛查,筛查出有效(或者合规)的形式化初始状态,从而可避免对无效的形式化初始状态进行处理导致执行效率低下的问题。在一些示例中,该方法如图8所示,形式化部署信息包括多个形式化初始状态,该方法还可以包括:
步骤260,根据多个形式化初始状态确定执行队列。执行队列中包括多个形式化初始状态中符合形式化规范的形式化初始状态。
形式化初始状态可以是多个,可以通过执行队列确定形式化初始状态在虚拟机中的部署顺序,避免遗漏部署形式化初始状态。
在一些示例中,步骤220:基于形式化初始状态,执行形式化行为列表包括的初始化执行函数和行为函数,可以包括:基于执行队列中的每一个形式化初始状态,执行形式化行为列表包括的初始化执行函数和行为函数。
本公开一些实施例中,遍历执行队列中的每一个形式化初始状态,相应执行形式化行为列表包括的初始化执行函数和行为函数,可提高形式化初始状态能够覆盖智能合约执行时各种交易情况的可能性,进而减少智能合约检测过程中可能出现的遗漏,提高智能合约检测精度。并且,执行队列中的形式化初始状态均为符合形式化规范的形式化初始状态,仅对有效的形式化初始状态执行初始化执行函数,可避免对无效的形式化初始状态进行处理导致执行效率低下的问题。
在一些实施例中,为了不遗漏可能存在的交易情况,提高对智能合约进行检查的全面性,该方法还可以包括:在执行队列中不存在与执行结果相同的形式化初始状态的情况下,将执行结果作为新的形式化初始状态添加到执行队列中。
本公开一些实施例中,在执行队列中不存在与执行结果相同的形式化初始状态的情况下,将执行结果作为新的形式化初始状态添加到执行队列中, 新的形式化初始状态又可以用于部署到虚拟机中,对基于新的形式化初始状态执行初始化执行函数后得到的执行结果进行形式化规范验证。可提高形式化初始状态能够覆盖智能合约执行时各种交易情况的可能性,进而减少智能合约检测过程中可能出现的遗漏,提高智能合约检测精度。
下面结合示例,对上述方法进行详细介绍:
首先在虚拟机内部创建一个执行队列Q和一个有向图G,执行队列Q可以参考步骤260中对执行队列的说明,有向图G可以参考图5以及步骤2302中的有向图说明。基于该执行队列Q和有向图G可以执行上述方法。基于该执行队列Q和有向图G执行上述方法的过程可以包括如下步骤:
①获取智能合约的形式化部署信息,通过形式化检测工具检查形式化初始化状态是否满足形式化规范,如果不满足,直接报错;如果满足则执行步骤②。即通过步骤①实现对形式化部署信息中包括的形式化初始状态进行筛查得到合规的形式化初始状态,将合规的形式化初始状态放到执行队列Q中。
②将满足形式化规范的形式化初始化状态放入执行队列Q中,同时将形式化初始化状态作为节点添加到有向图G中。形式化初始化状态可以是一个,也可以是多个。
③当执行队列Q不为空时,执行下述步骤1)~步骤4):
1)弹出执行队列Q中的第一个形式化初始化状态s,用s执行初始化执行函数以实现虚拟机的初始化。
2)执行形式化行为列表中所有的行为函数,并将每个行为函数执行后的结果放入集合Set中。
3)如果Set不为空:对于Set中的每一个元素t,执行如下操作,并再执行完如下操作后,将元素t从Set中删除:
检测t是否符合形式化规范,如果不符合,报告错误。
如果符合,则检查t是否已存在于有向图G中,如果存在则添加一条s到t的有向边,如果不存在,则将t添加到执行队列Q中,并添加到有向图中,同时在有向图中添加一条s指向t的有向边。
4)如果Set为空,则继续处理执行队列Q中的下一个形式化初始状态。重复执行上述步骤1)~4),当所有可能的情况(即执行队列中所有的形式化初始状态)都执行完毕后,执行队列Q为空,结束。
本公开一些实施例中,通过遍历执行队列中包括形式化初始状态的形式 确保各形式化初始状态均能被执行漏洞检测。在执行结果未包括在形式化部署信息中的情况下,将执行结果作为新的形式化初始状态包括在形式化部署信息中,新的形式化初始状态又可以用于部署到虚拟机中,进行形式化规范验证。可提高形式化初始状态覆盖智能合约执行时各种交易情况的可能性,进而减少智能合约检测过程中可能出现的遗漏,提高智能合约检测精度。
图1-图8描述了智能合约漏洞检测方法,下面结合图9和图10描述本公开一些实施例提供的装置。为了实现上述功能,智能合约漏洞检测装置包含了执行各个功能相应的硬件结构和/或软件模块。本领域技术人员应该很容易意识到,结合本文中所公开的实施例描述的各示例的算法步骤,智能合约漏洞检测方法能够以硬件或硬件和计算机软件的结合形式来实现。某个功能究竟以硬件还是计算机软件驱动硬件的方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本公开一些实施例的范围。
本公开一些实施例可以根据上述方法,示例性的对智能合约漏洞检测装置进行功能模块的划分。智能合约漏洞检测装置可以对应各个功能划分各个功能模块,也可以将两个或两个以上的功能集成在一个处理模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。需要说明的是,本公开一些实施例中对模块的划分是示意性的,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。
图9示出了根据一个或多个实施例的一种智能合约漏洞检测装置的结构示意图,图9所示装置中各模块具有实现图2中各个步骤的功能,并能达到其相应技术效果。如图9所示,该装置可以包括:获取模块910,用于获取智能合约的形式化部署信息。形式化部署信息包括形式化初始状态以及形式化行为列表。形式化行为列表包括智能合约的初始化执行函数和行为函数。执行模块920,用于基于形式化初始状态,执行形式化行为列表包括的初始化执行函数和行为函数,得到智能合约的执行结果。智能合约的执行结果包括执行初始化执行函数得到的执行结果。检测模块930,用于根据智能合约的形式化规范库检测智能合约的执行结果,得到漏洞检测结果。形式化规范库包括智能合约的形式化规范。
本公开一些实施例中,首先获取智能合约的形式化部署信息,然后基于形式化部署信息包括的形式化初始状态,执行形式化行为列表包括的初始化 执行函数和行为函数,得到智能合约的执行结果,再根据智能合约的形式化规范库检测智能合约的执行结果,得到漏洞检测结果。该漏洞检测结果能够表征智能合约在实际运行时是否存在漏洞,无论是已知漏洞类型还是未知漏洞类型均可以检测出,智能合约的漏洞检测精度较高。
在一些实施例中,检测模块930被配置为:对于每个行为函数,检测基于形式化初始状态,执行初始化执行函数和行为函数的执行结果是否符合形式化规范。若符合,则将执行结果与形式化初始状态建立关联关系,以及在执行结果未包括在形式化部署信息中的情况下,将执行结果作为新的形式化初始状态包括在形式化部署信息中。若不符合,则上报错误信息。
在一些实施例中,装置还包括建立模块。建立模块被配置为建立有向图。有向图包括与形式化初始状态对应的节点,存在关联关系的两个节点用有向边连接。检测模块930被配置为:若符合,则查看有向图中是否存在与执行结果对应的节点,若存在,则设置从初始化状态指向节点的有向边,若不存在,则将执行结果添加到有向图中,同时设置从初始化状态指向执行结果对应的节点的有向边。
在一些实施例中,形式化部署信息包括多个形式化初始状态。装置还包括确定模块。确定模块被配置为:根据多个形式化初始状态确定执行队列。执行队列中包括多个形式化初始状态中符合形式化规范的形式化初始状态。执行模块920被配置为:基于执行队列中的每一个形式化初始状态,执行形式化行为列表包括的初始化执行函数和行为函数。
在一些实施例中,装置还包括确定模块和添加模块。确定模块被配置为,根据智能合约的需求信息确定智能合约的定制形式化规范。添加模块被配置为,将定制形式化规范添加到形式化规范库中。
在一些实施例中,形式化规范库还包括通用规范,通用规范用于表示多个智能合约中的每个智能合约的形式化规范。装置还包括替换模块。替换模块被配置为,将通用规范替换为智能合约的定制形式化规范。
在一些实施例中,获取模块被配置为:获取智能合约,以及对智能合约进行解析,得到形式化初始状态以及形式化行为列表。
在一些实施例中,智能合约存储于电子设备中,虚拟机服务器和电子设备之间通信连接。获取模块被配置为:获取来自于电子设备的智能合约。
在一些实施例中,多个形式化初始状态中的每个形式化初始状态符合形式化规范,或者,多个形式化初始状态中的部分形式化初始状态符合形式化规范。
在一些实施例中,虚拟机服务器配置有数据存储库。获取智能合约的形式化部署信息之后,装置还包括存储模块。存储模块被配置为,将智能合约的形式化部署信息存储在数据存储库中。
在一些实施例中,初始化执行函数用于对虚拟机服务器进行初始化。
在一些实施例中,行为函数用于表示不同账户之间进行交易时的交易规则。
本公开一些实施例中,首先获取智能合约的形式化部署信息,然后基于形式化部署信息包括的形式化初始状态,执行形式化行为列表包括的初始化执行函数和行为函数,得到智能合约的执行结果,再根据智能合约的形式化规范库检测智能合约的执行结果,得到漏洞检测结果。该漏洞检测结果能够表征智能合约在实际运行时是否存在漏洞,无论是已知漏洞类型还是未知漏洞类型均可以检测出,智能合约的漏洞检测精度较高。
图10示出了根据一个或多个实施例的一种电子设备的结构示意图。如图10所示,该设备可以包括处理器101以及存储有计算机程序指令的存储器102。
例如,处理器101可以包括中央处理器(Central Processing Unit,CPU),或者特定集成电路(Application Specific Integrated Circuit,ASIC),或者可以被配置成实施本公开一些实施例的一个或多个集成电路。
存储器102可以包括用于数据或指令的大容量存储器。举例来说而非限制,存储器102可包括硬盘驱动器(Hard Disk Drive,HDD)、软盘驱动器、闪存、光盘、磁光盘、磁带或通用串行总线(Universal Serial Bus,USB)驱动器或者两个或更多个以上这些的组合。在一个实例中,存储器102可以包括可移除或不可移除(或固定)的介质,或者存储器102是非易失性固态存储器。存储器102可在综合网关容灾设备的内部或外部。
在一个实例中,存储器102可以是只读存储器(Read Only Memory,ROM)。在一个实例中,该ROM可以是掩模编程的ROM、可编程ROM(PROM)、可擦除PROM(EPROM)、电可擦除PROM(EEPROM)、电可改写ROM(EAROM)或闪存或者两个或更多个以上这些的组合。
处理器101被配置为读取并执行存储器102中存储的计算机程序指令,以实现图2所示实施例中的方法,并达到图2所示实例执行其方法达到的相应技术效果,为简洁描述在此不再赘述。
在一个示例中,该电子设备还可包括通信接口103和总线110。如图10 所示,处理器101、存储器102、通信接口103通过总线110连接并完成相互间的通信。
通信接口103,主要用于实现本公开一些实施例中各模块、装置、单元和/或设备之间的通信。
总线110可包括硬件、软件或两者,将在线数据流量计费设备的部件彼此耦接在一起。举例来说而非限制,总线可包括加速图形端口(Accelerated Graphics Port,AGP)或其他图形总线、增强工业标准架构(Extended Industry Standard Architecture,EISA)总线、前端总线(Front Side Bus,FSB)、超传输(Hyper Transport,HT)互连、工业标准架构(Industry Standard Architecture,ISA)总线、无限带宽互连、低引脚数(LPC)总线、存储器总线、微信道架构(MCA)总线、外围组件互连(PCI)总线、PCI-Express(PCI-X)总线、串行高级技术附件(SATA)总线、视频电子标准协会局部(VLB)总线或其他合适的总线或者两个或更多个以上这些的组合。在合适的情况下,总线110可包括一个或多个总线。尽管本公开一些实施例描述和示出了特定的总线,但可以考虑替换为任何合适的总线或互连。
该电子设备可以执行本公开一些实施例中的智能合约漏洞检测方法,从而实现图2描述的智能合约漏洞检测方法的相应技术效果。
另外,结合上述实施例中的智能合约漏洞检测方法,本公开一些实施例可提供一种计算机可读存储介质(例如,非暂态计算机可读存储介质)。该计算机可读存储介质上存储有计算机程序指令,该计算机程序指令在被处理器执行时实现上述实施例中的任意一种智能合约漏洞检测方法。
举例来说而非限制,计算机可读存储介质可包括硬盘驱动器(Hard Disk Drive,HDD)、软盘驱动器、闪存、光盘、磁光盘、磁带或通用串行总线(Universal Serial Bus,USB)驱动器或者两个或更多个以上这些的组合。在一个实例中,计算机可读存储介质可以包括可移除或不可移除(或固定)的介质,或者计算机可读存储介质是非易失性固态存储器。计算机可读存储介质可在综合网关容灾设备的内部或外部。
在示例性的实施例中,本公开一些实施例还提供了一种计算机程序产品,计算机程序产品在计算机上运行时,使得计算机实现上述实施例中的智能合约漏洞检测方法。
通过以上实施方式的描述,所属领域的技术人员可以清楚地了解到,为 描述的方便和简洁,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。
在本公开一些实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个装置,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是一个物理单元或多个物理单元,即可以位于一个地方,或者也可以分布到多个不同地方。可以根据实际的需要选择其中的部分或者全部单元来实现本公开一些实施例。
另外,在本公开各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个可读取存储介质中。基于这样的理解,本公开一些实施例的技术方案本质上或者该技术方案的全部或部分可以以软件产品的形式体现出来,该软件产品存储在一个存储介质中,包括若干指令用以使得一个设备(可以是单片机,芯片等)或处理器(processor)执行本公开各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。
以上内容,仅为本公开一些实施例的具体实施方式,但本公开的保护范围并不局限于此,任何在本公开揭露的技术范围内的变化或替换,都应涵盖在本公开的保护范围之内。因此,本公开的保护范围应以所述权利要求的保护范围为准。

Claims (15)

  1. 一种智能合约漏洞检测方法,应用于虚拟机服务器,包括:
    获取智能合约的形式化部署信息,其中,所述形式化部署信息包括形式化初始状态以及形式化行为列表,所述形式化行为列表包括所述智能合约的初始化执行函数和行为函数;
    基于所述形式化初始状态,执行所述形式化行为列表包括的初始化执行函数和行为函数,得到所述智能合约的执行结果;以及
    根据所述智能合约的形式化规范库检测所述智能合约的执行结果,得到漏洞检测结果,其中,所述形式化规范库包括所述智能合约的形式化规范。
  2. 根据权利要求1所述的方法,其中,所述根据所述智能合约的形式化规范库检测所述智能合约的执行结果,得到漏洞检测结果,包括:
    对于每个行为函数,检测基于所述形式化初始状态,执行所述初始化执行函数和所述行为函数的执行结果是否符合所述形式化规范;
    若符合,则将所述执行结果与所述形式化初始状态建立关联关系,以及在所述执行结果未包括在所述形式化部署信息中的情况下,将所述执行结果作为新的形式化初始状态包括在所述形式化部署信息中;以及
    若不符合,则上报错误信息。
  3. 根据权利要求2所述的方法,还包括:
    建立有向图,其中,所述有向图包括与所述形式化初始状态对应的节点,存在关联关系的两个节点用有向边连接,其中
    所述若符合,则将所述执行结果与所述形式化初始状态建立关联关系,包括:
    若符合,则查看所述有向图中是否存在与所述执行结果对应的节点;
    若存在,则设置从所述初始化状态指向所述节点的有向边;
    若不存在,则将所述执行结果添加到所述有向图中,并设置从所述初始化状态指向所述执行结果对应的节点的有向边。
  4. 根据权利要求1-3中任一项所述的方法,其中,所述形式化部署信息包括多个形式化初始状态,所述方法还包括:
    根据所述多个形式化初始状态确定执行队列,其中,所述执行队列中包括所述多个形式化初始状态中符合所述形式化规范的形式化初始状态,其中所述基于所述形式化初始状态,执行所述形式化行为列表包括的初始化执行函数和行为函数,包括:
    基于所述执行队列中的每一个形式化初始状态,执行所述形式化行为列表包括的初始化执行函数和行为函数。
  5. 根据权利要求1所述的方法,还包括:
    根据所述智能合约的需求信息确定所述智能合约的定制形式化规范;以及
    将所述定制形式化规范添加到所述形式化规范库中。
  6. 根据权利要求5所述的方法,其中,所述形式化规范库还包括通用规范,所述通用规范用于表示多个智能合约中的每个智能合约的形式化规范,所述将所述定制形式化规范添加到所述形式化规范库中之后,还包括:
    将所述通用规范替换为所述智能合约的定制形式化规范。
  7. 根据权利要求1所述的方法,其中,所述获取智能合约的形式化部署信息,包括:
    获取所述智能合约;以及
    对所述智能合约进行解析,得到所述形式化初始状态以及所述形式化行为列表。
  8. 根据权利要求7所述的方法,其中,所述智能合约存储于电子设备中,所述虚拟机服务器和所述电子设备之间通信连接,所述获取所述智能合约,包括:
    获取来自于所述电子设备的所述智能合约。
  9. 根据权利要求4所述的方法,其中,所述多个形式化初始状态中的每个形式化初始状态符合所述形式化规范,或者,所述多个形式化初始状态中的部分形式化初始状态符合所述形式化规范。
  10. 根据权利要求1所述的方法,其中,所述虚拟机服务器配置有数据存储库,所述获取智能合约的形式化部署信息之后,还包括:
    将所述智能合约的形式化部署信息存储在所述数据存储库中。
  11. 根据权利要求1所述的方法,其中,所述初始化执行函数用于对所述虚拟机服务器进行初始化。
  12. 根据权利要求1所述的方法,其中,所述行为函数用于表示不同账户之间进行交易时的交易规则。
  13. 一种智能合约漏洞检测装置,所述装置应用于虚拟机服务器,包括:
    获取模块,被配置为获取智能合约的形式化部署信息,其中,所述形式化部署信息包括形式化初始状态以及形式化行为列表,所述形式化行为列表包括所述智能合约的初始化执行函数和行为函数;
    执行模块,被配置为基于所述形式化初始状态,执行所述形式化行为列表包括的初始化执行函数和行为函数,得到所述智能合约的执行结果;
    检测模块,被配置为根据所述智能合约的形式化规范库检测所述智能合约的执行结果,得到漏洞检测结果,其中,所述形式化规范库包括所述智能合约的形式化规范。
  14. 一种电子设备,包括:存储器,处理器及存储在所述存储器上并可在所述处理器上运行的计算机程序,所述计算机程序在被所述处理器执行时,实现如权利要求1至12中任一项所述的智能合约漏洞检测方法。
  15. 一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机程序,所述计算机程序在被处理器执行时,实现如权利要求1至12中任一项所述的智能合约漏洞检测方法。
PCT/CN2023/102025 2022-06-27 2023-06-25 智能合约漏洞检测方法、装置和设备 WO2024001929A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210736727.0A CN115062313A (zh) 2022-06-27 2022-06-27 智能合约漏洞检测方法、装置、设备和存储介质
CN202210736727.0 2022-06-27

Publications (1)

Publication Number Publication Date
WO2024001929A1 true WO2024001929A1 (zh) 2024-01-04

Family

ID=83202310

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/102025 WO2024001929A1 (zh) 2022-06-27 2023-06-25 智能合约漏洞检测方法、装置和设备

Country Status (2)

Country Link
CN (1) CN115062313A (zh)
WO (1) WO2024001929A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115062313A (zh) * 2022-06-27 2022-09-16 中国人民银行数字货币研究所 智能合约漏洞检测方法、装置、设备和存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110489973A (zh) * 2019-08-06 2019-11-22 广州大学 一种基于Fuzz的智能合约漏洞检测方法、装置和存储介质
WO2021037196A1 (zh) * 2019-08-28 2021-03-04 杭州趣链科技有限公司 智能合约代码漏洞检测方法、装置、计算机设备和存储介质
CN113672515A (zh) * 2021-08-26 2021-11-19 北京航空航天大学 一种基于符号执行的wasm智能合约漏洞检测方法
CN114358934A (zh) * 2021-12-29 2022-04-15 中国农业银行股份有限公司 智能合约的校验方法和相关设备
CN115062313A (zh) * 2022-06-27 2022-09-16 中国人民银行数字货币研究所 智能合约漏洞检测方法、装置、设备和存储介质

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110489973A (zh) * 2019-08-06 2019-11-22 广州大学 一种基于Fuzz的智能合约漏洞检测方法、装置和存储介质
WO2021037196A1 (zh) * 2019-08-28 2021-03-04 杭州趣链科技有限公司 智能合约代码漏洞检测方法、装置、计算机设备和存储介质
CN113672515A (zh) * 2021-08-26 2021-11-19 北京航空航天大学 一种基于符号执行的wasm智能合约漏洞检测方法
CN114358934A (zh) * 2021-12-29 2022-04-15 中国农业银行股份有限公司 智能合约的校验方法和相关设备
CN115062313A (zh) * 2022-06-27 2022-09-16 中国人民银行数字货币研究所 智能合约漏洞检测方法、装置、设备和存储介质

Also Published As

Publication number Publication date
CN115062313A (zh) 2022-09-16

Similar Documents

Publication Publication Date Title
US10831826B2 (en) Validation of schema and schema conformance verification
CN111428462B (zh) 通讯协议模板构建的方法及终端设备
WO2024001929A1 (zh) 智能合约漏洞检测方法、装置和设备
CN108376364B (zh) 一种支付系统对账的方法、设备及终端设备
CN108363640B (zh) 数据校验方法及装置、计算机可读存储介质
US8484396B2 (en) Method and system for conditional interrupts
KR20190121372A (ko) 시스템 아키텍처를 표현하는 속성 그래프 데이터 모델
WO2022120995A1 (zh) 一种基于PoW共识机制的设备算力评价方法及系统
CN110766160A (zh) 一种数据校验方法、装置、存储介质及电子设备
CN115632976A (zh) 一种pcie事务层报文生成方法、装置及存储介质
CN111562965A (zh) 基于决策树的页面数据校验方法和装置
CN112363935A (zh) 数据联调方法、装置、电子设备及存储介质
CN112181430A (zh) 代码变更统计方法、装置、电子设备及存储介质
CN108289028A (zh) 一种签名认证方法、相关设备及计算机可读存储介质
CN112988215A (zh) 评价规则的实现与用户数据的评价方法、装置及电子设备
CN108089987B (zh) 功能验证方法和装置
CN115062312A (zh) 智能合约漏洞检测方法、装置、设备和存储介质
CN116125853A (zh) 集成电路的安全控制方法、装置、存储介质及电子设备
WO2022089063A1 (zh) 数据核对方法、装置、设备、系统及存储介质
CN107741887A (zh) 一种组件间的通信交互方法和装置
CN114116337A (zh) 基于pcie链路配置的硬盘测试方法、系统、终端及存储介质
CN114006819A (zh) 一种检测策略生成及装置、数据传输方法及装置
CN111797406A (zh) 一种医疗基金数据分析处理方法、装置及可读存储介质
CN110349025B (zh) 一种基于未花费交易输出的合约资产防遗失方法及装置
CN115509906A (zh) 软件缺陷检测方法、装置、设备和存储介质

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

Country of ref document: EP

Kind code of ref document: A1