The bitcoin mining algorithm from a programmer's viewpoint
bitcoin.stackexchange.com
bitcoin.stackexchange.com
It's somewhat surprising to me that the next difficulty level isn't an input the hash function. H(B, random number, next difficulty level).
Edit: How does the network agree on clock? How does it handle rogues?
Since difficulty is adjusted based on a simple median, if the hashrate is always growing (like for the past 8 months), average time between blocks is always below the target 10 minutes (it was around 7-8 minutes on average).
The nodes can "agree" without needing to communicate , because they all use the same formula (and share the blockchain) they should all agree on the same answer for what the difficulty of the next set of blocks should be.
miners choose a value for generated_value, hash it and hope it comes out with the required number of zeros, if not they try again, and again, and again until they (or someone else) finds a value.
for simplicity let's say the fn(x) = x.
difficulty of 5? hash must have 5 zeros at the beginning: 00000XXXXXXXXXXXXXXXXXXXXXXXXX
10? must have 10: 0000000000XXXXXXXXXXXXXXXXXXXX
each zero you add on requires exponentially more time.
Example:
Treshold = 001010
If you check 001011 or 001001 then the number of leading zeros are the same but one number is below the threshold and the other is not.
Threshold is 001010
The numbers 001001 and 001011 have the same number of leading zeroes but one is below the threshold and the other is not.
For a more concrete example, if the requirement is that a 16-bit word is less than 4096, you only have to verify that it leads with 4 zeros.
I've always thought that's how it worked since that is what is written in the original Bitcoin paper (which has for a long time been my only source of information on the protocol).
This is probably the best place for you to start with these specific questions:
https://en.bitcoin.it/wiki/Transactions
or more generally
BTC is the most interesting thing since the Internet, IMO. Yeah, I'm tired of speculative 'is BTC going to fail' posts, but I love reading about all the new developments.
[1] Multi-millionaire, creator of ColdFusion, CTO at Macromedia, now founded a $9 million-backed startup on Bitcoin (http://circle.com)
At the same time, it's fascinating from a purely technical perspective as well. I think as a topic it's a gold mine for interesting conversation, because it touches programming, economics, mathematics, and human psychology all so deeply.
"Blah in X lines of javascript"
"Is college worth it?"
http://bradconte.com/files/misc/HackerNewsParodyThread/