Is it better to buy lotto tickets or solo mine Bitcoin?
We periodically pose a question to our devs on slack, then post the lightly edited conversation here.
This Week’s Hacky Slack is about Bitcoin. We’re nerds, but we’re not bitcoin nerds. Even so, we were curious. Assuming you are a solo miner, is it better to mine bitcoin or buy a lotto ticket?
Bitcoin mining is pretty neat technically. Basically you are guess-and-checking to find a random number (nonce) that when added to the current block and hashed makes a number that matches a specific pattern.
The “specificness” of that pattern is called the difficulty. the network moves the difficulty up and down to make sure that blocks are found every 10 minutes or so.
the current difficulty is 23,581,981,443,664.
If you can find a nonce that makes a hash with a difficulty higher than that number, you have solved that block and you can collect your 6.25+ bitcoins ($396,525.00 USD)
I have been running a little USB dongle miner on my desk that can do about 20 billion hashes per second. So it’s picking nonces, adding them to the current block and hashing them to check if the difficulty is high enough, 20 billion times a second.
What are the odds of success? 1/current_difficulty?
Yup! So far I am proud to report that I have achieved a nonce with a difficulty of 33,200, so… I’m almost rich. A lot of miners work as a part of a pool, where they split up the rewards with everyone, based on how many hashes each person has done. even though only one of the hashes made any money
Solo mining means you get the whole reward yourself, if you get really lucky.
You get 20 billion * 600 chances per block (10 minutes of 60 seconds * 20 billion tries per second) so
20,000,000,000 * 60 * 10 = 12,000,000,000,000. If you run two of these, why don’t you hit almost every time?
23,581,981,443,663 / 12,000,000,000,000 is basically 2
I got a similar result from a different angle… if something has a chance of 1/x and you try it x times, it approaches 63% odds of happening at least once in those x times
that’s only 1100 seconds of trying
skot would be making almost 400k per 10 minutes if he just bought a 2nd usb dongle. must be nice
that 20billion/second stat sounds suspicious…
hmm. my average is reported as 22.27Gh/s
but you’re right, why am i not rich yet?
that’s because you only have one dongle
how long have you been running it, have you checked your accounts???
at least an hour
I don’t think there are many things that can do anything 20B times per second
just transmitting data that fast requires 160gigabit
20ghz is a big number, but not impossible
I think they mean gigahash
and each hash is multiple steps of mathing
it doesn’t have to transmit anything.. only when it hits the jackpot
the dongle must be really parallelized
seems like it’s clock is probably something like 1GHz and it’s running ~100 cores or something?
well, it’s probably an ASIC, right?
it’s clock is 100MHz, so it needs to be able to do at least 200 parallel hashes
The Bitmain AntMiner, widely touted as the most efficient and most powerful Bitcoin miner on the market, offers miners a highly impressive hash rate of 14 TH/s
we must be drastically underestimating how the difficulty works.
that has ~187 copies of the chip on my dongle
these numbers sound outrageous
and a lot of fans so it can run it at crazy higher frequency
maybe difficulty is log scale or something?
nice nerd-snipe skot, now I’m looking at this table…
yeah, 1/current_difficulty must not be right.
I can’t quite understand what’s going on here on the Difficulty page on Wikipedia.
This calculator says you’ll make $0.31/month
skot I’m solo mining, just to screw around with it… so it’s pure lottery
I understand that the current block has a SHA256 hash:
1 0 1 1 0 1 0 1 0 1 1 0 0 0 1 0 0 0 0 1 1 1 0 0 1 1 0 1 0 0 1 0
Then I want to come up with some other random number whose SHA256 hash differences with the current block’s has such that the first
n bits of the sum are 0. The higher
n is, the higher the difficulty. A winning sum might look like
block hash --------------- 1 0 1 1 0 1 0 1 0 1 1 0 0 0 1 0 0 0 0 1 1 1 0 0 1 1 0 1 0 0 1 0 my hash of my magic number --------------- 1 0 1 1 0 1 0 1 0 1 1 0 0 0 1 0 0 1 0 1 1 1 0 0 1 1 0 1 1 1 1 0 block hash - my hash of my magic number --------------- 0 0 0 0 0 0 0 0 <--------- win! 0 0 0 0 0 0 0 0 <--------- win! 0 0 0 1 1 1 0 0 1 1 0 1 0 0 1 0
I’m not sure that I really understand how SHA256 or any one way hashing works
why can’t I just do the hash making math in reverse?
It’s a one way function
if you could figure out how to reverse it, you could be very wealthy!
Yes, if you could reverse it, you would break all encryption and all bitcoin and everything
and basically send the global economy into a tailspin
That is a pretty fun “what if” scenario; what would you do if you one day figured it out?
This guy is an incredible explainer and does a great walk-through of blockchain and bitcoin: But how does bitcoin actually work?
but what makes it one way? if I want to use the new ZSA1 algorithm (
x * 69 = hash) to hash the number 420, I get 28,980. Everyone knows that can just divide the hash by 69 to get the original number since the hashing function is well known
I was curious too and found this one helpful: Cryptography: Hash Functions
A really simple example of an almost one-way function is the product of two large primes:
15,485,863 * 67,867,967 = 1,050,994,039,050,521 The product is the hash. To reverse the function, you need to determine which two prime numbers multiply to equal the output.
It’s just an example, but you can immediately see that it’s very easy to go “to the right” and much harder to go “to the left”
To go to the left, you have to divide
1,050,994,039,050,521 by every prime starting at 1, then if it’s divisible, you have to check to see if the quotient is also prime.
so it might take «1 second to go to the right and thousands of seconds to go to the left. SHA256 is like that, except it takes nanoseconds to go to the right and trillions of years to go to the left.
BUT, SHA256 was developed by the NSA, so maybe they know how to reverse it and are snooping on all our shit
so it’s not that has functions are irreversible, it’s just that it’s a giant pain in the ass to reverse them, and usually the best option is to just guess-and-check (which is what bitcoin miners do)
To return the original question, apparently authoritative CoinWarz says
Bitcoin difficulty is a measure of how many hashes (statistically) must be generated to find a valid solution to solve the next Bitcoin block and earn the mining reward.
The difficulty is in the trillions of hashes required, but the network is generating hundreds of quintillions of hashes per second (hashrate). Quintillions are obviously a lot bigger than trillions. If the network is generating quintillions of hashes per second, it’s not clear why it takes 10 minutes to achieve the trillions of difficulty. Side note, Skot’s single USB stick is contributing 0.0000001% of the total hashing effort.
CoinWarz doesn’t have access to some reported sum of hashes though, they’re actually backing into that quintillion number.
The Bitcoin hashrate is calculated using the current Bitcoin difficulty, the defined Bitcoin block time, and the average block time of the last (X) number of blocks.
AH! we must be totally missing something having to do with this difficulty concept
difficulty = hashrate / (2^256 / max_target / intended_time_per_block) = hashrate / (2^256 / (2^208*65535) / 600) = hashrate / (2^48 / 65535 / 600) = hashrate / 7158388.05
That… doesn’t help does it?
I am not sure what
max_target is 2^208*65535 (an application-defined constant, which sets the target hash corresponding to the lowest possible difficulty, 1), and intended_time_per_block is 600 (10 minutes, also a constant).
Does that make sense to you?
(2^256*difficulty/max_target) hashes are needed on average to find a block
now that’s a useful constant
So plugging in the numbers from CoinWarz to the formula from that Stack Exchange gets us these results
2^256*23.58 trillion/(2^208*65535) = 8e+23 135 quintillion * 60 seconds * 10 minutes = 1e+22 (or 0.1e+23)
(I feel like this paper would be marked down by my high school teachers for not using authoritative sources, but the numbers seem to get close)
135 quintillion come from?
That’s the current hashrate
Hmm, the difference between 8e+23 and 0.1e+23 is almost certainly because difficulty doesn’t update that frequently.
Once every 10 days or so. Those numbers almost definitionally won’t match exactly. I’m reasonably satisfied we have the formula right.
So the odds that Skot gets rich in any given second are
[number of hashes per second]/([difficulty]*[4,295,032,833])
or, in this case,
20 billion/(23.6 trillion * 4.3 billion)= 1.97e-13
The odds of winning the lottery are roughly 3.33e-9. The odds of winning the lottery are
3.33e-9 / 1.97e-13 = 16,903 times higher than getting a bitcoin in any given second, but the bitcoin miner just keeps running.
In terms of winning the prize, running that USB stick is essentially equivalent to buying a lotto ticket every 4.7 hours.
ooo I just had my best hash yet;
23,581,981,443,663 here we come!