Smart contract processing method and device, computer equipment and storage medium
By introducing a formal verification engine into the blockchain network and pre-deploying smart contracts, we can solve the security issues in the smart contract publishing process, achieve the consistency and reliability of smart contract security verification, and avoid data privacy leakage caused by contract vulnerabilities.
Patent Information
- Application Number
- CN202410344962.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-21
- Publication Date
- 2025-09-23
AI Technical Summary
The publishing process of smart contracts in existing technologies has security issues, especially data privacy leakage caused by contract loopholes, and lacks an effective security verification mechanism.
By introducing a formal verification engine into the blockchain network, the smart contract is pre-deployed. The security verification is first performed on the computer device to obtain the first verification result. After being stored in the cache pool, it is broadcast to other consensus nodes for further verification and finally deployed in the blockchain network.
It achieves the consistency and reliability of security verification of smart contracts, avoids security issues caused by contract loopholes, and ensures data security in the blockchain network.
Smart Images

Figure CN120688052A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a smart contract processing method, apparatus, computer equipment, and storage medium. Background Art
[0002] Blockchain is a decentralized, distributed ledger that is tamper-proof, secure, and reliable. Therefore, data storage and transaction execution on the blockchain effectively guarantee data security. The data storage process involved in blockchain often involves the invocation of smart contracts. Smart contracts are published to the blockchain network after consensus is reached by each consensus node. Currently, the publishing process for smart contracts uses a free deployment method. Once a smart contract with a vulnerability is published to the blockchain, data privacy leaks are inevitable. Therefore, how to securely publish smart contracts has become a current research hotspot. Summary of the Invention
[0003] Embodiments of the present invention provide a smart contract processing method, apparatus, computer equipment, and storage medium, which can improve the security of smart contract issuance.
[0004] In one aspect, an embodiment of the present invention provides a method for processing a smart contract, wherein the blockchain network includes at least one consensus node, and the method is executed by any consensus node, and the method includes:
[0005] Obtaining a smart contract to be deployed to the blockchain network from a pre-deployment interface, and obtaining a formalized management contract from the blockchain network, performing a security verification process on the smart contract using the formalized management contract, and obtaining a first verification result of the smart contract;
[0006] When the first verification result indicates that the smart contract is a secure contract, storing the smart contract in a cache pool, and broadcasting the smart contract to other consensus nodes of the blockchain network through the pre-deployment interface for security verification processing;
[0007] Obtain a second verification result obtained after the other consensus nodes perform security verification processing on the smart contract, and based on the second verification result, deploy the smart contract stored in the cache pool in the blockchain network through the deployment interface.
[0008] In another aspect, an embodiment of the present invention provides a smart contract processing device based on a blockchain network, characterized in that the blockchain network includes at least one consensus node, the device is any consensus node, and the device includes:
[0009] an acquiring unit, configured to acquire a smart contract to be deployed to the blockchain network from a pre-deployment interface, and acquire a formalized management contract from the blockchain network, and perform a security verification process on the smart contract using the formalized management contract to obtain a first verification result of the smart contract;
[0010] a processing unit, configured to, when the first verification result indicates that the smart contract is a secure contract, store the smart contract in a cache pool, and broadcast the smart contract to other consensus nodes of the blockchain network through the pre-deployment interface for security verification processing;
[0011] The acquisition unit is further configured to obtain a second verification result obtained after the other consensus nodes perform security verification processing on the smart contract;
[0012] The processing unit is further configured to deploy the smart contract stored in the cache pool in the blockchain network through a deployment interface based on the second verification result.
[0013] In yet another aspect, an embodiment of the present invention provides a computer device, comprising a processor, an input device, an output device, and a memory, wherein the processor, input device, output device, and memory are interconnected, wherein the memory is used to store a computer program that supports the computer device in executing the above method, wherein the computer program includes program instructions, and the processor is configured to call the program instructions and perform the following steps:
[0014] Obtaining a smart contract to be deployed to the blockchain network from a pre-deployment interface, and obtaining a formalized management contract from the blockchain network, performing a security verification process on the smart contract using the formalized management contract, and obtaining a first verification result of the smart contract;
[0015] When the first verification result indicates that the smart contract is a secure contract, storing the smart contract in a cache pool, and broadcasting the smart contract to other consensus nodes of the blockchain network through the pre-deployment interface for security verification processing;
[0016] Obtain a second verification result obtained after the other consensus nodes perform security verification processing on the smart contract, and based on the second verification result, deploy the smart contract stored in the cache pool in the blockchain network through the deployment interface.
[0017] On the other hand, an embodiment of the present invention provides a computer-readable storage medium, in which program instructions are stored. When the program instructions are executed by a processor, the program instructions are used to execute the smart contract processing method as described in the first aspect.
[0018] On the other hand, an embodiment of the present invention provides a computer program product, characterized in that the computer program product includes a computer program or computer instructions, and the computer program or the computer instructions are executed by a processor as the smart contract processing method described in the first aspect.
[0019] In an embodiment of the present application, after obtaining a smart contract from a pre-deployment interface, the computer device may first perform a security verification process on the smart contract to obtain a corresponding first verification result. Then, when the first verification result indicates that the smart contract is a secure contract, the computer device may store the smart contract in a cache pool and simultaneously broadcast the smart contract to other consensus nodes for security verification. Furthermore, based on a second verification result obtained after other consensus nodes perform security verification on the smart contract, the computer device may deploy the smart contract in the blockchain network through the deployment interface, thereby enabling the computer device to implement the pre-deployment process through the pre-deployment interface, i.e., the contract code and the basic state of the contract are published, but the contract is unavailable. At this time, the consensus nodes will each perform security checks such as pattern matching and symbolic execution on the pre-published contract through a preset smart contract formal verification engine. After the test passes, the consensus proposer will finally publish the smart contract on the chain and trigger the pre-deployed contract to officially take effect, thereby effectively avoiding security issues caused by directly publishing a smart contract with vulnerabilities on the chain, thereby ensuring the security of the smart contract published on the blockchain network. When computer equipment verifies the security of the smart contract, it mainly uses the formal verification method. The formal method adopted in the embodiment of the present application, by putting the formal verification contract on the chain, enables different consensus nodes to verify the smart contract using the same formal verification contract, thereby ensuring the consistency of the verification of the smart contract. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. 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.
[0021] Figure 1a is a schematic diagram of a distributed system provided by an embodiment of the present invention;
[0022] Figure 1b Schematic diagram of a blockchain network-based smart contract processing system provided by an embodiment of the present invention;
[0023] Figure 1c is a schematic diagram of a formalized conversion provided by an embodiment of the present invention;
[0024] Figure 2 is a schematic flow chart of a smart contract processing method provided by an embodiment of the present invention;
[0025] Figure 3a This is a schematic diagram of a security verification method provided by an embodiment of the present invention;
[0026] Figure 3b is a schematic diagram of a security verification process provided by an embodiment of the present invention;
[0027] Figure 3c This is a schematic diagram of a security verification based on the K framework provided by an embodiment of the present invention;
[0028] Figure 3d This is a schematic diagram of a smart contract deployment provided by an embodiment of the present invention;
[0029] Figure 4 This is a schematic diagram of the structure of a layered blockchain network provided by an embodiment of the present invention;
[0030] Figure 5 This is a business diagram of an electronic invoice business provided by an embodiment of the present invention;
[0031] Figure 6 is a schematic block diagram of a smart contract processing device provided by an embodiment of the present invention;
[0032] Figure 7 This is a schematic block diagram of a computer device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0033] Blockchain is a novel application model for computer technologies, including distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Essentially, a blockchain is a decentralized database, a chain of data blocks linked together using cryptographic methods. Each block contains information about a batch of network transactions, used to verify the validity of this information (to prevent counterfeiting) and generate the next block. A blockchain can include an underlying blockchain platform, a platform product and service layer, and an application service layer. The underlying blockchain platform includes processing modules such as object management, basic services, smart contracts, and operations management. The smart contract module is responsible for contract registration, issuance, contract triggering, and execution. Developers can define contract logic in a programming language and publish it to the blockchain (contract registration). Based on the contract terms, execution is triggered by calling keys or other events, completing the contract logic. It also provides the ability to upgrade and cancel contracts.
[0034] The blockchain system involved in the embodiment of the present application can be a distributed system formed by connecting a client and multiple nodes through network communication, wherein any node can be any form of computing device in the access network, specifically a server or an object terminal. In one embodiment, the distributed system of the blockchain system can be as follows: Figure 1a As shown, Figure 1a This is an optional structural diagram of a distributed system 100 provided by an embodiment of the present invention applied to a blockchain system, which consists of multiple nodes (such as Figure 1a Node 200 in ) and client (such as Figure 1a In a distributed system, any machine such as a server or terminal can join and become a node. The node includes a hardware layer, an intermediate layer, an operating system layer, and an application layer. Figure 1a In the blockchain system shown, each node can implement application services including smart contracts. Among them, smart contracts are computerized protocols that can execute the terms of a contract. They are implemented through code deployed on a shared ledger for execution when certain conditions are met. According to actual business needs, the code is used to complete automated transactions, such as querying the logistics status of the buyer's purchased goods and transferring the buyer's electronic resources to the merchant's address after the buyer signs for the goods. Of course, smart contracts are not limited to executing contracts for transactions, but can also execute contracts for processing received information.
[0035] The embodiments of the present application mainly relate to the deployment processing of smart contracts in the blockchain network. Specifically, when a computer device needs to deploy a smart contract to the blockchain network, it can first perform pre-deployment processing on the smart contract after obtaining the smart contract to be deployed, and then combine the consensus verification of the smart contract by other consensus nodes to realize the on-chain deployment of the smart contract. When the computer device deploys the smart contract, it avoids the direct release of the smart contract and instead adopts the form of pre-deployment, thereby avoiding the direct on-chain use and development of smart contracts with logical omissions, and thus effectively avoiding the losses caused by the existence of smart contract vulnerabilities. In one embodiment, the pre-deployment of the smart contract means that the contract code and basic state of the smart contract have been published to the blockchain network, but the smart contract is in an unavailable state. Then, based on the pre-deployment processing of the smart contract, other nodes in the blockchain network can obtain the smart contract from the blockchain network, but cannot execute transactions based on the smart contract, thereby ensuring the security and reliability of the smart contract while ensuring the accessibility of the smart contract to the blockchain node.
[0036] In one embodiment, the computer device can also be any node device in the blockchain network, and the computer device can be a terminal device or a server, wherein the terminal device includes but is not limited to: smart phones, tablet computers, smart wearable devices, smart voice interaction devices, smart home appliances, personal computers, vehicle terminals and other devices, and this application does not impose any restrictions on this. This application does not limit the number of terminal devices. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Deliver Network), and big data and artificial intelligence platforms, but is not limited to this. Similarly, this application does not impose any restrictions on the number of servers. The system architecture for the computer device and other node devices in the blockchain network to deploy smart contracts can be as follows: Figure 1b As shown. Figure 1b As shown, the computer device may be as Figure 1b The device marked by 10 in the figure, other node devices in the blockchain network can be as follows Figure 1b Any device marked by 11, and the computer device 10 and other node devices 11 are devices connected to the blockchain network.
[0037] When a computer device pre-deploys a smart contract, it must first perform a security check on the smart contract. In a specific implementation, the computer device can use a formal verification engine to perform security verification on the smart contract. The process of the computer device using a formal verification engine to perform security verification on the smart contract is the process of using the formal verification engine to perform formal verification on the smart contract. Formalization refers to the use of mathematical and logical proofs to model, specify, analyze, and reason about computer systems. It mainly covers the following research directions: theorem proving, formal models, formal semantics and formal modeling, formal specification, and formal verification technology. In the embodiment of the present application, formal processing of the smart contract is achieved by formally compiling the smart contract and constructing a corresponding syntax tree based on the smart contract. In one embodiment, the process of data processing based on formal thinking can be as follows. Figure 1cAs shown, when a system described in language needs to be judged to determine whether it possesses the desired properties based on the system's property description, based on the concept of formal transformation, a state transition system can be used to mathematically describe the system's behavior, and modal / temporal logic formulas can be used to mathematically describe the system's properties. Therefore, the question of whether the system to be determined possesses the desired properties is transformed into the question of whether the state transition system has the corresponding logical formula. This shows that based on the concept of formalization, it is possible to convert language descriptions that are not conducive to calculation and implementation into corresponding mathematical descriptions, thereby solving mathematical problems based on the results of computer calculation processes.
[0038] Among them, after converting the events to be processed into corresponding mathematical descriptions based on formalization ideas, the verification of mathematical problems mainly includes the following four steps: ① Provide the program source code (that is, the program source code of the mathematical problem); ② Mark the properties to be verified (Property / Specification); ③ Convert the problem to be verified into the corresponding logical formula (LogicFormula); ④ Prove the correctness of the converted logical formula (Correctness / Validity).
[0039] In one embodiment, mathematical problems obtained based on formalization ideas can be solved by reasoning using theorem proving, and the theorem proving method can be mainly carried out from the following two aspects:
[0040] 1) Interactive reasoning: Let computers assist in proving problems, such as Coq (an interactive proof assistant tool) and Isabelle (another proof assistant tool). The subject can send the mathematical problem to be solved to the proof assistant tool for problem solving.
[0041] 2) Automated reasoning: Allow computers to automatically prove problems, including SMT satisfiability modulo theory (algorithms implemented as Z3 and C4V4) and Resolution specification (algorithms implemented as SPASS and Vampire).
[0042] Based on the above-mentioned formal transformation ideas, it also involves formal models, formal semantics, formal modeling and formal specifications.
[0043] Formal models: Mathematical models that receive, generate, and transform specific structures (such as strings and trees). Automata models are widely studied, but they also include grammars and rewriting systems for representing programming languages. It's understandable that the fundamental theories and mathematical research tools for semantics and modeling are based on the idea of formal models.
[0044] Formal semantics (primarily for programming languages): Using mathematics as a tool, symbols and formulas are used to precisely define and rigorously explain the semantics of computer programming languages. This includes four semantic operations: algebra, reference, and axioms. Intermediate semantics uses the metalanguage of theorem provers (Coq, ACL2, Isabelle, HOL) and is generally verified manually or semi-automatically.
[0045] Formal modeling (primarily for computer system behavior): Formal models that describe behavior and properties. Functional programs and embedded systems often use automata for modeling. Adaptive systems and multi-agent systems generally use Petri nets, UML, the Z method, and Markov models. Automata are specialized formal models, while Petri nets, Event-B, Pi-calculus, CSP, and other general-purpose models are used.
[0046] Formal specification: Explicitly defining the properties a system should satisfy is called a specification. Classical methods for sequential programs use first-order Boolean logic, relational symbols, and first-order quantifiers, such as Floyd-Hoare. However, this method cannot describe memory layout. Separation logic was later proposed to support independent memory operations. For concurrent programs, which generally do not terminate without input or output, sequential logic is typically used for specification, including LTL, CTL, and CTL*.
[0047] Formal verification can be implemented using at least one of deductive reasoning, abstract interpretation, model checking, or symbolic execution. Deductive reasoning is used to convert specifications into mathematical proofs, creating proof obligations, and then solving them. Abstract interpretation is used to abstract program semantics to varying degrees (simplifying the actual model and improving computational efficiency), aiming to build a universal framework. Model checking verifies that the model satisfies constraints by traversing the system state space. This typically includes temporal model checking (based on logical formulas) and equivalence checking (based on automata). Symbolic execution systematically traverses the program path space, incorporating symbolic analysis to cover more program behavior. Symbolic execution, along with SAT / SMT techniques, often employs CFG control flow graphs. Classic tools include KLEE. Alternatively, symbolic execution is to statically execute the program through symbolic values, accumulate path conditions until the target location is reached, and then perform constraint solving on the path conditions to determine the reachability of the target location. Among them, symbolic execution emphasizes path traversal, while model checking mainly considers whether the state space exists.
[0048] Based on the above-mentioned formal processing ideas, the embodiment of the present application needs to verify the security of the smart contract before deploying the smart contract. Since the smart contract adopts contract rules described in language, based on the above-mentioned formal idea, the smart contract can be formally converted first, and then the converted problems can be verified to obtain the security verification results of the smart contract. For the security verification process of the smart contract and the process of deploying it on the chain, please refer to the detailed description of the subsequent embodiments.
[0049] See Figure 2 , is a schematic flow chart of a smart contract processing method based on a blockchain network proposed in an embodiment of the present application, wherein the blockchain network includes at least one consensus node, and the method is executed by any consensus node of the blockchain network, such as Figure 2 As shown, the method may include:
[0050] S201, obtaining a smart contract to be deployed to the blockchain network from a pre-deployment interface, and obtaining a formal management contract from the blockchain network, so as to perform security verification on the smart contract using the formal management contract and obtain a first verification result of the smart contract.
[0051] The computer device can obtain the smart contract to be deployed to the blockchain network from the object device through the pre-deployment interface, wherein the object device is the device where the smart contract corresponding writer is located. That is, after the smart contract corresponding writer completes the writing of the smart contract on the corresponding device, when the smart contract needs to be published and deployed to the blockchain network, the written smart contract can be sent to the computer device through the pre-deployment interface in the computer device connected to the device for pre-deployment processing. In one embodiment, the computer device is the device corresponding to any consensus node in the blockchain network, and the object device can be a terminal device or a server, which is not limited in the embodiments of the present application. In addition, it should be noted that the object device can also be a device joining the blockchain network or an off-chain device. When the object device is an off-chain device, the object device can communicate with each node in the blockchain network through the corresponding interface.
[0052] After the object device sends the completed smart contract to the computer device through the pre-deployment interface, the computer device can perform basic format verification on the smart contract in the pre-deployment interface, and only after the format verification passes, it performs security verification on the smart contract to obtain the corresponding first verification result. When the computer device performs format verification on the smart contract through the pre-deployment interface, it controls the pre-deployment interface to perform format verification on the smart contract, and then after the smart contract passes the format verification, it stores the smart contract in the formal verification engine to trigger the formal verification engine to perform security verification on the smart contract. In one embodiment, the format verification performed on the smart contract includes: verifying the code format, writing format, etc. of the smart contract. Based on the early format verification of the smart contract, it can be ensured that the smart contract is a smart contract that can operate normally in the blockchain network, rather than a smart contract with operating errors. This also ensures the effectiveness of the subsequent security verification performed by the computer device to a certain extent, and can effectively save the operating resources of the computer device.
[0053] After completing the format verification of the smart contract in the pre-deployment interface, the computer device can send the smart contract to a formal verification engine, which is also an engine within the computer device. After the formal verification engine obtains the smart contract, it can perform a security verification on the smart contract during the security verification process. It can also assess the security score of the smart contract based on certain security redline rules, thereby obtaining a first verification result for the smart contract. In other words, the first verification result obtained by the computer device from performing the security verification on the smart contract can include the assessment score obtained from the security assessment of the smart contract.
[0054] In one embodiment, the formal verification engine included in the computer device is a module for performing security verification on the smart contract. When performing security verification, this module will be divided into two parts, on-chain and off-chain, to be executed separately. The process of the formal verification engine performing security verification on the smart contract can be as follows: Figure 3aAs shown, the on-chain portion of the formal verification engine stores a formal management contract, which is used to publicly disclose the pattern verification rules and the set red line rules (or risk management rules) for verifying smart contracts. By storing the formal management contract on the chain, the non-tamperability of the formal management contract can be guaranteed. Based on the non-tamperability of the security verification of the smart contract, the fairness and justice of the verification of the smart contract is guaranteed, thereby ensuring the reliability of the results of the security verification of the smart contract. In addition, since the formal management contract is stored on the chain in the blockchain network, when the formal verification engine performs security verification on the smart contract, it first obtains the formal management contract from the blockchain network, and then performs security verification on the smart contract based on the verification rules and set red line rules in the formal management contract. In one embodiment, the verification rules set in the formal management contract include one or more of the following: verifying whether the smart contract has vulnerabilities, whether it is set by the administrator, whether there is an overflow risk, etc., and the redline rules set in the formal management contract are used to indicate the minimum conditions when the smart contract meets each verification rule, as well as the degree of satisfaction (or satisfaction level) between the smart contract and each verification rule.
[0055] Based on the formal verification engine, when the computer device performs security verification on the smart contract, it can first obtain the formal management contract from the blockchain network; the formal management contract is used to specify the verification rules required for security verification; then, the computer device can use the verification rules specified in the formal management contract (including the above-mentioned pattern verification rules and the set red line rules for smart contract verification) to perform security verification on the smart contract locally, thereby obtaining the first verification result of the smart contract. In one embodiment, when the computer device uses the verification rules specified in the formal management contract to perform security verification on the smart contract locally, it can first use a formal compiler to perform formal conversion processing on the smart contract locally, and obtain the syntax tree (AST) corresponding to the smart contract based on the result of the formal conversion processing; then, the syntax tree can be verified using the verification rules specified in the formal management contract to obtain the first verification result of the smart contract.
[0056] In one embodiment, since the smart contract is stored locally in the form of bytecode, the computer device locally uses a formal compiler to perform formal conversion processing on the smart contract. When the syntax tree corresponding to the smart contract is obtained based on the result of the formal conversion processing, the bytecode of the smart contract can be first converted by byte using a formal compiler locally to obtain the corresponding intermediate representation; then the syntax tree is constructed based on the intermediate representation to obtain the syntax tree corresponding to the smart contract. Among them, the syntax tree (or contract syntax tree) is the main carrier of the formal verification of the contract. By converting the smart contract into the corresponding contract syntax tree, the syntax structure of the smart contract can be more clearly displayed, so that when the formal verifier performs verification processing later, it can perform pattern matching processing on the smart contract based on the structure displayed by the contract syntax tree, thereby improving the accuracy of the security verification of the smart contract.
[0057] It can be understood that the process of the computer device performing a local security verification on a smart contract is the process of executing a security verification process off-chain based on the formal management contract obtained from the chain. When the computer device performs security verification on the smart contract off-chain, it mainly involves three modules: a formal compiler, a formal verifier, and a verification result processor. Among them, the contract formal compiler is used to convert the smart contract, and the formal verifier and verification result processor can perform security verification on the converted smart contract based on the verification rules in the formal management contract. In one embodiment, the formal management contract includes pattern verification rules and set redline rules for verifying the smart contract. Then, when the computer device performs security verification on the smart contract, the formal verifier specifically performs contract verification based on the pattern verification rules for verifying the smart contract in the formal management contract, and the verification result processor specifically summarizes the verification results based on the redline rules set in the formal management contract.
[0058] Based on the verification rules specified in the formal management contract, including pattern verification rules and risk management rules, when a computer device verifies a syntax tree using the verification rules specified in the formal management contract and obtains a first verification result of the smart contract, it can first use the pattern verification rules in the verification rules specified in the formal management contract to perform pattern matching on the syntax tree to obtain a pattern matching result; then, based on the risk management rules in the verification rules, it can perform risk analysis on the pattern matching result to obtain a risk analysis result, and then use the risk analysis result as the first verification result of the smart contract. In one embodiment, the pattern matching result obtained by the computer device performing pattern matching on the syntax tree can be used to indicate the logical situation of the syntax tree corresponding to the smart contract; then, based on the risk management rules in the verification rules, the computer device performs risk analysis on the pattern matching result to obtain a risk analysis result, and then, based on the risk management rules in the verification rules, it can determine a risk score corresponding to the logical situation indicated by the pattern matching result, and the risk score is the risk analysis result; wherein the value of the risk score is negatively correlated with the logical situation of the syntax tree corresponding to the smart contract; and when the risk score is less than or equal to a preset threshold, the first verification result of the smart contract indicates that the smart contract is a safe contract.
[0059] In one embodiment, when a computer device performs pattern matching on a syntax tree based on a pattern verification rule, since the pattern verification rule records the abnormal conditions existing in the smart contract, the pattern matching of the syntax tree by the pattern verification rule can analyze the vulnerability risks and logical errors that may exist in the smart contract. It can be understood that when a syntax branch of the syntax tree corresponding to the smart contract matches the abnormal conditions recorded by the pattern verification rule, it means that the smart contract also has a corresponding abnormal condition. In other words, through the pattern verification rule, the computer device can analyze the syntax or logic conditions of the smart contract to determine the vulnerability risks and logical errors that may exist in the smart contract. After the pattern verification rule is used to perform pattern matching on the smart contract, the pattern matching results can be output to the verification result processor, so that the verification result processor can organize the pattern matching results based on the risk management rule, obtain the corresponding risk score, and output the corresponding risk score as the verification result of the first smart contract.
[0060] Next, combine Figure 3b, describing the process of using a formal verification engine on a computer device to perform security verification on a smart contract. The on-chain portion of the formal verification engine includes a formal management contract (or formal verification management contract), which is used to publicly manage verification rules, set redline rules, and perform formal verification management on smart contracts. All off-chain formal verification engines can then read the rules and pass standards through this on-chain contract, thereby enabling a unified verification logic to be used for formal verification when performing security verification on the blockchain network's smart contracts. As for the off-chain portion of the formal verification engine, the following three modules are used to perform the formal verification processing locally.
[0061] ① Contract Formalization Compiler. This is the first step in processing the contract bytecode of a smart contract. Unlike ordinary compilers that convert high-level languages into target languages or bytecodes, this module mainly converts contract bytecodes into an intermediate representation language and then constructs a syntax tree (AST) based on this intermediate representation. The contract syntax tree is used as the main carrier for contract formal verification.
[0062] ② Formal Verifier. After obtaining the contract syntax tree, it performs pattern matching on the contract syntax tree according to the formal verification rules read from the formal management contract, i.e., the aforementioned pattern verification rules. It analyzes the possible vulnerability risks and logical errors in the smart contract and then outputs the obtained results to the verification result processor.
[0063] ③ Verification result processor. After obtaining the verification results provided by the formal verifier, the risk errors in the verification results can be sorted out according to the red line rules in the formal management contract, that is, the risk management rules mentioned above, to obtain relevant risk judgments and calculate scores. Based on the final score, it is determined whether the contract has passed the risk verification, and the risk issues of passing or failing are sorted into formatted results and returned to the outside (that is, the object device where the smart contract corresponding to the writing object is located).
[0064] In one embodiment, after obtaining a risk score, the verification result processor may determine that the smart contract has passed security verification if the risk score is less than or equal to a preset threshold. In this case, the obtained first verification result may indicate that the smart contract is a safe contract. If the risk score is greater than the preset threshold, the smart contract may be determined to have failed security verification, and a first verification result may be obtained indicating that the smart contract is a risky contract. If the first verification result obtained by the verification result processor indicates that the smart contract is a safe contract, step S202 may be executed instead. If the first verification result obtained by the verification result processor indicates that the smart contract is a risky contract, the risk issue of the smart contract being determined to be a risky contract may be returned to the target device via the smart contract's pre-deployment interface, so that the target device can adjust the smart contract based on the displayed risk issue. Furthermore, if the target device determines that the smart contract is a risky contract, it may trigger the computer device to stop deploying the blockchain network and simultaneously broadcast this to other node devices in the blockchain network, ceasing security verification and consensus processing on the smart contract, thereby enabling efficient storage of computing resources in the blockchain network.
[0065] In addition, when a computer device determines that a smart contract obtained from a certain object device has a risk problem, it can stop receiving other smart contracts uploaded by the object device within a certain time range to avoid the problem of the relevant object device maliciously uploading smart contracts to consume the network resources of the blockchain network.
[0066] In one embodiment, when a computer device performs security verification on a smart contract, it can also use the K framework to perform security verification on the smart contract. The K framework is a semantic framework based on a rewriting logic system (Rewriting). Therefore, a language system can be created based on the K framework. Since the K framework itself is a language system, then, based on the language system, a programming language can be created, a type system can be built, a formal analysis tool can be written, and the K framework can be used to implement the above functions based on configuration (Configuration) and rules (Rule). The process of the K framework performing security verification on a smart contract can be as follows: Figure 3cAs shown. First, the smart contract can be processed by a solid-state compiler to obtain the corresponding bytecodes of the smart contract, and the bytecodes are transmitted to the K framework. Then, the refined specifications in the contract specification of the smart contract can be transmitted to the K framework. The K framework can then perform security verification on the bytecode of the smart contract according to the refined rules under the framework based on virtual machine semantics and hints, and obtain corresponding verification results. Among them, the verification results obtained by using the K framework to perform security verification on the smart contract can also be transmitted to the object device of the corresponding programming object of the smart contract. Among them, the refined rules in the contract specification of the smart contract are the above-mentioned formal management contracts.
[0067] S202: When the first verification result indicates that the smart contract is a secure contract, the smart contract is stored in a cache pool, and the smart contract is broadcast to other consensus nodes of the blockchain network through a pre-deployment interface for security verification processing.
[0068] After obtaining the first verification result of the smart contract, the computer device may, if the first verification result indicates that the smart contract is safe, broadcast the smart contract to other consensus nodes in the blockchain network via the pre-deployment interface and store the smart contract in a cache pool. If the first verification result indicates that the smart contract is dangerous, the computer device may obtain the logical issues that make the smart contract dangerous and output the logical issues to prohibit the deployment of the smart contract on the blockchain network. A dangerous smart contract means that the smart contract contains a contract vulnerability or contract risk. If a smart contract contains a contract vulnerability or contract risk, deploying the smart contract on the blockchain will cause certain losses to the target nodes in the blockchain network. Therefore, if the smart contract is dangerous, the deployment of the smart contract on the blockchain network may be prohibited to prevent losses caused by the smart contract. If the computer device determines that the smart contract is dangerous, it may also output the logical issues that make the smart contract dangerous to the smart contract's authoring object so that the authoring object can adjust and process the smart contract.
[0069] After the computer device determines that the smart contract is a secure contract, when storing the smart contract in the cache pool, it can first perform a hash operation on the smart contract to obtain the contract hash value of the smart contract (i.e., the contract hash); then, the computer device can obtain the contract bytecode of the smart contract and associate the contract hash value with the contract bytecode and store it in the cache pool. In other words, the smart contract is stored in the cache pool in the form of [contract hash: contract bytecode], and the storage of the smart contract in the cache pool is persistent storage, rather than just cached in memory. In one embodiment, after the computer device determines that the first test result indicates that the smart contract is a secure contract, it can first store the smart contract in the cache pool and then broadcast the smart contract to other consensus nodes of the blockchain network; alternatively, it can first broadcast the smart contract to other consensus nodes and then store it in the cache pool; alternatively, the computer device can also broadcast and cache the smart contract simultaneously.
[0070] In one embodiment, when the computer device broadcasts the smart contract to other consensus nodes in the blockchain network, it also broadcasts it through the pre-deployment interface, and the other consensus nodes also obtain the broadcasted smart contract through the included pre-deployment interface. After obtaining the smart contract from the pre-deployment interface, the other consensus nodes will also call their own included formal verification engine to verify the smart contract and obtain the corresponding second verification result. After obtaining the corresponding second verification result, any other consensus node can return the second verification result to the computer device through its own pre-deployment interface, so that the computer device can obtain the second verification result returned by each other consensus node from the corresponding pre-deployment interface and then execute step S203.
[0071] When any other consensus node performs security verification on the smart contract, it also includes the following Figure 3a The on-chain and off-chain processes shown in the figure mean that when each consensus node in the blockchain network (including the consensus node corresponding to the computer device and any other consensus node) performs security verification on the smart contract, the formal management contract obtained for verification is obtained from the blockchain network chain, thereby ensuring the consistency of rules when different consensus nodes perform security verification on the smart contract.
[0072] S203, obtaining a second verification result obtained after other consensus nodes perform security verification processing on the smart contract, and based on the second verification result, deploying the smart contract stored in the cache pool in the blockchain network through the deployment interface.
[0073] After the other consensus nodes complete the security verification process on the smart contract and obtain the corresponding second verification result, the computer device can obtain the second verification result from the other consensus nodes. The computer device also obtains the second verification result from the other nodes through the pre-deployment interface of the other nodes. In one embodiment, there is at least one other consensus node, and each consensus node obtains a corresponding second verification result after performing security verification on the smart contract. Therefore, the process of the computer device obtaining the second verification result from the other consensus nodes is to obtain the second verification result obtained by each other consensus node after performing security verification on the smart contract. Based on the computer device's acquisition of the second verification result of each other consensus node on the smart contract, the computer device can further deploy the smart contract based on the obtained second verification result. In a specific implementation, when the computer device deploys the smart contract stored in the cache pool on the blockchain network based on the second verification result, it can first determine the number of second verification results obtained from at least one consensus node. Furthermore, when the number meets the quantity threshold, the computer device can deploy the smart contract stored in the cache pool on the blockchain network based on the obtained second verification result.
[0074] In one embodiment, when the number of other consensus nodes is N, N is a positive integer greater than or equal to 1, and one other consensus node obtains a corresponding second verification result after performing security verification processing on the smart contract, then when the computer device obtains the second verification result and triggers the deployment processing of the smart contract based on the second verification result, the computer device may trigger the deployment processing of the smart contract based on the second verification result after obtaining the second verification results corresponding to all N other consensus nodes. Alternatively, in another implementation, the computer device may directly trigger the deployment processing of the smart contract in the blockchain network when it obtains the second verification results of K other consensus nodes, and when the value of K is greater than the value of 2N / 3, and when these K second verification results all indicate that the smart contract is a secure contract, and the deployment processing of the smart contract in this case is to determine to directly deploy the smart contract on the blockchain network.
[0075] That is, after obtaining the second verification result corresponding to at least one other consensus node, the computer device will deploy the smart contract to the blockchain network when there are a sufficient number (2F+1) of second verification results in the at least one second verification result indicating that the smart contract is a secure contract. When there are not a sufficient number of second verification results indicating that the smart contract is a secure contract, the smart contract may be canceled from being deployed to the blockchain network. In other words, when the computer device deploys the smart contract stored in the cache pool on the blockchain network based on the second verification result, when the second verification result indicates that the smart contract is a secure contract, the contract hash value of the smart contract is obtained through the deployment interface. Then, based on the obtained contract hash value, the contract bytecode that matches the contract hash value can be found from the cache pool. Further, the computer device can deploy the smart contract to the blockchain network through the deployment interface based on the found contract bytecode. Wherein, if the number of obtained second verification results is multiple, then the second verification result indicating that the smart contract is a secure contract includes: any of the obtained second verification results indicates that the smart contract is a secure contract.
[0076] In one embodiment, after obtaining the second verification result of the smart contract from other nodes, the computer device can return the second verification result to the target device. The target device then controls the computer device through the deployment interface to deploy the smart contract stored in the cache pool on the blockchain network based on the second verification result. In a specific implementation, when the target device determines that the smart contract is a safe contract, it will pre-deploy the smart contract and obtain the contract hash stored in the cache pool, and send the contract hash (contract hash) to the computer device through the deployment interface, so that the computer device can find the corresponding contract bytecode from the cache pool based on the contract hash, and then store the obtained contract original bytecode on the chain.
[0077] Next, combine Figure 3d , the process of deploying a smart contract on the chain is explained. When a computer device deploys the smart contract on the chain, it can perform the following steps.
[0078] ① When deploying a smart contract, the object calls the pre-deployed contract interface in the computer device (i.e. the pre-deployed interface mentioned above) instead of the original deployment interface. After performing a basic format check on the contract, the pre-deployed interface stores the smart contract in the formal verification engine.
[0079] ② The formal verification engine performs security verification on smart contracts based on certain security redline rules.
[0080] ③If the security verification result shows that the smart contract submitted by the object meets the security rules, the smart contract will be sent to the pre-deployed contract broadcast module and broadcast to other consensus nodes. The broadcasted smart contract is also sent to the pre-deployed interface of other consensus nodes, and other consensus nodes will also perform the same security verification process for the smart contract as the above process.
[0081] ④ While broadcasting the smart contract, the computer device will also add the verified smart contract to the verified contract cache pool and store it in the form of [contract hash: contract bytecode]. Among them, the contract cache pool is persistently stored, not just cached in memory.
[0082] ⑤ After completing the storage in the cache pool, wait for the pre-deployment contract broadcast module to receive the return from other consensus nodes. After receiving the return results from enough (2F+1) consensus nodes, the received return results are sent to the object through the pre-deployment interface. Among them, for other consensus nodes, because they receive the broadcast contract for pre-deployment execution, other consensus nodes no longer collect return results from each other, nor broadcast the results. After completing the security verification of the smart contract and placing the verified smart contract into the verified contract cache pool, the result can be returned to the computer device.
[0083] ⑥After receiving the return result of successful pre-deployment, the object will call the deployment result again and pass in the contract hash of the last pre-deployment. At this time, the deployment result will directly obtain the original bytecode of the contract from the verified contract cache pool, and then perform the actual on-chain deployment.
[0084] In one embodiment, the smart contract can be a contract on invoice business in the tax electronic invoice blockchain system, wherein the tax electronic invoice blockchain system is a layered blockchain. The layered blockchain refers to the separation of the consensus network and the witness network. The consensus network mainly performs the core consensus algorithm, and the witness network performs data clearing and synchronization, and completes related specific business based on the SPV node. The blockchain network layered structure of the tax electronic invoice blockchain system can be as follows: Figure 4 As shown. Among them, the business nodes are deployed in the witness network on the public network, while the accounting nodes running the blockchain consensus protocol are deployed in the private consensus network, and the two interact through the routing boundary. Since the consensus network is in a relatively secure private cloud, the mutual access is guaranteed by the consensus mechanism, and there is no need to add additional identity management and network control. However, the business nodes are in the public network and may be accessed by other uncertain network terminals. Therefore, the behavior of business nodes and other possible nodes accessing the consensus network needs to be strictly controlled. Based on this layered architecture, the business logic of the business node, taking the electronic invoice business as an example, can be as follows Figure 5 shown. Figure 5 The network in is a point-to-point network, based on a specific type of network protocol. There is no need for a central node to maintain the network status between network nodes. Instead, each node maintains the node status of the entire network or the connection status of its adjacent nodes through broadcast interaction with adjacent nodes. Figure 5 The business layer shown is in the witness network and will also submit business operation interactions to the consensus layer. The business layer, routing proxy layer, and core consensus layer constitute the entire blockchain business system. Among them, the routing proxy layer plays a role in isolating the business layer and the core consensus network layer. Then, for the smart contract for invoice business in the tax electronic invoice blockchain system, it can also be deployed to the following locations according to the above deployment method: Figure 4 and Figure 5 In the blockchain network system shown in the figure, based on the double-layer chain architecture, a pre-deployment process is added to the core chain protocol, and a formal verification engine for the contract is added to the pre-deployment process to prevent contracts with core risk issues from being put on the chain. This can ensure the verification consistency of relevant smart contracts after being deployed to the tax electronic invoice blockchain system, and further effectively ensure the operation security of relevant smart contracts in the tax electronic invoice blockchain system.
[0085] In an embodiment of the present application, after obtaining a smart contract from a pre-deployment interface, the computer device may first perform a security verification process on the smart contract to obtain a corresponding first verification result. Then, when the first verification result indicates that the smart contract is a secure contract, the computer device may store the smart contract in a cache pool and simultaneously broadcast the smart contract to other consensus nodes for security verification. Furthermore, based on a second verification result obtained after other consensus nodes perform security verification on the smart contract, the computer device may deploy the smart contract in the blockchain network through the deployment interface, thereby enabling the computer device to implement the pre-deployment process through the pre-deployment interface, i.e., the contract code and the basic state of the contract are published, but the contract is unavailable. At this time, the consensus nodes will each perform security checks such as pattern matching and symbolic execution on the pre-published contract through a preset smart contract formal verification engine. After the test passes, the consensus proposer will finally publish the smart contract on the chain and trigger the pre-deployed contract to officially take effect, thereby effectively avoiding security issues caused by directly publishing a smart contract with vulnerabilities on the chain, thereby ensuring the security of the smart contract published on the blockchain network. When computer equipment verifies the security of the smart contract, it mainly uses the formal verification method. The formal method adopted in the embodiment of the present application, by putting the formal verification contract on the chain, enables different consensus nodes to verify the smart contract using the same formal verification contract, thereby ensuring the consistency of the verification of the smart contract.
[0086] Based on the description of the embodiment of the above-mentioned smart contract processing method, the embodiment of the present invention also proposes a smart contract processing device based on a blockchain network, wherein the blockchain network includes at least one consensus node. The smart contract processing device can be a computer program (including program code) running on the above-mentioned computer device, and the computer device is any consensus node in the blockchain network. The smart contract processing device can be used to execute Figure 2 For the smart contract processing method, please refer to Figure 6 The smart contract processing device includes: an acquisition unit 601 and a processing unit 602.
[0087] An acquisition unit 601 is configured to acquire a smart contract to be deployed to a blockchain network from a pre-deployment interface, and acquire a formalized management contract from the blockchain network, and perform a security verification process on the smart contract using the formalized management contract to obtain a first verification result of the smart contract;
[0088] Processing unit 602 is configured to, when the first verification result indicates that the smart contract is a secure contract, store the smart contract in a cache pool, and broadcast the smart contract to other consensus nodes of the blockchain network through the pre-deployment interface for security verification processing;
[0089] The obtaining unit 601 is further configured to obtain a second verification result obtained after the other consensus nodes perform security verification processing on the smart contract;
[0090] The processing unit 602 is further configured to deploy the smart contract stored in the cache pool in the blockchain network through a deployment interface based on the second verification result.
[0091] In one embodiment, the formal management contract is used to specify the verification rules required for security verification processing; the processing unit 602 is specifically used to:
[0092] Obtaining verification rules specified in the formal management contract;
[0093] The verification rule is used to perform security verification processing on the smart contract locally to obtain a first verification result of the smart contract.
[0094] In one embodiment, the processing unit 602 is specifically configured to:
[0095] Performing a formal conversion process on the smart contract locally using a formal compiler, and obtaining a syntax tree corresponding to the smart contract based on a result of the formal conversion process;
[0096] The syntax tree is verified using the verification rules specified in the formal management contract to obtain a first verification result of the smart contract.
[0097] In one embodiment, the verification rules specified in the formal management contract include: pattern verification rules and risk management rules; the processing unit 602 is specifically configured to:
[0098] Using a pattern verification rule in the verification rule specified in the formal management contract, performing pattern matching processing on the syntax tree to obtain a pattern matching result;
[0099] Based on the risk management rules in the verification rules, performing risk analysis processing on the pattern matching results to obtain risk analysis results;
[0100] The risk analysis result is used as the first verification result of the smart contract.
[0101] In one embodiment, the pattern matching result is used to indicate the logic of the syntax tree corresponding to the smart contract; the processing unit 602 is specifically used to:
[0102] Determining a risk score corresponding to the logical situation indicated by the pattern matching result based on the risk management rule in the verification rule, wherein the risk score is a risk analysis result;
[0103] The risk score is negatively correlated with the logic of the syntax tree corresponding to the smart contract; and when the risk score is less than or equal to a preset threshold, the first verification result of the smart contract indicates that the smart contract is a safe contract.
[0104] In one embodiment, the obtaining unit 601 is further configured to obtain a logic problem that causes the smart contract to be a dangerous contract when the first verification result indicates that the smart contract is a dangerous contract;
[0105] The processing unit 602 is further configured to output the logic problem and prohibit deployment of the smart contract on the blockchain network.
[0106] In one embodiment, the smart contract is stored locally in the form of bytecode; the processing unit 602 is specifically configured to:
[0107] Using a formal compiler locally to perform byte conversion on the bytecode of the smart contract to obtain the corresponding intermediate representation;
[0108] A syntax tree is constructed based on the intermediate representation to obtain a syntax tree corresponding to the smart contract.
[0109] In one embodiment, the processing unit 602 is further configured to control the pre-deployment interface to perform format verification on the smart contract;
[0110] The processing unit 602 is further configured to store the smart contract in a formal verification engine after the smart contract passes the format verification process, so as to trigger the formal verification engine to obtain a formal management contract from the blockchain network, and use the formal management contract to perform security verification on the smart contract.
[0111] In one embodiment, the number of the other consensus nodes is at least one, and one consensus node performs security verification on the smart contract to obtain a corresponding second verification result. The processing unit 602 is specifically configured to:
[0112] Determining a number of second verification results obtained from at least one consensus node;
[0113] When the quantity meets the quantity threshold, based on the obtained second verification result, the smart contract stored in the cache pool is deployed in the blockchain network through the deployment interface.
[0114] In one embodiment, the processing unit 602 is specifically configured to:
[0115] Performing a hash operation on the smart contract to obtain a contract hash value of the smart contract;
[0116] The contract bytecode of the smart contract is obtained, and the contract hash value is associated with the contract bytecode and stored in a cache pool.
[0117] In one embodiment, the processing unit 602 is specifically configured to:
[0118] When the second verification result indicates that the smart contract is a safe contract, obtaining the contract hash value of the smart contract through the deployment interface, and based on the contract hash value, searching the cache pool for the contract bytecode that matches the contract hash value;
[0119] Based on the found contract bytecode, the smart contract is deployed to the blockchain network through a deployment interface.
[0120] In one embodiment, the number of obtained second verification results is multiple, and the obtained second verification results indicating that the smart contract is a secure contract includes: any obtained second verification result indicates that the smart contract is a secure contract.
[0121] In an embodiment of the present application, after the acquisition unit 601 obtains the smart contract from the pre-deployment interface, the processing unit 602 may first perform a security verification process on the smart contract to obtain a corresponding first verification result. Then, when the first verification result indicates that the smart contract is a secure contract, the processing unit 602 may store the smart contract in the cache pool and simultaneously broadcast the smart contract to other consensus nodes for security verification. Furthermore, the processing unit 602 may deploy the smart contract in the blockchain network through the deployment interface based on the second verification result obtained after the security verification process on the smart contract by other consensus nodes, thereby realizing the pre-deployment process through the pre-deployment interface, that is, the contract code and the basic state of the contract are published, but the contract is unavailable. At this time, the consensus nodes will each perform security checks such as pattern matching and symbolic execution on the pre-published contract through a preset smart contract formal verification engine. After the test passes, the consensus proposer will finally publish the smart contract on the chain and trigger the pre-deployed contract to officially take effect, thereby effectively avoiding security issues caused by directly publishing a smart contract with vulnerabilities on the chain, thereby ensuring the security of the smart contract published on the blockchain network. When computer equipment verifies the security of the smart contract, it mainly uses the formal verification method. The formal method adopted in the embodiment of the present application, by putting the formal verification contract on the chain, enables different consensus nodes to verify the smart contract using the same formal verification contract, thereby ensuring the consistency of the verification of the smart contract.
[0122] See Figure 7 , is a schematic block diagram of the structure of a computer device provided by an embodiment of the present invention, wherein the computer device is any one of at least one consensus node included in the blockchain network. Figure 7 The computer device in the illustrated embodiment may include: one or more processors 701; one or more input devices 702; one or more output devices 703; and memory 704. The processors 701, input devices 702, output devices 703, and memory 704 are connected via a bus 705. The memory 704 is used to store computer programs, which include program instructions. The processor 701 is used to execute the program instructions stored in the memory 704.
[0123] The memory 704 may include volatile memory, such as random-access memory (RAM); the memory 704 may also include non-volatile memory, such as flash memory, solid-state drive (SSD), etc.; the memory 704 may also include a combination of the above types of memory.
[0124] The processor 701 may be a central processing unit (CPU). The processor 701 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), etc. The PLD may be a field-programmable gate array (FPGA), a generic array logic (GAL), etc. The processor 701 may also be a combination of the above structures.
[0125] In the embodiment of the present invention, the memory 704 is used to store a computer program, and the computer program includes program instructions. The processor 701 is used to execute the program instructions stored in the memory 704 to implement the above-mentioned Figure 2 Steps of the corresponding method.
[0126] In one embodiment, the processor 701 is configured to call the program instructions to execute:
[0127] The blockchain network includes at least one consensus node, and the method is performed by any consensus node, and the method includes:
[0128] Obtaining a smart contract to be deployed to the blockchain network from a pre-deployment interface, and obtaining a formalized management contract from the blockchain network, performing a security verification process on the smart contract using the formalized management contract, and obtaining a first verification result of the smart contract;
[0129] When the first verification result indicates that the smart contract is a secure contract, storing the smart contract in a cache pool, and broadcasting the smart contract to other consensus nodes of the blockchain network through the pre-deployment interface for security verification processing;
[0130] Obtain a second verification result obtained after the other consensus nodes perform security verification processing on the smart contract, and based on the second verification result, deploy the smart contract stored in the cache pool in the blockchain network through the deployment interface.
[0131] In one embodiment, the formal management contract is used to specify verification rules required for security verification processing; the processor 701 is configured to call the program instructions to execute:
[0132] Obtaining verification rules specified in the formal management contract;
[0133] The verification rule is used to perform security verification processing on the smart contract locally to obtain a first verification result of the smart contract.
[0134] In one embodiment, the processor 701 is configured to call the program instructions to execute:
[0135] Performing a formal conversion process on the smart contract locally using a formal compiler, and obtaining a syntax tree corresponding to the smart contract based on a result of the formal conversion process;
[0136] The syntax tree is verified using the verification rules specified in the formal management contract to obtain a first verification result of the smart contract.
[0137] In one embodiment, the verification rules specified in the formal management contract include: pattern verification rules and risk management rules; the processor 701 is configured to call the program instructions to execute:
[0138] Using a pattern verification rule in the verification rule specified in the formal management contract, performing pattern matching processing on the syntax tree to obtain a pattern matching result;
[0139] Based on the risk management rules in the verification rules, performing risk analysis processing on the pattern matching results to obtain risk analysis results;
[0140] The risk analysis result is used as the first verification result of the smart contract.
[0141] In one embodiment, the pattern matching result is used to indicate the logic of the syntax tree corresponding to the smart contract; the processor 701 is configured to call the program instructions to execute:
[0142] Determining a risk score corresponding to the logical situation indicated by the pattern matching result based on the risk management rule in the verification rule, wherein the risk score is a risk analysis result;
[0143] The risk score is negatively correlated with the logic of the syntax tree corresponding to the smart contract; and when the risk score is less than or equal to a preset threshold, the first verification result of the smart contract indicates that the smart contract is a safe contract.
[0144] In one embodiment, the processor 701 is configured to call the program instructions to execute:
[0145] When the first verification result indicates that the smart contract is a dangerous contract, obtaining a logic problem that makes the smart contract a dangerous contract;
[0146] Output the logic problem and prohibit the deployment of the smart contract on the blockchain network.
[0147] In one embodiment, the smart contract is stored locally in the form of bytecode; the processor 701 is configured to call the program instructions to execute:
[0148] Using a formal compiler locally to perform byte conversion on the bytecode of the smart contract to obtain the corresponding intermediate representation;
[0149] A syntax tree is constructed based on the intermediate representation to obtain a syntax tree corresponding to the smart contract.
[0150] In one embodiment, the processor 701 is configured to call the program instructions to execute:
[0151] Controlling the pre-deployment interface to perform format verification on the smart contract;
[0152] After the smart contract passes the format verification process, the smart contract is stored in a formal verification engine to trigger the formal verification engine to obtain a formal management contract from the blockchain network, and use the formal management contract to perform security verification on the smart contract.
[0153] In one embodiment, the number of the other consensus nodes is at least one, and one consensus node performs security verification on the smart contract to obtain a corresponding second verification result; the processor 701 is configured to call the program instructions to execute:
[0154] Determining a number of second verification results obtained from at least one consensus node;
[0155] When the quantity meets the quantity threshold, based on the obtained second verification result, the smart contract stored in the cache pool is deployed in the blockchain network through the deployment interface.
[0156] In one embodiment, the processor 701 is configured to call the program instructions to execute:
[0157] Performing a hash operation on the smart contract to obtain a contract hash value of the smart contract;
[0158] The contract bytecode of the smart contract is obtained, and the contract hash value is associated with the contract bytecode and stored in a cache pool.
[0159] In one embodiment, the processor 701 is configured to call the program instructions to execute:
[0160] When the second verification result indicates that the smart contract is a safe contract, obtaining the contract hash value of the smart contract through the deployment interface, and based on the contract hash value, searching the cache pool for the contract bytecode that matches the contract hash value;
[0161] Based on the found contract bytecode, the smart contract is deployed to the blockchain network through a deployment interface.
[0162] In one embodiment, the number of obtained second verification results is multiple, and the obtained second verification results indicating that the smart contract is a secure contract includes: any obtained second verification result indicates that the smart contract is a secure contract.
[0163] An embodiment of the present invention provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, so that the computer device performs the above-mentioned Figure 2 The computer-readable storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0164] The above disclosure is only a partial embodiment of the present invention, which certainly cannot be used to limit the scope of the rights of the present invention. Ordinary technicians in this field can understand that all or part of the processes of the above embodiments and equivalent changes made in accordance with the claims of the present invention are still within the scope of the invention.
Claims
1. A smart contract processing method based on a blockchain network, characterized in that: The blockchain network includes at least one consensus node, and the method is performed by any consensus node, and the method includes: Obtaining a smart contract to be deployed to the blockchain network from a pre-deployment interface, and obtaining a formalized management contract from the blockchain network, performing a security verification process on the smart contract using the formalized management contract, and obtaining a first verification result of the smart contract; When the first verification result indicates that the smart contract is a secure contract, storing the smart contract in a cache pool, and broadcasting the smart contract to other consensus nodes of the blockchain network through the pre-deployment interface for security verification processing; Obtain a second verification result obtained after the other consensus nodes perform security verification processing on the smart contract, and based on the second verification result, deploy the smart contract stored in the cache pool in the blockchain network through the deployment interface.
2. The method according to claim 1, wherein The formal management contract is used to specify verification rules required for performing security verification processing; the security verification processing of the smart contract using the formal management contract to obtain a first verification result of the smart contract includes: Obtaining verification rules specified in the formal management contract; The verification rule is used to perform security verification processing on the smart contract locally to obtain a first verification result of the smart contract.
3. The method according to claim 2, wherein The security verification process is performed locally on the smart contract using the verification rule to obtain a first verification result of the smart contract, including: Performing a formal conversion process on the smart contract locally using a formal compiler, and obtaining a syntax tree corresponding to the smart contract based on a result of the formal conversion process; The syntax tree is verified using the verification rules specified in the formal management contract to obtain a first verification result of the smart contract.
4. The method according to claim 3, wherein The verification rules specified in the formal management contract include: pattern verification rules and risk management rules; The verifying the syntax tree using the verification rules specified in the formal management contract to obtain a first verification result of the smart contract includes: Using a pattern verification rule in the verification rule specified in the formal management contract, performing pattern matching processing on the syntax tree to obtain a pattern matching result; Based on the risk management rules in the verification rules, performing risk analysis processing on the pattern matching results to obtain risk analysis results; The risk analysis result is used as the first verification result of the smart contract.
5. The method according to claim 4, wherein The pattern matching result is used to indicate the logical situation of the syntax tree corresponding to the smart contract; the risk management rules in the verification rules are used to perform risk analysis on the pattern matching result to obtain a risk analysis result, including: Determining a risk score corresponding to the logical situation indicated by the pattern matching result based on the risk management rule in the verification rule, wherein the risk score is a risk analysis result; The risk score is negatively correlated with the logic of the syntax tree corresponding to the smart contract; and when the risk score is less than or equal to a preset threshold, the first verification result of the smart contract indicates that the smart contract is a safe contract.
6. The method according to claim 5 or 1, wherein: The method further comprises: When the first verification result indicates that the smart contract is a dangerous contract, obtaining a logic problem that makes the smart contract a dangerous contract; Output the logic problem and prohibit the deployment of the smart contract on the blockchain network.
7. The method according to claim 3, wherein The smart contract is stored locally in the form of bytecode; the formal compiler is used locally to perform form conversion processing on the smart contract, and a syntax tree corresponding to the smart contract is obtained based on the result of the form conversion processing, including: Using a formal compiler locally to perform byte conversion on the bytecode of the smart contract to obtain the corresponding intermediate representation; A syntax tree is constructed based on the intermediate representation to obtain a syntax tree corresponding to the smart contract.
8. The method according to claim 1, wherein The method further comprises: Controlling the pre-deployment interface to perform format verification on the smart contract; After the smart contract passes the format verification process, the smart contract is stored in a formal verification engine to trigger the formal verification engine to obtain a formal management contract from the blockchain network, and use the formal management contract to perform security verification on the smart contract.
9. The method according to claim 1, wherein The number of the other consensus nodes is at least one, and each consensus node performs security verification on the smart contract to obtain a corresponding second verification result; The deploying the smart contract stored in the cache pool on the blockchain network through a deployment interface based on the second verification result includes: Determining a number of second verification results obtained from at least one consensus node; When the quantity meets the quantity threshold, based on the obtained second verification result, the smart contract stored in the cache pool is deployed in the blockchain network through the deployment interface.
10. The method according to claim 1, wherein Storing the smart contract in a cache pool includes: Performing a hash operation on the smart contract to obtain a contract hash value of the smart contract; The contract bytecode of the smart contract is obtained, and the contract hash value is associated with the contract bytecode and stored in a cache pool.
11. The method according to claim 1, wherein The deploying the smart contract stored in the cache pool on the blockchain network through a deployment interface based on the second verification result includes: When the second verification result indicates that the smart contract is a safe contract, obtaining the contract hash value of the smart contract through the deployment interface, and based on the contract hash value, searching the cache pool for the contract bytecode that matches the contract hash value; Based on the found contract bytecode, the smart contract is deployed to the blockchain network through a deployment interface.
12. The method according to claim 11, wherein There are multiple second verification results obtained, and the second verification results obtained indicate that the smart contract is a secure contract, including: any second verification result obtained indicates that the smart contract is a secure contract.
13. A smart contract processing device based on a blockchain network, characterized in that: The blockchain network includes at least one consensus node, the device is any consensus node, and the device includes: an acquiring unit, configured to acquire a smart contract to be deployed to the blockchain network from a pre-deployment interface, and acquire a formalized management contract from the blockchain network, and perform a security verification process on the smart contract using the formalized management contract to obtain a first verification result of the smart contract; a processing unit, configured to, when the first verification result indicates that the smart contract is a secure contract, store the smart contract in a cache pool, and broadcast the smart contract to other consensus nodes of the blockchain network through the pre-deployment interface for security verification processing; The acquisition unit is further configured to obtain a second verification result obtained after the other consensus nodes perform security verification processing on the smart contract; The processing unit is further configured to deploy the smart contract stored in the cache pool in the blockchain network through a deployment interface based on the second verification result.
14. A computer device, characterized in that: The method comprises a processor, an input device, an output device and a memory, wherein the processor, the input device, the output device and the memory are connected to each other, wherein the memory is used to store a computer program, the computer program includes program instructions, and the processor is configured to call the program instructions to execute the method according to any one of claims 1 to 12.
15. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions. When the program instructions are executed by a processor, the processor is caused to perform the method according to any one of claims 1 to 12.
16. A computer program product, characterized in that The computer program product comprises a computer program or computer instructions, and the computer program or the computer instructions are executed by a processor to perform the method according to any one of claims 1 to 12.