New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change PoW to Equihash #15

Merged
merged 21 commits into from Oct 19, 2017

Conversation

Projects
None yet
8 participants
@h4x3rotab
Contributor

h4x3rotab commented Sep 20, 2017

This ongoing PR changes the PoW to Equihash. The implementation of Equihash is taken from Zcash project.

It will include the following modifications:

  • Link sodium for Equihash library
  • Extend block header to include Equihash solution
    • Embed Equihash related consensus parameters
    • Introduce a new block version
    • Add Equihash solution field to block header
    • Legacy node serialization compatibility
    • Be Zcash miner compatible
  • Change PoW after fork height
    • Add PoW functions
    • Introduce Equihash block validation for the hard fork
    • Fix mining RPCs
  • Fix rest RPCs
  • Tests
    • Unittest everywhere
    • Regression test
  • Fix compact block

h4x3rotab added some commits Sep 11, 2017

PoW: Add dependency libsdoium for equihash.
Tested:
make (macOS 10.12.5, Xcode 8.3.3)
Hardfork: Introduce new protocol version & versionbits.
Protocol version: 70016 (BTG_HARD_FORK_VERSION)
Version bits: 0x60000000
Hardfork: New fields in block header
- Add two new fields: nHeight, nSolution (for Equihash)
- Calculate block hash in new block format after the hard fork.
- Serialize block in legacy format when talking to Bitcoin node.

Tested:
unittest
@h4x3rotab

This comment has been minimized.

Show comment
Hide comment
@h4x3rotab

h4x3rotab Sep 29, 2017

Contributor

Compact block is broken by new block format. Seems we have to fix it.

Contributor

h4x3rotab commented Sep 29, 2017

Compact block is broken by new block format. Seems we have to fix it.

h4x3rotab added some commits Sep 30, 2017

Link sodium in qt wallet.
Tested:
./autogen.sh && make
PoW: Add Equihash validation functions.
- Initialize sodium on startup
- Add Equihash validation logic
- Fix missing htole32 problem in mingw build.
@sennevb

This comment has been minimized.

Show comment
Hide comment
@sennevb

sennevb Oct 4, 2017

Watching this one closely, interested to add this coin to the pool on launch..

sennevb commented Oct 4, 2017

Watching this one closely, interested to add this coin to the pool on launch..

@daira

This comment has been minimized.

Show comment
Hide comment
@daira

daira Oct 5, 2017

(Zcash developer here.)

Zcash will also need to add compact blocks. We haven't thought about it much yet but our ticket for that is zcash/zcash#2316 . Let's cooperate on a spec.

daira commented Oct 5, 2017

(Zcash developer here.)

Zcash will also need to add compact blocks. We haven't thought about it much yet but our ticket for that is zcash/zcash#2316 . Let's cooperate on a spec.

h4x3rotab added some commits Oct 8, 2017

Backward compatible block serialization.
- Serialize in different formats based on the net protocol version.
- Remove the version bit 0x40000000.
- Support legacy block format for RPCs: getblock, getblockheader, getblocktemplate, submitblock.
- Temporarily disable SEND_CMPT.

Tested:
unit tests
Fix broken regression tests.
Intended broken testes:
- p2p-compactblocks.py
- rest.py

Tested:
reg tests.
Show outdated Hide outdated src/net.h

h4x3rotab added some commits Oct 11, 2017

Block header compatible with Zcash.
- Add fields to block header for Zcash compatibility
- Extend the nonce from `uint32_t` to `uint256`
- Add 'nonceUint32' for backward compatibility:
  - RPC: 'getblockheader', 'getblock'
  - Rest: '/rest/headers', '/rest/block'

Tested:
./src/test/test_bitcoin
./test/functional/test_runner.py
(all passed except intended failures: p2p-compactblocks.py, rest.py)
@daira

This comment has been minimized.

Show comment
Hide comment
@daira

daira Oct 11, 2017

hashReserved in a Zcash header is 32 bytes; this is 12 bytes.

daira commented on src/chain.h in 55c71bd Oct 11, 2017

hashReserved in a Zcash header is 32 bytes; this is 12 bytes.

This comment has been minimized.

Show comment
Hide comment
@h4x3rotab

h4x3rotab Oct 12, 2017

Contributor

Thank you for pointing out! It should be 32-4=28 bytes here, and also in CBlockHeader.

To be compatible with Zcash block header, the first 4 bytes of the hashReserved is used. The serialization of CBlockHeader in primitives/block.h reflects this.

Contributor

h4x3rotab replied Oct 12, 2017

Thank you for pointing out! It should be 32-4=28 bytes here, and also in CBlockHeader.

To be compatible with Zcash block header, the first 4 bytes of the hashReserved is used. The serialization of CBlockHeader in primitives/block.h reflects this.

This comment has been minimized.

Show comment
Hide comment
@h4x3rotab

h4x3rotab Oct 12, 2017

Contributor

Changed to uint32_t nReserved[7].

Contributor

h4x3rotab replied Oct 12, 2017

Changed to uint32_t nReserved[7].

@daira

This comment has been minimized.

Show comment
Hide comment
@daira

daira Oct 11, 2017

+1 on explicitly serializing the height; Zcash will probably change to do that at some point (zcash/zcash#2539). Of course this makes the format strictly incompatible with current Zcash, but it's in a good cause.

daira commented on src/chain.h in 55c71bd Oct 11, 2017

+1 on explicitly serializing the height; Zcash will probably change to do that at some point (zcash/zcash#2539). Of course this makes the format strictly incompatible with current Zcash, but it's in a good cause.

This comment has been minimized.

Show comment
Hide comment
@daira

daira Oct 11, 2017

You probably also want to change the consensus rule about the height in the coinbase transaction, though. (Unless you've already done that and I missed it.)

daira replied Oct 11, 2017

You probably also want to change the consensus rule about the height in the coinbase transaction, though. (Unless you've already done that and I missed it.)

This comment has been minimized.

Show comment
Hide comment
@martin-key

martin-key Oct 11, 2017

Contributor
Contributor

martin-key replied Oct 11, 2017

This comment has been minimized.

Show comment
Hide comment
@h4x3rotab

h4x3rotab Oct 12, 2017

Contributor

In my understanding, Bitcoin already gas block height stored in the coinbase. I think it's better to keep it there. Did I miss any other consensus rule to change?

Contributor

h4x3rotab replied Oct 12, 2017

In my understanding, Bitcoin already gas block height stored in the coinbase. I think it's better to keep it there. Did I miss any other consensus rule to change?

@antonifigueiredo

This comment has been minimized.

Show comment
Hide comment
@antonifigueiredo

antonifigueiredo Oct 11, 2017

Boa tarde, qual a previsão de Exchange terá o BTG? (BITCOINGOLD)?

antonifigueiredo commented Oct 11, 2017

Boa tarde, qual a previsão de Exchange terá o BTG? (BITCOINGOLD)?

h4x3rotab added some commits Oct 12, 2017

Fix unaligned block header problem.
Also add a test to ensure Zcash compability.

Tested:
./src/test/test_bitcoin --run_test=btg_tests
Add the sanity test for libsodium.
Tested:
./src/test/test_bitcoin --run_test=sanity_tests
Add unittests for Equihash PoW.
Tested:
./src/test/test_bitcoin --run_test=equihash_tests
RPC for mining and basic tests.
- RPC
  - generate
  - generatetoaddress
  - getblocktemplate
- Add regtest `btg-hardfork.py`

Tested:
./src/test/test_bitcoin
./test/functional/test_runner.py
@h4x3rotab

This comment has been minimized.

Show comment
Hide comment
@h4x3rotab

h4x3rotab Oct 18, 2017

Contributor

It's time to do mining tests. No way to do it in a regular regression test as there's no existing Equihash solver in Python.

Contributor

h4x3rotab commented Oct 18, 2017

It's time to do mining tests. No way to do it in a regular regression test as there's no existing Equihash solver in Python.

@peter-bonanni

This comment has been minimized.

Show comment
Hide comment
@peter-bonanni

peter-bonanni commented Oct 18, 2017

@h4x3rotab

https://github.com/str4d/zcash-pow

Isn't this an Equihash python solver?

@oliverw

This comment has been minimized.

Show comment
Hide comment
@oliverw

oliverw Oct 18, 2017

@h4x3rotab Is the daemon ready for pool integration now?

oliverw commented Oct 18, 2017

@h4x3rotab Is the daemon ready for pool integration now?

@h4x3rotab

This comment has been minimized.

Show comment
Hide comment
@h4x3rotab

h4x3rotab Oct 19, 2017

Contributor

This change should be further tested but for now let's merge it to the staging tree. I will create another issue to track the process of PoW changes & tests.

Will submit after it passes TravisCI check.

Contributor

h4x3rotab commented Oct 19, 2017

This change should be further tested but for now let's merge it to the staging tree. I will create another issue to track the process of PoW changes & tests.

Will submit after it passes TravisCI check.

@h4x3rotab h4x3rotab merged commit 2f5fe4c into BTCGPU:master Oct 19, 2017

1 check failed

continuous-integration/travis-ci/pr The Travis CI build failed
Details

@h4x3rotab h4x3rotab changed the title from [WIP] Change PoW to Equihash to Change PoW to Equihash Oct 19, 2017

h4x3rotab pushed a commit to h4x3rotab/BTCGPU that referenced this pull request May 6, 2018

Squashed 'src/leveldb/' changes from c521b3ac65..64052c76c5
64052c76c5 Merge #15: Add filename to corruption errors
135ed0fb4e Add filename to corruption errors

git-subtree-dir: src/leveldb
git-subtree-split: 64052c76c567cff3dad32d1db0ef969d97b5882f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment