Implementation method, device, electronic device and storage medium of multi-intelligent contract engine
The multi-smart contract engine adapter supports multiple coding languages and engines, which solves the problem of single engine limitation in existing technology, achieves compatibility and ease of use of multiple blockchain architectures, and reduces learning costs and development difficulty.
Patent Information
- Application Number
- CN202210322481.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-30
- Publication Date
- 2024-09-20
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing blockchain architecture only supports a single smart contract engine, resulting in high learning costs for users, inability to quickly switch contract programming, insufficient versatility, inability to be compatible with multiple virtual machine architectures, and low time performance and ease of use.
Provides a multi-smart contract engine implementation method that supports multiple coding languages through the smart contract engine adapter, obtains the user-coded smart contract language code, compiles it into intermediate bytecode, and loads multiple smart contract engines for implementation and adaptation Multiple blockchain architectures support multiple engines running and loading at the same time.
It reduces the learning cost and development threshold of smart contract language, enhances the compatibility with multiple virtual machine architectures, improves time performance and ease of use, and builds a friendly blockchain ecosystem.
Smart Images

Figure CN115022312B
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and specifically to a method, device, electronic device and storage medium for implementing a multi-intelligent contract engine. Background Art
[0002] Smart contracts are one of the most successful applications of blockchain technology. Blockchain smart contracts support the creation of trustless agreements. The two parties executing the contract can make commitments through the blockchain without knowing or trusting each other. The terms of the agreement are automatically executed after the specified conditions of the contract are met, eliminating the need for third-party intermediaries. Using smart contracts instead of traditional contracts can significantly reduce transaction costs. In the field of cryptocurrency applications, smart contracts are composed of a set of digital protocols with specific rules pre-defined by computer source code. They are applications running on the blockchain. Ethereum is the most popular blockchain platform for creating smart contracts. It supports a feature called Turing completeness, which allows the creation of more customized smart contracts. Smart contracts can be applied to different industries and fields, such as smart homes, e-commerce, real estate, and asset management.
[0003] After the concept of blockchain-based smart contracts was proposed, many studies focused on the application of contracts, and many scholars have done a lot of research on the security of smart contracts. However, there are relatively few technologies that specifically study the smart contract execution environment and support the execution of multiple contract languages. In addition, the existing blockchain architecture supports a single smart contract engine, which makes it costly for users to learn smart contracts and unable to quickly switch from familiar contract programming, making the chain architecture less versatile. Summary of the invention
[0004] The embodiments of the present application provide a method, device, electronic device and storage medium for implementing a multi-intelligent contract engine, which can support multiple engines running on a blockchain node at the same time, support multiple engines loading at the same time, so as to adapt to different types of blockchain architectures, be friendly to contract callers and application deployers, and facilitate the construction of a friendly blockchain ecosystem.
[0005] On the one hand, the present application provides a method for applying to a blockchain system, wherein the blockchain system includes a smart contract engine adapter, wherein the smart contract engine adapter includes multiple smart contract engines, wherein the smart contract engine adapter supports multiple coding languages, and each coding language corresponds to a compiler, wherein the method includes:
[0006] Get the smart contract language code corresponding to the target smart contract encoded by the user in the target compiler;
[0007] Compile the smart contract language code into contract bytecode by the target compiler to obtain the intermediate bytecode corresponding to the target smart contract;
[0008] The multiple smart contract engines are loaded to implement the smart contract on the intermediate bytecode to obtain the machine code of the target smart contract, and the machine code of the target smart contract is adapted to multiple different types of blockchain architectures.
[0009] In some embodiments of the present application, obtaining the smart contract language code corresponding to the target smart contract encoded by the user in the target compiler includes:
[0010] Obtaining a coding language selected by a user from among multiple coding languages supported by the smart contract engine adapter for encoding the target smart contract;
[0011] Start a target compiler corresponding to the coding language, and obtain a smart contract language code corresponding to the target smart contract encoded by the user in the target compiler.
[0012] In some embodiments of the present application, the loading of the multiple smart contract engines to implement the smart contract on the intermediate bytecode to obtain the machine code of the target smart contract includes:
[0013] Verifying the intermediate bytecode to obtain a verification result;
[0014] After the verification result is that the verification is passed, injecting a preset necessary code into the intermediate bytecode to obtain an injected bytecode;
[0015] The injected bytecode is translated into machine code to obtain the machine code of the target smart contract.
[0016] In some embodiments of the present application, the verifying the intermediate bytecode to obtain a verification result includes:
[0017] Performing an ABI check on the intermediate bytecode to obtain a first check result;
[0018] Checking the virtual machine execution environment corresponding to the intermediate bytecode to obtain a second checking result;
[0019] Performing a version check on the smart contract to select an interpreter corresponding to the version of the target smart contract, and obtaining a third check result;
[0020] The verification result includes a first inspection result, a second inspection result and a third inspection result.
[0021] In some embodiments of the present application, injecting the preset necessary code into the intermediate bytecode to obtain the injected bytecode includes:
[0022] Injecting the Gas data consumed by each operation of the target smart contract into the intermediate bytecode to obtain the bytecode after Gas injection;
[0023] In the Gas injected bytecode, the necessary calling interface and data for implementing the target smart contract are injected to build a reasonable context environment for the execution of the target smart contract to obtain the injected bytecode.
[0024] In some embodiments of the present application, injecting the Gas data consumed by each operation of the target smart contract into the intermediate bytecode to obtain the bytecode after Gas injection includes:
[0025] Collect statistics on the Gas data consumed by each operation of the target smart contract;
[0026] Convert the intermediate bytecode into a formatted text that is easy to parse;
[0027] Injecting the consumed Gas data into the formatted text to obtain the formatted text after Gas injection;
[0028] The formatted text after Gas injection is restored to bytecode to obtain the bytecode after Gas injection.
[0029] On the other hand, the present application provides a device for implementing multiple smart contract engines, which is applied to a blockchain system. The blockchain system includes a smart contract engine adapter, and the smart contract engine adapter includes multiple smart contract engines. The smart contract engine adapter supports multiple coding languages, and each coding language corresponds to a compiler. The device includes:
[0030] The acquisition module is used to obtain the smart contract language code corresponding to the target smart contract encoded by the user in the target compiler;
[0031] A compiling module, used to compile the smart contract language code into contract bytecode through the target compiler to obtain the intermediate bytecode corresponding to the target smart contract;
[0032] An implementation module is used to load the multiple smart contract engines to implement the smart contract on the intermediate bytecode to obtain the machine code of the target smart contract, and the machine code of the target smart contract is adapted to multiple different types of blockchain architectures.
[0033] In some embodiments of the present application, the acquisition module is specifically used for:
[0034] Obtaining a coding language selected by a user from among multiple coding languages supported by the smart contract engine adapter for encoding the target smart contract;
[0035] Start a target compiler corresponding to the coding language, and obtain a smart contract language code corresponding to the target smart contract encoded by the user in the target compiler.
[0036] In some embodiments of the present application, the implementation module is specifically used for:
[0037] Verifying the intermediate bytecode to obtain a verification result;
[0038] After the verification result is that the verification is passed, injecting a preset necessary code into the intermediate bytecode to obtain an injected bytecode;
[0039] The injected bytecode is translated into machine code to obtain the machine code of the target smart contract.
[0040] In some embodiments of the present application, the implementation module is specifically used for:
[0041] Performing an ABI check on the intermediate bytecode to obtain a first check result;
[0042] Checking the virtual machine execution environment corresponding to the intermediate bytecode to obtain a second checking result;
[0043] Performing a version check on the smart contract to select an interpreter corresponding to the version of the target smart contract, and obtaining a third check result;
[0044] The verification result includes a first inspection result, a second inspection result and a third inspection result.
[0045] In some embodiments of the present application, the implementation module is specifically used for:
[0046] Injecting the Gas data consumed by each operation of the target smart contract into the intermediate bytecode to obtain the bytecode after Gas injection;
[0047] In the Gas injected bytecode, the necessary calling interface and data for implementing the target smart contract are injected to build a reasonable context environment for the execution of the target smart contract to obtain the injected bytecode.
[0048] In some embodiments of the present application, the implementation module is specifically used for:
[0049] Collect statistics on the Gas data consumed by each operation of the target smart contract;
[0050] Convert the intermediate bytecode into a formatted text that is easy to parse;
[0051] Injecting the consumed Gas data into the formatted text to obtain the formatted text after Gas injection;
[0052] The formatted text after Gas injection is restored to bytecode to obtain the bytecode after Gas injection.
[0053] On the other hand, the present application also provides an electronic device, the electronic device comprising:
[0054] one or more processors;
[0055] Memory; and
[0056] One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor to implement the implementation method of the multi-smart contract engine described in any one of the first aspects.
[0057] In a fourth aspect, the present application also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program is loaded by a processor to execute the steps in the implementation method of the multi-smart contract engine described in any one of the first aspects.
[0058] In the embodiment of the present application, the smart contract language code corresponding to the target smart contract encoded by the user in the target compiler is obtained; the smart contract language code is compiled into the contract bytecode by the target compiler to obtain the intermediate bytecode corresponding to the target smart contract; multiple smart contract engines are loaded to implement the smart contract on the intermediate bytecode to obtain the machine code of the target smart contract, and the machine code of the target smart contract is adapted to multiple different types of blockchain architectures. The multi-smart contract engine of the present application can support multiple engines to run on the blockchain node at the same time, support multiple engines to be loaded at the same time, to adapt to different types of blockchain architectures, and is friendly to contract callers and application deployers, which is conducive to building a friendly blockchain ecosystem. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0060] Figure 1 It is a scenario diagram of a multi-intelligent contract engine implementation architecture provided in an embodiment of the present application;
[0061] Figure 2 It is a schematic diagram of a scenario of a smart contract system provided in an embodiment of the present application;
[0062] Figure 3 It is a structural diagram of the smart contract engine adapter in the embodiment of the present application;
[0063] Figure 4 It is a flowchart of an implementation method of a multi-smart contract engine in an embodiment of the present application;
[0064] Figure 5 This is a flowchart of an embodiment of step 403 provided in the embodiments of the present application;
[0065] Figure 6 It is a schematic diagram of the structure of an embodiment of a device for implementing a multi-smart contract engine provided in an embodiment of the present application;
[0066] Figure 7 It is a schematic diagram of the structure of an embodiment of an electronic device provided in the embodiments of the present application. DETAILED DESCRIPTION
[0067] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.
[0068] In the description of the present application, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside" and the like indicate positions or positional relationships based on the positions or positional relationships shown in the accompanying drawings, which are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present application. In addition, the terms "first" and "second" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the said features. In the description of the present application, the meaning of "multiple" is two or more, unless otherwise clearly and specifically defined.
[0069] In this application, the word "exemplary" is used to mean "used as an example, illustration, or description." Any embodiment described in this application as "exemplary" is not necessarily to be construed as being preferred or advantageous over other embodiments. The following description is given to enable any technician in the field to implement and use the present application. In the following description, details are listed for the purpose of explanation. It should be understood that a person of ordinary skill in the art can recognize that the present application can be implemented without using these specific details. In other instances, well-known structures and processes will not be elaborated in detail to avoid obscuring the description of the present application with unnecessary details. Therefore, the present application is not intended to be limited to the embodiments shown, but is consistent with the widest scope consistent with the principles and features disclosed in the present application.
[0070] The following first introduces some basic concepts involved in the embodiments of the present application:
[0071] Blockchain is a term in the field of information technology. In essence, it is a shared database, and the data or information stored in it has the characteristics of "unforgeable", "full traceability", "traceability", "openness and transparency", and "collective maintenance". Based on these characteristics, blockchain technology has laid a solid foundation of "trust", created a reliable "cooperation" mechanism, and has broad application prospects.
[0072] Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of the information (anti-counterfeiting) and generate the next block.
[0073] Blockchain Node: A node is a network node in a blockchain distributed system. It is a server, computer, phone, etc. connected through a network. For blockchains of different natures, the way to become a node will also be different.
[0074] Smart Contract: A set of digitally defined, propagated, verified or executed agreements, including protocols on which the parties can execute these agreements. Smart contracts allow for trusted transactions without a third party, which are traceable and irreversible. Smart contracts are used to manage transactions in blockchains and are a set of logical rules based on script code. The program reads the contract code when executing transactions, executes it and processes the results. The nature of smart contracts can not only be limited to code specific to a certain application, but can also be used to weave the terms and conditions of the agreement into the transaction process.
[0075] Genesis block: The first block of data in the blockchain ledger, which is the first block of the blockchain.
[0076] BFR (Blockchain Framework): It is the compilation framework of BVM, responsible for the compilation of smart contracts in BVM. After the contract enters the BFR module, it is compiled into executable machine code after BFR front-end, optimization, and back-end compilation, and runs on the blockchain. Among them, BVM is a blockchain-based virtual machine (Blockchain Virtual Machine), and the multi-smart contract virtual machine described in the embodiment of this application is a blockchain-based virtual machine. It should be noted that the multi-smart contract virtual machine in this application can support at least two smart contracts, so it is called a multi-smart contract virtual machine.
[0077] Smart contracts were first proposed by Nick Szabo in 1994, who defined them as contracts that are automatically executed by distributed ledgers, and are then called smart contracts. These digital contracts can be converted into code and run on the blockchain. Smart contracts are a tool that can combine protocols with user interfaces, thereby standardizing and securing computer networks.
[0078] It was not until the emergence of blockchain technology that it gradually developed. Smart contracts running on blockchains were not widely used until the emergence of Ethereum. Ethereum smart contracts run on virtual machines, and the contract language Solidity is Turing complete and supports the development of a variety of applications. Different types of blockchain networks have different categories of smart contracts. As a system, once the predefined rules are met, the smart contract will conduct digital asset transactions or information communication, and all network nodes will copy and execute the contract source code.
[0079] Smart contracts have account balances, private storage, and executable code. The contract state includes the contract storage and balance. The state is stored on the blockchain and is updated every time it is called. Figure 2 Depicts the smart contract system. Each smart contract will be assigned a unique address of fixed bytes, and once a smart contract is deployed to the blockchain, the contract content cannot be changed. First, the user only sends a transaction to the contract address to sign the contract, and then the transaction will be executed by each consensus node in the network to reach a consensus on the transaction and finally update the contract status. Based on the received transactions, the contract can read and write account data, deposit digital assets into the account, receive messages or digital assets from users or other contracts, and even create new contracts.
[0080] There are two types of smart contracts: deterministic smart contracts and non-deterministic smart contracts. Deterministic smart contracts do not require any external (from outside the blockchain) information when running. A non-deterministic smart contract is a contract that relies on external information, such as requiring the current weather information to run, which is not available on the blockchain.
[0081] After the concept of blockchain-based smart contracts was proposed, many studies focused on the application of contracts, as shown in the following document 1. Many scholars have also done a lot of research on the security of smart contracts, as shown in the following document 2. However, there are relatively few technologies that specifically study the smart contract execution environment and support the execution of multiple contract languages. The following will introduce several studies related to the contract execution system:
[0082] Reference 1: A tool called Geth-query for high-speed replay and data extraction of smart contracts is provided. This tool captures the intermediate process information of transaction execution in the EVM virtual machine, records the difference in the world state after each block executes transactions in sequence in the virtual machine, and maintains the key state transfer information of the entire blockchain system at the lowest cost. In addition, it saves the key trace information of the execution process of each transaction in the EVM through indexes, and retains the execution process information of the transaction. This solution can realize multi-dimensional execution process replay, all transaction execution replay in any block, any transaction execution process replay, and any virtual machine state replay during the execution of the contract. Finally, it can quickly restore the state of the smart contract at any time in history and adjust the parallel parameters to maximize the utilization efficiency of local resources.
[0083] Literature 2: A three-layer smart contract system framework including a high-level smart contract layer, a smart contract layer, and a machine code execution layer is proposed. A high-level smart contract layer is added to the original smart contract layer and machine code execution layer. First, users can write high-level smart contract languages according to real contracts or real intentions; then, through the compiler of the high-level smart contract language, the contract is converted into a smart contract written in a traditional programming language; finally, the machine code is generated and deployed and run in the blockchain. The contract language in this smart contract system is closer to natural language, easy to read and understand, supports efficient smart contract generation, and generates a more systematic target language smart contract program framework.
[0084] However, the learning cost and development threshold of the smart contract language in the above-mentioned existing technologies are high, it is not compatible with multiple virtual machine architectures, and its time performance and ease of use are low.
[0085] Based on this, this application aims at the compatibility issue of smart contract engines. Through the research on engine adapters, an implementation solution that supports multiple smart contract engines is designed. It supports multiple high-level smart contract languages, which can reduce the learning cost and development threshold of contract languages. At the same time, it is compatible with multiple virtual machine architectures, with better time performance and ease of use.
[0086] Specifically, the embodiments of the present application provide a method, device, electronic device and storage medium for implementing a multi-smart contract engine, which are described in detail below.
[0087] See also Figure 1 , Figure 1 A schematic diagram of the scenario of the pluggable architecture of multiple smart contract engines provided in the embodiment of the present application, including smart contract engine adaptation modules, distributed applications, development tools, oracles, etc. Through the integration of multiple technologies such as pluggable engines and smart oracles, the characteristics of data immutability, Turing completeness, consistent execution results, data interactivity, and contract interactivity are achieved.
[0088] Specifically, the multi-smart contract engine implementation architecture is as follows: Figure 1 As shown, it contains the following parts:
[0089] (1) DAPP
[0090] DAPP is the abbreviation of Decentralized Application, which is called distributed application / decentralized application in Chinese. Generally speaking, different DAPPs will adopt different underlying blockchain development platforms and consensus mechanisms, or issue tokens on their own (or use universal tokens based on the same blockchain platform).
[0091] The predefined business rules of DAPP are defined by smart contracts deployed on the blockchain, which initiate transactions to the blockchain ledger and receive transaction receipt information. They are executed deterministically, effectively reducing the trust cost. The resources consumed by the application are measured through the token rules in the blockchain.
[0092] (2) Development tools: An integrated development environment for smart contracts, used to publish smart contracts. It includes the following parts:
[0093] Editor: The development tool is based on the editor as the main theme, providing shortcut keys for various operations to facilitate code editing.
[0094] Debugger: When debugging your code, you can display variable values directly next to them in the source code. When the value of a variable changes, it is highlighted, so you can better understand how the state changes with the code.
[0095] Framework selector: You can quickly generate different language templates by selecting different frameworks.
[0096] Multi-language support: It can understand multiple languages, including solidity, java, C++, C, etc.
[0097] (3) Multi-smart contract virtual machine: including compilation, verification, injection, and execution layers. In the core module, the multi-smart contract engine adapter component dynamically adapts to engines such as EVM, WASM, and JVM, and can execute multiple languages such as JavaScript, Solidity, C / C++, and Go. In addition, the multi-smart contract engine adapter component provides a friendly debugging and development environment in each blockchain node, making it easier to write and debug contracts. It provides a variety of smart contract templates, such as transfer templates, token templates, signature templates, etc., which can quickly build safe and reliable smart contracts.
[0098] (4) Oracle: Through the oracle, data can be obtained and output by connecting to various off-chain environments such as data providers, web APIs, IoT devices, payment systems, and other blockchains. Running on-chain and off-chain at the same time, the on-chain module interacts with the blockchain and waits for data response and node consensus. The off-chain module processes data requests, obtains off-chain data and converts the format, and sends blockchain data to the off-chain system for calculation.
[0099] (5) Blockchain network: The underlying ledger structure of the blockchain includes blockchain nodes. The blockchain nodes include consensus, status, and storage. Multiple smart contract virtual machines interact with blockchain nodes through ChainVMC (Chain Client-VM Connector API), abstracting the ChainVMC interface standard. Through ChainVMC, blockchain nodes can connect to multiple smart contract virtual machines.
[0100] In the embodiment of the present application, the implementation method of multiple smart contract engines can be a blockchain node, wherein the blockchain node corresponds to an electronic device, which mainly obtains the smart contract language code corresponding to the target smart contract encoded by the user in the target compiler; compiles the smart contract language code into contract bytecode through the target compiler to obtain the intermediate bytecode corresponding to the target smart contract; loads the multiple smart contract engines to implement the smart contract on the intermediate bytecode to obtain the machine code of the target smart contract, and the machine code of the target smart contract is adapted to multiple different types of blockchain architectures.
[0101] In the embodiment of the present application, the blockchain node can be an electronic device, such as a user terminal or a server, wherein the server can be an independent server, or a server network or server cluster composed of servers, for example, the server described in the embodiment of the present application includes but is not limited to a computer, a network host, a single network server, a plurality of network server sets or a plurality of servers. Cloud servers. Among them, cloud servers are composed of a large number of computers or network servers based on cloud computing (Cloud Computing). In the embodiment of the present application, communication between the server and the user terminal can be achieved by any communication method, including but not limited to, mobile communications based on the third generation partnership project (3rd Generation Partnership Project, 3GPP), long term evolution (Long Term Evolution, LTE), Worldwide Interoperability for Microwave Access (Worldwide Interoperability for Microwave Access, WiMAX), or computer network communications based on TCP / IP protocol suite (TCP / IP Protocol Suite, TCP / IP), User Datagram Protocol (User Datagram Protocol, UDP) protocol, etc.
[0102] It is understood that the user terminal used in the embodiments of the present application includes both receiving and transmitting hardware devices, that is, devices with receiving and transmitting hardware capable of performing two-way communication on a two-way communication link. Such user terminal devices may include: cellular or other communication devices with a single-line display or a multi-line display or a cellular or other communication device without a multi-line display. The specific user terminal may be a desktop terminal or a mobile terminal, and the user terminal may be one of a mobile phone, a tablet computer, a laptop computer, etc.
[0103] Those skilled in the art will understand that Figure 1 The application environment shown in the figure is only one application scenario of the present application solution and does not constitute a limitation on the application scenario of the present application solution. Other application environments may also include Figure 1 There may be more or fewer modules shown in the figure, but the specific details are not limited here.
[0104] It should be noted that Figure 1 The multi-smart contract engine implementation architecture shown is only an example. The blockchain system and scenario described in the embodiment of the present application are intended to more clearly illustrate the technical solution of the embodiment of the present application, and do not constitute a limitation on the technical solution provided in the embodiment of the present application. Ordinary technicians in this field can know that with the evolution of the blockchain system and the emergence of new business scenarios, the technical solution provided in the embodiment of the present application is also applicable to similar technical problems.
[0105] Based on the above content, in an embodiment of the present application, a method for implementing a multi-smart contract engine is first provided. The executor of the method for implementing a multi-smart contract engine is an implementation device of the multi-smart contract engine. The implementation device of the multi-smart contract engine is applied to an electronic device. The method for implementing a multi-smart contract engine includes: obtaining a smart contract language code corresponding to a target smart contract encoded by a user in a target compiler; compiling the smart contract language code into a contract bytecode through the target compiler to obtain an intermediate bytecode corresponding to the target smart contract; loading the multiple smart contract engines to implement the smart contract on the intermediate bytecode to obtain a machine code of the target smart contract, and the machine code of the target smart contract is adapted to multiple different types of blockchain architectures.
[0106] like Figure 3 As shown, it is a schematic diagram of the structure framework of the smart contract engine adapter in the multi-smart contract virtual machine in the embodiment of the present application.
[0107] The smart contract engine adapter can support multiple smart contract engines running on the blockchain node at the same time, and supports multiple smart contract engines to be loaded at the same time to adapt to different types of blockchain architectures. The smart contract engine adapter mainly includes the following parts:
[0108] (1) Language layer: can support multiple languages: such as JavaScript, Solidity, C / C++, JAVA;
[0109] (2) Compilation layer: Different types of compilers are connected to different high-level languages, such as solidity connected to the solc compiler, java connected to the javac compiler, and C / C++ connected to the gcc compiler. The compilation unit compiles the input high-level smart contract language into bytecode through the compilation adapter. Different high-level smart contract languages output bytecode files with different suffixes. For example, the bytecode file generated by the solidity source file .sol after being compiled through the solc compiler interface is the sol smart contract file, and the bytecode file generated by the java source file a.java after being compiled through the javac compiler interface is a.class (execute java a); the C series language souceC.cpp is compiled through the gcc compilation (gcc, g++) interface to generate the file ouceC.out (execute the command . / a.out); the go language source.go is compiled through the gccgo compilation interface (go build) to generate the bytecode file source (execute the command . / program name).
[0110] The compiler adapter interface is connected to different compiler units. Different types of smart contracts are processed by different compiler units after the adapter interface, and different bytecode files are output. The output bytecode is a sequence of encoded numerical constants, references, instructions, etc. It has nothing to do with specific machine codes and needs to be translated by an interpreter to become an intermediate code of machine code.
[0111] (3) Engine layer: It can support smart contract engines such as JSVM, EVM, WASM, and JVM in a pluggable manner. Since different types of smart contracts contain different bytecode features, the pluggable virtual machine engine interface can identify the features and determine which virtual machine should be used to execute the bytecode. After selecting the corresponding virtual machine, it loads the bytecode, parses the bytecode, and then executes the corresponding function according to the instructions.
[0112] (4) Implementation layer: It is divided into verification, injection, interpretation, and execution modules to support the implementation of different smart contract engines.
[0113] 1) Verification: The verification module will perform some verification on the smart contract bytecode and passed parameters, including ABI check, environment check and version check:
[0114] ABI verification: Use the smart contract ABI to verify the smart contract calls and parameters sent by the user.
[0115] Environment check: Check whether the virtual machine execution environment meets expectations, whether the configuration fields and bytecodes are legal, and whether the types are correct; and whether the interpreter module is ready.
[0116] Version check: Check the smart contract version and select the corresponding version of the interpreter.
[0117] 2) Injection: The injection module mainly injects some necessary codes into the smart contract bytecode.
[0118] Gas Metering:
[0119] Count the Gas (gas is the number of instructions required to execute a transaction on the Ethereum virtual machine) required for each operation, implement the Env_api method useGas; then restore the bytecode to a formatted text that is easy to parse (such as JSON); then inject useGas into the formatted text; finally, restore the formatted text to bytecode again.
[0120] If Gas Metering is deployed at the compilation layer, although it only needs to be injected once, saving execution overhead, malicious users only need to change the compiler's Gas table to commit malicious acts, greatly reducing security; at the same time, it is no longer possible to update Gas Metering for deployed old contracts, resulting in inconsistent Gas charging standards for new and old contracts.
[0121] Deployed in the execution layer, the smart contract performs a Gas Metering injection each time it is executed. Although some execution efficiency is sacrificed, Gas can be flexibly changed, which is crucial for public chain projects that are constantly adjusted and iterated.
[0122] Context building:
[0123] Build a reasonable context environment for contract execution and provide necessary internal modules and data for contract use, including: blockchain ledger instance, providing a calling interface for blocks, transactions and other information; state database instance, providing a calling interface for adding, deleting, modifying and checking state data; current Transaction and Action related data; current block height and block time.
[0124] 3) Interpretation: Translate the bytecode into machine code and build the corresponding Env_api. Env_api is the interface provided by the blockchain to the contract for interacting with the blockchain. The env module is constructed by the virtual machine using the interpreter's API to build a native module and implement the pre-designed Env_api. Env_api must be implemented in the native language. Use the interpreter's module resolver moduleResolver to load before executing the code. ChainVMC provides a set of general interaction interfaces between virtual machines and clients. Different virtual machines only need to implement these interfaces to provide interactive functions for blockchain clients. The client and virtual machine implementations are separated from each other, and the underlying virtual machine implementation can be flexibly switched according to actual conditions.
[0125] 4) Execution: The core module of the virtual machine is responsible for executing the contract bytecode and returning the result. For the same parameters and context, no matter what device it is run on, when it is run, or how many times it is run, the running results are consistent. Efficient execution: The execution time of the virtual machine is no longer than the maximum time given by the consensus algorithm for transaction execution. A corresponding shutdown and rollback mechanism is provided. When the execution fails, all state changes involved in this execution need to be rolled back. The sandbox environment ensures resource isolation between contracts and between contracts and the host system, and can prevent the adverse effects of malicious and faulty contracts.
[0126] like Figure 4 As shown, it is a flowchart of an embodiment of a method for implementing a multi-intelligent contract engine in an embodiment of the present application. The method for implementing a multi-intelligent contract engine includes the following steps 401 to 403:
[0127] 401. Obtain the smart contract language code corresponding to the target smart contract encoded by the user in the target compiler.
[0128] Among them, the target compiler is one of the compilers corresponding to multiple coding languages, such as the solc compiler that supports solidity, the javac compiler that supports java, the gcc compiler that supports C / C++, etc., which are not limited here.
[0129] Furthermore, obtaining the smart contract language code corresponding to the target smart contract encoded by the user in the target compiler includes: obtaining the user to select a coding language for encoding the target smart contract from a plurality of coding languages supported by the smart contract engine adapter; starting the target compiler corresponding to the coding language, and obtaining the smart contract language code corresponding to the target smart contract encoded by the user in the target compiler.
[0130] Specifically, the method of obtaining the smart contract language code corresponding to the target smart contract encoded by the user in the target compiler may be to receive the smart contract and smart contract related parameters output by the user through the target compiler. The parameters related to the smart contract may specifically include but are not limited to: the language used by the smart contract, the type of the virtual machine running, the type of the smart contract, the permissions of the smart contract, etc.
[0131] The smart contract virtual machine that the smart contract is connected to can be determined based on the smart contract and the parameters related to the smart contract output by the target compiler. Specifically, the virtual machine interface category that the smart contract is connected to can be determined, and each smart contract virtual machine corresponds to a virtual machine interface category. Based on the virtual machine interface category, a unique smart contract virtual machine can be determined.
[0132] 402. Compile the smart contract language code into contract bytecode through the target compiler to obtain the intermediate bytecode corresponding to the target smart contract.
[0133] Specifically, the compilation adapter interface in the smart contract engine adapter is connected to different compiler units. Different types of smart contracts are processed by different compiler units after the adapter interface, and different bytecode files are output. The output bytecode is a sequence of encoded numerical constants, references, instructions, etc. It has nothing to do with specific machine codes and needs to be translated by an interpreter to become an intermediate code of machine code.
[0134] For example, the compilation unit in the smart contract engine adapter compiles the input high-level smart contract language into bytecode through the compilation adapter. Different high-level smart contract languages output bytecode files with different suffixes. For example, the bytecode file generated by the solidity source file .sol after being compiled through the solc compiler interface is the sol smart contract file, and the bytecode file generated by the java source file a.java after being compiled through the javac compiler interface is a.class (execute java a); the C series language souceC.cpp is compiled through the gcc compilation (gcc, g++) interface to generate a file ouceC.out (execute the command . / a.out); the go language source.go is compiled through the gccgo compilation interface (go build) to generate a bytecode file source (execute the command . / program name).
[0135] The smart contract engine adapter can support smart contract engines such as JSVM, EVM, WASM, JVM, etc. in a pluggable manner. Since different types of smart contracts contain different bytecode features, the pluggable virtual machine engine interface can identify the features and determine which multi-smart contract virtual machine to use to execute the bytecode. After selecting the corresponding virtual machine, it loads the bytecode, parses the bytecode, and then executes the corresponding function according to the instructions.
[0136] Preferably, before outputting the intermediate bytecode file, the intermediate bytecode file may be optimized accordingly.
[0137] 403. Load the multiple smart contract engines to implement the smart contract on the intermediate bytecode to obtain the machine code of the target smart contract, where the machine code of the target smart contract is compatible with multiple different types of blockchain architectures.
[0138] Among them, the machine code of the target smart contract is adapted to a variety of different types of blockchain architectures and can be adapted to different smart contract programming languages.
[0139] In the embodiment of the present application, the smart contract language code corresponding to the target smart contract encoded by the user in the target compiler is obtained; the smart contract language code is compiled into the contract bytecode by the target compiler to obtain the intermediate bytecode corresponding to the target smart contract; multiple smart contract engines are loaded to implement the smart contract on the intermediate bytecode to obtain the machine code of the target smart contract, and the machine code of the target smart contract is adapted to multiple different types of blockchain architectures. The multi-smart contract engine of the present application can support multiple engines to run on the blockchain node at the same time, support multiple engines to be loaded at the same time, to adapt to different types of blockchain architectures, and is friendly to contract callers and application deployers, which is conducive to building a friendly blockchain ecosystem.
[0140] In some embodiments of the present application, Figure 5 As shown, the loading of the multiple smart contract engines to implement the smart contract on the intermediate bytecode to obtain the machine code of the target smart contract may include the following steps 501 to 503:
[0141] 501. Verify the intermediate bytecode to obtain a verification result.
[0142] 502. After the verification result is that the verification is passed, a preset necessary code is injected into the intermediate bytecode to obtain an injected bytecode.
[0143] 503. Translate the injected bytecode into machine code to obtain the machine code of the target smart contract.
[0144] Steps 501 to 503 are implemented in the implementation layer of the smart contract engine adapter: divided into modules such as verification, injection, interpretation, and execution to support the implementation of different smart contract engines.
[0145] In some embodiments of the present application, the verification of the intermediate bytecode to obtain the verification result includes: performing an ABI check on the intermediate bytecode to obtain a first check result; checking the virtual machine execution environment corresponding to the intermediate bytecode to obtain a second check result; performing a version check on the smart contract to select an interpreter corresponding to the version of the target smart contract to obtain a third check result; the verification result includes the first check result, the second check result and the third check result. When the first check result and the second check result pass, it means that the above verification result is a passed verification.
[0146] Among them, the verification module in the smart contract engine adapter will perform some verification on the smart contract bytecode and parameter transmission, including ABI check, environment check and version check. ABI verification: Use the contract ABI to verify the contract call and parameters sent by the user. Environment check: Check whether the virtual machine execution environment meets expectations, configuration fields, whether the bytecode is legal, and whether the type is correct; whether the interpreter module is ready. Version check: Check the contract version and select the corresponding version of the interpreter.
[0147] Specifically, the first check result includes the ABI check result, the second check result is the environment check result, and the third check result is the version check result.
[0148] Furthermore, the injecting of preset necessary code into the intermediate bytecode to obtain the injected bytecode includes: injecting the Gas data consumed by each operation of the target smart contract into the intermediate bytecode to obtain the Gas-injected bytecode; injecting the necessary calling interface and data for implementing the target smart contract into the Gas-injected bytecode to build a reasonable context environment for the execution of the target smart contract to obtain the injected bytecode.
[0149] Among them, injecting the Gas data consumed by each operation of the target smart contract into the intermediate bytecode to obtain the bytecode after Gas injection includes: counting the Gas data consumed by each operation of the target smart contract; converting the intermediate bytecode into a formatted text that is easy to parse; injecting the consumed Gas data into the formatted text to obtain the formatted text after Gas injection; restoring the formatted text after Gas injection into bytecode to obtain the bytecode after Gas injection.
[0150] In the embodiment of the present application, some necessary codes are injected into the smart contract bytecode through the injection module of the smart contract engine adapter.
[0151] Among them, the injection module includes the Gas Metering step: used to count the Gas required for each operation. Implement the Env_api method useGas; then restore the bytecode to a formatted text that is easy to parse (such as JSON); then inject useGas into the formatted text; finally restore the formatted text to bytecode. If Gas Metering is deployed in the compilation layer, although it only needs to be injected once, saving the execution cost, malicious users only need to change the compiler's Gas table to do evil, which greatly reduces security; at the same time, it is no longer possible to update Gas Metering for old smart contracts that have been deployed, resulting in inconsistent Gas charging standards for new and old smart contracts. Deployed in the execution layer, the smart contract performs a Gas Metering injection each time it is executed. Although some execution efficiency is sacrificed, Gas can be flexibly changed, which is crucial for public chain projects that are constantly adjusted and iterated.
[0152] Context environment construction steps: Build a reasonable context environment for the execution of smart contracts, and provide necessary internal modules and data for the contract to use, including: blockchain ledger instance, providing a calling interface for block, transaction and other information; state database instance, providing a calling interface for adding, deleting, modifying and checking state data; current Transaction and Action related data; current block height and block time.
[0153] In some implementations of the present application, in step 503, the injected bytecode is translated into machine code to obtain the machine code of the target smart contract. The bytecode can be translated into machine code by the interpreter in the smart contract engine adapter. First, the corresponding Env_api is constructed. Env_api is the interface provided by the blockchain to the contract for interacting with the blockchain. The env module is constructed by the virtual machine using the API of the interpreter to build a native module and implement the pre-designed Env_api. Env_api must be implemented in the native language. The module resolver moduleResolver of the interpreter is used to load before executing the code.
[0154] ChainVMC provides a set of universal interaction interfaces between virtual machines and clients. Different virtual machines only need to implement these interfaces to provide interactive functions for blockchain clients. The client and virtual machine implementations are separated from each other, and the underlying virtual machine implementation can be flexibly switched according to actual conditions.
[0155] The execution module of the multi-smart contract virtual machine is responsible for executing the smart contract bytecode and returning the result. For the same parameters and context, no matter what device it is run on, when it is run, or how many times it is run, the running results are consistent. Efficient execution: The execution time of the multi-smart contract virtual machine is no longer than the maximum time given by the consensus algorithm for transaction execution. A corresponding shutdown and rollback mechanism is provided. When the execution fails, all state changes involved in this execution need to be rolled back. The sandbox environment ensures resource isolation between smart contracts and between smart contracts and the host system, and can prevent the adverse effects of malicious and faulty smart contracts.
[0156] In order to better implement the implementation method of multiple smart contract engines in the embodiment of the present application, based on the implementation method of multiple smart contract engines, an implementation device of multiple smart contract engines is also provided in the embodiment of the present application. The implementation device of multiple smart contract engines is applied to a blockchain system, and the blockchain system includes a smart contract engine adapter, and the smart contract engine adapter includes multiple smart contract engines. The smart contract engine adapter supports multiple coding languages, and each coding language corresponds to a compiler, such as Figure 6 As shown, the implementation device 600 of the multi-smart contract engine includes:
[0157] An acquisition module 601 is used to acquire a smart contract language code corresponding to a target smart contract encoded by a user in a target compiler;
[0158] A compiling module 602 is used to compile the smart contract language code into a contract bytecode through the target compiler to obtain an intermediate bytecode corresponding to the target smart contract;
[0159] The implementation module 603 is used to load the multiple smart contract engines to implement the smart contract on the intermediate bytecode to obtain the machine code of the target smart contract, and the machine code of the target smart contract is adapted to multiple different types of blockchain architectures.
[0160] In the embodiment of the present application, the acquisition module 601 obtains the smart contract language code corresponding to the target smart contract encoded by the user in the target compiler; the compilation module 602 compiles the smart contract language code into the contract bytecode through the target compiler to obtain the intermediate bytecode corresponding to the target smart contract; the implementation module 603 loads multiple smart contract engines to implement the smart contract on the intermediate bytecode to obtain the machine code of the target smart contract, and the machine code of the target smart contract is adapted to multiple different types of blockchain architectures. The multi-smart contract engine of the present application can support multiple engines to run on the blockchain node at the same time, support multiple engines to be loaded at the same time, to adapt to different types of blockchain architectures, to be friendly to contract callers and application deployers, and to help build a friendly blockchain ecosystem.
[0161] In some embodiments of the present application, the acquisition module 601 is specifically used for:
[0162] Obtaining a coding language selected by a user from among multiple coding languages supported by the smart contract engine adapter for encoding the target smart contract;
[0163] Start a target compiler corresponding to the coding language, and obtain a smart contract language code corresponding to the target smart contract encoded by the user in the target compiler.
[0164] In some implementation schemes of the present application, the implementation module 603 is specifically used to:
[0165] Verifying the intermediate bytecode to obtain a verification result;
[0166] After the verification result is that the verification is passed, injecting a preset necessary code into the intermediate bytecode to obtain an injected bytecode;
[0167] The injected bytecode is translated into machine code to obtain the machine code of the target smart contract.
[0168] In some implementation schemes of the present application, the implementation module 603 is specifically used to:
[0169] Performing an ABI check on the intermediate bytecode to obtain a first check result;
[0170] Checking the virtual machine execution environment corresponding to the intermediate bytecode to obtain a second checking result;
[0171] Performing a version check on the smart contract to select an interpreter corresponding to the version of the target smart contract, and obtaining a third check result;
[0172] The verification result includes a first inspection result, a second inspection result and a third inspection result.
[0173] In some implementation schemes of the present application, the implementation module 603 is specifically used to:
[0174] Injecting the Gas data consumed by each operation of the target smart contract into the intermediate bytecode to obtain the bytecode after Gas injection;
[0175] In the Gas injected bytecode, the necessary calling interface and data for implementing the target smart contract are injected to build a reasonable context environment for the execution of the target smart contract to obtain the injected bytecode.
[0176] In some implementation schemes of the present application, the implementation module 603 is specifically used to:
[0177] Collect statistics on the Gas data consumed by each operation of the target smart contract;
[0178] Convert the intermediate bytecode into a formatted text that is easy to parse;
[0179] Injecting the consumed Gas data into the formatted text to obtain the formatted text after Gas injection;
[0180] The formatted text after Gas injection is restored to bytecode to obtain the bytecode after Gas injection.
[0181] The embodiment of the present application further provides an electronic device, which integrates any one of the implementation devices of the multi-smart contract engine provided in the embodiment of the present application, and the electronic device includes:
[0182] one or more processors;
[0183] Memory; and
[0184] One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor in the steps of the implementation method of the multi-intelligent contract engine described in any of the embodiments of the implementation method of the multi-intelligent contract engine.
[0185] The present application also provides an electronic device that integrates any of the multi-smart contract engine implementation devices provided in the present application. Figure 7 As shown, it shows a schematic diagram of the structure of the electronic device involved in the embodiment of the present application, specifically:
[0186] The electronic device may include components such as a processor 701 with one or more processing cores, a memory 702 with one or more computer-readable storage media, a power supply 703, and an input unit 704. Those skilled in the art will appreciate that Figure 7 The electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0187] The processor 701 is the control center of the electronic device. It uses various interfaces and lines to connect various parts of the entire electronic device. By running or executing software programs and / or modules stored in the memory 702, and calling data stored in the memory 702, it performs various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole. Optionally, the processor 701 may include one or more processing cores; preferably, the processor 701 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 701.
[0188] The memory 702 can be used to store software programs and modules. The processor 701 executes various functional applications and data processing by running the software programs and modules stored in the memory 702. The memory 702 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 702 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 702 may also include a memory controller to provide the processor 701 with access to the memory 702.
[0189] The electronic device also includes a power supply 703 for supplying power to each component. Preferably, the power supply 703 can be logically connected to the processor 701 through a power management system, so as to manage charging, discharging, and power consumption through the power management system. The power supply 703 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.
[0190] The electronic device may further include an input unit 704, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0191] Although not shown, the electronic device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 701 in the electronic device will load the executable files corresponding to the processes of one or more application programs into the memory 702 according to the following instructions, and the processor 701 will run the application programs stored in the memory 702, thereby realizing various functions, as follows:
[0192] Obtain the smart contract language code corresponding to the target smart contract encoded by the user in the target compiler; compile the smart contract language code into contract bytecode through the target compiler to obtain the intermediate bytecode corresponding to the target smart contract; load the multiple smart contract engines to implement the smart contract on the intermediate bytecode to obtain the machine code of the target smart contract, and the machine code of the target smart contract is adapted to multiple different types of blockchain architectures.
[0193] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0194] To this end, an embodiment of the present application provides a computer-readable storage medium, which may include: a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc. A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps in any of the implementation methods of the multi-smart contract engine provided in the embodiment of the present application. For example, the computer program can be loaded by the processor to execute the following steps:
[0195] Obtain the smart contract language code corresponding to the target smart contract encoded by the user in the target compiler; compile the smart contract language code into contract bytecode through the target compiler to obtain the intermediate bytecode corresponding to the target smart contract; load the multiple smart contract engines to implement the smart contract on the intermediate bytecode to obtain the machine code of the target smart contract, and the machine code of the target smart contract is adapted to multiple different types of blockchain architectures.
[0196] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the detailed description of other embodiments above, and will not be repeated here.
[0197] In specific implementation, the above units or structures can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above units or structures can refer to the previous method embodiments, which will not be repeated here.
[0198] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0199] The above is a detailed introduction to the implementation method, device, electronic device and storage medium of a multi-smart contract engine provided in the embodiments of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, according to the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A method for implementing a multi-intelligent contract engine, characterized in that: Applied to a blockchain system, the blockchain system includes a smart contract engine adapter, the smart contract engine adapter includes multiple smart contract engines, the smart contract engine adapter supports multiple coding languages, each coding language corresponds to a compiler, the method includes: Get the smart contract language code corresponding to the target smart contract encoded by the user in the target compiler; Compile the smart contract language code into contract bytecode by the target compiler to obtain the intermediate bytecode corresponding to the target smart contract; Loading the multiple smart contract engines to implement the smart contract on the intermediate bytecode to obtain the machine code of the target smart contract, where the machine code of the target smart contract is adapted to multiple different types of blockchain architectures; The step of obtaining the smart contract language code corresponding to the target smart contract encoded by the user in the target compiler includes: Obtaining a coding language selected by a user from among multiple coding languages supported by the smart contract engine adapter for encoding the target smart contract; Start a target compiler corresponding to the coding language, and obtain a smart contract language code corresponding to the target smart contract encoded by the user in the target compiler; The loading of the multiple smart contract engines to implement the smart contract on the intermediate bytecode to obtain the machine code of the target smart contract includes: Verifying the intermediate bytecode to obtain a verification result; After the verification result is that the verification is passed, injecting a preset necessary code into the intermediate bytecode to obtain an injected bytecode; Translate the injected bytecode into machine code to obtain the machine code of the target smart contract; The step of verifying the intermediate bytecode to obtain a verification result includes: Performing an ABI check on the intermediate bytecode to obtain a first check result; Checking the virtual machine execution environment corresponding to the intermediate bytecode to obtain a second checking result; Performing a version check on the smart contract to select an interpreter corresponding to the version of the target smart contract, and obtaining a third check result; The verification result includes a first inspection result, a second inspection result and a third inspection result; The step of injecting a preset necessary code into the intermediate bytecode to obtain an injected bytecode includes: Injecting the Gas data consumed by each operation of the target smart contract into the intermediate bytecode to obtain the bytecode after Gas injection; In the Gas injected bytecode, the necessary calling interface and data for implementing the target smart contract are injected to build a reasonable context environment for the execution of the target smart contract to obtain the injected bytecode.
2. The method for implementing a multi-intelligent contract engine according to claim 1, characterized in that: The injecting the Gas data consumed by each operation of the target smart contract into the intermediate bytecode to obtain the bytecode after Gas injection includes: Collect statistics on the Gas data consumed by each operation of the target smart contract; Convert the intermediate bytecode into a formatted text that is easy to parse; Injecting the consumed Gas data into the formatted text to obtain the formatted text after Gas injection; The formatted text after Gas injection is restored to bytecode to obtain the bytecode after Gas injection.
3. A device for implementing a multi-intelligent contract engine, used to implement the method for implementing a multi-intelligent contract engine according to any one of claims 1-2, characterized in that: Applied to a blockchain system, the blockchain system includes a smart contract engine adapter, the smart contract engine adapter includes multiple smart contract engines, the smart contract engine adapter supports multiple coding languages, each coding language corresponds to a compiler, and the device includes: The acquisition module is used to obtain the smart contract language code corresponding to the target smart contract encoded by the user in the target compiler; A compiling module, used to compile the smart contract language code into contract bytecode through the target compiler to obtain the intermediate bytecode corresponding to the target smart contract; An implementation module is used to load the multiple smart contract engines to implement the smart contract on the intermediate bytecode to obtain the machine code of the target smart contract, and the machine code of the target smart contract is adapted to multiple different types of blockchain architectures.
4. The implementation device of the multi-intelligent contract engine according to claim 3 is characterized in that: The acquisition module is specifically used for: Obtaining a coding language selected by a user from among multiple coding languages supported by the smart contract engine adapter for encoding the target smart contract; Start a target compiler corresponding to the coding language, and obtain a smart contract language code corresponding to the target smart contract encoded by the user in the target compiler.
5. An electronic device, characterized in that: The electronic device comprises: one or more processors; memory; and One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor to implement the implementation method of the multi-smart contract engine described in any one of claims 1-2.
6. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps in the implementation method of a multi-smart contract engine as described in any one of claims 1-2.
