# Gasper Protocol
###### tags: `thread`
As we all know, the consensus protocol of PoS Ethereum is “Gasper”, which is constructed by applying the Casper FFG (a finality gadget) on top of LMD-GHOST (fork-choice rule)
So if you want to figure out the full Ethereum consensus protocol, it’s necessary to understand these two Ingredients (Casper + Ghost). Besides, these designs are really fun

I plan to sort out the background and evolution of these two protocols, as well as their simple workflow (which is very interesting!), and I will introduce Gasper in another article in the future
## PoS consensus algorithm
There are three major schools of PoS consensus algorithm👇
- Nakamoto-inspired (Peercoin)
- PBFT-inspired (Tendermint, Casper FFG)
- CBC Casper
**Nakamoto-inspired PoS**
Nakamoto-inspired PoS is a chain-based algorithm that simulates mining in PoW. It will pseudo-randomly select validators to create new blocks
It was first proposed in the "[Peercoin](https://www.peercoin.net/read/papers/peercoin-paper.pdf)" paper in 2012, and peercoin is the first implementation of a proof-of-stake based Cryptocurrency
**PBFT-inspired PoS**
PBFT-inspired (also, BFT-style) PoS is based on years of research on Byzantine fault tolerance (especially pBFT). It was first proposed in the "[Tendermint](https://tendermint.com/static/docs/tendermint.pdf)" paper in 2014
In general, these algorithms will select a unique chain that represents the canonical transactions of the ledger
Casper directly inherits BFT algorithms (more precise is pBFT), with some modifications
**CBC Casper**
CBC Casper was proposed by @VladZamfir, there are some good sources that explain it more fully (we won't go into depth here)
- [vb’s CBC Casper tutorial](https://vitalik.ca/general/2018/12/05/cbc_casper.html)
- [The history of Casper by VZ](https://medium.com/@Vlad_Zamfir/the-history-of-casper-part-1-59233819c9a9)
- [a video intro by VZ](https://www.youtube.com/watch?v=GNGbd_RbrzE)
Although Ethereum finally chose Casper FFG over CBC Casper, the research of CBC Casper also brought a lot of value, such as the fork choice rule "LMD-GHOST" that just met Ethereum's needs
## Casper FFG
As for Casper FFG, [it was proposed by VitalikButerin and Virgil Griffith in 2017](https://arxiv.org/abs/1710.09437v4), which introduced the concepts of justification and finalization, and introduced slashing conditions and dynamic validators, which are very important features
Casper FFG is used to guarantee "finality" (also, safety), which is non-existent in PoW
Simply put, each validator will vote on the checkpoint, and after two rounds of voting, the checkpoint will be "finalized" (one for justified, two for finalized)

All finalized checkpoints become the canonical chain (part of the blockchain history), and all honest nodes agree that they will never revert
The blocks after the "finalized checkpoint" can be forked at will, but the previous blocks are not allowed to fork

In addition to ensuring blockchain security through “finality”, Casper FFG also introduces a slashing condition to punish all validators who violate the rule (which cannot be done in traditional BFT algorithms)
All validators who violate the rules will be tracked and punished
Besides that, Casper FFG is permissionless (traditional BFT algorithms are permissioned)
pBFT maintains consensus through a list, and only those who in the list can be participants. Casper FFG has built a dynamic validators mechanism, all validators can enter and exit freely
Casper FFG is used to guarantee "finality" and "safety", it is responsible for confirming the final state of the block, but not responsible for creating new blocks
So it needs the underlying blockchain and fork-choice rules
## LMD-GHOST
The fork-choice rule used by Ethereum is based on GHOST, which was first proposed in a 2013 [paper](https://eprint.iacr.org/2013/881.pdf)
In 2017, when @VladZamfir was working on [CBC Casper](https://github.com/vladzamfir/research/blob/master/papers/CasperTFG/CasperTFG.pdf), he tried to combine GHOST with Casper, resulting in a variant "LMD-GHOST"
The blockchain allows forks, when different branches appear, which chain should be selected to continue adding subsequent new blocks, the fork-choice rule is required
PoW uses the longest chain rule. The idea is that forging the longest chain requires the most computing power, so this chain is the most credible
So when all miners add new blocks, they will work on the longest chain by default

The idea of GHOST is similar, it chooses the chain with the most votes over the chain with the longest height
LMD-GHOST made a few modifications to only consider the most recent votes (so call “Least Message Driven”, LMD)

The rules of LMD-GHOST are very simple👇
- start at the genesis block
- each time there is a fork, choose the branch with more votes
- repeat, until you research the block leaf
- return the head of the chain

## Gasper
This is the evolution of Casper FFG and LMD-GHOST and how they work, together they guarantee "safety" + "liveness"👇
- LMD-GHOST allows proposers to create new blocks at any time, and new blocks will be added to the heaviest chain following the fork-choice rule (which is liveness)
- While Casper FFG will finalize a canonical chain based on the votes of all validators (two rounds, more than 2/3, by deposits)
All honest nodes accept canonical chain by default, thus grantee the safety

## Conclusions
Anyways, the consensus is really interesting, Ethereum's [research](https://blog.ethereum.org/2014/01/15/slasher-a-punitive-proof-of-stake-algorithm) on PoS started in 2014, and the merge was completed in 2022
It's been a long and winding road in which many fantastic ideas, designs, and engineering have been born
I am deeply attracted by the thinking behind the design and the history of blockchain evolution
It was a very pleasant experience, I hope you can feel it too!!
[Thread](https://twitter.com/LuozhuZhang/status/1579845478920749060?s=20&t=hf32T6kwnUQiTjAV1MfiLA)