Smart contract data processing method, device, equipment, storage medium and program product for blockchain
By using a pre-trained natural language processing model to split smart contracts and using a hash value storage strategy, the problem of low efficiency in generating and storing smart contracts on the blockchain is solved, and more efficient smart contract processing is achieved.
Patent Information
- Application Number
- CN202411973633.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2044-12-30
AI Technical Summary
Smart contracts are inefficient in their generation, storage, and use on the blockchain, leading to a waste of computing resources and network bandwidth.
Use a pre-trained natural language processing model to automatically generate smart contracts and split them into multiple code snippets. Each snippet corresponds to a hash value, and only different hash values are stored. When reading, the code snippets are quickly indexed by hash value to avoid duplicate storage.
It improves the efficiency of smart contract generation, storage and reading, and improves the overall execution efficiency.
Smart Images

Figure CN119829681B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and in particular to a method, apparatus, device, storage medium, and program product for processing smart contract data for blockchain. Background Art
[0002] As the application of blockchain technology gradually increases, smart contracts are becoming more and more widely used on the blockchain due to their high accuracy and reliability, high degree of automation and efficiency, as well as the convenience and cost reduction they can provide to users.
[0003] The inventors discovered that in practical applications, smart contracts suffer from inefficiencies from generation to storage on the blockchain and subsequent use. Therefore, a method for processing blockchain smart contract data is urgently needed to address these technical issues. Summary of the Invention
[0004] The present application provides a method, apparatus, device, storage medium, and program product for processing smart contract data on a blockchain, which solves the problem of low efficiency in practical applications of smart contracts, from generation to storage on a blockchain and subsequent use.
[0005] In a first aspect, the present application provides a method for processing smart contract data for blockchain, comprising:
[0006] Obtain information on pre-trained natural language processing models and smart contract development requirements;
[0007] Performing data processing on the smart contract development requirement information according to the pre-trained natural language processing model to obtain smart contract text information, and constructing a smart contract to be stored based on the smart contract text information;
[0008] Input the smart contract to be stored into a pre-trained natural language processing model to obtain split contract code fragments to be stored, and determine a hash value based on each contract code fragment to be stored;
[0009] Store each contract code snippet to be stored and its corresponding hash value into the blockchain storage space in turn;
[0010] When a hash value is detected to exist in the blockchain storage space with the same hash value, only the hash value is stored in the blockchain storage space until the storage of the smart contract to be stored is completed;
[0011] Obtaining call information for the smart contract to be stored, and determining at least one hash value to be indexed based on the call information of the smart contract to be stored and the pre-trained natural language processing model;
[0012] A corresponding contract code snippet is read from the blockchain storage space in sequence according to each hash value to be indexed, until the contract code snippet corresponding to the last hash value to be indexed is read. During this period, when it is detected that the hash value to be indexed is repeated with the previous hash value to be indexed, the contract code snippet corresponding to the previous hash value to be indexed can be directly called.
[0013] In a second aspect, the present application provides a smart contract data processing device for blockchain, comprising:
[0014] The acquisition module is used to obtain pre-trained natural language processing models and smart contract development requirements information;
[0015] A smart contract construction module, configured to perform data processing on the smart contract development requirement information according to the pre-trained natural language processing model to obtain smart contract text information, and to construct a smart contract to be stored according to the smart contract text information;
[0016] A smart contract storage module is used to input the smart contract to be stored into a pre-trained natural language processing model to obtain split contract code fragments to be stored, and determine a hash value based on each contract code fragment to be stored;
[0017] The smart contract storage module is further configured to sequentially store each contract code fragment to be stored and a corresponding hash value into the blockchain storage space;
[0018] The smart contract storage module is further configured to, when detecting that a hash value exists in the blockchain storage space and the same hash value exists in the blockchain storage space, store only the hash value in the blockchain storage space until the storage of the smart contract to be stored is completed;
[0019] A smart contract reading module, configured to obtain call information for the smart contract to be stored, and determine at least one hash value to be indexed based on the call information of the smart contract to be stored and the pre-trained natural language processing model;
[0020] The smart contract reading module is further configured to sequentially read a corresponding contract code snippet from the blockchain storage space according to each hash value to be indexed, until the contract code snippet corresponding to the last hash value to be indexed is read. During this period, if it is detected that the hash value to be indexed is repeated with the previous hash value to be indexed, the contract code snippet corresponding to the previous hash value to be indexed can be directly called.
[0021] In a third aspect, an embodiment of the present application provides an electronic device, comprising: at least one processor, and a memory communicatively connected to the processor;
[0022] The memory stores computer-executable instructions;
[0023] The processor executes the computer-executable instructions stored in the memory to implement the method described in the first aspect.
[0024] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the method described in the first aspect.
[0025] In a fifth aspect, the present application provides a computer program product, comprising a computer program, which implements the method described in the first aspect when executed by a processor.
[0026] This application provides a method, apparatus, device, storage medium, and program product for processing smart contract data for blockchain. This method rapidly generates smart contracts using a pre-trained natural language processing model and divides the smart contract into multiple code blocks. Each code block has a corresponding hash value, and only different hash values and corresponding code blocks are stored. Only one code block with the same hash value is stored. The same strategy is also adopted when reading and calling smart contracts. When encountering the same hash value, the contract is directly called from the previously read code block. This improves the efficiency of smart contract generation, storage, and reading, and thus the execution efficiency of smart contracts. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0028] Figure 1 A schematic diagram of an application scenario of the smart contract data processing method for blockchain provided in an embodiment of the present application;
[0029] Figure 2 A flowchart of a smart contract data processing method for blockchain provided in an embodiment of the present application;
[0030] Figure 3 A schematic diagram of the structure of a smart contract data processing device for blockchain provided in an embodiment of the present application;
[0031] Figure 4 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application.
[0032] The above drawings illustrate specific embodiments of the present application, which will be described in more detail below. These drawings and the textual description are not intended to limit the scope of the present application in any way, but rather to illustrate the concepts of the present application to those skilled in the art by reference to specific embodiments. DETAILED DESCRIPTION
[0033] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
[0034] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of the relevant data comply with the relevant laws, regulations and standards of the relevant countries and regions, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0035] In addition, this application involves conducting big data analysis of user information (including but not limited to personal biometrics, identity data, consumption data, asset data, electronic terminal operation data, etc.), and using artificial intelligence technology to make automated decisions, and making technical solutions that have a significant impact on personal rights and interests based on the results of automated decisions. The application provides users with corresponding operation entrances for them to choose to agree or reject the results of automated decisions; if the user chooses to reject, the expert decision-making process will be entered.
[0036] It should be noted that the smart contract data processing method, device, equipment, storage medium and program product for blockchain provided in this application can be used in the field of blockchain technology, and can also be used in any field other than the field of blockchain technology. The application field of the smart contract data processing method, device, equipment, storage medium and program product for blockchain in this application is not limited.
[0037] In actual applications, the inventors found that smart contracts are stored and read as a whole, and the code and data of smart contracts are usually large. Therefore, during the chain-up process and call process of the smart contract, one-time loading and parsing will consume a large amount of computing resources and network bandwidth, resulting in low processing efficiency of the smart contract.
[0038] To solve the above technical problems, the inventors have proposed the following inventive concept: first, a pre-trained natural language processing model for smart contracts is used to automatically generate the smart contracts to be stored according to the smart contract creation requirements. Then, the trained natural language processing model is used to predict and split the smart contracts to be stored. Then, the hash values and the split smart contract code fragments are matched one by one, and the hash values and the corresponding smart contract code fragments are stored. When the stored hash values are the same, only the hash values are stored, which improves storage efficiency. When reading a stored smart contract, it is only necessary to quickly index to the corresponding smart contract code fragment by reading the hash value, without having to read the entire smart contract code, which improves reading efficiency. The efficiency of subsequent smart contract calls is also improved.
[0039] The following specific embodiments describe in detail the technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0040] Figure 1 Schematic diagram of the application scenario of the smart contract data processing method for blockchain provided in the embodiment of this application. Figure 1 As shown, the application scenario includes: an operating terminal 101 and a blockchain 102.
[0041] The operation terminal 101 can be a server capable of training large AI models or other computer devices with similar capabilities. The operation terminal 101 can receive smart contract development requirements, automatically generate smart contracts based on these requirements, and then store the smart contracts on the blockchain 102. The process of deploying smart contracts on the blockchain 102 is the process of storing smart contracts. Furthermore, the operation terminal 101 can also be used to read smart contracts and facilitate smart contract invocation operations.
[0042] Figure 2 This is a flow chart of a smart contract data processing method for blockchain provided in an embodiment of the present application. Figure 2 As shown, the execution subject of the smart contract data processing method for blockchain provided in the embodiment of the present application is Figure 1 The operating terminal 101 shown in the figure can, of course, also be other computer-related devices with the same control function, and this embodiment does not limit this.
[0043] like Figure 2 As shown, the smart contract data processing method for blockchain includes:
[0044] S201: Obtain pre-trained natural language processing models and smart contract development requirements information.
[0045] In this embodiment, the pre-trained natural language processing model can be trained on a large machine learning model using training data related to smart contracts, resulting in a model with text recognition and data processing capabilities. Smart contract development requirements can include the steps and tasks to be completed for the smart contract, as proposed by the business party.
[0046] Specifically, in an optional embodiment of the present application, step S201 includes:
[0047] S201a: Obtain existing smart contract data and pre-stored contract split mark data, and perform text format conversion processing based on the existing smart contract data to obtain contract text data.
[0048] In an optional embodiment of the present application, step S201a performs text format conversion processing based on the existing smart contract data to obtain contract text data, including:
[0049] Step a1: Perform text recognition processing based on the existing smart contract data to obtain a first vocabulary.
[0050] In this embodiment, the first vocabulary may include all possible words and phrases, keywords, variable names, function names, and data types used in the smart contract code.
[0051] For example, the first vocabulary may be as follows:
[0052] Keywords: function, conditional statement if, selection statement else, return, unsigned integer uint, address address.
[0053] Variable name: balance, user owner.
[0054] Function name: transfer, withdraw.
[0055] Data type: Boolean bool.
[0056] Step a2: Establish a mapping relationship between the first vocabulary and special characters in the existing smart contract data, and a mapping relationship between keywords and data types based on the first vocabulary and the existing smart contract data.
[0057] In this embodiment, a mapping relationship is established between the vocabulary and the special characters, keywords, and data types in the smart contract code. A mapping relationship is associated between each entry in the vocabulary and its corresponding text.
[0058] Step a3: Traverse each part of the existing smart contract data, and replace each element in the existing smart contract data with the corresponding text content based on the mapping relationship between the first vocabulary and the special characters in the existing smart contract data and the mapping relationship between keywords and data types to obtain contract text data.
[0059] In this embodiment, each element in the existing smart contract is replaced with the corresponding text content through the mapping relationship, so that the obtained contract text data is more accurate, providing more accurate data for subsequent model training, thereby improving the accuracy of the pre-trained natural language processing model.
[0060] S201b: Perform word segmentation processing based on the contract text data to obtain a contract word sequence.
[0061] Specifically, in an optional embodiment of the present application, step S201b includes:
[0062] Step b1: Identify and process the contract text data to obtain the text format type.
[0063] Step b2: Select a target word segmentation tool from a library of pre-existing word segmentation tools based on the text format type.
[0064] In this embodiment, the pre-existing word segmentation tool library includes many open source word segmentation tools to choose from, such as the jieba library, which specializes in Chinese word segmentation, the natural language toolkit NLTK, or word segmentation libraries for other languages. If you are processing Chinese text, you can choose jieba; for English, you can choose the natural language toolkit NLTK or the natural language processing tool spaCy as a word segmentation tool.
[0065] Step b3: Use the target word segmentation tool to segment the contract text data into word sequences consisting of words and / or tokens.
[0066] In this embodiment, the contract text data is segmented into word sequences consisting of words, word sequences consisting of tokens, and word sequences consisting of words and tokens by a target word segmentation tool.
[0067] For example, if the input text format contract is "Smart contracts are used to manage assets. They contain multiple functions, such as transfers, deposits, and withdrawals," the word sequence obtained after word segmentation can be "['smart contract', 'used for', 'management', 'digital', 'assets', '.', 'contains', 'multiple', 'functions', 'such as', 'transfers', '、', 'deposits', 'withdrawals', '.'].
[0068] In this embodiment, by selecting different target word segmentation tools, the obtained contract word sequence is made more accurate and more conducive to subsequent model training.
[0069] S201c: The initial model is trained based on the contract word sequence, the basic model, and the pre-labeled contract split data to obtain a transitional natural language processing model.
[0070] In this embodiment, the initial model can be an open-source text processing model in the field of artificial intelligence, such as an NLP model or other deep learning model with text recognition capabilities, a recurrent neural network (RNN), or a Transformer deep learning model based on the self-attention mechanism. The transitional natural language processing model can be an initial model that has undergone preliminary training and is capable of processing simple smart contract-related data.
[0071] S201d: Use the pre-stored contract split labeled data as the validation set and test set to perform model adjustment training on the transition natural language processing model to obtain a pre-trained natural language processing model.
[0072] In this embodiment, the pre-trained natural language processing model is trained using the contract word sequence obtained through text conversion and word segmentation, and the model is adjusted using the pre-stored contract split labeled data as the verification set and test set. The final pre-stored natural language processing model has a higher accuracy rate and is more efficient in generating smart contracts to be stored.
[0073] S202: Perform data processing on the smart contract development requirement information according to the pre-trained natural language processing model to obtain smart contract text information, and construct a smart contract to be stored based on the smart contract text information.
[0074] In this embodiment, data processing can be a process of using a pre-stored natural language processing model to perform text recognition and organization on smart contract creation requirement information.
[0075] Specifically, in an optional embodiment of the present application, in step S202, data processing is performed on the smart contract development requirement information according to the pre-trained natural language processing model to obtain the smart contract text information including:
[0076] S201a: Perform text recognition processing on the smart contract creation requirement information based on the pre-trained natural language processing model to obtain the overall contract text information.
[0077] S201b: Split the entire contract text information according to the contract steps based on the pre-trained natural language processing model to obtain contract text information consisting of multiple smart contract text fragments.
[0078] In this embodiment, text recognition processing can be the process of identifying key text content related to smart contract compilation in smart contract creation requirement information. Segmentation processing can be the process of segmenting key text content related to the smart contract into text segments related to individual execution steps according to the smart contract execution steps. For example, if a text content contains 10 natural paragraphs, each natural paragraph of text content corresponds to an execution step, then the 10 natural paragraphs of text content obtained in this segmentation correspond to 10 smart contract text segments.
[0079] In this embodiment, the text recognition processing of smart contracts is performed by using a pre-trained natural language processing model, which is more efficient than manual interpretation and recognition.
[0080] In an optional embodiment of the present application, the smart contract text information includes multiple smart contract text fragments, and the multiple smart contract text fragments are sorted according to the contract steps; accordingly, in step S201, constructing the smart contract to be stored based on the smart contract text information includes:
[0081] S202c: Execute a contract encoding operation according to the multiple smart contract text fragments to obtain multiple code fragments, where each code fragment has one and only one corresponding smart contract text fragment.
[0082] S202d: Sort and combine all code snippets according to the contract steps to construct the smart contract to be stored.
[0083] In this embodiment, the process of constructing the smart contract to be stored may be a process of generating a smart contract code package using a smart contract code compilation tool.
[0084] S203: Input the smart contract to be stored into the pre-trained natural language processing model to obtain the split contract code fragments to be stored, and determine a hash value based on each contract code fragment to be stored.
[0085] In this embodiment, the pre-trained natural language processing model can identify and split functions, keywords, and markup symbols within the code of the contract to be stored, and split the smart contract to be stored into multiple contract code snippets to be stored. In this embodiment, determining a hash value based on the smart contract code snippet to be stored can be performed by using a hash algorithm to generate a fixed-length output from the input smart contract code snippet, with the fixed-length output being the hash value. Only identical code snippets will generate the same hash value. Any modification to the smart contract will result in a change in the hash value.
[0086] S204: Store each contract code snippet to be stored and a corresponding hash value into the blockchain storage space in sequence.
[0087] In this embodiment, starting from the first smart contract code fragment to be stored in the smart contract to be stored, the first smart contract code fragment to be stored and the corresponding hash value are stored in the blockchain storage space, and then the second smart contract code fragment to be stored and the corresponding hash value are stored in the blockchain storage space, and so on.
[0088] S205: When it is detected that a hash value has the same hash value in the blockchain storage space, only the hash value is stored in the blockchain storage space until the smart contract to be stored is completed.
[0089] In this embodiment, whenever a hash value and a smart contract code snippet to be stored are stored, it is necessary to check whether a hash value already stored in the blockchain storage space is identical to the hash value to be stored. If an identical hash value exists, then the hash value is simply stored in the blockchain storage space. If an identical hash value does not exist, the same method as in step S204 is used to store the hash value and the smart contract code snippet to be stored corresponding to the hash value in the blockchain storage space until the smart contract to be stored is complete.
[0090] In this embodiment, storage completion may mean that all hash values corresponding to all the smart contract code fragments to be stored in the smart contract to be stored are stored in the blockchain storage space.
[0091] S206: Obtain call information for the smart contract to be stored, and determine at least one hash value to be indexed based on the call information of the smart contract to be stored and the pre-trained natural language processing model.
[0092] Specifically, in an optional embodiment of the present application, step S206 includes:
[0093] S206a: Use the pre-trained natural language processing model to perform intent recognition processing based on the call information of the smart contract to be stored to obtain a prediction result.
[0094] S206b: Determine the contract execution information of the smart contract to be stored based on the prediction result.
[0095] S206c: Determine at least one hash value to be indexed based on the contract execution information.
[0096] In this embodiment, the call information may be to query and read the description of a task in a smart contract, for example, the description of a deposit task in a smart contract. To do this, a pre-trained natural language processing model is used to identify keywords related to the smart contract execution steps associated with the deposit task. Based on these keywords, at least one hash value to be indexed is determined. Each hash value to be indexed corresponds to a contract code snippet.
[0097] In this embodiment, the intent recognition process can be a process of performing text recognition based on the call information, selecting keywords from the text, and generating a prediction result corresponding to the call information. The prediction result can be a description of the call information that reflects the intent of the smart industry research.
[0098] In this embodiment, the contract execution information may be the steps to be executed by the smart contract to be stored or the smart contract code snippet to be called and the corresponding calling order.
[0099] In this embodiment, a prediction is first performed through a pre-trained natural language processing model, and then the contract execution information is determined based on the pre-stored results, and then at least one hash value to be indexed is determined, thereby improving the accuracy and efficiency of determining the hash value to be indexed.
[0100] S207: Read a corresponding contract code snippet from the blockchain storage space according to each hash value to be indexed in turn, until the contract code snippet corresponding to the last hash value to be indexed is read. During this period, if it is detected that the hash value to be indexed is repeated with the previous hash value to be indexed, the contract code snippet corresponding to the previous hash value to be indexed can be directly called.
[0101] In this embodiment, a hash value to be indexed may be identical to at least one hash value already stored in the blockchain storage space. By matching the identical hash value, the contract code fragment corresponding to the hash value can be further indexed.
[0102] In order to make the blockchain smart contract processing method provided in the embodiment of the present application easier for those skilled in the art to understand, the following will be explained using the storage process of the entire digital asset management smart contract as an example:
[0103] 1. Obtain smart contract development requirement information for the digital asset management smart contract sent by the business party.
[0104] 2. Use the pre-trained natural language processing model to process the smart contract development requirement information to obtain the smart contract text information, and construct the smart contract to be stored based on the smart contract text information.
[0105] 3. Use the pre-trained natural language processing model to split the input smart contract to be stored into five smart contract code snippets to be stored. These five smart contract code snippets to be stored represent the five operation steps of deposit, A's outward transfer, withdrawal, deposit, and A's outward transfer.
[0106] 4. Based on the five smart contract code snippets to be stored, a hash algorithm is used to generate three hash values in sequence: Hash1 corresponding to the first deposit operation step, Hash2 corresponding to the first A outward transfer operation step, Hash3 corresponding to the withdrawal operation step, Hash1 corresponding to the second deposit operation step, and Hash2 corresponding to the second A outward transfer operation step.
[0107] 5. When storing the hash values and the smart contract snippets to be stored in step 4, first store Hash1 and smart contract snippet 1 corresponding to the first deposit operation step in the blockchain storage space. Then, store Hash2 and smart contract snippet 2 corresponding to the first outward transfer operation step A in the blockchain storage space. When storing the fourth Hash1, it is detected that a Hash1 already exists in the blockchain storage space. In this case, there is no need to store smart contract snippet 4, and only Hash1 is stored. This is because smart contract snippet 4 is identical to smart contract snippet 1 and does not need to be stored repeatedly. Similarly, the smart contract snippets to be stored in the blockchain storage space will eventually include: [smart contract snippet 1 to be stored, smart contract snippet 2 to be stored, smart contract snippet 3 to be stored]. The index hash values in the blockchain storage space will include: [Hash1, Hash2, Hash3, Hash1, Hash2].
[0108] 6. Obtain the user's deposit task call information for the digital asset management smart contract. Then, based on the deposit task call information and the pre-trained natural language processing model, determine at least one hash value Hash1 to be indexed. Then, query and read the same smart contract code snippet 1 to be stored in the blockchain storage space twice to complete the call of the digital asset management smart contract.
[0109] Based on the above embodiment, the smart contract data processing method for blockchain provided in an optional embodiment of the present application further includes:
[0110] Step A: Regularly obtain sample data of different types of smart contracts.
[0111] Step B: Perform text recognition processing based on each type of smart contract sample data to obtain a corresponding second vocabulary.
[0112] Step C: Merge all the second vocabulary lists with the first vocabulary list to obtain an updated first vocabulary list.
[0113] In this embodiment, the smart contract sample data may include data related to smart contracts of different fields, types, and mission objectives. The smart contract sample data includes the codes of different types of smart contracts and smart contract creation requirements.
[0114] In this embodiment, the principle of step B is similar to that of step a1 in the above embodiment, and therefore will not be further described in this embodiment. The process of merging all second vocabularies with the first vocabularies in step C refers to the process of adding keywords, symbols, data types, and other data in the second vocabularies that differ from those in the first vocabularies to the first vocabularies to obtain an updated first vocabularies.
[0115] In this embodiment, by updating the first vocabulary, different types of vocabularies are used for the subsequent generation and storage of different types of smart contracts, thereby further improving accuracy and efficiency.
[0116] Optionally, based on the above embodiment, the smart contract data processing method for blockchain provided in a possible implementation of the first embodiment of the present application further includes:
[0117] Step D: Regularly obtain new smart contract creation requirement information, and process the new smart contract creation requirement information according to the pre-trained natural language processing model to obtain new smart contract text information.
[0118] Step E: Construct a new smart contract to be stored based on the new smart contract text information.
[0119] Step F: Perform contract detection on the new smart contract to be stored and obtain the detection result.
[0120] Step G: Adjust the pre-trained natural language processing model according to the detection results to obtain an adjusted pre-trained natural language processing model.
[0121] In this embodiment, the principles of step D and step E are similar to those of step S201 to step S202 in the above embodiment, and therefore will not be described in detail in this embodiment.
[0122] It should be noted that the purpose of contract detection for new smart contracts to be stored is to detect whether the new smart contracts to be stored are generated in accordance with the needs of the business party, and whether they are close to or even the same as the actual needs of the business party.
[0123] In this embodiment, by regularly improving the target natural language processing model, the generation and storage efficiency of subsequent smart contracts can be higher, and the generated smart contracts are more in line with development requirements.
[0124] In summary, the embodiments of the present application provide a smart contract data processing method for blockchain. This method uses a pre-trained natural language processing model to quickly generate smart contracts and divides the smart contract into multiple code blocks. Each code block has a corresponding hash value, and only different hash values and corresponding code blocks are stored. Only one code block with the same hash value is stored. The same strategy is also adopted when reading and calling smart contracts. When encountering the same hash value, the code block that has already been read is directly called. This improves the efficiency of smart contract generation, storage, and reading, and thus the execution efficiency of smart contracts.
[0125] Figure 3 A schematic diagram of the structure of a smart contract data processing device for blockchain provided in an embodiment of the present application.
[0126] like Figure 3 As shown, the smart contract data processing device for blockchain provided in an embodiment of the present application includes: an acquisition module 31, a smart contract construction module 32, a smart contract storage module 33 and a smart contract reading module 34.
[0127] Among them, the acquisition module 31 is used to obtain the pre-trained natural language processing model and smart contract development requirement information.
[0128] The smart contract construction module 32 is used to process the smart contract development requirement information according to the pre-trained natural language processing model to obtain the smart contract text information, and construct the smart contract to be stored according to the smart contract text information.
[0129] The smart contract storage module 33 is used to input the smart contract to be stored into the pre-trained natural language processing model to obtain the split contract code fragments to be stored, and determine a hash value based on each contract code fragment to be stored.
[0130] The smart contract storage module 33 is further used to store each contract code fragment to be stored and a corresponding hash value into the blockchain storage space in sequence.
[0131] The smart contract storage module 33 is also used to store only the hash value in the blockchain storage space when it is detected that the same hash value exists in the blockchain storage space until the smart contract to be stored is completely stored.
[0132] The smart contract reading module 34 is used to obtain call information for the smart contract to be stored, and determine at least one hash value to be indexed based on the call information of the smart contract to be stored and the pre-trained natural language processing model.
[0133] The smart contract reading module 34 is further configured to sequentially read a corresponding contract code snippet from the blockchain storage space according to each hash value to be indexed, until the contract code snippet corresponding to the last hash value to be indexed is read. During this period, if it is detected that the hash value to be indexed is repeated with the previous hash value to be indexed, the contract code snippet corresponding to the previous hash value to be indexed can be directly called.
[0134] In an optional embodiment of the present application, the acquisition module 31 is specifically used to: obtain existing smart contract data and pre-stored contract split mark data, and perform text format conversion processing based on the existing smart contract data to obtain contract text data; perform word segmentation processing based on the contract text data to obtain a contract word sequence; perform model training on the initial model based on the contract word sequence, the basic model and the pre-marked contract split data to obtain a transitional natural language processing model; use the pre-stored contract split mark data as a verification set and a test set to perform model adjustment training on the transitional natural language processing model to obtain a pre-trained natural language processing model.
[0135] In an optional embodiment of the present application, the acquisition module 31 is specifically used to: perform text recognition processing based on the existing smart contract data to obtain a first vocabulary; establish a mapping relationship between the first vocabulary and special characters in the existing smart contract data, as well as a mapping relationship between keywords and data types based on the first vocabulary and the existing smart contract data; traverse each part of the existing smart contract data, and replace each element in the existing smart contract data with corresponding text content based on the mapping relationship between the first vocabulary and special characters in the existing smart contract data, as well as the mapping relationship between keywords and data types, to obtain contract text data.
[0136] In an optional embodiment of the present application, the acquisition module 31 is specifically used to: perform identification processing based on the contract text data to obtain the text format type; select a target word segmentation tool from a pre-stored word segmentation tool library based on the text format type; and use the target word segmentation tool to segment the contract text data into a word sequence consisting of words and / or tags.
[0137] In an optional embodiment of the present application, the smart contract text information includes multiple smart contract text fragments, and the multiple smart contract text fragments are sorted according to the contract steps; accordingly, the smart contract construction module 32 is specifically used to: perform contract encoding operations according to the multiple smart contract text fragments to obtain multiple code fragments, wherein each code fragment has one and only one corresponding smart contract text fragment; sort and combine all the code fragments according to the contract steps to construct the smart contract to be stored.
[0138] In an optional embodiment of the present application, the smart contract reading module 34 is specifically used to: use a pre-trained natural language processing model to perform intent recognition processing based on the call information of the smart contract to be stored to obtain a prediction result; determine the contract execution information of the smart contract to be stored based on the prediction result; and determine at least one hash value to be indexed based on the contract execution information.
[0139] In an optional embodiment of the present application, the acquisition module 31 is further used to: regularly acquire different types of smart contract sample data; perform text recognition processing based on each type of smart contract sample data to obtain a corresponding second vocabulary; and merge all second vocabulary tables with the first vocabulary table to obtain an updated first vocabulary table.
[0140] In an optional embodiment of the present application, the acquisition module 31 is also used to periodically obtain new smart contract creation requirement information, and perform data processing on the new smart contract creation requirement information according to the pre-trained natural language processing model to obtain new smart contract text information; construct a new smart contract to be stored according to the new smart contract text information; perform contract detection processing on the new smart contract to be stored to obtain a detection result; and adjust the pre-trained natural language processing model according to the detection result to obtain an adjusted pre-trained natural language processing model.
[0141] The smart contract data processing device for blockchain provided in this embodiment can be used to execute the above Figure 2 The technical solution of the method embodiment shown has similar implementation principles and technical effects, and will not be repeated here in this embodiment.
[0142] Figure 4 Schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. Figure 4 As shown, the electronic device includes: at least one processor 401 and a memory 402 communicatively connected to the processor 401 .
[0143] The memory 402 stores computer-executable instructions.
[0144] Processor 401 executes computer-executable instructions stored in memory 402 to implement the various steps involved in the method embodiment of the method for processing smart contract data for blockchain. For details, please refer to the relevant description in the aforementioned method embodiment.
[0145] Optionally, the memory 402 may be independent or integrated with the processor 401 .
[0146] When the memory 402 is independently provided, the electronic device further includes a bus 403 for connecting the memory 402 and the processor 401 .
[0147] An embodiment of the present application further provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, the above-mentioned smart contract data processing method for blockchain is implemented.
[0148] An embodiment of the present application also provides a computer program product, including a computer program, which, when executed by a processor, implements the above-mentioned smart contract data processing method for blockchain.
[0149] It should be noted that for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that this application is not limited by the order of the actions described, because according to this application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all optional embodiments, and the actions and modules involved are not necessarily required by this application.
[0150] It should be further noted that, although the various steps in the flowchart are shown in sequence as indicated by the arrows, these steps are not necessarily performed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps may be performed in other orders. Moreover, at least a portion of the steps in the flowchart may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily performed at the same time, but may be performed at different times. The execution order of these sub-steps or stages is not necessarily to be performed in sequence, but may be performed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
[0151] It should be understood that the above-described device embodiments are merely illustrative, and the device of the present application may also be implemented in other ways. For example, the division of units / modules in the above-described embodiments is merely a logical functional division, and actual implementations may employ other division methods. For example, multiple units, modules, or components may be combined or integrated into another system, or some features may be omitted or not implemented.
[0152] In addition, unless otherwise specified, the functional units / modules in the various embodiments of the present application may be integrated into a single unit / module, each unit / module may exist physically separately, or two or more units / modules may be integrated together. The aforementioned integrated units / modules may be implemented in the form of hardware or software program modules.
[0153] If an integrated unit / module is implemented in hardware, the hardware may be digital circuits, analog circuits, etc. The physical implementation of the hardware structure includes, but is not limited to, transistors, memristors, etc. Unless otherwise specified, the processor may be any appropriate hardware processor, such as a CPU, GPU, FPGA, DSP, and ASIC. Unless otherwise specified, the storage unit may be any appropriate magnetic storage medium or magneto-optical storage medium, such as resistive random access memory (RRAM), dynamic random access memory (DRAM), static random access memory (SRAM), enhanced dynamic random access memory (EDRAM), high-bandwidth memory (HBM), hybrid memory cube (HMC), etc.
[0154] If the integrated unit / module is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, 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. The computer software product is stored in a memory and includes a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned memory includes: U disk, read-only memory (ROM), random access memory (RAM), mobile hard disk, magnetic disk, or optical disk, etc., various media that can store program code.
[0155] In the above embodiments, the description of each embodiment has its own emphasis. For parts not described in detail in a particular embodiment, please refer to the relevant description of other embodiments. The technical features of the above embodiments can be combined in any way. To keep the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0156] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present application that follow the general principles of the present application and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered as exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0157] It should be understood that the present application is not limited to the exact structure described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A method for processing smart contract data for blockchain, characterized in that: include: Obtain existing smart contract data and pre-stored contract split mark data, and perform text format conversion processing based on the existing smart contract data to obtain contract text data; Perform word segmentation processing on the contract text data to obtain a contract word sequence; Performing model training on the initial model based on the contract word sequence, the basic model, and the pre-labeled contract split data to obtain a transitional natural language processing model; Using the pre-stored contract split labeled data as a validation set and a test set to perform model adjustment training on the transition natural language processing model to obtain a pre-trained natural language processing model; Obtain information on smart contract development requirements; Performing data processing on the smart contract development requirement information according to the pre-trained natural language processing model to obtain smart contract text information, and constructing a smart contract to be stored based on the smart contract text information; Input the smart contract to be stored into a pre-trained natural language processing model to obtain split contract code fragments to be stored, and determine a hash value based on each contract code fragment to be stored; Store each contract code snippet to be stored and its corresponding hash value into the blockchain storage space in turn; When a hash value is detected to exist in the blockchain storage space with the same hash value, only the hash value is stored in the blockchain storage space until the storage of the smart contract to be stored is completed; Obtaining call information for the smart contract to be stored, and performing intent recognition processing using the pre-trained natural language processing model based on the call information of the smart contract to be stored to obtain a prediction result; Determining the contract execution information of the smart contract to be stored according to the prediction result; Determine at least one hash value to be indexed based on the contract execution information; A corresponding contract code snippet is read from the blockchain storage space in sequence according to each hash value to be indexed, until the contract code snippet corresponding to the last hash value to be indexed is read. During this period, when it is detected that the hash value to be indexed is repeated with the previous hash value to be indexed, the contract code snippet corresponding to the previous hash value to be indexed can be directly called.
2. The method according to claim 1, characterized in that The text format conversion processing is performed according to the existing smart contract data to obtain the contract text data, including: Performing text recognition processing on the existing smart contract data to obtain a first vocabulary; Establishing, based on the first vocabulary and the existing smart contract data, a mapping relationship between special characters in the first vocabulary and the existing smart contract data, and a mapping relationship between keywords and data types; Each part of the existing smart contract data is traversed, and each element in the existing smart contract data is replaced with corresponding text content based on a mapping relationship between the first vocabulary and special characters in the existing smart contract data and a mapping relationship between keywords and data types to obtain contract text data.
3. The method according to claim 1, characterized in that The word segmentation processing is performed on the contract text data to obtain a contract word sequence, including: Performing identification processing on the contract text data to obtain a text format type; Selecting a target word segmentation tool from a pre-stored word segmentation tool library according to the text format type; The contract text data is segmented into word sequences consisting of words and / or tokens by the target word segmentation tool.
4. The method according to claim 1, wherein The smart contract text information includes multiple smart contract text fragments, and the multiple smart contract text fragments are sorted by contract steps; Accordingly, constructing a smart contract to be stored according to the smart contract text information includes: Performing a contract encoding operation according to the multiple smart contract text fragments to obtain multiple code fragments, wherein each code fragment has one and only one corresponding smart contract text fragment; Sort and combine all code snippets according to the contract steps to construct the smart contract to be stored.
5. The method according to claim 2, characterized in that Also includes: Regularly obtain sample data of different types of smart contracts; Perform text recognition processing on each type of smart contract sample data to obtain a corresponding second vocabulary; All second vocabulary lists are merged with the first vocabulary list to obtain an updated first vocabulary list.
6. The method according to any one of claims 1 to 5, characterized in that Also includes: Regularly obtain new smart contract creation requirement information, and perform data processing on the new smart contract creation requirement information according to the pre-trained natural language processing model to obtain new smart contract text information; Constructing a new smart contract to be stored based on the new smart contract text information; Performing contract detection on the new smart contract to be stored to obtain a detection result; The pre-trained natural language processing model is adjusted according to the detection result to obtain an adjusted pre-trained natural language processing model.
7. A smart contract data processing device for blockchain, characterized in that: include: An acquisition module is configured to: acquire existing smart contract data and pre-stored contract split-labeled data, perform text format conversion processing on the existing smart contract data to obtain contract text data; perform word segmentation processing on the contract text data to obtain a contract word sequence; train an initial model based on the contract word sequence, a basic model, and the pre-labeled contract split data to obtain a transitional natural language processing model; use the pre-stored contract split-labeled data as a validation set and a test set to perform model adjustment training on the transitional natural language processing model to obtain a pre-trained natural language processing model; and obtain smart contract development requirement information; A smart contract construction module, configured to perform data processing on the smart contract development requirement information according to the pre-trained natural language processing model to obtain smart contract text information, and to construct a smart contract to be stored according to the smart contract text information; A smart contract storage module is used to input the smart contract to be stored into a pre-trained natural language processing model to obtain split contract code fragments to be stored, and determine a hash value based on each contract code fragment to be stored; The smart contract storage module is further configured to sequentially store each contract code fragment to be stored and a corresponding hash value into the blockchain storage space; The smart contract storage module is further configured to, when detecting that a hash value exists in the blockchain storage space and the same hash value exists in the blockchain storage space, store only the hash value in the blockchain storage space until the storage of the smart contract to be stored is completed; A smart contract reading module is configured to: obtain call information for the smart contract to be stored, perform intent recognition processing using the pre-trained natural language processing model based on the call information of the smart contract to be stored, and obtain a prediction result; determine contract execution information of the smart contract to be stored based on the prediction result; and determine at least one hash value to be indexed based on the contract execution information; The smart contract reading module is further configured to sequentially read a corresponding contract code snippet from the blockchain storage space according to each hash value to be indexed, until the contract code snippet corresponding to the last hash value to be indexed is read. During this period, if it is detected that the hash value to be indexed is repeated with the previous hash value to be indexed, the contract code snippet corresponding to the previous hash value to be indexed can be directly called.
8. An electronic device, characterized in that: include: at least one processor, and a memory communicatively coupled to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 6 when executed by a processor.
10. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 6 when being executed by a processor.