# TDLearning: Trusted Distributed Collaborative Learning Based on Blockchain Smart Contracts
## 3 Method
### Smart Contract Design
#### 3.3.1 Role-Authority Management  
As shown in Algorithm 1, the role-authority-management module is implemented by the AMC, which implements a role-based authority-management mechanism for accessing and assigning authority to collaborative nodes to participate in collaboration. Its core  
\begin{table}
\begin{tabular}{l l} \hline \hline
**Notation** & **Description** \\ \hline \(N_{address}\) & Collaborative node Ethereum address \\ \(N_{info}\) & Node identity and authority information \\ \(N_{role}/N_{status}\) & Node role/status \\ \(N_{name}/N_{summary}\) & Node name/summary \\ \(D_{hash}/D_{status}\) & Data hash/availability status \\ \(D_{name}/D_{summary}\) & Data name/summary \\ \(T_{name}\) & Collaborative task name \\ \(T_{summary}/T_{reward}\) & Task summary/incentive benchmark \\ \(T_{secret}\) & Cryptographic numbers for model verification \\ \(V_{n}\) & The number of \(Mv_{s}\) specified by \(T\) \\ \(C_{\psi}\) & Credibility for \(Mv\) \\ \(V_{\theta}\) & Credibility threshold for \(Mv_{s}\) \\ \(\theta\) & Model-verification thresholds \\ \hline \hline \end{tabular}
\end{table}
Table 2: Notation symbols used in TDLearning.  
Figure 3: Sequence diagram of trusted distributed cooperative-learning mechanism based on smart contract.  
function is to maintain a list of trusted collaborative nodes. In addition, the _Mv_ is a special collaborative role, which interacts with both the _To_ and the _Tp_. Therefore, the AMC records the list of _Mv\({}_{s}\)_ and maintains credibility values for them. When the _To_ and _Tp\({}_{s}\)_ believe that the _Mv_ is behaving suspiciously, they can apply to the _Su_ to initiate arbitration, and the AMC will initiate a trust arbitration vote on the _Mv_.  
```
1.nodeRegister(0): if(msg.sender is not registered) Update node list: \(N_{info}\)[msg.sender] = nodeInfo (\(N_{role}\), \(N_{status}\), \(N_{name}\), \(N_{address}\), \(N_{summary}\)); Initialise node authority; else return false;
2.updateAuthority0: require(msg.sender_role = Su) Update \(N_{info}\)[\(N_{address}\).nodeRole] = \(N_{role}\); Update \(N_{info}\)[\(N_{address}\).nodeStatus] = \(N_{status}\);
3.updateVerifiersCredit0: require(msg.sender_role = Su) for each\(i\) in _Mv\({}_{s}\) if(\(i\) is not been applied for arbitration) \(Cv_{i}=Cv_{i}+1\); else \(Su\) creates the arbitration for \(i\);
```  
**Algorithm 1** Authority Management (AMC)  
(a) A new node participating in a collaborative task calls nodeRegister() to register identity information with the blockchain. \(N_{role}\) is represented by four sets of key-value pairs, 0 for an undefined role, 1 for _Su_, 2 for _To_ and _Tp_ and 3 for _Mv_. \(N_{status}\) is represented by two sets of key-value pairs, 0 for pending audit or illegal status and 1 for legal status. \(N_{address}\) is a unique node identifier, which is bound to the identity-authority information by keyword mapping.  
(b) _Su_ calls updateAuthority to edit collaborative node permissions. The blockchain keeps a realistic record of collaborative interactions, allowing _Su_ to intervene in a timely manner when a node behaves suspiciously.  
(c) _Su_ deploys smart contracts while initializing _Mv_ and initializing _Cv_. To deal with potentially malicious behaviour, the collaborative-learning mechanism introduces a model verifier credibility-evaluation system and an arbitration voting mechanism for suspicious behaviour. After the collaborative task is completed, _Su_ calls the updateVerifiersCredit() to update _Cv_. _Cv_ is updated as shown in Equation (1), where \(n\) is the number of untrusted votes for _Mv_ in the arbitration vote and n is 0 to mean that no node in this task has requested to initiate arbitration for _Mv_. \(m\) is the number of _Tp\({}_{s}\)_, and _Su_ removes the _Mv_ from the verifiers list and sets _Cv_ to 0 when more than half of the _Tp\({}_{s}\)_ believe that the _Mv_ has suspicious behaviour:  
\[C_{v}=\begin{cases}C_{v}+1,n=0\\ C_{v}-n,n\leq\frac{m}{2}\\ 0,n>\frac{m}{2}\end{cases} \tag{1}\]