From 79ad5984b1bb2b044c4fa7f6085cda9665f39ddc Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 9 Jul 2020 20:20:06 +1200 Subject: [PATCH] Remove JSDescription::h_sig This removes the zcash/JoinSplit.hpp dependency from primitives/transaction.cpp, and thus from libzcashconsensus. --- src/mempool_limit.h | 1 + src/primitives/transaction.cpp | 5 ----- src/primitives/transaction.h | 4 ---- src/test/coins_tests.cpp | 1 + src/transaction_builder.cpp | 5 ++++- src/utiltest.cpp | 5 ++++- .../asyncrpcoperation_mergetoaddress.cpp | 9 +++++--- src/wallet/asyncrpcoperation_sendmany.cpp | 9 +++++--- .../asyncrpcoperation_shieldcoinbase.cpp | 4 ++-- src/wallet/gtest/test_wallet.cpp | 11 ++++++++-- src/wallet/rpcdisclosure.cpp | 3 ++- src/wallet/rpcwallet.cpp | 4 ++-- src/wallet/wallet.cpp | 21 +++++++++++++++---- src/wallet/wallet.h | 1 + 14 files changed, 55 insertions(+), 28 deletions(-) diff --git a/src/mempool_limit.h b/src/mempool_limit.h index e34f147e2..61e22bc57 100644 --- a/src/mempool_limit.h +++ b/src/mempool_limit.h @@ -5,6 +5,7 @@ #ifndef ZCASH_MEMPOOL_LIMIT_H #define ZCASH_MEMPOOL_LIMIT_H +#include #include #include #include diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 61e3d76f3..090e8a55e 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -9,11 +9,6 @@ #include "tinyformat.h" #include "utilstrencodings.h" -uint256 JSDescription::h_sig(const Ed25519VerificationKey& joinSplitPubKey) const -{ - return ZCJoinSplit::h_sig(randomSeed, nullifiers, joinSplitPubKey); -} - std::string COutPoint::ToString() const { return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10), n); diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 16d210488..7b1b1e1c1 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -19,7 +19,6 @@ #include "zcash/NoteEncryption.hpp" #include "zcash/Zcash.h" -#include "zcash/JoinSplit.hpp" #include "zcash/Proof.hpp" #include @@ -235,9 +234,6 @@ public: JSDescription(): vpub_old(0), vpub_new(0) { } - // Returns the calculated h_sig - uint256 h_sig(const Ed25519VerificationKey& joinSplitPubKey) const; - ADD_SERIALIZE_METHODS; template diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index f35fee667..143028d10 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -13,6 +13,7 @@ #include "undo.h" #include "primitives/transaction.h" #include "pubkey.h" +#include "zcash/Note.hpp" #include #include diff --git a/src/transaction_builder.cpp b/src/transaction_builder.cpp index 38bb78258..301c007fd 100644 --- a/src/transaction_builder.cpp +++ b/src/transaction_builder.cpp @@ -634,7 +634,10 @@ void TransactionBuilder::CreateJSDescriptions() // Decrypt the change note's ciphertext to retrieve some data we need ZCNoteDecryption decryptor(changeKey.receiving_key()); - auto hSig = prevJoinSplit.h_sig(mtx.joinSplitPubKey); + auto hSig = ZCJoinSplit::h_sig( + prevJoinSplit.randomSeed, + prevJoinSplit.nullifiers, + mtx.joinSplitPubKey); try { auto plaintext = libzcash::SproutNotePlaintext::decrypt( decryptor, diff --git a/src/utiltest.cpp b/src/utiltest.cpp index ceec65569..652537687 100644 --- a/src/utiltest.cpp +++ b/src/utiltest.cpp @@ -114,7 +114,10 @@ CWalletTx GetInvalidCommitmentSproutReceive( libzcash::SproutNote GetSproutNote(const libzcash::SproutSpendingKey& sk, const CTransaction& tx, size_t js, size_t n) { ZCNoteDecryption decryptor {sk.receiving_key()}; - auto hSig = tx.vJoinSplit[js].h_sig(tx.joinSplitPubKey); + auto hSig = ZCJoinSplit::h_sig( + tx.vJoinSplit[js].randomSeed, + tx.vJoinSplit[js].nullifiers, + tx.joinSplitPubKey); auto note_pt = libzcash::SproutNotePlaintext::decrypt( decryptor, tx.vJoinSplit[js].ciphertexts[n], diff --git a/src/wallet/asyncrpcoperation_mergetoaddress.cpp b/src/wallet/asyncrpcoperation_mergetoaddress.cpp index 9508ba9cc..2212c2413 100644 --- a/src/wallet/asyncrpcoperation_mergetoaddress.cpp +++ b/src/wallet/asyncrpcoperation_mergetoaddress.cpp @@ -553,7 +553,10 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() // Decrypt the change note's ciphertext to retrieve some data we need ZCNoteDecryption decryptor(changeKey.receiving_key()); - auto hSig = prevJoinSplit.h_sig(tx_.joinSplitPubKey); + auto hSig = ZCJoinSplit::h_sig( + prevJoinSplit.randomSeed, + prevJoinSplit.nullifiers, + tx_.joinSplitPubKey); try { SproutNotePlaintext plaintext = SproutNotePlaintext::decrypt( decryptor, @@ -857,7 +860,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit( ss2 << ((unsigned char)0x00); ss2 << jsdesc.ephemeralKey; ss2 << jsdesc.ciphertexts[0]; - ss2 << jsdesc.h_sig(joinSplitPubKey_); + ss2 << ZCJoinSplit::h_sig(jsdesc.randomSeed, jsdesc.nullifiers, joinSplitPubKey_); encryptedNote1 = HexStr(ss2.begin(), ss2.end()); } @@ -866,7 +869,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit( ss2 << ((unsigned char)0x01); ss2 << jsdesc.ephemeralKey; ss2 << jsdesc.ciphertexts[1]; - ss2 << jsdesc.h_sig(joinSplitPubKey_); + ss2 << ZCJoinSplit::h_sig(jsdesc.randomSeed, jsdesc.nullifiers, joinSplitPubKey_); encryptedNote2 = HexStr(ss2.begin(), ss2.end()); } diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index f52b1ed18..5bd5cba22 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -638,7 +638,10 @@ bool AsyncRPCOperation_sendmany::main_impl() { // Decrypt the change note's ciphertext to retrieve some data we need ZCNoteDecryption decryptor(std::get(spendingkey_).receiving_key()); - auto hSig = prevJoinSplit.h_sig(tx_.joinSplitPubKey); + auto hSig = ZCJoinSplit::h_sig( + prevJoinSplit.randomSeed, + prevJoinSplit.nullifiers, + tx_.joinSplitPubKey); try { SproutNotePlaintext plaintext = SproutNotePlaintext::decrypt( decryptor, @@ -1106,7 +1109,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit( ss2 << ((unsigned char) 0x00); ss2 << jsdesc.ephemeralKey; ss2 << jsdesc.ciphertexts[0]; - ss2 << jsdesc.h_sig(joinSplitPubKey_); + ss2 << ZCJoinSplit::h_sig(jsdesc.randomSeed, jsdesc.nullifiers, joinSplitPubKey_); encryptedNote1 = HexStr(ss2.begin(), ss2.end()); } @@ -1115,7 +1118,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit( ss2 << ((unsigned char) 0x01); ss2 << jsdesc.ephemeralKey; ss2 << jsdesc.ciphertexts[1]; - ss2 << jsdesc.h_sig(joinSplitPubKey_); + ss2 << ZCJoinSplit::h_sig(jsdesc.randomSeed, jsdesc.nullifiers, joinSplitPubKey_); encryptedNote2 = HexStr(ss2.begin(), ss2.end()); } diff --git a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp index a1588cb49..18b8ec84e 100644 --- a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp +++ b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp @@ -369,7 +369,7 @@ UniValue AsyncRPCOperation_shieldcoinbase::perform_joinsplit(ShieldCoinbaseJSInf ss2 << ((unsigned char) 0x00); ss2 << jsdesc.ephemeralKey; ss2 << jsdesc.ciphertexts[0]; - ss2 << jsdesc.h_sig(joinSplitPubKey_); + ss2 << ZCJoinSplit::h_sig(jsdesc.randomSeed, jsdesc.nullifiers, joinSplitPubKey_); encryptedNote1 = HexStr(ss2.begin(), ss2.end()); } @@ -378,7 +378,7 @@ UniValue AsyncRPCOperation_shieldcoinbase::perform_joinsplit(ShieldCoinbaseJSInf ss2 << ((unsigned char) 0x01); ss2 << jsdesc.ephemeralKey; ss2 << jsdesc.ciphertexts[1]; - ss2 << jsdesc.h_sig(joinSplitPubKey_); + ss2 << ZCJoinSplit::h_sig(jsdesc.randomSeed, jsdesc.nullifiers, joinSplitPubKey_); encryptedNote2 = HexStr(ss2.begin(), ss2.end()); } diff --git a/src/wallet/gtest/test_wallet.cpp b/src/wallet/gtest/test_wallet.cpp index 710b4262e..3a2659ab7 100644 --- a/src/wallet/gtest/test_wallet.cpp +++ b/src/wallet/gtest/test_wallet.cpp @@ -11,6 +11,7 @@ #include "transaction_builder.h" #include "utiltest.h" #include "wallet/wallet.h" +#include "zcash/JoinSplit.hpp" #include "zcash/Note.hpp" #include "zcash/NoteEncryption.hpp" @@ -445,7 +446,10 @@ TEST(WalletTests, CheckSproutNoteCommitmentAgainstNotePlaintext) { auto note = GetSproutNote(sk, wtx, 0, 1); auto nullifier = note.nullifier(sk); - auto hSig = wtx.vJoinSplit[0].h_sig(wtx.joinSplitPubKey); + auto hSig = ZCJoinSplit::h_sig( + wtx.vJoinSplit[0].randomSeed, + wtx.vJoinSplit[0].nullifiers, + wtx.joinSplitPubKey); ASSERT_THROW(wallet.GetSproutNoteNullifier( wtx.vJoinSplit[0], @@ -466,7 +470,10 @@ TEST(WalletTests, GetSproutNoteNullifier) { auto note = GetSproutNote(sk, wtx, 0, 1); auto nullifier = note.nullifier(sk); - auto hSig = wtx.vJoinSplit[0].h_sig(wtx.joinSplitPubKey); + auto hSig = ZCJoinSplit::h_sig( + wtx.vJoinSplit[0].randomSeed, + wtx.vJoinSplit[0].nullifiers, + wtx.joinSplitPubKey); auto ret = wallet.GetSproutNoteNullifier( wtx.vJoinSplit[0], diff --git a/src/wallet/rpcdisclosure.cpp b/src/wallet/rpcdisclosure.cpp index 39851e4ce..dc30181cc 100644 --- a/src/wallet/rpcdisclosure.cpp +++ b/src/wallet/rpcdisclosure.cpp @@ -15,6 +15,7 @@ #include "wallet.h" #include "wallet/paymentdisclosure.h" #include "wallet/paymentdisclosuredb.h" +#include "zcash/JoinSplit.hpp" #include #include @@ -271,7 +272,7 @@ UniValue z_validatepaymentdisclosure(const UniValue& params, bool fHelp) try { // Decrypt the note to get value and memo field JSDescription jsdesc = tx.vJoinSplit[pd.payload.js]; - uint256 h_sig = jsdesc.h_sig(tx.joinSplitPubKey); + uint256 h_sig = ZCJoinSplit::h_sig(jsdesc.randomSeed, jsdesc.nullifiers, tx.joinSplitPubKey); ZCPaymentDisclosureNoteDecryption decrypter; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ea5b4c55c..d139abc5c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3196,7 +3196,7 @@ UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp) ss2 << ((unsigned char) 0x00); ss2 << jsdesc.ephemeralKey; ss2 << jsdesc.ciphertexts[0]; - ss2 << jsdesc.h_sig(joinSplitPubKey); + ss2 << ZCJoinSplit::h_sig(jsdesc.randomSeed, jsdesc.nullifiers, joinSplitPubKey); encryptedNote1 = HexStr(ss2.begin(), ss2.end()); } @@ -3205,7 +3205,7 @@ UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp) ss2 << ((unsigned char) 0x01); ss2 << jsdesc.ephemeralKey; ss2 << jsdesc.ciphertexts[1]; - ss2 << jsdesc.h_sig(joinSplitPubKey); + ss2 << ZCJoinSplit::h_sig(jsdesc.randomSeed, jsdesc.nullifiers, joinSplitPubKey); encryptedNote2 = HexStr(ss2.begin(), ss2.end()); } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 50d05d50c..ff0e30058 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -25,6 +25,7 @@ #include "script/sign.h" #include "timedata.h" #include "utilmoneystr.h" +#include "zcash/JoinSplit.hpp" #include "zcash/Note.hpp" #include "crypter.h" #include "wallet/asyncrpcoperation_saplingmigration.h" @@ -1468,7 +1469,10 @@ bool CWallet::UpdateNullifierNoteMap() if (!item.second.nullifier) { if (GetNoteDecryptor(item.second.address, dec)) { auto i = item.first.js; - auto hSig = wtxItem.second.vJoinSplit[i].h_sig(wtxItem.second.joinSplitPubKey); + auto hSig = ZCJoinSplit::h_sig( + wtxItem.second.vJoinSplit[i].randomSeed, + wtxItem.second.vJoinSplit[i].nullifiers, + wtxItem.second.joinSplitPubKey); item.second.nullifier = GetSproutNoteNullifier( wtxItem.second.vJoinSplit[i], item.second.address, @@ -1887,7 +1891,10 @@ mapSproutNoteData_t CWallet::FindMySproutNotes(const CTransaction &tx) const mapSproutNoteData_t noteData; for (size_t i = 0; i < tx.vJoinSplit.size(); i++) { - auto hSig = tx.vJoinSplit[i].h_sig(tx.joinSplitPubKey); + auto hSig = ZCJoinSplit::h_sig( + tx.vJoinSplit[i].randomSeed, + tx.vJoinSplit[i].nullifiers, + tx.joinSplitPubKey); for (uint8_t j = 0; j < tx.vJoinSplit[i].ciphertexts.size(); j++) { for (const NoteDecryptorMap::value_type& item : mapNoteDecryptors) { try { @@ -2317,7 +2324,10 @@ std::pair CWalletTx::DecryptSproutNot keyIO.EncodePaymentAddress(pa))); } - auto hSig = this->vJoinSplit[jsop.js].h_sig(this->joinSplitPubKey); + auto hSig = ZCJoinSplit::h_sig( + this->vJoinSplit[jsop.js].randomSeed, + this->vJoinSplit[jsop.js].nullifiers, + this->joinSplitPubKey); try { SproutNotePlaintext plaintext = SproutNotePlaintext::decrypt( decryptor, @@ -5101,7 +5111,10 @@ void CWallet::GetFilteredNotes( } // determine amount of funds in the note - auto hSig = wtx.vJoinSplit[i].h_sig(wtx.joinSplitPubKey); + auto hSig = ZCJoinSplit::h_sig( + wtx.vJoinSplit[i].randomSeed, + wtx.vJoinSplit[i].nullifiers, + wtx.joinSplitPubKey); try { SproutNotePlaintext plaintext = SproutNotePlaintext::decrypt( decryptor, diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 1accf8334..927f03711 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -24,6 +24,7 @@ #include "wallet/walletdb.h" #include "wallet/rpcwallet.h" #include "zcash/Address.hpp" +#include "zcash/Note.hpp" #include "base58.h" #include