Deployment method, calling method and related device of smart contract

By dividing smart contract code into a first code segment and a second code fragment and storing them in the blockchain's code fragment library, the problem of wasted storage space caused by smart contract deployment is solved, and storage costs and computing resource consumption are reduced.

CN122131966APending Publication Date: 2026-06-02TENCENT TECHNOLOGY (SHENZHEN) CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
TENCENT TECHNOLOGY (SHENZHEN) CO LTD
Filing Date
2024-12-02
Publication Date
2026-06-02

AI Technical Summary

Technical Problem

Existing smart contract deployment methods result in wasted storage space on blockchain nodes and high storage costs.

Method used

The smart contract's code is divided into a first code segment and a second code fragment. The second code fragment is stored in a preset code fragment library, and fragment combination information is generated for executing the call transaction.

Benefits of technology

This reduces the waste of storage space in blockchain nodes and lowers the storage costs and computing resource consumption for smart contract deployment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122131966A_ABST
    Figure CN122131966A_ABST
Patent Text Reader

Abstract

This application discloses a method for deploying and invoking smart contracts, as well as related equipment. The deployment method includes: obtaining a deployment transaction for a smart contract, the deployment transaction containing contract code; performing matching processing on the contract code based on a pre-set code fragment library on the blockchain, the matching result being used to indicate a first code fragment similar to the contract code in the code fragment library and a first code interval similar to the first code fragment in the contract code; determining a second code fragment in the contract code based on the first code interval, the second code fragment referring to the remaining code interval in the contract code excluding the first code interval; storing the second code fragment in the code fragment library; generating fragment combination information of the contract code based on the first and second code fragments in the code fragment library, the fragment combination information of the contract code being used to execute the invoking transaction of the smart contract. This application can reduce the storage cost of smart contract deployment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and more particularly to the field of blockchain technology, specifically to a method for deploying a smart contract, a method for invoking a smart contract, a device for deploying a smart contract, a device for invoking a smart contract, a computer device, a computer-readable storage medium, and a computer program product. Background Technology

[0002] Blockchain technology is an innovative technology combining distributed data storage, smart contracts, consensus mechanisms, and cryptographic algorithms. Its core mechanism is a distributed ledger technology maintained jointly by multiple parties in an untrusted, competitive environment. It possesses characteristics such as openness, tamper-proofing, anonymity, decentralization, and traceability, significantly expanding the breadth and depth of collaboration. In blockchain technology, smart contracts are the core of implementing business logic; however, current methods of deploying smart contracts greatly waste the storage space of blockchain nodes, resulting in high storage costs for smart contract deployment. Summary of the Invention

[0003] This application provides a method for deploying and invoking smart contracts, as well as related equipment, which can reduce the storage costs of smart contract deployment.

[0004] On one hand, embodiments of this application provide a method for deploying a smart contract, the method comprising:

[0005] Obtain a deployment transaction for a smart contract. The deployment transaction is used to request the deployment of the smart contract on the blockchain. The deployment transaction contains the contract code of the smart contract.

[0006] In response to the deployment of transactions, the contract code is matched based on a pre-set code snippet library on the blockchain to obtain a matching result. The matching result is used to indicate the first code snippet in the pre-set code snippet library that is similar to the contract code, and to indicate the first code interval in the contract code that is similar to the first code snippet.

[0007] Based on the first code segment, a second code segment is determined in the contract code. The second code segment refers to the remaining code segment in the contract code excluding the first code segment.

[0008] The second code fragment is stored in a preset code fragment library, and based on the first and second code fragments in the preset code fragment library, fragment combination information of the contract code is generated. The fragment combination information of the contract code is used to execute the smart contract call transaction.

[0009] On the other hand, embodiments of this application provide a method for invoking a smart contract, the method comprising:

[0010] Obtain the call transaction for the smart contract. The call transaction is used to request the call to the smart contract deployed on the blockchain. The call transaction contains the contract address of the smart contract.

[0011] In response to the transaction call, the fragment combination information of the smart contract's code is obtained based on the smart contract's contract address. The fragment combination information is used to indicate the first code segment and the second code segment that make up the contract code.

[0012] According to the instructions of the fragment combination information, the first code interval and the second code fragment are obtained, and the first code interval and the second code fragment are spliced ​​together to form the contract code;

[0013] Run the contract code to execute the call transaction.

[0014] On the other hand, embodiments of this application provide a smart contract deployment apparatus, the apparatus comprising:

[0015] The acquisition unit is used to acquire deployment transactions for smart contracts. Deployment transactions are used to request the deployment of smart contracts on the blockchain. The deployment transaction contains the contract code of the smart contract.

[0016] The processing unit is used to respond to the deployment transaction by matching the contract code based on a pre-set code snippet library on the blockchain to obtain a matching result. The matching result is used to indicate the first code snippet in the pre-set code snippet library that is similar to the contract code, and to indicate the first code interval in the contract code that is similar to the first code snippet.

[0017] The processing unit is also used to determine a second code segment in the contract code based on the first code segment, wherein the second code segment refers to the remaining code segment in the contract code excluding the first code segment;

[0018] The processing unit is also used to store the second code fragment into a preset code fragment library, and generate fragment combination information of contract code based on the first code fragment and the second code fragment in the preset code fragment library. The fragment combination information of contract code is used to execute the smart contract call transaction.

[0019] In one embodiment, in response to a deployment transaction, the processing unit performs matching processing on the contract code based on a pre-set code snippet library on the blockchain to obtain a matching result, including: in response to the deployment transaction, creating a contract address for the smart contract; extracting contract code from the deployment transaction, the contract code containing an initialization function; running the initialization function to set the world state of the smart contract, and storing the world state and contract address in a state database synchronized with the blockchain; obtaining the execution code obtained by the contract code after running the initialization function, and performing matching processing on the execution code based on the pre-set code snippet library on the blockchain to obtain a matching result.

[0020] In one embodiment, a preset code snippet library contains at least one code snippet; the processing unit performs matching processing on the executable code based on the preset code snippet library on the blockchain to obtain a matching result, including: obtaining the similarity between the executable code and each code snippet in the at least one code snippet; selecting a first code snippet from the at least one code snippet according to the similarity, wherein the first code snippet is the code snippet with the highest similarity to the executable code among the at least one code snippets; and adding the first code snippet to the matching result; wherein the similarity between the executable code and the code snippet is used to indicate the length of the longest common string between the executable code and the code snippet.

[0021] In one embodiment, the first code interval refers to the position interval of the longest common string between the first code segment and the executable code in the executable code; the processing unit determines the second code segment in the contract code based on the first code interval, including: removing the first code interval from the executable code to obtain the remaining code interval; if the length of the remaining code interval is less than a preset length threshold, then the remaining code interval is determined as the second code segment.

[0022] In one embodiment, the processing unit is further configured to: if the length of the remaining code interval is greater than or equal to a preset length threshold, set the remaining code interval as new executable code, and perform matching processing on the new executable code based on a preset code fragment library on the blockchain to obtain a matching result.

[0023] In one embodiment, a preset code snippet library includes storage identifiers for a first code snippet and a second code snippet; a first code interval contains the longest common string between the first code snippet and the executable code; the processing unit generates snippet combination information of the contract code based on the first code snippet and the second code snippet in the preset code snippet library, including: obtaining the start and end positions of the longest common string between the first code snippet and the executable code in the first code snippet; generating index information of the first code interval using the storage identifier of the first code snippet, and the start and end positions; generating index information of the second code snippet using the storage identifier of the second code snippet; and combining the index information of the first code interval and the index information of the second code snippet based on the order of the first code interval and the second code snippet in the executable code to obtain the snippet combination information of the contract code.

[0024] In one embodiment, the world state includes a code hash field, and the processing unit is further configured to: associate and store the code hash field in the world state with fragment combination information of the contract code in the state database.

[0025] In one embodiment, the deployment method of the preset code snippet library includes any of the following: the preset code snippet library is deployed on the blockchain in the form of a smart contract; the preset code snippet library is deployed on the blockchain in the form of a decentralized application.

[0026] On the other hand, embodiments of this application provide a smart contract invocation device, the device comprising:

[0027] The acquisition unit is used to acquire the call transaction for the smart contract. The call transaction is used to request the call to the smart contract deployed on the blockchain. The call transaction contains the contract address of the smart contract.

[0028] The processing unit is used to respond to the call transaction by obtaining the fragment combination information of the smart contract's code based on the smart contract's contract address. The fragment combination information is used to indicate the first code segment and the second code segment that make up the contract code.

[0029] The processing unit is also used to obtain the first code segment and the second code segment according to the instructions of the segment combination information, and to splice the first code segment and the second code segment to form contract code;

[0030] The processing unit is also used to run contract code to execute the call transaction.

[0031] In one embodiment, a state database synchronized with the blockchain stores a code hash field, which is configured to be associated with fragment combination information of the smart contract's contract code. In response to a call transaction, the processing unit obtains the fragment combination information of the smart contract's contract code based on the smart contract's contract address, including: extracting the smart contract's contract address from the call transaction; obtaining the code hash field from the state database based on the smart contract's contract address; and obtaining setting information associated with the code hash field, the setting information representing the fragment combination information of the smart contract's contract code.

[0032] In one embodiment, the processing unit obtains a first code interval and a second code segment according to the instructions of the segment combination information, and concatenates the first code interval and the second code segment to form contract code. This includes: obtaining index information of the first code interval and index information of the second code segment from the segment combination information; the index information of the first code interval includes the storage identifier, start position, and end position of the first code segment, and the index information of the second code segment includes the storage identifier of the second code segment; using the storage identifier of the first code segment, determining the first code segment from a pre-set code segment library on the blockchain, and defining the position interval formed by the start and end positions of the first code segment as the first code interval; using the storage identifier of the second code segment, obtaining the second code segment from the pre-set code segment library; and concatenating the first code interval and the second code segment based on their order in the execution code to form the execution code in the contract code. The execution code is obtained after the contract code runs its initialization function.

[0033] In one embodiment, the processing unit runs contract code to execute a call transaction, including: setting the contract code field in the context information of the smart contract to the executable code; and executing the call transaction based on the set context information.

[0034] On the other hand, embodiments of this application provide a computer device, which includes:

[0035] A processor is used to load and execute computer programs;

[0036] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the deployment method or the invocation method of the aforementioned smart contract.

[0037] On the other hand, embodiments of this application provide a computer-readable storage medium storing a computer program adapted to be loaded by a processor and executed for the deployment method or the invocation method of the aforementioned smart contract.

[0038] On the other hand, embodiments of this application provide a computer program product, which includes a computer program that, when executed by a processor, implements the above-mentioned smart contract deployment method or the above-mentioned smart contract invocation method.

[0039] In this embodiment, upon receiving a deployment request for a smart contract, the contract code of the smart contract can be divided into a first code segment and a second code fragment. The second code fragment is then stored in a pre-defined code fragment library on the blockchain. The first code segment is a code segment in the contract code similar to the first code fragment. The first code fragment is a code fragment in the pre-defined code fragment library similar to the contract code. The second code fragment refers to the remaining code segments in the contract code excluding the first code segment. In other words, the first code fragment contains the same code content as the first code segment. Therefore, based solely on the first and second code fragments in the pre-defined code fragment library, fragment combination information of the contract code can be generated. When executing a smart contract call transaction, the contract code can be assembled using the fragment combination information to execute the smart contract call transaction. Since blockchain nodes can ensure that similar code is stored only once through the pre-defined code fragment library, the waste of storage space on blockchain nodes is reduced. Simultaneously, by reducing the amount of data stored on blockchain nodes, the consumption of computing resources and bandwidth on blockchain nodes can be reduced, thereby lowering the storage cost of smart contract deployment. Attached Figure Description

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

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

[0042] Figure 3 This is a schematic diagram of a block generation process provided in an embodiment of this application;

[0043] Figure 4 This is a schematic diagram of a state database provided in an embodiment of this application;

[0044] Figure 5 This is a schematic diagram of the structure of a smart contract processing system provided in an embodiment of this application;

[0045] Figure 6 This is a flowchart illustrating a smart contract deployment method provided in an embodiment of this application;

[0046] Figure 7 This is a schematic diagram of transaction deployment logic within a blockchain node provided in an embodiment of this application;

[0047] Figure 8 This is a flowchart illustrating a smart contract invocation method provided in an embodiment of this application;

[0048] Figure 9This is a schematic diagram of transaction invocation logic within a blockchain node provided in an embodiment of this application;

[0049] Figure 10 This is a schematic diagram of the structure of a smart contract deployment device provided in an embodiment of this application;

[0050] Figure 11 This is a schematic diagram of the structure of a smart contract invocation device provided in an embodiment of this application;

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

[0052] To better understand the technical solutions provided in the embodiments of this application, the key terms involved in the embodiments of this application are introduced here:

[0053] I. Blockchain Network:

[0054] Nodes in a blockchain network are called blockchain nodes. A blockchain node can be a computer device (or computer node), which may include terminal devices or servers. Terminal devices include, but are not limited to, smartphones, tablets, smart wearable devices, smart voice interaction devices, smart home appliances, personal computers, in-vehicle terminals, smart cameras, etc., and this application does not impose any restrictions on this. A server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms, but is not limited to these.

[0055] A blockchain network is a peer-to-peer network. Each blockchain node connected in a peer-to-peer manner is called a peer node. The blockchain network is based on a specific network protocol, which allows peer nodes to maintain the network state without a central node. Each peer node maintains the state of the entire network and its connection state with neighboring nodes through broadcast interactions with neighboring nodes.

[0056] See also Figure 1The diagram illustrates the structure of a blockchain network. A blockchain network can include multiple blockchain nodes. Each blockchain node, during normal operation, receives input information (e.g., blockchain transactions) and maintains shared data within the network based on this input. To ensure interoperability within the blockchain network, information connections exist between each blockchain node, allowing for information transmission. For example, when any blockchain node receives input information, other blockchain nodes retrieve this input information according to a consensus algorithm and store it as part of the shared data, ensuring data consistency across all blockchain nodes. Each blockchain node has a corresponding node identifier, and each node can also store the node identifiers of other blockchain nodes. This allows for the broadcast of generated blocks to other blockchain nodes based on their identifiers. Each blockchain node maintains a node identifier list as shown in Table 1, storing node names and identifiers accordingly. The node identifier can be an IP (Internet Protocol) address or any other information that can be used to identify the blockchain node. Table 1 uses IP addresses as an example only:

[0057] Table 1

[0058] Node Name Node identifier Node 1 111.111.111.111 Node 2 222.222.222.222 … … Node N NNN.NNN.NNN.NNN

[0059] II. Blockchain Transactions:

[0060] Blockchain transactions are also known as transactions. A transaction includes operations that need to be submitted to the blockchain network for execution. It does not refer solely to transactions in a business context. Given that the term "transaction" is conventionally used in blockchain technology, this application follows this convention.

[0061] A transaction may contain at least one of the following information: 1) nonce field: Transaction count, the number of transactions initiated by the sender; 2) gasPrice field: The transaction fee that the sender is willing to pay per unit of gas (a unit of cost measurement for the cost of executing a unit of operation, used to quantify computational complexity and resource consumption) to execute this transaction; 3) gasLimit field: The maximum transaction fee that the sender is willing to pay to execute this transaction; 4) to field: The recipient's address; In smart contract deployment transactions, the smart contract's contract address does not yet exist, so an empty address (address 0) is used instead; 5) value field: The amount of electronic resources transferred from the sender to the recipient; In smart contract deployment transactions, the remaining amount of resources in the smart contract's contract account at the time of smart contract initialization (included in the balance field) is used instead; 6) v,r,s fields: The sender's signature.

[0062] In addition, smart contract deployment transactions typically include the following information: the smart contract's contract code, which can be stored in the `data` field. In one implementation, the smart contract's source code can be written using a high-level programming language (such as Solidity, a statically typed language), and then compiled into bytecode (an intermediary between source code and machine code) using a smart contract compiler (such as a Remix compiler or a Truffle compiler). The resulting bytecode is then identified as the smart contract's contract code.

[0063] The contract code of a smart contract can be executed on a transaction executor. For example, the transaction executor can be a smart contract virtual machine (SMVM). The SMVM can interpret the smart contract code into machine code (directly executable machine language instructions) and execute that machine code. The smart contract virtual machine is a virtual environment in a blockchain network used to execute smart contracts. It provides computing resources and a runtime container for smart contracts, ensuring that the execution of smart contracts is secure and independent, similar to a sandbox environment.

[0064] A smart contract's contract code includes an initialization function, which is the first function executed when the smart contract is deployed to the blockchain. For example, the initialization function can be defined as a constructor, executed only once during smart contract deployment. The initialization function is used to initialize the smart contract, which means setting the smart contract's initial state. For instance, running the initialization function can initialize and assign values ​​to the state variables defined in the smart contract, ensuring that the smart contract has a correct initial state when it is first invoked. The state variables defined in the smart contract are variables used to store data. This data can be various information about the smart contract, such as the smart contract's owner, maximum total supply, and usage permission rules.

[0065] III. Smart Contracts:

[0066] Smart contracts, also known as chaincode or application code, are computer protocols designed to disseminate, verify, or execute contracts in an informational manner. They carry the business logic for executing transactions and typically run in isolated environments (such as transaction executors, which include, but are not limited to, containers and smart contract virtual machines). Smart contracts are programs that automatically execute on various blockchain nodes according to specific conditions. They can manipulate data stored on the blockchain and are a crucial way for business entities to interact with the blockchain and utilize it to implement business logic. The purpose of smart contracts is to provide a security method superior to traditional contracts and reduce other transaction costs associated with contracts. They allow for trusted transactions without third parties, and these transactions are traceable and irreversible.

[0067] In a blockchain network, smart contracts are stored and executed through their contract accounts. A smart contract's contract account contains the contract's state information, its code, and internal information such as the current values ​​of its defined state variables. For example, the state information in the contract account might include: remaining resources (included in the `balance` field, representing the amount of electronic resources held in the contract account), contract count (included in the `nonce` field, representing the number of contracts created by the contract account), the root hash of the account's state tree (included in the `StorageRoot` field), and the hash value of the contract code (included in the `Codehash` field, used to verify whether the contract code has been tampered with). The smart contract's contract account is controlled by the contract code itself; for example, updates to the smart contract's state information are achieved through transaction-triggered execution of the contract code. The account state tree is used to store information about the smart contract itself. Each contract account has its own account state tree. For example, when the smart contract is initialized, Zhang San's points are set to 0 in the account state tree. When Zhang San performs a transfer operation, he can send a smart contract call transaction to the blockchain node. After executing the smart contract call transaction and completing the transfer operation, Zhang San's points can be set to 1 in the account state tree.

[0068] In addition to contract accounts for smart contracts, accounts in a blockchain network also include external accounts. External accounts are directly controlled by users, typically associated with their private keys, and can be used to send transactions, receive electronic resources, and interact with smart contracts. The state information of an external account usually includes: remaining resources (included in the balance field, representing the amount of electronic resources held in the external account) and a transaction count (included in the nonce field, representing the number of transactions initiated by the external account). Contract accounts for smart contracts cannot actively interact with external accounts; they must be triggered by external accounts to execute.

[0069] IV. Account Books:

[0070] The ledger is a collective term for the blockchain and the state database synchronized with it. Each blockchain node in a blockchain network stores the blockchain, and each blockchain node maintains a state database synchronized with the blockchain.

[0071] 1) Blockchain: Blockchain is a chained-block data structure built in a peer-to-peer network environment using transparent and trusted rules. It is designed to be tamper-proof, undisturbed, traceable, and shared. The chained-block data structure stores transactions occurring within a certain period in units of blocks, and uses cryptographic algorithms to link these blocks chronologically into a chain. See also... Figure 2 The blockchain structure shown consists of multiple blocks. The genesis block includes a block header and a block body. The block header of the genesis block stores input information feature values, version number, timestamp, and difficulty value. The block body of the genesis block stores input information (i.e., transactions). The next block after the genesis block takes the genesis block as its parent block. The next block also includes a block header and a block body. In addition to storing the input information feature values, version number, timestamp, and difficulty value of the current block, the block header feature values ​​of the parent block are also stored in the next block's block header. This process continues, ensuring that the block data stored in each block is related to the block data stored in its parent block, thus guaranteeing the security of input information in the blocks.

[0072] When generating the individual blocks in the blockchain, see [link / reference]. Figure 3 The block generation process shown involves the following steps: When a blockchain node receives input information, it verifies the input information. After verification, the input information is stored in the blockchain's transaction pool, and its hash tree (such as the world state tree, transaction tree, receipt tree, etc.) used to record the input information is updated. Then, the timestamp is updated to the time the input information was received, and different random numbers are tried multiple times to calculate the feature value, ensuring that the calculated feature value satisfies the following formula:

[0073] SHA256(SHA256(version+prev_hash+merkle_root+ntime+nbits+x)) <TARGET

[0074] Among them, SHA256 (Secure Hash Algorithm 256) is the feature value algorithm used to calculate the feature value; version (version number) is the version information of the relevant block protocol in the blockchain; prev_hash is the block header feature value of the parent block of the current block; merkle_root is the feature value of the input information; ntime is the update time of the update timestamp; nbits is the current difficulty, which is a fixed value for a period of time and is determined again after exceeding the fixed time period; x is a random number; TARGET is the feature value threshold, which can be determined based on nbits.

[0075] Thus, when a random number satisfying the above formula is calculated, the information can be stored accordingly, generating a block header and block body to obtain the current block. Subsequently, the blockchain node hosting the blockchain sends the newly generated block to other blockchain nodes in its network based on the node identifiers of other blockchain nodes. These other blockchain nodes then verify the newly generated block and add it to their stored blockchain after verification.

[0076] Blockchains are generally classified into three types: public blockchains, private blockchains, and consortium blockchains. Public blockchains offer the highest degree of decentralization. Nodes / participants in a public blockchain can read data on the chain, publish transactions, and compete for the right to record new blocks; moreover, nodes / participants can freely join and leave the public blockchain. Private blockchains, on the other hand, have their record-keeping and data reading permissions controlled by a specific organization or institution. Participants are fewer and cannot join arbitrarily; they must be approved by the organization or institution. Consortium blockchains, also known as community blockchains, are blockchains whose consensus process is controlled by pre-selected nodes. They are a hybrid of public and private blockchains, achieving "partial decentralization." Each node on the chain typically has a corresponding entity or organization; participants join the network through authorization and form a consortium of interested parties to jointly maintain the blockchain's operation. Through consortium blockchains, new participants can join an existing blockchain and share data without having to build it from scratch.

[0077] 2) State Database: The state database (stateDB) is a database that stores the world state of all accounts in the blockchain network. World state refers to the global state of an account within the blockchain network (including the smart contract's contract code, smart contract state information, and the smart contract's own information, etc.). For example, see... Figure 4 The diagram illustrates the state database, which includes a world state tree. The world state tree is a data structure (such as a Merkle Patricia tree) that stores the state information of all accounts (including external and contract accounts) in the blockchain network. Each leaf node in the world state tree represents the state information of an account. Each piece of state information stored in the world state tree requires a key, which is the account's address. In other words, the world state tree stores the mapping from account addresses to account state information. For contract accounts, the StorageRoot field is associated with the account state tree, and the contract code is associated with the Codehash field. For example, the state database can contain contract code storage units. Key-value pairs can be constructed by using the Codehash field as the key and the contract code as the value, and these key-value pairs can be stored in the contract code storage unit. The state database supports snapshots and rollbacks of state information. Through the snapshot mechanism, state information can be temporarily modified during transaction execution or smart contract invocation, and modifications can be revoked as needed.

[0078] An account address is a string used to uniquely identify an account. In one implementation, the contract account address can be calculated from the contract creator's address and the number of transactions sent from that address (included in the nonce field). For example, the contract account address can be calculated using RLP (Recursive Length Prefix) encoding and the Keccak-256 hash algorithm based on the contract creator's address and the number of transactions sent from that address. In another implementation, the external account address can be generated from a public key using a hash algorithm. For example, a public key is generated from a private key using an elliptic curve algorithm, the public key is hashed to generate a public key hash, and the external account address is obtained by encoding the public key hash using a specific encoding method.

[0079] V. Code Snippet Library:

[0080] A pre-defined code snippet library on the blockchain is a collection of code snippets used to store and manage smart contracts. These code snippets can contain part or all of the smart contract's code. In one feasible implementation, the pre-defined code snippet library may also include code snippets of commonly used functions and algorithms. In one implementation, this pre-defined code snippet library can be deployed on the blockchain as a smart contract or as a decentralized application (DApp). The pre-defined code snippet library includes at least one code snippet. Once deployed on the blockchain, at least one code snippet from the pre-defined code snippet library is stored in the ledger as part of the smart contract. This storage method allows the code snippets in the pre-defined code snippet library to be visible and accessible to all accounts in the blockchain network. A decentralized application (DApp) is an application that runs on a blockchain network without a single centralized control institution or node. Participant information is securely protected (and may be anonymized), and decentralized operations are performed by different people on the network nodes.

[0081] Currently, blockchain nodes directly store the contract code of smart contracts. Since many smart contracts share similar code, and their logic is often identical except for initial assignments of certain state variables (e.g., most of the code in asset-based ERC20 contracts is similar or even identical), this redundant storage consumes significant storage space on blockchain nodes, resulting in high storage costs. Furthermore, storing contract code by function segmentation makes it difficult to reassemble it during smart contract calls, leading to low usability. This application proposes a contract deployment and invocation scheme based on redundant storage of similar code, which can reduce the storage costs for deploying smart contracts and improve the efficiency of smart contract invocation.

[0082] The system architecture applicable to this application is described below; see [link to relevant documentation]. Figure 5 This is a schematic diagram of the structure of a smart contract processing system provided in an embodiment of this application, as shown below. Figure 5 As shown, the smart contract processing system may include at least one client 101 and a blockchain network 102, wherein the blockchain network 102 includes at least one blockchain node 103. The client 101 may be an application running on a terminal device to provide blockchain services to users, and the blockchain node 103 may be a computer device.

[0083] Blockchain node 103 is divided into full nodes and light nodes. Full nodes are a crucial component of the blockchain network, responsible for storing all blocks and transaction records since the blockchain's inception. By maintaining a complete data copy, they can independently verify the validity of transactions and the integrity of the blockchain, thereby ensuring network security and consistency. Light nodes, on the other hand, learn about the latest blocks through a distributed hash table, storing only block headers. They cannot independently verify transactions and rely on full nodes for data support. This application uses the example of all blockchain nodes 103 in blockchain network 102 being full nodes for illustration.

[0084] The blockchain network 102 may include one or more blockchains, and one blockchain may correspond to one channel. Blockchain nodes that have joined the same channel can conduct transactions or share ledgers. A single blockchain node can join one or more channels. When a blockchain node joins one channel, it holds one ledger; when it joins multiple channels, it holds multiple ledgers. This embodiment of the application uses an example where the blockchain network 102 includes one blockchain (which may be a public chain, a private chain, or a consortium chain), and all blockchain nodes 103 in the blockchain network 102 join the channel corresponding to that blockchain.

[0085] For example, any client 101 can send a transaction to any blockchain node 103. After receiving the transaction, each blockchain node 103 can write the transaction into the blockchain's transaction pool. Each blockchain node 103 in the blockchain network can select transactions from the blockchain's transaction pool to package into blocks. In addition, each blockchain node 103 is equipped with a transaction executor (such as a smart contract virtual machine), which can execute the selected transactions.

[0086] In one implementation, when the transaction selected by blockchain node 103 is a smart contract deployment transaction, the deployment transaction is used to request the deployment of the smart contract on the blockchain. The deployment transaction contains the contract code of the smart contract. Blockchain node 103 can send the smart contract deployment transaction to its installed transaction executor (such as a smart contract virtual machine) for processing. The transaction executor (such as a smart contract virtual machine) can respond to the deployment transaction by matching the contract code based on a preset code fragment library on the blockchain to obtain a matching result. The matching result is used to indicate a first code fragment similar to the contract code in the preset code fragment library and to indicate a first code interval similar to the first code fragment in the contract code. Based on the first code interval, a second code fragment is determined in the contract code. The second code fragment refers to the remaining code interval in the contract code excluding the first code interval. The second code fragment is stored in the preset code fragment library, and based on the first and second code fragments in the preset code fragment library, fragment combination information of the contract code is generated.

[0087] In one implementation, when the transaction selected by the blockchain node 103 is a smart contract invocation transaction, the invocation transaction contains the contract address of the smart contract. The blockchain node 103 can send the smart contract invocation transaction to its installed transaction executor (such as a smart contract virtual machine) for processing. The transaction executor (such as a smart contract virtual machine) can respond to the invocation transaction, obtain the fragment combination information of the smart contract's contract code according to the contract address of the smart contract, obtain the first code interval and the second code fragment according to the instructions of the fragment combination information, and concatenate the first code interval and the second code fragment to form contract code. The contract code is then run to execute the smart contract invocation transaction.

[0088] Blockchain node 103 can package the selected transaction and its execution result into a current block, and then use a consensus mechanism to reach a consensus within the blockchain network. Once consensus is reached, the current block is written into the blockchain. The consensus mechanism refers to the rules and algorithms that blockchain nodes agree upon. Its main purpose is to ensure the consistency and trustworthiness of data within the blockchain network, ensuring that all blockchain nodes agree on the transactions and state changes on the blockchain. Consensus mechanisms include, but are not limited to, Proof of Work (PoW), Proof of Stake (PoS), and Proof of Authority (PoA).

[0089] Therefore, in the smart contract processing system provided in this application, upon receiving a deployment request for a smart contract, the contract code of the smart contract can be divided into a first code segment and a second code fragment. The second code fragment is then stored in a pre-set code fragment library on the blockchain. The first code segment is a code segment in the contract code similar to the first code fragment, and the first code fragment is a code fragment in the pre-set code fragment library similar to the contract code. The second code fragment refers to the remaining code segments in the contract code excluding the first code segment. In other words, the first code fragment contains the same code content as the first code segment. Therefore, based solely on the first and second code fragments in the pre-set code fragment library, fragment combination information of the contract code can be generated. When executing a smart contract call transaction, the contract code can be assembled using the fragment combination information to execute the smart contract call transaction. In this way, blockchain nodes can ensure that similar code is stored only once through the pre-set code fragment library, reducing the waste of storage space on blockchain nodes. Simultaneously, by reducing the amount of data stored by blockchain nodes, the consumption of computing resources and bandwidth on blockchain nodes can be reduced, thereby lowering the storage cost and transaction fees for smart contract deployment.

[0090] Understandable, Figure 5 The smart contract processing system shown in the embodiments is intended to more clearly illustrate the technical solutions of the embodiments of this application, and does not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of system architecture and the emergence of new business scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.

[0091] The following describes specific embodiments of the contract deployment scheme based on similar code redundancy removal storage provided in this application. See also Figure 6 This is a flowchart illustrating a smart contract deployment method provided in an embodiment of this application. This smart contract deployment method can be executed by a blockchain node, such as... Figure 5 The smart contract is executed by any blockchain node 103. The deployment method of this smart contract mainly includes, but is not limited to, the following steps S11 to S14:

[0092] S11. Obtain a deployment transaction for the smart contract. The deployment transaction is used to request the deployment of the smart contract on the blockchain. The deployment transaction contains the contract code of the smart contract.

[0093] A smart contract deployment transaction is used to request the deployment of a smart contract on a blockchain. Once deployed, the smart contract can be used by accounts within the blockchain network. This application does not limit the type of smart contract; for example, a smart contract can be an asset exchange contract, an oracle contract, an insurance contract, a voting contract, etc.

[0094] In one embodiment, blockchain nodes store received transactions in the blockchain's transaction pool for storage and processing. Blockchain nodes can retrieve deployment transactions for smart contracts from the blockchain's transaction pool. For example, a blockchain node can select a transaction from the blockchain's transaction pool. If the "to" field of the selected transaction is an empty address: `Tx.To == Address(0)`, where `==` indicates equality, `Tx.To` represents the "to" field in the transaction, and `Address(0)` represents address 0, then the selected transaction can be identified as a deployment transaction for the smart contract.

[0095] The contract code of a smart contract refers to the bytecode formed by compiling the source code of the smart contract. It can be deployed and run on a blockchain network to execute specific functions or rules. In one implementation, the contract code of the smart contract can be obtained from the data field in the deployment transaction: ContractCode = Tx.Data, where Tx.Data represents the data field in the transaction.

[0096] S12. In response to the deployment transaction, the contract code is matched based on the pre-set code snippet library on the blockchain to obtain the matching result. The matching result is used to indicate the first code snippet in the pre-set code snippet library that is similar to the contract code, and to indicate the first code interval in the contract code that is similar to the first code snippet.

[0097] The pre-defined code snippet library on the blockchain is a collection of code snippets used to store and manage smart contracts. The pre-defined code snippet library includes at least one code snippet, which may be a code snippet stored in the pre-defined code snippet library when other smart contracts are deployed, or it may be code snippets of some commonly used functions and algorithms.

[0098] In one implementation, the pre-defined code snippet library is deployed in one of the following ways: the pre-defined code snippet library is deployed on the blockchain in the form of a smart contract; or the pre-defined code snippet library is deployed on the blockchain in the form of a decentralized application (DApplication). The DApplication includes the following components: 1) Blockchain technology: The DApplication is built on blockchain technology to ensure data security and transparency; 2) Smart contracts: These enable the DApplication to automatically execute corresponding operations when preset conditions are met; 3) Distributed storage: Data is distributed and stored across multiple blockchain nodes, improving data reliability and security and reducing reliance on centralized servers; 4) User interface: DApplications typically have a user-friendly interface, allowing users to easily access and operate the application. Similar to traditional centralized applications, users can conduct transactions, interact, and manage through the interface. When deploying the pre-defined code snippet library on the blockchain as a DApplication, the core lies in the implementation of smart contracts. For example, the functionality and logic of the code snippet library can be defined, such as defining the data structure, read and write operations, and access control rules of the code snippet library. A smart contract for deploying the code snippet library can then be written and deployed on the blockchain to pre-define the code snippet library on the blockchain.

[0099] In one embodiment, in response to a deployed transaction, transaction verification can be performed. Transaction verification is a crucial step in ensuring the authenticity and validity of the transaction. Transaction verification typically includes steps such as checking transaction validity, ensuring the legitimacy of participant identities, and verifying transaction signatures. After successful transaction verification, the contract code can be matched against a pre-defined code snippet library on the blockchain to obtain a matching result. The matching process identifies the first code snippet in the pre-defined code snippet library that is similar to the contract code. For example, the first code snippet can be the code snippet with the highest similarity to the contract code in the pre-defined code snippet library. The matching result can be used to indicate the first code snippet in the pre-defined code snippet library that is similar to the contract code, and to indicate the first code interval in the contract code that is similar to the first code snippet. For example, the code content contained in the first code interval can be the longest common string between the first code snippet and the contract code.

[0100] In one feasible implementation, in response to a deployment transaction, the contract code is matched against a pre-defined code snippet library on the blockchain to obtain a matching result. This includes: in response to the deployment transaction, creating a contract address for the smart contract. The contract address is the address of the smart contract, a string used to uniquely identify the smart contract. This application does not limit the method of generating the contract address. The contract code can be extracted from the deployment transaction. The contract code contains an initialization function, which can be run to initialize the smart contract, i.e., set the initial state of the smart contract. After setting the initial state of the smart contract, the world state of the smart contract is also set. The initial state of the smart contract refers to the state of the smart contract when it is deployed on the blockchain. It typically includes the initial values ​​of state variables defined in the contract code, the creator of the contract, and other necessary configuration parameters. The initial state of the smart contract is recorded in the world state of the smart contract. This means that the initial state of the smart contract becomes part of the world state of the smart contract. For example, if the smart contract is a contract for managing electronic resources, its initial state may include the initial quantity of electronic resources held, resource management rules, and other relevant parameters. The world state of the smart contract can contain this information. The world state and contract address can be associated and stored in a state database synchronized with the blockchain. That is, the contract address is used as the key, and the world state as the value to form a key-value pair, which is then stored in the state database. For example, the world state of a smart contract includes the smart contract code, the smart contract account (containing state information), and the smart contract's own information (such as the current value of state variables in the contract code). The contract address and the state information in the contract account can be stored as key-value pairs in the world state tree of the state database. Then, the smart contract's own information is stored in the smart contract's account state tree in the state database, and the StorageRoot field is associated with the smart contract's account state tree. This application does not associate the code hash field with the contract code in the state database; instead, it associates the code hash field with fragment combination information of the contract code. The contract code is then assembled using this fragment combination information. The executable code obtained after running the initialization function can be obtained, and the executable code can be matched against a pre-defined code fragment library on the blockchain to obtain the matching result.The executable code is the remaining code in the contract code after the initialization function runs. It is responsible for implementing the smart contract's functionality and business logic. For example, the executable code's role may include, but is not limited to: defining the smart contract's business logic (e.g., processing transactions, updating state, performing specific operations); handling events (e.g., triggering specific events to notify external systems or other smart contracts); interacting with other smart contracts (e.g., calling functions of other smart contracts or accessing their state); and maintaining the smart contract's state (e.g., updating state variables and managing data). In one feasible implementation, the contract code (ContractCode) can be sent to the smart contract virtual machine, which then calls the Execute function to automatically execute the initialization function portion of the contract code, set the smart contract's world state, and return the executable code (RuntimeCode): RuntimeCode = Execute(ContractCode). Since the initialization function is typically executed only once during smart contract deployment and is useless during smart contract calls, this application replaces the matching processing for the contract code with matching processing for the executable code, which helps reduce the amount of data stored during smart contract deployment.

[0101] In one embodiment, the execution code is matched against a pre-defined code snippet library on the blockchain to obtain matching results. This includes obtaining the similarity between the execution code and each code snippet in at least one code snippet. The similarity between the execution code and the code snippet indicates the length of the longest common string between them. Specifically, this application uses a longest common substring comparison method to obtain the longest common string between the execution code and each code snippet in the pre-defined code snippet library, and determines the length of this longest common string as the similarity between the execution code and each code snippet. The longest common substring comparison method refers to finding the longest common substring between two strings (such as the execution code and a code snippet in the pre-defined code snippet library), which can be implemented using dynamic programming and suffix arrays, etc. For example, if the executable code is 11101001000011111000011, and the first code snippet in the preset code snippet library is 11111001000011111011, then the longest common string between the executable code and code snippet 1 is 10010000111110. The similarity between the executable code and code snippet 1 in the preset code snippet library is 14 (i.e., the length of 10010000111110). A first code snippet can be selected from at least one code snippet based on similarity. The first code snippet is the code snippet with the highest similarity to the executable code among at least one code snippets, and can be added to the matching results. Additionally, the first code interval refers to the positional range of the longest common string between the first code snippet and the executable code within the executable code. The first code interval (e.g., 10010000111110) can be added to the matching results.

[0102] S13. Based on the first code interval, determine the second code segment in the contract code. The second code segment refers to the remaining code interval in the contract code excluding the first code interval.

[0103] In one embodiment, a first code segment can be removed from the executable code to obtain a remaining code segment. Specifically, the first start and end positions of the code content included in the first code segment within the executable code can be obtained. The code segment before the first start position and the code segment after the first end position in the executable code are determined as the remaining code segment. For example, if the executable code is 11101001000011111000011, and the first code segment is 10010000111110, then the remaining code segment contains 1110 and 00011. If the length of the remaining code segment is less than a preset length threshold (len, which can be set as needed, such as 1000), then the remaining code segment is determined as a second code segment. If the length of the remaining code segment is greater than or equal to the preset length threshold, then the remaining code segment is set as the new executable code, and the new executable code is matched against a preset code segment library on the blockchain to obtain a matching result. The execution process of matching new executable code based on a pre-set code snippet library on the blockchain is the same as the execution process of matching executable code based on a pre-set code snippet library on the blockchain, and will not be repeated here. That is, when the length of the remaining code interval is greater than or equal to a preset length threshold, a code snippet similar to the remaining code interval will continue to be searched from the pre-set code snippet library as the first code snippet. The first code snippet can include multiple snippets. This application can obtain a set of second code snippets: RemainCodeSet = [RemainCode1, RemainCode2, ..., RemainCodeN], where RemainCode1, RemainCode2, ..., RemainCodeN represent each second code snippet in the set of second code snippets. Each second code snippet in the set of second code snippets: RemainCodeSet can be stored in the pre-set code snippet library: InsertCode(RemainCode), where InsertCode() represents the insertion function, N is a positive integer, and N represents the number of second code snippets.

[0104] S14. Store the second code fragment in a preset code fragment library, and generate fragment combination information of contract code based on the first and second code fragments in the preset code fragment library. The fragment combination information of contract code is used to execute the smart contract call transaction.

[0105] Each code snippet in the pre-defined code snippet library has its own storage identifier, which can be obtained through hash calculation. In one embodiment, a hash calculation can be performed on the second code snippet to obtain its storage identifier, and the storage identifier of the second code snippet and the second code snippet can be associated and stored in the pre-defined code snippet library. The hash calculation algorithm includes, but is not limited to, MD (Message Digest) series algorithms and SHA (Secure Hash Algorithm) series algorithms.

[0106] In one embodiment, a preset code snippet library includes storage identifiers for a first code snippet and a second code snippet; a first code interval contains the longest common string between the first code snippet and the executable code. Based on the first and second code snippets in the preset code snippet library, fragment combination information of the contract code is generated, including: obtaining the start and end positions of the longest common string between the first code snippet and the executable code within the first code snippet; for example, if the executable code is: 11101001000011111000011, the first code snippet is: 11111001000011111011, and the first code interval is: 10010000111110, then the start position is 5 and the end position is 18. The storage identifier of the first code snippet, as well as the start and end positions, can be used to generate the index information of the first code interval: [codehash1,x,y], where codehash1 represents the storage identifier of the first code snippet, x represents the start position, and y represents the end position. The storage identifier of the second code fragment can be used to generate the index information of the second code fragment: [codehash2,x,y], where codehash2 represents the storage identifier of the second code fragment, x equals 1, and y equals the length of the second code fragment. Based on the order in which the first code segment and the second code fragment are executed, the index information of the first code segment and the index information of the second code fragment can be combined to obtain the fragment combination information of the contract code. For example, if the execution code is: 11101001000011111000011, the first code segment is: 11111001000011111011, then the index information of the first code segment: 10010000111110 is: [jdhadad,5,18], the index information of the second code segment: 1110 is: [dsdewes,1,4], the index information of the second code segment: 00011 is: [dreirur,1,5], and the combined information of the contract code segments is CombinedInfo = [[dsdewes,1,4],[jdhadad,5,18],[dreirur,1,5]].

[0107] In one implementation, the world state includes a code hash field, which is calculated by hashing the executable code. In existing technologies, the code hash field in the world state is associated with the executable code. For example, in the contract code storage unit of the state database, the code hash field is used as the key, and the executable code is used as the value to form a key-value pair, which is then stored in the contract code storage unit of the state database. This application, however, associates the code hash field in the world state with fragment combination information of the contract code in the state database. For example, the code hash field is used as the key, and the fragment combination information of the contract code is used as the value to form a key-value pair, which is then stored in the contract code storage unit of the state database. This allows the value to be changed from State[ADDR].CodeHash = RuntimeCode to State[ADDR].CodeHash = CombinedInfo, where State[ADDR].CodeHash represents the value associated with the Codehash field when it is used as the key. In other words, the fragment combination information CombinedInfo of the contract code can be indexed through the code hash field. Since the pre-built code snippet library on the blockchain can be accessed by accounts in the blockchain network, the executable code in the contract code can be assembled by combining the snippets of the contract code. The smart contract call transaction can be executed by running the executable code in the contract code.

[0108] See Figure 7 The diagram illustrates the transaction deployment logic within a blockchain node. A blockchain node may contain a transaction executor (such as a smart contract virtual machine), a contract code similarity identifier, a pre-defined code fragment library, and stores the world state of smart contracts (e.g., the world state of smart contract B, the world state of smart contract C, etc.). When a user submits a deployment transaction (containing contract code) for a smart contract (such as smart contract A) to the blockchain network, the blockchain node responds by sending the contract code to the transaction executor. The transaction executor runs an initialization function, sets the world state of smart contract A, and obtains the executable code obtained after running the initialization function. The transaction executor sends the executable code to the contract code similarity identifier. The contract code similarity identifier uses the pre-defined code fragment library on the blockchain to match the contract code, obtaining fragment combination information of smart contract A based on the matching result, and storing the second code fragment in the pre-defined code fragment library. The contract code similarity identifier returns the fragment combination information of smart contract A to the transaction executor, which stores the fragment combination information of smart contract A in the world state of smart contract A and associates it with the code hash field in the world state of smart contract A.

[0109] The contract deployment technology based on redundant storage of similar code proposed in this application can compare the similarity between code fragments of smart contracts, so that similar code is stored only once in a preset code fragment library. The world state of each smart contract stores the fragment combination information of the contract code, so that blockchain nodes do not need to redundantly store similar code, but only need to store the unique code fragments of smart contracts to the code fragment library. This greatly reduces the storage cost of smart contract deployment and reduces the transaction fees of smart contract deployment.

[0110] The following describes specific embodiments of the contract invocation scheme based on similar code redundancy removal storage provided in this application. See also Figure 8 This is a flowchart illustrating a smart contract invocation method provided in an embodiment of this application. This smart contract invocation method can be executed by a blockchain node, such as... Figure 5 The smart contract is executed by any blockchain node 103. The invocation method of this smart contract mainly includes, but is not limited to, the following steps S21–S24:

[0111] S21. Obtain the call transaction for the smart contract. The call transaction is used to request the call of the smart contract deployed on the blockchain. The call transaction contains the contract address of the smart contract.

[0112] A smart contract invocation transaction is a transaction used to request the invocation of a smart contract on the blockchain. In one embodiment, a blockchain node stores received transactions in a blockchain transaction pool for storage and processing. A blockchain node can retrieve smart contract invocation transactions from the blockchain transaction pool. For example, a blockchain node can select a transaction from the blockchain transaction pool; if the `to` field of the selected transaction is not an empty address (e.g., `Tx.To!= address(0)`, where `!=` indicates inequality), then the selected transaction can be identified as a smart contract invocation transaction.

[0113] S22. In response to the call transaction, obtain the fragment combination information of the smart contract's code based on the smart contract's contract address. The fragment combination information is used to indicate the first code segment and the second code segment that make up the contract code.

[0114] In one embodiment, a state database synchronized with the blockchain stores a code hash field, which is associated with fragment combination information of the smart contract's contract code. Retrieving the fragment combination information of the smart contract's contract code based on the smart contract's contract address in response to a call transaction includes: verifying the call transaction in response to the call transaction; after successful verification, extracting the smart contract's contract address from the call transaction; and retrieving the code hash field from the state database based on the smart contract's contract address. For example, the state database can use the smart contract's contract address as the key and store the smart contract's state information (including the code hash field) as the value, thus allowing indexing of the code hash field from the state database based on the smart contract's contract address. Setting information associated with the code hash field can be retrieved; this setting information represents the fragment combination information of the smart contract's contract code. For example, the state database can use the code hash field as the key and store the fragment combination information of the smart contract's contract code as the value, allowing indexing of the setting information associated with the code hash field from the state database.

[0115] S23. According to the instructions of the fragment combination information, obtain the first code interval and the second code fragment, and splice the first code interval and the second code fragment to form the contract code.

[0116] In one implementation, following the instructions of the fragment combination information, a first code interval and a second code fragment are obtained, and the first code interval and the second code fragment are concatenated to form contract code. This includes: obtaining the index information of the first code interval and the index information of the second code fragment from the fragment combination information; the index information of the first code interval includes the storage identifier, start position, and end position of the first code fragment, and the index information of the second code fragment includes the storage identifier of the second code fragment. Since the storage identifier of the first code fragment is associated with the first code fragment in a preset code fragment library, the first code fragment can be determined from the preset code fragment library on the blockchain using the storage identifier of the first code fragment, and the position interval formed by the start position to the end position in the first code fragment can be determined as the first code interval. In addition, the second code fragment can be obtained from the preset code fragment library using the storage identifier of the second code fragment; in one implementation, it can be verified whether the length of the second code fragment is equal to y in the index information of the second code fragment. If so, it indicates that the obtained second code fragment is accurate. Based on the order of the first code segment and the second code fragment in the executable code, the first code segment and the second code fragment are concatenated to form the executable code. The executable code is obtained after the contract code runs its initialization function. The index information of the first code segment and the second code fragment are arranged in the fragment combination information of the contract code according to their order in the executable code. Therefore, the first code segment and the second code fragment can be concatenated based on their order in the fragment combination information of the contract code to obtain the executable code.

[0117] S24. Run the contract code to execute the call transaction.

[0118] In one implementation, running contract code to execute a call transaction includes: setting the contract code field in the smart contract's context information as the execution code; and executing the call transaction based on the set context information. A blockchain node may include a transaction executor. The blockchain node can call the transaction executor to execute the call transaction. Before the transaction executor executes the call transaction, the blockchain node can set the smart contract's context information within the transaction executor. The set context information is used to configure and provide the transaction executor with necessary environmental information, state data, and execution parameters. The environmental information includes, but is not limited to, the state of the blockchain network and the current block height. This environmental information helps the transaction executor determine the correct context for its operation, ensuring that the transaction is executed in the correct network environment and at the correct time. For example, the current block height can be used to verify the validity of the transaction's timestamp or to determine the validity period of certain state variables. State data refers to the data that the transaction executor needs to access and modify during transaction execution. This includes, but is not limited to, the `balance` field, the `nonce` field, and the current values ​​of the smart contract's state variables. Context settings ensure that the transaction executor accesses the correct state data and updates it correctly after transaction execution. For example, if the smart contract needs to update the remaining resources in the sender's account, the state data will provide the remaining resources. Execution parameters include, but are not limited to, contract code fields (such as the `vm.Context` field), the name of the function calling the smart contract, and parameter values. The contract code field in the smart contract's context information can be set as the execution code, allowing the transaction executor to correctly call the specific function in the execution code according to the transaction requirements and pass the correct parameter values. This enables the execution of the transaction based on the configured context information.

[0119] See Figure 9 The diagram illustrates the transaction invocation logic within a blockchain node. A blockchain node may contain a transaction executor (such as a smart contract virtual machine), a pre-defined code snippet library, and store the world state of the smart contract. When a user submits a call transaction (including the contract address) for a smart contract (such as smart contract A) to the blockchain network, the blockchain node responds to the call transaction. Based on the smart contract's contract address, it retrieves the fragment combination information of smart contract A from the world state of smart contract A. Based on the fragment combination information of smart contract A, it reads the first and second code snippets from the pre-defined code snippet library, reads the first code interval from the first code snippet, concatenates the first code interval and the second code snippet into executable code, and provides the executable code to the transaction executor's context information to execute the call transaction. After the call transaction is executed, the state data in the world state of smart contract A is updated and stored.

[0120] This application proposes a contract invocation technology based on redundant storage of similar code. When a call request for a smart contract is received, the required code fragments can be read from a preset code fragment library through the code fragment combination information stored in the world state of the smart contract, and the complete execution code can be quickly assembled for use by the context execution of the transaction executor, maintaining the same availability as traditional blockchain smart contracts. In other words, the contract invocation technology proposed in this solution has high availability.

[0121] The methods of the embodiments of this application have been described in detail above. In order to facilitate better implementation of the above solutions of the embodiments of this application, the apparatus of the embodiments of this application is provided below.

[0122] Figure 10 This is a schematic diagram of a smart contract deployment device provided in an embodiment of this application; the smart contract deployment device can be used to execute the aforementioned... Figure 6 Some or all of the steps in the corresponding method embodiments. Please refer to [link / reference]. Figure 10 The deployment device for the smart contract includes the following units: an acquisition unit 201 and a processing unit 202.

[0123] The acquisition unit 201 is used to acquire a deployment transaction for a smart contract. The deployment transaction is used to request the deployment of a smart contract on the blockchain and contains the contract code of the smart contract.

[0124] The processing unit 202 is used to respond to the deployment transaction by matching the contract code based on a pre-set code snippet library on the blockchain to obtain a matching result. The matching result is used to indicate the first code snippet in the pre-set code snippet library that is similar to the contract code, and to indicate the first code interval in the contract code that is similar to the first code snippet.

[0125] The processing unit 202 is further configured to determine a second code segment in the contract code based on the first code segment, wherein the second code segment refers to the remaining code segment in the contract code excluding the first code segment;

[0126] The processing unit 202 is further configured to store the second code fragment into a preset code fragment library, and generate fragment combination information of contract code based on the first code fragment and the second code fragment in the preset code fragment library. The fragment combination information of contract code is used to execute the smart contract call transaction.

[0127] In one embodiment, in response to deploying a transaction, processing unit 202 performs matching processing on the contract code based on a pre-set code snippet library on the blockchain to obtain a matching result, including:

[0128] In response to the deployment transaction, a contract address is created for the smart contract;

[0129] Extract the contract code from the deployment transaction; the contract code contains initialization functions.

[0130] Run the initialization function to set the world state of the smart contract and store the world state and contract address in a state database synchronized with the blockchain.

[0131] The system retrieves the execution code obtained after the contract code runs its initialization function, and performs matching processing on the execution code based on a pre-set code snippet library on the blockchain to obtain the matching result.

[0132] In one embodiment, a preset code snippet library contains at least one code snippet; the processing unit 202 performs matching processing on the executable code based on the preset code snippet library on the blockchain to obtain a matching result, including:

[0133] Obtain the similarity between the executed code and each code segment in at least one code snippet;

[0134] A first code segment is selected from at least one code segment based on similarity. The first code segment is the code segment with the highest similarity to the executable code among at least one code segments.

[0135] Add the first code snippet to the matching results;

[0136] The similarity between the executable code and the code snippet is used to indicate the length of the longest common string between the executable code and the code snippet.

[0137] In one embodiment, the first code interval refers to the interval in the execution code where the longest common string between the first code segment and the execution code is located;

[0138] Processing unit 202 determines a second code segment in the contract code based on the first code interval, including:

[0139] Remove the first code segment from the executed code to obtain the remaining code segment;

[0140] If the length of the remaining code segment is less than the preset length threshold, then the remaining code segment is determined as the second code segment.

[0141] In one embodiment, the processing unit 202 is further configured to: if the length of the remaining code interval is greater than or equal to a preset length threshold, set the remaining code interval as new executable code, and perform matching processing on the new executable code based on a preset code fragment library on the blockchain to obtain a matching result.

[0142] In one embodiment, the preset code snippet library includes the storage identifier of the first code snippet and the storage identifier of the second code snippet; the first code interval contains the longest common string between the first code snippet and the executable code;

[0143] Processing unit 202 generates contract code fragment combination information based on a first code fragment and a second code fragment in a preset code fragment library, including:

[0144] Get the longest common string between the first code snippet and the executed code, and its start and end positions in the first code snippet;

[0145] The index information of the first code segment is generated using the storage identifier of the first code segment, as well as its start and end positions;

[0146] The index information of the second code segment is generated using the storage identifier of the second code segment;

[0147] Based on the order of the first code segment and the second code segment in the executed code, the index information of the first code segment and the index information of the second code segment are combined to obtain the fragment combination information of the contract code.

[0148] In one embodiment, the world state includes a code hash field, and the processing unit 202 is further configured to:

[0149] The state database associates and stores the code hash field in the world state with fragments of the contract code.

[0150] In one embodiment, the deployment method of the preset code snippet library includes any of the following: the preset code snippet library is deployed on the blockchain in the form of a smart contract; the preset code snippet library is deployed on the blockchain in the form of a decentralized application.

[0151] According to one embodiment of this application, Figure 10The smart contract deployment device shown can be composed of individual or combined units into one or more other units, or some of the units can be further divided into multiple functionally smaller units. This achieves the same operation without affecting the technical effect of the embodiments of this application. The above units are based on logical function division. In practical applications, the function of one unit can be implemented by multiple units, or the function of multiple units can be implemented by one unit. In other embodiments of this application, the smart contract deployment device may also include other units. In practical applications, these functions can also be implemented with the assistance of other units, and can be implemented by multiple units working together. According to another embodiment of this application, the aforementioned functions can be executed by running on a general-purpose computing device, such as a computer, which includes processing elements and storage elements such as a central processing unit (CPU), random access memory (RAM), and read-only memory (ROM). Figure 6 The computer program (including program code) for each step involved in the corresponding method embodiment is used to construct, as follows: Figure 10 The diagram illustrates a smart contract deployment apparatus and a method for deploying smart contracts to implement embodiments of this application. Computer programs can be recorded on, for example, a computer-readable recording medium, loaded onto the aforementioned computing device via the same medium, and run therein.

[0152] Figure 11 This is a schematic diagram of a smart contract invocation device provided in an embodiment of this application; the smart contract invocation device can be used to execute the aforementioned... Figure 8 Some or all of the steps in the corresponding method embodiments. Please refer to [link / reference]. Figure 11 The smart contract invocation device includes the following units: acquisition unit 301 and processing unit 302.

[0153] The acquisition unit 301 is used to acquire a call transaction for a smart contract. The call transaction is used to request to call a smart contract deployed on the blockchain. The call transaction contains the contract address of the smart contract.

[0154] The processing unit 302 is used to respond to the call transaction by obtaining the fragment combination information of the smart contract code according to the contract address of the smart contract. The fragment combination information is used to indicate the first code segment and the second code segment that make up the contract code.

[0155] The processing unit 302 is also configured to obtain the first code segment and the second code segment according to the instruction of the segment combination information, and to perform splicing processing on the first code segment and the second code segment to form contract code;

[0156] Processing unit 302 is also used to run contract code to execute the call transaction.

[0157] In one embodiment, a code hash field is stored in a state database synchronized with the blockchain. This code hash field is configured to be associated with fragment combination information of the smart contract's contract code. In response to a call transaction, processing unit 302 obtains the fragment combination information of the smart contract's contract code based on the smart contract's contract address, including:

[0158] In response to the call transaction, extract the smart contract's contract address from the call transaction;

[0159] Retrieve the code hash field from the state database based on the smart contract's contract address;

[0160] Retrieves the settings information associated with the code hash field, which represents a combination of fragments of the smart contract's contract code.

[0161] In one embodiment, the processing unit 302, according to the instructions of the fragment combination information, obtains a first code segment and a second code segment, and performs concatenation processing on the first code segment and the second code segment to form contract code, including:

[0162] Obtain the index information of the first code segment and the index information of the second code segment from the segment combination information; the index information of the first code segment includes the storage identifier, start position, and end position of the first code segment, and the index information of the second code segment includes the storage identifier of the second code segment;

[0163] Using the storage identifier of the first code segment, the first code segment is determined from the pre-set code segment library on the blockchain, and the position interval formed by the start position to the end position in the first code segment is determined as the first code interval;

[0164] Using the storage identifier of the second code fragment, retrieve the second code fragment from the preset code fragment library;

[0165] Based on the order of the first code segment and the second code segment in the execution code, the first code segment and the second code segment are concatenated to form the execution code, which is obtained by the contract code after running the initialization function in the contract code.

[0166] In one embodiment, processing unit 302 runs contract code to execute a call transaction, including:

[0167] Set the contract code field in the context information of the smart contract to the executable code;

[0168] The call transaction is executed based on the context information set.

[0169] According to one embodiment of this application, Figure 11The various units in the smart contract invocation device shown can be individually or entirely merged into one or more other units, or some of the units can be further divided into multiple functionally smaller units. This achieves the same operation without affecting the technical effect of the embodiments of this application. The above units are based on logical function division. In practical applications, the function of one unit can also be implemented by multiple units, or the function of multiple units can be implemented by one unit. In other embodiments of this application, the smart contract invocation device may also include other units. In practical applications, these functions can also be implemented with the assistance of other units, and can be implemented by multiple units working together. According to another embodiment of this application, the aforementioned functions can be executed by running on a general-purpose computing device, such as a computer, which includes processing elements and storage elements such as a central processing unit (CPU), random access memory (RAM), and read-only memory (ROM). Figure 8 The computer program (including program code) for each step involved in the corresponding method embodiment is used to construct, as follows: Figure 11 The diagram illustrates a smart contract invocation device and a smart contract invocation method for implementing embodiments of this application. A computer program may be recorded on, for example, a computer-readable recording medium, loaded onto the aforementioned computing device via the same medium, and executed therein.

[0170] In this embodiment, when a deployment request for a smart contract is received, the contract code of the smart contract can be divided into a first code segment and a second code fragment, and the second code fragment can be stored in a preset code fragment library on the blockchain. The first code segment is a first code segment in the contract code that is similar to the first code fragment, the first code fragment is a code fragment in the preset code fragment library that is similar to the contract code, and the second code fragment refers to the remaining code segment in the contract code excluding the first code segment. That is, the first code fragment contains the same code content as the first code segment. Therefore, the fragment combination information of the contract code can be generated based only on the first code fragment and the second code fragment in the preset code fragment library. When a smart contract call transaction is to be executed, the contract code can be assembled through the fragment combination information of the contract code to execute the smart contract call transaction. In existing technologies, blockchain nodes directly store the contract code of smart contracts. Since many smart contracts have similar contract codes, this results in blockchain nodes redundantly storing a large amount of similar code. However, in this embodiment, blockchain nodes can ensure that similar code is stored only once through a pre-set code snippet library, thus reducing the waste of storage space on the blockchain nodes. At the same time, by reducing the amount of data stored by the blockchain nodes, the consumption of computing resources and bandwidth on the blockchain nodes can be reduced, thereby reducing the storage costs and transaction fees for smart contract deployment.

[0171] Figure 12 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. Please refer to [link / reference]. Figure 12 The computer device includes a processor 401, a communication interface 402, and a computer-readable storage medium 403. The processor 401, communication interface 402, and computer-readable storage medium 403 can be connected via a bus or other means. The communication interface 402 is used to receive and send data. The computer-readable storage medium 403 can be stored in the computer device's memory and is used to store computer programs, including program instructions. The processor 401 is used to execute the program instructions stored in the computer-readable storage medium 403. The processor 401 (or CPU (Central Processing Unit)) is the computing and control core of the computer device, suitable for implementing one or more instructions, specifically suitable for loading and executing one or more instructions to achieve corresponding method flows or corresponding functions.

[0172] This application embodiment also provides a computer-readable storage medium (Memory), which is a memory device in a computer device used to store programs and data. It is understood that the computer-readable storage medium here can include both the built-in storage medium in the computer device and extended storage media supported by the computer device. The computer-readable storage medium provides storage space that stores the processing system of the computer device. Furthermore, the storage space also stores one or more instructions suitable for loading and execution by the processor 401, which may be one or more computer programs (including program code). It should be noted that the computer-readable storage medium here can be high-speed RAM or non-volatile memory, such as at least one disk storage device; optionally, it can also be at least one computer-readable storage medium located remotely from the aforementioned processor.

[0173] In one embodiment, the computer-readable storage medium stores one or more instructions; the processor 401 loads and executes one or more instructions stored in the computer-readable storage medium to implement the corresponding steps in the above-described smart contract deployment method embodiment; specifically, the processor 401 loads and executes one or more instructions in the computer-readable storage medium for the following steps:

[0174] Obtain a deployment transaction for a smart contract. The deployment transaction is used to request the deployment of the smart contract on the blockchain. The deployment transaction contains the contract code of the smart contract.

[0175] In response to the deployment of transactions, the contract code is matched based on a pre-set code snippet library on the blockchain to obtain a matching result. The matching result is used to indicate the first code snippet in the pre-set code snippet library that is similar to the contract code, and to indicate the first code interval in the contract code that is similar to the first code snippet.

[0176] Based on the first code segment, a second code segment is determined in the contract code. The second code segment refers to the remaining code segment in the contract code excluding the first code segment.

[0177] The second code fragment is stored in a preset code fragment library, and based on the first and second code fragments in the preset code fragment library, fragment combination information of the contract code is generated. The fragment combination information of the contract code is used to execute the smart contract call transaction.

[0178] In one embodiment, in response to deploying a transaction, the processor 401 performs matching processing on the contract code based on a pre-set code snippet library on the blockchain to obtain a matching result, including:

[0179] In response to the deployment transaction, a contract address is created for the smart contract;

[0180] Extract the contract code from the deployment transaction; the contract code contains initialization functions.

[0181] Run the initialization function to set the world state of the smart contract and store the world state and contract address in a state database synchronized with the blockchain.

[0182] The system retrieves the execution code obtained after the contract code runs its initialization function, and performs matching processing on the execution code based on a pre-set code snippet library on the blockchain to obtain the matching result.

[0183] In one embodiment, a preset code snippet library contains at least one code snippet; the processor 401 performs matching processing on the executable code based on the preset code snippet library on the blockchain to obtain matching results, including:

[0184] Obtain the similarity between the executed code and each code segment in at least one code snippet;

[0185] A first code segment is selected from at least one code segment based on similarity. The first code segment is the code segment with the highest similarity to the executable code among at least one code segments.

[0186] Add the first code snippet to the matching results;

[0187] The similarity between the executable code and the code snippet is used to indicate the length of the longest common string between the executable code and the code snippet.

[0188] In one embodiment, the first code interval refers to the interval in the execution code where the longest common string between the first code segment and the execution code is located;

[0189] Processor 401 determines a second code segment in the contract code based on the first code interval, including:

[0190] Remove the first code segment from the executed code to obtain the remaining code segment;

[0191] If the length of the remaining code segment is less than the preset length threshold, then the remaining code segment is determined as the second code segment.

[0192] In one embodiment, the processor 401 is further configured to: if the length of the remaining code interval is greater than or equal to a preset length threshold, set the remaining code interval as new executable code, and perform matching processing on the new executable code based on a preset code fragment library on the blockchain to obtain a matching result.

[0193] In one embodiment, the preset code snippet library includes the storage identifier of the first code snippet and the storage identifier of the second code snippet; the first code interval contains the longest common string between the first code snippet and the executable code;

[0194] Processor 401 generates fragment combination information of contract code based on the first and second code fragments in a preset code fragment library, including:

[0195] Get the longest common string between the first code snippet and the executed code, and its start and end positions in the first code snippet;

[0196] The index information of the first code segment is generated using the storage identifier of the first code segment, as well as its start and end positions;

[0197] The index information of the second code segment is generated using the storage identifier of the second code segment;

[0198] Based on the order of the first code segment and the second code segment in the executed code, the index information of the first code segment and the index information of the second code segment are combined to obtain the fragment combination information of the contract code.

[0199] In one embodiment, the world state includes a code hash field, and processor 401 is also used for:

[0200] The state database associates and stores the code hash field in the world state with fragments of the contract code.

[0201] In one embodiment, the deployment method of the preset code snippet library includes any of the following: the preset code snippet library is deployed on the blockchain in the form of a smart contract; the preset code snippet library is deployed on the blockchain in the form of a decentralized application.

[0202] In another embodiment, the computer-readable storage medium stores one or more instructions; the processor 401 loads and executes one or more instructions stored in the computer-readable storage medium to implement the corresponding steps in the above-described smart contract invocation method embodiment; specifically, the processor 401 loads and executes the following steps of one or more instructions in the computer-readable storage medium:

[0203] The contract is the address of the smart contract that is invoked in the transaction.

[0204] In response to the transaction call, the fragment combination information of the smart contract's code is obtained based on the smart contract's contract address. The fragment combination information is used to indicate the first code segment and the second code segment that make up the contract code.

[0205] According to the instructions of the fragment combination information, the first code interval and the second code fragment are obtained, and the first code interval and the second code fragment are spliced ​​together to form the contract code;

[0206] Run the contract code to execute the call transaction.

[0207] In one embodiment, a code hash field is stored in a state database synchronized with the blockchain. This code hash field is configured to be associated with fragment combination information of the smart contract's contract code. In response to a transaction call, processor 401 retrieves the fragment combination information of the smart contract's contract code based on the smart contract's contract address, including:

[0208] In response to the call transaction, extract the smart contract's contract address from the call transaction;

[0209] Retrieve the code hash field from the state database based on the smart contract's contract address;

[0210] Retrieves the settings information associated with the code hash field, which represents a combination of fragments of the smart contract's contract code.

[0211] In one embodiment, the processor 401, according to the instructions of the fragment combination information, obtains a first code segment and a second code segment, and concatenates the first code segment and the second code segment to form contract code, including:

[0212] Obtain the index information of the first code segment and the index information of the second code segment from the segment combination information; the index information of the first code segment includes the storage identifier, start position, and end position of the first code segment, and the index information of the second code segment includes the storage identifier of the second code segment;

[0213] Using the storage identifier of the first code segment, the first code segment is determined from the pre-set code segment library on the blockchain, and the position interval formed by the start position to the end position in the first code segment is determined as the first code interval;

[0214] Using the storage identifier of the second code fragment, retrieve the second code fragment from the preset code fragment library;

[0215] Based on the order of the first code segment and the second code segment in the execution code, the first code segment and the second code segment are concatenated to form the execution code, which is obtained by the contract code after running the initialization function in the contract code.

[0216] In one embodiment, processor 401 runs contract code to execute a call transaction, including:

[0217] Set the contract code field in the context information of the smart contract to the executable code;

[0218] The call transaction is executed based on the context information set.

[0219] Based on the same inventive concept, the principle and beneficial effects of the computer device provided in the embodiments of this application in solving the problem are similar to the principle and beneficial effects of the smart contract deployment method and smart contract invocation method in the embodiments of this application in solving the problem. Please refer to the principle and beneficial effects of the implementation of the method. For the sake of brevity, they will not be repeated here.

[0220] In the embodiments of this application, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.

[0221] This application also 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, causing the computer device to perform the aforementioned smart contract deployment method or smart contract invocation method.

[0222] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A method for deploying a smart contract, characterized in that, The method includes: Obtain a deployment transaction for a smart contract, the deployment transaction being used to request the deployment of the smart contract on the blockchain, the deployment transaction containing the contract code of the smart contract; In response to the deployment transaction, the contract code is matched based on a pre-set code snippet library on the blockchain to obtain a matching result. The matching result is used to indicate a first code snippet in the pre-set code snippet library that is similar to the contract code, and to indicate a first code interval in the contract code that is similar to the first code snippet. Based on the first code interval, a second code segment is determined in the contract code, wherein the second code segment refers to the remaining code interval in the contract code excluding the first code interval; The second code fragment is stored in the preset code fragment library, and based on the first code fragment and the second code fragment in the preset code fragment library, fragment combination information of the contract code is generated. The fragment combination information of the contract code is used to execute the call transaction of the smart contract.

2. The method as described in claim 1, characterized in that, In response to the deployment transaction, the contract code is matched based on a pre-defined code snippet library on the blockchain to obtain a matching result, including: In response to the deployment transaction, a contract address is created for the smart contract; The contract code, which contains an initialization function, is extracted from the deployment transaction. Run the initialization function to set the world state of the smart contract, and store the world state and the contract address in a state database synchronized with the blockchain. The execution code obtained after the initialization function is run is obtained from the contract code, and the execution code is matched based on the pre-set code snippet library on the blockchain to obtain the matching result.

3. The method as described in claim 2, characterized in that, The preset code snippet library contains at least one code snippet; The matching process for the executable code based on a pre-set code snippet library on the blockchain, to obtain the matching result, includes: Obtain the similarity between the executable code and each code segment in the at least one code segment; A first code segment is selected from the at least one code segment based on similarity, wherein the first code segment is the code segment with the highest similarity to the executable code among the at least one code segments; Add the first code snippet to the matching result; The similarity between the executable code and the code fragment is used to indicate the length of the longest identical string between the executable code and the code fragment.

4. The method as described in claim 3, characterized in that, The first code interval refers to the range of positions in the executable code where the longest common string between the first code segment and the executable code is located. The step of determining the second code segment in the contract code based on the first code interval includes: The first code segment is removed from the executed code to obtain the remaining code segment; If the length of the remaining code interval is less than a preset length threshold, then the remaining code interval is determined as the second code segment.

5. The method as described in claim 4, characterized in that, The method further includes: If the length of the remaining code interval is greater than or equal to the preset length threshold, the remaining code interval is set as the new executable code, and the new executable code is matched based on the preset code fragment library on the blockchain to obtain the matching result.

6. The method as described in claim 2, characterized in that, The preset code snippet library includes the storage identifier of the first code snippet and the storage identifier of the second code snippet; the first code interval contains the longest common string between the first code snippet and the executable code; The step of generating the contract code fragment combination information based on the first code fragment and the second code fragment in the preset code fragment library includes: Obtain the longest common string between the first code segment and the executed code, and its start and end positions within the first code segment; The index information of the first code segment is generated using the storage identifier of the first code segment, as well as the start position and the end position; The index information of the second code segment is generated using the storage identifier of the second code segment; Based on the order of the first code segment and the second code fragment in the executed code, the index information of the first code segment and the index information of the second code fragment are combined to obtain the fragment combination information of the contract code.

7. The method as described in claim 2, characterized in that, The world state includes a code hash field, and the method further includes: The state database associates and stores the code hash field in the world state with the fragment combination information of the contract code.

8. The method according to any one of claims 1-7, characterized in that, The deployment method of the preset code snippet library includes any of the following: the preset code snippet library is deployed on the blockchain in the form of a smart contract; the preset code snippet library is deployed on the blockchain in the form of a decentralized application.

9. A method for invoking a smart contract, characterized in that, The method includes: Obtain a call transaction for a smart contract, the call transaction being used to request a call to a smart contract deployed on the blockchain, the call transaction containing the contract address of the smart contract; In response to the call transaction, the fragment combination information of the smart contract's code is obtained based on the smart contract's contract address. The fragment combination information is used to indicate the first code segment and the second code segment that make up the contract code. According to the instructions of the fragment combination information, the first code segment and the second code segment are obtained, and the first code segment and the second code segment are spliced ​​together to form the contract code; Run the contract code to execute the call transaction.

10. The method as described in claim 9, characterized in that, The state database synchronized with the blockchain stores a code hash field, which is set to be associated with fragment combination information of the smart contract's contract code; In response to the call transaction, the method of obtaining fragment combination information of the smart contract's code based on the smart contract's contract address includes: In response to the invocation transaction, the contract address of the smart contract is extracted from the invocation transaction; The code hash field is obtained from the state database based on the contract address of the smart contract; Obtain the setting information associated with the code hash field, the setting information being used to represent the combination information of contract code fragments of the smart contract.

11. The method as described in claim 9 or 10, characterized in that, The step of obtaining the first code segment and the second code segment according to the instructions of the segment combination information, and concatenating the first code segment and the second code segment to form the contract code includes: The index information of the first code segment and the index information of the second code segment are obtained from the segment combination information; the index information of the first code segment includes the storage identifier, start position, and end position of the first code segment, and the index information of the second code segment includes the storage identifier of the second code segment; Using the storage identifier of the first code segment, the first code segment is determined from the preset code segment library on the blockchain, and the position interval formed by the start position to the end position in the first code segment is determined as the first code interval; Using the storage identifier of the second code fragment, the second code fragment is retrieved from the preset code fragment library; Based on the order of the first code segment and the second code fragment in the execution code, the first code segment and the second code fragment are concatenated to form the execution code, which is obtained by the contract code after running the initialization function in the contract code.

12. The method as described in claim 11, characterized in that, Running the contract code to execute the call transaction includes: Set the contract code field in the context information of the smart contract to the execution code; The invocation transaction is executed based on the configured context information.

13. A smart contract deployment device, characterized in that, The device includes: An acquisition unit is used to acquire a deployment transaction for a smart contract, the deployment transaction being used to request the deployment of the smart contract on the blockchain, the deployment transaction containing the contract code of the smart contract; The processing unit is configured to, in response to the deployment transaction, perform matching processing on the contract code based on a preset code snippet library on the blockchain to obtain a matching result. The matching result is used to indicate a first code snippet in the preset code snippet library that is similar to the contract code, and to indicate a first code interval in the contract code that is similar to the first code snippet. The processing unit is further configured to determine a second code segment in the contract code based on the first code segment, wherein the second code segment refers to the remaining code segment in the contract code excluding the first code segment; The processing unit is further configured to store the second code fragment into the preset code fragment library, and generate fragment combination information of the contract code based on the first code fragment and the second code fragment in the preset code fragment library. The fragment combination information of the contract code is used to execute the call transaction of the smart contract.

14. A device for invoking a smart contract, characterized in that, The device includes: The acquisition unit is used to acquire a call transaction for a smart contract, the call transaction being used to request a call to a smart contract deployed on the blockchain, and the call transaction containing the contract address of the smart contract; The processing unit is configured to, in response to the call transaction, obtain fragment combination information of the smart contract's code based on the smart contract's contract address, wherein the fragment combination information is used to indicate the first code segment and the second code segment that make up the contract code; The processing unit is further configured to obtain the first code segment and the second code segment according to the instruction of the segment combination information, and to perform splicing processing on the first code segment and the second code segment to form the contract code; The processing unit is also used to run the contract code to execute the call transaction.

15. A computer device, characterized in that, include: A processor, adapted to execute computer programs; A computer-readable storage medium storing a computer program, which, when executed by the processor, implements the deployment method of a smart contract as described in any one of claims 1-8 or the invocation method of a smart contract as described in any one of claims 9-12.

16. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program adapted to be loaded by a processor and executed as a method for deploying a smart contract as described in any one of claims 1-8 or a method for invoking a smart contract as described in any one of claims 9-12.

17. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the smart contract deployment method as described in any one of claims 1-8 or the smart contract invocation method as described in any one of claims 9-12.