A method, system, terminal and medium for calling multiple smart contracts mutually
By generating cross-contract call statements and building compilation rules, the problem of intermodulation of different contract languages is solved, the interoperability of smart contracts is achieved, and the development efficiency and platform compatibility are improved.
Patent Information
- Application Number
- CN202510062692.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-15
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2045-01-15
AI Technical Summary
Smart contracts in different contract languages in the prior art cannot be called with each other, resulting in limited interoperability of smart contracts.
The initial cross-contract call statement is generated by predefined the syntax structure of the cross-contract call statement, and the compilation rules are constructed based on the syntax structure to realize calls between different contract languages.
It realizes mutual calls between different contract languages, enhances the interoperability of smart contracts, reduces project migration costs, improves development efficiency, and promotes compatibility and cooperation between blockchain platforms.
Smart Images

Figure CN119473446B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain technology, and in particular to a method, system, terminal and medium that support mutual calling of smart contracts in different contract languages. Background Art
[0002] Since the introduction of smart contract technology, its unique decentralization and transparency have led to significant changes in multiple industries such as finance and supply chain. As the first blockchain platform to widely adopt smart contracts, Ethereum introduced the Solidity programming language, enabling developers to create complex contracts. Over the years, Solidity has become the preferred language for smart contract developers, and a variety of different projects have been established on the Ethereum platform, forming a thriving ecosystem. The formation of this ecosystem has not only promoted the application of smart contract technology, but also promoted the further development and innovation of blockchain technology.
[0003] As time goes by, other smart contract languages and platforms have emerged one after another. With their unique features and selling points, these languages have attracted many developers. However, smart contracts implemented in languages other than Solidity cannot introduce and call smart contract methods / functions implemented in Solidity, and smart contracts implemented in Solidity cannot call smart contract functions / methods implemented in languages other than Solidity. It can be seen that smart contracts in different contract languages in the prior art cannot call each other. Summary of the invention
[0004] The technical problem to be solved by the present invention is that, in view of the above-mentioned defects of the prior art, a method, system, terminal and medium that support mutual calling of smart contracts in different contract languages are provided, aiming to solve the problem in the prior art that smart contracts using different contract languages cannot call each other.
[0005] In order to solve the above technical problems, the technical solution adopted by the present invention is as follows:
[0006] In a first aspect, the present invention provides a method for supporting mutual invocation of smart contracts in different contract languages, wherein the method is applied when a first smart contract and a second smart contract in a different contract language mutually invoke each other, and the method comprises:
[0007] Generate an initial cross-contract call statement based on a predefined grammatical structure of a cross-contract call statement, wherein the initial cross-contract call statement is included in the first smart contract;
[0008] Constructing a compilation rule for the first smart contract according to the grammatical structure of the predefined cross-contract call statement;
[0009] Obtaining a cross-contract call function of the initial cross-contract call statement based on the compilation rule of the first smart contract;
[0010] Calling the second smart contract through the cross-contract call function corresponding to the initial cross-contract call statement;
[0011] Get the second smart contract with the cross-language call statement;
[0012] The first smart contract is called through the cross-language calling statement.
[0013] In one implementation, the generating of the initial cross-contract call statement based on the predefined grammatical structure of the cross-contract call statement includes:
[0014] Predefine the syntax structure of the cross-contract call statement, the syntax structure includes: syntax parameters, syntax parameter types and syntax logic, wherein the syntax parameters include keywords, the second smart contract name, the second smart contract function name, the first parameter list and the return value, the first parameter list is used to reflect the parameters required to execute the second smart contract, the syntax parameter type includes the second smart contract name type, the second smart contract function name type, the parameter type of the first parameter list and the return value type, the parameter type of the first parameter list includes basic data types, structures and arrays, the parameter type of the first parameter list is the same as the return value type, and the syntax logic is that the keywords, the second smart contract name, the second smart contract function name, the first parameter list and the return value are arranged in order from front to back;
[0015] The initial cross-contract call statement is generated based on the grammatical structure.
[0016] In one implementation, generating a compilation rule for the first smart contract according to the grammatical structure of the predefined cross-contract call statement includes:
[0017] Construct lexical analysis rules and grammatical analysis rules respectively according to the pre-defined grammatical structure of cross-contract call statements;
[0018] Based on the lexical analysis rule and the syntactic analysis rule, a compilation rule of the first smart contract is obtained.
[0019] In one implementation, a lexical analysis rule is constructed according to a predefined grammatical structure of a cross-contract call statement, including:
[0020] Obtaining keywords for predefined cross-contract call statements, and adding the keywords for predefined cross-contract call statements to a keyword table in a contract compiler of the first smart contract;
[0021] Add tags to other grammatical parameters of the grammatical parameters of the initial cross-contract call statement except for keywords to obtain extended tag information of the initial cross-contract call statement.
[0022] In one implementation, a syntax analysis rule is constructed according to a predefined syntax structure of a cross-contract call statement, including:
[0023] Parsing syntax parameters of the initial cross-contract call statement according to the extended tag information and the keywords in the keyword table added to the contract compiler of the first smart contract;
[0024] Performing integrity verification on the parsed grammatical parameters of the initial cross-contract call statement based on the grammatical parameters of the pre-defined cross-contract call statement;
[0025] If the syntax parameters of the initial cross-contract call statement are verified to be complete, an abstract syntax tree of the initial cross-contract call statement is constructed according to the syntax structure of the initial cross-contract call statement.
[0026] In one implementation, obtaining the cross-contract call function of the initial cross-contract call statement based on the compilation rule of the first smart contract includes:
[0027] Compile the initial cross-contract call statement based on the compilation rule of the first smart contract;
[0028] When the initial cross-contract call statement is compiled and passed, the cross-contract call function of the initial cross-contract call statement is obtained according to the initial cross-contract call statement.
[0029] In one implementation, compiling the initial cross-contract call statement based on the compilation rule of the first smart contract includes:
[0030] Analyze the initial cross-contract call statement based on the constructed lexical analysis rules to obtain a lexical analysis result;
[0031] Analyze the initial cross-contract call statement based on the constructed syntax analysis rules to obtain a syntax analysis result;
[0032] According to the syntax analysis result, the initial cross-contract call statement is compiled.
[0033] In one implementation, the initial cross-contract call statement is analyzed based on the constructed lexical rules to obtain a lexical analysis result, including:
[0034] Matching the keywords in the initial cross-contract call statement with the keywords of the cross-contract call statement predefined in the keyword table of the constructed lexical rules;
[0035] If the match is successful, the other grammatical parameters of the initial cross-contract call statement except the keywords are marked according to the constructed lexical rules to obtain the extended tag information of the initial cross-contract call statement.
[0036] In one implementation, the analyzing the initial cross-contract call statement based on the syntax analysis rule to obtain a syntax analysis result includes:
[0037] Parsing the grammatical parameters of the initial cross-contract call statement according to the constructed grammatical analysis rules, and verifying the integrity of the grammatical parameters;
[0038] If the syntax parameter verification is complete, the abstract syntax tree of the initial cross-contract call statement is obtained according to the syntax analysis rules.
[0039] In one implementation, compiling the initial cross-contract call statement according to the syntax analysis result includes:
[0040] Obtain the source code of the second smart contract;
[0041] Compile the source code and compilation parameters of the second smart contract to obtain a compilation result.
[0042] In one implementation, compiling the source code and compilation parameters of the second smart contract to obtain a compilation result includes:
[0043] Combining the source code and compilation parameters of the second smart contract to obtain a target file;
[0044] The target file is compiled to obtain a compilation result, where the compilation result includes the bytecode of the second smart contract, the compiled contract name of the second smart contract, and the compiled function information of the second smart contract.
[0045] In one implementation, after the initial cross-contract call statement is compiled, obtaining the cross-contract call function of the initial cross-contract call statement according to the initial cross-contract call statement includes:
[0046] Construct the second smart contract structure according to the compilation function information of the second smart contract and the name of the second smart contract;
[0047] Checking the syntax parameters of the initial cross-contract call statement according to the second smart contract structure;
[0048] Obtaining parameter types of a first parameter list of the predefined cross-contract call statement and checking syntax parameter types of the initial cross-language call statement;
[0049] The initial cross-contract call statement is translated into a cross-contract call function of the initial cross-contract call statement based on the grammatical structure of the pre-defined cross-contract call statement.
[0050] In one implementation, calling the second smart contract through the cross-contract call function corresponding to the initial cross-contract call statement includes:
[0051] Generate a contract deployment statement of the second smart contract based on the bytecode of the second smart contract;
[0052] Selecting function information corresponding to the function name of the second smart contract from all function information used by the second smart contract;
[0053] Generate a key-value pair array according to the function information corresponding to the second smart contract function name and the first parameter list in the initial cross-contract call statement, and encode the key-value pair array to obtain a parameter encoding byte array;
[0054] Execute the contract deployment statement, and construct first contract transaction information based on the encoded byte array and the compiled function information of the second smart contract;
[0055] Decoding the execution result of the first contract transaction information and the compiled function information of the second smart contract to obtain a decoded string;
[0056] The decoded string is converted into the target data format of the first smart contract and the cross-contract call function return value of the initial cross-contract call statement is updated.
[0057] In one implementation, obtaining the second smart contract with the cross-language call statement includes:
[0058] Constructing a cross-language call statement according to the contract call function of the second smart contract, wherein the cross-language call statement includes a special address and a contract call function, and the contract call function includes an encoded byte array, wherein the encoded byte array is obtained by encoding the first smart contract information;
[0059] The second smart contract is obtained based on the cross-language call statement.
[0060] In one implementation, calling the first smart contract through the cross-language call statement includes:
[0061] Constructing message information according to the encoded byte array, wherein the message information includes a data field and an address field;
[0062] Executing the cross-language call statement based on the message information;
[0063] Parsing the data field of the message information and searching for the first smart contract function signature;
[0064] Obtain the cross-language call statement and the message information according to the first smart contract function signature;
[0065] Decoding the obtained cross-language call statement and the message information to obtain execution engine parameters of the first smart contract;
[0066] Constructing second contract transaction information through the execution engine parameters and the first smart contract function name;
[0067] The first smart contract is called through the second contract transaction information.
[0068] In a second aspect, an embodiment of the present invention further provides a system for mutual invocation of multiple smart contracts, wherein the system is applied to mutual invocation of a first smart contract and a second smart contract in a different contract language, and the system comprises:
[0069] An initial cross-contract call statement generation module, used to generate an initial cross-contract call statement based on a predefined grammatical structure of a cross-contract call statement, wherein the initial cross-contract call statement is included in the first smart contract;
[0070] A compilation rule construction module, used to construct a compilation rule for the first smart contract according to the grammatical structure of the predefined cross-contract call statement;
[0071] A cross-contract call function determination module, used to obtain the cross-contract call function of the initial cross-contract call statement based on the compilation rule of the first smart contract;
[0072] A second smart contract calling module, used to call the second smart contract through the cross-contract calling function corresponding to the initial cross-contract calling statement;
[0073] A smart contract acquisition module, used to acquire a second smart contract with a cross-language call statement;
[0074] The first smart contract calling module is used to call the first smart contract through the cross-language calling statement.
[0075] In a third aspect, an embodiment of the present invention further provides a terminal, wherein the terminal includes a memory, a processor, and a program for mutual calling of multiple smart contracts stored in the memory and runnable on the processor, and when the processor executes the program for mutual calling of multiple smart contracts, the steps of the method for mutual calling of multiple smart contracts described in any one of the above items are implemented.
[0076] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a program for multiple smart contracts to call each other, and when the program for multiple smart contracts to call each other is executed by a processor, the steps of the method for multiple smart contracts to call each other described in any one of the above items are implemented.
[0077] Beneficial effects: Compared with the prior art, the present invention provides a method for mutual calling of multiple smart contracts, which can be used to realize mutual calling between smart contracts in different contract languages. The present invention first generates an initial cross-contract call statement based on the grammatical structure of a predefined cross-contract call statement, wherein the initial cross-contract call statement is included in the first smart contract, and then constructs the compilation rules of the first smart contract according to the grammatical structure of the predefined cross-contract call statement. Then, based on the compilation rules of the first smart contract, the cross-contract call function of the initial cross-contract call statement is obtained, and the second smart contract is called through the cross-contract call function corresponding to the initial cross-contract call statement. In addition, the present invention also obtains a second smart contract with a cross-language call statement, and calls the first smart contract through the cross-language call statement. The first smart contract and the second smart contract in the present invention use different contract languages. Therefore, the method based on the present invention can realize mutual calling between smart contracts in different contract languages, and enhance the interoperability between different contract languages. BRIEF DESCRIPTION OF THE DRAWINGS
[0078] Figure 1 A flowchart of a preferred embodiment of the method for mutual invocation of multiple smart contracts provided in an embodiment of the present invention.
[0079] Figure 2 An application flow chart of a first smart contract calling a second smart contract in a method for calling multiple smart contracts to each other provided in an embodiment of the present invention.
[0080] Figure 3 An example of writing a Move contract with a SolidityCall statement in the method for calling multiple smart contracts together provided in an embodiment of the present invention.
[0081] Figure 4 An application flow chart of the second smart contract calling the first smart contract in the method for mutual calling of multiple smart contracts provided in an embodiment of the present invention.
[0082] Figure 5 An example of writing a Solidity contract with a cross-language calling statement in the method for calling each other among multiple smart contracts provided in an embodiment of the present invention.
[0083] Figure 6 A schematic diagram of the architecture of a system for mutually calling multiple smart contracts provided in an embodiment of the present invention.
[0084] Figure 7 A functional block diagram of a terminal provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0085] In order to make the purpose, technical solution and effect of the present invention clearer and more specific, the present invention is further described in detail with reference to the accompanying drawings and examples. 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.
[0086] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations or steps, nor must they be executed in the order described. For example, some operations or steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.
[0087] It should be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0088] It should be understood that, in order to clearly describe the technical solutions of the embodiments of the present invention, in the embodiments of the present invention, words such as "first" and "second" are used to distinguish between identical or similar items with substantially identical functions and effects. For example, the first control information and the second control information are only used to distinguish different control information, and their order is not limited.
[0089] Those skilled in the art can understand that the words "first", "second", etc. do not limit the quantity and execution order, and the words "first", "second", etc. do not necessarily limit the differences.
[0090] It should also be understood that the term "and / or" used in the present description and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
[0091] In the existing technology, mutual calls between Solidity and other general-purpose programming languages (such as Go or Rust) provide many advantages. First, developers can take advantage of the advantages of different languages to perform complex logic processing and pass the results to the Solidity contract to make state changes on the blockchain. General-purpose languages usually perform better in terms of performance and can handle computationally intensive tasks, thereby reducing the burden on the blockchain and improving overall efficiency.
[0092] Compared with the mutual calls between Solidity and general programming languages, the mutual calls between Solidity and Move (i.e. non-Solidity) also show obvious advantages in terms of security and performance. Move emphasizes resource management and security in its design, aiming to reduce common security vulnerabilities, while Solidity, as the cornerstone of the Ethereum ecosystem, has a more mature application foundation. The combination of the two can not only take advantage of the security features of Move, but also maintain the wide application and support of Solidity, thereby promoting the expansion of cross-chain smart contract functions. This complementarity provides new possibilities for the development of blockchain technology.
[0093] In addition, languages like Rust have stricter memory safety features that can effectively reduce the risk of vulnerabilities. Combining these security features with Solidity's contract functions can improve the security of the entire system. Finally, general programming languages have a wider developer base and resources, making it easier for project teams to find suitable technical support and talent. This multi-language interoperability provides a more flexible solution for the development and maintenance of blockchain applications.
[0094] It can be seen that if Solidity and other smart contract languages can be interoperable, developers only need to implement the matching entry logic in other languages to complete the deployment. This will significantly reduce the migration cost of the project, improve development efficiency, and promote mutual compatibility and cooperation between different blockchain platforms. This interoperability provides new opportunities for the widespread application of smart contracts. In addition, Ethereum contracts can obtain language features that Solidity does not have by calling functions of other smart contract languages, further improving the efficiency of contract execution, breaking the barriers between smart contract programming languages, and promoting the innovation and development of blockchain technology.
[0095] Based on this, the present embodiment provides a method for mutual calling of multiple smart contracts, and the method based on the present embodiment can realize mutual calling between smart contracts using different contract languages. In specific application, the present embodiment first generates an initial cross-contract call statement based on the grammatical structure of the predefined cross-contract call statement, wherein the initial cross-contract call statement is included in the first smart contract, and then constructs the compilation rules of the first smart contract according to the grammatical structure of the predefined cross-contract call statement. Then, the cross-contract call function of the initial cross-contract call statement is obtained based on the compilation rule of the first smart contract, and the second smart contract is called through the cross-contract call function corresponding to the initial cross-contract call statement. In addition, the present invention also obtains a second smart contract with a cross-language call statement, and calls the first smart contract through the cross-language call statement. The first smart contract and the second smart contract in the present invention use different contract languages. Therefore, the method based on the present invention can realize mutual calling between smart contracts in different contract languages, and enhance the interoperability between different contract languages.
[0096] The method for calling multiple smart contracts in this embodiment can be applied to terminals, including smart product terminals such as computers, smart TVs, and mobile phones. Figure 1 As shown in , the method for calling multiple smart contracts to each other in this embodiment includes the following steps:
[0097] Step S100: Generate an initial cross-contract call statement based on a predefined grammatical structure of a cross-contract call statement, wherein the initial cross-contract call statement is included in the first smart contract.
[0098] In order to enable smart contracts in different contract languages to call each other, Figure 2 As shown, this embodiment first predefines the grammatical structure of the cross-contract call statement. The grammatical structure of the cross-contract call statement predefines in this embodiment includes: grammatical parameters, grammatical parameter types and grammatical logic, wherein the grammatical parameters include: keywords, the second smart contract name, the second smart contract function name, the first parameter list and the return value, the first parameter list is used to reflect the parameters required to execute the second smart contract, the grammatical parameter type includes the second smart contract name type, the second smart contract function name type, the parameter type of the first parameter list and the return value type, the parameter type of the first parameter list includes basic data types, structures and arrays, the parameter type of the first parameter list is the same as the return value type, and the grammatical logic is that the keywords, the second smart contract name, the second smart contract function name, the first parameter list and the return value are arranged in order from front to back.
[0099] Taking the Solidity contract as an example, the first smart contract in this embodiment is a non-Solidity contract, and the second smart contract is a Solidity contract. Therefore, the first smart contract and the second smart contract use different contract languages. In order to enable the non-Solidity contract (i.e., the first smart contract) to call the Solidity contract (the second smart contract), when pre-defining the grammatical structure of the cross-contract call statement, this embodiment can be based on the contract language of the Solidity contract, and add the keywords required by the Solidity contract function (Solidity Call) from the smart contract syntax level, so that developers can explicitly declare the call to the Solidity contract function (Solidity Call) operation in the smart contract. The grammatical structure of the contract call statement pre-defined in this embodiment is:
[0100] sol<Second smart contract name>.<Second smart contract function name>(first parameter list<parameter 1>,<parameter 2>…) =><return value>;
[0101] Among them, sol is a keyword used to identify that this is a Solidity contract call statement, which corresponds to a Solidity contract call operation; the name of the second smart contract is the name of the Solidity contract being called. The name of the second smart contract function is the function name of the Solidity contract being called. Parameters 1, 2, etc. in the first parameter list are the execution parameters required to call the Solidity contract, and the parameters are separated by commas. In this embodiment, each parameter has a clear data type so that it can be correctly parsed during execution. The syntax parameter type of this embodiment includes basic data types, wherein the basic data types include: unsigned integer (uint), Boolean value (bool), string (string), array (array), etc. In addition, the syntax parameter type of this embodiment can also use a structure (struct), wherein the definition of the structure needs to be separately declared in the first smart contract and the second smart contract. The return value is the result returned after the Solidity contract function (Solidity Call) is executed, and the result is converted into the data structure of the first smart contract.
[0102] When the grammatical structure of the contract call statement is defined, this embodiment can generate an initial cross-contract call statement based on the grammatical structure. In practical applications, this embodiment can write a first smart contract with the initial cross-contract call statement based on the grammatical structure of the contract call statement, such as Figure 3As shown in , the first smart contract written is a Move smart contract with a SolidityCall statement (i.e., the initial cross-contract call statement), i.e., a non-Solidity contract. The second smart contract is a Solidity contract. When the first smart contract calls the second smart contract, it can call the second smart contract by calling the initial cross-contract call statement, i.e., calling Figure 3 The g(uint64) function in contractB in the Solidity contract.
[0103] Step S200: Construct the compilation rules of the first smart contract according to the grammatical structure of the predefined cross-contract call statement.
[0104] In order to enable the first smart contract to call the second smart contract, this embodiment needs to construct the compilation rules of the contract compiler of the first smart contract based on the predefined grammatical structure of the cross-contract call statement, so that the first smart contract can identify and process the initial cross-contract call statement, thereby realizing the call to the second smart contract. To this end, this embodiment needs to modify the contract editor of the first smart contract, and these modifications are mainly focused on the lexical analysis and grammatical analysis of the contract compiler to ensure that the contract compiler can correctly identify and process the initial cross-contract call statement.
[0105] Specifically, this embodiment can construct lexical analysis rules and grammatical analysis rules according to the grammatical structure of the predefined cross-contract call statement. Then, based on the lexical analysis rules and the grammatical analysis rules, the compilation rules of the first smart contract are obtained. Figure 2As shown, in order to enable the first smart contract to support Solidity Call syntax, this embodiment can obtain keywords for predefined cross-contract call statements, such as "sol", and add the keyword "sol" for predefined cross-contract call statements to the keyword table in the contract compiler of the first smart contract, so that the contract compiler can identify statements using the keyword. Therefore, this embodiment can identify the initial cross-contract call statement based on the keywords of the predefined cross-contract call statement in the keyword table; if it is determined that the initial cross-contract call statement includes keywords for predefined cross-contract call statements, other syntax parameters other than keywords can be added to the syntax parameters of the initial cross-contract call statement to obtain the extended tag information of the initial cross-contract call statement. In actual application, this embodiment can specifically add new tags to the second smart contract name, the second smart contract function name, the first parameter list and the return value in the initial cross-contract call statement, and the data formed after adding new tags to these fields is the extended tag information. The contract compiler of the first smart contract can correctly identify and process these new extended tag information, and classify them into corresponding grammatical structures, so as to perform grammatical analysis on the initial cross-contract call statement in subsequent steps.
[0106] When constructing the syntax analysis rules of the initial cross-contract call statement, since this embodiment adds marks to the syntax parameters other than the keywords in the syntax parameters of the initial cross-contract call statement after identifying that the initial cross-contract call statement includes the keywords of the pre-defined cross-contract call statement, and obtains the extended mark information, this embodiment can parse the syntax parameters of the initial cross-contract call statement according to the extended mark information and the keywords in the keyword table added to the contract compiler of the first smart contract. Then, the integrity of the parsed syntax parameters of the initial cross-contract call statement is verified based on the syntax parameters of the pre-defined cross-contract call statement. Specifically, the syntax parameters of the pre-defined cross-contract call statement and the syntax parameters of the initial cross-contract call statement can be matched to verify whether the initial cross-contract call statement includes all the fields in the syntax parameters of the pre-defined cross-contract call statement, that is, verify whether it includes keywords, the name of the second smart contract, the name of the second smart contract function, the first parameter list, and the return value. Taking the initial cross-contract call statement as a Solidity Call statement as an example, this embodiment can continue to determine whether the fields in the Solidity Call statement conform to the pre-defined grammatical structure of the Solidity Call statement after determining that the Solidity Call statement contains the above-mentioned newly added keyword "sol", that is, whether it completely contains the target Solidity contract name, the target Solidity function name, the parameter list and the return value of the target Solidity contract.
[0107] Furthermore, if the syntax parameters of the initial cross-contract call statement are verified to be complete, this embodiment can construct an abstract syntax tree of the initial cross-contract call statement according to the syntax structure of the initial cross-contract call statement. Specifically, this embodiment can use the keywords in the initial cross-contract call statement as the root node, and use the second smart contract name, the second smart contract function name, the first parameter list and the return value in the initial cross-contract call statement as leaf nodes to construct an abstract syntax tree, that is, the second smart contract name, the second smart contract function name, the first parameter list and the return value are respectively used as leaf nodes of the keywords. This embodiment constructs the syntax analysis rules of the initial cross-contract call statement by converting the initial cross-contract call statement into a tree node on the abstract syntax tree, which is convenient for use in subsequent compilation and execution stages.
[0108] Step S300: Obtain a cross-contract call function of the initial cross-contract call statement based on the compilation rule of the first smart contract.
[0109] After obtaining the compilation rules of the first smart contract, this embodiment can perform lexical analysis and grammatical analysis on the initial cross-contract call statement in accordance with the compilation rules, thereby converting the initial cross-contract call statement into a cross-contract call function. In specific applications, this embodiment compiles the initial cross-contract call statement based on the compilation rules of the first smart contract. When the initial cross-contract call statement is compiled, the cross-contract call function of the initial cross-contract call statement is obtained according to the initial cross-contract call statement.
[0110] Specifically, when compiling the initial cross-contract call statement, the present embodiment can analyze the initial cross-contract call statement based on the constructed lexical analysis rules to obtain a lexical analysis result. Then, the initial cross-contract call statement is analyzed based on the constructed syntax analysis rules to obtain a syntax analysis result. Finally, according to the syntax analysis result, the initial cross-contract call statement is compiled. Among them, the lexical analysis is to define a cross-contract call statement (such as Solidity call) in the contract compiler, so that the contract compiler can recognize the statement and correctly parse the statement; secondly, the syntax analysis verifies the correctness of the parsed statement to verify whether the statement is a correct cross-contract call statement, so that the compiler can successfully compile the statement.
[0111] This embodiment can match the keywords in the initial cross-contract call statement with the keywords of the cross-contract call statement predefined in the keyword table of the constructed lexical rules to determine whether the initial cross-contract call statement includes the keywords of the predefined cross-contract call statement. Taking the above-mentioned first smart contract as a non-Solidity contract, the second smart contract as a Solidity contract, and the initial cross-contract call statement as a Solidity Call statement as an example, if the match is successful, it means that the keyword "sol" is included in the initial cross-contract call statement at this time. Therefore, this embodiment can add tags to the other grammatical parameters of the grammatical parameters of the initial cross-contract call statement except for the keywords according to the constructed lexical rules to obtain the extended tag information of the initial cross-contract call statement, that is, add new tags to the second smart contract name, the second smart contract function name, the first parameter list and the return value in the initial cross-contract call statement, respectively. The data formed after adding new tags to these fields is the extended tag information, so as to perform grammatical analysis on the initial cross-contract call statement in subsequent steps.
[0112] Further, after determining that the initial cross-contract call statement includes the keywords of the pre-defined cross-contract call statement, this embodiment can parse the grammatical parameters of the initial cross-contract call statement according to the grammatical analysis rules constructed above, and verify the integrity of the grammatical parameters. Specifically, the grammatical parameters of the pre-defined cross-contract call statement and the grammatical parameters of the initial cross-contract call statement can be matched to verify whether the initial cross-contract call statement includes all the fields in the grammatical parameters of the pre-defined cross-contract call statement, that is, verify whether the keywords, the second smart contract name, the second smart contract function name, the first parameter list and the return value are included. Taking the initial cross-contract call statement as a Solidity Call statement as an example, this embodiment can determine that the Solidity Call statement contains the above-mentioned newly added keyword "sol", and then obtain other grammatical parameters in the Solidity Call statement through the extension tag, and continue to judge whether the other grammatical parameters in the Solidity Call statement meet the grammatical parameters of the pre-defined Solidity Call statement, that is, whether the target Solidity contract name, the target Solidity function name, the parameter list and the return value of the target Solidity contract are completely included.
[0113] Furthermore, if the syntax parameters of the initial cross-contract call statement are verified to be complete, this embodiment can construct an abstract syntax tree of the initial cross-contract call statement according to the syntax structure of the initial cross-contract call statement. Specifically, this embodiment can use the keywords in the initial cross-contract call statement as the root node, and use the second smart contract name, the second smart contract function name, the first parameter list and the return value in the initial cross-contract call statement as leaf nodes to construct an abstract syntax tree, that is, the second smart contract name, the second smart contract function name, the first parameter list and the return value are the leaf nodes of the keywords. In addition, when constructing the abstract syntax tree, this embodiment will also construct it with the syntax parameter type and syntax parameter logic of the initial cross-contract call statement to convert the initial cross-contract call statement into a tree node on the abstract syntax tree, and construct the syntax analysis rules of the initial cross-contract call statement, which is convenient for use in subsequent compilation and execution stages.
[0114] When compiling the initial cross-contract call statement, the source code of the second smart contract must be obtained first, that is, the contract compiler of the first smart contract needs to obtain the storage path of the second smart contract from the contract introduction statement of the smart contract, and then the contract compiler of the first smart contract loads the source code of the second smart contract into the memory according to the storage path to compile the source code and compilation parameters of the second smart contract to obtain the compilation result. The source code includes the name of the second smart contract, all function names used to compile the second smart contract, and function information corresponding to all functions used to compile the second smart contract.
[0115] In one implementation, this embodiment combines the source code and compilation parameters of the second smart contract to obtain a target file. The compilation parameters include output options and optimization options, and the target file is a file in JSON format. Next, this embodiment compiles the target file through the second smart contract compiler (SOLC) to obtain a compilation result, and the compilation result includes the bytecode of the second smart contract (i.e., the bytecode of the target Solidity contract), the compiled contract name of the second smart contract, and the compiled function information of the second smart contract, wherein the compiled function information includes the function hash abbreviation (the hash abbreviation of all functions used by the compiled second smart contract), the compiled function information (i.e., the function information corresponding to all functions used by the compiled second smart contract), and the compiled function information includes: function name, function identifier, parameters (including parameter type) and return value type.
[0116] Further, after obtaining the above-mentioned compilation result, this embodiment can also parse the compilation result through a JSON parser to determine whether the second smart contract (i.e., the target Solidity contract) is compiled successfully, that is, check whether the compilation result is compiled successfully. This embodiment can determine whether the second smart contract is compiled successfully by checking whether there is an "errors" field in the compilation result. If not, it is determined that the second smart contract is compiled successfully. If there is an "errors" field in the compilation result, it is determined that the compilation of the second smart contract fails, and an error is directly returned. Then, if the second smart contract is compiled successfully, this embodiment can construct the second smart contract structure according to the compilation function information of the second smart contract and the name of the second smart contract, and store the second smart contract structure. Then, the grammatical parameters of the initial cross-contract call statement are checked according to the second smart contract structure to ensure that the grammatical parameters of the initial cross-contract call statement are all in the structure of the second smart contract, and then the parameter type of the first parameter list of the pre-defined cross-contract call statement is obtained to check the grammatical parameter type of the initial cross-language call statement. Finally, the initial cross-contract call statement is translated into a cross-contract call function of the initial cross-contract call statement based on the grammatical structure of the pre-defined cross-contract call statement.
[0117] In this embodiment, since there are intermodulation functions between the first smart contract and the second smart contract, the parameter data types supported by these intermodulation functions constitute an intermodulation parameter type list, wherein the intermodulation parameter list reflects the correspondence between the first smart contract and the second smart contract and the intermodulation function type, and is allowed to be a one-to-one correspondence between the data types of the parameters of the predefined cross-contract call statement. In this embodiment, the intermodulation parameter type list can be saved in the contract compiler to declare the acceptable data types for the language calls of both parties. Further, since the data types of the smart languages of the first smart contract and the second smart contract are different, it is necessary to determine which data types can support the call of the cross-contract call statement, and these data types constitute the parameter types of the first parameter list of the cross-contract call statement, wherein the parameter types of the first parameter list reflect the correspondence between the data types allowed as parameters of the predefined cross-contract call statement in the first smart contract and the second smart contract; the intermodulation parameter list contains all grammatical parameter types in the predefined cross-contract call statement. Specifically, this embodiment can obtain the grammatical parameter type of the initial cross-contract call statement by traversing the abstract syntax tree of the initial cross-contract call statement. This embodiment can also check the grammatical parameter types of the initial cross-contract call statement based on the intermodulation parameter list to ensure that the grammatical parameter types of the initial cross-contract call statement are all in the parameter types of the first parameter list, thereby realizing the validity check of the initial cross-contract call statement. After the initial cross-contract call statement is compiled, this embodiment can translate the initial cross-contract call statement into a cross-contract call function of the initial cross-contract call statement based on the grammatical structure of the pre-defined cross-contract call statement.
[0118] In addition, since there are intermodulation functions between the first smart contract (non-Solidity contract) and the second smart contract (Solidity contract), this embodiment can also form an intermodulation parameter list with the parameter types supporting these intermodulation functions. Similarly, in the intermodulation function parameter list, the data types allowed as parameters of the intermodulation function in the first smart contract (non-Solidity contract) and the second smart contract (Solidity contract) correspond one to one.
[0119] Step S400: Call the second smart contract through the cross-contract call function corresponding to the initial cross-contract call statement.
[0120] Specifically, this embodiment first generates the contract deployment statement of the second smart contract based on the bytecode of the second smart contract (i.e., the bytecode of the target Solidity contract). Then, the function information corresponding to the function name of the second smart contract is selected from all the function information used by the second smart contract, and then a key-value pair array is generated according to the function information of the second smart contract and the first parameter list in the initial cross-contract call statement, and the key-value pair array is encoded to obtain a parameter byte array. In specific application, this embodiment needs to integrate the EVM (Ethereum Virtual Machine, Ethereum Virtual Machine, a code running environment built on the Ethereum blockchain) of the underlying programming language of the first smart contract into the execution environment of the first smart contract, and overload the callback function in EVMHost (Ethereum Virtual Machine Host). In this embodiment, when the first smart contract calls the initial cross-contract call statement, the callback function of EVMHost does not need special processing, but only needs to implement the required functions. In this embodiment, the ABI encoder (abi.encode) and the ABI decoder (abi.decode) can be integrated into the execution engine of the first smart contract to realize the conversion of the parameters in the initial cross-contract call statement of the first smart contract into a data format recognizable by EVM. ABI encoder: Encode the data value in the form of a string into a parameter byte array expressed by EVM data according to the arrangement of the parameter types of the first parameter list in the initial cross-contract call statement. ABI decoder: Convert the parameter byte array output by EVM into a parameter string according to the arrangement of the parameter types of the first parameter list in the initial cross-contract call statement. Therefore, in this embodiment, the function information corresponding to the name of the second smart contract function and the parameter string in the initial cross-contract call statement can be combined into a key-value pair array, wherein the parameter type of the function of the second smart contract is the key of the key-value pair, and the parameter string in the initial cross-contract call statement is the value of the key-value pair, and the key-value pair array is transmitted to the ABI encoder, the key-value pair array is encoded to obtain the encoded byte array, and then the encoded byte array is spliced to the hash abbreviation of the second smart contract function to obtain the data field of the first message information.
[0121] Further, this embodiment executes the contract deployment statement, and constructs the first contract transaction information based on the encoded byte array and the compiled function information of the second smart contract of the initial cross-contract call statement. Specifically, this embodiment can concatenate the encoded byte array and the hash abbreviation of the second smart contract function as the data field (message data) of the first message information of the deployment contract transaction information of the Ethereum transaction to construct the first contract transaction information of the Ethereum transaction, wherein the first contract transaction information is a contract transaction in which the first smart contract calls the second smart contract, and the first contract transaction information is passed to the Execute function of the EVM to call the Execute function of the EVM to execute the first contract transaction information, and obtain the first contract transaction information execution result (Execute Result), wherein the first contract transaction information execution result includes a return value byte array. Then, the execution result of the first contract transaction information and the compiled function information of the second smart contract are decoded to obtain a decoded string. Specifically, first check whether the first contract transaction information is executed successfully. If the first contract transaction information is executed successfully, the return value byte array in the execution result of the first contract transaction information and the return value type in the compiled function information of the second smart contract can be input into the ABI decoder for decoding to obtain a decoded string. Next, the decoded string is converted into the target data format of the first smart contract, and the cross-contract call function return value of the initial cross-contract call statement is updated according to the target data format to complete the first smart contract calling the second smart contract through the updated cross-contract call function.
[0122] Combination Figure 2 and Figure 3 As shown, this embodiment takes the first smart contract as a non-Solidity contract, the second smart contract as a Solidity contract, and the initial cross-contract call statement as a Solidity Call statement as an example, and provides an example of a non-Solidity contract calling a Solidity contract using a Solidity Call statement, as follows:
[0123] Step 1. Write a non-Solidity contract with a Solidity Call statement
[0124] The contract developer writes a Move smart contract (non-Solidity contract) with a Solidity Call statement off-chain to implement a cross-language call to the g(uint64) function in the Solidity contract contractB.
[0125] Step 2: Compile a Move smart contract (not a Solidity contract) with a Solidity Call statement, including the following steps:
[0126] (1) The contract developer submits the written Move smart contract to the Move compiler (not the Solidity contract compiler) for compilation;
[0127] (2) The Move compiler performs lexical analysis on the Move smart contract to check whether there is the "sol" keyword, extended tag information, etc.
[0128] (3) The Move compiler performs syntax analysis on the Move smart contract to check whether there are errors that do not conform to the syntax structure of the SolidityCall statement;
[0129] (4) The Move compiler performs semantic analysis on the Move smart contract, finds the Solidity contract to be introduced in the memory location (0x1) of the Move smart contract, calls the Move compiler for compilation, and then obtains the target file in the Solidity contract source code (i.e., a file in JSON format). The structure of the Solidity contract information is constructed using the compilation result of the Move compiler, and the members of the structure are used to check the syntax parameters in the Solidity call statement to ensure that the syntax parameters in the Solidity call statement are in the structure of the Solidity contract, for example, whether the data type passed in by ContractA::f calling ContractB::g can be converted into the data type in the Solidity contract language.
[0130] (5) The Move compiler generates Move bytecode;
[0131] (6) The contract developer deploys the Move smart contract on the blockchain.
[0132] Step 3: The user calls the Solidity Call statement, which includes the following steps:
[0133] (1) The Move execution engine (not the Solidity contract execution engine) will pass the target function name and parameters called by the target Solidity contract to the intermediate connection module;
[0134] (2) The intermediate connection module finds the function information and function hash abbreviation (b3e8e519) of the compiled target Solidity contract source code according to the target function name ContractB.g;
[0135] (3) The intermediate connection module uses the parameter value and parameter data type of the Solidity call statement to construct a JSON format string {"uint":10};
[0136] (4) Convert the JSON format string into a byte array using the ABI encoder
[0137] (000000000000000000000000000000000000000000000000000000000000000a);
[0138] (5) Append the byte array to the function hash abbreviation to get:
[0139] b3e8e519000000000000000000000000000000000000000000000000000000000000000a;
[0140] (6) The intermediate link constructs the contract message of the Ethereum transaction and passes the contract message to the EVM's Execute function to call the EVM's Execute function to execute the Ethereum transaction;
[0141] (7) Call the EVM's Execute function to execute the Ethereum transaction, and read the Output field after obtaining the Execute Result:
[0142] 000000000000000000000000000000000000000000000000000000000000000b;
[0143] (8) Pass the byte array of the Output field and the return value type (uint) provided in the compiled target Solidity contract source code to the ABI decoder to obtain "11";
[0144] (9) The intermediate connection module converts “11” into the Move smart contract u64 type and assigns it to variable a of contractA.
[0145] It can be seen that this embodiment is a call of a Solidity contract by a non-Solidity contract, which significantly reduces the migration cost of the project, improves development efficiency, and promotes mutual compatibility and cooperation between different blockchain platforms.
[0146] Step S500: Obtain a second smart contract with a cross-language call statement.
[0147] In order to implement the call of the second smart contract to the first smart contract, this embodiment obtains the second smart contract with a cross-language call statement to implement the call of the first smart contract through the cross-language call statement. Figure 4As shown, this embodiment constructs a cross-language call statement according to the original contract call function of the second smart contract, the cross-language call statement includes a special address and a contract call function, the contract call function includes an encoded byte array, wherein the encoded byte array is obtained by encoding the first smart contract information, and the cross-language call statement is specifically as follows:
[0148] address(<special address>).call(abi.encode(first smart contract information));
[0149] Among them, <special address> is the address information of the recipient with a special identifier added, and the special identifier indicates that the statement is a cross-language call statement, which can realize cross-language call; the first smart contract information includes the first smart contract name, the first smart contract function name and the second parameter list, and the second parameter list contains the parameters required to call the first smart contract.
[0150] In this embodiment, a special address (addr) is set in the original contract call statement (address.call) of the second smart contract to obtain a cross-language call statement. Since the input parameter of the contract call statement is a byte array, this embodiment needs to convert the first smart contract name, the first smart contract function and the second parameter list into a byte array expression through the ABI encoder (abi.encode) built into the second smart contract. Specifically, the first smart contract in this embodiment is a non-Solidity contract, and the second smart contract is a Solidity contract.
[0151] Furthermore, this embodiment obtains the second smart contract based on the cross-language call statement. Figure 5 As shown, the contract developer can write a second smart contract with cross-language call statements off-chain, namely the Solidity contract.
[0152] Step S600: calling the first smart contract through the cross-language calling statement.
[0153] In actual application, the developer needs to integrate the EVM implementation of the underlying programming language of the second smart contract into the execution environment of the second smart contract, and overload the contract call function (i.e., call function) in EVMHost. In this embodiment, the cross-language call statement of the second smart contract only calls the contract call function of EVMHost, so the contract call function needs to be specially processed. In this embodiment, the first smart contract information (the first smart contract name, the first smart contract function name and the second parameter list) is firstly encoded by the ABI encoder (abi.encode) built into the second smart contract to obtain an encoded byte array, and then the encoded byte array is used as the contract call function parameter of the cross-language call statement; then, the message information is constructed according to the encoded byte array and the address information, and the message information includes a data field and an address field, wherein the encoded byte array is used as the data field (data field) of the message information, and the address information of the recipient is used as the address field of the message information; finally, in this embodiment, the EVMHost instance includes the first smart contract execution engine and the intermediate connection module of the EVM, and the address information of the recipient is obtained according to the address field in the message information, and it is determined whether the address information of the recipient has a <special address> identifier. If so, the cross-language call statement is executed. When the EVM executes the cross-language call statement, the contract call function of EVMHost is called through the data field of the message information, and the data field of the constructed message information is passed to the intermediate connection module.
[0154] Next, after obtaining the data field of the message information, the intermediate connection module in this embodiment parses the data field of the message information through the ABI decoder to obtain the first smart contract name and the first smart contract function name; the intermediate connection module calls the first smart contract execution engine to find the first smart contract function signature. If the first smart contract function signature is not found, or the first smart contract function signature is found but the function cannot be called, an error prompt is output. If the first smart contract function signature is found, the cross-language call statement and the message information in the first smart contract function signature are obtained, and the obtained cross-language call statement and the message information are decoded to obtain the execution engine parameters of the first smart contract. In specific applications, the parameter type of the second parameter list in the first smart contract function signature and the data field of the message information are obtained and transmitted to the ABI decoder for decoding, and the decoding result in the form of a string is obtained, and the decoding result is used as the input parameter of the first smart contract. Next, the input parameter of the first smart contract is converted from the string form to the function parameter form of the execution engine of the first smart contract.
[0155] Furthermore, this embodiment constructs the second contract transaction information through the execution engine parameter and the name of the first smart contract function, wherein the second contract transaction information is the contract transaction of the second smart contract calling the first smart contract, and the second contract transaction information is transmitted to the execution engine of the first smart contract to call the first smart contract function, and the second contract transaction information execution information is obtained, and the execution information includes the execution result and the return value. If the execution of the second contract transaction information fails, an error prompt message is returned. If the execution of the second contract transaction information is successful, the execution information is converted into a string form, and the execution information is converted into a byte array through the ABI encoder. Finally, the byte array is assigned to the EVM Result structure instance to construct EVM Result (execution result of the Ethereum virtual machine), and EVM Result is returned to the second smart contract. At this point, the second smart contract completes the call to the first smart contract through a cross-language call statement.
[0156] Combination Figure 4 and Figure 5 As shown, this embodiment takes the first smart contract as a non-Solidity contract, the second smart contract as a Solidity contract, and the contract call statement as a cross-contract call statement as an example, and provides an example of a Solidity contract calling a non-Solidity contract using a cross-contract call statement, as follows:
[0157] Step 1: User compiles and deploys Solidity contract to the chain
[0158] The callee compiles the Solidity contract (Contract A) normally and deploys the Solidity contract to the chain.
[0159] Step 2: The user calls a non-Solidity contract through a cross-language call statement
[0160] (1) The ABI encoder (abi.encode) built into the Solidity contract will encode "ContractB.f" and "10" into a byte array. The EVM uses the byte array as the data of the Ethereum transaction message to construct the message; the message is the parameter of the EVMHost contract call function: (0 ... 00000400000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000 0000000000000000000000000000000000b436f6e7472616374422e66000000000000000000000000000000000000000000);
[0161] (2) When EVM executes the contract call statement, it triggers the EVMHost reload callback function;
[0162] (3) The callback function determines that this is a special address for cross-language call statements based on the receiver address (001) in the contract call statement. The contract call statement is a cross-contract call statement, and then passes the message data to the intermediate connection module connected to the Move smart contract execution engine for further function calls.
[0163] (4) After the intermediate connection module receives the message data, since the only thing that is certain about the data is that the first element is a string of the contract name and function name, the intermediate connection module will construct a JSON Object {"input": <data>”,"layout”:"string”}, then send the JSON Object to the ABI decoder for parsing to get the non-Solidity contract name (ContractB) and the non-Solidity function name (f);
[0164] (5) The intermediate connection module calls the execution engine to obtain the non-Solidity contract function signature f(u64) based on the non-Solidity contract name (ContractB) and the non-Solidity function name (f);
[0165] (6) The intermediate connection module uses the function signature of the non-Solidity contract to construct another JSON object {"input":" <data>","layout":"string u64"}, and pass it to the ABI decoder to get the parameter "10" in string form;
[0166] (7) The intermediate connection module converts the string parameter into the data type stored internally by the Move execution engine, and adds the non-Solidity contract name (ContractB) and the non-Solidity function name (f) to form a contract transaction. The Move smart contract execution engine executes the contract transaction and obtains the return value and execution result (execution success or failure).
[0167] (8) Convert the return value of the execution into a string "11";
[0168] (9) Use the string return value and return value type (the middle connection module needs to obtain the data type according to the conversion list) to construct a JSON object {"uint64":"11"}, and call the ABI encoder to convert the JSON object into a byte array 000000000000000000000000000000000000000000000000000000000000000000000000000b;
[0169] (10) Construct EVM Result: Use the execution result and the byte array obtained in the previous step as the EVM Result field parameters to construct EVM Result, i.e., the transaction execution result, and return EVM Result to EVMHost.
[0170] It can be seen that this embodiment realizes the mutual calling between non-Solidity contracts and Solidity contracts, significantly reduces the migration cost of the project, improves development efficiency, and promotes mutual compatibility and cooperation between different blockchain platforms.
[0171] Based on the above method embodiment, the present invention also provides a method for calling multiple smart contracts to each other, such as Figure 6 As shown, the system is applied to the mutual call between the first smart contract and the second smart contract of different contract languages, including: an initial cross-contract call statement generation module 10, a compilation rule construction module 20, a contract call function determination module 30, a second smart contract call module 40, a smart contract acquisition module 50, and a first smart contract call module 60. Specifically, the initial cross-contract call statement generation module 10 is used to generate an initial cross-contract call statement based on a pre-defined grammatical structure of a cross-contract call statement, wherein the initial cross-contract call statement is included in the first smart contract. The compilation rule construction module 20 is used to construct the compilation rules of the first smart contract according to the grammatical structure of the pre-defined cross-contract call statement. The cross-contract call function determination module 30 is used to obtain the cross-contract call function of the initial cross-contract call statement based on the compilation rules of the first smart contract. The second smart contract call module 40 is used to call the second smart contract through the cross-contract call function corresponding to the initial cross-contract call statement. The smart contract acquisition module 50 is used to obtain the second smart contract with a cross-language call statement. The first smart contract calling module 60 is used to call the first smart contract through the cross-language calling statement.
[0172] The working principles of each module in the system of this embodiment are the same as the principles of each step in the above method embodiment, and will not be repeated here.
[0173] Each module in the above system can be implemented in whole or in part by software, hardware and their combination. Each module can be embedded in or independent of the processor in the terminal in the form of hardware, or can be stored in the memory in the terminal in the form of software, so that the processor can call and execute the operations corresponding to each module above.
[0174] Based on the above embodiment, the present invention further provides a terminal, the principle block diagram of the terminal can be as follows: Figure 7 The terminal may include one or more processors 100 ( Figure 7 Only one is shown in the figure), a memory 101 and a computer program 102 stored in the memory 101 and executable on one or more processors 100, without limitation herein.
[0175] In one embodiment, the processor 100 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. When the processor executes a program for multiple smart contracts to call each other, the steps of the method for multiple smart contracts to call each other in the above embodiment are implemented.
[0176] In one embodiment, the memory 101 may be an internal storage unit of an electronic device, such as a hard disk or memory of the electronic device. The memory 101 may also be an external storage device of the electronic device, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device. Further, the memory 101 may also include both an internal storage unit of the electronic device and an external storage device. The memory 101 is used to store computer programs and other programs and data required by the terminal. The memory 101 may also be used to temporarily store data that has been output or is to be output.
[0177] Those skilled in the art will understand that Figure 7 The principle block diagram shown in the figure is only a block diagram of a partial structure related to the scheme of the present invention, and does not constitute a limitation on the terminal to which the scheme of the present invention is applied. The specific terminal may include more or less components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0178] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, operating database or other media used in the embodiments provided by the present invention may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double operational data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0179] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.< / data> < / data>
Claims
1. A method for calling multiple smart contracts mutually, characterized in that: The method is applied to a mutual invocation between a first smart contract and a second smart contract in a different contract language, and the method includes: Generate an initial cross-contract call statement based on a predefined grammatical structure of a cross-contract call statement, wherein the initial cross-contract call statement is included in the first smart contract; Constructing a compilation rule for the first smart contract according to the grammatical structure of the predefined cross-contract call statement; Obtaining a cross-contract call function of the initial cross-contract call statement based on the compilation rule of the first smart contract; Calling the second smart contract through the cross-contract call function corresponding to the initial cross-contract call statement; Get the second smart contract with the cross-language call statement; Calling the first smart contract through the cross-language calling statement; The generating of the initial cross-contract call statement based on the predefined grammatical structure of the cross-contract call statement includes: Predefine the syntax structure of the cross-contract call statement, the syntax structure includes: syntax parameters, syntax parameter types and syntax logic, wherein the syntax parameters include keywords, the second smart contract name, the second smart contract function name, the first parameter list and the return value, the first parameter list is used to reflect the parameters required to execute the second smart contract, the syntax parameter type includes the second smart contract name type, the second smart contract function name type, the parameter type of the first parameter list and the return value type, the parameter type of the first parameter list includes basic data types, structures and arrays, the parameter type of the first parameter list is the same as the return value type, and the syntax logic is that the keywords, the second smart contract name, the second smart contract function name, the first parameter list and the return value are arranged in order from front to back; Generate the initial cross-contract call statement based on the grammatical structure; Generating a compilation rule for the first smart contract according to the grammatical structure of the predefined cross-contract call statement includes: Construct lexical analysis rules and grammatical analysis rules respectively according to the pre-defined grammatical structure of cross-contract call statements; Based on the lexical analysis rule and the grammatical analysis rule, obtaining a compilation rule for the first smart contract; The step of obtaining the cross-contract call function of the initial cross-contract call statement based on the compilation rule of the first smart contract includes: Compile the initial cross-contract call statement based on the compilation rule of the first smart contract; When the initial cross-contract call statement is compiled and passed, the cross-contract call function of the initial cross-contract call statement is obtained according to the initial cross-contract call statement.
2. The method for mutual invocation of multiple smart contracts according to claim 1, characterized in that: Construct lexical analysis rules based on the pre-defined grammatical structure of cross-contract call statements, including: Obtaining keywords for predefined cross-contract call statements, and adding the keywords for predefined cross-contract call statements to a keyword table in a contract compiler of the first smart contract; Add tags to other grammatical parameters of the grammatical parameters of the initial cross-contract call statement except for keywords to obtain extended tag information of the initial cross-contract call statement.
3. The method for mutual invocation of multiple smart contracts according to claim 2, characterized in that: Construct grammatical analysis rules based on the pre-defined grammatical structure of cross-contract call statements, including: Parsing syntax parameters of the initial cross-contract call statement according to the extended tag information and the keywords in the keyword table added to the contract compiler of the first smart contract; Performing integrity verification on the parsed grammatical parameters of the initial cross-contract call statement based on the grammatical parameters of the pre-defined cross-contract call statement; If the syntax parameters of the initial cross-contract call statement are verified to be complete, an abstract syntax tree of the initial cross-contract call statement is constructed according to the syntax structure of the initial cross-contract call statement.
4. The method for mutual invocation of multiple smart contracts according to claim 1, characterized in that: The compiling process of the initial cross-contract call statement based on the compilation rule of the first smart contract includes: Analyze the initial cross-contract call statement based on the constructed lexical analysis rules to obtain a lexical analysis result; Analyze the initial cross-contract call statement based on the constructed syntax analysis rules to obtain a syntax analysis result; According to the syntax analysis result, the initial cross-contract call statement is compiled.
5. The method for mutual invocation of multiple smart contracts according to claim 4, characterized in that: The constructed lexical analysis rule is used to analyze the initial cross-contract call statement to obtain a lexical analysis result, including: Matching the keywords in the initial cross-contract call statement with the keywords of the cross-contract call statement predefined in the keyword table of the constructed lexical rules; If the match is successful, the other grammatical parameters of the initial cross-contract call statement except the keywords are marked according to the constructed lexical rules to obtain the extended tag information of the initial cross-contract call statement.
6. The method for mutual invocation of multiple smart contracts according to claim 5, characterized in that: The constructed grammatical analysis rule is used to analyze the initial cross-contract call statement to obtain a grammatical analysis result, including: Parsing the grammatical parameters of the initial cross-contract call statement according to the constructed grammatical analysis rules, and verifying the integrity of the grammatical parameters; If the syntax parameter verification is complete, the abstract syntax tree of the initial cross-contract call statement is obtained according to the syntax analysis rules.
7. The method for mutual invocation of multiple smart contracts according to claim 4, characterized in that: The compiling the initial cross-contract call statement according to the grammatical analysis result includes: Obtain the source code of the second smart contract; Compile the source code and compilation parameters of the second smart contract to obtain a compilation result.
8. The method for mutual invocation of multiple smart contracts according to claim 7, characterized in that: The compiling the source code and compilation parameters of the second smart contract to obtain a compilation result includes: Combining the source code and compilation parameters of the second smart contract to obtain a target file; The target file is compiled to obtain a compilation result, where the compilation result includes the bytecode of the second smart contract, the compiled contract name of the second smart contract, and the compiled function information of the second smart contract.
9. The method for mutual invocation of multiple smart contracts according to claim 8, characterized in that: When the initial cross-contract call statement is compiled, a cross-contract call function of the initial cross-contract call statement is obtained according to the initial cross-contract call statement, including: Construct a second smart contract structure according to the compilation function information of the second smart contract and the name of the second smart contract; Checking the syntax parameters of the initial cross-contract call statement according to the second smart contract structure; Obtaining the parameter type of the first parameter list of the predefined cross-contract call statement and checking the syntax parameter type of the initial cross-contract call statement; The initial cross-contract call statement is translated into a cross-contract call function of the initial cross-contract call statement based on the grammatical structure of the pre-defined cross-contract call statement.
10. The method for mutual invocation of multiple smart contracts according to claim 8, characterized in that: The calling the second smart contract through the cross-contract calling function corresponding to the initial cross-contract calling statement includes: Generate a contract deployment statement of the second smart contract based on the bytecode of the second smart contract; Selecting function information corresponding to the function name of the second smart contract from all function information used by the second smart contract; Generate a key-value pair array according to the function information corresponding to the second smart contract function name and the first parameter list in the initial cross-contract call statement, and encode the key-value pair array to obtain an encoded byte array; Execute the contract deployment statement, and construct first contract transaction information based on the encoded byte array and the compiled function information of the second smart contract; Decoding the execution result of the first contract transaction information and the compiled function information of the second smart contract to obtain a decoded string; The decoded string is converted into the target data format of the first smart contract and the cross-contract call function return value of the initial cross-contract call statement is updated.
11. The method for mutual invocation of multiple smart contracts according to claim 1, characterized in that: The obtaining of the second smart contract with the cross-language calling statement includes: Constructing a cross-language call statement according to the contract call function of the second smart contract, wherein the cross-language call statement includes a special address and a contract call function, and the contract call function includes an encoded byte array, wherein the encoded byte array is obtained by encoding the first smart contract information; The second smart contract is obtained based on the cross-language call statement.
12. The method for mutual invocation of multiple smart contracts according to claim 11, characterized in that: The calling the first smart contract through the cross-language calling statement includes: Constructing message information according to the encoded byte array, wherein the message information includes a data field and an address field; Executing the cross-language call statement based on the message information; Parsing the data field of the message information and searching for the first smart contract function signature; Obtain the cross-language call statement and the message information according to the first smart contract function signature; Decoding the obtained cross-language call statement and the message information to obtain execution engine parameters of the first smart contract; Constructing second contract transaction information through the execution engine parameters and the first smart contract function name; The first smart contract is called through the second contract transaction information.
13. A system for multiple smart contracts to call each other, characterized in that: The system is used to implement the steps of the method for mutual invocation of multiple smart contracts as described in any one of claims 1 to 12, and the system is applied to mutual invocation of a first smart contract and a second smart contract in a different contract language, and the system includes: An initial cross-contract call statement generation module, used to generate an initial cross-contract call statement based on a predefined grammatical structure of a cross-contract call statement, wherein the initial cross-contract call statement is included in the first smart contract; A compilation rule construction module, used to construct a compilation rule for the first smart contract according to the grammatical structure of the predefined cross-contract call statement; A cross-contract call function determination module, used to obtain the cross-contract call function of the initial cross-contract call statement based on the compilation rule of the first smart contract; A second smart contract calling module, used to call the second smart contract through the cross-contract calling function corresponding to the initial cross-contract calling statement; A smart contract acquisition module, used to acquire a second smart contract with a cross-language call statement; The first smart contract calling module is used to call the first smart contract through the cross-language calling statement.
14. A terminal, characterized in that: The terminal includes a memory, a processor, and a program for mutual invocation of multiple smart contracts stored in the memory and run on the processor. When the processor executes the program for mutual invocation of multiple smart contracts, the steps of the method for mutual invocation of multiple smart contracts as described in any one of claims 1 to 12 are implemented.
15. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a program for multiple smart contracts to call each other. When the program for multiple smart contracts to call each other is executed by the processor, the steps of the method for multiple smart contracts to call each other as described in any one of claims 1 to 12 are implemented.
Citation Information
Patent Citations
Cross-virtual-machine calling method based on multi-virtual-machine blockchain platform
CN111176791A