An intelligent factory blockchain anomaly detection method
By employing federated learning and privacy-preserving data aggregation methods in the blockchain network, a global anomaly detection model is trained, solving the problem that traditional models cannot be applied and achieving efficient and privacy-preserving blockchain anomaly detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIHANG UNIV
- Filing Date
- 2023-06-28
- Publication Date
- 2026-07-03
AI Technical Summary
Traditional anomaly detection models cannot be directly applied to blockchain networks, and existing blockchain anomaly detection methods are inefficient and lack privacy protection, making them unable to effectively detect abnormal behavior in blockchain networks.
A novel anomaly detection model is designed in a blockchain network using federated learning. Combined with a privacy-preserving data aggregation method, the local model participates in the update of the global model in the cloud to train the global anomaly detection model, and the privacy-preserving method protects sensitive information during the training process.
It improves the efficiency of blockchain anomaly detection, protects the privacy of nodes, encourages more nodes to participate in anomaly detection, and effectively detects abnormal behavior in the blockchain network.
Smart Images

Figure CN116866017B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of blockchain technology, and in particular relates to a method for detecting blockchain anomalies in smart factories. Background Technology
[0002] With the development of blockchain technology, blockchain-based technologies are emerging across various industries, especially in the context of the Industrial Internet of Things (IIoT), where blockchain-based networks are one of the most compelling applications of blockchain technology. While blockchain is a powerful tool with features such as decentralization, anti-counterfeiting, immutability, and traceability, it is also vulnerable to attacks. For example, numerous Ponzi schemes have emerged on blockchain networks to steal funds from legitimate users, attracting unsuspecting users by promising future incentives. Furthermore, a large number of malicious accounts are regularly created on cryptocurrencies. In addition, in some anomalous attacks, malicious forks are created and deployed to overcome computational limitations and double-spend within the network. Therefore, detecting anomalies in blockchain-based networks is crucial for protecting networks and systems from attacks.
[0003] The concept of traditional network anomaly detection has been discussed for a long time in industry and academia, and a great deal of work has been done to date. However, traditional anomaly detection models cannot be directly integrated with blockchain technology because blockchain has several aspects that differ from traditional networks, such as consensus mechanisms, smart contracts, and the lack of a central authority. Therefore, given all these characteristics, traditional anomaly detection models cannot be directly applied to blockchain. Thus, there is an urgent need to develop anomaly detection models for purely blockchain-based networks and applications.
[0004] Because blockchain is a fully functional peer-to-peer network with decentralized communication, incentives, and consensus mechanisms, researchers have divided it into multiple layers to better understand its functionality. Each layer corresponds to a potential risk. Researchers have created and deployed numerous anomaly detection models for various blockchain networks, which can be categorized based on different blockchain layers. For example, some models predict anomalous commands within smart contracts, thus falling under the category of smart contract anomaly detection. Similarly, some models work on detecting malicious block deployments, thus classifying them under the umbrella of data layer anomaly detection. However, based on discussions across various research efforts, no single approach is applicable in all scenarios. Summary of the Invention
[0005] To address the aforementioned issues, this invention proposes a smart factory blockchain anomaly detection method. Based on federated learning, a novel blockchain anomaly detection method is proposed. Simultaneously, an efficient and privacy-preserving data aggregation method is designed to protect the privacy of data and models across all blockchain nodes (users). This method allows for the secret aggregation of trained user models without disclosing the user models themselves. It also exhibits effective fault tolerance for user disconnections, ensuring normal execution even when a large number of users disconnect during protocol runtime.
[0006] To achieve the above objectives, the technical solution adopted by this invention is: a smart factory blockchain anomaly detection method, comprising the following steps:
[0007] S10, based on federated learning in the smart factory blockchain scenario, utilizes the local model of each participating node, allowing each local model to participate in the update of the global model in the cloud, and aggregates to obtain a pre-trained model;
[0008] S20, then based on the pre-trained model, a global anomaly detection model is trained; during the training process, privacy protection methods are used to protect the sensitive information of the nodes involved in the training process;
[0009] S30. After obtaining the global anomaly detection model, the model is used to screen for abnormal states on the smart factory blockchain.
[0010] Furthermore, in the aforementioned smart factory blockchain scenario, the blockchain, based on a cluster architecture, integrates users, base stations, WiFi, service providers, and smart factories connected to the blockchain network; service providers collect sensor data from the smart factory and use this data according to their applications and services; transactions in the blockchain represent the exchange of sensitive factory information between parties during operation within the blockchain network; transactions have multiple inputs and outputs; blocks consist of a list of transactions, references to the previous block, and hashes; each block consists of transactions received by miners from the previous block in their mempool.
[0011] Furthermore, in the federated learning method under the smart factory blockchain scenario, the federated learning setup involves local models and distributed smart factory nodes, with K smart factories learning the local models in a federated learning manner; these K local models have the same structure, but they are trained using different datasets from connected clients.
[0012] Furthermore, the global model is updated forward in the blockchain network for identity verification and validation; miner nodes verify the update of the global model by solving cryptographic puzzles; after the verification process is completed, all industry sectors download the aggregated global model update.
[0013] The data explosion problem is solved by using a pruning pattern in the blockchain network; in this pattern, miner nodes only keep the Merkle tree for every three blocks, and the other one is kept in the archive node; based on the aggregated global model, each department updates the final output and transmits it to the cloud.
[0014] Furthermore, in S10, based on federated learning in the smart factory blockchain scenario, each participating node's local model is used to participate in the update of the global model in the cloud, and the pre-trained model is obtained by aggregation, including the following steps:
[0015] 1) Register all global and local model devices with 5G functionality {D1, D2, D3, ... D i} and {LBS1, LBS2, LBS3};
[0016] 2) The global model is used to validate each local model device;
[0017] 3) Send the initialized global model g0 to each department so that the devices in each department can be initialized;
[0018] 4) Utilize the equipment in each department Training a local model;
[0019] 5) Local model that receives updates of the optimized value of the tracking loss function
[0020] 6) Transfer the updated local model to the global model device;
[0021] 7) Aggregation of all local models with global training data;
[0022] 8) Receive global model update g kt+1 Optimize tracking using loss function values:
[0023]
[0024] in f j (g,x j ,y j ) is the data sample (x) j ,y j Loss function value, |D k | represents the size of the data sample, g t It is the global model at time t. It is the k-th local model at time t, and N is the total number of local models, which is also the number of participants; the global model is transferred in the blockchain network for verification;
[0025] 9) Solve the cryptographic calculation through miner nodes;
[0026] 10) Verification is completed by other mining nodes;
[0027] 11) Download the validated global model from each department;
[0028] 12) Transmit data to the distributed cloud, end.
[0029] Furthermore, in step S20, a global anomaly detection model is trained based on the pre-trained model, including the following steps:
[0030] The parameter server starts the federated learning scheme at t=0 and initializes the local model with the first set of weights.
[0031] Download these local models from the parameter server to the smart factory k=1,…K;
[0032] Using the training data from the corresponding blockchain dataset, a new local weight set is computed in parallel for local models of E=1, ...E.
[0033] Finally, the parameter server aggregates the weights in each client's local model to create an improved global model using a weighted average;
[0034] Each iteration of the loop will start a new epoch until a certain stopping criterion is reached; this is achieved by distributing the model to K clients of a learning federation at time t0.
[0035] Furthermore, considering that this model is based on a blockchain network environment, the pre-trained model, which serves as the local model, is sent from the parameter server to the cluster within this framework; the local model is then sent to the smart factory for training based on local time; and then, the parameters and hyperparameters are forwarded to the parameter server for model weight aggregation to calculate the global model.
[0036] Furthermore, during the training process, when protecting sensitive information of participating nodes using privacy protection methods, attackers are divided into two types: external attackers and internal attackers. External attackers compromise security through hostile behavior, while internal attackers spy on the user's trained model to perform reverse analysis attacks.
[0037] The participants in the protocol include two types: users and servers. Users do not connect directly to each other; communication between users must access the server. A user is a node in the blockchain.
[0038] Privacy protection methods include the following steps:
[0039] Preparation phase: Prepare data in advance, which is available not only in one round of model training, but also throughout the federated learning process;
[0040] Round 1: The user generates a private key-public key pair for the aggregation, and the public key is shared and used after communication;
[0041] Round 2: A user shares a secret with other users in the system, which will be encrypted using the public key in the aggregate;
[0042] Round 3: Users encrypt the input data using a shared key and send the ciphertext to the server;
[0043] Round 4: The server and users confirm the set of active users to defend against differential attacks;
[0044] Round 5: The user generates a special share containing the user's secret and sends it to the server. The server uses the collected shares and ciphertext to calculate the aggregated plaintext.
[0045] The beneficial effects of adopting this technical solution are:
[0046] This invention introduces a distributed federated learning scheme based on blockchain anomaly detection, and further proposes a privacy protection scheme based on federated learning. This invention proposes a federated learning scheme suitable for blockchain scenarios, providing the foundation for federated learning-based blockchain anomaly detection. This invention proposes a federated learning-based anomaly detection scheme, improving the efficiency of model updates and alleviating the generally low efficiency problem of traditional blockchain anomaly detection methods. This invention introduces a privacy protection scheme on top of the anomaly detection scheme, effectively protecting the privacy information of each participating node, ensuring blockchain anonymity while further encouraging more blockchain nodes to participate in the training of anomaly detection-related models.
[0047] This invention leverages the distributed nature shared by blockchain and federated learning to design a suitable federated learning scheme in the blockchain scenario, thereby effectively breaking the data silo problem caused by the decentralized nature of blockchain, enabling effective connections between distributed nodes, and achieving joint training of the model.
[0048] This invention uses federated learning to supervise the transactions of each node on the blockchain and detects abnormal behaviors that malicious nodes may attempt to perform.
[0049] While achieving anomaly detection, this invention also protects the sensitive information of each node participating in model training by designing a privacy protection scheme that complements federated learning. This protects the privacy of each participating node while encouraging more nodes to participate in model training. Attached Figure Description
[0050] Figure 1 This is a schematic diagram of a smart factory blockchain anomaly detection method according to the present invention;
[0051] Figure 2 This is a flowchart of the anomaly detection model training process in an embodiment of the present invention;
[0052] Figure 3 This is a schematic diagram of user-server interaction in privacy protection in an embodiment of the present invention. Detailed Implementation
[0053] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described below with reference to the accompanying drawings.
[0054] In this embodiment, see Figure 1 As shown, this invention proposes a method for detecting blockchain anomalies in smart factories, including the following steps:
[0055] S10, based on federated learning in the smart factory blockchain scenario, utilizes the local model of each participating node, allowing each local model to participate in the update of the global model in the cloud, and aggregates to obtain a pre-trained model;
[0056] S20, then based on the pre-trained model, a global anomaly detection model is trained; during the training process, privacy protection methods are used to protect the sensitive information of the nodes involved in the training process;
[0057] S30. After obtaining the global anomaly detection model, the model is used to screen for abnormal states on the smart factory blockchain.
[0058] As an optimization of the above embodiments, in the smart factory blockchain scenario, the blockchain, based on a cluster architecture, combines users, base stations, WiFi, service providers, and smart factories connected to the blockchain network; service providers collect sensor data from the smart factory and use this data according to their applications and services; transactions in the blockchain represent the exchange of sensitive factory information between parties during operation in the blockchain network; transactions have multiple inputs and outputs; blocks consist of a list of transactions, a reference to the previous block, and a hash; each block consists of transactions received by miners from the previous block in their mempool.
[0059] In the federated learning approach in the smart factory blockchain scenario, the federated learning setup involves local models and distributed smart factory nodes. K smart factories learn the local models in a federated learning manner; these K local models have the same structure, but they are trained using different datasets from connected clients.
[0060] The global model is updated forward in the blockchain network for identity verification and validation; miner nodes verify the update of the global model by solving cryptographic puzzles; after the verification process is completed, all industry sectors download the aggregated global model update.
[0061] The data explosion problem is solved by using a pruning pattern in the blockchain network; in this pattern, miner nodes only keep the Merkle tree for every three blocks, and the other one is kept in the archive node; based on the aggregated global model, each department updates the final output and transmits it to the cloud.
[0062] In the local and global models, the local model has local base stations (LBSs), and the global model has global base stations (MBSs). Compared to MBSs, LBSs have limited computing and storage capabilities. Various local models connect to the global model, meaning that many local base stations {LBS1, LBS2, LBS3} are also connected to a single global base station (MBS), which is the only trusted authority in the network because it is certified by the blockchain during registration.
[0063] In this scenario, we propose a blockchain-supported federated learning algorithm as follows, which is applicable to the latest 5G scenarios:
[0064] Input: Equipment from each department (Pr, Qr, Dr, corresponding to production, quality control, and distribution respectively) with parameters such as current, temperature, flow rate, power consumption, and rotational speed. f T p F r E l Input data is generated in the form of Rs, ...}.
[0065] Output: Through a federated learning layer using blockchain technology, identity verification and authentication are protected for privacy. The final output is a global model, which is then uploaded to the system's distributed cloud. The industrial department's data is stored in the cloud's DHT data center and verified by MBS (Blockchain-based Services) for LBS (Location-Based Services).
[0066] 1) Register all global and local model devices with 5G functionality {D1, D2, D3, ... D i}and
[0067] {LBS1,LBS2,LBS3};
[0068] 2) The global model is used to validate each local model device;
[0069] 3) Send the initialized global model g0 to each department so that each department's devices can initialize Pr, Qr, and Dr;
[0070] 4) Utilize the equipment in each department Training a local model;
[0071] 5) Local model that receives updates of the optimized value of the tracking loss function
[0072] 6) Transfer the updated local model to the global model device;
[0073] 7) Aggregation of all local models with global training data;
[0074] 8) Receive global model update g kt+1 Optimize tracking using loss function values:
[0075] 9)
[0076] 10) Among them f j (g,x j ,y j ) is the data sample (x) j ,y j Loss function value, |D k | represents the size of the data sample, g t It is the global model at time t. It is the k-th local model at time t, and N is the total number of local models, which is also the number of participants;
[0077] 11) Transfer the global model within the blockchain network for verification;
[0078] 12) Solve the cryptographic calculation through miner nodes;
[0079] 13) Verification is completed by other mining nodes;
[0080] 14) Download the validated global model from each department;
[0081] 15) Transmit data to the distributed cloud, end.
[0082] Detecting anomalous activity is crucial for automatically protecting systems from unintended attacks. In blockchain, anomalies must be detected by sending each data block to a central server for every block update. This is not only inefficient but also raises privacy concerns. Federated learning-based anomaly detection schemes promise to address this issue. Through frequent model updates, a global model for anomaly detection is obtained. After understanding the data, equipment, and service providers of each smart factory, the model's parameters are sent to a parameter server for aggregating and updating the general model used for anomaly detection.
[0083] Smart factories possess sensitive data, making it financially and computationally expensive to store it on a blockchain with limited storage space. Therefore, the actual data from smart devices and sensors is stored within the smart factory itself. Smart factory data also includes information about data types and control status.
[0084] The prerequisite for developing anomaly detection frameworks for blockchain-based industrial internet networks in smart factories lies in providing a new decentralized system based on federated learning, which can utilize all smart factory data while protecting its privacy. Furthermore, it is necessary to address forks across the blockchain during anomaly detection. In some cases, inconsistencies in the state of the blockchain by devices or nodes can lead to forks. Forks become even more concerning as blockchain-based applications are developed, as they could potentially be used for malicious purposes. Indeed, employing a global machine learning model can utilize all the information gathered from previous forks to detect anomalies during the training process. The advantage of this approach is that while an attack might only occur once within a smart factory, over time, the attack behavior towards other smart factories will be identical. Therefore, information about past attacks can help us blacklist them and prevent them from happening in the future. Thus, the advantages of adopting federated learning are obvious, as it trains a global machine learning model for anomaly detection.
[0085] Therefore, based on the federated learning scheme mentioned above, an anomaly detection algorithm for blockchain smart factories is further proposed.
[0086] In step S20, as Figure 2 As shown, a global anomaly detection model is trained based on a pre-trained model, including the following steps:
[0087] The parameter server starts the federated learning scheme at t=0 and initializes the local model with the first set of weights.
[0088] Download these local models from the parameter server to the smart factory k=1,…K;
[0089] Using the training data from the corresponding blockchain dataset, a new local weight set is computed in parallel for local models of E=1, ...E.
[0090] Finally, the parameter server aggregates the weights in each client's local model to create an improved global model using a weighted average;
[0091] Each iteration of the loop will start a new epoch until a certain stopping criterion is reached; this is achieved by distributing the model to K clients of a learning federation at time t0.
[0092] Specifically, the parameters are defined as follows:
[0093] C represents the batch size of the global operation; B determines the size of the local batch; factor k represents the k smart factories; E is the number of local epochs; h represents the learning rate. Initialization begins the process of initializing the model parameters. During the training step, the parameters are sent to the smart factories and the model is updated. Finally, this updated trained model can be tested to detect any anomalies. The specific algorithm is as follows:
[0094] Input: Pre-trained model.
[0095] Output: Global anomaly detection model.
[0096] (1) Initialization: (t=0) Start setting values, define initial values = B, E, h, C, K;
[0097] (2) Initial local model, model(m) i = Set weight parameters (w1, ... w) n );
[0098] (3) Update the client model and upload the local model to the smart factory cluster;
[0099] (4) Federated training, starting the federated learning method;
[0100] (5) Repeat execution when K>0: Obtain the local model, and repeat execution for local epoch E: run the local model from 1 to n (number of local models), obtain and set the model parameters, and return;
[0101] (6) Server parameters = FedAvg(w), where FedAvg is the model aggregation function;
[0102] (7) Update (w,m) and decrypt it;
[0103] (8) Divide the data into data blocks of size B. For local epochs E from 1 to B, repeat the following: For data blocks x that are not larger than B, return w and D to the server.
[0104] (9) Return the updated model;
[0105] (10) Model aggregation (FedAvg): Server (initialize w0 and perform homomorphic encryption);
[0106] (11) Calculate the loss P = loss(w,b) (loss is the loss function);
[0107] (12) Repeat the following steps for c from 1 to k: The server will execute w t-1 Send it to smart factory i-1, and E = E+1;
[0108] (13) Parameter server = updated (w1, ... wn ).
[0109] In actual operation, considering that this model is based on a blockchain network environment, the pre-trained model as the local model is sent from the parameter server to the cluster in this framework; the local model is sent to the smart factory for training based on local time; then, the parameters and hyperparameters are forwarded to the parameter server for model weight aggregation and calculation of the global model.
[0110] As an optimization of the above embodiments, while utilizing federated learning for anomaly detection in a blockchain environment, it is necessary to further consider the privacy protection of each participating node. Since the model is trained locally, users do not need to upload their own data, protecting user privacy. However, federated learning is still susceptible to reverse attacks, which can infer users' private data by analyzing the user model. Furthermore, servers are very curious about user data, which, in a sense, is also a potential threat to user privacy. In fact, servers may also analyze user data from the locally trained model parameters. Although the locally trained model parameters are encrypted, the server can decrypt them because it is also a legitimate participant. Therefore, it is dangerous for the server to act as a privacy adversary to analyze the user-trained model parameters. Therefore, this invention, while utilizing federated learning for anomaly detection in blockchain systems, further introduces a stronger privacy protection protocol to ensure the privacy and security of each distributed blockchain node participating in anomaly detection. Based on the attack purpose and target, we categorize attackers into external attackers and internal attackers. The two types of attackers are as follows: First, external attackers hope to disrupt security through hostile actions, such as monitoring channels, intercepting and tampering with information on channels, and impersonating legitimate users to send incorrect information. Second, internal attackers, especially servers, want to spy on user-trained models to conduct reverse analysis attacks.
[0111] During the training process, when protecting sensitive information of participating nodes using privacy protection methods, attackers are divided into two types: external attackers and internal attackers. External attackers compromise security through hostile behavior, while internal attackers spy on the user's trained model to perform reverse analysis attacks.
[0112] The participants in the protocol include two types: users and servers. Users do not connect directly to each other; communication between users must access the server. A user is a node in the blockchain.
[0113] like Figure 3 As shown, the privacy protection method includes the following steps:
[0114] Preparation phase: Prepare data in advance, which is available not only in one round of model training, but also throughout the federated learning process;
[0115] Round 1: The user generates a private key-public key pair for the aggregation, and the public key is shared and used after communication;
[0116] Round 2: A user shares a secret with other users in the system, which will be encrypted using the public key in the aggregate;
[0117] Round 3: Users encrypt the input data using a shared key and send the ciphertext to the server;
[0118] Round 4: The server and users confirm the set of active users to defend against differential attacks;
[0119] Round 5: The user generates a special share containing the user's secret and sends it to the server. The server uses the collected shares and ciphertext to calculate the aggregated plaintext.
[0120] Users can exit the scheme at any time during the protocol's runtime. If more than t users remain active, the data aggregation scheme will function correctly.
[0121] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely illustrative of the principles of the invention. Various changes and modifications can be made to the invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the present invention as claimed. The scope of protection of this invention is defined by the appended claims and their equivalents.
Claims
1. A method for detecting blockchain anomalies in smart factories, characterized in that, Including the following steps: S10, based on federated learning in the smart factory blockchain scenario, utilizes the local model of each participating node, allowing each local model to participate in the update of the global model in the cloud, and aggregates them to obtain a pre-trained model, including the following steps: 1) Register all global and local model devices with 5G functionality; 2) The global model is used to validate each local model device; 3) Send the initialized global model g0 to each department so that the devices in each department can be initialized; 4) Utilize the equipment in each department Training a local model; 5) Local model that receives updates of the optimized value of the tracking loss function ; 6) Transfer the updated local model to the global model device; 7) Aggregation of all local models with global training data; 8) Global model update, tracking loss function value optimization: ; in For data samples Loss function value, For the size of the data sample, It is the global model at time t. It is the k-th local model at time t, and N is the total number of local models, which is also the number of participants; 9) Transfer the global model within the blockchain network for verification; 10) Solve the cryptographic calculation through miner nodes; 11) Verification is completed by other mining nodes; 12) Download the validated global model from each department; 13) Transmit data to the distributed cloud, end; S20, then based on the pre-trained model, a global anomaly detection model is trained; during the training process, privacy protection methods are used to protect the sensitive information of the nodes involved in the training process, and attackers are divided into two types: external attackers and internal attackers; external attackers undermine security through hostile behavior; internal attackers spy on the user's trained model to perform reverse analysis attacks. The participants in the protocol include two types: users and servers. Users do not connect directly to each other; communication between users must access the server. A user is a node in the blockchain. Privacy protection methods include the following steps: Preparation phase: Prepare data in advance, which is available not only in one round of model training, but also throughout the federated learning process; Round 1: Users generate a pair of private and public keys to achieve global model aggregation, and the public key is shared and used after communication; Round 2: A user shares a secret with other users in the system, which will be encrypted using the public key generated in the aggregation; Round 3: Users encrypt their input data using a shared public key and send the ciphertext to the server; Round 4: The server and users confirm the set of active users to defend against differential attacks; Round 5: The user generates a special share containing the user's secret and sends it to the server. The server uses the collected shares and ciphertext to calculate the aggregated plaintext. S30. After obtaining the global anomaly detection model, the model is used to screen for abnormal states on the smart factory blockchain.
2. The method for detecting blockchain anomalies in a smart factory according to claim 1, characterized in that, In the smart factory blockchain scenario, the blockchain, based on a cluster architecture, combines users, base stations, WiFi, service providers, and smart factories connected to the blockchain network; service providers collect sensor data from the smart factory and use this data according to their applications and services; and transactions in the blockchain represent the exchange of sensitive factory information between the parties during operation in the blockchain network. A transaction has multiple inputs and outputs; a block consists of a list of transactions, a reference to the previous block, and a hash; each block consists of transactions that the miner receives from the previous block in the mempool.
3. The method for detecting blockchain anomalies in a smart factory according to claim 2, characterized in that, In the federated learning method in the smart factory blockchain scenario, the federated learning setup involves local models and distributed smart factory nodes. K smart factories learn the local models in a federated learning manner; these K local models have the same structure, but they are trained using different datasets from connected clients.
4. The method for detecting blockchain anomalies in a smart factory according to claim 3, characterized in that, The global model is updated forward in the blockchain network for authentication; miner nodes verify the update of the global model by solving cryptographic puzzles; after the verification process is completed, all industry sectors download the aggregated global model update. The data explosion problem is solved by using a pruning pattern in the blockchain network; in this pattern, miner nodes only keep the Merkle tree for every three blocks, and the Merkle trees for the remaining blocks are kept in the archive node. Based on the aggregated global model, each department updates the final output and transmits it to the cloud.
5. The method for detecting blockchain anomalies in a smart factory according to claim 1, characterized in that, In step S20, a global anomaly detection model is trained based on the pre-trained model, including the following steps: The parameter server starts the federated learning scheme at t = 0, and initializes the local model with the first set of weights; These local models are downloaded from the parameter server to each smart factory; Using the training data from the corresponding blockchain dataset, a new local weight set is computed in parallel for each local model. Finally, the parameter server aggregates the weights in each client's local model to create an improved global model using a weighted average; Each iteration of the loop will initiate a new epoch until a certain stopping criterion is reached; this is achieved by distributing the model across time intervals. The learning federation has M clients.
6. The method for detecting blockchain anomalies in a smart factory according to claim 5, characterized in that, Considering that the global anomaly detection model is based on a blockchain network environment, the pre-trained model, which serves as the local model, is sent from the parameter server to the cluster in the global anomaly detection model framework; the local model is then sent to the smart factory for training based on the local model; and then, the parameters and hyperparameters are forwarded to the parameter server for model weight aggregation to calculate the global model.