From ae37d2a4cd4c9b0ac5c4d75c664be735acbd029e Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 8 Jun 2016 17:08:18 +1200 Subject: [PATCH] Increase Equihash parameters to n = 96, k = 3 (about 430 MiB) Includes a tweak to set the fixed-width of the rows based on whether the first or last round is widest. This is necessary for some parameters, these ones included. --- src/chainparams.cpp | 12 ++++++------ src/crypto/equihash.cpp | 6 ++++++ src/crypto/equihash.h | 23 +++++++++++++++++------ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index ffadb9aa..7d303c1b 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -57,7 +57,7 @@ public: nMaxTipAge = 24 * 60 * 60; nPruneAfterHeight = 100000; nEquihashN = 96; - nEquihashK = 5; + nEquihashK = 3; /** * Build the genesis block. Note that the output of its generation @@ -85,11 +85,11 @@ public: // TODO generate harder genesis block //genesis.nBits = 0x1d00ffff; genesis.nBits = 0x207fffff; - genesis.nNonce = uint256S("0x0000000000000000000000000000000000000000000000000000000000000000"); - genesis.nSolution = {773, 46853, 54408, 65156, 29285, 44102, 84988, 128460, 5860, 111278, 95422, 129486, 54642, 125867, 57543, 96097, 6078, 6558, 43915, 99542, 10589, 52817, 28411, 63634, 17935, 94053, 50292, 64483, 22825, 62674, 69078, 121059}; + genesis.nNonce = uint256S("0x0000000000000000000000000000000000000000000000000000000000000001"); + genesis.nSolution = {587569, 8525894, 21341434, 29850428, 1031007, 14893603, 13508924, 18130124}; consensus.hashGenesisBlock = genesis.GetHash(); - assert(consensus.hashGenesisBlock == uint256S("0x1a856940aa2b37400e4d889b2c0316eccfc122e59964e74f9d5fc98cc47d3699")); + assert(consensus.hashGenesisBlock == uint256S("0x684925e346301a043b8f00ff81e2f96b0aab01ca177c72a29684cb682fb4f91e")); assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b")); vSeeds.push_back(CDNSSeedData("bitcoin.sipa.be", "seed.bitcoin.sipa.be")); // Pieter Wuille @@ -164,9 +164,9 @@ public: genesis.nTime = 1296688602; genesis.nBits = 0x207fffff; genesis.nNonce = uint256S("0x0000000000000000000000000000000000000000000000000000000000000000"); - genesis.nSolution = {2184, 77353, 22195, 83183, 8583, 109239, 67980, 100293, 42343, 118176, 48012, 76297, 50185, 118569, 78836, 127080, 4206, 16928, 112292, 130288, 17661, 41103, 69659, 114244, 14046, 116389, 17114, 42365, 47122, 58879, 56126, 129086}; + genesis.nSolution = {580051, 20198535, 25959899, 26476684, 6432082, 23053925, 18828144, 32724963}; consensus.hashGenesisBlock = genesis.GetHash(); - assert(consensus.hashGenesisBlock == uint256S("0x2121b53914dbfe110c5521c5bb81ff86bde4c0dd94f332f72e2c35ffa391b46e")); + assert(consensus.hashGenesisBlock == uint256S("0x260cf174620023182937d89aa5fa5f08df2193e9f775bab7de02f3d1f6eba4c2")); vFixedSeeds.clear(); vSeeds.clear(); diff --git a/src/crypto/equihash.cpp b/src/crypto/equihash.cpp index f2a3ca0c..784735e4 100644 --- a/src/crypto/equihash.cpp +++ b/src/crypto/equihash.cpp @@ -551,6 +551,12 @@ bool Equihash::IsValidSolution(const eh_HashState& base_state, std::vector< return X[0].IsZero(hashLen); } +// Explicit instantiations for Equihash<96,3> +template int Equihash<96,3>::InitialiseState(eh_HashState& base_state); +template std::set> Equihash<96,3>::BasicSolve(const eh_HashState& base_state); +template std::set> Equihash<96,3>::OptimisedSolve(const eh_HashState& base_state); +template bool Equihash<96,3>::IsValidSolution(const eh_HashState& base_state, std::vector soln); + // Explicit instantiations for Equihash<96,5> template int Equihash<96,5>::InitialiseState(eh_HashState& base_state); template std::set> Equihash<96,5>::BasicSolve(const eh_HashState& base_state); diff --git a/src/crypto/equihash.h b/src/crypto/equihash.h index 373daf46..2add95e8 100644 --- a/src/crypto/equihash.h +++ b/src/crypto/equihash.h @@ -108,6 +108,8 @@ public: eh_trunc* GetTruncatedIndices(size_t len, size_t lenIndices) const; }; +inline constexpr const size_t max(const size_t A, const size_t B) { return A > B ? A : B; } + template class Equihash { @@ -122,8 +124,8 @@ public: enum { CollisionByteLength=CollisionBitLength/8 }; enum : size_t { FullWidth=2*CollisionByteLength+sizeof(eh_index)*(1 << (K-1)) }; enum : size_t { FinalFullWidth=2*CollisionByteLength+sizeof(eh_index)*(1 << (K)) }; - enum : size_t { TruncatedWidth=2*CollisionByteLength+sizeof(eh_trunc)*(1 << (K-1)) }; - enum : size_t { FinalTruncatedWidth=2*CollisionByteLength+sizeof(eh_trunc)*(1 << (K)) }; + enum : size_t { TruncatedWidth=max((N/8)+sizeof(eh_trunc), 2*CollisionByteLength+sizeof(eh_trunc)*(1 << (K-1))) }; + enum : size_t { FinalTruncatedWidth=max((N/8)+sizeof(eh_trunc), 2*CollisionByteLength+sizeof(eh_trunc)*(1 << (K))) }; Equihash() { } @@ -135,11 +137,14 @@ public: #include "equihash.tcc" +static Equihash<96,3> Eh96_3; static Equihash<96,5> Eh96_5; static Equihash<48,5> Eh48_5; #define EhInitialiseState(n, k, base_state) \ - if (n == 96 && k == 5) { \ + if (n == 96 && k == 3) { \ + Eh96_3.InitialiseState(base_state); \ + } else if (n == 96 && k == 5) { \ Eh96_5.InitialiseState(base_state); \ } else if (n == 48 && k == 5) { \ Eh48_5.InitialiseState(base_state); \ @@ -148,7 +153,9 @@ static Equihash<48,5> Eh48_5; } #define EhBasicSolve(n, k, base_state, solns) \ - if (n == 96 && k == 5) { \ + if (n == 96 && k == 3) { \ + solns = Eh96_3.BasicSolve(base_state); \ + } else if (n == 96 && k == 5) { \ solns = Eh96_5.BasicSolve(base_state); \ } else if (n == 48 && k == 5) { \ solns = Eh48_5.BasicSolve(base_state); \ @@ -157,7 +164,9 @@ static Equihash<48,5> Eh48_5; } #define EhOptimisedSolve(n, k, base_state, solns) \ - if (n == 96 && k == 5) { \ + if (n == 96 && k == 3) { \ + solns = Eh96_3.OptimisedSolve(base_state); \ + } else if (n == 96 && k == 5) { \ solns = Eh96_5.OptimisedSolve(base_state); \ } else if (n == 48 && k == 5) { \ solns = Eh48_5.OptimisedSolve(base_state); \ @@ -166,7 +175,9 @@ static Equihash<48,5> Eh48_5; } #define EhIsValidSolution(n, k, base_state, soln, ret) \ - if (n == 96 && k == 5) { \ + if (n == 96 && k == 3) { \ + ret = Eh96_3.IsValidSolution(base_state, soln); \ + } else if (n == 96 && k == 5) { \ ret = Eh96_5.IsValidSolution(base_state, soln); \ } else if (n == 48 && k == 5) { \ ret = Eh48_5.IsValidSolution(base_state, soln); \