## 4 Platform Design
### Consensus Protocol  
Blockchain is principally a distributed architecture with no central authority, the validity of the shared ledger is agreed upon consensus held between nodes in the network. Thus, consensus protocol stands as a key feature in such an architecture-based application. It ensures the integrity of the data, which is uploaded to the blockchain without a central trusted authority. Ethereum private blockchain proposes two options for consensus protocols. Ethash, which is a Proof of Work-based protocol and Clique Proof-of-Authority consensus protocol. Moreover, in this work, we preferred to use Ethash to keep the platform decentralized, since PoA tends toward centralization by having a set of predefined validators. What is suggested is to use Ethash with a fixed difficulty and no mining rewards. All consumer nodes in the network are potential miners. All miner nodes would be having the same hashing power, thus, if a node attempts to tamper with the ledger, it would have to find new valid hashes for all the blocks preceding the blocks tampered with, and will be certainly leftover in the mining race. The only scenario where a node can successfully be fast enough to tamper with the already committed ledger is to use hardware having higher hashing power, which is supposedly not allowed, given that the nodes' hardware need to be certified. For that purpose, the proposed consensus algorithm for this architecture is that blocks are not accepted if the time difference between the last block mining time and the time of proposing a new valid block is less than a defined threshold. To define the threshold time, a PoW algorithm is developed in Java and run on a four (4) cores CPU: Intel(R) Core(TM) i5-9300H CPU @ 2.40 GHz and a GPU: NVIDIA GeForce GTX 1650 with Max-Q Design. The mining function is called in a loop for several iterations. In each iteration, the mining time is pushed in an array then the median of the set is deduced. \(M=M_{0},\ldots,M_{k}\) is the set of mining times where the mining function has been called for k times with a fixed difficulty and a random string of fixed size to be hashed. Threshold represents the minimum threshold time for accepting a new block. It is defined to be the median of the set \(M\). Threshold is computed for several sets \(M\) of different sizes. Threshold is picked when convergence is met, as illustrated in Table 3.  
According to Table 3, the deduced Threshold is 39 ms. To test the proposed mining protocol and assess its performance, it is executed on 10 different threads running  
Figure 11: State diagram. \begin{table}
\begin{tabular}{c c} \hline
**Set Size** & **Median of the Set [ms]** \\ \hline
50 & 69 \\
100 & 49 \\
150 & 39 \\
200 & 39 \\ \hline \end{tabular}
\end{table} 
Table 3: Threshold for different sizes of mining sets. concurrently on the same machine, as depicted in Figure 12. Each thread represents a miner. Fraudulent miners' nodes are represented by threads running mining protocol with less difficulty, to act as nodes having more hashing power. In the testing experiment, the certified miners are represented by threads mining with difficulty 5, whereas fraudulent miners are represented by threads mining with difficulty 4. The experiment consists of running the threads for 100 rounds corresponding to 100 blocks. The number of fraudulent miner nodes goes from a single node to 6 nodes representing more than 50% of the network. Threads with the shortest execution time in a round represent nodes successfully mining the new block for that particular round. If thread execution time is less than the accepted minimum threshold, its execution time is set to be Ththreshold. Miners for each round are defined according to the pseudocode of Algorithm 14. The obtained results showed that in each mining round there are always at least two successful miners, which corresponds to a fork situation. This is expected, since all miners are supposed to have the same hashing power.