# Privacy-Preserving Byzantine-Resilient Swarm Learning for E-Healthcare
## 5 Our Privacy-Preserving Swarm Learning  
As shown in Figure 3, our PBSL described in this section mainly includes four stages: (I) system initialization, (II) local computation, (III) model aggregation, and (IV) global model decryption and updating.  
Firstly, **TA** sets initialization parameters, generates key pairs \(<\)_sk\({}_{FHE}\)_, \(pk_{FHE}\)\(>\)_, divides _sk\({}_{FHE}\)_ into \(K\) shares through [PERSON]'s secret sharing, and distributes \(K\) shares to _K_**MCs**, respectively.  
Then, **MCs** train their model on its local dataset and encrypt their gradients by fully homomorphic encryption technology CKKS [34], which are broadcasted to the blockchain-based network.  
Furthermore, the **MC** that wins the consensus mechanism uses a cosine similarity-based strategy to punish malicious gradient vectors, obtain the encrypted global model through homomorphically aggregating the encrypted local gradients, and stores the encrypted collaborative learning results on the blockchain.  
Finally, **MCs** obtain the encrypted global models from the blockchain and cooperatively decrypt the encrypted global models to obtain the global models. We summarize PBSL in Algorithm 1, and illustrate the details of each process in the following. Table 2 lists the description of notations in our PBSL.  
Figure 3: An overview of proposed PBSL.  
```
Input:\(K\) medical centers \(\{\mathbf{MC}_{1},\ldots,\mathbf{MC}_{K}\}\) with local training datasets \(D=\{D_{1},\ldots,D_{K}\}\), learning rate \(\gamma\), and iterations \(e\). Output: Global model \(\mathbf{w}\).
1:\(\mathbf{MC}_{1},\ldots,\mathbf{MC}_{K}\) form a blockchain-based P2P network, where \(\mathbf{MC}_{k}\) has pseudo public key \(pk_{k}^{psu}\) and secret key \(sk_{k}\)
2:TA generates \(<sk_{FHE},pk_{FHE}>\), splits \(sk_{FHE}\) into \(K\) parts, and distributes \(sk_{FHE}^{k}\) to \(\mathbf{MC}_{k}\), where \(k\in\{1,2,\ldots,K\}\).
3:\(\mathbf{MC}_{T}\) as task publisher broadcasts the SL task by deploying an SC over the network, where SC specifies hyper-parameters: local learning rate \(\alpha\), local batch size \(b\), and initial global model \(\mathbf{w}_{0}\).
4:Each \(\mathbf{MC}_{k}\) publishes \(<pk_{k}^{psu},\mathit{proof}_{sk_{k}}>\) to SC, and SC verifies \(\mathit{proof}_{sk_{k}}\) and returns the hyper-parameters to \(\mathbf{MC}_{k}\) if the verification passes.
5:for\(t\in[1,e]\) and accuracy of the learned model is not up to standarddo for each \(k\in\{\mathbf{MC}_{1},\ldots,\mathbf{MC}_{K}\}\)do  Get global model \([\![\mathbf{w}_{t-1}]\!]_{pk_{FHE}}\) from blockchain ; \([\![\mathbf{\tilde{g}}_{t}]\!]_{pk_{FHE}}\leftarrow\mathbf{Local\_ Computation}(D_{k},b,\mathbf{\alpha},r)\) ;  Broadcast the message \(msg_{k}\): \(\mathbb{M}_{t}^{k}\leftarrow(pk_{k}^{psu},[\![\mathbf{\tilde{g}}_{t}^{k}]\!]_{ pk_{FHE}},t)\) ;  end for  Each \(\mathbf{MC}_{k}\) competes to solve PoW problem ; if\(\mathbf{MC}_{k}\) winsthen  Retrieve \(\{[\![\mathbf{\tilde{g}}_{t}^{k}]\!]_{pk_{FHE}}\}_{k=1}^{K}\) from its memory pool ; \([\![\mathbf{\tilde{g}}_{t}]\!]_{pk_{FHE}}\leftarrow\mathbf{Global\_ Aggregation}(\{[\![\mathbf{\tilde{g}}_{t}^{k}]\!]_{pk_{FHE}}\}_{k=1}^{K})\) ; \([\![\mathbf{w}_{t}]\!]_{pk_{FHE}}\leftarrow[\![\mathbf{w}_{t-1}]\!]_{pk_{FHE}} -\gamma[\![\mathbf{\tilde{g}}_{t}]\!]_{pk_{FHE}}\)  Create \(B_{t}=([\![\mathbf{w}_{t-1}]\!]_{pk_{FHE}},[\![\mathbb{M}_{t}^{1},\mathbb{M}_{ t}^{2},\ldots,\mathbb{M}_{t}^{K}]\!])\), and appends \(B_{t}\) to the blockchain;  end if  end for
```  
**Algorithm 1**PBSL