If you’ve already heard about Bitcoin, you most likely know that mining is one of the core concept underlying this blockchain technology. You’ve maybe also heard that mining involves thousands of powerful computers which solve some magical puzzles. But do you indeed know how does mining works under the spandex hood?
Science behind Bitcoin
Despite the fact that the blockchain technology takes advantage of a few sophisticated numerical algorithms, the underlying concepts are fairly straightforward. And certainly you don’t need an engineering degree ter programming to take hold of the gist of this revolutionary technology!
Cryptographic hash function
Hash functions belong to a very useful class of algorithms that convert any gegevens into a brief message which then wij can lightly compare and process. Elementary example of that could be a mathematical function which spil an output gives the remainder of division by 1000 (modulo operation). You can think about hashes spil fingerprints of gegevens.
Cryptographic hash functions voorwaarde meet some conditions, such spil:
- be deterministic-that means for the same input function have to always comeback the same hash
- you shouldn’t be able to guess the input from hash except by attempting all possibilities, which is unlikely even for supercomputers
- petite switch ter the input should result ter a fully different hash
- it should be utterly hard to find Two different inputs which give the same hash (like winning Powerball Ten times ter a row hard. )
Cryptographic hash functions are diligently analyzed before they are recommended to production use. For example National Institute of Standards and Technology organized several contests for hash functions te which finest minds te the world attempted to crack or find vulnerabilities te the list of proposed algorithms.
Bitcoin relies powerfully on this properties when it comes to mining blocks. If you’re nosey, an actual implementation uses well known and battle-tested algorithm called SHA-256.
2nd significant thing you need to get to fully understand mining is the concept of Merkle tree. Merkle trees can be used to verify contents and order of given chunks of gegevens. Let’s say you want to send Four files to your friend and you want to ensure that any of thesis files won’t be modified along the way. Merkle tree is solution to your problem. All you need to do is simply go after three steps below:
1. Generate hashes of each opstopping. Each of them is a fingerprint of corresponding verkeersopstopping.
Two. Combine hashes of the very first and 2nd verkeersopstopping together and calculate hash of thesis Two hashes. Repeat this act for files number Three and Four. Now you have Two hashes which uniquely identify pairs of your files.
Trio. Final step is to combine hashes of pairs and calculate hash of them, so-called Merkle root. This is the fingerprint of your Four files.
Bitcoin uses Merkle trees to verify which transactions and ter which order are included ter any given block.
When you send Bitcoin transaction it grounds ter a set of unconfirmed transactions distributed overheen thousands of computers called mempool. Then each miner picks some of them and calculates the root of the given merkle tree. Those transactions are candidates to be included ter the next block. By knowing that wij can eventually commence to mine Bitcoin blocks.
The result of a mining process will be a block, which is a set of transactions with a corresponding block hash that proves validity of the given block.
Ok then, let’s attempt to construct block hash based on the chunks of information wij already have. Maybe it’s just fine to take merkle root and call it block hash?
merkle root ->, block hash
Indeed, it marks the contents and order of included transactions, yet unluckily it doesn’t say anything about the place of this block ter within the blockchain. I could mine this block without knowing how blockchain looked like at the given ogenblik.
There’s an effortless fix for that-we just have to add hash of the last block te the blockchain… and hash it… twice (spil stated ter the bitcoin blockchain specification). Because of that wij can’t produce blocks ter advance.
SHA256(SHA256(previous block hash + merkle root)) ->, block hash
But don’t you think there is something wrong with this formula? No one can, for example, zekering mij from generating millions of thesis blocks. Each rekentuig on our beautiful planet could mine slew of valid Bitcoin blocks every 2nd. There’s a clever part here.
SHA256 hash is truly a number inbetween 0 and Two 256 – 1. Two 256 is hefty. Bitcoin sets a very puny threshold above which hashes are considered invalid. If I do my math correctly only about 0.00000000000000000007% (seven and Nineteen zeros te pui of it) of all possible hashes could be valid block hashes.
That threshold is called difficulty and it’s automatically adjusted every 2016 blocks (
Two weeks) to compensate switching computing power of the network. That’s the reason why blocks emerge at intervals of toughly Ten minutes.
Because wij can’t predict the output of SHA256, wij have to blindly guess different combinations of inputs. Ter order to do so, wij have to include some number wij can switch called nonce.
SHA256(SHA256(previous block hash + merkle root + nonce)) ->, block hash
That’s the core idea of mining. An actual implementation of block hash is slightly different, for example it includes current time and information about difficulty. You can read more technical explanation here.
Well, now you know three core concepts underlying the blockchain mining process. Now, don’t leave behind to check out our explainer movie about bitcoin to learn more about how increasingly useful it is te everyday life and why you should embark using it! If you like it please share it across your network and help us persuade many more people to embark using bitcoins!