# Secure Cognitive Radio Vehicular Ad Hoc Networks Using Blockchain Technology in Smart Cities
## 3 Proposed Scheme
The message is carried and forwarded to \(D\) by a relay within \(V\)'s communication range who is willing to participate in the network. We consider only two-hop communications in this scheme. We will extend it in the near future by considering both city and highway scenarios. In this network, it is crucial to have both relays and miners. Any node that is within the communication range of a sender can be considered a relay. Miners are the only authentic nodes that pay a fee to deliver messages to the destination and are all witnesses to incidents and validate the messages generated by the source. In order to join a blockchain network, the miner pays a fee and receives a reward from the destination upon honestly fulfilling its task. Miners are volunteers but relays are not. Miners can be a single node or more than one depending on who wants to receive a reward by paying a minimal amount from their account. Since the information (for example, roadblock) will be beneficial to \(D\), receiving that information will allow \(D\) to reroute its travel, which will save fuel and time. The rewards will be willingly given to those who aid \(D\) in providing this information. So, the complete path for communication is from source to miner to destination. The following is the general calculation of this path (\(P^{*}\)):  
\[P^{*}=max(PD_{p}). \tag{8}\]  
Figure 1: Secure CR-VANETs using blockchain. Calculating the path duration (\(PD\)) involves \(p=1,2,\ldots,P\) representing the number of paths between a source and a destination. \[PD_{p}=min(LD_{1,p},LD_{2,p},\ldots,LD_{h,p}), \tag{9}\]  
where \(h\) is the sum total of hops for each path between source and destination, and link duration (\(LD\)) measures how long two vehicles stay connected. \[LD_{ij}=\frac{r\pm d_{ij}}{\sqrt{(v_{i}\cos\theta_{i}-v_{j}\cos\theta_{j})^{2}+ (v_{i}\sin\theta_{i}-v_{j}\sin\theta_{j})^{2}}}\times\min(Ch_{1},Ch_{2},\ldots, Ch_{S}), \tag{10}\]  
where the communication range is defined by \(r\); \(d_{ij}\) refers to the distance between two moving vehicles, which is measured using Euclidean distance; the velocity is represented by \(v\); the angle relative to the destination is represented by \(\theta\); and the subchannel (\(S\)) with the highest belief among idle subchannels between vehicles \(i\) and \(j\) is identified as \(\min(Ch_{1},Ch_{2},\ldots,Cl_{S})\). The calculation of the \(Ch_{f^{*}}\) value for idle subchannel \(f^{*}(f^{*}=1,2,\ldots,S)\) between vehicles \(i\) and \(j\) is determined as \(Ch_{f^{*}}=1-min\left(b^{f^{*}}_{i,l_{c}}(H_{0}),b^{f^{*}}_{j,l_{c+r}}(H_{0})\right)\). The source vehicle selects the miner with the least \(LD\) among all the ones within the communication range. Therefore, after authentication, the best miner is calculated as  
\[min(LD_{1},LD_{2},\ldots,LD_{m}), \tag{11}\]  
where \(m\) represents miners. If a vehicle does not find a free subchannel but has a relay, it uses the store-carry-forward method until it reaches the location where the subchannel is available. Similarly, if a subchannel is available but there is no relay nearby, the vehicle again uses the store-carry-forward method until it reaches the relay. There is a slight increase in delay, which is acceptable because it is more advantageous to wait than to drop the packet. To put it briefly, PU has more coins in its wallet due to the free channel it offers to \(V\). \(V\) makes a message for \(D\) after confirming its authenticity from the RSU. A miner validates this message by paying some coins and forwarding it to \(D\). A miner is a node that has both sender and destination in its communication range. After receiving the message, the destination reads it, pays both the sender and miner as a token of appreciation and finally changes its route. To implement this system in the real world, vehicles need to have OBU to communicate with any RSU, along with digital currency accounts. Similarly, to communicate with vehicles, it is necessary to have a DSRC interface on every RSU.