CN114091111B - Method and device for storing intelligent contracts of block chains - Google Patents

Method and device for storing intelligent contracts of block chains Download PDF

Info

Publication number
CN114091111B
CN114091111B CN202111055168.9A CN202111055168A CN114091111B CN 114091111 B CN114091111 B CN 114091111B CN 202111055168 A CN202111055168 A CN 202111055168A CN 114091111 B CN114091111 B CN 114091111B
Authority
CN
China
Prior art keywords
code
intelligent contract
field
slice
block chain
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111055168.9A
Other languages
Chinese (zh)
Other versions
CN114091111A (en
Inventor
刘明臻
白兴强
黎宁
王�章
周禄
张开翔
范瑞彬
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
WeBank Co Ltd
Original Assignee
WeBank Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by WeBank Co Ltd filed Critical WeBank Co Ltd
Priority to CN202111055168.9A priority Critical patent/CN114091111B/en
Publication of CN114091111A publication Critical patent/CN114091111A/en
Application granted granted Critical
Publication of CN114091111B publication Critical patent/CN114091111B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/64Protecting data integrity, e.g. using checksums, certificates or signatures

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Theoretical Computer Science (AREA)
  • Health & Medical Sciences (AREA)
  • Bioethics (AREA)
  • General Health & Medical Sciences (AREA)
  • Computer Hardware Design (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The embodiment of the invention provides a method and a device for storing a block chain intelligent contract, wherein the method comprises the steps that when a first block chain node determines that an intelligent contract deployment transaction meets an execution condition, an intelligent contract source code is obtained by analyzing the intelligent contract deployment transaction, the intelligent contract source code is converted into an intelligent contract operation code, at least one key field is used as a segmentation field for segmenting the intelligent contract operation code, the intelligent contract operation code is segmented to obtain a code slice corresponding to at least one segmentation field, and when the hash value of the code slice corresponding to a certain segmentation field does not exist in a block chain, the hash value of the code slice corresponding to the segmentation field and the code slice corresponding to the segmentation field are stored to the block chain. Therefore, the scheme can avoid the situation that code segments corresponding to the same function of different intelligent contracts are repeatedly stored, so that the efficiency of storing the intelligent contract codes by the block chain can be effectively improved.

Description

Method and device for storing intelligent contracts of block chains
Technical Field
The embodiment of the invention relates to the field of financial technology (Fintech), in particular to a method and a device for storing a block chain intelligent contract.
Background
With the development of computer technology, more and more technologies are applied in the financial field, and the traditional financial industry is gradually changing to financial technology, but due to the requirements of the financial industry on safety and real-time performance, higher requirements are also put forward on the technologies.
At this stage, the smart contract code is stored in the blockchain and is in a block of storage area pointed to by the smart contract code hash value codehash in the account status accountstate. Specifically, the intelligent contract is deployed by submitting an intelligent contract deployment transaction including intelligent contract code at the time of deployment, encapsulating the intelligent contract deployment transaction in a block, and then linking the block to a blockchain. For any block, there is a tacle tree in the block, and the related information of the intelligent contract, such as the intelligent contract address, the intelligent contract code hash value codehash, etc., is stored in the tacle tree in the form of a key-value pair, for example, the intelligent contract address is used as key, and the transaction times nonce, the account balance, the hash value storageoot of the root of the tacle tree, and the intelligent contract code hash value codehash are stored as value. In the storage area pointed by the intelligent contract code hash value codehash, the structure form for storing the intelligent contract code takes the intelligent contract code hash value codehash as key, and the intelligent contract code is taken as the key-value pair form of value. However, the storage method is to store the intelligent contract code as a whole, so that the code segments corresponding to the same function of different intelligent contracts are repeatedly stored, which results in inefficient and poor flexibility of the blockchain storage of the intelligent contract code.
In summary, a method for storing a blockchain intelligent contract is needed to effectively improve the efficiency of blockchain storing an intelligent contract code.
Disclosure of Invention
The embodiment of the invention provides a method and a device for storing a block chain intelligent contract, which are used for effectively improving the efficiency of storing an intelligent contract code by a block chain.
In a first aspect, an embodiment of the present invention provides a method for storing a block chain intelligent contract, which is applicable to a block chain network having N block chain nodes, and the method includes:
when the first block chain node determines that the intelligent contract deployment transaction meets the execution condition, analyzing the intelligent contract deployment transaction to obtain an intelligent contract source code; the first blockchain node is any one of the N blockchain nodes;
the first block link point converts the intelligent contract source code into an intelligent contract operation code;
the first block chain node uses at least one key field as a segmentation field for segmenting the intelligent contract operation code, and the intelligent contract operation code is segmented to obtain a code slice corresponding to at least one segmentation field; the at least one key field is a field in the intelligent contract operation code;
and for the code slice corresponding to each segmentation field, when the first block chain node determines that the hash value of the code slice corresponding to the segmentation field does not exist in the block chain, storing the hash value of the code slice corresponding to the segmentation field and the code slice corresponding to the segmentation field into the block chain.
In the above technical solution, since the intelligent contract code is stored as a whole in the prior art, when different intelligent contracts are stored in the block chain, code segments corresponding to the same function in at least two different intelligent contracts are repeatedly stored, which results in low efficiency and poor flexibility in storing the intelligent contract code in the block chain. Based on this, the technical scheme of the invention divides the intelligent contract code to obtain the divided code segments, and stores the divided code segments to the block chain, so that the situation that the code segments corresponding to the same function functions of different intelligent contracts are repeatedly stored due to the integral storage of the intelligent contract code can be avoided, the efficiency of storing the intelligent contract code by the block chain can be effectively improved, the flexibility of the intelligent contract code storage can be higher, and the actual requirements of the block chain network can be better met. Specifically, when the first blockchain node determines that the intelligent contract deployment transaction meets the execution condition, the intelligent contract source code in the intelligent contract deployment transaction is converted into the intelligent contract operation code, so that the intelligent contract source code can be accurately segmented on the basis of the segmentation field in the intelligent contract operation code. And then at least one key field is used as a segmentation field for segmenting the intelligent contract operation code, so that the intelligent contract operation code can be accurately segmented into a plurality of code slices which can be flexibly stored in time. Then, for the code slice corresponding to each split field, if it is determined that the hash value of the code slice corresponding to the split field does not exist in the storage region for storing the code slice in the block chain, the hash value of the code slice corresponding to the split field and the code slice corresponding to the split field are stored into the block chain, and if it is determined that the hash value of the code slice corresponding to the split field exists in the storage region for storing the code slice in the block chain, the hash value of the code slice corresponding to the split field and the code slice corresponding to the split field are not stored into the block chain, so that the situation that the code segments corresponding to the same function functions of different intelligent contracts are repeatedly stored can be avoided, the storage space occupied by the stored intelligent contract codes is facilitated to be reduced, and the efficiency of the block chain for storing the intelligent contract codes can be effectively improved.
Optionally, the first block link point converts the intelligent contract source code into an intelligent contract operation code, including:
the first block link point compiles the intelligent contract source code into intelligent contract byte codes through a compiler;
the first block link point converts the intelligent contract bytecode into the intelligent contract opcode through a transcoder.
In the above technical solution, since the intelligent contract bytecode is stored at the bottom layer of the block chain, but the intelligent contract bytecode cannot be accurately split, in order to implement the split of the intelligent contract bytecode, the intelligent contract bytecode can be converted into the intelligent contract opcode, so that the intelligent contract opcode can be reasonably and accurately split through some split fields in the intelligent contract opcode, thereby implementing the split of the intelligent contract bytecode, and implementing the fragmented storage of the intelligent contract bytecode to the block chain.
Optionally, the first blockchain node uses at least one key field as a splitting field for splitting the intelligent contract operation code, and the splitting of the intelligent contract operation code includes:
the first block chain link point detects the content of the intelligent contract operation code, when at least one first segmentation field belonging to a first level is determined to exist in the intelligent contract operation code, the code segment where the at least one first segmentation field is located is sequentially segmented from the intelligent contract operation code according to the position sequence of the at least one first segmentation field in the intelligent contract operation code, so that the code segment corresponding to the at least one first segmentation field belonging to the first level is obtained, and the code segment corresponding to the at least one first segmentation field is used as the code segment corresponding to the at least one first segmentation field; the first sliced field is any one of the at least one sliced field.
In the above technical solution, when content of the intelligent contract operation code is detected, the tail position is always detected from the start position of the intelligent contract operation code, so that a certain division field is also detected in sequence. Moreover, since there may be nested layers in the split fields in the intelligent contract operation code, that is, a split field is nested below a split field, in order to accurately split the intelligent contract operation code, and in order to avoid missing splitting of code segments where some split fields are located, and certainly, in order to avoid repeated storage of code segments corresponding to the same function, detection and splitting of one level and another level are performed on the intelligent contract operation code, firstly, splitting of code segments where the split fields belonging to the first level are located is performed on the intelligent contract operation code, and after all code segments where the split fields belonging to the first level are located are completely split, detection of split fields belonging to the second level is performed, so that code segments where all split fields are located can be split, thereby implementing finer-grained splitting on the intelligent contract bytecode, and thus preventing code segments corresponding to the same function from being stored in a block chain.
Optionally, after obtaining the code segment corresponding to at least one first segmentation field belonging to the first hierarchy, the method further includes:
aiming at a code slice corresponding to each first segmentation field belonging to a first level, the first block chain link point performs content detection on the code segment where the first segmentation field is located, when it is determined that at least one second segmentation field belonging to a second level exists in the code segment where the first segmentation field is located, the code segment where the at least one second segmentation field is located is sequentially segmented from the code segment where the first segmentation field is located according to the position sequence of the at least one second segmentation field in the code segment where the first segmentation field is located, so that the code segment corresponding to the at least one second segmentation field belonging to the second level is obtained, and the code segment corresponding to the at least one second segmentation field is used as the code slice corresponding to the at least one second segmentation field; the second sliced field is any one of the at least one sliced field.
In the above technical solution, since there may be a nested layer in the split field existing in the intelligent contract operation code, that is, a split field is nested below one split field, and the nested split field below may also correspond to one code fragment, it is necessary to perform content detection again on the code fragment where the first split field is located, so as to perform detection of the re-split field on the code fragment where the split field existing in the nested layer is located, and perform splitting of a code fragment of a deeper level when it is determined that the split field exists, thereby implementing splitting of a finer granularity for the intelligent contract bytecode, and thus preventing a block chain from storing code fragments corresponding to the same function.
Optionally, the at least one slicing field includes a tag field;
for a code slice corresponding to each splitting field, when the first blockchain node determines that the hash value of the code slice corresponding to the splitting field does not exist in a blockchain, the storing the hash value of the code slice corresponding to the splitting field and the code slice corresponding to the splitting field into the blockchain includes:
for a code slice corresponding to each segmentation field, if the first block chain node determines that a push tag instruction exists in the code slice corresponding to the segmentation field, marking the segmentation field as an intermediate field, and replacing the intermediate field with a terminal field when determining that a code segment where the tag field pointed by the push tag instruction is located is a segment which cannot be segmented;
the first block chain node converts the code slice corresponding to the segmentation field into a first byte code slice through a code converter according to the ending state field, and performs hash operation on the first byte code slice to obtain a hash value of the first byte code slice;
and if the first block chain node determines that the hash value of the first byte code slice does not exist in the block chain, storing the hash value of the first byte code slice and the first byte code slice into the block chain.
In the above technical solution, for the code slice corresponding to each segmentation field, whether the hash operation and the code conversion of the code slice corresponding to the segmentation field are required to be immediately performed is determined by judging whether a push tag instruction exists in the code slice corresponding to the segmentation field. If a push tag instruction is stored in the code slice corresponding to the splitting field, and the code slice corresponding to the splitting field is converted through the code converter when the code slice where the tag field pointed by the instruction is located is determined to be a non-splitting segment, so that the absence of the splitting field capable of being continuously split in the intelligent contract operation code can be ensured, thereby avoiding repeated storage of byte code slices corresponding to the same function in different intelligent contracts, reducing the storage space occupied by the storage of the intelligent contract code, and enabling the flexibility of the intelligent contract byte code storage to be higher.
Optionally, the method further comprises:
if the first block chain node determines that the push tag instruction does not exist in the code slice corresponding to the segmentation field, converting the code slice corresponding to the segmentation field into a second byte code slice through the code converter;
the first block link point performs hash operation on the second bytecode slice to obtain a hash value of the second bytecode slice;
and if the first block chain node determines that the hash value of the second byte code slice does not exist in the block chain, storing the hash value of the second byte code slice and the second byte code slice into the block chain.
In the above technical solution, if it is determined that the push tag instruction does not exist in the code slice corresponding to the splitting field, it may be determined that the code slice corresponding to the splitting field is already split in the final state and cannot be split again, so that the code slice corresponding to the splitting field may be directly converted into the second bytecode slice by the transcoder, and when it is determined that the hash value of the second bytecode slice does not exist on the block chain, the hash value of the second bytecode slice and the second bytecode slice are stored to the block chain, so that it may be avoided that bytecode slices corresponding to the same function in different intelligent contracts are repeatedly stored, so that a storage space occupied by storing intelligent contract codes may be reduced, and it is helpful to improve efficiency of the block chain for storing intelligent contract bytecode.
Optionally, after storing the hash value of the code slice corresponding to the splitting field and the code slice corresponding to the splitting field in the blockchain, the method further includes:
when detecting an intelligent contract calling request, the first block chain node queries a corresponding intelligent contract from a block chain based on an intelligent contract address in the intelligent contract calling request, and acquires a hash value of each bytecode slice stored in the intelligent contract; the hash values of the byte code slices are arranged according to the position sequence of the byte code slices in the intelligent contract;
the first block link point queries each corresponding bytecode slice from a storage area for storing the bytecode slice in the block chain according to the hash value of each bytecode slice;
the first block chain link point splices all the byte code slices according to the position sequence of the hash value of each byte code slice in the intelligent contract to obtain intelligent contract byte codes;
the first block link point loads the intelligent contract bytecode to a virtual machine for executing intelligent contracts; the virtual machine is used for executing the intelligent contract bytecode.
In the above technical solution, when a certain intelligent contract needs to be called, the intelligent contract can be accessed through the address of the intelligent contract, and the hash value of at least one bytecode slice included in the intelligent contract is obtained from the intelligent contract. And then, accurately reading the byte code slices from the block chain according to the hash value of the at least one byte code slice, and splicing the byte code slices according to the position sequence of the byte code slices in the intelligent contract, so that complete intelligent contract byte codes can be obtained, and the intelligent contract byte codes can be loaded into the corresponding virtual machine for execution in time.
In a second aspect, an embodiment of the present invention further provides a storage apparatus for a blockchain intelligent contract, which is applicable to a blockchain network having N blockchain nodes, where the apparatus includes:
the analysis unit is used for analyzing the intelligent contract deployment transaction to obtain an intelligent contract source code when the intelligent contract deployment transaction meets the execution condition;
the processing unit is used for converting the intelligent contract source code into an intelligent contract operation code; taking at least one key field as a segmentation field for segmenting the intelligent contract operation code, and segmenting the intelligent contract operation code to obtain a code slice corresponding to the at least one segmentation field; the at least one key field is a field in the intelligent contract operation code; and for the code slice corresponding to each segmentation field, when the hash value of the code slice corresponding to the segmentation field does not exist in the block chain, storing the hash value of the code slice corresponding to the segmentation field and the code slice corresponding to the segmentation field into the block chain.
Optionally, the processing unit is specifically configured to:
compiling the intelligent contract source code into intelligent contract byte codes through a compiler;
and converting the intelligent contract bytecode into the intelligent contract operation code through a transcoder.
Optionally, the processing unit is specifically configured to:
detecting the content of the intelligent contract operation code, when at least one first segmentation field belonging to a first level is determined to exist in the intelligent contract operation code, sequentially segmenting the code segment where the at least one first segmentation field is located from the intelligent contract operation code according to the position sequence of the at least one first segmentation field in the intelligent contract operation code, so as to obtain a code segment corresponding to the at least one first segmentation field belonging to the first level, and taking the code segment corresponding to the at least one first segmentation field as a code slice corresponding to the at least one first segmentation field; the first sliced field is any one of the at least one sliced field.
Optionally, the processing unit is further configured to:
after obtaining a code segment corresponding to at least one first segmentation field belonging to a first level, performing content detection on the code segment where the first segmentation field is located aiming at a code slice corresponding to each first segmentation field belonging to the first level, when determining that at least one second segmentation field belonging to a second level exists in the code segment where the first segmentation field is located, sequentially segmenting the code segment where the at least one second segmentation field is located from the code segment where the first segmentation field is located according to the position sequence of the at least one second segmentation field in the code segment where the first segmentation field is located, thereby obtaining a code segment corresponding to the at least one second segmentation field belonging to the second level, and taking the code segment corresponding to the at least one second segmentation field as the code slice corresponding to the at least one second segmentation field; the second sliced field is any one of the at least one sliced field.
Optionally, the at least one slicing field includes a tag field;
the processing unit is specifically configured to:
for a code slice corresponding to each segmentation field, if a push tag instruction exists in the code slice corresponding to the segmentation field, marking the segmentation field as an intermediate field, and replacing the intermediate field with a final field when a code fragment in which the tag field pointed by the push tag instruction is located is determined to be a fragment which cannot be segmented;
according to the terminal field, converting a code slice corresponding to the segmented field into a first byte code slice through a code converter, and performing hash operation on the first byte code slice to obtain a hash value of the first byte code slice;
if the hash value of the first bytecode slice is determined not to exist in the block chain, storing the hash value of the first bytecode slice and the first bytecode slice to the block chain.
Optionally, the processing unit is further configured to:
if the fact that the push tag instruction does not exist in the code slice corresponding to the segmentation field is determined, converting the code slice corresponding to the segmentation field into a second byte code slice through the code converter;
performing hash operation on the second bytecode slice to obtain a hash value of the second bytecode slice;
if the hash value of the second bytecode slice is determined not to exist in the block chain, storing the hash value of the second bytecode slice and the second bytecode slice to the block chain.
Optionally, the processing unit is further configured to:
after the hash value of the code slice corresponding to the splitting field and the code slice corresponding to the splitting field are stored in the block chain, when an intelligent contract calling request is detected, inquiring a corresponding intelligent contract from the block chain based on an intelligent contract address in the intelligent contract calling request, and acquiring the hash value of each byte code slice stored in the intelligent contract; the hash values of the byte code slices are arranged according to the position sequence of the byte code slices in the intelligent contract;
inquiring corresponding byte code slices from a storage area for storing the byte code slices in the block chain according to the hash values of the byte code slices;
splicing the byte code slices according to the position sequence of the hash value of each byte code slice in the intelligent contract to obtain intelligent contract byte codes;
loading the intelligent contract bytecode to a virtual machine for executing an intelligent contract; the virtual machine is used for executing the intelligent contract bytecode.
In a third aspect, an embodiment of the present invention provides a computing device, including at least one processor and at least one memory, where the memory stores a computer program, and when the program is executed by the processor, the program causes the processor to execute the method for storing a blockchain smart contract according to any of the first aspect.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, which stores a computer program executable by a computing device, and when the program runs on the computing device, the computer program causes the computing device to execute the method for storing a blockchain intelligent contract according to any one of the first aspect.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required to be used in the description of the embodiments will be briefly introduced below, and it is apparent that the drawings in the description below are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings may be obtained based on these drawings without creative efforts.
FIG. 1 is a schematic diagram of a possible system architecture according to an embodiment of the present invention;
fig. 2 is a schematic flowchart of a method for storing a blockchain intelligent contract according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of an intelligent contract operation code of an intelligent contract a according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a blockchain storage intelligent contract a and an intelligent contract B according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of a storage device for a blockchain intelligent contract according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of a computing device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the present invention will be described in further detail with reference to the accompanying drawings, and it is apparent that the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In the following, some terms related to the embodiments of the present invention will be explained first to facilitate understanding by those skilled in the art.
(1) Smart contract (smart contract): is a computer protocol intended to propagate, verify or execute contracts in an informative manner, which intelligent contracts allow trusted transactions to be conducted without third parties, which transactions are traceable and irreversible.
(2) Function: is an executable unit of code in an intelligent contract.
(3) Function calling: may occur inside or outside a contract and functions may have varying degrees of visibility into other contracts.
As described above, some terms related to the embodiments of the present invention are described, and the technical features related to the embodiments of the present invention are described below.
To facilitate understanding of the embodiment of the present invention, a storage system architecture of a blockchain intelligent contract applicable to the embodiment of the present invention is first described by taking the system architecture shown in fig. 1 as an example. As shown in fig. 1, the system architecture may include a client 100 and a blockchain network 200. The block chain network 200 may include at least one block chain node, such as a block chain node 201, a block chain link point 202, a block chain link point 203, a block chain link point 204, and the like, where any two block chain link points in the at least one block chain node may be in communication connection; the client 100 and any blockchain node in the blockchain network 200 may be communicatively connected in a wired manner, or may be communicatively connected in a wireless manner, which is not limited in the embodiment of the present invention.
Illustratively, when a client 100 needs to deploy a certain intelligent contract, it will generally submit a request for deploying the intelligent contract to any blockchain node (such as blockchain node 201) in the blockchain network 200 in the form of a transaction, and after receiving the intelligent contract deployment transaction, the blockchain node 201 will put the intelligent contract deployment transaction into a local transaction pool, and at the same time synchronize the intelligent contract deployment transaction to other blockchain nodes (such as blockchain node 202, blockchain node 203, blockchain node 204, etc.) except for the blockchain node 201, and the other blockchain nodes will also put the intelligent contract deployment transaction into respective transaction pools. Then, when a certain blockchain node in the blockchain network 200 is determined to be a block node (e.g., the blockchain node 201), the blockchain node 201 packages multiple transactions in the local transaction pool into a block, and sends the block to other blockchain nodes except the blockchain node 201 for consensus, and after determining that the blockchain node is successful, the block is uplinked. That is, in the process of identifying a block, each block link node in the blockchain network 200 executes the block, for example, executes an intelligent contract deployment transaction in the block. When the intelligent contract deployment transaction meets the execution condition, the intelligent contract deployment transaction can be executed, namely, the intelligent contract deployment transaction is analyzed to obtain an intelligent contract source code, the intelligent contract source code is compiled into an intelligent contract bytecode through a compiler, and the intelligent contract bytecode is converted into an intelligent contract operation code through a transcoder. And then, the intelligent contract operation code is segmented into at least one code slice according to a set segmentation rule aiming at the intelligent contract operation code, the position sequence of each byte code slice in the intelligent contract is recorded, whether the hash value of the code slice exists in a block chain is determined aiming at each code slice, if the hash value does not exist, the code slice is converted into the byte code slice, and hash operation is carried out aiming at the byte code slice to obtain the hash value of the byte code slice. Then, each blockchain node verifies whether the execution result of the intelligent contract deployment transaction executed by itself is consistent with the execution result of the intelligent contract deployment transaction executed by other blockchain nodes, and when it is determined that all the consistent or agreed quantities meet a first set quantity threshold (for example, the execution results of two-thirds quantity of blockchain nodes) the execution result can be approved, and when it is determined that all the blockchain nodes or the blockchain nodes meeting a second set quantity threshold (for example, the execution result is approved by two-thirds quantity of blockchain nodes), at least one bytecode slice not existing in the blockchain and the corresponding hash value can be stored in the blockchain. The first set number threshold and the second set number threshold may be set according to experience or practical application scenarios of those skilled in the art, which is not limited in the embodiment of the present invention. The method includes accessing a corresponding intelligent contract through an address of each intelligent contract, and recording a position sequence of each bytecode slice and a hash value of each bytecode slice included in the intelligent contract in each intelligent contract, where in recording, recording may be performed according to a sequence of positions of each bytecode slice in each intelligent contract, or recording may not be performed according to a sequence of positions of each bytecode slice in each intelligent contract, but the position sequence needs to be marked for each bytecode slice in each intelligent contract, which is not limited in the embodiment of the present invention. It should be noted that, the position order of each bytecode slice in each intelligent contract in the intelligent contract is also labeled according to the position of each bytecode slice when being executed in the intelligent contract. For example, the intelligent contract a includes three bytecode slices, that is, a bytecode slice a, a bytecode slice b, and a bytecode slice c, and assuming that the sequence of the positions of the bytecode slice a, the bytecode slice b, and the bytecode slice c in the intelligent contract a is position 1, position 2, and position 3, that is, the starting position of the bytecode slice a in the intelligent contract a, the middle position of the bytecode slice b in the intelligent contract a, and the end position of the bytecode slice c in the intelligent contract a, at this time, 1 is marked for the bytecode slice a, 2 is marked for the bytecode slice b, and 3 is marked for the bytecode slice c. Then, when recording in the smart contract a, recording may be performed according to the bytecode slice a, the bytecode slice b, and the bytecode slice c, or recording may be performed according to the bytecode slice b, the bytecode slice a, and the bytecode slice c, and the hash value of each bytecode slice may be correspondingly recorded at the same time.
It should be noted that the system structure shown in fig. 1 is only an example, and the embodiment of the present invention is not limited thereto.
Based on the foregoing description, fig. 2 schematically illustrates a flow of a storage method of a blockchain intelligent contract, where the flow may be executed by a storage device of the blockchain intelligent contract according to an embodiment of the present invention. The storage method of the intelligent contract of the block chain in the embodiment of the invention is suitable for the block chain network of N block chain nodes.
As shown in fig. 2, the process specifically includes:
step 201, when the first block chain node determines that the intelligent contract deployment transaction meets the execution condition, analyzing the intelligent contract deployment transaction to obtain an intelligent contract source code.
In the embodiment of the invention, when a certain intelligent contract deployment transaction in a block is determined to meet an execution condition, a first block chain node executes the intelligent contract deployment transaction, that is, an intelligent contract source code included in the intelligent contract deployment transaction can be obtained by analyzing and processing the intelligent contract deployment transaction. The first blockchain node is any one of the N blockchain nodes.
For example, after a certain user writes a certain intelligent contract source code in a client of a terminal device (e.g., a smart phone, a tablet computer, a notebook computer, a desktop computer, etc.), an intelligent contract deployment request may be generated on the client of the terminal device based on the written intelligent contract source code, and the intelligent contract deployment request is sent to any block link node (e.g., block link node a) in a block link network in a transaction form through the client of the terminal device, after the block link node a stores the intelligent contract deployment transaction in a local transaction pool, the intelligent contract deployment transaction is synchronized to other block link nodes in the block link network except for the block link node a, and after receiving the intelligent contract deployment transaction, the other block link nodes also place the intelligent contract deployment transaction in their respective transaction pools. Then, if a certain blockchain node (e.g., blockchain node B) in the blockchain network is determined to be a block-out node (i.e., a master node), the blockchain node B packages multiple transactions in the local transaction pool into a block, and sends the block to other blockchain nodes in the blockchain network except the blockchain node B for consensus, and the block is uplinked after the block consensus is determined to be successful. That is, in the process of identifying the block, each block link point executes the block, that is, executes each transaction in the block, for example, each transaction may be executed when the execution condition is satisfied, the execution condition may be an execution time of each transaction, for example, an execution time may be set for each transaction when the transactions are packed into the block, or the execution condition may also be an execution sequence of each transaction, for example, each transaction may be packed into the block in a sequence, and the sequence in which each transaction is packed into the block may be an execution sequence of the transaction. For example, if a certain transaction is an intelligent contract deployment transaction, an execution time may be set for the intelligent contract deployment transaction, or a sequence number in a block may also be set for the intelligent contract deployment transaction, and when the execution time of the intelligent contract deployment transaction arrives, the intelligent contract deployment transaction may be executed, for example, an intelligent contract source code is obtained by parsing the intelligent contract deployment transaction, or when it is detected that the transaction execution has reached the sequence number of the intelligent contract deployment transaction, the intelligent contract deployment transaction may be executed, for example, an intelligent contract source code is obtained by parsing the intelligent contract deployment transaction. After each blockchain node executes a block, the execution result of the block is synchronized to other blockchain nodes except the blockchain node for consensus. Each blockchain node verifies whether the execution result of executing the block by itself is consistent with the received execution result of executing the block by other blockchain nodes, and if all or most of the execution results are consistent, the execution result of the block is approved, that is, an approval message for approving the block is sent to the block node, which can also be understood as an approval vote. For each block chain node, the block chain node verifies whether the execution result of each transaction executed by the block chain node is consistent with the received execution result of each transaction executed by other block chain nodes, and for each transaction, if the execution results of all the block chain nodes for the transaction are consistent or the execution results of most of the block chain nodes for the transaction are consistent, the block chain node approves the execution result of the transaction.
At step 202, the first block link point converts the intelligent contract source code into an intelligent contract operation code.
In the embodiment of the invention, because the intelligent contract byte code is stored at the bottom layer of the block chain, but the intelligent contract byte code cannot be accurately segmented, and the intelligent contract operation code opcode corresponds to the intelligent contract byte code in a mapping manner, that is, the intelligent contract operation code is an assembly form of the intelligent contract byte code, in order to realize the segmentation of the intelligent contract byte code, the intelligent contract operation code can be segmented accurately, so that each accurately segmented code slice can be converted into a byte code slice, and then the byte code not existing in the block chain is segmented and stored into the block chain. Specifically, the first block link point converts the intelligent contract source code into the intelligent contract byte code through the compiler and converts the intelligent contract byte code into the intelligent contract operation code through the code converter. Therefore, the intelligent contract operation code can be reasonably and accurately segmented through some segmentation fields in the intelligent contract operation code, so that the intelligent contract byte code can be segmented and stored in a block chain.
Illustratively, when a certain blockchain node (such as blockchain node a) executes an intelligent contract deployment transaction (such as intelligent contract deployment transaction a), the certain blockchain node firstly parses the intelligent contract deployment transaction a, so as to obtain an intelligent contract source code a in the intelligent contract deployment transaction a, and converts the intelligent contract source code a into an intelligent contract bytecode a through a compiler. Then, the intelligent contract bytecode A is converted into an intelligent contract operation code A through a transcoding tool. The intelligent contract operation code A and the intelligent contract byte code A are equivalent and are an assembly form of the intelligent contract byte code A.
And 203, the first block chain node uses at least one key field as a segmentation field for segmenting the intelligent contract operation code, and segments the intelligent contract operation code to obtain a code slice corresponding to at least one segmentation field.
In the embodiment of the present invention, the first block link point may use at least one key field as a splitting field for splitting the intelligent contract operation code to split the intelligent contract operation code, so as to obtain a code slice corresponding to the at least one splitting field. Wherein the at least one key field is a field in the intelligent contract operation code. Specifically, the content of the first block link point is detected with respect to the intelligent contract operation code, and when it is determined that at least one first segmentation field belonging to a first hierarchy exists in the intelligent contract operation code, the code segment in which the at least one first segmentation field is located may be sequentially segmented from the intelligent contract operation code according to the position order of the at least one first segmentation field in the intelligent contract operation code, so that the code segment corresponding to the at least one first segmentation field belonging to the first hierarchy may be obtained, and the code segment corresponding to the at least one first segmentation field is used as the code segment corresponding to the at least one first segmentation field. After the code segment where the at least one first segmentation field belonging to the first hierarchy is segmented from the intelligent contract operation code, content detection needs to be performed again on the code segment where the first segmentation field is located, when it is determined that the code segment where the first segmentation field is located has the at least one second segmentation field belonging to the second hierarchy, the code segment where the at least one second segmentation field is located can be sequentially segmented from the code segment where the first segmentation field is located according to the position sequence of the at least one second segmentation field in the code segment where the first segmentation field is located, so that the code segment corresponding to the at least one second segmentation field belonging to the second hierarchy can be obtained, and the code segment corresponding to the at least one second segmentation field is used as the code segment corresponding to the at least one second segmentation field. Wherein, the first and second split fields are any one of the at least one split field. Specifically, when the first blockchain node performs content detection on the intelligent contract operation code, the end position is always detected from the start position of the intelligent contract operation code, so that a certain partition field is also detected in sequence. Moreover, since there may be nested layers in the split field existing in the intelligent contract operation code, that is, one split field is nested below one split field, and the nested split field below the split field may also correspond to one code fragment, when content detection is performed on the intelligent contract operation code, a first round of detecting the split field of a first level is usually performed, and after all the split fields of the first level are detected in the first round, a second round of detecting the split field of a second level is started, that is, content detection is performed again on the code fragment where the split field of the nested layer (that is, the nested split field exists below) exists, so that detection of one level and another level can detect all the split fields, and simultaneously, the code fragments where all the split fields exist can be split, so that the code fragments corresponding to a plurality of split fields can be obtained, and further splitting of the code fragments where the split fields of the nested layer exist can be realized, that the code fragments where the nested field exists are further split, and the nested field where the nested layer exists is located can be further split into finer-grained code fragments.
For example, the first block chain node is taken as a block chain node a, and when the content of the intelligent contract operation code is detected, the block chain node a performs a first round of content detection on the intelligent contract operation code, that is, performs a first-level content detection on the intelligent contract operation code. For example, when the block link point a performs the first hierarchical content detection, and a segmentation field a is detected for the first time, the code segment where the segmentation field a is located may be segmented from the intelligent contract operation code; when the segmentation field B is detected for the second time, the code segment of the segmentation field B is segmented from the intelligent contract operation code, so that the content detection of the first level is continuously carried out, all the segmentation fields of the first level existing in the intelligent contract operation code can be detected, and all the code segments of all the segmentation fields of the first level are segmented. Then, the second round of content detection is performed on the intelligent contract operation code, that is, the second level of content detection is performed on the intelligent contract operation code, that is, the content detection is performed on the code segment where each split field of the first level is located. For example, when content detection is performed on a code segment in which each split field of the first level is located, for example, content detection is performed on a code segment in which the split field a of the first level is located, and the split field C is detected for the first time (or the split field a may be detected, or the split field B may be detected), the code segment in which the split field C is located may be split from the code segment in which the split field a is located; when the segmentation field A is detected for the second time (or the segmentation field B may be detected, or the segmentation field C may be detected), the code segment where the segmentation field A is located is segmented from the code segment where the segmentation field A is located, so that the content detection of the second level is continuously performed, all the segmentation fields existing in the code segment where the segmentation field A is located can be detected, and all the code segments where all the segmentation fields existing in the code segment where the segmentation field A is located are segmented, so that the content detection is performed in one round, all the code fields existing in the intelligent contract operation code can be detected, and simultaneously, the code segments where all the segmentation fields are located can be segmented, so that the code segments corresponding to a plurality of the segmentation fields can be obtained.
Step 204, for the code slice corresponding to each splitting field, when the first block chain node determines that the hash value of the code slice corresponding to the splitting field does not exist in the block chain, storing the hash value of the code slice corresponding to the splitting field and the code slice corresponding to the splitting field into the block chain.
In the embodiment of the present invention, after obtaining a code slice corresponding to at least one segmentation field, for the code slice corresponding to each segmentation field, if it is determined that a push tag instruction exists in the code slice corresponding to the segmentation field by a first block link point, the segmentation field may be labeled as a middle field, and then, when it is determined that a code segment where the tag field pointed by the push tag instruction is located is a segment that cannot be segmented, that is, when it is determined that a nested segmentation field does not exist in the code segment where the tag field pointed by the push tag instruction is located, the middle field is replaced by a terminal field, and then, based on the terminal field, the code slice corresponding to the segmentation field may be converted into a first byte code slice by a code converter, and the first byte code slice is subjected to hash operation to obtain a hash value of the first byte code slice. Finally, if the hash value of the first bytecode slice is determined not to exist in the block chain, the hash value of the first bytecode slice can be used as a key, the first bytecode slice is used as a value, and the hash value is stored into the block chain in a key value pair form; if the hash value of the first bytecode slice is determined to exist in the block chain, the hash value of the first bytecode slice and the first bytecode slice are not stored to the block chain. In addition, if the push tag instruction does not exist in the code slice corresponding to the segmentation field, the first block link point marks the segmentation field as a terminal field, and converts the code slice corresponding to the segmentation field into a second byte code slice through a code converter. And then, carrying out hash operation on the second byte code slice to obtain a hash value of the second byte code slice. Finally, if it is determined that the hash value of the second bytecode slice does not exist in the block chain, the hash value of the second bytecode slice can be stored into the block chain in a key-value pair form as a key and the second bytecode slice as a value; if the hash value of the second bytecode slice is determined to exist in the block chain, the hash value of the second bytecode slice and the second bytecode slice are not stored to the block chain. At least one of the segmentation fields may include any one or any combination of fields such as ". Code", ". Data", "tag1", "tag2", "tag3", "tag4", "tag5", and the like. Therefore, the situation that byte code slices with the same byte code slice hash values in different intelligent contracts are repeatedly stored can be avoided, the storage space occupied by the intelligent contract byte codes is reduced, the efficiency of storing the intelligent contract byte codes by the block chain can be effectively improved, the flexibility of storing the intelligent contract byte codes is higher, and the actual requirements of the block chain network are met better.
Illustratively, continuing with the first blockchain node as the blockchain node a and taking an intelligent contract (such as an intelligent contract a) as an example, the intelligent contract bytecode of the intelligent contract a is split into at least one code slice, such as four code slices, i.e., code slice 1, code slice 2, code slice 3, and code slice 4. Fig. 3 is a schematic structural diagram of an intelligent contract operation code of an intelligent contract a according to an embodiment of the present invention. Based on the graph 3, when the block chain node a performs a first round of content detection on the intelligent contract operation code of the intelligent contract a, the code segment where the 'code' is located, the code segment where the 'data' is located, and the code segment where the 'tag 1' is located may be sequentially detected to be segmented from the intelligent contract operation code of the intelligent contract a, and then, second round of content detection is performed on the code segments where the three segmentation fields are located, for example, content detection is performed on the code segment where the 'code' is located, and it is found that no nested segmentation field exists in the code segment where the 'code' is located, so that re-segmentation is not required on the code segment where the 'code' is located; content detection is carried out on the code segment where the tag1 is located, and if the code segment where the tag1 is located is found to have no nested segmentation field, the code segment where the tag1 is located does not need to be segmented again; when content detection is carried out on the code fragment where the 'data' is located, a nested segmentation field is found in the code fragment where the 'data' is located, then the code fragment where the 'data' is located needs to be segmented again, the segmentation field 'tag 2' is detected for the first time, then the code fragment where the 'tag 2' is located is segmented from the code fragment where the 'data' is located, and when the segmentation field 'tag 3' is detected for the second time, then the code fragment where the 'tag 3' is located is segmented from the code fragment where the 'data' is located until all nested segmentation fields in the code fragment where the 'data' is located are detected. In this way, all the segmentation fields existing in the operation code of the intelligent contract can be detected in one round of content detection, and the code segments where all the segmentation fields are located can be segmented, so that the code segment corresponding to the field ". Code" (namely, the code slice 1), the code segment corresponding to the segmentation field "tag1" (namely, the code slice 2), the code segment corresponding to the segmentation field "tag2" (namely, the code slice 3), and the code segment corresponding to the segmentation field "tag3" (namely, the code slice 4) can be segmented.
Then, for each code slice, the block link point a determines whether a push tag instruction exists in the code slice, for example, for a code slice 1, the block link point a performs content detection on the code slice 1, and finds that the code slice 1 has the push tag instruction and a tag field pointed by the push tag instruction is "tag1", then the slicing field ". Code" may be labeled as an intermediate field, and subsequently when it is determined that a code segment where the slicing field "tag1" pointed by the push tag instruction is located is a fragment that cannot be sliced, that is, when it is determined that a nested slicing field does not exist in the code segment where the slicing field "tag1" pointed by the push tag instruction is located, the intermediate field is replaced with a terminal field, and then when it is determined that the slicing field ". Code" is labeled as a terminal field, the code slice 1 may be converted into a byte code slice 1 by a code converter, and the byte code slice 1 is subjected to operation to obtain a hash value of the byte code slice 1. Finally, if it is determined that the hash value of the bytecode slice 1 does not exist in the block chain, the hash value of the bytecode slice 1 may be stored in the block chain in a form of a key-value pair as a key and the bytecode slice 1 as a value; if the hash value of the bytecode slice 1 is determined to exist in the block chain, the hash value of the bytecode slice 1 and the bytecode slice 1 are not stored to the block chain. For a code slice 2, the block link point a performs content detection on the code slice 2, and if it is found that a push tag instruction does not exist in the code slice 2, the slicing field "tag1" is marked as a final field, and the code slice 2 is converted into a bytecode slice 2 through a transcoder. Then, the hash operation is performed on the bytecode slice 2 to obtain a hash value of the bytecode slice 2. Finally, if it is determined that the hash value of the bytecode slice 2 does not exist in the block chain, the hash value of the bytecode slice 2 may be stored in the block chain in the form of a key value pair as a key and the bytecode slice 2 as a value; if the hash value of the bytecode slice 2 is determined to exist in the blockchain, the hash value of the bytecode slice 2 and the bytecode slice 2 are not stored to the blockchain. For a code slice 3, the block link point a performs content detection on the code slice 3, and if it is found that there is no push tag instruction in the code slice 3, the slicing field "tag2" is marked as a final field, and the code slice 3 is converted into a bytecode slice 3 through a transcoder. Then, the hash operation is performed on the bytecode slice 3 to obtain a hash value of the bytecode slice 3. Finally, if it is determined that the hash value of the bytecode slice 3 does not exist in the block chain, the hash value of the bytecode slice 3 may be stored in the form of a key value pair to the block chain as a key and the bytecode slice 3 as a value; if it is determined that the hash value of the bytecode slice 3 exists in the block chain, the hash value of the bytecode slice 3 and the bytecode slice 3 are not stored to the block chain. For a code slice 4, the block link point a performs content detection on the code slice 4, and it is found that a push tag instruction exists in the code slice 4, and a tag field pointed by the push tag instruction is "tag2", then a slicing field "tag3" may be first marked as a middle state field, and then when it is determined that a code fragment in which the slicing field "tag2" pointed by the push tag instruction is located is a fragment that cannot be sliced, that is, when it is determined that no nested slicing field exists in the code fragment in which the slicing field "tag2" pointed by the push tag instruction is located, the middle state field is replaced by a terminal state field, and then when it is determined that the slicing field "tag3" is marked as the terminal state field, the code slice 4 may be converted into a byte code slice 4 by a code converter, and the byte code slice 4 is subjected to a hash operation to obtain a hash value of the byte code slice 4. Finally, if it is determined that the hash value of the bytecode slice 4 does not exist in the block chain, the hash value of the bytecode slice 4 may be stored in the block chain in the form of a key value pair as a key and the bytecode slice 4 as a value; if it is determined that the hash value of the bytecode slice 4 exists in the block chain, the hash value of the bytecode slice 4 and the bytecode slice 4 are not stored to the block chain.
Further, taking the first block link node as the block link node a, and taking the intelligent contract node B as the example for description, the intelligent contract bytecode of the block link node a for the intelligent contract node B may be processed in a manner that the intelligent contract bytecode of the intelligent contract node a is stored in a split manner, and is assumed to be also split into four bytecode slices, that is, the bytecode slice a, the bytecode slice B, the bytecode slice c, and the bytecode slice d. Assuming that the hash value of the bytecode slice a in the intelligent contract B is the same as the hash value of the bytecode slice 1 stored in the blockchain, the blockchain node a does not store the hash value of the bytecode slice a and the bytecode slice a to the blockchain; if the hash value of the bytecode slice b is different from the hash value of any bytecode slice in the block chain, the block chain node A stores the hash value of the bytecode slice b and the bytecode slice b into the block chain; assuming that the hash value of the bytecode slice c is the same as the hash value of the bytecode slice 2, the chunk chain node a does not store the hash value of the bytecode slice c and the bytecode slice c to the chunk chain; assuming that the hash value of the bytecode slice d is different from the hash value of any bytecode slice in the blockchain, the blockchain link point a stores the hash value of the bytecode slice d and the bytecode slice d into the blockchain.
As an example, the storage of the blockchain is described by taking an intelligent contract a and an intelligent contract B as an example, as shown in fig. 4, a schematic structural diagram of a blockchain storage intelligent contract a and an intelligent contract B provided by an embodiment of the present invention is shown. Assume that the intelligent contract bytecode of the intelligent contract a is sliced into four bytecode slices, namely, bytecode slice 1, bytecode slice 2, bytecode slice 3, and bytecode slice 4; and assume that the intelligent contract bytecode of the intelligent contract B is sliced into four bytecode slices, namely, bytecode slice a, bytecode slice B, bytecode slice c, and bytecode slice d. Based on the fig. 4, the hash value of the bytecode slice in the intelligent contract a is the same as the hash value of the bytecode slice in the intelligent contract B, and only one copy of the bytecode slice is stored, but not all copies of the bytecode slice are stored, for example, if the hash value hash1 of the bytecode slice 1 in the intelligent contract a is the same as the hash value hash a of the bytecode slice a in the intelligent contract B, only one copy of the bytecode slice is stored in the block chain; if the hash value hash B of the byte code slice B in the intelligent contract B is different from any byte code slice in the intelligent contract A, the hash value hash B of the byte code slice B in the intelligent contract B and the byte code slice B are stored in a block chain; the hash value hash2 of the byte code slice 2 in the intelligent contract A is the same as the hash value hash c of the byte code slice c in the intelligent contract B, and only one byte code slice is stored in the block chain; if the hash value hash3 of the bytecode slice 3 in the intelligent contract a is different from any bytecode slice in the intelligent contract B, storing the hash value hash3 of the bytecode slice 3 in the intelligent contract a and the bytecode slice 3 to a block chain; if the hash value hash4 of the bytecode slice 4 in the intelligent contract a is different from any bytecode slice in the intelligent contract B, storing the hash value hash4 of the bytecode slice 4 in the intelligent contract a and the bytecode slice 4 in the block chain; and if the hash value hash d of the bytecode slice d in the intelligent contract B is different from any bytecode slice in the intelligent contract A, storing the hash value hash d of the bytecode slice d in the intelligent contract B and the bytecode slice d into a block chain.
In addition, the description is continued by taking the intelligent contract a as an example, when the intelligent contract bytecode of the intelligent contract a is stored into the block chain as a whole according to the prior art, the storage length of the intelligent contract bytecode of the intelligent contract a is assumed to be 2692 bits, but if the intelligent contract bytecode of the intelligent contract a is stored into the block chain in a form of segments according to the technical scheme of the invention, the storage length of the intelligent contract bytecode of the intelligent contract a is reduced, and if 1836 bits are assumed, so that it can be calculated that the storage space can be reduced by 31.8% when the intelligent contract bytecode of the intelligent contract a is stored into the block chain according to the technical scheme of the invention.
Further, after the hash value of at least one code slice of the intelligent bytecode of any intelligent contract and the at least one code slice are stored in the block chain, when a user needs to invoke a certain intelligent contract, an intelligent contract invoking request is submitted to a certain block link point through a client, and when the block link point detects the intelligent contract invoking request, the corresponding intelligent contract can be inquired according to the intelligent contract address of the intelligent contract, the hash value of at least one bytecode slice included in the intelligent contract is obtained, and the corresponding bytecode slices are accurately read from the block chain according to the hash value of the at least one bytecode slice. Then, the byte code slices are spliced according to the position sequence of the byte code slices in the intelligent contract, so that the complete intelligent contract byte code can be obtained, and the intelligent contract byte code can be loaded into the corresponding virtual machine for executing the intelligent contract byte code in time to execute. The hash values of the byte code slices can be arranged according to the position sequence of the byte code slices in the intelligent contract, or the hash values of the byte code slices can be marked with the position sequence of the byte code slices corresponding to the hash values of the byte code slices in the intelligent contract, so that complete intelligent contract byte codes can be accurately spliced when the byte code slices of the intelligent contract are spliced, and support is provided for accurately executing the intelligent contract byte codes by a subsequent virtual machine.
For example, assuming that a certain user needs to invoke intelligent contract a, an intelligent contract invocation request including an address of intelligent contract a may be submitted to a certain blockchain node (such as blockchain node a) through a client. After receiving the intelligent contract calling request, the block chain link point A can access the corresponding intelligent contract A through the address of the intelligent contract A in the intelligent contract calling request, can acquire the hash value of at least one byte code slice contained in the intelligent contract A, and can accurately read the corresponding byte code slice from the block chain according to the hash value of the at least one byte code slice. Then, the byte code slices are spliced according to the position sequence of the byte code slices in the intelligent contract a, so that complete intelligent contract byte codes can be obtained, and the intelligent contract byte codes can be loaded into the corresponding virtual machine in time to execute the intelligent contract byte codes.
The above embodiment shows that, in the prior art, the intelligent contract codes are stored as a whole, so when different intelligent contracts are stored in the block chain, code segments corresponding to the same function in at least two different intelligent contracts are repeatedly stored, which results in low efficiency and poor flexibility in storing the intelligent contract codes in the block chain. Based on this, the technical scheme of the invention divides the intelligent contract code to obtain the divided code segments, and stores the divided code segments to the block chain, so that the situation that the code segments corresponding to the same function functions of different intelligent contracts are repeatedly stored due to the integral storage of the intelligent contract code can be avoided, the efficiency of storing the intelligent contract code by the block chain can be effectively improved, the flexibility of the intelligent contract code storage can be higher, and the actual requirements of the block chain network can be better met. Specifically, when the first blockchain node determines that the intelligent contract deployment transaction meets the execution condition, the intelligent contract source code in the intelligent contract deployment transaction is converted into the intelligent contract operation code, so that the intelligent contract deployment transaction can be accurately segmented on the basis of the segmentation field in the intelligent contract operation code. And then at least one key field is used as a segmentation field for segmenting the intelligent contract operation code, so that the intelligent contract operation code can be timely and accurately segmented into a plurality of code slices which can be flexibly stored. Then, for the code slice corresponding to each split field, if it is determined that the hash value of the code slice corresponding to the split field does not exist in the storage region for storing the code slice in the block chain, the hash value of the code slice corresponding to the split field and the code slice corresponding to the split field are stored into the block chain, and if it is determined that the hash value of the code slice corresponding to the split field exists in the storage region for storing the code slice in the block chain, the hash value of the code slice corresponding to the split field and the code slice corresponding to the split field are not stored into the block chain, so that the situation that the code segments corresponding to the same function functions of different intelligent contracts are repeatedly stored can be avoided, the storage space occupied by the stored intelligent contract codes is facilitated to be reduced, and the efficiency of the block chain for storing the intelligent contract codes can be effectively improved.
Based on the same technical concept, fig. 5 exemplarily illustrates a storage apparatus for a blockchain intelligent contract according to an embodiment of the present invention, which may execute a flow of a storage method for the blockchain intelligent contract. The storage device of the intelligent block chain contract in the embodiment of the invention is suitable for a block chain network of N block chain nodes.
As shown in fig. 5, the apparatus includes:
the analysis unit 501 is configured to, when it is determined that the intelligent contract deployment transaction meets the execution condition, analyze the intelligent contract deployment transaction to obtain an intelligent contract source code;
a processing unit 502, configured to convert the intelligent contract source code into an intelligent contract operation code; taking at least one key field as a segmentation field for segmenting the intelligent contract operation code, and segmenting the intelligent contract operation code to obtain a code slice corresponding to the at least one segmentation field; the at least one key field is a field in the intelligent contract operation code; and for the code slice corresponding to each segmentation field, when the hash value of the code slice corresponding to the segmentation field does not exist in the block chain, storing the hash value of the code slice corresponding to the segmentation field and the code slice corresponding to the segmentation field into the block chain.
Optionally, the processing unit 502 is specifically configured to:
compiling the intelligent contract source code into intelligent contract byte codes through a compiler;
and converting the intelligent contract bytecode into the intelligent contract operation code through a transcoder.
Optionally, the processing unit 502 is specifically configured to:
detecting the content of the intelligent contract operation code, when at least one first segmentation field belonging to a first level is determined to exist in the intelligent contract operation code, sequentially segmenting the code segment where the at least one first segmentation field is located from the intelligent contract operation code according to the position sequence of the at least one first segmentation field in the intelligent contract operation code, so as to obtain a code segment corresponding to the at least one first segmentation field belonging to the first level, and taking the code segment corresponding to the at least one first segmentation field as a code slice corresponding to the at least one first segmentation field; the first sliced field is any one of the at least one sliced field.
Optionally, the processing unit 502 is further configured to:
after obtaining a code segment corresponding to at least one first segmentation field belonging to a first level, performing content detection on the code segment where the first segmentation field is located aiming at a code slice corresponding to each first segmentation field belonging to the first level, when determining that at least one second segmentation field belonging to a second level exists in the code segment where the first segmentation field is located, sequentially segmenting the code segment where the at least one second segmentation field is located from the code segment where the first segmentation field is located according to the position sequence of the at least one second segmentation field in the code segment where the first segmentation field is located, thereby obtaining a code segment corresponding to the at least one second segmentation field belonging to the second level, and taking the code segment corresponding to the at least one second segmentation field as the code slice corresponding to the at least one second segmentation field; the second sliced field is any one of the at least one sliced field.
Optionally, the at least one slicing field includes a tag field;
the processing unit 502 is specifically configured to:
for a code slice corresponding to each segmentation field, if a push tag instruction exists in the code slice corresponding to the segmentation field, marking the segmentation field as an intermediate field, and replacing the intermediate field with a final field when a code fragment in which the tag field pointed by the push tag instruction is located is determined to be a fragment which cannot be segmented;
according to the terminal field, converting a code slice corresponding to the segmented field into a first byte code slice through a code converter, and performing hash operation on the first byte code slice to obtain a hash value of the first byte code slice;
if the hash value of the first bytecode slice is determined not to exist in the block chain, storing the hash value of the first bytecode slice and the first bytecode slice to the block chain.
Optionally, the processing unit 502 is further configured to:
if the fact that the push tag instruction does not exist in the code slice corresponding to the segmentation field is determined, converting the code slice corresponding to the segmentation field into a second byte code slice through the code converter;
performing hash operation on the second bytecode slice to obtain a hash value of the second bytecode slice;
if the hash value of the second bytecode slice is determined not to exist in the block chain, storing the hash value of the second bytecode slice and the second bytecode slice to the block chain.
Optionally, the processing unit 502 is further configured to:
after the hash value of the code slice corresponding to the splitting field and the code slice corresponding to the splitting field are stored in the block chain, when an intelligent contract calling request is detected, inquiring a corresponding intelligent contract from the block chain based on an intelligent contract address in the intelligent contract calling request, and acquiring the hash value of each byte code slice stored in the intelligent contract; the hash values of the byte code slices are arranged according to the position sequence of the byte code slices in the intelligent contract;
inquiring corresponding byte code slices from a storage area for storing the byte code slices in the block chain according to the hash values of the byte code slices;
splicing the byte code slices according to the position sequence of the hash value of each byte code slice in the intelligent contract to obtain intelligent contract byte codes;
loading the intelligent contract bytecode to a virtual machine for executing an intelligent contract; the virtual machine is to execute the intelligent contract bytecode.
Based on the same technical concept, an embodiment of the present invention further provides a computing device, as shown in fig. 6, including at least one processor 601 and a memory 602 connected to the at least one processor, where a specific connection medium between the processor 601 and the memory 602 is not limited in the embodiment of the present invention, and the processor 601 and the memory 602 are connected through a bus in fig. 6 as an example. The bus may be divided into an address bus, a data bus, a control bus, etc.
In the embodiment of the present invention, the memory 602 stores instructions executable by the at least one processor 601, and the at least one processor 601 may execute the steps included in the foregoing method for storing a blockchain intelligent contract by executing the instructions stored in the memory 602.
The processor 601 is a control center of the computing device, and may connect various parts of the computing device by using various interfaces and lines, and implement data processing by executing or executing instructions stored in the memory 602 and calling data stored in the memory 602. Optionally, the processor 601 may include one or more processing units, and the processor 601 may integrate an application processor and a modem processor, where the application processor mainly processes an operating system, a user interface, an application program, and the like, and the modem processor mainly processes an issued instruction. It will be appreciated that the modem processor described above may not be integrated into the processor 601. In some embodiments, processor 601 and memory 602 may be implemented on the same chip, or in some embodiments, they may be implemented separately on separate chips.
The processor 601 may be a general-purpose processor, such as a Central Processing Unit (CPU), a digital signal processor, an Application Specific Integrated Circuit (ASIC), a field programmable gate array or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination thereof, configured to implement or perform the methods, steps, and logic blocks disclosed in the embodiments of the present invention. A general purpose processor may be a microprocessor or any conventional processor or the like. Storage method in conjunction with blockchain intelligent contracts the steps of the disclosed method may be directly implemented as a hardware processor or implemented by a combination of hardware and software modules in the processor.
The memory 602, which is a non-volatile computer-readable storage medium, may be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. The Memory 602 may include at least one type of storage medium, and may include, for example, a flash Memory, a hard disk, a multimedia card, a card-type Memory, a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Programmable Read Only Memory (PROM), a Read Only Memory (ROM), a charge Erasable Programmable Read Only Memory (EEPROM), a magnetic Memory, a magnetic disk, an optical disk, and the like. The memory 602 is any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited to such. The memory 602 in the embodiments of the present invention may also be circuitry or any other device capable of performing a storage function for storing program instructions and/or data.
Based on the same technical concept, the embodiment of the present invention further provides a computer-readable storage medium, which stores a computer program executable by a computing device, and when the program runs on the computing device, the computer program causes the computing device to execute the steps of the storage method of the blockchain intelligent contract.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present application and their equivalents, the present invention is also intended to include such modifications and variations.

Claims (9)

1. A method for storing a blockchain intelligent contract, the method being applicable to a blockchain network having N blockchain nodes, the method comprising:
when the first block chain node determines that the intelligent contract deployment transaction meets the execution condition, analyzing the intelligent contract deployment transaction to obtain an intelligent contract source code; the first blockchain node is any one of the N blockchain nodes;
the first block link point converts the intelligent contract source code into an intelligent contract operation code;
the first block chain node uses at least one key field as a segmentation field for segmenting the intelligent contract operation code, and the intelligent contract operation code is segmented to obtain a code slice corresponding to at least one segmentation field; the at least one key field is a field in the intelligent contract operation code;
for a code slice corresponding to each segmentation field, when the first block chain node determines that the hash value of the code slice corresponding to the segmentation field does not exist in a block chain, storing the hash value of the code slice corresponding to the segmentation field and the code slice corresponding to the segmentation field into the block chain;
the first block chain node uses at least one key field as a splitting field for splitting the intelligent contract operation code, and splits the intelligent contract operation code, including:
the first block chain link point detects the content of the intelligent contract operation code, when at least one first segmentation field belonging to a first level is determined to exist in the intelligent contract operation code, the code segment where the at least one first segmentation field is located is sequentially segmented from the intelligent contract operation code according to the position sequence of the at least one first segmentation field in the intelligent contract operation code, so that the code segment corresponding to the at least one first segmentation field belonging to the first level is obtained, and the code segment corresponding to the at least one first segmentation field is used as the code segment corresponding to the at least one first segmentation field; the first sliced field is any one of the at least one sliced field.
2. The method of claim 1, wherein the first block link point converts the intelligent contract source code into intelligent contract operation code, comprising:
the first block link point compiles the intelligent contract source code into intelligent contract byte codes through a compiler;
the first block link point converts the intelligent contract bytecode to the intelligent contract opcode through a transcoder.
3. The method of claim 1, wherein after obtaining the code fragment corresponding to the at least one first segmentation field belonging to the first hierarchy, further comprising:
aiming at a code slice corresponding to each first segmentation field belonging to a first level, the first block chain link point performs content detection on the code segment where the first segmentation field is located, when at least one second segmentation field belonging to a second level is determined to exist in the code segment where the first segmentation field is located, the code segment where the at least one second segmentation field is located is sequentially segmented from the code segment where the first segmentation field is located according to the position sequence of the at least one second segmentation field in the code segment where the first segmentation field is located, so that the code segment corresponding to the at least one second segmentation field belonging to the second level is obtained, and the code segment corresponding to the at least one second segmentation field is used as the code slice corresponding to the at least one second segmentation field; the second sliced field is any one of the at least one sliced field.
4. The method of claim 1, wherein the at least one sliced field comprises a tag field;
for a code slice corresponding to each splitting field, when the first blockchain node determines that the hash value of the code slice corresponding to the splitting field does not exist in a blockchain, the storing the hash value of the code slice corresponding to the splitting field and the code slice corresponding to the splitting field into the blockchain includes:
for a code slice corresponding to each segmentation field, if the first block chain node determines that a push tag instruction exists in the code slice corresponding to the segmentation field, marking the segmentation field as an intermediate field, and replacing the intermediate field with a terminal field when determining that a code segment where the tag field pointed by the push tag instruction is located is a segment which cannot be segmented;
the first block chain node converts the code slice corresponding to the segmentation field into a first byte code slice through a code converter according to the terminal field, and performs hash operation on the first byte code slice to obtain a hash value of the first byte code slice;
and if the first block chain node determines that the hash value of the first byte code slice does not exist in the block chain, storing the hash value of the first byte code slice and the first byte code slice into the block chain.
5. The method of claim 4, wherein the method further comprises:
if the first block link node determines that the push tag instruction does not exist in the code slice corresponding to the segmentation field, converting the code slice corresponding to the segmentation field into a second byte code slice through the code converter;
the first block link point performs hash operation on the second bytecode slice to obtain a hash value of the second bytecode slice;
and if the first block chain node determines that the hash value of the second byte code slice does not exist in the block chain, storing the hash value of the second byte code slice and the second byte code slice into the block chain.
6. The method of any of claims 1 to 5, further comprising, after storing the hash values of the code slices corresponding to the slicing fields and the code slices corresponding to the slicing fields to the blockchain:
when the first block chain node detects an intelligent contract calling request, inquiring a corresponding intelligent contract from a block chain based on an intelligent contract address in the intelligent contract calling request, and acquiring a hash value of each byte code slice stored in the intelligent contract; the hash values of the byte code slices are arranged according to the position sequence of the byte code slices in the intelligent contract;
the first block link point queries each corresponding bytecode slice from a storage area for storing the bytecode slice in the block chain according to the hash value of each bytecode slice;
the first block chain link points splice the byte code slices according to the position sequence of the hash values of the byte code slices in the intelligent contract to obtain intelligent contract bytes;
the first block link point loads the intelligent contract bytecode to a virtual machine for executing intelligent contracts; the virtual machine is used for executing the intelligent contract bytecode.
7. A storage device for blockchain intelligent contracts, adapted for a blockchain network having N blockchain nodes, the device comprising:
the analysis unit is used for analyzing the intelligent contract deployment transaction to obtain an intelligent contract source code when the intelligent contract deployment transaction meets the execution condition;
the processing unit is used for converting the intelligent contract source code into an intelligent contract operation code; taking at least one key field as a segmentation field for segmenting the intelligent contract operation code, and segmenting the intelligent contract operation code to obtain a code slice corresponding to the at least one segmentation field; the at least one key field is a field in the intelligent contract operation code; for a code slice corresponding to each segmentation field, when the hash value of the code slice corresponding to the segmentation field does not exist in a block chain, storing the hash value of the code slice corresponding to the segmentation field and the code slice corresponding to the segmentation field into the block chain;
the processing unit is specifically configured to:
detecting the content of the intelligent contract operation code, when at least one first segmentation field belonging to a first level is determined to exist in the intelligent contract operation code, sequentially segmenting the code segment where the at least one first segmentation field is located from the intelligent contract operation code according to the position sequence of the at least one first segmentation field in the intelligent contract operation code, so as to obtain a code segment corresponding to the at least one first segmentation field belonging to the first level, and taking the code segment corresponding to the at least one first segmentation field as a code slice corresponding to the at least one first segmentation field; the first sliced field is any one of the at least one sliced field.
8. A computing device comprising at least one processor and at least one memory, wherein the memory stores a computer program that, when executed by the processor, causes the processor to perform the method of any of claims 1 to 6.
9. A computer-readable storage medium, storing a computer program executable by a computing device, the program, when run on the computing device, causing the computing device to perform the method of any of claims 1 to 6.
CN202111055168.9A 2021-09-09 2021-09-09 Method and device for storing intelligent contracts of block chains Active CN114091111B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111055168.9A CN114091111B (en) 2021-09-09 2021-09-09 Method and device for storing intelligent contracts of block chains

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111055168.9A CN114091111B (en) 2021-09-09 2021-09-09 Method and device for storing intelligent contracts of block chains

Publications (2)

Publication Number Publication Date
CN114091111A CN114091111A (en) 2022-02-25
CN114091111B true CN114091111B (en) 2022-11-18

Family

ID=80296400

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111055168.9A Active CN114091111B (en) 2021-09-09 2021-09-09 Method and device for storing intelligent contracts of block chains

Country Status (1)

Country Link
CN (1) CN114091111B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109634932A (en) * 2018-11-30 2019-04-16 北京瑞卓喜投科技发展有限公司 A kind of intelligence contract storage method and storage system
CN110032547A (en) * 2019-01-29 2019-07-19 香港贝尔科技有限公司 File stores improved method under a kind of distributed environment
EP3724806A1 (en) * 2017-12-13 2020-10-21 Nchain Holdings Limited Blockchain-implemented systems and methods for concurrent bytecode interpretation

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101706825B (en) * 2009-12-10 2011-04-20 华中科技大学 Replicated data deleting method based on file content types
CN102469142A (en) * 2010-11-16 2012-05-23 英业达股份有限公司 Data transmission method for data deduplication program
CN105446964B (en) * 2014-05-30 2019-04-26 国际商业机器公司 The method and device of data de-duplication for file
CN110188097A (en) * 2019-04-19 2019-08-30 阿里巴巴集团控股有限公司 The storage of intelligent contract, execution method and device and electronic equipment in block chain
US20200202355A1 (en) * 2019-04-19 2020-06-25 Alibaba Group Holding Limited Storage and execution of smart contracts in blockchains
CN110147202A (en) * 2019-05-15 2019-08-20 杭州云象网络技术有限公司 A method of reducing block chain intelligence contract code storage volume
CN110825363B (en) * 2019-11-01 2024-05-17 北京知道创宇信息技术股份有限公司 Intelligent contract acquisition method and device, electronic equipment and storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP3724806A1 (en) * 2017-12-13 2020-10-21 Nchain Holdings Limited Blockchain-implemented systems and methods for concurrent bytecode interpretation
CN109634932A (en) * 2018-11-30 2019-04-16 北京瑞卓喜投科技发展有限公司 A kind of intelligence contract storage method and storage system
CN110032547A (en) * 2019-01-29 2019-07-19 香港贝尔科技有限公司 File stores improved method under a kind of distributed environment

Also Published As

Publication number Publication date
CN114091111A (en) 2022-02-25

Similar Documents

Publication Publication Date Title
US8914780B2 (en) Incremental generation of managed assemblies
US7861222B2 (en) Discoscript: a simplified distributed computing scripting language
US9152389B2 (en) Trace generating unit, system, and program of the same
CN107766130B (en) Method and device for migrating virtual machine to container
CN109032631B (en) Application program patch package obtaining method and device, computer equipment and storage medium
CN110231994B (en) Memory analysis method, memory analysis device and computer readable storage medium
CN108304175B (en) Code file isolation packaging method and device
CN110599183B (en) Intelligent contract calling method and device and storage medium
US10248409B1 (en) Limiting the effects of source code patches on corresponding native-code patches
US20180129494A1 (en) Detect application defects by correlating contracts in application dependencies
CN111694750A (en) Method and device for constructing software testing environment
US11036527B2 (en) Class splitting in object-oriented environments
CN112487092B (en) Intelligent contract calling method and device based on blockchain
CN111352631B (en) Interface compatibility detection method and device
CN114091111B (en) Method and device for storing intelligent contracts of block chains
CN114816772B (en) Debugging method, debugging system and computing device for application running based on compatible layer
CN111880803B (en) Software construction method and device applied to multiple platforms
CN113721928A (en) Binary analysis-based dynamic library clipping method
CN113867709A (en) Block chain intelligent contract read-write set construction method and device
CN103577170A (en) Construction method and construction device for web application
US9720660B2 (en) Binary interface instrumentation
CN106897588B (en) Processing method and device of label function
CN114201116B (en) Intelligent contract deployment method, device, equipment, medium and program product
CN110879722B (en) Method and device for generating logic schematic diagram and computer storage medium
CN117851505A (en) Block slicing method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant