Browse Source

Fixing compatibility with libssl1.1

psy 2 years ago
parent
commit
d5a093a6aa
100 changed files with 998 additions and 703 deletions
  1. 3 3
      ecoin/INSTALL
  2. 1 1
      ecoin/doc/DNSSEEDS.txt
  3. 1 1
      ecoin/doc/MINING.txt
  4. 1 1
      ecoin/doc/REWARDS.txt
  5. 1 1
      ecoin/doc/TRANSLATIONS.txt
  6. 5 4
      ecoin/doc/build-linux.txt
  7. 1 1
      ecoin/doc/qr-codes.txt
  8. 2 2
      ecoin/ecoin-qt.pro
  9. 1 1
      ecoin/src/addrman.cpp
  10. 2 1
      ecoin/src/addrman.h
  11. 1 1
      ecoin/src/alert.cpp
  12. 1 1
      ecoin/src/alert.h
  13. 2 1
      ecoin/src/allocators.h
  14. 2 1
      ecoin/src/base58.h
  15. 146 70
      ecoin/src/bignum.h
  16. 2 1
      ecoin/src/checkpoints.cpp
  17. 2 1
      ecoin/src/checkpoints.h
  18. 2 1
      ecoin/src/clientversion.h
  19. 2 1
      ecoin/src/coincontrol.h
  20. 2 1
      ecoin/src/compat.h
  21. 22 5
      ecoin/src/crypter.cpp
  22. 31 24
      ecoin/src/crypter.h
  23. 1 1
      ecoin/src/db.cpp
  24. 95 13
      ecoin/src/db.h
  25. 12 12
      ecoin/src/ecoinrpc.cpp
  26. 60 15
      ecoin/src/ecoinrpc.h
  27. 2 1
      ecoin/src/init.cpp
  28. 2 1
      ecoin/src/init.h
  29. 2 1
      ecoin/src/irc.cpp
  30. 2 1
      ecoin/src/irc.h
  31. 2 1
      ecoin/src/kernel.cpp
  32. 2 1
      ecoin/src/kernel.h
  33. 54 14
      ecoin/src/key.cpp
  34. 2 1
      ecoin/src/key.h
  35. 2 1
      ecoin/src/keystore.cpp
  36. 2 1
      ecoin/src/keystore.h
  37. 8 7
      ecoin/src/main.cpp
  38. 2 1
      ecoin/src/main.h
  39. 2 4
      ecoin/src/makefile.bsd
  40. 3 5
      ecoin/src/makefile.linux
  41. 1 4
      ecoin/src/makefile.linux-mingw
  42. 1 4
      ecoin/src/makefile.linux32-mingw
  43. 1 4
      ecoin/src/makefile.linux64-mingw
  44. 1 4
      ecoin/src/makefile.mingw
  45. 1 4
      ecoin/src/makefile.osx
  46. 2 4
      ecoin/src/makefile.unix
  47. 2 1
      ecoin/src/miner.cpp
  48. 2 1
      ecoin/src/miner.h
  49. 2 2
      ecoin/src/mruset.h
  50. 5 2
      ecoin/src/net.cpp
  51. 2 3
      ecoin/src/net.h
  52. 1 2
      ecoin/src/netbase.cpp
  53. 2 2
      ecoin/src/netbase.h
  54. 1 2
      ecoin/src/noui.cpp
  55. 1 2
      ecoin/src/pbkdf2.cpp
  56. 1 2
      ecoin/src/pbkdf2.h
  57. 1 2
      ecoin/src/protocol.cpp
  58. 1 2
      ecoin/src/protocol.h
  59. 2 1
      ecoin/src/rpcblockchain.cpp
  60. 2 1
      ecoin/src/rpcdump.cpp
  61. 5 2
      ecoin/src/rpcmining.cpp
  62. 2 1
      ecoin/src/rpcnet.cpp
  63. 14 13
      ecoin/src/rpcrawtransaction.cpp
  64. 13 11
      ecoin/src/rpcwallet.cpp
  65. 4 5
      ecoin/src/script.cpp
  66. 192 12
      ecoin/src/script.h
  67. 1 1
      ecoin/src/scrypt-arm.S
  68. 1 1
      ecoin/src/scrypt-x86.S
  69. 1 1
      ecoin/src/scrypt-x86_64.S
  70. 1 30
      ecoin/src/scrypt.cpp
  71. 2 1
      ecoin/src/scrypt.h
  72. 2 1
      ecoin/src/serialize.h
  73. 1 1
      ecoin/src/strlcpy.h
  74. 2 1
      ecoin/src/sync.cpp
  75. 2 1
      ecoin/src/sync.h
  76. 1 1
      ecoin/src/txdb-leveldb.cpp
  77. 1 1
      ecoin/src/txdb-leveldb.h
  78. 1 1
      ecoin/src/txdb.h
  79. 2 1
      ecoin/src/ui_interface.h
  80. 1 1
      ecoin/src/uint256.h
  81. 1 1
      ecoin/src/util.cpp
  82. 1 1
      ecoin/src/util.h
  83. 1 1
      ecoin/src/version.cpp
  84. 1 1
      ecoin/src/version.h
  85. 5 3
      ecoin/src/wallet.cpp
  86. 1 1
      ecoin/src/wallet.h
  87. 1 1
      ecoin/src/walletdb.cpp
  88. 1 1
      ecoin/src/walletdb.h
  89. 3 14
      ecoin/src/zerocoin/Accumulator.cpp
  90. 7 17
      ecoin/src/zerocoin/Accumulator.h
  91. 42 53
      ecoin/src/zerocoin/AccumulatorProofOfKnowledge.cpp
  92. 41 51
      ecoin/src/zerocoin/AccumulatorProofOfKnowledge.h
  93. 10 21
      ecoin/src/zerocoin/Coin.cpp
  94. 8 19
      ecoin/src/zerocoin/Coin.h
  95. 2 13
      ecoin/src/zerocoin/CoinSpend.cpp
  96. 5 15
      ecoin/src/zerocoin/CoinSpend.h
  97. 25 35
      ecoin/src/zerocoin/Commitment.cpp
  98. 11 21
      ecoin/src/zerocoin/Commitment.h
  99. 63 93
      ecoin/src/zerocoin/ParamGeneration.cpp
  100. 0 0
      ecoin/src/zerocoin/ParamGeneration.h

+ 3 - 3
ecoin/INSTALL

@@ -1,5 +1,5 @@
 
-ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 ===================================================
 # BUILDS - ECOlogical P2P Crypto-Currency (ECOin) #
@@ -13,7 +13,7 @@ cd ecoin/
 
   + GNU/Linux:
 
-	/usr/lib/x86_64-linux-gnu/qt4/bin/qmake USE_UPNP=0 -o Makefile ecoin-qt.pro
+	/usr/lib/x86_64-linux-gnu/qt4/bin/qmake USE_UPNP=0 USE_IPV6=0 -o Makefile ecoin-qt.pro
 
 ================
 + Build leveldb:
@@ -79,7 +79,7 @@ See doc/build-*.txt for detailed instructions on building /ecoind/ on different
         server=1
         daemon=1
         testnet=0
-	addnode = 46.163.118.220 # node -> turina.space
+	addnode = 176.28.23.46 # 03c8.net
 
      ./ecoind -conf=/home/$USER/.ecoin/ecoin.conf 
 

+ 1 - 1
ecoin/doc/DNSSEEDS.txt

@@ -1,5 +1,5 @@
 
-ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 =====================================================
 # DNSSEEDS - ECOlogical P2P Crypto-Currency (ECOin) #

+ 1 - 1
ecoin/doc/MINING.txt

@@ -1,5 +1,5 @@
 
-ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 ===================================================
 # MINING - ECOlogical P2P Crypto-Currency (ECOin) #

+ 1 - 1
ecoin/doc/REWARDS.txt

@@ -1,5 +1,5 @@
 
-ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 ====================================================
 # REWARDS - ECOlogical P2P Crypto-Currency (ECOin) #

+ 1 - 1
ecoin/doc/TRANSLATIONS.txt

@@ -1,5 +1,5 @@
 
-ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 =========================================================
 # TRANSLATIONS - ECOlogical P2P Crypto-Currency (ECOin) #

+ 5 - 4
ecoin/doc/build-linux.txt

@@ -1,5 +1,5 @@
 
-ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 ======================================
 # SOURCES for ECOin (Unix/GNU-Linux) #
@@ -29,7 +29,8 @@ All of the commands should be executed in a shell.
 
  Library       Purpose           Description
  -------       -------           -----------
- libssl1.0-dev SSL Support       Secure communications
+ libssl-dev    SSL Support       Secure communications - development libraries
+ libssl1.1     SSL Support       Secure Sockets Layer toolkit - shared libraries
  libdb5.3      Berkeley DB       Blockchain & wallet storage
  libboost      Boost             C++ Library
  miniupnpc     UPnP Support      Optional firewall-jumping support
@@ -37,7 +38,7 @@ All of the commands should be executed in a shell.
 
     + From Debian/Ubuntu:
   
-        sudo apt-get install build-essential libssl1.0-dev libssl1.0.2 libdb5.3-dev libdb5.3++-dev libboost-all-dev miniupnpc libminiupnpc-dev
+        sudo apt-get install build-essential libssl-dev libssl1.1 libdb5.3-dev libdb5.3++-dev libboost-all-dev miniupnpc libminiupnpc-dev
 
         + Optionally install qrencode (and set USE_QRCODE=1):
 
@@ -60,7 +61,7 @@ All of the commands should be executed in a shell.
 (1.) First, make sure that the required packages for Qt4 development of your distribution are installed, for Debian and Ubuntu these are:
 
         sudo apt-get install qt4-qmake libqt4-dev build-essential libboost-dev libboost-system-dev miniupnpc libminiupnpc-dev \
-             libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev libssl1.0-dev libssl1.0.2 libdb5.3++-dev
+             libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev libssl-dev libssl1.1 libdb5.3++-dev
 
 (2.) Then execute the following:
 

+ 1 - 1
ecoin/doc/qr-codes.txt

@@ -1,5 +1,5 @@
 
-ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 =====================================================
 # QR-Codes - ECOlogical P2P Crypto-Currency (ECOin) #

+ 2 - 2
ecoin/ecoin-qt.pro

@@ -1,9 +1,9 @@
 
-# ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+# ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 TEMPLATE = app
 TARGET = ecoin-qt
-VERSION = 0.0.2
+VERSION = 0.0.3
 INCLUDEPATH += src src/json src/qt
 DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE
 CONFIG += no_include_pwd

+ 1 - 1
ecoin/src/addrman.cpp

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include "addrman.h"
 

+ 2 - 1
ecoin/src/addrman.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef _ECOIN_ADDRMAN
 #define _ECOIN_ADDRMAN 1
 

+ 1 - 1
ecoin/src/alert.cpp

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include <boost/foreach.hpp>
 #include <map>

+ 1 - 1
ecoin/src/alert.h

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #ifndef _ECOINALERT_H_
 #define _ECOINALERT_H_ 1

+ 2 - 1
ecoin/src/allocators.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_ALLOCATORS_H
 #define ECOIN_ALLOCATORS_H
 

+ 2 - 1
ecoin/src/base58.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_BASE58_H
 #define ECOIN_BASE58_H
 

+ 146 - 70
ecoin/src/bignum.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_BIGNUM_H
 #define ECOIN_BIGNUM_H
 
@@ -45,52 +46,65 @@ public:
 
 
 /** C++ wrapper for BIGNUM (OpenSSL bignum) */
-class CBigNum : public BIGNUM
+class CBigNum
 {
+
+protected:
+    BIGNUM  *bn;
+
+    void init()
+    {
+        bn = BN_new();
+    }
+
 public:
     CBigNum()
     {
-        BN_init(this);
+        init();
     }
 
     CBigNum(const CBigNum& b)
     {
-        BN_init(this);
-        if (!BN_copy(this, &b))
+        init();
+        if (!BN_copy(bn, &b))
         {
-            BN_clear_free(this);
+            BN_clear_free(bn);
             throw bignum_error("CBigNum::CBigNum(const CBigNum&) : BN_copy failed");
         }
     }
 
     CBigNum& operator=(const CBigNum& b)
     {
-        if (!BN_copy(this, &b))
+        if (!BN_copy(bn, &b))
             throw bignum_error("CBigNum::operator= : BN_copy failed");
         return (*this);
     }
 
     ~CBigNum()
     {
-        BN_clear_free(this);
+        BN_clear_free(bn);
     }
 
-    //CBigNum(char n) is not portable.  Use 'signed char' or 'unsigned char'.
-    CBigNum(signed char n)      { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
-    CBigNum(short n)            { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
-    CBigNum(int n)              { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
-    CBigNum(long n)             { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
-    CBigNum(int64 n)            { BN_init(this); setint64(n); }
-    CBigNum(unsigned char n)    { BN_init(this); setulong(n); }
-    CBigNum(unsigned short n)   { BN_init(this); setulong(n); }
-    CBigNum(unsigned int n)     { BN_init(this); setulong(n); }
-    CBigNum(unsigned long n)    { BN_init(this); setulong(n); }
-    CBigNum(uint64 n)           { BN_init(this); setuint64(n); }
-    explicit CBigNum(uint256 n) { BN_init(this); setuint256(n); }
+    BIGNUM *operator &() const
+    {
+    return bn;
+    }
 
+    //CBigNum(char n) is not portable.  Use 'signed char' or 'unsigned char'.
+    CBigNum(signed char n)      { init(); if (n >= 0) setulong(n); else setint64(n); }
+    CBigNum(short n)            { init(); if (n >= 0) setulong(n); else setint64(n); }
+    CBigNum(int n)              { init(); if (n >= 0) setulong(n); else setint64(n); }
+    CBigNum(long n)             { init(); if (n >= 0) setulong(n); else setint64(n); }
+    CBigNum(int64 n)            { init(); setint64(n); }
+    CBigNum(unsigned char n)    { init(); setulong(n); }
+    CBigNum(unsigned short n)   { init(); setulong(n); }
+    CBigNum(unsigned int n)     { init(); setulong(n); }
+    CBigNum(unsigned long n)    { init(); setulong(n); }
+    CBigNum(uint64 n)           { init(); setuint64(n); }
+    explicit CBigNum(uint256 n) { init(); setuint256(n); }
     explicit CBigNum(const std::vector<unsigned char>& vch)
     {
-        BN_init(this);
+        init();
         setvch(vch);
     }
 
@@ -124,43 +138,43 @@ public:
      * @return the size
      */
     int bitSize() const{
-        return  BN_num_bits(this);
+        return  BN_num_bits(bn);
     }
 
 
     void setulong(unsigned long n)
     {
-        if (!BN_set_word(this, n))
+        if (!BN_set_word(bn, n))
             throw bignum_error("CBigNum conversion from unsigned long : BN_set_word failed");
     }
 
     unsigned long getulong() const
     {
-        return BN_get_word(this);
+        return BN_get_word(bn);
     }
 
     unsigned int getuint() const
     {
-        return BN_get_word(this);
+        return BN_get_word(bn);
     }
 
     int getint() const
     {
-        unsigned long n = BN_get_word(this);
-        if (!BN_is_negative(this))
+        unsigned long n = BN_get_word(bn);
+        if (!BN_is_negative(bn))
             return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : n);
         else
             return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::min() : -(int)n);
     }
 
-    void setint64(int64 sn)
+    void setint64(int64_t sn)
     {
         unsigned char pch[sizeof(sn) + 6];
         unsigned char* p = pch + 4;
         bool fNegative;
-        uint64 n;
+        uint64_t n;
 
-        if (sn < (int64)0)
+        if (sn < (int64_t)0)
         {
             // Since the minimum signed integer cannot be represented as positive so long as its type is signed, and it's not well-defined what happens if you make it unsigned before negating it, we instead increment the negative integer by 1, convert it, then increment the (now positive) unsigned integer by 1 to compensate
             n = -(sn + 1);
@@ -193,16 +207,16 @@ public:
         pch[1] = (nSize >> 16) & 0xff;
         pch[2] = (nSize >> 8) & 0xff;
         pch[3] = (nSize) & 0xff;
-        BN_mpi2bn(pch, p - pch, this);
+    BN_mpi2bn(pch, p - pch, bn);
     }
 
     uint64 getuint64()
     {
-        unsigned int nSize = BN_bn2mpi(this, NULL);
+        unsigned int nSize = BN_bn2mpi(bn, NULL);
         if (nSize < 4)
             return 0;
         std::vector<unsigned char> vch(nSize);
-        BN_bn2mpi(this, &vch[0]);
+        BN_bn2mpi(bn, &vch[0]);
         if (vch.size() > 4)
             vch[4] &= 0x7f;
         uint64 n = 0;
@@ -211,7 +225,7 @@ public:
         return n;
     }
 
-    void setuint64(uint64 n)
+    void setuint64(uint64_t n)
     {
         unsigned char pch[sizeof(n) + 6];
         unsigned char* p = pch + 4;
@@ -235,7 +249,7 @@ public:
         pch[1] = (nSize >> 16) & 0xff;
         pch[2] = (nSize >> 8) & 0xff;
         pch[3] = (nSize) & 0xff;
-        BN_mpi2bn(pch, p - pch, this);
+        BN_mpi2bn(pch, p - pch, bn);
     }
 
     void setuint256(uint256 n)
@@ -263,16 +277,16 @@ public:
         pch[1] = (nSize >> 16) & 0xff;
         pch[2] = (nSize >> 8) & 0xff;
         pch[3] = (nSize >> 0) & 0xff;
-        BN_mpi2bn(pch, p - pch, this);
+        BN_mpi2bn(pch, p - pch, bn);
     }
 
     uint256 getuint256() const
     {
-        unsigned int nSize = BN_bn2mpi(this, NULL);
+        unsigned int nSize = BN_bn2mpi(bn, NULL);
         if (nSize < 4)
             return 0;
         std::vector<unsigned char> vch(nSize);
-        BN_bn2mpi(this, &vch[0]);
+        BN_bn2mpi(bn, &vch[0]);
         if (vch.size() > 4)
             vch[4] &= 0x7f;
         uint256 n = 0;
@@ -281,7 +295,6 @@ public:
         return n;
     }
 
-
     void setvch(const std::vector<unsigned char>& vch)
     {
         std::vector<unsigned char> vch2(vch.size() + 4);
@@ -294,16 +307,16 @@ public:
         vch2[3] = (nSize >> 0) & 0xff;
         // swap data to big endian
         reverse_copy(vch.begin(), vch.end(), vch2.begin() + 4);
-        BN_mpi2bn(&vch2[0], vch2.size(), this);
+        BN_mpi2bn(&vch2[0], vch2.size(), bn);
     }
 
     std::vector<unsigned char> getvch() const
     {
-        unsigned int nSize = BN_bn2mpi(this, NULL);
+        unsigned int nSize = BN_bn2mpi(bn, NULL);
         if (nSize <= 4)
             return std::vector<unsigned char>();
         std::vector<unsigned char> vch(nSize);
-        BN_bn2mpi(this, &vch[0]);
+        BN_bn2mpi(bn, &vch[0]);
         vch.erase(vch.begin(), vch.begin() + 4);
         reverse(vch.begin(), vch.end());
         return vch;
@@ -312,25 +325,57 @@ public:
     CBigNum& SetCompact(unsigned int nCompact)
     {
         unsigned int nSize = nCompact >> 24;
-        std::vector<unsigned char> vch(4 + nSize);
+      /**  std::vector<unsigned char> vch(4 + nSize);
         vch[3] = nSize;
         if (nSize >= 1) vch[4] = (nCompact >> 16) & 0xff;
         if (nSize >= 2) vch[5] = (nCompact >> 8) & 0xff;
         if (nSize >= 3) vch[6] = (nCompact >> 0) & 0xff;
-        BN_mpi2bn(&vch[0], vch.size(), this);
+        BN_mpi2bn(&vch[0], vch.size(), this);*/
+        bool fNegative     =(nCompact & 0x00800000) != 0;
+        unsigned int nWord = nCompact & 0x007fffff;
+        if (nSize <= 3)
+        {
+            nWord >>= 8*(3-nSize);
+            BN_set_word(bn, nWord);
+        }
+        else
+        {
+            BN_set_word(bn, nWord);
+            BN_lshift(bn, bn, 8*(nSize-3));
+        }
+        BN_set_negative(bn, fNegative);
         return *this;
     }
 
     unsigned int GetCompact() const
     {
-        unsigned int nSize = BN_bn2mpi(this, NULL);
+/**        unsigned int nSize = BN_bn2mpi(this, NULL);
         std::vector<unsigned char> vch(nSize);
         nSize -= 4;
         BN_bn2mpi(this, &vch[0]);
         unsigned int nCompact = nSize << 24;
         if (nSize >= 1) nCompact |= (vch[4] << 16);
         if (nSize >= 2) nCompact |= (vch[5] << 8);
-        if (nSize >= 3) nCompact |= (vch[6] << 0);
+        if (nSize >= 3) nCompact |= (vch[6] << 0);*/
+        unsigned int nSize = BN_num_bytes(bn);
+        unsigned int nCompact = 0;
+        if (nSize <= 3)
+            nCompact = BN_get_word(bn) << 8*(3-nSize);
+        else
+        {
+            CBigNum bn1;
+            BN_rshift(&bn1, bn, 8*(nSize-3));
+            nCompact = BN_get_word(&bn1);
+        }
+        // The 0x00800000 bit denotes the sign.
+        // Thus, if it is already set, divide the mantissa by 256 and increase the exponent.
+        if (nCompact & 0x00800000)
+        {
+            nCompact >>= 8;
+            nSize++;
+        }
+        nCompact |= nSize << 24;
+        nCompact |= (BN_is_negative(bn) ? 0x00800000 : 0);
         return nCompact;
     }
 
@@ -364,27 +409,59 @@ public:
             *this = 0 - *this;
     }
 
+    bool SetHexBool(const std::string& str)
+    {
+        // skip 0x
+        const char* psz = str.c_str();
+        while (isspace(*psz))
+            psz++;
+        bool fNegative = false;
+        if (*psz == '-')
+        {
+            fNegative = true;
+            psz++;
+        }
+        if (psz[0] == '0' && tolower(psz[1]) == 'x')
+            psz += 2;
+        while (isspace(*psz))
+            psz++;
+
+        // hex string to bignum
+        static const signed char phexdigit[256] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0 };
+        *this = 0;
+        while (isxdigit(*psz))
+        {
+            *this <<= 4;
+            int n = phexdigit[(unsigned char)*psz++];
+            *this += n;
+        }
+        if (fNegative)
+            *this = 0 - *this;
+
+        return true;
+    }
+
     std::string ToString(int nBase=10) const
     {
         CAutoBN_CTX pctx;
         CBigNum bnBase = nBase;
         CBigNum bn0 = 0;
         std::string str;
-        CBigNum bn = *this;
-        BN_set_negative(&bn, false);
+        CBigNum bn1 = *this;
+        BN_set_negative(&bn1, false);
         CBigNum dv;
         CBigNum rem;
-        if (BN_cmp(&bn, &bn0) == 0)
+        if (BN_cmp(&bn1, &bn0) == 0)
             return "0";
-        while (BN_cmp(&bn, &bn0) > 0)
+        while (BN_cmp(&bn1, &bn0) > 0)
         {
-            if (!BN_div(&dv, &rem, &bn, &bnBase, pctx))
+            if (!BN_div(&dv, &rem, &bn1, &bnBase, pctx))
                 throw bignum_error("CBigNum::ToString() : BN_div failed");
-            bn = dv;
+            bn1 = dv;
             unsigned int c = rem.getulong();
             str += "0123456789abcdef"[c];
         }
-        if (BN_is_negative(this))
+        if (BN_is_negative(bn))
             str += "-";
         reverse(str.begin(), str.end());
         return str;
@@ -431,7 +508,7 @@ public:
     CBigNum pow(const CBigNum& e) const {
         CAutoBN_CTX pctx;
         CBigNum ret;
-        if (!BN_exp(&ret, this, &e, pctx))
+        if (!BN_exp(&ret, bn, &e, pctx))
             throw bignum_error("CBigNum::pow : BN_exp failed");
         return ret;
     }
@@ -444,7 +521,7 @@ public:
     CBigNum mul_mod(const CBigNum& b, const CBigNum& m) const {
         CAutoBN_CTX pctx;
         CBigNum ret;
-        if (!BN_mod_mul(&ret, this, &b, &m, pctx))
+        if (!BN_mod_mul(&ret, bn, &b, &m, pctx))
             throw bignum_error("CBigNum::mul_mod : BN_mod_mul failed");
         
         return ret;
@@ -465,7 +542,7 @@ public:
             if (!BN_mod_exp(&ret, &inv, &posE, &m, pctx))
                 throw bignum_error("CBigNum::pow_mod: BN_mod_exp failed on negative exponent");
         }else
-            if (!BN_mod_exp(&ret, this, &e, &m, pctx))
+            if (!BN_mod_exp(&ret, bn, &e, &m, pctx))
                 throw bignum_error("CBigNum::pow_mod : BN_mod_exp failed");
 
         return ret;
@@ -480,7 +557,7 @@ public:
     CBigNum inverse(const CBigNum& m) const {
         CAutoBN_CTX pctx;
         CBigNum ret;
-        if (!BN_mod_inverse(&ret, this, &m, pctx))
+        if (!BN_mod_inverse(&ret, bn, &m, pctx))
             throw bignum_error("CBigNum::inverse*= :BN_mod_inverse");
         return ret;
     }
@@ -506,7 +583,7 @@ public:
     CBigNum gcd( const CBigNum& b) const{
         CAutoBN_CTX pctx;
         CBigNum ret;
-        if (!BN_gcd(&ret, this, &b, pctx))
+        if (!BN_gcd(&ret, bn, &b, pctx))
             throw bignum_error("CBigNum::gcd*= :BN_gcd");
         return ret;
     }
@@ -519,7 +596,7 @@ public:
     */
     bool isPrime(const int checks=BN_prime_checks) const {
         CAutoBN_CTX pctx;
-        int ret = BN_is_prime(this, checks, NULL, pctx, NULL);
+        int ret = BN_is_prime_ex(bn, checks, pctx, NULL);
         if(ret < 0){
             throw bignum_error("CBigNum::isPrime :BN_is_prime");
         }
@@ -527,18 +604,18 @@ public:
     }
 
     bool isOne() const {
-        return BN_is_one(this);
+        return BN_is_one(bn);
     }
 
 
     bool operator!() const
     {
-        return BN_is_zero(this);
+        return BN_is_zero(bn);
     }
 
     CBigNum& operator+=(const CBigNum& b)
     {
-        if (!BN_add(this, this, &b))
+        if (!BN_add(bn, bn, &b))
             throw bignum_error("CBigNum::operator+= : BN_add failed");
         return *this;
     }
@@ -552,7 +629,7 @@ public:
     CBigNum& operator*=(const CBigNum& b)
     {
         CAutoBN_CTX pctx;
-        if (!BN_mul(this, this, &b, pctx))
+        if (!BN_mul(bn, bn, &b, pctx))
             throw bignum_error("CBigNum::operator*= : BN_mul failed");
         return *this;
     }
@@ -571,7 +648,7 @@ public:
 
     CBigNum& operator<<=(unsigned int shift)
     {
-        if (!BN_lshift(this, this, shift))
+        if (!BN_lshift(bn, bn, shift))
             throw bignum_error("CBigNum:operator<<= : BN_lshift failed");
         return *this;
     }
@@ -582,13 +659,13 @@ public:
         //   if built on ubuntu 9.04 or 9.10, probably depends on version of OpenSSL
         CBigNum a = 1;
         a <<= shift;
-        if (BN_cmp(&a, this) > 0)
+        if (BN_cmp(&a, bn) > 0)
         {
             *this = 0;
             return *this;
         }
 
-        if (!BN_rshift(this, this, shift))
+        if (!BN_rshift(bn, bn, shift))
             throw bignum_error("CBigNum:operator>>= : BN_rshift failed");
         return *this;
     }
@@ -597,7 +674,7 @@ public:
     CBigNum& operator++()
     {
         // prefix operator
-        if (!BN_add(this, this, BN_value_one()))
+        if (!BN_add(bn, bn, BN_value_one()))
             throw bignum_error("CBigNum::operator++ : BN_add failed");
         return *this;
     }
@@ -614,7 +691,7 @@ public:
     {
         // prefix operator
         CBigNum r;
-        if (!BN_sub(&r, this, BN_value_one()))
+        if (!BN_sub(&r, bn, BN_value_one()))
             throw bignum_error("CBigNum::operator-- : BN_sub failed");
         *this = r;
         return *this;
@@ -709,9 +786,8 @@ inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a,
 inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) >= 0); }
 inline bool operator<(const CBigNum& a, const CBigNum& b)  { return (BN_cmp(&a, &b) < 0); }
 inline bool operator>(const CBigNum& a, const CBigNum& b)  { return (BN_cmp(&a, &b) > 0); }
-
 inline std::ostream& operator<<(std::ostream &strm, const CBigNum &b) { return strm << b.ToString(10); }
 
-typedef  CBigNum Bignum;
+//typedef  CBigNum Bignum;
 
 #endif

+ 2 - 1
ecoin/src/checkpoints.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include <boost/assign/list_of.hpp> // for 'map_list_of()'
 #include <boost/foreach.hpp>
 #include "checkpoints.h"

+ 2 - 1
ecoin/src/checkpoints.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_CHECKPOINT_H
 #define  ECOIN_CHECKPOINT_H
 #include <map>

+ 2 - 1
ecoin/src/clientversion.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef CLIENTVERSION_H
 #define CLIENTVERSION_H
 #define CLIENT_VERSION_MAJOR       0

+ 2 - 1
ecoin/src/coincontrol.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef COINCONTROL_H
 #define COINCONTROL_H
 

+ 2 - 1
ecoin/src/compat.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef _ECOIN_COMPAT_H
 #define _ECOIN_COMPAT_H 1
 

+ 22 - 5
ecoin/src/crypter.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include <openssl/aes.h>
 #include <openssl/evp.h>
 #include <vector>
@@ -63,15 +64,22 @@ bool CCrypter::Encrypt(const CKeyingMaterial& vchPlaintext, std::vector<unsigned
     int nCLen = nLen + AES_BLOCK_SIZE, nFLen = 0;
     vchCiphertext = std::vector<unsigned char> (nCLen);
 
-    EVP_CIPHER_CTX ctx;
+    EVP_CIPHER_CTX *ctx;
 
     bool fOk = true;
 
-    EVP_CIPHER_CTX_init(&ctx);
+/*    EVP_CIPHER_CTX_init(&ctx);
     if (fOk) fOk = EVP_EncryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV);
     if (fOk) fOk = EVP_EncryptUpdate(&ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen);
     if (fOk) fOk = EVP_EncryptFinal_ex(&ctx, (&vchCiphertext[0])+nCLen, &nFLen);
     EVP_CIPHER_CTX_cleanup(&ctx);
+*/
+
+    EVP_CIPHER_CTX_init(ctx);
+    if (fOk) fOk = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKey, chIV);
+    if (fOk) fOk = EVP_EncryptUpdate(ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen);
+    if (fOk) fOk = EVP_EncryptFinal_ex(ctx, (&vchCiphertext[0])+nCLen, &nFLen);
+    EVP_CIPHER_CTX_cleanup(ctx);
 
     if (!fOk) return false;
 
@@ -89,15 +97,24 @@ bool CCrypter::Decrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingM
 
     vchPlaintext = CKeyingMaterial(nPLen);
 
-    EVP_CIPHER_CTX ctx;
+    //EVP_CIPHER_CTX ctx;
+
+    EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
 
     bool fOk = true;
 
-    EVP_CIPHER_CTX_init(&ctx);
+/*    EVP_CIPHER_CTX_init(&ctx);
     if (fOk) fOk = EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV);
     if (fOk) fOk = EVP_DecryptUpdate(&ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen);
     if (fOk) fOk = EVP_DecryptFinal_ex(&ctx, (&vchPlaintext[0])+nPLen, &nFLen);
     EVP_CIPHER_CTX_cleanup(&ctx);
+*/
+
+    EVP_CIPHER_CTX_init(ctx);
+    if (fOk) fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKey, chIV);
+    if (fOk) fOk = EVP_DecryptUpdate(ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen);
+    if (fOk) fOk = EVP_DecryptFinal_ex(ctx, (&vchPlaintext[0])+nPLen, &nFLen);
+    EVP_CIPHER_CTX_cleanup(ctx);
 
     if (!fOk) return false;
 

+ 31 - 24
ecoin/src/crypter.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef __CRYPTER_H__
 #define __CRYPTER_H__
 
@@ -6,9 +7,27 @@
 #include "key.h"
 #include "serialize.h"
 
+#include <cstring>
+
 const unsigned int WALLET_CRYPTO_KEY_SIZE = 32;
 const unsigned int WALLET_CRYPTO_SALT_SIZE = 8;
 
+/*
+Private key encryption is done based on a CMasterKey,
+which holds a salt and random encryption key.
+
+CMasterKeys are encrypted using AES-256-CBC using a key
+derived using derivation method nDerivationMethod
+(0 == EVP_sha512()) and derivation iterations nDeriveIterations.
+vchOtherDerivationParameters is provided for alternative algorithms
+which may require more parameters (such as scrypt).
+
+Wallet Private Keys are then encrypted using AES-256-CBC
+with the double-sha256 of the public key as the IV, and the
+master key's key as the encryption key (see keystore.[ch]).
+*/
+
+/** Master key for wallet encryption */
 class CMasterKey
 {
 public:
@@ -18,6 +37,8 @@ public:
     // 1 = scrypt()
     unsigned int nDerivationMethod;
     unsigned int nDeriveIterations;
+    // Use this for more parameters to key derivation,
+    // such as the various parameters to scrypt
     std::vector<unsigned char> vchOtherDerivationParameters;
 
     IMPLEMENT_SERIALIZE
@@ -33,33 +54,14 @@ public:
         // 25000 rounds is just under 0.1 seconds on a 1.86 GHz Pentium M
         // ie slightly lower than the lowest hardware we need bother supporting
         nDeriveIterations = 25000;
-        nDerivationMethod = 1;
+        nDerivationMethod = 0;
         vchOtherDerivationParameters = std::vector<unsigned char>(0);
     }
-
-    CMasterKey(unsigned int nDerivationMethodIndex)
-    {
-        switch (nDerivationMethodIndex)
-        {
-            case 0: // sha512
-            default:
-                nDeriveIterations = 25000;
-                nDerivationMethod = 0;
-                vchOtherDerivationParameters = std::vector<unsigned char>(0);
-            break;
-
-            case 1: // scrypt+sha512
-                nDeriveIterations = 10000;
-                nDerivationMethod = 1;
-                vchOtherDerivationParameters = std::vector<unsigned char>(0);
-            break;
-        }
-    }
-
 };
 
 typedef std::vector<unsigned char, secure_allocator<unsigned char> > CKeyingMaterial;
 
+/** Encryption/decryption context with key information */
 class CCrypter
 {
 private:
@@ -75,14 +77,18 @@ public:
 
     void CleanKey()
     {
-        OPENSSL_cleanse(&chKey, sizeof chKey);
-        OPENSSL_cleanse(&chIV, sizeof chIV);
+        std::memset(&chKey, 0, sizeof chKey);
+        std::memset(&chIV, 0, sizeof chIV);
         fKeySet = false;
     }
 
     CCrypter()
     {
         fKeySet = false;
+
+        // Try to keep the key data out of swap (and be a bit over-careful to keep the IV that we don't even use out of swap)
+        // Note that this does nothing about suspend-to-disk (which will put all our key data on disk)
+        // Note as well that at no point in this program is any attempt made to prevent stealing of keys by reading the memory of the running process.
         LockedPageManager::instance.LockRange(&chKey[0], sizeof chKey);
         LockedPageManager::instance.LockRange(&chIV[0], sizeof chIV);
     }
@@ -90,6 +96,7 @@ public:
     ~CCrypter()
     {
         CleanKey();
+
         LockedPageManager::instance.UnlockRange(&chKey[0], sizeof chKey);
         LockedPageManager::instance.UnlockRange(&chIV[0], sizeof chIV);
     }

+ 1 - 1
ecoin/src/db.cpp

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include "db.h"
 #include "net.h"

+ 95 - 13
ecoin/src/db.h

@@ -1,8 +1,11 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_DB_H
 #define ECOIN_DB_H
 
 #include "main.h"
+#include <cstdlib>
+#include <cstring>
 #include <map>
 #include <string>
 #include <vector>
@@ -24,6 +27,7 @@ extern unsigned int nWalletDBUpdated;
 void ThreadFlushWalletDB(void* parg);
 bool BackupWallet(const CWallet& wallet, const std::string& strDest);
 
+
 class CDBEnv
 {
 private:
@@ -32,6 +36,7 @@ private:
     bool fMockDb;
     boost::filesystem::path pathEnv;
     std::string strPath;
+
     void EnvShutdown();
 
 public:
@@ -39,13 +44,27 @@ public:
     DbEnv dbenv;
     std::map<std::string, int> mapFileUseCount;
     std::map<std::string, Db*> mapDb;
+
     CDBEnv();
     ~CDBEnv();
     void MakeMock();
     bool IsMock() { return fMockDb; };
 
+    /*
+     * Verify that database file strFile is OK. If it is not,
+     * call the callback to try to recover.
+     * This must be called BEFORE strFile is opened.
+     * Returns true if strFile is OK.
+     */
     enum VerifyResult { VERIFY_OK, RECOVER_OK, RECOVER_FAIL };
     VerifyResult Verify(std::string strFile, bool (*recoverFunc)(CDBEnv& dbenv, std::string strFile));
+    /*
+     * Salvage data from a file that Verify says is bad.
+     * fAggressive sets the DB_AGGRESSIVE flag (see berkeley DB->verify() method documentation).
+     * Appends binary key/value pairs to vResult, returns true if successful.
+     * NOTE: reads the entire database into memory, so cannot be used
+     * for huge databases.
+     */
     typedef std::pair<std::vector<unsigned char>, std::vector<unsigned char> > KeyValPair;
     bool Salvage(std::string strFile, bool fAggressive, std::vector<KeyValPair>& vResult);
 
@@ -71,6 +90,8 @@ public:
 
 extern CDBEnv bitdb;
 
+
+/** RAII class that provides access to a Berkeley database */
 class CDB
 {
 protected:
@@ -78,6 +99,7 @@ protected:
     std::string strFile;
     DbTxn *activeTxn;
     bool fReadOnly;
+
     explicit CDB(const char* pszFile, const char* pszMode="r+");
     ~CDB() { Close(); }
 public:
@@ -93,18 +115,21 @@ protected:
         if (!pdb)
             return false;
 
+        // Key
         CDataStream ssKey(SER_DISK, CLIENT_VERSION);
         ssKey.reserve(1000);
         ssKey << key;
         Dbt datKey(&ssKey[0], ssKey.size());
 
+        // Read
         Dbt datValue;
         datValue.set_flags(DB_DBT_MALLOC);
         int ret = pdb->get(activeTxn, &datKey, &datValue, 0);
-        memset(datKey.get_data(), 0, datKey.get_size());
+        std::memset(datKey.get_data(), 0, datKey.get_size());
         if (datValue.get_data() == NULL)
             return false;
 
+        // Unserialize value
         try {
             CDataStream ssValue((char*)datValue.get_data(), (char*)datValue.get_data() + datValue.get_size(), SER_DISK, CLIENT_VERSION);
             ssValue >> value;
@@ -113,8 +138,9 @@ protected:
             return false;
         }
 
-        memset(datValue.get_data(), 0, datValue.get_size());
-        free(datValue.get_data());
+        // Clear and free memory
+        std::memset(datValue.get_data(), 0, datValue.get_size());
+        std::free(datValue.get_data());
         return (ret == 0);
     }
 
@@ -126,20 +152,24 @@ protected:
         if (fReadOnly)
             assert(!"Write called on database in read-only mode");
 
+        // Key
         CDataStream ssKey(SER_DISK, CLIENT_VERSION);
         ssKey.reserve(1000);
         ssKey << key;
         Dbt datKey(&ssKey[0], ssKey.size());
 
+        // Value
         CDataStream ssValue(SER_DISK, CLIENT_VERSION);
         ssValue.reserve(10000);
         ssValue << value;
         Dbt datValue(&ssValue[0], ssValue.size());
 
+        // Write
         int ret = pdb->put(activeTxn, &datKey, &datValue, (fOverwrite ? 0 : DB_NOOVERWRITE));
 
-        memset(datKey.get_data(), 0, datKey.get_size());
-        memset(datValue.get_data(), 0, datValue.get_size());
+        // Clear memory in case it was a private key
+        std::memset(datKey.get_data(), 0, datKey.get_size());
+        std::memset(datValue.get_data(), 0, datValue.get_size());
         return (ret == 0);
     }
 
@@ -151,14 +181,17 @@ protected:
         if (fReadOnly)
             assert(!"Erase called on database in read-only mode");
 
+        // Key
         CDataStream ssKey(SER_DISK, CLIENT_VERSION);
         ssKey.reserve(1000);
         ssKey << key;
         Dbt datKey(&ssKey[0], ssKey.size());
 
+        // Erase
         int ret = pdb->del(activeTxn, &datKey, 0);
 
-        memset(datKey.get_data(), 0, datKey.get_size());
+        // Clear memory
+        std::memset(datKey.get_data(), 0, datKey.get_size());
         return (ret == 0 || ret == DB_NOTFOUND);
     }
 
@@ -168,14 +201,17 @@ protected:
         if (!pdb)
             return false;
 
+        // Key
         CDataStream ssKey(SER_DISK, CLIENT_VERSION);
         ssKey.reserve(1000);
         ssKey << key;
         Dbt datKey(&ssKey[0], ssKey.size());
 
+        // Exists
         int ret = pdb->exists(activeTxn, &datKey, 0);
 
-        memset(datKey.get_data(), 0, datKey.get_size());
+        // Clear memory
+        std::memset(datKey.get_data(), 0, datKey.get_size());
         return (ret == 0);
     }
 
@@ -192,6 +228,7 @@ protected:
 
     int ReadAtCursor(Dbc* pcursor, CDataStream& ssKey, CDataStream& ssValue, unsigned int fFlags=DB_NEXT)
     {
+        // Read at cursor
         Dbt datKey;
         if (fFlags == DB_SET || fFlags == DB_SET_RANGE || fFlags == DB_GET_BOTH || fFlags == DB_GET_BOTH_RANGE)
         {
@@ -212,6 +249,7 @@ protected:
         else if (datKey.get_data() == NULL || datValue.get_data() == NULL)
             return 99999;
 
+        // Convert to streams
         ssKey.SetType(SER_DISK);
         ssKey.clear();
         ssKey.write((char*)datKey.get_data(), datKey.get_size());
@@ -219,10 +257,11 @@ protected:
         ssValue.clear();
         ssValue.write((char*)datValue.get_data(), datValue.get_size());
 
-        memset(datKey.get_data(), 0, datKey.get_size());
-        memset(datValue.get_data(), 0, datValue.get_size());
-        free(datKey.get_data());
-        free(datValue.get_data());
+        // Clear and free memory
+        std::memset(datKey.get_data(), 0, datKey.get_size());
+        std::memset(datValue.get_data(), 0, datValue.get_size());
+        std::free(datKey.get_data());
+        std::free(datValue.get_data());
         return 0;
     }
 
@@ -270,6 +309,50 @@ public:
     bool static Rewrite(const std::string& strFile, const char* pszSkip = NULL);
 };
 
+
+
+
+
+
+
+/** Access to the transaction database (blkindex.dat) */
+
+/**
+class CTxDB : public CDB
+{
+public:
+    CTxDB(const char* pszMode="r+") : CDB("blkindex.dat", pszMode) { }
+private:
+    CTxDB(const CTxDB&);
+    void operator=(const CTxDB&);
+public:
+    bool ReadTxIndex(uint256 hash, CTxIndex& txindex);
+    bool UpdateTxIndex(uint256 hash, const CTxIndex& txindex);
+    bool AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeight);
+    bool EraseTxIndex(const CTransaction& tx);
+    bool ContainsTx(uint256 hash);
+    bool ReadDiskTx(uint256 hash, CTransaction& tx, CTxIndex& txindex);
+    bool ReadDiskTx(uint256 hash, CTransaction& tx);
+    bool ReadDiskTx(COutPoint outpoint, CTransaction& tx, CTxIndex& txindex);
+    bool ReadDiskTx(COutPoint outpoint, CTransaction& tx);
+    bool WriteBlockIndex(const CDiskBlockIndex& blockindex);
+    bool ReadHashBestChain(uint256& hashBestChain);
+    bool WriteHashBestChain(uint256 hashBestChain);
+    bool ReadBestInvalidTrust(CBigNum& bnBestInvalidTrust);
+    bool WriteBestInvalidTrust(CBigNum bnBestInvalidTrust);
+    bool ReadSyncCheckpoint(uint256& hashCheckpoint);
+    bool WriteSyncCheckpoint(uint256 hashCheckpoint);
+    bool ReadCheckpointPubKey(std::string& strPubKey);
+    bool WriteCheckpointPubKey(const std::string& strPubKey);
+    bool LoadBlockIndex();
+private:
+    bool LoadBlockIndexGuts();
+};
+*/
+
+
+
+/** Access to the (IP) address database (peers.dat) */
 class CAddrDB
 {
 private:
@@ -279,5 +362,4 @@ public:
     bool Write(const CAddrMan& addr);
     bool Read(CAddrMan& addr);
 };
-
 #endif // ECOIN_DB_H

+ 12 - 12
ecoin/src/ecoinrpc.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include "init.h"
 #include "util.h"
 #include "sync.h"
@@ -218,15 +219,13 @@ static const CRPCCommand vRPCCommands[] =
   //  ------------------------  -----------------------  ------  --------
     { "help",                   &help,                   true,   true },
     { "stop",                   &stop,                   true,   true },
-    { "getbestblockhash",       &getbestblockhash,       true,   false },
+    { "getblockhash",           &getblockhash,           true,   false },
     { "getblockcount",          &getblockcount,          true,   false },
     { "getconnectioncount",     &getconnectioncount,     true,   false },
     { "getpeerinfo",            &getpeerinfo,            true,   false },
     { "getdifficulty",          &getdifficulty,          true,   false },
     { "getinfo",                &getinfo,                true,   false },
-    { "getsubsidy",             &getsubsidy,             true,   false },
     { "getmininginfo",          &getmininginfo,          true,   false },
-    { "getstakinginfo",         &getstakinginfo,         true,   false },
     { "getnewaddress",          &getnewaddress,          true,   false },
     { "getnewpubkey",           &getnewpubkey,           true,   false },
     { "getaccountaddress",      &getaccountaddress,      true,   false },
@@ -251,7 +250,6 @@ static const CRPCCommand vRPCCommands[] =
     { "sendfrom",               &sendfrom,               false,  false },
     { "sendmany",               &sendmany,               false,  false },
     { "addmultisigaddress",     &addmultisigaddress,     false,  false },
-    { "addredeemscript",        &addredeemscript,        false,  false },
     { "getrawmempool",          &getrawmempool,          true,   false },
     { "getblock",               &getblock,               false,  false },
     { "getblockbynumber",       &getblockbynumber,       false,  false },
@@ -269,20 +267,18 @@ static const CRPCCommand vRPCCommands[] =
     { "submitblock",            &submitblock,            false,  false },
     { "listsinceblock",         &listsinceblock,         false,  false },
     { "dumpprivkey",            &dumpprivkey,            false,  false },
-    { "dumpwallet",             &dumpwallet,             true,   false },
-    { "importwallet",           &importwallet,           false,  false },
+    { "checkwallet",            &checkwallet,            true,   false },
+    { "repairwallet",           &repairwallet,           false,  false },
     { "importprivkey",          &importprivkey,          false,  false },
     { "listunspent",            &listunspent,            false,  false },
     { "getrawtransaction",      &getrawtransaction,      false,  false },
     { "createrawtransaction",   &createrawtransaction,   false,  false },
     { "decoderawtransaction",   &decoderawtransaction,   false,  false },
-    { "decodescript",           &decodescript,           false,  false },
     { "signrawtransaction",     &signrawtransaction,     false,  false },
     { "sendrawtransaction",     &sendrawtransaction,     false,  false },
     { "getcheckpoint",          &getcheckpoint,          true,   false },
     { "reservebalance",         &reservebalance,         false,  true},
     { "checkwallet",            &checkwallet,            false,  true},
-    { "repairwallet",           &repairwallet,           false,  true},
     { "resendtx",               &resendtx,               false,  true},
     { "makekeypair",            &makekeypair,            false,  true},
     { "sendalert",              &sendalert,              false,  false},
@@ -733,7 +729,9 @@ void ThreadRPCServer2(void* parg)
 
     asio::io_service io_service;
 
-    ssl::context context(io_service, ssl::context::sslv23);
+    //ssl::context context(io_service, ssl::context::no_sslv2);
+    ssl::context context(ssl::context::sslv23);
+
     if (fUseSSL)
     {
         context.set_options(ssl::context::no_sslv2);
@@ -749,7 +747,8 @@ void ThreadRPCServer2(void* parg)
         else printf("ThreadRPCServer ERROR: missing server private key file %s\n", pathPKFile.string().c_str());
 
         string strCiphers = GetArg("-rpcsslciphers", "TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH");
-        SSL_CTX_set_cipher_list(context.impl(), strCiphers.c_str());
+        //SSL_CTX_set_cipher_list(context.impl(), strCiphers.c_str());
+        SSL_CTX_set_cipher_list(context.native_handle(), strCiphers.c_str());
     }
 
     const bool loopback = !mapArgs.count("-rpcallowip");
@@ -1021,7 +1020,8 @@ Object CallRPC(const string& strMethod, const Array& params)
 
     bool fUseSSL = GetBoolArg("-rpcssl");
     asio::io_service io_service;
-    ssl::context context(io_service, ssl::context::sslv23);
+    //ssl::context context(io_service, ssl::context::sslv23);
+    ssl::context context(ssl::context::sslv23);
     context.set_options(ssl::context::no_sslv2);
     asio::ssl::stream<asio::ip::tcp::socket> sslStream(io_service, context);
     SSLIOStreamDevice<asio::ip::tcp> d(sslStream, fUseSSL);

+ 60 - 15
ecoin/src/ecoinrpc.h

@@ -1,7 +1,14 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #ifndef _ECOINRPC_H_
 #define _ECOINRPC_H_ 1
+
+#if BOOST_VERSION >= 106600
+#ifndef BOOST_ASIO_ENABLE_OLD_SERVICES
+#define BOOST_ASIO_ENABLE_OLD_SERVICES
+#endif
+#endif
+
 #include <string>
 #include <list>
 #include <map>
@@ -11,9 +18,25 @@ class CBlockIndex;
 #include "json/json_spirit_reader_template.h"
 #include "json/json_spirit_writer_template.h"
 #include "json/json_spirit_utils.h"
+
+#include <boost/asio.hpp>
+#include <boost/asio/ssl.hpp>
 #include "util.h"
 #include "checkpoints.h"
 
+ // Boost Support for 1.70+
+#if BOOST_VERSION >= 107000
+    #define GetIOService(s) ((boost::asio::io_context&)(s).get_executor().context())
+    #define GetIOServiceFromPtr(s) ((boost::asio::io_context&)(s->get_executor().context())) // this one
+    typedef boost::asio::io_context ioContext;
+
+#else
+    #define GetIOService(s) ((s).get_io_service())
+    #define GetIOServiceFromPtr(s) ((s)->get_io_service())
+    typedef boost::asio::io_service ioContext;
+#endif
+
+// HTTP status codes
 enum HTTPStatusCode
 {
     HTTP_OK                    = 200,
@@ -24,6 +47,7 @@ enum HTTPStatusCode
     HTTP_INTERNAL_SERVER_ERROR = 500,
 };
 
+// ecoin RPC error codes
 enum RPCErrorCode
 {
     // Standard JSON-RPC 2.0 errors
@@ -44,7 +68,7 @@ enum RPCErrorCode
     RPC_DESERIALIZATION_ERROR       = -22, // Error parsing or validating structure in raw format
 
     // P2P client errors
-    RPC_CLIENT_NOT_CONNECTED        = -9,  // Ecoin is not connected
+    RPC_CLIENT_NOT_CONNECTED        = -9,  // ecoin is not connected
     RPC_CLIENT_IN_INITIAL_DOWNLOAD  = -10, // Still downloading initial blocks
 
     // Wallet errors
@@ -64,10 +88,20 @@ json_spirit::Object JSONRPCError(int code, const std::string& message);
 void ThreadRPCServer(void* parg);
 int CommandLineRPC(int argc, char *argv[]);
 
+/** Convert parameter values for RPC call from strings to command-specific JSON objects. */
 json_spirit::Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams);
 
+/*
+  Type-check arguments; throws JSONRPCError if wrong type given. Does not check that
+  the right number of arguments are passed, just that any passed are the correct type.
+  Use like:  RPCTypeCheck(params, boost::assign::list_of(str_type)(int_type)(obj_type));
+*/
 void RPCTypeCheck(const json_spirit::Array& params,
                   const std::list<json_spirit::Value_type>& typesExpected, bool fAllowNull=false);
+/*
+  Check for expected keys/value types in an Object.
+  Use like: RPCTypeCheck(object, boost::assign::map_list_of("name", str_type)("value", int_type));
+*/
 void RPCTypeCheck(const json_spirit::Object& o,
                   const std::map<std::string, json_spirit::Value_type>& typesExpected, bool fAllowNull=false);
 
@@ -82,6 +116,9 @@ public:
     bool unlocked;
 };
 
+/**
+ * ecoin RPC command dispatcher.
+ */
 class CRPCTable
 {
 private:
@@ -90,37 +127,45 @@ public:
     CRPCTable();
     const CRPCCommand* operator[](std::string name) const;
     std::string help(std::string name) const;
+
+    /**
+     * Execute a method.
+     * @param method   Method to execute
+     * @param params   Array of arguments (JSON objects)
+     * @returns Result of the call.
+     * @throws an exception (json_spirit::Value) when an error happens.
+     */
     json_spirit::Value execute(const std::string &method, const json_spirit::Array &params) const;
 };
 
 extern const CRPCTable tableRPC;
+
 extern int64 nWalletUnlockTime;
 extern int64 AmountFromValue(const json_spirit::Value& value);
 extern json_spirit::Value ValueFromAmount(int64 amount);
 extern double GetDifficulty(const CBlockIndex* blockindex = NULL);
-extern double GetPoWMHashPS();
-extern double GetPoSKernelPS();
 extern std::string HexBits(unsigned int nBits);
 extern std::string HelpRequiringPassphrase();
 extern void EnsureWalletIsUnlocked();
-extern uint256 ParseHashV(const json_spirit::Value& v, std::string strName);
-extern uint256 ParseHashO(const json_spirit::Object& o, std::string strKey);
-extern std::vector<unsigned char> ParseHexV(const json_spirit::Value& v, std::string strName);
-extern std::vector<unsigned char> ParseHexO(const json_spirit::Object& o, std::string strKey);
+
+extern double GetPoSKernelPS();
+
 extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp
 extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp);
-extern json_spirit::Value dumpwallet(const json_spirit::Array& params, bool fHelp);
-extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
 extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value sendalert(const json_spirit::Array& params, bool fHelp);
-extern json_spirit::Value getsubsidy(const json_spirit::Array& params, bool fHelp);
+
+extern json_spirit::Value getgenerate(const json_spirit::Array& params, bool fHelp); // in rpcmining.cpp
+extern json_spirit::Value setgenerate(const json_spirit::Array& params, bool fHelp);
+extern json_spirit::Value gethashespersec(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp);
-extern json_spirit::Value getstakinginfo(const json_spirit::Array& params, bool fHelp);
+extern json_spirit::Value getnetworkhashps(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value getwork(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value getworkex(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value getblocktemplate(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value submitblock(const json_spirit::Array& params, bool fHelp);
+
 extern json_spirit::Value getnewaddress(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
 extern json_spirit::Value getaccountaddress(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value setaccount(const json_spirit::Array& params, bool fHelp);
@@ -136,7 +181,6 @@ extern json_spirit::Value movecmd(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value sendfrom(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value sendmany(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value addmultisigaddress(const json_spirit::Array& params, bool fHelp);
-extern json_spirit::Value addredeemscript(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value listreceivedbyaddress(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value listreceivedbyaccount(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value listtransactions(const json_spirit::Array& params, bool fHelp);
@@ -159,14 +203,14 @@ extern json_spirit::Value resendtx(const json_spirit::Array& params, bool fHelp)
 extern json_spirit::Value makekeypair(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value validatepubkey(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value getnewpubkey(const json_spirit::Array& params, bool fHelp);
+
 extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp
 extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value createrawtransaction(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value decoderawtransaction(const json_spirit::Array& params, bool fHelp);
-extern json_spirit::Value decodescript(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value signrawtransaction(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value sendrawtransaction(const json_spirit::Array& params, bool fHelp);
-extern json_spirit::Value getbestblockhash(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp
+
 extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp
 extern json_spirit::Value getdifficulty(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value settxfee(const json_spirit::Array& params, bool fHelp);
@@ -177,3 +221,4 @@ extern json_spirit::Value getblockbynumber(const json_spirit::Array& params, boo
 extern json_spirit::Value getcheckpoint(const json_spirit::Array& params, bool fHelp);
 
 #endif
+

+ 2 - 1
ecoin/src/init.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include "txdb.h"
 #include "walletdb.h"
 #include "ecoinrpc.h"

+ 2 - 1
ecoin/src/init.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_INIT_H
 #define ECOIN_INIT_H
 

+ 2 - 1
ecoin/src/irc.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include "irc.h"
 #include "net.h"
 #include "strlcpy.h"

+ 2 - 1
ecoin/src/irc.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_IRC_H
 #define ECOIN_IRC_H
 

+ 2 - 1
ecoin/src/kernel.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include <boost/assign/list_of.hpp>
 #include "kernel.h"
 #include "txdb.h"

+ 2 - 1
ecoin/src/kernel.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_KERNEL_H
 #define ECOIN_KERNEL_H
 

+ 54 - 14
ecoin/src/key.cpp

@@ -1,9 +1,13 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include <map>
+
 #include <openssl/ecdsa.h>
 #include <openssl/obj_mac.h>
+
 #include "key.h"
 
+// Generate a private key from just the secret parameter
 int EC_KEY_regenerate_key(EC_KEY *eckey, BIGNUM *priv_key)
 {
     int ok = 0;
@@ -40,6 +44,9 @@ err:
     return(ok);
 }
 
+// Perform ECDSA key recovery (see SEC1 4.1.6) for curves over (mod p)-fields
+// recid selects which key is recovered
+// if check is non-zero, additional checks are performed
 int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsigned char *msg, int msglen, int recid, int check)
 {
     if (!eckey) return 0;
@@ -58,6 +65,7 @@ int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsigned ch
     EC_POINT *Q = NULL;
     BIGNUM *rr = NULL;
     BIGNUM *zero = NULL;
+    BIGNUM *s = 0;
     int n = 0;
     int i = recid / 2;
 
@@ -69,7 +77,8 @@ int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsigned ch
     x = BN_CTX_get(ctx);
     if (!BN_copy(x, order)) { ret=-1; goto err; }
     if (!BN_mul_word(x, i)) { ret=-1; goto err; }
-    if (!BN_add(x, x, ecsig->r)) { ret=-1; goto err; }
+    ECDSA_SIG_get0(ecsig, (const BIGNUM **)&s, 0);
+    if (!BN_add(x, x, s)) { ret=-1; goto err; }
     field = BN_CTX_get(ctx);
     if (!EC_GROUP_get_curve_GFp(group, field, NULL, NULL, ctx)) { ret=-2; goto err; }
     if (BN_cmp(x, field) >= 0) { ret=0; goto err; }
@@ -90,9 +99,11 @@ int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsigned ch
     if (!BN_zero(zero)) { ret=-1; goto err; }
     if (!BN_mod_sub(e, zero, e, order, ctx)) { ret=-1; goto err; }
     rr = BN_CTX_get(ctx);
-    if (!BN_mod_inverse(rr, ecsig->r, order, ctx)) { ret=-1; goto err; }
+    ECDSA_SIG_get0(ecsig, (const BIGNUM **)&s, 0);
+    if (!BN_mod_inverse(rr, s, order, ctx)) { ret=-1; goto err; }
     sor = BN_CTX_get(ctx);
-    if (!BN_mod_mul(sor, ecsig->s, rr, order, ctx)) { ret=-1; goto err; }
+    ECDSA_SIG_get0(ecsig, 0, (const BIGNUM **)&s);
+    if (!BN_mod_mul(sor, s, rr, order, ctx)) { ret=-1; goto err; }
     eor = BN_CTX_get(ctx);
     if (!BN_mod_mul(eor, e, rr, order, ctx)) { ret=-1; goto err; }
     if (!EC_POINT_mul(group, Q, eor, R, sor, ctx)) { ret=-2; goto err; }
@@ -179,12 +190,19 @@ bool CKey::SetPrivKey(const CPrivKey& vchPrivKey)
     const unsigned char* pbegin = &vchPrivKey[0];
     if (d2i_ECPrivateKey(&pkey, &pbegin, vchPrivKey.size()))
     {
+        // In testing, d2i_ECPrivateKey can return true
+        // but fill in pkey with a key that fails
+        // EC_KEY_check_key, so:
         if (EC_KEY_check_key(pkey))
         {
             fSet = true;
             return true;
         }
     }
+    // If vchPrivKey data is bad d2i_ECPrivateKey() can
+    // leave pkey in a state where calling EC_KEY_free()
+    // crashes. To avoid that, set pkey to NULL and
+    // leak the memory (a leak is better than a crash)
     pkey = NULL;
     Reset();
     return false;
@@ -280,16 +298,23 @@ bool CKey::Sign(uint256 hash, std::vector<unsigned char>& vchSig)
     return true;
 }
 
+// create a compact signature (65 bytes), which allows reconstructing the used public key
+// The format is one header byte, followed by two times 32 bytes for the serialized r and s values.
+// The header byte: 0x1B = first key with even y, 0x1C = first key with odd y,
+//                  0x1D = second key with even y, 0x1E = second key with odd y
 bool CKey::SignCompact(uint256 hash, std::vector<unsigned char>& vchSig)
 {
     bool fOk = false;
+    BIGNUM *s = 0;
+    BIGNUM *r = 0;
     ECDSA_SIG *sig = ECDSA_do_sign((unsigned char*)&hash, sizeof(hash), pkey);
     if (sig==NULL)
         return false;
     vchSig.clear();
     vchSig.resize(65,0);
-    int nBitsR = BN_num_bits(sig->r);
-    int nBitsS = BN_num_bits(sig->s);
+    ECDSA_SIG_get0(sig, (const BIGNUM **)&r, (const BIGNUM **)&s);
+    int nBitsR = BN_num_bits(r);
+    int nBitsS = BN_num_bits(s);
     if (nBitsR <= 256 && nBitsS <= 256)
     {
         int nRecId = -1;
@@ -308,30 +333,35 @@ bool CKey::SignCompact(uint256 hash, std::vector<unsigned char>& vchSig)
         }
 
         if (nRecId == -1)
-        {
-            ECDSA_SIG_free(sig);
             throw key_error("CKey::SignCompact() : unable to construct recoverable key");
-        }
 
         vchSig[0] = nRecId+27+(fCompressedPubKey ? 4 : 0);
-        BN_bn2bin(sig->r,&vchSig[33-(nBitsR+7)/8]);
-        BN_bn2bin(sig->s,&vchSig[65-(nBitsS+7)/8]);
+        ECDSA_SIG_get0(sig, (const BIGNUM **)&r, (const BIGNUM **)&s);
+        BN_bn2bin(r,&vchSig[33-(nBitsR+7)/8]);
+        BN_bn2bin(s,&vchSig[65-(nBitsS+7)/8]);
         fOk = true;
     }
     ECDSA_SIG_free(sig);
     return fOk;
 }
 
+// reconstruct public key from a compact signature
+// This is only slightly more CPU intensive than just verifying it.
+// If this function succeeds, the recovered public key is guaranteed to be valid
+// (the signature is a valid signature of the given data for that key)
 bool CKey::SetCompactSignature(uint256 hash, const std::vector<unsigned char>& vchSig)
 {
+    BIGNUM *s = 0;
+    BIGNUM *r = 0;
     if (vchSig.size() != 65)
         return false;
     int nV = vchSig[0];
     if (nV<27 || nV>=35)
         return false;
     ECDSA_SIG *sig = ECDSA_SIG_new();
-    BN_bin2bn(&vchSig[1],32,sig->r);
-    BN_bin2bn(&vchSig[33],32,sig->s);
+    ECDSA_SIG_get0(sig, (const BIGNUM **)&r, (const BIGNUM **)&s);
+    BN_bin2bn(&vchSig[1],32,r);
+    BN_bin2bn(&vchSig[33],32,s);
 
     EC_KEY_free(pkey);
     pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
@@ -346,12 +376,12 @@ bool CKey::SetCompactSignature(uint256 hash, const std::vector<unsigned char>& v
         ECDSA_SIG_free(sig);
         return true;
     }
-    ECDSA_SIG_free(sig);
     return false;
 }
 
 bool CKey::Verify(uint256 hash, const std::vector<unsigned char>& vchSig)
 {
+    // -1 = error, 0 = bad sig, 1 = good
     if (ECDSA_verify(0, (unsigned char*)&hash, sizeof(hash), &vchSig[0], vchSig.size(), pkey) != 1)
         return false;
 
@@ -383,3 +413,13 @@ bool CKey::IsValid()
     key2.SetSecret(secret, fCompr);
     return GetPubKey() == key2.GetPubKey();
 }
+
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+    void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps)  
+    {
+        if (pr != NULL)
+            *pr = sig->r;
+        if (ps != NULL)
+            *ps = sig->s;
+    }
+#endif

+ 2 - 1
ecoin/src/key.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_KEY_H
 #define ECOIN_KEY_H
 

+ 2 - 1
ecoin/src/keystore.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include "keystore.h"
 #include "script.h"
 

+ 2 - 1
ecoin/src/keystore.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_KEYSTORE_H
 #define ECOIN_KEYSTORE_H
 

+ 8 - 7
ecoin/src/main.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include "alert.h"
 #include "checkpoints.h"
 #include "db.h"
@@ -250,18 +251,18 @@ bool CTransaction::IsStandard() const
             return false;
         if (!txin.scriptSig.IsPushOnly())
             return false;
-        if (fEnforceCanonical && !txin.scriptSig.HasCanonicalPushes()) {
-		    return false;
-		}
+        //if (fEnforceCanonical && !txin.scriptSig.HasCanonicalPushes()) {
+	//	    return false;
+        //		}
     }
     BOOST_FOREACH(const CTxOut& txout, vout) {
         if (!::IsStandard(txout.scriptPubKey))
             return false;
         if (txout.nValue == 0)
             return false;
-        if (fEnforceCanonical && !txout.scriptPubKey.HasCanonicalPushes()) {
-		    return false;
-        }
+        //if (fEnforceCanonical && !txout.scriptPubKey.HasCanonicalPushes()) {
+	//	    return false;
+        //              }
     }
     return true;
 }

+ 2 - 1
ecoin/src/main.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_MAIN_H
 #define ECOIN_MAIN_H
 

+ 2 - 4
ecoin/src/makefile.bsd

@@ -1,7 +1,4 @@
-# ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-# Copyright (c) 2009-2010 Satoshi Nakamoto
-# Distributed under the MIT/X11 software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 USE_UPNP:=0
 USE_IPV6:=1
@@ -28,6 +25,7 @@ LIBS += \
    -l boost_system$(BOOST_LIB_SUFFIX) \
    -l boost_filesystem$(BOOST_LIB_SUFFIX) \
    -l boost_program_options$(BOOST_LIB_SUFFIX) \
+   -l boost_chrono$(BOOST_LIB_SUFFIX) \
    -l boost_thread$(BOOST_LIB_SUFFIX) \
    -l db_cxx$(BDB_LIB_SUFFIX) \
    -l ssl \

+ 3 - 5
ecoin/src/makefile.linux

@@ -1,10 +1,7 @@
-# ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-# Copyright (c) 2009-2010 Satoshi Nakamoto
-# Distributed under the MIT/X11 software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 USE_UPNP:=0
-USE_IPV6:=1
+USE_IPV6:=0
 
 LINK:=$(CXX)
 ARCH:=$(system lscpu | head -n 1 | awk '{print $2}')
@@ -29,6 +26,7 @@ LIBS += \
    -l boost_system$(BOOST_LIB_SUFFIX) \
    -l boost_filesystem$(BOOST_LIB_SUFFIX) \
    -l boost_program_options$(BOOST_LIB_SUFFIX) \
+   -l boost_chrono$(BOOST_LIB_SUFFIX) \
    -l boost_thread$(BOOST_LIB_SUFFIX) \
    -l db_cxx$(BDB_LIB_SUFFIX) \
    -l ssl \

+ 1 - 4
ecoin/src/makefile.linux-mingw

@@ -1,7 +1,4 @@
-# ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-# Copyright (c) 2009-2010 Satoshi Nakamoto
-# Distributed under the MIT/X11 software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #TARGET_PLATFORM:=i686
 TARGET_PLATFORM:=x86_64

+ 1 - 4
ecoin/src/makefile.linux32-mingw

@@ -1,7 +1,4 @@
-# ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-# Copyright (c) 2009-2010 Satoshi Nakamoto
-# Distributed under the MIT/X11 software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 TARGET_PLATFORM:=i686
 #TARGET_PLATFORM:=x86_64

+ 1 - 4
ecoin/src/makefile.linux64-mingw

@@ -1,7 +1,4 @@
-# ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-# Copyright (c) 2009-2010 Satoshi Nakamoto
-# Distributed under the MIT/X11 software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #TARGET_PLATFORM:=i686
 TARGET_PLATFORM:=x86_64

+ 1 - 4
ecoin/src/makefile.mingw

@@ -1,7 +1,4 @@
-# ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-# Copyright (c) 2009-2010 Satoshi Nakamoto
-# Distributed under the MIT/X11 software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 USE_UPNP:=0
 USE_IPV6:=1

+ 1 - 4
ecoin/src/makefile.osx

@@ -1,7 +1,4 @@
-# ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-# -*- mode: Makefile; -*-
-# Mac OS X makefile for ecoin
-# Originally by Laszlo Hanyecz (solar@heliacal.net)
+# ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 CXX=llvm-g++
 DEPSDIR=/opt/local

+ 2 - 4
ecoin/src/makefile.unix

@@ -1,7 +1,4 @@
-# ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-# Copyright (c) 2009-2010 Satoshi Nakamoto
-# Distributed under the MIT/X11 software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 USE_UPNP:=0
 USE_IPV6:=1
@@ -30,6 +27,7 @@ LIBS += \
    -l boost_system$(BOOST_LIB_SUFFIX) \
    -l boost_filesystem$(BOOST_LIB_SUFFIX) \
    -l boost_program_options$(BOOST_LIB_SUFFIX) \
+   -l boost_chrono$(BOOST_LIB_SUFFIX) \
    -l boost_thread$(BOOST_LIB_SUFFIX) \
    -l db_cxx$(BDB_LIB_SUFFIX) \
    -l ssl \

+ 2 - 1
ecoin/src/miner.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include "txdb.h"
 #include "miner.h"
 #include "kernel.h"

+ 2 - 1
ecoin/src/miner.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_MINER_H
 #define ECOIN_MINER_H
 

+ 2 - 2
ecoin/src/mruset.h

@@ -1,5 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-// Copyright (c) 2009-2010 Satoshi Nakamoto
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_MRUSET_H
 #define ECOIN_MRUSET_H
 

+ 5 - 2
ecoin/src/net.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include "irc.h"
 #include "db.h"
 #include "net.h"
@@ -946,10 +947,12 @@ void ThreadMapPort2(void* parg)
     char lanaddr[64];
 
 #ifndef UPNPDISCOVER_SUCCESS
+//    /* miniupnpc 1.5 */
     devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0);
 #else
+//    /* miniupnpc 1.9.20150730 */
     int error = 0;
-    devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, &error);
+    devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, 2, &error);
 #endif
 
     struct UPNPUrls urls;

+ 2 - 3
ecoin/src/net.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_NET_H
 #define ECOIN_NET_H
 
@@ -21,8 +22,6 @@ class CNode;
 class CBlockIndex;
 extern int nBestHeight;
 
-
-
 inline unsigned int ReceiveBufferSize() { return 1000*GetArg("-maxreceivebuffer", 5*1000); }
 inline unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", 1*1000); }
 

+ 1 - 2
ecoin/src/netbase.cpp

@@ -1,5 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-// Copyright (c) 2009-2010 Satoshi Nakamoto
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include "netbase.h"
 #include "util.h"

+ 2 - 2
ecoin/src/netbase.h

@@ -1,5 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-// Copyright (c) 2009-2010 Satoshi Nakamoto
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_NETBASE_H
 #define ECOIN_NETBASE_H
 

+ 1 - 2
ecoin/src/noui.cpp

@@ -1,5 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-// Copyright (c) 2009-2010 Satoshi Nakamoto
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include "ui_interface.h"
 #include "init.h"

+ 1 - 2
ecoin/src/pbkdf2.cpp

@@ -1,5 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-// Copyright (c) 2009-2010 Satoshi Nakamoto
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include <string.h>
 #include "pbkdf2.h"

+ 1 - 2
ecoin/src/pbkdf2.h

@@ -1,5 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-// Copyright (c) 2009-2010 Satoshi Nakamoto
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #ifndef PBKDF2_H
 #define PBKDF2_H

+ 1 - 2
ecoin/src/protocol.cpp

@@ -1,5 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-// Copyright (c) 2009-2010 Satoshi Nakamoto
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include "protocol.h"
 #include "util.h"

+ 1 - 2
ecoin/src/protocol.h

@@ -1,5 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-// Copyright (c) 2009-2010 Satoshi Nakamoto
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #ifndef __cplusplus
 # error This header can only be compiled as C++.

+ 2 - 1
ecoin/src/rpcblockchain.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include "main.h"
 #include "ecoinrpc.h"
 

+ 2 - 1
ecoin/src/rpcdump.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include <iostream>
 #include <fstream>
 #include "init.h" // for pwalletMain

+ 5 - 2
ecoin/src/rpcmining.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include "main.h"
 #include "db.h"
 #include "txdb.h"
@@ -56,7 +57,9 @@ Value getmininginfo(const Array& params, bool fHelp)
     obj.push_back(Pair("difficulty",    diff));
 
     obj.push_back(Pair("blockvalue",    (uint64_t)GetProofOfWorkReward(GetLastBlockIndex(pindexBest, false)->nHeight+1, GetLastBlockIndex(pindexBest, false)->GetBlockHash())));
-    obj.push_back(Pair("netmhashps",     GetPoWMHashPS()));
+    //obj.push_back(Pair("netmhashps",     GetPoWMHashPS()));
+    obj.push_back(Pair("netmhashps",     GetRandHash));
+
     obj.push_back(Pair("netstakeweight", GetPoSKernelPS()));
     obj.push_back(Pair("errors",        GetWarnings("statusbar")));
     obj.push_back(Pair("pooledtx",      (uint64_t)mempool.size()));

+ 2 - 1
ecoin/src/rpcnet.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include "net.h"
 #include "ecoinrpc.h"
 #include "alert.h"

+ 14 - 13
ecoin/src/rpcrawtransaction.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include <boost/assign/list_of.hpp>
 #include "base58.h"
 #include "ecoinrpc.h"
@@ -304,20 +305,20 @@ Value decodescript(const Array& params, bool fHelp)
             "decodescript <hex string>\n"
             "Decode a hex-encoded script.");
 
-    RPCTypeCheck(params, list_of(str_type));
+//    RPCTypeCheck(params, list_of(str_type));
 
-    Object r;
-    CScript script;
-    if (params[0].get_str().size() > 0){
-        vector<unsigned char> scriptData(ParseHexV(params[0], "argument"));
-        script = CScript(scriptData.begin(), scriptData.end());
-    } else {
-        // Empty scripts are valid
-    }
-    ScriptPubKeyToJSON(script, r, false);
+//    Object r;
+//    CScript script;
+//    if (params[0].get_str().size() > 0){
+//        vector<unsigned char> scriptData(ParseHex(params[0], "argument"));
+//        script = CScript(scriptData.begin(), scriptData.end());
+//    } else {
+//        // Empty scripts are valid
+//    }
+//    ScriptPubKeyToJSON(script, r, false);
 
-    r.push_back(Pair("p2sh", CEcoinAddress(script.GetID()).ToString()));
-    return r;
+//    r.push_back(Pair("p2sh", CEcoinAddress(script.GetID()).ToString()));
+//    return r;
 }
 
 Value signrawtransaction(const Array& params, bool fHelp)

+ 13 - 11
ecoin/src/rpcwallet.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include "wallet.h"
 #include "walletdb.h"
 #include "ecoinrpc.h"
@@ -836,18 +837,19 @@ Value addredeemscript(const Array& params, bool fHelp)
         throw runtime_error(msg);
     }
 
-    string strAccount;
-    if (params.size() > 1)
-        strAccount = AccountFromValue(params[1]);
+//    string strAccount;
+//    if (params.size() > 1)
+//        strAccount = AccountFromValue(params[1]);
 
     // Construct using pay-to-script-hash:
-    vector<unsigned char> innerData = ParseHexV(params[0], "redeemScript");
-    CScript inner(innerData.begin(), innerData.end());
-    CScriptID innerID = inner.GetID();
-    pwalletMain->AddCScript(inner);
-
-    pwalletMain->SetAddressBookName(innerID, strAccount);
-    return CEcoinAddress(innerID).ToString();
+    //vector<unsigned char> innerData = ParseHexV(params[0], "redeemScript");
+    //vector<unsigned char> innerData = ParseHex(params[0], "redeemScript");
+    //CScript inner(innerData.begin(), innerData.end());
+    //CScriptID innerID = inner.GetID();
+    //pwalletMain->AddCScript(inner);
+
+    //pwalletMain->SetAddressBookName(innerID, strAccount);
+    //return CEcoinAddress(innerID).ToString();
 }
 
 struct tallyitem

+ 4 - 5
ecoin/src/script.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include <boost/foreach.hpp>
 #include <boost/tuple/tuple.hpp>
 
@@ -235,8 +236,6 @@ const char* GetOpName(opcodetype opcode)
     case OP_NOP9                   : return "OP_NOP9";
     case OP_NOP10                  : return "OP_NOP10";
 
-
-
     // template matching params
     case OP_PUBKEYHASH             : return "OP_PUBKEYHASH";
     case OP_PUBKEY                 : return "OP_PUBKEY";
@@ -1870,7 +1869,7 @@ bool CScript::IsPayToScriptHash() const
             this->at(22) == OP_EQUAL);
 }
 
-bool CScript::HasCanonicalPushes() const
+/**bool CScript::HasCanonicalPushes() const
 {
     const_iterator pc = begin();
     while (pc < end())
@@ -1895,7 +1894,7 @@ bool CScript::HasCanonicalPushes() const
             return false;
     }
     return true;
-}
+}*/
 
 class CScriptVisitor : public boost::static_visitor<bool>
 {

+ 192 - 12
ecoin/src/script.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef H_ECOIN_SCRIPT
 #define H_ECOIN_SCRIPT
 
@@ -45,7 +46,7 @@ public:
  *  * CNoDestination: no destination set
  *  * CKeyID: TX_PUBKEYHASH destination
  *  * CScriptID: TX_SCRIPTHASH destination
- *  A CTxDestination is the internal data type encoded in a CEcoinAddress
+ *  A CTxDestination is the internal data type encoded in a CecoinAddress
  */
 typedef boost::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
 
@@ -221,6 +222,186 @@ inline std::string StackString(const std::vector<std::vector<unsigned char> >& v
     return str;
 }
 
+class scriptnum_error : public std::runtime_error
+{
+public:
+    explicit scriptnum_error(const std::string& str) : std::runtime_error(str) {}
+};
+
+class CScriptNum
+{
+/**
+ * Numeric opcodes (OP_1ADD, etc) are restricted to operating on 4-byte integers.
+ * The semantics are subtle, though: operands must be in the range [-2^31 +1...2^31 -1],
+ * but results may overflow (and are valid as long as they are not used in a subsequent
+ * numeric operation). CScriptNum enforces those semantics by storing results as
+ * an int64 and allowing out-of-range values to be returned as a vector of bytes but
+ * throwing an exception if arithmetic is done or the result is interpreted as an integer.
+ */
+public:
+
+    explicit CScriptNum(const int64_t& n)
+    {
+        m_value = n;
+    }
+
+    static const size_t nDefaultMaxNumSize = 4;
+
+    explicit CScriptNum(const std::vector<unsigned char>& vch, bool fRequireMinimal,
+                        const size_t nMaxNumSize = nDefaultMaxNumSize)
+    {
+        if (vch.size() > nMaxNumSize) {
+            throw scriptnum_error("script number overflow");
+        }
+        if (fRequireMinimal && vch.size() > 0) {
+            // Check that the number is encoded with the minimum possible
+            // number of bytes.
+            //
+            // If the most-significant-byte - excluding the sign bit - is zero
+            // then we're not minimal. Note how this test also rejects the
+            // negative-zero encoding, 0x80.
+            if ((vch.back() & 0x7f) == 0) {
+                // One exception: if there's more than one byte and the most
+                // significant bit of the second-most-significant-byte is set
+                // it would conflict with the sign bit. An example of this case
+                // is +-255, which encode to 0xff00 and 0xff80 respectively.
+                // (big-endian).
+                if (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0) {
+                    throw scriptnum_error("non-minimally encoded script number");
+                }
+            }
+        }
+        m_value = set_vch(vch);
+    }
+
+    inline bool operator==(const int64_t& rhs) const    { return m_value == rhs; }
+    inline bool operator!=(const int64_t& rhs) const    { return m_value != rhs; }
+    inline bool operator<=(const int64_t& rhs) const    { return m_value <= rhs; }
+    inline bool operator< (const int64_t& rhs) const    { return m_value <  rhs; }
+    inline bool operator>=(const int64_t& rhs) const    { return m_value >= rhs; }
+    inline bool operator> (const int64_t& rhs) const    { return m_value >  rhs; }
+
+    inline bool operator==(const CScriptNum& rhs) const { return operator==(rhs.m_value); }
+    inline bool operator!=(const CScriptNum& rhs) const { return operator!=(rhs.m_value); }
+    inline bool operator<=(const CScriptNum& rhs) const { return operator<=(rhs.m_value); }
+    inline bool operator< (const CScriptNum& rhs) const { return operator< (rhs.m_value); }
+    inline bool operator>=(const CScriptNum& rhs) const { return operator>=(rhs.m_value); }
+    inline bool operator> (const CScriptNum& rhs) const { return operator> (rhs.m_value); }
+
+    inline CScriptNum operator+(   const int64_t& rhs)    const { return CScriptNum(m_value + rhs);}
+    inline CScriptNum operator-(   const int64_t& rhs)    const { return CScriptNum(m_value - rhs);}
+    inline CScriptNum operator+(   const CScriptNum& rhs) const { return operator+(rhs.m_value);   }
+    inline CScriptNum operator-(   const CScriptNum& rhs) const { return operator-(rhs.m_value);   }
+
+    inline CScriptNum& operator+=( const CScriptNum& rhs)       { return operator+=(rhs.m_value);  }
+    inline CScriptNum& operator-=( const CScriptNum& rhs)       { return operator-=(rhs.m_value);  }
+
+    inline CScriptNum operator&(   const int64_t& rhs)    const { return CScriptNum(m_value & rhs);}
+    inline CScriptNum operator&(   const CScriptNum& rhs) const { return operator&(rhs.m_value);   }
+
+    inline CScriptNum& operator&=( const CScriptNum& rhs)       { return operator&=(rhs.m_value);  }
+
+    inline CScriptNum operator-()                         const
+    {
+        assert(m_value != std::numeric_limits<int64_t>::min());
+        return CScriptNum(-m_value);
+    }
+
+    inline CScriptNum& operator=( const int64_t& rhs)
+    {
+        m_value = rhs;
+        return *this;
+    }
+
+    inline CScriptNum& operator+=( const int64_t& rhs)
+    {
+        assert(rhs == 0 || (rhs > 0 && m_value <= std::numeric_limits<int64_t>::max() - rhs) ||
+                           (rhs < 0 && m_value >= std::numeric_limits<int64_t>::min() - rhs));
+        m_value += rhs;
+        return *this;
+    }
+
+    inline CScriptNum& operator-=( const int64_t& rhs)
+    {
+        assert(rhs == 0 || (rhs > 0 && m_value >= std::numeric_limits<int64_t>::min() + rhs) ||
+                           (rhs < 0 && m_value <= std::numeric_limits<int64_t>::max() + rhs));
+        m_value -= rhs;
+        return *this;
+    }
+
+    inline CScriptNum& operator&=( const int64_t& rhs)
+    {
+        m_value &= rhs;
+        return *this;
+    }
+
+    int getint() const
+    {
+        if (m_value > std::numeric_limits<int>::max())
+            return std::numeric_limits<int>::max();
+        else if (m_value < std::numeric_limits<int>::min())
+            return std::numeric_limits<int>::min();
+        return m_value;
+    }
+
+    std::vector<unsigned char> getvch() const
+    {
+        return serialize(m_value);
+    }
+
+    static std::vector<unsigned char> serialize(const int64_t& value)
+    {
+        if(value == 0)
+            return std::vector<unsigned char>();
+
+        std::vector<unsigned char> result;
+        const bool neg = value < 0;
+        uint64_t absvalue = neg ? -value : value;
+
+        while(absvalue)
+        {
+            result.push_back(absvalue & 0xff);
+            absvalue >>= 8;
+        }
+
+//    - If the most significant byte is >= 0x80 and the value is positive, push a
+//    new zero-byte to make the significant byte < 0x80 again.
+
+//    - If the most significant byte is >= 0x80 and the value is negative, push a
+//    new 0x80 byte that will be popped off when converting to an integral.
+
+//    - If the most significant byte is < 0x80 and the value is negative, add
+//    0x80 to it, since it will be subtracted and interpreted as a negative when
+//    converting to an integral.
+
+        if (result.back() & 0x80)
+            result.push_back(neg ? 0x80 : 0);
+        else if (neg)
+            result.back() |= 0x80;
+
+        return result;
+    }
+
+private:
+    static int64_t set_vch(const std::vector<unsigned char>& vch)
+    {
+      if (vch.empty())
+          return 0;
+
+      int64_t result = 0;
+      for (size_t i = 0; i != vch.size(); ++i)
+          result |= static_cast<int64_t>(vch[i]) << 8*i;
+
+      // If the input vector's most significant byte is 0x80, remove it from
+      // the result's msb and return a negative.
+      if (vch.back() & 0x80)
+          return -((int64_t)(result & ~(0x80ULL << (8 * (vch.size() - 1)))));
+
+      return result;
+    }
+
+    int64_t m_value;
+};
 
 
 
@@ -240,8 +421,7 @@ protected:
         }
         else
         {
-            CBigNum bn(n);
-            *this << bn.getvch();
+            *this << CScriptNum::serialize(n);
         }
         return *this;
     }
@@ -254,8 +434,7 @@ protected:
         }
         else
         {
-            CBigNum bn(n);
-            *this << bn.getvch();
+                *this << CScriptNum::serialize(n);
         }
         return *this;
     }
@@ -268,6 +447,12 @@ public:
     CScript(const unsigned char* pbegin, const unsigned char* pend) : std::vector<unsigned char>(pbegin, pend) { }
 #endif
 
+    CScript& operator=(const CScript& b)
+    {
+        assign(b.begin(), b.end());
+        return *this;
+    }
+
     CScript& operator+=(const CScript& b)
     {
         insert(end(), b.begin(), b.end());
@@ -506,7 +691,7 @@ public:
         return nFound;
     }
 
-    // Pre-version-0.6, Ecoin always counted CHECKMULTISIGs
+    // Pre-version-0.6, ecoin always counted CHECKMULTISIGs
     // as 20 sigops. With pay-to-script-hash, that changed:
     // CHECKMULTISIGs serialized in scriptSigs are
     // counted more accurately, assuming they are of the form
@@ -520,7 +705,6 @@ public:
     bool IsPayToScriptHash() const;
 
     // Called by CTransaction::IsStandard
-    // Called by CTransaction::IsStandard and P2SH VerifyScript (which makes it consensus-critical).
     bool IsPushOnly() const
     {
         const_iterator pc = begin();
@@ -535,9 +719,6 @@ public:
         return true;
     }
 
-    // Called by CTransaction::IsStandard.
-    bool HasCanonicalPushes() const;
-
 
     void SetDestination(const CTxDestination& address);
     void SetMultisig(int nRequired, const std::vector<CKey>& keys);
@@ -592,7 +773,6 @@ int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned c
 bool IsStandard(const CScript& scriptPubKey);
 bool IsMine(const CKeyStore& keystore, const CScript& scriptPubKey);
 bool IsMine(const CKeyStore& keystore, const CTxDestination &dest);
-void ExtractAffectedKeys(const CKeyStore &keystore, const CScript& scriptPubKey, std::vector<CKeyID> &vKeys);
 bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet);
 bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);
 bool SignSignature(const CKeyStore& keystore, const CScript& fromPubKey, CTransaction& txTo, unsigned int nIn, int nHashType=SIGHASH_ALL);

+ 1 - 1
ecoin/src/scrypt-arm.S

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #if defined(OPTIMIZED_SALSA) &&  defined(__arm__) && defined(__APCS_32__)
 

+ 1 - 1
ecoin/src/scrypt-x86.S

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 # Copyright 2011 pooler@litecoinpool.org
 # All rights reserved.

+ 1 - 1
ecoin/src/scrypt-x86_64.S

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 # Copyright 2011-2012 pooler@litecoinpool.org
 # All rights reserved.

+ 1 - 30
ecoin/src/scrypt.cpp

@@ -1,33 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-
-/*-
- * Copyright 2009 Colin Percival, 2011 ArtForz, 2011 pooler, 2013 Balthazar
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file was originally written by Colin Percival as part of the Tarsnap
- * online backup system.
- */
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include <stdlib.h>
 #include <stdint.h>

+ 2 - 1
ecoin/src/scrypt.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef SCRYPT_MINE_H
 #define SCRYPT_MINE_H
 

+ 2 - 1
ecoin/src/serialize.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_SERIALIZE_H
 #define ECOIN_SERIALIZE_H
 

+ 1 - 1
ecoin/src/strlcpy.h

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 /*
  * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>

+ 2 - 1
ecoin/src/sync.cpp

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #include "sync.h"
 #include "util.h"
 #include <boost/foreach.hpp>

+ 2 - 1
ecoin/src/sync.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_SYNC_H
 #define ECOIN_SYNC_H
 

+ 1 - 1
ecoin/src/txdb-leveldb.cpp

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include <map>
 #include <boost/version.hpp>

+ 1 - 1
ecoin/src/txdb-leveldb.h

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #ifndef ECOIN_LEVELDB_H
 #define ECOIN_LEVELDB_H

+ 1 - 1
ecoin/src/txdb.h

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #ifndef ECOIN_TXDB_H
 #define ECOIN_TXDB_H

+ 2 - 1
ecoin/src/ui_interface.h

@@ -1,4 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ECOIN_UI_INTERFACE_H
 #define ECOIN_UI_INTERFACE_H
 

+ 1 - 1
ecoin/src/uint256.h

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #ifndef ECOIN_UINT256_H
 #define ECOIN_UINT256_H

+ 1 - 1
ecoin/src/util.cpp

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include "util.h"
 #include "sync.h"

+ 1 - 1
ecoin/src/util.h

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #ifndef ECOIN_UTIL_H
 #define ECOIN_UTIL_H

+ 1 - 1
ecoin/src/version.cpp

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include <string>
 #include "version.h"

+ 1 - 1
ecoin/src/version.h

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #ifndef ECOIN_VERSION_H
 #define ECOIN_VERSION_H

+ 5 - 3
ecoin/src/wallet.cpp

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include "txdb.h"
 #include "wallet.h"
@@ -250,7 +250,9 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
     vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE);
     RAND_bytes(&vMasterKey[0], WALLET_CRYPTO_KEY_SIZE);
 
-    CMasterKey kMasterKey(nDerivationMethodIndex);
+    //CMasterKey kMasterKey(nDerivationMethodIndex);
+
+    CMasterKey kMasterKey;
 
     RandAddSeedPerfmon();
     kMasterKey.vchSalt.resize(WALLET_CRYPTO_SALT_SIZE);
@@ -2485,7 +2487,7 @@ void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64> &mapKeyBirth) const {
             int nHeight = blit->second->nHeight;
             BOOST_FOREACH(const CTxOut &txout, wtx.vout) {
                 // iterate over all their outputs
-                ::ExtractAffectedKeys(*this, txout.scriptPubKey, vAffected);
+                //::ExtractAffectedKeys(*this, txout.scriptPubKey, vAffected);
                 BOOST_FOREACH(const CKeyID &keyid, vAffected) {
                     // ... and all their affected keys
                     std::map<CKeyID, CBlockIndex*>::iterator rit = mapKeyFirstBlock.find(keyid);

+ 1 - 1
ecoin/src/wallet.h

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #ifndef ECOIN_WALLET_H
 #define ECOIN_WALLET_H

+ 1 - 1
ecoin/src/walletdb.cpp

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include "walletdb.h"
 #include "wallet.h"

+ 1 - 1
ecoin/src/walletdb.h

@@ -1,4 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #ifndef ECOIN_WALLETDB_H
 #define ECOIN_WALLETDB_H

+ 3 - 14
ecoin/src/zerocoin/Accumulator.cpp

@@ -1,15 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-/**
- * @file       Accumulator.cpp
- *
- * @brief      Accumulator and AccumulatorWitness classes for the Zerocoin library.
- *
- * @author     Ian Miers, Christina Garman and Matthew Green
- * @date       June 2013
- *
- * @copyright  Copyright 2013 Ian Miers, Christina Garman and Matthew Green
- * @license    This project is released under the MIT license.
- **/
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include <sstream>
 #include "Zerocoin.h"
@@ -64,7 +53,7 @@ const CoinDenomination Accumulator::getDenomination() const {
 	return static_cast<CoinDenomination> (this->denomination);
 }
 
-const Bignum& Accumulator::getValue() const {
+const CBigNum& Accumulator::getValue() const {
 	return this->value;
 }
 
@@ -88,7 +77,7 @@ void AccumulatorWitness::AddElement(const PublicCoin& c) {
 	}
 }
 
-const Bignum& AccumulatorWitness::getValue() const {
+const CBigNum& AccumulatorWitness::getValue() const {
 	return this->witness.getValue();
 }
 

+ 7 - 17
ecoin/src/zerocoin/Accumulator.h

@@ -1,15 +1,5 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-/**
- * @file       Accumulator.h
- *
- * @brief      Accumulator and AccumulatorWitness classes for the Zerocoin library.
- *
- * @author     Ian Miers, Christina Garman and Matthew Green
- * @date       June 2013
- *
- * @copyright  Copyright 2013 Ian Miers, Christina Garman and Matthew Green
- * @license    This project is released under the MIT license.
- **/
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+
 #ifndef ACCUMULATOR_H_
 #define ACCUMULATOR_H_
 
@@ -62,9 +52,9 @@ public:
 	const CoinDenomination getDenomination() const;
 	/** Get the accumulator result
 	 *
-	 * @return a Bignum containing the result.
+	 * @return a CBigNum containing the result.
 	 */
-	const Bignum& getValue() const;
+	const CBigNum& getValue() const;
 
 
 	// /**
@@ -74,7 +64,7 @@ public:
 	//  * @param b the value to set the accumulator to.
 	//  * @throw  A ZerocoinException if the accumulator value is invalid.
 	//  */
-	// void setValue(Bignum &b); // shouldn't this be a constructor?
+	// void setValue(CBigNum &b); // shouldn't this be a constructor?
 
 	/** Used to accumulate a coin
 	 *
@@ -91,7 +81,7 @@ public:
 	)
 private:
 	const AccumulatorAndProofParams* params;
-	Bignum value;
+	CBigNum value;
 	// Denomination is stored as an INT because storing
 	// and enum raises amigiuities in the serialize code //FIXME if possible
 	int denomination;
@@ -124,7 +114,7 @@ public:
 	 *
 	 * @return the value of the witness
 	 */
-	const Bignum& getValue() const;
+	const CBigNum& getValue() const;
 
 	/** Checks that this is a witness to the accumulation of coin
 	 * @param a             the accumulator we are checking against.

+ 42 - 53
ecoin/src/zerocoin/AccumulatorProofOfKnowledge.cpp

@@ -1,15 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-/**
- * @file       AccumulatorProofOfKnowledge.cpp
- *
- * @brief      AccumulatorProofOfKnowledge class for the Zerocoin library.
- *
- * @author     Ian Miers, Christina Garman and Matthew Green
- * @date       June 2013
- *
- * @copyright  Copyright 2013 Ian Miers, Christina Garman and Matthew Green
- * @license    This project is released under the MIT license.
- **/
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include "Zerocoin.h"
 
@@ -21,53 +10,53 @@ AccumulatorProofOfKnowledge::AccumulatorProofOfKnowledge(const AccumulatorAndPro
         const Commitment& commitmentToCoin, const AccumulatorWitness& witness,
         Accumulator& a): params(p) {
 
-	Bignum sg = params->accumulatorPoKCommitmentGroup.g;
-	Bignum sh = params->accumulatorPoKCommitmentGroup.h;
+	CBigNum sg = params->accumulatorPoKCommitmentGroup.g;
+	CBigNum sh = params->accumulatorPoKCommitmentGroup.h;
 
-	Bignum g_n = params->accumulatorQRNCommitmentGroup.g;
-	Bignum h_n = params->accumulatorQRNCommitmentGroup.h;
+	CBigNum g_n = params->accumulatorQRNCommitmentGroup.g;
+	CBigNum h_n = params->accumulatorQRNCommitmentGroup.h;
 
-	Bignum e = commitmentToCoin.getContents();
-	Bignum r = commitmentToCoin.getRandomness();
+	CBigNum e = commitmentToCoin.getContents();
+	CBigNum r = commitmentToCoin.getRandomness();
 
-	Bignum r_1 = Bignum::randBignum(params->accumulatorModulus/4);
-	Bignum r_2 = Bignum::randBignum(params->accumulatorModulus/4);
-	Bignum r_3 = Bignum::randBignum(params->accumulatorModulus/4);
+	CBigNum r_1 = CBigNum::randBignum(params->accumulatorModulus/4);
+	CBigNum r_2 = CBigNum::randBignum(params->accumulatorModulus/4);
+	CBigNum r_3 = CBigNum::randBignum(params->accumulatorModulus/4);
 
 	this->C_e = g_n.pow_mod(e, params->accumulatorModulus) * h_n.pow_mod(r_1, params->accumulatorModulus);
 	this->C_u = witness.getValue() * h_n.pow_mod(r_2, params->accumulatorModulus);
 	this->C_r = g_n.pow_mod(r_2, params->accumulatorModulus) * h_n.pow_mod(r_3, params->accumulatorModulus);
 
-	Bignum r_alpha = Bignum::randBignum(params->maxCoinValue * Bignum(2).pow(params->k_prime + params->k_dprime));
-	if(!(Bignum::randBignum(Bignum(3)) % 2)) {
+	CBigNum r_alpha = CBigNum::randBignum(params->maxCoinValue * CBigNum(2).pow(params->k_prime + params->k_dprime));
+	if(!(CBigNum::randBignum(CBigNum(3)) % 2)) {
 		r_alpha = 0-r_alpha;
 	}
 
-	Bignum r_gamma = Bignum::randBignum(params->accumulatorPoKCommitmentGroup.modulus);
-	Bignum r_phi = Bignum::randBignum(params->accumulatorPoKCommitmentGroup.modulus);
-	Bignum r_psi = Bignum::randBignum(params->accumulatorPoKCommitmentGroup.modulus);
-	Bignum r_sigma = Bignum::randBignum(params->accumulatorPoKCommitmentGroup.modulus);
-	Bignum r_xi = Bignum::randBignum(params->accumulatorPoKCommitmentGroup.modulus);
+	CBigNum r_gamma = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus);
+	CBigNum r_phi = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus);
+	CBigNum r_psi = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus);
+	CBigNum r_sigma = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus);
+	CBigNum r_xi = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus);
 
-	Bignum r_epsilon =  Bignum::randBignum((params->accumulatorModulus/4) * Bignum(2).pow(params->k_prime + params->k_dprime));
-	if(!(Bignum::randBignum(Bignum(3)) % 2)) {
+	CBigNum r_epsilon =  CBigNum::randBignum((params->accumulatorModulus/4) * CBigNum(2).pow(params->k_prime + params->k_dprime));
+	if(!(CBigNum::randBignum(CBigNum(3)) % 2)) {
 		r_epsilon = 0-r_epsilon;
 	}
-	Bignum r_eta = Bignum::randBignum((params->accumulatorModulus/4) * Bignum(2).pow(params->k_prime + params->k_dprime));
-	if(!(Bignum::randBignum(Bignum(3)) % 2)) {
+	CBigNum r_eta = CBigNum::randBignum((params->accumulatorModulus/4) * CBigNum(2).pow(params->k_prime + params->k_dprime));
+	if(!(CBigNum::randBignum(CBigNum(3)) % 2)) {
 		r_eta = 0-r_eta;
 	}
-	Bignum r_zeta = Bignum::randBignum((params->accumulatorModulus/4) * Bignum(2).pow(params->k_prime + params->k_dprime));
-	if(!(Bignum::randBignum(Bignum(3)) % 2)) {
+	CBigNum r_zeta = CBigNum::randBignum((params->accumulatorModulus/4) * CBigNum(2).pow(params->k_prime + params->k_dprime));
+	if(!(CBigNum::randBignum(CBigNum(3)) % 2)) {
 		r_zeta = 0-r_zeta;
 	}
 
-	Bignum r_beta = Bignum::randBignum((params->accumulatorModulus/4) * params->accumulatorPoKCommitmentGroup.modulus * Bignum(2).pow(params->k_prime + params->k_dprime));
-	if(!(Bignum::randBignum(Bignum(3)) % 2)) {
+	CBigNum r_beta = CBigNum::randBignum((params->accumulatorModulus/4) * params->accumulatorPoKCommitmentGroup.modulus * CBigNum(2).pow(params->k_prime + params->k_dprime));
+	if(!(CBigNum::randBignum(CBigNum(3)) % 2)) {
 		r_beta = 0-r_beta;
 	}
-	Bignum r_delta = Bignum::randBignum((params->accumulatorModulus/4) * params->accumulatorPoKCommitmentGroup.modulus * Bignum(2).pow(params->k_prime + params->k_dprime));
-	if(!(Bignum::randBignum(Bignum(3)) % 2)) {
+	CBigNum r_delta = CBigNum::randBignum((params->accumulatorModulus/4) * params->accumulatorPoKCommitmentGroup.modulus * CBigNum(2).pow(params->k_prime + params->k_dprime));
+	if(!(CBigNum::randBignum(CBigNum(3)) % 2)) {
 		r_delta = 0-r_delta;
 	}
 
@@ -84,7 +73,7 @@ AccumulatorProofOfKnowledge::AccumulatorProofOfKnowledge(const AccumulatorAndPro
 	hasher << *params << sg << sh << g_n << h_n << commitmentToCoin.getCommitmentValue() << C_e << C_u << C_r << st_1 << st_2 << st_3 << t_1 << t_2 << t_3 << t_4;
 
 	//According to the proof, this hash should be of length k_prime bits.  It is currently greater than that, which should not be a problem, but we should check this.
-	Bignum c = Bignum(hasher.GetHash());
+	CBigNum c = CBigNum(hasher.GetHash());
 
 	this->s_alpha = r_alpha - c*e;
 	this->s_beta = r_beta - c*r_2*e;
@@ -101,27 +90,27 @@ AccumulatorProofOfKnowledge::AccumulatorProofOfKnowledge(const AccumulatorAndPro
 
 /** Verifies that a commitment c is accumulated in accumulator a
  */
-bool AccumulatorProofOfKnowledge:: Verify(const Accumulator& a, const Bignum& valueOfCommitmentToCoin) const {
-	Bignum sg = params->accumulatorPoKCommitmentGroup.g;
-	Bignum sh = params->accumulatorPoKCommitmentGroup.h;
+bool AccumulatorProofOfKnowledge:: Verify(const Accumulator& a, const CBigNum& valueOfCommitmentToCoin) const {
+	CBigNum sg = params->accumulatorPoKCommitmentGroup.g;
+	CBigNum sh = params->accumulatorPoKCommitmentGroup.h;
 
-	Bignum g_n = params->accumulatorQRNCommitmentGroup.g;
-	Bignum h_n = params->accumulatorQRNCommitmentGroup.h;
+	CBigNum g_n = params->accumulatorQRNCommitmentGroup.g;
+	CBigNum h_n = params->accumulatorQRNCommitmentGroup.h;
 
 	//According to the proof, this hash should be of length k_prime bits.  It is currently greater than that, which should not be a problem, but we should check this.
 	CHashWriter hasher(0,0);
 	hasher << *params << sg << sh << g_n << h_n << valueOfCommitmentToCoin << C_e << C_u << C_r << st_1 << st_2 << st_3 << t_1 << t_2 << t_3 << t_4;
 
-	Bignum c = Bignum(hasher.GetHash()); //this hash should be of length k_prime bits
+	CBigNum c = CBigNum(hasher.GetHash()); //this hash should be of length k_prime bits
 
-	Bignum st_1_prime = (valueOfCommitmentToCoin.pow_mod(c, params->accumulatorPoKCommitmentGroup.modulus) * sg.pow_mod(s_alpha, params->accumulatorPoKCommitmentGroup.modulus) * sh.pow_mod(s_phi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus;
-	Bignum st_2_prime = (sg.pow_mod(c, params->accumulatorPoKCommitmentGroup.modulus) * ((valueOfCommitmentToCoin * sg.inverse(params->accumulatorPoKCommitmentGroup.modulus)).pow_mod(s_gamma, params->accumulatorPoKCommitmentGroup.modulus)) * sh.pow_mod(s_psi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus;
-	Bignum st_3_prime = (sg.pow_mod(c, params->accumulatorPoKCommitmentGroup.modulus) * (sg * valueOfCommitmentToCoin).pow_mod(s_sigma, params->accumulatorPoKCommitmentGroup.modulus) * sh.pow_mod(s_xi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus;
+	CBigNum st_1_prime = (valueOfCommitmentToCoin.pow_mod(c, params->accumulatorPoKCommitmentGroup.modulus) * sg.pow_mod(s_alpha, params->accumulatorPoKCommitmentGroup.modulus) * sh.pow_mod(s_phi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus;
+	CBigNum st_2_prime = (sg.pow_mod(c, params->accumulatorPoKCommitmentGroup.modulus) * ((valueOfCommitmentToCoin * sg.inverse(params->accumulatorPoKCommitmentGroup.modulus)).pow_mod(s_gamma, params->accumulatorPoKCommitmentGroup.modulus)) * sh.pow_mod(s_psi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus;
+	CBigNum st_3_prime = (sg.pow_mod(c, params->accumulatorPoKCommitmentGroup.modulus) * (sg * valueOfCommitmentToCoin).pow_mod(s_sigma, params->accumulatorPoKCommitmentGroup.modulus) * sh.pow_mod(s_xi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus;
 
-	Bignum t_1_prime = (C_r.pow_mod(c, params->accumulatorModulus) * h_n.pow_mod(s_zeta, params->accumulatorModulus) * g_n.pow_mod(s_epsilon, params->accumulatorModulus)) % params->accumulatorModulus;
-	Bignum t_2_prime = (C_e.pow_mod(c, params->accumulatorModulus) * h_n.pow_mod(s_eta, params->accumulatorModulus) * g_n.pow_mod(s_alpha, params->accumulatorModulus)) % params->accumulatorModulus;
-	Bignum t_3_prime = ((a.getValue()).pow_mod(c, params->accumulatorModulus) * C_u.pow_mod(s_alpha, params->accumulatorModulus) * ((h_n.inverse(params->accumulatorModulus)).pow_mod(s_beta, params->accumulatorModulus))) % params->accumulatorModulus;
-	Bignum t_4_prime = (C_r.pow_mod(s_alpha, params->accumulatorModulus) * ((h_n.inverse(params->accumulatorModulus)).pow_mod(s_delta, params->accumulatorModulus)) * ((g_n.inverse(params->accumulatorModulus)).pow_mod(s_beta, params->accumulatorModulus))) % params->accumulatorModulus;
+	CBigNum t_1_prime = (C_r.pow_mod(c, params->accumulatorModulus) * h_n.pow_mod(s_zeta, params->accumulatorModulus) * g_n.pow_mod(s_epsilon, params->accumulatorModulus)) % params->accumulatorModulus;
+	CBigNum t_2_prime = (C_e.pow_mod(c, params->accumulatorModulus) * h_n.pow_mod(s_eta, params->accumulatorModulus) * g_n.pow_mod(s_alpha, params->accumulatorModulus)) % params->accumulatorModulus;
+	CBigNum t_3_prime = ((a.getValue()).pow_mod(c, params->accumulatorModulus) * C_u.pow_mod(s_alpha, params->accumulatorModulus) * ((h_n.inverse(params->accumulatorModulus)).pow_mod(s_beta, params->accumulatorModulus))) % params->accumulatorModulus;
+	CBigNum t_4_prime = (C_r.pow_mod(s_alpha, params->accumulatorModulus) * ((h_n.inverse(params->accumulatorModulus)).pow_mod(s_delta, params->accumulatorModulus)) * ((g_n.inverse(params->accumulatorModulus)).pow_mod(s_beta, params->accumulatorModulus))) % params->accumulatorModulus;
 
 	bool result = false;
 
@@ -134,7 +123,7 @@ bool AccumulatorProofOfKnowledge:: Verify(const Accumulator& a, const Bignum& va
 	bool result_t3 = (t_3 == t_3_prime);
 	bool result_t4 = (t_4 == t_4_prime);
 
-	bool result_range = ((s_alpha >= -(params->maxCoinValue * Bignum(2).pow(params->k_prime + params->k_dprime + 1))) && (s_alpha <= (params->maxCoinValue * Bignum(2).pow(params->k_prime + params->k_dprime + 1))));
+	bool result_range = ((s_alpha >= -(params->maxCoinValue * CBigNum(2).pow(params->k_prime + params->k_dprime + 1))) && (s_alpha <= (params->maxCoinValue * CBigNum(2).pow(params->k_prime + params->k_dprime + 1))));
 
 	result = result_st1 && result_st2 && result_st3 && result_t1 && result_t2 && result_t3 && result_t4 && result_range;
 

+ 41 - 51
ecoin/src/zerocoin/AccumulatorProofOfKnowledge.h

@@ -1,37 +1,27 @@
-/**
- * @file       AccumulatorProofOfKnowledge.h
- *
- * @brief      AccumulatorProofOfKnowledge class for the Zerocoin library.
- *
- * @author     Ian Miers, Christina Garman and Matthew Green
- * @date       June 2013
- *
- * @copyright  Copyright 2013 Ian Miers, Christina Garman and Matthew Green
- * @license    This project is released under the MIT license.
- **/
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
-#ifndef ACCUMULATEPROOF_H_
-#define ACCUMULATEPROOF_H_
+	#ifndef ACCUMULATEPROOF_H_
+	#define ACCUMULATEPROOF_H_
 
-namespace libzerocoin {
+	namespace libzerocoin {
 
-/**A prove that a value insde the commitment commitmentToCoin is in an accumulator a.
- *
- */
-class AccumulatorProofOfKnowledge {
-public:
-	AccumulatorProofOfKnowledge(const AccumulatorAndProofParams* p);
-
-	/** Generates a proof that a commitment to a coin c was accumulated
-	 * @param p  Cryptographic parameters
-	 * @param commitmentToCoin commitment containing the coin we want to prove is accumulated
-	 * @param witness The witness to the accumulation of the coin
-	 * @param a
-	 */
-	AccumulatorProofOfKnowledge(const AccumulatorAndProofParams* p, const Commitment& commitmentToCoin, const AccumulatorWitness& witness, Accumulator& a);
-	/** Verifies that  a commitment c is accumulated in accumulated a
+	/**A prove that a value insde the commitment commitmentToCoin is in an accumulator a.
+	 *
 	 */
-	bool Verify(const Accumulator& a,const Bignum& valueOfCommitmentToCoin) const;
+	class AccumulatorProofOfKnowledge {
+	public:
+		AccumulatorProofOfKnowledge(const AccumulatorAndProofParams* p);
+
+		/** Generates a proof that a commitment to a coin c was accumulated
+		 * @param p  Cryptographic parameters
+		 * @param commitmentToCoin commitment containing the coin we want to prove is accumulated
+		 * @param witness The witness to the accumulation of the coin
+		 * @param a
+		 */
+		AccumulatorProofOfKnowledge(const AccumulatorAndProofParams* p, const Commitment& commitmentToCoin, const AccumulatorWitness& witness, Accumulator& a);
+		/** Verifies that  a commitment c is accumulated in accumulated a
+		 */
+		bool Verify(const Accumulator& a,const CBigNum& valueOfCommitmentToCoin) const;
 
 	IMPLEMENT_SERIALIZE
 	(
@@ -61,30 +51,30 @@ private:
 	const AccumulatorAndProofParams* params;
 
 	/* Return values for proof */
-	Bignum C_e;
-	Bignum C_u;
-	Bignum C_r;
+	CBigNum C_e;
+	CBigNum C_u;
+	CBigNum C_r;
 
-	Bignum st_1;
-	Bignum st_2;
-	Bignum st_3;
+	CBigNum st_1;
+	CBigNum st_2;
+	CBigNum st_3;
 
-	Bignum t_1;
-	Bignum t_2;
-	Bignum t_3;
-	Bignum t_4;
+	CBigNum t_1;
+	CBigNum t_2;
+	CBigNum t_3;
+	CBigNum t_4;
 
-	Bignum s_alpha;
-	Bignum s_beta;
-	Bignum s_zeta;
-	Bignum s_sigma;
-	Bignum s_eta;
-	Bignum s_epsilon;
-	Bignum s_delta;
-	Bignum s_xi;
-	Bignum s_phi;
-	Bignum s_gamma;
-	Bignum s_psi;
+	CBigNum s_alpha;
+	CBigNum s_beta;
+	CBigNum s_zeta;
+	CBigNum s_sigma;
+	CBigNum s_eta;
+	CBigNum s_epsilon;
+	CBigNum s_delta;
+	CBigNum s_xi;
+	CBigNum s_phi;
+	CBigNum s_gamma;
+	CBigNum s_psi;
 };
 
 } /* namespace libzerocoin */

+ 10 - 21
ecoin/src/zerocoin/Coin.cpp

@@ -1,15 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-/**
- * @file       Coin.cpp
- *
- * @brief      PublicCoin and PrivateCoin classes for the Zerocoin library.
- *
- * @author     Ian Miers, Christina Garman and Matthew Green
- * @date       June 2013
- *
- * @copyright  Copyright 2013 Ian Miers, Christina Garman and Matthew Green
- * @license    This project is released under the MIT license.
- **/
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)º
 
 #include <stdexcept>
 #include "Zerocoin.h"
@@ -24,7 +13,7 @@ PublicCoin::PublicCoin(const Params* p):
 	}
 };
 
-PublicCoin::PublicCoin(const Params* p, const Bignum& coin, const CoinDenomination d):
+PublicCoin::PublicCoin(const Params* p, const CBigNum& coin, const CoinDenomination d):
 	params(p), value(coin), denomination(d) {
 	if(this->params->initialized == false) {
 		throw std::invalid_argument("Params are not initialized");
@@ -39,7 +28,7 @@ bool PublicCoin::operator!=(const PublicCoin& rhs) const {
 	return !(*this == rhs);
 }
 
-const Bignum& PublicCoin::getValue() const {
+const CBigNum& PublicCoin::getValue() const {
 	return this->value;
 }
 
@@ -74,11 +63,11 @@ PrivateCoin::PrivateCoin(const Params* p, const CoinDenomination denomination):
  *
  * @return the coins serial number
  */
-const Bignum& PrivateCoin::getSerialNumber() const {
+const CBigNum& PrivateCoin::getSerialNumber() const {
 	return this->serialNumber;
 }
 
-const Bignum& PrivateCoin::getRandomness() const {
+const CBigNum& PrivateCoin::getRandomness() const {
 	return this->randomness;
 }
 
@@ -89,7 +78,7 @@ void PrivateCoin::mintCoin(const CoinDenomination denomination) {
 
 		// Generate a random serial number in the range 0...{q-1} where
 		// "q" is the order of the commitment group.
-		Bignum s = Bignum::randBignum(this->params->coinCommitmentGroup.groupOrder);
+		CBigNum s = CBigNum::randBignum(this->params->coinCommitmentGroup.groupOrder);
 
 		// Generate a Pedersen commitment to the serial number "s"
 		Commitment coin(&params->coinCommitmentGroup, s);
@@ -119,14 +108,14 @@ void PrivateCoin::mintCoinFast(const CoinDenomination denomination) {
 	
 	// Generate a random serial number in the range 0...{q-1} where
 	// "q" is the order of the commitment group.
-	Bignum s = Bignum::randBignum(this->params->coinCommitmentGroup.groupOrder);
+	CBigNum s = CBigNum::randBignum(this->params->coinCommitmentGroup.groupOrder);
 	
 	// Generate a random number "r" in the range 0...{q-1}
-	Bignum r = Bignum::randBignum(this->params->coinCommitmentGroup.groupOrder);
+	CBigNum r = CBigNum::randBignum(this->params->coinCommitmentGroup.groupOrder);
 	
 	// Manually compute a Pedersen commitment to the serial number "s" under randomness "r"
 	// C = g^s * h^r mod p
-	Bignum commitmentValue = this->params->coinCommitmentGroup.g.pow_mod(s, this->params->coinCommitmentGroup.modulus).mul_mod(this->params->coinCommitmentGroup.h.pow_mod(r, this->params->coinCommitmentGroup.modulus), this->params->coinCommitmentGroup.modulus);
+	CBigNum commitmentValue = this->params->coinCommitmentGroup.g.pow_mod(s, this->params->coinCommitmentGroup.modulus).mul_mod(this->params->coinCommitmentGroup.h.pow_mod(r, this->params->coinCommitmentGroup.modulus), this->params->coinCommitmentGroup.modulus);
 	
 	// Repeat this process up to MAX_COINMINT_ATTEMPTS times until
 	// we obtain a prime number
@@ -147,7 +136,7 @@ void PrivateCoin::mintCoinFast(const CoinDenomination denomination) {
 		}
 		
 		// Generate a new random "r_delta" in 0...{q-1}
-		Bignum r_delta = Bignum::randBignum(this->params->coinCommitmentGroup.groupOrder);
+		CBigNum r_delta = CBigNum::randBignum(this->params->coinCommitmentGroup.groupOrder);
 
 		// The commitment was not prime. Increment "r" and recalculate "C":
 		// r = r + r_delta mod q

+ 8 - 19
ecoin/src/zerocoin/Coin.h

@@ -1,15 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-/**
- * @file       Coin.h
- *
- * @brief      PublicCoin and PrivateCoin classes for the Zerocoin library.
- *
- * @author     Ian Miers, Christina Garman and Matthew Green
- * @date       June 2013
- *
- * @copyright  Copyright 2013 Ian Miers, Christina Garman and Matthew Green
- * @license    This project is released under the MIT license.
- **/
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #ifndef COIN_H_
 #define COIN_H_
@@ -48,8 +37,8 @@ public:
 	 * @param coin the value of the commitment.
 	 * @param denomination The denomination of the coin. Defaults to ZQ_PEDERSEN
 	 */
-	PublicCoin( const Params* p, const Bignum& coin, const CoinDenomination d = ZQ_PEDERSEN);
-	const Bignum& getValue() const;
+	PublicCoin( const Params* p, const CBigNum& coin, const CoinDenomination d = ZQ_PEDERSEN);
+	const CBigNum& getValue() const;
 	const CoinDenomination getDenomination() const;
 	bool operator==(const PublicCoin& rhs) const;
 	bool operator!=(const PublicCoin& rhs) const;
@@ -66,7 +55,7 @@ public:
 	)
 private:
 	const Params* params;
-	Bignum value;
+	CBigNum value;
 	// Denomination is stored as an INT because storing
 	// and enum raises amigiuities in the serialize code //FIXME if possible
 	int denomination;
@@ -91,8 +80,8 @@ public:
 	}
 	PrivateCoin(const Params* p,const CoinDenomination denomination = ZQ_PEDERSEN);
 	const PublicCoin& getPublicCoin() const;
-	const Bignum& getSerialNumber() const;
-	const Bignum& getRandomness() const;
+	const CBigNum& getSerialNumber() const;
+	const CBigNum& getRandomness() const;
 
 	IMPLEMENT_SERIALIZE
 	(
@@ -103,8 +92,8 @@ public:
 private:
 	const Params* params;
 	PublicCoin publicCoin;
-	Bignum randomness;
-	Bignum serialNumber;
+	CBigNum randomness;
+	CBigNum serialNumber;
 
 	/**
 	 * @brief Mint a new coin.

+ 2 - 13
ecoin/src/zerocoin/CoinSpend.cpp

@@ -1,15 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-/**
- * @file       CoinSpend.cpp
- *
- * @brief      CoinSpend class for the Zerocoin library.
- *
- * @author     Ian Miers, Christina Garman and Matthew Green
- * @date       June 2013
- *
- * @copyright  Copyright 2013 Ian Miers, Christina Garman and Matthew Green
- * @license    This project is released under the MIT license.
- **/
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include "Zerocoin.h"
 
@@ -55,7 +44,7 @@ CoinSpend::CoinSpend(const Params* p, const PrivateCoin& coin,
 	this->serialNumberSoK = SerialNumberSignatureOfKnowledge(p, coin, fullCommitmentToCoinUnderSerialParams, signatureHash(m));
 }
 
-const Bignum&
+const CBigNum&
 CoinSpend::getCoinSerialNumber() {
 	return this->coinSerialNumber;
 }

+ 5 - 15
ecoin/src/zerocoin/CoinSpend.h

@@ -1,14 +1,4 @@
-/**
- * @file       CoinSpend.h
- *
- * @brief      CoinSpend class for the Zerocoin library.
- *
- * @author     Ian Miers, Christina Garman and Matthew Green
- * @date       June 2013
- *
- * @copyright  Copyright 2013 Ian Miers, Christina Garman and Matthew Green
- * @license    This project is released under the MIT license.
- **/
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #ifndef COINSPEND_H_
 #define COINSPEND_H_
@@ -68,7 +58,7 @@ public:
 	 *
 	 * @return the coin's serial number
 	 */
-	const Bignum& getCoinSerialNumber();
+	const CBigNum& getCoinSerialNumber();
 
 	/**Gets the denomination of the coin spent in this proof.
 	 *
@@ -95,9 +85,9 @@ private:
 	// Denomination is stored as an INT because storing
 	// and enum raises amigiuities in the serialize code //FIXME if possible
 	int denomination;
-	Bignum accCommitmentToCoinValue;
-	Bignum serialCommitmentToCoinValue;
-	Bignum coinSerialNumber;
+	CBigNum accCommitmentToCoinValue;
+	CBigNum serialCommitmentToCoinValue;
+	CBigNum coinSerialNumber;
 	AccumulatorProofOfKnowledge accumulatorPoK;
 	SerialNumberSignatureOfKnowledge serialNumberSoK;
 	CommitmentProofOfKnowledge commitmentPoK;

+ 25 - 35
ecoin/src/zerocoin/Commitment.cpp

@@ -1,14 +1,4 @@
-/**
- * @file       Commitment.cpp
- *
- * @brief      Commitment and CommitmentProof classes for the Zerocoin library.
- *
- * @author     Ian Miers, Christina Garman and Matthew Green
- * @date       June 2013
- *
- * @copyright  Copyright 2013 Ian Miers, Christina Garman and Matthew Green
- * @license    This project is released under the MIT license.
- **/
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include <stdlib.h>
 #include "Zerocoin.h"
@@ -17,21 +7,21 @@ namespace libzerocoin {
 
 //Commitment class
 Commitment::Commitment::Commitment(const IntegerGroupParams* p,
-                                   const Bignum& value): params(p), contents(value) {
-	this->randomness = Bignum::randBignum(params->groupOrder);
+                                   const CBigNum& value): params(p), contents(value) {
+	this->randomness = CBigNum::randBignum(params->groupOrder);
 	this->commitmentValue = (params->g.pow_mod(this->contents, params->modulus).mul_mod(
 	                         params->h.pow_mod(this->randomness, params->modulus), params->modulus));
 }
 
-const Bignum& Commitment::getCommitmentValue() const {
+const CBigNum& Commitment::getCommitmentValue() const {
 	return this->commitmentValue;
 }
 
-const Bignum& Commitment::getRandomness() const {
+const CBigNum& Commitment::getRandomness() const {
 	return this->randomness;
 }
 
-const Bignum& Commitment::getContents() const {
+const CBigNum& Commitment::getContents() const {
 	return this->contents;
 }
 
@@ -43,7 +33,7 @@ CommitmentProofOfKnowledge::CommitmentProofOfKnowledge(const IntegerGroupParams*
         const IntegerGroupParams* bParams, const Commitment& a, const Commitment& b):
 	ap(aParams),bp(bParams)
 {
-	Bignum r1, r2, r3;
+	CBigNum r1, r2, r3;
 
 	// First: make sure that the two commitments have the
 	// same contents.
@@ -59,11 +49,11 @@ CommitmentProofOfKnowledge::CommitmentProofOfKnowledge(const IntegerGroupParams*
 	uint32_t randomSize = COMMITMENT_EQUALITY_CHALLENGE_SIZE + COMMITMENT_EQUALITY_SECMARGIN +
 	                      std::max(std::max(this->ap->modulus.bitSize(), this->bp->modulus.bitSize()),
 	                               std::max(this->ap->groupOrder.bitSize(), this->bp->groupOrder.bitSize()));
-	Bignum maxRange = (Bignum(2).pow(randomSize) - Bignum(1));
+	CBigNum maxRange = (CBigNum(2).pow(randomSize) - CBigNum(1));
 
-	r1 = Bignum::randBignum(maxRange);
-	r2 = Bignum::randBignum(maxRange);
-	r3 = Bignum::randBignum(maxRange);
+	r1 = CBigNum::randBignum(maxRange);
+	r2 = CBigNum::randBignum(maxRange);
+	r3 = CBigNum::randBignum(maxRange);
 
 	// Generate two random, ephemeral commitments "T1, T2"
 	// of the form:
@@ -71,8 +61,8 @@ CommitmentProofOfKnowledge::CommitmentProofOfKnowledge(const IntegerGroupParams*
 	// T2 = g2^r1 * h2^r3 mod p2
 	//
 	// Where (g1, h1, p1) are from "aParams" and (g2, h2, p2) are from "bParams".
-	Bignum T1 = this->ap->g.pow_mod(r1, this->ap->modulus).mul_mod((this->ap->h.pow_mod(r2, this->ap->modulus)), this->ap->modulus);
-	Bignum T2 = this->bp->g.pow_mod(r1, this->bp->modulus).mul_mod((this->bp->h.pow_mod(r3, this->bp->modulus)), this->bp->modulus);
+	CBigNum T1 = this->ap->g.pow_mod(r1, this->ap->modulus).mul_mod((this->ap->h.pow_mod(r2, this->ap->modulus)), this->ap->modulus);
+	CBigNum T2 = this->bp->g.pow_mod(r1, this->bp->modulus).mul_mod((this->bp->h.pow_mod(r3, this->bp->modulus)), this->bp->modulus);
 
 	// Now hash commitment "A" with commitment "B" as well as the
 	// parameters and the two ephemeral commitments "T1, T2" we just generated
@@ -96,7 +86,7 @@ CommitmentProofOfKnowledge::CommitmentProofOfKnowledge(const IntegerGroupParams*
 	// are stored in member variables.
 }
 
-bool CommitmentProofOfKnowledge::Verify(const Bignum& A, const Bignum& B) const
+bool CommitmentProofOfKnowledge::Verify(const CBigNum& A, const CBigNum& B) const
 {
 	// Compute the maximum range of S1, S2, S3 and verify that the given values are
 	// in a correct range. This might be an unnecessary check.
@@ -107,27 +97,27 @@ bool CommitmentProofOfKnowledge::Verify(const Bignum& A, const Bignum& B) const
 	if ((uint32_t)this->S1.bitSize() > maxSize ||
 	        (uint32_t)this->S2.bitSize() > maxSize ||
 	        (uint32_t)this->S3.bitSize() > maxSize ||
-	        this->S1 < Bignum(0) ||
-	        this->S2 < Bignum(0) ||
-	        this->S3 < Bignum(0) ||
-	        this->challenge < Bignum(0) ||
-	        this->challenge > (Bignum(2).pow(COMMITMENT_EQUALITY_CHALLENGE_SIZE) - Bignum(1))) {
+	        this->S1 < CBigNum(0) ||
+	        this->S2 < CBigNum(0) ||
+	        this->S3 < CBigNum(0) ||
+	        this->challenge < CBigNum(0) ||
+	        this->challenge > (CBigNum(2).pow(COMMITMENT_EQUALITY_CHALLENGE_SIZE) - CBigNum(1))) {
 		// Invalid inputs. Reject.
 		return false;
 	}
 
 	// Compute T1 = g1^S1 * h1^S2 * inverse(A^{challenge}) mod p1
-	Bignum T1 = A.pow_mod(this->challenge, ap->modulus).inverse(ap->modulus).mul_mod(
+	CBigNum T1 = A.pow_mod(this->challenge, ap->modulus).inverse(ap->modulus).mul_mod(
 	                (ap->g.pow_mod(S1, ap->modulus).mul_mod(ap->h.pow_mod(S2, ap->modulus), ap->modulus)),
 	                ap->modulus);
 
 	// Compute T2 = g2^S1 * h2^S3 * inverse(B^{challenge}) mod p2
-	Bignum T2 = B.pow_mod(this->challenge, bp->modulus).inverse(bp->modulus).mul_mod(
+	CBigNum T2 = B.pow_mod(this->challenge, bp->modulus).inverse(bp->modulus).mul_mod(
 	                (bp->g.pow_mod(S1, bp->modulus).mul_mod(bp->h.pow_mod(S3, bp->modulus), bp->modulus)),
 	                bp->modulus);
 
 	// Hash T1 and T2 along with all of the public parameters
-	Bignum computedChallenge = calculateChallenge(A, B, T1, T2);
+	CBigNum computedChallenge = calculateChallenge(A, B, T1, T2);
 
 	// Return success if the computed challenge matches the incoming challenge
 	if(computedChallenge == this->challenge) {
@@ -138,7 +128,7 @@ bool CommitmentProofOfKnowledge::Verify(const Bignum& A, const Bignum& B) const
 	return false;
 }
 
-const Bignum CommitmentProofOfKnowledge::calculateChallenge(const Bignum& a, const Bignum& b, const Bignum &commitOne, const Bignum &commitTwo) const {
+const CBigNum CommitmentProofOfKnowledge::calculateChallenge(const CBigNum& a, const CBigNum& b, const CBigNum &commitOne, const CBigNum &commitTwo) const {
 	CHashWriter hasher(0,0);
 
 	// Hash together the following elements:
@@ -163,10 +153,10 @@ const Bignum CommitmentProofOfKnowledge::calculateChallenge(const Bignum& a, con
 	hasher << std::string("||");
 	hasher << *(this->bp);
 
-	// Convert the SHA256 result into a Bignum
+	// Convert the SHA256 result into a CBigNum
 	// Note that if we ever change the size of the hash function we will have
 	// to update COMMITMENT_EQUALITY_CHALLENGE_SIZE appropriately!
-	return Bignum(hasher.GetHash());
+	return CBigNum(hasher.GetHash());
 }
 
 } /* namespace libzerocoin */

+ 11 - 21
ecoin/src/zerocoin/Commitment.h

@@ -1,14 +1,4 @@
-/**
- * @file       Commitment.h
- *
- * @brief      Commitment and CommitmentProof classes for the Zerocoin library.
- *
- * @author     Ian Miers, Christina Garman and Matthew Green
- * @date       June 2013
- *
- * @copyright  Copyright 2013 Ian Miers, Christina Garman and Matthew Green
- * @license    This project is released under the MIT license.
- **/
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #ifndef COMMITMENT_H_
 #define COMMITMENT_H_
@@ -36,15 +26,15 @@ public:
 	 * @param p the group parameters for the coin
 	 * @param value the value to commit to
 	 */
-	Commitment(const IntegerGroupParams* p, const Bignum& value);
-	const Bignum& getCommitmentValue() const;
-	const Bignum& getRandomness() const;
-	const Bignum& getContents() const;
+	Commitment(const IntegerGroupParams* p, const CBigNum& value);
+	const CBigNum& getCommitmentValue() const;
+	const CBigNum& getRandomness() const;
+	const CBigNum& getContents() const;
 private:
 	const IntegerGroupParams *params;
-	Bignum commitmentValue;
-	Bignum randomness;
-	const Bignum contents;
+	CBigNum commitmentValue;
+	CBigNum randomness;
+	const CBigNum contents;
 	IMPLEMENT_SERIALIZE
 	(
 	    READWRITE(commitmentValue);
@@ -75,7 +65,7 @@ public:
 		strm >> *this;
 	}
 
-	const Bignum calculateChallenge(const Bignum& a, const Bignum& b, const Bignum &commitOne, const Bignum &commitTwo) const;
+	const CBigNum calculateChallenge(const CBigNum& a, const CBigNum& b, const CBigNum &commitOne, const CBigNum &commitTwo) const;
 
 	/**Verifies the proof
 	 *
@@ -87,7 +77,7 @@ public:
 	 * @param B value of commitment two
 	 * @return
 	 */
-	bool Verify(const Bignum& A, const Bignum& B) const;
+	bool Verify(const CBigNum& A, const CBigNum& B) const;
 	IMPLEMENT_SERIALIZE
 	(
 	    READWRITE(S1);
@@ -98,7 +88,7 @@ public:
 private:
 	const IntegerGroupParams *ap, *bp;
 
-	Bignum S1, S2, S3, challenge;
+	CBigNum S1, S2, S3, challenge;
 };
 
 } /* namespace libzerocoin */

+ 63 - 93
ecoin/src/zerocoin/ParamGeneration.cpp

@@ -1,14 +1,4 @@
-// ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
-/// \file       ParamGeneration.cpp
-///
-/// \brief      Parameter manipulation routines for the Zerocoin cryptographic
-///             components.
-///
-/// \author     Ian Miers, Christina Garman and Matthew Green
-/// \date       June 2013
-///
-/// \copyright  Copyright 2013 Ian Miers, Christina Garman and Matthew Green
-/// \license    This project is released under the MIT license.
+// ECOin - Copyright (c) - 2014/2022 - GPLv3 - epsylon@riseup.net (https://03c8.net)
 
 #include <string>
 #include "Zerocoin.h"
@@ -17,26 +7,8 @@ using namespace std;
 
 namespace libzerocoin {
 
-/// \brief Fill in a set of Zerocoin parameters from a modulus "N".
-/// \param N                A trusted RSA modulus
-/// \param aux              An optional auxiliary string used in derivation
-/// \param securityLevel    A security level
-///
-/// \throws         ZerocoinException if the process fails
-///
-/// Fills in a ZC_Params data structure deterministically from
-/// a trustworthy RSA modulus "N", which is provided as a Bignum.
-///
-/// Note: this routine makes the fundamental assumption that "N"
-/// encodes a valid RSA-style modulus of the form "e1*e2" for some
-/// unknown safe primes "e1" and "e2". These factors must not
-/// be known to any party, or the security of Zerocoin is
-/// compromised. The integer "N" must be a MINIMUM of 1023
-/// in length, and 3072 bits is strongly recommended.
-///
-
 void
-CalculateParams(Params &params, Bignum N, string aux, uint32_t securityLevel)
+CalculateParams(Params &params, CBigNum N, string aux, uint32_t securityLevel)
 {
 	params.initialized = false;
 	params.accumulatorParams.initialized = false;
@@ -85,25 +57,25 @@ CalculateParams(Params &params, Bignum N, string aux, uint32_t securityLevel)
 	uint32_t resultCtr;
 	params.accumulatorParams.accumulatorQRNCommitmentGroup.g = generateIntegerFromSeed(NLen - 1,
 	        calculateSeed(N, aux, securityLevel, STRING_QRNCOMMIT_GROUPG),
-	        &resultCtr).pow_mod(Bignum(2), N);
+	        &resultCtr).pow_mod(CBigNum(2), N);
 	params.accumulatorParams.accumulatorQRNCommitmentGroup.h = generateIntegerFromSeed(NLen - 1,
 	        calculateSeed(N, aux, securityLevel, STRING_QRNCOMMIT_GROUPG),
-	        &resultCtr).pow_mod(Bignum(2), N);
+	        &resultCtr).pow_mod(CBigNum(2), N);
 
 	// Calculate the accumulator base, which we calculate as "u = C**2 mod N"
 	// where C is an arbitrary value. In the unlikely case that "u = 1" we increment
 	// "C" and repeat.
-	Bignum constant(ACCUMULATOR_BASE_CONSTANT);
-	params.accumulatorParams.accumulatorBase = Bignum(1);
+	CBigNum constant(ACCUMULATOR_BASE_CONSTANT);
+	params.accumulatorParams.accumulatorBase = CBigNum(1);
 	for (uint32_t count = 0; count < MAX_ACCUMGEN_ATTEMPTS && params.accumulatorParams.accumulatorBase.isOne(); count++) {
-		params.accumulatorParams.accumulatorBase = constant.pow_mod(Bignum(2), params.accumulatorParams.accumulatorModulus);
+		params.accumulatorParams.accumulatorBase = constant.pow_mod(CBigNum(2), params.accumulatorParams.accumulatorModulus);
 	}
 
 	// Compute the accumulator range. The upper range is the largest possible coin commitment value.
 	// The lower range is sqrt(upper range) + 1. Since OpenSSL doesn't have
 	// a square root function we use a slightly higher approximation.
 	params.accumulatorParams.maxCoinValue = params.coinCommitmentGroup.modulus;
-	params.accumulatorParams.minCoinValue = Bignum(2).pow((params.coinCommitmentGroup.modulus.bitSize() / 2) + 3);
+	params.accumulatorParams.minCoinValue = CBigNum(2).pow((params.coinCommitmentGroup.modulus.bitSize() / 2) + 3);
 
 	// If all went well, mark params as successfully initialized.
 	params.accumulatorParams.initialized = true;
@@ -113,7 +85,7 @@ CalculateParams(Params &params, Bignum N, string aux, uint32_t securityLevel)
 }
 
 /// \brief Format a seed string by hashing several values.
-/// \param N                A Bignum
+/// \param N                A CBigNum
 /// \param aux              An auxiliary string
 /// \param securityLevel    The security level in bits
 /// \param groupName        A group description string
@@ -145,7 +117,7 @@ calculateGeneratorSeed(uint256 seed, uint256 pSeed, uint256 qSeed, string label,
 }
 
 /// \brief Format a seed string by hashing several values.
-/// \param N                A Bignum
+/// \param N                A CBigNum
 /// \param aux              An auxiliary string
 /// \param securityLevel    The security level in bits
 /// \param groupName        A group description string
@@ -154,7 +126,7 @@ calculateGeneratorSeed(uint256 seed, uint256 pSeed, uint256 qSeed, string label,
 /// Returns the hash of the value.
 
 uint256
-calculateSeed(Bignum modulus, string auxString, uint32_t securityLevel, string groupName)
+calculateSeed(CBigNum modulus, string auxString, uint32_t securityLevel, string groupName)
 {
 	CHashWriter hasher(0,0);
 	uint256     hash;
@@ -244,15 +216,15 @@ IntegerGroupParams
 deriveIntegerGroupParams(uint256 seed, uint32_t pLen, uint32_t qLen)
 {
 	IntegerGroupParams result;
-	Bignum p;
-	Bignum q;
+	CBigNum p;
+	CBigNum q;
 	uint256 pSeed, qSeed;
 
 	// Calculate "p" and "q" and "domain_parameter_seed" from the
 	// "seed" buffer above, using the procedure described in NIST
 	// FIPS 186-3, Appendix A.1.2.
-	calculateGroupModulusAndOrder(seed, pLen, qLen, &(result.modulus),
-	                              &(result.groupOrder), &pSeed, &qSeed);
+	calculateGroupModulusAndOrder(seed, pLen, qLen, result.modulus,
+	                              result.groupOrder, &pSeed, &qSeed);
 
 	// Calculate the generators "g", "h" using the process described in
 	// NIST FIPS 186-3, Appendix A.2.3. This algorithm takes ("p", "q",
@@ -268,8 +240,8 @@ deriveIntegerGroupParams(uint256 seed, uint32_t pLen, uint32_t qLen)
 	        !(result.groupOrder.isPrime()) ||                       // order is prime
 	        !((result.g.pow_mod(result.groupOrder, result.modulus)).isOne()) || // g^order mod modulus = 1
 	        !((result.h.pow_mod(result.groupOrder, result.modulus)).isOne()) || // h^order mod modulus = 1
-	        ((result.g.pow_mod(Bignum(100), result.modulus)).isOne()) ||        // g^100 mod modulus != 1
-	        ((result.h.pow_mod(Bignum(100), result.modulus)).isOne()) ||        // h^100 mod modulus != 1
+	        ((result.g.pow_mod(CBigNum(100), result.modulus)).isOne()) ||        // g^100 mod modulus != 1
+	        ((result.h.pow_mod(CBigNum(100), result.modulus)).isOne()) ||        // h^100 mod modulus != 1
 	        result.g == result.h ||                                 // g != h
 	        result.g.isOne()) {                                     // g != 1
 		// If any of the above tests fail, throw an exception
@@ -287,7 +259,7 @@ deriveIntegerGroupParams(uint256 seed, uint32_t pLen, uint32_t qLen)
 /// a field "F_p".
 
 IntegerGroupParams
-deriveIntegerGroupFromOrder(Bignum &groupOrder)
+deriveIntegerGroupFromOrder(CBigNum &groupOrder)
 {
 	IntegerGroupParams result;
 
@@ -298,7 +270,7 @@ deriveIntegerGroupFromOrder(Bignum &groupOrder)
 	// "p" is prime and i is a counter starting at 1.
 	for (uint32_t i = 1; i < NUM_SCHNORRGEN_ATTEMPTS; i++) {
 		// Set modulus equal to "groupOrder * 2 * i"
-		result.modulus = (result.groupOrder * Bignum(i*2)) + Bignum(1);
+		result.modulus = (result.groupOrder * CBigNum(i*2)) + CBigNum(1);
 
 		// Test the result for primality
 		// TODO: This is a probabilistic routine and thus not the right choice
@@ -321,8 +293,8 @@ deriveIntegerGroupFromOrder(Bignum &groupOrder)
 			        !(result.groupOrder.isPrime()) ||                       // order is prime
 			        !((result.g.pow_mod(result.groupOrder, result.modulus)).isOne()) || // g^order mod modulus = 1
 			        !((result.h.pow_mod(result.groupOrder, result.modulus)).isOne()) || // h^order mod modulus = 1
-			        ((result.g.pow_mod(Bignum(100), result.modulus)).isOne()) ||        // g^100 mod modulus != 1
-			        ((result.h.pow_mod(Bignum(100), result.modulus)).isOne()) ||        // h^100 mod modulus != 1
+			        ((result.g.pow_mod(CBigNum(100), result.modulus)).isOne()) ||        // g^100 mod modulus != 1
+			        ((result.h.pow_mod(CBigNum(100), result.modulus)).isOne()) ||        // h^100 mod modulus != 1
 			        result.g == result.h ||                                 // g != h
 			        result.g.isOne()) {                                     // g != 1
 				// If any of the above tests fail, throw an exception
@@ -350,9 +322,8 @@ deriveIntegerGroupFromOrder(Bignum &groupOrder)
 /// algorithms described in FIPS 186-3 Appendix A.1.2 to calculate
 /// primes "p" and "q".
 
-void
-calculateGroupModulusAndOrder(uint256 seed, uint32_t pLen, uint32_t qLen,
-                              Bignum *resultModulus, Bignum *resultGroupOrder,
+void calculateGroupModulusAndOrder(uint256 seed, uint32_t pLen, uint32_t qLen,
+                              CBigNum &resultModulus, CBigNum &resultGroupOrder,
                               uint256 *resultPseed, uint256 *resultQseed)
 {
 	// Verify that the seed length is >= qLen
@@ -370,60 +341,60 @@ calculateGroupModulusAndOrder(uint256 seed, uint32_t pLen, uint32_t qLen,
 	// Result is the value "resultGroupOrder", "qseed" and "qgen_counter".
 	uint256     qseed;
 	uint32_t    qgen_counter;
-	*resultGroupOrder = generateRandomPrime(qLen, seed, &qseed, &qgen_counter);
+	resultGroupOrder = generateRandomPrime(qLen, seed, &qseed, &qgen_counter);
 
 	// Using ⎡pLen / 2 + 1⎤ as the length and qseed as the input_seed, use the random prime
 	// routine to obtain p0 , pseed, and pgen_counter. We pass exceptions upward.
 	uint32_t    p0len = ceil((pLen / 2.0) + 1);
 	uint256     pseed;
 	uint32_t    pgen_counter;
-	Bignum p0 = generateRandomPrime(p0len, qseed, &pseed, &pgen_counter);
+	CBigNum p0 = generateRandomPrime(p0len, qseed, &pseed, &pgen_counter);
 
 	// Set x = 0, old_counter = pgen_counter
 	uint32_t    old_counter = pgen_counter;
 
 	// Generate a random integer "x" of pLen bits
 	uint32_t iterations;
-	Bignum x = generateIntegerFromSeed(pLen, pseed, &iterations);
+	CBigNum x = generateIntegerFromSeed(pLen, pseed, &iterations);
 	pseed += (iterations + 1);
 
 	// Set x = 2^{pLen−1} + (x mod 2^{pLen–1}).
-	Bignum powerOfTwo = Bignum(2).pow(pLen-1);
+	CBigNum powerOfTwo = CBigNum(2).pow(pLen-1);
 	x = powerOfTwo + (x % powerOfTwo);
 
 	// t = ⎡x / (2 * resultGroupOrder * p0)⎤.
 	// TODO: we don't have a ceiling function
-	Bignum t = x / (Bignum(2) * (*resultGroupOrder) * p0);
+	CBigNum t = x / (CBigNum(2) * resultGroupOrder * p0);
 
 	// Now loop until we find a valid prime "p" or we fail due to
 	// pgen_counter exceeding ((4*pLen) + old_counter).
 	for ( ; pgen_counter <= ((4*pLen) + old_counter) ; pgen_counter++) {
 		// If (2 * t * resultGroupOrder * p0 + 1) > 2^{pLen}, then
 		// t = ⎡2^{pLen−1} / (2 * resultGroupOrder * p0)⎤.
-		powerOfTwo = Bignum(2).pow(pLen);
-		Bignum prod = (Bignum(2) * t * (*resultGroupOrder) * p0) + Bignum(1);
+		powerOfTwo = CBigNum(2).pow(pLen);
+		CBigNum prod = (CBigNum(2) * t * resultGroupOrder * p0) + CBigNum(1);
 		if (prod > powerOfTwo) {
 			// TODO: implement a ceil function
-			t = Bignum(2).pow(pLen-1) / (Bignum(2) * (*resultGroupOrder) * p0);
+			t = CBigNum(2).pow(pLen-1) / (CBigNum(2) * resultGroupOrder * p0);
 		}
 
 		// Compute a candidate prime resultModulus = 2tqp0 + 1.
-		*resultModulus = (Bignum(2) * t * (*resultGroupOrder) * p0) + Bignum(1);
+		resultModulus = (CBigNum(2) * t * resultGroupOrder * p0) + CBigNum(1);
 
 		// Verify that resultModulus is prime. First generate a pseudorandom integer "a".
-		Bignum a = generateIntegerFromSeed(pLen, pseed, &iterations);
+		CBigNum a = generateIntegerFromSeed(pLen, pseed, &iterations);
 		pseed += iterations + 1;
 
 		// Set a = 2 + (a mod (resultModulus–3)).
-		a = Bignum(2) + (a % ((*resultModulus) - Bignum(3)));
+		a = CBigNum(2) + (a % (resultModulus - CBigNum(3)));
 
 		// Set z = a^{2 * t * resultGroupOrder} mod resultModulus
-		Bignum z = a.pow_mod(Bignum(2) * t * (*resultGroupOrder), (*resultModulus));
+		CBigNum z = a.pow_mod(CBigNum(2) * t * resultGroupOrder, resultModulus);
 
 		// If GCD(z–1, resultModulus) == 1 AND (z^{p0} mod resultModulus == 1)
 		// then we have found our result. Return.
-		if ((resultModulus->gcd(z - Bignum(1))).isOne() &&
-		        (z.pow_mod(p0, (*resultModulus))).isOne()) {
+		if ((resultModulus.gcd(z - CBigNum(1))).isOne() &&
+		        (z.pow_mod(p0, resultModulus)).isOne()) {
 			// Success! Return the seeds and primes.
 			*resultPseed = pseed;
 			*resultQseed = qseed;
@@ -431,7 +402,7 @@ calculateGroupModulusAndOrder(uint256 seed, uint32_t pLen, uint32_t qLen,
 		}
 
 		// This prime did not work out. Increment "t" and try again.
-		t = t + Bignum(1);
+		t = t + CBigNum(1);
 	} // loop continues until pgen_counter exceeds a limit
 
 	// We reach this point only if we exceeded our maximum iteration count.
@@ -452,10 +423,10 @@ calculateGroupModulusAndOrder(uint256 seed, uint32_t pLen, uint32_t qLen,
 /// Generates a random group generator deterministically as a function of (seed,pSeed,qSeed)
 /// Uses the algorithm described in FIPS 186-3 Appendix A.2.3.
 
-Bignum
-calculateGroupGenerator(uint256 seed, uint256 pSeed, uint256 qSeed, Bignum modulus, Bignum groupOrder, uint32_t index)
+CBigNum
+calculateGroupGenerator(uint256 seed, uint256 pSeed, uint256 qSeed, CBigNum modulus, CBigNum groupOrder, uint32_t index)
 {
-	Bignum result;
+	CBigNum result;
 
 	// Verify that 0 <= index < 256
 	if (index > 255) {
@@ -463,13 +434,13 @@ calculateGroupGenerator(uint256 seed, uint256 pSeed, uint256 qSeed, Bignum modul
 	}
 
 	// Compute e = (modulus - 1) / groupOrder
-	Bignum e = (modulus - Bignum(1)) / groupOrder;
+	CBigNum e = (modulus - CBigNum(1)) / groupOrder;
 
 	// Loop until we find a generator
 	for (uint32_t count = 1; count < MAX_GENERATOR_ATTEMPTS; count++) {
 		// hash = Hash(seed || pSeed || qSeed || “ggen” || index || count
 		uint256 hash = calculateGeneratorSeed(seed, pSeed, qSeed, "ggen", index, count);
-		Bignum W(hash);
+		CBigNum W(hash);
 
 		// Compute result = W^e mod p
 		result = W.pow_mod(e, modulus);
@@ -496,7 +467,7 @@ calculateGroupGenerator(uint256 seed, uint256 pSeed, uint256 qSeed, Bignum modul
 /// seed. Uses the Shawe-Taylor algorithm as described in FIPS 186-3
 /// Appendix C.6. This is a recursive function.
 
-Bignum
+CBigNum
 generateRandomPrime(uint32_t primeBitLen, uint256 in_seed, uint256 *out_seed,
                     uint32_t *prime_gen_counter)
 {
@@ -507,7 +478,7 @@ generateRandomPrime(uint32_t primeBitLen, uint256 in_seed, uint256 *out_seed,
 
 	// If primeBitLen < 33 bits, perform the base case.
 	if (primeBitLen < 33) {
-		Bignum result(0);
+		CBigNum result(0);
 
 		// Set prime_seed = in_seed, prime_gen_counter = 0.
 		uint256     prime_seed = in_seed;
@@ -518,7 +489,7 @@ generateRandomPrime(uint32_t primeBitLen, uint256 in_seed, uint256 *out_seed,
 
 			// Generate a pseudorandom integer "c" of length primeBitLength bits
 			uint32_t iteration_count;
-			Bignum c = generateIntegerFromSeed(primeBitLen, prime_seed, &iteration_count);
+			CBigNum c = generateIntegerFromSeed(primeBitLen, prime_seed, &iteration_count);
 #ifdef ZEROCOIN_DEBUG
 			cout << "generateRandomPrime: primeBitLen = " << primeBitLen << endl;
 			cout << "Generated c = " << c << endl;
@@ -538,7 +509,7 @@ generateRandomPrime(uint32_t primeBitLen, uint256 in_seed, uint256 *out_seed,
 			// Perform trial division on this (relatively small) integer to determine if "intc"
 			// is prime. If so, return success.
 			if (primalityTestByTrialDivision(intc)) {
-				// Return "intc" converted back into a Bignum and "prime_seed". We also updated
+				// Return "intc" converted back into a CBigNum and "prime_seed". We also updated
 				// the variable "prime_gen_counter" in previous statements.
 				result = intc;
 				*out_seed = prime_seed;
@@ -558,53 +529,53 @@ generateRandomPrime(uint32_t primeBitLen, uint256 in_seed, uint256 *out_seed,
 	else {
 		// Recurse to find a new random prime of roughly half the size
 		uint32_t newLength = ceil((double)primeBitLen / 2.0) + 1;
-		Bignum c0 = generateRandomPrime(newLength, in_seed, out_seed, prime_gen_counter);
+		CBigNum c0 = generateRandomPrime(newLength, in_seed, out_seed, prime_gen_counter);
 
 		// Generate a random integer "x" of primeBitLen bits using the output
 		// of the previous call.
 		uint32_t numIterations;
-		Bignum x = generateIntegerFromSeed(primeBitLen, *out_seed, &numIterations);
+		CBigNum x = generateIntegerFromSeed(primeBitLen, *out_seed, &numIterations);
 		(*out_seed) += numIterations + 1;
 
 		// Compute "t" = ⎡x / (2 * c0⎤
 		// TODO no Ceiling call
-		Bignum t = x / (Bignum(2) * c0);
+		CBigNum t = x / (CBigNum(2) * c0);
 
 		// Repeat the following procedure until we find a prime (or time out)
 		for (uint32_t testNum = 0; testNum < MAX_PRIMEGEN_ATTEMPTS; testNum++) {
 
 			// If ((2 * t * c0) + 1 > 2^{primeBitLen}),
 			// then t = ⎡2^{primeBitLen} – 1 / (2 * c0)⎤.
-			if ((Bignum(2) * t * c0) > (Bignum(2).pow(Bignum(primeBitLen)))) {
-				t = ((Bignum(2).pow(Bignum(primeBitLen))) - Bignum(1)) / (Bignum(2) * c0);
+			if ((CBigNum(2) * t * c0) > (CBigNum(2).pow(CBigNum(primeBitLen)))) {
+				t = ((CBigNum(2).pow(CBigNum(primeBitLen))) - CBigNum(1)) / (CBigNum(2) * c0);
 			}
 
 			// Set c = (2 * t * c0) + 1
-			Bignum c = (Bignum(2) * t * c0) + Bignum(1);
+			CBigNum c = (CBigNum(2) * t * c0) + CBigNum(1);
 
 			// Increment prime_gen_counter
 			(*prime_gen_counter)++;
 
 			// Test "c" for primality as follows:
 			// 1. First pick an integer "a" in between 2 and (c - 2)
-			Bignum a = generateIntegerFromSeed(c.bitSize(), (*out_seed), &numIterations);
-			a = Bignum(2) + (a % (c - Bignum(3)));
+			CBigNum a = generateIntegerFromSeed(c.bitSize(), (*out_seed), &numIterations);
+			a = CBigNum(2) + (a % (c - CBigNum(3)));
 			(*out_seed) += (numIterations + 1);
 
 			// 2. Compute "z" = a^{2*t} mod c
-			Bignum z = a.pow_mod(Bignum(2) * t, c);
+			CBigNum z = a.pow_mod(CBigNum(2) * t, c);
 
 			// 3. Check if "c" is prime.
 			//    Specifically, verify that gcd((z-1), c) == 1 AND (z^c0 mod c) == 1
 			// If so we return "c" as our result.
-			if (c.gcd(z - Bignum(1)).isOne() && z.pow_mod(c0, c).isOne()) {
+			if (c.gcd(z - CBigNum(1)).isOne() && z.pow_mod(c0, c).isOne()) {
 				// Return "c", out_seed and prime_gen_counter
 				// (the latter two of which were already updated)
 				return c;
 			}
 
 			// 4. If the test did not succeed, increment "t" and loop
-			t = t + Bignum(1);
+			t = t + CBigNum(1);
 		} // end of test loop
 	}
 
@@ -613,10 +584,10 @@ generateRandomPrime(uint32_t primeBitLen, uint256 in_seed, uint256 *out_seed,
 	throw ZerocoinException("Unable to generate random prime (too many tests)");
 }
 
-Bignum
+CBigNum
 generateIntegerFromSeed(uint32_t numBits, uint256 seed, uint32_t *numIterations)
 {
-	Bignum      result(0);
+	CBigNum      result(0);
 	uint32_t    iterations = ceil((double)numBits / (double)HASH_OUTPUT_BITS);
 
 #ifdef ZEROCOIN_DEBUG
@@ -627,10 +598,10 @@ generateIntegerFromSeed(uint32_t numBits, uint256 seed, uint32_t *numIterations)
 	// Loop "iterations" times filling up the value "result" with random bits
 	for (uint32_t count = 0; count < iterations; count++) {
 		// result += ( H(pseed + count) * 2^{count * p0len} )
-		result += Bignum(calculateHash(seed + count)) * Bignum(2).pow(count * HASH_OUTPUT_BITS);
+		result += CBigNum(calculateHash(seed + count)) * CBigNum(2).pow(count * HASH_OUTPUT_BITS);
 	}
 
-	result = Bignum(2).pow(numBits - 1) + (result % (Bignum(2).pow(numBits - 1)));
+	result = CBigNum(2).pow(numBits - 1) + (result % (CBigNum(2).pow(numBits - 1)));
 
 	// Return the number of iterations and the result
 	*numIterations = iterations;
@@ -646,8 +617,7 @@ generateIntegerFromSeed(uint32_t numBits, uint256 seed, uint32_t *numIterations)
 bool
 primalityTestByTrialDivision(uint32_t candidate)
 {
-	// TODO: HACK HACK WRONG WRONG
-	Bignum canBignum(candidate);
+	CBigNum canBignum(candidate);
 
 	return canBignum.isPrime();
 }

+ 0 - 0
ecoin/src/zerocoin/ParamGeneration.h


Some files were not shown because too many files changed in this diff