Blocks in a Blockchain - how are they formed?

Blocks in a Blockchain - how are they formed?

Hashing, cryptocurrency mining and consensus mechanisms.

Table of contents

No heading

No headings in the article.

In my last article, I briefly explained what the blockchain is, what endears it to many people, and why they refer to it as the technology of the future. Today, things are going to get a bit technical and, of course, interesting. So grab your favorite drink and come along!

The BLOCKCHAIN is very literal in its naming. Yes, it is a distributed ledger, but transactions saved to it are saved into 'blocks,' and these blocks are linked together by a hash in a chain. A hash is a cryptographic function that changes a given value into a fixed-length value. Changing a single value in a hash changes the whole hash. This ensures security on the blockchain, as changing the hash of a single block tampers the entire blockchain since the hash of a new block is linked to the hash of the previous block. Read more about hashing here.

Each of these blocks has a timestamp(which is the time of creation in milliseconds measured from 01/01/1970), forming some linear sequence in time. On the Bitcoin blockchain, there are about 2500 transactions in each block, and on the Ethereum blockchain, there are about 70 transactions in each block. After the confirmation of each transaction, that transaction is distributed among participating nodes.

Now, these blocks - where do they come from, who creates them?

Blocks are mined(created) by miners. Miners are computers(owned by people or companies) running software on the Blockchain network that solve cryptographic puzzles to create blocks and confirm transactions to be entered into these blocks. They earn a reward for doing these tasks - both creating blocks and validating transactions. Once a block is mined on the network, it is distributed, and all other participating nodes add this block to the end of their blockchain by a consensus mechanism. Simply put, a consensus mechanism is a system that blockchains use to confirm, broadcast transactions, and conclude whether the mined transaction should be saved into a block or if a new block should be accepted and added to the blockchain. Consensus mechanisms allow distributed systems to work together and stay secure.

There are many consensus mechanisms - Proof of Work, Proof of Stake, Proof of Capacity, Proof of Authority, Proof of Elapsed Time, Proof of Knowledge, and many more. Proof of Work(PoW) and Proof of Stake(PoS) are two of the most popular consensus mechanisms used, and we're going to talk about them. Currently, Ethereum and Bitcoin blockchains use proof of work, with Ethereum planning to upgrade to proof of stake later in the year. Many other blockchains like(but not limited to) Cardano, Avalanche, and Solana already use proof of stake.

What goes on behind the hood - How does each consensus mechanism work?

1)Proof of Work(PoW) - This requires that nodes in the blockchain solve a complex, mathematical puzzle that requires very high computational power. It's something of a competition, and the first computer to solve this puzzle wins the reward attached to mining a block. To stand a good chance of winning, one would need to invest in very expensive mining hardware, and be ready to pay for computational power. On the Bitcoin blockchain, the reward for solving this puzzle(and mining a block in the process) is 6.25 BTC, while on the Ethereum blockchain, the reward for mining a block sits around 2 ETH. Solving the said puzzle creates a cryptographic link between the current block and the previous block, even if they have different miners.

How secure is PoW?

The network is kept secure by the fact that a person trying to manipulate the blockchain will need 51% of the total computing power being used at that point to be able to succeed. This would cost so much in equipment and energy that you're likely to end up not making any gains. For context, the Digiconomist's Bitcoin Energy Consumption Index estimated that 1 Bitcoin transaction takes 1,544 kWh to complete, or the equivalent of approximately 53 days of power for the average US household. Think about this in cost alone, multiplied by hundreds of transactions waiting to be mined. It is a lot of money.

2)Proof of Stake(PoS) - This is very different from proof of work, and it uses far less computational power. The process of selecting block creators using PoS is randomized. To participate in this system, miners(validators in this case) are required to stake some cryptocurrency. A validator is chosen at random to create new blocks, broadcast them, and earn rewards. You don't solve any complex mathematical puzzle, and energy is surely preserved.

How secure is PoS?

Again, an attacker would need 51% of the total staked cryptocurrency to be able to make any malicious move. Given that there are hundreds of thousands of nodes(for public blockchains), gathering 51% of the staked cryptocurrency of all nodes is no small feat. This means that an attacker has to buy up a lot of mining equipment and also stake a lot cryptocurrency to run a node. There is even no guarantee that buying up those pieces of equipment will make you own 51% of the network. Also, if any malicious move is suspected from any validator, they lose some of their staked cryptocurrency. An attacker will end up losing more than they stand to gain.

In conclusion

Proof of work and proof of stake are Sybil resistance mechanisms. Sybil resistance mechanisms protect against Sybil attacks. A Sybil attack is one in which a person or user pretends to be many users. PoW and PoS prevent Sybil attacks by making sure that users expend a lot of energy(in the case of PoW) or put up a lot of collateral(PoS). To have a clearer understanding, to be an independent node on the Ethereum PoS network, you would need to stake 32Eth. As of writing, 32ETH is $56,322.56. Imagine trying to pretend to be a lot of users, it will cost you $56,322.56 times as many people as you're pretending to be. That is a lot of money. It is also an uncertain risk as it is unlikely that an attacker would succeed.