Blockchain Block Hashing
- We are getting to learn how SHA-256 applies to create a block within a blockchain. We’ll discuss here within the context of the Bitcoin blockchain and understand how this tie into the role of miners.
- The minors are actually within the process of building blocks, and these blocks are added to a blockchain to build out what the Bitcoin blockchain will be.
Block Hashing Algorithm
- Bitcoin mining uses the hashcash proof of work function; the hashcash algorithm requires the following parameters: a service string, a nonce, and a counter. In bitcoin the service string is encoded in the block header data structure, and includes a version field, the hash of the previous block, and the root hash of the merkle tree of all transactions in the block, the current time, and the difficulty.
Read Also
- Bitcoin stores the nonce in the extraNonce field which is part of the coinbase transaction, which is stored as the left most leaf node in the merkle tree (the coinbase is the special first transaction in the block).
- The counter parameter is small at 32-bits so each time it wraps the extraNonce field must be incremented (or otherwise changed) to avoid repeating work.
- When mining bitcoin, the hashcash algorithm repeatedly hashes the block header while incrementing the counter &extraNonce fields. Incrementing the extraNonce field entails recomputing the merkle tree, as the coinbase transaction is the left most leaf node.
- In this image, you'll see that this block is composed of a block number, data field, cryptographic hash associated with it and a Nonce.
Blockchain Block Hashing
- The generated hash would appear as if 00001acbm010gfh1010xxx. I'd wish to means that this hash has four leading zeros. The four leading zero's describes whether the block is valid or not. You'll see that this hash is like the nonce, and therefore the block number is like the available data. Since the hash has four leading zeroes, therefore, it's a valid block
- If we make any change within the data section, it'll give the completely different hash which will be shown within the below image.
Blockchain Block Hashing
- If the newly generating hash doesn't have four leading zeroes, then it'll not a valid block. To form the block valid, we'll do it by using the field named as nonce.
- Nonce stands for Number Used Once during a cryptographic communication such the block's hash meets a certain criterion. This criterion might be generated a hash that has got to have its leading four digits to be zero. The generated hash would appear as if 00001acbm010gfh1010xxx.
Read Also
- A nonce is basically a random number which figures out how you'll actually make this specific block provide you with a valid hash. The way you'll do that is by changing the nonce manually. The miner starts with a Nonce value of 1 and keeps on incrementing it until the generated hash meets the specified criterion. It's going to take several iterations until the specified hash with four leading zeros is generated. The expected time for generating a block within the bitcoin system is 10 minutes. Once the miner successfully mines the block, he releases that block within the system and making it the last block within the chain.
- In Anders Brownworth Hash Program, once we click mine button as shown within the image, it'll give the valid block. This block has a unique nonce with hash leading four zeroes within the beginning.
Blockchain Block Hashing