What is blockchain? How Does Blockchain Work?

by Admin
5 comments 718 views 21 minutes read

What is blockchain?

A blockchain is a list of data records that works as a decentralized digital ledger. The data is organized into blocks, which are chronologically arranged and secured by cryptography

The earliest model of a blockchain was created in the early 1990s when computer scientist Stuart Haber and physicist W. Scott Stornetta employed cryptographic techniques in a chain of blocks as a way to secure digital documents from data tampering. 

The work of Haber and Stornetta certainly inspired the work of many other computer scientists and cryptography enthusiasts – which eventually led to the creation of Bitcoin as the first decentralized electronic cash system (or simply the first cryptocurrency).

Although blockchain technology is older than cryptocurrencies, it was only after the creation of Bitcoin in 2008 that its potential started to be recognized. Since then, the interest in blockchain technology has been growing gradually, and cryptocurrencies are now being acknowledged on a larger scale.

Blockchain technology is mostly used to record cryptocurrency transactions, but it suits many other kinds of digital data and can be applied to a wide range of use cases. The oldest, safest, and largest blockchain network is Bitcoin, which was designed with a careful and balanced combination of cryptography and game theory.

Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial

This course will give you a full introduction into all of the core concepts in blockchain, smart contracts, solidity, NFTs/ERC721s, ERC20s, Coding Decentralized Finance (DeFi), python and solidity, Chainlink, Ethereum, upgradable smart contracts, and full stack blockchain development.

How does blockchain work?

In the context of cryptocurrencies, a blockchain consists of a stable chain of blocks, each one storing a list of previously confirmed transactions.  Since the blockchain network is maintained by a myriad of computers spread around the world, it functions as a decentralized database (or ledger). This means that each participant (node) maintains a copy of the blockchain data, and they communicate with each other to ensure that they are all on the same page (or block).

Therefore, blockchain transactions occur within a peer-to-peer global network and this is what makes Bitcoin a decentralized digital currency that is borderless, and censorship-resistant. In addition, most blockchain systems are considered trustless because they do not require any kind of trust. There is no single authority in control of Bitcoin.

A central part of almost every blockchain is the process of mining, which relies on hashing algorithms. Bitcoin uses the SHA-256 algorithm (Secure hash algorithm 256 bits). It takes an input of any length and generates an output that will always have the same length. The output produced is called a “hash” and, in this case, is always made of 64 characters (256bits).

So the same input will result in the same output, no matter how many times the process is repeated. But if a small change is made to the input, the output will change completely. As such, hash functions are deterministic, and in the cryptocurrency world, most of them are designed as a one-way hash function.

Being a one-way function means that it is almost impossible to calculate what was the input from the output. One can only guess what the input was, but the odds of guessing it right are extremely low. This is one of the reasons why Bitcoin’s blockchain is secure.

Now that we know what the algorithm does, let’s demonstrate how a blockchain works with a simple example of a transaction.

Imagine that we have Alice and Bob along with their Bitcoin balance. Let’s say Alice owes Bob 2 Bitcoins.

For Alice to send Bob that 2 bitcoin, Alice broadcasts a message with the transaction that she wants to make to all the miners in the network.

In that transaction, Alice gives the miners Bob’s address and the amount of Bitcoins she would like to send, along with a digital signature and her public key. The signature is made with Alice’s private key, and the miners can validate that Alice, in fact, is the owner of those coins.

Once the miners are sure that the transaction is valid, they can put it in a block along with many other transactions and attempt to mine the block. This is done by putting the block through the SHA-256 algorithm. The output needs to start with a certain amount of 0’s in order to be considered valid. The amount of 0’s needed depends on what’s called the “difficulty,” which changes depending on how much computing power there is on the network.

In order to produce an output hash with the desired amount of 0’s in the beginning, the miners add what’s called a “nonce” into the block before running it through the algorithm. Since a small change to the input completely changes the output, the miners try random nonces until they find a valid output hash.

Once the block is mined, the miner broadcasts that newly mined block to all the other miners. They then check to make sure that the block is valid so that they can add it to their copy of the blockchain and the transaction is complete. But in the block, the miners also need to include the output hash from the previous block so that all blocks are tied together, hence the name blockchain. This is an important part because of the way trust works in the system.

Every miner has their own copy of the blockchain on their computer, and everyone trusts whichever blockchain that has the most computational work put into it, the longest blockchain. If a miner changes a transaction in a previous block, the output hash for that block will change, which leads to all the hashes after it changing as well due to the blocks being liked with hashes. The miner would have to redo all of the work in order to make anyone accept his blockchain as the right one. So if a miner wanted to cheat, he would need more than 50% of the network’s computing power, which is very unlikely. Network attacks like this are thereby called 51% attacks.

The model of making computers work in order to produce blocks is called Proof-of-Work (PoW) there are also other models like Proof-of-Stake (PoS) which do not require as much computing power and are meant to require less electricity while being able to scale to more users.

Proof of work (PoW)

Proof of Work (commonly abbreviated to PoW) is a mechanism for preventing double-spends. Most major cryptocurrencies use this as their consensus algorithm. That’s just what we call a method for securing the cryptocurrency’s ledger.

Proof of Work was the first consensus algorithm to surface, and, to date, remains the dominant one. It was introduced by Satoshi Nakamoto in the 2008 Bitcoin white paper, but the technology itself was conceived long before then. 

Adam Back’s HashCash is an early example of a Proof of Work algorithm in the pre-cryptocurrency days. By requiring senders to perform a small amount of computing before sending an email, receivers could mitigate spam. This computation would cost virtually nothing to a legitimate sender, but quickly add up for someone sending emails en masse.

What is a double-spend?

A double-spend occurs when the same funds are spent more than once. The term is used almost exclusively in the context of digital money – after all, you’d have a hard time spending the same physical cash twice. When you pay for a coffee today, you hand cash over to a cashier who probably locks it in a register. You can’t go to the coffee shop across the road and pay for another coffee with the same bill.

In digital cash schemes, there’s the possibility that you could. You’ve surely duplicated a computer file before – you just copy and paste it. You can email the same file to ten, twenty, fifty people. 

Since digital money is just data, you need to prevent people from copying and spending the same units in different places. Otherwise, your currency will collapse in no time. 

For a more in-depth look at double-spending, check out Double Spending Explained.

Why is Proof of Work necessary?

If you’ve read our guide to blockchain technology, you’ll know that users broadcast transactions to the network. Those transactions aren’t immediately considered valid, though. That only happens when they get added to the blockchain. 

The blockchain is a big database that every user can see, so they can check if funds have been spent before. Picture it like this: you and three friends have a notepad. Anytime one of you wants to make a transfer of whatever units you’re using, you write it down – Alice pays Bob five units, Bob pays Carol two units, etc.

There’s another intricacy here – each time you make a transaction, you refer to the transaction where the funds came from. So, if Bob was paying Carol with two units, the entry would actually look like the following: Bob pays Carol two units from this earlier transaction with Alice.

Now, we have a way to track the units. If Bob tries to make another transaction using the same units he just sent to Carol, everyone will know immediately. The group won’t allow the transaction to be added to the notepad.

Now, this might work well in a small group. Everyone knows each other, so they’ll probably agree on which of the friends should add transactions to the notepad. What if we want a group of 10,000 participants? The notepad idea doesn’t scale well, because nobody wants to trust a stranger to manage it.

This is where Proof of Work comes in. It ensures that users aren’t spending money that they don’t have the right to spend. By using a combination of game theory and cryptography, a PoW algorithm enables anyone to update the blockchain according to the rules of the system.

How does PoW work?

Our notepad above is the blockchain. But we don’t add transactions one by one – instead, we lump them into blocks. We announce the transactions to the network, then users creating a block will include them in a candidate block. The transactions will only be considered valid once their candidate block becomes a confirmed block, meaning that it has been added to the blockchain.

Appending a block isn’t cheap, however. Proof of Work requires that a miner (the user creating the block) uses up some of their own resources for the privilege. That resource is computing power, which is used to hash the block’s data until a solution to a puzzle is found.

Hashing the block’s data means that you pass it through a hashing function to generate a block hash. The block hash works like a “fingerprint” – it’s an identity for your input data and is unique to each block.

It’s virtually impossible to reverse a block hash to get the input data. Knowing an input, however, it’s trivial for you to confirm that the hash is correct. You just have to submit the input through the function and check if the output is the same.

In Proof of Work, you must provide data whose hash matches certain conditions. But you don’t know how to get there. Your only option is to pass your data through a hash function and to check if it matches the conditions. If it doesn’t, you’ll have to change your data slightly to get a different hash. Changing even one character in your data will result in a totally different result, so there’s no way of predicting what an output might be.

As a result, if you want to create a block, you’re playing a guessing game. You typically take information on all of the transactions that you want to add and some other important data, then hash it all together. But since your dataset won’t change, you need to add a piece of information that is variable. Otherwise, you would always get the same hash as output. This variable data is what we call a nonce. It’s a number that you’ll change with every attempt, so you’re getting a different hash every time. And this is what we call mining.

Summing up, mining is the process of gathering blockchain data and hashing it along with a nonce until you find a particular hash. If you find a hash that satisfies the conditions set out by the protocol, you get the right to broadcast the new block to the network. At this point, the other participants of the network update their blockchains to include the new block.

For major cryptocurrencies today, the conditions are incredibly challenging to satisfy. The higher the hash rate on the network, the more difficult it is to find a valid hash. This is done to ensure that blocks aren’t found too quickly.

As you can imagine, trying to guess massive amounts of hashes can be costly on your computer. You’re wasting computational cycles and electricity. But the protocol will reward you with cryptocurrency if you find a valid hash.

Let’s recap what we know so far:

  • It’s expensive for you to mine.

  • You’re rewarded if you produce a valid block.

  • Knowing an input, a user can easily check its hash – non-mining users can verify that a block is valid without expending much computational power.

So far, so good. But what if you try to cheat? What’s to stop you from putting a bunch of fraudulent transactions into the block and producing a valid hash?

That’s where public-key cryptography comes in. We won’t go into depth in this article, but check out What is Public-Key Cryptography? for a comprehensive look at it. In short, we use some neat cryptographic tricks that allow any user to verify whether someone has a right to move the funds they’re attempting to spend.

When you create a transaction, you sign it. Anyone on the network can compare your signature with your public key, and check whether they match. They’ll also check if you can actually spend your funds and that the sum of your inputs is higher than the sum of your outputs (i.e., that you’re not spending more than you have).

Any block that includes an invalid transaction will be automatically rejected by the network. It’s expensive for you to even attempt to cheat. You’ll waste your own resources without any reward.

Therein lies the beauty of Proof of Work: it makes it expensive to cheat, but profitable to act honestly. Any rational miner will be seeking ROI, so they can be expected to behave in a way that guarantees revenue.

Proof of Stake (PoS)

Proof of Stake is a popular, alternative consensus mechanism to Proof of Work. Instead of needing computing power to validate transactions, validators must stake coins. This fact drastically reduces the energy consumption needed. Proof of Stake also improves decentralization, security, and scalability. 

However, Proof of Stake can be less accessible to get in without access to crypto. A 51% attack can also be easy to achieve with low market cap blockchains. As Proof of Stake is highly versatile, it has a wide range of variations for different blockchains and use cases.

Introduction

Proof of Stake is by far the most popular choice for blockchain networks today. But with so many variations, it can be tricky to understand its core concepts. Nowadays, you’re unlikely to see it in its original form. Nevertheless, all kinds of Proof of Stake share the same key core concepts. Understanding these similarities will help you make better choices about the blockchains you use and how they operate.

What does Proof of Stake mean?

The Proof of Stake consensus algorithm was introduced back in 2011 on the Bitcointalk forum. It was proposed as a solution to Proof of Work’s problems. While they both share the same goal of reaching blockchain consensus, the process they take is quite different. Rather than need to provide a computationally intensive proof, participants only prove they have staked coins.

How does Proof of Stake work?

The Proof Of Stake algorithm uses a pseudo-random election process to select validators from a group of nodes. The system uses a combination of factors, including staking age, an element of randomization, and the node’s wealth.

In Proof of Stake systems, blocks are ‘forged’ rather than mined. However, you still might hear the term ‘mined’ occasionally used. Most Proof of Stake cryptocurrencies launch with a supply of ‘pre-forged’ coins to allow nodes to start immediately.

Users participating in the forging process must lock a certain amount of coins into the network as their stake. The stakes’ size determines the chances for a node to be selected as the next validator – the bigger the stake, the larger the chances. Unique methods are added into the selection process to favor not just the wealthiest nodes in the network. The two most commonly used methods are Randomized Block Selection and Coin Age Selection.

Randomized Block Selection

In the Randomized Block Selection method, the validators are selected by looking for nodes with a combination of the lowest hash value and the highest stake. Since the sizes of stakes are public, the next forger can usually be predicted by other nodes.

Coin Age Selection

The Coin Age Selection method chooses nodes based on how long their tokens have been staked. Coin age is calculated by multiplying the number of days the coins have been staked by the number of coins staked. 

Once a node has forged a block, its coin age is reset to zero, and it must wait a certain period to be able to forge another block – this prevents large stake nodes from dominating the blockchain.

Validating transactions

Each cryptocurrency using a Proof of Stake algorithm has its own set of rules and methods combined for what it thinks is the best possible combination for the network and its users.

When a node gets chosen to forge the next block, it will check if the transactions in the block are valid. It then signs the block and adds it to the blockchain. As a reward, the node receives the transaction fees from the block and, on some blockchains, a coin reward.

If a node wants to stop being a forger, its stake and earned rewards will be released after a certain period, giving the network time to verify that there are no fraudulent blocks added to the blockchain by the node.

Which blockchains use Proof of Stake?

Most blockchains post-Ethereum use Proof of Stake consensus mechanisms. Typically, each one is modified to suit the needs of the network. We’ll cover these variations later on in the article. Ethereum itself is currently in the process of moving to Proof of Stake with Ethereum 2.0.

Blockchain networks that use Proof of Stake or a form of it include:

1. BNB Chain

2. BNB Smart Chain

3. Solana

4. Avalanche

5. Polkadot

Advantages of Proof of Stake

Proof of Stake has many clear advantages over Proof of Work. For this reason, new blockchains almost always use Proof of Stake. Its benefits include:

Adaptability

As users’ needs and blockchains change, so can Proof of Stake. It’s plain to see this with the vast number of adaptations available. The mechanism is versatile and can easily fit most blockchain use cases.

Decentralization

More users are encouraged to run nodes since it’s more affordable. This incentive and the randomization process also make the network more decentralized. Although staking pools exist, there is a much higher chance for an individual to forge a block under Proof of Stake successfully. Overall, this reduces the need for staking pools. 

Energy efficiency

Proof of Stake is incredibly energy efficient compared to Proof of Work. The cost of participating relies on the economic cost of staking coins rather than the computational cost of solving puzzles. This mechanism leads to a significant reduction in the energy required to run the consensus mechanism.

Scalability

As Proof of Stake doesn’t rely on physical machines to generate consensus, it’s more scalable. There’s no need for huge mining farms or sourcing large energy supplies. Adding more validators to the network is cheaper, simpler, and more accessible. 

Security

Staking works as a financial motivator for the validator not to process fraudulent transactions. If the network detects a fraudulent transaction, the validator will lose a part of its stake and its right to participate in the future. So as long as the stake is higher than the reward, the validator would lose more coins than it would gain with fraudulent activity.

To effectively control the network and approve fraudulent transactions, a node would have to own a majority stake in the network, also known as the 51% attack. Depending on the value of a cryptocurrency, it can be almost impossible to gain control of the network, as you would need to acquire 51% of the circulating supply. 

However, this can also be a disadvantage which we will explain below.

Disadvantages of Proof of Stake

Although Proof of Stake has many advantages compared to Proof of Work, it still has some weaknesses:

Forking

With a standard Proof of Stake mechanism, there’s no disincentive for mining both sides of a fork. Under Proof of Work, mining both sides will lead to a waste of energy. With Proof of Stake, the cost is much less, meaning that people can “bet” on both sides of a fork.

Accessibility

To begin staking, you’ll need a blockchain’s native token supply. This requires you to purchase the token via an exchange or other method. Depending on the amount required, you may need a significant investment to begin staking effectively. 

With Proof of Work, you can buy cheap mining equipment or even rent it. With this, you can join a pool and start validating and earning quickly.

51% attack

While Proof of Work is also prone to 51% attacks, they can be significantly easier with Proof of Stake. If a token’s price crashes or the blockchain has a low market capitalization, it can be theoretically cheap to purchase more than 50% of the tokens and control the network.

Proof of Work vs. Proof of Stake

When we compare the two consensus mechanisms, there are a few core differences.

 

Proof of Work (PoW)

Proof of Stake (PoS)

Equipment required

Mining equipment

Minimal amount or none

Energy consumption

High

Low

Tendency towards

Centralization

Decentralization

Validation method

Computational proof

Staking of coins

However, there’s a wide variety of Proof of Stake mechanisms across blockchains. Many differences will depend on the exact mechanism used.

Other consensus mechanisms that build on Proof of Stake

Proof of Stake is highly adaptable. Developers can change the exact mechanism to suit a blockchain’s specific use cases. Below are some of the most commonly seen  

Delegated Proof of Stake (DPoS)

Delegated Proof of Stake allows users to stake coins without becoming a validator. In this case, they stake them behind a validator to share in the block rewards. The more delegators stake behind a possible validator, the greater its selection chance. Validators can usually change the amount shared with delegators as an incentive. A validator’s reputation is also an important factor for delegators.

Nominated Proof of Stake (NPoS)

Nominated Proof of Stake is a consensus model developed by Polkadot. It has many similarities with Delegated Proof of Stake, but one key difference. If a nominator (delegator) stakes behind a malicious validator, they can also lose their stake. 

Nominators can choose up to 16 validators to stake behind. The network will then equally distribute their stake behind the chosen validators. Polkadot also uses several approaches in game theory and election theory to determine who will forge a new block.

Proof of Staked Authority (PoSA)

BNB Smart Chain uses Proof of Staked Authority to generate network consensus. This consensus mechanism combines Proof of Authority and Proof of Stake, letting validators take turns to forge blocks. A group of 21 active validators is eligible to take part, selected by the amount of BNB they stake or have delegated behind them. This set is determined daily, and BNB Chain stores the selection.

You may also like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

-
00:00
00:00
Update Required Flash plugin
-
00:00
00:00