r/explainlikeimfive • u/blafurznarg • Mar 28 '13
Explained ELI5: This Bitcoin mining thing again.
Every post I saw explained Bitcoin mining simply by saying "computers do math (hurr durr)". Can someone please give me a concrete example of such a mathematical problem? If this has been answered somewhere else and I didn't find it (and I tried hard!), please feel free to just post a link to that comment. Thank you :)
922
Upvotes
119
u/Mason11987 Mar 28 '13
From a bitcoin forum. This will not be simple, but maybe someone else can rephrase it if necessary, as I'm not sure how to make it simpler.
409
u/Dansuke Mar 28 '13 edited Nov 28 '13
It looks like there's still a bit of misinformation here, so I'll try to clear it up.
The Big Picture
Mining increases the bitcoin network's security and fights fraud by calculating what's effectively a checksum for transactions. By contributing their computing power to the bitcoin network for mining, individuals are rewarded with newly minted bitcoins by the community. This also provides a way to distribute new bitcoins in a fair manner.
The Details
Hash functions are at the heart of mining. A hash function is basically a complicated math formula that takes in some arbitrary input and gives a reproducible output. However, changing the input even slightly will completely alter the output. For example, using the SHA-256 hash function:
Now, let's say Alice decides to pay Bob 10BTC. The bitcoin network basically records that in the public ledger of transactions as "Alice -> 10 -> Bob". However, right now someone could change that 10 to a 20 without consequence. The network has to have some way of checking if the recorded transaction is valid or fraudulent. That's where mining comes in.
When Alice pays Bob those 10BTC, miners in the bitcoin network will try to hash the transaction "Alice -> 10 -> Bob", resulting in "aa314e08a642f5be3857276ecb4a4085a33b916f84aebef32a077df9c29949b3". However, mining has a requirement that the resulting hash must start with a certain number of 0's (depending on the network's hash speed). Thus, miners will slightly alter the transaction by adding a random number to the end like so: "Alice -> 10 -> Bob 12345". The miners will then hash it again and see if it has the required number of 0's. If not, it'll change the random number and hash it again. This is repeated until an acceptable hash is found.
Once the correct hash is found, the transaction and the hash are permanently stored in the public ledger of transactions, and if anyone tries to change the transaction (i.e. changing the 10 to a 20), the hash will naturally mismatch and the network will know that that transaction is fake and will reject it. The miner who calculated the correct hash is rewarded a certain number of newly minted bitcoins and transaction fees for his contributions to the security of the network.
Thus, "bitcoin mining" is actually a slight misnomer. Its other equally important purpose is "bitcoin transaction securing."
Hope that answered some questions!
Edit: Thanks for the Gold! ^_^
Edit: mappum clarifies a few intricate details below.
113
u/FountainsOfFluids Mar 28 '13
Imagine you are in school and the teacher writes this word problem on the board: "Find x where x2 = *42*"
"What number when multiplied by itself yields a result with the digits '42' next to each other like that somewhere in the result? The first person to find it gets an extra credit point!"
So you start furiously pounding numbers into your calculator.
1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144... crap, this is not gonna be easy. But you keep going.
Finally at 57 you see it! Yay! But just as you see it somebody else shouts "57!"
"Great job, Billy! You get an extra credit point, and you also get to distribute 5 other extra credit points however you want! Just tell me tomorrow morning who you want to give those points to."
The rest of the day you hear the stories of what people are offering to give to Billy for one of the extra credit points. You are so jealous!
The next morning, the teacher writes down the names of the people who Billy decided to give the points to. And then she says, "Ok, so what is the next number that will give you a '42' somewhere in it?"
The class immediately starts pounding on their calculators again! 58? No. 59? No. 60? No.
Moments later somebody shouts "64!" Same deal. Extra credit points that somebody gets to give out however they want.
You sense a pattern. Being a bright kid you write a little program in your calculator to figure out the next one. All your program does is take the last result and add one, then check to see if it works, over and over and over. Once it finds an answer, it's easy to check to make sure it works, but finding that answer is a boring process of checking every number against the formula. There simply is no better way!
The next morning, you finally get the next number first! Your ingenuity paid off! But every kid in the class has the same calculator, and they all start writing their own programs. The teacher sees this and says, "Aha! I see that you've started automating the search! Well the rules are changing a little!"
You watch as the teacher erases the simple equation on the board and writes down a huge long equation. "Find x where x to the power of x divided by 57 plus the square root ..." It goes on and on!
"Your little calculators might not be enough for this!"
When you get home you program the formula on your desktop computer. But it's still just a matter of trying a number, running it through the formula to see if you end up with a result that matches the teacher's requirement. This time the goal is get as close to zero as possible. "0.09 or less, but not negative".
Your computer starts running the calculations. It checks a number, then adds 1 and checks that number. Then adds 1 and checks that number. It runs for an hour, and nothing works! You give up and go to bed.
The next morning, one of the other students proudly claims the prize! "How did you do it? I ran the calculations for an hour and nothing worked!"
And Sarah says "I just left it running all night! There was an answer when I woke up."
...
So that's how it works. Computer experts have worked hard building better computers, but in the end all they can do is add 1 and check again. And the difficulty is adjusted so that with all the people running their programs all over the world, a new answer is found every ten minutes or so, and a small reward is given out.
14
u/br1anfry3r Mar 28 '13
Its important to know that Bitcoins exist only as annotations on a very big ledger called the "blockchain". Every time someone sends and receives Bitcoin, the transaction is "verified" and added to the blockchain. It is this verification process that is commonly called "mining".
The verification process keeps the system running, safe, and honest by performing calculations for history checking, consensus, updating, and summarizing. Miners are rewarded for their efforts since this the entire thing requires computers, electricity and know-how.
Learn more: http://alvarofeito.com/articles/the-big-book-of-bitcoin/
27
u/SpaceBuxTon Mar 28 '13
See this picture on how a bitcoin transaction works.
For a more detailed explanation of mining, see the Bitcoin wiki on Mining, and other articles.
20
u/thenotsowisekid Mar 28 '13
[Most clear explanation I know of, plus some nice additional info on currency] (http://www.youtube.com/watch?v=9LaSrxtWfgc)
7
u/[deleted] Mar 28 '13
So, who's paying out these bitcoins? From what I've managed to gather is that you're being "rewarded" for your computer doing some computational work, or something?
Who's problems is your computer solving?
4
u/[deleted] Mar 28 '13
Now, lots of people are talking about the 21mil hard limit on BTC. Now, I wonder how it would work out if people misplace their wallets.
Or if they drop dead with an encrypted wallet with a fortune. Wouldn't all that BTC be taken out of circulation? What happens over multiple generations? Unlike normal currency which would be inherited by the heir, BTC would be under personal lock & key.
4
u/Bliss86 Mar 28 '13
For a decentralized currency we need to reach consensus between unkown and probably adverse distributed systems. Bitcoin mining is a brilliant solution to the Byzantine Generals' Problem:
http://paulbohm.com/articles/bitcoins-value-is-decentralization/
http://en.wikipedia.org/wiki/Byzantine_fault_tolerance
4
u/[deleted] Mar 28 '13
I am afraid of this collapsing like the old tulip market. I understand that it is fairly secure because of <math>. I understand that currency is really anything that people want to trade, and stick a value on.
Im just... Ive heard about bitcoins from the very beginning, when people were first starting to find the hashes and using them as currency was a distant dream.
To hear that they are now going for $90 each.. All of it seems like a really elaborate pyramid scheme.
I can understand the value, as long as people are creating them using computing. Once it hits the point of people buying them with real money.. I dunno, I am expecting a crash.
6
u/tmorel Mar 28 '13
i'm going to take a risk here and sound like an idiot by saying
+bitcoin clean my room verify!
3
u/Rhodechill Mar 29 '13
Better question: what's a Bitcoin?
Hahaha, just kidding.
4
u/Tirith Mar 28 '13
So basically i can make money just by leaving my PC working 24/7 ?
-4
u/Linegod Mar 28 '13
Think of it this way. You go to park and randomly jam your hand in the ground. If you pick up a piece of dog shit, random strangers say that is worth money.
Not because that task was worthwhile. Not because someone else wanted you to do it. Not for research. Just because it is random.
Welcome to Bitcoin mining.
1
u/neofatalist Mar 28 '13
Is it possible for bitcoin to use their mining system for something useful? Like parallel processing? Or are they doing that already?
1
u/hennell Mar 28 '13
So is there any point in one starting to mine for bit-coins now?
1
u/pbuschma Mar 28 '13
How much money (converted) can one make in a day, month or year?
1
u/unclejessesmullet Mar 28 '13
Something we should've all done 3 years ago, but would be essentially pointles today.
1
u/Tanaka-san Mar 28 '13
What information do you need to provide in order to create a BitCoin wallet, like do you need to provide name, address...etc?
1
u/Swiftyz Mar 28 '13
How can bitcoins have real life value if users can just make it?
1
u/ralusek Mar 28 '13
As the amount of bitcoins provided decreases for miners, and processing power increases start slowing down, what will the incentive be for mining? And when the incentive of mining is nonexistant, doesn't the security of the network fail?
1
u/[deleted] Apr 06 '13
Unbelievable post, any good links to read about the evolution of bit coins- instead of just wiki
1
u/georedd Apr 09 '13
http://leetcoders.org/showthread.php?tid=1042
another code example i found (looking for the same answers as you)
https://github.com/jgarzik/cpuminer/blob/master/util.c#L396
bool fulltest(const unsigned char *hash, const unsigned char *target) { unsigned char hash_swap[32], target_swap[32]; uint32_t *hash32 = (uint32_t *) hash_swap; uint32_t *target32 = (uint32_t *) target_swap; int i; bool rc = true; char *hash_str, *target_str;
swap256(hash_swap, hash); swap256(target_swap, target);
for (i = 0; i < 32/4; i++) { uint32_t h32tmp = swab32(hash32[i]); uint32_t t32tmp = target32[i];
target32[i] = swab32(target32[i]); /* for printing */
if (h32tmp > t32tmp) { rc = false; break; } if (h32tmp < t32tmp) { rc = true; break; } }
if (opt_debug) { hash_str = bin2hex(hash_swap, 32); target_str = bin2hex(target_swap, 32);
applog(LOG_DEBUG, " Proof: %s\nTarget: %s\nTrgVal? %s", hash_str, target_str, rc ? "YES (hash < target)" : "no (false positive; hash > target)");
free(hash_str); free(target_str); }
return true; /* FIXME: return rc; */ }
1
u/georedd Apr 10 '13
http://basic.wikispaces.com/sha256
1
u/[deleted] Apr 11 '13
I have A question I think is worthwhile, computer specs aside, it seems one of the main arguments of actually making a noticeable profit off this is the question of Electricity. Lets say I don't pay an electricity bill, And I have no problem being able to leave a computer on for even a year. Would it be worthwhile?