# A Decentralized Blockchain-Based Trust Management Framework for Vehicular Ad Hoc Networks
## 2 Methods
### Block Generation and Validation  
The main objective of the proposed blockchain-based framework is to compute for each vehicle only one accurate and up-to-date trust metric that reflects its current behavior andis available to all the other vehicles in the network. Blockchain technology is a distributed ledger, it is exploited to record the trust metrics of the vehicles in it. Sharing the global trust metrics with all the vehicles in the network allows coping with the cold-start problem that arises when a new vehicle enters a new region without prior experience with the encountered vehicles. Consequently, it has to cooperate efficiently and for a long period to build a high trust metric. Unlike existing frameworks where the blocks are created continuously on every update of the local trust metrics [18,22], in the proposed BC-TMF the creation of the blocks is performed periodically every addBlockTimer period. The periodicity of the block generation has two main benefits. First, it allows the miners to collect more accurate trust metrics from the monitors because the more the monitor has a long experience with its neighbors, the more accurate the computed local trust metrics will be. Secondly, it economizes the computation resources of the miners upon the PoW calculation. More importantly, adding the blocks periodically to the Blockchain will reduce the number of blocks, consequently, it expedites the retrieve of the global trust metrics from the ledger.  
Each block consists of two compartments: the header and the body. The block header contains the block version that indicates the position of this block in the blockchain, the previous block's hash, Merkle tree root hash, which is a hash value of all the trust metrics included in the current block, the nonce used in the PoW, as well as the timestamp, which is the block generation time. Besides, the header contains difficulty metric D used to solve the Proof-of-Work [23]. The body contains the list of trust metrics of the vehicles aggregated as explained in the previous section. The structure of the block is shown in Figure 2.  
Since many miners may try to add their blocks at the same time to the blockchain, a technique to select which miner to add its block first must be expected. In Blockchain technology, the concept of PoW consensus is used to solve this problem [18]. The miner has to continuously hash the header of its block until getting a hash value H smaller than or equal to a threshold value named difficulty D: H \(\leq\) D, also D zeros must be padded in front of the hash. D is a hash threshold that can be tuned to control the difficulty of the PoW. The miner that solves the PoW first, adds its block first, to the blockchain. After the PoW computation, the miner signs the block using its private key and sends it to other miners. Other miners should validate the received block by checking if it fulfills the following condition H \(\leq\) D, also they check the signature of the miner originator of the block, if both conditions are fulfilled, the miners add the received block to their copies of the blockchain, also forward it to other vehicles in the network. Hereafter, every vehicle that receives an alert from a new vehicle can retrieve its global trust metric from the blockchain. The PoW Algorithm 1 is described below:  
Figure 2: The structure of the block.