A smart contract automatic generation method, management system and storage medium

By receiving contract text information and using ontology model and SWRL semantic rules, combined with LL(1) grammar syntax parser, we automatically generate smart contract codes, which solves the problem of cumbersome smart contract code generation process and insufficient platform compatibility, and achieves high efficiency The smart contract code generation and reduce the difficulty of writing and promote the promotion of blockchain technology.

CN117519667BActive Publication Date: 2024-11-01SHANGHAI JIAOTONG UNIV
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202311416825.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-30
Publication Date
2024-11-01
Estimated Expiration
2043-10-30

AI Technical Summary

Technical Problem

In the existing technology, the smart contract code generation process is complicated and the conversion platform is insufficient, making it difficult for business personnel to write smart contract codes, and text contracts fail to implement formal expression in computer languages, which has a huge gap.

Method used

By receiving contract text information, using the ontology model to convert it into a structured language, a syntax parser based on SWRL semantic rules and LL(1) grammar, automatically generates smart contract codes to realize the intelligent transformation of unstructured text to structured computer languages. , reduce writing difficulty and improve platform compatibility.

Benefits of technology

It improves the efficiency of automatic generation of smart contracts and platform compatibility, reduces the difficulty of contract writing for non-computer professionals and the labor cost of blockchain maintenance, and promotes the promotion of blockchain technology.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117519667B_ABST
    Figure CN117519667B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of blockchain technology, and in particular to a method, management system and storage medium for automatically generating smart contracts. The method first receives contract text information, and uses an ontology model to convert the contract text information into a structured language; secondly, based on a preset SWRL semantic rule, the structured language is converted into a high-level smart contract language; finally, based on a preset smart contract template, a syntax parser is used to convert the high-level smart contract language into a smart contract code, and a smart contract is automatically generated, and the syntax parser is constructed based on LL (1) grammar. Compared with the prior art, the present invention has the advantages of improving the efficiency of automatic generation of smart contracts and platform compatibility.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of blockchain technology, and in particular to a smart contract automatic generation method, management system and storage medium. Background Art

[0002] With the development and progress of blockchain technology, the core technology of blockchain, smart contracts, has attracted much attention. This technology automatically executes contracts on the blockchain in the form of code, and business personnel can realize automated transactions based on smart contracts developed by program developers. At present, the main form of smart contracts in practical applications is that business personnel manually extract information from contract texts and write them into smart contract codes. This technology involves collaboration between different fields such as computers and law, and most people in traditional professional fields lack programming skills, which is not conducive to the promotion and application of blockchain. In addition, most businesses do not realize the automatic performance function, which is specifically manifested in the failure of text-based contracts to achieve formal expression in computer language, that is, the logical relationship within the contract is not explicit; there is a huge gap between program language and contract, which makes it difficult for business personnel to write; there is a lack of intelligent conversion means between text-based contracts and executable smart contract codes. Although the existing technology has made some explorations on the automatic generation of smart contract codes, there are still problems such as the cumbersome smart contract code generation process and insufficient compatibility of the conversion platform. Summary of the invention

[0003] The purpose of the present invention is to provide a smart contract automatic generation method, management system and storage medium in order to overcome the defects of the above-mentioned prior art, such as the complicated smart contract code generation process and the insufficient compatibility of the conversion platform.

[0004] The purpose of the present invention can be achieved by the following technical solutions:

[0005] According to a first aspect of the present invention, a method for automatically generating a smart contract is provided, the method comprising the following steps:

[0006] S1, receiving contract text information, and converting the contract text information into structured language using an ontology model;

[0007] S2, based on the preset SWRL semantic rules, converting the structured language into a high-level smart contract language;

[0008] S3, based on a pre-set smart contract template, using a syntax parser to convert the high-level smart contract language into a smart contract code, and automatically generate a smart contract, wherein the syntax parser is constructed based on LL(1) grammar.

[0009] As a preferred technical solution, the conversion process of the smart contract code includes: after the syntax parser reads the SWRL semantic rules, based on the recursive descent analysis method, identifying each expression in the LL(1) grammar, and extracting corresponding instance information, condition information and conclusion information.

[0010] As a preferred technical solution, the verification process of the LL(1) grammar includes writing an initial grammar according to the SWRL semantic rules, eliminating left recursion in the initial grammar and extracting left common factors, establishing the First set and Follow set of the initial grammar, obtaining the select set, generating a corresponding prediction analysis table and performing verification.

[0011] As a preferred technical solution, the ontology model is constructed using the OWL language.

[0012] As a preferred technical solution, the feasibility of the OWL language is verified by Protégé software.

[0013] As a preferred technical solution, the construction content of the ontology model includes instance naming and attribute description.

[0014] As a preferred technical solution, the contract text information includes industry specification information.

[0015] As a preferred technical solution, after the smart contract code is deployed to the blockchain network, the cloud server calls the smart contract code to read the corresponding contract text information to achieve quality standard review.

[0016] According to a second aspect of the present invention, there is provided an intelligent contract management system, which includes a data layer, a processing layer, a functional layer and an application layer, wherein the data layer is used to receive contract text information and generate SWRL semantic rules for use by the processing layer and the functional layer; the processing layer is used to provide an ontology modeler, a high-level intelligent language parser and an intelligent contract code generator for use by the functional layer; the functional layer is used to execute the method described and to transmit data with the application layer to realize the search, editing and visualization of intelligent contracts.

[0017] According to a third aspect of the present invention, there is provided a storage medium having a program stored thereon, wherein the program implements the method described above when executed.

[0018] Compared with the prior art, the present invention has the following beneficial effects:

[0019] 1. After obtaining the high-level smart contract language based on SWRL semantic rules, the present invention directly uses the proposed semantic parser based on LL(1) grammar to automatically parse the SWRL language and generate smart contract code. The parsing and generation process does not rely on other software, the operation is convenient, and the efficiency of automatic generation of smart contracts is improved. In addition, the method can be integrated into other platforms and has high platform compatibility.

[0020] 2. The present invention utilizes the ontology model, SWRL semantic rules and the designed semantic parser to realize the conversion between unstructured contract text language, structured computer language, high-level smart contract language and smart contract code, further improving the intelligence level of smart contract code generation, reducing the difficulty of contract writing for non-computer professionals and the labor cost of blockchain maintenance, and reducing the obstacles to the promotion of blockchain technology. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 It is a schematic diagram of the process of the present invention;

[0022] Figure 2 Schematic diagram of the implementation process of the method of the embodiment of the present invention;

[0023] Figure 3 A schematic diagram of constructing an ontology model in an embodiment of the present invention;

[0024] Figure 4 The figure is a schematic diagram of the application system structure of the method according to the embodiment of the present invention. DETAILED DESCRIPTION

[0025] The present invention is described in detail below in conjunction with the accompanying drawings and specific embodiments. This embodiment is implemented based on the technical solution of the present invention, and provides a detailed implementation method and specific operation process, but the protection scope of the present invention is not limited to the following embodiments.

[0026] Example

[0027] This embodiment provides a method for automatically generating a smart contract. The method designs a syntax parser based on LL(1) grammar, uses recursive descent analysis to perform syntax analysis on SWRL (Semantic Web Rule Language) semantic rules, obtains contract rule information, and generates a smart contract corresponding to the contract text in combination with a smart contract template. Figure 1 As shown, the method specifically comprises the following steps:

[0028] Step S1, receiving contract text information, and converting the contract text information into structured language using the ontology model. For example, receiving the review rule information of ready-mixed concrete, using OWL (Ontology Web Language) to build a corresponding ontology model for this information, so as to convert the unstructured, natural language described contract text into a structured, clear computer-readable (computer-understandable and processable) contract. The main purpose of ontology model construction is to achieve the structuring of the contract text, but it is impossible to express the specific rule information in the contract as computer-readable instructions.

[0029] Step S2: based on the preset SWRL semantic rules, the structured language is converted into a high-level smart contract language. Specifically, on the basis of constructing the ontology model, the SWRL semantic rules are used to express the rule information in the contract text.

[0030] Step S3, based on the pre-set smart contract template, using the syntax parser built based on LL(1) grammar, converts the high-level smart contract language into smart contract code and automatically generates the smart contract. In other words, in order to further realize the computer readability of SWRL semantic rules, it is necessary to design a syntax parser based on LL(1) grammar. The design process includes writing the corresponding initial grammar according to the SWRL semantic rules, eliminating the left recursion in the initial grammar and extracting the left common factor, establishing the First set and Follow set of the initial grammar, obtaining the select set, generating the corresponding prediction analysis table, and then verifying whether the grammar is LL(1) grammar. The reason for the need for verification is that only when the LL(1) grammar is satisfied can the recursive descent method be used for semantic analysis. Among them, the First set and the Follow set are shown in Table 1, and the prediction analysis table is shown in Table 2.

[0031] When the initial grammar satisfies the LL(1) grammar, the recursive descent method is used to realize the recognition of the grammar and write a syntax parser based on the verified LL(1) grammar. Then, based on the smart contract template created by the user and the output of the syntax parser, the smart contract code corresponding to the contract text is obtained.

[0032] Table 1 First set and Follow set

[0033]

[0034] Table 2 Prediction analysis table

[0035]

[0036]

[0037] The method proposed in this embodiment is applied to the quality acceptance of ready-mixed concrete. The implementation process is as follows: Figure 2 The specific description is as follows:

[0038] First, implement the aforementioned step S1, construct an ontology model of the concrete quality specification through the OWL language, and convert the contract text expressed in natural language into a structured contract to improve the efficiency of knowledge utilization and dissemination. Specifically, relevant professionals need to construct an ontology model of the concrete quality specification in combination with actual needs and conditions. The specific construction content mainly includes the naming of the instance, the description of all object properties of the instance, the description of data properties, and other related descriptions, so as to obtain a complete instance. Use the OWL language to implement the ontology model, and use the Protégé software to verify the feasibility of the OWL language corresponding to the ontology. Figure 3 As shown, the construction content of the ontology includes acceptance objects, construction methods, stages, quality constraints, quality problems and solutions.

[0039] Secondly, the above step S2 is implemented to express the corresponding concrete quality specification based on the SWRL semantic rules to obtain a high-level smart contract language. The application of the high-level smart contract language can reduce the difficulty of contract writing for non-computer personnel and reduce the learning cost of relevant business personnel. Specifically, based on the constructed OWL ontology, the corresponding concrete quality specification is explained by comparing it with the expression in the SWRL semantic rules. For example Figure 4 An example of a corresponding ontology is given in : Ready-mixed concrete order 1 is delivered by pumping (Constructed By). During the on-site acceptance stage (has Stage), three quality constraints need to be met, namely, strength is 60 (has Strength), slump is 150 (has Slump), and chloride ion content is less than 0.2 (has Chlorine). The quality problem (has Hazard) found during the actual acceptance is that the measured slump is too small, and the corresponding solution (has Solution) is to add a water reducer.

[0040] Next, the aforementioned step S3 is implemented, and the developed syntax parser is used to realize the conversion of high-level smart contract language into executable smart contract code. The syntax parser first reads the written SWRL semantic rules, and then parses them according to the LL(1) grammar that can parse the SWRL language. The application of this syntax parser can realize the automatic generation of high-level smart contract language into executable smart contract code, reducing the manpower cost of blockchain maintenance. Specifically, the SWRL language is identified as tokens (the basic components of the SWRL language), and according to the LL(1) grammar, the recursive descent analysis method is used. After successfully identifying each expression in the LL(1) grammar, the instance name in the SWRL semantic rule, the attribute name and value of the condition, and the attribute name and value of the conclusion can be extracted. On this basis, the final smart contract is automatically generated according to the constructed smart contract template and the key information extracted by the syntax parser.

[0041] Next, use chaincode to deploy the smart contract code to Hyperledger Fabric (hyperledger network, hereinafter referred to as Fabric network). Chaincode is a general container for deploying code to the Fabric blockchain network. Specifically, it includes:

[0042] Chaincode packaging step: In the Fabric network, after the chaincode is compiled, it needs to be packaged into a package ending with .out or .cc for use by other peer nodes. The packaging process first requires entering the organization's client container and packaging the chaincode directory into a .out file.

[0043] In the proposal construction and sending steps, the client first executes the chaincode installation command, creates the proposal structure, signs, and sends the proposal to the endorsing node.

[0044] The legitimacy verification step is when the endorsement node verifies the legitimacy of the proposal. The endorsement node verifies the proposal for chaincode installation and approves it on behalf of the organization. Once all organizations have approved it, the chaincode can be installed on the channel.

[0045] In the proposal submission step, one of the organizations submits the chaincode proposal, and the chaincode is successfully installed in the Fabric network.

[0046] After completing the above-mentioned smart contract code deployment process, the cloud server can call the smart contract code in the Fabric network to write the data in the memory to the Fabric network, or call the smart contract code to read the data in the Fabric network, and implement relevant quality specification reviews. Specifically, when data needs to be written to the Fabric network, first call the relevant function in the smart contract code and use the data to be written as a parameter. The Fabric network will execute the relevant code of the smart contract and reach a consensus on the execution results. If the consensus is successful, the new data will be written to the block of the Fabric network for broadcast. After the updated data is written to the Fabric network, the relevant data information can be read by calling the query code related to the smart contract. From a program point of view, the above process specifically includes:

[0047] (1) The client creates a transaction proposal (chain code function and parameters, where the parameters are concrete attributes and corresponding values) and sends it to the endorsing node;

[0048] (2) The endorsing node executes the chaincode, generates a set of read and write operations based on the read and written keys, and returns the proposal result to the client;

[0049] (3) The client submits the transaction to the sorting service. The transaction content contains the read and write operation set from the proposal result.

[0050] (4) The sorting service encapsulates the sorted transactions into blocks;

[0051] (5) The block will be sent to the Commit Peer node;

[0052] (6) The Commit Peer node runs the verification logic, adds the block to the blockchain in memory or on the file system, and writes the valid transactions in the block to the state database;

[0053] (7) After the concrete-related attributes are written, the smart contract code related to the quality specification review in the chain code will be triggered, which will modify the relevant attribute values ​​in the smart contract. The result of the quality specification review (whether it is compliant and the solution) can be known through the attribute values.

[0054] Furthermore, the above method can also be combined with contract management and integrated into the smart contract automatic generation and management system as different functional modules. Figure 4As shown in the figure, based on the proposed smart contract automatic generation method, a smart contract automatic generation and management system based on the proposed method can be designed. The various layers involved in the operation of the system include the application layer, the functional layer (the functions that the smart contract generation and management system should include in the process of building the smart contract generation and management system), the processing layer, and the data layer. The specific functions and specific composition of each layer are as follows:

[0055] The data layer receives and provides the data sources required by the system, mainly including "contract text", "industry specifications" and other types of file texts, which are used to generate SWRL semantic rules.

[0056] The processing layer includes three components: "ontology modeler", "high-level intelligent language parser" and "smart contract code generator". The "ontology modeler" is used to implement the program of building ontology model through OWL language; the "high-level intelligent language parser" is a tool for grammatical and semantic analysis of the programming language involved in smart contracts; the "smart contract code generator" is used to receive the "structured ontology" edited and generated by the user and generate smart contracts. This function is used by the "functional layer".

[0057] The functional layer includes six functions: "Contract ontology creation", "Advanced smart contract writing guide", "Contract automatic generation", "Contract debugging and compilation", "Contract preview" and "Contract installation and instantiation". "Contract ontology creation" means that users can edit SWRL semantic rules through the "Smart Contract IDE" (Integrated Development Environment) of the "Application Layer" to convert unstructured contract text into a structured ontology. "Advanced smart contract writing guide" refers to the SWRL semantic rules and smart contract editing tips displayed in the blank space in the "Smart Contract IDE" interface of the "Application Layer" to provide users with a simple tutorial. "Contract automatic generation" means that the "Processing Layer" will generate and create smart contracts based on the "structured ontology" created by the user. "Contract preview" means that users can view the specific contents of various structured ontologies and smart contracts that have been created by accessing the Web page of the "Application Layer". "Contract installation and instantiation" means that users can install and deploy the smart contracts generated by the "Contract automatic generation" function to the blockchain by accessing the Web page of the "Application Layer".

[0058] The application layer includes two functions: "smart contract IDE" and "contract management". In this embodiment, the smart contract IDE is implemented based on the open source project Monaco-editor, and the contract management function is implemented based on the MySQL database and the jsp-based Web page.

[0059] The system can achieve the following functions:

[0060] (1) In the smart contract IDE, write a natural language-like contract text based on SWRL semantic rules;

[0061] (2) After the contract text based on SWRL semantic rules is stored in the database, the contract text is converted into a smart contract using a syntax parser and stored in the database;

[0062] (3) Provide a labeling function for the contract text generated by the user. The user can create custom labels on the front-end interface of the system and label the contract text according to the labels.

[0063] The above system includes two applications: smart contract IDE and contract management. Smart contract IDE can realize multiple functions such as smart contract writing, compilation, debugging, etc., and improve the writing efficiency of advanced smart contracts; contract management application can realize the search, editing and visualization of smart contracts, which is convenient for later maintenance.

[0064] Further, the present embodiment also provides a storage medium on which a program is stored, and the aforementioned method is implemented when the program is executed. The program code for implementing the method of the present invention can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code can be executed entirely on the machine, partially on the machine, partially on the machine as an independent software package and partially on a remote machine or completely on a remote machine or server. In the context of the present invention, a computer-readable medium can be a tangible medium that can contain or store a program for use by an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the above. More specific examples of machine-readable storage media would include electrical connections based on one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), optical fibers, a portable compact disk-read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0065] The preferred specific embodiments of the present invention are described in detail above. It should be understood that a person skilled in the art can make many modifications and changes based on the concept of the present invention without creative work. Therefore, any technical solution that can be obtained by a person skilled in the art through logical analysis, reasoning or limited experiments based on the concept of the present invention on the basis of the prior art should be within the scope of protection determined by the claims.

Claims

1. A method for automatically generating a smart contract, characterized in that: The following steps are involved: S1, receiving the contract text information, constructing an ontology model for the concrete quality specification, and converting the contract text information expressed in natural language into structured language; the specific construction content includes the naming of the instance, the description of all object attributes of the instance, and the description of data attributes, so as to obtain a complete instance including the acceptance object, construction method, stage, quality constraint, quality problem and solution; S2, based on the preset SWRL semantic rules, converting the structured language into a high-level smart contract language; wherein step S2 specifically includes: on the basis of the constructed ontology model, comparing the expression in the SWRL semantic rules to explain the corresponding concrete quality specification; S3, based on a preset smart contract template, using a syntax parser to convert the high-level smart contract language into smart contract code, and automatically generate a smart contract, wherein the syntax parser is constructed based on the LL(1) grammar; wherein step S3 specifically includes: the syntax parser first reads the written SWRL semantic rules, and then parses them according to the LL(1) grammar that can parse the SWRL language; the SWRL language is identified as tokens, and after successfully identifying each expression in the LL(1) grammar using a recursive descent analysis method according to the LL(1) grammar, the instance name in the SWRL semantic rule, the attribute name and value of the condition, and the attribute name and value of the conclusion are extracted; The design process of the grammar parser includes: writing an initial grammar according to the SWRL semantic rules, eliminating left recursion in the initial grammar and extracting left common factors, establishing the First set and Follow set of the initial grammar, obtaining the select set, generating a corresponding prediction analysis table and verifying it; the prediction analysis table contains different non-terminal symbols: <rule-seq> 、 <rule> 、 <condition> 、 <instance> 、 <objproperty-seq> 、 <objproperty> 、 <dataproperty-seq> 、 <dataproperty>、<operation_seq>、 <operation> 、 <operator> 、 <conclusion> 、 <name> 、 <var>、 <value> ; and, a plurality of different input symbols corresponding to the non-terminal symbols; when the initial grammar satisfies the LL(1) grammar, a recursive descent method is used to realize the recognition of the grammar and write a syntax parser based on the verified LL(1) grammar.< / value> < / var> < / name> < / conclusion> < / operator> < / operation> < / dataproperty> < / dataproperty-seq> < / objproperty> < / objproperty-seq> < / instance> < / condition> < / rule> < / rule-seq> 2. The method for automatically generating a smart contract according to claim 1, characterized in that: The ontology model is constructed using the OWL language.

3. The method for automatically generating a smart contract according to claim 2, characterized in that: The feasibility of the OWL language is verified by Protégé software.

4. The method for automatically generating a smart contract according to claim 1, characterized in that: The contract text information includes industry standard information.

5. The method for automatically generating a smart contract according to claim 1, characterized in that: After the smart contract code is deployed to the blockchain network, the cloud server calls the smart contract code to read the corresponding contract text information to achieve quality standard review.

6. A smart contract management system, characterized in that: The system includes a data layer, a processing layer, a functional layer and an application layer. The data layer is used to receive contract text information and generate SWRL semantic rules for use by the processing layer and the functional layer; the processing layer is used to provide an ontology modeler, a high-level intelligent language parser and an intelligent contract code generator for use by the functional layer; the functional layer is used to execute the method described in any one of claims 1 to 5, and to transmit data with the application layer to realize the search, editing and visualization of intelligent contracts.

7. A storage medium having a program stored thereon, characterized in that: When the program is executed, the method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Intelligent contract vulnerability checking method, system and medium

    CN110399730A

  • Secure translation and analysis method for Ethereum Solidy intelligent contract

    CN110688151A

  • Intelligent contract generation method and device for constructional engineering quality acceptance

    CN113191629A

  • System and a method for automatic generation of smart contracts across blockchain platforms

    US20230072988A1