Method, device, equipment and storage medium for executing smart contracts

By using the Golong assembler to compile the bytecode of the smart contract into machine code and store it, the machine code is directly executed to improve the efficiency of smart contract execution and solve the problem of low execution rate in the existing technology.

CN112612482BActive Publication Date: 2025-01-21HANGZHOU QULIAN TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202011585209.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-28
Publication Date
2025-01-21
Estimated Expiration
2040-12-28

AI Technical Summary

Technical Problem

The existing technology lacks effective methods to improve execution rate when executing smart contracts, resulting in large compilation performance and memory consumption.

Method used

The bytecode of the smart contract is compiled into machine code through the Golong assembler, and the machine code is stored in the cache and/or disk, and the machine code is directly executed to improve execution efficiency.

Benefits of technology

This method can save compilation performance consumption and memory consumption when smart contracts are run, and improve the efficiency of smart contract execution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112612482B_ABST
    Figure CN112612482B_ABST
Patent Text Reader

Abstract

The present application relates to a method, apparatus, device and storage medium for executing a smart contract, the method comprising: receiving a creation request for creating a smart contract, the creation request including the bytecode of the smart contract; deploying the smart contract according to the creation request, compiling the bytecode into machine code through the Golong assembler, and storing the machine code; when executing the smart contract, executing the machine code corresponding to the smart contract. The present application is used to improve the execution rate of executing smart contracts.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of blockchain technology, and in particular to a method, apparatus, device and storage medium for executing a smart contract. Background Art

[0002] Currently, blockchain technology is gradually being recognized by everyone and applied to various fields and links of social production. Smart contracts, as a key technology in the field of blockchain technology, account for a considerable proportion in the entire blockchain technology and scope.

[0003] In the prior art, the execution of smart contracts is accelerated by compiling the program code into machine code before the program is run and executing the machine code (Ahead of Time Compailiation, AOT for short). It can be seen that AOT is just a general direction of converting bytecode into machine code to accelerate the execution of smart contracts, and there is no specific implementation plan. Summary of the invention

[0004] The present application provides a method, apparatus, device and storage medium for executing a smart contract to increase the execution rate of the smart contract.

[0005] In a first aspect, the present application provides a method for executing a smart contract, which is applied to a blockchain node, and the method comprises:

[0006] Receiving a creation request for creating a smart contract, wherein the creation request includes a bytecode of the smart contract;

[0007] According to the creation request, deploy the smart contract, compile the bytecode into machine code through the Golong assembler, and store the machine code;

[0008] When executing the smart contract, the machine code corresponding to the smart contract is executed.

[0009] Optionally, before the bytecode is compiled into machine code by the Golong assembler, the following steps are further included:

[0010] The bytecode is converted into an intermediate language between the bytecode and the machine code, wherein the intermediate language is an equivalent code of the bytecode that can be translated into the machine code.

[0011] Optionally, converting the bytecode into an intermediate language between the bytecode and the machine code comprises:

[0012] The bytecode is converted into an abstract syntax tree AST by using syntax analysis and lexical analysis, and the AST is converted into the intermediate language.

[0013] Optionally, compiling the bytecode into machine code by a Golong assembler includes:

[0014] The intermediate language is compiled into the machine code by the Golong assembler.

[0015] Optionally, storing the machine code includes:

[0016] The machine code is stored in a cache, and / or the machine code is stored on a disk.

[0017] Optionally, when executing the smart contract, executing the machine code corresponding to the smart contract includes:

[0018] When executing the smart contract, determining whether there is a machine code corresponding to the smart contract in the cache and / or the disk;

[0019] If yes, extract the machine code corresponding to the smart contract from the cache and / or the disk, and execute the machine code corresponding to the smart contract;

[0020] Otherwise, the step of compiling the bytecode into machine code by using the Golong assembler and storing the machine code is performed.

[0021] Optionally, after the bytecode is compiled into machine code by the Golong assembler, the following steps are further included:

[0022] Write the bytecode into the ledger.

[0023] In a second aspect, the present application provides a device for executing a smart contract, comprising:

[0024] A receiving module, configured to receive a creation request for creating a smart contract, wherein the creation request includes the bytecode of the smart contract;

[0025] A deployment module, used to deploy the smart contract according to the creation request, compile the bytecode into machine code through the Golong assembler, and store the machine code;

[0026] An execution module is used to execute the machine code corresponding to the smart contract when executing the smart contract.

[0027] In a third aspect, the present application provides an electronic device, comprising: a processor, a communication component, a memory and a communication bus, wherein the processor, the communication component and the memory communicate with each other through the communication bus; the memory is used to store computer programs; the processor is used to execute the program stored in the memory to implement the method for executing a smart contract described in the first aspect.

[0028] In a fourth aspect, the present application provides a computer-readable storage medium storing a computer program for implementing the method for executing a smart contract as described in the first aspect.

[0029] The above technical solution provided by the embodiment of the present application has the following advantages over the prior art: the method provided by the embodiment of the present application is applied to a blockchain node, by receiving a creation request for creating a smart contract, the creation request including the bytecode of the smart contract; according to the creation request, the smart contract is deployed, the bytecode is compiled into machine code through the Golong assembler, and the machine code is stored. The present application uses the Golong assembler to compile the bytecode into machine code, which is more friendly than other languages, and there is no need to consider memory issues, making the assembly process easier; when executing the smart contract, the machine code of the smart contract is executed. When deploying the smart contract, the present application compiles the bytecode into machine code, and when executing the smart contract, the machine code corresponding to the smart contract is directly executed, which can save the compilation performance consumption and memory consumption during the runtime of the smart contract, and improve the efficiency of executing the smart contract. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0031] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0032] Figure 1 This is a schematic diagram of the system structure for executing smart contracts in an embodiment of the present application;

[0033] Figure 2 This is a schematic diagram of the blockchain structure in the embodiment of this application;

[0034] Figure 3 This is a schematic diagram of the functional structure of the blockchain network in the embodiment of this application;

[0035] Figure 4 This is a flow chart of a method for executing a smart contract in an embodiment of the present application;

[0036] Figure 5 This is a schematic diagram of the deployment process of the smart contract in the embodiment of this application;

[0037] Figure 6 This is a schematic diagram of the execution process of the smart contract in the embodiment of this application;

[0038] Figure 7This is a schematic diagram of the structure of a device for executing a smart contract in an embodiment of the present application;

[0039] Figure 8 This is a schematic diagram of the structure of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION

[0040] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0041] In the following description, reference is made to “one specific embodiment”, which describes a subset of all possible embodiments, but it can be understood that “one specific embodiment” describes the same subset or different subsets of all possible embodiments and can be combined with each other without conflict.

[0042] Unless otherwise defined, all technical science and technology used herein have the same meaning as commonly understood by those skilled in the art of the present invention. The terms used herein are only for the purpose of describing the embodiments of the present invention and are not intended to limit the present invention.

[0043] Before further describing the embodiments of the present invention in detail, the nouns and terms involved in the embodiments of the present invention are described. The nouns and terms involved in the embodiments of the present invention are subject to the following explanations.

[0044] (1) Transaction, which is equivalent to the computer term "transaction". Transaction includes operations that need to be submitted to the blockchain network for execution, and does not refer only to transactions in a business context. Since the term "transaction" is commonly used in blockchain technology, the embodiments of the present invention follow this convention.

[0045] For example, the Deploy transaction is used to install the specified smart contract to the nodes in the blockchain network and prepare it to be called; the Invoke transaction is used to append transaction records to the blockchain by calling the smart contract and perform operations on the blockchain's state database, including update operations (including adding, deleting, and modifying key-value pairs in the state database) and query operations (i.e. querying key-value pairs in the state database).

[0046] (2) Blockchain is an encrypted, chained transaction storage structure formed by blocks.

[0047] (3) Blockchain Network: A collection of nodes that incorporate new blocks into the blockchain through consensus.

[0048] (4) Ledger is a general term for blockchain (also called ledger data) and the state database synchronized with the blockchain. The blockchain records transactions in the form of files in the file system; the state database records transactions in the blockchain in the form of different types of key-value pairs, which is used to support fast query of transactions in the blockchain.

[0049] (5) Smart Contracts, also known as chaincode or application code, are programs deployed in the nodes of the blockchain network (or blockchain nodes). The nodes execute the smart contracts called in the received transactions to update or query the key-value data in the state database.

[0050] (6) Consensus is a process in a blockchain network that is used to reach agreement on transactions in a block among multiple nodes involved. The blocks that reach agreement will be appended to the end of the blockchain. The mechanisms for achieving consensus include Proof of Work (PoW), Proof of Stake (PoS), Delegated Proof-of-Stake (DPoS), Proof of Elapsed Time (PoET), etc.

[0051] The following describes an exemplary application of the blockchain network provided by the embodiment of the present invention, such as Figure 1 As shown, Figure 1 1 is a schematic diagram of a system for executing a smart contract provided by an embodiment of the present invention, including a blockchain network 101, a consensus node 102, a certification center 103, a business entity 104, a client node 104-1, a business entity 105 and a client node 105-1, which are described below respectively:

[0052] The types of blockchain network 101 are flexible and diverse, for example, it can be any one of public chain, private chain or alliance chain. Taking the public chain as an example, any electronic device of any business subject, such as user terminal and server, can access the blockchain network 101 without authorization; taking the alliance chain as an example, after the business subject obtains authorization, its electronic device (such as terminal / server) can access the blockchain network 101, and at this time, it becomes a client node in the blockchain network 101.

[0053] In some embodiments, the client node 104 can only be used as an observer of the blockchain network 101, that is, to provide support for business entities to initiate transactions (for example, for storing data on the chain or querying data on the chain). For the functions of the consensus node 102 of the blockchain network 101, such as sorting function, consensus service and account book function, the client node can implement them by default or selectively (for example, depending on the specific business needs of the business entity). Thus, the data and business processing logic of the business entity can be migrated to the blockchain network 101 to the greatest extent, and the credibility and traceability of the data and business processing process can be achieved through the blockchain network 101.

[0054] The consensus nodes in the blockchain network 101 receive data from different business entities, such as Figure 1 The transaction submitted by the client node 104 - 1 of the business entity 104 shown in the figure is executed to update the ledger or query the ledger. Various intermediate results or final results of the transaction can be returned to the client node 104 - 1 of the business entity 104 for display.

[0055] For example, client node 104-1 can subscribe to events of interest in blockchain network 101, such as transactions occurring in a specific organization / channel in blockchain network 101, and consensus node 102 pushes corresponding transaction notifications to client node 104-1, thereby triggering corresponding business logic in client node 104-1.

[0056] As an example of blockchain, Figure 2 As shown, Figure 2 It is a schematic diagram of the structure of the blockchain in the blockchain network 101 provided in an embodiment of the present invention. The header of each block can include the hash value of all transactions in the block, and also includes the hash value of all transactions in the previous block. The newly generated transaction records are filled into the block and after the consensus of the nodes in the blockchain network, they will be appended to the end of the blockchain to form a chain growth. The chain structure based on the hash value between blocks ensures the anti-tampering and anti-counterfeiting of transactions in the block.

[0057] The following describes an exemplary functional architecture of a blockchain network provided by an embodiment of the present invention. Figure 3 As shown, Figure 3 1 is a functional architecture diagram of a blockchain network 101 provided in an embodiment of the present invention, including an application layer 301, a consensus layer 302, a network layer 303, a data layer 304 and a resource layer 305, which are described below respectively:

[0058] The application layer 301 encapsulates various services that can be implemented in the blockchain network, including transaction traceability, evidence storage, and verification.

[0059] The consensus layer 302 encapsulates the mechanism (i.e., consensus mechanism) for the nodes 102 in the blockchain network 101 to reach a consensus on the block, transaction management, and account management functions. The consensus mechanism includes consensus algorithms such as POS, POW, and DPOS, and supports pluggable consensus algorithms. Transaction management is used to verify the digital signature carried in the transaction received by the node 101, verify the identity information of the business subject 104, and determine whether it has the authority to conduct transactions based on the identity information (read relevant information from the business subject identity management); for the business subject that has obtained the authorization to access the blockchain network 101, they all have a digital certificate issued by the certification center, and the business subject uses the private key in its digital certificate to sign the submitted transaction, thereby declaring its legal identity. Account management is used to maintain the blockchain and state database. For the blocks that have reached consensus, they are appended to the end of the blockchain; execute the transactions in the blocks that have reached consensus, update the key-value pairs in the state database when the transaction includes an update operation, and query the key-value pairs in the state database when the transaction includes a query operation and return the query results to the client node of the business subject. Supports query operations on the state database in multiple dimensions, including: querying blocks based on block serial numbers (such as transaction hash values); querying blocks based on block hash values; querying blocks based on transaction serial numbers; querying transactions based on transaction serial numbers; querying business subject account data based on business subject account numbers (serial numbers); querying blockchains in channels based on channel names.

[0060] The network layer 303 encapsulates the functions of point-to-point (P2P) network protocol, data transmission mechanism and data verification mechanism, access authentication mechanism and business subject identity management.

[0061] Among them, the P2P network protocol realizes the communication between nodes 102 in the blockchain network 101, the data propagation mechanism ensures the propagation of transactions in the blockchain network 101, and the data verification mechanism is used to realize the reliability of data transmission between nodes 102 based on cryptographic methods (such as digital certificates, digital signatures, public / private key pairs); the access authentication mechanism is used to authenticate the identity of the business subject joining the blockchain network 101 according to the actual business scenario, and grant the business subject the right to access the blockchain network 101 when the authentication is passed; the business subject 104 identity management is used to store the identity of the business subject 104 allowed to access the blockchain network 101, and the authority (such as the type of transaction that can be initiated).

[0062] The data layer 304 encapsulates various data structures for implementing the ledger, including the blockchain implemented as files in the file system, the key-value state database, and the existence proof (such as the hash tree of transactions in the block).

[0063] The resource layer 305 encapsulates the computing resources, storage resources, and communication resources of each node 102 in the blockchain network 101.

[0064] Based on the above architecture, the embodiment of the present invention proposes the following implementation method.

[0065] The present application embodiment provides a method for executing a smart contract, which is applied in a blockchain node. The specific implementation of the method is as follows: Figure 4 As shown:

[0066] Specifically, it should be noted that the examples in the embodiments of the present application are limited to examples and are not used to limit the scope of protection, and will not be described one by one in the embodiments.

[0067] Step 401: Receive a creation request for creating a smart contract, where the creation request includes the bytecode of the smart contract.

[0068] Specifically, the user can use a high-level programming language to write the smart contract to be deployed locally, compile the written smart contract into bytecode, and send the compiled bytecode to the blockchain network 101.

[0069] Of course, users can also write smart contracts directly in a high-level programming language on the blockchain node, which calls a pre-stored compiler and uses the compiler to compile the smart contract into bytecode.

[0070] Step 402, deploy the smart contract according to the creation request, compile the bytecode into machine code through the Golong assembler, and store the machine code.

[0071] Specifically, Golong is a statically strongly typed, compiled, concurrent programming language with garbage collection capabilities.

[0072] The Golong assembler supports cross-platform compilation, allowing source code to be compiled into binary files that can be executed on the target system and architecture.

[0073] In a specific embodiment, before the bytecode is compiled into machine code by the Golong assembler, the bytecode is first converted into an intermediate language between the bytecode and the machine code, wherein the intermediate language is an equivalent code of the bytecode that can be translated into machine code.

[0074] Specifically, the intermediate language is an intermediate language that can be recognized by the Golong assembler. This application uses the Golong assembler and converts the bytecode into the intermediate language corresponding to the Golong assembler. This is because the intermediate language is closer to the representation of the machine language, and it is easier and faster to convert the intermediate language into machine code, which can increase the speed of deploying smart contracts.

[0075] In a specific embodiment, syntax analysis and lexical analysis are used to convert the bytecode into an abstract syntax tree (AST), which is converted into an intermediate language. The intermediate language converted from the AST is then subjected to a series of optimization processes, such as deleting common expressions, dead code deletion, and constant merging, to obtain the final intermediate language.

[0076] Specifically, lexical analysis is performed first and then grammatical analysis.

[0077] In simple terms, syntax analysis is to translate source code into tokens. Golong's token types include: variable names, literals, operators, separators, and keywords. The source code is split according to the set rules to achieve the purpose of word segmentation.

[0078] After lexical analysis, a token sequence is obtained, and AST is obtained through the token sequence.

[0079] In a specific embodiment, the final intermediate language is compiled into machine code by the Golong assembler.

[0080] Specifically, the final intermediate language is an intermediate code (IR) with a static single assignment (SSA) feature. The Golong assembler will call the corresponding function to convert the intermediate code into machine code according to the preset architecture.

[0081] Specifically, the Golong assembler can be embedded in the blockchain node in advance, and the Golong assembler can be directly called to convert the intermediate code into machine code.

[0082] In a specific embodiment, the bytecode is compiled into machine code by the Golong assembler, and the machine code is stored in a cache and / or stored on a disk for subsequent calls.

[0083] In a specific embodiment, after the bytecode is compiled into machine code by the Golong assembler, the bytecode is written into the ledger.

[0084] Next, through Figure 5 The deployment process of smart contracts is described in detail:

[0085] Step 501, receiving a creation request for creating a smart contract to deploy the smart contract.

[0086] Step 502, convert the bytecode into an intermediate code corresponding to the Golong assembler.

[0087] Step 503, using the Golong assembler to convert the intermediate code into machine code.

[0088] Step 504: store the machine code in a cache and / or a disk.

[0089] Step 403: When executing the smart contract, the machine code corresponding to the smart contract is executed.

[0090] In a specific embodiment, when executing a smart contract, it is determined whether there is a machine code corresponding to the smart contract in the cache and / or disk; if so, the machine code corresponding to the smart contract is extracted from the cache and / or disk, and the machine code corresponding to the smart contract is executed; otherwise, the step of compiling the bytecode into machine code through the Golong assembler and storing the machine code is executed.

[0091] Specifically, if the machine code corresponding to the smart contract does not exist in the cache and / or disk, the bytecode is compiled into machine code through the Golong assembler, the machine code is stored in the cache and / or disk, and then the machine code corresponding to the stored smart contract is executed.

[0092] Specifically, determining whether there is a machine code corresponding to the smart contract in the cache and / or disk; if so, extracting the machine code corresponding to the smart contract from the cache and / or disk, and executing the machine code corresponding to the smart contract, specifically including:

[0093] Determine whether the machine code corresponding to the smart contract exists in the cache.

[0094] If so, extract the machine code corresponding to the smart contract from the cache and execute the machine code corresponding to the smart contract.

[0095] Otherwise, determine whether there is a machine code corresponding to the smart contract in the disk. If so, extract the machine code corresponding to the smart contract from the disk and execute the machine code corresponding to the smart contract. Otherwise, compile the bytecode into machine code through the Golong assembler, store the machine code in the cache and / or disk, and then execute the stored machine code corresponding to the smart contract.

[0096] Next, through Figure 6 The execution process of smart contracts is described in detail:

[0097] Step 601, receiving an execution request for executing a smart contract to execute the smart contract.

[0098] Step 602, extract the machine code corresponding to the smart contract from the cache or disk.

[0099] Step 603: execute the machine code corresponding to the smart contract to obtain the execution result.

[0100] The method provided in the embodiment of the present application is applied to a blockchain node, by receiving a creation request for creating a smart contract, wherein the creation request includes the bytecode of the smart contract; according to the creation request, the smart contract is deployed, the bytecode is compiled into machine code through the Golong assembler, and the machine code is stored. The present application uses the Golong assembler to compile the bytecode into machine code, which is more friendly than other languages, and there is no need to consider memory issues, making the assembly process easier; when executing the smart contract, the machine code of the smart contract is executed. When deploying the smart contract, the present application compiles the bytecode into machine code, and when executing the smart contract, directly executes the machine code corresponding to the smart contract, which can save the compilation performance consumption and memory consumption during the runtime of the smart contract, and improve the efficiency of executing the smart contract.

[0101] The present application also provides a device for executing a smart contract. The specific implementation of the device can be found in the description of the method embodiment part, and the repetitive parts will not be repeated. Figure 7 As shown, the device mainly includes:

[0102] The receiving module 701 is used to receive a creation request for creating a smart contract, where the creation request includes the bytecode of the smart contract.

[0103] The deployment module 702 is used to deploy the smart contract according to the creation request, compile the bytecode into machine code through the Golong assembler, and store the machine code.

[0104] The execution module 703 is used to execute the machine code corresponding to the smart contract when executing the smart contract.

[0105] Based on the same concept, an electronic device is also provided in the embodiment of the present application, such as Figure 8 As shown, the electronic device mainly includes: a processor 801, a communication component 802, a memory 803 and a communication bus 804, wherein the processor 801, the communication component 802 and the memory 803 communicate with each other through the communication bus 804. The memory 803 stores a program that can be executed by the processor 801, and the processor 801 executes the program stored in the memory 803 to implement the following steps: receiving a creation request for creating a smart contract, the creation request includes the bytecode of the smart contract; deploying the smart contract according to the creation request, compiling the bytecode into machine code through the Golong assembler, and storing the machine code; when executing the smart contract, executing the machine code corresponding to the smart contract.

[0106] The communication bus 804 mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The communication bus 804 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 8 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0107] The communication component 802 is used for communication between the above electronic device and other devices.

[0108] The memory 803 may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Alternatively, the memory may also be at least one storage device located away from the processor 801.

[0109] The above-mentioned processor 801 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc., and can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.

[0110] In another embodiment of the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is run on a computer, the computer executes the method of the smart contract described in the above embodiment.

[0111] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instruction is loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instruction can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instruction is transmitted from a website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server, a data center, etc. that contains one or more available media integration. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape, etc.), an optical medium (e.g., a DVD) or a semiconductor medium (e.g., a solid-state hard disk), etc.

[0112] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0113] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A method for executing a smart contract, characterized in that: Applied to a blockchain node, the method comprises: Receiving a creation request for creating a smart contract, wherein the creation request includes a bytecode of the smart contract; Deploy the smart contract according to the creation request, compile the bytecode into machine code through the Golong assembler, and store the machine code; When executing the smart contract, executing the machine code corresponding to the smart contract; Before the bytecode is compiled into machine code by the Golong assembler, the following steps are also included: Converting the bytecode into an intermediate language between the bytecode and the machine code, wherein the intermediate language is an equivalent code of the bytecode that can be translated into the machine code; The step of converting the bytecode into an intermediate language between the bytecode and the machine code includes: Using syntax analysis and lexical analysis, the bytecode is converted into an abstract syntax tree AST, and the AST is converted into the intermediate language; The bytecode is compiled into machine code by the Golong assembler, including: Compiling the intermediate language into the machine code by the Golong assembler; The storing of the machine code comprises: storing the machine code in a cache, and / or storing the machine code on a disk; Wherein, when executing the smart contract, executing the machine code corresponding to the smart contract includes: When executing the smart contract, determining whether there is a machine code corresponding to the smart contract in the cache and / or the disk; If yes, extract the machine code corresponding to the smart contract from the cache and / or the disk, and execute the machine code corresponding to the smart contract; Otherwise, the step of compiling the bytecode into machine code by using the Golong assembler and storing the machine code is performed.

2. The method for executing a smart contract according to claim 1, characterized in that: After the bytecode is compiled into machine code by the Golong assembler, it also includes: Write the bytecode into the ledger.

3. A device for executing a smart contract, characterized in that: include: A receiving module, configured to receive a creation request for creating a smart contract, wherein the creation request includes the bytecode of the smart contract; A deployment module, configured to deploy the smart contract according to the creation request, compile the bytecode into machine code through a Golong assembler, and store the machine code; wherein, compiling the bytecode into machine code through a Golong assembler comprises: converting the bytecode into an intermediate language between the bytecode and the machine code, wherein the intermediate language is an equivalent code of the bytecode that can be translated into the machine code; wherein, converting the bytecode into an intermediate language between the bytecode and the machine code comprises: using syntax analysis and lexical analysis to convert the bytecode into an abstract syntax tree AST, and converting the AST into the intermediate language; compiling the intermediate language into the machine code through the Golong assembler; wherein, storing the machine code comprises: storing the machine code in a cache, and / or storing the machine code on a disk; An execution module is used to execute the machine code corresponding to the smart contract when executing the smart contract; wherein, when executing the smart contract, executing the machine code corresponding to the smart contract includes: when executing the smart contract, determining whether the machine code corresponding to the smart contract exists in the cache and / or the disk; if so, extracting the machine code corresponding to the smart contract from the cache and / or the disk, and executing the machine code corresponding to the smart contract; otherwise, executing the step of compiling the bytecode into machine code through the Golong assembler and storing the machine code.

4. An electronic device, characterized in that: include: A processor, a communication component, a memory and a communication bus, wherein the processor, the communication component and the memory communicate with each other via the communication bus; The memory is used to store computer programs; The processor is used to execute the program stored in the memory to implement the method for executing a smart contract as described in claim 1 or 2.

5. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method for executing a smart contract as described in claim 1 or 2 is implemented.

Citation Information

Patent Citations

  • An intelligent contract conversion system and method

    CN109523383A