Skip to content

Commit

Permalink
[Cleanup] Remove Sprout address/key classes
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Nov 21, 2020
1 parent 09875f0 commit 52d2625
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 122 deletions.
8 changes: 2 additions & 6 deletions src/rpc/misc.cpp
Expand Up @@ -349,19 +349,15 @@ UniValue spork(const JSONRPCRequest& request)
HelpExampleCli("spork", "show") + HelpExampleRpc("spork", "show"));
}

// Every possibly address (todo: clean sprout address)
typedef boost::variant<libzcash::InvalidEncoding, libzcash::SproutPaymentAddress, libzcash::SaplingPaymentAddress, CTxDestination> PPaymentAddress;
// Every possibly address
typedef boost::variant<libzcash::InvalidEncoding, libzcash::SaplingPaymentAddress, CTxDestination> PPaymentAddress;

class DescribePaymentAddressVisitor : public boost::static_visitor<UniValue>
{
public:
explicit DescribePaymentAddressVisitor(bool _isStaking) : isStaking(_isStaking) {}
UniValue operator()(const libzcash::InvalidEncoding &zaddr) const { return UniValue(UniValue::VOBJ); }

UniValue operator()(const libzcash::SproutPaymentAddress &zaddr) const {
return UniValue(UniValue::VOBJ); // todo: Clean Sprout code.
}

UniValue operator()(const libzcash::SaplingPaymentAddress &zaddr) const {
UniValue obj(UniValue::VOBJ);
obj.pushKV("diversifier", HexStr(zaddr.d));
Expand Down
25 changes: 0 additions & 25 deletions src/sapling/address.cpp
Expand Up @@ -13,35 +13,10 @@ const unsigned char ZCASH_SAPLING_FVFP_PERSONALIZATION[crypto_generichash_blake2

namespace libzcash {

uint256 SproutPaymentAddress::GetHash() const {
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << *this;
return Hash(ss.begin(), ss.end());
}

uint256 ReceivingKey::pk_enc() const {
return ZCNoteEncryption::generate_pubkey(*this);
}

SproutPaymentAddress SproutViewingKey::address() const {
return SproutPaymentAddress(a_pk, sk_enc.pk_enc());
}

ReceivingKey SproutSpendingKey::receiving_key() const {
return ReceivingKey(ZCNoteEncryption::generate_privkey(*this));
}

SproutViewingKey SproutSpendingKey::viewing_key() const {
return SproutViewingKey(PRF_addr_a_pk(*this), receiving_key());
}

SproutSpendingKey SproutSpendingKey::random() {
return SproutSpendingKey(random_uint252());
}

SproutPaymentAddress SproutSpendingKey::address() const {
return viewing_key().address();
}

//! Sapling
uint256 SaplingPaymentAddress::GetHash() const {
Expand Down
72 changes: 1 addition & 71 deletions src/sapling/address.hpp
Expand Up @@ -17,42 +17,11 @@ class InvalidEncoding {
friend bool operator<(const InvalidEncoding &a, const InvalidEncoding &b) { return true; }
};

const size_t SerializedSproutPaymentAddressSize = 64;
const size_t SerializedSproutViewingKeySize = 64;
const size_t SerializedSproutSpendingKeySize = 32;

const size_t SerializedSaplingPaymentAddressSize = 43;
const size_t SerializedSaplingFullViewingKeySize = 96;
const size_t SerializedSaplingExpandedSpendingKeySize = 96;
const size_t SerializedSaplingSpendingKeySize = 32;

class SproutPaymentAddress {
public:
uint256 a_pk;
uint256 pk_enc;

SproutPaymentAddress() : a_pk(), pk_enc() { }
SproutPaymentAddress(uint256 a_pk, uint256 pk_enc) : a_pk(a_pk), pk_enc(pk_enc) { }

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(a_pk);
READWRITE(pk_enc);
}

//! Get the 256-bit SHA256d hash of this payment address.
uint256 GetHash() const;

friend inline bool operator==(const SproutPaymentAddress& a, const SproutPaymentAddress& b) {
return a.a_pk == b.a_pk && a.pk_enc == b.pk_enc;
}
friend inline bool operator<(const SproutPaymentAddress& a, const SproutPaymentAddress& b) {
return (a.a_pk < b.a_pk ||
(a.a_pk == b.a_pk && a.pk_enc < b.pk_enc));
}
};

class ReceivingKey : public uint256 {
public:
Expand All @@ -62,45 +31,6 @@ class ReceivingKey : public uint256 {
uint256 pk_enc() const;
};

class SproutViewingKey {
public:
uint256 a_pk;
ReceivingKey sk_enc;

SproutViewingKey() : a_pk(), sk_enc() { }
SproutViewingKey(uint256 a_pk, ReceivingKey sk_enc) : a_pk(a_pk), sk_enc(sk_enc) { }

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(a_pk);
READWRITE(sk_enc);
}

SproutPaymentAddress address() const;

friend inline bool operator==(const SproutViewingKey& a, const SproutViewingKey& b) {
return a.a_pk == b.a_pk && a.sk_enc == b.sk_enc;
}
friend inline bool operator<(const SproutViewingKey& a, const SproutViewingKey& b) {
return (a.a_pk < b.a_pk ||
(a.a_pk == b.a_pk && a.sk_enc < b.sk_enc));
}
};

class SproutSpendingKey : public uint252 {
public:
SproutSpendingKey() : uint252() { }
SproutSpendingKey(uint252 a_sk) : uint252(a_sk) { }

static SproutSpendingKey random();

ReceivingKey receiving_key() const;
SproutViewingKey viewing_key() const;
SproutPaymentAddress address() const;
};

//! Sapling functions.
class SaplingPaymentAddress {
public:
Expand Down Expand Up @@ -219,7 +149,7 @@ class SaplingSpendingKey : public uint256 {
SaplingPaymentAddress default_address() const;
};

typedef boost::variant<InvalidEncoding, SproutPaymentAddress, SaplingPaymentAddress> PaymentAddress;
typedef boost::variant<InvalidEncoding, SaplingPaymentAddress> PaymentAddress;

}

Expand Down
18 changes: 0 additions & 18 deletions src/sapling/key_io_sapling.cpp
Expand Up @@ -25,12 +25,6 @@ class PaymentAddressEncoder : public boost::static_visitor<std::string>
public:
PaymentAddressEncoder(const CChainParams& params) : m_params(params) {}

std::string operator()(const libzcash::SproutPaymentAddress& zaddr) const
{
// Not implemented. Clean Sprout code.
return "";
}

std::string operator()(const libzcash::SaplingPaymentAddress& zaddr) const
{
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
Expand All @@ -55,12 +49,6 @@ class ViewingKeyEncoder : public boost::static_visitor<std::string>
public:
ViewingKeyEncoder(const CChainParams& params) : m_params(params) {}

std::string operator()(const libzcash::SproutViewingKey& vk) const
{
// Not implemented. Clean Sprout code.
return "";
}

std::string operator()(const libzcash::SaplingExtendedFullViewingKey& extfvk) const
{
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
Expand Down Expand Up @@ -88,12 +76,6 @@ class SpendingKeyEncoder : public boost::static_visitor<std::string>
public:
SpendingKeyEncoder(const CChainParams& params) : m_params(params) {}

std::string operator()(const libzcash::SproutSpendingKey& zkey) const
{
// Not implemented. Clean Sprout code.
return "";
}

std::string operator()(const libzcash::SaplingExtendedSpendingKey& zkey) const
{
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
Expand Down
4 changes: 2 additions & 2 deletions src/sapling/zip32.h
Expand Up @@ -134,8 +134,8 @@ struct SaplingExtendedSpendingKey {
}
};

typedef boost::variant<InvalidEncoding, SproutSpendingKey, SaplingExtendedSpendingKey> SpendingKey;
typedef boost::variant<InvalidEncoding, SproutViewingKey, SaplingExtendedFullViewingKey> ViewingKey;
typedef boost::variant<InvalidEncoding, SaplingExtendedSpendingKey> SpendingKey;
typedef boost::variant<InvalidEncoding, SaplingExtendedFullViewingKey> ViewingKey;

}

Expand Down
4 changes: 4 additions & 0 deletions src/test/librust/noteencryption_tests.cpp
Expand Up @@ -348,6 +348,8 @@ BOOST_AUTO_TEST_CASE(SaplingApi_test)
));
}

//// BEGIN REMOVE

BOOST_AUTO_TEST_CASE(api_test)
{
uint256 sk_enc = ZCNoteEncryption::generate_privkey(uint252(uint256S("21035d60bc1983e37950ce4803418a8fb33ea68d5b937ca382ecbae7564d6a07")));
Expand Down Expand Up @@ -480,6 +482,8 @@ BOOST_AUTO_TEST_CASE(PrfNf_test)
}
}

//// END REMOVE

BOOST_AUTO_TEST_CASE(uint252_test)
{
BOOST_CHECK_THROW(uint252(uint256S("f6da8716682d600f74fc16bd0187faad6a26b4aa4c24d5c055b216d94516847e")), std::domain_error);
Expand Down

0 comments on commit 52d2625

Please sign in to comment.