The hash functions used in Bitcoin
Bitcoin’s consensual algorithm is based on a cryptographic system which ensures the integrity and safety of blockchain. The hash functions play a crucial role in maintaining the network’s privacy and non-repurgence properties. In this article, we will explore how the blockhead is chopped to produce the next Bitcoin block.
hash functions
The Bitcoin protocol uses two main hash functions:
- SHA-256 (Secure hash algorithm 256) : This is the main cryptographic hash function used for the majority of Bitcoin transactions.
- Merkle Tree
: This is a probabilistic digital tree data structure which allows us to check the accuracy of the blockchain.
Haping up for blocking
To produce the blocking, the following steps are taken:
- Calculate the shadow SHA-256 of the transaction of the previous block
The transaction chopping of the previous block is used as a input for the SHA-256 hash function.
- Add the Merkle root and nonce to the outlet
A random nuncio (a single number) is added to the outlet of the HHA-256 hash function, as well as the Merkle root and other relevant data.
The order of operations
Here is a step by step ventilation of the way the blocking is chopped:
- Hash Sha-256 of the previous block transaction : Calculate the SHA-256 hash of the transaction in the previous block.
- Add Merkle Root and Nonce : Combine Merkle Root, Nunce and SHA-256 chopping of the previous block to produce new value.
- hash : Apply the Hhawrm SHA-256 to this new value.
The complete calculation of the hash
To give you an idea of what is happening behind the scenes, consider the following example:
Suppose we have three blocks: block A, block B and block C. The transaction in block A is as follows:
`'
Transaction A (txid = 1) - Value = 10
'
Here are the steps involved in the calculation of the hash transaction of block A:
- Calculate the hash Sha-256 :SHA-256 (10)
- Add Merkle Root and Nonce : The Merkle root is generated using a random selected Merkle tree, and a nonce (0x1234567890abcdef) is added to the result.
- hash : Apply the Hhawrm SHA-256 to this new value.
The hatching resulting from the Bloc A transaction would be:0 … 012345678901234567890abcdef
Similarly, we can calculate the hases of the B and C blocks:
- Hash of Bloc B:
* Transaction in block B
'
Transaction B (txid = 2) - Value = 20
'
Chop:
* SHA-256 (20)
* Add Merkle Root and Nunce:0 … 123456789012345678901234567890abcdef
* Hash:0 … 01234567890123456
- Hash of the C:
* Transaction in block C
`'
Transaction C (txid = 3) - Value = 30
'
Chop:
* SHA-256 (30)
Add Merkle Root and Nunce:0 … Fedcba987654321098765432109876 *
* Hash: 0 ... 01234567890123456
The chopping resulting from the Block C transaction would be:0 … 01234567890ABCDEF`