<p>This exercise is actually a good way to understand proof-of-work. In order solve your problem, you need to pass your input into <code>SHA256</code> until you get a hash with 9 zeros, there is no other way around it other than brute force. This is because <code>SHA256</code> is a <a href="https://en.wikipedia.org/wiki/One-way_function" rel="nofollow noreferrer">one-way function</a> which cannot be solved in reverse. As you've already learned, brute forcing will take many guesses. It would be a good exercise to calculate just how many guesses it would take and how fast normal hardware could do this:</p>
<ol>
<li><p>Get the target value. Your maximum target is:</p>
<p><code>000000000fffffffffffffffffffffffffffffffffffffffffffffffffffffff</code></p>
</li>
<li><p>Divide by <code>ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff</code>, which is the maximum value of a 256-bit number. You now have the probability of a single hash solving a block. Or, as you pointed out, you can calculate the probability of getting 9 zeros in a row in base 16 (1/16^9). Using <a href="https://www.wolframalpha.com/input/?i=0x000000000fffffffffffffffffffffffffffffffffffffffffffffffffffffff%20%2F%200xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" rel="nofollow noreferrer">wolframalpha</a>,</p>
<p><code>target / max256 = 1.46E-11</code></p>
</li>
<li><p>Take the reciprocal of the probability to get the average number of hashes to solve a block.</p>
<p><code>1/1.46E-11 = 6.85E10</code> or<br />
<code>68.5 Billion</code></p>
</li>
<li><p>Divide the average number of hashes by the hashrate of your hardware (a typical laptop does can maybe do around 100k Hash/sec) to get the average number of seconds required to solve a block.</p>
<p><code>6.85E10 / 100,000 = 685,000 seconds or just over a week</code></p>
</li>
</ol>
<p>Nowadays Bitcoin is mined using dedicated hardware (ASICs) that can do terahashes/second and solve this in less than a second, however, they are usually configured to mine on a pool using a specific protocol (e.g. stratum) so it would require either modifying the miner software or the pool software if you wanted to pass in arbitrary data to hash. Since this is a finance class, this is not likely the purpose of the assignment and was probably designed for you to fail to teach a lesson.</p>
<p>Also, here is another resource that might help: <a href="https://en.bitcoin.it/wiki/Generation_Calculator" rel="nofollow noreferrer">Generation Calculator</a>.</p>

CC BY-SA 4.0
2018-12-05T10:11:13.707Z
A typical laptop can easily do a few million hashes/s.
Pieter Wuille
CC BY-SA 4.0
2018-12-05T13:16:12.233Z
I think 100kH/s is about what I was able to do on a 2014 MacBook pro running https://github.com/jgarzik/cpuminer maybe I should test again
JBaczuk
CC BY-SA 4.0
2021-03-02T01:45:09.097Z
it took me 15.7 seconds to do 6 in node using worker_threads on my macbook. src: https://github.com/robbiemu/learning-chain/tree/chain -- that should be about 167 at 100kHs right? so 1MHs is pretty easily doable I would think
roberto tomás
CC BY-SA 4.0
2018-12-05T05:43:59.367Z
2018-12-05T05:51:54.803Z
2020-06-16T11:10:03.350Z
JBaczuk
<p>I am working on a school problem and want to generate a hash starting with 9 zeros, it is assumed to be the first block with only your name and the previous hash is 64 zeros. </p>

<p>Can anybody help me or show me how to mine/create a 9 zero hash?</p>

CC BY-SA 4.0
2018-12-05T01:27:07.670Z
Maybe you ought to explain what you know, what you've tried, and where you're stuck.  Nobody wants to just do your homework for you.
Nate Eldredge
CC BY-SA 4.0
2018-12-05T04:20:14.347Z
I am pretty new to this, I understand the basics. I have the block number, some data to enter and the previous hashcode. I tried to just enter random numbers, but soon realized the futility seeing as it would be 1 in 16^9 to get a nonce that would give me the hash I am looking for. So basically I am looking for ways to brute force it. I was hoping I could somehow use bitcoin mining software or something. It is a finance course so we are not coders or anything, I think it is mainly to understand how crypto currencies work versus the technical aspect. Any guidance would be appreciated.
Jakes
CC BY-SA 4.0
2018-12-05T04:34:04.110Z
The way it's worked in Bitcoin (SHA256d) is by using a nonce value in the block header that can be incremented; that will naturally result in a different hash per nonce. If you brute-force enough nonce values you'll eventually get a hash lower or equal to your "target". The lower the hexadecimal number the more leading zeros. What hashing algorithm are you using?
Mason Ticehurst
CC BY-SA 4.0
2018-12-05T04:46:55.960Z
The hashing algorithm I am using is SHA256
Jakes
<mining-theory>
creating a hash that starts wtih 9 zeros
Jakes
# creating a hash that starts wtih 9 zeros

(Asked by: username_0 on 2018-12-05)

I am working on a school problem and want to generate a hash starting with 9 zeros, it is assumed to be the first block with only your name and the previous hash is 64 zeros.

Can anybody help me or show me how to mine/create a 9 zero hash?

**Tags:** mining-theory

> **Comments:**
> **username_1**: Maybe you ought to explain what you know, what you've tried, and where you're stuck.  Nobody wants to just do your homework for you.  
> **username_0**: I am pretty new to this, I understand the basics. I have the block number, some data to enter and the previous hashcode. I tried to just enter random numbers, but soon realized the futility seeing as it would be 1 in 16^9 to get a nonce that would give me the hash I am looking for. So basically I am looking for ways to brute force it. I was hoping I could somehow use bitcoin mining software or something. It is a finance course so we are not coders or anything, I think it is mainly to understand how crypto currencies work versus the technical aspect. Any guidance would be appreciated.  
> **username_2**: The way it's worked in Bitcoin (SHA256d) is by using a nonce value in the block header that can be incremented; that will naturally result in a different hash per nonce. If you brute-force enough nonce values you'll eventually get a hash lower or equal to your "target". The lower the hexadecimal number the more leading zeros. What hashing algorithm are you using?  
> **username_0**: The hashing algorithm I am using is SHA256  

---

## 1 answers

### Answer by username_3 on 2018-12-05. Score: 3

This exercise is actually a good way to understand proof-of-work. In order solve your problem, you need to pass your input into `SHA256` until you get a hash with 9 zeros, there is no other way around it other than brute force. This is because `SHA256` is a [one-way function](https://en.wikipedia.org/wiki/One-way_function) which cannot be solved in reverse. As you've already learned, brute forcing will take many guesses. It would be a good exercise to calculate just how many guesses it would take and how fast normal hardware could do this:

1. Get the target value. Your maximum target is:

   `000000000fffffffffffffffffffffffffffffffffffffffffffffffffffffff`
2. Divide by `ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff`, which is the maximum value of a 256-bit number. You now have the probability of a single hash solving a block. Or, as you pointed out, you can calculate the probability of getting 9 zeros in a row in base 16 (1/16^9). Using [wolframalpha](https://www.wolframalpha.com/input/?i=0x000000000fffffffffffffffffffffffffffffffffffffffffffffffffffffff%20%2F%200xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff),

   `target / max256 = 1.46E-11`
3. Take the reciprocal of the probability to get the average number of hashes to solve a block.

   `1/1.46E-11 = 6.85E10` or  
   `68.5 Billion`
4. Divide the average number of hashes by the hashrate of your hardware (a typical laptop does can maybe do around 100k Hash/sec) to get the average number of seconds required to solve a block.

   `6.85E10 / 100,000 = 685,000 seconds or just over a week`

Nowadays Bitcoin is mined using dedicated hardware (ASICs) that can do terahashes/second and solve this in less than a second, however, they are usually configured to mine on a pool using a specific protocol (e.g. stratum) so it would require either modifying the miner software or the pool software if you wanted to pass in arbitrary data to hash. Since this is a finance class, this is not likely the purpose of the assignment and was probably designed for you to fail to teach a lesson.

Also, here is another resource that might help: [Generation Calculator](https://en.bitcoin.it/wiki/Generation_Calculator).

> **Comments:**
> **username_4**: A typical laptop can easily do a few million hashes/s.  
> **username_3**: I think 100kH/s is about what I was able to do on a 2014 MacBook pro running https://github.com/jgarzik/cpuminer maybe I should test again  
> **username_5**: it took me 15.7 seconds to do 6 in node using worker_threads on my macbook. src: https://github.com/robbiemu/learning-chain/tree/chain -- that should be about 167 at 100kHs right? so 1MHs is pretty easily doable I would think  

---

