From 3252efc837d5bc361277d13427f5bbd5fca28a96 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Nov 2019 21:44:49 -1100 Subject: [PATCH 01/11] Mempool fix from upstream --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 264cb0643..96068a489 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1809,8 +1809,9 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return error("AcceptToMemoryPool: CheckTransaction failed"); } // DoS level set to 10 to be more forgiving. + // Check transaction contextually against the set of consensus rules which apply in the next block to be mined. - if (!fSkipExpiry && !ContextualCheckTransaction(0,0,0,tx, state, nextBlockHeight, (dosLevel == -1) ? 10 : dosLevel,0)) + if (!fSkipExpiry && !ContextualCheckTransaction(0,0,0,tx, state, nextBlockHeight, (dosLevel == -1) ? 10 : dosLevel)) { return error("AcceptToMemoryPool: ContextualCheckTransaction failed"); } From f69e3697aa25f687660e30f17b8dd881d6cb1aa2 Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Fri, 8 Nov 2019 09:16:50 -0700 Subject: [PATCH 02/11] Fix of CVE-2017-18350 Adapted from bitcoin/bitcoin#11397 by Wladimir J. van der Laan. Co-Authored-By: Jack Grigg Co-Authored-By: Daira Hopwood --- src/netbase.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/netbase.cpp b/src/netbase.cpp index 5ad6353e9..b118446b9 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -267,7 +267,7 @@ struct timeval MillisToTimeval(int64_t nTimeout) * * @note This function requires that hSocket is in non-blocking mode. */ -bool static InterruptibleRecv(char* data, size_t len, int timeout, SOCKET& hSocket) +bool static InterruptibleRecv(uint8_t* data, size_t len, int timeout, SOCKET& hSocket) { int64_t curTime = GetTimeMillis(); int64_t endTime = curTime + timeout; @@ -335,7 +335,7 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials CloseSocket(hSocket); return error("Error sending to proxy"); } - char pchRet1[2]; + uint8_t pchRet1[2]; if (!InterruptibleRecv(pchRet1, 2, SOCKS5_RECV_TIMEOUT, hSocket)) { CloseSocket(hSocket); return error("Error reading proxy response"); @@ -360,7 +360,7 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials return error("Error sending authentication to proxy"); } LogPrint("proxy", "SOCKS5 sending proxy authentication %s:%s\n", auth->username, auth->password); - char pchRetA[2]; + uint8_t pchRetA[2]; if (!InterruptibleRecv(pchRetA, 2, SOCKS5_RECV_TIMEOUT, hSocket)) { CloseSocket(hSocket); return error("Error reading proxy authentication response"); @@ -389,7 +389,7 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials CloseSocket(hSocket); return error("Error sending to proxy"); } - char pchRet2[4]; + uint8_t pchRet2[4]; if (!InterruptibleRecv(pchRet2, 4, SOCKS5_RECV_TIMEOUT, hSocket)) { CloseSocket(hSocket); return error("Error reading proxy response"); @@ -417,7 +417,7 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials CloseSocket(hSocket); return error("Error: malformed proxy response"); } - char pchRet3[256]; + uint8_t pchRet3[256]; switch (pchRet2[3]) { case 0x01: ret = InterruptibleRecv(pchRet3, 4, SOCKS5_RECV_TIMEOUT, hSocket); break; @@ -429,7 +429,7 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials CloseSocket(hSocket); return error("Error reading from proxy"); } - int nRecv = pchRet3[0]; + size_t nRecv = pchRet3[0]; ret = InterruptibleRecv(pchRet3, nRecv, SOCKS5_RECV_TIMEOUT, hSocket); break; } From f3d06aa5995c413d46c2ea856ee134576f1d4dd8 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 13 Nov 2019 18:38:49 -0800 Subject: [PATCH 03/11] mostly port travis.yml to hush, api keys are not correct yet --- .travis.yml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index d7291e03e..74ebd6b0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ branches: only: - master - dev - - cctests + - duke compiler: - gcc before_install: @@ -24,14 +24,14 @@ before_install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew link --overwrite gcc@6; fi script: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./zcutil/build.sh -j 5; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar cvfz komodo_linux_$TRAVIS_BRANCH.tar.gz src/komodod src/komodo-cli; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar cvfz hush_linux_$TRAVIS_BRANCH.tar.gz src/komodod src/komodo-cli src/komodo-tx src/hushd src/hush-cli src/hush-tx; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./zcutil/build-mac.sh -j 5; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./makeRelease.sh; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then tar cvfz komodo_osx_$TRAVIS_BRANCH.tar.gz src/komodod src/komodo-cli src/libgcc_s.1.dylib src/libgomp.1.dylib src/libstdc++.6.dylib; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then tar cvfz hush_osx_$TRAVIS_BRANCH.tar.gz src/komodod src/komodo-cli src/libgcc_s.1.dylib src/libgomp.1.dylib src/libstdc++.6.dylib; fi notifications: irc: channels: - - chat.freenode.net#komodoplatform + - chat.freenode.net#hush template: - "%{repository}/%{branch} (%{commit} - %{author}): %{message}" - 'Alt Message : %{repository_slug} - (%{commit} - %{author}): %{message}, Build @@ -45,44 +45,44 @@ deploy: - provider: releases api_key: secure: id69KBVsY0p41WFlqd5cGrAIksJAkUempmdrQwHtfqIbB6es7MVfXuxfmTxk7lZNEItSvLGilYtqhBMNVAVjRRPvk90hveGDMkbpjFz3XBbFEFqtrAr2GdIcpGtII2T3T/TG7j11TMtJ6GvBVt4OcatHFVsKBCFDIx0fB0fd1oLrEAwgRdBO2Jq7bMzoLdzGx3mVtdW5dSRBQzG/Z0yvx+R9mQHSvyPGh6oNPD6mvXPzEaCeRW6Y8g8y1SW/6zDJR6sSdOKA0jsHkr/hM8st3Qkr5Cu3roEbL8598uvfBahjxVHVT8+lu/nJnQyrvtWZKu/uUefybqgZl7UpGvZVFxbNwAB/ZNn0pBKIpZlX/kh6rdGF0XrAG7g+Ths6iklh7wDefYP2JeGwHWJ38YcdF8T/VcSdOXz7EiWwEeZO5sGcTRSl5Ql8mcU3YyyB7BTdViYNTHf5VFFJ/baLZG+shZ/0tb1Ntx5mLDbV8vcYXJpUNTJcXbhcUDSF3QuSz04ftkzgpcsODzcTzD6+2sezV1vlOAlxK04C+zzxG96Md/TegvZYYns78RSgrP/UH1qwEbgxTo3xpErGllzntzZfHJ887Goez+DeB9ga7pUBc5AXGpfRhYqJP66wR10zqfWuWYvjAwRBRNySjr3pUvaA3T1iSZ5HLrpKBfcHXJOTg8M= - name: komodo_linux-$TRAVIS_BRANCH + name: hush_linux-$TRAVIS_BRANCH prerelease: true - file: komodo_linux_$TRAVIS_BRANCH.tar.gz + file: hush_linux_$TRAVIS_BRANCH.tar.gz skip_cleanup: true on: - repo: KomodoPlatform/komodo + repo: MyHush/hush3 branch: master condition: $LINUX_DEPLOY = "true" - provider: releases api_key: secure: id69KBVsY0p41WFlqd5cGrAIksJAkUempmdrQwHtfqIbB6es7MVfXuxfmTxk7lZNEItSvLGilYtqhBMNVAVjRRPvk90hveGDMkbpjFz3XBbFEFqtrAr2GdIcpGtII2T3T/TG7j11TMtJ6GvBVt4OcatHFVsKBCFDIx0fB0fd1oLrEAwgRdBO2Jq7bMzoLdzGx3mVtdW5dSRBQzG/Z0yvx+R9mQHSvyPGh6oNPD6mvXPzEaCeRW6Y8g8y1SW/6zDJR6sSdOKA0jsHkr/hM8st3Qkr5Cu3roEbL8598uvfBahjxVHVT8+lu/nJnQyrvtWZKu/uUefybqgZl7UpGvZVFxbNwAB/ZNn0pBKIpZlX/kh6rdGF0XrAG7g+Ths6iklh7wDefYP2JeGwHWJ38YcdF8T/VcSdOXz7EiWwEeZO5sGcTRSl5Ql8mcU3YyyB7BTdViYNTHf5VFFJ/baLZG+shZ/0tb1Ntx5mLDbV8vcYXJpUNTJcXbhcUDSF3QuSz04ftkzgpcsODzcTzD6+2sezV1vlOAlxK04C+zzxG96Md/TegvZYYns78RSgrP/UH1qwEbgxTo3xpErGllzntzZfHJ887Goez+DeB9ga7pUBc5AXGpfRhYqJP66wR10zqfWuWYvjAwRBRNySjr3pUvaA3T1iSZ5HLrpKBfcHXJOTg8M= - name: komodo_linux-$TRAVIS_BRANCH + name: hush_linux-$TRAVIS_BRANCH prerelease: true - file: komodo_linux_$TRAVIS_BRANCH.tar.gz + file: hush_linux_$TRAVIS_BRANCH.tar.gz skip_cleanup: true on: - repo: KomodoPlatform/komodo + repo: MyHush/hush3 branch: dev condition: $LINUX_DEPLOY = "true" - provider: releases api_key: secure: id69KBVsY0p41WFlqd5cGrAIksJAkUempmdrQwHtfqIbB6es7MVfXuxfmTxk7lZNEItSvLGilYtqhBMNVAVjRRPvk90hveGDMkbpjFz3XBbFEFqtrAr2GdIcpGtII2T3T/TG7j11TMtJ6GvBVt4OcatHFVsKBCFDIx0fB0fd1oLrEAwgRdBO2Jq7bMzoLdzGx3mVtdW5dSRBQzG/Z0yvx+R9mQHSvyPGh6oNPD6mvXPzEaCeRW6Y8g8y1SW/6zDJR6sSdOKA0jsHkr/hM8st3Qkr5Cu3roEbL8598uvfBahjxVHVT8+lu/nJnQyrvtWZKu/uUefybqgZl7UpGvZVFxbNwAB/ZNn0pBKIpZlX/kh6rdGF0XrAG7g+Ths6iklh7wDefYP2JeGwHWJ38YcdF8T/VcSdOXz7EiWwEeZO5sGcTRSl5Ql8mcU3YyyB7BTdViYNTHf5VFFJ/baLZG+shZ/0tb1Ntx5mLDbV8vcYXJpUNTJcXbhcUDSF3QuSz04ftkzgpcsODzcTzD6+2sezV1vlOAlxK04C+zzxG96Md/TegvZYYns78RSgrP/UH1qwEbgxTo3xpErGllzntzZfHJ887Goez+DeB9ga7pUBc5AXGpfRhYqJP66wR10zqfWuWYvjAwRBRNySjr3pUvaA3T1iSZ5HLrpKBfcHXJOTg8M= - name: komodo_osx-$TRAVIS_BRANCH + name: hush_osx-$TRAVIS_BRANCH prerelease: true - file: komodo_osx_$TRAVIS_BRANCH.tar.gz + file: hush_osx_$TRAVIS_BRANCH.tar.gz skip_cleanup: true on: - repo: KomodoPlatform/komodo + repo: MyHush/hush3 branch: master condition: $OSX_DEPLOY = "true" - provider: releases api_key: secure: id69KBVsY0p41WFlqd5cGrAIksJAkUempmdrQwHtfqIbB6es7MVfXuxfmTxk7lZNEItSvLGilYtqhBMNVAVjRRPvk90hveGDMkbpjFz3XBbFEFqtrAr2GdIcpGtII2T3T/TG7j11TMtJ6GvBVt4OcatHFVsKBCFDIx0fB0fd1oLrEAwgRdBO2Jq7bMzoLdzGx3mVtdW5dSRBQzG/Z0yvx+R9mQHSvyPGh6oNPD6mvXPzEaCeRW6Y8g8y1SW/6zDJR6sSdOKA0jsHkr/hM8st3Qkr5Cu3roEbL8598uvfBahjxVHVT8+lu/nJnQyrvtWZKu/uUefybqgZl7UpGvZVFxbNwAB/ZNn0pBKIpZlX/kh6rdGF0XrAG7g+Ths6iklh7wDefYP2JeGwHWJ38YcdF8T/VcSdOXz7EiWwEeZO5sGcTRSl5Ql8mcU3YyyB7BTdViYNTHf5VFFJ/baLZG+shZ/0tb1Ntx5mLDbV8vcYXJpUNTJcXbhcUDSF3QuSz04ftkzgpcsODzcTzD6+2sezV1vlOAlxK04C+zzxG96Md/TegvZYYns78RSgrP/UH1qwEbgxTo3xpErGllzntzZfHJ887Goez+DeB9ga7pUBc5AXGpfRhYqJP66wR10zqfWuWYvjAwRBRNySjr3pUvaA3T1iSZ5HLrpKBfcHXJOTg8M= - name: komodo_osx-$TRAVIS_BRANCH + name: hush_osx-$TRAVIS_BRANCH prerelease: true - file: komodo_osx_$TRAVIS_BRANCH.tar.gz + file: hush_osx_$TRAVIS_BRANCH.tar.gz skip_cleanup: true on: - repo: KomodoPlatform/komodo + repo: MyHush/hush3 branch: dev condition: $OSX_DEPLOY = "true" From 71d9e4beceb3233f85346dd338e4740791b7df54 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 10 Nov 2019 13:27:58 +0100 Subject: [PATCH 04/11] fix WIN build --- src/netbase.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/netbase.cpp b/src/netbase.cpp index b118446b9..fa8b80435 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -275,7 +275,11 @@ bool static InterruptibleRecv(uint8_t* data, size_t len, int timeout, SOCKET& hS // to break off in case of an interruption. const int64_t maxWait = 1000; while (len > 0 && curTime < endTime) { +#ifdef _WIN32 + ssize_t ret = recv(hSocket, (char*)data, len, 0); // Optimistically try the recv first +#else ssize_t ret = recv(hSocket, data, len, 0); // Optimistically try the recv first +#endif if (ret > 0) { len -= ret; data += ret; From f0cb8ba145067f296a8e93a92e2602fdc7b39fc3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Nov 2019 07:10:31 -1100 Subject: [PATCH 05/11] +debug --- src/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 96068a489..04ab8e670 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1195,6 +1195,10 @@ bool ContextualCheckTransaction(int32_t slowflag,const CBlock *block, CBlockInde if (tx.fOverwintered && tx.nVersionGroupId != SAPLING_VERSION_GROUP_ID) { //return state.DoS(dosLevel, error("CheckTransaction(): invalid Sapling tx version"),REJECT_INVALID, "bad-sapling-tx-version-group-id"); + { + string strHex = EncodeHexTx(tx); + fprintf(stderr,"invalid Sapling rawtx.%s\n",strHex.c_str()); + } return state.DoS(isInitBlockDownload() ? 0 : dosLevel, error("CheckTransaction(): invalid Sapling tx version"), REJECT_INVALID, "bad-sapling-tx-version-group-id"); From a40f0b0f19d281a3c189875781e50c90a3b61e5c Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 14 Nov 2019 14:26:31 -0800 Subject: [PATCH 06/11] Delete sprout code from HaveJoinSplitRequirements and log reasons for failing reqs to stderr --- src/coins.cpp | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index eac89c030..167120bbd 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -622,41 +622,14 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr bool CCoinsViewCache::HaveJoinSplitRequirements(const CTransaction& tx) const { - boost::unordered_map intermediates; - - BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) - { - BOOST_FOREACH(const uint256& nullifier, joinsplit.nullifiers) - { - if (GetNullifier(nullifier, SPROUT)) { - // If the nullifier is set, this transaction - // double-spends! - return false; - } - } - - SproutMerkleTree tree; - auto it = intermediates.find(joinsplit.anchor); - if (it != intermediates.end()) { - tree = it->second; - } else if (!GetSproutAnchorAt(joinsplit.anchor, tree)) { - return false; - } - - BOOST_FOREACH(const uint256& commitment, joinsplit.commitments) - { - tree.append(commitment); - } - - intermediates.insert(std::make_pair(tree.root(), tree)); - } - for (const SpendDescription &spendDescription : tx.vShieldedSpend) { if (GetNullifier(spendDescription.nullifier, SAPLING)) // Prevent double spends + fprintf(stderr,"%s: sapling nullifier %s exists, preventing double spend\n", __FUNCTION__, spendDescription.nullifier); return false; SaplingMerkleTree tree; if (!GetSaplingAnchorAt(spendDescription.anchor, tree)) { + fprintf(stderr,"%s: missing sapling anchor: %s \n", __FUNCTION__, spendDescription.anchor); return false; } } From f3247b7209743feab31df18a64810594d9a2b65b Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 14 Nov 2019 15:52:01 -0800 Subject: [PATCH 07/11] remove some sprout code --- src/coins.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 167120bbd..3405e63f3 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -333,13 +333,6 @@ void CCoinsViewCache::PopAnchor(const uint256 &newrt, ShieldedType type) { } void CCoinsViewCache::SetNullifiers(const CTransaction& tx, bool spent) { - for (const JSDescription &joinsplit : tx.vjoinsplit) { - for (const uint256 &nullifier : joinsplit.nullifiers) { - std::pair ret = cacheSproutNullifiers.insert(std::make_pair(nullifier, CNullifiersCacheEntry())); - ret.first->second.entered = spent; - ret.first->second.flags |= CNullifiersCacheEntry::DIRTY; - } - } for (const SpendDescription &spendDescription : tx.vShieldedSpend) { std::pair ret = cacheSaplingNullifiers.insert(std::make_pair(spendDescription.nullifier, CNullifiersCacheEntry())); ret.first->second.entered = spent; From cc88d26b5711754b09e457ff3ea829d016962dc7 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 18 Nov 2019 04:48:34 -0800 Subject: [PATCH 08/11] add hush:// URI protocol handler for windows --- contrib/hush-uri.bat | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 contrib/hush-uri.bat diff --git a/contrib/hush-uri.bat b/contrib/hush-uri.bat new file mode 100644 index 000000000..8e6ac1dee --- /dev/null +++ b/contrib/hush-uri.bat @@ -0,0 +1,46 @@ +@Echo On +Title Reg Converter v1.1 & Color 1A +REM ~ call :IsAdmin + +call :RegExport +Exit + +:RegExport +Set RegFile="%Temp%\~etsaclu.tmp" + +Set "pirate=%~dp0" +set "pirate=%pirate:\=\\%" + +If Exist %RegFile% ( + Attrib -R -S -H %RegFile% & Del /F /Q %RegFile% + If Exist %RegFile% cls & Echo Could not delete file %RegFile% & Pause +) +> %RegFile% Echo Windows Registry Editor Version 5.00 +>> %RegFile% Echo. +>> %RegFile% Echo [HKEY_CLASSES_ROOT\hush] +>> %RegFile% Echo @="URL:hush protocol" +>> %RegFile% Echo "URL Protocol"="" +>> %RegFile% Echo. +>> %RegFile% Echo [HKEY_CLASSES_ROOT\hush\DefaultIcon] +>> %RegFile% Echo @="sevenseas.exe" +>> %RegFile% Echo. +>> %RegFile% Echo [HKEY_CLASSES_ROOT\hush\Shell] +>> %RegFile% Echo. +>> %RegFile% Echo [HKEY_CLASSES_ROOT\hush\Shell\Open] +>> %RegFile% Echo. +>> %RegFile% Echo [HKEY_CLASSES_ROOT\hush\Shell\Open\Command] +>> %RegFile% Echo @="%hush%silentdragon.exe \"%%1\"" + +Start /Wait %systemroot%\Regedit.exe /S %RegFile% +Del %RegFile% +goto:eof + +:IsAdmin +Reg.exe query "HKU\S-1-5-19\Environment" +If Not %ERRORLEVEL% EQU 0 ( + Cls & Echo You must have administrator rights to continue ... + Pause & Exit +) +Cls +goto:eof + From 4d70123bf1bff148a040f4816445c53438ffe508 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 18 Nov 2019 04:56:36 -0800 Subject: [PATCH 09/11] Update hush-uri.bat --- contrib/hush-uri.bat | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/hush-uri.bat b/contrib/hush-uri.bat index 8e6ac1dee..08f4bc1ef 100644 --- a/contrib/hush-uri.bat +++ b/contrib/hush-uri.bat @@ -8,8 +8,8 @@ Exit :RegExport Set RegFile="%Temp%\~etsaclu.tmp" -Set "pirate=%~dp0" -set "pirate=%pirate:\=\\%" +Set "hush=%~dp0" +set "hush=%hush:\=\\%" If Exist %RegFile% ( Attrib -R -S -H %RegFile% & Del /F /Q %RegFile% @@ -22,7 +22,7 @@ If Exist %RegFile% ( >> %RegFile% Echo "URL Protocol"="" >> %RegFile% Echo. >> %RegFile% Echo [HKEY_CLASSES_ROOT\hush\DefaultIcon] ->> %RegFile% Echo @="sevenseas.exe" +>> %RegFile% Echo @="silentdragon.exe" >> %RegFile% Echo. >> %RegFile% Echo [HKEY_CLASSES_ROOT\hush\Shell] >> %RegFile% Echo. From 3544f56d53816a690729b60f791740df4eb57c70 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 21 Nov 2019 07:57:24 -0800 Subject: [PATCH 10/11] Verify file sizes of sapling params and try to support running inside a .dmg --- src/init.cpp | 98 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 68 insertions(+), 30 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index e1cf892c6..9b65b0b3e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -776,14 +776,23 @@ bool InitSanityCheck(void) void NoParamsShutdown(void) { - //TODO: error message incorrect about location - fprintf(stderr,"%s: no params!\n", __FUNCTION__); - LogPrintf("Could not find Sapling params anywhere! Exiting..."); + fprintf(stderr,"%s: no params!\n", __FUNCTION__); + LogPrintf("Could not find valid Sapling params anywhere! Exiting..."); uiInterface.ThreadSafeMessageBox(strprintf( - _("Cannot find the Sapling network parameters in the following directory:\n" - "%s\n" - "Please run join our Discord for help: https://myhush.org/discord/"), - ZC_GetParamsDir()), + _("Cannot find the Sapling network parameters! Something is very wrong.\n" + "Please join our Discord for help: https://myhush.org/discord/")), + "", CClientUIInterface::MSG_ERROR); + StartShutdown(); + return; +} + +void CorruptParamsShutdown(void) +{ + fprintf(stderr,"%s: corrupt params!\n", __FUNCTION__); + LogPrintf("We detected corrupt Sapling params! Exiting..."); + uiInterface.ThreadSafeMessageBox(strprintf( + _("Corrupt Sapling network parameters were detected! Something is very wrong.\n" + "Please join our Discord for help: https://myhush.org/discord/")), "", CClientUIInterface::MSG_ERROR); StartShutdown(); return; @@ -802,16 +811,19 @@ static void ZC_LoadParams( float elapsed; bool found = false; - // Some people have previous partial downloads of zcash params, so check that last - // Sapling Param Search path: . /usr/share/hush .. ../hush3 ~/.zcash-params + // Some people have previous partial downloads of zcash params, so check that last + // Sapling Param Search path: . /usr/share/hush .. ../hush3 ./Contents/MacOS/ ~/.zcash-params + + LogPrintf("Looking for sapling params..."); + gettimeofday(&tv_start, 0); // PWD - boost::filesystem::path sapling_spend = "sapling-spend.params"; - boost::filesystem::path sapling_output = "sapling-output.params"; - if (files_exist(sapling_spend, sapling_output)) { - fprintf(stderr,"Found sapling params in .\n"); + boost::filesystem::path sapling_spend = "sapling-spend.params"; + boost::filesystem::path sapling_output = "sapling-output.params"; + if (files_exist(sapling_spend, sapling_output)) { + fprintf(stderr,"Found sapling params in .\n"); found = true; - } + } if (!found) { // Debian global install dir: /usr/share/hush @@ -825,33 +837,43 @@ static void ZC_LoadParams( if (!found) { // Try .. - sapling_spend = boost::filesystem::path("..") / "sapling-spend.params"; + sapling_spend = boost::filesystem::path("..") / "sapling-spend.params"; sapling_output = boost::filesystem::path("..") / "sapling-output.params"; - if (files_exist(sapling_spend, sapling_output)) { + if (files_exist(sapling_spend, sapling_output)) { fprintf(stderr,"Found sapling params in ..\n"); found = true; - } + } } if (!found) { // This will catch the case of any external software (i.e. GUI wallets) needing params and installed in same dir as hush3.git - sapling_spend = boost::filesystem::path("..") / "hush3" / "sapling-spend.params"; + sapling_spend = boost::filesystem::path("..") / "hush3" / "sapling-spend.params"; sapling_output = boost::filesystem::path("..") / "hush3" / "sapling-output.params"; - if (files_exist(sapling_spend, sapling_output)) { + if (files_exist(sapling_spend, sapling_output)) { fprintf(stderr,"Found sapling params in ../hush3\n"); found = true; - } + } + } + + if (!found) { + // DMG Support: Apple just has to do things differently... + sapling_spend = boost::filesystem::path("Contents/MacOS") / "hush3" / "sapling-spend.params"; + sapling_output = boost::filesystem::path("Contents/MacOS") / "hush3" / "sapling-output.params"; + if (files_exist(sapling_spend, sapling_output)) { + fprintf(stderr,"Found sapling params in ../Contents/MacOS\n"); + found = true; + } } if (!found) { // The traditional place Zcash params are stored, should not hit this case in normal circumstances, // as Hush packages sapling params now - sapling_spend = ZC_GetParamsDir() / "sapling-spend.params"; + sapling_spend = ZC_GetParamsDir() / "sapling-spend.params"; sapling_output = ZC_GetParamsDir() / "sapling-output.params"; - if (files_exist(sapling_spend, sapling_output)) { + if (files_exist(sapling_spend, sapling_output)) { fprintf(stderr,"Found sapling params in ~/.zcash\n"); found = true; - } + } } if (!found) { @@ -860,20 +882,36 @@ static void ZC_LoadParams( return; } + boost::system::error_code ec1, ec2; + boost::uintmax_t spend_size = file_size(sapling_spend, ec1); + boost::uintmax_t output_size = file_size(sapling_output, ec2); + fprintf(stderr,"Sapling spend: %d bytes, output: %d bytes\n", spend_size, output_size); + // We could check sha hashes, but we mostly want to detect on-disk file corruption + // or people having a full harddrive. Full validation happens in librustzcash_init_zksnark_params + // This prevents users seeing very low-level errors from that routine + boost::uintmax_t spend_valid = 47958396; + boost::uintmax_t output_valid = 3592860; + //TODO: passing the exact reason for corruption to GUI + if (spend_size != spend_valid) { + fprintf(stderr,"Sapling spend %d bytes != %d is invalid!\n", spend_size, spend_valid); + CorruptParamsShutdown(); + return; + } - //LogPrintf("Loading verifying key from %s\n", vk_path.string().c_str()); - gettimeofday(&tv_start, 0); - - //pzcashParams = ZCJoinSplit::Prepared(vk_path.string(), pk_path.string()); + if (output_size != output_valid) { + fprintf(stderr,"Sapling ouput %d bytes != %d is invalid!\n", output_size, output_valid); + CorruptParamsShutdown(); + return; + } gettimeofday(&tv_end, 0); elapsed = float(tv_end.tv_sec-tv_start.tv_sec) + (tv_end.tv_usec-tv_start.tv_usec)/float(1000000); - LogPrintf("Loaded verifying key in %fs seconds.\n", elapsed); + LogPrintf("Found sapling param in %fs seconds.\n", elapsed); static_assert( sizeof(boost::filesystem::path::value_type) == sizeof(codeunit), "librustzcash not configured correctly"); - auto sapling_spend_str = sapling_spend.native(); + auto sapling_spend_str = sapling_spend.native(); auto sapling_output_str = sapling_output.native(); LogPrintf("Loading Sapling (Spend) parameters from %s\n", sapling_spend.string().c_str()); @@ -887,7 +925,7 @@ static void ZC_LoadParams( reinterpret_cast(sapling_output_str.c_str()), sapling_output_str.length(), "657e3d38dbb5cb5e7dd2970e8b03d69b4787dd907285b5a7f0790dcc8072f60bf593b32cc2d1c030e00ff5ae64bf84c5c3beb84ddc841d48264b4a171744d028", - // These are dummy arguments, ignored by Hush-flavored librustzcash + // These are dummy arguments, ignored by Hush-flavored librustzcash reinterpret_cast(sapling_output_str.c_str()), sapling_output_str.length(), "657e3d38dbb5cb5e7dd2970e8b03d69b4787dd907285b5a7f0790dcc8072f60bf593b32cc2d1c030e00ff5ae64bf84c5c3beb84ddc841d48264b4a171744d028" From 0f5e636fa8608c7710602aa1c762fde4d77d9060 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 22 Nov 2019 08:03:46 -0800 Subject: [PATCH 11/11] For the want of parens consensus was lost --- src/coins.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/coins.cpp b/src/coins.cpp index 3405e63f3..20875c9ae 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2012-2014 The Bitcoin Core developers +// Copyright (c) 2019 The Hush developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -616,9 +617,10 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr bool CCoinsViewCache::HaveJoinSplitRequirements(const CTransaction& tx) const { for (const SpendDescription &spendDescription : tx.vShieldedSpend) { - if (GetNullifier(spendDescription.nullifier, SAPLING)) // Prevent double spends + if (GetNullifier(spendDescription.nullifier, SAPLING)) { // Prevent double spends fprintf(stderr,"%s: sapling nullifier %s exists, preventing double spend\n", __FUNCTION__, spendDescription.nullifier); return false; + } SaplingMerkleTree tree; if (!GetSaplingAnchorAt(spendDescription.anchor, tree)) {