A blockchain federated learning method and system based on sgx
By introducing the SGX secure aggregation method and asynchronous federated learning algorithm into blockchain federated learning, the problems of malicious attacks and low efficiency of consensus mechanisms are solved, achieving efficient and secure model aggregation and verification, and improving the reliability and scalability of the system.
Patent Information
- Application Number
- CN202410084093.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-19
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2044-01-19
AI Technical Summary
Existing blockchain-based federated learning schemes are difficult to defend against attacks by malicious aggregators, and traditional consensus mechanisms have high communication complexity and poor scalability. Existing secure aggregation methods are not effective under TEE memory constraints.
A secure aggregation method based on SGX is adopted. By establishing a secure channel between the client and the aggregation server, remote authentication is performed using Intel Remote Authentication Service, and model aggregation and verification are carried out in the SGX environment. Combined with asynchronous federated learning algorithms and improved consensus mechanisms, the security and efficiency of the model are ensured.
It improves the security and scalability of blockchain federated learning, reduces time overhead, prevents malicious attacks, and ensures the accuracy and integrity of the model.
Smart Images

Figure CN117875452B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of federated learning technology in artificial intelligence, and more specifically to a blockchain-based federated learning method. Background Technology
[0002] Federated learning, as an emerging machine learning method, offers significant advantages in addressing issues such as data privacy protection and inter-data center communication costs. By distributing machine learning algorithms to local devices for training, it avoids the privacy risks associated with data transmission and centralized storage, and significantly reduces data transmission and communication costs. Currently, federated learning is widely used in finance, healthcare, and the Internet of Things (IoT).
[0003] While federated learning offers significant advantages in addressing data privacy and communication costs, it also presents potential security and privacy challenges, such as malicious nodes and Byzantine faults. To address these issues, blockchain-based federated learning (BFL) has garnered significant attention in recent years. The decentralized, immutable, and traceable characteristics of blockchain technology enable it to guarantee the security and privacy of federated learning, thereby driving its development.
[0004] The introduction of blockchain has changed the training architecture of traditional federated learning, but it has also introduced new security risks. In blockchain-based federated learning, there is no longer an honest and curious aggregator as in traditional federated learning; instead, there is a more serious adversary model. In this open environment, the aggregator may be malicious. They may hinder training by returning an incorrect model, launch backdoor attacks, or initiate free-riding attacks, replacing the global model with their own private model and handing it over to the client for training.
[0005] Unfortunately, due to the security limitations of the underlying blockchain consensus mechanism, current BFL solutions are vulnerable to such attacks. In FL, aggregators update the global model relying on numerous client-side local models, while clients generate their local models based on the global model generated by the aggregator in the previous round. However, most BFLs employ the longest-chain consensus mechanism, which does not require the blockchain state on each node to remain globally consistent in every round; new blocks need to wait for confirmation from a sufficient number of subsequent blocks before the state can be probabilistically determined. Therefore, when applying the longest-chain consensus directly in BFL, clients must rely on the latest, untrusted global model for training. Malicious aggregators can easily exploit this security vulnerability to launch attacks. Although some research has attempted to avoid this problem through strong consistency consensus based on PBFT, the PBFT mechanism has high communication complexity and poor scalability. Its performance degrades significantly as the number of nodes increases, making it difficult to apply in BFLs.
[0006] Worse still, existing secure and robust federated learning methods are difficult to apply simply to BFL to address this security vulnerability due to differing security assumptions about malicious aggregators. Most secure aggregation methods are designed to defend against inference attacks and must rely on honest aggregators. Other schemes targeting backdoor attacks are also insufficient to completely prevent attacks aimed at hindering training. Some secure aggregation methods based on Trusted Execution Environments (TEEs) decrypt and aggregate client cryptographic models within the TEE to protect client privacy, but this does not prevent malicious aggregators from achieving their goals by tampering with the TEE's inputs and outputs. Furthermore, associating consensus algorithms with TEE deployment and execution can lead to significant costs, limiting the application of these secure aggregation methods in BFL. The memory limitations of TEEs further weaken the applicability of these methods. Summary of the Invention
[0007] The technical problem this invention aims to solve is to provide a fast, efficient, and secure blockchain federated learning method and system based on SGX, addressing the aforementioned problems in existing technologies.
[0008] To address the aforementioned technical problems, the present invention adopts the following technical solution: a blockchain federated learning method and system based on SGX, comprising:
[0009] S1: Each client and each aggregation server's SGX, as well as each aggregation server's SGX, use Intel Remote Authentication Service to perform remote authentication and establish secure channels.
[0010] S2: The client trains the local model and saves the parameters of the local model.
[0011] S3: The client generates training results and publishes them to the blockchain network.
[0012] In S4, the blockchain system uses a consensus mechanism to determine the aggregation server that will perform the aggregation in this round. The aggregation server asynchronously retrieves the client model from the blockchain network and verifies it. If the verification is successful, the model is aggregated.
[0013] S5: After the aggregation server completes the model aggregation, it generates the aggregation result and publishes it to the blockchain.
[0014] S6, other blockchain nodes verify the integrity of the aggregation result. If the verification is successful, the block is added to the local block and the next round of training begins.
[0015] Optionally, the method for establishing a secure channel in step S1 includes: each aggregation server generating a pair of keys using an asymmetric key generation algorithm and distributing the public key to all other nodes in the system; and each client exchanging symmetric keys with the aggregation server using a secure key exchange algorithm.
[0016] Optionally, the method for the client to generate training results in step S3 includes: the client performing a hash operation on the local model gradient, and encrypting the hash operation result and the local model gradient together using a symmetric key to obtain the training result.
[0017] Optionally, the method for the aggregation server to verify the local model gradient in step S4 includes: the aggregation server decrypts the local model gradient of each client using a symmetric key in SGX, calculates the hash of the local model gradient, and compares it with the hash calculated by the client itself. If they match, the verification is successful. If they do not match, the gradient is discarded.
[0018] Optionally, the asynchronous aggregation method in step S4 includes: whenever a client publishes training results on the blockchain, the aggregation server immediately obtains the training results and aggregates them.
[0019] Optionally, the federated learning aggregation algorithm used in step S4 is shown in equation (1):
[0020]
[0021] In equation (1), n represents the temporary global model generated during the aggregation process. k Let be the total number of training samples on device k, and n represent the total number of samples across all devices. Let represent the local model gradient of device k. When aggregating the first local model, the parameters of the aggregation algorithm described above are shown in equation (2):
[0022]
[0023] In equation (2), w t Let represent the global model in round t. When aggregating the last local model, the parameters of the above aggregation algorithm are shown in equation (3):
[0024]
[0025] In equation (3), w t+1 This represents the global model after this round of aggregation, where K represents the total number of clients participating in training this round. The aggregated model is a weighted average of the local models on each device.
[0026] Optionally, the method for generating the aggregation result in step S5 includes: performing a hash operation on the aggregation model and signing it using a private key.
[0027] Optionally, the method for verifying the integrity of the aggregation result in step S6 includes: the client uses the public key to decrypt the model hash value calculated by the aggregation server and compares it with the hash value calculated by itself; if they are the same, the verification is successful.
[0028] Compared with the prior art, the advantages of the present invention are as follows:
[0029] 1. We have discovered a security vulnerability in BFL, where malicious aggregators can exploit the time lag before the latest global model is reached in consensus to launch attacks on clients by tampering with the global model. We also present a secure aggregation method based on SGX as a solution.
[0030] 2. We propose an asynchronous federated learning aggregation algorithm within SGX, which aims to improve the performance of SGX aggregation in heterogeneous environments. In each round, only a small number of models need to be aggregated within SGX, thereby overcoming the memory constraints of SGX and improving the efficiency and scalability of the algorithm.
[0031] 3. We propose an improved consensus mechanism for the BFL aggregation process based on TEE. By verifying the digital signature generated within SGX, other nodes can efficiently verify the correctness of the global model without hardware requirements, ensuring the correctness of the aggregation and improving the credibility and security of the entire system. Attached Figure Description
[0032] Figure 1 This is a schematic diagram of the basic process of the method in an embodiment of the present invention.
[0033] Figure 2 This is a schematic diagram of the workflow in the aggregation server in the method of this embodiment of the invention.
[0034] Figure 3 The time cost of training on different models and datasets in the embodiments of the present invention.
[0035] Figure 4 This refers to the test accuracy of the embodiments of the present invention when attacked during training on different models and datasets. Detailed Implementation
[0036] The present invention will be further described below with reference to the accompanying drawings and specific preferred embodiments, but this does not limit the scope of protection of the present invention.
[0037] In this embodiment, the blockchain includes several aggregation servers and several client devices. The set of aggregation servers is denoted as A = {a1, a2, ..., a...}. M The set of client devices is denoted as C = {c1, c2, ..., c}.N} where M is the total number of aggregation servers and N is the total number of client devices. Both aggregation servers and clients are nodes in the blockchain. Aggregation servers can communicate with each other and with clients through on-chain and off-chain channels to exchange information and data. This blockchain is not limited to the one described in this embodiment; those skilled in the art can implement blockchain deployment according to actual circumstances.
[0038] This embodiment presents a blockchain federated learning method and system based on trusted execution swapping, such as... Figure 1 As shown, the process includes the following steps: S1, each client and the SGX of each aggregation server, and the SGX of each aggregation server, use Intel Remote Authentication Service to perform remote authentication and establish a secure channel. S2, the client trains the local model and saves the parameters of the local model. S3, the client generates the training results and publishes them to the blockchain network. S4, the blockchain system uses a consensus mechanism to determine the aggregation server to perform the aggregation in this round. The aggregation server asynchronously obtains the client's client model from the blockchain network and verifies it. After successful verification, it performs model aggregation. S5, after completing model aggregation, the aggregation server generates the aggregation result and publishes it to the blockchain. S6, other blockchain nodes verify the integrity of the aggregation result. After successful verification, the block is added to their local block, and the next round of training begins.
[0039] In this embodiment, the method for establishing a secure channel in step S1 includes: each aggregation server generating a pair of keys using an asymmetric key generation algorithm and distributing the public key to all other nodes in the system; and each client exchanging symmetric keys with the aggregation server using a secure key exchange algorithm.
[0040] In this embodiment, the method for the client to generate training results in step S3 includes: the client performing a hash operation on the local model gradient, and encrypting the hash operation result and the local model gradient together using a symmetric key to obtain the training result.
[0041] In this embodiment, the method for the aggregation server to verify the local model gradient in step S4 includes: the aggregation server decrypts the local model gradient of each client using a symmetric key in SGX, performs a hash operation on the local model gradient, and compares it with the hash operation calculated by the client itself. If they match, the verification is successful. If they do not match, the gradient is discarded.
[0042] In this embodiment, the asynchronous aggregation method in step S4 includes: whenever a client publishes training results on the blockchain, the aggregation server immediately obtains the training results and aggregates them.
[0043] In this embodiment, the federated learning aggregation algorithm used in step S4 is shown in equation (1):
[0044]
[0045] In equation (1), n represents the temporary global model generated during the aggregation process. k Let be the total number of training samples on device k, and n represent the total number of samples across all devices. Let represent the local model gradient of device k. When aggregating the first local model, the parameters of the aggregation algorithm described above are shown in equation (2):
[0046]
[0047] In equation (2), w t Let represent the global model in round t. When aggregating the last local model, the parameters of the above aggregation algorithm are shown in equation (3):
[0048]
[0049] In equation (3), w t+1 This represents the global model after this round of aggregation, where K represents the total number of clients participating in training this round. The aggregated model is a weighted average of the local models on each device.
[0050] In this embodiment, the method for generating the aggregation result in step S5 includes: performing a hash operation on the aggregation model and signing it using a private key.
[0051] In this embodiment, the method for verifying the integrity of the aggregation result in step S6 includes: the client uses the public key to decrypt the model hash value calculated by the aggregation server and compares it with the hash value calculated by itself. If they are the same, the verification is successful.
[0052] In this embodiment, the technical solution is verified through simulation experiments. PyTorch is used for client-side model training, and the aggregation program running in SGX is developed using the Teaclave SGX SDK. In the simulation experiments, the system consists of one aggregation server and 100 client devices. In each training round, 10 clients are selected to participate in the training, and each client iterates once on its own training data in each round. In this embodiment, CNN and MLP neural network models are selected for the experiments. For each neural network model, CIFAR10 and MNIST datasets are used as benchmark datasets. The training time results for four combinations with or without SGX aggregation are shown below. Figure 3As shown. When evaluating using a CNN model, the number of parameters was 62006 for the CIFAR10 dataset and 21840 for the MNIST dataset; when evaluating using an MLP model, the number of parameters was 197322 for the CIFAR10 dataset and 50890 for the MNIST dataset. Figure 3 It can be seen that the time overhead introduced by using SGX for aggregation is very small or even negligible. Under these four experimental settings, the training time per round increases by 4.53%, 3.67%, 1.86%, and 7.45%, respectively. The basic trend is that the larger the model and the more model parameters, the smaller the relative time overhead generated by using SGX for aggregation.
[0053] In this simulation experiment, Gaussian noise X ~ N(0, σ) was also added to the global model. 2 This simulation aims to model a system subjected to a malicious aggregation attack. In this simulation, σ is taken as... 2 =0.1. Figure 4 This section illustrates the impact of noise injection attacks on model accuracy with or without SGX protection, under different model and dataset conditions. (a) represents the test accuracy under the CNN & MNIST settings, (b) represents the test accuracy under the MLP & CIFAR settings, and (c) represents the test accuracy under the MLP & MNIST settings. Figure 4 It can be seen that when using SGX for aggregation, attackers cannot attack the global model, while without protection, the accuracy of the model drops significantly due to the injection of noise.
[0054] In summary, this embodiment, based on the SGX-based BFL scheme, transfers the aggregation process from the aggregation server to the SGX environment of the aggregation server, and establishes a secure channel between the client and the SGX environment on the aggregation server to protect the gradient security of the client and prevent server tampering, free-riding, and other attacks. It enhances the security and reliability of the blockchain federated learning process with only a small time overhead, without affecting the accuracy of the model.
[0055] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-readable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. 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, create a machine for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The 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 operate 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 functions specified in one or more boxes. These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable apparatus 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.
[0056] The above are merely preferred embodiments of the present invention and are not intended to limit the invention in any way. Although the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the invention. Therefore, any simple modifications, equivalent changes, and alterations made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention should fall within the protection scope of the present invention.
Claims
1. A blockchain federated learning method based on SGX, characterized in that, include: S1, each client and each aggregation server's SGX, and each aggregation server's SGX, use Intel Remote Authentication Service to perform remote authentication and establish a secure channel; S2, the client trains the local model and saves the parameters of the local model; S3: The client generates training results and publishes them to the blockchain network; S4, the blockchain system uses a consensus mechanism to determine the aggregation server that will execute the aggregation in this round; The aggregation server asynchronously retrieves and verifies the client model from the blockchain network. After successful verification, it performs model aggregation. Whenever a client publishes training results on the blockchain, the aggregation server immediately retrieves and aggregates the training results. The federated learning aggregation algorithm used in this step is shown in Equation (1): (1) In equation (1), This represents a temporary global model generated during the aggregation process. Let be the total number of training samples on device k, and n represent the total number of samples across all devices. Indicates equipment The local model gradient; when aggregating the first local model, the parameters of the above aggregation algorithm are shown in equation (2): (2) In equation (2), wt represents the global model in round t; when aggregating the last local model, the parameters of the above aggregation algorithm are shown in equation (3): (3) In equation (3), wt+1 represents the global model after this round of aggregation, and K represents the total number of clients participating in training in this round; the aggregated model is the weighted average of the local models of each device. S5: After the aggregation server completes the model aggregation, it generates the aggregation result and publishes it to the blockchain; S6, other blockchain nodes verify the integrity of the aggregation result. If the verification is successful, the block is added to the local block and the next round of training begins.
2. The blockchain federated learning method based on SGX according to claim 1, characterized in that, The method for establishing a secure channel in step S1 includes: each aggregation server generating a pair of keys using an asymmetric key generation algorithm and distributing the public key to all other nodes in the system; and each client exchanging symmetric keys with the aggregation server using a secure key exchange algorithm.
3. The blockchain federated learning method based on SGX according to claim 2, characterized in that, The method for generating training results by the client in step S3 includes: the client performing a hash operation on the local model gradient, and encrypting the hash operation result and the local model gradient together using a symmetric key to obtain the training result.
4. The blockchain federated learning method based on SGX according to claim 3, characterized in that, The method for the aggregation server to verify the local model gradient in step S4 includes: the aggregation server decrypts the local model gradient of each client in SGX using a symmetric key, performs a hash operation on the local model gradient, and compares it with the hash operation calculated by the client itself. If they match, the verification is successful; otherwise, it is discarded.
5. The blockchain federated learning method based on SGX according to claim 4, characterized in that, The method for generating the aggregation result in step S5 includes: performing a hash operation on the aggregation model and signing it using a private key.
6. The blockchain federated learning method based on SGX according to claim 5, characterized in that, The method for verifying the integrity of the aggregation result in step S6 includes: the client uses the public key to decrypt the model hash value calculated by the aggregation server and compares it with the hash value calculated by itself. If they are the same, the verification is successful.
Citation Information
Patent Citations
Federal learning method and system based on block chain and trusted execution environment
CN113837761A
Medical data federal learning method and system based on trusted execution environment
CN116484426A
