# Consensus Algorithms¶

Within blockchain network there are several actions that could be undertaken and every one of them has to be validated. But what does it mean?

Validation within blockchain network is based on proofs which are wide known as

**Consensus Algorithms**. Consensus stands behind achieving agreement on such matter as confirm transaction or produce new blocks to the chain. Whenever one of those actions are requested, a consensus protocol is triggered. To reach a consensus majority of nodes has to agree on something. People can reach a consensus easily by voting on something and when majority of votes are the same, the consensus is reached. In computer world things have been different since simply voting would be too vulnerable to attack and too easy to get tampered. That’s why consensus algorithms are brought.There are plenty of different consensus algorithms, for example: Proof of Work, Proof of Authority, Proof of Stake, Proof of Burn and many more.

Right now Proof of Work is the most often used consensus algorithm but ethereum has plans to use Proof of Stake in the future. It’s worth to mention that Proof of Work (PoS) and Proof of Stake (PoS) are the two best known Sybil deterrence mechanisms. Which is why they are the most common mechanisms within cryptocurrency world.

## Proof of work¶

Understanding the name of this algorithm is pretty easy - you’ve got to proof that you’ve done some work. But what exactly does it mean?

A Proof of Work involves all nodes within a network to do some work and that means every computer has to take part in solving a complex mathematical problem. In simpler words, work means computer calculations.

But mentioned above mathematical problem solve isn’t based on the mathematic methods we know from school. Solving it can be done only by trial and error and the odds of solving the problem are about 1 in 5.9 trillion. That means it needs a lot of computing power which leads to large energy consumption. Solving the problem is known as mining and nodes taking part in it are miners. So to encourage miners to mine, this huge energy consumption must be profitable. And it is.

Because one computer would be solving this kind of problem for years, a whole chain is working altogether but not every node will win. The winner is the first node which would be able to solve the problem. That node shares requested action to the chain and gains freshly minted currency as a reward. Mining allows earning cryptocurrency without buying it.

To understand that better, let’s imagine a mine. Let’s put aside how mines works in reality to better explain it. To begin with, miner doesn’t know where gems are located so in purpose of find it, standing alone would have to work huge amount of time, digging one spot at time and having no certainty of finding anything. However with a team it would go much faster, since a bunch of people would dig in the same time, looking in different spots, even though founded gem would be received only by miner who found that first. But as they say, it’s all or nothing.

And now speaking more technically, first let’s establish that

**the cryptocurrency network sets a target hash**. We’ll need that information later.Mathematical problem to solve can be found in block’s header, which contains:

the block version number,

a timestamp,

the hash used in the previous block,

the hash of the Merkle Root,

the nonce,

the target hash.

All above creates a block hash, which in PoW, each node takes and calculates. Since a given set of data can only generate one hash, miners alter the input by adding an integer, called a nonce. When one node reaches the expected calculated value (finds correct nonce), it would broadcast the block to other nodes and all of them must mutually confirm the correctness of the hash value.

What is target hash?

Target hash is a numeric value which is used to determine how hard it is for the miners to solve the block.

What is nonce?

A nonce is an abbreviation for “number only used once”. It is one of the block header component and the number that blockchain miners are solving for. The nonce is the value that miners can alter to create different permutations and generate a correct hash.

The purpose of proof-of-work algorithms is to deterring manipulation of data.

## Proof of stake¶

In build