# Blockchain Based Secure Routing and Trust Management in Wireless Sensor Networks +
## 5 Simulation Results
### Performance Metrics
#### 5.2.6 Detection Accuracy
The trust evaluation mechanism is performed by considering DT, FR and RT values, which are completely dependent upon the behavior of a node. Moreover, it is clear from the figure that the computational cost of the network increases as the trust  
Figure 4: (**a**) Number of dead nodes with rounds, (**b**) residual energy of the nodes. Figure 3: (**a**) FPR and FNR, (**b**) detection accuracy. evaluation increases with the increasing number of nodes. Figure 5b shows the amount of time that the RSA technique takes in the generation of public and private keys with respect to different key lengths. The time taken to generate a key of 1024 bits takes less time, that is, 0.81 s, while the generation of keys with 2048 bits and 4097 bits takes 2.20 s and 8.73 s, respectively. RSA with a large bit key size takes a lot of time in key generation and provides more security than other schemes. Moreover, there is a tradeoff between security and performance time, as, while achieving high security, time will be compromised. Figure 6 shows the trust values of different nodes that are calculated considering three performance metrics: DT, FR and RT. Different nodes have different trust values due to their performance in the network. The trust value of each node is compared with a predefined threshold and nodes with high trust values are considered legitimate nodes, otherwise they are considered malicious nodes. Moreover, the figure depicts the amount of energy consumed in the calculation of the trust value of different nodes in the network. The amounts of energy consumed for calculating DT, FR and RT are 0.00165 J, 0.0017 J and 0.00165 J, respectively. Furthermore, the amount of total energy consumed in the network increases when the number of nodes increases. After some time, the overall energy consumption of the network shows a gradual increase until it becomes almost constant. The blockchain based trust evaluation model of [19] uses the PoW consensus mechanism for validating transactions and adding blocks into the blockchain. On the other hand, we use both PoA and PoW in our proposed model. Figure 7a shows the comparison between PoA and PoW consensus mechanisms. The comparison is shown in terms of gas consumption. When any transaction is performed in Solidity, a fixed amount of gas is consumed against it. The unit of gas consumption in Solidity is Gwei and 1 \(Gwei\approx 0.00000001\)  
Figure 5: (**a**) Processing time of trust evaluation, (**b**) processing time of RSA encryption. other. Moreover, the cost of 1 Ethereum is approximately equal to USD 3825.16. It is shown in the figure that gas consumption of PoW is more compared to PoA. The reason is that PoW becomes computationally expensive due to the participation of all miner nodes in solving the complex mathematical puzzle. The node that solves the puzzle first is responsible for validating the transaction and adding the block into the blockchain. On the other hand, no puzzle solving is involved in PoA, because there are preselected validators that validate the transaction and add blocks into the blockchain. Although the PoW is costly in terms of monetary cost as compared to PoA, the PoW consensus mechanism is implemented on the public blockchain, which is connected with many other private blockchains and it is more likely to be attacked by the malicious nodes. Therefore, we have considered the PoW. In the case of a private blockchain, we use the PoA because the environment is private and only authenticated nodes exist. So, ultimately, there is a tradeoff between the cost and security. Moreover, Figure 7b shows the average transaction latency of both the PoW and PoA consensus mechanisms. PoA has low transaction latency as compared to PoW. In PoA, the miners are preselected nodes that do not perform mathematical puzzles, which consumes high computational power, as in the case of PoW. Figure 6: Energy consumption in trust evaluation of nodes. Figure 7: Cont.