<p>The hash function used in the Proof of Work is not some variable or additional data in blocks that Bitcoin Core needs to check. Furthermore, the Proof of Work is not just something that you submit; in fact, it is not a separate data field at all. The Proof of Work is the hash of the block header, and checking the Proof of Work means computing that hash and comparing it against the current target value.</p>

<p>So to change the proof of work algorithm, you need to change the hash function used for hashing block headers. Keep in mind that doing so will also change how blocks are identified because blocks are identified by hash.</p>

<p>The function that is called to compute and get the block header's hash can be found <a href="https://github.com/bitcoin/bitcoin/blob/master/src/primitives/block.cpp#L13" rel="nofollow noreferrer">here</a>. This function itself calls a helper function which calls some other helpers. If you want to change the hash function used in the PoW, you need to change those helpers as well. Keep in mind that if you change those functions too, other things may break and more than the hash function used in the PoW will change.</p>

CC BY-SA 4.0
2019-05-02T23:33:09.360Z
2019-05-02T23:33:09.360Z
Ava Chow
<p>I'm using <a href="https://github.com/jgarzik/pyminer/blob/master/pyminer.py" rel="nofollow noreferrer">https://github.com/jgarzik/pyminer/blob/master/pyminer.py</a> to test a few different hash functions.  Instead, I'd like to try keccak, a few of them in some order like an "X5" and so on.</p>

<p>This is a toy project to try and change the proof of work in Bitcoin and recompile and test, either an old version &lt; 0.10.0 since getwork() might be easier to test with, or the latest release - apparently bitcoin-cli can mine blocks if starting from a new genesis block and the difficulty is set so low that a CPU can mine as much as you like.</p>

<p>My problem is that I can't find in Bitcoin Core where the proof of work is. I've looked in pow and validation files for near a week now, but no luck so far, or I just can't see it for some reason.</p>

<p>I thought it might have been obvious in miner.cpp which I think is no longer used (but might be able to be enabled?), and the best I can find is CheckProofOfWork in pow.cpp.</p>

<p>It doesn't seem to check whether the PoW is sha256d. Does it?  I must be missing something.  So it looks like I can just change the miner code and submit a proof of work and if it meets the requirements, it will be accepted.</p>

<p>Is there a reasonably easy way to use a toy miner, change the PoW algorithm, and modify Bitcoin Core if necessary to try a different proof of work?</p>

<blockquote>
  <p>Edit: this is not altcoin development, it's an effort to understand Bitcoin's code in more detail.  Please stop begging the question. Also please consider downvoting only questions which are truly useless instead of those you just don't like.  Thanks!</p>
</blockquote>

CC BY-SA 4.0
2019-05-01T12:15:21.397Z
Edit: Found https://github.com/BitcoinHardfork/bitcoin and what seems easier to implement with adding a few new files and adjusting a couple of bits: use Keccak from some date also by Luke DashJr https://github.com/luke-jr/bitcoin/commit/8d3a84c242598ef3cdc733e99dddebfecdad84a6  Still no real information on how to get it going and test it though, unless it's as easy as cloning the code to make an altcoin and using this proof of work from the beginning.
James Young
CC BY-SA 4.0
2019-05-01T16:57:18.823Z
Why was this down voted?  Changing a proof of work not an interesting enough topic for our voting overlords?
James Young
CC BY-SA 4.0
2019-05-02T15:08:03.433Z
Generally speaking, altcoin "development" questions provide little to no value. Basic code comprehension assistance for a financial product being akin to asking for help finding the ignition button in an aircraft, we can help you with the very specific question, but everybody knows you're not getting off the ground.
Claris
CC BY-SA 4.0
2019-05-02T20:22:30.477Z
Altcoin development is useful to understand the guts of Bitcoin.  Why isn't writing and modifying code considered useful anymore?  If you believe in learning by doing, along with books like Programming Bitcoin, then it's possible to get off the ground.  This is a very specific question, changing sha256d to something else. Isn't it? Why do I need anyone's permission to try this?  That's what it seems like.
James Young
CC BY-SA 4.0
2019-05-02T20:27:10.450Z
I’ve been involved in Bitcoin for the better part of a decade and have never seen an instance of someone producing meaningful understanding by producing altcoins. It is usually the complete opposite, with misunderstanding born from the misconception that the implementation of Bitcoin has a huge amount to do with its overall design. The same way disassembling a cake doesn’t tell you much about its ingredients, or why taking a spanner to a car unsupervised can lead to confusion rather than detailed knowledge.
Claris
CC BY-SA 4.0
2019-05-02T20:30:05.857Z
While you don’t need to ask our permission, you also don’t get to demand responses.
Claris
CC BY-SA 4.0
2019-05-02T20:44:07.003Z
How is asking a question a demand for a response?
James Young
CC BY-SA 4.0
2019-05-02T20:49:47.033Z
How is this an altcoin anyway?  Whoever said this was altcoin development?  Why is it not useful to understand where this is and how it works?  Learning by doing something can be useful in understanding. I don't see the disassembling of a cake analogy. Disassembling code is always useful to understand how it works, recompile, run it, get to know it.  I got the same bizarre responses when I asked about the mempool when all I wanted to do was get to know how it worked.  That was, instead of RBF, try to drop all transactions that are >= 3 hours old.
James Young
CC BY-SA 4.0
2019-05-02T20:54:27.043Z
Overall the code in Bitcoin will teach you absolutely nothing about the underlying concepts, other than the eccentricities of the implementation itself.
Claris
CC BY-SA 4.0
2019-05-02T20:55:58.307Z
I understand enough of the concepts, and I would like to understand the eccentricities of the implementation.  Why not, if you're going to hack on the code?
James Young
CC BY-SA 4.0
2019-05-02T23:20:40.403Z
This is altcoin development because the end result is that you will have created an altcoin.
Ava Chow
CC BY-SA 4.0
2019-05-03T00:19:13.577Z
I guess so, but I'm not releasing an altcoin.  I want to get into the guts of it and that's all.  The other fork thing was trying to understand how hard forks work.
James Young
<altcoin><proof-of-work>
How to change Bitcoin's proof of work? Then enable miner
James Young
# How to change Bitcoin's proof of work? Then enable miner

(Asked by: username_0 on 2019-05-01)

I'm using <https://github.com/jgarzik/pyminer/blob/master/pyminer.py> to test a few different hash functions. Instead, I'd like to try keccak, a few of them in some order like an "X5" and so on.

This is a toy project to try and change the proof of work in Bitcoin and recompile and test, either an old version < 0.10.0 since getwork() might be easier to test with, or the latest release - apparently bitcoin-cli can mine blocks if starting from a new genesis block and the difficulty is set so low that a CPU can mine as much as you like.

My problem is that I can't find in Bitcoin Core where the proof of work is. I've looked in pow and validation files for near a week now, but no luck so far, or I just can't see it for some reason.

I thought it might have been obvious in miner.cpp which I think is no longer used (but might be able to be enabled?), and the best I can find is CheckProofOfWork in pow.cpp.

It doesn't seem to check whether the PoW is sha256d. Does it? I must be missing something. So it looks like I can just change the miner code and submit a proof of work and if it meets the requirements, it will be accepted.

Is there a reasonably easy way to use a toy miner, change the PoW algorithm, and modify Bitcoin Core if necessary to try a different proof of work?

> Edit: this is not altcoin development, it's an effort to understand Bitcoin's code in more detail. Please stop begging the question. Also please consider downvoting only questions which are truly useless instead of those you just don't like. Thanks!

**Tags:** altcoin, proof-of-work

> **Comments:**
> **username_0**: Edit: Found https://github.com/BitcoinHardfork/bitcoin and what seems easier to implement with adding a few new files and adjusting a couple of bits: use Keccak from some date also by Luke DashJr https://github.com/luke-jr/bitcoin/commit/8d3a84c242598ef3cdc733e99dddebfecdad84a6  Still no real information on how to get it going and test it though, unless it's as easy as cloning the code to make an altcoin and using this proof of work from the beginning.  
> **username_0**: Why was this down voted?  Changing a proof of work not an interesting enough topic for our voting overlords?  
> **username_1**: Generally speaking, altcoin "development" questions provide little to no value. Basic code comprehension assistance for a financial product being akin to asking for help finding the ignition button in an aircraft, we can help you with the very specific question, but everybody knows you're not getting off the ground.  
> **username_0**: Altcoin development is useful to understand the guts of Bitcoin.  Why isn't writing and modifying code considered useful anymore?  If you believe in learning by doing, along with books like Programming Bitcoin, then it's possible to get off the ground.  This is a very specific question, changing sha256d to something else. Isn't it? Why do I need anyone's permission to try this?  That's what it seems like.  
> **username_1**: I’ve been involved in Bitcoin for the better part of a decade and have never seen an instance of someone producing meaningful understanding by producing altcoins. It is usually the complete opposite, with misunderstanding born from the misconception that the implementation of Bitcoin has a huge amount to do with its overall design. The same way disassembling a cake doesn’t tell you much about its ingredients, or why taking a spanner to a car unsupervised can lead to confusion rather than detailed knowledge.  
> **username_1**: While you don’t need to ask our permission, you also don’t get to demand responses.  
> **username_0**: How is asking a question a demand for a response?  
> **username_0**: How is this an altcoin anyway?  Whoever said this was altcoin development?  Why is it not useful to understand where this is and how it works?  Learning by doing something can be useful in understanding. I don't see the disassembling of a cake analogy. Disassembling code is always useful to understand how it works, recompile, run it, get to know it.  I got the same bizarre responses when I asked about the mempool when all I wanted to do was get to know how it worked.  That was, instead of RBF, try to drop all transactions that are >= 3 hours old.  
> **username_1**: Overall the code in Bitcoin will teach you absolutely nothing about the underlying concepts, other than the eccentricities of the implementation itself.  
> **username_0**: I understand enough of the concepts, and I would like to understand the eccentricities of the implementation.  Why not, if you're going to hack on the code?  
> **username_2**: This is altcoin development because the end result is that you will have created an altcoin.  
> **username_0**: I guess so, but I'm not releasing an altcoin.  I want to get into the guts of it and that's all.  The other fork thing was trying to understand how hard forks work.  

---

## 1 answers

### Answer by username_2 on 2019-05-02. Score: 0 | Accepted answer

The hash function used in the Proof of Work is not some variable or additional data in blocks that Bitcoin Core needs to check. Furthermore, the Proof of Work is not just something that you submit; in fact, it is not a separate data field at all. The Proof of Work is the hash of the block header, and checking the Proof of Work means computing that hash and comparing it against the current target value.

So to change the proof of work algorithm, you need to change the hash function used for hashing block headers. Keep in mind that doing so will also change how blocks are identified because blocks are identified by hash.

The function that is called to compute and get the block header's hash can be found [here](https://github.com/bitcoin/bitcoin/blob/master/src/primitives/block.cpp#L13). This function itself calls a helper function which calls some other helpers. If you want to change the hash function used in the PoW, you need to change those helpers as well. Keep in mind that if you change those functions too, other things may break and more than the hash function used in the PoW will change.


---

