## 3 System Model
### Workflow  
FL allows clients to collaboratively train global models while keeping personal data on their own devices for privacy. In the proposed framework, the cloud accepts the task request and then publishes the initial global model and task requirements to the blockchain at the edge layer. Subsequently, \(N\) (\(N\leq M\)) clients are selected according to the client selection policy to participate in model training, then \(N\) clients are assigned to \(K\) edge servers according to distance. Each edge server is assigned the \(a\) device closest to it, and the size of the dataset under each edge server is \(|H_{k}|=\sum_{n=1}^{a}|H_{n}|\). Different from traditional centralized federated learning, the hierarchical federated learning process not only contains local and global models but also introduces edge models. For each time interval \(T\), the client \(n\) under the edge server \(k\) divides its own data \(H_{n}\) into batches for \(T_{n}^{iter}\) iterative training to generate the local model \(\omega_{n}^{(T_{n}^{iter})}\). At time \(T\), the client uploads the model parameters to the edge server for edge aggregation to obtain the edge model \(\omega_{k}^{(l)}\). Then, after every \(L\) edge model aggregation, the cloud server aggregates the models of all edge servers to obtain the global model \(\omega^{(t)}\). The aggregation process is shown in Figure 1.  
As shown in Figure 2, the system works as follows:  
1. Initialization: Initializing the global model in the cloud server and uploading it to the blockchain. 2. Client selection: The server selects \(N\) (\(N\leq M\)) clients from \(M\) candidates based on the client selection scheme proposed in Section 4, then assigns the \(N\) clients to \(K\) edge servers according to distance for model training. 3. Local model update: Client \(n\) downloads the initial global model from the blockchain. Based on the global model, each client uses the local dataset for model training. The goal of local training is to minimize the loss function on the training dataset, and for each data sample \(j\in H_{n}\), the loss function \(l_{j}(\mathbf{x}_{j},y_{j},\omega_{j})\) is defined as the difference between its predicted and actual values, where \(\omega_{j}\) denotes the local model parameter for client \(n\). The loss function for the dataset on client \(n\) is defined as follows: \[L_{n}(\omega)=\frac{1}{|H_{n}|}\sum_{j\in H_{n}}l_{j}(\mathbf{x}_{j},y_{j}, \omega_{j})\] (1)  
Figure 1: Aggregation process. The local model update is expressed as follows:  
\[\omega_{n}^{(T^{tl})}=\omega_{n}^{(T^{tl}-1)}-\eta\
abla L_{n}\Big{(}\omega_{n}^{ (T^{tl}-1)}\Big{)} \tag{2}\]  
where \(\eta\) denotes the learning rate at the time of parameter update and \(T^{tl}\) denotes the number of iterations for local training. 1. Local model upload: Each mobile device encrypts its local model parameter \(\omega_{n}^{(T^{\sharp})}\) with a unique digital signature and uploads the model to miner nodes. 2. Edge model aggregation and score update: In the \(l\)-th edge iteration, the client downloads the current edge model, all models under edge server k, the current score from the blockchain. In this step, the edge models are aggregated in an semi-asynchronous manner. One verified local model is aggregated every time. The aggregation process is defined as follows: \[\omega_{k}^{(l)}=(1-\xi)\omega_{k}^{(l-1)}+\xi\omega_{k,new}\] (3) where \(\omega_{k,new}\) is a newly generated local model, and \(\xi\) is the weight of the new model. The greater the weight, the greater the contribution of the newly generated local model to the edge model. Each device uses the score, the local model, and the edge model to compute a new score for device \(n\) for the current round. 3. Edge model and score upload: Each edge server \(k\) encrypts the edge model parameter \(\omega_{k}^{(l)}\) with a unique digital signature, then uploads the model and the score to the blockchain. 4.