Auto merge of #4486 - defuse:fix-undefined-behavior-in-gtest, r=daira

Fix undefined behavior in gtest tests
This commit is contained in:
Homu 2020-05-27 23:47:58 +00:00
commit 72edd11bd9
11 changed files with 23 additions and 26 deletions

View File

@ -99,7 +99,7 @@ public:
bool operator()(const libzcash::GrothProof& proof) const
{
uint256 h_sig = params.h_sig(jsdesc.randomSeed, jsdesc.nullifiers, joinSplitPubKey);
uint256 h_sig = ZCJoinSplit::h_sig(jsdesc.randomSeed, jsdesc.nullifiers, joinSplitPubKey);
return librustzcash_sprout_verify(
proof.begin(),
@ -126,9 +126,9 @@ bool JSDescription::Verify(
return boost::apply_visitor(pv, proof);
}
uint256 JSDescription::h_sig(ZCJoinSplit& params, const uint256& joinSplitPubKey) const
uint256 JSDescription::h_sig(const uint256& joinSplitPubKey) const
{
return params.h_sig(randomSeed, nullifiers, joinSplitPubKey);
return ZCJoinSplit::h_sig(randomSeed, nullifiers, joinSplitPubKey);
}
std::string COutPoint::ToString() const

View File

@ -269,7 +269,7 @@ public:
) const;
// Returns the calculated h_sig
uint256 h_sig(ZCJoinSplit& params, const uint256& joinSplitPubKey) const;
uint256 h_sig(const uint256& joinSplitPubKey) const;
ADD_SERIALIZE_METHODS;

View File

@ -583,7 +583,7 @@ 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(*sproutParams, mtx.joinSplitPubKey);
auto hSig = prevJoinSplit.h_sig(mtx.joinSplitPubKey);
try {
auto plaintext = libzcash::SproutNotePlaintext::decrypt(
decryptor,

View File

@ -116,7 +116,7 @@ libzcash::SproutNote GetSproutNote(ZCJoinSplit& params,
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(params, tx.joinSplitPubKey);
auto hSig = tx.vJoinSplit[js].h_sig(tx.joinSplitPubKey);
auto note_pt = libzcash::SproutNotePlaintext::decrypt(
decryptor,
tx.vJoinSplit[js].ciphertexts[n],

View File

@ -543,7 +543,7 @@ 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(*pzcashParams, tx_.joinSplitPubKey);
auto hSig = prevJoinSplit.h_sig(tx_.joinSplitPubKey);
try {
SproutNotePlaintext plaintext = SproutNotePlaintext::decrypt(
decryptor,
@ -843,7 +843,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(
ss2 << ((unsigned char)0x00);
ss2 << jsdesc.ephemeralKey;
ss2 << jsdesc.ciphertexts[0];
ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey_);
ss2 << jsdesc.h_sig(joinSplitPubKey_);
encryptedNote1 = HexStr(ss2.begin(), ss2.end());
}
@ -852,7 +852,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(
ss2 << ((unsigned char)0x01);
ss2 << jsdesc.ephemeralKey;
ss2 << jsdesc.ciphertexts[1];
ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey_);
ss2 << jsdesc.h_sig(joinSplitPubKey_);
encryptedNote2 = HexStr(ss2.begin(), ss2.end());
}

View File

@ -688,7 +688,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
// Decrypt the change note's ciphertext to retrieve some data we need
ZCNoteDecryption decryptor(boost::get<libzcash::SproutSpendingKey>(spendingkey_).receiving_key());
auto hSig = prevJoinSplit.h_sig(*pzcashParams, tx_.joinSplitPubKey);
auto hSig = prevJoinSplit.h_sig(tx_.joinSplitPubKey);
try {
SproutNotePlaintext plaintext = SproutNotePlaintext::decrypt(
decryptor,
@ -1122,7 +1122,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(
ss2 << ((unsigned char) 0x00);
ss2 << jsdesc.ephemeralKey;
ss2 << jsdesc.ciphertexts[0];
ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey_);
ss2 << jsdesc.h_sig(joinSplitPubKey_);
encryptedNote1 = HexStr(ss2.begin(), ss2.end());
}
@ -1131,7 +1131,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(
ss2 << ((unsigned char) 0x01);
ss2 << jsdesc.ephemeralKey;
ss2 << jsdesc.ciphertexts[1];
ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey_);
ss2 << jsdesc.h_sig(joinSplitPubKey_);
encryptedNote2 = HexStr(ss2.begin(), ss2.end());
}

View File

@ -363,7 +363,7 @@ UniValue AsyncRPCOperation_shieldcoinbase::perform_joinsplit(ShieldCoinbaseJSInf
ss2 << ((unsigned char) 0x00);
ss2 << jsdesc.ephemeralKey;
ss2 << jsdesc.ciphertexts[0];
ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey_);
ss2 << jsdesc.h_sig(joinSplitPubKey_);
encryptedNote1 = HexStr(ss2.begin(), ss2.end());
}
@ -372,7 +372,7 @@ UniValue AsyncRPCOperation_shieldcoinbase::perform_joinsplit(ShieldCoinbaseJSInf
ss2 << ((unsigned char) 0x01);
ss2 << jsdesc.ephemeralKey;
ss2 << jsdesc.ciphertexts[1];
ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey_);
ss2 << jsdesc.h_sig(joinSplitPubKey_);
encryptedNote2 = HexStr(ss2.begin(), ss2.end());
}

View File

@ -471,8 +471,7 @@ TEST(WalletTests, CheckSproutNoteCommitmentAgainstNotePlaintext) {
auto note = GetSproutNote(sk, wtx, 0, 1);
auto nullifier = note.nullifier(sk);
auto hSig = wtx.vJoinSplit[0].h_sig(
*params, wtx.joinSplitPubKey);
auto hSig = wtx.vJoinSplit[0].h_sig(wtx.joinSplitPubKey);
ASSERT_THROW(wallet.GetSproutNoteNullifier(
wtx.vJoinSplit[0],
@ -493,8 +492,7 @@ TEST(WalletTests, GetSproutNoteNullifier) {
auto note = GetSproutNote(sk, wtx, 0, 1);
auto nullifier = note.nullifier(sk);
auto hSig = wtx.vJoinSplit[0].h_sig(
*params, wtx.joinSplitPubKey);
auto hSig = wtx.vJoinSplit[0].h_sig(wtx.joinSplitPubKey);
auto ret = wallet.GetSproutNoteNullifier(
wtx.vJoinSplit[0],

View File

@ -258,7 +258,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(*pzcashParams, tx.joinSplitPubKey);
uint256 h_sig = jsdesc.h_sig(tx.joinSplitPubKey);
ZCPaymentDisclosureNoteDecryption decrypter;

View File

@ -3116,7 +3116,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(*pzcashParams, joinSplitPubKey);
ss2 << jsdesc.h_sig(joinSplitPubKey);
encryptedNote1 = HexStr(ss2.begin(), ss2.end());
}
@ -3125,7 +3125,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(*pzcashParams, joinSplitPubKey);
ss2 << jsdesc.h_sig(joinSplitPubKey);
encryptedNote2 = HexStr(ss2.begin(), ss2.end());
}

View File

@ -1432,8 +1432,7 @@ 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(
*pzcashParams, wtxItem.second.joinSplitPubKey);
auto hSig = wtxItem.second.vJoinSplit[i].h_sig(wtxItem.second.joinSplitPubKey);
item.second.nullifier = GetSproutNoteNullifier(
wtxItem.second.vJoinSplit[i],
item.second.address,
@ -1848,7 +1847,7 @@ 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(*pzcashParams, tx.joinSplitPubKey);
auto hSig = tx.vJoinSplit[i].h_sig(tx.joinSplitPubKey);
for (uint8_t j = 0; j < tx.vJoinSplit[i].ciphertexts.size(); j++) {
for (const NoteDecryptorMap::value_type& item : mapNoteDecryptors) {
try {
@ -2276,7 +2275,7 @@ std::pair<SproutNotePlaintext, SproutPaymentAddress> CWalletTx::DecryptSproutNot
EncodePaymentAddress(pa)));
}
auto hSig = this->vJoinSplit[jsop.js].h_sig(*pzcashParams, this->joinSplitPubKey);
auto hSig = this->vJoinSplit[jsop.js].h_sig(this->joinSplitPubKey);
try {
SproutNotePlaintext plaintext = SproutNotePlaintext::decrypt(
decryptor,
@ -4951,7 +4950,7 @@ void CWallet::GetFilteredNotes(
}
// determine amount of funds in the note
auto hSig = wtx.vJoinSplit[i].h_sig(*pzcashParams, wtx.joinSplitPubKey);
auto hSig = wtx.vJoinSplit[i].h_sig(wtx.joinSplitPubKey);
try {
SproutNotePlaintext plaintext = SproutNotePlaintext::decrypt(
decryptor,