Smart contract credibility proof method, device, equipment and storage medium

By generating the behavior sequence of smart contracts in the blockchain system and performing multi-node verification, and using a trusted behavior benchmark library to verify contract behavior, the problem of unreliable smart contract behavior is solved and the security of the blockchain network is improved.

CN116150814BActive Publication Date: 2025-10-14BEIJING UNIV OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211610343.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-14
Publication Date
2025-10-14
Estimated Expiration
2042-12-14

AI Technical Summary

Technical Problem

Existing technologies cannot effectively guarantee the behavioral credibility of smart contracts, making blockchain networks vulnerable to malicious contract attacks and affecting security.

Method used

By obtaining the call transaction request of the smart contract in the blockchain system, generating a behavior sequence, and performing credibility verification between the consensus node and other nodes, the contract behavior is verified using the trusted behavior benchmark library to ensure that the contract is executed in a trusted environment.

Benefits of technology

It improves the security of the blockchain system, prevents malicious contract attacks, ensures the credibility of contract behavior, and enhances the system's protection capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116150814B_ABST
    Figure CN116150814B_ABST
Patent Text Reader

Abstract

The application provides a smart contract credibility proving method, device, equipment and storage medium, the method comprises the following steps: obtaining a calling transaction request of a smart contract in a blockchain system, generating a first behavior sequence corresponding to the smart contract according to the calling transaction request; verifying the behavior credibility of the smart contract based on the first behavior sequence to obtain a first verification result; writing the calling transaction request into a target block in the blockchain system and broadcasting the calling transaction request in the blockchain system; receiving a second verification result of the behavior credibility of the smart contract from each target node in the blockchain system; and determining the credibility of the smart contract according to the first verification result and the second verification result. Based on the behavior sequence of the smart contract, the consensus mechanism of the blockchain is used to verify the credibility of the contract behavior, prevent malicious contract behavior from attacking the blockchain system maliciously, ensure the credibility of the contract behavior, and improve the security of the blockchain system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of information security technology, and in particular to a method, apparatus, device, and storage medium for proving the credibility of a smart contract. Background Art

[0002] Blockchain has gained widespread adoption due to its decentralized and tamper-proof nature. Smart contracts, a key technology for extending blockchain technology, not only grant programmability to the underlying logic but also encapsulate the complex interactions between nodes within a blockchain network, extending its functionality. However, as code, smart contracts are inherently vulnerable. Malicious attackers can exploit hidden security vulnerabilities within smart contracts to create malicious contracts and disrupt their proper execution. Once released, these malicious contracts can cause severe damage to a blockchain network. According to incomplete statistics, attacks targeting smart contracts account for a significant proportion of attacks on blockchain networks. Therefore, improving the security of blockchain networks is urgent.

[0003] Trustworthiness is not the same as security, but it is the foundation of security. Existing methods for improving blockchain network security cannot guarantee the trustworthiness of smart contract behavior. For example, patent publication number CN114896604 proposes a "method, system, device, and medium for detecting vulnerabilities in interactions between smart contracts and chain environments," and patent publication number CN111581047A proposes a "method for monitoring smart contract behavior." The former uses a method of inferring function information from contract bytecode to generate a smart contract behavior model. This method generates arbitrary transaction sequences based on the behavior model without considering the execution order of functions. Furthermore, this approach only considers the state transitions of transactions during contract interactions, ignoring the trustworthiness of individual contracts. Therefore, it cannot effectively guarantee the trustworthiness of contract behavior. The latter method for monitoring smart contract behavior transforms real-world regulatory rules and the state of the regulatory entity into digital regulatory rules within a formal reasoning system. This method cannot detect situations like reentrant contracts that comply with each regulatory rule but whose overall behavior sequence does not meet the requirements. Consequently, it also cannot guarantee the trustworthiness of smart contract behavior. Summary of the Invention

[0004] The present invention provides a method, apparatus, device and storage medium for proving the credibility of a smart contract, which are used to address the defect that the existing technology cannot guarantee the behavioral credibility of smart contracts.

[0005] The present invention provides a smart contract credibility proof method, which is applied to a consensus node in a blockchain system, comprising:

[0006] Obtaining a transaction request for invoking a smart contract in a blockchain system, and generating a first behavior sequence corresponding to the smart contract according to the transaction request;

[0007] Verifying the behavioral credibility of the smart contract based on the first behavior sequence to obtain a first verification result;

[0008] Writing the call transaction request into a target block in the blockchain system, and broadcasting the call transaction request in the blockchain system;

[0009] Receiving a second verification result of the credibility of the behavior of the smart contract from each target node in the blockchain system;

[0010] The second verification result is obtained by the target node verifying the credibility of the behavior of the smart contract based on a second behavior sequence, where the second behavior sequence is generated by the target node according to the call transaction request; the target node is a node in the blockchain system other than the consensus node that has the authority to simulate execution of the smart contract;

[0011] Determine the credibility of the smart contract based on the first verification result and the second verification result.

[0012] According to a method for proving the credibility of a smart contract provided by the present invention, generating a first behavior sequence corresponding to the smart contract according to the calling transaction request includes:

[0013] Obtaining basic contract information of the smart contract according to the call transaction request; the basic contract information includes the contract name and the key system that triggers the call;

[0014] Determine the element information corresponding to the contract behavior of the smart contract based on the basic contract information; the element information includes the behavior subject, behavior object, executed operation, execution environment, execution time and execution number;

[0015] Verifying the execution environment of the smart contract based on the element information;

[0016] If the verification is successful, the smart contract is simulated and executed based on the element information to obtain the contract behavior information of the smart contract; the contract behavior information includes the call parameters, call sequence and call count of the key system;

[0017] Performing permission verification on the target system in the key system, and if the permission verification passes, generating a first behavior sequence corresponding to the smart contract based on the contract behavior information;

[0018] The target system is the key system that needs to access external data or call the smart contract.

[0019] According to a method for proving the credibility of a smart contract provided by the present invention, before generating a first behavior sequence corresponding to the smart contract according to the calling transaction request, the method further includes:

[0020] Based on the contract functions of the smart contract, the contract code of the smart contract is divided to obtain target code blocks corresponding to the contract functions;

[0021] Obtaining a key function set in each functional function in the target code block, and determining a target key system for each key function in the key function set to trigger a call;

[0022] Generate a control flow graph with each of the target key systems as a node, and divide the control flow graph into execution traces to obtain a system call sequence of the smart contract;

[0023] Dynamically testing the smart contract and adjusting the system call sequence based on the test results to obtain an expected behavior sequence corresponding to the smart contract;

[0024] A trusted behavior benchmark library corresponding to the smart contract is generated based on the expected behavior sequence.

[0025] According to a smart contract credibility proof method provided by the present invention, generating a trusted behavior benchmark library corresponding to the smart contract based on the expected behavior sequence includes:

[0026] Determine a system call sequence set corresponding to a target function according to the expected behavior sequence; the target function is any one of the contract functions;

[0027] Traversing each target system call sequence in the system call sequence set, and counting target values ​​of system call parameters of each key system corresponding to the target system call sequence;

[0028] Based on the target value, extract key parameters from the system call parameters, and generate a value range for each key parameter;

[0029] Taking each key system corresponding to the target system call sequence as a segmentation point and the key parameter as a segmentation condition, constructing a trusted behavior rule corresponding to the target function based on the value range;

[0030] Calculate the benchmark value of the trusted behavior rule, and generate a trusted behavior benchmark library corresponding to the smart contract based on the benchmark value.

[0031] According to a method for proving the credibility of a smart contract provided by the present invention, generating a first behavior sequence corresponding to the smart contract based on the contract behavior information includes:

[0032] Matching the contract behavior information with the trusted behavior benchmark library to determine the target trusted behavior rules corresponding to the contract behavior information;

[0033] Generate a first behavior sequence corresponding to the smart contract according to the target trusted behavior rule.

[0034] According to a method for proving the credibility of a smart contract provided by the present invention, before obtaining a transaction request for calling a smart contract in a blockchain system, the method further includes:

[0035] Obtain a transaction request to create a smart contract in the blockchain system;

[0036] Performing credibility verification on the smart contract according to the transaction creation request to obtain a third verification result;

[0037] Creating a first block in the blockchain system, writing the transaction creation request into the first block, and broadcasting the transaction creation request in the blockchain system; the first block includes the identity information and computing environment of the consensus node, so that each target node can authenticate the consensus node and verify the credibility of the computing environment;

[0038] receiving a fourth verification result of the smart contract by each of the target nodes; the fourth verification result is obtained by the target node performing credibility verification on the smart contract according to the transaction creation request;

[0039] Determining the credibility of the smart contract based on the third verification result and the fourth verification result;

[0040] If the smart contract is credible, a contract release instruction is generated; the contract release instruction is used to indicate the release permission of the smart contract.

[0041] According to a method for proving the credibility of a smart contract provided by the present invention, the transaction creation request includes the identity information and computing environment of the target user requesting to create the smart contract;

[0042] The performing credibility verification on the smart contract according to the transaction creation request to obtain a third verification result includes:

[0043] Performing credibility verification on the target user's identity and computing environment based on the transaction creation request, and verifying the target user's contract publishing authority to verify the credibility of the contract code of the smart contract;

[0044] If the credibility verification of the contract code of the smart contract passes, the credibility of the behavior of the smart contract is verified to obtain a third verification result.

[0045] The present invention also provides a smart contract credibility certification device, which is arranged in a consensus node in a blockchain system and includes:

[0046] A behavior sequence generation module is configured to obtain a transaction request for invoking a smart contract in the blockchain system and generate a first behavior sequence corresponding to the smart contract based on the transaction request;

[0047] A first verification module, configured to verify the credibility of the behavior of the smart contract based on the first behavior sequence, and obtain a first verification result;

[0048] a transaction broadcast module, configured to write the transaction call request into a target block in the blockchain system and broadcast the transaction call request in the blockchain system;

[0049] A receiving module, configured to receive a second verification result of the credibility of the behavior of the smart contract from each target node in the blockchain system;

[0050] The second verification result is obtained by the target node verifying the credibility of the behavior of the smart contract based on a second behavior sequence, where the second behavior sequence is generated by the target node according to the call transaction request; the target node is a node in the blockchain system other than the consensus node that has the authority to simulate execution of the smart contract;

[0051] A trustworthy proof module is used to determine the trustworthiness of the smart contract based on the first verification result and the second verification result.

[0052] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method for proving the credibility of a smart contract as described above is implemented.

[0053] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the above-described methods for proving the credibility of a smart contract.

[0054] The present invention also provides a computer program product, comprising a computer program, which, when executed by a processor, implements any of the above-described methods for proving the credibility of a smart contract.

[0055] The smart contract credibility verification method, apparatus, device, and storage medium provided by the present invention obtain a call transaction request for a smart contract in a blockchain system and generate a first behavior sequence corresponding to the smart contract; verify the behavioral credibility of the smart contract based on the first behavior sequence to obtain a first verification result; write the call transaction request into a target block in the blockchain system and broadcast the call transaction request in the blockchain system; receive a second verification result of the behavioral credibility of the smart contract from each target node in the blockchain system; and determine the credibility of the smart contract based on the first and second verification results. Based on the smart contract's behavior sequence, the blockchain's consensus mechanism performs credibility verification on the contract behavior, preventing malicious contract behavior from launching malicious attacks on the blockchain system. By ensuring the credibility of the contract behavior, the security of the blockchain system is improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0056] In order to more clearly illustrate the technical solutions in the present invention or the prior art, a brief introduction is given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0057] Figure 1 This is a flow chart of the smart contract credibility proof method provided by the present invention;

[0058] Figure 2 This is a schematic diagram of the structure of the smart contract credibility proof device provided by the present invention;

[0059] Figure 3 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0060] To make the objectives, technical solutions, and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments described are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.

[0061] The following combination Figure 1-Figure 3 Describe the smart contract credibility proof method, device, equipment and storage medium of the present invention.

[0062] The smart contract credibility proof method provided by the present invention is applied to the consensus node in the blockchain system. Based on the behavior sequence of the smart contract, the blockchain consensus mechanism is used to verify the credibility of the contract behavior before the contract is released and called. This prevents malicious attacks on the blockchain system after the malicious contract is released, ensures the credibility of the contract behavior, avoids serious damage to the blockchain, and improves the security of the blockchain system. Specifically, refer to Figure 1 , Figure 1 A flow chart of a method for proving the credibility of a smart contract provided by an embodiment of the present invention, based on Figure 1 The smart contract credibility verification method provided by the embodiment of the present invention includes:

[0063] Step 100: Obtain a transaction request for invoking a smart contract in the blockchain system, and generate a first behavior sequence corresponding to the smart contract based on the transaction request;

[0064] First, a transaction request to invoke a smart contract in a blockchain system is obtained. Based on the transaction request, a first behavior sequence corresponding to the smart contract is generated. This first behavior sequence can be obtained by dynamically testing the invoked smart contract based on the transaction request; it can also be obtained by statically analyzing the behavior of the smart contract; or it can be obtained through a combination of static analysis and dynamic testing, without specific limitations here. The first behavior sequence is used to characterize the system calls involved in invoking the smart contract based on the transaction request, specifically including the invoked systems, the order in which each system is called, and the number of calls.

[0065] Step 200: Verify the credibility of the smart contract's behavior based on the first behavior sequence to obtain a first verification result;

[0066] The behavioral credibility of the smart contract is verified based on the generated first behavior sequence to obtain a first verification result of the smart contract, which is used to indicate whether the behavioral feasibility verification of the smart contract has passed.

[0067] Step 300: writing the call transaction request into the target block in the blockchain system and broadcasting the call transaction request in the blockchain system;

[0068] The call transaction request is written into the target block in the blockchain system, and the call transaction request is broadcast in the blockchain system. The target block can be created by the consensus node or pre-created in the blockchain system, which is not limited here.

[0069] Step 400: Receive a second verification result of the credibility of the behavior of the smart contract from each target node in the blockchain system;

[0070] The second verification result is obtained by the target node verifying the credibility of the behavior of the smart contract based on a second behavior sequence, where the second behavior sequence is generated by the target node according to the call transaction request; the target node is a node in the blockchain system other than the consensus node that has the authority to simulate execution of the smart contract;

[0071] Receive a second verification result of the smart contract from each target node in the blockchain system, where the target node is a node in the blockchain system that has simulated execution authority for the smart contract, excluding the consensus node. The second verification result is obtained by the target node verifying the behavioral credibility of the smart contract based on a second behavioral sequence, where the second behavioral sequence is generated by the target node based on a call transaction request broadcasted in the blockchain system. It should be noted that the first and second verification results correspond to the same method for verifying the behavioral credibility of the smart contract.

[0072] Step 500: Determine the credibility of the smart contract based on the first verification result and the second verification result.

[0073] Determine the credibility of the smart contract based on the first verification result and the second verification result. If any node in the first verification result and the second verification result of each target node fails the credibility verification of the smart contract's behavior, the smart contract is proven to be untrustworthy.

[0074] When the verification results of all nodes pass, it proves that the behavior of the smart contract is credible.

[0075] In this embodiment, by obtaining the call transaction of the smart contract in the blockchain system

[0076] The transaction request is sent to the target block in the blockchain system, and the first behavior sequence corresponding to the smart contract is generated; the credibility of the behavior of the smart contract is verified based on the first behavior sequence to obtain a first verification result; the transaction request is written into the target block in the blockchain system, and the call is broadcast in the blockchain system.

[0077] Receive the second verification result of the credibility of the 5 behaviors of the smart contract from each target node in the blockchain system; confirm the credibility of the 5 behaviors of the smart contract according to the first verification result and the second verification result;

[0078] Determine the credibility of smart contracts. Based on the behavior sequence of smart contracts, the blockchain consensus mechanism performs trustworthy verification of contract behaviors, preventing malicious contract behaviors from launching malicious attacks on the blockchain system and avoiding damage to the blockchain system. By ensuring the credibility of contract behaviors, the security of the blockchain system is improved.

[0079] In a preferred embodiment, based on the simulation execution of the smart contract, the smart

[0080] The behavior sequence of the contract, specifically, is set up with monitoring points in the key system call context of the smart contract. The actual trajectory of the contract runtime is extracted through the monitoring points and represented in the form of a data structure chain to describe the contract behavior sequence.

[0081] The monitoring point established by the system call context obtains the subject, object, operation, environment, execution time, execution times and other element information related to the system call, obtains the contract operation information, and then generates

[0082] A sequence of actions that form a smart contract.

[0083] In step 100, the first action sequence of the smart contract is generated according to the transaction request, specifically including:

[0084] Step 101: Obtain basic contract information of the smart contract according to the call transaction request; the basic contract information includes the contract name and the key system that triggers the call;

[0085] Step 102: Determine the element information corresponding to the contract behavior of the smart contract based on the basic contract information; the element information includes the behavior subject, behavior object, executed operation, execution environment, execution time, and execution number;

[0086] Step 103: Verify the execution environment of the smart contract based on the element information;

[0087] Step 104: If the verification passes, simulate and execute the smart contract based on the element information to obtain contract behavior information of the smart contract; the contract behavior information includes the call parameters, call sequence, and call count of the key system;

[0088] Step 105: Perform permission verification on the target system in the key system. If the permission verification passes, generate a first behavior sequence corresponding to the smart contract based on the contract behavior information.

[0089] The target system is the key system that needs to access external data or call the smart contract.

[0090] Based on the call transaction request, the basic contract information of the smart contract is obtained. This basic contract information includes the contract name, key system calls triggered by the contract, and the contract bytecode. Specifically, the basic information of the smart contract to be called is obtained based on the call transaction request. Based on this basic contract information, the element information corresponding to the smart contract's contract behavior is determined. This element information includes the subject of the behavior, the object of the behavior, the executed operation, the execution environment, the execution time, and the number of executions. The operations executed by the contract include read and write operations. The key system calls triggered by the contract are determined by the key functions contained in the contract code. When called, the smart contract triggers the corresponding system calls by executing these key functions. When creating a smart contract, the user can specify which nodes can call the smart contract, forming a contract policy. The blockchain system specifies whether the smart contract has access to the ledger, forming a blockchain system policy. Based on the smart contract's contract policy and blockchain system policy, the blockchain system ensures secure calls to the smart contract from each node.

[0091] It should be noted that the element information of smart contracts mainly involves subjects, objects, operations, and environments. Among them, the subject is the entity that operates on the object. When creating a smart contract, the user is the subject, and in the process of calling the contract, the smart contract is the subject; the object is the resource accessed by the subject. When creating a contract, the object is the contract, and in the process of calling the contract, the object is the ledger or other contracts; the operation refers to the action performed by the subject on the object, for example, the user creates, calls, and deletes the contract, and the contract reads, writes, and updates the ledger; the environment refers to the computing environment in which the user creates or calls the contract. In this embodiment, all nodes in the blockchain system have a TPCM (Trusted Platform Control Module) trusted computing environment. The contract will verify the trustworthiness of the contract behavior after being trusted before being released; the contract cannot be tampered with, so the subject is trustworthy; the contract is trusted before being released and cannot be tampered with after being released. The blockchain ledger cannot be tampered with, so the object is trustworthy; TPCM provides cryptographic support and trust support for the blockchain system.

[0092] Based on the element information corresponding to the contract behavior, the credibility of the execution environment of the smart contract is verified. Before simulating the execution of the contract, the execution environment is verified for credibility. Only contract behaviors executed in a trusted environment are credible. If the verification is successful, the smart contract is simulated based on the element information corresponding to the contract behavior to obtain the contract behavior information of the smart contract. This contract behavior information includes key system call parameters, call sequence, and call count. The target system in the key system is verified for permissions. If the permission verification is successful, the first behavior sequence corresponding to the smart contract is generated based on the obtained contract behavior information. Among them, the target system is the system in the key system that needs to access external data or call smart contracts. The permission verification of the target system specifically verifies the access rights to external data or contract call permissions of the target system.

[0093] Furthermore, the behavior sequence of the smart contract is generated based on a pre-built trusted behavior benchmark library. This trusted behavior benchmark library consists of benchmark values ​​for trusted behavior rules, which are generated based on the expected behavior sequence of the smart contract. By comparing the generated behavior sequence with the expected behavior sequence of the smart contract, the trustworthiness of the smart contract's behavior can be proven. Before generating the first behavior sequence corresponding to the smart contract based on the call transaction request, the following is also included:

[0094] Step 001: Based on the contract functions of the smart contract, the contract code of the smart contract is divided to obtain the target code blocks corresponding to the contract functions;

[0095] Step 002: obtaining a key function set in each function in the target code block, and determining a target key system to be called by each key function in the key function set;

[0096] Step 003: Generate a control flow graph with each target key system as a node, and divide the control flow graph into execution traces to obtain the system call sequence of the smart contract;

[0097] Step 004: Dynamically test the smart contract and adjust the system call sequence based on the test results to obtain the expected behavior sequence corresponding to the smart contract;

[0098] Step 005: Generate a trusted behavior benchmark library corresponding to the smart contract based on the expected behavior sequence.

[0099] To generate the expected behavior sequence of a smart contract and build a trusted behavior benchmark library, a combination of static and dynamic metrics is employed. After creating a contract, users graphically analyze the possible behavior sequences during contract runtime using the smart contract source code. Dynamic testing then refines these behavior sequences. Specifically, the contract code is divided into contract functions, and the corresponding target code blocks are determined. Based on these divided target code blocks, the key execution function sets within each function are determined, using key execution functions as the division principle. Based on the correspondence between functions and system calls, the key system calls triggered by each key function are identified. Based on the call relationships and control structures, a control flow graph is generated with key system call sequences as nodes. Based on the generated control flow graph, all execution traces are mapped, resulting in all possible system call execution sequences for the contract. Dynamic testing of the smart contract is then performed, monitoring the key system call sequences and parameter information during contract runtime based on monitoring points configured in the system. The system call sequences obtained through static analysis are compared, and incorrect behavior sequences are adjusted to obtain the expected behavior sequence of the smart contract, which serves as a reference for the behavior sequences of other system calls. Based on the generated expected behavior sequences, a trusted behavior benchmark library corresponding to the smart contract is generated.

[0100] Furthermore, based on the generated expected behavior sequence, a trusted behavior benchmark library corresponding to the smart contract is generated, specifically including:

[0101] Step 0051: determining a system call sequence set corresponding to a target function according to the expected behavior sequence; the target function is any one of the contract functions;

[0102] Step 0052: traverse each target system call sequence in the system call sequence set, and count target values ​​of system call parameters of each key system corresponding to the target system call sequence;

[0103] Step 0053: extract key parameters from the system call parameters based on the target value, and generate a value range for each key parameter;

[0104] Step 0054: Using the key systems corresponding to the target system call sequence as segmentation points and the key parameters as segmentation conditions, constructing trusted behavior rules corresponding to the target function based on the value range;

[0105] Step 0055: Calculate the benchmark value of the trusted behavior rule, and generate a trusted behavior benchmark library corresponding to the smart contract based on the benchmark value.

[0106] Based on the generated expected behavior sequence, a set of behavior sequences corresponding to the target function, namely, a set of system call sequences, is determined. The target function is any one of the contract functions of the smart contract. In this embodiment, trusted behavior rules are generated for each function of the smart contract. The rule base corresponding to the trusted behavior rules consists of system call sequences and system call parameters, and the behavior rules are generated by combining a decision tree algorithm. Specifically, each target system call sequence in the system call sequence set of the target function is first traversed. Based on the system call order, the values ​​of the system call parameters are statistically analyzed to determine the target values ​​of the system call parameters of each key system corresponding to each target system call sequence.

[0107] Based on the target values, the system call parameters are simplified, key parameters are extracted, and the value ranges of the system call parameters corresponding to each target system call sequence are generated. Using key system calls as segmentation points and system call parameters as segmentation conditions, based on the value ranges of key parameters, the behavior sequence rules corresponding to each contract function are constructed in the form of a decision tree. The behavior sequence rules are then measured and the baseline values ​​of the behavior sequence rules are calculated to construct a trusted behavior benchmark library.

[0108] Based on this, the first behavior sequence corresponding to the smart contract is generated according to the contract behavior information, including:

[0109] Step 1051: Match the contract behavior information with the trusted behavior benchmark library to determine the target trusted behavior rule corresponding to the contract behavior information;

[0110] Step 1052: Generate a first behavior sequence corresponding to the smart contract according to the target trusted behavior rule.

[0111] The contract behavior information is matched with the trusted behavior benchmark library to determine the target trusted behavior rules corresponding to the contract behavior information. Based on the target trusted behavior rules corresponding to the contract behavior information, the first behavior sequence corresponding to the smart contract is generated. Based on the contract behavior information, it is determined whether a decision tree corresponding to the trusted behavior rule in the trusted behavior benchmark library has been successfully executed. If not, the contract behavior is untrustworthy. If a decision tree rule is successfully executed, a corresponding behavior sequence is generated based on the execution results of the decision tree for the contract behavior information. The actual generated behavior sequence is compared with the expected behavior sequence to confirm whether the two are consistent. If they are consistent, the contract behavior is credible; otherwise, the contract behavior is untrustworthy.

[0112] In this embodiment, the trustworthiness of contract behavior is verified before contract invocation based on a generated expected behavior sequence for the smart contract and a constructed trusted behavior benchmark library, ensuring the security of the blockchain system. When generating the expected behavior sequence, static analysis is used to obtain a control flow graph of the key system call sequences triggered by the contract's key functions. This control flow graph is used to obtain a set of all possible sequences, which are then refined through dynamic execution to serve as the expected behavior sequence. Monitoring points are embedded in the context of key system calls to monitor contract behavior information for trustworthiness verification. The blockchain system determines whether the system call has access to the corresponding resources, and the trusted behavior benchmark library is used to determine whether the smart contract's behavior sequence conforms to expectations. By using the key system calls triggered by key functions as the minimum behavior unit and the key system call sequences as the contract behavior sequence, reentrancy vulnerabilities can be quickly and effectively detected, effectively preventing malicious contracts from attacking the blockchain system through reentrancy.

[0113] Furthermore, existing methods only verify the integrity of the subject and operation of the blockchain system, but ignore the credibility of the environment. In this embodiment, by performing dynamic credibility verification on the four elements involved in the contract behavior, namely the subject, object, operation and environment, a more credible verification result is obtained.

[0114] In a preferred embodiment, not only is the credibility of the contract behavior verified when the smart contract is called, but it is also required to verify the credibility of the smart contract before the smart contract is created and released. Only when the credibility verification passes, the creation and release of the smart contract are allowed. Specifically, the smart contract is created by the user. After the smart contract creation user writes the smart contract source code, the smart contract release process begins. Based on the smart contract created by the user, the expected behavior sequence of the smart contract is first generated, and the trusted behavior rules are generated and stored in the trusted behavior benchmark library; the various parts of the smart contract are measured, and the measurement values ​​are signed and bound to the contract; based on the contract creation transaction triggered by the user, the credibility of the smart contract is verified before release. Before obtaining the call transaction request for the smart contract in the blockchain system, it also includes:

[0115] Step 01: Obtain a transaction request to create a smart contract in the blockchain system;

[0116] Step 02: Performing credibility verification on the smart contract according to the transaction creation request to obtain a third verification result;

[0117] Step 03: Create a first block in the blockchain system, write the transaction creation request into the first block, and broadcast the transaction creation request in the blockchain system; the first block contains the identity information and computing environment of the consensus node, so that each target node can authenticate the consensus node and verify the credibility of the computing environment;

[0118] Step 04: Receive a fourth verification result of the smart contract from each target node; the fourth verification result is obtained by the target node performing credibility verification on the smart contract according to the transaction creation request;

[0119] Step 05: Determine the credibility of the smart contract based on the third verification result and the fourth verification result;

[0120] Step 06: If the smart contract is trustworthy, generate a contract release instruction; the contract release instruction is used to indicate the release permission of the smart contract.

[0121] A transaction request for creating a smart contract in a blockchain system is obtained. This transaction request can be triggered by a target user creating the smart contract. The smart contract is verified for credibility based on the transaction request, resulting in a third verification result for the smart contract. A first block is created in the blockchain system, the transaction request for creating the smart contract is written into the first block, and the block is broadcasted within the blockchain system. The first block also includes the identity information and computing environment of the consensus node, allowing other nodes in the blockchain system to verify the credibility of the consensus node. After each target node in the blockchain system successfully authenticates the consensus node and determines that the consensus node's computing environment is credible based on the identity information and computing environment in the first block, it then verifies the credibility of the smart contract. A fourth verification result for the smart contract is received from each target node. This fourth verification result is obtained by each target node performing credibility verification on the smart contract based on the transaction request broadcast within the blockchain system. The third and fourth verification results correspond to the same credibility verification method for the smart contract. The credibility of the smart contract is determined based on the third verification result and the fourth verification result. If the smart contract is credible, a contract release instruction is generated to allow the smart contract to be released, wherein the contract release instruction is used to indicate the release permission of the smart contract.

[0122] Furthermore, the transaction creation request includes the identity information of the target user creating the smart contract and the computing environment to verify the credibility of the smart contract, including the contract credibility verification and contract behavior credibility verification of the smart contract. The credibility of the smart contract refers to the credibility of the contract code of the smart contract. The credibility of the smart contract is verified based on the transaction creation request to obtain the third verification result, which specifically includes:

[0123] Step 021: Verify the credibility of the target user's identity and computing environment based on the transaction creation request, and verify the target user's contract publishing authority to verify the credibility of the smart contract's contract code;

[0124] Step 022: If the credibility verification of the contract code of the smart contract passes, the credibility of the behavior of the smart contract is verified to obtain a third verification result.

[0125] Based on the target user's identity information and computing environment in the transaction creation request, the smart contract's contract code is verified for credibility. Specifically, the target user is authenticated based on their identity information and their authorization to publish the contract is determined. Based on the target user's computing environment, the target user's computing environment is measured and, based on the measured value, the trustworthiness of the target user's computing environment is determined. If the smart contract's contract code passes the credibility verification, the smart contract's behavior is verified for credibility, resulting in a third verification result.

[0126] It should be noted that in this embodiment, the method for verifying the credibility of the behavior of the smart contract can be the same as the method for verifying the credibility of the contract behavior of the smart contract when the smart contract is called in the above embodiments, and will not be repeated here.

[0127] In this embodiment, the credibility of the smart contract during its life cycle is improved by separately verifying the credibility of the contract code and contract behavior of the smart contract before the smart contract is released.

[0128] The following describes the smart contract credibility proof device provided by the present invention. The smart contract credibility proof device described below and the smart contract credibility proof method described above can refer to each other.

[0129] Reference Figure 2 The embodiment of the present invention provides a smart contract credibility certification device, which is set in a consensus node in a blockchain system and includes:

[0130] The behavior sequence generation module 10 is used to obtain a call transaction request for a smart contract in the blockchain system and generate a first behavior sequence corresponding to the smart contract according to the call transaction request;

[0131] A first verification module 20 is configured to verify the credibility of the behavior of the smart contract based on the first behavior sequence and obtain a first verification result;

[0132] a transaction broadcast module 30, configured to write the transaction call request into a target block in the blockchain system and broadcast the transaction call request in the blockchain system;

[0133] A receiving module 40 is configured to receive a second verification result of the credibility of the behavior of the smart contract from each target node in the blockchain system;

[0134] The second verification result is obtained by the target node verifying the credibility of the behavior of the smart contract based on a second behavior sequence, where the second behavior sequence is generated by the target node according to the call transaction request; the target node is a node in the blockchain system other than the consensus node that has the authority to simulate execution of the smart contract;

[0135] The trustworthy certification module 50 is used to determine the trustworthiness of the smart contract based on the first verification result and the second verification result.

[0136] In one embodiment, the behavior sequence generation module 10 is further configured to:

[0137] Obtaining basic contract information of the smart contract according to the call transaction request; the basic contract information includes the contract name and the key system that triggers the call;

[0138] Determine the element information corresponding to the contract behavior of the smart contract based on the basic contract information; the element information includes the behavior subject, behavior object, executed operation, execution environment, execution time and execution number;

[0139] Verifying the execution environment of the smart contract based on the element information;

[0140] If the verification is successful, the smart contract is simulated and executed based on the element information to obtain the contract behavior information of the smart contract; the contract behavior information includes the call parameters, call sequence and call count of the key system;

[0141] Performing permission verification on the target system in the key system, and if the permission verification passes, generating a first behavior sequence corresponding to the smart contract based on the contract behavior information;

[0142] The target system is the key system that needs to access external data or call the smart contract.

[0143] In one embodiment, the smart contract credibility proof device further includes a benchmark library construction module for:

[0144] Based on the contract functions of the smart contract, the contract code of the smart contract is divided to obtain target code blocks corresponding to the contract functions;

[0145] Obtaining a key function set in each functional function in the target code block, and determining a target key system for each key function in the key function set to trigger a call;

[0146] Generate a control flow graph with each of the target key systems as a node, and divide the control flow graph into execution traces to obtain a system call sequence of the smart contract;

[0147] Dynamically testing the smart contract and adjusting the system call sequence based on the test results to obtain an expected behavior sequence corresponding to the smart contract;

[0148] A trusted behavior benchmark library corresponding to the smart contract is generated based on the expected behavior sequence.

[0149] In one embodiment, the benchmark library construction module is further configured to:

[0150] Determine a system call sequence set corresponding to a target function according to the expected behavior sequence; the target function is any one of the contract functions;

[0151] Traversing each target system call sequence in the system call sequence set, and counting target values ​​of system call parameters of each key system corresponding to the target system call sequence;

[0152] Based on the target value, extract key parameters from the system call parameters, and generate a value range for each key parameter;

[0153] Taking each key system corresponding to the target system call sequence as a segmentation point and the key parameter as a segmentation condition, constructing a trusted behavior rule corresponding to the target function based on the value range;

[0154] Calculate the benchmark value of the trusted behavior rule, and generate a trusted behavior benchmark library corresponding to the smart contract based on the benchmark value.

[0155] In one embodiment, the behavior sequence generation module 10 is further configured to:

[0156] Matching the contract behavior information with the trusted behavior benchmark library to determine the target trusted behavior rules corresponding to the contract behavior information;

[0157] Generate a first behavior sequence corresponding to the smart contract according to the target trusted behavior rule.

[0158] In one embodiment, the smart contract credibility verification device further includes a contract publishing module for:

[0159] Obtain a transaction request to create a smart contract in the blockchain system;

[0160] Performing credibility verification on the smart contract according to the transaction creation request to obtain a third verification result;

[0161] Creating a first block in the blockchain system, writing the transaction creation request into the first block, and broadcasting the transaction creation request in the blockchain system; the first block includes the identity information and computing environment of the consensus node, so that each target node can authenticate the consensus node and verify the credibility of the computing environment;

[0162] receiving a fourth verification result of the smart contract by each of the target nodes; the fourth verification result is obtained by the target node performing credibility verification on the smart contract according to the transaction creation request;

[0163] Determining the credibility of the smart contract based on the third verification result and the fourth verification result;

[0164] If the smart contract is credible, a contract release instruction is generated; the contract release instruction is used to indicate the release permission of the smart contract.

[0165] In one embodiment, the transaction creation request includes the identity information and computing environment of the target user requesting to create the smart contract; the contract publishing module is further configured to:

[0166] Performing credibility verification on the target user's identity and computing environment based on the transaction creation request, and verifying the target user's contract publishing authority to verify the credibility of the contract code of the smart contract;

[0167] If the credibility verification of the contract code of the smart contract passes, the credibility of the behavior of the smart contract is verified to obtain a third verification result.

[0168] Figure 3 An example of a physical structure diagram of an electronic device is shown below. Figure 3 As shown, the electronic device may include: a processor 310, a communication interface 320, a memory 330, and a communication bus 340, wherein the processor 310, the communication interface 320, and the memory 330 communicate with each other via the communication bus 340. The processor 310 may call the logic instructions in the memory 330 to execute the smart contract credibility proof method, which includes:

[0169] Obtaining a transaction request for invoking a smart contract in a blockchain system, and generating a first behavior sequence corresponding to the smart contract according to the transaction request;

[0170] Verifying the behavioral credibility of the smart contract based on the first behavior sequence to obtain a first verification result;

[0171] Writing the call transaction request into a target block in the blockchain system, and broadcasting the call transaction request in the blockchain system;

[0172] Receiving a second verification result of the credibility of the behavior of the smart contract from each target node in the blockchain system;

[0173] The second verification result is obtained by the target node verifying the credibility of the behavior of the smart contract based on a second behavior sequence, where the second behavior sequence is generated by the target node according to the call transaction request; the target node is a node in the blockchain system other than the consensus node that has the authority to simulate execution of the smart contract;

[0174] Determine the credibility of the smart contract based on the first verification result and the second verification result.

[0175] In addition, the logic instructions in the above-mentioned memory 330 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0176] On the other hand, the present invention further provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can perform the smart contract credibility proof method provided by the above methods, which includes:

[0177] Obtaining a transaction request for invoking a smart contract in a blockchain system, and generating a first behavior sequence corresponding to the smart contract according to the transaction request;

[0178] Verifying the behavioral credibility of the smart contract based on the first behavior sequence to obtain a first verification result;

[0179] Writing the call transaction request into a target block in the blockchain system, and broadcasting the call transaction request in the blockchain system;

[0180] Receiving a second verification result of the credibility of the behavior of the smart contract from each target node in the blockchain system;

[0181] The second verification result is obtained by the target node verifying the credibility of the behavior of the smart contract based on a second behavior sequence, where the second behavior sequence is generated by the target node according to the call transaction request; the target node is a node in the blockchain system other than the consensus node that has the authority to simulate execution of the smart contract;

[0182] Determine the credibility of the smart contract based on the first verification result and the second verification result.

[0183] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the method for proving the credibility of a smart contract provided by the above methods is implemented. The method includes:

[0184] Obtaining a transaction request for invoking a smart contract in a blockchain system, and generating a first behavior sequence corresponding to the smart contract according to the transaction request;

[0185] Verifying the behavioral credibility of the smart contract based on the first behavior sequence to obtain a first verification result;

[0186] Writing the call transaction request into a target block in the blockchain system, and broadcasting the call transaction request in the blockchain system;

[0187] Receiving a second verification result of the credibility of the behavior of the smart contract from each target node in the blockchain system;

[0188] The second verification result is obtained by the target node verifying the credibility of the behavior of the smart contract based on a second behavior sequence, where the second behavior sequence is generated by the target node according to the call transaction request; the target node is a node in the blockchain system other than the consensus node that has the authority to simulate execution of the smart contract;

[0189] Determine the credibility of the smart contract based on the first verification result and the second verification result.

[0190] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one location or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.

[0191] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, or of course, by hardware. Based on this understanding, the essence of the above technical solution or the part that contributes to the existing technology can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or certain parts of the embodiments.

[0192] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.

Claims

1. A smart contract credibility proof method, applied to the consensus node in the blockchain system, characterized by: The method comprises: Obtaining a transaction request for invoking a smart contract in a blockchain system, and generating a first behavior sequence corresponding to the smart contract according to the transaction request; Verifying the behavioral credibility of the smart contract based on the first behavior sequence to obtain a first verification result; Writing the call transaction request into a target block in the blockchain system, and broadcasting the call transaction request in the blockchain system; Receiving a second verification result of the credibility of the behavior of the smart contract from each target node in the blockchain system; The second verification result is obtained by the target node verifying the credibility of the behavior of the smart contract based on a second behavior sequence, where the second behavior sequence is generated by the target node according to the call transaction request; the target node is a node in the blockchain system other than the consensus node that has the authority to simulate execution of the smart contract; Determining the credibility of the smart contract based on the first verification result and the second verification result; Generating a first action sequence corresponding to the smart contract according to the calling transaction request includes: Obtaining basic contract information of the smart contract according to the call transaction request; the basic contract information includes the contract name and the key system that triggers the call; Determine the element information corresponding to the contract behavior of the smart contract based on the basic contract information; the element information includes the behavior subject, behavior object, executed operation, execution environment, execution time and execution number; Verifying the execution environment of the smart contract based on the element information; If the verification is successful, the smart contract is simulated and executed based on the element information to obtain the contract behavior information of the smart contract; the contract behavior information includes the call parameters, call sequence and call count of the key system; Performing permission verification on the target system in the key system, and if the permission verification passes, generating a first behavior sequence corresponding to the smart contract based on the contract behavior information; The target system is the key system that needs to access external data or call the smart contract.

2. The smart contract credibility proof method according to claim 1, characterized in that: Before generating the first action sequence corresponding to the smart contract according to the calling transaction request, the method further includes: Based on the contract functions of the smart contract, the contract code of the smart contract is divided to obtain target code blocks corresponding to the contract functions; Obtaining a key function set in each functional function in the target code block, and determining a target key system for each key function in the key function set to trigger a call; Generate a control flow graph with each of the target key systems as a node, and divide the control flow graph into execution traces to obtain a system call sequence of the smart contract; Dynamically testing the smart contract and adjusting the system call sequence based on the test results to obtain an expected behavior sequence corresponding to the smart contract; A trusted behavior benchmark library corresponding to the smart contract is generated based on the expected behavior sequence.

3. The smart contract credibility proof method according to claim 2, characterized in that: Generating a trusted behavior benchmark library corresponding to the smart contract based on the expected behavior sequence includes: Determine a system call sequence set corresponding to a target function according to the expected behavior sequence; the target function is any one of the contract functions; Traversing each target system call sequence in the system call sequence set, and counting target values ​​of system call parameters of each key system corresponding to the target system call sequence; Based on the target value, extract key parameters from the system call parameters, and generate a value range for each key parameter; Taking each key system corresponding to the target system call sequence as a segmentation point and the key parameter as a segmentation condition, constructing a trusted behavior rule corresponding to the target function based on the value range; Calculate the benchmark value of the trusted behavior rule, and generate a trusted behavior benchmark library corresponding to the smart contract based on the benchmark value.

4. The smart contract credibility proof method according to claim 2, characterized in that: Generating a first behavior sequence corresponding to the smart contract according to the contract behavior information includes: Matching the contract behavior information with the trusted behavior benchmark library to determine the target trusted behavior rules corresponding to the contract behavior information; Generate a first behavior sequence corresponding to the smart contract according to the target trusted behavior rule.

5. The smart contract credibility proof method according to claim 1, characterized in that: Before obtaining the transaction request for calling the smart contract in the blockchain system, the process further includes: Obtain a transaction request to create a smart contract in the blockchain system; Performing credibility verification on the smart contract according to the transaction creation request to obtain a third verification result; Creating a first block in the blockchain system, writing the transaction creation request into the first block, and broadcasting the transaction creation request in the blockchain system; the first block includes the identity information and computing environment of the consensus node, so that each target node can authenticate the consensus node and verify the credibility of the computing environment; receiving a fourth verification result of the smart contract by each of the target nodes; the fourth verification result is obtained by the target node performing credibility verification on the smart contract according to the transaction creation request; Determining the credibility of the smart contract based on the third verification result and the fourth verification result; If the smart contract is credible, a contract release instruction is generated; the contract release instruction is used to indicate the release permission of the smart contract.

6. The smart contract credibility proof method according to claim 5, characterized in that: The transaction creation request includes the identity information and computing environment of the target user requesting to create the smart contract; The performing credibility verification on the smart contract according to the transaction creation request to obtain a third verification result includes: Performing credibility verification on the target user's identity and computing environment based on the transaction creation request, and verifying the target user's contract publishing authority to verify the credibility of the contract code of the smart contract; If the credibility verification of the contract code of the smart contract passes, the credibility of the behavior of the smart contract is verified to obtain a third verification result.

7. A smart contract credibility verification device, which is set in a consensus node in a blockchain system, characterized in that: The device comprises: A behavior sequence generation module is configured to obtain a transaction request for invoking a smart contract in the blockchain system and generate a first behavior sequence corresponding to the smart contract based on the transaction request; A first verification module, configured to verify the credibility of the behavior of the smart contract based on the first behavior sequence, and obtain a first verification result; a transaction broadcast module, configured to write the transaction call request into a target block in the blockchain system and broadcast the transaction call request in the blockchain system; A receiving module, configured to receive a second verification result of the credibility of the behavior of the smart contract from each target node in the blockchain system; The second verification result is obtained by the target node verifying the credibility of the behavior of the smart contract based on a second behavior sequence, where the second behavior sequence is generated by the target node according to the call transaction request; the target node is a node in the blockchain system other than the consensus node that has the authority to simulate execution of the smart contract; a trustworthy certification module, configured to determine the trustworthiness of the smart contract based on the first verification result and the second verification result; The behavior sequence generation module is further used to: Obtaining basic contract information of the smart contract according to the call transaction request; the basic contract information includes the contract name and the key system that triggers the call; Determine the element information corresponding to the contract behavior of the smart contract based on the basic contract information; the element information includes the behavior subject, behavior object, executed operation, execution environment, execution time and execution number; Verifying the execution environment of the smart contract based on the element information; If the verification is successful, the smart contract is simulated and executed based on the element information to obtain the contract behavior information of the smart contract; the contract behavior information includes the call parameters, call sequence and call count of the key system; Performing permission verification on the target system in the key system, and if the permission verification passes, generating a first behavior sequence corresponding to the smart contract based on the contract behavior information; The target system is the key system that needs to access external data or call the smart contract.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the smart contract credibility proof method according to any one of claims 1 to 6 is implemented.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for proving the credibility of a smart contract as described in any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Supervision method for intelligent contract behaviors

    CN111581047A

  • Block chain intelligent contract attack behavior detection method, storage medium and electronic equipment

    CN115293776A