Hailed as a potential game changer in the financial industry, blockchain is the technology that ensures the security of cryptocurrency transactions. In this article, we’ll go over how blockchain works and how it protects your cryptocurrency transactions.
What is Blockchain?
Blockchain is a collection of blocks that contain data that linked and sequenced with each other. In other words, blockchain can be considered a digital data storage system. The most recent linked block must have the hash information from the previous block. Each block will lead to the previous block and so on to form a chain.
If there is a bit of data in the block changes then the hash value will also change.
Read also: What is Hashing and How Does It Work?
How to get block hash?
The hash of a block is taken from the summary of other hashes. Blockchain uses The Merkle Tree to generate a hash which is referred to as a Merkle Root. You can see from the diagram below:
![How to get block hash?](https://pintu-academy.pintukripto.com/wp-content/uploads/2021/10/Screen-Shot-2021-08-31-at-14.44.15-1-1024x395.png)
- In Block 11, transaction 0 (Tx0) and transaction 1 (Tx1) are made into hash 0 and hash 1. Then these two hashes are combined to produce hash 01.
- Transaction 2 (Tx2) and transaction 3 (Tx3) are made into hash 2 and hash 3, and combined to produce hash 23.
- Combination hash 01 and hash combination 23 are combined and hashed to generate transaction root/merkle root (Tx_Root).
Thus, if there is a change in one of the transactions, the hash value will change, the merkle root will change, and the block hash will also change.
We can see in the following example what will happen if any data or hash is changed in the blockchain network.
How does blockchain work?
Let’s take an example of two interrelated blocks as follows.
![How does blockchain work?](https://pintu-academy.pintukripto.com/wp-content/uploads/2021/10/Screen-Shot-2021-09-07-at-10.23.55-2-1024x526.png)
- A proof-of-work block is considered valid if the resulting hash has a small value and meets the mining difficulty target. If we look at the above example, the two blocks have a small value because the hash begins with a zero. In this example, assume the difficulty target is 0000x (four leading zeros).
- If you notice in block #3 also write down the hash of the previous block #2 which is 000078be… . The entire block will have a summary hash of the previous block and the very first block is called a genesis block because it has no reference block.
What happens if someone wants to change data from within the blockchain?
If anyone changes the contents of one of the blocks, the hash will change.
For example, suppose someone wants to change the transaction in block #2 between Hudson —> Gorman from $45 to $50. As this data changes the hash of block #2 as well as subsequent hashes will change.
Before data change:
![What happens if someone wants to change data from within the blockchain? 1](https://pintu-academy.pintukripto.com/wp-content/uploads/2021/10/Screen-Shot-2021-09-07-at-10.23.55-1-1-1024x526.png)
After data change:
![What happens if someone wants to change data from within the blockchain? 2](https://pintu-academy.pintukripto.com/wp-content/uploads/2021/10/Screen-Shot-2021-09-07-at-13.51.50-1-1024x550.png)
![What happens if someone wants to change data from within the blockchain? 3](https://pintu-academy.pintukripto.com/wp-content/uploads/2021/10/Screen-Shot-2021-09-07-at-13.44.56-1-1024x573.png)
To make a valid block, the miner must re-mine the block by finding a hash that has a small value and follows the level of mining difficulty (in the following example, the hash must start with four zeros).
If the miner succeeds in generating a hash with a small value and in accordance with the level of mining difficulty, the miner must also replace the data from the next block.
If someone changes the data from the transaction it will be easy to find out because everyone who runs the blockchain has a copy of the blockchain data from the beginning to the latest block.
Assuming that Peer A has the blockchain with the modified/tampered data, while Peer B and C have the original data, we can see that:
Peer A
![Peer A](https://pintu-academy.pintukripto.com/wp-content/uploads/2021/10/Screen-Shot-2021-09-07-at-13.56.25-1-1-1024x545.png)
Peer B & C
![Peer B & C](https://pintu-academy.pintukripto.com/wp-content/uploads/2021/10/Screen-Shot-2021-09-07-at-10.23.55-2-1-1024x526.png)
We can see that the Hash of blocks #2 and #3 between Peer A and Peer B & C are different. This way miners can decide which chain they want to follow. So what if there are two different blockchains?
How do miners come to an agreement?
As we know that with blockchain technology, it allows the Bitcoin network to run without a central party. This is one of the benefits of blockchain. But if we look at how Blockchain works, how can miners know which chain they should follow?
Broadly speaking, miners will always choose the longest chain. However, if there are two different chains there will be a fork. When a branch occurs, one group of miners will follow one chain and another group will follow another chain. Even if for example the hashing power of the miners in these two chains is the same, it is very likely that one of the miners will find the block first than the other miner. If the block is found first, it will create a block with the longest chain, miners who choose to mine a different block will eventually merge back into the longer chain.
To produce a long chain requires a lot of energy, so bad actors are very unlikely to fake transactions because when a transaction is changed the actor has to change the transactions after it and has to compete with all the hash rate around the world.