A blockchain system smart contract transaction conflict detection system and method based on federated learning
By employing federated learning in the blockchain system for smart contract transaction conflict detection, the problem of transaction conflicts caused by optimistic parallel mechanisms is solved, achieving efficient and accurate transaction processing and data privacy protection, and improving the reliability and performance of the system.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2026-03-24
AI Technical Summary
The transaction conflict problem caused by the optimistic parallel mechanism in existing blockchain systems leads to transaction pool congestion and transaction loss, affecting system reliability and user experience. In addition, traditional centralized detection methods have insufficient data privacy protection.
A blockchain system smart contract transaction conflict detection method based on federated learning is adopted. By training a smart contract transaction conflict detection model locally on the client side, and using global model aggregation and iteration, combined with the decentralized characteristics of blockchain, transaction conflicts are detected and resolved.
It improves the accuracy and efficiency of transaction processing, protects data privacy, reduces transaction loss, enhances system performance and reliability, and adapts to different client business scenarios.
Smart Images

Figure CN119671731B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of smart contract security detection technology in blockchain, and in particular to a smart contract transaction conflict detection system and method based on federated learning in a blockchain system. Background Technology
[0002] With the continuous development of blockchain technology, smart contracts are playing an increasingly important role in blockchain networks. A smart contract is an automatically executed, immutable contract whose rules and conditions exist in the form of code within the blockchain. While ensuring transaction transparency and immutability, these contracts also face challenges in transaction processing, especially the conflict issues arising from parallel transaction processing.
[0003] In recent years, optimistic parallelism has been widely adopted in blockchain systems due to its advantages in improving transaction processing throughput and efficiency. Systems such as Aptos, Sui, Monad, and my country's independently developed Chang'an Chain have all begun using this advanced execution mechanism. However, this mechanism often leads to transaction conflicts, where multiple transactions attempt to modify the same data or resources, causing conflicts between transactions performing read and write operations. Transaction conflicts not only cause congestion in the blockchain transaction pool but may also trigger timeout mechanisms, leading to transaction loss and impacting the reliability of the entire blockchain system and user experience.
[0004] To address these challenges, traditional methods typically rely on centralized conflict detection mechanisms, but these methods suffer from insufficient data privacy protection and centralized computational resources. Therefore, it is necessary to provide a method for detecting transaction conflicts in smart contracts of blockchain systems. This method should be able to detect potential conflicting transactions within smart contracts, improve the accuracy and efficiency of conflict detection while protecting data privacy, and effectively detect and resolve transaction conflicts in multi-client environments to prevent transaction loss and improve the overall performance and reliability of the system. Summary of the Invention
[0005] The purpose of this invention is to provide a smart contract transaction conflict detection system and method based on federated learning for blockchain systems, which can solve the transaction conflict problem caused by optimistic parallelism in existing blockchain systems.
[0006] To achieve the above objectives, this invention provides a method for detecting smart contract transaction conflicts in a blockchain system based on federated learning, comprising:
[0007] First, each client runs a smart contract to obtain the read and write sets of transactions and annotate them;
[0008] Secondly, based on the read and write set of labeled transactions, a 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.
[0009] Then, federated learning is used to aggregate the trained smart contract transaction conflict detection models to generate a global smart contract transaction conflict detection model, which is then distributed to clients for iteration.
[0010] Preferably, the smart contract contains the address information of the transaction read / write set.
[0011] Preferably, the client uses a global smart contract transaction conflict detection model to detect the smart contract to be submitted and determine whether it contains transaction conflicts;
[0012] When a transaction conflict is detected, the smart contract will be refused to be uploaded to the blockchain;
[0013] When the test passes, the smart contract has no transaction conflicts. At this point, it is uploaded to the blockchain through the consensus node and awaits further processing.
[0014] Preferably, training the smart contract transaction conflict detection model locally includes training the TransFormer model using a labeled transaction read / write set:
[0015] First, the data is converted into vector representations using an encoder and decoder;
[0016] Next, a fully connected layer is used to map the vector representation generated by the decoder to a log-odds vector to predict whether a transaction will conflict.
[0017] Then, the log-odds vector is converted into probabilities through the SoftMax layer, thereby determining the probability of a conflict occurring for each transaction.
[0018] A blockchain smart contract transaction conflict detection system based on federated learning includes:
[0019] The client is used to obtain the read and write sets of transactions in order to complete the local training of the smart contract transaction conflict detection model;
[0020] Consensus nodes are used to upload locally trained smart contract transaction conflict detection models and to distribute global smart contract transaction conflict detection models to clients participating in federated learning.
[0021] The blockchain is used to receive locally trained smart contract transaction conflict detection models and complete global aggregation to train a global smart contract transaction conflict detection model.
[0022] Preferably, the system includes consensus nodes, and each consensus node is connected to a client.
[0023] Therefore, the present invention employs the above-mentioned blockchain system smart contract transaction conflict detection system and method based on federated learning, which has the following technical effects:
[0024] (1) In terms of enhancing data privacy protection, through federated learning, the transaction read and write set data is always kept locally, and only the model parameters are transmitted, which reduces 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, which improves the universality and accuracy of the model; in terms of optimizing transaction processing efficiency, by detecting transaction conflicts in advance, the congestion of the blockchain transaction pool is reduced, and the transaction processing speed and system performance are improved.
[0025] (2) The client and the blockchain are working together to detect conflicting transactions on smart contracts. The client is deployed under each consensus node to train the read and write set in the smart contract locally, and then the global model is aggregated on the decentralized blockchain. The model is then returned to each client to detect smart contract transaction conflicts. 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.
[0026] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0027] Figure 1 This is an overall structural diagram of a blockchain smart contract transaction conflict detection system based on federated learning;
[0028] Figure 2 This is a flowchart illustrating model training in an embodiment of a blockchain smart contract transaction conflict detection system and method based on federated learning;
[0029] Figure 3 This is a flowchart of a global smart contract transaction conflict detection model for client applications in an embodiment of a blockchain system smart contract transaction conflict detection system and method based on federated learning. Detailed Implementation
[0030] The present invention will be explained in more detail through the following embodiments. The purpose of disclosing the present invention is to protect all changes and modifications within the scope of the present invention. The present invention is not limited to the following embodiments.
[0031] Example 1
[0032] First, a blockchain smart contract transaction conflict detection system based on federated learning is built, such as... Figure 1As shown in the diagram. In this system architecture, the blockchain network contains N consensus nodes, each connected to multiple clients, forming a multi-layered federated learning and smart contract transaction conflict detection system. The specific workflow is as follows:
[0033] At the client level, the operation process is divided into two parts: First, the client uses the transaction read / write set in the smart contract as a dataset to train a smart contract transaction conflict detection model locally. This process uses local transaction read / write data for training to obtain a preliminary smart contract transaction conflict detection model. After training, the local smart contract transaction conflict detection model is uploaded to the blockchain through a consensus node to participate in the aggregation of the global model. This global model is an aggregation of the local models of each client, and it is iterated step by step through federated learning until the accuracy of the global model converges, ensuring that its performance is sufficient to support the detection of smart contract conflict transactions. Then, the global model is distributed to each client. Second, each client uses the obtained global model to detect the smart contract to be submitted and determine whether it contains transaction conflicts. If a transaction conflict is detected, the smart contract will be rejected from being uploaded to the blockchain; if the detection passes, it indicates that the contract has no transaction conflicts, and it can be uploaded to the blockchain through a consensus node for further processing.
[0034] On the blockchain side, the operation is also divided into two parts: First, the blockchain system packages all conflict-free transactions that pass the detection into a block and records the block in the blockchain to ensure data security and immutability. Second, the blockchain system receives local models uploaded by each client through consensus nodes and globally aggregates these models to form a unified global smart contract conflict transaction detection model. This global model is then sent back to each client participating in federated learning for subsequent use and optimization. This process continues to loop until convergence is achieved, thereby generating an efficient global smart contract conflict transaction detection model. This model integrates conflict data from each client's read / write sets and detection model information, representing the entire system's knowledge of smart contract transaction conflicts.
[0035] Because the optimistic parallelism mechanism used in existing blockchains often leads to transaction conflicts, causing congestion in the transaction pool, some transactions may trigger the blockchain's timeout mechanism and ultimately be lost. Therefore, in a federated learning-based blockchain smart contract detection system, training the smart contract transaction conflict detection model using federated learning is a crucial part. This involves training the model locally on a set of smart contract read / write operations, without uploading these sets to a central server. This effectively protects local transaction privacy and allows for the optimization of the detection model using local computing resources. Figure 2 As shown.
[0036] Example 2
[0037] The model training process in the federated learning-based blockchain smart contract detection method is as follows:
[0038] First, the client uses a large set of pre-labeled smart contract transaction read / write sets as training data. Each of these smart contracts may contain multiple methods, and the key and field values of the key functions (Put state and Get state) within each method represent the addresses of the transaction read / write sets. When the key and field values of Put state and Get state in the same method are equal, the system determines it as a conflicting transaction. This means that simultaneous read and write operations are attempted on the same data address within the same method. Similarly, if the key and field values of Put state and Get state are equal in two or more different methods, it will also be considered a conflicting transaction, indicating a conflict between different methods reading and writing to the same data address.
[0039] During model training, methods labeled 0 represent conflict-free transactions, meaning read and write operations do not interfere with each other; while methods labeled 1 represent conflicting transactions, meaning read and write operations on the same address conflict. Based on these labeled datasets, the system inputs them into the TransFormer model for training. First, the model converts this data into vector representations using an encoder and decoder. Next, a fully connected layer maps the vectors generated by the decoder to a logits vector to predict whether a transaction will conflict. Finally, a SoftMax layer converts these logits vectors into probabilities to determine the probability of conflict for each transaction.
[0040] In this process, each client trains its own local smart contract transaction conflict detection model based on its local transaction read / write set, and uploads it to the blockchain for aggregation after training. The blockchain integrates the received local smart contract transaction conflict detection models to generate a global smart contract transaction conflict detection model. This process is repeated until the performance of the global smart contract transaction conflict detection model reaches convergence, ensuring its accuracy and stability. Then, the global smart contract transaction conflict detection model is distributed to each client to guide subsequent smart contract detection.
[0041] Through multiple iterations and gradual optimization of the global model, a wider range of transaction conflict detection capabilities are formed, providing reliable security for smart contract transactions in the blockchain network.
[0042] Then, the client uses the distributed global smart contract transaction conflict detection model to perform conflict detection on the smart contracts to be detected, such as... Figure 3 As shown, a client n will use a global smart contract transaction conflict detection model to detect conflicts in its written smart contract. During this process, the smart contract detection model analyzes the transactions in the contract to determine if any conflicts exist. If a conflict is detected, the system rejects the smart contract, returns it to the client, and requests that the conflict be corrected and the contract resubmitted. If no conflict is found, the smart contract is uploaded to the blockchain through consensus nodes, where it awaits being packaged into a block along with other contracts, ultimately being written into the blockchain to ensure its official validity and becoming part of the blockchain network.
[0043] 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, thereby improving the efficiency and accuracy of transaction processing and reducing the problem of transaction loss caused by transaction conflicts.
[0044] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the technical solutions of the present invention, and these modifications or equivalent substitutions cannot cause the modified technical solutions to deviate from the spirit and scope of the technical solutions 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 a smart contract, obtains the read / write set of transactions, and labels it. The specific process is as follows: The client uses a global smart contract transaction conflict detection model to check the smart contracts to be submitted and determine whether they contain transaction conflicts; when a transaction conflict is detected, the smart contract will be rejected from being uploaded to the blockchain. When the test passes, the smart contract has no transaction conflicts. At this point, it is uploaded to the blockchain through the consensus node and awaits further processing. Secondly, based on the labeled transaction read / write set, a 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. The local training of the smart contract transaction conflict detection model includes training the TransFormer model based on the labeled transaction read / write set, as detailed below: First, the data is converted into vector representations using an encoder and decoder; Next, a fully connected layer is used to map the vector representation generated by the decoder to a log-odds vector to predict whether a transaction will conflict. Then, the log odds vector is converted into probabilities through the SoftMax layer, thereby determining the probability of a conflict occurring for each transaction; Finally, federated learning is used to aggregate the trained smart contract transaction conflict detection models to generate a global smart contract transaction conflict detection model, which is then distributed to clients for iteration.
2. The method for detecting smart contract transaction conflicts in a blockchain system based on federated learning according to claim 1, characterized in that, Smart contracts contain address information for transaction read / write sets.
3. 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 in order to complete the local training of the smart contract transaction conflict detection model; The obtained global model is used to detect smart contracts to be submitted and determine whether they contain transaction conflicts; The client uses a global smart contract transaction conflict detection model to check the smart contracts to be submitted and determine whether they contain transaction conflicts; when a transaction conflict is detected, the smart contract will be rejected from being uploaded to the blockchain. When the test passes, the smart contract has no transaction conflicts. At this point, it is uploaded to the blockchain through the consensus node and awaits further processing. Consensus nodes are used to upload locally trained smart contract transaction conflict detection models and to distribute global smart contract transaction conflict detection models to clients participating in federated learning. The TransFormer model is trained locally using a set of labeled transaction read / write data to detect smart contract transactions. First, the data is converted into vector representations using an encoder and decoder; Next, a fully connected layer is used to map the vector representation generated by the decoder to a log-odds vector to predict whether a transaction will conflict. Then, the log odds vector is converted into probabilities through the SoftMax layer, thereby determining the probability of a conflict occurring for each transaction; The blockchain packages all conflict-free transactions that pass the detection into a block and records the block on the blockchain; it receives local models uploaded by each client through consensus nodes and completes global aggregation to form a global smart contract transaction conflict detection model.
4. The blockchain smart contract transaction conflict detection system based on federated learning according to claim 3, characterized in that, The system contains consensus nodes, and each consensus node connects to a client.
Citation Information
Patent Citations
Multi-domain DDoS attack detection method and device based on trusted federated learning
CN115102763A
Transaction processing method and device based on block chain, equipment and medium
CN116957792A