Blockchain – How it works?

Blockchain – How it works?

Blockchain can be explained as a chain of digital blocks linked sequentially by a cryptographic hash. Each block contains records of immutable transactions. Each transaction is digitally signed by a private key of the sender and addressed to the receiver’s public key. An identical copy of whole blockchain is shared by all the participating nodes.

Blockchain can be defined as a distributed, immutable, public/private digital ledger consisting of blocks that are sequentially linked by cryptographic hashes having each block containing a set of digitally signed transactions.

Public blockchain: Any one can participate as a node or can transact in the blockchain. They are also called permission-less blockchains.

Private blockchain: A membership is required to participate. They are also called permissioned blockchains.

Hash: A cryptographic hash function, such as SHA-256 used in bitcoin (BTC) blockchain, takes any size of input data and outputs a string of 256 bits or 64 hex characters. The length of SHA-256 hash value is always 64 characters, whether the input was a single word or a whole book. Even a single character change in input causes a significant change in the hash. Hashing is one way - when a hash is computed with one input, that same input cannot be derived back from that hash. This one-way nature of hashing makes the message/input secure from tampering.

No alt text provided for this image

Public/private key pair: In asymmetric cryptography, a pair of private/public keys is used to encrypt and decrypt messages. Blockchain uses the asymmetric cryptography for securing the transaction. Private key is securely stored in the crypto wallet and public key is shared with transacting parties. Private key is used to digitally sign a transaction before sending it. Public key is used as the owner’s wallet address for receiving transactions. Digitally signing the transaction makes it verifiable.

No alt text provided for this image

Double Spending: This is a problem of party spending the same digital currency twice, similar to the problem of counterfeiting currency notes. For example, party A has a balance of 70 BTC and sends 50 to B and 30 to C. In blockchain, one of these transactions would be invalidated by the mining nodes and would not be included in the block. Even if a faulty/fraudulent node includes it, other participating nodes would invalidate the block and would not accept it.

Transaction: Transaction includes the sender and receiver addresses and the amount in BTC to transfer. This data is used as the input to compute the transaction hash. Below is a summary of a transaction.

No alt text provided for this image

Screenshot Source: https://www.blockchain.com/btc/tx/8efc8d2bbcc0cb35ea63cc8b8c0bac7229b885418221af6aaa37e2645638ce3a

No alt text provided for this image

Merkle Root: Merkle root is a binary tree where each non-leaf node is a hash of its children. All the transaction hashes are kept at the bottom with same depth and a cumulative hash is computed up to the top. This top node hash is the Merkle root. This method ensures that any minor change in the leaf(transaction) results a change in the Merkle root. Since Merkle root is one of the inputs to the hash function, any change in the Merkle root changes the block hash.

Creating a new Block: The first block in a blockchain is called genesis block which has a height as zero. Height of a block simply denotes its sequential position from the genesis block. Each block is linked to the block before and after using block hash which is computed by SHA-256 algorithm.

No alt text provided for this image

When a transaction is digitally signed and sent over the network, it is added to the transaction pool. Miners verify transactions in the pool to include them in a new block. The verification process involves validation of the digital signature and confirmation against double spending. Only verified transactions are included in the block. Once the transaction is included and is confirmed, the receiver can spend the amount. Each block consists of a block header and a set of transactions. Block header is meta data of the block. Block hash is derived by SHA-256 hash function passing it inputs such as Block version, Previous block hash, Merkle root, Timestamp, Bits, Nonce. Below is the simplified linear representation of the nonce finding problem.

Targeted Hash = SHA-256 Function (Block version, Previous block hash, Merkle Root, Timestamp, Bits, Nonce)

No alt text provided for this image

Given other inputs, miners needs to find a nonce?(a number) such that the output hash value does not exceed the target. In simple words or rudimentary way, this indicates that the computed hash should have certain number of leading zeros so that its value remains below the target value.?The mining nodes use lot of processing power to run millions of computations to find a nonce that can output the hash below the given target. This is referred as Proof of Work (PoW) consensus mechanism. PoW makes it difficult for the malicious nodes or attackers to game the system and take the control of the network.

Bitcoin blockchain is set up to keep the duration between two blocks at 10 minutes. To achieve this goal, the system adjusts the target periodically with a varying level of difficulty. As difficulty level goes up, the target bar slides down and the odds of finding the nonce below that target reduces. Due to this, more work and time is required to solve the nonce problem. The difficulty is adjusted to lower or higher level by the network so that the duration between block creation averages to 10 minutes. This adjustment occurs exactly after 2016 blocks, roughly every two weeks.

Once a miner successfully solves the nonce problem, they create the block and broadcast it to the network. All the nodes then verify the transactions and accept the newly created valid block by consensus using the gossip protocol. At all times, nodes tend to maintain the longest chain. When a node receives information/gossip that a longer chain exists, it updates its copy with the history of the longest chain. This keeps the whole network in sync.?

Mining: Miner node creates and broadcasts the block over the network to add to the chain. Miners get the block reward which is 6.25 BTC as of now. When the Bitcoin was launched, the reward was 50 BTC for each block created. Satoshi Nakamoto (the creator of Bitcoin) has set a cap of 21 million BTC supply through mining reward over the time. To limit the supply over time (for deflationary reasons), the block mining reward amount halves after every 210,000 blocks or roughly around 4 years. It is estimated that it would take up to year 2140 (not a typo) until the final coin is mined. So far, roughly 18.85 million coins are mined which is close to 90% of the cap of 21 million. Miners also get the transaction fees for each transaction included in the block. Thus, miners get block reward and fees for working for the network. Miners can spend this amount after the block they mined becomes 100 blocks deep in the chain. This incentivizes the miner to keep adding the block to the longest chain and maintain the network.

Longest Chain: All the nodes always adopt to the longest chain and thereby all nodes share the same view of the chain history. Most of the times it is the one with highest number of blocks. There can be scenarios when the chain with highest number of blocks is not the longest chain, this is because the longest chain is actually determined on the basis of chainwork. Longest chain is the one which has the most work or the biggest chainwork value.

No alt text provided for this image

When more than one miner solves the nonce problem simultaneously and mine a block, the network is in disagreement about which block should be accepted. This gets resolved when the next block is linked to one of these blocks and becomes the longest chain, and adopted by the network. What happens to the blocks that are not in the longest chain? They are considered as orphaned blocks and the transactions re-added to the pool so that they can be included in a new block.

Benefits of Blockchain:

  • Trust: Blockchain facilitates person to person transactions without a trusted intermediary. Trust is secured by eliminating the problem of double spending.
  • Security: Blockchains provide security and finality of the transaction once confirmed. If someone wants to tamper a transaction by modifying it, they will have to modify the whole chain from that transaction onwards. When a transaction is tampered, the Merkle root changes and that changes the block hash. The attacker/hacker has to recompute the hashes of all the subsequent blocks to replace with a new version of the chain. This is practically impossible as the modified blocks would not be accepted by all the nodes unless the attacker own 51% nodes. Even if the attacker manages to control the 51% of the network, the next challenge is to compute the hashes of the blocks sequentially. By the time the attacker computes the hashes, a new block is added to the chain by a valid node making the attack more difficult.
  • Privacy: Only the public address is seen on the network, this provides the anonymity to the party who owns that address/wallet. When a transaction is added to the block and that block is added to the chain, only the address of the receiver can decrypt the transaction and can be shown on his wallet as received.
  • Immutability: Once transaction is added it cannot be modified. This immutability of blockchain is useful in many use cases.
  • Smart Contracts: These are the program of code that run on Blockchains like Ethereum. They take actions based on events and can perform many tasks without intermediary and human intervention. This feature has opened tremendous opportunities for numerous use cases for blockchain.

Nagendra Mirajkar

Enterprise Architect @ Zensar Technologies | Driving Innovation| |Front End Engineering Practice Head | AI-First Practitioner | IIM Ahmedabad - RPG Leadership Development Programme II

3 年

Nicely explained... agreed informative...

回复

Very informative.

回复

要查看或添加评论,请登录

Ramakant Kasar的更多文章

  • Ethereum – Layer2 Scaling Solutions Overview

    Ethereum – Layer2 Scaling Solutions Overview

    As explained in the previous articles, blockchains have to trade off within decentralization, security and scalability…

  • Ethereum part 4 – The Eth2 upgrade

    Ethereum part 4 – The Eth2 upgrade

    The Blockchain Trilemma There are three main aspects of blockchain technology. Decentralization: Decentralization is at…

  • Ethereum part 3 – The dApp ecosystem

    Ethereum part 3 – The dApp ecosystem

    Ethereum has made running smart contracts on decentralized network a reality. This is resulting in proliferation of…

  • Ethereum - part 2 : Details

    Ethereum - part 2 : Details

    This is a sequel to Ethereum – Introduction where I covered Ethereum overview, transaction fees, smart contracts…

  • Ethereum: Introduction

    Ethereum: Introduction

    What is Ethereum: Ethereum is a programmable blockchain, in other words it is a blockchain based platform where…

    1 条评论
  • DeFi: The future of Finance

    DeFi: The future of Finance

    DeFi is an acronym for Decentralized Finance, which means it is not controlled by a central agency/intermediary such as…

    2 条评论
  • Crypto Assets – Coins Vs Tokens

    Crypto Assets – Coins Vs Tokens

    Crypto asset is a form of digital asset that is uniquely identified by use of cryptography. Cryptography ensures the…

社区洞察

其他会员也浏览了