A smart contract compilation matching method, device and equipment and a storage medium

By automating the matching and processing of smart contract and compiler data within the Ethereum system, the high compilation cost of Ethereum smart contracts is solved, achieving an efficient compilation process.

CN114201176BActive Publication Date: 2025-10-28SUN YAT SEN UNIV
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111538095.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-15
Publication Date
2025-10-28
Estimated Expiration
2041-12-15

AI Technical Summary

Technical Problem

Existing Ethereum smart contract compilation solutions struggle to achieve low-cost and efficient smart contract compilation because they rely solely on manual compiler selection.

Method used

By acquiring smart contract and compiler data from the Ethereum system within a preset acquisition period, performing data preprocessing, matching the target compiler using the contract compiler hash number and version number, and combining compilation optimization flags for automated compilation, the compilation results are generated.

Benefits of technology

It enables efficient compilation of smart contracts at low cost, reduces the cost of manually selecting compilers, and improves compilation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114201176B_ABST
    Figure CN114201176B_ABST
Patent Text Reader

Abstract

This invention discloses a smart contract compilation and matching method, apparatus, device, and storage medium. The method includes: acquiring smart contract data and compiler data from the Ethereum system according to a preset acquisition cycle; performing contract data preprocessing on the smart contract data to obtain preprocessed contract data; performing compiler data preprocessing on the compiler data to obtain multiple preprocessed compiler data; matching the multiple preprocessed compiler data with the preprocessed contract data, and determining a target compiler based on the matching results; and compiling the contract using the target compiler in conjunction with the preprocessed contract data to obtain a compilation result. This method efficiently compiles smart contracts by automatically selecting compilers while maintaining low cost.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of smart contract compilation technology, and in particular to a smart contract compilation and matching method, apparatus, device, and storage medium. Background Technology

[0002] Blockchain is a decentralized ledger technology that plays a significant role in various application scenarios due to its decentralized, privacy-preserving, and tamper-proof characteristics. With technological advancements, representative blockchain platforms such as Ethereum and Hyperledger Fabric have emerged, representing the vigorous development of the blockchain technology field.

[0003] On blockchains like Ethereum, smart contract functionality is achieved by deploying smart contract bytecode. Since Ethereum transaction records are immutable, smart contracts deployed on Ethereum cannot be tampered with, and their application functionality is permanently effective once deployed to the contract.

[0004] Currently, the common approach to compiling Ethereum smart contracts involves manually screening the compiler for a given contract. After obtaining the compiled content, this content needs to be processed. However, there is limited publicly available information about smart contracts on Ethereum. Most contracts only have source code and binary files, and there are numerous smart contracts with many compiler versions. Different compilers can produce different results for the same smart contract, making manual screening and compilation of each contract costly. Summary of the Invention

[0005] This invention provides a smart contract compilation and matching method, apparatus, device, and storage medium, which solves the technical problem that existing Ethereum smart contract compilation schemes, which can only rely on manual selection of compilers, are unable to achieve low-cost and efficient smart contract compilation.

[0006] The first aspect of this invention provides a smart contract compilation and matching method, comprising:

[0007] Retrieve smart contract data and compiler data from the Ethereum system according to a preset acquisition cycle;

[0008] The smart contract data is preprocessed to obtain preprocessed contract data;

[0009] The compiler data is preprocessed to obtain multiple preprocessed compiler data sets;

[0010] The target compiler is determined based on the matching results of the preprocessed contract data and the multiple preprocessed compiler data.

[0011] The contract is compiled using the target compiler in conjunction with the preprocessed contract data to obtain the compilation result.

[0012] Optionally, the step of performing contract data preprocessing on the smart contract data to obtain preprocessed contract data includes:

[0013] The smart contract data is retrieved according to the preset contract key value to determine the corresponding contract address, contract source code, contract bytecode, compilation optimization flags and contract compiler name;

[0014] The SHA256 algorithm is used to calculate the bytecode hash value corresponding to the contract bytecode;

[0015] The compiler name is divided into the preset number of bits to obtain the corresponding contract compiler hash number and contract compiler version number;

[0016] Preprocessed contract data is constructed using the contract address, the contract source code, the contract bytecode, the bytecode hash value, the compilation optimization flag, the contract compiler version number, and the contract compiler hash number.

[0017] Optionally, the step of performing compiler data preprocessing on the compiler data to obtain multiple preprocessed compiler data includes:

[0018] The compiler data is retrieved according to the preset compiler key value to determine the full names of multiple corresponding compilers;

[0019] Each compiler's full name is truncated according to a preset number of bits to obtain multiple corresponding compiler hash numbers and multiple compiler version numbers;

[0020] Store the compiler associated with the full name of each compiler and record the corresponding compiler storage address;

[0021] Multiple preprocessor data are constructed using the full name of the compiler, the compiler version number, the compiler hash number, and the compiler storage address.

[0022] Optionally, the step of matching the preprocessed contract data with the plurality of preprocessed compiler data and determining the target compiler based on the matching results includes:

[0023] Match multiple compiler hashes according to the contract compiler hash number, and determine whether there is a target compiler hash number that is the same as the contract compiler hash number;

[0024] If so, the target compiler is obtained from the compiler storage address corresponding to the target compiler hash number.

[0025] Optionally, it also includes:

[0026] If not, then match multiple compiler version numbers according to the contract compiler version number to determine whether there is a target compiler version number that is the same as the contract compiler version number;

[0027] If it exists, then obtain the target compiler from the compiler storage address corresponding to the target compiler version number;

[0028] If it does not exist, missing compiler information is generated and uploaded to the log component within the Ethereum system.

[0029] Optionally, the compilation result includes a first compilation result and a second compilation result; the step of compiling the contract using the target compiler in conjunction with the preprocessed contract data to obtain the compilation result includes:

[0030] If the compilation optimization flag is a first preset flag, then the contract source code is compiled by the target compiler to obtain a first compilation result;

[0031] If the compilation optimization flag is the second preset flag, then the contract source code is compiled a second time by the target compiler to obtain the second compilation result.

[0032] Optionally, the method further includes:

[0033] Extract the compiled contract bytecode from the compiled result;

[0034] The hash value of the compiled bytecode corresponding to the compiled contract bytecode is calculated using the SHA256 algorithm;

[0035] Determine whether the compiled bytecode hash value is the same as the bytecode hash value;

[0036] If so, a compilation success message will be generated;

[0037] If not, a compilation error message is generated and uploaded to the logging component within the Ethereum system.

[0038] A second aspect of the present invention provides a smart contract compilation and matching apparatus, comprising:

[0039] The data acquisition module is used to acquire smart contract data and compiler data from the Ethereum system according to a preset acquisition cycle;

[0040] The contract data preprocessing module is used to preprocess the smart contract data to obtain preprocessed contract data.

[0041] The compiler data preprocessing module is used to preprocess the compiler data to obtain multiple preprocessed compiler data.

[0042] The target compiler selection module is used to match the multiple preprocessor compiler data according to the preprocessor contract data, and determine the target compiler based on the matching results.

[0043] The compilation module is used to compile the contract using the target compiler and the preprocessed contract data to obtain the compilation result.

[0044] A third aspect of the present invention provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the steps of the smart contract compilation and matching method as described in any of the first aspects of the present invention.

[0045] A fourth aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed, implements the smart contract compilation and matching method as described in any of the first aspects of the present invention.

[0046] As can be seen from the above technical solutions, the present invention has the following advantages:

[0047] This invention acquires smart contract data and compiler data from the Ethereum system according to a preset acquisition cycle; it performs contract data preprocessing on the smart contract data and compiler data preprocessing on the compiler data, resulting in preprocessed contract data and multiple preprocessed compiler data; it then matches the compiler hashes corresponding to the multiple preprocessed compiler data with the contract compiler hashes within the preprocessed contract data, and retrieves the target compiler from the compiler storage address based on the matching results; finally, it uses the target compiler in conjunction with the compilation optimization flags within the preprocessed contract data to compile the corresponding contract, obtaining the compilation result corresponding to the smart contract data. This solves the technical problem of existing Ethereum smart contract compilation schemes, which rely solely on manual compiler selection, making it difficult to achieve low-cost and efficient smart contract compilation. Furthermore, it achieves efficient smart contract compilation through automated compiler selection while maintaining low cost. Attached Figure Description

[0048] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0049] Figure 1 This is a flowchart illustrating the steps of a smart contract compilation and matching method provided in Embodiment 1 of the present invention;

[0050] Figure 2This is a flowchart illustrating the steps of a smart contract compilation and matching method provided in Embodiment 2 of the present invention;

[0051] Figure 3 This is a schematic diagram of the structure of preprocessed contract data provided in an embodiment of the present invention;

[0052] Figure 4 This is a schematic diagram of the structure of preprocessor data provided in an embodiment of the present invention;

[0053] Figure 5 This is a structural block diagram of a smart contract compilation and matching device provided in Embodiment 3 of the present invention. Detailed Implementation

[0054] This invention provides a smart contract compilation and matching method, apparatus, device, and storage medium to address the technical problem that existing Ethereum smart contract compilation schemes, which rely solely on manual compiler selection, struggle to achieve low-cost and efficient smart contract compilation.

[0055] Ethereum refers to an open software platform based on blockchain technology. The Ethereum network not only records transaction history but also allows developers to build and deploy decentralized applications (DApplications) on Ethereum. The difference between DApplications and traditional applications is that DApplications do not rely on a central platform to achieve their functionality; rather, they rely on smart contracts.

[0056] The term "smart contract" originally referred to the automation of general legal contracts. In this embodiment of the invention, a smart contract refers to a script of code running on a blockchain. Smart contracts allow for trusted transactions without a third party; these transactions are traceable and irreversible. On Ethereum, smart contract functionality is implemented by deploying smart contract bytecode. Because Ethereum transaction records are immutable, smart contracts deployed on Ethereum are also immutable, and their application functionality is permanently effective once deployed.

[0057] To make the objectives, features, and advantages of this invention more apparent and understandable, the technical solutions of the embodiments of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the embodiments described below are only some embodiments of this invention, and not all embodiments. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this invention.

[0058] Please see Figure 1 , Figure 1 This is a flowchart illustrating the steps of a smart contract compilation and matching method provided in Embodiment 1 of the present invention.

[0059] This invention provides a smart contract compilation and matching method, comprising:

[0060] Step 101: Obtain smart contract data and compiler data from the Ethereum system according to the preset acquisition cycle;

[0061] Because only smart contract bytecode is currently deployed on Ethereum, there is insufficient information to locate the error when an anomaly occurs in a transaction based on a certain contract. Furthermore, there is no mapping information between bytecode and contract source code on the Ethereum platform. If a mapping relationship is needed, the contract needs to be recompiled, and relevant information needs to be obtained and processed from the compilation results.

[0062] Therefore, in this embodiment of the invention, the latest smart contract data and compiler data can be obtained from the Ethereum system according to a preset acquisition cycle by setting a timed task, so as to obtain the data basis for subsequent processing.

[0063] It should be noted that, in order to save resources, the acquisition period can be set to one day or one hour, etc., and the specific period is not limited in this embodiment of the invention.

[0064] Step 102: Perform contract data preprocessing on the smart contract data to obtain preprocessed contract data;

[0065] In this embodiment of the invention, since the obtained smart contract data is usually HTML format page data, the smart contract data can be preprocessed first to extract the corresponding preprocessed contract data, such as contract source code, contract bytecode, compilation optimization flags, contract compiler version number and contract compiler hash number.

[0066] Step 103: Perform compiler data preprocessing on the compiler data to obtain multiple preprocessed compiler data;

[0067] At the same time, since the obtained compiler data includes not only the compiler itself but also related HTML file data, compiler data preprocessing can be performed on the obtained compiler data to extract preprocessed compiler data such as the full name of the compiler, the compiler version number, the compiler hash number, and the compiler storage address for each compiler.

[0068] Step 104: Match multiple preprocessor data according to the preprocessor contract data, and determine the target compiler based on the matching results;

[0069] In a practical implementation, the contract compiler hash number in the preprocessed contract data can be used as the matching target to match the compiler hash numbers in multiple preprocessed compiler data to determine the target compiler hash number corresponding to the contract compiler hash number.

[0070] After determining the target compiler hash number, the corresponding target compiler is retrieved from its associated compiler storage address.

[0071] Step 105: Compile the contract using the target compiler in conjunction with the preprocessed contract data to obtain the compilation result.

[0072] After determining the target compiler, the target compiler can be used in conjunction with the compilation optimization flags in the preprocessed contract data. The corresponding compilation method can be selected according to the compilation optimization flags to compile the source code and obtain the compilation result corresponding to the smart contract data.

[0073] In this embodiment of the invention, smart contract data and compiler data are obtained from the Ethereum system according to a preset acquisition cycle. Contract data preprocessing is performed on the smart contract data, and compiler data preprocessing is performed on the compiler data, resulting in preprocessed contract data and multiple preprocessed compiler data sets. Then, the compiler hashes corresponding to the multiple preprocessed compiler data sets are matched according to the contract compiler hashes within the preprocessed contract data. Based on the matching results, the target compiler is obtained from the compiler storage address. Finally, the target compiler, combined with the compilation optimization flags within the preprocessed contract data, is used to compile the corresponding contract, resulting in the compilation result corresponding to the smart contract data. This solves the technical problem of existing Ethereum smart contract compilation schemes, which rely solely on manual compiler selection, making it difficult to achieve low-cost and efficient smart contract compilation. Furthermore, it efficiently compiles smart contracts through automated compiler selection while maintaining low cost.

[0074] Please see Figure 2 , Figure 2 This is a flowchart illustrating the steps of a smart contract compilation and matching method provided in Embodiment 2 of the present invention.

[0075] This invention provides a smart contract compilation and matching method, comprising:

[0076] Step 201: Obtain smart contract data and compiler data from the Ethereum system according to the preset acquisition cycle;

[0077] In this embodiment of the invention, the specific implementation process of step 201 is similar to that of step 101, and will not be repeated here.

[0078] Step 202: Perform contract data preprocessing on the smart contract data to obtain preprocessed contract data;

[0079] Optionally, step 202 may include the following sub-steps:

[0080] Retrieve smart contract data according to preset contract key values, and determine the corresponding contract address, contract source code, contract bytecode, compilation optimization flags and contract compiler name;

[0081] The SHA256 algorithm is used to calculate the bytecode hash value corresponding to the contract bytecode;

[0082] The compiler name is divided according to the preset number of bits to obtain the corresponding contract compiler hash number and contract compiler version number;

[0083] Preprocessed contract data is constructed using the contract address, contract source code, contract bytecode, bytecode hash value, compilation optimization flags, contract compiler version number, and contract compiler hash number.

[0084] Contract key values ​​refer to the HTML files within the smart contract data, used to retrieve the location of certain data tags within the smart contract data, such as Contract Name, CompilerVersion, Contract Source Code, Contract Creation Code, and OptimizationEnabled.

[0085] In this embodiment of the invention, smart contract data is retrieved according to the aforementioned contract key value to determine the contract source code, contract bytecode, compilation optimization identifier, and contract compiler name corresponding to the contract address. After obtaining the above data, since the contract bytecode is too long, directly comparing the contract bytecode consumes a lot of time and resources. Therefore, the SHA256 algorithm can be further used to calculate the bytecode hash value corresponding to the contract bytecode. Then, the compiler name is divided according to a preset number of bits to determine the corresponding contract compiler hash number and contract compiler version number.

[0086] After obtaining the contract address, contract source code, contract bytecode, bytecode hash value, compilation optimization flags, contract compiler version number, and contract compiler hash number, the above data can be used to construct preprocessed contract data, the data structure of which is as follows: Figure 3 As shown.

[0087] It should be noted that the specific calculation process of the SHA256 algorithm is as follows: the maximum length of the input message does not exceed 2^64 bits, the input is processed in 512-bit blocks, and the output is a 256-bit message digest. The algorithm processing includes the following steps:

[0088] STEP 1: Add padding bits. Pad the message to make its length congruent to 448 mod 512 (length = 448 mod 512). The number of padding bits ranges from 1 to 512, with the highest bit of the padding bit string being 1 and the rest being 0. This involves first adding a 1 to the end of the message, then adding many 0s until the length satisfies mod 512 = 448. Why 448? Because 448 + 64 = 512. The second step adds a 64-bit length information of the original message.

[0089] STEP 2: Append the length value. Append the bit length of the initial message (before padding), represented in 64-bit form, to the result of step 1 (lower byte first).

[0090] STEP 3: Initialize the buffer. Use a 256-bit buffer to store the intermediate and final results of the hash function. This buffer is represented as A = 0x6A09E667, B = 0xBB67AE85, C = 0x3C6EF372, D = 0xA54FF53A, E = 0x510E527F, F = 0x9B05688C, G = 0x1F83D9AB, H = 0x5BE0CD19.

[0091] STEP 4: Process the 512-bit (16-word) message packet sequence. This algorithm uses six basic logic functions and consists of 64 iterative operations. Each step takes a 256-bit buffer value ABCDEFGH as input and then updates the buffer content. Each step uses a 32-bit constant value Kt and a 32-bit value Wt.

[0092] Step 203: Perform compiler data preprocessing on the compiler data to obtain multiple preprocessed compiler data;

[0093] Optionally, step 203 may include the following sub-steps:

[0094] Retrieve compiler data according to preset compiler key values ​​to determine the full names of multiple corresponding compilers;

[0095] Each compiler's full name is truncated according to a preset number of characters to obtain multiple corresponding compiler hash numbers and multiple compiler version numbers;

[0096] Store the compiler associated with the full name of each compiler, and record the corresponding compiler storage address;

[0097] Multiple preprocessor data sets are constructed using the compiler's full name, version number, hash number, and storage address.

[0098] Compiler key-value pairs refer to information obtained from HTML files that contain compiler data, such as CompilerVersion: compiler version.

[0099] In one example of this invention, compiler data can be retrieved according to a preset compiler key value to determine the corresponding full names of multiple compilers. The full names of compilers are then truncated according to a preset number of bits to obtain the compiler hash number and compiler version number. For example, if the compiler data is 4.1.1-ac245ac, then ac245ac is the compiler hash number and 4.1.1 is the compiler version number.

[0100] The compilers are retrieved from the Ethereum system according to their full names and stored, with the storage addresses of each compiler recorded. Finally, multiple preprocessed compiler datasets are constructed using the compiler's full name, version number, hash number, and storage address. The specific data structure can be found in [reference needed]. Figure 4 .

[0101] Step 204: Match multiple compiler hashes according to the contract compiler hash to determine if there is a target compiler hash that is the same as the contract compiler hash.

[0102] Step 205: If yes, then obtain the target compiler from the compiler storage address corresponding to the target compiler hash number;

[0103] In one example of the present invention, after obtaining the contract compiler hash number, it can be matched with multiple compiler hash numbers with the contract compiler hash number as the matching target to determine whether there is a common target compiler hash number.

[0104] If it exists, the target compiler can be obtained from the compiler storage address corresponding to the target compiler hash number, in order to wait for the subsequent compilation of the smart contract.

[0105] Step 206: If not, match multiple compiler version numbers according to the contract compiler version number to determine if there is a target compiler version number that is the same as the contract compiler version number;

[0106] Step 207: If it exists, obtain the target compiler from the compiler storage address corresponding to the target compiler version number;

[0107] Step 208: If the missing compiler information does not exist, generate the missing compiler information and upload it to the logging component within the Ethereum system.

[0108] In another example of this invention, if no target compiler hash number exists that matches the contract compiler hash number, the contract compiler version number within the preprocessed contract data is used as the matching target. This is then matched against multiple compiler version numbers to determine if a target compiler version number exists that matches the contract compiler version number. If it exists, the target compiler is retrieved from the compiler storage address corresponding to the target compiler version number. If it does not exist, missing compiler information can be generated and uploaded to the Ethereum logging component to generate the corresponding exception log.

[0109] Step 209: Compile the contract using the target compiler in conjunction with the preprocessed contract data to obtain the compilation result.

[0110] Optionally, the compilation result includes a first compilation result and a second compilation result; step 209 may include the following sub-steps:

[0111] If the compilation optimization flag is the first preset flag, then the contract source code is compiled by the target compiler to obtain the first compilation result;

[0112] If the compilation optimization flag is the second preset flag, then the contract source code is compiled a second time by the target compiler to obtain the second compilation result.

[0113] In this embodiment of the invention, smart contracts may require compilation optimization or not, depending on user needs. After selecting a target compiler, the compilation optimization flags can be read by the target compiler to determine the type of compilation optimization required for the smart contract data.

[0114] If the compilation optimization flag is the first preset flag, the contract source code is compiled by the target compiler to obtain the first compilation result; if the compilation optimization flag is the second preset flag, the contract source code is compiled by the target compiler to obtain the second compilation result.

[0115] Furthermore, the method also includes:

[0116] Extract the compiled contract bytecode from the compiled results;

[0117] The SHA256 algorithm is used to calculate the hash value of the compiled bytecode corresponding to the compiled contract bytecode;

[0118] Determine if the compiled bytecode hash value is the same as the bytecode hash value;

[0119] If so, a compilation success message will be generated;

[0120] If not, a compilation error message is generated and uploaded to the logging component within the Ethereum system.

[0121] In another example of the present invention, after the compilation of the smart contract data is completed, the corresponding compiled contract bytecode can be further extracted from it. The SHA256 algorithm is used again to calculate the hash value of the compiled bytecode corresponding to the compiled contract bytecode. By comparing the hash value of the compiled contract bytecode with the bytecode in the preprocessed contract data, it is determined whether the compilation was successful. If the two are the same, it indicates that the compilation was successful and a compilation success message is generated. If the two are different, it indicates that the compilation failed and a compilation exception message is generated and uploaded to the logging component in the Ethereum system to generate the corresponding compilation exception log.

[0122] In this embodiment of the invention, smart contract data and compiler data are obtained from the Ethereum system according to a preset acquisition cycle. Contract data preprocessing is performed on the smart contract data, and compiler data preprocessing is performed on the compiler data, resulting in preprocessed contract data and multiple preprocessed compiler data sets. Then, the compiler hashes corresponding to the multiple preprocessed compiler data sets are matched according to the contract compiler hashes within the preprocessed contract data. Based on the matching results, the target compiler is obtained from the compiler storage address. Finally, the target compiler, combined with the compilation optimization flags within the preprocessed contract data, is used to compile the corresponding contract, resulting in the compilation result corresponding to the smart contract data. This solves the technical problem of existing Ethereum smart contract compilation schemes, which rely solely on manual compiler selection, making it difficult to achieve low-cost and efficient smart contract compilation. Furthermore, it efficiently compiles smart contracts through automated compiler selection while maintaining low cost.

[0123] Please see Figure 5 , Figure 5 This is a structural block diagram of a smart contract compilation and matching device provided in Embodiment 3 of the present invention.

[0124] This invention also provides a smart contract compilation and matching device, comprising:

[0125] The data acquisition module 501 is used to acquire smart contract data and compiler data from the Ethereum system according to a preset acquisition cycle;

[0126] The contract data preprocessing module 502 is used to preprocess smart contract data to obtain preprocessed contract data.

[0127] The compiler data preprocessing module 503 is used to preprocess compiler data to obtain multiple preprocessed compiler data.

[0128] The target compiler selection module 504 is used to match multiple preprocessor compiler data according to the preprocessor contract data and determine the target compiler based on the matching results.

[0129] Compiler module 505 is used to compile contracts using the target compiler and preprocessed contract data to obtain the compilation results.

[0130] Optionally, the contract data preprocessing module 502 is specifically used for:

[0131] Retrieve smart contract data according to preset contract key values, and determine the corresponding contract address, contract source code, contract bytecode, compilation optimization flags and contract compiler name;

[0132] The SHA256 algorithm is used to calculate the bytecode hash value corresponding to the contract bytecode;

[0133] The compiler name is divided according to the preset number of bits to obtain the corresponding contract compiler hash number and contract compiler version number;

[0134] Preprocessed contract data is constructed using the contract address, contract source code, contract bytecode, bytecode hash value, compilation optimization flags, contract compiler version number, and contract compiler hash number.

[0135] Optionally, the compiler data preprocessing module 503 is specifically used for:

[0136] Retrieve compiler data according to preset compiler key values ​​to determine the full names of multiple corresponding compilers;

[0137] Each compiler's full name is truncated according to a preset number of characters to obtain multiple corresponding compiler hash numbers and multiple compiler version numbers;

[0138] Store the compiler associated with the full name of each compiler, and record the corresponding compiler storage address;

[0139] Multiple preprocessor data sets are constructed using the compiler's full name, version number, hash number, and storage address.

[0140] Optionally, the target compiler selects module 504 specifically for:

[0141] Match multiple compiler hashes based on the contract compiler hash to determine if there is a target compiler hash that is the same as the contract compiler hash.

[0142] If so, the target compiler is obtained from the compiler storage address corresponding to the target compiler hash number.

[0143] Optionally, the target compiler selects module 504 for:

[0144] If not, then match multiple compiler version numbers according to the contract compiler version number to determine if there is a target compiler version number that is the same as the contract compiler version number;

[0145] If it exists, then obtain the target compiler from the compiler storage address corresponding to the target compiler version number;

[0146] If it does not exist, missing compiler information is generated and uploaded to the logging component within the Ethereum system.

[0147] Optionally, the compilation result includes a first compilation result and a second compilation result; compilation module 505 is specifically used for:

[0148] If the compilation optimization flag is the first preset flag, then the contract source code is compiled by the target compiler to obtain the first compilation result;

[0149] If the compilation optimization flag is the second preset flag, then the contract source code is compiled a second time by the target compiler to obtain the second compilation result.

[0150] Optionally, the device further includes:

[0151] The bytecode extraction module for compiled contracts is used to extract the bytecode of the compiled contracts from the compilation results.

[0152] The bytecode hash value calculation module is used to calculate the hash value of the compiled bytecode corresponding to the compiled contract bytecode using the SHA256 algorithm.

[0153] The compiled bytecode hash determination module is used to determine whether the compiled bytecode hash value is the same as the bytecode hash value;

[0154] The compilation success determination module is used to generate a compilation success message if the result is successful.

[0155] The compilation exception detection module is used to generate a compilation exception message if the error is not found, and upload it to the logging component within the Ethereum system.

[0156] This invention also provides an electronic device, including a memory and a processor. The memory stores a computer program, and when the computer program is executed by the processor, the processor performs the steps of the smart contract compilation and matching method as described in any embodiment of this invention.

[0157] This invention also provides a computer-readable storage medium storing a computer program thereon, which, when executed, implements the smart contract compilation and matching method as described in any embodiment of this invention.

[0158] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the above-described device and module can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0159] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0160] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0161] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0162] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0163] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A smart contract compilation and matching method, characterized in that, include: Retrieve smart contract data and compiler data from the Ethereum system according to a preset acquisition cycle; The smart contract data is preprocessed to obtain preprocessed contract data; The compiler data is preprocessed to obtain multiple preprocessed compiler data sets; The target compiler is determined based on the matching results of the preprocessed contract data and the multiple preprocessed compiler data. The contract is compiled using the target compiler in conjunction with the preprocessed contract data to obtain the compilation result; The step of performing contract data preprocessing on the smart contract data to obtain preprocessed contract data includes: The smart contract data is retrieved according to the preset contract key value to determine the corresponding contract address, contract source code, contract bytecode, compilation optimization flags and contract compiler name; The SHA256 algorithm is used to calculate the bytecode hash value corresponding to the contract bytecode; The compiler name is divided into the preset number of bits to obtain the corresponding contract compiler hash number and contract compiler version number; Preprocessed contract data is constructed using the contract address, the contract source code, the contract bytecode, the bytecode hash value, the compilation optimization flag, the contract compiler version number, and the contract compiler hash number.

2. The method according to claim 1, characterized in that, The step of performing compiler data preprocessing on the compiler data to obtain multiple preprocessed compiler data includes: The compiler data is retrieved according to the preset compiler key value to determine the full names of multiple corresponding compilers; Each compiler's full name is truncated according to a preset number of bits to obtain multiple corresponding compiler hash numbers and multiple compiler version numbers; Store the compiler associated with the full name of each compiler and record the corresponding compiler storage address; Multiple preprocessor data are constructed using the full name of the compiler, the compiler version number, the compiler hash number, and the compiler storage address.

3. The method according to claim 2, characterized in that, The step of matching the preprocessed contract data with the plurality of preprocessed compiler data and determining the target compiler based on the matching results includes: Match multiple compiler hashes according to the contract compiler hash number, and determine whether there is a target compiler hash number that is the same as the contract compiler hash number; If so, the target compiler is obtained from the compiler storage address corresponding to the target compiler hash number.

4. The method according to claim 3, characterized in that, Also includes: If not, then match multiple compiler version numbers according to the contract compiler version number to determine whether there is a target compiler version number that is the same as the contract compiler version number; If it exists, then obtain the target compiler from the compiler storage address corresponding to the target compiler version number; If it does not exist, missing compiler information is generated and uploaded to the log component within the Ethereum system.

5. The method according to claim 2, characterized in that, The compilation result includes a first compilation result and a second compilation result; the step of compiling the contract using the target compiler in conjunction with the preprocessed contract data to obtain the compilation result includes: If the compilation optimization flag is a first preset flag, then the contract source code is compiled by the target compiler to obtain a first compilation result; If the compilation optimization flag is the second preset flag, then the contract source code is compiled a second time by the target compiler to obtain the second compilation result.

6. The method according to claim 2 or 5, characterized in that, The method further includes: Extract the compiled contract bytecode from the compiled result; The hash value of the compiled bytecode corresponding to the compiled contract bytecode is calculated using the SHA256 algorithm; Determine whether the compiled bytecode hash value is the same as the bytecode hash value; If so, a compilation success message will be generated; If not, a compilation error message is generated and uploaded to the logging component within the Ethereum system.

7. A smart contract compilation and matching device, characterized in that, include: The data acquisition module is used to acquire smart contract data and compiler data from the Ethereum system according to a preset acquisition cycle; The contract data preprocessing module is used to preprocess the smart contract data to obtain preprocessed contract data. The compiler data preprocessing module is used to preprocess the compiler data to obtain multiple preprocessed compiler data. The target compiler selection module is used to match the multiple preprocessor compiler data according to the preprocessor contract data, and determine the target compiler based on the matching results. The compilation module is used to compile the contract using the target compiler and the preprocessed contract data to obtain the compilation result. The contract data preprocessing module is specifically used for: The smart contract data is retrieved according to the preset contract key value to determine the corresponding contract address, contract source code, contract bytecode, compilation optimization flags and contract compiler name; The SHA256 algorithm is used to calculate the bytecode hash value corresponding to the contract bytecode; The compiler name is divided into the preset number of bits to obtain the corresponding contract compiler hash number and contract compiler version number; Preprocessed contract data is constructed using the contract address, the contract source code, the contract bytecode, the bytecode hash value, the compilation optimization flag, the contract compiler version number, and the contract compiler hash number.

8. An electronic device, characterized in that, The system includes a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor causes the processor to perform the steps of the smart contract compilation and matching method as described in any one of claims 1-6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed, it implements the smart contract compilation and matching method as described in any one of claims 1-6.

Citation Information

Patent Citations

  • Method for efficiently compiling Solidity smart contract at browser end

    CN111176625A