From dc7525f12e6531b41596da64de533005542a4c5d Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 4 Mar 2020 09:17:05 -0500 Subject: [PATCH 1/3] Untested sapling consolidation plus sietch outputs to reduce metadata leakage --- src/komodo_bitcoind.h | 1 + ...asyncrpcoperation_saplingconsolidation.cpp | 25 ++++++++++++++++--- src/wallet/rpcwallet.cpp | 3 ++- src/wallet/wallet.h | 1 + 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b89aa5c0a..b5e825a58 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -24,6 +24,7 @@ #include "komodo_defs.h" #include "script/standard.h" #include "cc/CCinclude.h" +#include "sietch.h" int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); int32_t komodo_electednotary(int32_t *numnotariesp,uint8_t *pubkey33,int32_t height,uint32_t timestamp); diff --git a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp index 26809f2b8..0d1599916 100644 --- a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp +++ b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp @@ -1,3 +1,8 @@ +// Copyright (c) 2020 The Hush developers +// TODO: Forge should add his preferred copyright line here +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + #include "assert.h" #include "boost/variant/static_visitor.hpp" #include "asyncrpcoperation_saplingconsolidation.h" @@ -11,11 +16,13 @@ #include "util.h" #include "utilmoneystr.h" #include "wallet.h" +//#include "sietch.h" CAmount fConsolidationTxFee = DEFAULT_CONSOLIDATION_FEE; bool fConsolidationMapUsed = false; const int CONSOLIDATION_EXPIRY_DELTA = 15; +extern string randomSietchZaddr(); AsyncRPCOperation_saplingconsolidation::AsyncRPCOperation_saplingconsolidation(int targetHeight) : targetHeight_(targetHeight) {} @@ -168,10 +175,22 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() { builder.SetFee(fConsolidationTxFee); - //TODO: we want at least 2 zouts and potentially Sietch - // We could split funds into 2 parts and send as 2 zouts - // or add amount=0 sietch zaddrs + // Add the actual consolidation tx builder.AddSaplingOutput(extsk.expsk.ovk, addr, amountToSend - fConsolidationTxFee); + + // Add sietch zouts + int MIN_ZOUTS = 7; + for(size_t i = 0; i < MIN_ZOUTS; i++) { + // In Privacy Zdust We Trust -- Duke + string zdust = randomSietchZaddr(); + LogPrint("zrpcunsafe", "%s: Adding sietch output", getId(), zdust); + auto zaddr = DecodePaymentAddress(zdust); + if (IsValidPaymentAddress(zaddr)) { + auto sietchZoutput = boost::get(zaddr); + int amount=0; + builder.AddSaplingOutput(extsk.expsk.ovk, sietchZoutput, amount); + } + } //CTransaction tx = builder.Build(); auto maybe_tx = builder.Build(); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 79dab0c5b..8f5688026 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -62,7 +62,7 @@ #include "komodo_defs.h" #include -#include "sietch.h" +//#include "sietch.h" #include "rpchushwallet.h" using namespace std; @@ -79,6 +79,7 @@ uint32_t komodo_segid32(char *coinaddr); int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); int32_t komodo_isnotaryvout(char *coinaddr,uint32_t tiptime); // from ac_private chains only CBlockIndex *komodo_getblockindex(uint256 hash); +extern string randomSietchZaddr(); int64_t nWalletUnlockTime; static CCriticalSection cs_nWalletUnlockTime; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 79d24a86d..6b9a1d628 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -42,6 +42,7 @@ #include "zcash/Address.hpp" #include "zcash/zip32.h" #include "base58.h" +//#include "sietch.h" #include #include From 9c72f4c2f5b9a442e6e3c1acda91c603770f3670 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 6 Mar 2020 14:40:24 -0500 Subject: [PATCH 2/3] Change consolidation fee to be the default instead of zero and require zinput arity to be inside [3,8] --- .../asyncrpcoperation_saplingconsolidation.cpp | 13 +++++++++---- src/wallet/asyncrpcoperation_saplingconsolidation.h | 11 ++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp index 0d1599916..32601e0fd 100644 --- a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp +++ b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp @@ -120,7 +120,10 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() { std::vector fromNotes; CAmount amountToSend = 0; - int maxQuantity = rand() % 35 + 10; + // max of 8 zins means the tx cannot reduce the anonset, + // since there will be 8 zins and 8 zouts at worst case + // This also helps reduce ztx creation time + int maxQuantity = rand() % 8 + 1; for (const SaplingNoteEntry& saplingEntry : saplingEntries) { libzcash::SaplingIncomingViewingKey ivk; @@ -132,14 +135,16 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() { fromNotes.push_back(saplingEntry); } - //Only use a randomly determined number of notes between 10 and 45 + //Only use a randomly determined number of notes if (fromNotes.size() >= maxQuantity) break; } - //random minimum 2 - 12 required - int minQuantity = rand() % 10 + 2; + // minimum required + // We use 3 so that addresses can spent one zutxo and still have another zutxo to use while that + // tx is confirming + int minQuantity = 3; if (fromNotes.size() < minQuantity) continue; diff --git a/src/wallet/asyncrpcoperation_saplingconsolidation.h b/src/wallet/asyncrpcoperation_saplingconsolidation.h index 8e38204c7..9a80ff7c7 100644 --- a/src/wallet/asyncrpcoperation_saplingconsolidation.h +++ b/src/wallet/asyncrpcoperation_saplingconsolidation.h @@ -1,11 +1,16 @@ +// Copyright (c) 2020 The Hush developers +// TODO: Forge should add his preferred copyright line here +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + #include "amount.h" #include "asyncrpcoperation.h" #include "univalue.h" #include "zcash/Address.hpp" #include "zcash/zip32.h" -//Default fee used for consolidation transactions -static const CAmount DEFAULT_CONSOLIDATION_FEE = 0; +//Default fee used for consolidation transactions, in puposhis +static const CAmount DEFAULT_CONSOLIDATION_FEE = 10000; extern CAmount fConsolidationTxFee; extern bool fConsolidationMapUsed; @@ -34,4 +39,4 @@ private: void setConsolidationResult(int numTxCreated, const CAmount& amountConsolidated, const std::vector& consolidationTxIds); -}; \ No newline at end of file +}; From fad66953fb037ba9e40ba29760f9de8cec8cf09f Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 6 Mar 2020 15:22:50 -0500 Subject: [PATCH 3/3] Cleanup --- src/wallet/asyncrpcoperation_saplingconsolidation.cpp | 1 - src/wallet/rpcwallet.cpp | 1 - src/wallet/wallet.h | 3 +-- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp index 32601e0fd..e85ce5861 100644 --- a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp +++ b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp @@ -16,7 +16,6 @@ #include "util.h" #include "utilmoneystr.h" #include "wallet.h" -//#include "sietch.h" CAmount fConsolidationTxFee = DEFAULT_CONSOLIDATION_FEE; bool fConsolidationMapUsed = false; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8f5688026..ea4b43a5a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -62,7 +62,6 @@ #include "komodo_defs.h" #include -//#include "sietch.h" #include "rpchushwallet.h" using namespace std; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 6b9a1d628..ea327b2d9 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2019 The Hush developers +// Copyright (c) 2019-2020 The Hush developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -42,7 +42,6 @@ #include "zcash/Address.hpp" #include "zcash/zip32.h" #include "base58.h" -//#include "sietch.h" #include #include