Smart contract optimization method and device, equipment, storage medium and program product
By introducing a credit rating prediction model and reinforcement learning strategy into smart contracts, and adjusting the contract execution strategy in real time, the problem of insufficient credit status control in smart contract technology is solved, enabling the contract to self-optimize and dynamically adapt, reducing default risk and improving execution efficiency.
Patent Information
- Application Number
- CN202411161971.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-22
- Publication Date
- 2026-03-03
AI Technical Summary
Existing smart contract technology lacks real-time control over the credit status of trading parties, resulting in low default risk and execution efficiency. It cannot dynamically adapt to changes in the credit environment, lacks self-optimization capabilities, and relies on manual review, which is costly and highly subjective.
By combining deep learning technology with blockchain, a credit rating prediction model is used to collect and analyze multi-dimensional information from both parties in real time. By utilizing Markov decision process models and reinforcement learning strategies, the execution strategy of smart contracts is dynamically adjusted to achieve real-time credit rating assessment and contract self-optimization.
It enhances the flexibility and adaptability of smart contracts, reduces default risk, improves execution efficiency and risk management capabilities, reduces human error, and enables contracts to self-optimize and dynamically adapt.
Smart Images

Figure CN121599760A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of smart contract technology, and in particular to a smart contract optimization method, apparatus, device, storage medium, and program product. Background Technology
[0002] With the widespread application of blockchain technology, smart contracts, with their transparency, immutability, and automatic execution, have shown great potential in areas such as commercial contract signing. However, related smart contract technologies generally lack real-time control over the credit status of the transacting parties during execution, leading to default risks and commercial losses, as well as relatively rigid and inefficient execution. Summary of the Invention
[0003] To address the aforementioned technical problems, embodiments of the present invention provide a smart contract optimization method, apparatus, device, storage medium, and program product.
[0004] The smart contract optimization method provided in this application includes:
[0005] The predicted credit rating of a transaction entity is determined based on environmental information related to credit assessment using a credit rating prediction model.
[0006] Receive a transaction request and determine the real-time credit rating of the transaction entity corresponding to the transaction request;
[0007] If the real-time credit rating reaches the credit rating threshold, then determine whether the real-time credit rating has reached the predicted credit rating.
[0008] If the real-time credit rating does not reach the predicted credit rating, the transaction request is rejected; or, if the real-time credit rating reaches the predicted credit rating, the execution strategy of the smart contract in the blockchain is adjusted based on the real-time credit rating through a smart contract optimization model.
[0009] The smart contract optimization device provided in this application includes:
[0010] The determining unit is used to determine the predicted credit rating of a transaction entity based on environmental status information of credit assessment using a credit rating prediction model; and to receive a transaction request and determine the real-time credit rating of the transaction entity corresponding to the transaction request.
[0011] The judgment unit is used to determine whether the real-time credit rating has reached the predicted credit rating if the real-time credit rating reaches the credit rating threshold.
[0012] The processing unit is configured to reject the transaction request if the real-time credit rating does not reach the predicted credit rating; or, if the real-time credit rating reaches the predicted credit rating, adjust the execution strategy of the smart contract in the blockchain based on the real-time credit rating through a smart contract optimization model.
[0013] The processing device provided in this application includes a processor and a memory. The memory is used to store computer programs, and the processor is used to call and run the computer programs stored in the memory to execute any of the smart contract optimization methods described above.
[0014] The computer-readable storage medium provided in this application embodiment is used to store a computer program that causes a computer to execute any of the above-described smart contract optimization methods.
[0015] The computer program product provided in this application includes computer program instructions that cause a computer to execute any of the above-described smart contract optimization methods.
[0016] In the technical solution of this application embodiment, a credit rating prediction model determines the predicted credit rating of the transaction entity based on environmental state information for credit assessment. It then receives transaction requests, determines the real-time credit rating of the transaction entity corresponding to the request, and if the real-time credit rating reaches a credit rating threshold, it checks whether the real-time credit rating reaches the predicted credit rating. If the real-time credit rating does not reach the predicted credit rating, the transaction request is rejected. Alternatively, if the real-time credit rating reaches the predicted credit rating, the execution strategy of the smart contract in the blockchain is adjusted based on the real-time credit rating using a smart contract optimization model. Thus, by collecting and analyzing historical transaction records, financial data, payment behavior, and other multi-dimensional information from both parties in real time through the credit rating prediction model, the credit ratings of both parties are predicted. Furthermore, based on the real-time changes in the credit ratings of both parties and the predicted credit ratings, the execution logic of the smart contract is dynamically adjusted through the smart contract optimization model. This not only enables dynamic management of smart contracts, improving their flexibility and adaptability, but also allows for self-optimization of smart contracts to adapt to new market environments and credit conditions, avoiding default risks and business losses. Attached Figure Description
[0017] Figure 1 This is a flowchart illustrating a smart contract optimization method provided in an embodiment of this application;
[0018] Figure 2 This is a flowchart illustrating the blockchain smart contract optimization system based on transaction credit rating prediction provided in this application embodiment;
[0019] Figure 3This is a schematic diagram of the structure of the smart contract optimization device provided in the embodiments of this application;
[0020] Figure 4 This is a schematic diagram of the processing device provided in the embodiments of this application. Detailed Implementation
[0021] The technical solutions of the embodiments of this application will now be described with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.
[0022] To facilitate understanding of the technical solutions of the embodiments of this application, the relevant technologies of the embodiments of this application are described below. The following relevant technologies are optional solutions and can be combined with the technical solutions of the embodiments of this application in any way, and they all fall within the protection scope of the embodiments of this application.
[0023] In various business sectors, credit is an important foundation for commercial trade. With the widespread application of blockchain technology, smart contracts, with their transparency, immutability, and automatic execution, have shown great potential in areas such as commercial contracting.
[0024] However, related smart contract technologies generally lack real-time acquisition and correlation of the credit status of the trading parties during execution, and cannot dynamically adjust the contract execution logic and terms according to changes in credit rating. This may lead to significant default risks due to changes in the credit status of the trading parties in some cases, resulting in commercial losses. At the same time, the execution efficiency of smart contracts is relatively rigid and inefficient.
[0025] Therefore, related smart contract technologies exhibit significant limitations when facing complex and ever-changing credit environments and market conditions, particularly in areas such as dynamic adjustment and risk management, which urgently require improvement. The main problems include the following:
[0026] (1) Lack of dynamic adaptability. Most of the relevant smart contracts are executed based on pre-set rules and conditions. Once deployed on the blockchain, their internal execution logic and execution conditions usually cannot be adjusted in real time, and they cannot respond flexibly to changes in the external environment or changes in the credit status of the trading entities.
[0027] (2) Inadequate risk management. The relevant smart contracts were not designed to fully consider changes in the credit risk of the trading parties. They are unable to predict and judge the credit status of both parties in real time, which may lead to the original plan being executed even if the other party's credit rating declines, increasing the risk of contract default.
[0028] (3) Lack of self-optimization capability. The relevant smart contracts do not have the ability to learn and optimize themselves, and cannot optimize their internal execution strategies to adapt to new market environments and credit conditions.
[0029] (4) Lack of objective understanding. Credit rating of commercial transactions is still based on manual review and judgment, which is costly and highly subjective, and is limited by the individual's level of understanding, making it easy to make mistakes.
[0030] To address the aforementioned technical issues, this application proposes a smart contract optimization method that applies deep learning technology to transaction credit rating prediction and blockchain smart contracts. The method dynamically optimizes the smart contract execution strategy based on the real-time credit ratings of both parties in the transaction. Specifically, it includes:
[0031] (1) To address the lack of dynamic adaptability, relevant smart contract systems struggle to respond in real-time to changes in the credit status of transacting parties during execution. This application proposes a dynamic adjustment mechanism by combining deep learning technology with blockchain smart contracts. This mechanism uses a credit rating prediction module to collect and analyze multi-dimensional information such as historical transaction records, financial data, and payment behavior of both transacting parties in real time. This information is transformed into feature vectors, and a Markov decision process model is used to predict credit ratings. Subsequently, the execution logic of the smart contract is dynamically adjusted based on real-time changes in credit ratings, thereby improving the flexibility and adaptability of the contract.
[0032] (2) Regarding the issue of insufficient risk management, the relevant smart contracts neglect the dynamic assessment of counterparty credit risk, increasing the risk of default. This application proposes to predict changes in the credit risk of both parties through real-time credit assessment, and adjust execution strategies in a timely manner, such as adding guarantee measures or adjusting payment terms, effectively reducing the risk of default due to credit decline.
[0033] (3) To address the problem of lack of self-optimization capability, this application proposes to introduce a reinforcement learning strategy optimization module. This module continuously optimizes the execution strategy of smart contracts through the dual-network DQN algorithm. Based on historical execution and real-time market feedback, it automatically adjusts such as execution order and guarantee conditions, enabling smart contracts to learn and optimize autonomously, thereby improving contract execution efficiency and risk control capabilities.
[0034] (4) Regarding the lack of objective understanding, this application proposes to replace the traditional manual review process with an automated credit assessment model, which reduces the subjectivity and cost of credit rating. The model is based on big data analysis and deep learning algorithms to quickly and accurately assess the credit rating of both parties in a transaction, reduce human error, and improve assessment efficiency.
[0035] To facilitate understanding of the technical solutions of the embodiments of this application, the technical solutions of this application are described in detail below through specific embodiments. The above-mentioned related technologies are optional solutions and can be arbitrarily combined with the technical solutions of the embodiments of this application, all of which fall within the protection scope of the embodiments of this application. The embodiments of this application include at least some of the following contents.
[0036] This application proposes a smart contract optimization method. Figure 1 This is a flowchart illustrating a smart contract optimization method provided in an embodiment of this application, as shown below. Figure 1 As shown, the method includes the following steps:
[0037] Step 101: Determine the predicted credit rating of the transaction entity based on the environmental status information of credit assessment using the credit rating prediction model.
[0038] In this embodiment, the required dataset is first collected, namely, environmental status information for credit assessment. Then, a credit rating prediction model is used to predict the credit rating of the transaction entity based on the environmental status information for credit assessment. The predicted credit rating is the credit rating within a unit of time from the current credit rating (real-time credit rating). This unit of time can be 1 second, 1 hour, 1 day, etc., and there are no restrictions here.
[0039] Here, the environmental status information for credit assessment includes historical transaction records of both parties (such as transaction amount, transaction frequency, and whether there are any default records), key financial statement data (such as current assets, liabilities, and net profit), payment behavior data (such as on-time repayment ratio and number of days of delayed repayment), and complaint feedback information, among other multi-dimensional status indicators. Integrating this information forms the environmental status information required for credit assessment.
[0040] Specifically, to construct the dataset needed for credit rating prediction, data can be integrated from multiple sources and channels to ensure the comprehensiveness and timeliness of the information. Specific collection methods include, but are not limited to, the following:
[0041] (1) Financial institutions and credit rating agencies: Cooperate with banks, credit card companies and credit rating agencies to obtain official credit scores, credit reports and past lending and repayment records of both parties to the transaction. These data directly reflect the credit history and repayment ability of the transaction entities.
[0042] (2) Public financial reports and corporate databases: Collect annual reports and financial statements (including key indicators such as current assets, liabilities, and net profit) of companies through public channels such as corporate websites, stock exchanges, and business registration agencies to assess the financial health and capital strength of companies.
[0043] (3) Payment platform and e-commerce platform data: Cooperate with third-party payment platforms and e-commerce platforms to obtain payment behavior data of both parties in the transaction, such as transaction frequency, transaction amount, on-time repayment ratio, and number of days of delayed repayment. This data helps to measure payment habits and credit performance.
[0044] (4) Social media and user feedback: Analyze public comments, ratings and complaints on social media, as well as direct feedback collected through the customer service center, to assess the market reputation and customer satisfaction of both parties in the transaction.
[0045] (5) Industry alliances and industry associations: Join industry-related data sharing alliances or industry associations. These organizations often have transaction data, compliance records, etc. of companies in the industry, which can provide an industry-specific perspective for credit assessment.
[0046] (6) Public market data and macroeconomic indicators: Integrate public market data, such as commodity price fluctuations, market interest rates, and changes in macroeconomic policies. These macroeconomic factors can also affect the creditworthiness of both parties in a transaction.
[0047] (7) Government public databases and legal documents: Search public databases such as court announcements, bankruptcy records, and tax registrations to obtain information on legal proceedings and tax compliance of the parties involved in the transaction in order to assess potential legal risks.
[0048] The data collected through the aforementioned channels, after being cleaned, integrated, and standardized, forms the dataset required for credit assessment, providing a solid foundation for subsequent credit rating prediction and smart contract optimization.
[0049] Based on this, in some implementation methods, determining the predicted credit rating of a transaction entity using a credit rating prediction model based on environmental status information for credit assessment may specifically include:
[0050] Convert environmental status information for credit assessment into a state feature vector;
[0051] The state feature vector is input into the credit rating prediction model, and the model outputs the predicted credit rating.
[0052] Here, the environmental status information for credit assessment is first preprocessed by cleaning, deduplication, and filling missing data. Feature extraction or feature selection is performed on the preprocessed data, and the extracted or selected data is transformed into a state feature vector by scaling or standardization. The state feature vector is then input into the credit rating prediction model, which outputs the predicted credit rating.
[0053] Here, the credit rating prediction model is a Markov decision process model, which defines a state space, an action space, and a reward function. The state space represents the credit status of the two parties in the transaction, the action space represents possible credit assessment strategies or credit rating control strategies, and the reward function represents the evaluation index of the credit rating. Specifically, the current credit status of the two parties is determined through the state space, and a credit assessment strategy for that credit status is selected through the action space. After executing the selected credit assessment strategy, the reward is determined through the reward function based on the current credit status of the two parties and the selected credit assessment strategy, thereby quantifying the effectiveness of the credit assessment strategy. In other words, the evaluation result of the credit rating prediction model can be obtained through the reward function. The larger the reward of the reward function, the better the prediction result of the credit rating prediction model, and vice versa.
[0054] Based on this, in some implementations, the credit rating prediction model includes a first state space, a first action space, and a first reward function; the first state space represents the credit rating status of the transaction entity, the first action space represents the credit rating assessment strategy, and the first reward function represents the credit rating evaluation index; wherein, the training process of the credit rating prediction model may specifically include:
[0055] Based on the first state space, the first action space, and the first reward function, determine the first value and the first target value;
[0056] Based on the first value and the first target value, determine the first loss function;
[0057] A credit rating prediction model is trained based on the first loss function.
[0058] Here, the training process of the credit rating prediction model involves reinforcement learning algorithms. In reinforcement learning, the model learns how to make optimal decisions to maximize cumulative rewards through interaction with the environment. First, a first memory unit, a first evaluation network, and a first target network are initialized. Using the first memory unit, based on the first state space, the first action space, and the first reward function, a first value and a first target value are determined for the first state space and the first action space. Then, based on the first value and the first target value, a first loss function is determined. Finally, based on the first loss function, gradient descent is used to minimize the first loss function to train the credit rating prediction model.
[0059] Based on this, in some implementations, determining the first value and the first target value based on the first state space, the first action space, and the first reward function may specifically include:
[0060] Initialize the first memory unit, the first estimation network, and the first target network;
[0061] Select a first initial state from the first state space, and select a first action from the first action space under the first initial state through the first valuation network;
[0062] Perform the first action and calculate the first reward using the first reward function;
[0063] Based on the first initial state, the first action, and the first reward, determine the first update state;
[0064] The first initial state, the first action, the first reward, and the first updated state are taken as the first experience and stored in the first memory unit;
[0065] Based on the first memory unit and the first valuation network, the first value and the first target value are determined.
[0066] Here, after initializing the first memory unit, the first valuation network, and the first target network, the first initial state is collected from the first state space, and the first action under the first initial state is selected from the first action space through the first valuation network. Then, the first action is executed, and the first reward is returned immediately through the first reward function. Based on the first initial state, the first action, and the first reward, a new state, namely the first updated state, is formed. The first initial state, the first action, the first reward, and the first updated state are stored as the first experience in the first memory unit. Thus, based on the first memory unit and the first valuation network, the first value and the first target value for the first state space and the first action space are determined.
[0067] Here, the method for selecting the first action from the first action space can employ an ε-greedy strategy. The ε-greedy strategy is a reinforcement learning strategy used to balance exploration and exploitation. Specifically, the ε-greedy strategy defines an exploration rate ε, which takes a value between 0 and 1. At each action selection, a random number between 0 and 1 is generated. If this random number is less than ε, a random action is selected; if it is greater than ε, the best action is chosen based on learned information. In reinforcement learning algorithms, the ε-greedy strategy is commonly used to select the next action, allowing the agent to balance learning and exploitation. In practical implementation, an appropriate value of ε can be determined based on the specific problem and requirements, and ε can be gradually decreased during training so that the agent can make decisions by utilizing existing knowledge more effectively.
[0068] Based on this, in some implementations, determining the first value and the first target value based on the first memory unit and the first valuation network may specifically include:
[0069] Select the first experience from the first memory unit and calculate the first value of the first action through the first valuation network;
[0070] Based on the first value and the first updated state, the maximum value among all actions in the first updated state is calculated through the first valuation network and used as the first target value.
[0071] Here, after storing the first experience in the first memory unit, the first experience is extracted from the first memory unit and input into the first valuation network. The first value of the first action in the first initial state of the first experience is calculated through the first valuation network. Then, based on the first value and the first updated state in the first experience, the most valuable or advantageous action among all possible actions in the first updated state is calculated through the first valuation network. The value of this action has the maximum value, which is the first target value.
[0072] Based on this, in some implementations, after determining the first loss function based on the first value and the first target value, since both the first value and the first target value are determined through the first valuation network, minimizing the first loss function is equivalent to updating the parameters of the first valuation network. When the first loss function reaches its minimum, the parameter update of the first valuation network is completed simultaneously. Therefore, after a first preset period, the first target network can be updated based on the parameters of the first valuation network, that is, the parameters of the first valuation network can be copied to the first target network, enabling the first target network to track and learn the latest credit assessment strategy.
[0073] Through the training process described above, the credit rating prediction model can find the optimal credit rating control strategy in credit rating prediction scenarios, predicting more accurate credit ratings. This allows it to adjust credit ratings up or down based on the prediction results and the real-time credit ratings of both parties in the transaction. For example, a credit rating grading mechanism can be established, dividing credit ratings into 1-20 levels from low to high. Levels 1-5 correspond to extremely poor credit, levels 6-10 to average credit, levels 11-15 to good credit, and levels 16-20 to excellent credit. If the real-time credit rating of both parties in a transaction is level 10, and the credit rating prediction model predicts a future credit rating of level 12 within a given timeframe, then based on the prediction result, the credit rating of both parties needs to be increased by 2 levels.
[0074] Step 102: Receive the transaction request and determine the real-time credit rating of the transaction entity corresponding to the transaction request.
[0075] Step 103: If the real-time credit rating reaches the credit rating threshold, then determine whether the real-time credit rating has reached the predicted credit rating.
[0076] Step 104: If the real-time credit rating does not reach the predicted credit rating, the transaction request is rejected; or, if the real-time credit rating reaches the predicted credit rating, the execution strategy of the smart contract in the blockchain is adjusted based on the real-time credit rating through the smart contract optimization model.
[0077] In this embodiment, after the credit rating prediction model determines the predicted credit rating, the predicted credit rating is embedded as a trigger condition into the smart contract terms. A credit rating threshold is also set. When a transaction request is received, the real-time credit rating of the transaction entity corresponding to the request is first determined, and it is then judged whether the real-time credit rating reaches the credit rating threshold. If it does not reach the threshold, the transaction request is rejected. Otherwise, it is further judged whether the real-time credit rating reaches the predicted credit rating. If it does not reach the threshold, the transaction request is rejected. Otherwise, it indicates that the real-time credit rating has reached the predicted credit rating. At this point, the execution strategy of the smart contract in the blockchain can be adjusted based on the real-time credit rating through the smart contract optimization model. The setting of the credit rating threshold varies depending on the characteristics of different industries or the standards of assessment institutions, and no restrictions are imposed here.
[0078] Based on this, in some implementations, adjusting the execution strategy of smart contracts in the blockchain through a smart contract optimization model based on real-time credit rating may specifically include:
[0079] Based on the smart contract optimization model, the mapping relationship between different credit ratings and execution strategies is determined;
[0080] Based on the mapping relationship, determine the execution strategy corresponding to the real-time credit rating;
[0081] The smart contract is adjusted based on the execution strategy corresponding to the real-time credit rating.
[0082] Here, the mapping relationship between different credit ratings and corresponding smart contract execution strategies is first determined based on the smart contract optimization model. Then, the execution strategy corresponding to the trading entity is determined based on the mapping relationship, allowing for corresponding adjustments to the smart contract. The smart contract optimization model is a Markov decision process model, defined by a state space, action space, and reward function. The state space represents all important indicators affecting smart contract execution, the action space represents all execution strategies for smart contract adjustment, and the reward function represents the evaluation indicators of credit assessment results and contract execution. The state space determines the appropriate smart contract adjustment strategy, and the action space selects the corresponding strategy. After executing the selected strategy, the reward is determined by the reward function, providing real-time feedback on the credit assessment results and contract execution. In other words, the evaluation result of the smart contract optimization model can be obtained through the reward function. A positive reward indicates accurate credit rating prediction and successful contract execution; conversely, a negative reward indicates significant deviation in credit rating prediction and problems with contract execution.
[0083] Based on this, in some implementations, the smart contract optimization model includes a second state space, a second action space, and a second reward function; the second state space represents relevant indicators affecting the execution of the smart contract, the second action space represents adjusting the execution strategy of the smart contract, and the second reward function represents the evaluation indicators of credit assessment results and contract execution; wherein, the training process of the smart contract optimization model may specifically include:
[0084] Based on the second state space, the second action space, and the second reward function, determine the second value and the second target value;
[0085] Based on the second value and the second target value, determine the second loss function;
[0086] A smart contract optimization model is trained based on the second loss function.
[0087] Here, the training process of the smart contract optimization model typically involves reinforcement learning algorithms. In reinforcement learning, the model learns how to make optimal decisions and maximize cumulative rewards through interaction with the environment. First, a second memory unit, a second value network, and a second target network need to be initialized. Then, using the second memory unit, based on the second state space, the second action space, and the second reward function, a second value and a second target value are determined for the second state space and the second action space. Next, a second loss function is determined based on the second value and the second target value. Finally, the second loss function is minimized using gradient descent to train the smart contract optimization model.
[0088] Based on this, in some implementations, determining the second value and the second target value based on the second state space, the second action space, and the second reward function may specifically include:
[0089] Initialize the second memory unit, the second estimating network, and the second target network;
[0090] Select a second initial state from the second state space, and select a second action from the second action space under the second initial state through the second valuation network;
[0091] Perform the second action and calculate the second reward using the second reward function;
[0092] Determine the second updated state based on the second initial state, the second action, and the second reward;
[0093] The second initial state, the second action, the second reward, and the second updated state are used as the second experience and stored in the second memory unit;
[0094] Based on the second memory unit and the second valuation network, the second value and the second target value are determined.
[0095] Here, after initializing the second memory unit, the second valuation network, and the second target network, a second initial state is collected from the second state space, and a second action under the second initial state is selected from the second action space through the second valuation network. Then, the second action is executed, and a second reward is returned immediately through the second reward function. Based on the second initial state, the second action, and the second reward, a new state, namely the second updated state, is formed. The second initial state, the second action, the second reward, and the second updated state are stored as the second experience in the second memory unit. Thus, based on the second memory unit and the second valuation network, the second value and the second target value for the second state space and the second action space are determined.
[0096] Here, the method for selecting the second action from the second action space can adopt the ε-greedy strategy. For details, please refer to the above content, and we will not go into too much detail here.
[0097] Based on this, in some implementations, determining the second value and the second target value based on the second memory unit and the second valuation network may specifically include:
[0098] Select a second experience from the second memory unit and calculate the second value of the second action through the second valuation network;
[0099] Based on the second value and the second updated state, the maximum value among all actions in the second updated state is calculated through the second valuation network and used as the second target value.
[0100] Here, after storing the second experience in the second memory unit, the second experience is extracted from the second memory unit and input into the second valuation network. The second value of the second action in the second initial state of the second experience is calculated through the second valuation network. Then, based on the second value and the second updated state in the second experience, the most valuable or advantageous action among all possible actions in the second updated state is calculated through the second valuation network. The action with the maximum value is the second target value.
[0101] Based on this, in some implementations, after determining the second loss function based on the second value and the second target value, since both the second value and the second target value are determined through the second valuation network, minimizing the second loss function is equivalent to updating the parameters of the second valuation network. When the second loss function reaches its minimum, the parameter update of the second valuation network is completed simultaneously. Therefore, after the second preset period, the second target network can be updated based on the parameters of the second valuation network, that is, the parameters of the second valuation network can be copied to the second target network, enabling the second target network to track and learn the latest smart contract optimization strategies.
[0102] In the technical solution of this application embodiment, a credit rating prediction model determines the predicted credit rating of the transaction entity based on environmental state information for credit assessment. It then receives transaction requests, determines the real-time credit rating of the transaction entity corresponding to the request, and if the real-time credit rating reaches a credit rating threshold, it checks whether the real-time credit rating reaches the predicted credit rating. If the real-time credit rating does not reach the predicted credit rating, the transaction request is rejected. Alternatively, if the real-time credit rating reaches the predicted credit rating, the execution strategy of the smart contract in the blockchain is adjusted based on the real-time credit rating using a smart contract optimization model. Thus, by collecting and analyzing historical transaction records, financial data, payment behavior, and other multi-dimensional information from both parties in real time through the credit rating prediction model, the credit ratings of both parties are predicted. Furthermore, based on the real-time changes in the credit ratings of both parties and the predicted credit ratings, the execution logic of the smart contract is dynamically adjusted through the smart contract optimization model. This not only enables dynamic management of smart contracts, improving their flexibility and adaptability, but also allows for self-optimization of smart contracts to adapt to new market environments and credit conditions, avoiding default risks and business losses.
[0103] This application also proposes a blockchain smart contract optimization system based on transaction credit rating prediction. Figure 2 This is a flowchart illustrating the blockchain smart contract optimization system based on transaction credit rating prediction provided in this application embodiment, as shown below. Figure 2 As shown, the method includes the following steps:
[0104] Step 201: Collect the required dataset through the data collection module, including historical transaction records of both parties (such as transaction amount, transaction frequency, whether there are any default records, etc.), key financial statement data (such as current assets, liabilities, net profit, etc.), payment behavior data (such as on-time repayment ratio, number of days of delayed repayment, etc.), and multi-dimensional status indicators such as complaint feedback information. Integrate this information to form the environmental status information required for credit assessment.
[0105] Specifically, in order to build the dataset required for an optimized blockchain smart contract system based on transaction credit rating prediction, the data collection module can integrate data from multiple sources and channels to ensure the comprehensiveness and timeliness of the information. Specific collection methods include, but are not limited to, the following:
[0106] (1) Financial institutions and credit rating agencies: Cooperate with banks, credit card companies and credit rating agencies to obtain official credit scores, credit reports and past lending and repayment records of both parties to the transaction. These data directly reflect the credit history and repayment ability of the transaction entities.
[0107] (2) Public financial reports and corporate databases: Collect annual reports and financial statements (including key indicators such as current assets, liabilities, and net profit) of companies through public channels such as corporate websites, stock exchanges, and business registration agencies to assess the financial health and capital strength of companies.
[0108] (3) Payment platform and e-commerce platform data: Cooperate with third-party payment platforms and e-commerce platforms to obtain payment behavior data of both parties in the transaction, such as transaction frequency, transaction amount, on-time repayment ratio, and number of days of delayed repayment. This data helps to measure payment habits and credit performance.
[0109] (4) Social media and user feedback: Analyze public comments, ratings and complaints on social media, as well as direct feedback collected through the customer service center, to assess the market reputation and customer satisfaction of both parties in the transaction.
[0110] (5) Industry alliances and industry associations: Join industry-related data sharing alliances or industry associations. These organizations often have transaction data, compliance records, etc. of companies in the industry, which can provide an industry-specific perspective for credit assessment.
[0111] (6) Public market data and macroeconomic indicators: Integrate public market data, such as commodity price fluctuations, market interest rates, and changes in macroeconomic policies. These macroeconomic factors can also affect the creditworthiness of both parties in a transaction.
[0112] (7) Government public databases and legal documents: Search public databases such as court announcements, bankruptcy records, and tax registrations to obtain information on legal proceedings and tax compliance of the parties involved in the transaction in order to assess potential legal risks.
[0113] The data collected through the aforementioned channels, after being cleaned, integrated, and standardized, forms the dataset required for credit assessment, providing a solid foundation for subsequent credit rating prediction and smart contract optimization.
[0114] Step 202: Apply the credit rating prediction module to predict the credit rating of both parties in the transaction in real time, and store the prediction results on the blockchain as the basis for the decision to execute the smart contract.
[0115] Specifically, the dataset collected by the data collection module is first defined into states based on its features. The state St is defined as (delinquency rate Mt, repayment timeliness index Mj, registered capital Mz, transaction activity index Mh, ...). Among them, the delinquency rate Mt is calculated from the transaction history, the repayment timeliness index Mj comes from payment records, the registered capital Mz comes from financial reports, and the transaction activity index Mh is calculated based on the transaction frequency.
[0116] Here, the delinquency rate (Mt) is used to measure the proportion of transactions in which the transacting party has failed to repay on time, and its calculation formula is as follows:
[0117]
[0118] Here, Mod represents the number of overdue transactions, indicating the number of transactions that have not been repaid within the stipulated time, and Mn represents the total number of transactions, indicating the total number of all completed transactions by the transacting party. The number of overdue transactions and the total number of transactions can be directly calculated from the transaction history.
[0119] Here, the repayment timeliness indicator (Mj) reflects the frequency with which a transacting party makes timely repayments. The specific calculation method is to calculate the on-time repayment ratio, and the formula is as follows:
[0120]
[0121] Here, Mr represents the number of transactions due for repayment, referring to the total number of transactions for which repayment is due by the transacting party, and Mtr represents the number of transactions repaid on time, referring to the number of transactions that were repaid on time (without overdue payments) within the stipulated time. The number of transactions due for repayment and the number of transactions repaid on time can be directly calculated from the transaction history.
[0122] Here, the average number of days of delayed repayment can also be calculated to quantify the frequency of on-time repayments. For each transaction with delayed repayment, its average number of days of delayed repayment (Ad) is calculated using the following formula:
[0123]
[0124] Here, Mi represents the number of days of delayed repayment for each transaction, referring to the number of days between the repayment deadline and the actual repayment date for each overdue payment. N represents the number of transactions with delayed repayments, referring to the number of transactions that were not repaid within the stipulated time (overdue repayments). It should be noted that the specific method used to reflect the frequency of timely repayments by the transacting party depends on business needs. The timely repayment indicator is used to measure the punctuality of repayments, while the average number of days of delayed repayment is used to measure the severity of delayed repayments.
[0125] Here, the registered capital (Mz) is extracted directly from the financial report. Usually, no complicated calculations are required. The amount of registered capital registered by the enterprise or individual business with the industrial and commercial department can be directly recorded.
[0126] Here, the trading activity index (Mh) measures the frequency of trading within a certain period of time. It is generally measured by the number of trades per unit of time, and its calculation formula is as follows:
[0127]
[0128] Where TMn is the number of transactions within a specific time period, and Tl is the length of that time period, which is calculated in fixed units such as days or months.
[0129] These indicators, taken together, can comprehensively reflect the creditworthiness and trading habits of both parties in a transaction, providing key inputs for credit rating prediction.
[0130] Based on this, the credit rating prediction problem can be constructed as a Markov decision process model, defining a state space St, an action space a, and a reward function r. Here, the state space St represents the credit status of the two parties in the transaction, the action space a represents possible credit assessment strategies or credit rating adjustment strategies, and the reward function r represents the evaluation index of credit rating.
[0131] For action space a, a series of adjustable credit assessment parameters are set in action space a, with historical transaction weights θ. z Financial stability weight θ f Behavioral performance weights θ c Industry position weight θ s Macroeconomic impact weight θ n By adjusting these weights, credit ratings can be predicted or evaluated, i.e., a = [θ] z ,θ f ,θ c ,θ s ,θ n ].
[0132] For the reward function r, the performance rate (PR) and the complaint rate (CR) are selected as credit rating indicators. Specifically, if the PR is less than 95% or the CR is greater than a predetermined threshold (set according to actual needs), the reward function r is set to -1; if the PR is greater than 95% and the CR is less than the predetermined threshold (set according to actual needs), then the reward function r = W1 (contract performance rate reward parameter) + W2 (complaint rate reward parameter) + W3 (reward parameter for achieving specific business goals), where W1, W2, and W3 represent the weight parameters of the contract performance rate reward parameter, the complaint rate reward parameter, and the revenue reward parameter for the same period, respectively.
[0133] Here, the formula for calculating the contract fulfillment rate bonus parameter is:
[0134]
[0135] Among them, Performance Reward represents the contract performance rate reward parameter, and PR represents the contract performance rate.
[0136] Here, the formula for calculating the complaint rate bonus parameter is:
[0137] Complaint Reward = |1-CR| (6)
[0138] Here, Complaint Reward represents the complaint rate reward parameter, and CR represents the business complaint rate.
[0139] Here, the formula for calculating the reward parameters for achieving specific business targets (revenue in the same period) is:
[0140]
[0141] Among them, Business Objective Reward represents the reward parameter for achieving a specific business goal (revenue in the same period), Turnover1 represents the current revenue, and Turnover0 represents the revenue in the same period last year.
[0142] Based on this, it can be seen from the relevant indicators of the reward function that the weighted result of contract fulfillment rate, business complaint rate, and revenue determines the value of the reward function r, which is the evaluation result of the credit rating prediction model. The reward function shows that the model needs the largest possible r value; that is, the higher the PR, the lower the CR, and the higher the current revenue, the higher the r value, and vice versa. Furthermore, if PR and CR do not meet the threshold requirements, a negative feedback value of -1 is assigned to r, thus reflecting the accuracy of the credit rating prediction and the actual loss of bad debt risk.
[0143] The training phase of a credit rating prediction model typically involves reinforcement learning algorithms, including:
[0144] (1) Initialization phase
[0145] Memory unit: Create a buffer to store the previously experienced state-action-reward-new state quadruple (St,a,r,St+1). These quadruple samples will be reused in subsequent training.
[0146] Valuation Network: Construct a Deep Q-Network (DQN) with parameters denoted as θ, used to estimate the value Q of performing a certain action in the current state.
[0147] Target network: Construct another network with the same structure, denoted by parameters θ. ′ , used to stabilize the learning process, defines the parameters to be updated as the value network.
[0148] (2) Data sampling and Q-value calculation
[0149] The state St is collected from the environment, and an action a is selected based on the valuation network (which can be determined by the ε-greedy policy). After the action a is executed, the environment returns an immediate reward r and a new state St+1. The experience (St, a, r, St+1) is stored in the memory unit.
[0150] (3) Q-value update and network optimization
[0151] Randomly sample a quadruple of data (St,a,r,St+1) from the memory unit, and use the valuation network to calculate the Q-value of action a in the current state St, denoted as Q(St,a;θ); simultaneously calculate the target Q-value according to the Bellman equation, the formula of which is:
[0152] Target_Q=r+γa ′ maxQ(St+1,a′;θ′) (8)
[0153] Here, γ is a discount factor used to discount future rewards, and a′ represents the best possible action in the next state St+1, which is considered the most valuable or advantageous action in the new state. It is relative to the current action a. When calculating the target Q value, it is determined by selecting the maximum Q value of all possible actions under the future state St+1. The purpose is to guide the system to learn how to select actions based on the current state in order to obtain the maximum cumulative reward.
[0154] (4) Loss function and gradient update
[0155] After calculating the Q-value of action a and the target Q-value in the current state St, the loss function is defined as the mean squared error of TD-error. The gradient of the loss function with respect to the weight parameters θ is calculated, and the weights θ of the estimation network are updated using gradient descent to reduce the loss. The formula for the loss function is:
[0156] L(θ)=E[(Target_Q-Q(St,a;θ))2] (9)
[0157] Where Target_Q is the target Q value, and Q(St,a;θ) is the Q value of action a under the current state St.
[0158] (5) Periodic synchronization target network
[0159] After the loss function converges, the parameters θ of the valuation network are copied to the target network θ′ at regular intervals, so that the target network can track the latest learned credit assessment strategy.
[0160] Through the training process described above, the credit rating prediction model can find the optimal credit rating control strategy in credit rating prediction scenarios, predicting more accurate credit ratings. This allows it to adjust credit ratings up or down based on the prediction results and the real-time credit ratings of both parties in the transaction. For example, a credit rating grading mechanism can be established, dividing credit ratings into 1-20 levels from low to high. Levels 1-5 correspond to extremely poor credit, levels 6-10 to average credit, levels 11-15 to good credit, and levels 16-20 to excellent credit. If the real-time credit rating of both parties in a transaction is level 10, and the credit rating prediction model predicts a future credit rating of level 12 within a given timeframe, then based on the prediction result, the credit rating of both parties needs to be increased by 2 levels.
[0161] Step 203: Smart contract dynamically triggered based on credit rating: When designing a smart contract, the predicted credit rating is embedded as a trigger condition into the contract terms. When the contract receives a transaction request, it will automatically determine whether the execution conditions are met based on the real-time credit ratings of both parties. That is, when the real-time credit rating reaches the credit rating threshold, the contract will be triggered. At this time, it will determine whether the real-time credit rating reaches the predicted credit rating. If it does, it means that the contract requirements are met, and the smart contract optimization process will be executed automatically. Otherwise, the contract will reject the transaction request.
[0162] Here, the choice of credit rating thresholds in practical applications will be adjusted according to the characteristics of specific industries or the standards of assessment agencies. For example, a credit rating grading mechanism can be established, dividing credit ratings into 1-20 levels from low to high, with levels 1-5 corresponding to extremely poor credit, levels 6-10 to average credit, levels 11-15 to good credit, and levels 16-20 to excellent credit. Alternatively, internationally accepted standards can be followed, dividing credit ratings into three grades and nine levels, specifically AAA, AA, A, BBB, BB, B, CCC, CC, C, and D. These levels reflect the level of an entity's credit quality, with AAA representing the highest credit quality and D indicating a very poor credit condition, close to or already in default.
[0163] Step 204: Smart Contract Optimization. When the smart contract is triggered for execution, the smart contract optimization module will dynamically optimize and adjust the execution logic and rules of the smart contract based on the real-time credit assessment results. For example, it may change the execution order of the contract, update the guarantee measures, or adjust the profit distribution rules to ensure that the smart contract maximizes execution efficiency while reducing the risk of default.
[0164] Here, the specific implementation steps of the smart contract optimization module to dynamically optimize the execution logic of smart contracts are similar to the algorithmic approach of the aforementioned transaction credit rating prediction model. Specifically, the smart contract optimization problem is constructed as a Markov decision process model, defining the state space St1, the dynamic space a1, and the reward function r1. This includes:
[0165] For the state space St1, it is constructed based on the real-time credit ratings of the two parties in the transaction predicted by the credit rating prediction module and other relevant environmental state information (such as transaction volume, market volatility, external regulatory policies, etc.). It contains all the important indicators that affect the execution of smart contracts.
[0166] For the dynamic space a1, it represents the possible adjustment execution strategies of the smart contract, such as adjusting the contract execution order, increasing or decreasing the guarantee requirements, redistributing contract benefits, adjusting the contract triggering conditions, etc. These actions can be reflected by adjusting the corresponding business volume weight values (such as credit rating weight, risk tolerance weight, etc.).
[0167] For the reward function r1, factors such as credit assessment results, contract execution status, and market reaction are selected as evaluation indicators for smart contract execution. That is, if the credit rating prediction is accurate, the contract is executed smoothly, and no default events occur, a positive reward is given; conversely, if there is a large deviation in the credit rating prediction or problems occur in contract execution, a negative penalty is given. At the same time, the reward function r1 also considers factors related to execution efficiency and risk reduction, such as incorporating external regulatory policy reward parameters, credit rating consistency reward parameters, and market volatility reward parameters through weighted parameters such as W1, W2, and W3.
[0168] The training phase of smart contract optimization models typically involves reinforcement learning algorithms, including:
[0169] (1) Initialization phase
[0170] Memory unit: Create a buffer to store the previously experienced state-action-reward-new state quadruple (St1,a1,r1,St1+1). These quadruple samples will be reused in subsequent training.
[0171] Valuation Network: Construct a DQN with parameters denoted as θ1, used to estimate the value Q of performing a certain action in the current state.
[0172] Target network: Construct another network with the same structure, denoted by parameters θ1. ′ , used to stabilize the learning process, defines the parameters to be updated as the value network.
[0173] (2) Data sampling and Q-value calculation
[0174] The state St1 is collected from the environment, and an action a1 is selected according to the valuation network (which can be determined by the ε-greedy policy). After the action a1 is executed, the environment returns an immediate reward r1 and a new state St1+1. The experience (St1, a1, r1, St1+1) is stored in the memory unit.
[0175] (3) Q-value update and network optimization
[0176] Randomly sample a quadruple of data (St1, a1, r1, St1+1) from the memory unit, and use the valuation network to calculate the Q-value of action a1 in the current state St1, denoted as Q(St1, a1; θ1); simultaneously calculate the target Q-value according to the Bellman equation, the formula of which is:
[0177] Target1_Q=r1+γa1 ′ maxQ(St1+1,a1′;θ1′) (10)
[0178] Here, γ is a discount factor used to discount future rewards, and a1′ represents the best possible action in the next state St1+1, which is considered the most valuable or advantageous action in the new state. It is relative to the current action a1. When calculating the target Q value, it is determined by selecting the maximum Q value of all possible actions under the future state St1+1. The purpose is to guide the system to learn how to select actions based on the current state in order to obtain the maximum cumulative reward.
[0179] (4) Loss function and gradient update
[0180] After calculating the Q-value of action a1 and the target Q-value in the current state St1, the loss function is defined as the mean squared error of TD-error. The gradient of the loss function with respect to the weight parameter θ1 is calculated, and the weights θ1 of the estimation network are updated using gradient descent to reduce the loss. The formula for the loss function is:
[0181] L(θ1)=E[(Target1_Q-Q(St1,a1;θ1))2] (11)
[0182] Where Target1_Q is the target Q value, and Q(St1,a1;θ1) is the Q value of action a1 under the current state St1.
[0183] (5) Periodic synchronization target network
[0184] After the loss function converges, the parameters θ1 of the valuation network are copied to the target network θ1′ at regular intervals, so that the target network can track the latest learned smart contract optimization strategy.
[0185] Through the training process described above, the smart contract optimization model can find the optimal smart contract optimization strategy. This enables the dynamic optimization and adjustment of the smart contract's execution logic using reinforcement learning algorithms, making it more adaptable to complex and ever-changing market environments and the changing credit status of the transacting parties. For example, when the system discovers through the smart contract optimization model that a transacting party with a higher credit rating is more suitable for early execution of certain terms, or that additional collateral is needed to address potential risks, the smart contract will automatically adjust its execution order or collateral requirements, ensuring that risk is minimized while maximizing execution efficiency.
[0186] In the technical solution provided in this application, the credit rating prediction problem is constructed into a Markov decision process model based on multi-dimensional state indicators such as historical transaction records, key financial statement data, payment behavior data, and complaint feedback information of both parties. Based on a reinforcement learning strategy, the optimal credit rating control strategy is obtained in the credit rating prediction scenario, thereby enabling real-time and accurate prediction of the credit rating of the trading entities and effectively improving risk control. Simultaneously, the smart contract optimization module, based on the real-time credit ratings of both parties predicted by the credit rating prediction module and other relevant environmental state information, obtains the optimal smart contract optimization strategy based on a reinforcement learning strategy. This strategy dynamically optimizes and adjusts the execution logic and rules of the smart contract, thereby ensuring that execution efficiency is maximized while reducing risk.
[0187] This application also proposes a smart contract optimization device. Figure 3 This is a schematic diagram of the structure of the smart contract optimization device provided in the embodiments of this application, as shown below. Figure 3 As shown, the device includes:
[0188] The determining unit 301 is used to determine the predicted credit rating of the transaction entity based on the environmental status information of credit assessment through the credit rating prediction model; and to receive transaction requests and determine the real-time credit rating of the transaction entity corresponding to the transaction request.
[0189] The judgment unit 302 is used to determine whether the real-time credit rating has reached the predicted credit rating if the real-time credit rating reaches the credit rating threshold.
[0190] The processing unit 303 is used to reject a transaction request if the real-time credit rating does not reach the predicted credit rating; or, if the real-time credit rating reaches the predicted credit rating, adjust the execution strategy of the smart contract in the blockchain based on the real-time credit rating through a smart contract optimization model.
[0191] In some implementations, the determining unit 301 is specifically used to convert the environmental state information of credit assessment into a state feature vector; input the state feature vector into the credit rating prediction model; and output the predicted credit rating through the credit rating prediction model.
[0192] In some implementations, the processing unit 303 is specifically used to determine the mapping relationship between different credit ratings and execution strategies based on the smart contract optimization model; determine the execution strategy corresponding to the real-time credit rating based on the mapping relationship; and adjust the smart contract based on the execution strategy corresponding to the real-time credit rating.
[0193] In some embodiments, the device further includes:
[0194] The first training unit is used to determine a first value and a first target value based on a first state space, a first action space, and a first reward function; determine a first loss function based on the first value and the first target value; and train a credit rating prediction model based on the first loss function. The credit rating prediction model includes a first state space, a first action space, and a first reward function. The first state space represents the credit rating status of the transaction entity, the first action space represents the credit rating assessment strategy, and the first reward function represents the credit rating evaluation index.
[0195] The second training unit is used to determine the second value and the second target value based on the second state space, the second action space, and the second reward function; to determine the second loss function based on the second value and the second target value; and to train the smart contract optimization model based on the second loss function. The smart contract optimization model includes the second state space, the second action space, and the second reward function. The second state space represents relevant indicators affecting the execution of the smart contract, the second action space represents the execution strategy of the smart contract, and the second reward function represents the evaluation indicators of the credit assessment results and the contract execution status.
[0196] In some implementations, the first training unit is specifically used to initialize a first memory unit, a first valuation network, and a first target network; select a first initial state from a first state space, and select a first action from a first action space under the first initial state through the first valuation network; execute the first action, and calculate a first reward through a first reward function; determine a first updated state based on the first initial state, the first action, and the first reward; store the first initial state, the first action, the first reward, and the first updated state as a first experience in the first memory unit; and determine a first value and a first target value based on the first memory unit and the first valuation network.
[0197] In some implementations, the first training unit is further specifically used to select a first experience from the first memory unit and calculate a first value of the first action through the first valuation network; based on the first value and the first update state, the maximum value among all actions in the first update state is calculated through the first valuation network as the first target value.
[0198] In some implementations, the first training unit is further specifically used to update the first target network based on the parameters of the first valuation network after a first preset period.
[0199] In some implementations, the second training unit is specifically used to initialize a second memory unit, a second valuation network, and a second target network; select a second initial state from a second state space, and select a second action from a second action space under the second initial state through the second valuation network; execute the second action, and calculate a second reward through a second reward function; determine a second updated state based on the second initial state, the second action, and the second reward; store the second initial state, the second action, the second reward, and the second updated state as a second experience in the second memory unit; and determine a second value and a second target value based on the second memory unit and the second valuation network.
[0200] In some implementations, the second training unit is further specifically used to select a second experience from the second memory unit and calculate a second value of the second action through the second valuation network; based on the second value and the second updated state, the maximum value among all actions in the second updated state is calculated through the second valuation network as the second target value.
[0201] In some implementations, the second training unit is also specifically used to update the second target network based on the parameters of the second valuation network after a second preset period.
[0202] In the technical solution of this application embodiment, a credit rating prediction model determines the predicted credit rating of the transaction entity based on environmental state information for credit assessment. It then receives transaction requests, determines the real-time credit rating of the transaction entity corresponding to the request, and if the real-time credit rating reaches a credit rating threshold, it checks whether the real-time credit rating reaches the predicted credit rating. If the real-time credit rating does not reach the predicted credit rating, the transaction request is rejected. Alternatively, if the real-time credit rating reaches the predicted credit rating, the execution strategy of the smart contract in the blockchain is adjusted based on the real-time credit rating using a smart contract optimization model. Thus, by collecting and analyzing historical transaction records, financial data, payment behavior, and other multi-dimensional information from both parties in real time through the credit rating prediction model, the credit ratings of both parties are predicted. Furthermore, based on the real-time changes in the credit ratings of both parties and the predicted credit ratings, the execution logic of the smart contract is dynamically adjusted through the smart contract optimization model. This not only enables dynamic management of smart contracts, improving their flexibility and adaptability, but also allows for self-optimization of smart contracts to adapt to new market environments and credit conditions, avoiding default risks and business losses.
[0203] Those skilled in the art should understand that Figure 3 The functions of each unit in the smart contract optimization device shown can be understood by referring to the relevant description of the aforementioned method. Figure 3 The functions of each unit in the smart contract optimization device shown can be implemented by a program running on a processor or by specific logic circuits.
[0204] Figure 4 This is a schematic diagram of the processing device provided in an embodiment of this application. The processing device may be a terminal device or a network device. Figure 4 The processing device shown includes a processor 401, which can call and run computer programs from memory to implement the methods in the embodiments of this application.
[0205] Optionally, such as Figure 4 As shown, the processing device may further include a memory 402. The processor 401 can retrieve and run computer programs from the memory 402 to implement the methods described in this embodiment.
[0206] The memory 402 can be a separate device independent of the processor 401, or it can be integrated into the processor 401.
[0207] Optionally, such as Figure 4 As shown, the processing device may also include a transceiver 403, which the processor 401 can control to communicate with other devices. Specifically, it can send information or data to other devices or receive information or data sent by other devices.
[0208] The transceiver 403 may include a transmitter and a receiver. The transceiver 403 may further include an antenna, and the number of antennas may be one or more.
[0209] The processing device may specifically be the smart contract optimization device in the embodiments of this application, and the processing device can implement the corresponding processes implemented by the smart contract optimization device in the various methods of the embodiments of this application. For the sake of brevity, it will not be described in detail here.
[0210] It should be understood that the processor in the embodiments of this application may be an integrated circuit chip with signal processing capabilities. In implementation, the steps of the above method embodiments can be completed by integrated logic circuits in the processor's hardware or by instructions in software form. The processor described above can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this application can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software modules can be located in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. The storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method.
[0211] It is understood that the memory in the embodiments of this application can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced Synchronous DRAM (ESDRAM), Synchlink DRAM (SLDRAM), and Direct Rambus RAM (DR RAM). It should be noted that the memory used in the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0212] It should be understood that the above-described memory is exemplary and not a limiting description. For example, the memory in the embodiments of this application may also be static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct memory bus RAM (DR RAM), etc. That is to say, the memory in the embodiments of this application is intended to include, but is not limited to, these and any other suitable types of memory.
[0213] This application also provides a computer-readable storage medium for storing a computer program. This computer-readable storage medium can be applied to the processing device in the embodiments of this application, and the computer program causes the computer to execute the corresponding processes implemented by the smart contract optimization device in the various methods of the embodiments of this application; for the sake of brevity, further details are omitted here.
[0214] This application also provides a computer program product, including computer program instructions. This computer program product can be applied to the processing device in this application embodiment, and the computer program instructions cause the computer to execute the corresponding processes implemented by the smart contract optimization device in the various methods of this application embodiment; for simplicity, further details are omitted here.
[0215] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0216] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0217] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0218] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0219] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0220] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0221] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A smart contract optimization method, characterized in that, The method includes: The predicted credit rating of a transaction entity is determined based on environmental information related to credit assessment using a credit rating prediction model. Receive a transaction request and determine the real-time credit rating of the transaction entity corresponding to the transaction request; If the real-time credit rating reaches the credit rating threshold, then determine whether the real-time credit rating has reached the predicted credit rating. If the real-time credit rating does not reach the predicted credit rating, the transaction request is rejected; or, if the real-time credit rating reaches the predicted credit rating, the execution strategy of the smart contract in the blockchain is adjusted based on the real-time credit rating through a smart contract optimization model.
2. The method according to claim 1, characterized in that, The method of determining the predicted credit rating of a transaction entity based on environmental information for credit assessment using a credit rating prediction model includes: The environmental status information of the credit assessment is converted into a state feature vector; The state feature vector is input into the credit rating prediction model, and the predicted credit rating is output through the credit rating prediction model.
3. The method according to claim 1, characterized in that, The step of adjusting the execution strategy of smart contracts in the blockchain based on the real-time credit rating through a smart contract optimization model includes: Based on the aforementioned smart contract optimization model, the mapping relationship between different credit ratings and execution strategies is determined; Based on the mapping relationship, the execution strategy corresponding to the real-time credit rating is determined; The smart contract is adjusted based on the execution strategy corresponding to the real-time credit rating.
4. The method according to any one of claims 1 to 3, characterized in that, The credit rating prediction model includes a first state space, a first action space, and a first reward function; the first state space represents the credit rating status of the transaction entity, the first action space represents the credit rating assessment strategy, and the first reward function represents the credit rating evaluation index; the method further includes: Based on the first state space, the first action space, and the first reward function, determine the first value and the first target value; Based on the first value and the first target value, a first loss function is determined; The credit rating prediction model is trained based on the first loss function.
5. The method according to claim 4, characterized in that, The determination of the first value and the first target value based on the first state space, the first action space, and the first reward function includes: Initialize the first memory unit, the first estimation network, and the first target network; A first initial state is selected from the first state space, and a first action in the first initial state is selected from the first action space through the first valuation network; Perform the first action and calculate the first reward using the first reward function; Based on the first initial state, the first action, and the first reward, determine the first update state; The first initial state, the first action, the first reward, and the first updated state are taken as the first experience and stored in the first memory unit; Based on the first memory unit and the first valuation network, the first value and the first target value are determined.
6. The method according to claim 5, characterized in that, The determination of the first value and the first target value based on the first memory unit and the first valuation network includes: The first experience is selected from the first memory unit, and the first value of the first action is calculated through the first valuation network; Based on the first value and the first updated state, the maximum value among all actions in the first updated state is calculated through the first valuation network and used as the first target value.
7. The method according to claim 6, characterized in that, The method further includes: After the first preset period, the first target network is updated based on the parameters of the first valuation network.
8. The method according to any one of claims 1 to 3, characterized in that, The smart contract optimization model includes a second state space, a second action space, and a second reward function; the second state space represents relevant indicators affecting the execution of the smart contract, the second action space represents adjusting the execution strategy of the smart contract, and the second reward function represents the evaluation indicators of credit assessment results and contract execution status; the method further includes: Based on the second state space, the second action space, and the second reward function, determine the second value and the second target value; Based on the second value and the second target value, determine the second loss function; The smart contract optimization model is trained based on the second loss function.
9. The method according to claim 8, characterized in that, The determination of the second value and the second target value based on the second state space, the second action space, and the second reward function includes: Initialize the second memory unit, the second estimating network, and the second target network; Select a second initial state from the second state space, and select a second action from the second action space under the second initial state through the second valuation network; Perform the second action and calculate the second reward using the second reward function; Based on the second initial state, the second action, and the second reward, determine the second updated state; The second initial state, the second action, the second reward, and the second updated state are used as the second experience and stored in the second memory unit; Based on the second memory cell and the second valuation network, the second value and the second target value are determined.
10. The method according to claim 9, characterized in that, The determination of the second value and the second target value based on the second memory unit and the second valuation network includes: The second experience is selected from the second memory unit, and the second value of the second action is calculated through the second valuation network; Based on the second value and the second updated state, the maximum value among all actions in the second updated state is calculated through the second valuation network and used as the second target value.
11. The method according to claim 10, characterized in that, The method further includes: After the second preset period, the second target network is updated based on the parameters of the second valuation network.
12. A smart contract optimization device, characterized in that, The device includes: The determining unit is used to determine the predicted credit rating of a transaction entity based on environmental status information of credit assessment using a credit rating prediction model; and to receive a transaction request and determine the real-time credit rating of the transaction entity corresponding to the transaction request. The judgment unit is used to determine whether the real-time credit rating has reached the predicted credit rating if the real-time credit rating reaches the credit rating threshold. The processing unit is configured to reject the transaction request if the real-time credit rating does not reach the predicted credit rating; or, if the real-time credit rating reaches the predicted credit rating, adjust the execution strategy of the smart contract in the blockchain based on the real-time credit rating through a smart contract optimization model.
13. A processing apparatus, characterized in that, include: A processor and a memory for storing a computer program, the processor for calling and running the computer program stored in the memory to perform the method as described in any one of claims 1 to 11.
14. A computer-readable storage medium, characterized in that, Used to store a computer program that causes a computer to perform the method as described in any one of claims 1 to 11.
15. A computer program product, characterized in that, It includes computer program instructions that cause a computer to perform the method as described in any one of claims 1 to 11.