An Instruction Expansion Management Method for Blockchain Smart Contracts

Through dynamic expansion and modular management strategies, the flexible expansion of the smart contract instruction set is achieved, which solves the problem that the existing instruction set cannot meet complex application scenarios, and improves the functional customization and expansion capabilities of the smart contract.

CN119847605BActive Publication Date: 2025-06-27BEIJING WUZI UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411959635.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-30
Publication Date
2025-06-27
Estimated Expiration
2044-12-30

AI Technical Summary

Technical Problem

Due to the static and closed design, the existing smart contract instruction set cannot meet the needs of complex application scenarios, and lacks flexibility and expansion capabilities, which limits the development of blockchain technology and the implementation of innovative applications.

Method used

Using dynamic expansion and modular management strategies, a blockchain smart contract instruction expansion management method is designed, and the dynamic loading, execution and management of new instructions is realized through the instruction expansion manager, smart contract compiler and function expansion manager.

Benefits of technology

On the basis of ensuring the efficient implementation environment of existing smart contracts, it provides flexible and customizable instruction expansion solutions, supports the addition and execution of new instructions, improves the customization and expansion capabilities of smart contracts, and meets the needs of complex application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119847605B_ABST
    Figure CN119847605B_ABST
Patent Text Reader

Abstract

An instruction expansion management method for blockchain smart contracts includes a smart contract with new instructions written by a user, a new function mapping file, an instruction expansion manager, a smart contract compiler, a function extension manager, and a smart contract running environment. The instruction expansion manager generates a new instruction operation table based on the parameters passed in by the user and the instruction information in the new function mapping file. The smart contract compiler completes the compilation operation according to the compilation command passed in by the user, and accesses the new instruction operation table to retrieve the information related to the new instructions during this process, and finally generates bytecode and an application programming interface and deploys them to the smart contract running environment. The function extension manager generates a new function dynamic library through the parameters passed in by the user, the basic function library, and the new function mapping file. The smart contract running environment runs the smart contract according to the user's call command, and calls the operation function corresponding to the new instruction in the new function dynamic library during this process, and finally outputs the execution result 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 technology, and particularly to a method for managing instruction expansion of a blockchain smart contract. Background Art

[0002] With the rapid development of blockchain technology, smart contracts, as an important part of the blockchain ecosystem, have been widely applied in multiple industries. Smart contracts automatically execute contract terms based on preset logic in the blockchain system, improving the transparency and efficiency of transactions and reducing the possibility of human intervention and manual operation errors. This automated feature makes smart contracts an indispensable foundation for distributed applications, and they are applied in multiple fields such as financial services, data security, digital identity authentication, and digital asset management. Especially in the financial field, the application of blockchain and smart contracts reduces transaction costs and improves the credibility of services. However, with the continuous enrichment of blockchain application scenarios, the challenges faced by smart contracts have become more prominent. Especially in scientific research innovation and specific industry applications with increasingly complex requirements, the existing smart contract instruction sets have gradually exposed the bottleneck of being unable to meet diverse needs.

[0003] The current smart contract instruction sets are usually predefined by smart contract compilers, with limited quantity and functions, and their expansion space is relatively limited. This static and closed instruction set design, although able to meet basic needs in traditional applications, is inadequate when faced with complex application scenarios. For example, with the diversified development trend of blockchain technology application scenarios, the development requirements of smart contracts are not only limited to traditional aspects such as finance and asset management, but also extended to more complex scenarios such as scientific research exploration, cross-industry cooperation, and multi-party interaction. In these scenarios, the existing instruction sets often lack sufficient flexibility, have limited expansion capabilities, and cannot efficiently support developers in implementing new business logics and functions. This defect not only restricts the further development of blockchain technology but also affects the implementation of innovative applications. Therefore, how to break through the limitations of the existing instruction sets and improve their expansion capabilities has become an important topic in the development of blockchain technology.

[0004] The expansion of the instruction set is not just a simple addition of functions. It also involves the optimization and adjustment of the overall process from the compilation to the invocation of smart contracts, and factors such as compatibility, efficiency, and operability need to be considered. Currently, some researchers have achieved specified functions during the research process by adding custom instructions, such as permission control and vulnerability checking. However, excessive instruction expansion will increase the complexity of the contract execution environment and affect performance and resource utilization. Therefore, instruction expansion also needs to provide a flexible and operable custom instruction interface for developers without affecting the execution efficiency of existing contract code. In summary, it is particularly important to design an efficient and operable smart contract instruction expansion management method, which not only needs to solve the problem of limited instruction set space but also enables the smart contract execution environment to efficiently manage newly added instructions and provide the execution functions to support these new instructions.

[0005] To solve this problem, the present invention proposes a method for managing the instruction expansion of smart contracts, aiming to break the traditional instruction set limitations and provide a flexible and customizable instruction expansion solution by introducing dynamic expansion and modular management strategies. The expansion of the instruction set is designed as a modular structure, allowing developers to flexibly add new instructions according to actual needs and efficiently manage the execution of newly added instructions. Different from the traditional static instruction set, this dynamic expansion method can flexibly support the addition and execution of new instructions on the basis of ensuring the high efficiency of the existing smart contract execution environment. This method not only provides effective technical support for blockchain and smart contract developers but also offers new ideas for the development of blockchain technology. Especially in meeting scientific research needs, promoting cross-industry applications, and supporting the implementation of complex smart contract logics, it has important theoretical value and practical significance. Summary of the Invention

[0006] A method for managing the instruction expansion of a blockchain smart contract, characterized in that the following operations are performed in an instruction expansion manager, including:

[0007] The parameter parser parses the parameters input by the user to obtain the basic configuration information and sends it to the instruction list loading parser. The basic configuration information includes the path of the newly added function mapping file and the name of the new instructions used by the current smart contract.

[0008] The instruction list loading parser accesses the newly added function mapping file according to the basic configuration information, reads the basic information of the new instructions used by the current smart contract, and generates a new instruction operation table. The newly added function mapping file consists of two parts: the basic information of the new instructions and the operation functions.

[0009] Preferably, the following operations are performed in the smart contract compiler, including:

[0010] The compilation command input by the user is parsed by the compilation parameter parser. According to the name and path of the smart contract in the compilation command, the smart contract is read and parsed into a character stream form and then sent to the contract parser;

[0011] The contract parser performs lexical analysis, syntax analysis, and semantic analysis on the smart contract in character stream form in sequence to obtain a semantic information table containing new instruction names and an abstract syntax tree;

[0012] The instruction processor performs instruction analysis, retrieves default instructions, and retrieves new instructions based on the semantic information table and the abstract syntax tree to generate a contract intermediate representation including new instruction information, data, data flow, and control flow information;

[0013] The bytecode generator generates bytecode including new instruction information and corresponding application programming interfaces according to the contract intermediate representation and deploys them to the smart contract running environment.

[0014] Preferably, the following operations are performed in the function extension manager, including:

[0015] The dynamic library generator reads the parameters input by the user. The parameters include the command rules, path of the new function dynamic library, and the path of the new function mapping file. It checks the correctness of the path of the new function mapping file. If it is correct, it reads the basic information and operation functions of the new instructions from the new function mapping file. The operation function of the new instruction represents the execution logic of the new instruction;

[0016] The new function mapping file calls the basic operation function module in the basic function library to cooperate with the implementation of the operation function of the new instruction. The basic operation function module represents common and general basic operation logics;

[0017] The dynamic library generator operates on the new function mapping file and the basic function library to generate a new function dynamic library. The new function dynamic library includes the operation functions of the new instructions;

[0018] The new function processor manages the new function dynamic library and performs running environment processing and mapping file monitoring.

[0019] Preferably, the following operations are performed in the smart contract running environment, including:

[0020] The running parameter parser parses the call command input by the user. According to the call command, it determines the bytecode involved in the currently running smart contract, and then parses the bytecode to extract the operation code and operation number. The operation code and operation number are sent to the operation code parser. The operation code corresponds to an instruction one by one. The default operation code corresponds to the default instruction, and the new operation code corresponds to the new instruction;

[0021] The default operation functions corresponding to the default instructions are stored in the default function library;

[0022] The opcode parser calls the operation functions according to the opcode, including calling the default function and the newly added function. If the current opcode is the default opcode, the opcode parser accesses the default function library and loads the default operation function module corresponding to the default opcode; if the current opcode is the new opcode, the opcode parser sends the name of the new opcode to the running extension processor, and the running extension processor retrieves the corresponding newly added function to obtain the opcode and operand containing the operation function, and then sends the opcode and operand to the execution engine;

[0023] The running extension processor loads the new function dynamic library to call the newly added function, which specifically includes two parts: preprocessing and calling the function. The preprocessing is that the running extension processor saves the memory address and library name of the received new function dynamic library; the calling the function is that the running extension processor loads the new function dynamic library according to the memory address and library name of the new function dynamic library and retrieves the corresponding newly added function module;

[0024] The execution engine executes the opcode and outputs the execution result.

[0025] Preferably, the newly added function mapping file consists of two parts: the basic information of the newly added instruction and the operation function, including:

[0026] a. Basic information of the new instruction: The basic information of the new instruction includes type, group number, instruction name, and bytecode. The type indicates the category to which the new instruction belongs. The new instructions are divided into identification instructions and character instructions. The identification instructions are used to guide the behavior of the contract through specific symbols or marks and are used to transmit control information; the character instructions are composed of letters and numbers and are used to execute specific business logics or data processing. The group number indicates the group to which the new instruction belongs. The instruction name indicates the name of the new instruction. The bytecode indicates the byte representation form of the new instruction. The bytecode has a unique correspondence with the instruction name and cannot be repeated with the bytecode corresponding to the default instruction in the compiler. Users can support further classification of instructions according to functional characteristics by defining different group numbers;

[0027] b. Operation function: The operation function of the new instruction refers to the instruction function executed during the operation of the contract, including the function name and the function body. The function name represents the function name of the instruction function, and the function body represents the execution function corresponding to the instruction, which is divided into contract behavior control function and business logic processing function according to the instruction type.

[0028] Preferably, the contract parser performs lexical analysis, syntax analysis, and semantic analysis on the smart contract in the form of a character stream in sequence, including:

[0029] a. Lexical analysis: Scan the character stream, identify the basic elements of the contract, convert them into tokens with syntactic meaning, and new instructions will be processed as new special identifiers;

[0030] b. Syntactic analysis: Parse the token stream according to the syntactic rules to generate an abstract syntax tree. When a new instruction is encountered, the contract parser will match the instruction with relevant functions or variables in the program and add a new field identifier to the corresponding node in the abstract syntax tree to mark the target and context environment associated with the new instruction operation;

[0031] c. Semantic analysis: Check whether the contract complies with the semantic rules according to the information in the abstract syntax tree. The instruction processor will add the identifier corresponding to the new instruction to the semantic information table. At the same time, the contract parser will ensure that the relationships and logics between the various elements of the contract are correct according to the context information in the contract semantic information table.

[0032] Preferably, the generation of the contract intermediate representation by the instruction processor includes:

[0033] a. Instruction analysis: Determine the instructions to be used according to the semantic information table and the abstract syntax tree, and analyze the instructions to determine whether the instruction is a default instruction or a new instruction;

[0034] b. Retrieving default instructions: If the current instruction is a default instruction, the instruction processor accesses the default instruction table to retrieve the detailed information related to the current instruction;

[0035] c. Retrieving new instructions: If the current instruction is a new instruction, the instruction processor accesses the new instruction execution table to retrieve the relevant information of the new instruction. Specifically, look up the entry corresponding to the name of the new instruction in the new instruction execution table to obtain the bytecode of the instruction.

[0036] Preferably, the processing of the operating environment and the monitoring of the mapping file by the new function processor include:

[0037] a. Operating environment processing: The new function processor sends the memory address and library name of the new function dynamic library to the runtime extension processor, so that the opcode parser can correctly retrieve the function module in the new function dynamic library through the runtime extension processor when calling the new function;

[0038] b. Mapping file monitoring: Monitor the new function mapping file according to the user's requirements, continuously monitor at the set interval. If it is detected that there are unloaded new instructions during the monitoring, regenerate the new function dynamic library containing all new instructions, and send the memory address and library name of the new function dynamic library to the runtime extension processor again. Description of the Drawings

[0039] Some specific embodiments of the present invention will be described in detail hereinafter with reference to the accompanying drawings in an exemplary but not restrictive manner. The same reference numerals in the drawings denote the same or similar components or parts. Those skilled in the art should understand that these drawings are not necessarily drawn to scale. The objectives and features of the present invention will become more apparent in view of the following description in conjunction with the accompanying drawings, in which:

[0040] Figure 1 It is a schematic flowchart of the operation of the instruction extension management method for blockchain smart contracts;

[0041] Figure 2 It is a detailed flowchart of the operation of the instruction extension management method for blockchain smart contracts;

[0042] Figure 3 It is a flowchart of the operation of the instruction extension manager;

[0043] Figure 4 It is a flowchart of the operation of the function extension manager. Specific Embodiments

[0044] To solve the contradiction between the current application scenarios and scientific research exploration requirements for new instructions in smart contracts and the fixed and limited number of instructions in the existing smart contract compilation and running environments, the present invention proposes an instruction extension management method for blockchain smart contracts, which supports users to customize instructions according to actual needs, and can realize the dynamic loading, execution, and management of new instructions in the smart contract compiler and running environment, providing users with a flexible and extensible smart contract instruction usage environment.

[0045] The present invention proposes an instruction extension management method for blockchain smart contracts, and the overall operation process is as Figure 1 shown.

[0046] The overall operation process involves a smart contract with new instructions written by users, a new function mapping file, an instruction extension manager, a contract compiler, a function extension manager, and a smart contract running environment, as Figure 1As shown in the figure. The instruction expansion manager generates a new instruction execution table based on the parameters passed in by the user and the instruction information in the new function mapping file, and through the parameter parser and the instruction list loading parser. The smart contract compiler compiles the smart contract with new instructions according to the compilation command passed in by the user through multiple components such as the compilation parameter parser, the contract parser, the instruction processor, the default instruction table, and the bytecode generator. During this process, the instruction processor will access the new instruction execution table to query the relevant information of the new instruction, and finally generate bytecode and application programming interfaces and deploy them to the smart contract runtime environment. The function extension manager generates a new function dynamic library based on the parameters passed in by the user and the information in the new function mapping file, and through the dynamic library generator and the basic function library. The smart contract runtime environment runs the smart contract according to the call command input by the user through the runtime parameter parser, the opcode parser, the runtime extension processor, and the execution engine. During this process, the runtime extension processor will call the operation function corresponding to the new instruction in the new function dynamic library, and finally output the execution result of the smart contract.

[0047] Furthermore, the process is described in detail as Figure 2 shown in the figure, including the contract writing stage, the contract compilation stage, and the contract running stage. The components involved are described as follows:

[0048] (1) Instruction expansion manager: It consists of a parameter parser, an instruction list loading parser, and a new instruction execution table, and can provide information about new instructions for compilation according to requirements;

[0049] (2) Parameter parser: Parse the parameters input by the user before the compilation starts to obtain the basic configuration information, where the basic configuration information includes the name of the new instructions used in the contract and the path of the new function mapping file;

[0050] (3) Instruction list loading parser: Access the new function mapping file according to the basic configuration information, obtain the relevant information of the new instructions involved in the current smart contract, and generate a new instruction execution table;

[0051] (4) New instruction execution table: Provide the relevant information of the new instructions, including type, group number, instruction name, and bytecode;

[0052] (5) Smart contract compiler: It consists of a compilation parameter parser, a contract parser, an instruction processor, a default instruction table, and a bytecode generator, and can compile the smart contract and, in combination with the instruction expansion manager, enable the new instructions to be correctly compiled;

[0053] (6) Compilation parameter parser: Parse the compilation command input by the user, read the compilation parameters, and convert the specified smart contract into a character stream form;

[0054] (7) Contract Parser: Perform lexical analysis, syntax analysis, and semantic analysis on the smart contract in the form of a character stream in sequence to obtain a semantic information table and an abstract syntax tree;

[0055] (8) Instruction Processor: Determine the instructions to be used according to the semantic information table and the abstract syntax tree information, and analyze the instructions. If it is a default instruction, access the default instruction table to retrieve the default instruction; if it is a new instruction, access the new instruction execution table in the instruction extension manager to retrieve the new instruction, and generate the corresponding contract intermediate representation according to the instruction information;

[0056] (9) Bytecode Generator: Generate bytecode according to the intermediate representation of the contract, and output the bytecode and the corresponding application programming interface;

[0057] (10) Function Extension Manager: Consisting of a dynamic library generator, a basic function library, and a new function processor, it can dynamically load the operation functions of new instructions and integrate them into the smart contract running environment;

[0058] (11) Dynamic Library Generator: By parsing the parameters input by the user, check whether the new function mapping file exists, and read the basic information and operation functions of the new instruction from it to support the generation of the new function dynamic library;

[0059] (12) Basic Function Library: Provide basic operation function modules for the new function mapping file, which can be called by the new instructions in the new function mapping file;

[0060] (13) New Function Processor: Include two operations of running environment processing and mapping file monitoring, and can manage the generated new function dynamic library at the same time;

[0061] (14) Smart Contract Running Environment: Consisting of a running parameter parser, an opcode parser, a default function library, a running extension processor, and an execution engine, it can execute the smart contract bytecode;

[0062] (15) Running Parameter Parser: Parse the call command input by the user, determine the bytecode involved in the current call, and extract the corresponding opcode and operands from the bytecode;

[0063] (16) Opcode Parser: Receive the opcode and operands passed in by the running parameter parser, and retrieve the corresponding default operation function and new operation function according to the opcode;

[0064] (17) Default Function Library. Store the default operation function modules corresponding to the default opcodes;

[0065] (18) Running extension processor: It is the connection bridge between the intelligent contract running environment and the function extension manager. It can receive the information of the call for new function requirements passed in by the opcode parser, and dynamically load the new function dynamic library in the new function processor according to the requirements;

[0066] (19) Execution engine: Execute the operation function corresponding to the contract opcode of this call and output the corresponding execution result.

[0067] Based on the above functional components, the execution process of the contract instruction expansion management method for the blockchain intelligent contract designed by the present invention is described as follows:

[0068] In the contract writing stage, the user first writes a new function mapping file, which includes the basic information of the new instruction (type, group number, instruction name, and bytecode) and the operation function corresponding to the instruction (①). Then, the user can write an intelligent contract and add new instructions (character instructions and identification instructions) to the contract (②).

[0069] After the writing stage is completed, it enters the contract compilation stage. Before starting to compile the contract, the user needs to first input parameters to the parameter parser (③). The parameters include the path of the new function mapping file and the names of the new instructions used in the intelligent contract (i.e., the basic configuration information). The parameter parser sends the above basic configuration information to the instruction list loading and parser (④). The instruction list loading and parser reads the corresponding basic information from the new function mapping file according to the names of the new instructions used (⑤⑥), and generates a new instruction operation table (⑦). The user inputs a compilation command to start the compilation operation (⑧). The compilation parameter parser parses the compilation parameters from the compilation command, determines the intelligent contract to be compiled, converts the intelligent contract into a character stream form, and inputs it into the contract parser (⑨). The contract parser performs lexical analysis (a), syntax analysis (b), and semantic analysis (c) on the intelligent contract in sequence, generates a semantic information table and an abstract syntax tree carrying the new instruction names, and transmits them to the instruction processor (⑩). The instruction processor performs instruction analysis based on the input information (a). If it encounters a default instruction, it retrieves the information of the default instruction from the default instruction table (b) If it encounters a new instruction, it retrieves the information of the new instruction from the new instruction operation table (c) After retrieving the instructions, generate a contract intermediate representation carrying the new instruction information and input it into the bytecode generator Generate bytecode and application programming interface Deploy to the intelligent contract running environment Complete the compilation link.

[0070] After the contract compilation stage is completed, the contract running stage is entered. Before starting to call the contract, the user needs to first input parameters (the naming rule, path of the new function dynamic library, and the path of the new function mapping file) to the dynamic library generator The dynamic library generator parses the parameters and first checks whether the new function mapping file at the specified path exists. If it exists, it reads the basic information of the new instruction and the corresponding operation function from it The operation function corresponding to the new instruction can be implemented by calling the basic operation function module in the basic dynamic library Generate a new function dynamic library based on the basic information and operation function of the new instruction The new function processor can not only manage the generated new function dynamic library, but also perform runtime environment processing (a), and send the preprocessing information to the runtime extension processor in the smart contract runtime environment The runtime extension processor performs preprocessing operations, records the memory address of the new function dynamic library for convenient subsequent invocation of the operation function corresponding to the new instruction. At the same time, the new function processor can monitor whether the new function mapping file has changed (b) If it has changed, a new new function dynamic library will be dynamically generated. After the preparation work is completed, the user sends a call command to the smart contract runtime environment The call command is parsed by the runtime parameter parser, and the bytecode used for this call is determined according to the call command. The bytecode is parsed, and the obtained operation code and operands are sent to the operation code parser The operation code parser loads the default operation function corresponding to the default operation code from the default function library (a) The runtime extension processor retrieves the new operation function corresponding to the new operation code from the new function dynamic library (b) Send the operation code and operands carrying the function module to the execution engine The execution engine executes the operation code and outputs the execution result, completing the contract running link.

[0071] Based on the above overall process design, the specific work of the important steps is described in detail as follows:

[0072] In the contract writing stage, the user needs to write a new function mapping file and a smart contract with new instructions.

[0073] (1) The user writes a new function mapping file

[0074] The new function mapping file defines the information of the new instruction.

[0075] The information of the new instruction includes two parts: the basic information of the new instruction and the operation function.

[0076] The basic information of the new instruction is used to generate the corresponding bytecode during the contract compilation process, including type, group number, instruction name, and bytecode. The type represents the category to which the new instruction belongs. The new instructions are divided into identification instructions and character instructions. The identification instructions are used to guide the behavior of the contract through specific symbols or marks, for transmitting control information without involving new business logic, and are mainly used to instruct specific functional components to perform some functions as required. The character instructions are composed of letters and numbers and are used to execute specific business logic or data processing, which can directly affect the running content and results of the contract. The introduction of these two types of instructions can enhance the expression ability of the smart contract language, enabling it to more flexibly handle complex compilation and execution requirements. The group number represents the group to which the new instruction belongs, the instruction name represents the name of the new instruction, and the bytecode represents the hexadecimal byte representation of the new instruction. The bytecode has a unique correspondence with the instruction name and cannot be repeated with the bytecode corresponding to the default instructions in the compiler. Users can support further classification of instructions according to functional characteristics by defining different group numbers. The operation function of the new instruction refers to the instruction function executed during the contract operation, including function name and function body. The function name represents the name of the functional function of the instruction, and the function body represents the corresponding execution function of the instruction, which is divided into contract behavior control function and business logic processing function according to the instruction type.

[0077] (2) Users write a smart contract with new instructions

[0078] The smart contract with new instructions refers to adding new instructions on the basis of the original smart contract writing logic. Users can select instructions in the newly added function mapping file and write these instructions in the appropriate positions of the smart contract according to actual needs.

[0079] In the contract compilation stage, all operations are completed in the instruction expansion manager and the smart contract compiler. Users need to pass the names of the new instructions used in the smart contract and the path of the newly added function mapping file into the instruction expansion manager, and at the same time input the compilation command to execute the compilation operation of the smart contract.

[0080] The operations involved in the instruction expansion manager are as Figure 2 shown.

[0081] (3) Users input parameters

[0082] Before the start of the smart contract compilation process, users need to input parameters (the path of the newly added function mapping file and the names of the new instructions used in the smart contract, that is, the basic configuration information) to the parameter parser, and the parameter parser is responsible for processing and parsing these parameters, so as to accurately transmit the basic configuration information to the subsequent processing stages.

[0083] (4) The parameter parser sends the parsed basic configuration information to the instruction list loading and parser

[0084] After receiving the parameters input by the user, the parameter parser first parses the basic configuration information to confirm the path of the newly added function mapping file and the name of the new instruction contained therein. Then, the parsed information is passed to the instruction list loading parser.

[0085] (5) Access the newly added function mapping file

[0086] Based on the file path in the incoming basic configuration information, the instruction list loading parser accesses the specified newly added function mapping file.

[0087] (6) Read instruction information

[0088] The instruction list loading parser extracts the specific data related to the new instructions in the smart contract from the newly added function mapping file. This data includes the type, group number, instruction name, and corresponding bytecode of each new instruction.

[0089] (7) Dynamically generate a new instruction execution table

[0090] The instruction list loading parser dynamically generates a new instruction execution table based on the read instruction data. The new instruction execution table provides the necessary instruction information for the subsequent compilation work of the smart contract compiler, enabling the new instructions to be correctly integrated and function properly.

[0091] So far, the new instruction information used in the current smart contract has been dynamically loaded. Next, the smart contract needs to be compiled in the smart contract compiler.

[0092] (8) User inputs a compilation command

[0093] At the initial stage of the smart contract compilation process, the user needs to provide a compilation command to start the entire compilation process. The compilation command includes the smart contract file name and compilation options.

[0094] (9) Parse the compilation command and the smart contract

[0095] The compilation parameter parser parses the compilation command, obtains the compilation parameters, loads and parses the smart contract, and transfers the contract in the form of a character stream obtained by parsing to the contract parser.

[0096] (10) Analyze the smart contract

[0097] The contract parser performs a. lexical analysis, b. syntax analysis, and c. semantic analysis on the contract. The contract parser is one of the core components in the smart contract compilation process and is responsible for comprehensively analyzing the contract. This process includes three stages: lexical analysis, syntax analysis, and semantic analysis, ensuring the correct syntax and semantics of the contract and providing a basis for subsequent instruction processing.

[0098] a. Lexical analysis: Lexical analysis is the process of converting the character stream of a smart contract into a series of token streams. In this stage, the contract parser scans the character stream in the source code, identifies basic contract elements such as keywords, identifiers, constants, operators, delimiters, etc., and converts them into tokens with syntactic meanings. Each token represents a specific language component in the program, such as variable names, types, control statements, etc. For new instructions encountered, the lexical analyzer treats them as a new and special identifier, thus providing accurate input for subsequent syntactic analysis.

[0099] b. Syntactic analysis: Syntactic analysis is based on lexical analysis and parses the token stream according to the syntax rules of the smart contract to generate an abstract syntax tree. The abstract syntax tree is a tree representation of the source code structure, which can record the syntactic relationships and hierarchies of various parts of the program. During the construction of the syntactic analysis, when new instructions are encountered, the contract parser matches these instructions with relevant functions or variables in the program and adds new field identifiers to the corresponding nodes in the abstract syntax tree to indicate the targets (such as functions or variables) that the instructions act on, so as to be able to identify the specific operation positions of the new instructions in the tree structure.

[0100] c. Semantic analysis: Semantic analysis is an operation based on the abstract syntax tree, and its main purpose is to verify the logical consistency of the program, the correctness of data types, and the compliance with other semantic rules. During this process, the contract parser checks whether the contract follows the semantic rules of the language, such as whether variables are correctly declared and whether types match, according to the information in the abstract syntax tree. For new instructions, the instruction processor adds their corresponding identifiers to the semantic information table and ensures that the instructions are correct both logically and syntactically.

[0101] The semantic information table and the abstract syntax tree generated here have been integrated with the names of the new instructions. The contract parser transmits the semantic information table and the abstract syntax tree to the instruction processor.

[0102] (11) Instruction analysis and instruction retrieval

[0103] The instruction processor includes three parts of operations: a. instruction analysis, b. retrieving default instructions, and c. retrieving new instructions.

[0104] a. Instruction analysis: Instruction analysis refers to determining and analyzing the instructions to be used according to the semantic information table and the abstract syntax tree. In this stage, the instruction processor first accurately identifies the instructions to be applied in the contract according to the information such as variables, functions, and their types recorded in the semantic information table, combined with the operation structure defined in the abstract syntax tree, and analyzes the instructions to determine the instruction types. Here, the instruction types refer to default instructions and new instructions. Once the instruction processor determines the instruction types, it will proceed to the next step of instruction invocation.

[0105] b. Retrieving default instructions: If the current instruction is a default instruction, the instruction processor will access the default instruction table to retrieve detailed information related to that instruction. Default instructions refer to instruction types that have been predefined and widely used during the contract compilation process, and the behavior and bytecode of these instructions are fixed. By looking up the entries in the default instruction table, the instruction processor can quickly find the information related to the target instruction and accurately embed it into the contract intermediate representation.

[0106] c. Retrieving new instructions: If the current instruction is a new instruction, the instruction processor needs to access the new instruction execution table to retrieve the relevant information of the new instruction. Based on the name of the new instruction, the instruction processor looks up the corresponding entry in the new instruction execution table to obtain the bytecode of that instruction. These bytecodes will be used to generate the contract intermediate representation and ultimately be converted into executable smart contract bytecodes.

[0107] (12) Transmitting the contract intermediate representation

[0108] After the instruction processor retrieves the default instructions and new instructions in sequence, it will generate the corresponding contract intermediate representation, which already incorporates the relevant information of the new instructions. Next, the contract intermediate representation will be transmitted to the bytecode generator for further processing and generating the final bytecode.

[0109] (13) Generating bytecode

[0110] The bytecode generator converts the contract intermediate representation into bytecodes that can be executed in the smart contract runtime environment. Finally, the output bytecodes and the corresponding application interface files are generated.

[0111] (14) Deployment

[0112] Deploy the bytecodes and the application interface to the smart contract runtime environment for subsequent user calls.

[0113] At this point, all the operations in the current smart contract compilation phase are completed, and next, the user can start the call operation to run the smart contract.

[0114] During the contract runtime phase, all operations are completed in the function extension manager and the smart contract runtime environment. The user needs to transmit the naming rules, paths of the new function dynamic libraries, and the paths of the new function mapping files to the function extension manager, and at the same time input the call command to execute the call operation of the smart contract.

[0115] Operations involved in the function extension manager are as Figure 3 shown.

[0116] (15) User input parameters

[0117] Before the smart contract call operation starts, the user needs to input parameters (the naming rule, path of the new function dynamic library, and the path of the new function mapping file) to the dynamic library generator for subsequent generation of the new function dynamic library.

[0118] (16) Check and read the information of the new instruction

[0119] The dynamic library generator parses the parameters to obtain the naming rule, path of the new function dynamic library, and the path of the new function mapping file. First, it checks whether the new function mapping file exists. If it exists, it accesses the new function mapping file to read the basic information of the new instruction and the corresponding operation function.

[0120] (17) Call the basic operation function

[0121] The operation function of the new instruction in the new function mapping file can be implemented on the basis of the basic operation function in the basic dynamic library, that is, the basic operation function module in the basic dynamic library can be directly called.

[0122] (18) The new function processor manages the new function dynamic library and undertakes the work of running environment processing and mapping file monitoring

[0123] The dynamic library generator operates on the new function mapping file and the basic function library to generate the corresponding new function dynamic library. The new function processor can manage the new function dynamic library. During the dynamic library generation process, the mapping relationship between the function and the instruction is strictly managed so that the instruction and the function can be correctly matched and executed during subsequent calls. At the same time, the new function processor can also perform two operations: a. running environment processing and b. mapping file monitoring.

[0124] a. Running environment processing: Send the memory address and library name of the loaded new function dynamic library to the running extension processor in the running environment of the smart contract, so that the running environment of the smart contract can correctly identify and call the function module in the new function library. If the new function dynamic library is updated subsequently, only this operation needs to be performed to resend the memory address and name of the library. This operation can not only ensure the flexibility during the contract operation but also adapt to new function requirements in real time without large-scale modification of the original structure.

[0125] b. Mapping File Monitoring: The mapping file monitoring section can monitor the mapping files of newly added functional modules according to the user's requirements. The monitoring process continuously monitors at set intervals to ensure that new instructions in the library can be loaded and updated in a timely manner. Since the mapping file contains information about new instructions and related functional modules, by monitoring the mapping file, when unloaded new instructions are found, they can be automatically loaded into the running environment, and the addresses and names of the library can be updated as needed, enabling the smart contract to call the latest functions according to requirements during execution, and resending the memory address and library name of the new functional library to the running extension processor.

[0126] At this point, all new instruction information and their functions in the current newly added function mapping file have been dynamically loaded. Next, the new functional library needs to be called during the execution of the smart contract to execute the functions corresponding to the new instructions.

[0127] (19) User inputs a call command

[0128] The user needs to provide a call command to start the execution process of the smart contract. The call command includes the smart contract file name, the function name to be called, and the input of the function.

[0129] (20) Obtain the operation code involved in the current call

[0130] The runtime parameter parser will parse the previously deployed bytecode and the call command input by the user to determine the bytecode involved in this call, and extract the operation code and operands from the bytecode.

[0131] (21) Call the function corresponding to the operation code

[0132] The runtime parameter parser sends the parsed operation code to the operation code parser. The operation code parser will determine whether the default instruction corresponding to the current processed operation code is the default operation code or the new operation code corresponding to the new instruction, and execute two parts: a. Call the default function and b. Call the newly added function.

[0133] a. Call the default function: If it is recognized as the default operation code, the operation code parser will access the default function library and load the operation function module corresponding to the default operation code.

[0134] b. Call the newly added function: When the runtime parameter parser recognizes the new operation code, it needs to call the newly added function corresponding to the new operation code. First, the instruction name needs to be transmitted to the running extension processor. The running extension processor will load the new functional library based on the name and memory address of the new functional library received previously, and call the corresponding newly added function.

[0135] (22) Execute the operation code

[0136] The opcode parser transmits the opcode appended with the operation function to the execution engine. The execution engine executes the operation function corresponding to the opcode and finally outputs the execution result.

[0137] Advantages of the present invention:

[0138] A method for managing instruction expansion of a blockchain smart contract is proposed, which is manifested as follows: Design an instruction expansion manager for loading the basic information of new instructions, so that new instructions can be correctly identified and processed during the contract compilation process. At the same time, since the instruction expansion manager can be dynamically loaded in memory according to the requirements of the application program and can interact with the smart contract compiler, it has strong flexibility and solves the problems of customization and recognition of new instructions during the compilation of application programs; the smart contract compiler includes the parsing and processing process of new instructions and works in cooperation with the instruction expansion manager to jointly complete the compilation process of the smart contract including new instructions, thus solving the problem of the fixed number of smart contract instructions. Different application programs load different new instructions through the instruction expansion manager, and the expandability of new instructions is significantly increased; design a function expansion manager to realize the generation of a new function dynamic library, which is convenient for the contract to correctly call the operation function of the new instruction when executing in the smart contract running environment. The function expansion manager also has a dynamic monitoring function and can adaptively and flexibly load new function modules.

[0139] In summary, the present invention provides a flexible and extensible smart contract instruction management method, which enhances the customizability of the functions of the smart contract, thereby meeting the diverse needs of different application scenarios and scientific research.

[0140] In the above embodiments, all or part of the functions can be implemented by software, hardware, or a combination of software and hardware. 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 program instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium. The computer-readable storage medium can be any available medium that the computer can access or a data storage device such as a server or a data center that includes one or more integrated available media. The available medium can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid-state disk (SSD)), etc.

[0141] As described above, it is only the specific implementation manner of the embodiments of the present application. However, the protection scope of the embodiments of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the embodiments of the present application should be covered within the protection scope of the embodiments of the present application. Therefore, the protection scope of the embodiments of the present application shall be subject to the protection scope of the claims.

Claims

1. A method for managing instruction expansion of blockchain smart contracts, characterized in that: Perform the following operations in the Command Extension Manager, including: The parameter parser parses the parameters input by the user, obtains the basic configuration information and sends it to the instruction list loader parser. The basic configuration information includes the path of the newly added function mapping file and the name of the new instruction used by the current smart contract; The parser loaded by the instruction list accesses the new function mapping file according to the basic configuration information, reads the basic information of the new instructions used by the current smart contract, and generates a new instruction operation table. The new function mapping file consists of two parts: the basic information of the new instruction and the operation function; The following operations are performed in the smart contract compiler, including: The compilation parameter parser parses the compilation command input by the user, reads the smart contract according to the name and path of the smart contract in the compilation command, parses it into a character stream form and then sends it to the contract parser; The contract parser performs lexical analysis, grammatical analysis, and semantic analysis on the smart contract in the form of a character stream, and obtains a semantic information table and an abstract syntax tree containing the new instruction name; The instruction processor performs instruction analysis, calls default instructions, and calls new instructions according to the semantic information table and the abstract syntax tree, and generates a contract intermediate expression including new instruction information, data, data flow, and control flow information; The bytecode generator generates bytecode including new instruction information and corresponding application program interface according to the intermediate expression of the contract, and deploys it to the smart contract running environment.

2. The method according to claim 1, characterized in that: Perform the following operations in the Extension Manager, including: The dynamic library generator reads the parameters input by the user, including the command rules and path of the new function dynamic library and the path of the new function mapping file, checks the correctness of the new function mapping file path, and if correct, reads the basic information and operation function of the new instruction from the new function mapping file, wherein the operation function of the new instruction represents the execution logic of the new instruction; The new function mapping file calls the basic operation function module in the basic function library to cooperate with the operation function of the new instruction, and the basic operation function module represents the common and general basic operation logic; The dynamic library generator operates the newly added function mapping file and the basic function library to generate a new function dynamic library, wherein the new function dynamic library includes the operation function of the new instruction; The new function processor manages the new function dynamic library and performs operating environment processing and mapping file monitoring.

3. The method according to claim 1, characterized in that: Perform the following operations in the smart contract runtime environment, including: The running parameter parser parses the call command input by the user, determines the bytecode involved in the currently running smart contract according to the call command, and then parses the bytecode to extract the opcode and operand from it, and sends the opcode and operand to the opcode parser. The opcode corresponds to the instruction one by one, the default opcode corresponds to the default instruction, and the new opcode corresponds to the new instruction; The default operation functions corresponding to the default instructions are stored in the default function library; The operation code parser calls the operation function according to the operation code, including calling the default function and calling the newly added function. If the current operation code is the default operation code, the operation code parser accesses the default function library to load the default operation function module corresponding to the default operation code; if the current operation code is a new operation code, the operation code parser transmits the name of the new operation code to the operation extension processor, and the operation extension processor calls the corresponding newly added function to obtain the operation code and operand containing the operation function, and then sends the operation code and operand to the execution engine; The running extension processor loads the new function dynamic library to call the new function, which specifically includes two parts: preprocessing and calling functions. The preprocessing is that the running extension processor saves the memory address and library name of the received new function dynamic library; the calling function is that the running extension processor loads the new function dynamic library according to the memory address and library name of the new function dynamic library, and calls the corresponding new function module; The execution engine executes the operation code and outputs the execution result.

4. The method according to claim 1, characterized in that: The new function mapping file consists of two parts: basic information of the new instruction and operation function, including: a. Basic information of new instructions: The basic information of the new instructions includes type, group number, instruction name and bytecode. The type indicates the category to which the new instruction belongs. The new instructions are divided into identification instructions and character instructions. The identification instructions guide the behavior of the contract through specific symbols or marks and are used to transmit control information. The character instructions are composed of letters and numbers and are used to execute specific business logic or data processing. The group number indicates the group to which the new instruction belongs. The instruction name indicates the name of the new instruction. The bytecode indicates the byte representation of the new instruction. The bytecode has a unique correspondence with the instruction name and cannot be repeated with the bytecode corresponding to the default instruction in the compiler. Users can support further classification of instructions according to functional characteristics by defining different group numbers; b. Operation function: The operation function of the new instruction refers to the instruction function executed during the contract operation, including the function name and the function body. The function name indicates the function name of the instruction, and the function body indicates the execution function corresponding to the instruction. It is divided into contract behavior control function and business logic processing function according to the instruction type.

5. The method according to claim 1, characterized in that: The contract parser performs lexical analysis, grammatical analysis, and semantic analysis on the smart contract in the form of a character stream in sequence, including: a. Lexical analysis: Scan the character stream, identify the basic elements of the contract, and convert them into tokens with grammatical meaning. New instructions will be processed as new, special identifiers; b. Syntax analysis: Parse the token stream according to the syntax rules to generate an abstract syntax tree. When encountering a new instruction, the contract parser will match the instruction with the relevant function or variable in the program, and add a new field identifier in the corresponding node of the abstract syntax tree to mark the target and context environment associated with the new instruction operation; c. Semantic analysis: Based on the information in the abstract syntax tree, check whether the contract complies with the semantic rules. The instruction processor will add the identifier corresponding to the new instruction to the semantic information table. At the same time, the contract parser will ensure that the relationship and logic between the various elements of the contract are correct based on the context information in the contract semantic information table.

6. The method according to claim 1, characterized in that: The generation of the contract intermediate expression by the instruction processor includes: a. Instruction analysis: determining the instruction to be used according to the semantic information table and the abstract syntax tree, and analyzing the instruction to determine whether the instruction is a default instruction or a new instruction; b. Retrieving the default instruction: If the current instruction is a default instruction, the instruction processor accesses the default instruction table to retrieve detailed information related to the current instruction; c. Retrieving a new instruction: If the current instruction is a new instruction, the instruction processor accesses the new instruction execution table to retrieve relevant information of the new instruction, specifically, searching the new instruction execution table for an entry corresponding to the name of the new instruction to obtain the bytecode of the instruction.

7. The method according to claim 2, characterized in that: The new function processor performs operating environment processing and mapping file monitoring, including: a. Runtime environment processing: The new function processor sends the memory address and library name of the new function dynamic library to the run extension processor, so that the opcode parser can correctly call the function module in the new function dynamic library through the run extension processor when calling the new function; b. Mapping file monitoring: Monitor the newly added function mapping files according to user needs, and continue monitoring at the set interval. If the monitoring finds that there are new instructions that have not been loaded, regenerate a new function dynamic library containing all new instructions, and resend the memory address and library name of the new function dynamic library to the running extension processor.

Citation Information

Patent Citations

  • Highly-available contract executing method and system

    CN107844294A

  • Data processing method and system based on blockchain smart contract

    CN111782338A