Smart contract deployment and calling method based on blockchain platform and related equipment
By translating the Solidity smart contract into WASM bytecode and storing it on the blockchain platform, the problems of low execution efficiency and difficult development of smart contracts are solved, and more efficient smart contract deployment and call are achieved, thus improving the blockchain Overall performance of the system.
Patent Information
- Application Number
- CN202011602278.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-29
- Publication Date
- 2025-01-17
- Estimated Expiration
- 2040-12-29
AI Technical Summary
The execution efficiency of smart contracts on existing blockchain platforms is low and difficult to develop, especially for the improvement of deployed Solidity smart contracts.
Deploy transactions by obtaining Solidity contracts from the software development toolkit, parsing and translating the Solidity bytecode BIN contract file as WASM bytecode BIN contract file, and storing it on the blockchain platform, and determining whether to translate and call based on the contract call transactions , improve execution efficiency and reduce development difficulty.
It improves the deployment and execution efficiency of smart contracts on the blockchain platform, reduces the development difficulty of developers, simplifies the development process, and increases the throughput and overall performance of the blockchain system.
Smart Images

Figure CN112631613B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of blockchain, and in particular to a method, device, computer equipment and computer storage medium for deploying and calling a smart contract based on a blockchain platform. Background Art
[0002] At present, the smart contract execution methods based on the blockchain platform mainly include: directly using Solidity smart contracts, using WASM smart contract bytecode technology, or converting Solidity smart contracts into WASM bytecode files through intermediate language files.
[0003] Since most smart contracts in existing blockchains are written in Solidity, the learning cost of using Solidity smart contracts is very low, which makes it the most widely used method. However, due to the design of Solidity smart contracts themselves, their execution efficiency will become lower and lower as the business becomes more and more complex, and this reason cannot be overcome at present.
[0004] The use of WASM smart contract bytecode technology mainly involves writing smart contracts in development languages such as RUST / C++, then compiling smart contracts into WASM bytecodes through the corresponding compiler, and then deploying the WASM bytecodes to the blockchain. This method requires the use of the blockchain platform's WASM interpreter to interpret and execute WASM bytecodes to call WASM smart contracts. Since WASM bytecodes can usually be optimized through some technical means to achieve good execution efficiency, the execution efficiency of WASM smart contracts is improved compared to Solidity smart contracts, but it is only applicable to the deployment of new smart contracts. When the blockchain platform already has Solidity smart contracts, if a new smart contract is developed to replace the original smart contract, it will increase development costs and development risks. In addition, the use of WASM smart contracts requires developers to learn multiple smart contract development languages in order to use WASM smart contract development interfaces in various languages to adapt to the blockchain platform, which increases the development difficulty of the blockchain platform and developers.
[0005] For converting Solidity smart contracts into WASM bytecode files through intermediate language files, the main method is to use Solidity to write smart contracts, then use some compilers to convert Solidity into intermediate language files, and then convert the intermediate language files into WASM bytecode files, and then deploy them to the blockchain platform. This method is similar to using WASM smart contract bytecode technology and is suitable for newly deployed Solidity smart contracts. Therefore, this method does not work for smart contracts that have been deployed on the original blockchain. For developers, they often hope to improve the execution efficiency of smart contracts that have been deployed to the blockchain. Therefore, how to improve the execution efficiency of smart contracts on the blockchain without increasing the development difficulty of the blockchain and developers is a problem that needs to be solved urgently.
[0006] In summary, the above-mentioned existing technologies have the problems of low execution efficiency and great development difficulty of smart contracts on the blockchain platform. Summary of the invention
[0007] The embodiments of the present invention provide a method, device, computer equipment and storage medium for deploying and calling a smart contract based on a blockchain platform to solve the problems of low execution efficiency and high development difficulty of smart contracts on the blockchain platform.
[0008] A smart contract deployment method based on a blockchain platform, comprising:
[0009] Get the Solidity contract deployment transaction from the SDK;
[0010] When there is no contract deployment address corresponding to the Solidity contract deployment transaction in the blockchain platform, parse the Solidity contract deployment transaction and obtain the corresponding Solidity bytecode BIN contract file and interface description ABI file;
[0011] After confirming that the type of the smart contract to be deployed is a Solidity contract according to the Solidity bytecode BIN contract file, the Solidity bytecode BIN contract file is translated to obtain a WASM bytecode BIN contract file;
[0012] The Solidity bytecode BIN contract file, the interface description ABI file, and the WASM bytecode BIN contract file are stored in the blockchain platform for calling.
[0013] A smart contract calling method based on a blockchain platform, comprising:
[0014] When the contract file has been deployed on the blockchain platform, when the contract file needs to be called, the contract call transaction is obtained from the software development kit;
[0015] When there is a contract call address corresponding to the contract call transaction in the blockchain platform, parse the contract call transaction and obtain the corresponding interface description ABI file, the contract call address and function information;
[0016] According to the contract call transaction, search in the blockchain platform whether there is a corresponding WASM bytecode BIN contract file for the contract call address;
[0017] When the WASM bytecode BIN contract file is not found, extracting the Solidity bytecode BIN contract file corresponding to the contract call address from the blockchain platform;
[0018] When the pressure of the blockchain platform is less than a preset pressure threshold, the Solidity bytecode BIN contract file is translated into a WASM bytecode BIN contract file, and the WASM bytecode BIN contract file is executed and called according to the contract call transaction;
[0019] When the pressure of the blockchain platform is not less than the preset pressure threshold, the Solidity bytecode BIN contract file is executed and called according to the contract call transaction;
[0020] The Solidity bytecode BIN contract file, the interface description ABI file, and the WASM bytecode BIN contract file are stored in the blockchain platform for calling.
[0021] A smart contract deployment device based on a blockchain platform, comprising:
[0022] Deployment transaction acquisition module, used to obtain Solidity contract deployment transactions from the software development kit;
[0023] A deployment transaction parsing module, used to parse the Solidity contract deployment transaction and obtain the corresponding Solidity bytecode BIN contract file and interface description ABI file when there is no contract deployment address corresponding to the Solidity contract deployment transaction in the blockchain platform;
[0024] A file translation module, for translating the Solidity bytecode BIN contract file to obtain a WASM bytecode BIN contract file after confirming that the type of the smart contract to be deployed is a Solidity contract according to the Solidity bytecode BIN contract file;
[0025] The first storage module is used to store the Solidity bytecode BIN contract file, the interface description ABI file and the WASM bytecode BIN contract file to the blockchain platform for calling.
[0026] A smart contract calling device based on a blockchain platform, comprising:
[0027] The call transaction acquisition module is used to obtain the contract call transaction from the software development kit when the contract file needs to be called when the contract file has been deployed on the blockchain platform;
[0028] A call transaction parsing module, used to parse the contract call transaction when there is a contract call address corresponding to the contract call transaction in the blockchain platform, and obtain the corresponding interface description ABI file, contract call address and function information;
[0029] An address search module, used to search the blockchain platform for whether the contract call address has a corresponding WASM bytecode BIN contract file according to the contract call transaction;
[0030] A file extraction module, used to extract the Solidity bytecode BIN contract file corresponding to the contract call address from the blockchain platform when the WASM bytecode BIN contract file is not found;
[0031] A first execution calling module, used for translating the Solidity bytecode BIN contract file into a WASM bytecode BIN contract file when the pressure of the blockchain platform is less than a preset pressure threshold, and executing and calling the WASM bytecode BIN contract file according to the contract calling transaction;
[0032] A second execution calling module, configured to execute and call the Solidity bytecode BIN contract file according to the contract calling transaction when the pressure of the blockchain platform is not less than the preset pressure threshold;
[0033] The second storage module is used to store the Solidity bytecode BIN contract file, the interface description ABI file and the WASM bytecode BIN contract file to the blockchain platform for calling.
[0034] A computer device comprises a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the above-mentioned smart contract deployment method based on the blockchain platform or the smart contract calling method based on the blockchain platform are implemented.
[0035] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the above-mentioned smart contract deployment method based on a blockchain platform or the smart contract calling method based on a blockchain platform.
[0036] The above-mentioned smart contract deployment and calling method, device, computer equipment and storage medium based on the blockchain platform obtains the Solidity contract deployment transaction from the software development kit, parses the Solidity contract deployment transaction, and obtains the corresponding Solidity bytecode BIN contract file and interface description ABI file, translates the Solidity bytecode BIN contract file into a WASM bytecode BIN contract file, and then stores the Solidity bytecode BIN contract file, the interface description ABI file and the WASM bytecode BIN contract file to the blockchain platform. When calling the smart contract, the contract call transaction is obtained from the software development kit, and the contract call address pair is found in the blockchain platform according to the contract call transaction. The WASM bytecode BIN contract file corresponding to the contract call address is found. When the WASM bytecode BIN contract file is not found, the Solidity bytecode BIN contract file corresponding to the contract call address is extracted from the blockchain platform, the Solidity bytecode BIN contract file is translated into a WASM bytecode BIN contract file, and the WASM bytecode file is executed and called according to the contract call transaction, or the Solidity bytecode BIN contract file is executed and called according to the contract call transaction, which improves the deployment efficiency of smart contracts on the blockchain platform and reduces the development difficulty of developers. When the blockchain platform calls a smart contract, it can directly call the stored smart contract, which improves the execution efficiency of the smart contract. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0038] Figure 1 It is a schematic diagram of an application environment of a smart contract deployment method based on a blockchain platform and a smart contract calling method based on a blockchain platform in one embodiment of the present invention;
[0039] Figure 2 It is another application environment schematic diagram of a smart contract deployment method based on a blockchain platform and a smart contract calling method based on a blockchain platform in one embodiment of the present invention;
[0040] Figure 3 It is a flow chart of a smart contract deployment method based on a blockchain platform in one embodiment of the present invention;
[0041] Figure 4 It is a flow chart of a smart contract calling method based on a blockchain platform in one embodiment of the present invention;
[0042] Figure 5 It is a structural diagram of a smart contract deployment device based on a blockchain platform in one embodiment of the present invention;
[0043] Figure 6 It is a structural diagram of a smart contract calling device based on a blockchain platform in one embodiment of the present invention;
[0044] Figure 7 is a schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION
[0045] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0046] The smart contract deployment method based on the blockchain platform provided by the embodiment of the present invention can be applied in Figure 1 In the application environment shown, the computer device / terminal device / ... communicates with the server through a network. The computer device / terminal device / ... may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, and portable wearable devices. The server may be implemented as an independent server or a server cluster consisting of multiple servers.
[0047] In one embodiment of the present invention, Figure 3 As shown, a smart contract deployment method based on a blockchain platform is provided, and the method is applied in Figure 1 Taking the server in as an example, the method includes the following steps S301 to S304.
[0048] Before step S301, the smart contract developer writes a Solidity smart contract, and uses the Solidity compiler to compile the Solidity smart contract source code to obtain the Solidity bytecode BIN (Binar, binary) file and the interface description ABI (Application Binary Interface) file required for deployment. Based on the Solidity bytecode BIN contract file and the interface description ABI file, the software development kit corresponding to the blockchain platform is used to form a contract deployment transaction. After the contract deployment transaction is completed, the blockchain account is used to sign the contract deployment transaction.
[0049] The following is a detailed description of steps S301 to S304:
[0050] Step S301: Get the Solidity contract deployment transaction from the software development kit.
[0051] Specifically, the Solidity contract deployment transaction is obtained from the software development kit and given to the blockchain platform for contract deployment address identification. The Solidity contract deployment transaction includes information such as the transaction initiator's account address, the Solidity bytecode BIN contract file, and the interface description ABI file.
[0052] It should be noted here that:
[0053] Solidity is a contract-oriented, high-level programming language created to implement smart contracts. A bytecode file is a binary file that contains an execution program and consists of a sequence of opcode / data pairs. A byte is a unit of data in a computer.
[0054] The software development kit (SDK) is considered to be the initiator of the contract call transaction or contract deployment transaction, and can also be called the user of the blockchain platform.
[0055] The Solidity bytecode BIN (Binar) file is a binary readable file compiled from the Solidity bytecode BIN contract file source code, containing all executable instructions.
[0056] The interface description ABI (Application Binary Interface) file refers to the interface file after the source code of the Solidity bytecode BIN contract file is compiled in the embodiment of the present invention. It is mainly used to facilitate the software toolkit to construct the contract deployment transaction, the contract call transaction, and the analysis of the execution result after the call is executed.
[0057] After the Solidity contract deployment transaction is obtained in step S301 and sent to the blockchain platform, in an embodiment of the present invention, it is determined whether there is a contract deployment address corresponding to the Solidity contract deployment transaction in the blockchain platform according to whether the contract deployment address in the Solidity contract deployment transaction is empty. If so, the blockchain platform determines that the Solidity contract deployment transaction is a smart contract call transaction. If not, the blockchain platform determines that the Solidity contract deployment transaction is a contract deployment transaction.
[0058] Step S302: When there is no contract deployment address corresponding to the Solidity contract deployment transaction in the blockchain platform, parse the Solidity contract deployment transaction and obtain the corresponding Solidity bytecode BIN contract file and interface description ABI file.
[0059] Step S303: After confirming that the type of the smart contract to be deployed is a Solidity contract according to the Solidity bytecode BIN contract file, the Solidity bytecode BIN contract file is translated to obtain a WASM bytecode BIN contract file.
[0060] For example, if the information of the solidity bytecode BIN contract file starts with "0x6d736100", it is confirmed that the type of smart contract to be deployed is a WASM contract, otherwise it is a Solidity contract. According to the information of the solidity bytecode BIN contract file, it is determined that the smart contract deployed this time is a Solidity contract, and the Solidity bytecode BIN contract file is translated to obtain a WASM bytecode BIN contract file. Among them, WASM is called WebAssembly, which is an open standard that defines a portable binary code format for executable programs, a corresponding text assembly language, and an interface for facilitating interaction between such programs and their host environment. It can enable high-performance applications on web pages and can also be executed and integrated in other environments (including standalone environments). Using WebAssembly to write contracts is more versatile and faster to execute than writing smart contracts in other languages.
[0061] In step S303, the step of translating the Solidity bytecode BIN contract file to obtain the WASM bytecode BIN contract file specifically includes the following steps a and b:
[0062] a. Identify the Solidity execution instructions of the Solidity bytecode BIN contract file.
[0063] b. Translate Solidity execution instructions into WASM execution instructions, and obtain WASM bytecode BIN contract files based on all WASM execution instructions.
[0064] Specifically, the methods of translating Solidity execution instructions into WASM execution instructions in the above step b include the following direct translation method and external call method:
[0065] (1) Direct translation methods include the following:
[0066] Method 1:
[0067] a1. When the data format of Solidity execution instructions and WASM execution instructions are the same and their functions are the same, translate the Solidity execution instructions into WASM execution instructions.
[0068] a2. Construct a WASM bytecode BIN contract file according to the WASM execution instructions.
[0069] In order to better understand the above step a1, step a1 is further explained with reference to an example:
[0070] For example, the Solidity execution instruction is ADD, which needs to pop two parameters from the operand stack as the parameters involved in the addition calculation, and then push the addition calculation result back into the operand stack. This instruction has a corresponding instruction in the WASM execution instruction, named "i32.add", so the Solidity execution instruction ADD can be directly translated and replaced with the WASM execution instruction i32.add. The WASM execution instruction i32.add has the same calculation effect as the Solidity execution instruction ADD.
[0071] Method 2:
[0072] b1. When the data formats of the Solidity execution instructions and the WASM execution instructions are the same but the functions are different, the operand stack and memory of the Solidity execution instructions are simulated in the blockchain platform to obtain a simulated operand stack and a simulated memory.
[0073] b2. Pre-execute the Solidity execution instruction in the simulated operand stack and the simulated memory to obtain the corresponding pre-execution result and the jump path during pre-execution.
[0074] b3. Analyze the pre-execution result and the jump path to obtain the execution path of the Solidity execution instruction from the simulation operand stack and the simulation memory.
[0075] b4. Analyze the execution path to obtain the execution conditions corresponding to the Solidity execution instructions.
[0076] b5. Translate the Solidity execution instructions into WASM execution instructions according to the execution conditions.
[0077] b6. Construct the WASM bytecode BIN contract file according to the WASM execution instruction.
[0078] In the above steps b4 and b5, the execution conditions include but are not limited to data operation type, data length, stack depth, etc.
[0079] In order to better understand the above steps b1 to b5, the above steps b1 to b5 are further explained here with reference to examples:
[0080] For example, the jump instruction in the solidity execution instruction represents a jump instruction, and the br instruction in the wasm execution instruction represents a line break instruction. The br instruction has the same data format as the jump instruction but different functions. In order to translate the jump instruction in the Solidity execution instruction into the br instruction in the WASM execution instruction, it is necessary to simulate the operand stack and memory of the jump instruction in the Solidity execution instruction in the blockchain platform to obtain a simulated operand stack and simulated memory. The specific jump path generated when the jump instruction in the Solidity execution instruction performs instruction pre-execution in the simulated operand stack and simulated memory (such as jumping from counter position 1 to position 3) can be known to the data length, stack depth and other execution conditions of the jump instruction, so that the data length, stack depth and other execution conditions of the jump instruction are applied to the br instruction, and the jump instruction in the Solidity execution instruction is translated into the br instruction in the WASM execution instruction.
[0081] Method 3:
[0082] c1. When the data formats of the Solidity execution instruction and the WASM execution instruction are not interoperable, the operand type of the Solidity execution instruction is obtained in combination with the ABI interface file.
[0083] c2. Translate the Solidity execution instruction into a WASM execution instruction according to the operand type.
[0084] c3. Construct the WASM bytecode BIN contract file according to the WASM execution instruction.
[0085] For the above step c1, when the data formats of Solidity execution instructions and WASM execution instructions are not interoperable, the operand types corresponding to various instructions need to be known during the instruction translation process. After the Solidity smart contract source code is compiled using the Solidity compiler to obtain the Solidity bytecode BIN contract file required for deployment, the operand type of the Solidity execution instruction is lost. However, since the operands of all instructions are of type uint256, the operand type can be obtained by combining the ABI interface file, and the Solidity execution instruction can be translated into the WASM execution instruction according to the operand type.
[0086] In order to better understand the above steps c1 to c2, the above steps c1 to c2 are further explained with reference to examples:
[0087] For example, the Solidity execution instruction is SUB. First, the operand type and data length corresponding to the SUB instruction are obtained according to the interface description ABI file, and then translated into the corresponding WASM execution instruction i32.sub or i64.sub.
[0088] (2) External calling methods include the following:
[0089] d1. When the internal instruction structures of the Solidity execution instruction and the WASM execution instruction are inconsistent, the call instruction in the Solidity execution instruction is translated into a call instruction applicable to the WASM execution instruction.
[0090] d2. According to the call instruction in the WASM execution instruction, the predefined function information is called from the blockchain platform, and the WASM bytecode BIN contract file is formed according to the call instruction in the WASM execution instruction and the predefined function information; the predefined function information is pre-defined inside the virtual machine of the blockchain platform and is used for interacting with the blockchain platform.
[0091] In the above step d2, the predefined function information for interacting with the blockchain platform defined inside the virtual machine of the blockchain platform is called through the call instruction in the WASM execution instruction. The predefined function information is the same as the function information in the contract call transaction to realize cross-contract calling and achieve the same computing effect as the Solidity execution instruction.
[0092] In order to better illustrate the translation relationship between Solidity execution instructions and WASM execution instructions, an instruction translation relationship correspondence table between Solidity execution instructions and WASM execution instructions is provided, as shown in Table 1.
[0093]
[0094]
[0095] Table 1
[0096] It should be noted that if an error is encountered during the instruction translation process, the translation will be stopped, and the translation will be attempted again when the contract is modified and called again. If the translation fails multiple times, the blockchain platform will no longer attempt to translate and will directly deploy the solidity bytecode BIN contract file to prevent multiple invalid translations from causing excessive performance loss to the blockchain platform.
[0097] In addition, while executing the above step S303, this embodiment also includes the following steps:
[0098] Perform memory initialization, function index information construction, global object construction, and execution engine construction for the WASM bytecode BIN contract file.
[0099] Step S304: Store the Solidity bytecode BIN contract file, the interface description ABI file, and the WASM bytecode BIN contract file on the blockchain platform.
[0100] Specifically, step S304 includes:
[0101] Store the Solidity bytecode BIN contract file, interface description ABI file, and WASM bytecode BIN contract file in the database of the blockchain platform;
[0102] Generate a WASM smart contract address corresponding to the WASM bytecode BIN contract file in the database;
[0103] The WASM bytecode BIN contract file and the WASM smart contract address form a one-to-one mapping relationship and store it in the memory of the blockchain platform.
[0104] It should be noted that a WASM smart contract address corresponding to the WASM bytecode BIN contract file is generated in the database of the blockchain platform. The WASM smart contract address can be the same as the address of the solidity bytecode BIN contract file. In the subsequent execution of the contract file, the WASM bytecode BIN file can be directly called according to the address of the solidity bytecode BIN contract file. Alternatively, the WASM smart contract address corresponding to the WASM bytecode BIN contract file generated in the database can be different from the address of the solidity bytecode BIN contract file as needed. In this way, a unique mapping relationship can be established between the solidity bytecode BIN contract file, the WASM bytecode BIN contract file and the WASM smart contract address or the address of the solidity bytecode BIN contract file. In the subsequent execution of the contract file, when querying the address of the solidity bytecode BIN contract file or the WASM smart contract address, the corresponding solidity bytecode BIN contract file and the WASM bytecode BIN contract file can be queried at the same time, and the call of the corresponding contract file can be executed as needed.
[0105] In step S304, the method is applied to Figure 2 In the application environment shown, the blockchain is composed of several nodes that can communicate with each other. Each node can be regarded as a block storage. Each block storage is used to save data. Each data node contains all data. The block storage data has a complete historical record and can be quickly restored and expanded. The regional chain is divided into a public chain, a private chain and an alliance chain. The public chain is open to any node. Everyone can participate in the blockchain calculation, and anyone can download and obtain complete blockchain data. The private chain is that some blockchains do not want anyone to participate in this system. It is not open to the public and is suitable for internal data management and auditing or open testing of specific institutions. The alliance chain is that the permissions of each node participating are completely equal, and everyone can achieve trusted data exchange without full mutual trust. Each node of the alliance chain usually has a corresponding entity organization, and can join and exit the network after authorization. In the process of using the entire blockchain backup system, a digital signature is required. The digital signature designs a hash function, the sender's public key, and the sender's private key. The blockchain has complete distributed storage characteristics. In fact, it is a larger network data storage and uses a data structure in the form of a "hash algorithm" to save basic data.
[0106] In the above step S304, a one-to-one mapping relationship is formed between the Solidity bytecode BIN contract file, the WASM bytecode BIN contract file and the WASM smart contract address, and stored in the blockchain database storage. The characteristics of the blockchain can be used to improve data security, so that when the contract file is called, the execution efficiency of the smart contract in the blockchain platform and the consensus efficiency of the blockchain platform are improved.
[0107] The smart contract calling method based on the blockchain platform provided in the embodiment of the present invention can be applied in the following aspects: Figure 1 In the application environment shown, the computer device / terminal device / ... communicates with the server through a network. The computer device / terminal device / ... may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, and portable wearable devices. The server may be implemented as an independent server or a server cluster consisting of multiple servers.
[0108] In one embodiment of the present invention, Figure 4 As shown, a smart contract calling method based on a blockchain platform is provided, and the method is applied in Figure 1 Taking the server in as an example, the method includes the following steps S401 to S407.
[0109] Step S401: When the contract file has been deployed on the blockchain platform, when the contract file needs to be called, a contract call transaction is obtained from the software development kit.
[0110] It should be noted here that: before step S401, the software toolkit constructs a contract call transaction based on the returned contract deployment result and the deployed smart contract address and other information. After the contract call transaction is completed, the contract call transaction is signed using the sending transaction blockchain account.
[0111] Based on the above content, the specific step of obtaining the contract call transaction from the software development kit in step S401 is: the software development kit sends the signed contract call transaction to the blockchain platform. Among them, the content of the contract call transaction includes the contract call address, contract call function, interface description ABI file and other information.
[0112] Step S402: When there is a contract call address corresponding to the contract call transaction in the blockchain platform, the contract call transaction is parsed, and the corresponding interface description ABI file, the contract call address and function information are obtained.
[0113] Step S403: Search the blockchain platform for the contract call address to see whether there is a corresponding WASM bytecode BIN contract file according to the contract call transaction.
[0114] Specifically, the above-mentioned contract calling address comes from: after the smart contract is deployed to the blockchain platform, the blockchain platform will return the result of the contract deployment and the calling address of the deployed smart contract in the blockchain platform (that is, the above-mentioned contract calling address), and the software toolkit can call the blockchain contract according to this contract address.
[0115] When there is a contract call address corresponding to the contract call transaction in the blockchain platform, the blockchain platform determines that the transaction is a contract call transaction, and searches the blockchain platform for a corresponding WASM bytecode BIN contract file for the contract call address according to the contract call transaction. If there is a corresponding WASM bytecode BIN contract file, the corresponding WASM bytecode BIN contract file is directly executed and called.
[0116] It should be noted here that when searching for a corresponding WASM bytecode BIN contract file at a contract call address in the blockchain platform according to a contract call transaction, in addition to first determining whether a corresponding WASM bytecode BIN contract file exists at a contract call address in the blockchain platform according to a contract call transaction, and then deciding whether to execute the WASM bytecode BIN contract file or to retrieve the solidity bytecode BIN contract file for execution based on the determination result, the solidity bytecode BIN contract file can also be retrieved at the same time when making the determination. If the corresponding WASM bytecode BIN contract file does not exist, the solidity bytecode BIN contract file can be directly executed to further improve the execution efficiency of the smart contract.
[0117] Step S404: When the WASM bytecode BIN contract file is not found, extract the Solidity bytecode BIN contract file corresponding to the contract call address from the blockchain platform.
[0118] Specifically, after parsing the specific content of the contract call transaction, and then identifying that this transaction is a smart contract call transaction based on the contract call address contained in the contract call transaction, the blockchain platform first searches the memory for the WASM bytecode BIN contract file corresponding to the contract call address. If the WASM bytecode BIN contract file corresponding to the contract call address does not exist in the memory, the WASM bytecode BIN contract file corresponding to the contract call address is searched from the blockchain database. If the WASM bytecode BIN contract file corresponding to the contract call address cannot be found, the Solidity bytecode BIN contract file corresponding to the contract call address is retrieved from the blockchain database.
[0119] Step S405: When the pressure of the blockchain platform is less than a preset pressure threshold, the Solidity bytecode BIN contract file is translated into a WASM bytecode BIN contract file, and the WASM bytecode file is executed and called according to the contract call transaction.
[0120] It should be noted here that the pressure of the blockchain platform refers to the capacity status presented in the process of running all transactions on the current blockchain platform. When the pressure does not exceed the preset pressure threshold, it indicates that the blockchain platform can bear the file translation task, so the above step S405 can be executed. The process of translating the Solidity bytecode BIN contract file into the WASM bytecode BIN contract file is described in detail in the process of the smart contract deployment method based on the blockchain platform, and will not be repeated here.
[0121] It should be noted that if an error is encountered during the instruction translation process, the translation will be stopped. The translation will be attempted again when the contract is modified and called again or the pressure on the blockchain platform is less than the preset pressure threshold. If the translation fails multiple times, the blockchain platform will no longer attempt to translate and will directly execute the solidity bytecode BIN contract file to prevent multiple invalid translations from causing excessive performance loss to the blockchain platform.
[0122] In step S405, the step of executing and calling the WASM bytecode BIN contract file according to the contract call transaction includes the following steps A, B and C:
[0123] A. Find the WASM function information corresponding to the contract call transaction in the WASM bytecode BIN contract file according to the contract call transaction;
[0124] B. When WASM function information exists, extract the WASM code segment corresponding to the WASM function information from the WASM bytecode BIN contract file;
[0125] C. Execute all instructions of the WASM code segment in the virtual machine of the blockchain platform until a return instruction or a stop instruction is executed, and generate a WASM instruction execution result and send it to the software development kit.
[0126] For the above step A, the specific steps are:
[0127] According to the contract call function, function parameters and other information in the contract call transaction, find the WASM function information corresponding to the contract call transaction in the WASM bytecode BIN contract file.
[0128] For the above step B, the specific steps are:
[0129] When searching for the WASM function information corresponding to the contract call transaction in the WASM bytecode BIN contract file based on the contract call function, function parameters and other information in the contract call transaction, the WASM code segment corresponding to the WASM function information is taken out from the WASM bytecode BIN contract file. If the WASM function information corresponding to the contract call transaction is not found in the WASM bytecode BIN contract file, the blockchain platform determines that the transaction is an illegal transaction and stops the execution call of the WASM bytecode BIN contract file.
[0130] For the above step C, it is specifically:
[0131] In the virtual machine of the blockchain platform, all instructions in the WASM code segment are executed in sequence according to the order in which all instructions in the WASM code segment are arranged.
[0132] Based on the above step C, all instructions for executing the WASM code segment in the virtual machine of the blockchain platform also include:
[0133] During the execution of a WASM code segment, if function information contained in the WASM code segment is encountered, the function information is directly executed.
[0134] In the process of executing the instructions of the WASM code segment, if the function information defined by the virtual machine to interact with the blockchain platform is encountered, the function information is called and then executed.
[0135] Among them, a virtual machine is an abstract computer that is realized by simulating various computer functions on an actual computer. A relatively famous virtual machine is the Java virtual machine. The Java virtual machine has its own complete hardware architecture, such as processors, stacks, registers, etc., and also has a corresponding instruction system. The Java virtual machine shields information related to the specific operating system platform, so that the Java program only needs to generate target code (bytecode) running on the Java virtual machine, and can run on multiple platforms without modification.
[0136] Step S406: When the pressure of the blockchain platform is not less than the preset pressure threshold, the Solidity bytecode BIN contract file is executed and called according to the contract call transaction.
[0137] It should be noted here that when the pressure of the blockchain platform exceeds the preset pressure threshold, it indicates that the blockchain platform cannot bear the file translation task. Therefore, the above step S406 can specifically execute the Solidity bytecode file according to the contract call function, parameter information, etc. contained in the contract call transaction.
[0138] Specifically, in step S406, the steps of executing and calling the Solidity bytecode BIN contract file according to the contract call transaction include:
[0139] 1. Find the Solidity function information corresponding to the contract call transaction in the Solidity bytecode BIN contract file according to the contract call transaction;
[0140] Specifically, the Solidity function information corresponding to the contract call transaction is searched in the Solidity bytecode file according to the contract call function, parameter information, etc. contained in the contract call transaction.
[0141] 2. When the Solidity function information is found, the instructions of the Solidity code segment are executed in the virtual machine of the blockchain platform until a return instruction or a stop instruction is executed, and the Solidity instruction execution result is generated and sent to the software development kit.
[0142] Specifically, when the Solidity function information is found, the instructions of the Solidity code segment are executed in the virtual machine of the blockchain platform in the order of the instructions of the Solidity code segment until the return instruction or the stop instruction is executed, and the Solidity instruction execution result is generated and sent to the software development kit. During the execution call process, the virtual machine interacts with the data stack, memory and blockchain database, and records the changes in the blockchain database during the interaction process. When the Solidity function information is not found, the execution call of the Solidity bytecode BIN contract file is stopped.
[0143] In addition, after the above step 1, the following steps are included:
[0144] When the Solidity function information cannot be found, the contract call transaction is determined to be an illegal transaction, and the execution call of the Solidity bytecode BIN contract file is stopped.
[0145] Step S407: store the Solidity bytecode BIN contract file, the interface description ABI file, and the WASM bytecode BIN contract file in the blockchain platform for calling.
[0146] Specifically, step S407 includes:
[0147] Store the Solidity bytecode BIN contract file, interface description ABI file, and WASM bytecode BIN contract file in the database of the blockchain platform;
[0148] Generate a WASM smart contract address corresponding to the WASM bytecode BIN contract file in the database;
[0149] The WASM bytecode BIN contract file and the WASM smart contract address form a one-to-one mapping relationship and store it in the memory of the blockchain platform.
[0150] It should be noted that the WASM smart contract address corresponding to the WASM bytecode BIN contract file is generated in the blockchain platform database. The WASM smart contract address can be the same as the address of the solidity bytecode BIN contract file. In the subsequent execution of the contract file, the WASM bytecode BIN file can be directly called according to the address of the solidity bytecode BIN contract file. It can also be necessary to make the WASM smart contract address corresponding to the WASM bytecode BIN contract file generated in the database different from the address of the solidity bytecode BIN contract file. In this way, a unique mapping relationship can be established between the solidity bytecode BIN contract file, the WASM bytecode BIN contract file and the WASM smart contract address or the address of the solidity bytecode BIN contract file. In the subsequent execution of the contract file, when querying the address of the solidity bytecode BIN contract file or the WASM smart contract address, the corresponding solidity bytecode BIN contract file and the WASM bytecode BIN contract file can be queried at the same time, and the call of the corresponding contract file can be executed as needed.
[0151] In step S407, the method is applied to Figure 2 In the application environment shown, the blockchain is composed of several nodes that can communicate with each other. Each node can be regarded as a block storage. Each block storage is used to save data. Each data node contains all data. The block storage data has a complete historical record and can be quickly restored and expanded. The regional chain is divided into a public chain, a private chain and an alliance chain. The public chain is open to any node. Everyone can participate in the blockchain calculation, and anyone can download and obtain complete blockchain data. The private chain is that some blockchains do not want anyone to participate in this system. It is not open to the public and is suitable for internal data management and auditing or open testing of specific institutions. The alliance chain is that the permissions of each node participating are completely equal, and everyone can achieve trusted data exchange without full mutual trust. Each node of the alliance chain usually has a corresponding entity organization, and can join and exit the network after authorization. In the process of using the entire blockchain backup system, a digital signature is required. The digital signature designs a hash function, the sender's public key, and the sender's private key. The blockchain has complete distributed storage characteristics. In fact, it is a larger network data storage and uses a data structure in the form of a "hash algorithm" to save basic data.
[0152] In the above step S407, a one-to-one mapping relationship is formed between the Solidity bytecode BIN contract file, the WASM bytecode BIN contract file and the WASM smart contract address, and stored in the blockchain database storage. The characteristics of the blockchain can be used to improve data security, so that when the contract file is called, the execution efficiency of the smart contract in the blockchain platform and the consensus efficiency of the blockchain platform are improved.
[0153] The smart contract calling and deployment method based on the blockchain platform proposed in the embodiment of the present invention obtains the Solidity contract deployment transaction from the software development kit, parses the Solidity contract deployment transaction, and obtains the corresponding Solidity bytecode BIN contract file and interface description ABI file, translates the Solidity bytecode BIN contract file into a WASM bytecode BIN contract file, and then stores the Solidity bytecode BIN contract file, the interface description ABI file and the WASM bytecode BIN contract file to the blockchain platform. When calling the smart contract, it will first determine whether there is a converted WASM bytecode BIN contract file in the memory. If there is a WASM bytecode BIN contract file, the WASM bytecode BIN contract file is directly called, otherwise the traditional solidity bytecode BIN contract file is called. When the pressure on the blockchain platform is less than the preset pressure threshold, the solidity bytecode BIN contract file will be converted into a WASM bytecode BIN contract file, and then saved in the memory and blockchain database, and an address corresponding to the WASM bytecode file will be generated. When the software toolkit calls the Solidity bytecode BIN contract file of the corresponding address again next time, the corresponding WASM bytecode BIN contract file can be directly found in the memory or blockchain database of the blockchain platform, and the call to the Solidity bytecode BIN contract file will be converted into a call to the WASM bytecode BIN contract file. By converting Solidity bytecode BIN contract files to WASM bytecode BIN contract files, the execution efficiency of smart contracts in the blockchain platform and the consensus efficiency of the blockchain platform are greatly improved, the overall execution performance of the blockchain system is improved, and the throughput of the blockchain system is increased. By converting Solidity bytecode BIN contract files to WASM bytecode BIN contract files, there is no need to learn a new smart contract development language, which saves development costs, greatly improves the development efficiency of smart contracts and maximizes the reuse of the original Solidity bytecode BIN contract files. In addition, the execution speed of WASM bytecode BIN contract files with the same functions can be obtained, which simplifies the development process and reduces the development difficulty for developers.
[0154] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0155] In one embodiment, if Figure 5 As shown, a smart contract deployment device based on a blockchain platform is provided, and the smart contract deployment device of the blockchain platform corresponds one-to-one to the smart contract deployment method of the blockchain platform in the above embodiment. Figure 5 As shown, the smart contract deployment and calling device of the blockchain platform includes a deployment transaction acquisition module 50, a deployment transaction parsing module 51, a file translation module 52, and a first storage module 53. The detailed description of each functional module is as follows:
[0156] A deployment transaction acquisition module 50, used to obtain a Solidity contract deployment transaction from a software development kit;
[0157] A deployment transaction parsing module 51 is used to parse the Solidity contract deployment transaction and obtain the corresponding Solidity bytecode BIN contract file and interface description ABI file when there is no contract deployment address corresponding to the Solidity contract deployment transaction in the blockchain platform;
[0158] A file translation module 52, configured to translate the Solidity bytecode BIN contract file to obtain a WASM bytecode BIN contract file after confirming that the type of the smart contract to be deployed is a Solidity contract according to the Solidity bytecode BIN contract file;
[0159] The first storage module 53 is used to store the Solidity bytecode BIN contract file, the interface description ABI file and the WASM bytecode BIN contract file to the blockchain platform for calling.
[0160] Furthermore, the file translation module 52 includes a first file translation unit, a second file translation unit, and a third file translation unit, wherein:
[0161] The first file translation unit includes a first translation unit and a first constituent unit. The detailed description of each functional unit is as follows:
[0162] The first translation unit is used to translate the Solidity execution instruction into the WASM execution instruction when the data format of the Solidity execution instruction and the WASM execution instruction are the same and the function is the same.
[0163] The first constituent unit is used to form a WASM bytecode BIN contract file according to the WASM execution instruction.
[0164] The second file translation unit includes a simulation processing unit, a jump path acquisition unit, an execution path acquisition unit, a path analysis unit, a second translation unit and a second composition unit. The detailed description of each functional unit is as follows:
[0165] The simulation processing unit is used to simulate the operand stack and memory of the Solidity execution instruction in the blockchain platform to obtain a simulated operand stack and a simulated memory when the data formats of the Solidity execution instruction and the WASM execution instruction are the same but the functions are different.
[0166] A jump path acquisition unit is used to pre-execute the Solidity execution instruction in the simulation operand stack and the simulation memory to obtain the corresponding pre-execution result and the jump path during pre-execution.
[0167] An execution path acquisition unit is used to analyze the pre-execution result and the jump path to obtain an execution path of the Solidity execution instruction from the simulation operand stack and the simulation memory.
[0168] A path analysis unit is used to analyze the execution path to obtain the execution condition corresponding to the Solidity execution instruction.
[0169] The second translation unit is used to translate the Solidity execution instruction into the WASM execution instruction according to the execution condition.
[0170] The second constituent unit is used to construct the WASM bytecode BIN contract file according to the WASM execution instruction.
[0171] The third file translation unit includes a type acquisition unit, a third translation unit and a third composition unit. The detailed description of each functional unit is as follows:
[0172] A type acquisition unit is used to acquire the operand type of the Solidity execution instruction in combination with the ABI interface file when the data formats of the Solidity execution instruction and the WASM execution instruction are not interoperable.
[0173] The third translation unit is used to translate the Solidity execution instruction into the WASM execution instruction according to the operand type.
[0174] The third constituent unit is used to construct the WASM bytecode BIN contract file according to the WASM execution instruction.
[0175] Furthermore, the file translation module 52 includes a fourth file translation unit, wherein:
[0176] The fourth file translation unit includes a fourth translation unit and a fourth composition unit. The detailed description of each functional unit is as follows:
[0177] a fourth translation unit, configured to translate a call instruction in the Solidity execution instruction into a call instruction applicable to the WASM execution instruction when the internal instruction structures between the Solidity execution instruction and the WASM execution instruction are inconsistent;
[0178] The fourth constituent unit is used to call the predefined function information from the blockchain platform according to the call instruction in the WASM execution instruction, and to construct the WASM bytecode BIN contract file according to the call instruction in the WASM execution instruction and the predefined function information; the predefined function information is pre-defined inside the virtual machine of the blockchain platform and is used for interacting with the blockchain platform.
[0179] Furthermore, the file translation module 52 may also include an instruction recognition unit and an instruction translation unit, and each unit is described in detail as follows:
[0180] The instruction recognition unit is used to identify the Solidity execution instructions of the Solidity bytecode BIN contract file.
[0181] The instruction translation unit is used to translate Solidity execution instructions into WASM execution instructions, and obtain WASM bytecode BIN contract files based on all WASM execution instructions.
[0182] Furthermore, the file translation module 52 also includes an initialization unit, and the initialization unit is described in detail as follows:
[0183] The initialization unit is used to initialize the memory of the WASM bytecode BIN contract file, build function index information, build global objects, and build the execution engine.
[0184] Furthermore, the first storage module 53 includes a first storage unit, an address generating unit, and a second storage unit. The details of each unit are as follows:
[0185] The first storage unit is used to store the Solidity bytecode BIN contract file, the interface description ABI file, and the WASM bytecode BIN contract file in the database of the blockchain platform.
[0186] The address generation unit is used to generate a WASM smart contract address corresponding to the WASM bytecode BIN contract file in the database.
[0187] The second storage unit is used to form a one-to-one mapping relationship between the WASM bytecode BIN contract file and the WASM smart contract address and store it in the memory of the blockchain platform.
[0188] In one embodiment, if Figure 6 As shown, a smart contract calling device based on a blockchain platform is provided, and the smart contract calling device of the blockchain platform corresponds one-to-one with the smart contract calling method of the blockchain platform in the above embodiment. Figure 6 As shown, the smart contract calling device of the blockchain platform includes a calling transaction acquisition module 60, a calling transaction parsing module 61, an address search module 62, a file extraction module 63, a first execution calling module 64, a second execution calling module 65, and a second storage module 66. The detailed description of each functional module is as follows:
[0189] The call transaction acquisition module 60 is used to obtain a contract call transaction from the software development kit when a contract file needs to be called when the contract file has been deployed on the blockchain platform.
[0190] The call transaction parsing module 61 is used to parse the contract call transaction when there is a contract call address corresponding to the contract call transaction in the blockchain platform, and obtain the corresponding interface description ABI file, contract call address and function information.
[0191] The address search module 62 is used to search the blockchain platform for whether there is a corresponding WASM bytecode BIN contract file for the contract call address according to the contract call transaction.
[0192] The file extraction module 63 is used to extract the Solidity bytecode BIN contract file corresponding to the contract call address from the blockchain platform when the WASM bytecode BIN contract file is not found.
[0193] The first execution calling module 64 is used to translate the Solidity bytecode BIN contract file into a WASM bytecode BIN contract file when the pressure of the blockchain platform is less than a preset pressure threshold, and to execute and call the WASM bytecode BIN contract file according to the contract calling transaction.
[0194] The second execution calling module 65 is used to execute and call the Solidity bytecode BIN contract file according to the contract calling transaction when the pressure of the blockchain platform is not less than the preset pressure threshold.
[0195] The second storage module 66 is used to store the Solidity bytecode BIN contract file, the interface description ABI file and the WASM bytecode BIN contract file to the blockchain platform for calling.
[0196] Further, the first execution calling module 64 includes a second file translation module and an execution calling module, wherein the second file translation module includes a fifth file translation unit, a sixth file translation unit, and a seventh file translation unit, and each unit is specifically described as follows:
[0197] The fifth file translation unit includes a fifth translation unit and a fifth constituent unit. The detailed description of each functional unit is as follows:
[0198] The fifth translation unit is used to translate the Solidity execution instruction into the WASM execution instruction when the data format of the Solidity execution instruction and the WASM execution instruction are the same and the function is the same.
[0199] The fifth constituent unit is used to form a WASM bytecode BIN contract file according to the WASM execution instruction.
[0200] The sixth file translation unit includes a sixth simulation processing unit, a sixth jump path acquisition unit, a sixth execution path acquisition unit, a sixth path analysis unit, a sixth translation unit and a sixth composition unit. The detailed description of each functional unit is as follows:
[0201] The sixth simulation processing unit is used to simulate the operand stack and memory of the Solidity execution instruction in the blockchain platform to obtain a simulated operand stack and a simulated memory when the data formats of the Solidity execution instruction and the WASM execution instruction are the same but the functions are different.
[0202] The sixth jump path acquisition unit is used to pre-execute the Solidity execution instruction in the simulation operand stack and the simulation memory to obtain the corresponding pre-execution result and the jump path during pre-execution.
[0203] A sixth execution path acquisition unit is used to analyze the pre-execution result and the jump path to obtain an execution path of the Solidity execution instruction from the simulation operand stack and the simulation memory.
[0204] The sixth path analysis unit is used to analyze the execution path to obtain the execution condition corresponding to the Solidity execution instruction.
[0205] A sixth translation unit is used to translate the Solidity execution instruction into a WASM execution instruction according to the execution condition.
[0206] The sixth constituent unit is used to construct the WASM bytecode BIN contract file according to the WASM execution instruction.
[0207] The seventh file translation unit includes a seventh type acquisition unit, a seventh translation unit and a seventh composition unit. The detailed description of each functional unit is as follows:
[0208] The seventh type acquisition unit is used to obtain the operand type of the Solidity execution instruction in combination with the ABI interface file when the data formats of the Solidity execution instruction and the WASM execution instruction are not interoperable.
[0209] A seventh translation unit is used to translate the Solidity execution instruction into a WASM execution instruction according to the operand type.
[0210] The seventh constituent unit is used to construct the WASM bytecode BIN contract file according to the WASM execution instruction.
[0211] Further, the second file translation module includes an eighth file translation unit, wherein:
[0212] The eighth file translation unit includes the fourth translation unit and the fourth composition unit. The detailed description of each functional unit is as follows:
[0213] an eighth translation unit, configured to translate a call instruction in the Solidity execution instruction into a call instruction applicable to the WASM execution instruction when the internal instruction structures between the Solidity execution instruction and the WASM execution instruction are inconsistent;
[0214] The eighth constituent unit is used to call the predefined function information from the blockchain platform according to the call instruction in the WASM execution instruction, and to constitute the WASM bytecode BIN contract file according to the call instruction in the WASM execution instruction and the predefined function information; the predefined function information is pre-defined inside the virtual machine of the blockchain platform and is used for interacting with the blockchain platform.
[0215] Furthermore, the execution calling module includes a first function information searching unit, a first extracting unit and a first instruction executing unit, and each unit is described in detail as follows:
[0216] The first function information searching unit is used to search the WASM function information corresponding to the contract calling transaction in the WASM bytecode BIN contract file according to the contract calling transaction.
[0217] The first extraction unit is used to extract the WASM code segment corresponding to the WASM function information from the WASM bytecode BIN contract file when WASM function information exists.
[0218] The first execution instruction unit is used to execute all instructions of the WASM code segment in the virtual machine of the blockchain platform until a return instruction or a stop instruction is executed, and generate a WASM instruction execution result and send it to the software development kit.
[0219] Furthermore, the second execution calling module 65 includes a second function information searching unit and a second instruction executing unit. The detailed description of each unit is as follows:
[0220] The second function information search unit is used to search the Solidity function information corresponding to the contract call transaction in the Solidity bytecode BIN contract file according to the contract call transaction.
[0221] The second instruction execution unit is used to execute the instructions of the Solidity code segment in the virtual machine of the blockchain platform when the Solidity function information is found, until a return instruction or a stop instruction is executed, and generate a Solidity instruction execution result and send it to the software development kit.
[0222] Furthermore, the second function information search unit further includes a stop execution call unit, and the stop execution call unit is described in detail as follows:
[0223] The execution call stop unit is used to determine that the contract call transaction is an illegal transaction when no Solidity function information is found, and to stop the execution call of the Solidity bytecode BIN contract file.
[0224] Furthermore, the second storage module 66 includes a second storage unit, a second contract address generation unit and a third storage unit, and each unit is described in detail as follows:
[0225] The second storage unit is used to store the Solidity bytecode BIN contract file, the interface description ABI file and the WASM bytecode BIN contract file in the database of the blockchain platform.
[0226] The second contract address generation unit is used to generate a WASM smart contract address corresponding to the WASM bytecode BIN contract file in the database.
[0227] The third storage unit is used to form a one-to-one mapping relationship between the WASM bytecode BIN contract file and the WASM smart contract address and store it in the memory of the blockchain platform.
[0228] The meaning of the serial numbers such as "first" and "second" in the above modules / units is only to distinguish different modules / units, and is not used to define which module / unit has a higher priority or other limiting meanings. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or modules is not necessarily limited to those steps or modules clearly listed, but may include other steps or modules that are not clearly listed or inherent to these processes, methods, products or devices. The division of modules in this application is only a logical division, and there may be other division methods when implemented in actual applications.
[0229] For the specific definition of the smart contract deployment device based on the blockchain platform, please refer to the definition of the smart contract deployment method based on the blockchain platform above, which will not be repeated here. Each module in the above-mentioned smart contract deployment device based on the blockchain platform can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0230] For the specific definition of the smart contract calling device based on the blockchain platform, please refer to the definition of the smart contract calling method based on the blockchain platform above, which will not be repeated here. Each module in the above-mentioned smart contract calling device based on the blockchain platform can be implemented in whole or in part by software, hardware and their combination. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0231] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 7 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data involved in the smart contract deployment and calling method based on the blockchain platform. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a smart contract deployment method based on the blockchain platform is implemented.
[0232] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 7 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data involved in the smart contract deployment and calling method based on the blockchain platform. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a smart contract calling method based on the blockchain platform is implemented.
[0233] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the smart contract deployment and calling method based on the blockchain platform in the above embodiment are implemented, such as Figure 3 Steps 301 to 304 and other extensions of the method and related steps are shown. Alternatively, when the processor executes the computer program, the functions of each module / unit of the smart contract deployment device based on the blockchain platform in the above embodiment are realized, for example Figure 5 The functions of modules 50 to 53 are shown in Figure 5. To avoid repetition, they will not be described here.
[0234] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the smart contract deployment and calling method based on the blockchain platform in the above embodiment are implemented, such as Figure 4 Steps 401 to 407 and other extensions of the method and related steps are shown. Alternatively, when the processor executes the computer program, the functions of each module / unit of the smart contract calling device based on the blockchain platform in the above embodiment are realized, for example Figure 6 The functions of the modules 60 to 66 are shown in Figure 6. To avoid repetition, they will not be described here.
[0235] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the computer device, and various interfaces and lines are used to connect various parts of the entire computer device.
[0236] The memory can be used to store the computer program and / or module, and the processor realizes various functions of the computer device by running or executing the computer program and / or module stored in the memory and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can 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 can store data created according to the use of the mobile phone (such as audio data, video data, etc.), etc.
[0237] The memory may be integrated into the processor or may be arranged separately from the processor.
[0238] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the smart contract deployment method based on the blockchain platform in the above embodiment are implemented, such as Figure 3 Steps 301 to 304 and other extensions of the method and related steps are shown. Alternatively, when the computer program is executed by the processor, the functions of each module / unit of the smart contract deployment and invocation device based on the blockchain platform in the above embodiment are realized, for example Figure 5 The functions of modules 50 to 53 are shown in Figure 5. To avoid repetition, they will not be described here.
[0239] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the smart contract deployment and calling method based on the blockchain platform in the above embodiment are implemented, such as Figure 4Steps 401 to 407 and other extensions of the method and related steps are shown. Alternatively, when the computer program is executed by the processor, the functions of each module / unit of the smart contract deployment and invocation device based on the blockchain platform in the above embodiment are realized, for example Figure 6 The functions of the modules 60 to 66 are shown in Figure 6. To avoid repetition, they will not be described here.
[0240] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0241] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0242] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0243] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A smart contract deployment method based on a blockchain platform, characterized in that: include: Get the Solidity contract deployment transaction from the SDK; When there is no contract deployment address corresponding to the Solidity contract deployment transaction in the blockchain platform, parse the Solidity contract deployment transaction and obtain the corresponding Solidity bytecode BIN contract file and interface description ABI file; After confirming that the type of the smart contract to be deployed is a Solidity contract according to the Solidity bytecode BIN contract file, when the data format and function of the Solidity execution instruction and the WASM execution instruction are the same, the Solidity execution instruction is translated into a WASM execution instruction; a WASM bytecode BIN contract file is formed according to the WASM execution instruction; or, when the data format of the Solidity execution instruction and the WASM execution instruction are the same but the function is different, the operand stack and memory of the Solidity execution instruction are simulated in the blockchain platform to obtain a simulated operand stack and a simulated memory; the Solidity execution instruction is pre-executed in the simulated operand stack and the simulated memory to obtain a corresponding pre-execution result and a jump path during pre-execution; the pre-execution result and the jump path are analyzed to obtain an execution path of the Solidity execution instruction from the simulated operand stack and the simulated memory; Analyze the execution path to obtain the execution condition corresponding to the Solidity execution instruction; translate the Solidity execution instruction into a WASM execution instruction according to the execution condition; construct the WASM bytecode BIN contract file according to the WASM execution instruction; or, when the data formats of the Solidity execution instruction and the WASM execution instruction are not interoperable, obtain the operand type of the Solidity execution instruction in combination with the interface description ABI file; translate the Solidity execution instruction into a WASM execution instruction according to the operand type; construct the WASM bytecode BIN contract file according to the WASM execution instruction; The Solidity bytecode BIN contract file, the interface description ABI file, and the WASM bytecode BIN contract file are stored in the blockchain platform for calling.
2. The method according to claim 1, characterized in that The Solidity bytecode BIN contract file is translated to obtain a WASM bytecode BIN contract file, including: When the internal instruction structures of the Solidity execution instruction and the WASM execution instruction are inconsistent, translating the call instruction in the Solidity execution instruction into a call instruction applicable to the WASM execution instruction; According to the call instruction in the WASM execution instruction, the predefined function information is called from the blockchain platform, and the WASM bytecode BIN contract file is constructed according to the call instruction in the WASM execution instruction and the predefined function information; the predefined function information is pre-defined inside the virtual machine of the blockchain platform and is used for interacting with the blockchain platform.
3. The method according to claim 1 or 2, characterized in that: While translating the Solidity bytecode BIN contract file to obtain a WASM bytecode BIN contract file, the method further includes: Perform memory initialization, function index information construction, global object construction, and execution engine construction of the WASM bytecode BIN contract file.
4. The method according to claim 1, characterized in that: The step of storing the Solidity bytecode BIN contract file, the interface description ABI file, and the WASM bytecode BIN contract file in the blockchain platform includes: Store the Solidity bytecode BIN contract file, the interface description ABI file, and the WASM bytecode BIN contract file in a database; Generate a WASM smart contract address corresponding to the WASM bytecode BIN contract file in a database of the blockchain platform; A one-to-one mapping relationship is formed between the WASM bytecode BIN contract file and the WASM smart contract address and stored in the memory of the blockchain platform.
5. A blockchain-based smart contract calling method, characterized in that: include: When the contract file has been deployed on the blockchain platform, when the contract file needs to be called, the contract call transaction is obtained from the software development kit; When there is a contract call address corresponding to the contract call transaction in the blockchain platform, parse the contract call transaction and obtain the corresponding interface description ABI file, the contract call address and function information; According to the contract call transaction, search in the blockchain platform whether there is a corresponding WASM bytecode BIN contract file for the contract call address; When the WASM bytecode BIN contract file is not found, extracting the Solidity bytecode BIN contract file corresponding to the contract call address from the blockchain platform; When the pressure of the blockchain platform is less than a preset pressure threshold, the Solidity bytecode BIN contract file is translated into a WASM bytecode BIN contract file, and the WASM bytecode BIN contract file is executed and called according to the contract call transaction; When the pressure of the blockchain platform is not less than the preset pressure threshold, the Solidity bytecode BIN contract file is executed and called according to the contract call transaction; The Solidity bytecode BIN contract file, the interface description ABI file, and the WASM bytecode BIN contract file are stored in the blockchain platform for calling.
6. The method according to claim 5, characterized in that The Solidity bytecode BIN contract file is translated to obtain a WASM bytecode BIN contract file, including: When the data format of the Solidity execution instruction and the WASM execution instruction are the same and the function is the same, the Solidity execution instruction is translated into the WASM execution instruction; Construct the WASM bytecode BIN contract file according to the WASM execution instruction; or, When the data formats of the Solidity execution instruction and the WASM execution instruction are the same but the functions are different, the operand stack and the memory of the Solidity execution instruction are simulated in the blockchain platform to obtain a simulated operand stack and a simulated memory; Pre-execute the Solidity execution instruction in the simulated operand stack and the simulated memory to obtain a corresponding pre-execution result and a jump path during pre-execution; Analyze the pre-execution result and the jump path to obtain an execution path of the Solidity execution instruction from the simulation operand stack and the simulation memory; Analyze the execution path to obtain the execution condition corresponding to the Solidity execution instruction; Translate the Solidity execution instructions into WASM execution instructions according to the execution conditions; Construct the WASM bytecode BIN contract file according to all the WASM execution instructions; or, When the data formats of the Solidity execution instruction and the WASM execution instruction are not interoperable, the operand type of the Solidity execution instruction is obtained in combination with the ABI interface file; Translate Solidity execution instructions into WASM execution instructions according to the operand type; The WASM bytecode BIN contract file is constructed according to the WASM execution instruction.
7. The method according to claim 6, characterized in that The Solidity bytecode BIN contract file is translated to obtain a WASM bytecode BIN contract file, including: When the internal instruction structures of the Solidity execution instruction and the WASM execution instruction are inconsistent, translating the call instruction in the Solidity execution instruction into a call instruction applicable to the WASM execution instruction; According to the call instruction in the WASM execution instruction, the predefined function information is called from the blockchain platform, and the WASM bytecode BIN contract file is constructed according to the call instruction in the WASM execution instruction and the predefined function information; the predefined function information is pre-defined inside the virtual machine of the blockchain platform and is used for interacting with the blockchain platform.
8. The method according to claim 6 or 7, characterized in that: While translating the Solidity bytecode BIN contract file to obtain a WASM bytecode BIN contract file, the method further includes: Perform memory initialization, function index information construction, global object construction, and execution engine construction of the WASM bytecode BIN contract file.
9. The method according to claim 8, characterized in that The step of storing the Solidity bytecode BIN contract file, the interface description ABI file, and the WASM bytecode BIN contract file on the blockchain platform includes: Storing the Solidity bytecode BIN contract file, the interface description ABI file, and the WASM bytecode BIN contract file in a database of the blockchain platform; Generate a WASM smart contract address corresponding to the WASM bytecode BIN contract file in a database of the blockchain platform; A one-to-one mapping relationship is formed between the WASM bytecode BIN contract file and the WASM smart contract address and stored in the memory of the blockchain platform.
10. The method according to claim 5, characterized in that The step of executing and calling the WASM bytecode BIN contract file according to the contract call transaction includes: According to the contract call transaction, search the WASM function information corresponding to the contract call transaction in the WASM bytecode BIN contract file; When the WASM function information exists, extract the WASM code segment corresponding to the WASM function information from the WASM bytecode BIN contract file; All instructions of the WASM code segment are executed in the virtual machine of the blockchain platform until a return instruction or a stop instruction is executed, and a WASM instruction execution result is generated and sent to the software development kit.
11. The method according to claim 5, characterized in that The step of executing and calling the Solidity bytecode BIN contract file according to the contract call transaction includes: According to the contract call transaction, search for the Solidity function information corresponding to the contract call transaction in the Solidity bytecode BIN contract file; When the Solidity function information is found, the instructions of the Solidity code segment are executed in the virtual machine of the blockchain platform until a return instruction or a stop instruction is executed, and a Solidity instruction execution result is generated and sent to the software development kit.
12. The method according to claim 11, characterized in that After the step of searching the Solidity function information corresponding to the contract call transaction in the Solidity bytecode BIN contract file according to the contract call transaction, the method further includes: When the Solidity function information cannot be found, the contract call transaction is determined to be an illegal transaction, and the execution call of the Solidity bytecode BIN contract file is stopped.
13. A smart contract deployment device based on a blockchain platform, characterized in that: include: Deployment transaction acquisition module, used to obtain Solidity contract deployment transactions from the software development kit; A deployment transaction parsing module, used to parse the Solidity contract deployment transaction and obtain the corresponding Solidity bytecode BIN contract file and interface description ABI file when there is no contract deployment address corresponding to the Solidity contract deployment transaction in the blockchain platform; A file translation module, for translating the Solidity execution instruction into a WASM execution instruction after confirming that the type of the smart contract to be deployed is a Solidity contract according to the Solidity bytecode BIN contract file, when the data format of the Solidity execution instruction and the WASM execution instruction are the same and the function is the same; forming a WASM bytecode BIN contract file according to the WASM execution instruction; or, when the data format of the Solidity execution instruction and the WASM execution instruction are the same but the function is different, simulating the operand stack and memory of the Solidity execution instruction in the blockchain platform to obtain a simulated operand stack and a simulated memory; pre-executing the Solidity execution instruction in the simulated operand stack and the simulated memory to obtain a corresponding pre-execution result and a jump path during pre-execution; analyzing the pre-execution result and the jump path to obtain an execution path of the Solidity execution instruction from the simulated operand stack and the simulated memory; Analyze the execution path to obtain the execution condition corresponding to the Solidity execution instruction; translate the Solidity execution instruction into a WASM execution instruction according to the execution condition; construct the WASM bytecode BIN contract file according to the WASM execution instruction; or, when the data formats of the Solidity execution instruction and the WASM execution instruction are not interoperable, obtain the operand type of the Solidity execution instruction in combination with the interface description ABI file; translate the Solidity execution instruction into a WASM execution instruction according to the operand type; construct the WASM bytecode BIN contract file according to the WASM execution instruction; The first storage module is used to store the Solidity bytecode BIN contract file, the interface description ABI file and the WASM bytecode BIN contract file to the blockchain platform for calling.
14. A smart contract calling device based on a blockchain platform, characterized in that: include: The call transaction acquisition module is used to obtain the contract call transaction from the software development kit when the contract file needs to be called when the contract file has been deployed on the blockchain platform; A call transaction parsing module, used to parse the contract call transaction when there is a contract call address corresponding to the contract call transaction in the blockchain platform, and obtain the corresponding interface description ABI file, contract call address and function information; An address search module, used to search the blockchain platform for whether the contract call address has a corresponding WASM bytecode BIN contract file according to the contract call transaction; A file extraction module, used to extract the Solidity bytecode BIN contract file corresponding to the contract call address from the blockchain platform when the WASM bytecode BIN contract file is not found; A first execution calling module, configured to translate the Solidity bytecode BIN contract file into a WASM bytecode BIN contract file when the pressure of the blockchain platform is less than a preset pressure threshold, and to execute and call the WASM bytecode BIN contract file according to the contract calling transaction; A second execution calling module, configured to execute and call the Solidity bytecode BIN contract file according to the contract calling transaction when the pressure of the blockchain platform is not less than the preset pressure threshold; The second storage module is used to store the Solidity bytecode BIN contract file, the interface description ABI file and the WASM bytecode BIN contract file to the blockchain platform for calling.
15. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the smart contract deployment method based on the blockchain platform as described in any one of claims 1 to 4 or 5 to 12 are implemented.
16. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the smart contract deployment method based on the blockchain platform as described in any one of claims 1 to 4 or 5 to 12 are implemented.
Citation Information
Patent Citations
Intelligent contract function-level dynamic monitoring analysis system and implementation method
CN112015628A