SHA-256 is a cryptographic hash function that takes an input of a random size and produces an output of a fixed size. Hash functions are powerful because they are ‘one-way’. What this is means is, it is possible for anyone to use a hash function to produce an output when given an input. However, it is impossible to use the output of the hash function to reconstruct its given input. This powerful feature of the SHA-256 hash function makes it ideal for application within the Bitcoin network.
The SHA-256 hash function is utilised within the Bitcoin network in two main ways:
- Creation of Bitcoin addressess
Mining is a process by which new coins are introduced into the existing circulating supply of Bitcoin, as well as a method used to secure the network that Bitcoin operates on. Make sure to check out this article here if you are unsure what mining is.
When a miner is adding a block to the blockchain, it is necessary for them to perform what is called proof-of-work, in-order to prevent fraudulent blocks from being added to the blockchain. Proof-of-work involves the computation of a hash function, which as you may have guessed, is the SHA-256 hash function. Once the miner successfully solves the hash function, his block is then relayed to the network to be checked against the consensus rules.
Creation of Bitcoin addresses
In-order to produce a Bitcoin address, a public key must be hashed. The hash function used to achieve this, is the SHA-256 hash function. The use of a hash function in the creation of a Bitcoin address has two distinct advantages:
- Shorter addresses
Hashing a public key to produce a Bitcoin address adds an extra layer of protection. If a user’s account were to be compromised but the hash function remained unbroken, then the user would still be ok.
Another advantage of hashing a public key to produce a Bitcoin address is simply shorter addresses. A public key is 256 bits long whereas, the hashed version, i.e the Bitcoin address, is 160 bits long. This makes it a lot more convenient for users to use due to the shorter character length.