# Blockchain Based Secure Routing and Trust Management in Wireless Sensor Networks +
## 4 System Model  
We propose a secure routing mechanism in WSNs using a blockchain based encryption and trust evaluation model, motivated by [19; 44]. Some assumptions of this paper are as follows. * All the ANs, SNs and BSs have a particular Ethereum address. * All the BSs and ANs are legitimate. * There are no external factors and harsh network conditions that can affect the objective parameters: DT, FR and RT. This proposed model is an extension of our work in [45]. In the proposed blockchain based routing and trust evaluation mechanism, the encrypted information of routing and trust values is transferred from BSs to other nodes in the network. Moreover, all the transactions between nodes are validated through consensus mechanisms of blockchain. Whenever the SNs communicate with the ANs, the ANs authenticate and authorize the SNs and allow them to send packets to ANs. Furthermore, when ANs want to communicate with other ANs or BSs, the BSs authenticate the ANs. After the validation of nodes' identities, the transactions are added to the blockchain. The transaction data cannot be deleted from blockchain. When any malicious node manipulates the routing data or trust value, it is easily detected by utilizing the properties of the Merkle tree structure. The proposed model identifies the malicious nodes due to the traceability and transparency features of the blockchain. In this way, the blockchain provides secure routing and an efficient trust evaluation mechanism for malicious node detection. The proposed work uses an RSA technique to secure and reliably transmit data in the network, while in the work done in [45], enhancing the security of the transmission data is not considered. In the proposed model, initially, the data are sensed by the SNs and sent to the associated ANs. Afterwards, the ANs receive and forward the data to the nearest BSs. Two blockchains are used in our model to register and authenticate different nodes in the network. Ethereum is used for implementing the PoW and PoA consensus mechanisms by ropsen and rinkeby test networks. However, in the previous model of Bitcoin, a smart contract was not introduced. Ethereum introduces the smart contract that is a self-executing agreement that executes when predefined operations are met. A smart contract helps in eliminating the need for a third party and the associated risks. This is the reason that Ethereum is used for the blockchain in our proposed model. The public blockchain is deployed on the BSs that register and authenticate the ANs. Moreover, the BSs authenticate the communication between the ANs. The identities of the ANs are stored on the public blockchain, and they are allowed to join and access the private blockchain. Furthermore, ANs that are a part of the private blockchain perform the registration and authentication of the SNs, as shown in Figure 1.  
Private and public blockchains are used for authentication of SNs and ANs. Each SN can only be a part of one cluster network. Afterwards, the SNs broadcast the request message of registration (\(SN_{ID}\), \(AN_{ID}\) and \(BS_{ID}\)). The smart contract deployed for the SNs' registration process is triggered by the registration event in the private blockchain. Two types of blockchains are used in this model to minimize the workload of ANs. In the previous authentication scheme, the ANs are responsible for registering and authenticating other ANs [44], due to which they die in initial rounds. However, in our proposed model, ANs are registered and authenticated by BSs, which have high computational resources. In this way, the workload of ANs is reduced. Hence, both blockchains coexist to reduce the computational overhead of the proposed model. The identification of all nodes is uploaded on the public blockchain as the ANs are directly connected with the public blockchain. Furthermore, different features of the blockchain that make our model efficient are given below. * PoA consensus algorithm is used in the private blockchain for validation of transactions and adding the blocks into the blockchain.