Introduction
Crowdsourcing is an effective way to solve complex problems by outsourcing to a crowd of people [1]. In recent years, it has gained considerable attention in academia and adoption in the industry. A large number of companies are using crowdsourcing as a method to solve critical problems. Human intelligence-based crowdsourcing consists of service consumers, service providers, and a crowdsourcing platform, as shown in Figure 1.
Mechanical Turk [2], Upwork [3] and Uber [4] are some of the famous crowdsourcing platforms. In crowdsourcing, service consumers post tasks through a crowdsourcing platform that are hard to solve for computers but are comparatively easy for humans. In some platforms, such as Upwork, a service consumer needs to deposit the payment as an escrow amount to a crowdsourcing platform before a task begins. The interested service providers receive tasks through a crowdsourcing platform. They compete to solve and submit solutions of tasks to the crowdsourcing platform. The service consumers then select the appropriate solutions, and the corresponding service providers get the task payment.
Crowdsourcing has a wide range of applications in various security-critical systems, for example, disaster management systems [5], traffic monitoring systems [6], and healthcare systems [7]. With the rapid development of crowdsourcing applications, the limitations of traditional crowdsourcing systems are exposed. Firstly, the traditional crowdsourcing systems are based on centralized servers, which can suffer from a single point of failure [8]. Secondly, in case of a dispute between service providers and consumers, issues of free riding and false reporting can occur due to a lack of accountability and effective trust management [9]. In free riding, service providers try to get rewards without providing satisfactory solutions, and in false reporting, service consumers intentionally get useful solutions without losing the deposit. Thirdly, crowdsourcing systems are vulnerable to various security attacks, such as sybil, distributed denial of service (DDoS), and hijacking attacks [10]. Fourthly, sensitive information of users is at risk of privacy disclosure during the process of task assignment [11]. Lastly, there is minimal work on the formal verification of crowdsourcing systems to ensure the correctness, consistency, and completeness of the algorithms and protocols [12]. The advent of blockchain technology [13] brings high hopes to overcome most of the drawbacks in traditional crowdsourcing systems. A consensus protocol is the most critical component of blockchain which can establish mutual trust among crowdsourcing participants in a decentralized way. Therefore, crowdsourcing issues are solved using blockchain consensus algorithms.
A. Motivation for a New Consensus Protocol
Most of the existing generic blockchain consensus protocols have certain limitations. For example, Proof of Work (PoW) is highly resource-intensive and difficult to apply for large-scale online systems [13]. Employing Proof of Stake (PoS) in crowdsourcing systems may compromise the rights of nodes [14] as it suffers from security, fairness, and centralization issues. Delegated Proof of Stake (DPoS) handles the fairness issue by democratic voting, but still, it has some degree of centralization [15]. Moreover, employing DPoS cannot avoid collusion among stakeholders. Therefore, an application-specific blockchain consensus protocol is highly desirable, considering the peculiarities of crowdsourcing systems [16], [17]. To address the security and trust challenges, some recent studies [18]–[20] have proposed blockchain-based consensus protocols for crowdsourcing applications that also strive to handle accountability, credible crowdsourcing, free riding, and false reporting, and compelling trust management issues. These studies were the prime motivation behind this work.
Several drawbacks are identified in the existing blockcha-in-based crowdsourcing consensus protocols. For example, Proof of Trust (PoT) elects a leader from ledger nodes using Reliable-Replicated-Redundant And Fault-Tolerant (RAFT) and validators from crowdsourcing service participants based on trust values [18]. However, PoT analyzes some of the security attacks, including sybil, DDoS, and collusion through simulations, and theoretically describes a few of the security properties. An improved PoT is a reputation-based protocol in which a high reputation worker is selected as a miner of the block, and verification nodes are also selected based on reputation [19]. However, the reputation calculation is based on the historical interaction of a miner and feedback of other nodes that may not be reliable. It is based on simulation techniques and analyzes collusion attacks. Mobile Crowdsourcing (MCS) chain is based on the total payment for block generation which informally analyzes security properties [20]. The consensus protocol of zkCrowd is based on DPoS and Practical Byzantine Fault Tolerance (PBFT) and is validated using simulation techniques, which favors voters having more tokens [21]. The RAFT and PBFT used in the existing blockchain-based crow-dsourcing consensus protocols are formally verified [22]–[24], therefore, PoT and zkCrowd are partially verified. The existing blockchain-based crowdsourcing consensus protocols discussed-above employ simulation techniques that do not assure the models’ correctness as simulations are performed on limited data set.
B. Challenges
The weaknesses of the existing blockchain-based crowdsourcing consensus protocols present the following challenges.
How to design a secure and trustworthy consensus protocol that applies to crowdsourcing services?
How to prevent security attacks, such as blockchain fork, invalid block insertion, and selfish mining?
How to select trusted leader and validators to prevent their malicious behaviors?
How to ensure the correctness of the blockchain-based crowdsourcing consensus protocol?
C. Contributions
This research work aims to present a formally verified Secure and Trustworthy Blockchain-based Cr-owdsourcing (STBC) consensus protocol to deal with the above-discussed challenges. The consensus protocol is nam-ed as STBC because we have defined the security properties of the protocol and trustworthy selection process of a leader and validators based on trust factors. The peculiarities of the STBC consensus protocol are:
It records the activities of service providers and consumers, e.g., post, receive, and perform tasks as transactions, and the transactions that gain maximum votes are included in the proposed block.
The service consumers have to escrow deposit when they post a task, and the service providers get their share from the escrowed deposit after the successful completion of a task. When the service providers and consumers perform activities, their activity rate is incremented.
It selects a trusted leader from blockchain management nodes to propose a block and trusted validators from blockchain management nodes, crowdsourcing service providers, and consumers to validate and vote for the transactions and the block. The trusted leader and validators have to escrow deposit to prevent malicious behaviors.
Unlike the existing consensus protocols of blockchain-based crowdsourcing [18]–[21], the selection criteria of a leader and the validators are different. While the leader is selected based on three trust factors (i.e., deposit ratio, activity rate, missed rate), the validators are chosen based on deposit ratio and activity rate.
The STBC consensus protocol prevents blockchain fork, selfish mining, and invalid block insertion attacks. In STBC consensus protocol, at most one block is proposed in every round, which avoids the possibility of a blockchain fork. If multiple nodes propose a block simultaneously, then blockchain can fork. A single leader is selected to propose a block in each round of consensus to prevent this situation. A successfully generated block that is accepted by a majority of the validators is only added in the blockchain. In this way, all the nodes record the same block, which ensures the absence of a fork. Moreover, only the block of a trusted leader is added to the blockchain which prevents selfish mining attack. If a leader acts maliciously to add an invalid block, the consensus protocol resists it by adding no block.
The guarantee of correctness of any system is essential, especially critical and real-time systems. As a crowdsourcing system involves several critical tasks, therefore its correctness has vital importance. Formal methods are rigorous mathematical techniques to model computer systems that help designers verify the system’s properties and assist in system testing to increase the confidence of correctness of a system. Model checking is an important formal methods-based technique used for the formal verification of critical systems. It is automatic, effective, and requires less human intervention. Therefore, it is utilized in this work.
The main contributions of this work are summarized below:
Security: The proposed consensus protocol provides security by defining security properties, i.e., safety and fault tolerance to prevent blockchain fork and selfish mining attacks. It is secure when at most
nodes are faulty. Here n denotes the total number of nodes. This ratio is assumed similar to most of the byzantine fault tolerance (BFT) consensus protocols.$\left \lfloor{ \frac {n-1}{3}}\right \rfloor $ Trustworthy: We presented an improved trust model based on several new factors such as deposit ratio, activity rate, and missed rate. The leader and validators’ trust properties are defined to prevent blockchain fork, selfish mining, and invalid block insertion attacks.
Fairness: The proposed consensus protocol provides a fair environment for the selection of leaders and validators. The activity rate is included to prevent rich nodes dominating the network. The introduction of missed rate of a node will increase its chances to be selected as a leader. The trust values update mechanism enforces nodes to obey protocol rules; because in the case of malicious activity, in addition to trust values, they also lose their deposit as a punishment.
Energy-saving: The protocol saves energy as a single leader is supposed to propose a block in every round.
Correctness: The correctness of the proposed consensus protocol is ensured utilizing a formal methods-based technique, i.e., model checking. The formal specification of the proposed STBC protocol is performed using CSP#. Furthermore, the PAT model checker is applied for the formal verification of safety, fault tolerance, leader trust, and validators’ trust properties. Linear Temporal Logic (LTL) is utilized to specify the security and trust properties.
The rest of the paper is organized as follows: Section II establishes the background knowledge; Section III discusses the related work; Section IV presents the system model; Section V defines the formal model of the proposed protocol; Section VI describes the results; and finally Section VII presents the conclusion and future work.
Background
This section provides background knowledge about blockchain and formal modeling and verification.
A. Blockchain Technology
Blockchain technology was introduced by an unknown person Satoshi Nakamoto, as a distributed, peer-to-peer, decentralized, and a linked structure to address the issue of double-spending [13]. Figure 2 represents an example of blockchain. The transactions are grouped and ordered in a structure called a block. In addition to transactions, a block contains its hash and the previous block hash. The variable Prev. Block Hash in the current block in Figure 2 is used to link the block to its previous block which prevents alteration of blocks and insertion of a block between existing blocks. The miners are responsible for adding the blocks in chronological order. In the blockchain, any node can initiate a transaction and broadcast it to the nodes of the network. The network nodes validate transactions and the miner of the block adds the validated transactions to the blockchain. The number of transactions in a block depends upon the size of a block.
Blockchain have applications in various fields, for example, healthcare [29], banking sector [30], insurance companies [31], and crowdsourcing [32]. In this work blockchain is exploited for crowdsourcing systems, as it helps to provide accountability, transparency, and immutability to avoid unfaithful and dishonest behaviors.
B. Formal Modeling and Verification
Formal modeling and verification of consensus protocols is important to ensure their correctness. Model checking is the formal methods-based technique that is effectively used for formal verification. Model checking involves verifying whether a formal model of the system satisfies the desired properties. Model checking technique is useful to reveal the errors that cannot be identified using testing and simulation techniques. In this work, we use the model checking technique because in comparison to other techniques, e.g., theorem proving, it is more effective, automatic, and needs less human involvement. Model checking technique is useful to check partial specifications. However, the state explosion problem is a big limitation of the model checking approach [33], as the state of the model grows infinitely large with the increase of variables, distinct values, and components.
CSP# is a formal specification language used for the formal modeling of concurrent aspects of critical systems. The high-level modeling constructs such as sequential/parallel composition, channels, and interleaving are combined with low-level C# constructs, e.g., variables, if-then-else, and arrays. The syntax of CSP# can be described as:\begin{align*} \begin{array}{lll}&~~ {Proc} ::= \mathrm {SKIP} & ~\,\!~\hspace {-0.4em} (\text {termination}) \\ & | \mathrm {STOP} & (\text {deadlock}) \\ & | ev \{program\} \rightarrow {Proc} & (\text {operation prefixing})\\ & | ev \rightarrow {Proc} & (\text {event prefixing})\\ & | [\,guard]\, {Proc} & (\text {state guard}) \\ & | {Proc_{1}} \;\vert \vert \; {Proc_{2}} & (\text {parallel composition}) \\ & | {Proc_{1}} \;\vert \vert \vert \; {Proc_{2}} & (\text {interleaving}) \\ & | {Proc_{1}}; {Proc_{2}} & (\text {sequential} \; \text {composition})\\ & | ch ? a \rightarrow {Proc(a)} & (\text {channel input})\\ & | ch ! a \rightarrow {Proc} & (\text {channel output})\\ & | {Proc_{1}} \;\Box \; {Proc_{2}} & (\text {external} \; \text {choice})\\ & | {Proc_{1}} \;\sqcap \; {Proc_{2}} & (\text {internal} \; \text {choice})\\ & | \mathrm {if} \; guard \; \mathrm {then} \; {Proc_{1}}\; \mathrm {else}\; Proc_{2} & (\text {boolean} \; \text {statement})\\ & | {Proc_{1}} \;\triangleright \; {Proc_{2}} & (\text {timeout})\\ & | {Proc_{1}} \;\triangle \; {Proc_{2}} & (\text {interrupt}) \end{array}\end{align*}
Assertions are used to query properties about the behavior of a system. Various types of assertions are supported in PAT, such as, deadlock-freeness, divergence-free, nonterminating, reachability and LTL. Deadlock-freeness and LTL assertions are used in this work.
C. Deadlock-Freeness
This assertion checks whether a process Proc is deadlock-free or not.
#assert Proc() deadlockfree;
D. Linear Temporal Logic (LTL)
LTL is used to specify properties to be checked on a formal model. LTL extends predicate or propositional logic by modalities and provide a way to mathematically represent linear time properties. PAT supports the full syntax of LTL. For a process Proc(), the below assertion checks whether Proc() satisfies the LTL formula
#assert Proc()
The syntax of LTL is defined according to following rules:\begin{equation*} \phi = ev\, |\, prop\, |\, \phi _{1} \, \land \, \phi _{2} |\, \neg \, \phi | \, \Box \, \phi |\, \lozenge \, \phi |\, \bigcirc \, \phi |\, \phi _{1}\, \cup \, \phi _{2}\end{equation*}
Related Work
In this section, firstly blockchain consensus protocols are described, then blockchain-based crowdsourcing consensus protocols are discussed and crowdsourcing systems based on blockchain are described in the end.
A. Blockchain Consensus Protocols
Some important blockchain consensus protocols are briefly described here. PoW is the first consensus algorithm that is used in Bitcoin [13]. It is based on complicated computation where every node of the network continuously computes a hash value of every block header using different nonce values until the calculated hash value becomes less than or equal to a certain target value. When a node gets the desired value, other nodes of the network verifies its correctness, and the block is added to the blockchain. However, it is highly resource-intensive and has low throughput.
PoS is an alternative to PoW that requires much less energy to be consumed [14]. In this mechanism, a node is selected based on its stake to propose a block. However, it favors rich nodes in the network. In this way, centralization can occur in the network. Several solutions are proposed to address this issue. For example, Peercoin [34] uses coin age selection procedure, Blackcoin [35] is based on randomization and Bitshares [36] uses Delegated Proof of Stake (DPoS) [15] in which stakeholders select delegates based on voting for the generation and validation of a block, however, it has some degree of centralization.
PBFT is proposed for tolerating byzantine faults [37]. It can tolerate 1/3 byzantine faults. The consensus is divided into three phases, i.e., pre-prepare, prepared, and commit. A node can transit from one phase to another phase after getting 2/3 votes from other nodes. Tendermint is another BFT consensus protocol [38]. However, the BFT protocols are suitable for small networks and have poor scalability. The survey of several other blockchain consensus protocols is provided in [39].
B. Blockchain-Based Crowdsourcing Consensus Protocols
Recently, the integration of blockchain technology and crow-dsourcing has gained the attention of the research community. PoT is a consensus protocol built upon the idea of blockchain technology to handle the accountability issue in crowdsourcing services [18]. The protocol utilizes RAFT [22] to elect a leader from ledger nodes and selects service participants as validators of transactions based on trust values. The PoT protocol addresses the issue of scalability associated with BFT and Paxos-based algorithms. It considers the unfaithful behavior of nodes that is not addressed in BFT algorithms. The security attacks, including, sybil, collusion, and DDoS are analyzed in the work. As RAFT is formally verified through TLA proof system and Coq proof assistant [22], [23], therefore, PoT is defined as partially verified in Table 1. However, PoT cannot preserve privacy of users. An improved PoT consensus algorithm is presented for crowdsourcing using blockchain as an underlying technology [19]. In this protocol, a high reputation worker is selected as a miner of the block. The calculation of reputation is based on the historical interaction of a miner and feedback of other nodes which may not be reliable. It analyzes the collusion attacks and does not provide a mechanism to evaluate task solutions. Further, privacy and reliability are also not addressed in this work.
MCS-Chain is presented as a blockchain-based mobile crowdsourcing platform for decentralized and distributed tr-ust management [20]. The trust evaluation mechanism is defined which allows users to select reliable workers. A consensus protocol is presented in MCS-Chain for block generation to improve the efficiency of the blockchain. In the protocol, a new block is created when the total payment which needs to be recorded into the next block exceeds the defined threshold. The centralization and fork issues are addressed in the work which guarantee that even if several blocks are generated simultaneously, a unique block is added to the blockchain. The liveness, safety, fault tolerance, and decentralization are demonstrated theoretically but the system lacks in privacy and anonymity of users and workers.
The zkCrowd, a hybrid blockchain-based crowdsourcing platform is proposed to balance transaction transparency and privacy [21]. The zkCrowd consists of a public chain to manage public tasks and multiple subchains to handle private tasks. DPoS is implemented on the public blockchain to elect validators. The alternative validators which are not elected in the public chain are elected as subchain validators in a round-robin manner using PBFT on private subchains. The zkCrowd is resilient against a 51% attack, sybil attack, privacy leakage, free riding and false reporting, and byzantine failures. As continuous-time Markov chain models are defined for PBFT and are formally verified through PRISM model checker [24], therefore, zkCrowd is termed as partially verified in Table 1. However, zkCrowd lacks in defining cross-communication between public and private chains, privacy protection of answers, and a proper reward distribution mechanism. On the public chain, voters having more tokens have more influence on the network. Further, if there are a large number of private tasks then an issue of scalability can occur. The comparison of the above-discussed consensus protocols is provided in Table 1. Unlike [18]–[21], the proposed protocol is formally verified.
C. Blockchain-Based Crowdsourcing Systems
1) Trust Management
MCS-Chain+ is presented to address the issue of privacy in MCS-Chain [40]. The Intel Software Guard Extension (SGX) is utilized to anonymously authenticate trust through a trustworthy evaluation of trust. RC-chain is a reputation-based framework that is proposed as a crowdsourcing blockchain to support crowdsourcing trading and evaluation of user-reputation [41]. CrowdR-FBC is presented as a distribu-ted fog-blockchain mechanism for reputation management in crowdsourcing which prevents leakage of users’ privacy, involvement of malicious users, and tampering of users’ reputation [42]. It ensures the selection of trusted workers and the reliability of data. Blockchain technology is utilized to present a trusted and decentralized approach for a crowdsourcing system [43]. The proposed mechanism enables information of users and several behaviors to be transparent and cannot maintain the privacy of user’s information. A blockchain-based trust model using weighted consensus technique to share information in crowd environments is presented to achieve higher accuracy [44].
2) Task Management
CrowdBC is a blockchain-based decentralized framework for solving tasks of requesters by a crowd of workers without any trusted third party [32]. It protects the privacy of users as it utilizes pseudonymous addresses for the identities of requesters and workers, and stores encrypted solutions in distributed storage. However, defining an efficient evaluation function for tasks solution is crucial in CrowdBC. ZebraLancer is another platform that protects user privacy, but it depends on a trusted third party for registration of identities [47]. A novel hybrid blockchain-based crowdsourcing platform is proposed to ensure decentralization and privacy [45]. The platform consists of a hybrid structure of blockchain and dual consensus protocols to ensure secure communication among requesters and workers. Zero-knowl-edge proofs are used to protect the privacy of users whereas the access control model is not defined in detail. FedCrowd platform is proposed as a privacy-preserving and federated platform for blockchain-based crowdsourcing [48]. The sma-rt contracts are employed as a trusted platform to publish encrypted tasks and craft matching protocols are designed for task recommendation in an efficient way. But it depends on a trusted third party for the management of public and private keys. PFcrowd platform is presented to allow crowdsourcing systems to perform encrypted task-worker matching on the blockchain without any third party [49].
Blockchain-powered crowdsourcing model for the mobile environment is proposed to address several challenges such as, participants privacy, the integrity of services, and improving quality of experience [50]. A blockchain-based task matching (BPTM) model for crowdsourcing for reliable and secure matching is proposed using smart contracts [51]. Confidentiality and identity anonymity are achieved using searchable encryption. An auction-blockchain-based crowdsourcing technique, ABCrowd is presented to execute crowdsourcing on Ethereum blockchain including auctions [52]. It utilizes repeated bidders auction technique which allows truthful bidding. However, it lacks to protect user privacy. Task Select Worker Crowd (TSWCrowd) is presented to address the issues of reliable tasks allocation, ensuring workers’ payments and reliability of the platform [53]. The task-select-worker mechanism is defined to sort the tasks and the tasks having higher priority are assigned first. In contrast to ABCrowd, the average workers’ payment in TSW-Crowd is higher. ConGradetect is presented as a blockchain-based crowdsourcing detection system that addresses code and identity privacy but it analyzes simple codes [54].
Blockchain-based crowdsourcing is used for reliable data analysis in Mobile Ad-hoc Cloud (MAC) [55]. It addresses the challenges of attracting mobile devices to join the MAC network and able to collect reliable computation from mobile devices. A resilient-improved two-stage auction (ITA) is presented for fault tolerance in mobile crowdsourcing [56]. The proposed technique is beneficial for organizations as the workers are selected according to the time and budget of organizations. The designs for crowdsourced energy systems using blockchain technology are presented in [57], [58] to crowdsource small-scale production or trading of energy from distributed resources of energy. To handle the issues of crowdsourcing data access, analysis, and management, a framework based on blockchain technology is proposed [46]. The framework helps researchers in accessing operational data ensuring confidentiality, traceability, and accountability of data, and disseminating data in a controlled way to the public, but it lacks scalability.
3) Dispute Arbitration
A blockchain-based scheme for fine-grained authorization in data crowdsourcing (BC-FGA-DCrowd) is proposed in [59]. The scheme resists internal malicious actions and external sybil and DDoS attacks. The feasibility of the scheme is tested on the Ethereum network, however, it lacks in defining a proper function for evaluating the quality of data. A decentralized oracle-based game is proposed to decide the truth of queries and to resolve disputes [60]. In crowdsourcing, the quality of completed tasks and fairness in the evaluation of tasks are addressed using blockchain technology [61]. An arbitration mechanism is described for the realization of business services and to avoid security attacks, e.g., false reporting and free-riding but it lacks privacy analysis.
The comparison of the discussed research work in terms of security and trust is provided in Table 2. It is observed in the literature that there are very few blockchain-based crowdsourcing consensus protocols and some of these are partially verified [18], [21]. To the best of our knowledge, this is the first work which utilizes CSP# for the formal specification of a blockchain-based crowdsourcing consensus protocol and the PAT model checker for the verification of security and trust properties.
System Model and Consensus Protocol
This section describes the architecture of the system, design of the consensus protocol, security properties, and associated attacks. In the end, a threat model with attacks and defenses is presented.
A. System Architecture
The architecture of the blockchain-based crowdsourcing system (BBCS) is represented in Figure 3. It consists of four actors: service consumer, service provider, blockchain management nodes, and validator nodes. The service consumers request for services by posting a task to the crowdsourcing platform. A service consumer can check the status of a task by sending a query to the blockchain. Service providers provide services by receiving a task through a crowdsourcing platform. A service provider can send a query to the blockchain to get information about the task payment. The blockchain management nodes are responsible for managing blockchain, e.g., proposing and validating blocks. In every round of consensus, a trusted leader is elected from the blockchain management nodes to propose and add a block to the blockchain. The validators validate and vote for transactions and blocks. The blockchain management nodes, service consumers, and providers can serve as validators.
B. Design of Consensus Protocol
1) Crowdsourcing Consensus Protocol
The overview of the proposed STBC consensus protocol is presented in Figure 4. The consensus process starts with the initialization of nodes that can perform the transactions. The blockchain management node having the highest trust value is selected as a leader for the current round. The trust is calculated based on deposit ratio, activity rate, and missed rate.The trusted validators are selected from blockchain management nodes, crowdsourcing service providers, and consumers to validate and vote for the transactions and the block to avoid malicious behaviors. The validator’s trust is calculated based on deposit ratio and activity rate. The process of selection of leader and validators runs in parallel to save time. After the process of selection, the trusted validators vote for transactions and broadcast votes. The leader prepares the block by including the transactions that gain the majority of the votes from validators. The leader then broadcasts the block to the validators and they vote for the block. If the majority of the validators accept the block then the leader adds the block in the blockchain and all the nodes update their ledger. The trust values and deposit of leader and validators are updated and the consensus process enters into the next round. If the block is rejected, then the leader and validators lose the trust and deposit, and the consensus protocol moves to the next round.
2) Calculation of Trust of a Leader
The trust factors of management nodes for the selection of a leader are defined as:
Deposit ratio of a management node: The deposit that a management node
Activity rate of a management node: Let
Missed rate of a management node: Let
A leader for block generation is selected from management nodes based on the above trust factors.
Trust of a leader: The trust of a leader
3) Calculation of Trust of Validators
The trust factors to define a criteria for the selection of validators are described below.
Deposit ratio of a validator node: The deposit that a validator node
Activity rate of a validator node: Let
Trust of a validator: The trust of a validator
4) Algorithm
The high-level pseudocode of STBC consensus protocol is described in Algorithm 1. It takes management
Algorithm 1: High level pseudocode of STBC consensus protocol
STBC(M, C, P, V)
Nodes_Initialization(M, C, P, V)
Perform_Transactions(C, P)
Selection() = Leader_Selection(M)
Validators_Selection(V, K)
VTransactions
Validators)
Propose(Block(index, TLeader, prevHash, hash,
Tmax(VTransactions)))
Broadcast(Block, TValidators)
Vote(Block, TValidators)
if (Accept(Block, Majority) == true)
Blockchain
UpdateTrustAndDeposit()
else
Discard(Block)
LoseTrustAndDeposit()
Next_Round()
The high level pseudocode of
Algorithm 2: Pseudocode of nodes intialization
Nodes_Initialization(M, C, P, V)
for i
if(
M = M
V = V
for c
if(
&&
C = C
V = V
for
if(
&&
P = P
V = V
Algorithm 3 defines the types of transactions that can occur in a crowdsourcing system. A consumer
Algorithm 3: Pseudocode of performing transactions
Perform_Transactions(C, P)
PostTask(c)
Escrow(d_c)
c.UpdateNumActivities(1)
ReceiveTask(p)
PerformTask(p)
EvaluateTask(c)
if (AcceptTask(c) == true)
treward
TaskReward(p, treward)
p.UpdateNumActivities(1)
else
RejectTask(c)
pdeposit
DepositReturned(pdeposit)
Algorithm 4 describes the procedure of leader selection (line 1). Initially, the first management node
Algorithm 4: Pseudocode of leader selection
Leader_Selection(M)
let TLeader
x = 1
while (x < len
if (
else if (
TLeader
else if (
if (Hash(TLeader.GetMId(),
Hash(
TLeader
else
Escrow(
Algorithm 5 presents the process of selection of
Algorithm 5: Pseudocode of validators selection
Validators_Selection(V, K)
len(TValidators) =0
while (a < len V −1 &&
len(TValidators)
while (b < len V &&
if (
else
Swap(
TValidators
Escrow(
The update trust process is described in Algorithm 6. When the leader’s block is accepted by the network, then its number of activities
Algorithm 6: Pseudocode of updating trust and deposit
UpdateTrustAndDeposit()
greward
BlockGReward(greward)
DepositReturned(RemoveEscrow(
vreward
BlockVReward(TValidators, vreward)
DepositReturned(RemoveEscrow(
C. Properties and Attacks
In this work, we have defined security and trust properties, i.e., safety, fault tolerance, trusted leader, and trusted validators to prevent security attacks, such as blockchain fork, selfish mining, and invalid block insertion. The properties and attacks are defined below.
Definition 1 (Safety):
The consensus protocol is safe if all the nodes of network eventually reach the same decision.
Definition 2 (Fault Tolerance):
The consensus protocol is fault tolerant if all the honest nodes eventually accept the same block even in the presence of malicious nodes.
Definition 3 (Trusted Leader):
In every round of consensus protocol, a management node having the highest trust value is selected eventually.
Definition 4 (Trusted Validators):
In every round of consensus protocol, validator nodes that have the highest trust values are eventually selected.
Definition 5 (Blockchain Fork):
It represents a state of the blockchain in which nodes have different views about the blockchain state. The network nodes may receive more than one block at the same time.
Definition 6 (Selfish Mining):
Miners secretly mine blocks to earn rewards. The selfish miners release the blocks to the public when they get a longer chain.
Definition 7 (Invalid Block Insertion):
The blocks that disobey network rules are known as invalid blocks. A malicious leader tries to add invalid blocks in the blockchain.
D. Threat Model
To introduce an effective attack against the STBC consensus protocol, an attacker needs to compromise more than 1/3 of network nodes. A malicious leader and a validator can pose several threats which can affect the working of the consensus process. If there are multiple nodes mining at the same time then blockchain can fork, therefore, in the proposed consensus protocol, a unique leader is selected in every round to propose a block to prevent blockchain fork. Malicious nodes may try to mine blocks secretly and broadcast to the network nodes. To avoid this situation, it is ensured that only the trusted leader can execute the block propose and broadcast process and all the nodes add the block of a trusted leader in their ledger in each round. A malicious leader may try to add an invalid block in the blockchain, but the consensus protocol prevents its addition by adding no block. The deposit of a leader is stored in the blockchain to avoid malicious behavior. If a leader remains honest then the escrowed deposit is returned, otherwise, the deposit is slashed away. Moreover, it also loses its trust and it becomes very difficult for the malicious leader to become the leader again. This incentivises the leader to behave honestly.
Malicious validators may refuse to vote for transactions or blocks to prevent the addition of the correct blocks. This situation can occur only if more than 1/3 of the validators are malicious. To avoid this situation, the selected validators must also submit a deposit to the blockchain. If the correct block cannot be added to blockchain due to malicious validators then the validators not only lose the trust but also the escrowed deposit which incentivises validators to behave honestly. Further, it becomes difficult for these nodes to become trusted validators again. Further, if the consensus process is localized among some fixed nodes then it can lead to centralization. Therefore, the trust model for the selection of a leader and validators is designed in such a way that it prevents centralization. For the selection of a trusted leader and validators, activity rate is utilized in addition to deposit ratio to restrict rich nodes from dominating the network. Missed rate is also introduced in the selection of a leader so that the nodes waiting to become leaders also get a chance. This ensures fairness and decentralization in the protocol.
Formal Specification of Consensus Protocol
This section presents the formal model of the STBC consensus protocol using CSP#. In the formal model, the structure of blocks and the blockchain is defined at an abstract level and our main focus is to model the communication among nodes to achieve the consensus.
A. Consensus Protocol
The consensus protocol is defined as a process (line 3) which involves four nodes represented as
;$\#define\,\,PNodes\,\,4$ $\#define\,\,T\,\,2;$ $\begin{aligned} Consensus\_{}\,\,Protocol()=\\ \hspace {-1.5em}\qquad \quad (\parallel \,\,i:\{0..PNodes-1\}\text{@}\\ \hspace {-1.5em}\qquad \quad (NodeInitialization();\,\,PerformTransactions();\\ \hspace {-1.5em}\qquad \quad \,\,Selection();\,\,VoteForTransactions(T,\,\,i);\\ \hspace {-1.5em}\qquad \quad \,\,ProposeAndBroadcast(i);\,\,VoteToBlock(i);\\ \hspace {-1.5em}\qquad \quad \,\,isValidBlockchain();\,\,AddBlock(i);\\ \hspace {-1.5em}\qquad \quad \,\,UpdateTrustAndDeposit()));\\ \hspace {-1.5em}\qquad \quad NextRound(); \end{aligned}$
B. Nodes Initialization
Firstly, the nodes are initialized having unique identifiers, with sufficient deposit, number of activities, and number of misses (line 4). There are three types of nodes, i.e., management nodes, provider nodes, and consumer nodes. All these nodes can serve as validator nodes.
$\begin{aligned} NodeInitialization()=(MngNode1(0,\,\,20,\,\,0,\,\,0);\\ \quad \,\,\,\,MngNode2(1,\,\,30,\,\,0,\,\,0);\,\,ProvNode1(2,\,\,15,\,\,0);\\ \quad \,\,\,\,ProvNode2(3,\,\,20,\,\,0);\,\,ConsNode1(4,\,\,10,\,\,0);\\ \quad \,\,\,\,ConsNode2(5,\,\,30,\,\,0);\,\,ConsNode3(6,\,\,20,\,\,0)); \end{aligned}$
$MngNode1(id,\,\,deposit,\,\,numActivities,\,\,numMisses)=$ $\begin{aligned} [id\,\,>=\,\,0\,\,\&\&\,\,deposit\,\,>=\,\,minDeposit\,\,\&\&\\ \hspace {-1.5em}\qquad \qquad \,\,\,\,deposit\,\, < =\,\,maxDeposit\,\,\&\&\\ \hspace {-1.5em}\qquad \qquad \,\,\,\,numActivities\,\,>=\,\,minNumActivities\,\,\,\,\&\&\\ \hspace {-1.5em}\qquad \qquad \,\,\,\,numActivities\,\, < =\,\,maxNumActivities\,\,\&\&\\ \hspace {-1.5em}\qquad \qquad \,\,\,\,numMisses\,\,>=\,\,minNumMisses\,\,\&\&\\ \hspace {-1.5em}\qquad \qquad \,\,\,\,numMisses\,\, < =\,\,maxNumMisses] \end{aligned}$ $\begin{aligned} add1\,\,\{var\,\,m1=new\,\,ManagementNode(id,\,\,deposit,\,\,\\ \hspace {-1.5em}\qquad \qquad \quad \,\,\,\,numActivities,\,\,numMisses);\\ \hspace {-1.5em}\qquad \qquad \quad \,\,\,\,managementNodes.Add(m1);\\ \hspace {-1.5em}\qquad \qquad \,\,\,\,validatorNodes.AddNode(new\,\,ValidatorNode(id,\,\,\\ \hspace {-1.5em}\qquad \qquad \,\,\,\,deposit,\,\,numActivities,\,\,numMisses,\,\,m1)); \}\,\, \rightarrow \,\,Skip; \end{aligned}$ $MngNode2(id,\,\,deposit,\,\,numActivities,\,\,numMisses)\,\,\!=\! \ldots $
$ProvNode1(id,\,\,deposit,\,\,numActivities)=$ $\begin{aligned} [id\,\,>=\,\,0\,\,\&\&\,\,deposit\,\,>=\,\,minDeposit\,\,\&\&\,\,\\ \,\,deposit\,\, < =\,\,maxDeposit\,\,\&\&\,\,\\ \,\,numActivities\,\,>=\,\,minNumActivities\,\,\\ \,\,\&\&\,\,numActivities\,\, < =\,\,maxNumActivities] \end{aligned}$ $\begin{aligned} add3\,\,\{\,\,var\,\,v1=new\,\,ProviderNode(id,\,\,deposit,\,\,\\ \,\,numActivities);\,\,providerNodes.Add(v1);\\ \,\,validatorNodes.AddNode(new\,\,ValidatorNode(id, \\ \,\,deposit,\,\,numActivities,\,\,v1));\,\,\}\,\,\rightarrow \,\,Skip; \end{aligned}$ $ProvNode2(id,\,\,deposit,\,\,numActivities)\,\,= \ldots $
$ConsNode1(id,\,\,deposit,\,\,numActivities)\,\,= \ldots $ $ConsNode2(id,\,\,deposit,\,\,numActivities)\,\,= \ldots $ $ConsNode3(id,\,\,deposit,\,\,numActivities)\,\,= \ldots $
C. Perform Transactions
When the nodes become part of the system they perform transactions for the execution of tasks (line 12). The transactions of a post, receive, perform, evaluate, accept, reject, and finish a task are described.
$\begin{aligned} PerformTransactions()=\\ \hspace {-1.0em}\qquad PostTask(consumerNode,\,\,30);\,\,ReceiveTask(\\ \hspace {-0.85em}\qquad providerNode);\,\,PerformTask(\,\,providerNode);\\ \hspace {-1.0em}\qquad EvaluateTask(consumerNode);\,\,(AcceptTask(\\ \hspace {-0.85em}\qquad consumerNode)\,\,\square \,\,RejectTask(\,\,consumerNode));\\ \hspace {-1.0em}\qquad FinishTask(providerNode); \end{aligned}$
The post task transaction is specified as a process that takes a node
$\begin{aligned} var\,\,state\!=\![not\_{}\,\,post,\,\,post,\,\,receive,\,\,perform,\,\,evaluate,\\ \hspace {-1.5em}\,\,taccept,\,\,treject,\,\,finish]; \end{aligned}$ $var\,\,task\_{}\,\,state=state[{0}];\,\,\,\,$ $PostTask(vl,\,\,deposit)=$ $\begin{aligned} [vl==consumerNode\,\,\&\&\,\,task\_{}\,\,state==state[{0}]\,\,\\ \qquad \&\&\,\,deposit\,\,>=\,\,minDeposit\,\,\&\&\\ \qquad deposit\,\, < =\,\,maxDeposit] \end{aligned}$ $\begin{aligned} post\_{}\,\,task\,\,\{task\_{}\,\,state=state[{1}];\,\,\,\,\\ \qquad escrowC=consumerNode.SubmitDeposit(deposit);\\ \qquad blockchain.SetEscrowAmount(escrowC);\\ \qquad consumerNode.UpdateNumActivities(1);\}\,\, \rightarrow \,\,Skip; \end{aligned}$
When the task is posted it is received by the provider and the state changes from
$\begin{aligned} ReceiveTask(vl)=[vl==providerNode\,\,\&\& \\ \hspace {-1.0em}\qquad task\_{}\,\,state==state[{1}]] \end{aligned}$ $receive\_{}\,\,task\,\,\{task\_{}\,\,state=state[{2}];\}\,\, \rightarrow \,\,Skip;$
When the provider receives the task then he performs the task and the state of the task changes to
$\begin{aligned} PerformTask(vl)=[vl==providerNode\,\,\&\& \\ \hspace {-1.0em}\qquad task\_{}\,\,state==state[{2}]] \end{aligned}$ $perform\_{}\,\,task\,\,\{task\_{}\,\,state=state[{3}];\}\,\, \rightarrow \,\,Skip;$
After the task is performed by the provider, then the consumer evaluates it (line 18).
$\begin{aligned} EvaluateTask(vl)=[vl==consumerNode\,\,\&\& \\ \hspace {-1.0em}\qquad task\_{}\,\,state==state[{3}]] \end{aligned}$ $evaluate\_{}\,\,task\,\,\{task\_{}\,\,state=state[{4}];\,\,\}\,\, \rightarrow \,\,Skip;$
The consumer can accept or reject the task (lines 19-20). If it is accepted then its state changes to
$\begin{aligned} AcceptTask(vl)=[vl==consumerNode\,\,\&\&\\ \hspace {-1.0em}\qquad task\_{}\,\,state==state[{4}]] \end{aligned}$ $accept\_{}\,\,task\,\,\{task\_{}\,\,state=state[{5}];\,\,\}\,\, \rightarrow \,\,Skip;$
If the task is rejected then its state changes to
$\begin{aligned} RejectTask(vl)=[vl==consumerNode\,\,\&\& \\ \hspace {-1.0em}\qquad task\_{}\,\,state==state[{4}]] \end{aligned}$ $\begin{aligned} reject\_{}\,\,task\,\,\{task\_{}\,\,state=state[{6}];\\ \hspace {-1.0em}\qquad blockchain.RemoveEscrowAmount(escrowC/\\ \hspace {-1.0em}\qquad numShares);\,\,consumerNode.AddDeposit(escrowC/\\ \hspace {-1.0em}\qquad numShares);\,\,\} \rightarrow \,\,Skip; \end{aligned}$
When the task is accepted by the provider then its state is changed to
$\begin{aligned} FinishTask(vl)=[vl==providerNode\,\,\&\& \\ \hspace {-1.0em}\qquad task\_{}\,\,state==state[{5}]]\,\, \end{aligned}$ $\begin{aligned} task\_{}\,\,finish\,\,\{task\_{}\,\,state=state[{7}];\\ \hspace {-1.7em}\qquad blockchain.RemoveEscrowAmount(escrowC/numShares);\\ \hspace {-1.7em}\qquad providerNode.AddDeposit(escrowC/numShares);\\ \hspace {-1.7em}\qquad providerNode.UpdateNumActivities(1)\,\,\}\,\, \rightarrow \,\,Skip; \end{aligned}$
D. Selection
The consensus protocol starts with the selection of leader and validators (line 22). There should exist some management and validator nodes in the network to execute the selection, and their selection executes in parallel to save time.
$\begin{aligned} Selection()=\,\,[managementNodes.GetLength()\,\,>\,\,0\,\,\\ \hspace {-1.0em}\qquad \&\&\,\,validatorNodes.GetLength()\,\,>\,\,0]\,\,\,\,\\ \qquad (LeaderSelection()\,\,\parallel \,\,SelectValidator(K)); \end{aligned}$
1) Leader Selection
The leader selection algorithm is executed by each node in parallel in a distributed environment. It is assumed that all the nodes should have exactly the same inputs to achieve synchronous agreement [63]. It is ensured using a flooding algorithm in [63]. Otherwise, disagreement may occur. Given the same input, each node chooses exactly the same leader. In case of a tie among the nodes of the same trust values, an approach similar to the work presented in [62] is used in this work to avoid this situation. Following this approach, if any two management nodes have the same trust values then a management node with the smaller hash value of identifier and trust is selected.
The process of selection of a trusted leader is specified as
$LeaderSelection()=leaderSelection\{\,\,$ $var\,\,index=0;$ $mn1=managementNodes.GetNode(index);$ $tempLeader=mn1;$ $tempLeader.UpdateNumParticipated(1);$ $\begin{aligned} while(index\,\, < \,\,managementNodes.GetLength()-1)\,\,\{\,\,\\ \qquad \,\,\,\,mn2=managementNodes.GetNode(index+1);\\ \qquad \,\,mn2.UpdateNumParticipated(1);\\ \qquad \,\,var\,\,depositRatio1=tempLeader.GetDeposit()/\\ \qquad \qquad \quad managementNodes.GetTotalDeposit();\\ \qquad var\,\,activityRate1=tempLeader.GetNumActivities()\\ \qquad \qquad \,\,\,\,/\,\,tempLeader.GetNumSelected();\\ \qquad \,\,var\,\,missedRate1=tempLeader.GetNumMisses()/\\ \qquad \qquad \quad tempLeader.GetNumParticipated();\\ \qquad \,\,var\,\,depositRatio2=mn2.GetDeposit()/\\ \qquad \qquad \,\,managementNodes.GetTotalDeposit();\\ \qquad \,\,var\,\,activityRate2=mn2.GetNumActivities()/\\ \qquad \qquad \,\,mn2.GetNumSelected();\\ \quad \,\,\,\,var\,\,missedRate2=mn2.GetNumMisses()/\\ \qquad \qquad \,\,mn2.GetNumParticipated(); \end{aligned}$ $\begin{aligned} if\,\,(((depositRatio1\,\,+\,\,activityRate1\,\,+\,\,\\ \qquad \qquad \,\,missedRate1)/3)\,\,>\,\,((depositRatio2\,\,+\\ \qquad \qquad \,\,activityRate2\,\,+\,\,missedRate2)/3))\{\,\,\\ \qquad \qquad \,\,index=index+1; \}\,\, \end{aligned}$ $\begin{aligned} else\,\,if\,\,(((depositRatio1\,\,+\,\,activityRate1\,\,+\,\,\\ \qquad \qquad \,\,missedRate1)/3)\,\, < \,\,((depositRatio2\,\,+\\ \qquad \qquad \,\,activityRate2\,\,+\,\,missedRate2)/3))\{\,\,\\ \qquad \qquad \,\,tempLeader=mn2;\\ \qquad \qquad \,\,index=index+1;\}\,\,\}\,\, \end{aligned}$ $\begin{aligned} else\,\,if\,\,(((depositRatio1\,\,+\,\,activityRate1\,\,+\,\,\\ \qquad \qquad \,\,missedRate1)/3)==((depositRatio2\,\,+ \\ \qquad \qquad \,\,activityRate2\,\,+\,\,missedRate2)/3))\{\,\,\\ \qquad \,\,\,\,if\,\,((tempLeader.computeHash(tempLeader.\\ \qquad \qquad \,\,\,\,GetMId(),\,\,(depositRatio1\,\,+\,\,activityRate1\,\,+\,\,\\ \qquad \qquad \,\,\,\,missedRate1)/3))\,\,>\,\,(mn2.computeHash(mn2.\\ \qquad \qquad \,\,\,\,GetMId(),\,\,(depositRatio2\,\,+\,\,activityRate2\,\,+\,\,\\ \qquad \qquad \,\,\,\,missedRate2)/3)))\,\,\{\,\,\,\,tempLeader=mn2;\\ \qquad \qquad \qquad \quad \,\,index=index+1;\}\,\,\\ \qquad \,\,\,\,else\,\,\{\,\,index=index+1;\,\,\}\,\,\}\,\,\}\,\, \end{aligned}$ $selectedLeader=tempLeader;$ $leaderSelected=1;$ $selectedLeader.SetRound(rd);$ $selectedLeader.UpdateNumSelected(1); $ $escrowL=selectedLeader.\,\,$ $SubmitDeposit(selectedLeader.GetDeposit());$ $blockchain.SetEscrowAmount(escrowL);$ $selectedLeader.SetDeposit(0); \,\,\}\,\, \rightarrow \,\,Skip;$
2) Validators Selection
The trusted validators selection process is specified as
$SelectValidator(k)=selectkval\{\,\,$ $var\,\,index1=0;$ $var\,\,index2=1;$ $\begin{aligned} while(index1\,\, < \,\,validatorNodes.GetLength()-1\,\,\&\&\\ \qquad index1\,\, < \,\,k)\,\,\{\,\, \end{aligned}$ $\begin{aligned} while(index2\,\, < \,\,validatorNodes.GetLength())\,\,\{\,\,\\ \qquad \quad \,\,\,\,vn1=validatorNodes.GetNode(index1);\\ \qquad \quad \,\,\,\,vn2=validatorNodes.GetNode(index2);\\ \qquad \quad \,\,\,\,var\,\,depositRatio1=vn1.GetDeposit()/\\ \qquad \qquad validatorNodes.GetTotalDeposit();\\ \qquad \quad \,\,\,\,var\,\,activityRate1=vn1.GetNumActivities()/\\ \qquad \qquad vn1.GetNumSelected();\\ \qquad \quad \,\,\,\,var\,\,depositRatio2=vn2.GetDeposit()/\\ \qquad \qquad \,\,\,\,validatorNodes.GetTotalDeposit();\\ \qquad \quad \,\,\,\,var\,\,activityRate2=vn2.GetNumActivities()/\\ \qquad \qquad \,\,\,\,vn2.GetNumSelected(); \end{aligned}$ $\begin{aligned} if\,\,(((depositRatio1\,\,+\,\,activityRate1)/2)\,\,>=\,\,\,\,\\ \qquad \qquad \quad ((depositRatio2\,\,+\,\,activityRate2)/2))\{\,\,\\ \qquad \qquad \quad \,\,\,\,validatorNodes.SetNode(index1,\,\,vn1);\,\,\,\,\\ \qquad \qquad \quad \,\,\,\,validatorNodes.SetNode(index2,\,\,vn2);\,\,\,\,\\ \qquad \qquad \quad \,\,\,\,index2++;\}\,\, \end{aligned}$ $\begin{aligned} else\,\,\{\,\,validatorNodes.SetNode(index1,\,\,vn2);\,\,\,\,\\ \qquad \qquad \quad \,\,\,\,validatorNodes.SetNode(index2,\,\,vn1);\,\,\,\,\\ \qquad \qquad \quad \,\,\,\,index2++;\}\,\,\,\,\}\,\, \end{aligned}$ $var\,\,tn=validatorNodes.GetNode(index1);$ $tn.UpdateNumSelected(1);$ $escrowV=tn.SubmitDeposit(tn.GetDeposit());$ $blockchain.SetEscrowAmount(escrowV);$ $tn.SetDeposit(0);$ $trustedValidatorNodes.AddNode(tn);$ $index1++;\,\,\}\,\,valSelected=1;\,\,\}\,\, \rightarrow \,\,Skip;$
E. Vote and Broadcast Transactions
After the process of selection, the leader has to prepare the block and for this purpose, the transactions that receive maximum votes from validators are required. The procedure Vote ForTransactions is specified at line 25. This process takes a number of transactions, and a validator as input. The number of transactions to vote for should be greater than zero and less than or equal to the maximum number of transactions (line 25.1). Otherwise, no transaction is available to vote for (line 25.2). Before the voting process, a leader and validators must be selected, otherwise, no transaction can be selected for the voting process (line 25.1).
$VoteForTransactions(t,\,\,vl)=$ $\begin{aligned} [t\,\,>\,\,0\,\,\&\&\,\,t\,\, < =\,\,maxTransactions]\,\,\\ \qquad \quad ([leaderSelected == 1\,\,\&\&\,\,valSelected == 1]\\ \qquad \quad selection\_{}\,\,end\,\, \rightarrow \,\,voteTrans(t,\,\,vl)\,\, \square \\ \qquad \quad [leaderSelected == 0\,\,\parallel \,\,valSelected == 0]\\ \qquad \quad \,\,\,\,no\_{}\,\,transaction\_{}\,\,selected\,\, \rightarrow \,\,Skip)\,\, \square \end{aligned}$ $[t\,\, < \,\,0]\,\,no\_{}\,\,transaction\_{}\,\,to\_{}\,\,vote\,\, \rightarrow \,\,Skip;$
The voting process is described in procedure
$voteTrans(t,\,\,vl)=vote.t\,\,\{\,\,$ $var\,\,index1=0;$ $\begin{aligned} while(index1\,\, < \,\,trustedValidatorNodes.\\ \qquad GetLength()-1)\,\,\{\,\,\\ \qquad \quad tvn=trustedValidatorNodes.GetNode(index1);\\ \qquad \quad index1++;\,\,var\,\,index2=0; \end{aligned}$ $\begin{aligned} while(index2\,\, < \,\,pendingTransactions.GetLength()\\ \qquad \quad -1\,\,\&\&\,\,index2\,\, < \,\,t\,\,\&\&\,\,vl==tvn.GetVId())\,\,\{\,\,\\ \qquad \quad tran1=pendingTransactions.Get(index2);\\ \qquad \quad tTransactions.Set(index2,\,\,tran1);\,\,index2++;\}\,\,\\ \qquad \,\,\,\,transactionsProposals.Set(index1,\\ \qquad \quad new\,\,TransactionProposal(tTransactions,\\ \qquad \quad new\,\,TransactionSignature(index2)));\,\,\,\,\}\,\,\}\,\, \rightarrow \end{aligned}$ $\begin{aligned} ([vl==0]\,\,VoteToTransaction\_{}\,\,0();\,\,(\,\,\\ \qquad \quad ([voteflag0==1]\,\,(ch01!tempTVote0\,\, \rightarrow \,\,Skip\,\,\parallel \\ \qquad \qquad ch02!tempTVote0 \rightarrow \,\,Skip\parallel \,\,ch03!tempTVote0 \rightarrow \\ \qquad \qquad \,\,Skip)\,\, \square \,\,[voteflag0==0]\,\,Skip)\,\,\parallel \,\,\,\,\\ \qquad \quad ([voteflag1==1]\,\,ch10?y\,\,\{\,\,tvotes0.Add(y)\,\,\}\,\, \rightarrow \,\,\\ \qquad \quad \,\,\,\,Skip\,\, \square [voteflag1==0]\,\,Skip)\,\,\parallel \,\,\,\,\\ \qquad \quad ([voteflag2==1]\,\,ch20?y\,\,\{\,\,tvotes0.Add(y)\,\,\}\,\, \rightarrow \,\,\\ \qquad \quad \,\,\,\,Skip\,\, \square \,\,[voteflag2==0]\,\,Skip)\,\,\parallel \,\,\,\,\\ \qquad \quad ([voteflag3==1]\,\,ch30?y\,\,\{\,\,tvotes0.Add(y)\,\,\}\,\, \rightarrow \,\,\\ \qquad \quad \,\,\,\,Skip\,\, \square [voteflag3==0]\,\,Skip))\,\, \square \,\, \end{aligned}$ $[vl==1]\,\,VoteToTransaction\_{}\,\,1(); \ldots $ $[vl==2]\,\,VoteToTransaction\_{}\,\,2(); \ldots $ $[vl==3]\,\,VoteToTransaction\_{}\,\,3(); \ldots $
$\begin{aligned} VoteToTransaction\_{}\,\,0()=\,\,\\ \hspace {-0.5em}\qquad \,\,validateTProposal.0\,\,\{\,\,\\ \hspace {-0.5em}\qquad \,\,tempTProposal0=transactionsProposals.Get(0);\,\,\,\,\\ \hspace {-0.5em}\qquad \,\,tempProposedTransaction0\,\,=\,\,tempTProposal0.\\ \qquad GetTransactions();\\ \hspace {-0.5em}\qquad \,\,if(voteBehaviour[{0}]==Honest\_{}\,\,Vote)\,\,\{\\ \qquad \,\,\,\,tempTVote0=new\,\,TransactionVote(\\ \qquad \quad \,\,tempProposedTransaction0,\,\,tsignature0);\quad \,\,\,\,\\ \qquad \,\,\,\,tempTVote0.updateVotes(1);\} \\ \hspace {-0.5em}\qquad \,\,else\,\,if(voteBehaviour[{0}]==No\_{}\,\,Vote)\,\,\{\\ voteflag 0=0\} \,\,tvotes0.Add(tempTVote0);\} \rightarrow \,\,Skip; \end{aligned}$ $VoteToTransaction\_{}\,\,1()\,\,= \ldots $ $VoteToTransaction\_{}\,\,2()\,\,= \ldots $ $VoteToTransaction\_{}\,\,3()\,\,= \ldots $
$TransWithMaxVotes(t)=trans\,\,\{\quad \,\,\,\,$ $\begin{aligned} while(index1\,\, < \,\,votedTransactions.GetLength()-1\,\,\\ \qquad \&\&\,\,index1\,\, < \,\,t)\,\,\{\,\, \end{aligned}$ $\begin{aligned} while(index2\,\, < \,\,votedTransactions.GetLength())\,\,\{\,\,\\ \qquad \qquad \,\,\,\,tran1=votedTransactions.Get(index1);\\ \qquad \qquad \,\,\,\,tran2=votedTransactions.Get(index2); \end{aligned}$ $\begin{aligned} \qquad \,\,\,\,if\,\,(tran1.getVotes()\,\,>=\,\,tran2.getVotes())\{\,\,\\ \qquad \qquad \qquad \quad \,\,votedTransactions.Set(index1,\,\,tran1);\\ \qquad \qquad \qquad \quad \,\,votedTransactions.Set(index2,\,\,tran2);\\ \qquad \qquad \qquad \quad \,\,index2++;\}\,\, \end{aligned}$ $\begin{aligned} \qquad \,\,\,\,else\,\,\{\,\,votedTransactions.Set(index1,\,\,tran2);\\ \qquad \qquad \qquad \quad \,\,votedTransactions.Set(index2,\,\,tran1);\\ \qquad \qquad \qquad \quad \,\,index2++;\,\,\}\,\, \end{aligned}$ $ \qquad \,\,\,\,maxVotedTransactions.Set(index1,\,\,tran1);$ $ \qquad \,\,\,\,index1++; \quad \} \,\,\,\,\} \,\,\}\,\, \rightarrow \,\,Skip;$
F. Propose and Broadcast Block
After getting transactions that gain maximum votes, the block can be proposed. The block propose and broadcast procedure is described in line 32. If the leader is selected for the round, the block
$ProposeAndBroadcast(b)=\,\,$ $\begin{aligned} [selectedLeader.GetRound()==b]\,\,proposeBlock.b\,\,\\ \quad \,\,\,\,\{\,\,proposedBlock=lockedBlocks.Get(b);\\ \qquad if\,\,(proposedBlock.GetBlockHash()==initialHash)\\ \qquad \quad \,\,\,\,\{\,\,prevBlock=blockchain.GetPeekBlock();\\ \qquad \qquad \,\,\,\,proposedBlock=new\,\,Block(b,\,\,selectedLeader,\\ \qquad \qquad \,\,\,\,prevBlock.GetBlockHash(),\\ \qquad \qquad \,\,\,\,maxVotedTransactions); \,\,\}\,\,\\ \qquad blocksProposals.SetProposal(b,\,\,new\,\,BlockProposal\\ \qquad \quad (proposedBlock,\,\,new\,\,BlockSignature(b)))\,\,\}\,\, \rightarrow \,\,\,\, \end{aligned}$ $\begin{aligned} ((\,\,[b==0]\,\,(ch01!blocksProposals.GetProposal(b)\,\,\\ \qquad \,\, \rightarrow Skip\,\,\parallel \,\,ch02!blocksProposals.GetProposal(b)\,\,\\ \qquad \,\, \rightarrow \,\,Skip\,\,\parallel \,\,ch03!blocksProposals.GetProposal(b)\,\,\\ \quad \,\, \rightarrow \,\,Skip)\,\, \square [b==1] \ldots [b==2] \ldots [b==3] \ldots \end{aligned}$ $\begin{aligned} [b==0]\,\,(ch10?y\,\, \rightarrow \,\,\{blocksProposals.\\ \qquad \quad SetProposal(b,\,\,y)\}\,\, \rightarrow \,\,Skip\,\, \square \,\,ch20?y\,\, \rightarrow \\ \qquad \quad \,\,\{blocksProposals.SetProposal(b,\,\,y)\}\,\, \rightarrow \,\,Skip\,\, \square \\ \qquad \quad \,\,ch30?y\,\, \rightarrow \,\,\{blocksProposals.SetProposal(b,\,\,y)\}\,\,\\ \quad \rightarrow \,\,Skip\,\,) \square [b==1] \ldots [b==2] \ldots [b==3] \ldots \end{aligned}$
$VoteToBlock(b)=\,\,$ $\begin{aligned} [b==0]\,\,propose\_{}\,\,end\,\, \rightarrow \,\,VoteToBlock\_{}\,\,0();\,\,(\,\,\\ \qquad \quad ([voteflag0==1]\,\,(ch01!tempBVote0\,\, \rightarrow \,\,Skip\,\,\parallel \\ \qquad \quad ch02!tempBVote0 \rightarrow \,\,Skip\,\,\parallel \,\,ch03!tempBVote0\,\,\\ \qquad \quad \rightarrow \,\,Skip)\,\, \square \,\,[voteflag0==0]\,\,Skip)\,\,\parallel \,\,\,\,\\ \qquad \quad ([voteflag1==1]\,\,ch10?y\,\,\{\,\,bvotes0.Add(y)\,\,\}\,\, \rightarrow \\ \qquad \quad Skip\,\, \square \,\,[voteflag1==0]\,\,Skip)\parallel \,\,\,\,\\ \qquad \quad ([voteflag2==1]\,\,ch20?y\,\,\{\,\,bvotes0.Add(y)\,\,\}\,\, \rightarrow \,\,\\ \qquad \quad Skip\,\, \square \,\,[voteflag2==0]\,\,Skip)\parallel \,\,\,\,\\ \qquad \quad ([voteflag3==1]\,\,ch30?y\,\,\{\,\,bvotes0.Add(y)\,\,\}\,\, \rightarrow \,\,\\ \qquad \quad Skip\,\, \square \,\,[voteflag3==0]\,\,Skip))\,\, \square \,\, \end{aligned}$ $[b==1]\,\,propose\_{}\,\,end\,\, \rightarrow \,\,VoteToBlock\_{}\,\,1();\ldots $ $[b==2]\,\,propose\_{}\,\,end\,\, \rightarrow \,\,VoteToBlock\_{}\,\,2();\ldots $ $[b==3]\,\,propose\_{}\,\,end\,\, \rightarrow \,\,VoteToBlock\_{}\,\,3();\ldots $
In every process of
$VoteToBlock\_{}\,\,0()=\,\,$ $\begin{aligned} validateProposal.0\,\,\{\,\,\\ \qquad tempProposal0=blocksProposals.GetProposal(0);\,\,\,\,\\ \qquad tempProposedBlock0=tempProposal0.GetBlock();\quad \,\,\,\,\\ \qquad var\,\,invalidBlock=blockchain0.\,\,\\ \qquad \quad ContainsBlock(tempProposedBlock0); \end{aligned}$ $if(invalidBlock)\,\,\{tempProposedBlock0=new\,\,Block();\}\,\,$ $\begin{aligned} if(voteBehaviour[{0}]==Honest\_{}\,\,Vote)\,\,\{\\ \qquad \quad \,\,tempBVote0=new\,\,BlockVote(tempProposedBlock0.\\ \qquad \quad \,\,GetBlockHash(), bsignature0); \\ \qquad \quad \,\,tempBVote0.updateVotes(1);\,\,\}\quad \,\,\,\, \end{aligned}$ $\begin{aligned} else\,\,if(voteBehaviour[{0}]==No\_{}\,\,Vote)\,\,\\ \qquad \quad \,\,\{voteflag0=0\}\,\,bvotes0.Add(tempBVote0);\}\,\,\\ \qquad \quad \,\, \rightarrow \,\,Skip; \end{aligned}$ $VoteToBlock\_{}\,\,1()\,\,= \ldots \,\,$ $VoteToBlock\_{}\,\,2()=\ldots $ $VoteToBlock\_{}\,\,3()=\ldots $
G. Blockchain Validity
After receiving enough votes, the block can be added to the blockchain. Before adding the block, the validity of the blockchain is checked, specified as
$isValidBlockchain()=validBlockchain\{\,\,$ $var\,\,index=blockchain.GetHeight();$ $\begin{aligned} while\,\,(index\,\, < =\,\,blockchain.GetHeight()\,\,\&\&\\ \qquad index\,\,>=\,\,2)\{\,\,\\ \qquad \,\,\,\,curBlock=blockchain.GetBlock(index);\\ \qquad \,\,\,\,prevBlock=blockchain.GetBlock(index-1); \end{aligned}$ $\begin{aligned} if\,\,(curBlock.GetBlockHash()\,\,!=\,\,\\ \qquad \qquad \,\,curBlock.computeHash())\{\,\,v=\,\,Not\_{}\,\,Valid;\}\,\, \end{aligned}$ $\begin{aligned} if\,\,(curBlock.GetPrevHash()\,\,!=\\ \qquad \qquad \,\,prevBlock.GetBlockHash())\{\,\,v=\,\,Not\_{}\,\,Valid;\}\,\, \end{aligned}$ $\begin{aligned} else\,\,if\,\,(curBlock.GetBlockHash()\,\,==\\ \qquad \qquad curBlock.computeHash()\,\,\&\&\\ \qquad \quad \,\,\,\,curBlock.GetPrevHash()\,\,==\\ \qquad \quad \,\,\,\,prevBlock.GetBlockHash())\{\quad \\ \qquad \quad \,\,\,\,v=valid;\,\,index--;\,\,\} \,\,\} \,\,\}\,\, \rightarrow \,\,Skip; \end{aligned}$
H. Adding Block in Blockchain
The process of block addition is specified as
$AddBlock(b)=\,\,$ $\begin{aligned} [b==0\,\,\&\&\,\,v==valid]\,\,addtoBChain.b\,\,\{\,\,\\ \qquad \,\,\,\,tempProposedBlock0=bvotes0.\\ \qquad \quad \,\,GetBlockWithMajorityVotes(MajorityValidators);\\ \qquad \,\,\,\,if(tempProposedBlock0.GetBlockHash()\,\,!=\\ \qquad \qquad \,\,\,\,initialHash\,\,\&\&\,\,untrustedLeader==false)\,\,\{\,\,\\ \qquad \qquad \,\,\,\,blockchain0.AddBlock(tempProposedBlock0)\,\,\}\,\,\\ \qquad \,\,\,\,\}\,\, \rightarrow \,\,Skip\,\, \square \,\, \end{aligned}$ $[b==1\,\,\&\&\,\,v==valid] \ldots $ $[b==2\,\,\&\&\,\,v==valid]\,\,\ldots $ $[b==3\,\,\&\&\,\,v==valid]\,\,\ldots $
I. Update Trust Values and Deposit
At the end of the consensus protocol, trust values are updated (line 40). If the block is successfully added to blockchain then the leader’s number of activities is incremented, the leader gets the block generation reward and the escrow amount is returned (lines 40.1-40.2, 41-43). Similarly, the number of misses of participating management nodes are updated, the validators number of activities are incremented, they receive the block validation reward and their escrow deposit is returned (lines 40.2, 44-47). If the proposed block is not successfully added to the blockchain then the leader and validators lose trust (lines 40.3, 48-49). The leader deposit, the number of activities, and misses are set to zero. Similarly, the validators’ deposit and number of activities are set to zero.
$UpdateTrust()=$ $\begin{aligned} [blockchain0.ContainsBlock(tempProposedBlock0)\,\,\parallel \\ \qquad \quad blockchain1.ContainsBlock(tempProposedBlock1)\,\,\\ \quad \,\,\quad \parallel blockchain2.ContainsBlock(tempProposedBlock2)\,\,\\ \quad \,\,\quad \parallel blockchain3.ContainsBlock(tempProposedBlock3)]\,\, \end{aligned}$ $\begin{aligned} (UpdateLNumActivities(1);\\ \quad \,\,\quad GetBlockGReward(escrowC/numShares);\\ \quad \,\,\quad LDepositReturned(escrowL);\\ \quad \,\,\quad UpdatePMNumMisses(1);UpdateVNumActivities(1);\\ \quad \,\,\quad GetBlockVReward();TVDepositReturned();\,\,Skip) \square \,\, \end{aligned}$ $\begin{aligned} [!(blockchain0.ContainsBlock(tempProposedBlock0))\\ \hspace {-0.2em}\quad \,\,\quad \parallel !(blockchain1.ContainsBlock(tempProposedBlock1))\\ \hspace {-0.2em}\quad \,\,\quad \parallel !(blockchain2.ContainsBlock(tempProposedBlock2))\\ \hspace {-0.2em}\quad \,\,\quad \parallel !(blockchain3.ContainsBlock(tempProposedBlock3))\\ \quad \,\,\quad]\,\,maliciousLeader\,\, \rightarrow \,\,LLoseTrustAndDeposit()\,\, \square \\ \qquad \quad maliciousValidators\,\, \rightarrow \,\,VLoseTrustAndDeposit(); \end{aligned}$
$\begin{aligned} UpdateLNumActivities(l)=update\,\,\{selectedLeader.\\ \,\,\,\,\quad UpdateNumActivities(l)\}\,\, \rightarrow \,\,Skip; \end{aligned}$
$\begin{aligned} GetBlockGReward(deposit)=getdep\,\,\{blockchain.\\ \qquad RemoveEscrowAmount(deposit);\\ \qquad selectedLeader.AddDeposit(deposit)\}\,\, \rightarrow \,\,Skip; \end{aligned}$
$\begin{aligned} LDepositReturned(deposit)=getdep\,\,\{blockchain.\\ \qquad RemoveEscrowAmount(deposit);\\ \,\,\qquad selectedLeader.AddDeposit(deposit)\}\,\, \rightarrow \,\,Skip; \end{aligned}$
$\begin{aligned} UpdatePMNumMisses(m)=update\,\,\{\,\,\\ \,\,\,\,while(index\,\, < \,\,managementNodes.GetLength()-1)\{\,\,\\ \quad \,\,\quad mn1=managementNodes.GetNode(index);\\ \quad \,\,\quad if\,\,(mn1\,\,!=\,\,selectedLeader\,\,\&\&\,\,\\ \qquad \quad \,\,\quad mn1.GetNumMisses()\,\, < \,\,maxNumMisses)\{\,\,\\ \qquad \quad \,\,\quad mn1.UpdateNumMisses(m);\}\,\,\\ \qquad \quad \,\,\quad index++;\,\,\}\,\,\,\,\}\,\, \rightarrow \,\,Skip; \end{aligned}$
$\begin{aligned} UpdateVNumActivities(a)=update\,\,\{\,\,\\ \hspace {-0.7em}\,\,\,\,while(index < trustedValidatorNodes.GetLength()-1)\,\,\\ \qquad \{\,\,tvn=trustedValidatorNodes.GetNode(index);\\ \qquad tvn.UpdateNumActivities(a);\\ \qquad index++;\,\,\}\,\,\,\,\}\,\, \rightarrow \,\,Skip; \end{aligned}$
$\begin{aligned} GetBlockVReward()=vreward\,\,\{\,\,\\ \hspace {-0.7em} \,\,\,\,while(index < trustedValidatorNodes.GetLength()-1)\,\,\\ \qquad \quad \{\,\,tvn=trustedValidatorNodes.GetNode(index);\\ \qquad \quad blockchain.RemoveEscrowAmount((escrowC/\\ \qquad \quad numShares)/trustedValidatorNodes.GetLength());\,\,\,\,\\ \qquad \quad tvn.AddDeposit((escrowC/numShares)/\\ \qquad \quad trustedValidatorNodes.GetLength());\\ \qquad \quad index++;\,\,\} \,\,\}\,\, \rightarrow \,\,Skip; \end{aligned}$
$\begin{aligned} TVDepositReturned()=tvdep\,\,\{\,\,\\ \quad \,\,while(index\,\, < \,\,trustedValidatorNodes.\\ \qquad \quad GetLength()-1)\,\,\{\,\,\\ \qquad \quad tvn=trustedValidatorNodes.GetNode(index);\\ \qquad \quad escrowV=tvn.GetEscrow();\\ \qquad \quad blockchain.RemoveEscrowAmount(escrowV);\,\,\,\,\\ \qquad \quad tvn.AddDeposit(escrowV);\,\,index++;\} \} \rightarrow Skip; \end{aligned}$
$\begin{aligned} LLoseTrustAndDeposit()=ltrust\,\,\{\,\,\\ \,\,\,\,\quad selectedLeader.SetNumActivities(0);\\ \,\,\,\,\quad selectedLeader.SetNumMisses(0);\\ \,\,\,\,\quad selectedLeader.SetDeposit(0); \,\,\}\,\, \rightarrow \,\,Skip; \end{aligned}$
$\begin{aligned} VLoseTrustAndDeposit()=vltrust\,\,\{\,\,\\ \,\,\,\,\quad while(index\,\, < \,\,trustedValidatorNodes.\\ \qquad \quad GetLength()-1)\,\,\{\\ \qquad \quad tvn=trustedValidatorNodes.GetNode(index);\\ \qquad \quad tvn.SetNumActivities(0);\\ \qquad \quad tvn.SetDeposit(0);\,\,index++;\}\,\,\,\,\}\,\, \rightarrow \,\,Skip; \end{aligned}$
J. Next Round
In order to move the consensus protocol to the next round, the
$\begin{aligned} NextRound()=\,\,\\ \,\,\,\,\quad [rd\,\, < \,\,maxRounds]\,\,nextround\,\,\{\,\,rd++;\\ \,\,\,\,\quad lockedBlocks.Clear();\\ \,\,\,\,\quad bvotes0.Clear();\,\,bvotes1.Clear();\,\,bvotes2.Clear();\\ \quad \,\,\quad bvotes3.Clear();\,\,\,\,\\ \,\,\,\,\quad tvotes0.Clear();\,\,tvotes1.Clear();\,\,tvotes2.Clear();\\ \quad \,\,\quad tvotes3.Clear();\\ \,\,\,\,\quad managementNodes.Nullify(selectedLeader);\\ \,\,\,\,\quad validatorNodes.Nullify(trustedValidatorNodes);\\ \,\,\,\,\quad blockchain.Nullify(proposedBlock);\\ \,\,\quad \}\,\, \rightarrow \,\,Consensus\_{}\,\,Protocol()\,\, \square \,\,\\ \,\,\,\,\quad [rd\,\,>=\,\,maxRounds]\,\,Skip; \end{aligned}$
Results and Analysis
We have verified our formal model of the proposed consensus protocol under normal and byzantine environments using the PAT model checker. We have defined five variations of our consensus protocol. The first two variations are defined with different numbers of malicious nodes with a threat factor of no vote (lines 51-52). The next two variations are specified with different numbers of malicious nodes but the voting behavior is defined as honest (lines 53-54). The fifth variation of consensus protocol simulates the behavior of an untrusted leader (lines 55-56). After the selection process, an untrusted leader is introduced which can try to add a block in the blockchain.
$\begin{aligned} Consensus\_{}\,\,Protocol\_{}\,\,With\_{}\,\,Minority\_{}\,\,Malicious\_{}\\ \hspace {-1.5em}\qquad \,\,\,\,No\_{}\,\,Vote()=IntroduceMaliciousNodes(Minority\_{}\\ \hspace {-1.5em}\qquad \,\,\,\,Nodes,\,\,No\_{}\,\,Vote);\,\,Consensus\_{}\,\,Protocol(); \end{aligned}$ $\begin{aligned} Consensus\_{}\,\,Protocol\_{}\,\,With\_{}\,\,Majority\_{}\,\,Malicious\_{}\\ \hspace {-1.5em}\qquad \,\,\,\,No\_{}\,\,Vote()=IntroduceMaliciousNodes(Majority\_{}\\ \hspace {-1.5em}\qquad \,\,\,\,Nodes,\,\,No\_{}\,\,Vote);\,\,Consensus\_{}\,\,Protocol(); \end{aligned}$ $\begin{aligned} Consensus\_{}\,\,Protocol\_{}\,\,With\_{}\,\,Minority\_{}\,\,Malicious\_{}\\ \hspace {-1.5em}\qquad \,\,\,\,Honest\_{}\,\,Vote()=IntroduceMaliciousNodes(Minority\\ \hspace {-1.5em}\qquad \quad \_{}Nodes,\,\,Honest\_{}\,\,Vote);Consensus\_{}\,\,Protocol(); \end{aligned}$ $\begin{aligned} Consensus\_{}\,\,Protocol\_{}\,\,With\_{}\,\,Majority\_{}\,\,Malicious\_{}\\ \hspace {-1.5em}\qquad \,\,\,\,Honest\_{}\,\,Vote()=IntroduceMaliciousNodes(Majority\\ \hspace {-1.5em}\qquad \,\,\,\,\_{}\,\,Nodes,\,\,Honest\_{}\,\,Vote);\,\,Consensus\_{}\,\,Protocol(); \end{aligned}$ $\begin{aligned} Consensus\_{}\,\,Protocol\_{}\,\,With\_{}\,\,Untrusted\_{}\,\,Leader()=\\ \hspace {-1.5em}\qquad \,\,\,\,(\parallel \,\,i:\{0..PNodes-1\} \text{@}(NodeInitialization();\\ \hspace {-1.5em}\qquad \,\,\,\,PerformTransactions();\,\,Selection();IntroduceUntr-\\ \hspace {-1.5em}\qquad \,\,\,\,ustedLeader();\,\,VoteForTransactions(T,\,\,i);\\ \hspace {-1.5em}\qquad \,\,\,\,ProposeAndBroadcast(i);\,\,VoteToBlock(i);\\ \hspace {-1.5em}\qquad \,\,\,\,isValidBlockchain();\,\,\,\,AddBlock(i);\\ \hspace {-1.5em}\qquad \,\,\,\,UpdateTrustAndDeposit()));\,\,NextRound(); \end{aligned}$ $\begin{aligned} IntroduceUntrustedLeader()=\{\,\,\\ \,\,\,\,\qquad selectedLeader=untrustedLeaderNode;\\ \,\,\,\,\qquad untrustedLeader=true; \,\,\}\,\, \rightarrow \,\,Skip; \end{aligned}$
LTL is used to specify the desired properties. The properties are represented as assertions in Table 3. We have verified general properties, as well as security properties, under normal and byzantine environments. The verification of properties under a byzantine environment shows that the proposed model is fault tolerant.
A. Deadlock-Free
A deadlock-free formal model is described as there does not occur a situation where a node has to wait for another node for an activity. The PAT model checker is used to query deadlock in the formal model. We have specified assertions and verified that the consensus protocol is deadlock-free in both normal and byzantine environments as shown in Table 3. The assertion
$\#assert Consensus\_{} Protocol() deadlockfree;$
B. Consensus
Consensus is defined using
$\begin{aligned} \#define\,\,Consensus\,\,(!blockchain0.IsEmpty()\,\,\&\&\\ \hspace {-1.4em}\,\,blockchain0.GetPeekBlock()\,\,==\\ \hspace {-0.3em} \,\,\quad blockchain1.GetPeekBlock()\,\,\&\&\\ \hspace {-1.4em}\,\,blockchain1.GetPeekBlock()\,\,==\\ \hspace {-0.3em} \,\,\quad blockchain2.GetPeekBlock()\,\,\&\&\\ \hspace {-1.4em}\,\,blockchain2.GetPeekBlock()\,\,==\\ \hspace {-0.3em}\,\,\quad blockchain3.GetPeekBlock()); \end{aligned}$
LTL formulas are specified as assertions to verify that the formal model eventually reaches consensus or not in normal and byzantine environments. The assertion
$\#assert Consensus\_{} Protocol() \models \lozenge Consensus;$
C. No Blockchain Fork
No blockchain fork can be assured when all nodes record the same proposed block in their blockchain. All nodes have a same view about the blockchain state.
$\begin{aligned} \#define\,\,No\_{}\,\,Blockchain\_{}\,\,Fork\,\,(!blockchain0.IsEmpty()\,\,\&\&\\ \hspace {-1.4em}\,\,proposedBlock==blockchain0.GetPeekBlock()\,\,\&\&\\ \hspace {-1.4em}\,\,proposedBlock==blockchain1.GetPeekBlock()\,\,\&\&\\ \hspace {-1.4em}\,\,proposedBlock==blockchain2.GetPeekBlock()\,\,\&\&\\ \hspace {-1.4em}\,\,proposedBlock==blockchain3.GetPeekBlock()); \end{aligned}$
LTL formulas are specified below to verify that eventually no blockchain fork is ensured. Table 3 shows that the model ensures that a blockchain fork cannot occur in the normal environment as specified by an LTL formula
$\begin{aligned} \#assert Consensus\_{} Protocol() \models \\ \qquad \lozenge No\_{} Blockchain\_{} Fork; \end{aligned}$
D. No Selfish Mining
No selfish mining is ensured when a leader of a peek block of every copy of the blockchain is the same. It shows that only the block of a single leader is added to the blockchain.
$\begin{aligned} \#define\,\,No\_{}\,\,Selfish\_{}\,\,Mining\,\,(!blockchain0.IsEmpty()\,\,\&\&\\ \hspace {-1.8em}\,\,blockchain0.GetBlockLeader(blockchain0.GetPeekBlock())\\ \hspace {-1.8em}==blockchain1.GetBlockLeader(blockchain1.\\ \hspace {-1.8em}GetPeekBlock())\,\,\&\&\,\,blockchain1.GetBlockLeader(\\ \hspace {-1.8em}blockchain1.GetPeekBlock())==blockchain2.\\ \hspace {-1.8em}GetBlockLeader(blockchain2.GetPeekBlock())\,\,\&\&\,\,\,\,\\ \hspace {-1.8em}\,\,blockchain2.GetBlockLeader(blockchain2.GetPeekBlock())\\ \hspace {-1.8em}==blockchain3.GetBlockLeader(blockchain3.\\ \hspace {-1.8em}GetPeekBlock())); \end{aligned}$
LTL formulas are described to verify that there is no selfish mining in the protocol. The LTL formula
$\begin{aligned} \#assert Consensus\_{} Protocol() \models \\ \qquad \lozenge No\_{} Selfish\_{} Mining; \end{aligned}$
E. No Invalid Block Insertion
It is defined as in each round of consensus protocol there should not be any invalid (duplicate) block submitted by malicious leaders in the copy of blockchain of a node.
$\begin{aligned} \#define\,\,No\_{}\,\,Invalid\_{}\,\,Block\_{}\,\,Insertion\,\,(rd>0\,\,\&\&\\ \hspace {-1.4em}\,\,!blockchain0.ContainsDuplicateBlocks()\,\,\&\&\\ \hspace {-1.4em}\,\,!blockchain1.ContainsDuplicateBlocks()\,\,\&\&\\ \hspace {-1.4em}\,\,!blockchain2.ContainsDuplicateBlocks()\,\,\&\& \\ \hspace {-1.4em}\,\,!blockchain3.ContainsDuplicateBlocks()); \end{aligned}$
$\begin{aligned} \#assert\,\,Consensus\_{}\,\,Protocol()\,\,\models \\ \hspace {-0.3em}\,\,\qquad \lozenge \,\,No\_{}\,\,Invalid\_{}\,\,Block\_{}\,\,Insertion; \end{aligned}$
F. Safety
The safety property is defined as all the nodes reach the same decision. It means that all the nodes must agree on adding the same block. It can be ensured when there are no blockchain fork and no selfish mining attacks.
$\begin{aligned} \#define\,\,Safety\,\,No\_{}\,\,Blockchain\_{}\,\,Fork\,\,\&\&\\ \hspace {-1.4em}\,\,No\_{}\,\,Selfish\_{}\,\,Mining; \end{aligned}$
$\#assert Consensus\_{} Protocol() \models \lozenge Safety;$
G. Fault Tolerance
In each round, a common block will be accepted by all honest nodes even in the existence of some malicious nodes. This property is specified as reaching consensus. It is described below by an LTL formula
$\begin{aligned} \#define\,\,Fault\_{}\,\,Tolerance\,\,Consensus;\\ \hspace {-2.1em}\,\,A37.\,\,\#assert\,\,Consensus\_{}\,\,Protocol()\,\,\models \,\,\lozenge \,\,Fault\_{}\,\,Tolerance; \end{aligned}$
H. Trusted Leader
In every round of consensus, a trusted leader is selected. The LTL formulas are specified to verify that eventually a trusted leader is selected.
$\begin{aligned} \#define\,\,trustedLeader\,\,(rd>=0\,\,\&\&\,\,leaderSelected==1);\\ \hspace {-2.1em}\,\,A43.\,\,\#assert\,\,Consensus\_{}\,\,Protocol()\,\,\models \,\,\lozenge \,\,trustedLeader; \end{aligned}$
I. Trusted Validators
The trusted validators are selected in every round of consensus protocol. LTL formulas are used to specify that eventually trusted validators are selected.
$\begin{aligned} \#define\,\,trustedValidators(rd>=0\,\,\&\&\,\,valSelected==1);\\ \hspace {-2.1em}\,\,A48.\,\,\#assert\,\,Consensus\_{}\,\,Protocol()\,\,\models \,\,\lozenge \,\,trustedValidators; \end{aligned}$
J. Analysis of the Protocol
We have performed the formal verification of the desired properties against the STBC protocol on an Intel i5-7200U 2.5 GHz CPU with 8 GB of memory, running Windows 10 and PAT version 3.5.1. The results of verification time (in seconds) of safety, fault tolerance, trusted leader, and trusted validators are presented in Figures 5, 6, 7, and 8 respectively. The number of nodes is represented on the horizontal axis and the verification time in seconds is shown on the vertical axis. The nodes involved are service consumers, service providers, blockchain management nodes, and validator nodes. When the properties are satisfied, it is analyzed that the verification time increases continuously with the increased count of nodes. In case of violation of a property, the verification time remains close to zero. For example, for the safety property, Figure 5 shows the assertions
We have performed formal verification for a limited number of nodes in the network. However, the proposed protocol itself is generic, and it can work for an arbitrary number of nodes. The noticeable point is that the verification time increases continuously with the increased count of nodes. With many nodes, an issue of state explosion may occur, which is one of the limitations of the model checking approach [33]. These limitations are outside the scope of this work. In the future, we plan to improve the efficiency of our model using different techniques, such as symbolic model checking with binary decision diagrams, partial order reduction, counterexample-guided abstraction refinement, and bounded model checking.
Conclusion and Future Work
Secure and Trustworthy Blockchain-based Crowdsourcing consensus protocol is a formally verified consensus protocol, which ensures safety, fault tolerance, trusted leader, and trusted validator properties. It prevents security attacks, e.g., blockchain fork, selfish mining, and invalid block insertion. The proposed consensus protocol is energy-efficient as a single leader proposes a block in each round of the protocol. The trust model ensures fairness and decentralization because the waiting nodes also get a chance to become leaders. Ensuring the correctness of a consensus protocol has significant importance because the failure of a consensus protocol can lead to disastrous consequences. Therefore, to mitigate the associated risks, we have used a formal methods-based technique, i.e., model checking, which is automatic and effective to increase the formal model’s confidence of correctness. We have used CSP# for the formal specification of the consensus protocol. The security and trust properties are formally specified using LTL formulas. The PAT model checker is utilized to ensure the correctness of the formal specification against the specified properties.
At present, we have done model checking of our formal model for small number of nodes. For large number of nodes, state explosion can occur which will be addressed in future using different techniques such as symbolic model checking with binary decision diagrams, partial order reduction, counterexample-guided abstraction refinement and bounded model checking. The future work will consider failure or unavailability of nodes. Formal verification of further security properties, e.g., persistence and liveness, against the formal model will be done. We will do the performance analysis of the proposed consensus protocol using simulation techniques in addition to formal verification to get benefit of both approaches.