163

As with mining, what are the bitcoin miners really solving? I read they are solving hashes, but what does that really mean. Can we see what they are solving? Can someone give an example of what a bitcoin mining machine sees to solve?

Vojtěch Strnad
  • 8,292
  • 2
  • 12
  • 40
Patoshi パトシ
  • 11,056
  • 18
  • 84
  • 158
  • 2
    Related: http://bitcoin.stackexchange.com/q/148/153 – Stephen Gornick Feb 28 '13 at 23:52
  • Ok but WHAT data are we mining! Nobody seems to know. I don't care how it works I want to know where the data is coming from that bit mining is decryption or encrypting. –  Dec 05 '13 at 20:18
  • Here is a visual, gamified version of the problem that bitcoin miners are typing to solve. It is literally a bincoin miner, and if you solve the problem then you win a bitcoin. http://hashhunt.josh.com/ – bigjosh May 05 '22 at 19:47

6 Answers6

162

Here is an extremely simplified sketch of the problem, but it should give a pretty good idea of what the problem is.

The data:

This is the hash of the lastest block (shortened to 30 characters):

00000000000001adf44c7d69767585

These are the hashes of a few valid transactions waiting for inclusion (shortened).

5572eca4dd4
db7d0c0b845

And this the hash of one special transaction that you just crafted, which gives 25BTC (the current reward) to yourself:

916d849af76

Building the next block:

Now, let's use a gross approximation of what a new block might look like (the real one uses binary format). It contains the hash of the previous block and the hashes of those 3 transactions:

00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--

Now let's do mining by hand! Our goal is to complete this block with a nonce (a piece of garbage) such that the hash of the new block starts with 13 zeros (considering the previous hash, it seems that 13 zeroes is the current difficulty!).

Mining (trying to finalize this block):

Let's try with nonce=1, and compute the hash of the block (I'm using the md5 hash algorithm, but Bitcoin uses double sha256):

> echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--1" | md5sum 
8b9b994dcf57f8f90194d82e234b72ac

No luck, the hash does not start with a 0… Let's try with nonce=2

> echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--2" | md5sum 
5b7ce5bcc07a2822f227fcae7792fd90

No luck…

If we pursue until nonce=16, we get our first leading zero.

> echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--16" | md5sum 
03b80c7a34b060b33dd8fbbece79cee3

For nonce=208, we get two leading zeroes!

> echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--208" | md5sum 
0055e55df5758517c9bed0981b52ce4a

Continue like this… If you finally find a hash that has 13 leading zeroes… you're a winner! Other miners will now build upon your block, you've just got 25BTC.

But you'll have to be fast!

Back to step 1…

If someone manages to build a block before you do, you'll have to start again from the beginning with the new block's hash (the one of the winner).

Stéphane Gimenez
  • 5,134
  • 3
  • 32
  • 38
  • Note that you're not actually "counting zeroes". In reality approximately the first four non zero numbers are being compared with something called a "target". This is stored in compact form in each block in a field called "bits". – makerofthings7 Mar 01 '13 at 18:50
  • 12
    Also your example is conceptually heading in the right direction, but the real success is when the sha256 hash of the header is less than the target. Example target: 00000000000001ae00000000000000 is greater than 00000000000001adf44c7d69767585 <-- this would be a valid hash. – makerofthings7 Mar 01 '13 at 18:54
  • "And this the hash of one special transaction that you just crafted and which gives 25BTC (the current reward) to yourself: 916d849af76" How is this transaction crafted? – Leonardo Marques Jul 01 '13 at 17:05
  • @Reonarudo: the simplest is to use one of your addresses to produce a single standard output to be spent, but you can forge any kind of custom transaction with custom scripts as well if it pleases you (you are allowed a +25 BTC total balance for this transaction, additionnal inputs were not allowed some time ago, but maybe they are now). – Stéphane Gimenez Jul 01 '13 at 20:33
  • So normally I would just append my wallet address in the end between - and --? – Leonardo Marques Jul 01 '13 at 20:35
  • 3
    @Reonarudo, not exactly, this is a very simplified sketch of what is actally done. Transactions are made with scripts which are often made from adresses, you can find more info on the Bitcoin wiki. – Stéphane Gimenez Jul 01 '13 at 20:39
  • 3
    This basically sounds like a nice (simplified) summary, but at what point does the bitcoin network accept this as the next valid block, and what happens in the (unlikely) event that two different miners managed to submit a valid block almost simultaneously? – Tobias Kienzler Dec 02 '13 at 09:13
  • 1
    Wow, great answer! There're a couple of things I still couldn't get my head around though: Let's say you've been searching for a solution for 6 minutes and there comes a new transaction. 1) what happens now? if I have to start over, then that sounds like everyone has to start over. Then how can blockchain guarantee to find a block in ~10 minutes? 2) How does that transaction come to me anyway? 3) What if I find a solution for this block and then a new transaction comes to me from some other node who accepted it for the block I just closed? – keremispirli Apr 28 '14 at 17:24
  • 2
  • Yes everyone starts over, if you build on top of an old block there's little chance your blocks will be part of the longer chain and they will be disregarded by the rest of the network. There is no guaranty that a block is find within 10 minutes, it's just an average statistical outcome. 2) What transaction? Blocks are broadcast by whoever mined them and relayed by other nodes. 3) Nothing forces you to include all pending transactions, but the more transactions you include the more fees you can collect.
  • – Stéphane Gimenez Apr 30 '14 at 10:47
  • The transaction to be added to current block, the one that caused me and all(?) others to restart the calculation. How does it come to me? And also, 3) Why would I accept it for 0.001 btc if I am to find a new block and get 25 btc?
  • Thanks Stephane!

    – keremispirli May 01 '14 at 12:39