## 3 Framework Design and Deployment
### Proposed Framework
#### 3.4.4 Blockchain Validation and Smart Contract Deployment  
Once the global model is updated, it undergoes validation to ensure it meets predefined accuracy thresholds. This process guarantees that only high-quality model updates are considered for deployment. The validated model \(M_{i+1}\) is recorded on the blockchain as \(Validate(M_{i+1})\to BChain\), creating an immutable and transparent record of each model version. By recording validated updates only, the framework prevents unauthorized modifications and ensures data integrity, providing a robust mechanism to maintain trust in the FL process.  
Following validation, the framework employs smart contracts to evaluate the updated model's quality before deployment. These contracts enforce predefined conditions, expressed as \(Deploy(M_{i+1})\)\(if\)\(SC(M_{i+1})==true\), ensuring that only models meeting specific performance standards are deployed. This automated compliance check safeguards model reliability, offering an additional security layer critical for real-world applications. Smart contracts not only streamline the deployment process but also enhance the overall trustworthiness of the system by automating governance and reducing the potential for human error.  
Algorithm 1 outlines the overarching workflow of the proposed blockchain-assisted FL framework. It integrates distinct yet interconnected procedures, including model initialization, local training on edge devices, federated model aggregation, blockchain validation, and smart contract deployment. Each step operates at a different layer of the system, collectively contributing to the framework's end-to-end functionality. This modular design ensures scalability, flexibility, and maintainability, allowing components to be adapted or enhanced independently while preserving the overall system integrity. By clearly delineating these tasks, the algorithm demonstrates how the framework achieves its goals of enhancing security, privacy, and operational efficiency in IIoT applications.  
```
1:Input: Initial model \(M_{0}\), edge devices data \(\{data_{local}^{k}\}_{k=1}^{N}\), blockchain \(BChain\), encryption key \(K\)
2:Output: Trained global model \(M_{final}\) securely recorded on blockchain
3:procedureInitialize Model on Blockchain
4:\(M_{0}=init()\)
5:\(BChain\leftarrow\mathrm{Hash}(M_{0})\)\(\triangleright\) Record hash of initial model on blockchain
6:endprocedure
7:procedureLocal Training with Homomorphic Encryption
8:for each edge device \(k=1,\ldots,N\)do
9:\(Enc(data_{local}^{k})=Encrypt(data_{local}^{k},K)\)\(\triangleright\) Encrypt local data using HE
10:\(Enc(M_{i+1}^{local})=Train(Enc(M_{i}),Enc(data_{local}^{k}))\)\(\triangleright\) Train locally on encrypted data
11:endfor
12:endprocedure
13:procedureFederated Averaging with XAI Integration
14: Collect \(Enc(M_{i+1}^{local})\) from all edge devices
15:\(Enc(M_{i+1})=Aggregate(\{Enc(M_{i+1})\}_{k=1}^{N})\)\(\triangleright\) Aggregate encrypted models using weighted averaging
16:\(M_{i+1}=Decrypt(Enc(M_{i+1}),K)\)\(\triangleright\) Decrypt aggregated model
17:for each prediction in \(M_{i+1}\)do
18: Generate XAI explanations (e.g., feature importance, attention maps)
19:endfor
20:endprocedure
21:procedureBlockchain Validation and Recording
22:ifValidate(\(M_{i+1}\))then
23:\(BChain\leftarrow\mathrm{Hash}(M_{i+1})\)\(\triangleright\) Record hash of validated model on blockchain
24:endif
25:endprocedure
26:procedureSmart Contract Execution and Deployment
27:ifSmartContract(\(M_{i+1}\)) == true then
28: Deploy \(M_{i+1}\) to edge devices\(\triangleright\) Deploy global model if conditions are met
29:endif
30:endprocedure
31:return\(M_{final}\)
```  
**Algorithm 1** Blockchain-assisted FL framework with HE and digital twins in IIoT (overall procedure).