Block chain system intelligent contract transaction conflict detection system and method based on federal learning
By adopting a smart contract transaction conflict detection method based on federated learning in the blockchain system, the transaction conflict problem caused by optimistic parallel mechanism is solved, and more efficient and reliable transaction processing is achieved.
Patent Information
- Application Number
- CN202411789623.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2044-12-06
AI Technical Summary
The optimistic parallel mechanism leads to transaction conflicts in the blockchain system, resulting in congestion in transaction pools and loss of transactions, affecting system reliability and user experience.
The smart contract transaction conflict detection method based on federated learning is adopted. The smart contract transaction conflict detection model is trained locally through the client to predict the transaction conflict probability, and the global model is aggregated through federated learning to detect and resolve transaction conflicts.
It improves the accuracy and efficiency of transaction conflict detection, protects data privacy, reduces transaction loss, and improves system performance and reliability.
Smart Images

Figure CN119671731A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of smart contract security detection in blockchain, and in particular to a blockchain system smart contract transaction conflict detection system and method based on federated learning. Background Art
[0002] As blockchain technology continues to develop, smart contracts play an increasingly important role in blockchain networks. Smart contracts are automatically executed, unchangeable contracts whose rules and conditions exist in the form of code in the blockchain. While these contracts ensure that transactions are transparent and cannot be tampered with, they also face challenges in transaction processing, especially conflicts caused by parallel transaction processing.
[0003] In recent blockchain systems, optimistic parallelism has been widely used for its advantages in improving transaction processing throughput and efficiency. For example, Aptos, Sui, Monad, and my country's independently developed Changan Chain have begun to use this advanced execution mechanism. However, this mechanism often causes transaction conflicts, that is, multiple transactions attempt to modify the same data or resources, resulting in conflicts in transactions that perform read and write operations. Transaction conflicts not only cause congestion in the blockchain transaction pool, but may also trigger a timeout mechanism, leading to transaction loss, thereby affecting the reliability and user experience of the entire blockchain system.
[0004] In order to cope with these challenges, traditional methods usually rely on centralized conflict detection mechanisms, but this method has problems such as insufficient data privacy protection and centralized computing resources. Therefore, it is necessary to provide a blockchain system smart contract transaction conflict detection method that can detect potential conflicting transactions in smart contracts, improve the accuracy and efficiency of transaction conflict detection while protecting data privacy, and effectively detect and resolve transaction conflicts in a multi-client environment, avoid transaction loss, and improve the performance and reliability of the entire system. Summary of the invention
[0005] The purpose of the present invention is to provide a blockchain system smart contract transaction conflict detection system and method based on federated learning, which is used to solve the transaction conflict problem caused by the optimistic parallel mechanism in the existing blockchain system.
[0006] To achieve the above objectives, the present invention provides a blockchain system smart contract transaction conflict detection method based on federated learning, comprising: First, each client runs the smart contract, obtains the read-write set of the transaction, and annotates it; Secondly, based on the read-write set of the annotated transactions, the smart contract transaction conflict detection model is trained locally to predict the probability of transaction conflicts, and the trained smart contract transaction conflict detection model is uploaded to the blockchain; Then, federated learning is used to aggregate the trained smart contract transaction conflict detection model to generate a global smart contract transaction conflict detection model, which is distributed to the client for iteration.
[0007] Preferably, the smart contract contains address information of the transaction read-write set.
[0008] Preferably, the client uses a global smart contract transaction conflict detection model to detect the submitted smart contract and determine whether it contains a transaction conflict; When a transaction conflict is detected, the smart contract will be rejected from being uploaded to the blockchain; When the test passes, there is no transaction conflict in the smart contract. At this time, it is uploaded to the blockchain through the consensus node and waits for further processing.
[0009] Preferably, training the smart contract transaction conflict detection model locally includes training the TransFormer model based on the labeled transaction read and write set: First, the data is converted into vector representation through an encoder and a decoder; Next, a fully connected layer is used to map the vector representation generated by the decoder to a log-probability vector to predict whether a transaction conflicts. Then, the log-odds vector is converted into probability through the SoftMax layer to determine the probability of conflict for each transaction.
[0010] A blockchain system smart contract transaction conflict detection system based on federated learning, comprising: The client is used to obtain the read and write sets of transactions to complete the local training of the smart contract transaction conflict detection model; Consensus nodes are used to upload the locally trained smart contract transaction conflict detection model and distribute the global smart contract transaction conflict detection model to clients participating in federated learning; The blockchain is used to receive the locally trained smart contract transaction conflict detection model, complete global aggregation, and train the global smart contract transaction conflict detection model.
[0011] Preferably, the system includes consensus nodes, and each consensus node is connected to a client.
[0012] Therefore, the present invention adopts the above-mentioned blockchain system smart contract transaction conflict detection system and method based on federated learning, which has the following technical effects: (1) In terms of enhancing data privacy protection, through federated learning, transaction read and write set data is always retained locally, and only model parameters are transmitted, reducing the risk of data leakage; in terms of improving the adaptability of the model, the continuous updating and iteration of the global model enables it to better adapt to the business scenarios of different clients, improving the versatility and accuracy of the model; in terms of optimizing transaction processing efficiency, by pre-detecting transaction conflicts, the congestion of the blockchain transaction pool is reduced, and the transaction processing speed and system performance are improved.
[0013] (2) Build a client and blockchain end to collaborate in detecting conflicting transactions on smart contracts. The client deployed on each consensus node performs local training on the read-write set in the smart contract, aggregates the global model on the decentralized blockchain, and then returns it to each client to implement smart contract transaction conflict detection. This effectively utilizes the decentralized characteristics of the blockchain and the distributed training mechanism of federated learning, which can improve the efficiency and accuracy of transaction processing and reduce the problem of transaction loss caused by transaction conflicts.
[0014] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 It is an overall structure diagram of a blockchain system smart contract transaction conflict detection system based on federated learning; Figure 2 It is a flowchart of model training in an embodiment of a blockchain system smart contract transaction conflict detection system and method based on federated learning; Figure 3 The present invention is a flowchart of a global smart contract transaction conflict detection model applied by a client in an embodiment of a blockchain system smart contract transaction conflict detection system and method based on federated learning. DETAILED DESCRIPTION
[0016] The present invention can be explained in more detail by the following examples. The purpose of disclosing the present invention is to protect all changes and improvements within the scope of the present invention. The present invention is not limited to the following examples.
[0017] Embodiment 1 First, build a blockchain system smart contract transaction conflict detection system based on federated learning, such as Figure 1 In this system structure, the blockchain network contains N consensus nodes, each of which is connected to multiple clients, forming a multi-level federated learning and smart contract transaction conflict detection system. The specific workflow is as follows: At the client level, the operation process is divided into two parts: On the one hand, the client uses the transaction read-write set in the smart contract as a data set to perform smart contract transaction conflict detection model training locally. This process uses the local transaction read-write set data for training to obtain a preliminary smart contract transaction conflict detection model. After the training is completed, the local smart contract transaction conflict detection model is uploaded to the blockchain through the consensus node to participate in the aggregation of the global model. The global model is an aggregation of the local models of each client. It is gradually iterated through federated learning until the accuracy of the global model converges to ensure that its performance is sufficient to support the detection of smart contract conflict transactions, and then the global model is sent to each client. On the other hand, each client uses the obtained global model to detect the smart contract to be submitted to determine whether it contains transaction conflicts. If a transaction conflict is detected, the smart contract will be rejected on the chain; if the detection passes, indicating that there is no transaction conflict in the contract, it can be uploaded to the blockchain through the consensus node for further processing.
[0018] On the blockchain side, the operation is also divided into two parts: first, the blockchain system packages all conflict-free transactions that have passed the detection into a block and records the block in the blockchain to ensure the security and immutability of the data; second, the blockchain system receives the local models uploaded by each client through the consensus node, and globally aggregates these models to form a unified global smart contract conflict transaction detection model. The global model is then sent back to each client participating in federated learning for subsequent use and optimization. This process will continue to cycle until it reaches a convergence state, thereby generating an efficient global smart contract conflict transaction detection model. This model combines the read-write set conflict data and detection model information of each client, and represents the smart contract transaction conflict knowledge of the entire system.
[0019] Since the optimistic parallel mechanism used in existing blockchains often leads to transaction conflicts, which in turn causes congestion in the transaction pool, some transactions may trigger the blockchain's timeout mechanism and eventually lose the transaction. Therefore, in the blockchain smart contract detection system based on federated learning, the use of federated learning to train the smart contract transaction conflict detection model is a key part, that is, by training the smart contract read-write set locally without uploading these read-write sets to the central server, the local transaction privacy is effectively protected, and the detection model can be optimized using local computing resources, such as Figure 2 shown.
[0020] Embodiment 2 In the blockchain smart contract detection method based on federated learning, the model training process is as follows: First, the client uses a large number of pre-labeled smart contract transaction read and write sets as data sets for training. Each of these smart contracts may contain multiple Methods, and the key and field values of the key functions (Put state and Getstate) in each Method represent the address of the transaction read and write set. When the key and field values of Put state and Get state in the same Method are equal, the system will determine it as a conflicting transaction. This means that simultaneous read and write operations are attempted on the same data address in the same Method. Similarly, if the key and field values of Put state and Getstate in two or more different Methods are equal, it will also be regarded as a conflicting transaction. At this time, there is a conflict in the reading and writing of the same data address by different methods.
[0021] During the model training process, the Method marked as 0 represents a non-conflicting transaction, that is, the transaction read and write operations do not interfere with each other; and the Method marked as 1 represents a conflicting transaction, that is, the read and write operations of the same address conflict. Based on these labeled data sets, the system will input them into the TransFormer model for training. First, the model converts these data into vector representations through the encoder and decoder. Next, the fully connected layer is used to map the vector generated by the decoder to a log probability (logits) vector to predict whether the transaction conflicts. Finally, these log probability vectors are converted into probabilities through the SoftMax layer to determine the possibility of conflict for each transaction.
[0022] In this process, each client will train its own local smart contract transaction conflict detection model based on the local transaction read and write set, and upload it to the blockchain for aggregation after training. The blockchain will integrate the received local smart contract transaction conflict detection models to generate a global smart contract transaction conflict detection model. The above process will be repeated until the performance of the global smart contract transaction conflict detection model reaches a convergence state to ensure its accuracy and stability. Then the global smart contract transaction conflict detection model will be sent to each client to guide subsequent smart contract detection.
[0023] Through multiple iterations and gradually optimized global models, a larger range of transaction conflict detection capabilities are formed, providing reliable security protection for smart contract transactions in blockchain networks.
[0024] Then, the client uses the issued global smart contract transaction conflict detection model to perform conflict detection on the smart contract to be detected, such as Figure 3As shown in Figure 1. A client n will use the global smart contract transaction conflict detection model to perform conflict detection on the smart contract it has written. During this process, the smart contract detection model will analyze the transactions in the contract to determine whether there are conflicting transactions. If a conflicting transaction is detected, the system will reject the smart contract and return it to the client, requiring it to correct the conflict and resubmit it. If no conflicting transaction is found, the smart contract will be uploaded to the blockchain through the consensus node, where it will wait to be packaged into a block with other contracts and finally written into the blockchain to ensure that it officially takes effect and becomes part of the blockchain network.
[0025] Therefore, the present invention adopts the above-mentioned blockchain system smart contract transaction conflict detection system and method based on federated learning, which effectively utilizes the decentralized characteristics of blockchain and the distributed training mechanism of federated learning, can improve the efficiency and accuracy of transaction processing, and reduce the problem of transaction loss caused by transaction conflicts.
[0026] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that they can still modify or replace the technical solution of the present invention with equivalents, and these modifications or equivalent replacements cannot cause the modified technical solution to deviate from the spirit and scope of the technical solution of the present invention.
Claims
1. A method for detecting smart contract transaction conflicts in a blockchain system based on federated learning, characterized in that: include: First, each client runs the smart contract, obtains the read-write set of the transaction, and annotates it; Secondly, based on the read-write set of the annotated transactions, the smart contract transaction conflict detection model is trained locally to predict the probability of transaction conflicts, and the trained smart contract transaction conflict detection model is uploaded to the blockchain; Then, federated learning is used to aggregate the trained smart contract transaction conflict detection model to generate a global smart contract transaction conflict detection model, which is distributed to the client for iteration.
2. According to a method for detecting conflicts in smart contract transactions in a blockchain system based on federated learning according to claim 1, it is characterized in that: The smart contract contains the address information of the transaction read and write sets.
3. According to a method for detecting conflicts in smart contract transactions in a blockchain system based on federated learning according to claim 1, it is characterized in that: The client uses the global smart contract transaction conflict detection model to detect the submitted smart contract and determine whether it contains transaction conflicts; When a transaction conflict is detected, the smart contract will be rejected from being uploaded to the blockchain; When the test passes, there is no transaction conflict in the smart contract. At this time, it is uploaded to the blockchain through the consensus node and waits for further processing.
4. According to a method for detecting conflicts in smart contract transactions in a blockchain system based on federated learning according to claim 1, it is characterized in that: Local training of the smart contract transaction conflict detection model includes training the TransFormer model based on the labeled transaction read and write sets: First, the data is converted into vector representation through an encoder and a decoder; Next, a fully connected layer is used to map the vector representation generated by the decoder to a log-probability vector to predict whether a transaction conflicts. Then, the log-odds vector is converted into probability through the SoftMax layer to determine the probability of conflict for each transaction.
5. A blockchain system smart contract transaction conflict detection system based on federated learning, characterized in that: include: The client is used to obtain the read and write sets of transactions to complete the local training of the smart contract transaction conflict detection model; Consensus nodes are used to upload the locally trained smart contract transaction conflict detection model and distribute the global smart contract transaction conflict detection model to clients participating in federated learning; The blockchain is used to receive the locally trained smart contract transaction conflict detection model, complete global aggregation, and train the global smart contract transaction conflict detection model.
6. According to a blockchain system smart contract transaction conflict detection system based on federated learning according to claim 5, it is characterized in that: The system contains consensus nodes, and each consensus node is connected to the client.
Citation Information
Patent Citations
Block chain transaction execution method and system, electronic equipment and storage medium
CN109559226A
Multi-domain DDoS attack detection method and device based on trusted federated learning
CN115102763A
Block chain transaction execution method based on conflict detection
CN115170125A
Model application method and system based on block chain
CN116362343A
Transaction processing method and device based on block chain, equipment and medium
CN116957792A