A user electricity stealing behavior detection method and system based on a consortium chain and federated learning

By employing consortium blockchains and federated learning methods, and utilizing threshold homomorphic key pairs and a two-stage aggregation algorithm, the data privacy and performance issues of traditional electricity theft detection model training are resolved, enabling efficient and secure electricity theft detection model updates and detection.

CN115270145BActive Publication Date: 2026-04-21STATE GRID HEBEI ELECTRIC POWER CO LTD +2
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
STATE GRID HEBEI ELECTRIC POWER CO LTD
Filing Date
2022-06-22
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

Traditional electricity theft detection models require a large amount of valid data for training, resulting in high communication overhead and data privacy and security issues. Furthermore, the models have poor performance and cannot meet the standards for online operation.

Method used

By adopting a method based on consortium blockchain and federated learning, threshold homomorphic key pairs are generated by a key management institution. Each participant encrypts the model parameters after training locally. The agent node cluster that meets the threshold jointly recovers the decryption key and puts it on the blockchain to realize the aggregation and updating of the model.

Benefits of technology

Without leaking local data, efficient training and updating of the electricity theft detection model were achieved, ensuring data privacy. A two-stage aggregation algorithm was used to evaluate the performance of the local model, prevent malicious behavior, and improve the training effect of the global model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115270145B_ABST
    Figure CN115270145B_ABST
Patent Text Reader

Abstract

This invention discloses a method and system model for detecting user electricity theft based on consortium blockchain and federated learning. The detection method includes the following sequential steps: 1) Node registration; 2) Training initialization; 3) Key distribution; 4) Local training: Selected participants download the global model and iterate through it using a local optimization strategy, then encrypt the model and send the encrypted data to the proxy nodes; 5) Model aggregation: A cluster of proxy nodes that meet the threshold jointly recovers the decryption key and calls a smart contract to execute a two-stage aggregation, with the result uploaded to the blockchain after consensus; 6) Global model update: After global iteration meets the conditions, global training ends, and the electricity theft detection model is updated; 7) Electricity theft detection. This invention can obtain a model with performance exceeding that of local individual training while also ensuring the privacy of local data, thus improving security, and enabling continuous iteration and updating of the user electricity theft detection model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to a method and system for detecting user electricity theft based on consortium blockchain and federated learning, belonging to the fields of blockchain and federated learning technology. Background Technology

[0002] For a long time, electricity theft and leakage in the power grid have been difficult to eradicate, not only harming the interests of relevant power companies but also endangering the lives and property of surrounding residents and jeopardizing the stable transmission of electricity. Traditional anti-theft and leakage measures require enormous human and material resources and have yielded minimal results. To address this, many studies have used machine learning algorithms to build electricity anomaly detection models, which can efficiently and accurately detect the daily electricity consumption patterns of relevant users. However, traditional machine learning methods typically require a large amount of effective data to train the algorithm model. In reality, some power companies, due to outdated equipment and false alarms / missed alarms at terminals, produce poor-performing models that fail to meet the standards for online operation. A common approach is to collect data from different power companies into a data center, but this not only incurs significant communication overhead but also raises widespread concerns about data privacy and security. Summary of the Invention

[0003] To overcome the drawbacks of the "data collection" method used in training traditional electricity theft detection models, this invention provides a user electricity theft behavior detection method and system model based on consortium blockchain and federated learning.

[0004] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows:

[0005] A method for detecting user electricity theft based on consortium blockchain and federated learning, wherein the participants and agent nodes in the federated training are different nodes of the same consortium blockchain, includes the following steps:

[0006] 1) Each participating party, acting as a peer node in the consortium blockchain, enters the system by submitting legally recognized identity credentials approved by the organization;

[0007] 2) Initial global model parameter information is written into the genesis block, and each participant responds to the training;

[0008] 3) The key management authority generates and distributes threshold homomorphic key pairs;

[0009] 4) The selected participant downloads the global model and iterates through the local optimization strategy, then encrypts it and sends the ciphertext to the proxy node;

[0010] 5) The agent node cluster that meets the threshold jointly recovers the decryption key, calls the smart contract to execute two-phase aggregation, and uploads the result to the blockchain after consensus is reached;

[0011] 6) After the global iteration of the model update meets the conditions, the global training ends and the electricity theft detection model is updated.

[0012] 7) The client submits the user's electricity consumption data records over a period of time as input to the electricity theft detection model, and the electricity theft detection model outputs whether the user is an electricity thief.

[0013] In step 6), if the model update condition is not met after the current global model performance is checked, return to the local training step in step 4) until the result of the current global model performance check meets the model update condition.

[0014] In step 1) above, only peer nodes in the consortium blockchain need to register with the system using identity credentials. Proxy nodes, acting as super nodes in the consortium blockchain, have write permissions and are selected and authorized by the various organizations. They execute the blockchain's consensus mechanism and have on-chain accounting permissions. Proxy nodes are not entirely reliable and may experience risks such as disconnection.

[0015] In step 2) above, during the system initialization phase, the initial global model parameter information is written into the genesis block as the first transaction information; during the initialization phase of the subsequent electricity theft detection model update, the final model of the previous version is directly used as the initial global model for the new round of version training, and the training parameters of the model update conditions are packaged into the new block, and each participant responds to the training.

[0016] In step 3) above, the key pair generated by the key management authority is based on Paillier's threshold variant algorithm. The key management authority needs to broadcast the public key to all peer nodes and distribute the private key share to each agent node, and then go offline.

[0017] Step 4 above includes:

[0018] 4.1) In each round, participants are selected from the peer node cluster according to a fixed ratio C;

[0019] 4.2) Local optimization strategies during local training, including optimization methods, local iteration counts, and local learning rates, can be downloaded from the blockchain along with the initial global model;

[0020] 4.3) After the peer node has trained the local dataset according to the local optimization strategy, it obtains the local model update and uses the public key issued by the key management authority to encrypt the local model update using a threshold variant of the Paillier algorithm.

[0021] 4.4) The encrypted ciphertext is sent to any proxy node.

[0022] In step 5) above, 5.1) the two-stage aggregation includes: in the pre-aggregation stage, the pre-aggregated global model is obtained by weighting the number of local samples of each participant; in the formal aggregation stage, the weight is divided into two parts: the first part is also weighted according to the number of local samples of each participant, and the second part is weighted according to the Euclidean distance between the global model ciphertext in the pre-aggregation stage and each local model ciphertext; 5.2) Combining the threshold Paillier variant method, based on the assumption of an honest and stable number of nodes in the system, a threshold is set, and the decryption key can only be recovered if the number of private key shares collected exceeds the threshold value; 5.3) The proxy node packages the decrypted global model and performs Raft consensus within the proxy node, adding the transaction blocks that have successfully reached consensus to the end of the blockchain.

[0023] In step 6) above, after each round of global model generation, the proxy node needs to check the model against the model update conditions recorded on the chain. If the model update conditions are met, the global training ends. After adding the transaction block to the end of the blockchain, the proxy node adds a training end flag and adds a new version of the electricity theft detection model as the initial model for the next training.

[0024] In step 7) above, as input to the electricity theft detection model, the client submits an electricity theft detection request to the system. The client can choose to submit electricity consumption data records for a single user over a period of time, or it can input electricity consumption data for a batch of users. The proxy node collects the client's detection requests and performs the detection using the latest version of the model. The model outputs whether the user is stealing electricity, and the proxy node returns the detection result to the client.

[0025] A user electricity theft detection system based on consortium blockchain and federated learning includes:

[0026] Peer node: The first entity with actual electricity consumption data participates in horizontal federated training as a training entity and has the right to read data on the blockchain. After downloading the global model from the proxy node in each round, it uses local data for iterative training and uses the threshold Paillier algorithm to encrypt the trained local model parameters. The encrypted ciphertext is sent to any proxy node. This process is repeated until the global model meets the model update conditions.

[0027] Proxy node: The second entity collects the model update ciphertext submitted by each peer node and decrypts it together, and performs the model ciphertext aggregation process;

[0028] Organization: The third entity organizes the first entity to participate in the training of the system model and is responsible for the admission of peer nodes in the blockchain. The second entity must be jointly authorized by the organizations in the system; Key Management Authority: The fourth entity is responsible for generating and distributing the key pairs required for the cryptographic algorithm;

[0029] The global model structure and local iteration strategy generated during system initialization are written into the genesis block. Subsequent iteration rounds of training initialization only require adding the local iteration strategy. The key management organization generates the key pairs required for subsequent cryptographic algorithms, and the public and private keys are distributed separately. In each round, a certain proportion (the proportion of participants set in the local iteration strategy) of peer nodes are selected for local training. The selected nodes obtain a new round of local model updates based on the downloaded current global model and local dataset, encrypt it using the distributed public key, and send it to the proxy node. The proxy node calls the smart contract to execute the two-stage aggregation algorithm and decryption algorithm sequentially to obtain the global model for the current round. The decryption key can only be recovered if more than a threshold number of proxy nodes provide a share of the private key. The steps from local training to global aggregation are repeated until the obtained global model meets the model update conditions. Training ends, and the new version of the global model is marked and recorded in the blockchain. When performing the detection task, the client submits the user's electricity consumption data records over a period of time as input to the electricity theft detection model. The proxy node uses the latest version of the model to perform electricity theft detection and returns the model output as a result of whether the user is an electricity thief to the client.

[0030] Of the four entities in the above system:

[0031] 1) The first and second entities primarily undertake the horizontal federated training task during the model training phase, and act as peer nodes and super nodes in the consortium blockchain, respectively, with read permissions and read-write permissions. The second entity executes the consensus algorithm in the blockchain.

[0032] 2) The third entity is responsible for granting access permissions to the first entity's system and jointly authorizing the second entity.

[0033] 3) The fourth entity is responsible for the initialization of the cryptographic algorithm in the Paillier-based threshold variant algorithm execution system. The key management authority broadcasts the public key to all peer nodes and distributes the private key shares to each agent node.

[0034] The system includes a model training process and an electricity theft detection process, and the two processes do not conflict with each other.

[0035] During the initialization phase of the aforementioned system, the global model structure and local iteration strategy are written into the genesis block. In subsequent updates to the electricity theft detection model, the previous version is used as the initial model, and a local iteration strategy is added, such as the selected peer node participation ratio C for each round. After training initialization is complete, the peer nodes respond to the training session.

[0036] The local training phase of the above system training process includes:

[0037] 1) Randomly select nodes from the peer node cluster to participate in each round of training according to the proportion C in the local iteration strategy on the blockchain;

[0038] 2) The selected participant first downloads the local optimization strategy from the blockchain, including the optimization method, the number of local iterations and the local learning rate. Then, it trains the local data according to the local optimization strategy and encrypts the model parameters obtained by the threshold variant of the Paillier algorithm, and sends the encrypted data to any proxy node.

[0039] The two-stage aggregation phase of the above system training process includes:

[0040] 1) In the pre-aggregation stage, the FedAvg algorithm is used, which means that the aggregation weight is positively correlated with the number of local samples of the participants, thus obtaining the pre-aggregated global model;

[0041] 2) In the formal aggregation stage, the aggregation weight is divided into two parts. The first part is positively correlated with the number of local samples of the participants, and the second part is negatively correlated with the Euclidean distance between the global model ciphertext and each local model ciphertext in the pre-aggregation stage. The two parts are combined and weighted together.

[0042] After obtaining the aggregate model, the proxy nodes perform joint decryption. According to the characteristics of the threshold Paillier variant method, the number of proxy nodes performing joint decryption needs to exceed the threshold value to successfully recover the decryption key. The decrypted global model is packaged into a transaction, and Raft consensus is performed within the proxy nodes. The transaction block that successfully reaches consensus is added to the end of the blockchain.

[0043] The global detection phase of the above system training process includes:

[0044] 1) The proxy node needs to check the global model generated in each round. If the model update conditions recorded on the chain are met, the global training ends. After the proxy node adds the newly generated transaction block to the end of the blockchain, it adds a training end flag and records the new electricity theft detection model version number as the initial model for the next training.

[0045] 2) If the model update condition is not met, return to the local training steps described above until the result of the current global model performance test meets the model update condition.

[0046] During the electricity theft detection process of the above system, the system receives electricity theft detection requests submitted by the client, including electricity consumption data records of a user or a group of users over a period of time; the agent node collects the detection requests from the client and performs the detection using the latest version of the electricity theft detection model, and the agent node returns the detection results to the client.

[0047] By implementing this invention, data silos among power companies can be broken down, ensuring the security of the training process while extensively collecting data for federated training, and enabling the continuous iteration and updating of the user electricity theft detection model.

[0048] In this application, the following symbols and definitions are used: a peer node is represented as P. i The number of samples in its dataset The proportion of peer nodes selected in each round is C; proxy nodes are represented as pr. i The total number of proxy nodes is n r The number of honest and stable proxy nodes is t. E is the number of local iterations, and η is the local learning rate; the threshold value k = n required for decryption. r -t+1; In the l-th round, the global model is Gw l P i The local model is The aggregation weight based on the number of samples is w. s The weights based on the actual performance of the model are w. p The public key in the encryption algorithm is pk, and the private key is...

[0049] Any techniques not mentioned in this invention are based on existing technologies.

[0050] The present invention provides a user electricity theft detection method and system model based on consortium blockchain and federated learning. Each participant can participate in the training of the detection model without leaving their local machine, thereby obtaining a model with performance exceeding that of local individual training while also ensuring the privacy of local data. At the same time, the consortium blockchain can screen node admission to a certain extent and act as an immutable ledger for the model. Furthermore, to prevent adversaries from inferring sensitive information in the samples through local model updates, the local models submitted by each participant are encrypted, and a threshold cryptography algorithm is designed to prevent malicious behaviors such as proxy node disconnection and collusion. The two-stage model aggregation algorithm can also better evaluate the performance of each local model and match the corresponding weights, thereby avoiding the impact of poor local models on the global model training process. Attached Figure Description

[0051] Figure 1 This is a schematic diagram of the user electricity theft detection system model based on consortium blockchain and federated learning according to the present invention;

[0052] Figure 2 This is a flowchart of the user electricity theft detection method based on consortium blockchain and federated learning according to the present invention;

[0053] Figure 3 This is an optional federated learning model (CNN) embodiment used in the simulation of this invention;

[0054] Figure 4 This is a comparison of the experimental results of the present invention with the baseline method FedAvg; Detailed Implementation

[0055] To better understand the present invention, the following embodiments further illustrate the content of the present invention, but the content of the present invention is not limited to the following embodiments.

[0056] It should be noted that in the description of this invention, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0057] A method for detecting user electricity theft based on consortium blockchain and federated learning, using, for example Figure 1 The federated learning system shown in the diagram consists of different nodes on the same consortium blockchain, representing the various participants and agent nodes involved in the federated training.

[0058] This invention provides a user electricity theft detection system based on consortium blockchain and federated learning, such as... Figure 1 As shown, the participants in the federated training are different nodes of the same consortium blockchain. The server in the traditional federated learning system is replaced by a smart contract within the consortium blockchain. The entities in the system model include:

[0059] Peer node: The first entity with actual electricity consumption data participates in horizontal federated training as a training entity and has the right to read data on the blockchain. After downloading the global model from the proxy node in each round, it uses local data for iterative training and uses the threshold Paillier algorithm to encrypt the trained local model parameters. The encrypted ciphertext is sent to any proxy node. This process is repeated until the global model meets the model update conditions.

[0060] Proxy node: The second entity collects the model update ciphertext submitted by each peer node and decrypts it together, and performs the model ciphertext aggregation process;

[0061] Organization: The third entity organizes the first entity to participate in the training of the system model and is responsible for the admission of peer nodes in the blockchain. The second entity must be jointly authorized by the organizations in the system; Key Management Authority: The fourth entity is responsible for generating and distributing the key pairs required for the cryptographic algorithm;

[0062] The global model structure and local iteration strategy generated during system initialization are written into the genesis block. Subsequent iteration rounds of training initialization only require adding the local iteration strategy. The key management organization generates the key pairs required for subsequent cryptographic algorithms, and the public and private keys are distributed separately. In each round, a certain proportion (the proportion of participants set in the local iteration strategy) of peer nodes are selected for local training. The selected nodes obtain a new round of local model updates based on the downloaded current global model and local dataset, encrypt it using the distributed public key, and send it to the proxy node. The proxy node calls the smart contract to execute the two-stage aggregation algorithm and decryption algorithm sequentially to obtain the global model for the current round. The decryption key can only be recovered if more than a threshold number of proxy nodes provide a share of the private key. The steps from local training to global aggregation are repeated until the obtained global model meets the model update conditions. Training ends, and the new version of the global model is marked and recorded in the blockchain. When performing the detection task, the client submits the user's electricity consumption data records over a period of time as input to the electricity theft detection model. The proxy node uses the latest version of the model to perform electricity theft detection and returns the model output as a result of whether the user is an electricity thief to the client.

[0063] In one optional embodiment, the first entity and the second entity act as the main undertakers of the horizontal federated training task during the model training phase, and respectively serve as a peer node and a super node in the consortium blockchain, possessing read permissions and read-write permissions, respectively. The second entity executes the consensus algorithm in the blockchain.

[0064] In one alternative embodiment, the third entity is responsible for granting access permissions to the first entity system and jointly authorizing the second entity.

[0065] In one alternative embodiment, a fourth entity is responsible for initializing the cryptographic algorithm in the Paillier-based threshold variant algorithm execution system, and for providing the public-private key pairs required during successful system model training, wherein the private key is split into shares equal to the number of proxy nodes. The key management authority broadcasts the public key to all peer nodes and distributes the private key shares to each proxy node.

[0066] In an optional embodiment, the system includes a model training process and an electricity theft detection process, which do not conflict with each other.

[0067] In one optional embodiment, the system first initiates the model training process. The global model structure and local iteration strategy are written into the genesis block during the system's initialization phase. If the current version of the electricity theft detection model fails to meet detection requirements or the detection success rate decreases, federated training initialization restarts. In subsequent training initialization phases, the previous version of the model is used as the initial model, and local iteration strategies are added, such as the proportion C of selected peer nodes participating in each round, optimization methods, and the number of local iterations. After training initialization is complete, the peer nodes respond to the training session.

[0068] In one optional embodiment, local training randomly selects nodes from the peer node cluster for each round of training according to a proportion C in the local iteration strategy on the blockchain. The selected participants first download the local optimization strategy from the blockchain, including the optimization method, the number of local iterations, and the local learning rate. They then train the local data according to the local optimization strategy, iterating multiple times to obtain the new round of local model parameters. The model parameters obtained by the peer node are encrypted using a threshold variant of the Paillier algorithm and sent in ciphertext to any proxy node.

[0069] In an optional embodiment, the two-stage aggregation of the above system training process includes a pre-aggregation stage and a formal aggregation stage: In the pre-aggregation stage, the FedAvg algorithm is used, that is, the aggregation weight is positively correlated with the number of local samples of the participants, thereby obtaining the pre-aggregated global model; In the formal aggregation stage, the aggregation weight is divided into two parts, the first part is positively correlated with the number of local samples of the participants, and the second part is negatively correlated with the Euclidean distance between the global model ciphertext of the pre-aggregation stage and each local model ciphertext, and the two parts are weighted together in equal proportions.

[0070] After obtaining the officially aggregated global model ciphertext, the proxy node performs joint decryption by submitting the aggregated private key shares. According to the necessary condition of the threshold Paillier variant decryption algorithm, the number of collected private key shares must exceed the threshold value in order to successfully recover the decryption key.

[0071] The decrypted global model is packaged into a transaction, and Raft consensus is achieved within the proxy node. The transaction block that successfully reaches consensus is added to the end of the blockchain for the next round of participants to read.

[0072] In one optional embodiment, the proxy node needs to check the global model generated in each round. If the model update conditions recorded on the chain are met, the global training ends. After the proxy node adds the newly generated transaction block to the end of the blockchain, it adds a training end flag and records the new electricity theft detection model version number as the final model for this training.

[0073] If the model update condition is not met, return to the local training step described above, and continue until the result of the current global model performance test meets the model update condition.

[0074] In one optional embodiment, during the electricity theft detection process, the system receives an electricity theft detection request submitted by the client, including electricity consumption data records of a user or a group of users over a period of time; the agent node collects the client's detection request and performs detection using the latest version of the electricity theft detection model, and the agent node returns the detection results to the client.

[0075] like Figure 2 As shown, the user electricity theft detection method based on consortium blockchain and federated learning includes:

[0076] Step S1: Each participating party, as a peer node of the consortium blockchain, enters the system by submitting legal identity credentials recognized by the organization.

[0077] In one optional embodiment, based on the consortium blockchain's access control mechanism, each peer node joining the system for the first time needs to submit its identity credentials to register as a legitimate node in the blockchain. These credentials need to be prepared by the organization for peer nodes that meet the requirements to participate in training, which will reduce the possibility of malicious adversaries joining the system to some extent. If a new organization needs to join the system, it needs to provide the system with the entire organization's certificate chain and the identity credentials of each peer node it carries.

[0078] In one optional embodiment, after joining the system, each peer node participates in horizontal federated training as a training entity. They possess a large amount of user electricity consumption data, can train local models, and upload them. No single party can obtain specific data sample information from other participants. They belong to their own organization within the blockchain and can only read data on the blockchain, without having the right to record transactions. After downloading the global model from the proxy node in each round, they iteratively train using local data and encrypt the trained local model parameters using the threshold Paillier algorithm. The encrypted ciphertext is then sent to any proxy node, and this process is repeated iteratively until the global model meets the convergence condition.

[0079] In one optional embodiment, only peer nodes in the consortium blockchain need to register with the system using identity credentials. Proxy nodes, acting as super nodes in the consortium blockchain, have write permissions and are selected and authorized by the various organizations. They execute the blockchain's consensus mechanism and have on-chain accounting permissions. Proxy nodes are not entirely reliable and may be subject to threats such as disconnection or collusion.

[0080] In one optional embodiment, the organization in the system does not perform specific federated learning tasks, but acts as a regional division unit in the consortium blockchain, responsible for organizing peer nodes within its region to participate in the training of the electricity theft detection model and granting them access credentials to participate in the system. If any peer node within its jurisdiction engages in dishonest behavior such as "free-riding," it will be held accountable.

[0081] Step S2: Initial global model and other parameter information are written into the genesis block, and each participant responds to the training;

[0082] In an optional embodiment, since the entire electricity theft detection model may need to be continuously updated, each training iteration can use the previous final global model as the initial model. Before the system's first training begins, the initialized global model Gw0, termination condition, local iteration count E, participant ratio C in each round, and the set of participant IDs for the first round of training are written into the genesis block as the first initial transaction. The participant IDs for the first round of training are generated by the proxy node using a random selection algorithm based on the participant ratio C.

[0083] In an optional embodiment, during the initialization phase of subsequent electricity theft detection model updates, the final model of the previous version can be directly used as the initial global model for the new version training. Therefore, only training parameters such as model update conditions need to be provided and packaged into a new block.

[0084] In one optional embodiment, when a participant joins the training, they need to call the `party_confirm()` function in the smart contract to submit their identity, the number of local users, and the total number of samples participating in the training. They then sign off on their participation in the training. Each organization endorses the data submitted by its peer nodes.

[0085] Step S3: The key management authority generates and distributes threshold homomorphic key pairs;

[0086] In this embodiment, the key management authority needs to execute Paillier's threshold variant algorithm for key generation and immediately go offline after distributing the key pair.

[0087] In this embodiment, the key management authority generates the public and private keys required for the homomorphic encryption algorithm, and broadcasts the public key to all peer nodes, making the number of proxy nodes in the system n. r If there are 1, then the private key will be split into shares. Distribute the decryption to proxy nodes. Assume the minimum number of honest and stable proxy nodes the system can tolerate is t. Then the decryption threshold is k = n. r -t+1.

[0088] Step S4: The selected participant downloads the global model and iterates through the local optimization strategy, then encrypts the data and sends the encrypted data to the proxy node;

[0089] In this embodiment, in the lth round, the selected participant P i Download the global model for the current round from the blockchain and train it using the local dataset. Assume the local optimization strategy uses stochastic gradient descent, and let the loss function be F. i (w), if the local iteration is E times, then the local iteration process can be represented as

[0090] in η is the local learning rate.

[0091] The model parameters for this round are obtained after E iterations.

[0092] P i The local model update is encrypted by calling a threshold variant of the Paillier algorithm using the public key pk issued by the key management authority: The encrypted ciphertext is sent to any proxy node pr i .

[0093] In an optional embodiment, when encrypting local model updates, the participants employ a threshold variant of the Paillier algorithm, wherein...

[0094] KeyGen()→{n,s i |i∈{1,2,…n r Choose integers n such that n = pq and m = p'q', where p and q satisfy conditions such as p = 2p' + 1 and q = 2q' + 1. The plaintext space is Z. n Choose d = 0 mod m, d = 1 mod n. Select a from {0, ..., n×m-1}. i Construct polynomial a0 = d, where 0 < i < k, and k is the decryption threshold. If there are l′ decryption entities in total, then the private key share of the i-th entity is s. i = f(i), public key is n, g, where g = 1 + n

[0095] Encrypt(m) → c = g M r n modn 2 Random selection Encryption yields the ciphertext of plaintext M.

[0096] Each decryption entity calculates its decryption share using the ciphertext. Where Δ = l′!, if more than k decryption shares are collected, let the set of decryption shares be S, then it can be calculated. in From the secret sharing algorithm:

[0097]

[0098] Therefore, if we set the function... but:

[0099] in

[0100] The homomorphism of this algorithm can be proven as follows: Let plaintext m1, m2

[0101]

[0102] Step S5: The agent node cluster that meets the threshold jointly recovers the decryption key and calls the smart contract to execute the two-phase aggregation. After consensus is reached, the result is uploaded to the blockchain.

[0103] In this embodiment, after each agent node collects the model update ciphertext, it reports the number of model updates it has received to other agent nodes, and queries the number of samples in its local dataset on the chain based on the uploaded peer node ID. Then, it jointly signs and calls the Two_stage_Aggr() function of the smart contract to perform model aggregation with all online agents.

[0104] In an alternative embodiment, a two-stage aggregation algorithm is performed:

[0105] During the pre-aggregation phase, the weights of each participant during aggregation are weighted according to the number of local samples. Where n p This is the set of participant IDs selected for this round. Based on the number of local samples submitted by each participant, participants with more samples are considered more likely to train a better model, and sample weights are set accordingly. The aggregation algorithm is

[0106] In the formal aggregation phase, to filter out malicious or incompletely trained participants, the weights of each participant during aggregation are divided into two parts. The first part is the same as in the pre-aggregation phase, weighted according to the number of local samples from which model performance can be predicted. The second part is weighted according to the actual model performance, calculating the Euclidean distance between each model ciphertext and the pre-aggregated model ciphertext. Assuming most nodes in the system are honest, participants farther from the pre-aggregation model are more likely to be malicious or undertrained, potentially negatively impacting the global model's training process. Therefore, the reciprocal of this distance is used as the weighting criterion for the second part of the weighting. The total weight is Therefore, the final aggregation algorithm is:

[0107]

[0108] In this embodiment, each agent node needs to jointly invoke the decryption contract to decrypt the obtained global model ciphertext. Invoking this contract requires a set of at least k = n. r -t+1 private key shares from proxy nodes are needed to recover the decryption key, therefore proxy node pr i It needs to be based on the private key share sk i The decryption share is calculated and used as input to the contract. The decryption contract executes the Decrypt() function of a threshold variant of the Paillier algorithm to obtain the plaintext of the global model.

[0109] In one optional embodiment, the formally aggregated global model uses the Raft mechanism for consensus confirmation among proxy nodes. Raft consensus is a consensus algorithm well-suited for consortium blockchains. Nodes participating in the consensus have three states: leader, follower, and candidate. To achieve synchronization in the distributed system, Raft consensus segments time into "terms," ​​with one leader responsible for record-keeping within each term. The Raft consensus record-keeping process applied in the blockchain system includes the following steps:

[0110] ① Leader election: When a follower discovers that a term has expired, it considers the leader to be invalid and can change its state to candidate. It can then vote for itself. If it receives the support of more than half of the nodes, it is successfully elected as the leader; otherwise, the election fails.

[0111] ② Consensus Ledger: The leader writes the received command to its local log, at which point the command state is uncommitted. It then synchronizes the logs to all followers. Once all nodes have written the command to their logs, the leader commits the command and returns the result. Other nodes, upon receiving the command, execute it using their state machines, ensuring that all node logs remain consistent.

[0112] In this embodiment, after the global model is written to the blockchain after each round of formal aggregation, the proxy node needs to check the model against the model update conditions recorded on the chain.

[0113] If the model update conditions are met after verification, then perform the following steps:

[0114] Step S6: After the global iteration of the model update meets the conditions, the global training ends and the electricity theft detection model is updated.

[0115] In this embodiment, global training ends if the model update condition is met; after the proxy node adds the transaction block to the end of the blockchain, it needs to add a training end flag and add a new version of the electricity theft detection model to it.

[0116] In this embodiment, if the model update condition is not met, the proxy node needs to call the random selection algorithm in step S2 to reselect the IDs of the participants in the next round according to the participant ratio C. Then, steps S4-S5 are repeated iteratively until the model update condition is met.

[0117] Step S7: The client submits the user's electricity consumption data records over a period of time as input to the electricity theft detection model. The model outputs whether the user is an electricity thief.

[0118] In this embodiment, the latest version of the model in the current system is used to detect electricity theft. As input to the electricity theft detection model, the client submits an electricity theft detection request to the system. The client can choose to submit electricity consumption data records for a single user over a period of time, or it can input electricity consumption data for a batch of users. The proxy node collects the client's detection requests and performs the detection using the latest version of the model. The model outputs whether the user is stealing electricity, and the proxy node returns the detection result to the client.

[0119] In the user electricity theft detection method and system based on consortium blockchain and federated learning provided by this invention, each participant can participate in the training of the detection model without leaving their local machine. This achieves a model with performance exceeding that of individual local training while maintaining the privacy of local data. Simultaneously, the consortium blockchain can screen node access to a certain extent and act as an immutable ledger for the model. Furthermore, to prevent adversaries from inferring sensitive information in samples through local model updates, the local models submitted by each participant are encrypted, and a threshold cryptography algorithm is designed to prevent malicious behaviors such as proxy node disconnection or collusion. The two-stage model aggregation algorithm can also better evaluate the performance of each local model and match appropriate weights, thereby avoiding the impact of poor local models on the global model training process.

[0120] Application examples

[0121] This implementation adopts Figure 1The example shown illustrates a user electricity theft detection application scenario based on consortium blockchain and federated learning. The consortium blockchain system is configured to contain 500 peer nodes, numbered {P1, P2, ..., P...}. 500 There are 10 proxy nodes, i.e., n r =10, numbered {Pr1,Pr2,...,Pr 10 Assume the minimum number of honest and stable proxy nodes that the system can tolerate is t = n. r / 2 = 5, then the decryption threshold is k = n r -t+1=6. This example demonstrates the entire training process of the electricity theft detection model, including how each peer node trains locally, encrypts the local model, sends it to the proxy node, and then the proxy node aggregates the model according to a two-stage aggregation algorithm and records it on the blockchain.

[0122] The system's safety parameter is set to 128, meaning that large prime numbers will be selected from 0 to 2. 128 A number of bits. During the key generation phase, the key management authority first randomly generates two large prime numbers:

[0123] p′=40381822629508445329194325876161708563

[0124] q′=79352408235426049959432545381794026419

[0125] Then calculate:

[0126] p=2p′+1=80763645259016890658388651752323417127

[0127] q=2q′+1=158704816470852099918865090763588052839

[0128] n=pq=12817579498349279940142085707121137292846181805728973273359499808188713573553

[0129] g=n+1=12817579498349279940142085707121137292846181805728973273359499808188713573554

[0130] m=p′q′=3204394874587319985035521426780284323151678335999776070695561516418200525897

[0131] To satisfy d = 0 mod m and d = 1 mod n, according to the Chinese Remainder Theorem, let Ω = mn, then Since e1m≡1modm and e2n≡1modn, we need to first find the multiplicative inverse of m modulo n.

[0132] e2 = 5977363971036351473180424920716591231307266244063897728080167121948391334922, then multiply it by m to get d.

[0133] d=191538344723317944463426369714054337176191440095563402076904978017108729186 43788689314864712418170761084059330217484543750900261794076249309538261475034

[0134] Next, calculate the private key share of the 10 proxy nodes, and select a from {0,…n×m-1}. i Where a0 = d, and the selected random numbers are shown in Table 1. A polynomial is constructed using this. Where 0 < i < 6, k = 6 is the decryption threshold.

[0135] The private key share of the first proxy node is

[0136]

[0137] The private key share of the second proxy node is

[0138]

[0139] Similarly, the private key shares of all proxy nodes are shown in Table 1:

[0140] Table 1: Basic parameter settings for the key generation stage

[0141]

[0142]

[0143]

[0144] At this point, the key generation part of the key management organization is complete. The private key shares are distributed to the agent nodes, and the public key is distributed to all peer nodes. After that, the key management organization goes offline.

[0145] Assume the global model initialized by the system is a simple convolutional neural network (CNN), with the network structure as follows: Figure 3 As shown, both the server-side optimizer and the client-side optimizer use the Adam optimizer, where learning_rate = 0.001, β1 = 0.9, β2 = 0.999, and ε = 10. -7 The proportion of clients selected in each round is 20%, and the client iterates locally 3 times in each round, with a batch size of 32.

[0146] To simulate the learning performance of the proposed model, a federated version of the MNIST dataset was used for testing. This dataset contains recognition of 10 classes of handwritten digits from 0 to 9, with a total training / test set of 341,873 and a test set of 40,832. It includes 3,383 clients, each with a different sample size. Here, we only use the training set (47,981 samples) from 500 clients and the entire test set. Each participant trains the global model based on their local samples in each round and submits the encrypted model to the server. To describe a specific implementation of the Paillier threshold algorithm, an integer is used as the plaintext. The complete encryption and shared decryption process is as follows:

[0147] To simplify our description, we set the plaintext M=6, select a random number r=101960347371885113110184269182448853610901741345978585331634093808881646486067518415372985634215497110082422270547678345388931251516201211042381948980481, and encrypt it:

[0148] c = g M r n modn 2 =16528152545340870770429405359833445371177443845098765007198974137821257489743712629717094782491383462635261741277562585112234290199582516286715080925467

[0149] During the decryption process, assuming there are exactly 6 proxy nodes (holding s1, ..., s6) participating in the decryption (with a decryption threshold k), each proxy node needs to calculate its decryption share. Where Δ=n r ! = 10! = 3628800:

[0150] First proxy node:

[0151] Similarly, the decryption share of all proxy nodes is shown in Table 2:

[0152] Table 2: Calculation parameters during the decryption phase

[0153]

[0154] Joint decryption calculation of all decrypted shares in

[0155]

[0156] It can be solved

[0157] To test the homomorphism of the algorithm, we further encrypted the plaintexts m1=2 and m2=3, obtaining the ciphertexts as follows:

[0158] c1=72398289451786246873548974563049369275674864655032764741387270887706172510 620576154118858935541962081564646988846259513155400234985222470585299685827373

[0159] c2=72107121812442184759626961110251146656102345188190211667954065780165677880 418586846817157606163220695474215687776134086481280111347592798163349456853740

[0160] c1×c2=52204322765123990245159413251937608864486368902644131777735431110628911832293118452036130432658875920142380498748001554948416394136078833212141669570 88599332894761714596067614967075286905364599242002182568332690304630330019623738020162771521340062744123917153689600710957874969029063374020043237349425020

[0161] Deciphering the deciphering process, we get D(c1×c2)=5=m1+m2.

[0162] The server employs a two-stage aggregation algorithm to aggregate the local models from each client. To demonstrate the superiority of the proposed method, a comparison is made between the baseline algorithm (federated averaging algorithm) and the method proposed in this invention, and the accuracy of the global model is tested over 100 rounds. Figure 4 As shown, the proposed method can avoid the problem of uneven distribution of client data to a certain extent, thereby improving the accuracy of the global model.

[0163] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0164] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0165] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0166] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0167] 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 it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the specific implementation of the present invention. Any modifications or equivalent substitutions that do not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.

Claims

1. A method for detecting user electricity theft based on consortium blockchain and federated learning, characterized in that, The participants and proxy nodes involved in the federated training are different nodes of the same consortium blockchain, and the process includes the following steps: 1) Each participating party, acting as a peer node in the consortium blockchain, enters the system by submitting legally recognized identity credentials approved by the organization; 2) Initial global model parameter information is written into the genesis block, and each participant responds to the training; 3) The key management authority generates and distributes threshold homomorphic key pairs; 4) The selected participant downloads the global model and iterates through the local optimization strategy, then encrypts it and sends the ciphertext to the proxy node; 5) The agent node cluster that meets the threshold jointly recovers the decryption key, calls the smart contract to execute two-phase aggregation, and uploads the result to the blockchain after consensus is reached; In step 5), the two-stage aggregation includes: in the pre-aggregation stage, a pre-aggregated global model is obtained by weighting the number of local samples of each participant; in the formal aggregation stage, the weights are divided into two parts: the first part is also weighted according to the number of local samples of each participant, and the second part is weighted according to the Euclidean distance between the global model ciphertext of the pre-aggregation stage and the ciphertext of each local model; combined with the threshold Paillier variant method, based on the assumption of an honest and stable number of nodes in the system, a threshold is set, and the decryption key is restored when the number of private key shares collected exceeds the threshold; the proxy node packages the decrypted global model and performs Raft consensus within the proxy node, adding the successfully consensused transaction blocks to the end of the blockchain; 6) After the global iteration of the model update meets the conditions, the global training ends and the electricity theft detection model is updated; 7) The client submits the user's electricity consumption data records over a period of time as input to the electricity theft detection model, and the electricity theft detection model outputs whether the user is an electricity thief.

2. The user electricity theft detection method based on consortium blockchain and federated learning according to claim 1, characterized in that, In step 6), if the current global model performance is not satisfied after testing, the local training step in step 4) is returned until the result of the current global model performance test satisfies the model update condition.

3. The user electricity theft detection method based on consortium blockchain and federated learning according to claim 1 or 2, characterized in that, In step 1), the proxy node acts as a super node in the consortium blockchain, has write permissions, and is selected and authorized by each organization to serve as the proxy node. It executes the blockchain's consensus mechanism and has the permission to record transactions on the chain.

4. The user electricity theft detection method based on consortium blockchain and federated learning according to claim 1 or 2, characterized in that, In step 2), during the system initialization phase, the initial global model parameter information is written into the genesis block as the first transaction information; during the subsequent initialization phase of the electricity theft detection model update, the final model of the previous version is used as the initial global model for the new round of version training, and the training parameters of the model update conditions are packaged into a new block, and each participant responds to the training.

5. The user electricity theft detection method based on consortium blockchain and federated learning according to claim 1 or 2, characterized in that, In step 3), the key pair generated by the key management authority is generated based on Paillier's threshold variant algorithm. The key management authority broadcasts the public key to all peer nodes and distributes the private key share to each agent node.

6. The user electricity theft detection method based on consortium blockchain and federated learning according to claim 1 or 2, characterized in that, Step 4) includes: 4.1) Each round follows a fixed ratio. Participants are randomly selected from the peer node cluster; 4.2) Local optimization strategies during local training, including optimization methods, local iteration counts, and local learning rates, are downloaded from the blockchain along with the initial global model; 4.3) After the peer node has trained the local dataset according to the local optimization strategy, it obtains the local model update and uses the public key issued by the key management authority to encrypt the local model update using a threshold variant of the Paillier algorithm. 4.4) The encrypted ciphertext is sent to any proxy node.

7. The user electricity theft detection method based on consortium blockchain and federated learning according to claim 1 or 2, characterized in that, In step 6), after each round of global model generation, the proxy node needs to check the model against the model update conditions recorded on the chain. If the model update conditions are met, the global training ends. After adding the transaction block to the end of the blockchain, the proxy node adds a marker indicating the end of training and adds a new version of the electricity theft detection model as the initial model for the next training.

8. The user electricity theft detection method based on consortium blockchain and federated learning according to claim 1 or 2, characterized in that, In step 7), as input to the electricity theft detection model, the client submits an electricity theft detection request to the system, submitting a user's electricity consumption data record over a period of time, or inputting a batch of users' electricity consumption data in batches. The proxy node collects the detection requests from the client and uses the electricity theft detection model to perform the detection. The electricity theft detection model outputs whether the user is stealing electricity, and the proxy node returns the detection result to the client.

9. A user electricity theft detection system based on consortium blockchain and federated learning, characterized in that, include: peer node: The first entity participates in horizontal federated training as a training entity and has the right to read data on the blockchain. After downloading the global model from the proxy node in each round, iterative training is performed using local data, and the trained local model parameters are encrypted using the threshold Paillier algorithm. The encrypted ciphertext is then sent to any proxy node. This process is repeated until the global model meets the model update conditions. Proxy node: The second entity collects the model update ciphertext submitted by each peer node and decrypts it together, and performs the model ciphertext aggregation process; Organization: The third entity organizes the first entity to participate in the training of the system model and is responsible for the admission of peer nodes in the blockchain. The second entity must be jointly authorized by the organization in the system. Key management authority: The fourth entity is responsible for generating and distributing the key pairs required for the cryptographic algorithm; The global model structure and local iteration strategy generated during system initialization are written into the genesis block. Subsequent iteration rounds of training initialization only require adding the local iteration strategy. The key management organization generates the key pairs required for subsequent cryptographic algorithms, and the public and private keys are distributed separately. In each round, peer nodes with the proportion of participants set in the local iteration strategy are selected for local training. The selected nodes obtain a new round of local model updates based on the downloaded current global model and local dataset, encrypt it using the distributed public key, and send it to the proxy node. The proxy node calls the smart contract to execute the two-stage aggregation algorithm and decryption algorithm sequentially to obtain the global model for the current round. The decryption key can only be recovered if more than a threshold number of proxy nodes provide a share of the private key. The steps from local training to global aggregation are repeated until the obtained global model meets the model update conditions. Training ends, and the new version of the global model is marked and recorded in the blockchain. When performing the detection task, the client submits the user's electricity consumption data records over a period of time as input to the electricity theft detection model. The proxy node uses the latest version of the model to perform electricity theft detection and returns the model output to the client, indicating whether the user is stealing electricity. Two-phase aggregation algorithms include, a. In the pre-aggregation stage, the federated average algorithm is adopted, and the aggregation weight is positively correlated with the number of local samples of the participants to obtain the pre-aggregated global model; b. In the formal aggregation stage, the aggregation weight is divided into two parts. The first part is positively correlated with the number of local samples of the participants, and the second part is negatively correlated with the Euclidean distance between the global model ciphertext and each local model ciphertext in the pre-aggregation stage. The two parts are combined and weighted together. Combining the threshold Paillier variant method, based on the assumption of an honest and stable number of nodes in the system, a threshold is set, and the decryption key is restored when the number of private key shares collected exceeds the threshold. The proxy node packages the decrypted global model and performs Raft consensus within the proxy node, adding the successfully consensused transaction blocks to the end of the blockchain.

10. The user electricity theft detection system based on consortium blockchain and federated learning according to claim 9, characterized in that, The system includes a model training process and an electricity theft detection process, which do not conflict with each other; the first entity and the second entity have read permissions and read-write permissions respectively, and the second entity executes the consensus algorithm in the blockchain; the fourth entity is responsible for initializing the cryptographic algorithm in the system based on Paillier's threshold variant algorithm, and the key management authority broadcasts the public key to all peer nodes and distributes the private key shares to each agent node.

11. The user electricity theft detection system based on consortium blockchain and federated learning according to claim 9 or 10, characterized in that, During the system initialization phase, the global model structure and local iteration strategy are written into the genesis block. When the electricity theft detection model is updated in the future, the previous version of the model is used as the initial model, and then the local iteration strategy is added.

12. The user electricity theft detection system based on consortium blockchain and federated learning according to claim 9 or 10, characterized in that, Local training includes: a. According to the proportion in the local iteration strategy on the blockchain Nodes participating in each round of training are randomly selected from the peer node cluster; b. The selected participant downloads the local optimization strategy from the blockchain, including the optimization method, the number of local iterations, and the local learning rate. Then, it trains the local data according to the local optimization strategy and encrypts the model parameters obtained by using a threshold variant of the Paillier algorithm, and sends the encrypted data to any proxy node.

13. The user electricity theft detection system based on consortium blockchain and federated learning according to claim 9 or 10, characterized in that, After obtaining the aggregate model, the proxy nodes perform joint decryption. According to the characteristics of the threshold Paillier variant method, the number of proxy nodes performing joint decryption needs to exceed the threshold value to successfully recover the decryption key. The decrypted global model is packaged into a transaction, and Raft consensus is performed within the proxy nodes. The transaction block that successfully reaches consensus is added to the end of the blockchain.

14. The user electricity theft detection system based on consortium blockchain and federated learning according to claim 9 or 10, characterized in that, The proxy node needs to check the global model generated in each round. If the model update conditions recorded on the chain are met, the global training ends. After the proxy node adds the newly generated transaction block to the end of the blockchain, it adds a training end marker and records the new electricity theft detection model version number as the initial model for the next training. If the model update condition is not met, return to the local training step until the result of the current global model performance test meets the model update condition.

Citation Information

Patent Citations

  • Distributed Internet of Things intrusion detection method and system based on block chain and federated learning

    CN113794675A

  • Security release-oriented aggregation model training method, training device and system

    CN114398661A