diff --git a/TODO.md b/TODO.md index fa7b35f85e..9a50c918dc 100644 --- a/TODO.md +++ b/TODO.md @@ -23,6 +23,7 @@ MUST-HAVE: - Adjust difficulty/subsidity (KGW, DGW based on blockheight) - Add masternode payment checks a.k.a. enforcement (based on blockheight) - Remove bitcoin dead weight (SHA256, hardcoded keys, nodes) +- Adjust wallet keypool size and add loading indicator on fresh wallet ADD-ON: diff --git a/configure.ac b/configure.ac index 7df52f6e77..e5290cb78f 100644 --- a/configure.ac +++ b/configure.ac @@ -137,7 +137,7 @@ AC_PATH_PROG(XGETTEXT,xgettext) AC_PATH_PROG(HEXDUMP,hexdump) PKG_PROG_PKG_CONFIG -# Enable debug +# Enable debug AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug], [use debug compiler flags and macros (default is no)])], @@ -148,11 +148,11 @@ if test "x$enable_debug" = xyes; then if test "x$GCC" = xyes; then CFLAGS="-g3 -O0 -DDEBUG" fi - + if test "x$GXX" = xyes; then CXXFLAGS="-g3 -O0 -DDEBUG" fi -fi +fi ## TODO: Remove these hard-coded paths and flags. They are here for the sake of ## compatibility with the legacy buildsystem. @@ -354,7 +354,9 @@ fi if test x$use_hardening != xno; then AX_CHECK_COMPILE_FLAG([-Wstack-protector],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wstack-protector"]) AX_CHECK_COMPILE_FLAG([-fstack-protector-all],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-protector-all"]) - AX_CHECK_COMPILE_FLAG([-fPIE],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fPIE"]) + +### -fPIE breaks X11 linking (sph_*) +# AX_CHECK_COMPILE_FLAG([-fPIE],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fPIE"]) AX_CHECK_PREPROC_FLAG([-D_FORTIFY_SOURCE=2],[ AX_CHECK_PREPROC_FLAG([-U_FORTIFY_SOURCE],[ @@ -368,10 +370,11 @@ if test x$use_hardening != xno; then AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"]) AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"]) - if test x$TARGET_OS != xwindows; then - # -pie will link successfully with MinGW, but it's unsupported and leads to undeterministic binaries - AX_CHECK_LINK_FLAG([[-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"]) - fi +### -fPIE breaks X11 linking (sph_*) +# if test x$TARGET_OS != xwindows; then +# # -pie will link successfully with MinGW, but it's unsupported and leads to undeterministic binaries +# AX_CHECK_LINK_FLAG([[-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"]) +# fi CXXFLAGS="$CXXFLAGS $HARDENED_CXXFLAGS" CPPFLAGS="$CPPFLAGS $HARDENED_CPPFLAGS" diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 9921661641..7fa9a3b3bd 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -39,7 +39,7 @@ public: vAlertPubKey = ParseHex("040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9"); nDefaultPort = 9999; nRPCPort = 9998; - bnProofOfWorkLimit = CBigNum(~uint256(0) >> 32); + bnProofOfWorkLimit = CBigNum(~uint256(0) >> 20); // Darkcoin starting difficulty is 1 / 2^12 nSubsidyHalvingInterval = 210000; // Genesis block @@ -59,13 +59,6 @@ public: genesis.nNonce = 28917698; hashGenesisBlock = genesis.GetHash(); - - /* exit without failure */ /* @TODO Debug remove! */ - printf("%s #HASH\n", hashGenesisBlock.ToString().c_str()); /* @TODO Debug remove! */ - printf("%s #HARD\n", uint256("0x00000ffd590b1485b3caadc19b22e6379c733355108f107a430458cdf3407ab6").ToString().c_str()); /* @TODO Debug remove! */ - printf("So far so good... Next: Update X11! \n"); /* @TODO Debug remove! */ - exit(0); /* @TODO Debug remove! */ - assert(hashGenesisBlock == uint256("0x00000ffd590b1485b3caadc19b22e6379c733355108f107a430458cdf3407ab6")); assert(genesis.hashMerkleRoot == uint256("0xe0028eb9648db56b1ac77cf090b99048a8007e2bb64b68f092c03c7f56a662c7")); @@ -131,13 +124,6 @@ public: genesis.nNonce = 3861367235; hashGenesisBlock = genesis.GetHash(); - - /* exit without failure */ /* @TODO Debug remove! */ - printf("%s #HASH\n", hashGenesisBlock.ToString().c_str()); /* @TODO Debug remove! */ - printf("%s #HARD\n", uint256("0x00000bafbc94add76cb75e2ec92894837288a481e5c005f6563d91623bf8bc2c").ToString().c_str()); /* @TODO Debug remove! */ - printf("So far so good... Next: Update X11! \n"); /* @TODO Debug remove! */ - exit(0); /* @TODO Debug remove! */ - assert(hashGenesisBlock == uint256("0x00000bafbc94add76cb75e2ec92894837288a481e5c005f6563d91623bf8bc2c")); vFixedSeeds.clear(); @@ -171,11 +157,11 @@ public: genesis.nTime = 1296688602; genesis.nBits = 0x207fffff; genesis.nNonce = 2; - hashGenesisBlock = genesis.GetHash(); nDefaultPort = 19994; strDataDir = "regtest"; - assert(hashGenesisBlock == uint256("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")); + hashGenesisBlock = genesis.GetHash(); + assert(hashGenesisBlock == uint256("0xa86aac1aa39f8296820ea3d710d07178492e201ff66cc311d4ad25042bb399d0")); vSeeds.clear(); // Regtest mode doesn't have any DNS seeds. } diff --git a/src/core.cpp b/src/core.cpp index 7651ce9957..5954ee716e 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin developers +// Copyright (c) 2014 vertoe & the Darkcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -214,7 +215,7 @@ uint64_t CTxOutCompressor::DecompressAmount(uint64_t x) uint256 CBlockHeader::GetHash() const { - return Hash(BEGIN(nVersion), END(nNonce)); + return HashX11(BEGIN(nVersion), END(nNonce)); } uint256 CBlock::BuildMerkleTree() const diff --git a/src/hash.h b/src/hash.h index 7dbf1b6448..8d529083c8 100644 --- a/src/hash.h +++ b/src/hash.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers +// Copyright (c) 2014 vertoe & the Darkcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -10,11 +11,63 @@ #include "uint256.h" #include "version.h" +#include "sph_blake.h" +#include "sph_bmw.h" +#include "sph_groestl.h" +#include "sph_jh.h" +#include "sph_keccak.h" +#include "sph_skein.h" +#include "sph_luffa.h" +#include "sph_cubehash.h" +#include "sph_shavite.h" +#include "sph_simd.h" +#include "sph_echo.h" + #include #include #include +#ifdef GLOBALDEFINED +#define GLOBAL +#else +#define GLOBAL extern +#endif + +GLOBAL sph_blake512_context z_blake; +GLOBAL sph_bmw512_context z_bmw; +GLOBAL sph_groestl512_context z_groestl; +GLOBAL sph_jh512_context z_jh; +GLOBAL sph_keccak512_context z_keccak; +GLOBAL sph_skein512_context z_skein; +GLOBAL sph_luffa512_context z_luffa; +GLOBAL sph_cubehash512_context z_cubehash; +GLOBAL sph_shavite512_context z_shavite; +GLOBAL sph_simd512_context z_simd; +GLOBAL sph_echo512_context z_echo; + +#define fillz() do { \ + sph_blake512_init(&z_blake); \ + sph_bmw512_init(&z_bmw); \ + sph_groestl512_init(&z_groestl); \ + sph_jh512_init(&z_jh); \ + sph_keccak512_init(&z_keccak); \ + sph_skein512_init(&z_skein); \ + sph_luffa512_init(&z_luffa); \ + sph_cubehash512_init(&z_cubehash); \ + sph_shavite512_init(&z_shavite); \ + sph_simd512_init(&z_simd); \ + sph_echo512_init(&z_echo); \ +} while (0) + +#define ZBLAKE (memcpy(&ctx_blake, &z_blake, sizeof(z_blake))) +#define ZBMW (memcpy(&ctx_bmw, &z_bmw, sizeof(z_bmw))) +#define ZGROESTL (memcpy(&ctx_groestl, &z_groestl, sizeof(z_groestl))) +#define ZJH (memcpy(&ctx_jh, &z_jh, sizeof(z_jh))) +#define ZKECCAK (memcpy(&ctx_keccak, &z_keccak, sizeof(z_keccak))) +#define ZSKEIN (memcpy(&ctx_skein, &z_skein, sizeof(z_skein))) + +/* ----------- Bitcoin Hash ------------------------------------------------- */ template inline uint256 Hash(const T1 pbegin, const T1 pend) { @@ -136,4 +189,71 @@ int HMAC_SHA512_Init(HMAC_SHA512_CTX *pctx, const void *pkey, size_t len); int HMAC_SHA512_Update(HMAC_SHA512_CTX *pctx, const void *pdata, size_t len); int HMAC_SHA512_Final(unsigned char *pmd, HMAC_SHA512_CTX *pctx); +/* ----------- Darkcoin Hash ------------------------------------------------ */ +template +inline uint256 HashX11(const T1 pbegin, const T1 pend) + +{ + sph_blake512_context ctx_blake; + sph_bmw512_context ctx_bmw; + sph_groestl512_context ctx_groestl; + sph_jh512_context ctx_jh; + sph_keccak512_context ctx_keccak; + sph_skein512_context ctx_skein; + sph_luffa512_context ctx_luffa; + sph_cubehash512_context ctx_cubehash; + sph_shavite512_context ctx_shavite; + sph_simd512_context ctx_simd; + sph_echo512_context ctx_echo; + static unsigned char pblank[1]; + + uint512 hash[17]; /* @TODO uint512 not declared */ + + sph_blake512_init(&ctx_blake); + sph_blake512 (&ctx_blake, (pbegin == pend ? pblank : static_cast(&pbegin[0])), (pend - pbegin) * sizeof(pbegin[0])); + sph_blake512_close(&ctx_blake, static_cast(&hash[0])); + + sph_bmw512_init(&ctx_bmw); + sph_bmw512 (&ctx_bmw, static_cast(&hash[0]), 64); + sph_bmw512_close(&ctx_bmw, static_cast(&hash[1])); + + sph_groestl512_init(&ctx_groestl); + sph_groestl512 (&ctx_groestl, static_cast(&hash[1]), 64); + sph_groestl512_close(&ctx_groestl, static_cast(&hash[2])); + + sph_skein512_init(&ctx_skein); + sph_skein512 (&ctx_skein, static_cast(&hash[2]), 64); + sph_skein512_close(&ctx_skein, static_cast(&hash[3])); + + sph_jh512_init(&ctx_jh); + sph_jh512 (&ctx_jh, static_cast(&hash[3]), 64); + sph_jh512_close(&ctx_jh, static_cast(&hash[4])); + + sph_keccak512_init(&ctx_keccak); + sph_keccak512 (&ctx_keccak, static_cast(&hash[4]), 64); + sph_keccak512_close(&ctx_keccak, static_cast(&hash[5])); + + sph_luffa512_init(&ctx_luffa); + sph_luffa512 (&ctx_luffa, static_cast(&hash[5]), 64); + sph_luffa512_close(&ctx_luffa, static_cast(&hash[6])); + + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512 (&ctx_cubehash, static_cast(&hash[6]), 64); + sph_cubehash512_close(&ctx_cubehash, static_cast(&hash[7])); + + sph_shavite512_init(&ctx_shavite); + sph_shavite512(&ctx_shavite, static_cast(&hash[7]), 64); + sph_shavite512_close(&ctx_shavite, static_cast(&hash[8])); + + sph_simd512_init(&ctx_simd); + sph_simd512 (&ctx_simd, static_cast(&hash[8]), 64); + sph_simd512_close(&ctx_simd, static_cast(&hash[9])); + + sph_echo512_init(&ctx_echo); + sph_echo512 (&ctx_echo, static_cast(&hash[9]), 64); + sph_echo512_close(&ctx_echo, static_cast(&hash[10])); + + return hash[10].trim256(); +} + #endif diff --git a/src/uint256.h b/src/uint256.h index ba903bc8fc..a3beb8b5e8 100644 --- a/src/uint256.h +++ b/src/uint256.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers +// Copyright (c) 2014 vertoe & the Darkcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -396,10 +397,12 @@ public: friend class uint160; friend class uint256; + friend class uint512; }; typedef base_uint<160> base_uint160; typedef base_uint<256> base_uint256; +typedef base_uint<512> base_uint512; @@ -632,4 +635,125 @@ inline const uint256 operator|(const uint256& a, const uint256& b) { return inline const uint256 operator+(const uint256& a, const uint256& b) { return (base_uint256)a + (base_uint256)b; } inline const uint256 operator-(const uint256& a, const uint256& b) { return (base_uint256)a - (base_uint256)b; } + + +////////////////////////////////////////////////////////////////////////////// +// +// uint512 +// + +/** 512-bit unsigned integer */ +class uint512 : public base_uint512 +{ +public: + typedef base_uint512 basetype; + + uint512() + { + for (int i = 0; i < WIDTH; i++) + pn[i] = 0; + } + + uint512(const basetype& b) + { + for (int i = 0; i < WIDTH; i++) + pn[i] = b.pn[i]; + } + + uint512& operator=(const basetype& b) + { + for (int i = 0; i < WIDTH; i++) + pn[i] = b.pn[i]; + return *this; + } + + uint512(uint64_t b) + { + pn[0] = (unsigned int)b; + pn[1] = (unsigned int)(b >> 32); + for (int i = 2; i < WIDTH; i++) + pn[i] = 0; + } + + uint512& operator=(uint64_t b) + { + pn[0] = (unsigned int)b; + pn[1] = (unsigned int)(b >> 32); + for (int i = 2; i < WIDTH; i++) + pn[i] = 0; + return *this; + } + + explicit uint512(const std::string& str) + { + SetHex(str); + } + + explicit uint512(const std::vector& vch) + { + if (vch.size() == sizeof(pn)) + memcpy(pn, &vch[0], sizeof(pn)); + else + *this = 0; + } + + uint256 trim256() const + { + uint256 ret; + for (unsigned int i = 0; i < uint256::WIDTH; i++){ + ret.pn[i] = pn[i]; + } + return ret; + } +}; + +inline bool operator==(const uint512& a, uint64_t b) { return (base_uint512)a == b; } +inline bool operator!=(const uint512& a, uint64_t b) { return (base_uint512)a != b; } +inline const uint512 operator<<(const base_uint512& a, unsigned int shift) { return uint512(a) <<= shift; } +inline const uint512 operator>>(const base_uint512& a, unsigned int shift) { return uint512(a) >>= shift; } +inline const uint512 operator<<(const uint512& a, unsigned int shift) { return uint512(a) <<= shift; } +inline const uint512 operator>>(const uint512& a, unsigned int shift) { return uint512(a) >>= shift; } + +inline const uint512 operator^(const base_uint512& a, const base_uint512& b) { return uint512(a) ^= b; } +inline const uint512 operator&(const base_uint512& a, const base_uint512& b) { return uint512(a) &= b; } +inline const uint512 operator|(const base_uint512& a, const base_uint512& b) { return uint512(a) |= b; } +inline const uint512 operator+(const base_uint512& a, const base_uint512& b) { return uint512(a) += b; } +inline const uint512 operator-(const base_uint512& a, const base_uint512& b) { return uint512(a) -= b; } + +inline bool operator<(const base_uint512& a, const uint512& b) { return (base_uint512)a < (base_uint512)b; } +inline bool operator<=(const base_uint512& a, const uint512& b) { return (base_uint512)a <= (base_uint512)b; } +inline bool operator>(const base_uint512& a, const uint512& b) { return (base_uint512)a > (base_uint512)b; } +inline bool operator>=(const base_uint512& a, const uint512& b) { return (base_uint512)a >= (base_uint512)b; } +inline bool operator==(const base_uint512& a, const uint512& b) { return (base_uint512)a == (base_uint512)b; } +inline bool operator!=(const base_uint512& a, const uint512& b) { return (base_uint512)a != (base_uint512)b; } +inline const uint512 operator^(const base_uint512& a, const uint512& b) { return (base_uint512)a ^ (base_uint512)b; } +inline const uint512 operator&(const base_uint512& a, const uint512& b) { return (base_uint512)a & (base_uint512)b; } +inline const uint512 operator|(const base_uint512& a, const uint512& b) { return (base_uint512)a | (base_uint512)b; } +inline const uint512 operator+(const base_uint512& a, const uint512& b) { return (base_uint512)a + (base_uint512)b; } +inline const uint512 operator-(const base_uint512& a, const uint512& b) { return (base_uint512)a - (base_uint512)b; } + +inline bool operator<(const uint512& a, const base_uint512& b) { return (base_uint512)a < (base_uint512)b; } +inline bool operator<=(const uint512& a, const base_uint512& b) { return (base_uint512)a <= (base_uint512)b; } +inline bool operator>(const uint512& a, const base_uint512& b) { return (base_uint512)a > (base_uint512)b; } +inline bool operator>=(const uint512& a, const base_uint512& b) { return (base_uint512)a >= (base_uint512)b; } +inline bool operator==(const uint512& a, const base_uint512& b) { return (base_uint512)a == (base_uint512)b; } +inline bool operator!=(const uint512& a, const base_uint512& b) { return (base_uint512)a != (base_uint512)b; } +inline const uint512 operator^(const uint512& a, const base_uint512& b) { return (base_uint512)a ^ (base_uint512)b; } +inline const uint512 operator&(const uint512& a, const base_uint512& b) { return (base_uint512)a & (base_uint512)b; } +inline const uint512 operator|(const uint512& a, const base_uint512& b) { return (base_uint512)a | (base_uint512)b; } +inline const uint512 operator+(const uint512& a, const base_uint512& b) { return (base_uint512)a + (base_uint512)b; } +inline const uint512 operator-(const uint512& a, const base_uint512& b) { return (base_uint512)a - (base_uint512)b; } + +inline bool operator<(const uint512& a, const uint512& b) { return (base_uint512)a < (base_uint512)b; } +inline bool operator<=(const uint512& a, const uint512& b) { return (base_uint512)a <= (base_uint512)b; } +inline bool operator>(const uint512& a, const uint512& b) { return (base_uint512)a > (base_uint512)b; } +inline bool operator>=(const uint512& a, const uint512& b) { return (base_uint512)a >= (base_uint512)b; } +inline bool operator==(const uint512& a, const uint512& b) { return (base_uint512)a == (base_uint512)b; } +inline bool operator!=(const uint512& a, const uint512& b) { return (base_uint512)a != (base_uint512)b; } +inline const uint512 operator^(const uint512& a, const uint512& b) { return (base_uint512)a ^ (base_uint512)b; } +inline const uint512 operator&(const uint512& a, const uint512& b) { return (base_uint512)a & (base_uint512)b; } +inline const uint512 operator|(const uint512& a, const uint512& b) { return (base_uint512)a | (base_uint512)b; } +inline const uint512 operator+(const uint512& a, const uint512& b) { return (base_uint512)a + (base_uint512)b; } +inline const uint512 operator-(const uint512& a, const uint512& b) { return (base_uint512)a - (base_uint512)b; } + #endif