Understanding slot battles

Published 4.8.2023

Cardano's PoS is based on the Nakamoto consensus. Thus, it is only possible to achieve the so-called probabilistic finality of blocks. Therefore, it sometimes happens that pools produce blocks that will be orphaned. We will talk about the circumstances under which this happens and how the network can deal with it.

How blocks are minted in the Cardano network

A Cardano epoch lasts 5 days and is divided into so-called slots with a length of one second. So there are 432,000 slots in an epoch. The randomness of the Cardano protocol is configured to produce a block approximately every 20 seconds. Thus, approximately 21,600 blocks can be created in each epoch.

Each registered pool is a potential candidate that can mint a block in a specific slot. A node that gets the right to mint a block is called a slot leader. The selection of slot leaders must be random. The network runs a lottery that is not dependent on any central control. Individual nodes can autonomously find out if they have won the lottery in a given slot, i.e. if they can produce a new block.

A cryptographic primitive called Verifiable Random Function (VRF) is used to draw the slot leader. VRF was Introduced by Micali, Rabin, and Vadhan in 1999 and is used in various cryptographic schemes, protocols, and systems.

The basic concept of VRF is simple. The owner of the secret key can compute the output value as well as an associated proof for any input value. Everyone else, using the proof and the associated public key (verification key), can check that the output value was indeed calculated correctly.

In the Cardano network, only a node that creates the necessary certificate and stores it in the blockchain can mint blocks. Through registration certificates, all necessary information (including verification keys) is stored in the blockchain. Thus, all nodes have all the relevant information to validate the blocks (and proofs) produced by other nodes.

When a node receives a block from the network, it can verify that it is valid through the VRF proof and that it was created by a node that was really the leader in that slot.

The VRF algorithm takes multiple inputs to be able to evaluate whether a given node has become the slot leader in a specific slot. Besides others, these include the current slot ID and ⅔ of all VRF output from the previous epoch, from which a single hash (value) is created. This hash is also called a Nonce. Nonce makes it impossible to compute VRF results too far in advance.

Each node needs to calculate its threshold number. It is an easy task since it is derived from the size of the stake. The stake consists of ADA coins of the operator (pledge) and all stakers. The larger the stake, the more blocks the pool might produce in a given epoch.

Every second, every pool employs the VRF algorithm to get a VRF output. The VRF output is compared with the threshold. If the VRF output is less than the threshold, the pool has become the slot leader and gets the right to mint a new block.

In our example, NODE 7 became the slot leader. The VRF output was 28,454,834 and the threshold was 30,000,000. So the node mints a new block and inserts VRF proof (the VRF output) in the block header.

The VRF proof contained in the proposed block is used for validation. Any other node in the network uses the VRF algorithm to verify that the block is valid. In addition to VRF proof, the block must be signed by a KES key (Key Evolving Signature cryptography). This is the next level of security so that if an attacker were able to somehow break the operation of the VRF, they still don't have the operator’s KES keys to sign the blocks.

Who will win in the slot battle?

A slot battle occurs when 2 pools mint a block in the same slot. So there are two slot leaders in one slot. Thus, potentially two competing blocks. Only one block can be inserted into the blockchain per given slot, so one of them must be discarded. It is said that the latter gets orphaned.

In our example, NODE 7 became the slot leader since the VRF output was 28,454,834 which is less than the threshold of 30,000,000. In the same slot, also NODE 3 became the slot leader with the VRF output of 16,459,996 which is less than the threshold of 27,500,000.

Both nodes mint a new block, insert VRF output (VRF proof) into it and distribute it to other nodes in the Cardano network. A block that is orphaned does not count towards the pool reward. This means that only a single pool can receive a reward for a block produced in the same slot.

If the block distribution is fast (low delay), it is likely that many other nodes in the network will receive both blocks. So the block minted by NODE 7 with VRF output 28,454,834 and the block minted by NODE 3 with VRF output 16,459,996.

If a node receives two valid blocks for a single slot, it will choose the one with lower VRF output. A node discards a block with a higher VRF proof, essentially making it orphaned. Pools with a lower stake have an advantage in the slot battle because there is a greater chance that a lower VRF output will be produced.

You probably already know that in our example, the red block minted by NODE 3 won over the green block from NODE 7.

If a slot battle occurs, the winner is determined by randomness. Pool operators have no chance to influence block selection happening on other nodes in the network as long as they behave honestly.

From a blockchain perspective, the situation looks like this. There was a slot battle in slot N+40. A node receives two blocks minted in the same slot. It chooses the red block as the last block in the blockchain and discards the green one. Another block is minted in slot N+60 and the slot leader has correctly followed the red block. With each additional block added, it becomes more obvious that the chain behind the red block will remain in the blockchain forever while the green block will remain orphaned.

As we mentioned at the beginning, roughly 21,600 blocks can be minted in an epoch. The best result in the last few epochs was 21,417 blocks minted in epoch 411. Usually, in epochs around 20,900 to 21.11 blocks are minted. A node can become a slot leader and for some reason, it may not be able to mint a block (for example, because it is not online at the time it became a slot leader).

Slot battles occur relatively often, about 420 in each epoch, i.e. about 4 every hour. It is about 2% of the total number of blocks. It is therefore a good idea to wait several blocks before considering the block with your transaction as final. If there are about 4 slot battles per hour, I dare to say that waiting 6 blocks (2 minutes) is long enough to be sure that the block is final.

Conclusion

A block can become orphaned for another reason. If it does not reach the node that becomes the slot leader fast enough, the slot leader is forced to follow the previous block (the last one available). We'll talk about that next time.

Featured:

Related articles

Did you enjoy this article? Other great articles by the same author