<p>Hash functions are unpredictable.</p>

<p>You can't simply find an input to the hash function that produces such an output. The only way to accomplish that is by trying lots and lots of candidate blocks as input. If the target is 1000 times smaller, it requires 1000 times as many tries.</p>

CC BY-SA 4.0
2019-04-11T20:05:27.347Z
Deleted comment. Please see edit to question.
Zduff
CC BY-SA 4.0
2019-04-11T19:58:48.330Z
2019-04-11T19:58:48.330Z
Pieter Wuille
<blockquote>
  <p>EDIT: For clarity, I mean this in the sense of what part of the technology requires me to use a hash function? As opposed, to just constructing something that looks like a valid hash.</p>
</blockquote>

<p>When determining whether or not a block is valid, each and every bitcoin node on the network will take the header of that block, and run it through a hashing algorithm to see what the output is. If the output is lower than the target value, then the block is valid (assuming that the rest of the block is also valid, of course). </p>

<p>Notice something important: <em>the hash value itself is not explicitly stored in the block</em>. So you cannot just append some fabricated value that falls below the target value onto the block in lieu of a valid PoW. To create a valid block, you must construct it such that all other network nodes can independently verify it as being valid, and to do so, they use a hash function. </p>

<p>As Pieter mentioned, hash functions are unpredictable 'one-way' functions. The only way to find a valid output is by trying a huge number of possible inputs, and 'getting lucky', so to speak. </p>

CC BY-SA 4.0
2019-04-12T01:08:08.883Z
It's not quite that simple. The hash needs to be resistant to [pre-image attacks](https://en.wikipedia.org/wiki/Preimage_attack).
jpmc26
CC BY-SA 4.0
2019-04-12T04:00:57.093Z
@jpmc26 Any useful cryptographic hash function should be.
Criticize SE actions means ban
CC BY-SA 4.0
2019-04-12T14:17:40.433Z
@jpmc26 A cryptographic hash function is commonly understood to mean indistinguishable from random, which implies preimage and collision resistant. This doesn't hold for non-cryptographic hash functions.
Pieter Wuille
CC BY-SA 4.0
2019-04-11T20:50:24.837Z
2019-04-11T20:50:24.837Z
chytrik
<p>I just started learning about Bitcoin, and something I can figure out is why miners have to use a random process (hashing a nonce) to get lower than the target. For example, if the target is</p>

<pre><code>00000000000001ae00000000000000
</code></pre>

<p>why not just produce</p>

<pre><code>000000000000000000000000000001
</code></pre>

<p>to become the winner? I have no practical experience mining, I'm guessing my ignorance lies in the requirements of how a hash is produced. If so, where can I find about those requirements? Thanks.</p>

<hr>

<p><strong>EDIT:</strong> For clarity, I mean this in the sense of <em>what part of the technology requires me to use a hash function?</em> Rather than in the sense of just constructing something that looks like a valid hash.</p>

CC BY-SA 4.0
2019-04-12T06:38:55.140Z
Other nodes checking your hash will notice that you are lying: the hash does not match the calculated hash. The only thing you can do to influence weather your hash matches the calculated hash is to change the nonce and try - this is in fact the proof of work algorithm - change nonce, calculate hash, see if it fits the target and try, try again. You are always welcome to voluntarily choose a harder target but statistically that means other people would be able to find a matching hash before you
slebetman
CC BY-SA 4.0
2019-04-12T06:42:42.500Z
Also, you have a slight misunderstanding. The process is not hashing the nonce, it is hashing the block. Of course hashing the block will generate a fixed hash value which may never match the target. The solution? Allow miners to add their own garbage/ignored data to the block - the nonce - then hash the whole thing. If the hash don't match the target you need to change the nonce and retry. In this way it is impossible to pre-calculate the hash using a pre-generated nonce because you have no control over the other data in the block
slebetman
<mining-theory><hash>
What is preventing me from simply constructing a hash that's lower than the current target?
Zduff
# What is preventing me from simply constructing a hash that's lower than the current target?

(Asked by: username_0 on 2019-04-11)

I just started learning about Bitcoin, and something I can figure out is why miners have to use a random process (hashing a nonce) to get lower than the target. For example, if the target is

```
00000000000001ae00000000000000

```

why not just produce

```
000000000000000000000000000001

```

to become the winner? I have no practical experience mining, I'm guessing my ignorance lies in the requirements of how a hash is produced. If so, where can I find about those requirements? Thanks.

---

**EDIT:** For clarity, I mean this in the sense of *what part of the technology requires me to use a hash function?* Rather than in the sense of just constructing something that looks like a valid hash.

**Tags:** mining-theory, hash

> **Comments:**
> **username_1**: Other nodes checking your hash will notice that you are lying: the hash does not match the calculated hash. The only thing you can do to influence weather your hash matches the calculated hash is to change the nonce and try - this is in fact the proof of work algorithm - change nonce, calculate hash, see if it fits the target and try, try again. You are always welcome to voluntarily choose a harder target but statistically that means other people would be able to find a matching hash before you  
> **username_1**: Also, you have a slight misunderstanding. The process is not hashing the nonce, it is hashing the block. Of course hashing the block will generate a fixed hash value which may never match the target. The solution? Allow miners to add their own garbage/ignored data to the block - the nonce - then hash the whole thing. If the hash don't match the target you need to change the nonce and retry. In this way it is impossible to pre-calculate the hash using a pre-generated nonce because you have no control over the other data in the block  

---

## 2 answers

### Answer by username_3 on 2019-04-11. Score: 6 | Accepted answer

> EDIT: For clarity, I mean this in the sense of what part of the technology requires me to use a hash function? As opposed, to just constructing something that looks like a valid hash.

When determining whether or not a block is valid, each and every bitcoin node on the network will take the header of that block, and run it through a hashing algorithm to see what the output is. If the output is lower than the target value, then the block is valid (assuming that the rest of the block is also valid, of course).

Notice something important: *the hash value itself is not explicitly stored in the block*. So you cannot just append some fabricated value that falls below the target value onto the block in lieu of a valid PoW. To create a valid block, you must construct it such that all other network nodes can independently verify it as being valid, and to do so, they use a hash function.

As username_2 mentioned, hash functions are unpredictable 'one-way' functions. The only way to find a valid output is by trying a huge number of possible inputs, and 'getting lucky', so to speak.

> **Comments:**
> **username_4**: It's not quite that simple. The hash needs to be resistant to [pre-image attacks](https://en.wikipedia.org/wiki/Preimage_attack).  
> **username_5**: @username_4 Any useful cryptographic hash function should be.  
> **username_2**: @username_4 A cryptographic hash function is commonly understood to mean indistinguishable from random, which implies preimage and collision resistant. This doesn't hold for non-cryptographic hash functions.  

---

### Answer by username_2 on 2019-04-11. Score: 6

Hash functions are unpredictable.

You can't simply find an input to the hash function that produces such an output. The only way to accomplish that is by trying lots and lots of candidate blocks as input. If the target is 1000 times smaller, it requires 1000 times as many tries.

> **Comments:**
> **username_0**: Deleted comment. Please see edit to question.  

---

