# pFedBASC: Personalized Federated Learning with Blockchain-Assisted Semi-Centralized Framework
## 4 Methodology
### pFedBASC Workflow  
The training procedure of pFedBASC is shown in Figure 3. We will explain the workflow of pFedBASC in combination with Algorithm 2. When users participate in the training for the first time, they need to initialize both the model and blockchain parameters. The framework can use any FL algorithm; in this paper, we use FedHype, where the passed and aggregated parameters are denoted as \(\mathbf{\varphi}\). After training starts, clients update their models locally and broadcast their new model \(\mathbf{\varphi}_{i}^{t}\) to the trusted client group \(\text{C}_{i}^{group}\) via the Gossip protocol. \(C_{i}\) receives updated models \(\mathbf{\varphi}_{j}^{t_{j}}\) from \(\forall C_{j}\in\text{C}_{j}^{group}\), while for \(\forall C_{k}\
otin\Big{(}\text{C}_{i}^{group}\cup\{\text{C}_{i}\}\Big{)}\), the latest uploaded models \(\mathbf{\varphi}_{k}^{t_{k}}\) are downloaded from the blockchain. The blockchain constructs a _download block_ based on client behavior and proceeds with on-chain processes. ```
0: total communication rounds \(T\), HN learning rate \(\eta\), datasets \(\{D_{1},...,D_{N}\}\), trusted client group \(\{\mathcal{C}^{group},...,\mathcal{C}^{group}_{N}\}\)
0:\(\boldsymbol{\tilde{\varphi}}^{T}=\{\boldsymbol{\tilde{\varphi}}_{1}^{T},..., \boldsymbol{\tilde{\varphi}}_{N}^{T}\}\)
1: Initialize both local client and blockchain related parameters
2:at client \(i=1\) to \(N\) in parallel do
3:for each round \(t=1\) to \(T\)do
4:\(\boldsymbol{\varphi}_{i}^{t}\leftarrow\)ClientUpdate\(\left(\boldsymbol{\tilde{\varphi}}_{i}^{t-1}\right)\) via Fedhype
5:Communication: broadcast\(\boldsymbol{\varphi}_{i}^{t}\) to client within \(\mathcal{C}^{group}_{i}\) via Gossip protocol
6:Communication:
7: receive \(\boldsymbol{\varphi}_{j}^{t}\) from clients in \(\mathcal{C}^{group}_{i}\)
8: receive \(\boldsymbol{\varphi}_{k}^{t}\) from blockchain
9: construct a download block and submit it to blockchain for on-chain processes
10: Evaluate each received model \(\boldsymbol{\varphi}\) and calculate all required weights for \(p^{t}=p_{i}^{t}p_{1,i}^{t}\\ +\sum_{\mathcal{C}_{i}\in\mathcal{C}^{group}_{i}}p_{i}^{t}p_{1,j}^{t}p_{2,j}^{t }+\sum_{\mathcal{C}_{i}\
otin\mathcal{C}^{group}_{i}}p_{k}^{t}p_{1,k}^{t}p_{2,k} ^{t}\)
11:Communication:
12: upload evaluation scores to blockchain
13: construct an evaluation block with the evaluation scores and submit it to block-chain for on-chain processes
14:ModelAggregation: \(\boldsymbol{\tilde{\varphi}}_{i}^{t}=\frac{p_{i}^{t}p_{1,i}^{t}}{p^{t}} \boldsymbol{\varphi}_{i}^{t}+\sum_{\mathcal{C}_{j}\in\mathcal{C}^{group}_{i}} \frac{p_{i}^{t}p_{1,i}^{t}p_{2,i}^{t}}{p^{t}}\boldsymbol{\varphi}_{j}^{t}+ \sum_{\mathcal{C}_{i}\
otin\mathcal{C}^{group}_{i}}\frac{p_{i}^{t}p_{1,i}^{t}p _{2,k}^{t}}{p^{t}}\boldsymbol{\varphi}_{k}^{t}\)
15:Communication:
16: upload the aggregated model \(\boldsymbol{\tilde{\varphi}}_{i}^{t}\) to blockchain
17: construct an upload block containing the aggregated model and submit it to blockchain for on-chain processes
18:endfor
19:end at client
```  
**Algorithm 2**pFedBAS  
Then, \(\mathcal{C}_{i}\) evaluates each received and downloaded model to determine the weights \(p_{j}^{t}\) and \(p_{k}^{t}\). \(\mathcal{C}_{i}\) conducts local dataset model inference, determining the weights \(p_{1,i}^{t}\) and \(p_{1,k}^{t}\) by the loss function. \(\mathcal{C}_{i}\) records the round of each model and computes delayed round compensation weights \(p_{2,i}^{t}\) and \(p_{2,k}^{t}\). The clients submit the above evaluation scores, such as the loss and distinct model index for the blockchain. The construction of an _evaluation block_ and execution of on-chain processes follow. \(\mathcal{C}_{i}\) aggregates models to obtain the new round's \(\boldsymbol{\tilde{\varphi}}_{i}^{t}\) for training and uploads it. The blockchain constructs an _upload block_, and on-chain processes follow accordingly. This iterative process continues until the network converges or reaches the target number of rounds.