# A Scalable and Trust-Value-Based Consensus Algorithm for Internet of Vehicles
## 5 Theoretical Analysis
### Attacks Discussion  
Next, we discuss the possible attacks on the consensus algorithm proposed in this paper, which include both internal and external attacks, and show how they are mitigated and defended against by our algorithm.  
Internal Attacks. An attacker may collude with nodes in the blockchain network or inject malicious nodes into the blockchain network in order to perform malicious acts and attack the consensus process from within the network.  
Internal attacks can be classified into two cases depending on the type and behavior of the node.  
1. The master node may be a malicious node. Malicious primary nodes intentionally generate divergent pre-prepared messages and transmit them to other nodes. In the PBFT's prepare and commit phases, nodes engage in voting amongst themselves. If the pre-prepared messages from the primary node are inconsistent, replica nodes can readily detect this discrepancy. Consequently, replica nodes will abandon the consensus proposed by the primary node and await the re-presentation of transactions by other nodes. Simultaneously, the credibility assessment mechanism and the view change protocol ensure that the malicious behavior of the primary node is curtailed within reasonable bounds.
2. The malicious nodes predict the master node in advance to carry out the attack. Our proposed consensus algorithm utilizes a committee election mechanism to randomly designate primary nodes. This approach ensures a certain degree of randomness while still maintaining the requirement that nodes meet the credibility threshold. This prevents the scenario wherein the node with the highest reputation consistently acts as the primary node, thereby thwarting malicious nodes from preemptively predicting the primary node. External attack. An attacker may maliciously attack the nodes in the blockchain network to make them behave maliciously and thus attack the consensus algorithm from the external network. This paper mainly includes the following cases: 1. The data is tampered and forged. The RSU nodes within the system employ techniques such as pseudonymous identification, hash algorithms, and digital signatures. To safeguard against data tampering, the blockchain system utilizes asymmetric encryption technology. As a result, nodes lacking the requisite private keys are incapable of forging the identities of other nodes or the signatures of their messages. The integration of blockchain technology and digital signatures substantially elevates the cost of successful impersonation by potential attackers, thereby reinforcing the overall system's reliability. 2. On-off attack by malicious nodes. The so-called On-off attack is when the attacker performs well for a period of time to enhance its reputation value, and when it accumulates to a high reputation value, it suddenly launches an attack until the reputation value is about to drop to a certain value, and then stops doing evil and becomes a normal node.  
Our CRMWSL reputation value calculation model can achieve high-precision reputation calculation. Due to the recommendation of other vehicles and the multi-weight calculation of nodes, the reputation value of evil nodes will drop sharply, and below the threshold value will be withdrawn from the committee to participate in consensus. Also according to different environments, the trust threshold can be increased appropriately, which will distinguish more abnormal nodes.