# Reputation-Driven Dynamic Node Consensus and Reliability Sharding Model in IoT Blockchain
## 3 System Model
#### 3.1.2 Master Node Election of RE-PBFT  
To solve the problem that the traditional PBFT master node rotation election may lead to malicious nodes becoming the master node, in the consensus network, nodes with high reputation are relatively more reliable and have a higher possibility of working normally. Therefore, the top 50% of nodes with reputation are selected as the master node preliminary interval. To increase the randomness, to prevent the occurrence of the same node becoming the primary node continuously, 60% of the nodes in the preliminary interval are selected as the master node interval by random probability, the master node is selected from the master node interval. The node that became the master node in the last round can only appear in the preliminary interval in the next round and cannot enter the master node interval again. To increase the randomness and unpredictability of principal nodes, we decided to select principal nodes through VRF (verifiable random function).  
Verifiable random function [40] is a pseudo-random function proposed by [PERSON] et al. in 1999. It consists of a key generation function, random number generation function, proof value generation function, and verification function.  
* Key generation function: RSA digital signature algorithm is used to generate a pair of public and private keys, the public key is PK, the private key is SK;
* The random number generating function: The random number \(\beta\) is obtained from the given input and the private key of the node through Equation (3), where _Vrf_hash_() is the hash function and \(\alpha\) is the input. \[\beta=Vrf\_hash(sk,\alpha)\] (3)
* Proof value-generating function: Prove \(\beta\) is the correct output of the input \(\alpha\). First, obtain the zero-knowledge proof result \(\pi\) of the input \(\alpha\) through Equation (4). Then, any node can obtain whether \(\beta\) is the correct output by taking \(\pi\) as the input of formula (4). \[\pi=Vrf\_prove(sk,\alpha)\] (4) \[\beta=Vrf\_prove\_to\_hash(\pi)\] (5)  
Figure 2: Reputation replacement based on smart contract.  
* Verification function: After Equation (5) proves that the output \(\beta\) is obtained from the input \(\alpha\), the result of Equation (6) is calculated, True means that the verification is passed, while False means that the verification is not passed. \[Vrf\_verify(pk,\alpha,\pi)\] (6)  
The proportion of reputation of each node in the master node interval is calculated by the Equation (7). m is the number of nodes in the master node interval, \(r_{i}\) is the reputation of node \(i\), and \(p_{i}\) is the proportion of reputation of a node \(i\) in the master node interval. The probability space of the master node can be obtained \(B_{i}=\left[\sum_{j=0}^{i-1}p_{j}\sum_{j=0}^{i}p_{j}\right)\) nodes.  
\[p_{i}=\frac{r_{i}}{\sum_{j=1}^{m}r_{j}} \tag{7}\]  
First, the public key PK and private key SK are generated. Then, given the random input seed number \(\alpha\), \(\beta_{i}\) is obtained by Equation (3). The result bits of the hash are consistent, \(\beta_{len}\) is the data length of \(\beta_{i}\). The zero-knowledge proof result is calculated by the Equation (4), and then the node sends the \(\beta_{i}\) and \(\pi\) obtained by local calculation to the other consensus nodes. After receiving the data from other consensus nodes, calculate Equation (5). If it is correct, calculate \(\beta_{i}/\beta_{len}\). Count the number falling in each \(\beta_{i}\) interval, and the one with the largest number will be the main node. Finally, Equation (6) is used to verify whether all the results are calculated \(\alpha\).