Smart contract generation and execution method and device, equipment and medium
By building a natural language understanding model and automatically generating smart contract code, the problem of inefficient and prone to errors in smart contract generation is solved, and efficient and reliable smart contract generation and execution is achieved.
Patent Information
- Application Number
- CN202411512352.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-28
- Publication Date
- 2025-02-14
AI Technical Summary
The generation process of smart contracts in the prior art relies on manual code writing, lack of automation support, resulting in inefficient contract generation and prone to syntax and logic errors.
By collecting transaction behavior data and transaction requirements data of smart contract participants, building a natural language understanding model, generating a natural language description of the contract, parsing it into smart contract code, performing grammatical and logical verification, and finally on the blockchain Execute the contract code and record the execution process and results.
The automatic generation of smart contracts is realized, which reduces the requirements for programming capabilities, improves the efficiency of contract generation, ensures the accuracy and reliability of contracts, and improves the transparency of transactions and data security by recording execution processes and results. .
Smart Images

Figure CN119440486A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of artificial intelligence technology and financial technology, and in particular to a smart contract generation and execution method, device, equipment and storage medium. Background Art
[0002] With the rapid development of blockchain technology, the financial sector has gradually adopted blockchain as a data storage and transaction platform. The decentralized nature of blockchain can ensure the security and transparency of transactions, while providing tamper-proof distributed ledger records. This makes blockchain an important tool for ensuring the security of financial transactions. In addition, the emergence of smart contracts has further promoted the application of automated transactions. Smart contracts can automatically execute specific financial transactions on the blockchain by writing preset conditions, reducing manual intervention in the middle and improving transaction efficiency.
[0003] However, most current smart contracts rely on programming languages to be written, and developers usually write the contract logic manually. This approach requires not only a high level of mastery of blockchain programming languages (such as Solidity, etc.), but also a deep understanding of financial transaction logic. Most financial institutions’ participants lack programming skills, making the generation and application of contracts complex and time-consuming.
[0004] In the prior art, the generation process of smart contracts usually cannot automatically generate contract descriptions dynamically based on transaction data and requirements. Participants need to manually write or modify contract codes, which increases the risk of errors, especially when dealing with complex financial transactions. This approach leads to inefficient contract generation and is difficult to adapt to high-frequency and complex financial transaction scenarios. Summary of the invention
[0005] The main purpose of the present invention is to provide a smart contract generation and execution method, device, equipment and storage medium, aiming to solve the technical problems in the prior art that the generation process of smart contracts relies on manual code writing and lacks automation support, resulting in low contract generation efficiency and prone to grammatical and logical errors.
[0006] To achieve the above objectives, the present invention provides a smart contract generation and execution method, comprising:
[0007] Collect transaction behavior data and transaction demand data of smart contract participants;
[0008] Building a natural language understanding model for contract generation based on the transaction behavior data and transaction demand data;
[0009] Obtaining contract requirements, and using the natural language understanding model to generate a natural language description of the contract based on the contract requirements;
[0010] Parsing the natural language description of the contract and converting it into smart contract code;
[0011] Performing syntax and logic verification on the smart contract code in the distributed node network of the blockchain;
[0012] When syntax and logic verification pass, the smart contract code is executed;
[0013] The execution process and results of the smart contract code are recorded in the distributed ledger of the blockchain.
[0014] Furthermore, to achieve the above-mentioned purpose, the present invention provides a smart contract generation and execution device, comprising:
[0015] Data collection module, used to collect transaction behavior data and transaction demand data of smart contract participants;
[0016] A model building module, used to build a natural language understanding model for contract generation based on the transaction behavior data and transaction demand data;
[0017] A contract generation module, used to obtain contract requirements and generate a natural language description of the contract based on the contract requirements using the natural language understanding model;
[0018] A code generation module, used to parse the natural language description of the contract and convert it into smart contract code;
[0019] A code verification module, used to perform syntax and logic verification on the smart contract code in a distributed node network of the blockchain;
[0020] A contract execution module, used to execute the smart contract code when syntax and logic verification pass;
[0021] The recording and storage module is used to record the execution process and execution results of the smart contract code in the distributed ledger of the blockchain.
[0022] Furthermore, to achieve the above-mentioned purpose, the present invention also provides a computer device, which includes a memory, a processor, and a smart contract generation and execution program stored in the memory and executable on the processor, and the smart contract generation and execution program, when executed by the processor, implements the steps of the smart contract generation and execution method as described above.
[0023] Furthermore, to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium, on which a smart contract generation and execution program is stored, and when the smart contract generation and execution program is executed by a processor, the steps of the smart contract generation and execution method as described above are implemented.
[0024] Beneficial effects: The present invention relates to the fields of artificial intelligence technology and financial technology, and discloses a method for generating and executing a smart contract. By collecting transaction behavior data and transaction demand data of smart contract participants, a natural language understanding model is constructed based on the collected data, contract requirements are obtained and a natural language description of the contract is generated, the generated natural language description of the contract is parsed and converted into a smart contract code, the smart contract code is subjected to syntax and logic verification, the smart contract code that has passed the verification is executed, and the execution process and execution results are recorded in the distributed ledger of the blockchain. The present invention reduces the requirements for the programming ability of the participants by automatically generating smart contracts, and solves the problem that the writing of smart contracts in the prior art is inefficient and prone to errors. By introducing syntax and logic verification steps, the accuracy of the smart contract before execution is ensured, and potential risks caused by contract logic errors are avoided. At the same time, by recording the contract execution process and results in the distributed ledger of the blockchain, the transparency of the transaction and the security of the data are improved, data tampering is effectively prevented, and the generation efficiency and execution reliability of the smart contract are significantly improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] The present invention will be further described below with reference to the accompanying drawings and embodiments, in which:
[0026] Figure 1 A schematic diagram of an application environment of a smart contract generation and execution method in one embodiment of the present invention;
[0027] Figure 2 A flowchart of an embodiment of a method for generating and executing a smart contract according to the present invention;
[0028] Figure 3 A schematic diagram of the functional modules of a preferred embodiment of the smart contract generation and execution device of the present invention;
[0029] Figure 4 A schematic diagram of the structure of a computer device in one embodiment of the present invention;
[0030] Figure 5 FIG. 4 is another schematic diagram of the structure of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION
[0031] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0032] The smart contract generation and execution method provided by the embodiment of the present invention can be applied in Figure 1In the application environment of , the user end communicates with the server end through the network. The server end can collect the transaction behavior data and transaction demand data of the smart contract participants through the user end, build a natural language understanding model based on the collected data, obtain the contract requirements and generate a natural language description of the contract, parse the generated natural language description of the contract and convert it into a smart contract code, perform syntax and logic verification on the smart contract code, execute the verified smart contract code, and record the execution process and execution results in the distributed ledger of the blockchain. The present invention reduces the requirements for the programming ability of the participants by automatically generating smart contracts, and solves the problem that the smart contract writing efficiency is low and prone to errors in the prior art. By introducing syntax and logic verification steps, the accuracy of the smart contract before execution is ensured, and the potential risks caused by contract logic errors are avoided. At the same time, by recording the contract execution process and results in the distributed ledger of the blockchain, the transparency of the transaction and the security of the data are improved, data tampering is effectively prevented, and the generation efficiency and execution reliability of the smart contract are significantly improved. Among them, the user end can be but not limited to various personal computers, laptops, smart phones, tablet computers and portable wearable devices. The server end can be implemented with an independent server or a server cluster composed of multiple servers. The present invention is described in detail below through specific embodiments.
[0033] See also Figure 2 , Figure 2 A flowchart of an embodiment of a method for generating and executing a smart contract provided by the present invention. It should be noted that although a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than that shown here.
[0034] like Figure 2 As shown, the smart contract generation and execution method proposed in the present invention includes the following steps:
[0035] S10, collect transaction behavior data and transaction demand data of smart contract participants;
[0036] In this embodiment, transaction behavior data refers to the specific behavior records of smart contract participants in past transactions, including but not limited to transaction time, transaction amount, transaction type, assets involved, accounts or information of both parties to the transaction. Through these data, the trading habits, risk preferences and transaction patterns of the participants can be judged, providing a basic basis for generating smart contracts that meet their needs.
[0037] Transaction behavior data can be collected through connecting with financial institutions, trading platforms, historical transaction records on the blockchain, etc. The collection process can be automatically extracted from banking systems, exchanges, blockchain nodes, etc. through API interfaces, or retrieved through the platform's internal record system.
[0038] The collected transaction behavior data may exist in various forms (such as JSON, XML, etc.), and should be formatted during the data collection process to facilitate subsequent data analysis and contract generation. Data from different sources can be managed uniformly through standardized data formats (such as structured transaction record tables).
[0039] The collected data may contain noise and duplicate records, and data cleaning operations are required to ensure the completeness and accuracy of transaction data. For example, the system can remove duplicate transaction records, fill in missing data fields, and correct erroneous data.
[0040] Transaction demand data refers to the specific needs of smart contract participants for future transactions. This includes requirements for contract terms, such as fund transfer, execution conditions, asset delivery, transaction time nodes, etc. These demand data are the core information source for generating personalized smart contracts.
[0041] Transaction demand data is usually provided by the participants, and the system can collect the participants' input through user interface interaction. The participants can provide their transaction requirements by filling out forms or selecting predefined templates. The demand data can also come from the participants' business documents (such as contracts, orders, etc.) or existing demand systems.
[0042] In order to simplify the demand input of the participants, the system can design a user-friendly interactive interface, provide selectable demand options and drop-down menus to help users define transaction parameters. The automated recommendation system can automatically fill in some demand items based on the historical transaction behavior of the participants, reducing the complexity of user input.
[0043] The system will verify the input transaction demand data to ensure its integrity and logic. For example, the scope of the amount of funds, the validity of the transaction time, etc. will be verified through logical checks at the input stage to avoid non-compliant clauses when the contract is generated later.
[0044] Example: In the financial sector, a bank provides its corporate customers with automated contract generation services based on blockchain. The bank automatically obtains customers' past transaction behavior data by integrating its internal transaction system, including detailed information such as the time, amount, and transaction parties of each transaction. In addition, the bank also allows customers to submit their future financial transaction needs, such as the amount, interest rate, and repayment time of the loan contract, through an interactive platform. Based on the collected data, the system automatically generates smart contract terms and verifies its logic to ensure the validity and contractuality of the contract.
[0045] By automatically collecting the transaction behavior data and transaction demand data of smart contract participants, the complexity of manual input and processing is avoided, and the efficiency and accuracy of data collection are improved. Through data cleaning and standardization, the integrity and consistency of the collected transaction behavior data are ensured, providing a reliable data foundation for subsequent contract generation.
[0046] S20, constructing a natural language understanding model for contract generation based on the transaction behavior data and the transaction demand data;
[0047] In this embodiment, the natural language understanding model is based on the transaction behavior data and transaction demand data of the participants, and can understand and process natural language input, and generate smart contract terms that meet the financial business scenarios according to the needs of the participants. The natural language understanding model uses deep learning algorithms to learn the language structure, semantics and business logic in the financial field to ensure that the generated contract terms meet industry standards.
[0048] Transaction behavior data (such as transaction history, transaction amount, account information) and transaction demand data (such as specific contract terms, execution conditions, transaction time, etc.) will be used as input data for the model to train the model to understand the needs of the participants.
[0049] The output generated by the model is a natural language description of the contract, which can be executable contract terms that clearly express the responsibilities, obligations and execution conditions of the parties to the contract.
[0050] Before building a model, the transaction behavior data and transaction demand data need to be preprocessed. This includes data cleaning (removing noise data), data annotation (providing labels for training data), and format conversion (converting data into a format recognizable by the model). For example, format historical transaction records into standard financial transaction fields and annotate transaction types and key parameters.
[0051] Convert the contract requirement data entered by the user into a standard language structure to make it suitable for model training.
[0052] You can use existing pre-trained natural language processing models (such as BERT, GPT), which have been trained on large-scale corpora and have good natural language understanding capabilities. On this basis, fine-tuning is performed on data in the financial field to make the model more suitable for generating financial contract terms.
[0053] The labeled transaction behavior data and transaction demand data are input into the natural language understanding model for training. Through supervised learning methods, the model can learn how to convert transaction demand data into natural language descriptions of contract terms. During the training process, cross-validation techniques in machine learning can be used to evaluate the accuracy of the model, adjust the model's learning rate, parameters, and number of training rounds to achieve optimal model performance.
[0054] Fine-tuning refers to retraining a pre-trained natural language model (such as BERT, GPT) on data from a specific field, so that the model can understand the terminology and language style of a specific field. For the financial field, the fine-tuning process is crucial because financial contracts have their own specific language structure and legal requirements.
[0055] Create annotated datasets for model fine-tuning based on actual contracts and transaction records in the financial industry. These datasets should cover common terms and terminology of financial contracts, as well as various transaction scenarios. Through annotation by financial experts, the datasets are classified into different contract terms to ensure the high quality of the training set.
[0056] Model fine-tuning is achieved by adjusting the parameters of the pre-trained model, and the model will learn specific language features in the financial field. This process can be accelerated using GPU or TPU, reducing training time, and adjusting the convergence speed of the model through dynamic learning rate.
[0057] The natural language understanding model generates a natural language description of the contract by analyzing the transaction behavior data and transaction demand data of the parties involved. These descriptions cover information such as the terms of the contract, execution conditions, and responsibilities of the parties involved. This description ensures that the semantics of the contract are accurate and the terms are clear, making it easier for all parties to understand and execute the contract.
[0058] After obtaining the transaction requirements of the participants, the model converts the requirements into corresponding contract terms. These terms are based on standard legal language to ensure that they are legally effective in contract execution. The model generates a natural language description of the contract layer by layer through a multi-layer neural network to ensure the correctness of its grammar and logic.
[0059] The generated contract description can be automatically saved in an editable text format (such as TXT, DOCX, etc.), or directly converted into executable smart contract code. These descriptions can be further manually reviewed and modified to ensure that they meet specific business needs.
[0060] Example: In a financial scenario, a bank uses a natural language understanding model based on customer transaction behavior data and demand data to generate a loan contract for a customer. The model automatically generates loan contract terms that meet customer needs by analyzing the customer's past loan records, repayment habits, and input requirements (such as loan amount, number of repayment periods, etc.). For example, a customer's demand is a loan of 300,000 yuan, with an interest rate of 4% and a repayment period of 5 years. The contract terms generated by the model clearly list the loan amount, repayment plan, and corresponding interest rate terms.
[0061] By building a natural language understanding model based on the transaction behavior data and transaction demand data of the participants, it is possible to automatically generate a natural language description of the contract that meets the needs of the participants, greatly reducing the time and complexity of contract writing. At the same time, by fine-tuning the natural language model, it can generate contracts with strong legal effect and clear terms in the financial field, ensuring the accuracy and enforceability of the contract.
[0062] S30, obtaining contract requirements, and using the natural language understanding model to generate a natural language description of the contract according to the contract requirements;
[0063] In this embodiment, contract requirements refer to the specific requirements of the smart contract terms proposed by the participants, including execution conditions, transaction amounts, asset types, delivery methods, time nodes, etc. These requirements constitute the core input for generating contract content, ensuring that the generated contract meets the business needs of the participants.
[0064] Participants can input contract requirements through the interactive interface. The system guides participants to fill in necessary information through preset input fields or templates to reduce input errors.
[0065] When receiving a contract request, the system performs preliminary data validation to ensure that all necessary fields have been filled in and that the format and content of the data meet the basic requirements of the contract terms.
[0066] The system provides a user-friendly interface that allows participants to select predefined contract templates or create contracts from scratch. Input fields are provided on the interface, and participants can fill in specific contract requirements, such as amount, assets, execution conditions, time frame, etc.
[0067] If the parties are not familiar with the contract terms, they can select an existing contract template and the system will guide the parties to fill in or adjust the personalized terms based on the template.
[0068] After obtaining user input, the system automatically performs formatting, such as unifying the currency unit, to ensure data consistency and contract standardization.
[0069] Based on the pre-trained natural language processing (NLP) model, the system can understand the contract requirements of the parties and generate a natural language description of the contract terms. The model converts the transaction requirements entered by the user into appropriate legal terms by learning the grammar and logical structure of the contract language.
[0070] The contract requirements provided by the participants serve as the input of the model. The model will analyze the requirements and generate legal and compliant contract terms based on existing contract templates or generation rules.
[0071] The output of the natural language understanding model is a natural language description of the contract, including the responsibilities, obligations, asset transfer and other terms of the parties involved, to ensure that these terms can be correctly interpreted and executed when the contract is executed.
[0072] The model generates a corresponding natural language description based on the input content of the contract requirements (such as funds, execution conditions, time, etc.). For example, if the participant inputs the requirement of "paying RMB 500,000 within 3 months", the model will generate the following contract terms: "Party A shall pay Party B RMB 500,000 within 10 days after the signing of the contract, and Party B shall complete the delivery within 3 months after receiving the payment."
[0073] By extracting features from the user's input requirements, the natural language understanding model automatically generates complete contract terms that match the input requirements. The generation process uses the deep learning model's understanding of financial contract terms to ensure that the legal language of the contract is accurate and rigorous.
[0074] The contract terms generated by the system can be automatically saved in an editable text format (such as DOCX, PDF) to facilitate review and signing by the participating parties.
[0075] After generating the contract terms, the system will perform a logical check to ensure that there are no conflicts between the terms. Especially when multiple execution conditions and time nodes are involved, the model will automatically detect whether the relationship between the terms is reasonable.
[0076] After the contract terms are generated, the system will also perform a consistency check to ensure that the descriptions of all terms meet the requirements of the parties involved and that there are no conflicts between different terms.
[0077] The system integrates automated verification tools and uses a rule-based engine to check whether the generated contract terms meet the business logic, such as the rationality of payment terms, delivery conditions, funds flow, etc.
[0078] If logical errors or clause conflicts are found during the verification process, the system will provide real-time feedback to users and make modification suggestions. For example, if the delivery time conflicts with the payment time, the system will prompt the parties to modify these time clauses to ensure smooth contract execution.
[0079] Example: In the financial sector, an investment company needs to generate a customized asset management contract for its clients. The company inputs the client's asset management requirements through the system interface, including the types of assets to be managed, the amount distribution, the management period, and the return target. The natural language understanding model generates an asset management contract with a natural language description of all key terms based on these requirements. The contract describes the company's management responsibilities for different asset categories, profit distribution rules, and return targets.
[0080] By automatically obtaining the contract requirements of the participants and using the natural language understanding model to generate the corresponding natural language description of the contract, the difficulty and error rate of manually writing contracts are greatly reduced. The system can ensure that the generated contract terms meet the specific needs of the participants and ensure the rigor and consistency of the contract terms through automated logic verification. At the same time, the participants can easily enter the contract requirements through the interactive interface, which significantly improves the efficiency and accuracy of smart contract generation.
[0081] S40, parsing the natural language description of the contract and converting it into smart contract code;
[0082] In this embodiment, the parsing of the natural language description refers to converting the contract terms generated by the natural language understanding model into structured data forms (such as variables, conditions, etc.). These structured data can be mapped to the code logic of the smart contract to ensure that the semantics of the contract terms can be executed by computers.
[0083] The system uses natural language processing tools to parse the generated contract terms and extract key elements involved in the contract, such as execution conditions, payment amounts, parties involved, etc. The parsed results will be converted into standardized fields for code generation.
[0084] Smart contract code conversion refers to converting the parsed contract structured data into smart contract code. The code is a programming language that can be executed on the blockchain platform, such as Solidity or other smart contract languages.
[0085] The system selects the applicable smart contract code template based on the parsing results and fills in the relevant variables and logic (such as payment amount, execution conditions). The template contains the basic contract structure, such as functions and trigger conditions. The system dynamically matches the contract terms with the logic of the code template and automatically generates a complete smart contract code.
[0086] The generated smart contract code is automatically generated code that contains the contract clause execution logic. This code will be used to deploy and execute the smart contract on the blockchain.
[0087] The system aggregates the filled templates and generates an executable contract code file. This file can be directly uploaded to the blockchain platform for compilation and deployment to ensure that the contract can be automatically executed when the conditions are met.
[0088] Through the above steps, the system can automatically convert natural language contract descriptions into smart contract codes, avoiding the complexity and potential errors of manual code writing and simplifying the contract generation process.
[0089] S50, performing syntax and logic verification on the smart contract code in a distributed node network of the blockchain;
[0090] In this embodiment, the distributed node network of the blockchain refers to a network composed of multiple decentralized nodes, each of which can independently verify the content, logic and execution results of the smart contract. The decentralized nature of the blockchain network ensures the transparency and reliability of the contract verification process and avoids single point failure problems.
[0091] In a distributed network, nodes verify the deployment, execution, and status updates of smart contracts through consensus mechanisms (such as PoW, PoS, etc.). Each node performs verification operations independently to ensure the legitimacy of the contract code. Blockchain nodes run verification tools for smart contract code, such as compilers for Solidity code, to ensure that the code can be parsed normally and meets the execution requirements of the blockchain.
[0092] Syntax verification refers to checking whether the smart contract code complies with the syntax rules of the programming language to ensure that the code can be compiled correctly and deployed in the blockchain network. Syntax verification can prevent the contract from being unable to execute due to spelling errors, format errors, or undeclared variables.
[0093] Use a blockchain platform-specific compiler (such as Solidity's compiler solc) for syntax checking. Before the contract code is deployed, it is first compiled by the compiler to ensure that the code syntax is correct. If a syntax error is found, the system will return an error message to prompt the developer to make changes. The compiler will detect syntax errors such as undefined variables, bracket matching problems, function call errors, etc.
[0094] Logic verification refers to checking whether the logic in the smart contract is reasonable and whether it conforms to the expected execution process to avoid logical loopholes or potential attack risks. For example, check whether the conditional judgment, loop structure, and state update in the contract conform to the set business logic.
[0095] The system will analyze the logic of the contract code through static analysis tools or formal verification tools. For example, use smart contract analysis tools such as Slither or MythX to detect logical vulnerabilities in smart contract code (such as reentrancy attacks, integer overflows, and conditions that are always true).
[0096] Logical verification also includes checking business logic, for example, checking whether the payment is triggered correctly, whether the contract status update is reasonable, etc. The system simulates the execution process of the smart contract to ensure that the contract can be executed as expected under different conditions.
[0097] The distributed nodes of the blockchain jointly participate in the contract verification process through the consensus mechanism. Each node will run the contract code independently and reach a consensus with other nodes through the verification results. The consensus process ensures the credibility of the contract code and execution.
[0098] In the blockchain network, each node independently verifies the syntax and logic of the smart contract. If a node finds a problem with the syntax or logic of the contract, the node will refuse to deploy or execute the contract. The consensus mechanism ensures that all nodes in the network reach an agreement and jointly confirm the correctness of the contract. The verification results will be broadcast in the blockchain network, and other nodes will synchronize the verification results and update the verified smart contract status to the blockchain to ensure that the status of all nodes is consistent.
[0099] The verification tool will provide feedback on the syntax and logic check results of the contract. If the verification passes, the contract will enter the execution phase; if it fails, the system will return an error message and prompt the developer to modify the code.
[0100] The system generates a verification report based on the output of the compiler and logic verification tools, including syntax errors, logic problems, etc. Contract developers can debug and modify according to the detailed information in the report. After verification, the contract enters the deployment process on the blockchain and is ready for execution.
[0101] By performing syntax and logic verification of smart contract codes in the distributed node network of the blockchain, it is ensured that the smart contract codes comply with the programming language specifications before deployment, thus avoiding contract deployment failures caused by syntax errors. At the same time, logic verification analyzes the execution process of the contract, identifies potential logic vulnerabilities or security issues, and ensures the safe and reliable execution of the contract.
[0102] S60, when the syntax and logic verification pass, execute the smart contract code;
[0103] In this embodiment, when the smart contract code passes the syntax verification of the compiler and the security and rationality check of the logic verification tool, it means that the contract has the conditions for execution on the blockchain network.
[0104] Execution preparation includes the deployment, initialization and configuration of the execution environment of the contract. At this point, the blockchain system will allocate resources for the smart contract and prepare to start the contract's operating environment.
[0105] The system confirms that the contract has passed verification through the consensus mechanism of the blockchain node network and enters the deployment and execution stage. The contract will be deployed to a smart contract account on the blockchain and will be automatically executed when the execution conditions are met.
[0106] Smart contracts usually set certain execution conditions, such as time, transaction completion, funds reaching a certain threshold, etc. When these conditions are met, the execution logic of the smart contract code will be triggered to start the corresponding operations, such as fund transfer, asset delivery, etc.
[0107] There is an event listener in the smart contract. When the trigger conditions in the contract are met, the system will automatically call the relevant functions in the contract. For example, when a payment is completed, the "payment success" event in the smart contract is triggered, and the system automatically executes the corresponding operation logic.
[0108] The contract execution function is the core functional part of the contract code, including the transfer of funds, delivery of assets, status update, etc. Each smart contract contains multiple functions, which will complete the corresponding operations according to the terms of the contract when executed.
[0109] When the execution conditions of the contract are met, the system will automatically call the corresponding function in the contract. For example, in a loan contract, when the repayment conditions are met, the contract automatically calls the repayLoan() function to process the repayment. During the contract execution process, the system will update the relevant state variables and perform operations according to the terms of the contract.
[0110] During the contract execution process, the state variables in the contract will be updated according to the execution results. For example, in a payment contract, the payment status will be updated from "unpaid" to "paid", and the time, amount and other information will be recorded.
[0111] The state variables of the contract are stored in the distributed ledger of the blockchain. When the contract is executed, all participating nodes will synchronously update the state of the contract to ensure that all nodes in the network maintain the same state of the contract.
[0112] After the contract is executed, the system will notify the relevant parties of the execution results through the blockchain event mechanism. The feedback results usually include whether the operation is successful, the amount executed, the status of asset delivery, etc.
[0113] The system pushes the execution results of the contract to all relevant nodes and participants through the event broadcasting mechanism of the blockchain. For example, after the payment contract is completed, the system will broadcast a message of successful payment, and all relevant participants (such as the recipient of funds) will receive a notification.
[0114] Example: In the financial field, an investment company generates an asset management contract for a client. The contract stipulates that when a client deposits 1 million yuan, the system will automatically trigger the asset management service and transfer the funds to the designated account. After the contract passes syntax and logic verification, it is deployed on the blockchain.
[0115] Trigger execution conditions: When the amount deposited by the customer reaches 1 million yuan, the contract automatically detects that the condition is met and calls the startAssetManagement() function to start the asset management service.
[0116] Function execution: The system transfers funds from the customer account to the asset management account and updates the contract status on the blockchain, marking that asset management has started.
[0117] Result feedback: The system notifies customers and asset managers through the blockchain event broadcast mechanism that the fund transfer has been completed and asset management has officially started.
[0118] After passing syntax and logic verification, the contract code can be executed safely and reliably in the blockchain network. This ensures that smart contracts are executed only after passing all verifications, reducing the risk of code errors or vulnerabilities. During the contract execution process, all operations are automatically triggered according to predetermined conditions, avoiding manual intervention, while ensuring the transparency and immutability of the execution results, improving the automation level and execution efficiency of smart contracts.
[0119] S70, recording the execution process and execution result of the smart contract code in the distributed ledger of the blockchain.
[0120] In this embodiment, during the execution of the smart contract, all operation steps and state changes are recorded. This includes each function call of the contract, the transfer of funds, the delivery of assets, the update of status, etc. Recording these processes helps to ensure the transparency and traceability of contract execution.
[0121] The distributed ledger of the blockchain records the contract execution process in each node, ensuring that each node has the same execution record to prevent tampering or loss.
[0122] At each stage of smart contract execution, the system captures the operations during the execution and generates logs. These logs include the hash value of the transaction, the timestamp of the operation, the status of the execution, etc. Each operation log will be broadcast to the distributed node network of the blockchain to ensure that each node is saved synchronously.
[0123] These records will be stored in the blocks of the blockchain and become part of the blockchain ledger, permanently preserved to ensure that they can be queried and verified in the future.
[0124] The execution result record refers to the final result after the contract execution is completed, such as whether the transaction is successful, whether the funds are transferred, whether the asset delivery is completed, etc. The result record ensures that the status of each contract execution can be clearly reflected.
[0125] After the contract is executed, the system will write the results of the execution (such as "transaction successful", "funds transferred", "assets delivered", etc.) into the distributed ledger as result logs. These results include key information such as success or failure status, transaction details involved, and timestamps.
[0126] The blockchain node will broadcast the result information to all participating distributed nodes to ensure that all nodes save the same execution results and update their respective ledger records.
[0127] Each record (including the contract execution process and results) will have a unique timestamp to mark the time when the operation occurred. The timestamp ensures that each transaction and operation has a clear time sequence and provides a reliable traceability mechanism.
[0128] The system will automatically generate a corresponding timestamp for each contract execution step and final result. The timestamp is generated using the blockchain's built-in time mechanism to ensure that it cannot be tampered with, and all nodes reach a consensus on the timestamp through a consensus mechanism.
[0129] All records of the contract execution process and results will be synchronized through the distributed storage mechanism of the blockchain, and all nodes will store a copy. This distributed storage method ensures the security and reliability of the records and prevents single point failures and data loss.
[0130] The system will broadcast the detailed records and results of the contract execution to each node in the network through the consensus mechanism of the blockchain. Each node stores the execution log and results in the block, forming a permanent record on the chain. The distributed ledgers of each node remain consistent, and individual modification of records is not allowed.
[0131] The execution process and results of the contract can be queried at any time in the distributed ledger of the blockchain. Due to the tamper-proof nature of the blockchain, anyone can verify whether the execution process of the contract complies with the terms of the contract and ensure the authenticity of the results.
[0132] Through the blockchain browser or API interface, contract participants can query the execution record of the contract, verify whether the funds are transferred in accordance with the contract provisions, whether the asset delivery is successfully completed, etc. The query results are based on the public records on the blockchain, ensuring transparency and immutability.
[0133] By recording the execution process and results of smart contracts in the distributed ledger of the blockchain, the transparency and traceability of contract execution are ensured. Each execution step and result has a clear timestamp and operation log to ensure the immutability and security of the records. The distributed storage mechanism ensures the high availability and reliability of data. Even if a node fails, the records can still be restored through other nodes. This improves the credibility and execution efficiency of smart contracts in sensitive fields such as finance.
[0134] The present invention relates to the fields of artificial intelligence technology and financial technology, and discloses a method for generating and executing a smart contract. By collecting transaction behavior data and transaction demand data of smart contract participants, a natural language understanding model is constructed based on the collected data, contract requirements are obtained and a natural language description of the contract is generated, the generated natural language description of the contract is parsed and converted into a smart contract code, the smart contract code is subjected to syntax and logic verification, the smart contract code that has passed the verification is executed, and the execution process and the execution result are recorded in a distributed ledger of a blockchain. The present invention reduces the requirements for the programming ability of the participants by automatically generating smart contracts, and solves the problem that the writing efficiency of smart contracts in the prior art is low and prone to errors. By introducing syntax and logic verification steps, the accuracy of the smart contract before execution is ensured, and potential risks caused by contract logic errors are avoided. At the same time, by recording the contract execution process and results in the distributed ledger of a blockchain, the transparency of the transaction and the security of the data are improved, data tampering is effectively prevented, and the generation efficiency and execution reliability of the smart contract are significantly improved.
[0135] In one embodiment, the above S10 includes:
[0136] S101, extracting transaction behavior data from the trading platform of the smart contract participants;
[0137] S102, obtaining transaction demand data from the document library of the smart contract participants;
[0138] S103, performing data cleaning operations on the transaction behavior data and transaction demand data;
[0139] S104, converting the transaction behavior data and transaction demand data after the data cleaning operation into a unified data format.
[0140] In this embodiment, transaction behavior data refers to all behavior records of smart contract participants in past transactions, including detailed information such as transaction time, amount, transaction type, counterparty, etc. These data reflect the historical transaction patterns, behavioral habits and preferences of the participants, and provide data support for the generation of smart contracts.
[0141] The system automatically extracts transaction data through API integration with the trading platform of the smart contract participants. This data can be obtained from sources such as banking systems, blockchain trading platforms, and e-commerce platforms.
[0142] The system regularly extracts transaction data in batches from these platforms to ensure the integrity of transaction records. The latest transaction data can be obtained in a time window to ensure the real-time nature of the data.
[0143] Transaction demand data refers to the demand of the participants for future transactions, such as expected transaction terms, capital flow, contract conditions, etc. The document library may contain the business demand documents, historical contracts, invoices, orders and other documents of the participants. The demand information stored in these documents is crucial for generating smart contracts.
[0144] The system extracts key information from the document library of the parties through automated document processing tools such as OCR (Optical Character Recognition) technology or Natural Language Processing (NLP) models. The parsed transaction demand data will be stored in a structured manner for subsequent use.
[0145] The system is integrated with the document management systems of the participants (such as enterprise document management systems, cloud storage, etc.), regularly scans and extracts new demand data, and ensures that the latest business needs are taken into account when contracts are generated.
[0146] Clean the extracted transaction behavior data and transaction demand data to remove duplicate, erroneous, and invalid data to ensure data accuracy and consistency. Data cleaning is a key step in data processing to ensure that subsequent smart contract generation is based on high-quality data sources.
[0147] The system first removes duplicate transaction records and invalid requirement documents. For example, multiple identical transaction entries are only retained once, and transaction records with incorrect formats are marked and excluded. The system also verifies the integrity and accuracy of the data according to predefined rules to ensure that the data meets the requirements of contract generation.
[0148] Correct or fill in missing or incomplete data. For example, if the date of a transaction is missing, the system can automatically fill in the field using historical data or default values. All data corrections are automatically performed according to business rules, avoiding manual intervention.
[0149] Unified data format means converting cleaned transaction behavior data and transaction demand data into a system standard format to facilitate subsequent processing and contract generation. By unifying the format, it can be ensured that the system can consistently parse and use data from different sources.
[0150] The system uses data conversion tools to convert transaction and demand data from different sources and formats (such as JSON, XML, CSV, etc.) into a unified standard data structure. For example, the system can convert all transaction data into a structured JSON format to ensure the consistency of all fields (such as time, amount, transaction type, etc.).
[0151] Standardize the fields in the transaction data (such as the "amount" field, which may come from different platforms and have different units or formats). The system will define a unified field name and format to ensure that data from different sources can be seamlessly connected in the subsequent contract generation process.
[0152] This embodiment extracts transaction behavior data and demand data from the trading platform and document library of the smart contract participants, so that the system can automatically obtain the detailed transaction history and requirements of the participants, reduce manual intervention, and improve data integrity. The data cleaning operation ensures the accuracy and consistency of the data and avoids the impact of erroneous data on contract generation. Through unified data format conversion, the system can ensure standardized data processing and provide high-quality data support for subsequent smart contract generation.
[0153] In one embodiment, the above S20 includes:
[0154] S201, labeling the transaction behavior data and the transaction demand data to generate a label data set for training a model;
[0155] S202, determining a basic natural language model, and setting a learning rate and a number of training rounds for the basic natural language model;
[0156] S203, training the basic natural language model using the label data set according to the learning rate and the number of training rounds, so as to adjust the parameters of the basic natural language model;
[0157] S204, when the training is completed, the natural language understanding model is obtained.
[0158] In this embodiment, data labeling refers to classifying and labeling the collected transaction behavior data and transaction demand data to generate a label data set for training the natural language understanding model. The purpose of labeling is to enable the model to recognize and understand key features in the data, such as transaction amount, transaction conditions, parties involved and other contract elements.
[0159] The system first pre-processes the transaction behavior data and transaction demand data, and classifies the key information of each transaction (such as transaction time, amount, transaction type, etc.) and demand data (such as contract terms, execution conditions, etc.).
[0160] The system combines machine learning models and manual methods to annotate data. Manual annotation can be used for more complex contract elements, while automatic annotation is based on predefined rules or models to mark common contract fields. After the annotation is completed, the system generates a labeled dataset for training natural language models.
[0161] The basic natural language model refers to the natural language processing model used for smart contract generation, which is usually based on pre-trained deep learning models, such as BERT, GPT, etc. The model is fine-tuned on language data related to the financial field so that it can understand and generate natural language that complies with the terms of the smart contract.
[0162] The learning rate determines the step size of the model's parameter adjustment in each iteration, while the number of training rounds refers to the number of times the entire dataset is input into the model and the parameters are updated. Appropriate learning rate and number of training rounds can help the model effectively adjust parameters during the learning process to prevent overfitting or underfitting.
[0163] The system can choose pre-trained natural language models, such as BERT, GPT, etc. These models have been trained on large-scale corpora, have strong language understanding capabilities, and can perform detailed contract generation tasks.
[0164] The system selects the appropriate learning rate and number of training rounds through experiments. The learning rate is usually optimized through grid search, random search and other methods, and the number of training rounds is dynamically adjusted according to the performance of the model. For example, a smaller learning rate helps the model learn complex contract terms logic more stably.
[0165] The basic natural language model is trained using the labeled transaction behavior data and demand data set. The purpose of the training is to adjust the parameters of the model so that it can more accurately generate natural language descriptions of contracts. Through multiple rounds of training iterations, the weights and bias parameters of the model are continuously adjusted to improve the accuracy of the model's generation of contract terms.
[0166] The system will input the labeled dataset into the pre-selected natural language model. During the training process, the model will learn the structure and language patterns of the contract terms based on the input transaction behavior data and demand data. After each round of training, the parameters of the model will be adjusted based on the error feedback so that it can better understand the input data. In each round of training, the system will use the validation set to evaluate the performance of the model and adjust the training hyperparameters (such as learning rate) based on the results. In order to ensure the effectiveness of the model for the smart contract generation task, the system will also use evaluation indicators such as precision, recall, and F1 score.
[0167] The trained model can generate accurate natural language contract descriptions based on the input transaction behavior data and demand data. The model has the ability to understand and generate complex financial contract terms and can automatically generate compliant contract terms. After training, the system tests the model to ensure that the contract terms it generates are accurate. Through the evaluation of the test set, the system verifies the performance of the model when dealing with different types of contract requirements. After verification, the model will be used to automatically generate contract terms that meet transaction requirements and can be applied to real smart contract generation scenarios.
[0168] In this embodiment, by annotating and training transaction behavior data and transaction demand data, the system can build a natural language understanding model for smart contract generation. By optimizing the learning rate and the number of training rounds, the model can accurately generate contract terms that meet the needs of the parties involved, reducing the complexity and potential errors of manually writing contracts. The trained model has the ability to understand and generate contract terms, greatly improving the efficiency and accuracy of smart contract generation.
[0169] In one embodiment, the above S30 includes:
[0170] S301, an interactive interface displays an interactive field for inputting contract requirements, so that smart contract participants can input contract requirements;
[0171] S302, receiving a contract requirement including execution conditions and execution time;
[0172] S303: Use the natural language understanding model to convert the contract requirements into a natural language description of the contract.
[0173] In this embodiment, the interactive input field refers to a series of input boxes or options provided by the system for smart contract participants to fill in or select specific requirements related to the contract. Through the interactive interface, participants can enter their contract requirements, such as transaction amount, asset transfer conditions, execution time, etc.
[0174] The user-friendly input interface is designed to be concise and intuitive, ensuring that users can easily fill in their requirements and reduce input errors. Interactive fields can include text boxes, date pickers, drop-down menus, etc. to help users enter information effectively.
[0175] The interface provided by the system contains multiple fields for the parties to enter or select key information of the contract. For example, the fields include transaction amount, asset type, delivery conditions, etc. The interactive interface is presented through a web or mobile application and can be integrated through an API. The system will perform preliminary verification of the data entered by the user to ensure the integrity and correct format of the data. For example, the transaction amount must be a number and the execution time must be a valid date.
[0176] Execution conditions refer to the triggering conditions for the execution of a contract. For example, in a payment contract, the execution condition may be the arrival of funds; in an asset delivery contract, the execution condition may be the consent of both parties or the completion of the delivery of funds.
[0177] Execution time refers to the time point when the contract is executed. It can be a fixed date or a dynamically triggered time range. The execution time is closely related to the execution conditions, ensuring that the contract is executed within the correct time range.
[0178] In the interactive interface, users can enter or select execution conditions (such as "execution after receiving payment") and execution time (such as "December 31, 2024" or "execution within 10 days"). The system receives this information through predefined templates or free formats.
[0179] After receiving the execution conditions and execution time, the system will verify to ensure that the input conditions and time are reasonable and logical. For example, ensure that the execution time is not earlier than the signing date of the contract, or that the triggering logic of the conditions is consistent with the actual business scenario.
[0180] Through the natural language understanding model, the system can understand the contract requirements entered by the parties and convert these requirements into natural language descriptions of the contract. The model can generate clear contract terms, ensuring that the language expression of the terms is accurate and complies with legal and business regulations.
[0181] The system first converts the contract requirements such as execution conditions and execution time entered by the user into structured data. Then, using the natural language understanding model, this data is used to generate a natural language description of the contract. For example, if the user enters "deliver the goods within 10 days after payment is completed", the system will automatically generate: "Party A shall deliver the goods to Party B within 10 days after payment is completed, and the delivery location shall be the location designated by Party B."
[0182] The natural language understanding model is fine-tuned through transaction behavior data and historical contract data to ensure that the generated terms meet business needs. The generated natural language contract terms need to pass the system's logical verification and legal compliance checks to ensure that the generated terms meet actual business scenarios.
[0183] This embodiment collects contract requirements through an interactive interface and generates contract terms using a natural language understanding model. The system can greatly simplify the generation process of smart contracts. The natural language understanding model not only ensures that the generated contract description complies with business logic and legal regulations, but also dynamically generates personalized contract terms based on user input requirements. By setting execution conditions and execution time, the contract can be automatically executed when the conditions are met, improving the automation level and accuracy of contract execution.
[0184] In one embodiment, the above S40 includes:
[0185] S401, parsing the natural language description of the contract into a structured representation of the contract terms;
[0186] S402, determining a smart contract code template according to the structured representation;
[0187] S403, filling the parameters in the structured representation into the smart contract code template to generate a complete smart contract code.
[0188] In this embodiment, the parsing of natural language description refers to the grammatical and semantic analysis of the contract requirements (such as payment terms, asset transfer, etc.) entered by the user, and converting them into structured data representation that can be processed by the computer. For example, the payment amount, time conditions, etc. will be parsed into specific parameters and logical conditions.
[0189] Structured representation refers to the conversion of the natural language terms of a contract into a unified, computer-processable data format, such as JSON, XML or other formats, to facilitate the automated processing of subsequent operations.
[0190] The system uses the NLP engine to parse the natural language description of the contract, extract key information and convert it into structured data. The parsed content includes execution conditions, amount, time, participants and other terms.
[0191] The system uses a semantic analysis model to ensure that each clause in the natural language description can be correctly mapped to the execution logic of the contract. For example, "delivery of goods within 7 days after payment" will be mapped as a time condition in the contract execution.
[0192] Smart contract code template refers to the basic structure framework of the contract code, which defines the functions, conditional judgments and event handling mechanisms used in the contract. The functions and logic framework in the template are universal and can adapt to different types of contract generation. The system automatically selects or generates a suitable smart contract code template based on the parsed structured representation (such as payment conditions, execution time). The template contains basic contract logic, such as payment process, asset transfer, conditional triggering, etc.
[0193] The system maintains a code template library that contains common contract types, such as payment contracts, loan contracts, asset transfer contracts, etc. The system selects the appropriate template by matching the key fields in the structured data. For example, for a payment contract, the system will select a template that contains the logic of fund transfer.
[0194] For complex or highly customized contracts, the system will dynamically generate appropriate code templates based on the structured representation. The functions and conditions in the templates will be adjusted according to the user's specific needs.
[0195] The system fills the specific parameters in the structured representation (such as amount, time, participants, etc.) into the corresponding variable positions in the smart contract code template to generate a complete smart contract code. For example, amount, time, and execution conditions will be used as variables in the code.
[0196] Smart contract code refers to the code that contains all contract terms and execution logic, which can be automatically executed on blockchain platforms (such as Ethereum, Hyperledger, etc.). The code contains the main logical structure of the contract, variable definitions, and conditional judgments. The system's code generation engine will automatically fill in the parameters to the corresponding positions in the template based on the structured data.
[0197] The system formats the generated smart contract code into a programming language supported by the blockchain platform (such as Solidity, Chaincode, etc.) to ensure that the contract can be successfully executed in a distributed environment.
[0198] By parsing natural language descriptions and converting them into smart contract code, this embodiment automates the process of generating smart contracts, reducing the requirements for user programming skills. The parsing and structured processing of natural language descriptions ensure that the generated contract code is accurate and executable. The automatic selection and dynamic generation of smart contract code templates allow the system to flexibly respond to different types of contract requirements, improving the generation efficiency and adaptability of smart contracts.
[0199] In one embodiment, the above S60 includes:
[0200] S601, when the syntax and logic verification pass, check whether the execution conditions of the smart contract code are met;
[0201] S602, when it is confirmed that the execution conditions of the smart contract code are met, calling the function in the smart contract code to execute the corresponding contract operation;
[0202] S603, updating the status of the smart contract participants according to the executed contract operation;
[0203] S604, recording the execution result of the smart contract code;
[0204] S605, notifying the smart contract participants of the execution result through the blockchain event mechanism.
[0205] In this embodiment, after the smart contract code is generated, it must be checked by the compiler's syntax verification and logic verification tool. Only when there are no errors in the syntax and business logic of the contract code can the contract operation be executed.
[0206] The contract execution conditions are the trigger points of the contract, such as "funds arrival" in a payment contract, "asset delivery" in an asset contract, etc. Before the contract is executed, the system will check whether these conditions are met to ensure that the execution of the contract meets expectations.
[0207] The system's built-in validator will regularly check the execution conditions of the contract. For example, in a payment contract, the system will check the payment status and whether the funds have been received. Only when the conditions are met will the contract be allowed to continue execution.
[0208] The system will obtain the conditional data required for contract execution in real time through interface integration with external data sources (such as payment gateways, supply chain systems, etc.). For example, if the contract involves conditions for funds to arrive, the system will query the transaction records of the bank system.
[0209] Each smart contract contains several predefined functions that implement the specific execution logic of the contract. For example, fund transfer, asset delivery, status change, etc. When the execution conditions are met, the system will automatically call the corresponding contract function to complete the contract operation.
[0210] When the system detects that the contract conditions have been met, the function defined in the contract will be automatically called. For example, in a loan contract, when the repayment date arrives, the system will call the repayment function payInstallment() to perform the repayment operation.
[0211] Through the event monitoring mechanism of the blockchain, the system can monitor the occurrence of events in real time, and automatically call the contract function to perform operations when the trigger conditions are met. For example, monitoring account arrival events or asset delivery events.
[0212] During the execution of a smart contract, the status of the parties involved (such as account balance, transaction status, asset ownership, etc.) will be updated according to the execution results of the contract. For example, in a payment contract, after execution, the balance of the payee decreases and the balance of the payee increases.
[0213] The state variables in the smart contract will be automatically updated according to the function execution results. For example, in a fund transfer contract, the payer's balance status is updated from balance = 1000 to balance = 900. The system automatically updates the status and saves it to the distributed ledger of the blockchain.
[0214] After each contract operation is completed, the system will trigger a status update based on the event mechanism to ensure that the status of all nodes is synchronized. For example, in an asset delivery contract, the asset status of the buyer and seller will be updated immediately after the delivery is completed.
[0215] After each contract is executed, the system will record the execution results of the contract and save information such as operations, participants, and capital flows during the execution process. These records will be stored in the distributed ledger of the blockchain to ensure that the execution results are traceable and cannot be tampered with.
[0216] When a contract is executed, the system generates a series of logs, including the executed functions, operation time, result status, etc. These logs are stored in the transaction records of the blockchain and become part of the contract execution history.
[0217] The system broadcasts the execution results to all nodes in the blockchain network, ensuring that all participating nodes save the results synchronously. For example, the execution result of "payment completed" will be written to the blockchain, and all nodes will save this information.
[0218] Blockchain platforms usually have a built-in event notification mechanism to notify relevant parties of the results after the contract is executed. Participants can obtain the execution status of the contract in real time through the event mechanism.
[0219] After the contract is executed, the system will send the execution results of the contract to all relevant parties through the event notification mechanism. For example, the recipient will receive a "successful payment" notification after the funds arrive. The system will broadcast the execution results to all parties associated with the contract through the blockchain's broadcast mechanism.
[0220] Participants can also query the execution results of the contract through the blockchain's API or smart contract interface to ensure that the operation results are transparent and public. For example, buyers and sellers can query the results of transactions and asset delivery through the blockchain.
[0221] This embodiment ensures that the smart contract will only be executed when the conditions are met through strict execution condition checks, avoiding errors or unexpected situations in contract execution. The system automatically calls the contract function and updates the status, reducing manual intervention and improving execution efficiency and accuracy. Through the event mechanism of the blockchain, the system can notify the participants of the execution results in real time, ensuring the transparency and traceability of the contract, and improving the credibility and security of the contract.
[0222] In one embodiment, the above S70 includes:
[0223] S701, using an asymmetric encryption module to encrypt data and operation records generated during the execution of the smart contract code to generate an encrypted record of the execution process;
[0224] S702, encrypting the execution result generated after the smart contract code is executed to generate an encrypted record of the execution result;
[0225] S703, adding corresponding timestamps to the encrypted records of the execution process and the encrypted records of the execution results;
[0226] S704, writing the encrypted record of the execution process and the encrypted record of the execution result and the corresponding timestamp into the distributed ledger of the blockchain.
[0227] In this embodiment, asymmetric encryption uses a pair of public and private keys, where the public key is used to encrypt data and the private key is used to decrypt it. This encryption method ensures that the data during execution can only be decrypted and viewed by authorized parties, thus ensuring the security of the data.
[0228] The encrypted record of the execution process refers to the log records of the data generated during the execution of the smart contract (such as function calls, operation time, capital flow, etc.) after encryption. These encrypted records will be used to save the detailed information of the execution operation.
[0229] The system integrates an asymmetric encryption module to encrypt the data generated during the execution process. After each operation record is generated, the system will encrypt it with a preset public key to ensure that only legitimate users with private keys can decrypt it. Each contract operation (such as fund transfer, status update) will record the generated log, and the log content is encrypted with the public key. The generated encrypted record contains detailed information such as the time and content of the operation.
[0230] When the smart contract execution is completed, the final execution results are generated, such as whether the funds transfer is successful, the status of asset delivery, etc. To protect these results, the system encrypts them to prevent unauthorized users from obtaining the contract execution details. The encrypted record of the execution results contains the final status of the execution and related details, such as the flow of funds, the completion of the transaction, etc. After encryption, the results can only be viewed by authorized parties.
[0231] When the smart contract is executed, the system will generate the execution result and encrypt it with the public key. For example, after the payment contract is completed, the system will generate the result of "payment successful" or "payment failed" and encrypt this information and store it in the ledger. The system will encrypt the key information in the execution result (such as transaction status and amount) to ensure that this sensitive information can only be interpreted by legitimate users.
[0232] Each execution process and execution result record will be timestamped to mark the specific time when the operation occurred. This ensures that the chronological order of each operation and execution result is clearly visible and provides a reliable traceability mechanism.
[0233] The system uses the time mechanism of the blockchain platform to automatically generate a timestamp for each record. The timestamp will be based on the consensus time of the blockchain node to ensure that all nodes synchronize the time when the operation occurs.
[0234] When the system generates an encrypted record, it automatically attaches the current timestamp, so that each encrypted record has a clear time stamp for subsequent verification and tracing.
[0235] The distributed ledger of the blockchain stores all operations and results during the contract execution process. By writing these encrypted execution records and results, all blockchain nodes will synchronize this data to ensure the consistency and immutability of the ledger.
[0236] The system will write the encrypted execution records and execution results, as well as their timestamps, into the ledger through the blockchain transaction mechanism. Each node will receive these records and save them in the local distributed ledger.
[0237] Through the consensus mechanism of blockchain, all nodes confirm and synchronize these encrypted records to ensure the consistency of the records stored in the ledger, and no single node can tamper with the execution records or results.
[0238] This embodiment uses an asymmetric encryption module to encrypt the execution process and results of the smart contract, and the system ensures the security and privacy protection of the contract execution data. The encrypted records can only be decrypted and viewed by authorized parties to prevent data leakage. The timestamp mechanism provides an accurate time mark for each encrypted record, making the contract execution process highly transparent and traceable. Through the storage mechanism of the distributed ledger, all nodes synchronously save these encrypted records to ensure the consistency and non-tamperability of the data, enhancing the security and credibility of the system.
[0239] In one embodiment, a smart contract generation and execution device is provided, and the smart contract generation and execution device corresponds one-to-one to the smart contract generation and execution method in the above embodiment. Figure 3 , Figure 3 This is a functional module diagram of a preferred embodiment of the smart contract generation and execution device of the present invention. Data collection module 10, model building module 20, contract generation module 30, code generation module 40, code verification module 50, contract execution module 60 and recording and storage module 70. The functional modules are described in detail as follows:
[0240] Data collection module 10, used to collect transaction behavior data and transaction demand data of smart contract participants;
[0241] A model building module 20, for building a natural language understanding model for contract generation based on the transaction behavior data and the transaction demand data;
[0242] A contract generation module 30, used to obtain contract requirements and generate a natural language description of the contract based on the contract requirements using the natural language understanding model;
[0243] A code generation module 40, used to parse the natural language description of the contract and convert it into smart contract code;
[0244] A code verification module 50, used to perform syntax and logic verification on the smart contract code in the distributed node network of the blockchain;
[0245] The contract execution module 60 is used to execute the smart contract code when the syntax and logic verification pass;
[0246] The recording and storage module 70 is used to record the execution process and execution results of the smart contract code in the distributed ledger of the blockchain.
[0247] In one embodiment, the data collection module 10 is specifically used for:
[0248] Extract transaction behavior data from the trading platforms of smart contract participants;
[0249] Obtain transaction demand data from the document library of smart contract participants;
[0250] Performing data cleaning operations on the transaction behavior data and transaction demand data;
[0251] Convert the transaction behavior data and transaction demand data after data cleaning operations into a unified data format.
[0252] In one embodiment, the model building module 20 is specifically used to:
[0253] Labeling the transaction behavior data and transaction demand data to generate a label data set for training a model;
[0254] Determine a basic natural language model, and set a learning rate and a number of training rounds for the basic natural language model;
[0255] According to the learning rate and the number of training rounds, the basic natural language model is trained using the label data set to adjust parameters of the basic natural language model;
[0256] When the training is completed, the natural language understanding model is obtained.
[0257] In one embodiment, the contract generation module 30 is specifically used to:
[0258] An interactive interface displays an interactive field for inputting contract requirements, so that smart contract participants can input contract requirements;
[0259] receiving a contract requirement including execution conditions and execution time;
[0260] The contract requirements are converted into a natural language description of the contract using the natural language understanding model.
[0261] In one embodiment, the code generation module 40 is specifically used to:
[0262] Parse the natural language description of the contract into a structured representation of the contract terms;
[0263] Determining a smart contract code template according to the structured representation;
[0264] Fill the parameters in the structured representation into the smart contract code template to generate a complete smart contract code.
[0265] In one embodiment, the contract execution module 60 is specifically used to:
[0266] When syntax and logic verification pass, check whether the execution conditions of the smart contract code are met;
[0267] When it is confirmed that the execution conditions of the smart contract code are met, the function in the smart contract code is called to execute the corresponding contract operation;
[0268] Update the status of the smart contract participants according to the executed contract operations;
[0269] Record the execution results of smart contract code;
[0270] The execution results are notified to the smart contract participants through the blockchain event mechanism.
[0271] In one embodiment, the recording and storage module 70 is specifically used for:
[0272] Use an asymmetric encryption module to encrypt the data and operation records generated during the execution of the smart contract code to generate encrypted records of the execution process;
[0273] Encrypt the execution result generated after the smart contract code is executed to generate an encrypted record of the execution result;
[0274] Add corresponding timestamps to the encrypted records of the execution process and the encrypted records of the execution results;
[0275] The encrypted record of the execution process and the encrypted record of the execution result and the corresponding timestamp are written into the distributed ledger of the blockchain.
[0276] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 4As shown. The computer device includes a processor, a memory, a network interface and a database connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external user terminal through a network connection. When the computer program is executed by the processor, it realizes the functions or steps of a service-side side of a smart contract generation and execution method.
[0277] In one embodiment, a computer device is provided. The computer device may be a user terminal, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external server via a network connection. When the computer program is executed by the processor, it implements the functions or steps on the user side of a smart contract generation and execution method
[0278] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the following steps are implemented:
[0279] Collect transaction behavior data and transaction demand data of smart contract participants;
[0280] Building a natural language understanding model for contract generation based on the transaction behavior data and transaction demand data;
[0281] Obtaining contract requirements, and using the natural language understanding model to generate a natural language description of the contract based on the contract requirements;
[0282] Parsing the natural language description of the contract and converting it into smart contract code;
[0283] Performing syntax and logic verification on the smart contract code in the distributed node network of the blockchain;
[0284] When syntax and logic verification pass, the smart contract code is executed;
[0285] The execution process and results of the smart contract code are recorded in the distributed ledger of the blockchain.
[0286] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0287] Collect transaction behavior data and transaction demand data of smart contract participants;
[0288] Building a natural language understanding model for contract generation based on the transaction behavior data and transaction demand data;
[0289] Obtaining contract requirements, and using the natural language understanding model to generate a natural language description of the contract based on the contract requirements;
[0290] Parsing the natural language description of the contract and converting it into smart contract code;
[0291] Performing syntax and logic verification on the smart contract code in the distributed node network of the blockchain;
[0292] When syntax and logic verification pass, the smart contract code is executed;
[0293] The execution process and results of the smart contract code are recorded in the distributed ledger of the blockchain.
[0294] It should be noted that the above functions or steps that can be implemented by the computer-readable storage medium or computer device can refer to the relevant descriptions on the server side and the user side in the aforementioned method embodiment. To avoid repetition, they will not be described one by one here.
[0295] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0296] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0297] It should be noted that if software tools or components other than those of the Company appear in the embodiments of the present application, they are only used for illustration and do not represent actual use. The above-described embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the above-mentioned embodiments, a person of ordinary skill in the art should understand that the technical solutions described in the above-mentioned embodiments can still be modified, or some of the technical features thereof can be replaced by equivalents; and these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A method for generating and executing a smart contract, characterized in that: The following steps are involved: Collect transaction behavior data and transaction demand data of smart contract participants; Building a natural language understanding model for contract generation based on the transaction behavior data and transaction demand data; Obtaining contract requirements, and using the natural language understanding model to generate a natural language description of the contract based on the contract requirements; Parsing the natural language description of the contract and converting it into smart contract code; Performing syntax and logic verification on the smart contract code in the distributed node network of the blockchain; When syntax and logic verification pass, the smart contract code is executed; The execution process and results of the smart contract code are recorded in the distributed ledger of the blockchain.
2. The method for generating and executing a smart contract according to claim 1, wherein: Collect transaction behavior data and transaction demand data of smart contract participants, including: Extract transaction behavior data from the trading platforms of smart contract participants; Obtain transaction demand data from the document library of smart contract participants; Performing data cleaning operations on the transaction behavior data and transaction demand data; Convert the transaction behavior data and transaction demand data after data cleaning operations into a unified data format.
3. The method for generating and executing a smart contract according to claim 1, wherein: A natural language understanding model for contract generation is constructed based on the transaction behavior data and the transaction demand data, including: Labeling the transaction behavior data and transaction demand data to generate a label data set for training a model; Determine a basic natural language model, and set a learning rate and a number of training rounds for the basic natural language model; According to the learning rate and the number of training rounds, the basic natural language model is trained using the label data set to adjust parameters of the basic natural language model; When the training is completed, the natural language understanding model is obtained.
4. The method for generating and executing a smart contract as claimed in claim 1, wherein: Obtaining contract requirements, and using the natural language understanding model to generate a natural language description of the contract according to the contract requirements, including: An interactive interface displays an interactive field for inputting contract requirements, so that smart contract participants can input contract requirements; receiving a contract requirement including execution conditions and execution time; The contract requirements are converted into a natural language description of the contract using the natural language understanding model.
5. The method for generating and executing a smart contract according to claim 1, wherein: Parse and convert the natural language description of the contract into smart contract code, including: Parse the natural language description of the contract into a structured representation of the contract terms; Determining a smart contract code template according to the structured representation; Fill the parameters in the structured representation into the smart contract code template to generate a complete smart contract code.
6. The method for generating and executing a smart contract according to claim 1, wherein: When the syntax and logic verification pass, the smart contract code is executed, including: When syntax and logic verification pass, check whether the execution conditions of the smart contract code are met; When it is confirmed that the execution conditions of the smart contract code are met, the function in the smart contract code is called to execute the corresponding contract operation; Update the status of the smart contract participants according to the executed contract operations; Record the execution results of smart contract code; The execution results are notified to the smart contract participants through the blockchain event mechanism.
7. The smart contract generation and execution method according to claim 1, characterized in that: The execution process and results of the smart contract code are recorded in the distributed ledger of the blockchain, including: Use an asymmetric encryption module to encrypt the data and operation records generated during the execution of the smart contract code to generate encrypted records of the execution process; Encrypt the execution result generated after the smart contract code is executed to generate an encrypted record of the execution result; Add corresponding timestamps to the encrypted records of the execution process and the encrypted records of the execution results; The encrypted record of the execution process and the encrypted record of the execution result and the corresponding timestamp are written into the distributed ledger of the blockchain.
8. A smart contract generation and execution device, characterized in that: The smart contract generation and execution device comprises: Data collection module, used to collect transaction behavior data and transaction demand data of smart contract participants; A model building module, used to build a natural language understanding model for contract generation based on the transaction behavior data and transaction demand data; A contract generation module, used to obtain contract requirements and generate a natural language description of the contract based on the contract requirements using the natural language understanding model; A code generation module, used to parse the natural language description of the contract and convert it into smart contract code; A code verification module, used to perform syntax and logic verification on the smart contract code in a distributed node network of the blockchain; A contract execution module, used to execute the smart contract code when syntax and logic verification pass; The recording and storage module is used to record the execution process and execution results of the smart contract code in the distributed ledger of the blockchain.
9. A computer device, characterized in that: The computer device includes a memory, a processor, and a smart contract generation and execution program stored in the memory and executable on the processor. When the smart contract generation and execution program is executed by the processor, the steps of the smart contract generation and execution method as described in any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that: The storage medium stores a smart contract generation and execution program, which, when executed by the processor, implements the steps of the smart contract generation and execution method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Intelligent contract management method and device based on block chain and electronic device
CN110245506A
Block chain smart contract generation method and device, and electronic equipment
CN115268847A
Intelligent legal contract generation method and device, electronic equipment and storage medium
CN117311726A
Intelligent contract generation system, method and device based on large model and storage medium
CN118504542A
Cited By
Contract management method and system based on block chain
CN120257333A
Contract management method and system based on blockchain
CN120257333B