WASM smart contract development suite and development method thereof

By designing the WASM smart contract development kit, it provides simple and easy-to-use development tools and modular languages, solving the complexity and cost of traditional smart contract development, realizing safe and efficient development of WASM smart contracts, and improving development efficiency.

CN119127153APending Publication Date: 2024-12-13WUHAN TIANYU INFORMATION IND
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411107664.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-13
Publication Date
2024-12-13

AI Technical Summary

Technical Problem

The learning curve of traditional smart contract development languages ​​is steep and the ecosystem is closed, resulting in high development costs and the complexity of WASM technology increases the difficulty of development.

Method used

A WASM smart contract development kit is designed, including WASM interface, development language and development tools, providing simple and easy-to-use contract creation, code editing and compilation functions, lowering development thresholds through modular design, automatically building contract execution modules, hiding the underlying layer Logic, supports multilingual compilation.

Benefits of technology

It simplifies the smart contract development process, lowers the development threshold, improves development efficiency, reduces the possibility of errors, and realizes safe and efficient WASM smart contract development.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119127153A_ABST
    Figure CN119127153A_ABST
Patent Text Reader

Abstract

The invention discloses a WASM smart contract development suite and a development method thereof. Specifically, the WASM smart contract development suite comprising a WASM interface, a development language and a development tool is constructed for a developer to compile a WASM smart contract. Wherein the WASM interface comprises a contract interface and an environment interface; the development language is modularly designed according to a specific scene of the smart contract, each module realizes a corresponding function through a corresponding interface in the packaging environment interface, and a specific grammar is automatically constructed or provided for a developer to use through a development tool; the development tool is a visual WASM intelligent contract integrated development environment and is used for providing contract creation, code editing and contract compiling functions for developers. The invention aims to simplify the development process of the smart contract and improve the development efficiency of the smart contract.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of blockchain, and in particular to a WASM smart contract development kit and a development method thereof. Background Art

[0002] With the rapid development of blockchain technology, smart contracts, as an agreement to automatically execute contract terms, have been widely used in financial services, supply chain management, healthcare, government services and other fields. The concept of smart contracts was first proposed by the famous cryptographer Nick Szabo in 1994. It was not until the emergence of the Ethereum platform that smart contracts were truly widely used. Ethereum designed a high-level programming language Solidity to write smart contracts and designed the EVM virtual machine to execute the contract bytecode.

[0003] With the emergence of WASM (WebAssembly) technology, it has been widely used in the field of Web applications as a portable and high-performance virtual machine technology. In recent years, many popular blockchains at home and abroad have used WASM technology to implement smart contracts, such as FISCO BCOS's Liquid and Substrate's ink. They use rust's powerful macro system and metaprogramming technology to implement dedicated eDSL to write smart contracts.

[0004] Traditional smart contract development mainly uses specific smart contract programming languages ​​such as Solidity (Ethereum). These specialized languages ​​often have steep learning curves and relatively closed ecosystems, which makes developers face many challenges in use. WASM, as the underlying technology of smart contracts, can provide higher security and performance than EVM, and can also support smart contracts written in a variety of common development languages. However, the Rust language has a steep learning curve and high development costs due to its ownership system, life cycle and complex type system.

[0005] Therefore, there is an urgent need for a simple, general, secure and efficient WASM smart contract development kit to solve the above problems. Summary of the invention

[0006] The main purpose of this invention is to provide a simple, universal, safe and efficient WASM smart contract development kit to lower the development threshold, simplify the development process, and improve the development efficiency of smart contracts.

[0007] The technical solution adopted by the present invention is:

[0008] A method for developing a WASM smart contract development kit is provided to construct a WASM smart contract development kit including a WASM interface, a development language and development tools for developers to write WASM smart contracts; wherein:

[0009] The WASM interface includes the contract interface and the environment interface. The node and the WASM virtual machine interact through the WASM interface. The node executes the contract code by calling the contract interface, and the WASM virtual machine obtains the node's environment data and returns the contract execution data by calling the environment interface.

[0010] The development language is modularly designed according to the specific scenarios of smart contracts. Each module implements the corresponding function through the corresponding interface in the encapsulation environment interface, and is automatically constructed or provided with specific syntax for developers through development tools;

[0011] The development tool is a visual WASM smart contract integrated development environment that provides developers with contract creation, code editing, and contract compilation functions.

[0012] Following the above technical solution, the environment interface includes the Input API for obtaining input data, the Output API for returning output data, the Context API for obtaining context information of contract execution, the Storage API for storing contract status data, the Oracle API for obtaining oracle data, the Logs API for returning event logs during contract execution, and the Other API for transaction rollback, exception information return, etc.

[0013] According to the above technical solution, the contract interface includes the contract deployment interface Deploy API and the contract calling interface MainAPI. The acquisition of input parameters is realized by calling the Input API of the environment interface, and the return of output parameters is realized by calling the Output API of the environment interface. The Deploy API realizes the data initialization when the contract is deployed by calling the constructor of the contract. The Main API is the entry point for calling the contract, and the corresponding contract method is executed by judging the function signature ID internally. The contract method is a series of functions in the smart contract that can be publicly called.

[0014] Following the above technical solution, the context information obtained by the Context API includes but is not limited to block height, timestamp, contract caller, contract address, etc.

[0015] Following the above technical solution, the function signature ID is the first n bytes after the contract method signature hash, such as the first 4 bytes.

[0016] According to the above technical solution, input and output data need to be serialized for interaction.

[0017] Following the above technical solution, in the process of building the WASM smart contract development kit, the development language is modularly designed according to the specific scenarios of the smart contract. It is mainly divided into data type module, contract execution module, contract event module, exception handling module, contract oracle module and contract context module; the contract execution module is automatically constructed by the development tool, and other modules provide specific syntax for developers to use.

[0018] According to the above technical solution, the data type module provides basic data types, composite data types and state variable types. The basic data types include unsigned integer type, signed integer type, string type, address type and Boolean type; the composite data types include enumeration, array and structure; the state variable types include single-value variable, mapping variable and vector variable.

[0019] Following the above technical solution, developers use the visual WASM smart contract integrated development environment, select the integrated smart contract scenario template according to the function of creating a contract project, quickly create a smart contract project, and edit the code of the smart contract according to the code editing function of the development tool. Finally, the final bytecode and contract description file are generated through the contract compilation function.

[0020] Following the above technical solution, the contract compilation function integrates the core functions of contract preprocessing, contract compilation and contract optimization; contract preprocessing is used to combine the WASM interface and the contract development language to parse the simple contract code written by the developer and reconstruct the underlying code; contract compilation is used to combine the multi-language support characteristics of WASM technology, integrate the compiler in the development tool, select the compilation target, and compile the preprocessed smart contract code; contract optimization optimizes the compiled WASM bytecode through integrated tools to reduce the size of the contract bytecode.

[0021] Following the above technical solution, contract preprocessing mainly includes syntax parsing, deployment interface code and execution interface code generation.

[0022] The present invention also provides a WASM smart contract development kit, which is a WASM smart contract development kit implemented using the development method of the WASM smart contract development kit described in the above technical solution, including a WASM interface, a development language and development tools.

[0023] The present invention also provides a method for writing a smart contract using a WASM smart contract development kit, wherein a developer uses the WASM smart contract development kit described in the above technical solution to write a WASM smart contract.

[0024] The beneficial effects of the present invention are as follows: the present invention designs a WASM smart contract development kit, the contract bytecode uses WASM, based on a simple and general programming language, combines the specific scenarios of smart contracts, designs a WASM interface, and provides a concise and easy-to-use development language and development tools; the development kit is simple, general, safe and efficient, which can lower the development threshold for developers when writing smart contracts, simplify the development process, and improve the development efficiency of smart contracts; and the development language is modularly designed according to the specific scenarios of smart contracts, and each module realizes the corresponding function through the corresponding interface in the encapsulation environment interface, which can realize the syntax required in the smart contract development process, such as various data types, entry functions, contract feature-related data structures and APIs.

[0025] Furthermore, the contract compilation function in the WASM smart contract IDE integrates the core functions of contract preprocessing, compilation and optimization. Contract preprocessing combines the WASM interface and the contract development language to parse the simple contract code written by the developer and reconstruct the underlying code. The advantage of this is that developers do not need to worry about the complex WASM interface and how to implement the underlying logic code, which can greatly reduce the development workload and eliminate the possibility of errors in the writing of underlying code; contract compilation combines the multi-language support characteristics of WASM technology, simplifies the complex process of developers configuring the compilation environment and using commands to compile contracts, and realizes a one-click visual automatic compilation function, hiding the compilation details, and further simplifying the development process.

[0026] Of course, any product implementing the present invention does not necessarily need to achieve all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0028] Figure 1 This is a schematic diagram of a WASM interface according to an embodiment of the present invention;

[0029] Figure 2 This is a schematic diagram of the Deploy execution process of an embodiment of the present invention;

[0030] Figure 3 It is a schematic diagram of the Main execution flow of an embodiment of the present invention;

[0031] Figure 4 This is a schematic diagram of a contract language module according to an embodiment of the present invention;

[0032] Figure 5 It is a schematic diagram of the contract development process of an embodiment of the present invention. DETAILED DESCRIPTION

[0033] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0034] It should be noted that the illustrations provided in the embodiments of the present invention are only used to illustrate the basic concept of the present invention in a schematic manner. Therefore, the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout type may also be more complicated.

[0035] In the present invention, it is also necessary to explain that, if the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc. appear, the orientation or position relationship indicated is based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present application and simplifying the description, and does not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present application. In addition, if the terms "first" and "second" appear, they are only used for description and distinction purposes, and cannot be understood as indicating or implying relative importance.

[0036] The development method of the WASM smart contract development kit in the embodiment of the present invention mainly constructs a WASM smart contract development kit including a WASM interface, a development language and development tools for developers to write WASM smart contracts, aiming to simplify the smart contract development process and improve the development efficiency of smart contracts.

[0037] in:

[0038] The WASM interface includes the contract interface and the environment interface. The node and the WASM virtual machine interact through the WASM interface. The node executes the contract code by calling the contract interface, and the WASM virtual machine obtains the node's environment data and returns the contract execution data by calling the environment interface.

[0039] The development language is modularly designed according to the specific scenarios of smart contracts. Each module implements the corresponding function through the corresponding interface in the encapsulation environment interface, and is automatically constructed or provided with specific syntax for developers through development tools;

[0040] The development tool is a visual WASM smart contract integrated development environment that provides developers with contract creation, code editing, and contract compilation functions.

[0041] The contract bytecode of the WASM smart contract development kit of the present invention uses WASM, based on a simple and general programming language (such as C++, and other programming languages ​​can also be selected as needed), combined with the specific scenarios of smart contracts, and a WASM interface is designed to provide a concise and easy-to-use development language and development tools, aiming to simplify the smart contract development process and improve the development efficiency of smart contracts.

[0042] WASM interface: such as Figure 1 As shown, the node and the WASM virtual machine interact through the "WASM interface", the node executes the contract code by calling the "contract interface", and the WASM virtual machine obtains the node environment data and returns the contract execution data by calling the "environment interface".

[0043] The environment interface includes:

[0044] Input API: interface for obtaining input data;

[0045] Output API: interface that returns output data;

[0046] Context API: Get the context information of contract execution, such as block height, timestamp, contract caller, contract address, etc.

[0047] Storage API: storage interface for contract status data;

[0048] Oracle API: oracle data acquisition interface;

[0049] Logs API: event log return interface during contract execution;

[0050] Other API: interfaces such as transaction rollback and exception information return.

[0051] The Deploy API in the contract interface is the contract deployment interface. The execution process is as follows: Figure 2 As shown. Main API is the contract calling interface, and the execution process is as follows Figure 3 As shown. Deploy API and Main API have no input parameters and output parameters. The input parameters are obtained by calling the environment Input API, and the output parameters are returned by calling the environment Output API. Deploy API will call the smart contract construction method, and developers can implement contract initialization related operations in the contract construction method. Main API is the entry point for calling the contract, and internally determines which contract method to execute through the function signature ID (contract method is a series of functions that are open to the outside world and can be called in the smart contract).

[0052] The function signature ID is the first 4 bytes of the contract method signature after hashing. For example, the contract method set_name(string) calculates the hash of "set_name(string)" and takes the first four bytes as the function signature ID. The hash can be keccak256\SM3, etc. Input and output parameters need to be serialized and encoded before transmission. Scale (Simple Concatenated Aggregate Little-Endian) serialization is used here.

[0053] Development language: Figure 4 As shown in the figure, according to the specific scenarios of smart contracts, the development language is modularly designed, mainly divided into data type module, contract execution module, contract event module, exception handling module, contract oracle module and contract context module, etc. The contract execution module is automatically constructed by the development tool, and other modules provide specific syntax for developers to use.

[0054] The data type module provides basic data types, composite data types, and state variable types. Basic data types include unsigned integer types (u8, u16, u32, u64, u128, u256), signed integer types (i8, i16, i32, i64, i128, i256), string types (string), address types (address), and Boolean types (bool). Composite data types include enumerations (enmu), arrays, structures (struct), and more.

[0055] State variable types include single-value variables, mapping variables, vector variables, etc. Based on the C++ language, libc is removed, the data type is redefined using C++ class modules, operators are overloaded, the environment interface StorageAPI is encapsulated, and persistent storage of state variable data is achieved.

[0056] The contract execution module implements the Deploy API and the Main API. By encapsulating the environment interface, Figure 2 and Figure 3 The execution process of the smart contract is the main entry point, which is automatically implemented through development tools.

[0057] The contract event module implements the function of sending contract events, and provides the emit statement to send the log information of the smart contract through the encapsulation environment interface Logs API.

[0058] The contract exception module implements functions such as contract transaction rollback and exception information return. It provides statements such as revert and error to handle exceptions through the encapsulation environment interface Other API.

[0059] The contract oracle module implements the function of accessing external trusted data by the contract, and it does this by encapsulating the environment interface Oracle API to provide oracle-related interfaces.

[0060] The contract context module implements the function of accessing node environment data when the contract is executed, including obtaining information such as block height, timestamp, contract caller, contract address, etc., and implements interfaces such as getBlockNumber, getTimestamp, getSender, and getAddress by encapsulating the environment interface Context API.

[0061] The above encapsulation of C++ language and environment interface realizes the syntax of various data types, entry functions, contract feature-related data structures and API required in the smart contract development process.

[0062] Development tools: It is a visual WASM smart contract integrated development environment (IDE) that provides developers with functions such as contract creation, code editing, and contract compilation. Developers can use the IDE to write smart contracts and use various data types, data structures, APIs, and other syntax provided by the development language to implement relevant contract interfaces for business logic.

[0063] Development process such as Figure 5 As shown in the figure, developers use the WASM smart contract IDE to create a contract project, select a smart contract scenario template integrated in the IDE, quickly create a smart contract project, and then edit the code of the smart contract through the code editing function provided by the IDE. Finally, the contract compilation function generates the final bytecode and contract description file (contract name, generation time, version, interface description, etc.).

[0064] The contract compilation function is the most important in the WASM smart contract IDE, which integrates the core functions of contract preprocessing, compilation and optimization.

[0065] In contract preprocessing, the WASM interface and contract development language are combined to parse the simple contract code written by the developer and reconstruct the underlying code. The advantage of this is that the developer does not need to worry about the complex WASM interface and how to implement the underlying logic code, which can greatly reduce the development workload and eliminate the possibility of errors in the writing of the underlying code. Contract preprocessing is mainly divided into syntax parsing, deployment interface code and execution interface code generation.

[0066] In syntax parsing, the libclang library is integrated in the IDE to perform syntax parsing on the C++ contract code developed by the developer, mainly obtaining the contract class name, contract class construction method (function name, input parameters, function body, etc.), contract class member method (function name, input parameters, output parameters, function body, etc.) and contract class member variables (type, name, etc.), and checking whether the syntax of the contract code is correct. The next step is to reconstruct the underlying code through the parsed contract syntax information.

[0067] During the deployment interface code generation, a WASM interface of the Deploy API will be generated and declared as a WASM export interface (which can be called externally), and automatically generated Figure 2 The code related to the Deploy execution process is shown. It mainly processes the constructor information in the syntax parsing, first obtains the input data through the Input API, then decodes the input data to obtain the execution parameters, and finally generates the related initialization code in the constructor.

[0068] When executing interface code generation, a WASM interface of the Main API will be generated and declared as a WASM export interface (which can be called externally), and automatically generated Figure 3 The relevant code of the Main execution process is shown. It mainly processes the member function information in the syntax parsing. First, the input data is obtained through the Input API, the input data is decoded to obtain the function ID to be executed, and then the function ID is matched to execute the specified contract interface code. When executing the contract interface code, the input data needs to be further decoded to obtain the input data. After the execution is completed, the output data needs to be encoded and the data is returned using the Output API interface. The acquisition of input and output data is strictly generated according to the member function definition in the syntax parsing, and the final execution logic is the specific code defined in the member function.

[0069] In addition, in the generation of the deployment interface and the execution interface, when accessing state variables is involved, the relevant code for calling the StorageAPI will be generated; when sending contract events is involved, the relevant code for calling the LogsAPI will be generated; when accessing context data (block height, timestamp, contract caller, contract address, etc.), the relevant code for calling the ContextAPI will be generated; when abnormal errors are involved, the relevant code for calling the OtherAPI will be generated; when oracle operations are involved, the relevant code for calling the OracleAPI will be generated.

[0070] Contract compilation combines the multi-language support feature of WASM technology, integrates the compiler Emscripten in the IDE, selects the wasm32-unknown-unknown compilation target, and compiles the preprocessed C++ smart contract code. This simplifies the complex process of developers configuring the compilation environment and using commands to compile contracts, realizes a one-click visual automatic compilation function, hides the compilation details, and further simplifies the development process.

[0071] Contract optimization integrates the wasm-opt tool to perform -O3 optimization on the compiled WASM bytecode, further reducing the size of the contract bytecode and ultimately obtaining an optimized .wasm bytecode file.

[0072] It should be pointed out that, according to the needs of implementation, the various steps / components described in this application can be split into more steps / components, and two or more steps / components or partial operations of steps / components can be combined into new steps / components to achieve the purpose of the present invention.

[0073] The order of execution of each step in the above embodiment does not mean the order of execution. The order of execution 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 application.

[0074] It should be understood that those skilled in the art can make improvements or changes based on the above description, and all these improvements and changes should fall within the scope of protection of the appended claims of the present invention.

Claims

1. A method for developing a WASM smart contract development kit, characterized in that: Build a WASM smart contract development kit including WASM interface, development language and development tools for developers to write WASM smart contracts; among them: The WASM interface includes the contract interface and the environment interface. The node and the WASM virtual machine interact through the WASM interface. The node executes the contract code by calling the contract interface, and the WASM virtual machine obtains the node's environment data and returns the contract execution data by calling the environment interface. The development language is modularly designed according to the specific scenarios of smart contracts. Each module implements the corresponding function through the corresponding interface in the encapsulation environment interface, and is automatically constructed or provided with specific syntax for developers through development tools; The development tool is a visual WASM smart contract integrated development environment that provides developers with contract creation, code editing, and contract compilation functions.

2. The method for developing a WASM smart contract development kit according to claim 1, characterized in that: The environmental interfaces include the Input API for obtaining input data, the Output API for returning output data, the Context API for obtaining context information of contract execution, the Storage API for storing contract status data, the Oracle API for obtaining oracle data, the Logs API for returning event logs during contract execution, and the Other API for transaction rollback, exception information return, etc.

3. The method for developing a WASM smart contract development kit according to claim 2, characterized in that: The contract interface includes the contract deployment interface Deploy API and the contract calling interface Main API. The acquisition of input parameters is realized by calling the Input API of the environment interface, and the return of output parameters is realized by calling the Output API of the environment interface. The Deploy API calls the constructor of the contract to initialize the data when the contract is deployed. The Main API is the entry point for calling the contract. The function signature ID is used to determine the execution of the corresponding contract method. The contract method is a series of functions in the smart contract that can be publicly called.

4. The method for developing a WASM smart contract development kit according to claim 1, characterized in that: The context information obtained by ContextAPI includes block height, timestamp, contract caller, and contract address.

5. The method for developing a WASM smart contract development kit according to claim 3, characterized in that: The function signature ID is the first n bytes of the contract method signature hash.

6. The method for developing a WASM smart contract development kit according to claim 2, characterized in that: In the process of building the WASM smart contract development kit, the development language is modularly designed according to the specific scenarios of smart contracts. It is mainly divided into data type module, contract execution module, contract event module, exception handling module, contract oracle module and contract context module; the contract execution module is automatically built by the development tool, and other modules provide specific syntax for developers to use.

7. The method for developing a WASM smart contract development kit according to claim 1, characterized in that: The data type module provides basic data types, composite data types and state variable types. The basic data types include unsigned integer type, signed integer type, string type, address type and Boolean type; the composite data types include enumeration, array and structure; the state variable types include single-value variable, mapping variable and vector variable.

8. The method for developing a WASM smart contract development kit according to claim 1, characterized in that: Developers use the visual WASM smart contract integrated development environment to select the integrated smart contract scenario template according to the function of creating a contract project, quickly create a smart contract project, and edit the code of the smart contract according to the code editing function of the development tool. Finally, the final bytecode and contract description file are generated through the contract compilation function.

9. The method for developing a WASM smart contract development kit according to claim 1, characterized in that: The contract compilation function integrates the core functions of contract preprocessing, contract compilation and contract optimization; contract preprocessing is used to combine the WASM interface and the contract development language to parse the simple contract code written by the developer and reconstruct the underlying code; contract compilation is used to combine the multi-language support characteristics of WASM technology, integrate the compiler in the development tool, select the compilation target, and compile the preprocessed smart contract code; contract optimization optimizes the compiled WASM bytecode through integrated tools to reduce the size of the contract bytecode.

10. The method for developing a WASM smart contract development kit according to claim 9, characterized in that: Contract preprocessing mainly includes syntax parsing, deployment interface code and execution interface code generation.

11. A WASM smart contract development kit, characterized in that: A WASM smart contract development kit implemented using the development method of the WASM smart contract development kit described in any one of claims 1 to 10, comprising a WASM interface, a development language, and development tools.

12. A method for writing smart contracts using a WASM smart contract development kit, characterized in that: Developers use the WASM smart contract development kit described in claim 11 to write WASM smart contracts.

Citation Information

Cited By

  • Low-code platform and Wasm high-performance computing integration system and method

    CN120406919A