# TDLearning: Trusted Distributed Collaborative Learning Based on Blockchain Smart Contracts
## 3 Method
### Smart Contract Design
#### 3.3.3 Collaborative Task Management and Collaboration-Incentive Allocation  
To protect data privacy, the blockchain only stores a summary of the data, so the registration of the data by data nodes, i.e., \(Tp\), is completely subjective, and it is difficult to assess the quality of their local data. In order to cope with this problem, we introduce the fuzzy comprehensive evaluation method into smart contracts to realise the quality evaluation of on-chain registration data. In order to realise the dynamic evaluation of the dataset quality, the evaluation factors are divided into initial static-evaluation factors and dynamic-behaviour-evaluation factors. For example, for supervised classification questions, set the evaluation factors as shown in Table 3.  
The three initial evaluation factors and \(T_{num}\) all belong to a skewed large trapezoidal distribution, corresponding to the function shown in Equation (2), where \(x\) is the true value of the evaluation factor and \(S(x)\) is the rating of the evaluation factor, and the constants \(a\) and \(b\) are determined by the properties of the task and the associated dataset, respectively:  
\[S(x)=\begin{cases}0,x<a\\ \frac{x-a}{x-b},a\leq x\leq b\\ 1,b<x\end{cases} \tag{2}\]  
\(T_{time}\) is affiliated with a small skewed trapezoidal distribution with the corresponding function shown in Equation (3), and \(t\) is the predefined model submission-time threshold for the collaborative task:  
\[S(x)=\begin{cases}1,x<t\\ \frac{2t-x}{t},t\leq x\leq 2t\\ 0,2t<x\end{cases} \tag{3}\]  
\(N_{credit}\) is set as an adjustable constant with the update expression as in Equation (4). \(C\) is the current credit value, \(C_{r}\) is the task-completion credit reward value and \(C_{p}\) is the noncompletion credit penalty value. \(\theta_{i}\) is the value of the pretrained model-verification metric for data node \(i\), such as the model-classification accuracy, and \(\theta\) is the model-verification metric threshold:  
\[C=\begin{cases}C+Cr,\theta_{i}\geq\theta\\ C-Cp,\theta_{i}<\theta\end{cases} \tag{4}\]  
The evaluation steps are shown in Algorithm 3, including initialising the data scores and updating the data scores. The smart contract calculates a composite score Dscore based on a predefined weight vector and evaluation factors, as shown in Equation (5). \(E_{i}\) is the evaluation factor, \(w_{i}\) is the corresponding weight and \(D_{score}\in[0,1]\), with higher scores representing the higher quality of the corresponding dataset:  
\[D_{score}=\sum w_{i}\times E_{i} \tag{5}\]  
In summary, the data-index construction and data-quality evaluation are performed through smart contracts, and the data registered by the data nodes to the blockchain are organised into the structure shown in Figure 4. Each piece of data in the trusted database is associated with a data owner and is highly structured in a way that creates an inverted index for easy data retrieval. A data-quality-evaluation mechanism encourages data nodes to upload high-value data, and records of dynamic updates to the data scores are permanently stored in the blockchain in the form of transactions.  
\begin{table}
\begin{tabular}{l l} \hline \hline
**Initial Static Factors** & **Dynamic Behaviour Factors** \\ \hline Data size: \(D_{size}\) & Number of tasks completed: \(T_{num}\) \\ Sample label completeness: \(D_{lable}\) & Completion time for this task: \(T_{time}\) \\ Node computing power: \(D_{node}\) & Node Credits: \(N_{credit}\) \\ \hline \hline \end{tabular}
\end{table}
Table 3: Factor sets of the fuzzy comprehensive evaluation.