How to change Bitcoin's proof of work? Then enable miner

-2

1

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!

James Young

Posted 2019-05-01T10:19:29.480

Reputation: 3

Question was closed 2019-05-09T17:09:37.967

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 2019-05-01T12:15:21.397

Why was this down voted? Changing a proof of work not an interesting enough topic for our voting overlords?James Young 2019-05-01T16:57:18.823

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.Anonymous 2019-05-02T15:08:03.433

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 2019-05-02T20:22:30.477

1I’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.Anonymous 2019-05-02T20:27:10.450

While you don’t need to ask our permission, you also don’t get to demand responses.Anonymous 2019-05-02T20:30:05.857

How is asking a question a demand for a response?James Young 2019-05-02T20:44:07.003

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 2019-05-02T20:49:47.033

Overall the code in Bitcoin will teach you absolutely nothing about the underlying concepts, other than the eccentricities of the implementation itself.Anonymous 2019-05-02T20:54:27.043

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 2019-05-02T20:55:58.307

2This is altcoin development because the end result is that you will have created an altcoin.Andrew Chow 2019-05-02T23:20:40.403

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 2019-05-03T00:19:13.577

Answers

0

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. 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.

Andrew Chow

Posted 2019-05-01T10:19:29.480

Reputation: 40 910