Smart contract execution method, device, storage medium and electronic device

By converting third-party functional components into binary resources and saving them in the blockchain, the problem of limited functions of smart contracts is solved, the richness and diversity of functions are achieved, and the limitations of contract development languages ​​are broken.

CN113472512BActive Publication Date: 2024-11-12NEUSOFT CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110648090.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-06-10
Publication Date
2024-11-12
Estimated Expiration
2041-06-10

AI Technical Summary

Technical Problem

In actual applications, smart contracts are limited by development language and contract capacity, and their functions are relatively limited, making it difficult to achieve diversified functional requirements.

Method used

By converting third-party functional components into binary resources and saving them in the blockchain, they are obtained and converted into executable files based on contract call requests to meet functional needs, breaking through the limitations of contract development languages.

Benefits of technology

It realizes the functions of rich smart contracts, avoids the need to write corresponding functional codes in the contract, and improves the functional diversity and usability of the contract.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113472512B_ABST
    Figure CN113472512B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a smart contract execution method, device, storage medium and electronic device, the method comprising: in response to receiving a contract call request, determining the functional requirements corresponding to the contract call request according to the call parameters in the contract call request; obtaining binary resources corresponding to the functional requirements from the blockchain, the binary resources being obtained by converting third-party functional components; converting the obtained binary resources into an executable file; and executing the executable file to meet the functional requirements. In this way, when faced with relevant functional requirements, there is no need to write the corresponding functional code in the smart contract, but the function can be implemented by calling the binary resources of the third-party functional components. In other words, the functions of the smart contract can be enriched by the above technical solution.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of blockchain technology, and in particular, to a smart contract execution method, device, storage medium and electronic device. Background Art

[0002] Blockchain technology is a technology that can collectively maintain a reliable database in a decentralized and trustless manner. In the blockchain network, contract participants can formulate a series of smart contracts. In this way, after the contract is deployed, the relevant operations can be automatically executed through the contract to achieve the corresponding functions.

[0003] However, smart contracts still face many difficulties in practical applications. For example, due to limitations such as development language and contract capacity, smart contracts still have technical problems with limited functions. Summary of the invention

[0004] The purpose of the present disclosure is to provide a smart contract execution method, device, storage medium and electronic device to solve the above-mentioned related technical problems.

[0005] In order to achieve the above objective, according to a first aspect of an embodiment of the present disclosure, a smart contract execution method is provided, comprising:

[0006] In response to receiving a contract call request, determining a functional requirement corresponding to the contract call request according to a call parameter in the contract call request;

[0007] Obtaining a binary resource corresponding to the functional requirement from the blockchain, wherein the binary resource is obtained by transforming a third-party functional component;

[0008] Convert the acquired binary resource into an executable file;

[0009] The executable file is executed to meet the functional requirement.

[0010] Optionally, in response to receiving a contract call request, before determining a functional requirement corresponding to the contract call request according to a call parameter in the contract call request, the method further includes:

[0011] Acquire the third-party functional component;

[0012] Convert the executable file of the third-party functional component into a binary resource;

[0013] Saving the binary resource to the blockchain;

[0014] The storage location information of the binary resource is recorded.

[0015] Optionally, the step of saving the binary resource to a blockchain includes:

[0016] When the capacity of the binary resource is greater than the block capacity threshold, dividing the binary resource into a plurality of resource slices;

[0017] Saving each of the resource shards in the blockchain;

[0018] The storage location information includes an offset between a block where a target resource slice is located and a block where a previous resource slice of the target resource slice is located, and the target resource slice is any resource slice among the multiple resource slices except the first resource slice.

[0019] Optionally, the binary resource includes a plurality of resource slices, the contract includes a homomorphic check field and a homomorphic checksum, the homomorphic check field includes a digital summary of each of the resource slices, and the homomorphic checksum is determined by:

[0020] For each of the digital summaries, calculating a ciphertext corresponding to the digital summaries based on the target homomorphic encryption key;

[0021] Summing each of the ciphertexts to obtain the homomorphic checksum;

[0022] Before obtaining the binary resource corresponding to the functional requirement from the blockchain, the method further includes:

[0023] Calculate a target homomorphic checksum according to the homomorphic encryption key and the homomorphic check field;

[0024] Determine whether the target homomorphic checksum is consistent with the homomorphic checksum stored in the contract.

[0025] Optionally, for each of the digital summaries, calculating a ciphertext corresponding to the digital summaries based on a homomorphic encryption key includes:

[0026] Calculate the ciphertext c corresponding to the digital summary m by the following calculation formula m :

[0027] c m =E(m,r)=g m r t modt 2 , r∈Z n ;

[0028] The summing each of the ciphertexts includes: calculating a homomorphic checksum c by the following calculation formula:

[0029]

[0030] Wherein, the target homomorphic encryption key is (t, g, r), i is the number value of the digital summary, x∈[1, i] and x is an integer, mod is the remainder function, Z n The domain of integers.

[0031] Optionally, the target homomorphic encryption key is determined by:

[0032] Randomly determine a first prime number and a second prime number, wherein the number of digits of the first prime number and the second prime number is the same, and the number of digits of the first prime number and the second prime number is greater than a digit threshold;

[0033] Using the product of the first prime number and the second prime number as parameter t in the target homomorphic encryption key;

[0034] Determine a target random integer as a parameter g in the target homomorphic encryption key, where and the parameter t divides the order of the parameter g, There exists a multiplicative inverse for the remainder system;

[0035] From Z n A random number is determined as a parameter r in the target homomorphic encryption key.

[0036] Optionally, the obtaining a binary resource corresponding to the functional requirement from the blockchain includes:

[0037] When the capacity of the binary resource is greater than the memory capacity threshold, dividing the binary resource into a plurality of binary resource slices;

[0038] The binary resource fragments are loaded into the memory in sequence for release.

[0039] According to a second aspect of an embodiment of the present disclosure, there is provided a smart contract execution device, comprising:

[0040] A determination module, configured to, in response to receiving a contract call request, determine a functional requirement corresponding to the contract call request according to a call parameter in the contract call request;

[0041] A resource acquisition module, used to acquire binary resources corresponding to the functional requirements from the blockchain, wherein the binary resources are obtained by converting third-party functional components;

[0042] A first resource conversion module, used to convert the acquired binary resource into an executable file;

[0043] An execution module is used to execute the executable file to meet the functional requirements.

[0044] Optionally, the device further comprises:

[0045] A functional component acquisition module, used for acquiring the third-party functional component before the determination module determines the functional requirement corresponding to the contract call request;

[0046] A second resource conversion module, used to convert the executable file of the third-party functional component into a binary resource;

[0047] A resource storage module, used to save the binary resources into the blockchain;

[0048] The recording module is used to record the storage location information of the binary resource.

[0049] Optionally, the resource storage module includes:

[0050] A resource segmentation submodule, configured to segment the binary resource into a plurality of resource slices when the capacity of the binary resource is greater than a block capacity threshold;

[0051] A resource storage submodule, used to store each resource shard in the blockchain;

[0052] The storage location information includes an offset between a block where a target resource slice is located and a block where a previous resource slice of the target resource slice is located, and the target resource slice is any resource slice among the multiple resource slices except the first resource slice.

[0053] Optionally, the binary resource includes a plurality of resource slices, the contract includes a homomorphic check field and a homomorphic checksum, the homomorphic check field includes a digital summary of each of the resource slices, and the homomorphic checksum is determined in the following manner: for each of the digital summaries, a ciphertext corresponding to the digital summary is calculated based on a target homomorphic encryption key; each of the ciphertexts is summed to obtain the homomorphic checksum;

[0054] The device also includes:

[0055] A calculation module, configured to calculate a target homomorphic checksum according to the homomorphic encryption key and the homomorphic check field before the resource acquisition module acquires the binary resource corresponding to the functional requirement from the blockchain;

[0056] A checksum determination module is used to determine whether the target homomorphic checksum is consistent with the homomorphic checksum stored in the contract.

[0057] Optionally, for each of the digital summaries, calculating a ciphertext corresponding to the digital summaries based on a homomorphic encryption key includes:

[0058] Calculate the ciphertext c corresponding to the digital summary m by the following calculation formula m :

[0059] c m =E(m,r)=g m r t modt 2 , r∈Z n ;

[0060] The summing each of the ciphertexts includes: calculating a homomorphic checksum c by the following calculation formula:

[0061]

[0062] Wherein, the target homomorphic encryption key is (t, g, r), i is the number value of the digital summary, x∈[1, i] and x is an integer, mod is the remainder function, Z n The domain of integers.

[0063] Optionally, the target homomorphic encryption key is determined by:

[0064] Randomly determine a first prime number and a second prime number, wherein the number of digits of the first prime number and the second prime number is the same, and the number of digits of the first prime number and the second prime number is greater than a digit threshold;

[0065] Using the product of the first prime number and the second prime number as parameter t in the target homomorphic encryption key;

[0066] Determine a target random integer as a parameter g in the target homomorphic encryption key, where and the parameter t divides the order of the parameter g, There exists a multiplicative inverse for the remainder system;

[0067] From Z n A random number is determined as a parameter r in the target homomorphic encryption key.

[0068] Optionally, the obtaining a binary resource corresponding to the functional requirement from the blockchain includes:

[0069] When the capacity of the binary resource is greater than the memory capacity threshold, dividing the binary resource into a plurality of binary resource slices;

[0070] The binary resource fragments are loaded into the memory in sequence for release.

[0071] According to a third aspect of an embodiment of the present disclosure, there is provided a non-temporary computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, the steps of any one of the methods described in the first aspect are implemented.

[0072] According to a fourth aspect of an embodiment of the present disclosure, there is provided an electronic device, including:

[0073] a memory having a computer program stored thereon;

[0074] A processor is used to execute the computer program in the memory to implement the steps of any one of the methods described in the first aspect above.

[0075] The above technical solution can at least have the following beneficial effects:

[0076] By converting the third-party functional components into binary resources, the obtained binary resources can be saved in the blockchain. In this way, after receiving the contract call request, the contract execution device can determine the functional requirements corresponding to the contract call request according to the call parameters in the contract call request, and obtain the corresponding binary resources from the blockchain according to the functional requirements. After obtaining the binary resources, the obtained binary resources can be converted into executable files, and the functional requirements can be met by executing the executable files. In this way, when facing relevant functional requirements, there is no need to write corresponding functional codes in the smart contract, but the function can be realized by calling the binary resources of the third-party functional components. In other words, the functions of the smart contract can be enriched by the above technical solution. In addition, by converting the third-party functional components into binary resources and converting the binary resources into executable files, it is also possible to break through the limitations of the contract development language, thereby further enriching the functions of the smart contract.

[0077] Other features and advantages of the present disclosure will be described in detail in the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS

[0078] The accompanying drawings are used to provide a further understanding of the present disclosure and constitute a part of the specification. Together with the following specific embodiments, they are used to explain the present disclosure but do not constitute a limitation of the present disclosure. In the accompanying drawings:

[0079] Figure 1 It is a schematic diagram of the execution of a contract shown in an exemplary embodiment of the present disclosure.

[0080] Figure 2 It is a flowchart of a smart contract execution method shown in an exemplary embodiment of the present disclosure.

[0081] Figure 3 It is a flowchart of a smart contract execution method shown in an exemplary embodiment of the present disclosure.

[0082] Figure 4 It is a schematic diagram of a data conversion process shown in an exemplary embodiment of the present disclosure.

[0083] Figure 5It is a block diagram of a smart contract execution device shown in an exemplary embodiment of the present disclosure.

[0084] Figure 6 It is a block diagram of an electronic device shown in an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION

[0085] The specific implementation of the present disclosure is described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation described herein is only used to illustrate and explain the present disclosure, and is not used to limit the present disclosure.

[0086] Before introducing the smart contract execution method, device, storage medium and electronic device of the present invention, the application scenarios of the present invention are first introduced.

[0087] A smart contract (hereinafter referred to as a contract in this disclosure) can be considered as an agreement that can automatically execute tasks that would otherwise be done manually. By constructing and deploying contracts, a variety of operations can be implemented in a blockchain network. However, contracts are still subject to many limitations in their actual application, such as limitations on development languages, limitations on contract capacity, etc., which ultimately result in fewer functions that can be implemented by contracts.

[0088] Figure 1 This is a schematic diagram of the execution of a contract shown in the present disclosure. In related scenarios, in order to enable the contract to achieve more functions, necessary off-chain environment information can be recorded in the blockchain network. Accordingly, the contract can read this information and call the interface of the off-chain environment, and then the off-chain environment performs related operations. After the off-chain environment performs related operations, the contract virtual machine can receive the execution results of the off-chain environment, thereby completing the contract call.

[0089] It is worth noting that since the off-chain environment cannot be guaranteed to be credible, this approach still has the problem of low security. Moreover, after the off-chain environment changes, the off-chain environment information recorded on the blockchain may be inconsistent with the actual off-chain environment information, thus affecting the availability of the contract. In addition, there may be many interference factors in the interaction process between the contract virtual machine and the off-chain environment, which also reduces the availability of the contract.

[0090] To this end, the present disclosure provides a smart contract execution method. Figure 2 is a flow chart of a smart contract execution method shown in the present disclosure, such as Figure 2 As shown, the method includes:

[0091] In step 21, in response to receiving a contract call request, a functional requirement corresponding to the contract call request is determined according to a call parameter in the contract call request.

[0092] Among them, the method provided in this embodiment can be applied to the contract execution device. According to the difference of the blockchain network, the contract execution device may have corresponding differences. For example, in Ethereum, the contract execution device may refer to the Ethereum virtual machine, and in the related alliance chain network, the contract execution device may also be some contract containers.

[0093] Thus, the receiving of the contract call request may refer to the contract execution device receiving the relevant contract call parameters. Accordingly, the contract execution device may determine the functional requirements associated with the contract call request based on the contract call parameters.

[0094] It should be understood that the functions of the contract can be set according to the requirements when the contract is formulated. These functions may be one or more, such as accessing pictures, performing encryption operations, performing decryption operations, etc., and the present disclosure does not limit this. In specific implementation, different functions can be called by calling the contract through different calling parameters.

[0095] In step 22, a binary resource corresponding to the functional requirement is obtained from the blockchain, and the binary resource is obtained by converting a third-party functional component.

[0096] Among them, the third-party functional components can be, for example, processing tools developed for different application requirements. Due to the restrictions of the contract on the development language, these third-party functional components are usually difficult to run directly in the contract execution device. In addition, it is also difficult to implement the functions of the corresponding third-party functional components through the contract development language.

[0097] Therefore, in this embodiment, the executable file corresponding to the third-party functional component can be converted into a binary resource, and the binary resource can be stored in the blockchain. For example, for a decryption component written in C language, the decryption component can be compiled into an .exe executable file, and the .exe executable file can be converted into a binary resource and stored in the blockchain.

[0098] In this way, when the functional requirement corresponding to the contract call request is decryption, the binary resource can be obtained from the blockchain. For example, in some implementation scenarios, the executable file can be embedded into the contract in the form of a binary stream when the contract is constructed, and the relevant resource location information can be recorded. In this case, the binary resource of the .exe executable file can be obtained according to the resource location information saved in the contract.

[0099] In step 23, the acquired binary resource is converted into an executable file.

[0100] Using the above example, the acquired binary resources can be converted back into an .exe executable file.

[0101] Thus, in step 24, the executable file is executed to meet the functional requirements.

[0102] For example, the .exe executable file may be executed to implement the functions corresponding to the decryption component originally written in C language.

[0103] The above technical solution converts the third-party functional components into binary resources, so that the obtained binary resources can be saved in the blockchain. In this way, after receiving the contract call request, the contract execution device can determine the functional requirements corresponding to the contract call request according to the call parameters in the contract call request, and obtain the corresponding binary resources from the blockchain according to the functional requirements. After obtaining the binary resources, the obtained binary resources can be converted into executable files, and the functional requirements can be met by executing the executable files.

[0104] In this way, when faced with relevant functional requirements, there is no need to write corresponding functional codes in the smart contract, but the functions can be implemented by calling the binary resources of the third-party functional components. In other words, the functions of the smart contract can be enriched by the above technical solution. In addition, by converting the third-party functional components into binary resources and converting the binary resources into executable files, the limitations of the contract development language can also be broken. For example, in the above embodiment, assuming that the contract development language is the go language, the above technical solution can also be used to execute the functions corresponding to the decryption component originally written in C language in the contract execution device. Therefore, the above technical solution can break through the limitations of the contract development language and provide a basis for the contract to realize more functions.

[0105] Figure 3 is a flow chart of a smart contract execution method shown in an exemplary embodiment of the present disclosure, such as Figure 3 As shown, the method includes:

[0106] S31, obtaining a third-party functional component, wherein the third-party functional component may be, for example, a processing tool developed for different application requirements, such as an image access tool, an encryption tool, a decryption tool, and the like.

[0107] S32, converting the executable file of the third-party functional component into a binary resource.

[0108] S33, saving the binary resource in the blockchain.

[0109] For example, for a decryption component written in C language, the decryption component can be compiled into an .exe executable file, and the .exe executable file can be converted into a binary resource and stored in the blockchain.

[0110] S34, recording the storage location information of the binary resource.

[0111] Here, the storage location information may be, for example, a hash value of a storage block corresponding to the binary resource. Thus, when the binary resource needs to be acquired, the corresponding block may be searched according to the hash value, and the binary resource stored in the block may be acquired.

[0112] In some possible implementation scenarios, the capacity of the binary resource may also exceed the capacity limit of the block. In this case, step S34 further includes:

[0113] When the capacity of the binary resource is greater than the block capacity threshold, the binary resource is divided into a plurality of resource slices, and each of the resource slices is saved in the blockchain.

[0114] The number of resource slices can be set based on the capacity of the binary resource and the block capacity threshold. When there are multiple resource slices, in order to facilitate the subsequent search for resource slices, the offsets between the blocks stored in adjacent resource slices can be saved. That is, in this case, the storage location information can include the offset between the block where the target resource slice is located and the block where the previous resource slice of the target resource slice is located. The target resource slice is any resource slice among the multiple resource slices except the first resource slice.

[0115] S35, in response to receiving the contract call request, determining the functional requirements corresponding to the contract call request according to the call parameters in the contract call request.

[0116] S36, obtaining binary resources corresponding to the functional requirements from the blockchain.

[0117] In a possible implementation, obtaining a binary resource corresponding to the functional requirement from the blockchain includes:

[0118] When the capacity of the binary resource is greater than the memory capacity threshold, dividing the binary resource into a plurality of binary resource slices;

[0119] The binary resource fragments are loaded into the memory in sequence for release.

[0120] That is, the contract execution device can first store some binary resources in the memory for release, and then replace the resources in the memory after the release is completed. In this way, the problem of unusable resources due to the memory size limit of the virtual machine can be avoided.

[0121] S37, converting the acquired binary resource into an executable file.

[0122] S38, executing the executable file to meet the functional requirements.

[0123] For steps S35 to S38, please refer to the above Figure 2 For the sake of brevity, the present disclosure will not be repeated here.

[0124] The above technical solution can convert third-party functional components into binary resources and deploy them to the blockchain. In this way, when the contract needs to execute related functions, the binary resources can be obtained and converted into executable files. In this way, by executing the executable files, the functions corresponding to the third-party functional components can be implemented in the contract, thereby enriching the functions of the smart contract. Moreover, this method can also break through the limitations of the contract development language.

[0125] In addition, it is worth noting that for the convenience and simplicity of description, the embodiments described in the specification are all preferred embodiments, and the parts involved are not necessarily necessary for the present invention. For example, in some possible implementations, the above steps S31 and S32 can also be performed by relevant nodes. Accordingly, the contract execution device can obtain the binary resources calculated by the relevant nodes and save the binary resources to the blockchain.

[0126] Figure 4 It is a schematic diagram of a data conversion process shown in the present disclosure. In some possible implementations, the binary stream of the resource can be written into the blockchain ledger through the resource writing contract, and the binary resource can be obtained from the blockchain ledger through the resource calling contract, thereby restoring the executable file.

[0127] Regarding the resource writing contract, the resource writing contract may include, for example, the following protocol fields:

[0128] {

[0129] Resource Name:

[0130] Resource Owner:

[0131] Resource content:

[0132] }

[0133] In some possible implementations, when the capacity of the binary stream is large, the binary stream shards can be stored in multiple blocks. In this case, the resource write contract can also include a field "offset from the previous resource block (i.e., the block storing the binary stream shards)" to facilitate subsequent searches for each binary stream shard.

[0134] For the resource call contract, there may be a relevant record field in the resource call contract to record the hash value of the resource block. When the contract is called, the corresponding resources can be read and released from the blockchain account book according to the hash value, thereby completing the conversion of the executable file. In this way, by executing the executable file, the corresponding functional requirements can be met.

[0135] It is worth noting that the above-mentioned resource writing contract and resource calling contract can be different parts of the same contract, or can be deployed separately as two different contracts, and this disclosure does not impose any restrictions on this.

[0136] In a possible implementation, the binary resource includes a plurality of resource slices, and the contract includes a homomorphic check field and a homomorphic checksum, wherein the homomorphic check field includes a digital summary of each resource slice. Here, the digital summary may be, for example, a hash value obtained by performing a hash calculation on the resource slice. When constructing a contract, the contract participants may write the digital summary of each resource slice into the homomorphic check field in the contract.

[0137] In addition, the homomorphic checksum in the contract can be determined as follows:

[0138] For each of the digital summaries, calculating a ciphertext corresponding to the digital summaries based on the target homomorphic encryption key;

[0139] The homomorphic checksum is obtained by summing each of the ciphertexts.

[0140] For example, the target homomorphic encryption key may be generated off-chain by the resource owner, and the generation process may include:

[0141] A first prime number and a second prime number are randomly determined. Wherein, the number of digits of the first prime number and the second prime number is the same, and the number of digits of the first prime number and the second prime number is greater than a digit threshold. Wherein, the digit threshold can be set based on application requirements, for example, in some implementation scenarios, the digit threshold can be set to 32, and then the first prime number and the second prime number are selected.

[0142] For example, it can be determined that the first prime number p and the second prime number q whose digits are greater than 32 are such that p and q satisfy gcd(pq, (p-1)(q-1))=1, thereby ensuring that the digits of the first prime number p and the second prime number q are consistent. Wherein, gcd() is the greatest common divisor calculation function.

[0143] After determining the first prime number and the second prime number, the product of the first prime number and the second prime number can be used as parameter t in the target homomorphic encryption key. Continuing with the above example, t=pq.

[0144] In addition, a target random integer can be determined as a parameter g in the target homomorphic encryption key and obtained from Z n A random number is determined as a parameter r in the target homomorphic encryption key. and the parameter t divides the order of the parameter g, There exists a multiplicative inverse under the residue system. In this way, the target homomorphic encryption key (t, g, r) can be obtained.

[0145] After determining the target homomorphic encryption key, the ciphertext c corresponding to the digital summary m can be calculated by the following formula: m :

[0146] c m =E(m,r)=g m r t modt 2 , r∈Z n ;

[0147] For example, when the number of resource slices is 4, the digital summaries m of the 4 resource slices can be calculated separately. 1 、m 2 、m 3 and m 4 , and calculate the digital summary m respectively through the above formula 1 、m 2 、m 3 and m 4 The corresponding ciphertext.

[0148] In this way, each of the ciphertexts can be summed to obtain the homomorphic checksum c:

[0149]

[0150] Wherein, the target homomorphic encryption key is (t, g, r), i is the number value of the digital summary, x∈[1, i] and x is an integer, mod is the remainder function, Z n The domain of integers.

[0151] After calculating the homomorphic checksum and the digital summary of each resource shard, the homomorphic checksum and the digital summary of each resource shard can be saved in the contract to facilitate subsequent verification.

[0152] Accordingly, before obtaining the binary resource corresponding to the functional requirement from the blockchain, it also includes:

[0153] Calculate a target homomorphic checksum according to the homomorphic encryption key and the homomorphic check field;

[0154] Determine whether the target homomorphic checksum is consistent with the homomorphic checksum stored in the contract.

[0155] It should be understood that, in a specific implementation, the target homomorphic encryption key can be authorized to the corresponding execution device as required. In addition, the calculation method of the homomorphic checksum is described in the above embodiment, and for the sake of brevity of the specification, this disclosure will not be repeated here.

[0156] It is worth noting that when the homomorphic encryption key owned by the contract execution device is different from the target homomorphic encryption key, the target homomorphic checksum calculated by the contract execution device is inconsistent with the homomorphic checksum saved in the contract. Similarly, if the contract execution device has the target homomorphic encryption key, but the digital summary is wrong, the target homomorphic checksum calculated by the contract execution device will also be inconsistent with the homomorphic checksum saved in the contract.

[0157] Therefore, when the calculated target homomorphic checksum is consistent with the homomorphic checksum saved in the contract, it can be determined that the homomorphic encryption key owned by the contract execution device is correct (that is, the contract execution device has the authority to call resources) and that the content of the binary resource is correct.

[0158] In other words, the above technical solution can verify the legality of resource loading and the correctness of resources at the same time, thus helping to improve the execution efficiency of the contract. Moreover, such a homomorphic verification method can also verify the correctness of binary resources without obtaining the original text of the binary resources stored on the chain, thereby avoiding data leakage during the verification process and improving the verification speed.

[0159] Of course, in some implementation scenarios, the contract execution end can also calculate the digital summary based on the binary resources obtained on the chain, and then calculate the target homomorphic checksum. In this way, the legality of resource loading and the correctness of resources can be verified by comparing the target homomorphic checksum and the homomorphic checksum saved in the contract.

[0160] Based on the same inventive concept, the present disclosure also provides a smart contract execution device. Figure 5 is a block diagram of a smart contract execution device provided by the present disclosure, such as Figure 5 As shown, the device 500 includes:

[0161] A determination module 501, configured to, in response to receiving a contract call request, determine a functional requirement corresponding to the contract call request according to a call parameter in the contract call request;

[0162] A resource acquisition module 502, used to acquire a binary resource corresponding to the functional requirement from the blockchain, wherein the binary resource is obtained by converting a third-party functional component;

[0163] A first resource conversion module 503, used to convert the acquired binary resource into an executable file;

[0164] The execution module 504 is used to execute the executable file to meet the functional requirements.

[0165] The above technical solution converts the third-party functional components into binary resources, so that the obtained binary resources can be saved in the blockchain. In this way, after receiving the contract call request, the contract execution device can determine the functional requirements corresponding to the contract call request according to the call parameters in the contract call request, and obtain the corresponding binary resources from the blockchain according to the functional requirements. After obtaining the binary resources, the obtained binary resources can be converted into executable files, and the functional requirements can be met by executing the executable files. In this way, when facing relevant functional requirements, there is no need to write corresponding functional codes in the smart contract, but the function can be realized by calling the binary resources of the third-party functional components. In other words, the functions of the smart contract can be enriched by the above technical solution. In addition, by converting the third-party functional components into binary resources and converting the binary resources into executable files, it is also possible to break through the limitations of the contract development language, thereby further enriching the functions of the smart contract.

[0166] Optionally, the device 500 further includes:

[0167] A functional component acquisition module, used for acquiring the third-party functional component before the determination module determines the functional requirement corresponding to the contract call request;

[0168] A second resource conversion module, used to convert the executable file of the third-party functional component into a binary resource;

[0169] A resource storage module, used to save the binary resources into the blockchain;

[0170] The recording module is used to record the storage location information of the binary resource.

[0171] Optionally, the resource storage module includes:

[0172] A resource segmentation submodule, configured to segment the binary resource into a plurality of resource slices when the capacity of the binary resource is greater than a block capacity threshold;

[0173] A resource storage submodule, used to store each resource shard in the blockchain;

[0174] The storage location information includes an offset between a block where a target resource slice is located and a block where a previous resource slice of the target resource slice is located, and the target resource slice is any resource slice among the multiple resource slices except the first resource slice.

[0175] Optionally, the binary resource includes a plurality of resource slices, the contract includes a homomorphic check field and a homomorphic checksum, the homomorphic check field includes a digital summary of each of the resource slices, and the homomorphic checksum is determined in the following manner: for each of the digital summaries, a ciphertext corresponding to the digital summary is calculated based on a target homomorphic encryption key; each of the ciphertexts is summed to obtain the homomorphic checksum;

[0176] The device 500 further includes:

[0177] A calculation module, used for calculating a target homomorphic checksum according to the homomorphic encryption key and the homomorphic check field before the resource acquisition module 502 acquires the binary resource corresponding to the functional requirement from the blockchain;

[0178] A checksum determination module is used to determine whether the target homomorphic checksum is consistent with the homomorphic checksum stored in the contract.

[0179] Optionally, for each of the digital summaries, calculating a ciphertext corresponding to the digital summaries based on a homomorphic encryption key includes:

[0180] Calculate the ciphertext c corresponding to the digital summary m by the following calculation formula m :

[0181] c m =E(m,r)=g m r t modt 2 , r∈Z n ;

[0182] The summing each of the ciphertexts includes: calculating a homomorphic checksum c by the following calculation formula:

[0183]

[0184] Wherein, the target homomorphic encryption key is (t, g, r), i is the number value of the digital summary, x∈[1, i] and x is an integer, mod is the remainder function, Z n The domain of integers.

[0185] Optionally, the target homomorphic encryption key is determined by:

[0186] Randomly determine a first prime number and a second prime number, wherein the number of digits of the first prime number and the second prime number is the same, and the number of digits of the first prime number and the second prime number is greater than a digit threshold;

[0187] Using the product of the first prime number and the second prime number as parameter t in the target homomorphic encryption key;

[0188] Determine a target random integer as a parameter g in the target homomorphic encryption key, where and the parameter t divides the order of the parameter g, There exists a multiplicative inverse for the remainder system;

[0189] From Z n A random number is determined as a parameter r in the target homomorphic encryption key.

[0190] Optionally, the obtaining a binary resource corresponding to the functional requirement from the blockchain includes:

[0191] When the capacity of the binary resource is greater than the memory capacity threshold, dividing the binary resource into a plurality of binary resource slices;

[0192] The binary resource fragments are loaded into the memory in sequence for release.

[0193] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0194] The present disclosure also provides a non-temporary computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the smart contract execution method provided by the present disclosure.

[0195] The present disclosure also provides an electronic device, comprising:

[0196] a memory having a computer program stored thereon;

[0197] A processor is used to execute the computer program in the memory to implement the steps of the smart contract execution method provided by the present disclosure.

[0198] Figure 6 FIG. 6 is a block diagram of an electronic device 600 according to an exemplary embodiment. Figure 6 As shown, the electronic device 600 may include: a processor 601 and a memory 602. The electronic device 600 may also include one or more of a multimedia component 603, an input / output (I / O) interface 604, and a communication component 605.

[0199] The processor 601 is used to control the overall operation of the electronic device 600 to complete all or part of the steps in the above-mentioned smart contract execution method. The memory 602 is used to store various types of data to support the operation of the electronic device 600. These data may include instructions for any application or method used to operate on the electronic device 600, as well as application-related data, such as sent and received messages, pictures, contract codes, etc. The memory 602 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (Static Random Access Memory, referred to as SRAM), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, referred to as EEPROM), erasable programmable read-only memory (Erasable Programmable Read-Only Memory, referred to as EPROM), programmable read-only memory (Programmable Read-Only Memory, referred to as PROM), read-only memory (Read-Only Memory, referred to as ROM), magnetic memory, flash memory, disk or optical disk. The multimedia component 603 may include a screen and an audio component. The screen may be, for example, a touch screen, and the audio component is used to output and / or input audio signals. For example, the audio component may include a microphone for receiving external audio signals. The received audio signal may be further stored in the memory 602 or sent through the communication component 605. The audio component also includes at least one speaker for outputting audio signals. The I / O interface 604 provides an interface between the processor 601 and other interface modules, and the other interface modules may be keyboards, mice, buttons, etc. These buttons may be virtual buttons or physical buttons. The communication component 605 is used for wired or wireless communication between the electronic device 600 and other devices. Wireless communication, such as Wi-Fi, Bluetooth, Near Field Communication (NFC), 2G, 3G, 4G, NB-IOT, eMTC, or other 5G, etc., or a combination of one or more of them, is not limited here. Therefore, the corresponding communication component 605 may include: Wi-Fi module, Bluetooth module, NFC module, etc.

[0200] In an exemplary embodiment, the electronic device 600 can be implemented by one or more application specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPD), programmable logic devices (PLD), field programmable gate arrays (FPGA), controllers, microcontrollers, microprocessors or other electronic components to execute the above-mentioned smart contract execution method.

[0201] In another exemplary embodiment, a computer-readable storage medium including program instructions is also provided, and when the program instructions are executed by a processor, the steps of the above-mentioned smart contract execution method are implemented. For example, the computer-readable storage medium can be the above-mentioned memory 602 including program instructions, and the above-mentioned program instructions can be executed by the processor 601 of the electronic device 600 to complete the above-mentioned smart contract execution method.

[0202] In another exemplary embodiment, a computer program product is also provided, which includes a computer program that can be executed by a programmable device, and the computer program has a code portion for executing the above-mentioned smart contract execution method when executed by the programmable device.

[0203] The preferred embodiments of the present disclosure are described in detail above in conjunction with the accompanying drawings; however, the present disclosure is not limited to the specific details in the above embodiments. Within the technical concept of the present disclosure, a variety of simple modifications can be made to the technical solution of the present disclosure, and these simple modifications all fall within the protection scope of the present disclosure.

[0204] It should also be noted that the various specific technical features described in the above specific embodiments can be combined in any suitable manner without contradiction. In order to avoid unnecessary repetition, the present disclosure will not further describe various possible combinations.

[0205] In addition, various embodiments of the present disclosure may be arbitrarily combined, and as long as they do not violate the concept of the present disclosure, they should also be regarded as the contents disclosed by the present disclosure.

Claims

1. A smart contract execution method, characterized in that: include: In response to receiving a contract call request, determining a functional requirement corresponding to the contract call request according to a call parameter in the contract call request; Obtaining a binary resource corresponding to the functional requirement from the blockchain, wherein the binary resource is obtained by transforming a third-party functional component outside the smart contract; Convert the acquired binary resource into an executable file; Executing the executable file to meet the functional requirements; The binary resource includes multiple resource slices, the contract includes a homomorphic check field and a homomorphic checksum, the homomorphic check field includes a digital summary of each resource slice, and the homomorphic checksum is determined by: For each of the digital summaries, calculating a ciphertext corresponding to the digital summaries based on the target homomorphic encryption key; Summing each of the ciphertexts to obtain the homomorphic checksum; Before obtaining the binary resource corresponding to the functional requirement from the blockchain, the method further includes: Calculate a target homomorphic checksum according to the homomorphic encryption key and the homomorphic check field; Determining that the target homomorphic checksum is consistent with the homomorphic checksum stored in the contract; The step of calculating, for each of the digital summaries, a ciphertext corresponding to the digital summaries based on a target homomorphic encryption key comprises: Calculate the ciphertext c corresponding to the digital summary m by the following calculation formula m : c m =E(m,r)=g m r t received 2 ,r∈Z n ; The summing each of the ciphertexts includes: calculating a homomorphic checksum c by the following calculation formula: Wherein, the target homomorphic encryption key is (t, g, r), i is the number value of the digital summary, x∈[1, i] and x is an integer, mod is the remainder function, Z n The domain of integers.

2. The method according to claim 1, characterized in that In response to receiving the contract call request, before determining the functional requirements corresponding to the contract call request according to the call parameters in the contract call request, the method further includes: Obtaining the third-party functional component; Convert the executable file of the third-party functional component into a binary resource; Saving the binary resource to the blockchain; The storage location information of the binary resource is recorded.

3. The method according to claim 2, characterized in that The step of saving the binary resource to the blockchain includes: When the capacity of the binary resource is greater than the block capacity threshold, dividing the binary resource into a plurality of resource slices; Saving each of the resource shards in the blockchain; The storage location information includes an offset between a block where a target resource slice is located and a block where a previous resource slice of the target resource slice is located, and the target resource slice is any resource slice among the multiple resource slices except the first resource slice.

4. The method according to claim 1, characterized in that The target homomorphic encryption key is determined as follows: Randomly determine a first prime number and a second prime number, wherein the number of digits of the first prime number and the second prime number is the same, and the number of digits of the first prime number and the second prime number is greater than a digit threshold; Using the product of the first prime number and the second prime number as parameter t in the target homomorphic encryption key; Determine a target random integer as a parameter g in the target homomorphic encryption key, where and the parameter t divides the order of the parameter g, There exists a multiplicative inverse for the remainder system; From Z n A random number is determined as a parameter r in the target homomorphic encryption key.

5. The method according to claim 1, characterized in that: The obtaining of binary resources corresponding to the functional requirements from the blockchain includes: When the capacity of the binary resource is greater than the memory capacity threshold, dividing the binary resource into a plurality of binary resource slices; The binary resource fragments are loaded into the memory in sequence for release.

6. A smart contract execution device, characterized in that: include: A determination module, configured to, in response to receiving a contract call request, determine a functional requirement corresponding to the contract call request according to a call parameter in the contract call request; A resource acquisition module, used to acquire binary resources corresponding to the functional requirements from the blockchain, wherein the binary resources are obtained by converting third-party functional components outside the smart contract; A first resource conversion module, used to convert the acquired binary resource into an executable file; An execution module, used for executing the executable file to meet the functional requirements; The binary resource includes a plurality of resource slices, the contract includes a homomorphic check field and a homomorphic checksum, the homomorphic check field includes a digital summary of each resource slice, and the homomorphic checksum is determined in the following manner: for each digital summary, a ciphertext corresponding to the digital summary is calculated based on a target homomorphic encryption key; each ciphertext is summed to obtain the homomorphic checksum; The device also includes: A calculation module, configured to calculate a target homomorphic checksum according to the homomorphic encryption key and the homomorphic check field before the resource acquisition module acquires the binary resource corresponding to the functional requirement from the blockchain; A checksum determination module, used to determine whether the target homomorphic checksum is consistent with the homomorphic checksum stored in the contract; for each digital summary, calculating the ciphertext corresponding to the digital summary based on the target homomorphic encryption key, including: Calculate the ciphertext c corresponding to the digital summary m by the following calculation formula m : c m =E(m,r)=g m r t received 2 ,r∈Z n ; The summing each of the ciphertexts includes: calculating a homomorphic checksum c by the following calculation formula: Wherein, the target homomorphic encryption key is (t, g, r), i is the number value of the digital summary, x∈[1, i] and x is an integer, mod is the remainder function, Z n The domain of integers.

7. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method described in any one of claims 1 to 5 are implemented.

8. An electronic device, characterized in that: include: a memory having a computer program stored thereon; A processor, configured to execute the computer program in the memory to implement the steps of the method according to any one of claims 1 to 5.