Blockchain system, smart contract synchronization method, computer device and storage medium

By segmenting smart contracts and generating verification information, the problems of resource waste and security during smart contract download are solved, achieving efficient contract synchronization and business security.

CN117333175BActive Publication Date: 2026-08-25TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210714143.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-22
Publication Date
2026-08-25
Estimated Expiration
2042-06-22

AI Technical Summary

Technical Problem

The existing smart contract download process in the blockchain's Layer 2 network wastes transmission and storage resources, and also affects business security.

Method used

The smart contract is divided into multiple contract blocks, and verification information is generated. The first network node sends the matching contract block and verification information to the second network node, and the second network node verifies the legality and integrity of the contract block based on the verification information.

Benefits of technology

It effectively saves transmission and storage resources, enhances business security and privacy, and ensures the accuracy and trustworthiness of contract blocks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117333175B_ABST
    Figure CN117333175B_ABST
Patent Text Reader

Abstract

The application discloses a kind of blockchain system, smart contract synchronization method, computer equipment and storage medium, belong to blockchain technical field.The application is based on the first network node in blockchain system and is divided into multiple contract blocks based on the smart contract of block;Based on multiple contract blocks, the verification information of the smart contract is generated, and it is sent to the second network node;By the first network node, in response to the contract synchronization request of the second network node, the target contract block matched with its branch service is sent, so that the second network node stores the target contract block based on the verification information.The technical scheme in the above, by dividing into multiple contract blocks and issuing smart contract, greatly save the transmission resources and storage resources consumed by contract synchronization, and by providing trusted verification information, each node can verify the contract block received based on verification information, thereby effectively guaranteeing the privacy and security of service.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of blockchain technology, and in particular to a blockchain system, a smart contract synchronization method, a computer device, and a storage medium. Background Technology

[0002] Layer 2 blockchain networks are a solution to the performance bottleneck of blockchain computing. By dividing the blockchain system into a first-layer network and a second-layer network, transactions are processed in the second-layer network nodes, while consensus is reached on the transaction results returned by the second-layer network nodes in the first-layer network nodes (i.e., the blockchain main chain), thus reducing the computational burden on the blockchain. Transactions occurring in this blockchain system can be implemented through smart contracts.

[0003] Currently, when smart contracts run on a Layer 2 blockchain network, Layer 2 network nodes typically retrieve the smart contract from Layer 1 network nodes to obtain the logic for processing transactions. However, the current technical solution of downloading the complete smart contract not only wastes significant transmission and storage resources but also greatly impacts business security. Therefore, there is an urgent need for a smart contract synchronization method that can effectively save transmission and storage resources and improve business security. Summary of the Invention

[0004] This application provides a blockchain system, a smart contract synchronization method, a computer device, and a storage medium, which can effectively save transmission and storage resources and improve business security. The technical solution is as follows:

[0005] On the one hand, a blockchain system is provided, which includes a first-layer network and a second-layer network, wherein the first-layer network includes multiple first-layer network nodes and the second-layer network includes multiple second-layer network nodes;

[0006] The first network node is used to divide the smart contract into blocks to obtain multiple contract blocks, generate verification information for the smart contract based on the multiple contract blocks, and send the verification information to the multiple second network nodes. The contract block is used to implement at least one branch of the business corresponding to the smart contract.

[0007] The first network node is also configured to send a target contract block to the second network node in response to any contract synchronization request from the second network node for the smart contract. The target contract block is the contract block among the plurality of contract blocks that matches the branch business of the second network node.

[0008] The second network node is used to store the target contract block based on the verification information of the target contract block and the smart contract, if it is determined that the target contract block is a contract block of the smart contract.

[0009] On the one hand, a smart contract synchronization method is provided, executed by a first network node in a blockchain system. This blockchain system includes a first-layer network and a second-layer network. The first-layer network includes multiple first network nodes, and the second-layer network includes multiple second network nodes. The method includes:

[0010] The smart contract is divided into blocks to obtain multiple contract blocks. Based on these multiple contract blocks, the verification information of the smart contract is generated and sent to the multiple second network nodes. The contract block is used to implement at least one branch of the business corresponding to the smart contract.

[0011] In response to any contract synchronization request from the second network node for the smart contract, a target contract block is sent to the second network node. The target contract block is the contract block among the plurality of contract blocks that matches the branch business of the second network node.

[0012] On the one hand, a smart contract synchronization method is provided, executed by a second network node in a blockchain system. This blockchain system includes a first-layer network and a second-layer network. The first-layer network includes multiple first network nodes, and the second-layer network includes multiple second network nodes. The method includes:

[0013] Send a contract synchronization request for the smart contract to any of the first network nodes. The contract synchronization request is used to obtain the target contract block. The target contract block is the contract block that matches the branch business of the second network node among the multiple contract blocks of the smart contract. The contract block of the smart contract is used to implement at least one branch business in the corresponding business of the smart contract.

[0014] Based on the verification information of the smart contract and the target contract block, if it is determined that the target contract block is a contract block of the smart contract, the target contract block is stored.

[0015] On the one hand, a smart contract synchronization method is provided, which includes:

[0016] The smart contract is divided into blocks to obtain multiple contract blocks. Based on these multiple contract blocks, the verification information of the smart contract is generated and sent. The contract block is used to implement at least one branch of the business corresponding to the smart contract.

[0017] In response to a contract synchronization request for the smart contract, a target contract block is sent, which is the contract block among the plurality of contract blocks that matches the branch business corresponding to the contract synchronization request.

[0018] In one possible implementation, the smart contract is divided into blocks to obtain multiple contract blocks, including:

[0019] The smart contract is compiled to determine its syntax information, which indicates the start and end range of the code in the smart contract used to implement the at least one branch of the business;

[0020] Based on this syntax information, the smart contract is divided into blocks, resulting in multiple contract blocks.

[0021] In one possible implementation, the generation of smart contract verification information based on the multiple contract blocks includes:

[0022] Based on the multiple contract blocks and their block order within the smart contract, a Merkle tree for the smart contract is generated.

[0023] Based on the Merkle root of the Merkle tree and the contract identifier of the smart contract, the verification information of the smart contract is generated.

[0024] In one possible implementation, the verification information for the smart contract is generated based on the Merkle root of the Merkle tree and the contract identifier of the smart contract, including:

[0025] The verification information is generated based on the verification key, the Merkle root, and the contract identifier of the smart contract.

[0026] In one possible implementation, the method further includes:

[0027] Send the verification information, and the verification key used to generate the verification information, which is used to generate the verification information corresponding to the contract block.

[0028] In one possible implementation, the response to a contract synchronization request for the smart contract, sending a target contract block, includes:

[0029] Based on the node identifier carried in the contract synchronization request, determine the target contract block that matches the branch business of the node that sent the contract synchronization request;

[0030] Based on the target contract block, obtain the proof information corresponding to the target contract block. The proof information includes the Merkle path of the target contract block in the Merkle tree of the smart contract. The Merkle path is used to verify the block order of the target contract block in the smart contract.

[0031] The method also includes:

[0032] Send the target contract block and the proof information.

[0033] In one possible implementation, the method further includes:

[0034] Based on the node identifier carried in the contract synchronization request, the permission information of the node that sent the contract synchronization request for the smart contract is determined, and the permission information indicates that the node can obtain the code scope of the smart contract.

[0035] If the target contract block is outside the scope of this code, return the corresponding call interface in the smart contract to this node.

[0036] On the one hand, a smart contract synchronization method is provided, which includes:

[0037] Send a contract synchronization request for the smart contract. The contract synchronization request is used to obtain the target contract block. The target contract block is the contract block that matches the branch business corresponding to the contract synchronization request among the multiple contract blocks of the smart contract. The contract block of the smart contract is used to implement at least one branch business in the corresponding business of the smart contract.

[0038] Based on the verification information of the smart contract and the target contract block, if it is determined that the target contract block is a contract block of the smart contract, the target contract block is stored.

[0039] In one possible implementation, based on the verification information of the smart contract and the target contract block, if it is determined that the target contract block is a contract block of the smart contract, storing the target contract block includes:

[0040] Based on the Merkel path of the target contract block and the target contract block itself, determine the information to be verified for the target contract block;

[0041] If the verification information of the target contract block matches the verification information of the smart contract, the target contract block is determined to be a contract block of the smart contract, and the target contract block is stored.

[0042] On one hand, a computer device is provided, which includes one or more processors and one or more memories, wherein at least one computer program is stored in the one or more memories, and the computer program is loaded and executed by the one or more processors to implement the above-described smart contract synchronization method.

[0043] On the one hand, a computer-readable storage medium is provided, which stores at least one computer program that is loaded and executed by a processor to implement the above-described smart contract synchronization method.

[0044] On one hand, a computer program product or computer program is provided, which includes program code stored in a computer-readable storage medium. The processor of a computer device reads the program code from the computer-readable storage medium and executes the program code, causing the computer device to execute the aforementioned smart contract synchronization method.

[0045] By using the above technical solution, smart contracts are divided into multiple contract blocks and distributed, which greatly saves the transmission and storage resources consumed by contract synchronization. By providing trusted verification information, each node can verify the received contract blocks based on the verification information, thereby effectively ensuring the privacy and security of the business. Attached Figure Description

[0046] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0047] Figure 1 This is a schematic diagram of the structure of a blockchain system provided in an embodiment of this application;

[0048] Figure 2 This is a schematic diagram of a block structure provided in an embodiment of this application;

[0049] Figure 3 This is a schematic diagram of another blockchain system provided in an embodiment of this application;

[0050] Figure 4 This is a flowchart of a smart contract synchronization method provided in an embodiment of this application;

[0051] Figure 5 This is a flowchart of a smart contract synchronization method provided in an embodiment of this application;

[0052] Figure 6 This is a schematic diagram of a Merkle tree provided in an embodiment of this application;

[0053] Figure 7 This is a flowchart of a smart contract synchronization method provided in an embodiment of this application;

[0054] Figure 8 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation

[0055] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0056] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0057] In this application, the terms "first," "second," etc., are used to distinguish identical or similar items that have essentially the same function. It should be understood that there is no logical or temporal dependency between "first," "second," and "nth," nor does it limit the quantity or execution order. It should also be understood that although the following description uses the terms "first," "second," etc., to describe various elements, these elements should not be limited by the terms.

[0058] These terms are simply used to distinguish one element from another. For example, without departing from the various examples, a first node can be called a second node, and similarly, a second node can be called a first node. Both first and second nodes can be nodes, and in some cases, they can be separate and distinct nodes.

[0059] "At least one" refers to one or more nodes. For example, at least one node can be one node, two nodes, three nodes, or any integer number of nodes greater than or equal to one. "Multiple" refers to two or more nodes. For example, multiple nodes can be two nodes, three nodes, or any integer number of nodes greater than or equal to two.

[0060] It should be noted that all information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.), and signals involved in this application have been authorized by the user or fully authorized by all parties, and the collection, use, and processing of related data must comply with the relevant laws, regulations, and standards of the relevant countries and regions. For example, the smart contracts involved in this application were all obtained under full authorization.

[0061] To facilitate understanding of the technical processes in the embodiments of this application, some terms involved in the embodiments of this application are explained below:

[0062] Blockchain is a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and cryptographic algorithms. Essentially, a blockchain is a decentralized database, a chain of data blocks linked together using cryptographic methods. Each data block contains information about a batch of network transactions, used to verify the validity of the information (anti-counterfeiting) and generate the next block. A blockchain can include an underlying platform, a platform product service layer, and an application service layer.

[0063] The underlying blockchain platform can include basic services and processing modules such as smart contracts. The basic service module is deployed on all blockchain node devices to verify the validity of business requests. After reaching a consensus on valid requests, it records them in storage. For a new business request, the basic service first performs interface adaptation parsing and authentication (interface adaptation), then encrypts the business information using a consensus algorithm (consensus management), and transmits it completely and consistently to the shared ledger (network communication) for recording and storage. The smart contract module is responsible for contract registration, issuance, triggering, and execution. Developers can define contract logic using a programming language and publish it to the blockchain (contract registration). According to the contract terms, execution is triggered by calling keys or other events to complete the contract logic. It also provides functions for contract upgrades and cancellations.

[0064] The platform's product service layer provides the basic capabilities and implementation frameworks for typical applications. Developers can leverage these basic capabilities, along with the specific characteristics of their business needs, to implement blockchain-based business logic. The application service layer provides blockchain-based application services to business stakeholders.

[0065] A consortium blockchain is a blockchain whose consensus process is controlled by pre-selected blockchain nodes. The blockchain ledger can restrict read access only to consortium members or provide read capabilities to external users. In a consortium blockchain, all or some functions are only open to the blockchain node members within the chain, and each blockchain node in the consortium blockchain can customize read / write permissions, query permissions, etc., as needed.

[0066] Consensus mechanism: A mathematical algorithm used in blockchain systems to establish trust and assign rights among different nodes. In a blockchain system, transactions can be verified and confirmed in a very short time through voting by specific nodes or all nodes. Specifically, if multiple nodes with unrelated interests can reach a consensus on a transaction, it can be assumed that all nodes in the system can also reach a consensus on it.

[0067] The blockchain system involved in this application embodiment can be a distributed system formed by connecting clients and multiple nodes (any form of computing device accessing the network, such as servers and user terminals) through network communication. See [link to relevant documentation]. Figure 1 , Figure 1 This is a schematic diagram of the structure of a blockchain system provided in an embodiment of this application. The blockchain system 100 consists of multiple nodes 101 (any form of computing device in the network, such as servers or user terminals) and clients 102. The nodes form a peer-to-peer (P2P) network. The P2P protocol is an application layer protocol running on top of the Transmission Control Protocol (TCP). In the blockchain system 100, any machine, such as a server or terminal, can join and become a node. A node includes a hardware layer, a middleware layer, an operating system layer, and an application layer.

[0068] See Figure 1 The functions of each node in the blockchain system shown include:

[0069] 1) Routing: A basic function of nodes used to support communication between nodes.

[0070] 2) Applications are deployed in the blockchain to implement specific business needs. They record data related to the implementation of functions to form record data, carry digital signatures in the record data to indicate the source of the task data, and send the record data to other nodes in the blockchain system. When other nodes successfully verify the source and integrity of the record data, they add the record data to a temporary block.

[0071] For example, the business logic implemented by the application includes:

[0072] 2.1) Smart contracts are computerized protocols that can execute the terms of a contract. They are implemented through code deployed on a shared ledger that executes when certain conditions are met. Based on actual business needs, the code is used to complete automated transactions, such as querying the logistics status of goods purchased by a buyer and transferring the buyer's transaction 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; they can also execute contracts for processing received information.

[0073] 2.2) Shared ledger, used to provide functions such as storage, query and modification of ledger data. It sends the record data of the operation on the ledger data to other nodes in the blockchain system. After the other nodes verify the validity, as a response to acknowledge the validity of the ledger data, they store the record data in a temporary block. They can also send confirmation to the node that initiated the operation.

[0074] 3) A blockchain consists of a series of blocks linked together in chronological order of their creation. Once a new block is added to the blockchain, it cannot be removed. Each block records the data submitted by nodes within the blockchain system. See also... Figure 2 , Figure 2 This is a schematic diagram of a block structure provided in an embodiment of this application. Each block includes the hash value of the transaction records stored in this block (the hash value of this block) and the hash value of the previous block. The blocks are connected through their hash values ​​to form a blockchain. Additionally, each block may include information such as a timestamp when it was generated. A blockchain is essentially a decentralized database, a chain of data blocks linked together using cryptographic methods. Each data block contains relevant information used to verify the validity of the information (anti-counterfeiting) and to generate the next block.

[0075] Based on the above description of blockchain system 100, this application embodiment provides another blockchain system, see [link to relevant documentation]. Figure 3 , Figure 3 This is a schematic diagram of another blockchain system provided in the embodiments of this application. The blockchain system 300 includes a layer 1 network and a layer 2 network.

[0076] This first-layer network includes multiple first-network nodes 301. These first-network nodes 301 participate in the blockchain consensus process, sending transaction data returned by second-network nodes 302 to other first-network nodes in the blockchain system for consensus. This allows other first-network nodes to verify the source and integrity of the transaction data, thereby recording the successfully verified transaction data in a block and constructing the blockchain. See the diagram for the blockchain consisting of blocks 1 to n, where n is a positive integer. This first-network node is used to maintain the consensus mechanism within the blockchain system, ensuring the decentralization and security of the blockchain system 300.

[0077] The second-layer network includes multiple second network nodes 302. These second network nodes 302 do not participate in the blockchain consensus process but are used to process transactions to achieve specified business operations. Optionally, these second network nodes can also provide transaction data query services. In essence, this second-layer network is equivalent to off-chain scaling on the first-layer network of the blockchain system (i.e., the main blockchain). By constructing the blockchain and achieving node consensus based on transaction data in the first network nodes, and processing business-related transactions in the second network nodes, the speed and efficiency of the blockchain system in processing transactions can be effectively improved while ensuring decentralization and security.

[0078] In this embodiment of the application, the business operations in the blockchain system can be implemented based on smart contracts. In some embodiments, the plurality of first network nodes reach consensus based on a complete smart contract, and then any one of the first network nodes synchronizes the smart contract with a second network node, enabling the second network node to implement the business it supports based on the smart contract. It can be understood that the smart contract synchronization process is also the process of the first network node issuing the smart contract to the second network node.

[0079] In some embodiments, the blockchain in the blockchain system 300 is a consortium blockchain, and the consensus process of the blockchain is controlled by the pre-selected plurality of first network nodes. Optionally, the first network nodes are determined based on the business corresponding to the smart contract running in the blockchain system. For example, the smart contract is used to implement electronic invoice business, and the first-layer network of the blockchain is a consensus network maintained by the tax department responsible for electronic invoice declaration business. The plurality of first network nodes in the first-layer network are multiple computer devices such as servers or terminals operated by the tax department. Correspondingly, the plurality of second network nodes are used to implement multiple branch businesses included in the business corresponding to the smart contract. For example, the blockchain system is applied to electronic invoice business, which includes multiple branch businesses such as invoicing and reimbursement. The second-layer network consists of multiple downstream service provider nodes or enterprise nodes that provide invoicing or reimbursement services to users. The second network nodes include computer devices such as servers or terminals used by the downstream service providers to process their branch businesses. Since the business corresponding to a smart contract usually includes multiple branches, and the second network node in the blockchain system usually only provides some of the branches, the sending of the complete smart contract from the first network node to the second network node, and the downloading of the complete smart contract by the second network node, both result in a huge waste of transmission and storage resources.

[0080] In view of this, this application provides a smart contract synchronization method that can be applied to the blockchain system 300 described above, so as to effectively save transmission and storage resources. Figure 4 This is a flowchart of a smart contract synchronization method provided in an embodiment of this application. See also... Figure 4 The method includes the following steps 401 to 403.

[0081] 401. The first network node divides the smart contract into blocks to obtain multiple contract blocks. Based on the multiple contract blocks, it generates verification information for the smart contract and sends the verification information to the multiple second network nodes. The contract block is used to implement at least one branch of the business corresponding to the smart contract.

[0082] The smart contract is code deployed on the first network node of the blockchain system, used to provide the transaction processing logic for implementing the corresponding business. For a description of the smart contract's corresponding business and branch businesses, please refer to the above explanation. Figure 3 The corresponding blockchain system will not be described in detail here.

[0083] In this embodiment of the application, the smart contract is stored in the first network node after consensus among multiple first network nodes in the first layer network of the blockchain system. Therefore, the smart contract has trustworthy characteristics such as immutability and decentralization in the blockchain system.

[0084] In this embodiment of the application, the contract block is used to provide transaction processing logic corresponding to the branch business, and the transaction processing logic is recorded in the form of code.

[0085] In some embodiments, the first network node divides the smart contract into blocks with the code snippets corresponding to the branch business as the smallest granularity, to obtain the multiple contract blocks. For example, the smart contract includes multiple code modules, which are used to implement multiple branch businesses such as invoicing and reimbursement. Contract block 1 includes code snippets for implementing the invoicing business, and contract block 2 includes code snippets for implementing the reimbursement business.

[0086] In other embodiments, the first network node divides the smart contract into blocks with a global function as the smallest granularity to obtain the multiple contract blocks. In this example, the contract block is a code segment in the smart contract that can be executed as a unit; for example, the contract block is the code segment corresponding to the tax rate calculation function. Optionally, a branch business can be implemented based on multiple contract blocks, and a contract block can be used to implement multiple different branch businesses. The embodiments of this application do not limit the way contract blocks are combined.

[0087] In this embodiment, the verification information is used to verify whether any code block to be verified is a contract block of the smart contract. In some embodiments, the verification information is generated based on immutable information such as the division and block order of the multiple contract blocks, and can achieve accurate verification of code integrity and source consistency by verifying whether any code block is the same as any of the contract blocks and whether it conforms to the block order of any of the contract blocks in the smart contract.

[0088] 402. In response to any contract synchronization request from the second network node for the smart contract, the first network node sends a target contract block to the second network node, wherein the target contract block is the contract block among the plurality of contract blocks that matches the branch business of the second network node.

[0089] In some embodiments, the contract synchronization request instructs the smart contract and the branch service of the second network node to instruct the first network node to determine the target contract block in the smart contract that matches the branch service, and then send the target contract block to the second network node.

[0090] 403. Based on the verification information of the target contract block and the smart contract, the second network node stores the target contract block if it determines that the target contract block is a contract block of the smart contract.

[0091] The second network node verifies the received target contract block based on the smart contract's verification information to determine whether the received code fragment is a block of the smart contract. Thus, while ensuring code integrity and consistency between the code source and the verification information, the target contract block is stored to complete the smart contract synchronization process.

[0092] Through the above technical solution, in the first layer of the blockchain network, the smart contract is divided into multiple contract blocks and distributed by the first network node used for blockchain consensus. This greatly saves the transmission and storage resources consumed by contract synchronization. By providing trustworthy verification information, each node can verify the received contract blocks based on the verification information, thereby effectively ensuring the privacy and security of the business.

[0093] Next, the technical solutions of the embodiments of this application will be described in detail through some examples. In the smart contract synchronization method provided in the embodiments of this application, the first network node is used to execute the deployment process of the smart contract, so that after the smart contract is deployed, the contract block of the smart contract is issued to the second network node according to the branch business, that is, the smart contract is synchronized with the second network node. Figure 5 This is a flowchart of a smart contract synchronization method provided in an embodiment of this application. See also... Figure 5 The method is executed by any first network node in the aforementioned blockchain system, and includes the following steps 501 to 506.

[0094] 501. The first network node initiates consensus with the first layer of the blockchain system based on the smart contract in order to store the smart contract in the blockchain.

[0095] For a description of the smart contract, the blockchain system, and the layer network, please refer to the above. Figure 3 and Figure 4 The corresponding content will not be elaborated here.

[0096] In some embodiments, the first network node sends a smart contract to multiple other first network nodes to initiate a consensus process for the smart contract. If the other first network nodes verify the legitimacy of the smart contract's origin, the smart contract is stored as a block in the blockchain system to complete the storage process of the smart contract on the blockchain, thereby ensuring the trustworthy characteristics of the smart contract, such as immutability and decentralization, in the blockchain system.

[0097] 502. The first network node compiles the smart contract and determines the syntax information of the smart contract, which indicates the start and end range of the code in the smart contract used to implement the at least one branch of the business.

[0098] In some embodiments, the syntactic information is determined based on the Abstract Syntax Tree (AST) obtained by compiling the smart contract. The AST is a tree-like representation of the source code's syntactic structure, essentially representing the understanding of the source code starting from its syntactic structure. Compiling the smart contract to obtain the AST is equivalent to translating the program code, consisting of strings, into multiple nested syntactic units. Each syntactic unit points to the syntactic structure and statements involved in implementing a specific operation. Based on this, the compiled AST of the smart contract is equivalent to understanding the smart contract's transaction processing logic at the statement level, thereby enabling the smart contract to be divided into multiple code fragments, or multiple syntactic units, for implementing different operations. For example, the multiple syntactic units indicated by the smart contract's AST correspond to multiple global functions in the smart contract, each global function performing a different operation, such as retrieving an invoice number, calculating a tax rate, or calculating an amount.

[0099] In some embodiments, the AST is used to record the start and end ranges of each syntactic unit in the source code, for example, to identify the start and end line numbers of the syntactic unit in the source code. In this example, the AST of the smart contract can record the start and end ranges of the code corresponding to each global function after compilation. Based on the start and end ranges of the code recorded in the AST, the syntax information of the smart contract can be determined. For example, the syntax information of the smart contract code is represented as: "code={f1[1,10],f2[11,20],f3[21,80],f4[81,100]}".

[0100] The above technical solution, based on the syntax structure of smart contracts, allows for the understanding of source code at the statement level, thereby enabling fine-grained code segmentation for different business branches, improving the accuracy and reliability of the segmentation.

[0101] 503. Based on the syntax information, the first network node divides the smart contract into blocks to obtain multiple contract blocks. Each contract block is used to implement at least one branch of the business corresponding to the smart contract.

[0102] In this embodiment of the application, the first network node can divide the smart contract into blocks according to the operations involved in each branch business in the corresponding business of the smart contract, combined with the start and end range of the code indicated by the syntax information, to obtain multiple code fragments for implementing the branch business, that is, the multiple contract blocks.

[0103] In some embodiments, a contract block includes a code fragment corresponding to at least one global function. In this example, the first network node divides the smart contract into multiple code fragments based on the start and end ranges of the code for each global function indicated in the syntax information, with each code fragment corresponding to a global function. For example, the multiple code fragments obtained can be represented as: [TxA = code[1, 10], TxB = code[11, 20], TxB = code[21, 80], TxD = code[81, 100]]; where TxA is the code fragment corresponding to function f1, TxB is the code fragment corresponding to function f2, TxC is the code fragment corresponding to function f3, and TxD is the code fragment corresponding to function f4; correspondingly, contract block 1 can be TxA, contract block 2 is TxB, contract block 3 is TxC, and contract block 4 can be TxD.

[0104] In some embodiments, the first network node adds business identifiers to multiple contract blocks of the smart contract. These business identifiers indicate the branch business that the contract block can be used to implement. Taking a contract block corresponding to a global function as an example, the first network node adds business identifiers to the global function based on the call statements to the global function in the AST included in the syntax information. For example, for function 1 used to obtain an invoice number, based on the branch business "invoicing" pointed to by statement 1 calling function 1, and the branch business "reimbursement" pointed to by statement 2 calling function 1, an identifier "K" indicating the "invoicing" business and an identifier "B" indicating the "reimbursement" business are added to the business identifier of function 1.

[0105] In some embodiments, the first network node can combine multiple contract blocks according to the business identifiers of each contract block to obtain a contract block with larger granularity. For example, based on the business identifiers "K" and "B" of function f1 and the business identifier "K" of function f2, the code segment TxA corresponding to function f1 and the code segment TxB corresponding to function f2 are combined to obtain contract block A.

[0106] Through the above technical solution, smart contracts can be divided into contract blocks at multiple granularities based on the operations involved in implementing branch business. While ensuring the accuracy of smart contract block division, the flexibility of block division is effectively improved, enabling the smart contract synchronization method provided in this application embodiment to be applied to different business scenarios. Furthermore, by obtaining multiple contract blocks through the above technical solution, multiple clear, unified, and easily scheduled smart contract business interfaces are provided to the front-end and back-end, thereby effectively improving the efficiency of deploying branch business based on multiple contract blocks of smart contracts.

[0107] 504. The first network node generates the Merkle tree of the smart contract based on the multiple contract blocks and the block order of the multiple contract blocks in the smart contract.

[0108] In this embodiment of the application, the first network node uses the multiple contract blocks (i.e., code fragments of the smart contract) as basic data and constructs the Merkle Tree of the smart contract based on the block order of the multiple contract blocks in the smart contract.

[0109] In some embodiments, the block order of the multiple contract blocks is determined based on the order of the start and end ranges of the code of the multiple contract blocks in the smart contract. For example, based on the start and end ranges of the code of four contract blocks TxA, TxB, TxC and TxD: [TxA = code[1, 10], TxB = code[11, 20], TxB = code[21, 80], TxD = code[81, 100]], the block order of the four contract blocks can be determined as TxA—TxB—TxC—TxD. In other embodiments, based on the business flow rules of the smart contract, the block order of the multiple contract blocks is determined according to the execution stage of the branch business corresponding to the contract block in the corresponding business of the smart contract. For example, if the four contract blocks TxA, TxB, TxC and TxD correspond to the four sequential execution stages of invoicing, approval, acceptance and accounting, then according to the flow rules of electronic invoice business (applicant invoicing - tax authority approval - reimbursement company acceptance - accounting), the block order of the four contract blocks can be determined as TxA-TxB-TxC-TxD.

[0110] In some embodiments, the first network node determines multiple leaf nodes of the Merkle tree based on the hash values ​​of the multiple contract blocks, performs pairwise hash operations on each leaf node to obtain the intermediate nodes of the penultimate level, and so on, until the root node value of the Merkle tree is determined, that is, the root of the Merkle tree. In some embodiments, the first network node constructs the tree by first determining the left subtree and then the right subtree, and determines the values ​​of the leaf nodes of the Merkle tree by sequentially determining the hash values ​​of the contract blocks based on the block division order of the multiple contract blocks. For example, Figure 6This is a schematic diagram of a Merkle tree provided in an embodiment of this application. See also... Figure 6 The block division yielded four contract blocks of the smart contract: TxA, TxB, TxC, and TxD, with the block division order being: TxA—TxB—TxC—TxD; the four leaf nodes H of this Merkle tree... A H B H C and H D The values ​​are the hash values ​​of the four contract blocks: Hash(TxA), Hash(TxB), Hash(TxC), and Hash(TxD); the intermediate node H AB The value is the hash value Hash(H) obtained by performing a hash operation on Hash(TxA) and Hash(TxB). A +H B ), the intermediate node H CD The value is the hash value Hash(H) obtained by performing a hash operation on Hash(TxC) and Hash(TxD). C +H D ); The Merkel root H of the Merkel tree ABCD To this intermediate node H AB and H CD The hash value (Hash(H)) is obtained by performing a hash operation on the value. AB +H CD ).

[0111] It should be noted that in the above example, the Merkle tree is described as a binary tree. In other embodiments, the Merkle tree can be a multi-branch tree. That is, the intermediate nodes of the Merkle tree can be determined based on the hash values ​​of two or more contract blocks. This application embodiment does not limit this.

[0112] In some embodiments, the first network node stores the Merkle tree of the smart contract in the blockchain system to make the block division process of the smart contract transparent, immutable and traceable, thereby improving the trustworthiness of the contract blocks of the smart contract.

[0113] 505. The first network node generates the verification information of the smart contract based on the Merkle root of the Merkle tree and the contract identifier of the smart contract.

[0114] In some embodiments, the first network node can generate unique verification information that indicates the smart contract based on the Merkle root and the contract identifier of the smart contract.

[0115] In some embodiments, the first network node can encrypt the Merkle root and the contract identifier of the smart contract based on the verification key, thereby generating verification information that provides higher security and privacy. For example, the verification information of the smart contract can be obtained using the following formula (1).

[0116] ID = F(name, root) (1)

[0117] In formula (1), the verification information ID of the smart contract is obtained by encrypting the contract identifier name and the Merkle root of the smart contract using the verification key F.

[0118] In other embodiments, the first network node can map the verification information of the smart contract based on the Merkle root and the contract identifier of the smart contract using any mapping algorithm that reaches consensus with the second network node. This reduces the data processing difficulty for the second network node to perform verification based on the verification information, thereby saving computing resources. The embodiments of this application do not limit the method of generating the verification information.

[0119] 506. The first network node sends the verification information to multiple second network nodes.

[0120] In this embodiment of the application, the first network node sends the verification information to the plurality of second network nodes, enabling the plurality of second network nodes to synchronize the smart contract based on the verification information.

[0121] In some embodiments, the first network node also sends a verification key to the plurality of second network nodes for generating the verification information, so that the plurality of second network nodes can verify any received contract block based on the verification key, which is used to generate the verification information corresponding to the contract block.

[0122] In some embodiments, the first network node sends the contract identifier of the smart contract to the plurality of second network nodes. Optionally, the first network node sends the contract identifier of the smart contract to the plurality of second network nodes when the smart contract is based on consensus among the plurality of first network nodes and stored in the first network node (i.e., after executing step 501). Optionally, the first network node sends the contract identifier of the smart contract to the plurality of second network nodes when sending the verification information of the smart contract to the plurality of second network nodes (i.e., when executing this step 506), and this embodiment of the application does not limit this.

[0123] In some embodiments, after executing step 505, the first network node runs the smart contract to obtain the initial state information of the smart contract and stores the initial state information in the blockchain system. Optionally, the initial state information includes multiple variables declared by the smart contract and the initial state of these multiple variables. By storing the initial state information of the smart contract, the security and determinism of the smart contract can be further guaranteed.

[0124] Through the above technical solution, in the first-layer network of the blockchain system, the first network node used for blockchain consensus divides the smart contract into blocks and generates trustworthy verification information. For each branch business corresponding to the second network node in the second-layer network of the blockchain system, the corresponding target contract block is issued, significantly saving the transmission and storage resources consumed by contract synchronization. The second network node can verify the received contract block based on the verification information, effectively ensuring the privacy and security of the business. Furthermore, based on the implementation of multiple branch businesses, smart contracts can be divided into contract blocks at various granularities, ensuring the accuracy of smart contract block division, improving the flexibility of smart contract block division, and increasing the efficiency of deploying multiple branch businesses based on smart contracts.

[0125] After describing the process of deploying and executing smart contracts on the first network node, the following section details the process of synchronizing smart contracts between the first and second network nodes. Figure 7 This is a flowchart of a smart contract synchronization method provided in an embodiment of this application. See also... Figure 7 The method is applied to the aforementioned blockchain system and is implemented based on the interaction process between the first network node and the second network node in the blockchain system. The method includes the following steps 701 to 706.

[0126] 701. The second network node sends a contract synchronization request for the smart contract to any of the first network nodes.

[0127] The contract synchronization request instructs the first network node to send a target contract block to the second network node. This target contract block is the contract block among the multiple contract blocks of the smart contract that matches the branch service of the second network node. This contract block of the smart contract is used to implement at least one branch service in the corresponding business of the smart contract. The smart contract and contract block in this embodiment are described above. Figure 3 , Figure 4 and Figure 5 The corresponding content will not be elaborated here.

[0128] In some embodiments, the contract synchronization request instructs the smart contract and the branch service of the second network node to send the target contract block in the smart contract that matches the branch service to the second network node. Optionally, the contract synchronization request carries the contract identifier of the smart contract to indicate the smart contract, and the contract synchronization request carries the node identifier of the second network node to indicate the branch service of the second network node. The process by which the second network node obtains the contract identifier of the smart contract is described in step 506 and will not be repeated here.

[0129] In some embodiments, in response to receiving the smart contract verification information sent by the first network node, if the second network node determines that the smart contract is used to implement its own branch business, it sends a contract synchronization request to any of the first network nodes to synchronize the smart contract. In other embodiments, the second network node sends a contract synchronization request for the smart contract to any of the first network nodes at target time intervals, and determines whether the smart contract has been updated based on the message returned by the first network node, thereby synchronizing the latest smart contract in a timely manner.

[0130] In some embodiments, the second network node sends the contract synchronization request to the target first network node. Optionally, the target first network node is a first network node that sends the smart contract verification information to the second network node. Optionally, the target first network node is a first network node located in the same network area as the second network node, for example, in the same metropolitan area network.

[0131] 702. In response to the contract synchronization request for the smart contract from the second network node, the first network node determines the target contract block that matches the branch business of the second network node based on the node identifier carried in the contract synchronization request.

[0132] The node identifier of the second network node indicates the branch service of the second network node.

[0133] In some embodiments, there is a correspondence between the node identifier and the service identifier of the contract block. The service identifier indicates the branch service that the contract block can be used to implement. A description of the service identifier is provided in step 503 and will not be repeated here. Based on this, the first network node can determine the target contract block based on the node identifier and the service identifiers of multiple contract blocks of the smart contract.

[0134] In some embodiments, the node identifier corresponds to the service identifier. For example, corresponding to the description of the service identifier in step 503, node identifier "K" indicates the "invoicing" service, and node identifier "B" indicates the "reimbursement" service. In this example, the first network node can determine the target contract block by querying the service identifiers of multiple contract blocks based on the node identifier.

[0135] In other embodiments, the first network node stores a mapping table between each branch service and the contract block of the smart contract, so that the target contract block matching the branch service of the second network node can be determined by querying the mapping table based on the node identifier.

[0136] In some embodiments, the target contract block includes at least one contract block for implementing the branch business, but this application embodiment does not limit this.

[0137] 703. The first network node obtains the proof information corresponding to the target contract block based on the target contract block. The proof information includes the Merkle path of the target contract block in the Merkle tree of the smart contract. The Merkle path is used to verify the block order of the target contract block in the smart contract.

[0138] The explanation of the block order and the generation principle of the Merkle tree are referenced in step 504 above, and will not be repeated here.

[0139] In some embodiments, the first network node queries the Merkle tree of the smart contract based on at least one contract block included in the target contract block to obtain the Merkle path of the target contract block in the Merkle tree. Taking a target contract block comprising a contract block TxC as an example, refer to... Figure 6 In the Merkle tree, the Merkle path of contract block TxC is the leaf node H corresponding to the hash value of contract block TxC. C The node path "[H" in the Merkle tree of the smart contract AB H D According to the principle of generating Merkle trees, based on this "[H" AB H D This can be used to verify the leaf node H. A The existence and correct position of the target contract block in the Merkle tree are checked to verify the correct block order within the smart contract. The process for determining the Merkle path of contract block TxA when the target contract block comprises multiple blocks is similar and will not be elaborated here. It should be noted that the Merkle path indicates the multiple nodes used for verification and their corresponding hash values; for example, the Merkle path [H...] AB H D Instruction H ABThe corresponding hash value is Hash(H) A +H B ), H D The corresponding hash value is Hash(TxD).

[0140] Through the above technical solution, based on the segmentable verification characteristics of Merkle trees, a secure and trustworthy verification method can be provided for target contract blocks of any granularity, while ensuring the error-free matching between branch business and target contract blocks, thereby ensuring the security and reliability of block-based smart contracts.

[0141] In some embodiments, the first network node determines the second network node's permission information for the smart contract based on the node identifier carried in the contract synchronization request. This permission information indicates that the second network node can access the code range of the smart contract. Based on this, if the target contract block exceeds this code range, the first network node returns a call interface corresponding to the target contract block within the smart contract to the second network node. For example, the permission information indicates that the second network node can access the start and end range of the code corresponding to function 4 in the smart contract: code[81, 100]. If the target contract block includes functions 1 and 4 in the smart contract, since the second network node does not have permission to access the code fragment code[1, 10] corresponding to function 1, that is, the target contract block exceeds the code range indicated by the permission information. Based on the code of function 1, the first network node generates a call interface to call function 1 through the target contract block, replacing the code outside the code range in the target contract block with the call interface. Thus, even if the original code of function 1 is not included in the target contract block, function 1 can still be called to perform the corresponding operation.

[0142] By using the above technical solution to process the target contract block based on permission information, the privacy of the code can be further maintained, thereby ensuring the security of the smart contract.

[0143] 704. The first network node sends the target contract block and the proof information to the second network node.

[0144] 705. The second network node determines the verification information of the target contract block based on the Merkel path of the target contract block and the target contract block.

[0145] In this embodiment of the application, the second network node performs a hash operation on the target contract block according to the principle of generating a Merkle tree to obtain a target hash value. Then, based on the target hash value and the multiple hash values ​​included in the Merkle path, it generates a Merkle root to be verified corresponding to the target contract block according to the node order indicated by the Merkle path. The Merkle root to be verified can be used to verify whether the target contract block is a contract block of the smart contract.

[0146] In some embodiments, the second network node encrypts the contract identifier of the smart contract and the Merkle root to be verified based on the verification key used to generate the verification information of the smart contract, thereby generating the verification information of the target contract block. The process of obtaining the verification key and the contract identifier refers to step 506 and will not be repeated here. For example, the verification information can be obtained by the following formula (2).

[0147] IDx = F(name, rootx) (2)

[0148] In the above formula (2), the IDx of the target contract block to be verified is obtained by encrypting the contract identifier name of the smart contract and the Merkle root to be verified by the verification key F.

[0149] 706. If the verification information of the target contract block is consistent with the verification information of the smart contract, the second network node determines that the target contract block is the contract block of the smart contract and stores the target contract block.

[0150] In some embodiments, the second network node caches the target contract block and related information in temporary storage space to perform step 705 above. If the verification information of the target contract block and the verification information of the smart contract are consistent, the target contract block is persisted in memory to implement its branch business based on the target contract block. For example, the second network node compares the verification information IDx calculated based on the above formula (2) with the verification information ID of the smart contract. If IDx = ID, the target contract block is persisted in memory. The calculation process of ID is referred to formula (1), and will not be repeated here.

[0151] Through the above technical solution, corresponding target contract blocks are issued to each branch business of the second network node in the second-layer network of the blockchain system, greatly saving the transmission and storage resources consumed by contract synchronization. Each second network node can verify the received contract block based on verification information, effectively ensuring the privacy and security of the business. Furthermore, the second network node can verify the target contract block in a secure and reliable manner based on lightweight verification and proof information, saving computing resources while ensuring the security of the contract synchronization process. Moreover, synchronizing smart contracts on a block-by-block basis achieves code isolation between multiple branch businesses, effectively ensuring the privacy of businesses while greatly saving transmission and storage resources.

[0152] This application provides another smart contract synchronization method that can be executed by a computer device. The smart contract synchronization method includes the following steps A and B.

[0153] Step A: The computer device divides the smart contract into blocks to obtain multiple contract blocks. Based on these multiple contract blocks, the verification information of the smart contract is generated and sent. The contract block is used to implement at least one branch of the business corresponding to the smart contract.

[0154] In some embodiments, the computer device compiles the smart contract to determine the syntax information of the smart contract, the syntax information indicating the start and end range of the code in the smart contract used to implement the at least one branch of business; based on the syntax information, the smart contract is divided into blocks to obtain the multiple contract blocks.

[0155] In some embodiments, the computer device generates a Merkle tree of the smart contract based on the plurality of contract blocks and the block order of the plurality of contract blocks in the smart contract; and generates verification information of the smart contract based on the Merkle root of the Merkle tree and the contract identifier of the smart contract.

[0156] In some embodiments, the computer device generates the verification information based on the verification key, the Merkle root, and the contract identifier of the smart contract.

[0157] In some embodiments, the computer device sends the verification information and a verification key for generating the verification information, the verification key being used to generate the verification information corresponding to the contract block.

[0158] Step B: In response to the contract synchronization request for the smart contract, the computer device sends a target contract block, which is the contract block among the multiple contract blocks that matches the branch business corresponding to the contract synchronization request.

[0159] In some embodiments, the computer device determines the target contract block that matches the branch business of the node that sent the contract synchronization request based on the node identifier carried in the contract synchronization request; based on the target contract block, it obtains the proof information corresponding to the target contract block, the proof information including the Merkle path of the target contract block in the Merkle tree of the smart contract, the Merkle path being used to verify the block order of the target contract block in the smart contract.

[0160] In some embodiments, the computer device sends the proof information when sending the target contract block.

[0161] In some embodiments, the computer device determines the permission information of the node that sent the contract synchronization request for the smart contract based on the node identifier carried in the contract synchronization request. The permission information indicates that the node can access the code scope of the smart contract. If the target contract block is outside the code scope, the device returns the calling interface corresponding to the target contract block in the smart contract to the node.

[0162] The implementation principles of steps A and B above are as described above. Figures 3 to 7 The corresponding implementation examples will not be described in detail here.

[0163] By using the above technical solution, smart contracts are divided into multiple contract blocks and distributed, which greatly saves the transmission and storage resources consumed by contract synchronization. By providing trusted verification information, each node can verify the received contract blocks based on the verification information, thereby effectively ensuring the privacy and security of the business.

[0164] This application provides yet another smart contract synchronization method that can be executed by a computer device. The smart contract synchronization method includes the following steps 1 and 2.

[0165] Step 1: The computer device sends a contract synchronization request for the smart contract. The contract synchronization request is used to obtain the target contract block. The target contract block is the contract block that matches the branch business corresponding to the contract synchronization request among the multiple contract blocks of the smart contract. The contract block of the smart contract is used to implement at least one branch business in the corresponding business of the smart contract.

[0166] Step 2: Based on the verification information of the smart contract and the target contract block, the computer device stores the target contract block if it determines that the target contract block is a contract block of the smart contract.

[0167] In some embodiments, the computer device determines the verification information of the target contract block based on the Merkel path of the target contract block and the target contract block; if the verification information of the target contract block and the verification information of the smart contract are consistent, the target contract block is determined to be the contract block of the smart contract, and the target contract block is stored.

[0168] The implementation principles of steps 1 and 2 above are as described above. Figures 3 to 7 The corresponding implementation examples will not be described in detail here.

[0169] By using the above technical solution, smart contracts are divided into multiple contract blocks and distributed, which greatly saves the transmission and storage resources consumed by contract synchronization. By providing trusted verification information, each node can verify the received contract blocks based on the verification information, thereby effectively ensuring the privacy and security of the business.

[0170] This application provides a computer device that can be implemented as the first network node, second network node, or computer device described above, to implement the smart contract synchronization method provided in the various embodiments above. The structure of the computer device is described below:

[0171] Figure 8This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. The computer device 800 can vary significantly due to differences in configuration or performance. It may include one or more Central Processing Units (CPUs) 801 and one or more memories 802. The one or more memories 802 store at least one computer program, which is loaded and executed by the one or more processors 801 to implement the methods provided in the various method embodiments described above. Of course, the computer device 800 may also have wired or wireless network interfaces, a keyboard, and input / output interfaces for input and output. The computer device 800 may also include other components for implementing device functions, which will not be elaborated upon here.

[0172] In an exemplary embodiment, a computer-readable storage medium is also provided, such as a memory including a computer program that can be executed by a processor to perform the smart contract synchronization method in the above embodiments. For example, the computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc read-only memory (CD-ROM), magnetic tape, floppy disk, and optical data storage device, etc.

[0173] In an exemplary embodiment, a computer program product or computer program is also provided, which includes program code stored in a computer-readable storage medium. The processor of a computer device reads the program code from the computer-readable storage medium and executes the program code, causing the computer device to execute the aforementioned smart contract synchronization method.

[0174] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.

[0175] The above are merely optional embodiments of this application and are not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A blockchain system, characterized in that, The system includes a first-layer network and a second-layer network. The first-layer network includes multiple first network nodes, and the second-layer network includes multiple second network nodes. The first network node is used to compile the smart contract and determine the syntax information of the smart contract, wherein the syntax information indicates the start and end range of the code in the smart contract used to implement at least one branch of business; Based on the syntax information, the smart contract is divided into blocks to obtain multiple contract blocks. Based on the multiple contract blocks, verification information of the smart contract is generated and sent to the multiple second network nodes. The contract blocks are used to implement at least one branch of the business corresponding to the smart contract. The first network node is further configured to, in response to a contract synchronization request from any of the second network nodes for the smart contract, send a target contract block to the second network node, wherein the target contract block is a contract block among the plurality of contract blocks that matches the branch business of the second network node; The second network node is used to store the target contract block based on the verification information of the target contract block and the smart contract, if it is determined that the target contract block is a contract block of the smart contract.

2. The system according to claim 1, characterized in that, The first network node is used for: Based on the multiple contract blocks and the block order of the multiple contract blocks in the smart contract, a Merkle tree of the smart contract is generated; Based on the Merkle root of the Merkle tree and the contract identifier of the smart contract, the verification information of the smart contract is generated.

3. The system according to claim 2, characterized in that, The first network node is configured to: generate the verification information based on the verification key, the Merkle root, and the contract identifier of the smart contract.

4. The system according to claim 2 or 3, characterized in that, The first network node is also used for: The verification information is sent to the plurality of second network nodes, and a verification key is used to generate the verification information, wherein the verification key is used to generate the verification information corresponding to the contract block.

5. The system according to claim 1, characterized in that, The first network node is used for: Based on the node identifier carried in the contract synchronization request, the target contract block that matches the branch business of the second network node is determined; Based on the target contract block, obtain the proof information corresponding to the target contract block. The proof information includes the Merkle path of the target contract block in the Merkle tree of the smart contract. The Merkle path is used to verify the block order of the target contract block in the smart contract. The first network node is also used to send the target contract block and the proof information to the second network node.

6. The system according to claim 5, characterized in that, The second network node is used for: Based on the Merkel path of the target contract block and the target contract block, determine the verification information of the target contract block; If the verification information of the target contract block matches the verification information of the smart contract, the target contract block is determined to be a contract block of the smart contract, and the target contract block is stored.

7. The system according to claim 1, characterized in that, The first network node is also used for: Based on the node identifier carried in the contract synchronization request, the permission information of the second network node for the smart contract is determined, and the permission information instructs the second network node to obtain the code scope of the smart contract; If the target contract block exceeds the code range, return the calling interface corresponding to the target contract block in the smart contract to the second network node.

8. A smart contract synchronization method, characterized in that, Executed by a first network node in a blockchain system, the blockchain system comprising a layer 1 network and a layer 2 network, the layer 1 network comprising multiple first network nodes, and the layer 2 network comprising multiple second network nodes, the method comprising: The smart contract is compiled to determine its syntax information, which indicates the start and end range of the code in the smart contract used to implement at least one branch of the business; based on the syntax information, the smart contract is divided into blocks to obtain multiple contract blocks; based on the multiple contract blocks, verification information of the smart contract is generated and sent to the multiple second network nodes; the contract blocks are used to implement at least one branch of the business corresponding to the smart contract. In response to a contract synchronization request from any of the second network nodes for the smart contract, a target contract block is sent to the second network node, wherein the target contract block is the contract block among the plurality of contract blocks that matches the branch business of the second network node.

9. The method according to claim 8, characterized in that, The step of generating verification information for the smart contract based on the multiple contract blocks includes: Based on the multiple contract blocks and the block order of the multiple contract blocks in the smart contract, a Merkle tree of the smart contract is generated; Based on the Merkle root of the Merkle tree and the contract identifier of the smart contract, the verification information of the smart contract is generated.

10. The method according to claim 9, characterized in that, The process of generating verification information for the smart contract based on the Merkle root of the Merkle tree and the contract identifier of the smart contract includes: The verification information is generated based on the verification key, the Merkle root, and the contract identifier of the smart contract.

11. The method according to claim 9 or 10, characterized in that, The method further includes: The verification information is sent to the plurality of second network nodes, and a verification key is used to generate the verification information, wherein the verification key is used to generate the verification information corresponding to the contract block.

12. The method according to claim 8, characterized in that, The step of sending the target contract block to the second network node in response to any contract synchronization request from the second network node for the smart contract includes: Based on the node identifier carried in the contract synchronization request, the target contract block that matches the branch business of the second network node is determined; Based on the target contract block, obtain the proof information corresponding to the target contract block. The proof information includes the Merkle path of the target contract block in the Merkle tree of the smart contract. The Merkle path is used to verify the block order of the target contract block in the smart contract. The method further includes: The target contract block and the proof information are sent to the second network node.

13. A smart contract synchronization method, characterized in that, Executed by a second network node in a blockchain system, the blockchain system comprising a first-layer network and a second-layer network, the first-layer network comprising multiple first network nodes, and the second-layer network comprising multiple second network nodes, the method comprising: Send a contract synchronization request for the smart contract to any of the first network nodes. The contract synchronization request is used to obtain a target contract block. The target contract block is a contract block among multiple contract blocks of the smart contract that matches the branch business of the second network node. The contract block of the smart contract is used to implement at least one branch business in the corresponding business of the smart contract. Based on the verification information of the smart contract and the target contract block, if it is determined that the target contract block is a contract block of the smart contract, the target contract block is stored. The multiple contract blocks are obtained by dividing the smart contract into blocks based on the syntax information of the smart contract. The syntax information indicates the start and end range of the code in the smart contract used to implement the at least one branch business. The syntax information is obtained by compiling the smart contract.

14. A smart contract synchronization method, characterized in that, The method includes: The smart contract is compiled to determine its syntax information, which indicates the start and end range of the code in the smart contract used to implement at least one branch of the business; based on the syntax information, the smart contract is divided into blocks to obtain multiple contract blocks; based on the multiple contract blocks, verification information of the smart contract is generated and sent; the contract blocks are used to implement at least one branch of the business in the corresponding business of the smart contract. In response to a contract synchronization request for the smart contract, a target contract block is sent, wherein the target contract block is the contract block among the plurality of contract blocks that matches the branch business corresponding to the contract synchronization request.

15. A smart contract synchronization method, characterized in that, The method includes: Send a contract synchronization request for the smart contract. The contract synchronization request is used to obtain a target contract block. The target contract block is a contract block that matches the branch business corresponding to the contract synchronization request among multiple contract blocks of the smart contract. The contract block of the smart contract is used to implement at least one branch business in the corresponding business of the smart contract. Based on the verification information of the smart contract and the target contract block, if it is determined that the target contract block is a contract block of the smart contract, the target contract block is stored. The multiple contract blocks are obtained by dividing the smart contract into blocks based on the syntax information of the smart contract. The syntax information indicates the start and end range of the code in the smart contract used to implement the at least one branch business. The syntax information is obtained by compiling the smart contract.

16. A computer device, characterized in that, The computer device includes one or more processors and one or more memories, wherein at least one computer program is stored in the one or more memories, and the computer program is loaded and executed by the one or more processors to implement the smart contract synchronization method as described in claim 14 or claim 15.

17. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one computer program, which is loaded and executed by a processor to implement the smart contract synchronization method as described in claim 14 or claim 15.

18. A computer program product, characterized in that, The computer program product includes program code stored in a computer-readable storage medium. A processor of a computer device reads the program code from the computer-readable storage medium and executes the program code, causing the computer device to perform the smart contract synchronization method as described in claim 14 or claim 15.

Citation Information

Patent Citations

  • Method and system for submitting cross-fragment transaction, main chain node and source fragment node

    CN112261157A