# Enable Fair Proof-of-Work (PoW) Consensus for Blockchains in IoT by Miner Twins (MinT)
## 4 Miner Twin-Enabled Fair-Mining Mechanism
### Fast Anomaly Detection for Fair Mining
Grouping and Reconstructing:** The next step is to group the matrices \(X_{i}\) into certain groups and to calculate the sum within these groups. Therefore, we denote a subset indices \(I=i_{1},i_{2},\ldots,i_{l}\), where \(l<L\). Therefore, the corresponding matrix is \(X_{I}=X_{i_{1}}+\ldots+X_{i_{l}}\). **4. Diagonal Averaging:** Using diagonal averaging, we can transfer \(X_{I}\) into time series \(\mathbb{X}_{I}\). \[\mathbb{X}_{I}(i)=\left\{ \begin{array}{ll}\frac{1}{I}\sum_{j=1}^{i}x_{j,i-j+ 1}&\text{for}\quad 1\leq i<L\\ \frac{1}{L}\sum_{j=1}^{L}x_{j,i-j+1}&\text{for}\quad L\leq i\leq K\\ \frac{1}{N-i+1}\sum_{j=i-k+1}^{N-K+1}x_{j,i-j+1}&\text{for}\quad K\leq i\leq N.\end{array} \right. \tag{2}\]  
By selecting certain subset indices \(I=i_{1},i_{2},\ldots,i_{l}\), one can reconstruct the time series. By observing the distance between the \(l\)-dimensional matrix and the test time series matrix, we can detect the anomaly by identifying a significant increase in the distance. The SSA-based Change-Point detection utilized in the paper can be described in following stages [41]:  
**Stage 1: Construct Base Matrix** First, construct the base matrix (or target matrix) according to the four steps of the SSA algorithm. Given the target time series \(\mathbb{X}=[x_{n+1},\ldots,x_{n+N}]\), embed it into the trajectory matrix \(X=[\vec{X}_{1},\vec{X}_{2},\ldots,\vec{X}_{K}]\), where \(K=N-L+1\). Then, the columns of the trajectory matrix are the vectors:  
\[\vec{X}_{i}=(x_{n+i},\ldots,x_{n+L+i-1})^{\prime},i=1,\ldots,K. \tag{3}\]  
Then, conduct the SVD and get L eigenvectors which can be grouped into certain subset \(I=i_{1},i_{2},\ldots i_{l},l<L\). **Stage 2: Construct Test Matrix** Similarly, we select integers \(p,q\) and \(Q\) where \(Q=q-p>0\). Then, we construct the test matrix of size \(L\times Q\):  
\[X_{test}=[X_{p+1}^{\rightarrow},X_{p+2}^{\rightarrow},\ldots,X_{p+Q}^{ \rightarrow}], \tag{4}\]  
and the columns of the matrix are the vectors:  
\[\vec{X}_{j}=(x_{n+j},\ldots,x_{n+L+j-1})^{\prime},j=p+1,\ldots,p+Q, \tag{5}\]  
**Stage 3: Compute the Detection Statistics** In this stage, we first compute \(D_{n,I,p,q}\), the sum of the squared Euclidean distances between the \(l\)-dimensional subspace from the base matrix and the vectors \(\vec{X}_{j}(j=p+1,\ldots,p+Q)\)from the test matrix. \[D_{n,I,p,q}=\sum_{j=p+1}^{q}((\vec{X}_{j})^{T}\vec{X}_{j}-(\vec{X}_{j})^{T}UU^ {T}\vec{X}_{j}). \tag{6}\]  
Then, we give the normalized sum of squared distances  
\[S_{n}=\frac{1}{\mu_{n,l}}\tilde{D}_{n,I,p,q}, \tag{7}\]  
where \(\tilde{D}_{n,I,p,q}=\frac{1}{LQ}D_{n,I,p,q}\) and \(\mu_{n,l}=\tilde{D}_{m,I,0,K}\) is the estimator and we make the hypothesis that no change of time series structure occurs at the time intervals where \(m\) is the largest value of \(m\leq n\). We also compute the Cumulative Sum (CUSUM) \(W_{n}\) of the normalized sum of squared distances as the final score for the anomaly detection. \[W_{1}=S_{1},W_{n+1}=max\{0,W_{n}+S_{n+1}-S_{n}-\kappa/\sqrt{LQ}\},n\geq 1, \tag{8}\]where \(\kappa\) is a constant, and in this paper, we set \(\kappa=1/(3\sqrt{LQ})\)[43]. **Stage 4: Set threshold and make decisions** To detect the change of the time series, we could check the values of \(D_{n,l,p,q}\), \(S_{n}\) and \(W_{n}\). Basically the large value of the three detection statistics indicates the change or the anomaly. In this paper, we choose the \(W_{n}\)-based detection algorithm as it gives greater sensitivity compared with the former two detection statistics [41]. The algorithm announces a structural change if we observe \(W_{n}>h\) for some \(n\) where \(h\) is the threshold given by  
\[h=\frac{2t_{\alpha}}{LQ}\sqrt{\frac{1}{3}Q(3 LQ-Q^{2}+1)}, \tag{9}\]  
and \(t_{\alpha}\) is the \(1-\alpha\)-quantile of the standard normal distribution [41].