> For the complete documentation index, see [llms.txt](https://cvnnt.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cvnnt.gitbook.io/documentation/algorithms-and-cryptography/cbft.md).

# CBFT

{% hint style="info" %}
Note: This chapter is currently under development.
{% endhint %}

The purpose of a consensus protocol is to provide verifiable state synchronization of a distributed dynamic system even in the presence of an unpredictable behavior by some of the participating nodes.

Covenant system utilizes CBFT (Credit-graded Group-based BFT) consensus algorithm for dynamic integrity and distributed state sync.

Credit represents a score which, in Covenant system, is combined of several parameters such as node reputation, performance and governance stake amount.

### CBFT algorithm description

CBFT algorithm contains in-group round and outgroup round, which mainly achieves consensus among the current validation set of master nodes. In each group member master nodes receive the broadcast from the current group management node ( management node is a temporary status assigned dynamically for each round), and in the intra-group preparation and commit phases, the management nodes receive enough information about the proposal, and when the out-group preparation phase is completed, it means that enough nodes have verified and passed the proposal initiated by the client, and the outgroup commit phase is only the confirmation of the proposal passed in the preparation phase to ensure that enough nodes have completed the verification of the proposal.

### CBFT algorithm advantages&#x20;

CBFT algorithm has several useful features for distributed system:

* Secure decentralized decision making – CBFT is built on battle-tested PBFT model - one of the most known decentralized decision making algorithms widely utilized in distributed systems.
* Scalability – Grouping allows to optimize consensus performance as number of master nodes increases.
* EAAC property – CBFT combined with other Covenant mechanics provides an opportunity to achieve the "Expensive to Attack in the Absence of Collapse" property that allows to further improve the security level and robustness of the Covenant system.

### CBFT algorithm features&#x20;

The CBFT consensus algorithm contains in-group and outgroup consensus, which mainly achieves consensus among the nodes involved in consensus.&#x20;

The group member nodes receive the management node broadcast, and in the intra-group preparation and commit phases, the management nodes receive enough information about the proposal, and when the out-group preparation phase is completed, it means that enough nodes have verified and passed the proposal initiated by the client, and the outgroup commit phase is only the confirmation of the proposal passed in the preparation phase to ensure that enough nodes have completed the verification of the proposal. Thus, the three-phase protocol outside the group can be optimized into two phases.

### Improved scalability of CBFT algorithm in comparison with PBFT

In comparison with the original PBFT algorithm, CBFT is suitable for scalable systems as it has significant improvements in throughput, latency, and communication overhead as the number of nodes in the system expands, improving the performance, security, and reliability of the distributed system, increasing the scalability of the system.

&#x20;Let $$N$$ represent the amount of nodes in the distributed system. In PBFT there are three phases where messages need to be sent for communication.&#x20;

* The client sends the request to the master node, which sends the pre-preparation message to all replica nodes, and the number of communications in the pre-preparation phase is $$(N-1)$$.
* The node receives the message, verifies, and sends the message in the preparation phase, and the number of communications in this phase is $$(N-1)^2$$.
* In the commit phase, the node receives the preparation message and when the verification result is consistent, the submitted message is sent to all nodes and the number of communications in this phase is $$N(N-1)$$.&#x20;

Based on the communication times of the above three phases, the PBFT algorithm is simplified to obtain the completion time $$T\_1$$ for consistent communication as:

$$T\_1= N-1+(N-1)^2+N(N-1)=2N(N-1)$$

In CBFT, there are two phases in each consensus set where messages need to be sent for communication. Assuming that each consensus set has $$M(M\geq3)$$ nodes, the number of communications in the preparation phase is $$N-\dfrac{N}{M}$$ and the number of communications in the commit phase is $$N-\dfrac{N}{M}$$, the total number of communications in the consensus set $$T\_2$$ is:

$$T\_2=N-\dfrac{N}{M}+N-\dfrac{N}{M}=2\left(N-\dfrac{N}{M}\right)$$

Number of communications $$T\_3$$ (the consensus within the consensus set, participation in global consensus):

$$T\_3=\dfrac{N}{M}\left(\dfrac{N}{M}-1\right)=\left(\dfrac{N}{M}\right)^2-\dfrac{N}{M}$$

Then the total number of CBFT communications $$T\_4$$ is:

$$T\_4=T\_2+T\_3=2\left(N-\dfrac{N}{M}\right)+\left(\dfrac{N}{M}\right)^2-\dfrac{N}{M}=\left(\dfrac{N}{M}\right)^2-3\dfrac{N}{M}+2N$$

When $$N>12$$ , $$T\_4\<T\_1$$, showing the communication overhead is smaller with CBFT algorithm.

### CBFT algorithm step by step&#x20;

* **Out-group pre-preparation phase:** Upon receiving a request from a client, the master node chosen as management master node in the current group validates and sequences the request and broadcasts a pre-preparation message $$\<OUT-PRE-PREPARE,n,t,v,D(m)>\sigma\_i$$ to its group master node members, where $$n$$ is the sequence number assigned to the request, $$t$$ is the timestamp, $$v$$ denotes the view number, $$D(m)$$ is the message digest, and $$\sigma\_i$$ is the signature of management master node $$i$$.
* **Intra-group preparation phase:** Group master node members receive and validate the pre-preparation message.
* **Intra-group commit phase:** Group master node members verify the proposal and if it is correct send the response to the proposal $$\<IN-COMMIT,n,t,v,D(m)>\sigma\_x$$ , where $$\sigma\_x$$ is the signature of peer $$x$$.
* **Out-group preparation phase:** The management master node receives responses from a sufficient number of group master node members, turns on global phase, and broadcasts the result of the in-group phase $$\<OUTPREPARE,n,t,v,D(m)>\sigma\_i$$ to all management master nodes.
* **Intra-group reply phase:** The management master node receives more than $$2f$$ identical messages and sends a request acknowledgment $$\<IN-REPLY,n,t,v,D(m)>\sigma\_i$$ to the group master node members.
* **Out-group reply phase:** The management master node replies to the client $$\<OUT-REPLY,n,t,v,D(m)>\sigma\_i$$, and when the client receives $$f+1$$ identical reply messages, the message is considered verified across the decentralized system.
