Intelligent Contract Deployment and Execution Method, Device, and Storage Medium
By deploying multiple contract virtual machine instances in WASM virtual machines and using the first smart contract to parse and deploy the second smart contract, the isolation problem between the blockchain virtual machine and the smart contract language is solved, and cross-blockchain smart contract fusion and reuse and ecological interoperability are realized.
Patent Information
- Application Number
- CN202111457391.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-01
- Publication Date
- 2025-07-01
- Estimated Expiration
- 2041-12-01
AI Technical Summary
The blockchain virtual machines in the existing blockchain system are related to the contract language of smart contracts, resulting in the project ecological isolation of smart contracts and the inability to achieve cross-blockchain smart contract fusion and reuse.
Deploy multiple contract virtual machine instances in WASM virtual machines. Each instance supports smart contracts in different contract languages. Transactions are deployed through the first smart contract parsing contracts, and the corresponding second smart contract is generated and deployed to realize cross-blockchain smart contract calls and execution.
The smart contract convergence and reuse across blockchain systems has been realized, avoiding adaptation and reconstruction of the underlying architecture of blockchain, and improving the portability and ecological interoperability of smart contracts.
Smart Images

Figure CN114116134B_ABST
Abstract
Description
Background Art
[0002] A virtual machine (VM) in the architecture of computer science refers to a special software that can create an environment between a computer platform and an end user, and the end user operates other software based on the environment created by this software.
[0003] The blockchain virtual machine derived with the emergence of blockchain was first introduced into the blockchain technology set by Ethereum and extended to virtual machines based on other contract languages.
[0004] The blockchain virtual machine is an executor of smart contract code. Specifically, when a smart contract is compiled into a binary file, it is deployed on the blockchain, and the execution and invocation of the contract are supported by the blockchain virtual machine deployed on the blockchain platform. When invoked, the smart contract code is obtained according to the contract address, and after generating an environment, it is loaded into the blockchain virtual machine to run and modify the data (status) on the current blockchain. The modified data will be consensus to ensure consistency.
[0005] However, when implementing a blockchain virtual machine in each blockchain system, it is related to the contract language of the smart contract. Each blockchain virtual machine can execute and invoke smart contracts in the corresponding contract language, which also leads to the isolation of the project ecosystem implemented using smart contracts. Summary of the Invention
[0006] Aiming at the problems in the prior art, the purpose of the present invention is to provide a method, device and storage medium for deploying and executing smart contracts, so as to realize the fusion and reuse of smart contracts across blockchain systems.
[0007] An embodiment of the present invention provides a method for deploying a smart contract based on a blockchain platform. A WASM virtual machine is deployed in the blockchain platform, multiple contract virtual machine instances that respectively support different contract languages are deployed in the WASM virtual machine, and a first smart contract supported by the WASM virtual machine is deployed in the blockchain. The method includes:
[0008] Obtain a contract deployment transaction based on a target contract language, and the target contract language corresponds to a target contract virtual machine instance among multiple virtual machine instances;
[0009] Invoke the first smart contract in the blockchain according to the contract deployment transaction;
[0010] Execute the first smart contract in the WASM virtual machine, and parse the contract deployment transaction by executing the first smart contract to obtain a second smart contract based on the target contract language;
[0011] Deploy the second smart contract on the blockchain.
[0012] Optionally, by executing the first smart contract to parse the contract deployment transaction, a second smart contract based on the target contract language is obtained, including:
[0013] By executing the first smart contract to parse the contract deployment transaction, a bytecode contract file based on the target contract language and the second smart contract formed by using the bytecode file are obtained.
[0014] An embodiment of the present invention further provides a method for executing a smart contract based on a blockchain platform. A WASM virtual machine is deployed in the blockchain platform, multiple contract virtual machine instances that respectively support different contract languages are deployed in the WASM virtual machine, and a first smart contract supported by the WASM virtual machine and multiple instance smart contracts respectively supported by the multiple contract virtual machine instances are deployed in the blockchain. The method includes:
[0015] In the blockchain, a call is initiated to the second smart contract and the first smart contract among the multiple instance smart contracts;
[0016] The first smart contract is executed in the WASM virtual machine. By executing the first smart contract, a target contract virtual machine instance that supports the second smart contract is called among the multiple contract virtual machine instances, and the second smart contract is executed by using the target contract virtual machine instance, and the execution result is output;
[0017] The execution result is uploaded to the blockchain.
[0018] Optionally, before executing the first smart contract in the WASM virtual machine, the method further includes:
[0019] The called second smart contract is instantiated by using a transaction instance to obtain a contract transaction;
[0020] The called first smart contract is instantiated by using the contract transaction to obtain a virtual machine instance call transaction;
[0021] Executing the first smart contract in the WASM virtual machine. By executing the first smart contract, a target contract virtual machine instance that supports the second smart contract is called among the multiple contract virtual machine instances, and the second smart contract is executed by using the target contract virtual machine instance, including:
[0022] The virtual machine instance call transaction is executed in the WASM virtual machine to call the target contract virtual machine instance of the contract type that supports the second smart contract, and the contract transaction is executed by using the target contract virtual machine instance.
[0023] Optionally, instantiating the called second smart contract by using a transaction instance to obtain a contract transaction, including:
[0024] In the case where the second smart contract called is a bytecode file, instantiate the bytecode file using the transaction instance to obtain a contract transaction implemented based on the bytecode;
[0025] Execute the contract transaction using the target contract virtual machine instance, including:
[0026] Use the target contract virtual machine instance to translate the bytecode into machine code and execute the machine code.
[0027] Optionally, instantiate the first smart contract called using the contract transaction to obtain a virtual machine instance call transaction, including:
[0028] In the case where the first smart contract called is a bytecode file, instantiate the bytecode file using the contract transaction to obtain a virtual machine instance call transaction based on the bytecode;
[0029] Execute the virtual machine instance call transaction in the WASM virtual machine to call the target contract virtual machine instance that supports the second smart contract, including:
[0030] Use the WASM virtual machine to translate the bytecode into machine code and execute the machine code, and call the target contract virtual machine instance that supports the second smart contract by executing the machine code.
[0031] Optionally, the method further includes:
[0032] Before initiating calls to the second smart contract and the first smart contract among multiple instance smart contracts in the blockchain, receive a transaction request from the transaction initiator based on the second smart contract;
[0033] Initiate a call to the second smart contract among multiple instance smart contracts in the blockchain, including:
[0034] In response to the transaction request, initiate a call to the second smart contract among multiple instance smart contracts in the blockchain, and also call the first smart contract.
[0035] An embodiment of the present invention further provides a smart contract deployment device based on a blockchain platform. Deploy a WASM virtual machine in the blockchain platform, deploy multiple contract virtual machine instances that support different contract languages in the WASM virtual machine, and deploy the first smart contract supported by the WASM virtual machine in the blockchain. The device includes:
[0036] A first acquisition module that acquires a contract deployment transaction based on a target contract language, where the target contract language corresponds to a target contract virtual machine instance among multiple virtual machine instances;
[0037] A first call module that calls the first smart contract in the blockchain according to the contract deployment transaction;
[0038] The first execution module executes the first smart contract in the WASM virtual machine, parses the contract deployment transaction by executing the first smart contract, and obtains a second smart contract based on the target contract language;
[0039] The deployment module deploys the second smart contract to the blockchain.
[0040] An embodiment of the present invention further provides a smart contract execution device based on a blockchain platform. A WASM virtual machine is deployed in the blockchain platform, multiple contract virtual machine instances that respectively support different contract languages are deployed in the WASM virtual machine, and a first smart contract supported by the WASM virtual machine and multiple instance smart contracts respectively supported by the multiple contract virtual machine instances are deployed in the blockchain. The device includes:
[0041] The second invocation module initiates an invocation of the second smart contract and the first smart contract among the multiple instance smart contracts in the blockchain;
[0042] The second execution module executes the first smart contract in the WASM virtual machine, invokes a target contract virtual machine instance that supports the second smart contract among the multiple contract virtual machine instances by executing the first smart contract, and uses the target contract virtual machine instance to execute the second smart contract and outputs an execution result;
[0043] The upload module uploads the execution result to the blockchain.
[0044] An embodiment of the present invention further provides an electronic device, including:
[0045] A processor;
[0046] A memory, in which executable instructions of the processor are stored;
[0047] Wherein, the processor is configured to execute the steps of the above-mentioned smart contract deployment method based on the blockchain platform or the steps of the smart contract execution method based on the blockchain platform by executing the executable instructions.
[0048] An embodiment of the present invention further provides a computer-readable storage medium for storing a program, and when the program is executed, it implements the steps of the above-mentioned smart contract deployment method based on the blockchain platform or the steps of the smart contract execution method based on the blockchain platform.
[0049] The purpose of the present invention is to provide a method, device, and storage medium for deploying and executing smart contracts based on a blockchain platform. By deploying a contract virtual machine instance that supports multiple contract languages in the WASM virtual machine, deploying a second smart contract corresponding to the multiple contract languages on the blockchain, and when a call request for the second smart contract in any one of the contract languages is received, calling a blockchain contract virtual machine instance of the contract type that can support the second smart contract to execute the second smart contract, and storing the execution result on the blockchain. Using the solution of the embodiment of the present invention, by implementing multiple specific contract virtual machine instances in the WASM virtual machine, it is possible to deploy and call smart contracts implemented in multiple contract languages on top of the smart contracts in the WASM virtual machine without the need to adaptively reconstruct the underlying architecture of the blockchain. The embodiment of the present invention has high feasibility in realizing cross-blockchain smart contract fusion and reuse. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Other features, objects, and advantages of the present invention will become more apparent by reading the following detailed description of non-limiting embodiments with reference to the accompanying drawings.
[0051] Figure 1 It is a schematic diagram of the structure of the WASM virtual machine based on the blockchain platform provided by the embodiment of the present invention;
[0052] Figure 2 It is a flowchart of the method for deploying smart contracts based on the blockchain platform provided by the embodiment of the present invention;
[0053] Figure 3 It is one of the flowcharts of the method for executing smart contracts based on the blockchain platform provided by the embodiment of the present invention;
[0054] Figure 4 It is another flowchart of the method for executing smart contracts based on the blockchain platform provided by the embodiment of the present invention;
[0055] Figure 5 It is yet another flowchart of the method for executing smart contracts based on the blockchain platform provided by the embodiment of the present invention;
[0056] Figure 6 It is a schematic diagram of the smart contract deployment module based on the blockchain platform provided by the embodiment of the present invention;
[0057] Figure 7 It is one of the schematic diagrams of the smart contract execution module based on the blockchain platform provided by the embodiment of the present invention;
[0058] Figure 8 It is another schematic diagram of the smart contract execution module based on the blockchain platform provided by the embodiment of the present invention;
[0059] Figure 9It is the third schematic diagram of the intelligent contract execution module based on the blockchain platform provided by the embodiments of the present invention;
[0060] Figure 10 It is the schematic diagram of the electronic device structure of the present invention. Detailed implementation manners
[0061] Example embodiments will now be described more fully with reference to the accompanying drawings. However, the example embodiments can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. On the contrary, these embodiments are provided so that this invention will be thorough and complete, and will fully convey the concept of the example embodiments to those skilled in the art.
[0062] The accompanying drawings are only schematic illustrations of the present invention and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and thus their repeated description will be omitted. Some of the block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or in one or more hardware forwarding modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0063] In addition, the processes shown in the accompanying drawings are only exemplary illustrations and do not necessarily include all steps. For example, some steps can be decomposed, some steps can be combined or partially combined, and the actual execution order may be changed according to the actual situation. The terms "first", "second" and similar terms used in the specific description do not denote any order, quantity or importance, but are only used to distinguish different components. It should be noted that, without conflict, the embodiments of the present invention and the features in different embodiments can be combined with each other.
[0064] The inventors of the present invention have studied various existing blockchain virtual machines, and there are currently the following three solutions for the integration of blockchain multi-virtual machines and contract languages:
[0065] Chang'an ChainMaker provides an open-source solution for integrating multi-virtual machines and contract languages, but these integrated virtual machines do not have a unified general process and specification.
[0066] Hyperledger Fabric, whose smart contract is simply called chaincode, only supports the Go language, and the integrated Go language virtual machine is implemented based on Docker containers and does not support multi-contract ecosystems.
[0067] FISCO-BCOS is a heavy refactoring of the open-source project Ethereum. Its underlying layer natively supports the Ethereum Virtual Machine (EVM), but it lacks a general horizontal expansion interface and a general process specification. When expanding virtual machines of other technical architectures, a large number of modifications and adaptation refactoring need to be done to the underlying implementation architecture.
[0068] Therefore, there is no highly feasible multi-contract fusion and reuse solution in the industry yet.
[0069] Thinking further, blockchain virtual machines need to be applicable to more complex, extensive, and general scenarios, that is, Turing completeness. From the perspective of software simulation, a virtual machine is a mechanism for simulating the operation of a specific machine with software, and the input of the machine is the code instructions of humans. However, from high-level languages similar to humans to low-level languages that machines can execute, and then to the operation and state change of virtual machine operation instructions, a series of processing processes are required. And these differences are the differences between blockchain virtual machines and traditional virtual machines.
[0070] The inventor noticed that among various blockchain virtual machine implementation technologies, the WebAssembly (WASM) virtual machine is one of the blockchain virtual machines implemented using WASM. WASM is an experimental low-level programming language, a machine language about concepts, and supports compilation with C / C++ as the implementation target. This feature enables it to have broader generality.
[0071] As a low-level programming language, WASM can not only be used for smart contract coding and implement the execution and invocation of contracts through the WASM virtual machine, but also be used to implement other types of blockchain contract virtual machine instances on top of this low-level programming language, making it possible to solve the multi-contract fusion and reuse across the blockchain ecosystem.
[0072] Therefore, the embodiments of the present invention propose to deploy multiple contract virtual machine instances that respectively support multiple contract languages in the WASM virtual machine, and deploy the first smart contract supported by the WASM in the blockchain to implement the migration and deployment of multiple contract virtual machine instances and the corresponding smart contracts.
[0073] Among them, the first smart contract is used to define the deployment and invocation of the second smart contract supported by these contract virtual machine instances, so that the deployment and invocation of multiple contract virtual machine instances can be realized on top of the first smart contract.
[0074] In the deployment stage, for the contract deployment transaction of the second smart contract using any contract language, the first smart contract can be called and the first smart contract can be executed for the contract deployment transaction in the WASM virtual machine to parse out the second smart contract and deploy it to the blockchain.
[0075] In the execution stage, when a call request for a second smart contract in any contract language is received, the first smart contract and the second smart contract are called. By executing the first smart contract in the WASM virtual machine, a blockchain contract virtual machine instance of the contract type that can support the second smart contract is called to execute the second smart contract, and the execution result is stored on the blockchain.
[0076] Using the solution of the embodiment of the present invention, by implementing various specific contract virtual machine instances in the WASM virtual machine, the deployment and call of smart contracts implemented in multiple contract languages can be realized on top of the smart contracts in the WASM virtual machine, without the need to adaptively reconstruct the underlying blockchain architecture. The embodiment of the present invention has high feasibility in realizing cross-blockchain smart contract fusion and reuse.
[0077] In the embodiment of the present invention, referring to Figure 1 , multiple contract virtual machine instances that respectively support contract languages of different blockchain platforms can be deployed in the WASM virtual machine 100. The multi-instance heterogeneous virtual machine implementation abstracted and implemented on top of the WASM virtual machine, and the WASM virtual machine provides a running environment for multiple contract virtual machine instances.
[0078] In Figure 1 , the contract virtual machine instances deployed in the WASM virtual machine 100 are respectively the WASM virtual machine 110 based on C++, the EVM 120 based on Solidity, the Golang execution engine 130, and other script interpretation engines, which are not specifically limited here.
[0079] Specifically, when developers obtain the official documents and specifications of the virtual machine to be transplanted, they extract the instruction set definition and constraint constant definition, as well as the implementation of encoding / decoding and related serialization methods from them, to obtain the implementation of the network transaction data parsing logic, which is used to construct the virtual execution environment and transaction structure instance, and deploy it as a contract virtual machine instance in the WASM virtual machine.
[0080] Figure 2 FIG. is a flowchart of an embodiment of a method for deploying a smart contract based on a blockchain platform according to the present invention. The blockchain platform can be understood as the entrance of the blockchain system, which is used to deploy the WASM virtual machine. The WASM virtual machine provides a running environment for multiple contract virtual machine instances, and deploys the first smart contract supported by the WASM virtual machine in the blockchain.
[0081] As Figure 2 shown, an embodiment of the present invention provides a method for deploying a smart contract based on a blockchain platform. The execution subject of this method is a blockchain node. This method includes the following steps:
[0082] Step 210: Obtain a contract deployment transaction based on a target contract language, where the target contract language corresponds to a target contract virtual machine instance among multiple virtual machine instances;
[0083] Step 220: Invoke a first smart contract in the blockchain according to the contract deployment transaction;
[0084] Step 230: Execute the first smart contract in the WASM virtual machine, and by executing the first smart contract, parse the contract deployment transaction to obtain a second smart contract based on the target contract language;
[0085] Step 240: Deploy the second smart contract to the blockchain.
[0086] In this embodiment, the contract deployment transaction can be understood as a transaction for deploying a second smart contract based on the target contract language on the blockchain. The first smart contract is a contract for deploying the second smart contract, and the deployment of smart contracts supported by multiple contract virtual machines is realized on top of the first smart contract.
[0087] In the application scenario of the embodiments of the present invention, users do not need to develop multiple copies of smart contract codes according to the contract languages supported by different blockchain systems and then deploy them separately on different blockchain systems. Instead, they can directly deploy and implement multiple smart contracts on the blockchain through this blockchain platform, bringing a good user experience.
[0088] Therefore, by using the embodiments of the present invention, the transplantation and deployment of smart contracts implemented in multiple contract languages are realized on top of the smart contracts in the WASM virtual machine, without the need to adaptively reconstruct the underlying architecture of the blockchain, which has high feasibility in realizing cross-blockchain smart contract fusion and reuse.
[0089] In the embodiments of the present invention, the blockchain platform provides an interface for invoking the first smart contract and receives the contract deployment transaction for the second smart contract, which is an example of obtaining the contract deployment transaction.
[0090] In the embodiments of the present invention, by executing the first smart contract to parse the contract deployment transaction to obtain a second smart contract based on the target contract language, it includes:
[0091] By executing the first smart contract to parse the contract deployment transaction, a bytecode contract file based on the target contract language and a second smart contract formed by using the bytecode file are obtained.
[0092] Bytecode (English: Bytecode) generally refers to a sequence composed of compiled values, references, instructions, etc. that have been encoded but are specific. Bytecode is mainly for realizing specific software operation and is independent of the software environment and hardware environment. Use a compiler to compile the source code into bytecode and output a bytecode contract file to form a contract deployment transaction.
[0093] This bytecode contract file is used so that during the execution phase, the corresponding target contract virtual machine instance can translate this bytecode into machine code instructions that can be directly executed.
[0094] Therefore, a contract deployment transaction may include information such as the transaction initiator's account address, the bytecode contract file, and the interface description file. The interface description file describes an application binary interface, specifically, it can be an interface file after compilation of the source code of the bytecode contract file, which facilitates the composition of the contract deployment transaction, the composition of the contract call transaction, and the parsing of the execution result after the call is executed by a software toolkit.
[0095] In an embodiment of the present invention, before deploying the second smart contract to the blockchain, the second smart contract can be consensus in the blockchain. After the consensus is passed, a contract address of the second smart contract is generated and uploaded to the blockchain according to the contract address.
[0096] Figure 3 The flowchart of the smart contract execution method based on the blockchain platform provided by the embodiment of the present invention, the execution subject of this method is a blockchain node. Among them, a WASM virtual machine is deployed in the blockchain platform, multiple contract virtual machine instances that support different contract languages are deployed in the WASM virtual machine, and a first smart contract supported by the WASM virtual machine and multiple instance smart contracts supported by multiple contract virtual machine instances are deployed in the blockchain.
[0097] This method includes the following steps:
[0098] Step 310: Initiate calls to the second smart contract and the first smart contract among multiple instance smart contracts in the blockchain;
[0099] Step 320: Execute the first smart contract in the WASM virtual machine, call the target contract virtual machine instance that supports the second smart contract among multiple contract virtual machine instances by executing the first smart contract, and use the target contract virtual machine instance to execute the second smart contract and output the execution result;
[0100] Step 330: Upload the execution result to the blockchain.
[0101] In an embodiment of the present invention, the smart contract execution process is applied to a specific business transaction, and the final execution result is the business transaction result based on the second smart contract.
[0102] In an embodiment of the present invention, the WASM virtual machine provides a running environment for other contract virtual machines, calls a specific target contract virtual machine instance according to the contract type of the second smart contract, and is interpreted and executed by the target contract virtual machine instance implemented during the runtime of the WASM virtual machine.
[0103] In this case, multiple contract virtual machine instances can be run in parallel in the WASM virtual machine.
[0104] In an embodiment of the present invention, the second smart contract is called according to the contract address of the second smart contract. The second smart contract is directly used as the input of the WASM virtual machine instance, and the WASM virtual machine calls the template contract virtual machine instance to execute the second smart contract.
[0105] In an embodiment of the present invention, with reference to Figure 4 , the method for executing a smart contract based on a blockchain platform includes the following steps:
[0106] Step 410: Initiate calls to the second smart contract and the first smart contract among multiple instance smart contracts in the blockchain;
[0107] Step 420: Instantiate the called second smart contract using a transaction instance to obtain a contract transaction;
[0108] Step 430: Instantiate the called first smart contract using the contract transaction to obtain a virtual machine instance call transaction;
[0109] Step 440: Execute the virtual machine instance call transaction in the WASM virtual machine, call the target contract virtual machine instance that supports the second smart contract, use the target contract virtual machine instance to execute the contract transaction, and output the execution result;
[0110] Step 450: Upload the execution result to the blockchain.
[0111] In an embodiment of the present invention, the transaction instance includes blockchain transaction parameters submitted to the blockchain platform, specifically including transaction initiator information, transaction recipient information, transaction object, transaction subject matter, etc. These parameters are used to instantiate a specific second smart contract.
[0112] In this case, the target contract virtual machine instance executes the contract transaction, specifically executes the transaction conditions set by the smart contract based on the corresponding transaction instance, and outputs the transaction execution result.
[0113] In an embodiment of the present invention, instantiating the first smart contract using the contract transaction may refer to instantiating the first smart contract using the contract type of the second smart contract. In this case, the WASM virtual machine parses out the contract type of the second smart contract by executing the virtual machine instance call transaction, thereby using this contract type to call the target contract virtual machine instance that supports this contract type and running the target contract virtual machine instance.
[0114] In an embodiment of the present invention, the second smart contract is deployed on the blockchain in the form of a bytecode file. Therefore, instantiating the called second smart contract using a transaction instance to obtain a contract transaction includes:
[0115] When the called second smart contract is a bytecode file, instantiating the bytecode file using a transaction instance to obtain a contract transaction implemented based on the bytecode;
[0116] In this case, executing the contract transaction using a target contract virtual machine instance specifically includes:
[0117] Using the target contract virtual machine instance to translate the bytecode into machine code and execute the machine code.
[0118] The target contract virtual machine instance has an interpreter function to interpret and translate the bytecode into machine code, and the machine code is a series of executable instructions, so that it can be executed by the target contract virtual machine instance.
[0119] In an embodiment of the present invention, the first smart contract is also deployed on the blockchain in bytecode form. Therefore, instantiating the called first smart contract using the contract transaction to obtain a virtual machine instance call transaction specifically includes:
[0120] When the called first smart contract is a bytecode file, instantiating the bytecode file using the contract transaction to obtain a virtual machine instance call transaction based on the bytecode;
[0121] Executing the virtual machine instance call transaction in the WASM virtual machine to call the target contract virtual machine instance that supports the second smart contract, including:
[0122] Using the WASM virtual machine to translate the bytecode into machine code and execute the machine code, and calling the target contract virtual machine instance that supports the second smart contract by executing the machine code.
[0123] The WASM virtual machine can interpret and translate the bytecode of the first smart contract into machine code, execute the machine code, and output the transaction execution result.
[0124] In an embodiment of the present invention, referring to Figure 5 , the smart contract execution method includes the following steps:
[0125] Step 510: Receive a transaction request from a transaction initiator based on the second smart contract;
[0126] Step 520: In response to the transaction request, initiate a call to the second smart contract among the multiple instance smart contracts in the blockchain, and also call the first smart contract;
[0127] Step 530: Execute the first smart contract in the WASM virtual machine, call the target contract virtual machine instance that supports the second smart contract among multiple contract virtual machine instances through the execution of the first smart contract, and use the target contract virtual machine instance to execute the second smart contract and output the execution result;
[0128] Step 540: Upload the execution result to the blockchain.
[0129] The smart contract execution method of the embodiment of the present invention is applied to a specific transaction scenario.
[0130] In the embodiment of the present invention, before the execution result is uploaded to the chain, it is sent to the consensus node, and the consensus node conducts consensus, and after the consensus is passed, it is uploaded to the chain, that is, stored in each blockchain node.
[0131] Figure 6 The following is a structural diagram of a smart contract deployment device based on a blockchain platform provided by an embodiment of the present invention. This device may include:
[0132] An acquisition module 610, which acquires a contract deployment transaction based on a target contract language, and the target contract language corresponds to a target contract virtual machine instance among multiple virtual machine instances;
[0133] A first call module 620, which calls the first smart contract in the blockchain according to the contract deployment transaction;
[0134] A first execution module 630, which executes the first smart contract in the WASM virtual machine, and parses the contract deployment transaction through the execution of the first smart contract to obtain a second smart contract based on the target contract language;
[0135] A deployment module 640, which deploys the second smart contract to the blockchain.
[0136] Optionally, the first execution module 630 is specifically used for:
[0137] Parse the contract deployment transaction through the execution of the first smart contract to obtain a bytecode contract file based on the target contract language and the second smart contract formed by using the bytecode file.
[0138] Using the solution of the embodiment of the present invention, by implementing multiple specific contract virtual machine instances in the WASM virtual machine, it is possible to implement the deployment and call of smart contracts implemented in multiple contract languages on top of the smart contract in the WASM virtual machine, without the need to adaptively reconstruct the underlying architecture of the blockchain. The embodiment of the present invention has high feasibility in realizing cross-blockchain smart contract fusion and reuse.
[0139] The implementation principle of the above modules can be found in the relevant introduction of the smart contract deployment method based on the blockchain platform, which will not be repeated here.
[0140] Figure 7 The structure diagram of the smart contract execution device based on the blockchain platform provided by the embodiment of the present invention may include:
[0141] A second calling module 710 initiates a call to a second smart contract and the first smart contract in the multiple instance smart contracts in the blockchain;
[0142] The second execution module 720 executes the first smart contract in the WASM virtual machine, calls a target contract virtual machine instance supporting the second smart contract in multiple contract virtual machine instances by executing the first smart contract, executes the second smart contract using the target contract virtual machine instance, and outputs the execution result;
[0143] The upload module 730 uploads the execution result to the blockchain.
[0144] Optionally, refer to Figure 8 ,and Figure 7 compared to, Figure 8 The smart contract deployment device also includes:
[0145] A first instantiation module 810 instantiates the called second smart contract using a transaction instance to obtain a contract transaction;
[0146] A second instantiation module 820 instantiates the called first smart contract using the contract transaction to obtain a virtual machine instance calling transaction;
[0147] The second execution module 830 is specifically used for:
[0148] The virtual machine instance call transaction is executed in the WASM virtual machine, the target contract virtual machine instance that supports the second smart contract is called, and the contract transaction is executed using the target contract virtual machine instance.
[0149] Optionally, the first instantiation module 810 is specifically configured to:
[0150] When the second smart contract called is a bytecode file, instantiate the bytecode file using a transaction instance to obtain a contract transaction implemented based on the bytecode;
[0151] The second execution module 830 is specifically used for:
[0152] The target contract virtual machine instance is used to translate the bytecode into machine code, and the machine code is executed.
[0153] Optionally, the second instantiation module 820 is specifically configured to:
[0154] When the first smart contract called is a bytecode file, instantiate the bytecode file using the contract transaction to obtain a virtual machine instance call transaction based on the bytecode;
[0155] The second execution module 830 is specifically configured to:
[0156] Translate the bytecode into machine code using the WASM virtual machine and execute the machine code, and call a target contract virtual machine instance that supports the second smart contract by executing the machine code.
[0157] Optionally, compared with Figure 7 compared with Figure 9 the smart contract execution device shown further includes:
[0158] A receiving module 910, which receives a transaction request from a transaction initiator based on the second smart contract before initiating a call to the second smart contract and the first smart contract among the multiple instance smart contracts in the blockchain;
[0159] The second call module 920 is specifically configured to:
[0160] In response to the transaction request, initiate a call to the second smart contract among the multiple instance smart contracts in the blockchain, and also call the first smart contract.
[0161] For the implementation principle of the above modules, refer to the relevant introduction in the smart contract execution method based on the blockchain platform, which will not be elaborated here.
[0162] Using the solution of the embodiment of the present invention, by implementing multiple specific contract virtual machine instances in the WASM virtual machine, it is possible to deploy and call smart contracts implemented in multiple contract languages on top of the smart contracts in the WASM virtual machine without adapting and reconstructing the underlying architecture of the blockchain. The embodiment of the present invention has high feasibility in realizing cross-blockchain smart contract fusion and reuse.
[0163] The embodiment of the present invention further provides an electronic device, including a processor and a memory, in which executable instructions of the processor are stored. Among them, the processor is configured to execute the steps of the smart contract deployment method based on the blockchain platform or the steps of the smart contract execution method based on the blockchain platform by executing the executable instructions.
[0164] As shown above, by using the solution of the embodiment of the present invention, a variety of specific contract virtual machine instances are implemented in the WASM virtual machine, so that the deployment and invocation of smart contracts implemented in a variety of contract languages can be achieved on top of the smart contracts of the WASM virtual machine, without the need to adapt and reconstruct the underlying architecture of the blockchain. The embodiment of the present invention has high feasibility in realizing the cross-blockchain smart contract fusion and reuse.
[0165] Those skilled in the art of the present technology can understand that various aspects of the present invention can be implemented as a system, a method, or a program product. Therefore, various aspects of the present invention can be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or an implementation combining hardware and software aspects, which can be collectively referred to here as "circuit", "module", or "platform".
[0166] Figure 10 is a schematic structural diagram of the electronic device of the present invention. Referring below to Figure 10 to describe the electronic device 1000 according to this embodiment of the present invention. Figure 10 The electronic device 1000 shown is only an example and should not impose any limitation on the functions and usage scope of the embodiments of the present invention.
[0167] As Figure 10 shown, the electronic device 1000 is presented in the form of a general-purpose computing device. The components of the electronic device 1000 may include, but are not limited to: at least one processing unit 1010, at least one storage unit 1020, a bus 1030 connecting different platform components (including the storage unit 1020 and the processing unit 1010), a display unit 1040, etc.
[0168] Among them, the storage unit stores program code, and the program code can be executed by the processing unit 1010, so that the processing unit 1010 executes the steps according to various exemplary embodiments of the present invention described in the above-mentioned electronic prescription transfer processing method part of this specification. For example, the processing unit 1010 can execute the steps as shown in Figure 2 in.
[0169] The storage unit 1020 may include a readable medium in the form of a volatile storage unit, such as a random access storage unit (RAM) 1021 and / or a cache storage unit 1022, and may further include a read-only storage unit (ROM) 1023.
[0170] The storage unit 1020 may also include a program / utility 1024 having a set (at least one) of program modules 1025. Such program modules 1025 include, but are not limited to, a processing system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment.
[0171] The bus 1030 may represent one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus structures.
[0172] The electronic device 1000 may also communicate with one or more external devices 1100 (such as a keyboard, a pointing device, a Bluetooth device, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 1000, and / or may communicate with any device that enables the electronic device 1000 to communicate with one or more other computing devices (such as a router, a modem, etc.). Such communication may be through the input / output (I / O) interface 1050. Also, the electronic device 1000 may communicate with one or more networks (such as a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through the network adapter 1060. The network adapter 10100 may communicate with other modules of the electronic device 1000 through the bus 1030. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 1000, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage platforms, etc.
[0173] An embodiment of the present invention also provides a computer-readable storage medium for storing a program, which when executed implements the steps of a method for deploying a smart contract based on a blockchain platform or the steps of a method for executing a smart contract based on a blockchain platform. In some possible implementation manners, various aspects of the present invention may also be implemented in the form of a program product, which includes program code. When the program product runs on a terminal device, the program code is used to cause the terminal device to execute the steps according to various exemplary embodiments of the present invention described in the above-mentioned part of the electronic prescription circulation processing method of this specification.
[0174] As shown above, through implementing a variety of specific contract virtual machine instances in the WASM virtual machine, the above embodiments of the present invention can implement the deployment and invocation of smart contracts implemented in a variety of contract languages on top of the smart contracts of the WASM virtual machine, without the need to adaptively reconstruct the underlying blockchain architecture. The embodiments of the present invention have high feasibility in realizing cross-blockchain smart contract fusion and reuse.
[0175] A program product 1000 for implementing the above method according to an embodiment of the present invention may be a portable compact disc read-only memory (CD-ROM), include program code, and may run on a terminal device such as a personal computer. However, the program product of the present invention is not limited thereto. In this document, a readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0176] The program product may adopt any combination of one or more readable media. The readable media may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0177] The computer-readable storage medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries the readable program code. Such a propagated data signal may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The readable storage medium may also be any readable medium other than the readable storage medium that can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the readable storage medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination of the above.
[0178] The program code for performing the processing of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and also including conventional procedural programming languages such as the "C" language or similar programming languages. The program code may be executed entirely on the user's computing device, partially on the user's device, executed as a stand-alone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user's computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., by connecting through the Internet using an Internet service provider).
[0179] In summary, the object of the present invention is to provide a method, device and storage medium for deploying and executing smart contracts based on a blockchain platform, which can implement a variety of specific contract virtual machine instances in the WASM virtual machine, so that the deployment and invocation of smart contracts implemented in a variety of contract languages can be realized on top of the smart contracts of the WASM virtual machine, without the need to adapt and reconstruct the underlying architecture of the blockchain. The embodiments of the present invention have high feasibility in realizing the fusion and reuse of cross-blockchain smart contracts.
[0180] The above content is a further detailed description of the present invention in combination with specific preferred embodiments, and it cannot be determined that the specific implementation of the present invention is only limited to these descriptions. For those of ordinary skill in the technical field to which the present invention belongs, without departing from the concept of the present invention, several simple deductions or substitutions can be made, and all should be regarded as belonging to the protection scope of the present invention.
Claims
1. A method for deploying a smart contract based on a blockchain platform, characterized in that, Deploy a WASM virtual machine in the blockchain platform, deploy multiple contract virtual machine instances in the WASM virtual machine that respectively support contract languages of different blockchain platforms, and deploy a first smart contract supported by the WASM virtual machine in the blockchain. The method includes: Obtain a contract deployment transaction based on a target contract language, where the target contract language corresponds to a target contract virtual machine instance among the multiple virtual machine instances; Invoke the first smart contract in the blockchain according to the contract deployment transaction; Execute the first smart contract in the WASM virtual machine, and parse the contract deployment transaction by executing the first smart contract to obtain a second smart contract based on the target contract language; Deploy the second smart contract onto the blockchain.
2. The intelligent contract deployment method based on a blockchain platform according to claim 1, wherein The step of parsing the contract deployment transaction by executing the first smart contract to obtain a second smart contract based on the target contract language includes: Parse the contract deployment transaction by executing the first smart contract to obtain a bytecode contract file based on the target contract language, and the second smart contract formed by using the bytecode file.
3. A method for executing a smart contract based on a blockchain platform, characterized in that, Deploy a WASM virtual machine in the blockchain platform, deploy multiple contract virtual machine instances in the WASM virtual machine that respectively support different contract languages, and deploy a first smart contract supported by the WASM virtual machine and multiple instance smart contracts respectively supported by the multiple contract virtual machine instances in the blockchain. The method includes: Initiate an invocation of a second smart contract and the first smart contract among the multiple instance smart contracts in the blockchain; Execute the first smart contract in the WASM virtual machine, invoke a target contract virtual machine instance that supports the second smart contract among the multiple contract virtual machine instances by executing the first smart contract, and use the target contract virtual machine instance to execute the second smart contract and output an execution result; Upload the execution result to the blockchain.
4. The method for executing a smart contract based on a blockchain platform according to claim 3, wherein Before executing the first smart contract in the WASM virtual machine, the method further includes: Instantiate the invoked second smart contract by using a transaction instance to obtain a contract transaction; Instantiate the invoked first smart contract by using the contract transaction to obtain a virtual machine instance invocation transaction; Execute the first smart contract in the WASM virtual machine, invoke a target contract virtual machine instance that supports the second smart contract among the multiple contract virtual machine instances by executing the first smart contract, and use the target contract virtual machine instance to execute the second smart contract, including: Execute the virtual machine instance invocation transaction in the WASM virtual machine, invoke a target contract virtual machine instance that supports the second smart contract, and use the target contract virtual machine instance to execute the contract transaction.
5. The method for executing a smart contract based on a blockchain platform according to claim 4, wherein Instantiating the invoked second smart contract by using a transaction instance to obtain a contract transaction includes: In the case where the invoked second smart contract is a bytecode file, instantiate the bytecode file by using a transaction instance to obtain a contract transaction implemented based on the bytecode. Executing the contract transaction by using the target contract virtual machine instance includes: Using the target contract virtual machine instance to translate the bytecode into machine code and execute the machine code.
6. The method for executing a smart contract based on a blockchain platform according to claim 4, wherein Instantiating the first smart contract called by the contract transaction to obtain a virtual machine instance call transaction, including: When the first smart contract called is a bytecode file, using the contract transaction to instantiate the bytecode file to obtain a virtual machine instance call transaction based on the bytecode. Executing the virtual machine instance call transaction in the WASM virtual machine to call a target contract virtual machine instance that supports the second smart contract, including: Using the WASM virtual machine to translate the bytecode into machine code and execute the machine code, and calling a target contract virtual machine instance that supports the second smart contract by executing the machine code.
7. The method for executing a smart contract based on a blockchain platform according to claim 3, wherein The method further includes: Before initiating calls to the second smart contract and the first smart contract among the multiple instance smart contracts in the blockchain, receiving a transaction request from a transaction initiator based on the second smart contract. Initiating a call to the second smart contract among the multiple instance smart contracts in the blockchain includes: In response to the transaction request, initiating a call to the second smart contract among the multiple instance smart contracts in the blockchain and also calling the first smart contract.
8. An intelligent contract deployment device based on a blockchain platform, characterized in that, Deploying a WASM virtual machine in the blockchain platform, deploying multiple contract virtual machine instances that respectively support different contract languages in the WASM virtual machine, and deploying the first smart contract supported by the WASM virtual machine in the blockchain. The device includes: A first acquisition module that acquires a contract deployment transaction based on a target contract language, where the target contract language corresponds to a target contract virtual machine instance among the multiple virtual machine instances. A first call module that calls the first smart contract in the blockchain according to the contract deployment transaction. A first execution module that executes the first smart contract in the WASM virtual machine, and parses the contract deployment transaction by executing the first smart contract to obtain a second smart contract based on the target contract language. A deployment module that deploys the second smart contract to the blockchain.
9. An intelligent contract execution device based on a blockchain platform, characterized in that, Deploying a WASM virtual machine in the blockchain platform, deploying multiple contract virtual machine instances that respectively support different contract languages in the WASM virtual machine, and deploying the first smart contract supported by the WASM virtual machine and multiple instance smart contracts respectively supported by the multiple contract virtual machine instances in the blockchain. The device includes: A second call module that initiates calls to the second smart contract and the first smart contract among the multiple instance smart contracts in the blockchain. A second execution module that executes the first smart contract in the WASM virtual machine, calls a target contract virtual machine instance that supports the second smart contract among the multiple contract virtual machine instances by executing the first smart contract, and uses the target contract virtual machine instance to execute the second smart contract and output an execution result. An upload module that uploads the execution result to the blockchain.
10. An electronic device, characterized in that, It includes: A processor; A memory that stores executable instructions of the processor; Wherein, the processor is configured to execute the steps of the smart contract deployment method based on the blockchain platform described in any one of claims 1 to 2, or the steps of the smart contract execution method based on the blockchain platform described in any one of claims 3 - 7 by executing the executable instructions.
11. A computer-readable storage medium for storing a program, characterized in that, When the program is executed by the processor, it implements the steps of the smart contract deployment method based on the blockchain platform described in any one of 1 to 2, or the steps of the smart contract execution method based on the blockchain platform described in any one of claims 3 - 7.
Citation Information
Patent Citations
Multi-intelligent contract virtual machine implementation method, multi-intelligent contract virtual machine and system
CN111736954A
Intelligent contract deployment and calling method based on block chain platform and related equipment
CN112631613A