# IC consensus layer

The job of the consensus layer of the IC is to order transaction requests so that all replicas in a subnet will process such requests in the same order. There are many protocols in the literature for this problem. The IC uses a new consensus protocol, which is described here at a high level. For more details, see the paper https://eprint.iacr.org/2021/632 (in particular, Protocol ICC1 in that paper).

Any secure consensus protocol should guarantee two properties, which (roughly stated) are:

• safety: all replicas in fact agree on the same ordering of transaction requests, and
• liveness: all replicas should make steady progress.

The paper https://eprint.iacr.org/2021/632 proves that the IC consensus protocol satisfies both of these properties.

The IC consensus protocol is designed to be

• simple,
• robust (performance degrades gracefully when some replicas are crashed or malicious), and
• optimistically responsive (when certain optimistic conditions are met, the protocol may proceed at the pace of the actual network delay, rather than some worst-case upper bound on the network delay).

## Assumptions

As discussed in the introduction, assume

• a subnet of $\displaystyle{ n }$ replicas, and
• at most $\displaystyle{ f \lt n/3 }$ of the replicas are faulty.

Faulty replicas may exhibit arbitrary, malicious (i.e., Byzantine) behavior.

Assume communication is asynchronous, with no a priori bound on the delay of messages sent between replicas. In fact, the scheduling of message delivery may be completely under adversarial control. The IC consensus protocol guarantees safety under this very weak communication assumption. However, to guarantee liveness, a form of partial synchrony is needed, which (roughly stated) says that the network will be periodically synchronous for short intervals of time. In such intervals of synchrony, all undelivered messages will be delivered in less than time $\displaystyle{ \delta }$, for some fixed bound $\displaystyle{ \delta }$. The bound $\displaystyle{ \delta }$ does not have to be known in advance (the protocol is initialized with a reasonable bound, but will dynamically adapt and increase this bound if it is too small). Regardless of whether an asynchronous or a partially synchronous network is assumed, it is assumed that every message sent from one honest party to another will eventually be delivered.

## Protocol overview

Like a number of consensus protocols, the IC consensus protocol is based on a blockchain. As the protocol progresses, a tree of blocks is grown, starting from a special genesis block that is the root of the tree. Each non-genesis block in the tree contains (among other things) a payload, consisting of a sequence of transaction requests, and a hash of the block's parent in the tree. The honest replicas have a consistent view of this tree: while each replica may have a different, partial view of this tree, all the replicas have a view of the same tree. In addition, as the protocol progresses, there is always a path of finalized blocks in this tree. Again, the honest replicas have a consistent view of this path: while each replica may have a different, partial view of this path, all the parties have a view of the same path. The transaction requests in the payloads of the blocks along this path are the ordered transaction requests will be processed by the execution layer of the Internet Computer.

The protocol proceeds in rounds. In round $\displaystyle{ h }$ of the protocol, one or more blocks of height $\displaystyle{ h }$ are added to the tree. That is, the blocks added in round $\displaystyle{ h }$ are always at a distance of exactly $\displaystyle{ h }$ from the root. In each round, a pseudo-random process is used to assign each replica a unique rank, which is an integer in the range $\displaystyle{ 0,\ldots,n-1 }$. This pseudo-random process is implemented using a random beacon (see below). The party of lowest rank is the leader of that round. When the leader is honest and the network is synchronous, the leader will propose a block, which will be added to the tree; moreover, this will be the only block added to the tree in this round and it will extend the finalized path. If the leader is not honest or the network is not synchronous, some other parties of higher rank may also propose blocks, and also have their blocks added to the tree. In any case, the logic of the protocol gives highest priority to the leader's proposed block and some block or blocks will be added to this tree in this round. Even if the protocol proceeds for a few rounds without extending the finalized path, the height of the tree will continue to grow with each round, so that when the finalized path is extended in round $\displaystyle{ h }$, the finalized path will be of length $\displaystyle{ h }$. A consequence of this, even if the latency occasionally occasionally increases because of faulty replicas or unexpectedly high network latency, the throughput of the protocol remains essentially constant.

## Public keys

To implement the protocol, each replica is associated with a public key for the BLS signature scheme, and each replica also holds the corresponding secret signing key. The association of replicas to public keys is maintained by the Network Nervous System (NNS) of the Internet Computer. These BLS signatures will be used to authenticate messages sent by replicas.

The protocol also uses the signature aggregation feature of BLS signatures, which allows many signatures on the same message to be aggregated into a compact multi-signature. The protocol will use these multi-signatures for notarizations and finalizations, which are aggregations of $\displaystyle{ n-f }$ signatures on messages of a certain form.

## Random Beacon

In addition to BLS signatures and multi-signatures as discussed above, the protocol makes use of a BLS threshold signature scheme to implement the above-mentioned random beacon. The random beacon for height $\displaystyle{ h }$ is a $\displaystyle{ (f+1) }$-threshold signature on a message unique to height $\displaystyle{ h }$. In each round of the protocol, each replica broadcasts its share of the beacon for the next round, so that when the next round begins, all replicas should have enough shares to reconstruct the beacon for that round. As discussed above, the random beacon at height $\displaystyle{ h }$ is used to assign a pseudo-random rank to each replica that will be used in round $\displaystyle{ h }$ of the protocol. Because of the security properties of the threshold signature, an adversary will not be able to predict the ranking of the replicas more than one round in advance, and these rankings will effectively be as good as random. To set up such a threshold signature scheme, the Internet Computer runs a distributed key generation (DKG) protocol. There are many DKG protocols in the literature. The Internet Computer implements a new non-interactive DKG (NiDKG) protocol.

## Block making

Each replica may at different points in time play the role of a block maker. As a block maker in round $\displaystyle{ h }$, the replica proposes a block $\displaystyle{ B }$ of height $\displaystyle{ h }$ that is to be a child of some block $\displaystyle{ B' }$ of height $\displaystyle{ h-1 }$ in the tree of blocks. To do this, the block maker first gathers together a payload consisting of all transaction requests it knows about (but not including those already included in payloads in blocks in the path through the tree ending at $\displaystyle{ B' }$). The block $\displaystyle{ B }$ consists of

• the hash of $\displaystyle{ B' }$,
• the rank of the block maker,
• the height $\displaystyle{ h }$ of the block.

After forming the block $\displaystyle{ B }$, the block maker forms a block proposal, consisting of

• the block $\displaystyle{ B }$,
• the block maker's identity, and
• the block maker's signature on $\displaystyle{ B }$.

A block maker will broadcast its block proposal to all other replicas.

## Notarization

A block is effectively added to the tree of blocks when it becomes notarized. For a block to become notarized, $\displaystyle{ n-f }$ distinct replicas must support its notarization.

Given a proposed block $\displaystyle{ B }$ at height $\displaystyle{ h }$, a replica will determine if the proposal is valid, which means that $\displaystyle{ B }$ has the syntactic form described above. In particular, $\displaystyle{ B }$ should contain the hash of a block $\displaystyle{ B' }$ of height $\displaystyle{ h' }$ that is already in the tree of blocks (i.e., already notarized). In addition, the payload of $\displaystyle{ B }$ must satisfy certain conditions (in particulat, all of the transaction requests in the payload must satisfy various constraints, but these constraints are unrelated to consensus). Also, the rank of the block maker (as recorded in the block $\displaystyle{ B }$) must match the rank assigned in round $\displaystyle{ h }$ by the random beacon to the replica that proposed the block (as recorded in the block proposal) .

If the block is valid and certain other constraints hold, the replica will support the notarization of the block by broadcasting a notarization share for $\displaystyle{ B }$, consisting of

• the hash of $\displaystyle{ B }$,
• the height $\displaystyle{ h }$ of $\displaystyle{ B }$,
• the identity of the supporting replica, and
• the supporting replica's signature on a message comprising the hash of $\displaystyle{ B }$ and the height $\displaystyle{ h }$.

Any set of $\displaystyle{ n-f }$ notarization shares on $\displaystyle{ B }$ may be aggregated together to form a notarization for $\displaystyle{ B }$, consisting of

• the hash of $\displaystyle{ B }$,
• the height $\displaystyle{ h }$ of $\displaystyle{ B }$,
• the set of identities of the $\displaystyle{ n-f }$ supporting replicas,
• an aggregation of the $\displaystyle{ n-f }$ signatures on the message comprising the hash of $\displaystyle{ B }$ and the height $\displaystyle{ h }$.

As soon as a replica obtains a notarized block of height $\displaystyle{ h }$, it will finish round $\displaystyle{ h }$, and will subsequently not support the notarization of any other blocks at height $\displaystyle{ h }$. At this point in time, such a replica will also relay this notarization to all other replicas. Note that this replica may have obtained the notarization either by (1) receiving it from another replica, or (2) aggregating $\displaystyle{ n-f }$ notarization shares that it has received.

The growth invariant states that each honest replica will eventually complete each round and start the next, so that the tree of notarized blocks continues to grow (and this holds only assuming asynchronous eventual delivery, and not partial synchrony). The proof of growth invariant can be found below.

## Finalization

There may be more than one notarized block at a given height $\displaystyle{ h }$. However, if a block is finalized, then it is sure that there is no other notarized block at height $\displaystyle{ h }$. Let us call this the safety invariant.

For a block to become finalized, $\displaystyle{ n-f }$ distinct replicas must support its finalization. Recall that round $\displaystyle{ h }$ ends for a replica when it obtains a notarized block $\displaystyle{ B }$ of height $\displaystyle{ h }$. At that point in time, such a replica will check if it supported the notarization of any block at height $\displaystyle{ h }$ other than block $\displaystyle{ B }$ (it may or may not have supported the notarization of $\displaystyle{ B }$ itself). If not, the replica will support the finalization of $\displaystyle{ B }$ by broadcasting a finalization share for $\displaystyle{ B }$. A finalization share has exactly the same format as a notarization share (but is tagged in such a way notarization shares and finalization shares cannot be confused with one another). Any set of $\displaystyle{ n-f }$ finalization shares on $\displaystyle{ B }$ may be aggregated together to form a finalization for $\displaystyle{ B }$, which has exactly the same format as a notarization (but again, is appropriately tagged). Any replica that obtains a finalized block will broadcast the finalization to all other replicas.

The proof of safety invariant can be found below. One consequence of the safety invariant is the following. Suppose two blocks $\displaystyle{ B }$ and $\displaystyle{ B' }$ are finalized, where $\displaystyle{ B }$ has height $\displaystyle{ h }$, $\displaystyle{ B' }$ has height $\displaystyle{ h'\le h }$. Then the safety invariant implies that the path in the tree of notarized blocks ending at $\displaystyle{ B' }$ is a prefix of the path ending at $\displaystyle{ B }$ (if not, then there would be two notarized blocks at height $\displaystyle{ h' }$, contradicting the finalization invariant). Thus, whenever a replica sees a finalized block $\displaystyle{ B }$, it may view all ancestors of $\displaystyle{ B }$ as being implicitly finalized, and because of the safety invariant, the safety property is guaranteed to hold for these (explicitly and implicitly) finalized blocks.

## Delay functions

The protocol makes use of two delay functions, $\displaystyle{ \Delta_\textrm{m} }$ and $\displaystyle{ \Delta_\textrm{n} }$, which control the timing of block making and notarization activity. Both of these functions map the rank $\displaystyle{ r }$ of the proposing replica no a nonnegative delay amount, and it is assumed that each function is monotonely increasing in $\displaystyle{ r }$, and that $\displaystyle{ \Delta_\textrm{m}(r) \le \Delta_\textrm{n}(r) }$ for all $\displaystyle{ r = 0, \ldots, n-1 }$. The recommended definition of these functions is $\displaystyle{ \Delta_\textrm{m}(r) = 2 \delta r }$ and $\displaystyle{ \Delta_\textrm{n}(r) = 2 \delta r + \epsilon }$, where $\displaystyle{ \delta }$ is an upper bound on the time to deliver messages from one honest replica to another, and $\displaystyle{ \epsilon \ge 0 }$ is a "governor" to keep the protocol from running too fast. With these definitions, liveness will be ensured in those rounds in which (1) the leader is honest, and (2) messages really are delivered between honest parties within time $\displaystyle{ \delta }$. Indeed, if (1) and (2) both hold in a given round, then the block proposed by the leader in that round will be finalized. Let us call this the liveness invariant. The proof of liveness invariant can be found below.

## An example

The figure above illustrates a block tree. Each block is labeled with its height (30, 31, 32, ...) and the rank of its block maker. The figure also shows that each block in the tree is notarized, as indicated by the diamond-N symbol. This means that for each notarized block in the tree, at least $\displaystyle{ n-f }$ distinct replicas supported its notarization. As one can see, there can be more than one notarized block in the tree at a given height. For example, at height 31, note there are two notarized blocks, proposed by block makers of rank 1 and 2. The same thing happens at height 34. Note that the block at height 36 is also explicitly finalized, as indicated by the diamond-F symbol. This means that $\displaystyle{ n-f }$ distinct replicas supported this block's finalization, which means that these replicas (or at least, the honest replicas among these) did not support the notarization of any other block. All of the ancestors of this block, which are shaded gray, are considered implicitly finalized.

## Putting it all together

This section describes in more detail how the protocol works; specifically, this section describes more precisely when a replica will propose a block and when a replica will support the notarization of a block. A given replica $\displaystyle{ P }$ will record the time at which it enters a given round $\displaystyle{ h }$, which happens when it has obtained (1) some notarization for a block of height $\displaystyle{ h-1 }$, and (2) the random beacon for round $\displaystyle{ h }$. Since the random beacon for round $\displaystyle{ h }$ has been determined, $\displaystyle{ P }$ can determine its own rank $\displaystyle{ r_P }$, as well as the rank $\displaystyle{ r_Q }$ of each other replica $\displaystyle{ Q }$ for round $\displaystyle{ h }$.

### Random beacon details

As soon as a replica enters round $\displaystyle{ h }$, it will generate and broadcast its share of the random beacon at round $\displaystyle{ h+1 }$.

### Block making details

Replica $\displaystyle{ P }$ will only propose its own block $\displaystyle{ B_P }$ provided (1) at least $\displaystyle{ \Delta_\textrm{m}(r_P) }$ time units have passed since the beginning of the round, and (2) there is no valid lower ranked block currently seen by $\displaystyle{ P }$.

Note that since $\displaystyle{ P }$ is guaranteed to have a notarized block of height $\displaystyle{ h-1 }$ when it enters round $\displaystyle{ h }$, it can make its proposed block a child of this notarized block (or any other notarized block of height $\displaystyle{ h-1 }$ that it may have). Also note that when $\displaystyle{ P }$ broadcasts its proposal for $\displaystyle{ B_P }$, it must also ensure that it also has relayed the notarization of $\displaystyle{ B_P }$'s parent to all replicas.

Suppose a replica $\displaystyle{ Q }$ sees a valid block proposal from a replica $\displaystyle{ P }$ of rank $\displaystyle{ r_P \lt r_Q }$ such that (1) at least $\displaystyle{ \Delta_\textrm{m}(r_P) }$ time units have passed since the beginning of the round, and (2) there is no block of rank less than $\displaystyle{ r_P }$ currently seen by $\displaystyle{ Q }$. Then at this point in time, if it has not already done so, $\displaystyle{ Q }$ will relay this block proposal (along with the notarization of the proposed block's parent) to all other replicas.

### Notarization details

Replica $\displaystyle{ P }$ will support the notarization of a valid block $\displaystyle{ B_Q }$ proposed by a replica $\displaystyle{ Q }$ of rank $\displaystyle{ r_Q }$ provided (1) at least $\displaystyle{ \Delta_\textrm{n}(r_Q) }$ time units have passed since the beginning of the round, and (2) there is no block of rank less than $\displaystyle{ r_Q }$ currently seen by $\displaystyle{ P }$.

### Proof of growth invariant

The growth invariant states that each honest replica will eventually complete each round and start the next. Assume that all honest replicas have started round $\displaystyle{ h }$. Let $\displaystyle{ r^* }$ be the rank of the lowest ranked honest replica $\displaystyle{ P^* }$ in round $\displaystyle{ h }$. Eventually, $\displaystyle{ P^* }$ will either (1) propose its own block, or (2) relay a valid block proposed by a lower ranked replica. In either case, some block must eventually be supported by all honest replicas, which means that some block will become notarized and all honest replicas will finish round $\displaystyle{ h }$. All honest replicas will also receive the shares needed to construct the random beacon for round $\displaystyle{ h+1 }$, and so will start round $\displaystyle{ h+1 }$.

### Proof of safety invariant

The safety invariant states that if a block is finalized in a given round, then no other block may be notarized in that round. Here is a proof of the safety invariant:

1. Suppose that the number of corrupt parties is exactly $\displaystyle{ f^* \le f \lt n/3 }$.
2. If a block $\displaystyle{ B }$ is finalized, then its finalization must have been supported by a set $\displaystyle{ S }$ of at least $\displaystyle{ n-f-f^* }$ honest replicas (by the security property for aggregate signatures).
3. Suppose (by way of contradction) that another block $\displaystyle{ B' \ne B }$ were notarized. Then its notarization must have been supported by a set $\displaystyle{ S' }$ of at least $\displaystyle{ n-f-f^* }$ honest replicas (again, by the security property for aggregate signatures).
4. The sets $\displaystyle{ S }$ and $\displaystyle{ S' }$ are disjoint (by the finalization logic).
5. Therefore, $\displaystyle{ n-f^* \ge |S \cup S'| = |S| + |S'| \ge 2 (n-f-f^*) }$, which implies $\displaystyle{ n \le 3f }$, a contradiction.

### Proof of liveness invariant

It is said that the network is $\displaystyle{ \delta }$-synchronous at time $\displaystyle{ t }$ if if all messages that have been sent by honest replicas at or before time $\displaystyle{ t }$ arrive at their destinations before time $\displaystyle{ t+\delta }$.

The liveness invariant may be stated as follows. Suppose that $\displaystyle{ \Delta_\mathrm{n}(1) \ge \Delta_\mathrm{m}(0) + 2\delta }$. Also suppose that in a given round $\displaystyle{ h }$,

• the leader $\displaystyle{ P }$ in round $\displaystyle{ h }$ is honest,
• the first honest replica $\displaystyle{ Q }$ to enter round $\displaystyle{ h }$ does so at time $\displaystyle{ t }$, and
• the network is $\displaystyle{ \delta }$-synchronous at times $\displaystyle{ t }$ and $\displaystyle{ t+\delta+\Delta_\mathrm{m}(0) }$.

Then the block proposed by $\displaystyle{ P }$ in round $\displaystyle{ h }$ will be finalized.

Here is a proof of the liveness invariant:

1. Under partial synchrony at time $\displaystyle{ t }$, all honest replicas will enter round $\displaystyle{ h }$ before time $\displaystyle{ t+\delta }$ (the notarization that ended round $\displaystyle{ h-1 }$ for $\displaystyle{ Q }$, as well as the necessary round $\displaystyle{ h }$ random beacon shares, will arrive at all honest replicas before this time).
2. The leader $\displaystyle{ P }$ in round $\displaystyle{ h }$ will propose a block $\displaystyle{ B }$ before time $\displaystyle{ t+\delta+\Delta_\mathrm{m}(0) }$, and again by partial synchrony, this block proposal will be delivered to all other replicas before time $\displaystyle{ t+2\delta+\Delta_\mathrm{m}(0) }$.
3. Since $\displaystyle{ \Delta_\mathrm{n}(1) \ge \Delta_\mathrm{m}(0) + 2\delta }$, the protocol logic guarantees that each honest replica supports the notarization of block $\displaystyle{ B }$ and no other block, and thus $\displaystyle{ B }$ will become notarized and finalized.

## Other issues

### Growth latency

Under a partial synchrony assumption, a quantitative version of the growth invariant can also be formulated and proven. For simplicity, assume that the delay functions are defined as recommended above: $\displaystyle{ \Delta_\textrm{m}(r) = 2 \delta r }$ and $\displaystyle{ \Delta_\textrm{n}(r) = 2 \delta r + \epsilon }$, and further assume that $\displaystyle{ \epsilon \le \delta }$. Suppose that at time $\displaystyle{ t }$, the highest numbered round entered by any honest replica is $\displaystyle{ h }$. Let $\displaystyle{ r^* }$ be the rank of the lowest ranked honest replica $\displaystyle{ P^* }$ in round $\displaystyle{ h }$. Finally, suppose that the network is $\displaystyle{ \delta }$-synchronous at all times in the interval $\displaystyle{ [t,t+(3r^*+2)\delta] }$. Then all honest replicas will start round $\displaystyle{ h+1 }$ before time $\displaystyle{ t+3(r^*+1)\delta }$.

When a replica does not see any finalized blocks for several rounds, it will start increasing its own delay function $\displaystyle{ \Delta_\textrm{n} }$ for notarization. Replicas need not agree on these locally adjusted notarization delay functions.
Also, while replicas do not explicitly adjust the delay function $\displaystyle{ \Delta_\textrm{p} }$, local clock drift can be mathematically modeled by locally adjusting both delay functions.
Thus, there are many delay fucntions, parameterized by replica and round. The critical condition $\displaystyle{ \Delta_\mathrm{n}(1) \ge \Delta_\mathrm{m}(0) + 2\delta }$ needed for liveness then becomes $\displaystyle{ \max \Delta_\mathrm{n}(1) \ge \min \Delta_\mathrm{m}(0) + 2\delta }$, where the $\displaystyle{ \max }$ and $\displaystyle{ \min }$ are taken over all the honest replicas in a given round. Thus, if finalization fails for enough rounds, all honest replicas will eventually increase their notarization delay until this holds and finalization will then resume. If some honest replicas increase their notarization latency function more than other replicas, there is no penalty in terms of liveness (but there may be in terms of growth latency).