Overview: Often we hear that miners have to solve a difficult mathematical puzzle to add a new block to existing blockchain. Now the question is - what is this mathematical puzzle and how difficult it is. Let us understand this in context of Bitcoin mining. The Mathematical Puzzle: A Bitcoin block basically consists of block header, a number of recent verified transactions and other details. The block header contains following fields: Field Purpose Size (Bytes) Version Block version number 4 hashPrevBlock 256-bit hash of the previous block header 32 hashMerkleRoot 256-bit hash based on all of the transactions in the block 32 Time Current timestamp as seconds since 1970-01-01T00:00 UTC 4 Bits Current target in compact format 4 Nonce 32-bit number (starts at 0) 4 Courtesy: https://en.bitcoin.it/wiki/Block_hashing_algorithm Here the Bits field is a target or threshold value. All one has to do is to find a Nonce for which the hash of the block header is less than or eq
Overview: A Merkle Tree is a tree where every leaf node is hash of data block and every non leaf node is a cryptographic hash of its children. Following diagram demonstrate the structure of the Merkle Tree: Above diagram is an example of binary Merkle tree but the data structure is not restricted and it is possible to have n-nary Merkle tree as well. There have been extensive use of this data structure in blockchain technology especially in Bitcoin and Ethereum. How it is used in Bitcoin: Every transaction that happens on Bitcoin network is stored in blocks. These data blocks contain multiple transactions and each transaction is eventually hashed. Every two hashed values are again hashed together and stored in its parent node. The root of the tree also known as Merkle Root stores the hash based on all transaction in block. This merkle root of the block is stored in the block header and used as one of the input parameters to calculate the hash of entire block. Advantage of Mer