Browse Source

Dynamic generation of zaddrs not stored in wallet

These zaddrs can be created via:

    z_getnewaddress donotremember

and return a zaddr like normal usage, but without storing it's extended
spending key in wallet.dat. This will be utilized by Sietch to generate
dynamic zdust for every shielded transaction, preventing attacks related
to having chain-wide fixed pools of zdust.
pull/141/head
Duke Leto 5 years ago
parent
commit
c58fef0d01
  1. 2
      src/init.cpp
  2. 23
      src/wallet/rpcwallet.cpp
  3. 6
      src/wallet/wallet.cpp
  4. 5
      src/wallet/wallet.h

2
src/init.cpp

@ -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.

23
src/wallet/rpcwallet.cpp

@ -70,8 +70,8 @@ using namespace libzcash;
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
extern std::string ASSETCHAINS_OVERRIDE_PUBKEY;
const std::string ADDR_TYPE_SPROUT = "sprout";
const std::string ADDR_TYPE_SAPLING = "sapling";
const std::string ADDR_TYPE_SAPLING = "sapling";
const std::string ADDR_TYPE_DONOTREMEMBER = "donotremember";
extern UniValue TxJoinSplitToJSON(const CTransaction& tx);
extern int32_t KOMODO_INSYNC;
uint32_t komodo_segid32(char *coinaddr);
@ -3716,15 +3716,16 @@ UniValue z_getnewaddress(const UniValue& params, bool fHelp, const CPubKey& mypk
throw runtime_error(
"z_getnewaddress ( type )\n"
"\nReturns a new shielded address for receiving payments.\n"
"\nWith no arguments, returns a Sprout address.\n"
"\nWith no arguments, returns a Sapling address.\n"
"\nBe very careful with 'donotremember' address type, the extended spending key (xsk) of that address is not stored in wallet.dat!\n"
"\nArguments:\n"
"1. \"type\" (string, optional, default=\"" + defaultType + "\") The type of address. One of [\""
+ ADDR_TYPE_SAPLING + "\"].\n"
"1. \"type\" (string, optional, default=\"" + defaultType + "\") The type of address. Either "+ ADDR_TYPE_SAPLING + " or " + ADDR_TYPE_DONOTREMEMBER + " .\n"
"\nResult:\n"
"\"" + strprintf("%s",komodo_chainname()) + "_address\" (string) The new shielded address.\n"
"\nExamples:\n"
+ HelpExampleCli("z_getnewaddress", "")
+ HelpExampleCli("z_getnewaddress", ADDR_TYPE_SAPLING)
+ HelpExampleCli("z_getnewaddress", ADDR_TYPE_DONOTREMEMBER)
);
LOCK2(cs_main, pwalletMain->cs_wallet);
@ -3735,11 +3736,17 @@ UniValue z_getnewaddress(const UniValue& params, bool fHelp, const CPubKey& mypk
if (params.size() > 0) {
addrType = params[0].get_str();
}
if (addrType == ADDR_TYPE_SAPLING) {
return EncodePaymentAddress(pwalletMain->GenerateNewSaplingZKey());
} else if (addrType == ADDR_TYPE_DONOTREMEMBER) {
bool addToWallet = false;
auto zaddr = EncodePaymentAddress(pwalletMain->GenerateNewSaplingZKey(addToWallet));
if(fZdebug) {
fprintf(stderr,"%s: Sietch zaddr=%s created, xsk not stored in wallet.dat!\n", __FUNCTION__, zaddr.c_str() );
}
return zaddr;
} else {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid address type!");
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid address type! Try " + ADDR_TYPE_SAPLING + " or " + ADDR_TYPE_DONOTREMEMBER);
}
}
@ -4049,7 +4056,7 @@ UniValue z_gettotalbalance(const UniValue& params, bool fHelp, const CPubKey& my
"\nResult:\n"
"{\n"
" \"transparent\": xxxxx, (numeric) the total balance of transparent funds\n"
" \"private\": xxxxx, (numeric) the total balance of private funds (in both Sprout and Sapling addresses)\n"
" \"private\": xxxxx, (numeric) the total balance of shielded funds\n"
" \"total\": xxxxx, (numeric) the total balance of both transparent and private funds\n"
"}\n"
"\nExamples:\n"

6
src/wallet/wallet.cpp

@ -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.
@ -127,7 +127,7 @@ libzcash::SproutPaymentAddress CWallet::GenerateNewSproutZKey()
}
// Generate a new Sapling spending key and return its public payment address
SaplingPaymentAddress CWallet::GenerateNewSaplingZKey()
SaplingPaymentAddress CWallet::GenerateNewSaplingZKey(bool addToWallet)
{
AssertLockHeld(cs_wallet); // mapSaplingZKeyMetadata
@ -168,7 +168,7 @@ SaplingPaymentAddress CWallet::GenerateNewSaplingZKey()
mapSaplingZKeyMetadata[ivk] = metadata;
auto addr = xsk.DefaultAddress();
if (!AddSaplingZKey(xsk, addr)) {
if (addToWallet && !AddSaplingZKey(xsk, addr)) {
throw std::runtime_error("CWallet::GenerateNewSaplingZKey(): AddSaplingZKey failed");
}
// return default sapling payment address.

5
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.
@ -1093,7 +1093,8 @@ public:
* Sapling ZKeys
*/
//! Generates new Sapling key
libzcash::SaplingPaymentAddress GenerateNewSaplingZKey();
// Sietch uses addToWallet=false
libzcash::SaplingPaymentAddress GenerateNewSaplingZKey(bool addToWallet=true);
//! Adds Sapling spending key to the store, and saves it to disk
bool AddSaplingZKey(
const libzcash::SaplingExtendedSpendingKey &key,

Loading…
Cancel
Save