Smart contract deployment method, transaction method, device and electronic equipment
By establishing a code segment table in the memory of blockchain nodes and building a first contract summary, the problem of smart contract deployment occupying a large amount of storage space is solved, and more efficient storage utilization is achieved.
Patent Information
- Application Number
- CN202111529605.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-14
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2041-12-14
AI Technical Summary
In the prior art, the smart contract deployment method occupies a large storage space of blockchain nodes, resulting in insufficiency of storage.
By establishing a code segment table in the memory of the blockchain node, the tags of the tag column in the code segment table correspond one by one, and then building and storing the first contract summary of the smart contract based on the tags and code segments to achieve Smart contract deployment.
Compared with the existing technology, storing the entire runtime code in the blockchain node, the storage space of the blockchain node is greatly saved and the storage efficiency is improved.
Smart Images

Figure CN114168159B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and in particular to a smart contract deployment method, transaction method, device and electronic device. Background Art
[0002] With the development of computer technology, more and more technologies are applied in the financial field. The traditional financial industry is gradually transforming to Fintech, and blockchain technology is no exception. However, due to the security and real-time requirements of the financial industry, higher requirements are also placed on technology.
[0003] Blockchain technology is a new application model of computer technologies such as distributed ledger technology, consensus algorithm, encryption algorithm, etc. The characteristics of blockchain technology are decentralization, openness, transparency, and immutability. For modern blockchain, the development of smart contracts can be regarded as a milestone in the development of blockchain technology, providing more powerful logical functions, which can meet the business requirements of various fields and integrate blockchain from the initial single digital currency application to finance, government services, supply chain, games and other fields. In the prior art, during the deployment of smart contracts, each node of the blockchain network saves the runtime code (Runtime code) in the bytecode file of the smart contract in each node of the blockchain network.
[0004] However, the smart contract deployment method in the existing technology occupies a large storage space of the blockchain node. Summary of the invention
[0005] The present application provides a smart contract deployment method, transaction method, device and electronic device to solve the technical problem of occupying a large node space in the smart contract deployment method in the prior art.
[0006] In a first aspect, the present application provides a smart contract deployment method, comprising:
[0007] A smart contract deployment request is received, the smart contract deployment request includes a bytecode file of the smart contract, and the bytecode file includes a runtime code; according to the runtime code, a code segment table is established in the blockchain node memory, the code segment table includes a label column and a code column, and the label of the label column corresponds to the code segment of the code column one by one; according to the label and the code segment, a first contract summary of the smart contract is constructed; the first contract summary is stored in the blockchain node to realize the smart contract deployment.
[0008] In an embodiment of the present application, after receiving the smart contract deployment request sent by the client, the blockchain node establishes a code segment table in the blockchain node memory according to the runtime code of the smart contract. The labels in the label column and the code segments in the code column in the code segment table correspond one to one. Then, based on the labels and the code segments, the first contract summary of the smart contract is constructed and stored to realize the smart contract deployment. Compared with the prior art, the entire runtime code is stored in the blockchain node, which greatly saves the storage space of the blockchain node.
[0009] In a possible implementation, the smart contract deployment method provided in the embodiment of the present application establishes a code segment table in the blockchain node memory according to the runtime code, including:
[0010] Traverse the address of each opcode (OPCODE) in the runtime code, and record the address of each opcode in the label column; determine the offset of each opcode; use the offset to segment the runtime code to determine the code segment of each opcode; record the code segment of each opcode in the code column, wherein the address of the opcode corresponds to the code segment of the opcode one by one.
[0011] In an embodiment of the present application, the establishment of a code segment table is achieved by traversing the runtime code, querying the address and offset of the opcode in the runtime code, segmenting each code segment in the runtime code, and recording the address of each opcode and the code segment of the opcode in a code segment table.
[0012] In a possible implementation, the smart contract deployment method provided in the embodiment of the present application further includes:
[0013] If the operation code is a jump code, the jump address of the jump code is determined and the jump address is recorded in the tag column.
[0014] In a possible implementation, the smart contract deployment method provided in the embodiment of the present application constructs a first contract summary of the smart contract according to the tag and the code segment, including:
[0015] Each tag in the code segment table and the code segment corresponding to the tag are concatenated and hashed to obtain the first hash value of each tag; according to the preset rules, the first hash value of each tag is processed to generate the first contract summary.
[0016] In a possible implementation, the smart contract deployment method provided in the embodiment of the present application processes the first hash value of each tag according to a preset rule to generate a first contract summary, including:
[0017] According to the order of the labels in the label column, the first hash values of adjacent labels are concatenated and hashed in pairs to obtain multiple second hash values; the adjacent second hash values in the multiple second hash values are concatenated and hashed in pairs in turn to obtain a third hash value; if there are multiple third hash values, the multiple third hash values are concatenated and hashed to obtain the first contract summary.
[0018] In a possible implementation, the smart contract deployment method provided in the embodiment of the present application, the bytecode file also includes initialization code, and the method also includes:
[0019] The length information of the initialization code is sent to the client, so that the client reads the runtime code after the length information in the bytecode file, generates a code segment table, and uses the code segment table and preset rules to generate the first contract summary, and records the intermediate hash value in the process of generating the first contract summary.
[0020] In a second aspect, the present application provides a smart contract deployment method, comprising:
[0021] A smart contract deployment request is sent to a blockchain node, wherein the smart contract deployment request includes a bytecode file of the smart contract, wherein the bytecode file includes an initialization code and a runtime code, so that the blockchain node establishes a code segment table in the blockchain node memory according to the runtime code, wherein the code segment table includes a label column and a code column, wherein the label of the label column corresponds to the code segment of the code column one by one, and then, according to the label and the code segment, a first contract summary of the smart contract is constructed and stored, and length information of the initialization code is sent to the client; the length information of the initialization code sent by the blockchain node is received, and the runtime code after the length information is read in the bytecode file to generate a code segment table of the smart contract; a first contract summary is generated using the code segment table and preset rules, and an intermediate hash value in the process of generating the first contract summary is recorded.
[0022] In a third aspect, the present application provides a smart contract transaction method, which uses the smart contract deployment method provided in the second aspect of the present application to deploy the smart contract to the client. The smart contract transaction method provided by the present application includes:
[0023] Determine the target code segment; generate a smart contract transaction request based on the target code segment and the code segment table, the smart contract transaction request including a label of the target code segment, a code segment of the target code segment and a proof of the target code segment; send the smart contract transaction request to the blockchain node.
[0024] In an embodiment of the present application, a smart contract transaction request is generated by a client, and the smart contract transaction request includes a label, a code segment and a proof of the target code segment, which is conducive to the verification and execution of the transaction by the blockchain node.
[0025] In a possible implementation, the smart contract transaction method provided in the embodiment of the present application generates a smart contract transaction request according to the target code segment and the code segment table, including:
[0026] Determine a first label and a first code segment of the target code segment in the code segment table;
[0027] Using the position of the target code segment in the code segment table and a preset rule, a target hash value of the target code segment is determined in the intermediate hash value, and the target hash value is a proof of the target code segment;
[0028] A smart contract transaction request is generated using the first tag, the first code segment, and the proof of the target code segment.
[0029] In a fourth aspect, an embodiment of the present application provides a smart contract transaction method, which deploys a smart contract to a blockchain node using the smart contract deployment method provided in the first aspect and the optional manner of the first aspect. The smart contract transaction method provided in the embodiment of the present application includes:
[0030] A smart contract transaction request is received, which includes a label of a target code segment, a code of the target code segment, and a proof of the target code segment; the target code segment is verified according to the label of the target code segment, the code of the target code segment, and the proof of the target code segment; if the target code segment is verified successfully, the smart contract transaction request is executed.
[0031] In a possible implementation, the smart contract transaction method provided in the embodiment of the present application verifies the target code segment according to the label of the target code segment, the code of the target code segment and the proof of the target code segment, including:
[0032] The label of the target code segment and the code of the target code segment are concatenated and hashed to generate a fourth hash value; a second contract summary is constructed using the node relationship between the fourth hash value and the proof of the target code segment; the second contract summary and the first contract summary stored in the node are compared; if the first contract summary is consistent with the second contract summary, the target code segment is successfully verified.
[0033] In the embodiment of the present application, the verification efficiency is improved by using the label, code and proof of the target code segment to calculate the contract summary and then verifying it.
[0034] The following introduces the smart contract deployment device, electronic device, computer-readable storage medium and computer program product provided in the embodiments of the present application. Their contents and effects can refer to the smart contract deployment method provided in the embodiments of the present application and will not be repeated here.
[0035] In a fifth aspect, the present application provides a smart contract deployment device, including:
[0036] The first receiving module is used to receive a smart contract deployment request, where the smart contract deployment request includes a bytecode file of the smart contract, and the bytecode file includes a runtime code.
[0037] The processing module is used to establish a code segment table in the blockchain node memory according to the runtime code. The code segment table includes a label column and a code column. The label of the label column corresponds to the code segment of the code column one by one.
[0038] The processing module is also used to construct a first contract summary of the smart contract according to the tags and the code segments.
[0039] The storage module is used to store the first contract summary in the blockchain node to implement smart contract deployment.
[0040] In a sixth aspect, the present application provides a smart contract deployment device, including:
[0041] The second receiving module is used to receive a smart contract transaction request, which includes a label of the target code segment, a code of the target code segment, and a proof of the target code segment.
[0042] The verification module is used for verifying the target code segment according to the label of the target code segment, the code of the target code segment and the proof of the target code segment.
[0043] The execution module is used to execute the smart contract transaction request if the target code segment is verified.
[0044] In a seventh aspect, an embodiment of the present application provides an electronic device, including:
[0045] A processor, and a memory communicatively connected to the processor;
[0046] Memory stores computer-executable instructions;
[0047] The processor executes the computer-executable instructions stored in the memory to implement the first aspect or the first aspect that can be implemented to provide a smart contract deployment method, and the fourth aspect or the fourth aspect that can be implemented to provide a smart contract execution method.
[0048] In an eighth aspect, an embodiment of the present application provides an electronic device, including:
[0049] A processor, and a memory communicatively connected to the processor;
[0050] Memory stores computer-executable instructions;
[0051] The processor executes the computer-executable instructions stored in the memory to implement the second aspect or the second aspect that can be implemented to provide a smart contract deployment method, and the third aspect or the third aspect that can be implemented to provide a smart contract execution method.
[0052] In the ninth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the smart contract deployment method provided by the first aspect or the first aspect can be implemented, and the smart contract execution method provided by the fourth aspect or the fourth aspect can be implemented; or they are used to implement the smart contract deployment method provided by the second aspect or the second aspect can be implemented, and the smart contract execution method provided by the third aspect or the third aspect can be implemented.
[0053] In the tenth aspect, an embodiment of the present application provides a computer program product, comprising computer executable instructions, which, when executed by a processor, are used to implement the smart contract deployment method provided by the first aspect or the first aspect's implementable method, and the smart contract execution method provided by the fourth aspect or the fourth aspect's implementable method; or are used to implement the smart contract deployment method provided by the second aspect or the second aspect's implementable method, and the smart contract execution method provided by the third aspect or the third aspect's implementable method.
[0054] The smart contract deployment method, transaction method, device and electronic device provided by the present application receive a smart contract deployment request, the smart contract deployment request includes a bytecode file of the smart contract, and the bytecode file includes a runtime code; according to the runtime code, a code segment table is established in the blockchain node memory, the code segment table includes a label column and a code column, and the label of the label column corresponds to the code segment of the code column one by one; according to the label and the code segment, the first contract summary of the smart contract is constructed; the first contract summary is stored in the blockchain node to realize the deployment of the smart contract. After receiving the smart contract deployment request sent by the client, the blockchain node establishes a code segment table in the blockchain node memory according to the runtime code of the smart contract, and the label of the label column in the code segment table corresponds to the code segment of the code column one by one, and then the first contract summary of the smart contract is constructed and stored according to the label and the code segment to realize the deployment of the smart contract. Compared with the prior art, the entire runtime code is stored in the blockchain node, which greatly saves the storage space of the blockchain node. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0056] Figure 1 This is an exemplary application scenario architecture diagram of the first embodiment of the present application;
[0057] Figure 2 It is a flowchart of a smart contract deployment method provided by an embodiment of the present application;
[0058] Figure 3 is a schematic diagram of a structure for constructing a first contract summary provided in an embodiment of the present application;
[0059] Figure 4 is a flowchart of a smart contract deployment method provided by another embodiment of the present application;
[0060] Figure 5 It is a schematic diagram of the interaction process of the smart contract transaction method provided in one embodiment of the present application;
[0061] Figure 6 is a schematic diagram of determining label certification provided by another embodiment of the present application;
[0062] Figure 7 is a schematic diagram of a structure for constructing a second contract summary provided by another embodiment of the present application;
[0063] Figure 8 It is a structural diagram of a smart contract deployment device provided in one embodiment of the present application;
[0064] Fig. 9 It is a structural diagram of a smart contract transaction device provided in one embodiment of the present application;
[0065] Fig.10 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0066] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0067] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0068] The terms "first" and "second" in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein, for example. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0069] With the development of computer technology, more and more technologies are applied in the financial field. The traditional financial industry is gradually transforming to Fintech. Blockchain technology is no exception. However, due to the security and real-time requirements of the financial industry, higher requirements are also put forward for technology. Blockchain technology is a new application mode of computer technologies such as distributed ledger technology, consensus algorithm, encryption algorithm, etc. The characteristics of blockchain technology are decentralization, openness, transparency, and immutability. For modern blockchain, the development of smart contracts can be regarded as a milestone in the development of blockchain technology. It provides more powerful logical functions and can meet the business requirements of various fields. The blockchain has been integrated from the initial single digital currency application to finance, government services, supply chain, games and other fields. In the prior art, during the deployment of smart contracts, each node of the blockchain network saves the runtime code in the bytecode file of the smart contract in each node of the blockchain network. However, the deployment method of smart contracts in the prior art occupies a large space of blockchain nodes.
[0070] In order to solve the above technical problems, the inventive concept of the smart contract deployment method, transaction method, device and electronic device provided in the embodiment of the present application is that the blockchain node establishes a code segment table in the blockchain node memory according to the runtime code of the smart contract, and the label of the label column in the code segment table corresponds to the code segment of the code column one by one, and then according to the label and the code segment, the first contract summary of the smart contract is constructed and stored to realize the deployment of the smart contract. Compared with the smart contract deployment of the prior art, the entire runtime code is stored in the blockchain node, which greatly saves the storage space of the blockchain node. Further, during the execution of the smart contract, the client deploys the required target code segment label, code segment and proof in the transaction and sends it to the blockchain node. The blockchain node constructs a contract summary according to the label, code segment and proof of the target code segment, and compares it with the contract summary stored in the node to realize the verification of the transaction. After the verification is passed, the transaction is executed, which improves the efficiency of transaction execution.
[0071] The following is an introduction to exemplary application scenarios of the embodiments of the present application.
[0072] The smart contract deployment method provided in the embodiment of the present application can be executed by the smart contract deployment device provided in the embodiment of the present application, and the smart contract execution method provided in the embodiment of the present application can be executed by the smart contract execution device provided in the embodiment of the present application. The embodiment of the present application can be executed through the interaction between the server and the client, and the embodiment of the present application does not limit the specific type of the server.
[0073] Blockchain is a distributed storage system jointly maintained and trusted by multiple nodes. Figure 1 This is an exemplary application scenario architecture diagram of the first embodiment of the present application. Figure 1 As shown, the architecture mainly includes a terminal device 11 and a server 12. The terminal device 11 sends a smart contract deployment request to the blockchain node in the server 12 through the client, and the blockchain node deploys the smart contract according to the smart contract deployment request. After that, the client sends a smart contract transaction request to the blockchain node, and the blockchain node verifies and executes the smart contract transaction request according to the smart contract transaction request, thereby realizing the deployment of the smart contract and the execution of the smart contract transaction. The embodiments of the present application do not limit the specific types of terminal devices and servers.
[0074] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0075] Figure 2 This is a flow chart of a smart contract deployment method provided by an embodiment of the present application. The method can be executed by a smart contract deployment device, which can be implemented by software and / or hardware. The following describes the smart contract deployment method using a server as the execution subject. Figure 2 As shown, the smart contract deployment method provided in the embodiment of the present application may include:
[0076] Step S101: receiving a smart contract deployment request, where the smart contract deployment request includes a bytecode file of the smart contract, and the bytecode file includes a runtime code.
[0077] The client compiles the smart contract to obtain the bytecode file of the smart contract, wherein the bytecode file includes the initialization code (Creation code) and the runtime code (Runtime code). The client fills the bytecode file into the transaction and attaches the initialization parameters to generate a smart contract deployment request, and sends the smart contract deployment request to each node of the server blockchain in the form of a transaction. In a possible implementation, the client can send the transaction to the blockchain node through a network communication method such as HyperText Transfer Protocol (HTTP) or Remote Procedure Call Protocol (RPC).
[0078] In one possible implementation, after receiving a transaction, the blockchain node first stores the transaction in an internal buffer pool, waits for the packaging conditions to be met, and then retrieves enough transactions from the buffer pool to build a block. The node broadcasts and sends all nodes participating in the consensus to reach a consensus, where the nodes are participants in the blockchain. When the transactions in a block are executed on multiple consensus nodes and the status is consistent, we say that a consensus has been reached on the block, and the block is permanently recorded in the blockchain.
[0079] The blockchain node receives the smart contract deployment request, executes the initialization code in the bytecode file in the transaction, and copies the runtime code in the bytecode file. The runtime code contains the main logic of the smart contract. In one possible implementation, the smart contract deployment method provided in the embodiment of the present application also includes: sending the length information of the initialization code to the client.
[0080] Step S102: According to the runtime code, a code segment table is established in the blockchain node memory, and the code segment table includes a label column and a code column.
[0081] Among them, the labels in the label column and the code segments in the code column correspond one to one.
[0082] The runtime code includes multiple code segments, each code segment includes an opcode and opcode parameters. After obtaining the runtime code, the blockchain node establishes a code segment table in the blockchain node memory, wherein the code segment table includes a label column and a code column, and the label of the label column corresponds to the code segment of the code column one by one, wherein the label can be the address of the opcode, and the code segment can be the parameter of the opcode. The embodiment of the present application does not limit the specific format and content of the code segment table. For example, the code segment table can also include other columns for placing other required information, etc.
[0083] The embodiment of the present application does not limit the specific implementation method of how to establish a code segment table in the blockchain node memory according to the runtime code. In a possible implementation, the smart contract deployment method provided in the embodiment of the present application establishes a code segment table in the blockchain node memory according to the runtime code, including:
[0084] Traverse the address of each opcode in the runtime code and record the address of each opcode in the label column; determine the offset of each opcode; segment the runtime code using the offset to determine the code segment of each opcode; record the code segment of each opcode in the code column, wherein the address of the opcode corresponds to the code segment of the opcode one by one.
[0085] The blockchain node traverses each byte in the runtime code, starting from the first byte, and takes the current byte, which corresponds to an operation code (OPCODE). The operation code represents various operation instructions, and each operation instruction is represented by one byte. In addition, each OPCODE has a preset parameter value, for example, the PUSH1 operation code will be followed by 1 byte of data, the PUSH2 operation code will be followed by 2 bytes of data, and the ADD operation code will be followed by two 32-byte data.
[0086] Therefore, when traversing the runtime code, the type of OPCODE determines how many bytes after the OPCODE are the parameters of the OPCODE, and the parameters of the OPCODE are skipped during traversal. For example, if the current byte is 0x01, then it represents the OPCODE ADD, and this OPCODE has two 32-byte parameters. Therefore, when we look for the next OPCODE, we need to skip the subsequent 64 bytes, and the next byte is the next OPCODE, and so on, until the runtime code is traversed. By traversing the runtime code, the address of each opcode can be obtained, and the offset of the opcode can be determined by the address of the opcode and the type of the opcode. Then, the runtime code is segmented using the offset to obtain the code segment of each opcode.
[0087] In the embodiment of the present application, during the process of traversing the runtime code, the offset of the currently traversed opcode in the runtime code can be recorded by a counter, and the calculation method is as follows:
[0088] The offset of the first OPCODE is 0;
[0089] The offset of the subsequent OPCODE = the offset of the previous OPCODE + the total number of bytes occupied by the parameters of the previous OPCODE + 1.
[0090] For example: the current OPCODE is the first byte of the runtime code. Assuming it is PUSH1, the counter is 0. It has a 1-byte parameter. After jumping over it, we get the second OPCODE, so the counter is updated to 2, and so on.
[0091] After determining the offset of each OPCODE, the runtime code is segmented. For example, the offset of the first OPCODE is 0x00. When we continue to traverse and find the OPCODE with an offset of 0x0C, we copy the bytecode between 0x0C and 0x0C and store it in the code column of the code segment table, where the bytecode corresponds to the label 0x00. This process is repeated until all the bytecodes in the runtime code are stored in the code segment table.
[0092] In a possible implementation, the smart contract deployment method provided in the embodiment of the present application further includes: if the operation code is a jump code, determining the jump address of the jump code, and recording the jump address in the label column.
[0093] If the opcode is JUMP (bytecode is 0X56) or JUMPI (bytecode is 0x57), not only the offset of the current opcode needs to be updated, but also the jump address to be jumped to needs to be read from the parameter after the opcode. For example, if the bytecode is JUMP 0X00AA, then the jump address is 0x00AA, and the jump address of JUMP / JUMPI is recorded in the code segment table.
[0094] In an embodiment of the present application, the address and code segment of each opcode can be determined by traversing the bytecode file once, or the address of the opcode can be determined by traversing the bytecode file for the first time, and then the code segment of the opcode can be determined by traversing the bytecode file for a second time. The embodiment of the present application does not impose any restrictions on this.
[0095] For ease of understanding, Table 1 is an exemplary code segment table provided in an embodiment of the present application. Please refer to the table for details. The code segment table includes a label column and a code column, which will not be elaborated in the embodiment of the present application.
[0096] Table 1 is an exemplary code segment table provided in an embodiment of the present application
[0097]
[0098]
[0099] In an embodiment of the present application, the establishment of a code segment table is achieved by traversing the runtime code, querying the address and offset of the opcode in the runtime code, segmenting each code segment in the runtime code, and recording the address of each opcode and the code segment of the opcode in a code segment table.
[0100] Step S103: Construct the first contract summary of the smart contract according to the tag and the code segment.
[0101] After determining the code segment table, the blockchain node constructs the first contract summary of the smart contract based on the label and the code segment. In the embodiment of the present application, there is no limitation on the specific implementation method of how to construct the first contract summary of the smart contract based on the label and the code segment. In one possible implementation, the smart contract deployment method provided in the embodiment of the present application constructs the first contract summary of the smart contract based on the label and the code segment, including:
[0102] Each tag in the code segment table and the code segment corresponding to the tag are concatenated and hashed to obtain the first hash value of each tag; according to the preset rules, the first hash value of each tag is processed to generate the first contract summary.
[0103] For ease of introduction, the embodiment of the present application takes the code segment table of the smart contract as shown in Table 1 as an example for introduction, and the embodiment of the present application is not limited to this. Each tag in the code segment table and the code segment corresponding to the tag are concatenated and hashed. For example, "0x00" and "608060405260043610604957" are concatenated and hashed to obtain the first hash value of the first tag "0x00". The embodiment of the present application does not specifically limit the concatenation method and hashing method of the tag and the code segment corresponding to the tag. Concatenate and hash "0x0C" and "6000357c0100000000000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b114604e57" to get the first hash value of the second label "0x0C", and so on, until the last label and the code segment corresponding to the last label are concatenated and hashed to get the last first hash value.
[0104] After obtaining the first hash value of each tag, the first hash value of each tag is processed according to the preset rules to generate the first contract summary. The embodiment of the present application does not limit the preset rules. For example, the hash value of each group can be obtained by dividing the multiple first hash values into multiple groups, and then the first hash values in each group are spliced and hashed, and then the hash values of each group are spliced and hashed to obtain the first contract summary. The embodiment of the present application takes this as an example only and is not limited to this.
[0105] In a possible implementation, the smart contract deployment method provided in the embodiment of the present application processes the first hash value of each tag according to a preset rule to generate a first contract summary, including:
[0106] According to the order of the labels in the label column, the first hash values of adjacent labels are concatenated and hashed in pairs to obtain multiple second hash values; the adjacent second hash values in the multiple second hash values are concatenated and hashed in pairs in turn to obtain a third hash value; if there are multiple third hash values, the multiple third hash values are concatenated and hashed to obtain the first contract summary.
[0107] For ease of introduction, in one possible implementation, Figure 3 is a schematic diagram of a structure for constructing a first contract summary provided by an embodiment of the present application, wherein n represents the number of tags, and tag n represents the nth tag in the tag list. Figure 3 As shown, each tag in the code segment table and the code segment corresponding to the tag are concatenated and hashed to obtain the first hash value of each tag, and then the first hash values of adjacent tags are concatenated and hashed in the order of the tags in the tag column to obtain multiple second hash values, and then the adjacent second hash values in the multiple second hash values are concatenated and hashed to obtain a third hash value. In a possible implementation, if there are multiple third hash values, the multiple third hash values are concatenated and hashed to obtain the first contract summary. For details, please refer to Figure 3 , the embodiments of the present application are Figure 3 In another possible implementation, if the third hash value is 1, the third hash value is the first contract summary.
[0108] In a possible implementation, Figure 3 As shown, if n is an odd number, the label n and the code n are concatenated and hashed to obtain a first hash value, and then hashed to obtain a second hash value.
[0109] Step S104: Storing the first contract summary in the blockchain node to implement smart contract deployment.
[0110] After determining the first contract summary of the smart contract, the first contract summary is stored in the blockchain node to implement the deployment of the smart contract.
[0111] In an embodiment of the present application, after receiving the smart contract deployment request sent by the client, the blockchain node establishes a code segment table in the blockchain node memory according to the runtime code of the smart contract. The labels in the label column and the code segments in the code column in the code segment table correspond one to one. Then, based on the labels and the code segments, the first contract summary of the smart contract is constructed and stored to realize the smart contract deployment. Compared with the prior art, the entire runtime code is stored in the blockchain node, which greatly saves the storage space of the blockchain node.
[0112] Figure 4This is a flow chart of a smart contract deployment method provided by another embodiment of the present application. The method can be executed by a smart contract deployment device, which can be implemented by software and / or hardware. The following describes the smart contract deployment method with the terminal device as the execution subject. Figure 4 As shown, the smart contract deployment method provided in the embodiment of the present application may include:
[0113] Step S201: Send a smart contract deployment request to the blockchain node.
[0114] The terminal device sends a smart contract deployment request to the blockchain node through the client, wherein the smart contract deployment request includes the bytecode file of the smart contract, and the bytecode file includes the initialization code and the runtime code, so that the blockchain node establishes a code segment table in the blockchain node memory according to the runtime code, and the code segment table includes a label column and a code column, and the label of the label column corresponds to the code segment of the code column one by one, and then constructs and stores the first contract summary of the smart contract according to the label and the code segment, and sends the length information of the initialization code to the client. For specific implementation methods, please refer to Figure 2 The embodiments shown are not described in detail in the present application.
[0115] Step S202: Receive the length information of the initialization code sent by the blockchain node, and read the runtime code after the length information in the bytecode file to generate a code segment table of the smart contract.
[0116] The client receives the length information of the initialization code sent by the blockchain node, and can determine the runtime code in the bytecode file, and then generate a code segment table of the smart contract based on the runtime code. For the specific implementation method of generating the code segment table of the smart contract based on the runtime code, please refer to the relevant content in the above embodiment, and the embodiments of this application will not go into details.
[0117] Step S203: Generate a first contract summary using the code segment table and preset rules, and record the intermediate hash values in the process of generating the first contract summary.
[0118] After generating the code segment table of the smart contract, the client generates the first contract summary using the code segment table and preset rules, and records the intermediate hash values in the process of generating the first contract summary. Figure 3 As shown, the intermediate hash values include a first hash value, a second hash value, and a third hash value, etc. The embodiment of the present application does not limit this. The specific implementation method in which the client generates the first contract summary is consistent with the specific implementation method in which the blockchain node generates the first contract summary. You can refer to the above embodiment and will not repeat it here.
[0119] In an embodiment of the present application, by receiving the length information of the initialization code sent by the blockchain node and reading the runtime code after the length information in the bytecode file, a code segment table of the smart contract is generated, and the first contract summary is generated by using the code segment table and preset rules, and the intermediate hash value in the process of generating the first contract summary is recorded, thereby realizing the deployment of the smart contract in the client.
[0120] Through the smart contract deployment method provided in the above embodiment, after the smart contract is deployed, the execution of the smart contract transaction can be realized on the blockchain node. Based on this, the embodiment of the present application provides a smart contract transaction method.
[0121] Figure 5 This is a schematic diagram of the interaction flow of the smart contract transaction method provided by an embodiment of the present application. The method can be executed by a smart contract transaction device, which can be implemented by software and / or hardware. The following takes the interaction between the client and the server as an example to illustrate the smart contract transaction method. Figure 5 As shown, the smart contract transaction method provided in the embodiment of the present application may include:
[0122] Step S301: The client determines a target code segment.
[0123] Step S302: The client generates a smart contract transaction request based on the target code segment and the code segment table.
[0124] Step S303: The client sends the smart contract transaction request to the blockchain node.
[0125] The target code segment is a code segment that may be used in this transaction. For example, Table 2 is a code segment table of the target code segment provided in an embodiment of the present application. As shown in Table 2, if this transaction needs to call the set function, you only need to select the code you need in the code segment table without the need for other functions.
[0126] Table 2 is a code segment table of target code segments provided by an embodiment of the present application
[0127]
[0128] The tags and code segments in Table 2 are the target code segments required for this transaction. The client generates a smart contract transaction request based on the target code segment and the code segment table. The smart contract transaction request includes the tag of the target code segment, the code segment of the target code segment, and the proof of the target code segment.
[0129] Taking the above as an example, the label of the target code segment and the code segment of the target code segment are shown in Table 2. The proof of the target code segment can be determined according to the construction method of the first contract summary.
[0130] In a possible implementation, the smart contract transaction method provided in the embodiment of the present application generates a smart contract transaction request according to the target code segment and the code segment table, including:
[0131] Determine a first tag and a first code segment of a target code segment in a code segment table; determine a target hash value of the target code segment in an intermediate hash value using the position of the target code segment in the code segment table and preset rules, the target hash value being a proof of the target code segment; generate a smart contract transaction request using the first tag, the first code segment and the proof of the target code segment.
[0132] For ease of introduction, in one possible implementation, Figure 6 This is a schematic diagram of determining a tag proof provided by another embodiment of the present application. The client reconstructs the contract summary for each code segment in the target code segment. Taking 0X0C as an example, 0X0C is located in the second tag in the code segment table, such as Figure 6 As shown, the proof of 0X0C is the first hash value 1, the second hash value 2 and the third hash value 2. The proof can be expressed in the following way: [Sibling1, left node]; [Sibling2, right node]; [Sibling3, right node], where Sibling1 is the first hash value 1, Sibling2 is the second hash value 2, and Sibling3 is the third hash value 2. The above only takes the proof of the target code block 0x0C as an example for explanation, and the client also needs to determine the proofs of 0x59, 0x76, and 0XA0.
[0133] After determining the label, code segment and proof of the target code segment, the label, code segment and proof of the target code segment are carried in the smart contract transaction. The smart contract transaction may also include other content. For details, please refer to the relevant content in the prior art, and the embodiments of the present application will not be repeated here.
[0134] Step S304: The server receives the smart contract transaction request.
[0135] Step S305: The server verifies the target code segment according to the tag of the target code segment, the code of the target code segment and the certification of the target code segment.
[0136] Step S306: If the target code segment is verified, the smart contract transaction request is executed.
[0137] The first contract summary is stored in the blockchain node of the server. The second contract summary can be constructed according to the same preset rules through the label of the target code segment, the code of the target code segment and the proof of the target code segment. The target code segment can then be verified by comparing the first contract summary with the second contract summary.
[0138] In a possible implementation, the smart contract transaction method provided in the embodiment of the present application verifies the target code segment according to the label of the target code segment, the code of the target code segment and the proof of the target code segment, including:
[0139] The label of the target code segment and the code of the target code segment are concatenated and hashed to generate a fourth hash value; a second contract summary is constructed using the node relationship between the fourth hash value and the proof of the target code segment; the second contract summary and the first contract summary stored in the node are compared; if the first contract summary is consistent with the second contract summary, the target code segment is successfully verified.
[0140] For ease of introduction, Figure 7 is a schematic diagram of a structure for constructing a second contract summary provided by another embodiment of the present application, such as Figure 7 As shown, taking 0X0C as an example, label 2 "0X0C" and code 2 "6000357c0100000000000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b114604e57" are concatenated and hashed to generate a fourth hash value, and then the fourth hash value and the first hash value 1 are concatenated and hashed to generate a fifth hash value, and then the fifth hash value and the second hash value 2 are concatenated and hashed to obtain a sixth hash value, and finally the sixth hash value and the third hash value 2 are concatenated and hashed to obtain the second contract summary.
[0141] If the second contract summary is consistent with the first contract summary, the verification of the target code segment is successful; if the second contract summary is inconsistent with the first contract summary, the verification of the target code segment fails.
[0142] If the target code segment is verified successfully, the smart contract transaction request is executed. The embodiment of the present application does not limit the specific implementation method of how to execute the smart contract transaction request. For details, please refer to the relevant content in the prior art part, and the embodiment of the present application will not go into details.
[0143] In the embodiment of the present application, the verification efficiency is improved by using the label, code and proof of the target code segment to calculate the contract summary and then verifying it.
[0144] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0145] Figure 8 is a schematic diagram of the structure of a smart contract deployment device provided in an embodiment of the present application. The device can be implemented by software and / or hardware, for example, by a server, such as Figure 8 As shown, the smart contract deployment device provided in the embodiment of the present application may include: a first receiving module 41, a processing module 42 and a storage module 43.
[0146] The first receiving module 41 is used to receive a smart contract deployment request, where the smart contract deployment request includes a bytecode file of the smart contract, and the bytecode file includes a runtime code.
[0147] The processing module 42 is used to establish a code segment table in the blockchain node memory according to the runtime code, and the code segment table includes a label column and a code column, and the label of the label column corresponds to the code segment of the code column one by one.
[0148] The processing module 42 is also used to construct a first contract summary of the smart contract based on the tags and code segments.
[0149] The storage module 43 is used to store the first contract summary in the blockchain node to implement smart contract deployment.
[0150] In a possible implementation, in the smart contract deployment method provided in the embodiment of the present application, the processing module 42 is specifically used to:
[0151] Traverse the address of each opcode in the runtime code and record the address of each opcode in the label column; determine the offset of each opcode; segment the runtime code using the offset to determine the code segment of each opcode; record the code segment of each opcode in the code column, wherein the address of the opcode corresponds to the code segment of the opcode one by one.
[0152] In a possible implementation, in the smart contract deployment method provided in the embodiment of the present application, the processing module 42 is further used to:
[0153] If the operation code is a jump code, the jump address of the jump code is determined and the jump address is recorded in the tag column.
[0154] In a possible implementation, in the smart contract deployment method provided in the embodiment of the present application, the processing module 42 is specifically used to:
[0155] Each tag in the code segment table and the code segment corresponding to the tag are concatenated and hashed to obtain the first hash value of each tag; according to the preset rules, the first hash value of each tag is processed to generate the first contract summary.
[0156] In a possible implementation, in the smart contract deployment method provided in the embodiment of the present application, the processing module 42 is specifically used to:
[0157] According to the order of the labels in the label column, the first hash values of adjacent labels are concatenated and hashed in pairs to obtain multiple second hash values; the adjacent second hash values in the multiple second hash values are concatenated and hashed in pairs in turn to obtain a third hash value; if there are multiple third hash values, the multiple third hash values are concatenated and hashed to obtain the first contract summary.
[0158] In a possible implementation, in the smart contract deployment method provided by the embodiment of the present application, the bytecode file also includes initialization code, and the method also includes: a sending module 44.
[0159] The sending module 44 is used to send the length information of the initialization code to the client, so that the client reads the runtime code after the length information in the bytecode file, generates a code segment table, and uses the code segment table and preset rules to generate the first contract summary, and records the intermediate hash value in the process of generating the first contract summary.
[0160] The device of this embodiment can perform the above Figure 2 The technical principle and technical effect of the method embodiment shown are similar to those of the above-mentioned embodiment and will not be described in detail here.
[0161] Fig. 9 is a schematic diagram of the structure of a smart contract transaction device provided in an embodiment of the present application. The device can be implemented by software and / or hardware, for example, by a server, such as Fig. 9 As shown, the smart contract transaction device provided in the embodiment of the present application may include: a second receiving module 51, a verification module 52 and an execution module 53.
[0162] The second receiving module 51 is used to receive a smart contract transaction request, which includes a label of the target code segment, a code of the target code segment, and a proof of the target code segment.
[0163] The verification module 52 is used to verify the target code segment according to the label of the target code segment, the code of the target code segment and the certificate of the target code segment.
[0164] The execution module 53 is used to execute the smart contract transaction request if the target code segment is verified.
[0165] In a possible implementation, in the smart contract transaction method provided in the embodiment of the present application, the verification module 52 is specifically used to:
[0166] The label of the target code segment and the code of the target code segment are concatenated and hashed to generate a fourth hash value; a second contract summary is constructed using the node relationship between the fourth hash value and the proof of the target code segment; the second contract summary and the first contract summary stored in the node are compared; if the first contract summary is consistent with the second contract summary, the target code segment is successfully verified.
[0167] In the embodiment of the present application, the verification efficiency is improved by using the label, code and proof of the target code segment to calculate the contract summary and then verifying it.
[0168] The device embodiments provided in this application are merely illustrative. Figure 8 and Fig. 9 The module division in the description is only a logical function division, and there may be other division methods in actual implementation. For example, multiple modules can be combined or integrated into another system. The coupling between the modules can be realized through some interfaces, which are usually electrical communication interfaces, but it is not excluded that they may be mechanical interfaces or other forms of interfaces. Therefore, the modules described as separate components may or may not be physically separated, and may be located in one place or distributed in different locations of the same or different devices.
[0169] Fig.10 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. The electronic device may be a terminal or a server. Fig.10 As shown, the electronic device includes:
[0170] A receiver 60, a transmitter 61, a processor 62, a memory 63 and a computer program; wherein the receiver 60 and the transmitter 61 realize data transmission between other devices, the computer program is stored in the memory 63 and is configured to be executed by the processor 62, and the computer program includes instructions for executing the above-mentioned smart contract deployment method or smart contract transaction method. For its content and effect, please refer to the method embodiment.
[0171] In addition, an embodiment of the present application further provides a computer-readable storage medium, in which computer-executable instructions are stored. When at least one processor of a user device executes the computer-executable instructions, the user device executes the above-mentioned various possible methods.
[0172] Among them, computer-readable media include computer storage media and communication media, wherein the communication media include any media that facilitates the transmission of computer programs from one place to another. The storage medium can be any available medium that can be accessed by a general or special-purpose computer. An exemplary storage medium is coupled to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be an integral part of the processor. The processor and the storage medium can be located in an ASIC. In addition, the ASIC can be located in a user device. Of course, the processor and the storage medium can also be present in a communication device as discrete components.
[0173] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0174] The embodiment of the present application also provides a computer program product, including computer instructions, which implement the various steps of the method in the above embodiment when executed by a processor.
[0175] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0176] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A smart contract deployment transaction method, characterized in that: include: Receive a smart contract deployment request, wherein the smart contract deployment request includes a bytecode file of the smart contract, and the bytecode file includes a runtime code; According to the runtime code, a code segment table is established in the blockchain node memory, wherein the code segment table includes a label column and a code column, and the labels of the label column correspond to the code segments of the code column one by one; Constructing a first contract summary of the smart contract according to the tag and the code segment; Storing the first contract summary in the blockchain node to implement smart contract deployment; Receiving a smart contract transaction request, wherein the smart contract transaction request includes a tag of a target code segment, a code of the target code segment, and a certificate of the target code segment; Verifying the target code segment based on the label of the target code segment, the code of the target code segment, and the certification of the target code segment; If the target code segment is verified, the smart contract transaction request is executed; The code segment includes: an operation code and an operation code parameter, and the label is the address of the operation code.
2. The method according to claim 1, characterized in that The step of establishing a code segment table in the blockchain node memory according to the runtime code includes: Traversing the address of each operation code in the runtime code, and recording the address of each operation code in the tag column; determining an offset for each of said opcodes; Using the offset to segment the runtime code, determining a code segment for each of the opcodes; The code segment of each operation code is recorded in the code column, wherein the address of the operation code corresponds to the code segment of the operation code one by one.
3. The method according to claim 2, characterized in that Also includes: If the operation code is a jump code, a jump address of the jump code is determined, and the jump address is recorded in the tag column.
4. The method according to claim 2, characterized in that: The step of constructing a first contract summary of the smart contract according to the tag and the code segment includes: Concatenate and hash each tag in the code segment table and the code segment corresponding to the tag to obtain a first hash value of each tag; According to preset rules, the first hash value of each tag is processed to generate the first contract summary.
5. The method according to claim 4, characterized in that The first hash value of each tag is processed according to a preset rule to generate the first contract summary, including: According to the order of the labels in the label column, the first hash values of adjacent labels are concatenated and hashed in pairs to obtain multiple second hash values; Sequentially concatenate and hash adjacent second hash values in pairs among the plurality of second hash values to obtain a third hash value; If there are multiple third hash values, the multiple third hash values are concatenated and hashed to obtain the first contract summary.
6. The method according to any one of claims 1 to 5, characterized in that: The bytecode file also includes initialization code, and the method further includes: The length information of the initialization code is sent to the client, so that the client reads the runtime code after the length information in the bytecode file, generates the code segment table, and uses the code segment table and preset rules to generate the first contract summary, and records the intermediate hash value in the process of generating the first contract summary.
7. The method according to claim 1, characterized in that The verifying the target code segment according to the label of the target code segment, the code of the target code segment and the proof of the target code segment comprises: concatenating and hashing the label of the target code segment and the code of the target code segment to generate a fourth hash value; constructing a second contract digest using a node relationship between the fourth hash value and the proof of the target code segment; The second contract digest and the first contract digest stored in the node are compared. If the first contract digest is consistent with the second contract digest, the target code segment is successfully verified.
8. A smart contract deployment transaction method, characterized in that: include: Sending a smart contract deployment request to a blockchain node, wherein the smart contract deployment request includes a bytecode file of the smart contract, wherein the bytecode file includes an initialization code and a runtime code, so that the blockchain node establishes a code segment table in the blockchain node memory according to the runtime code, wherein the code segment table includes a label column and a code column, wherein the label of the label column corresponds to the code segment of the code column one by one, and then constructing and storing a first contract summary of the smart contract according to the label and the code segment, and sending the length information of the initialization code to the client; Receive the length information of the initialization code sent by the blockchain node, and read the runtime code after the length information in the bytecode file to generate a code segment table of the smart contract; Generate a first contract summary using the code segment table and preset rules, and record an intermediate hash value in the process of generating the first contract summary; Determine the target code segment; Generate a smart contract transaction request according to the target code segment and the code segment table, wherein the smart contract transaction request includes a tag of the target code segment, a code segment of the target code segment, and a certificate of the target code segment; Sending the smart contract transaction request to a blockchain node; The code segment includes: an operation code and an operation code parameter, and the label is the address of the operation code.
9. The method according to claim 8, characterized in that The step of generating a smart contract transaction request according to the target code segment and the code segment table includes: Determine a first label and a first code segment of the target code segment in the code segment table; Determine a target hash value of the target code segment in the intermediate hash value by using the position of the target code segment in the code segment table and a preset rule, wherein the target hash value is a proof of the target code segment; The smart contract transaction request is generated using the first tag, the first code segment, and the proof of the target code segment.
10. A smart contract deployment transaction device, characterized in that: include: A first receiving module, configured to receive a smart contract deployment request, wherein the smart contract deployment request includes a bytecode file of the smart contract, and the bytecode file includes a runtime code; A processing module, configured to establish a code segment table in a blockchain node memory according to the runtime code, wherein the code segment table includes a label column and a code column, and the labels of the label column correspond to the code segments of the code column in a one-to-one manner; The processing module is further used to construct a first contract summary of the smart contract according to the tag and the code segment; A storage module, used to store the first contract summary in the blockchain node to implement smart contract deployment; A second receiving module is used to receive a smart contract transaction request, wherein the smart contract transaction request includes a label of a target code segment, a code of the target code segment, and a certificate of the target code segment; a verification module, configured to verify the target code segment according to the label of the target code segment, the code of the target code segment and the certification of the target code segment; An execution module, configured to execute the smart contract transaction request if the target code segment is verified; The code segment includes: an operation code and an operation code parameter, and the label is the address of the operation code.
11. An electronic device, comprising: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the smart contract deployment transaction method as described in any one of claims 1-7.
12. An electronic device comprising: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the smart contract deployment transaction method as described in any one of claims 8-9.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 9 when executed by a processor.
14. A computer program product, comprising computer executable instructions, which implement the method according to any one of claims 1 to 9 when executed by a processor.
Citation Information
Patent Citations
Intelligent contract storage method and storage system
CN109634932A