From 4d4cb444404100d2c688f44ecfad72233899b383 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Wed, 26 Feb 2020 16:49:34 -0300 Subject: [PATCH 1/3] change cm() to cmu() in SaplingNote class --- src/gtest/test_noteencryption.cpp | 4 ++-- src/gtest/test_sapling_note.cpp | 2 +- src/transaction_builder.cpp | 4 ++-- src/utiltest.cpp | 2 +- src/wallet/gtest/test_wallet.cpp | 6 +++--- src/zcash/Note.cpp | 2 +- src/zcash/Note.hpp | 2 +- src/zcbenchmarks.cpp | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/gtest/test_noteencryption.cpp b/src/gtest/test_noteencryption.cpp index f60f34ee8..d66580ac9 100644 --- a/src/gtest/test_noteencryption.cpp +++ b/src/gtest/test_noteencryption.cpp @@ -35,7 +35,7 @@ TEST(noteencryption, NotePlaintext) } SaplingNote note(addr, 39393); - auto cmu_opt = note.cm(); + auto cmu_opt = note.cmu(); if (!cmu_opt) { FAIL(); } @@ -92,7 +92,7 @@ TEST(noteencryption, NotePlaintext) ASSERT_TRUE(note.d == new_note.d); ASSERT_TRUE(note.pk_d == new_note.pk_d); ASSERT_TRUE(note.r == new_note.r); - ASSERT_TRUE(note.cm() == new_note.cm()); + ASSERT_TRUE(note.cmu() == new_note.cmu()); SaplingOutgoingPlaintext out_pt; out_pt.pk_d = note.pk_d; diff --git a/src/gtest/test_sapling_note.cpp b/src/gtest/test_sapling_note.cpp index 3e336ec7e..b6846217a 100644 --- a/src/gtest/test_sapling_note.cpp +++ b/src/gtest/test_sapling_note.cpp @@ -45,7 +45,7 @@ TEST(SaplingNote, TestVectors) // Test commitment SaplingNote note = SaplingNote(diversifier, pk_d, v, r); - ASSERT_EQ(note.cm().get(), cm); + ASSERT_EQ(note.cmu().get(), cm); // Test nullifier SaplingSpendingKey spendingKey(sk); diff --git a/src/transaction_builder.cpp b/src/transaction_builder.cpp index 0e524524a..1a1ba43bf 100644 --- a/src/transaction_builder.cpp +++ b/src/transaction_builder.cpp @@ -265,7 +265,7 @@ TransactionBuilderResult TransactionBuilder::Build() // Create Sapling SpendDescriptions for (auto spend : spends) { - auto cm = spend.note.cm(); + auto cm = spend.note.cmu(); auto nf = spend.note.nullifier( spend.expsk.full_viewing_key(), spend.witness.position()); if (!cm || !nf) { @@ -302,7 +302,7 @@ TransactionBuilderResult TransactionBuilder::Build() // Create Sapling OutputDescriptions for (auto output : outputs) { - auto cm = output.note.cm(); + auto cm = output.note.cmu(); if (!cm) { librustzcash_sapling_proving_ctx_free(ctx); return TransactionBuilderResult("Output is invalid"); diff --git a/src/utiltest.cpp b/src/utiltest.cpp index a3576fd6d..965987349 100644 --- a/src/utiltest.cpp +++ b/src/utiltest.cpp @@ -246,7 +246,7 @@ CKey AddTestCKeyToKeyStore(CBasicKeyStore& keyStore) { TestSaplingNote GetTestSaplingNote(const libzcash::SaplingPaymentAddress& pa, CAmount value) { // Generate dummy Sapling note libzcash::SaplingNote note(pa, value); - uint256 cm = note.cm().get(); + uint256 cm = note.cmu().get(); SaplingMerkleTree tree; tree.append(cm); return { note, tree }; diff --git a/src/wallet/gtest/test_wallet.cpp b/src/wallet/gtest/test_wallet.cpp index bb16d614e..a975b5c2e 100644 --- a/src/wallet/gtest/test_wallet.cpp +++ b/src/wallet/gtest/test_wallet.cpp @@ -388,7 +388,7 @@ TEST(WalletTests, SetSaplingNoteAddrsInCWalletTx) { auto pk = sk.DefaultAddress(); libzcash::SaplingNote note(pk, 50000); - auto cm = note.cm().get(); + auto cm = note.cmu().get(); SaplingMerkleTree tree; tree.append(cm); auto anchor = tree.root(); @@ -657,7 +657,7 @@ TEST(WalletTests, GetConflictedSaplingNotes) { // Generate note A libzcash::SaplingNote note(pk, 50000); - auto cm = note.cm().get(); + auto cm = note.cmu().get(); SaplingMerkleTree saplingTree; saplingTree.append(cm); auto anchor = saplingTree.root(); @@ -1021,7 +1021,7 @@ TEST(WalletTests, SpentSaplingNoteIsFromMe) { // Generate Sapling note A libzcash::SaplingNote note(pk, 50000); - auto cm = note.cm().get(); + auto cm = note.cmu().get(); SaplingMerkleTree saplingTree; saplingTree.append(cm); auto anchor = saplingTree.root(); diff --git a/src/zcash/Note.cpp b/src/zcash/Note.cpp index 23210c784..5f8b439fb 100644 --- a/src/zcash/Note.cpp +++ b/src/zcash/Note.cpp @@ -48,7 +48,7 @@ SaplingNote::SaplingNote(const SaplingPaymentAddress& address, const uint64_t va } // Call librustzcash to compute the commitment -boost::optional SaplingNote::cm() const { +boost::optional SaplingNote::cmu() const { uint256 result; if (!librustzcash_sapling_compute_cm( d.data(), diff --git a/src/zcash/Note.hpp b/src/zcash/Note.hpp index 7d3377306..dee17bfe4 100644 --- a/src/zcash/Note.hpp +++ b/src/zcash/Note.hpp @@ -56,7 +56,7 @@ public: virtual ~SaplingNote() {}; - boost::optional cm() const; + boost::optional cmu() const; boost::optional nullifier(const SaplingFullViewingKey &vk, const uint64_t position) const; }; diff --git a/src/zcbenchmarks.cpp b/src/zcbenchmarks.cpp index 7ac607c2b..88f077f7b 100644 --- a/src/zcbenchmarks.cpp +++ b/src/zcbenchmarks.cpp @@ -596,7 +596,7 @@ double benchmark_create_sapling_spend() auto address = sk.default_address(); SaplingNote note(address, GetRand(MAX_MONEY)); SaplingMerkleTree tree; - auto maybe_cm = note.cm(); + auto maybe_cm = note.cmu(); tree.append(maybe_cm.get()); auto anchor = tree.root(); auto witness = tree.witness(); From 445ae593d68a7f6d71039a8f8d4f603b88a24e85 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Wed, 26 Feb 2020 17:43:50 -0300 Subject: [PATCH 2/3] change the cm member of OutputDescription to cmu --- src/bench/verification.cpp | 2 +- src/main.cpp | 4 ++-- src/miner.cpp | 2 +- src/primitives/transaction.h | 6 +++--- src/rpc/rawtransaction.cpp | 2 +- src/test/sighash_tests.cpp | 2 +- src/transaction_builder.cpp | 8 ++++---- src/wallet/gtest/test_wallet.cpp | 6 +++--- src/wallet/test/rpc_wallet_tests.cpp | 4 ++-- src/wallet/wallet.cpp | 14 +++++++------- src/zcbenchmarks.cpp | 2 +- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/bench/verification.cpp b/src/bench/verification.cpp index 76c931396..2fff0c8a4 100644 --- a/src/bench/verification.cpp +++ b/src/bench/verification.cpp @@ -134,7 +134,7 @@ static void SaplingOutput(benchmark::State& state) librustzcash_sapling_check_output( ctx, output.cv.begin(), - output.cm.begin(), + output.cmu.begin(), output.ephemeralKey.begin(), output.zkproof.begin()); } diff --git a/src/main.cpp b/src/main.cpp index dfb1ba736..5669f9271 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -952,7 +952,7 @@ bool ContextualCheckTransaction( if (!librustzcash_sapling_check_output( ctx, output.cv.begin(), - output.cm.begin(), + output.cmu.begin(), output.ephemeralKey.begin(), output.zkproof.begin() )) @@ -2731,7 +2731,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin } BOOST_FOREACH(const OutputDescription &outputDescription, tx.vShieldedOutput) { - sapling_tree.append(outputDescription.cm); + sapling_tree.append(outputDescription.cmu); } vPos.push_back(std::make_pair(tx.GetHash(), pos)); diff --git a/src/miner.cpp b/src/miner.cpp index 20918ee68..a8093542c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -362,7 +362,7 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s UpdateCoins(tx, view, nHeight); BOOST_FOREACH(const OutputDescription &outDescription, tx.vShieldedOutput) { - sapling_tree.append(outDescription.cm); + sapling_tree.append(outDescription.cmu); } // Added diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 458497781..a62ca3120 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -99,7 +99,7 @@ class OutputDescription { public: uint256 cv; //!< A value commitment to the value of the output note. - uint256 cm; //!< The note commitment for the output note. + uint256 cmu; //!< The u-coordinate of the note commitment for the output note. uint256 ephemeralKey; //!< A Jubjub public key. libzcash::SaplingEncCiphertext encCiphertext; //!< A ciphertext component for the encrypted output note. libzcash::SaplingOutCiphertext outCiphertext; //!< A ciphertext component for the encrypted output note. @@ -112,7 +112,7 @@ public: template inline void SerializationOp(Stream& s, Operation ser_action) { READWRITE(cv); - READWRITE(cm); + READWRITE(cmu); READWRITE(ephemeralKey); READWRITE(encCiphertext); READWRITE(outCiphertext); @@ -123,7 +123,7 @@ public: { return ( a.cv == b.cv && - a.cm == b.cm && + a.cmu == b.cmu && a.ephemeralKey == b.ephemeralKey && a.encCiphertext == b.encCiphertext && a.outCiphertext == b.outCiphertext && diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index b3898bd71..bfe287116 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -138,7 +138,7 @@ UniValue TxShieldedOutputsToJSON(const CTransaction& tx) { for (const OutputDescription& outputDesc : tx.vShieldedOutput) { UniValue obj(UniValue::VOBJ); obj.push_back(Pair("cv", outputDesc.cv.GetHex())); - obj.push_back(Pair("cmu", outputDesc.cm.GetHex())); + obj.push_back(Pair("cmu", outputDesc.cmu.GetHex())); obj.push_back(Pair("ephemeralKey", outputDesc.ephemeralKey.GetHex())); obj.push_back(Pair("encCiphertext", HexStr(outputDesc.encCiphertext.begin(), outputDesc.encCiphertext.end()))); obj.push_back(Pair("outCiphertext", HexStr(outputDesc.outCiphertext.begin(), outputDesc.outCiphertext.end()))); diff --git a/src/test/sighash_tests.cpp b/src/test/sighash_tests.cpp index 3677ddb3d..8f1ed9e4a 100644 --- a/src/test/sighash_tests.cpp +++ b/src/test/sighash_tests.cpp @@ -159,7 +159,7 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle, uint32_t co for (int out = 0; out < shielded_outs; out++) { OutputDescription odesc; odesc.cv = GetRandHash(); - odesc.cm = GetRandHash(); + odesc.cmu = GetRandHash(); odesc.ephemeralKey = GetRandHash(); randombytes_buf(odesc.encCiphertext.begin(), odesc.encCiphertext.size()); randombytes_buf(odesc.outCiphertext.begin(), odesc.outCiphertext.size()); diff --git a/src/transaction_builder.cpp b/src/transaction_builder.cpp index 1a1ba43bf..ae6c72cd3 100644 --- a/src/transaction_builder.cpp +++ b/src/transaction_builder.cpp @@ -302,8 +302,8 @@ TransactionBuilderResult TransactionBuilder::Build() // Create Sapling OutputDescriptions for (auto output : outputs) { - auto cm = output.note.cmu(); - if (!cm) { + auto cmu = output.note.cmu(); + if (!cmu) { librustzcash_sapling_proving_ctx_free(ctx); return TransactionBuilderResult("Output is invalid"); } @@ -336,7 +336,7 @@ TransactionBuilderResult TransactionBuilder::Build() return TransactionBuilderResult("Output proof failed"); } - odesc.cm = *cm; + odesc.cmu = *cmu; odesc.ephemeralKey = encryptor.get_epk(); odesc.encCiphertext = enc.first; @@ -344,7 +344,7 @@ TransactionBuilderResult TransactionBuilder::Build() odesc.outCiphertext = outPlaintext.encrypt( output.ovk, odesc.cv, - odesc.cm, + odesc.cmu, encryptor); mtx.vShieldedOutput.push_back(odesc); } diff --git a/src/wallet/gtest/test_wallet.cpp b/src/wallet/gtest/test_wallet.cpp index a975b5c2e..458497e02 100644 --- a/src/wallet/gtest/test_wallet.cpp +++ b/src/wallet/gtest/test_wallet.cpp @@ -703,7 +703,7 @@ TEST(WalletTests, GetConflictedSaplingNotes) { wtx.vShieldedOutput[0].encCiphertext, ivk, wtx.vShieldedOutput[0].ephemeralKey, - wtx.vShieldedOutput[0].cm); + wtx.vShieldedOutput[0].cmu); ASSERT_EQ(static_cast(maybe_pt), true); auto maybe_note = maybe_pt.get().note(ivk); ASSERT_EQ(static_cast(maybe_note), true); @@ -1080,7 +1080,7 @@ TEST(WalletTests, SpentSaplingNoteIsFromMe) { wtx.vShieldedOutput[0].encCiphertext, ivk, wtx.vShieldedOutput[0].ephemeralKey, - wtx.vShieldedOutput[0].cm); + wtx.vShieldedOutput[0].cmu); ASSERT_EQ(static_cast(maybe_pt), true); auto maybe_note = maybe_pt.get().note(ivk); ASSERT_EQ(static_cast(maybe_note), true); @@ -2000,7 +2000,7 @@ TEST(WalletTests, MarkAffectedSaplingTransactionsDirty) { // Prepare to spend the note that was just created auto maybe_pt = libzcash::SaplingNotePlaintext::decrypt( - tx1.vShieldedOutput[0].encCiphertext, ivk, tx1.vShieldedOutput[0].ephemeralKey, tx1.vShieldedOutput[0].cm); + tx1.vShieldedOutput[0].encCiphertext, ivk, tx1.vShieldedOutput[0].ephemeralKey, tx1.vShieldedOutput[0].cmu); ASSERT_EQ(static_cast(maybe_pt), true); auto maybe_note = maybe_pt.get().note(ivk); ASSERT_EQ(static_cast(maybe_note), true); diff --git a/src/wallet/test/rpc_wallet_tests.cpp b/src/wallet/test/rpc_wallet_tests.cpp index 3cdbca33f..6effcfff6 100644 --- a/src/wallet/test/rpc_wallet_tests.cpp +++ b/src/wallet/test/rpc_wallet_tests.cpp @@ -1389,7 +1389,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_taddr_to_sapling) tx.vShieldedOutput[0].outCiphertext, uint256(), tx.vShieldedOutput[0].cv, - tx.vShieldedOutput[0].cm, + tx.vShieldedOutput[0].cmu, tx.vShieldedOutput[0].ephemeralKey)); // We should be able to decrypt the outCiphertext with the ovk @@ -1400,7 +1400,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_taddr_to_sapling) tx.vShieldedOutput[0].outCiphertext, ovkForShieldingFromTaddr(seed), tx.vShieldedOutput[0].cv, - tx.vShieldedOutput[0].cm, + tx.vShieldedOutput[0].cmu, tx.vShieldedOutput[0].ephemeralKey)); // Tear down diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index f7a366966..22b79f8a2 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1174,7 +1174,7 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex, } // Sapling for (uint32_t i = 0; i < tx.vShieldedOutput.size(); i++) { - const uint256& note_commitment = tx.vShieldedOutput[i].cm; + const uint256& note_commitment = tx.vShieldedOutput[i].cmu; saplingTree.append(note_commitment); // Increment existing witnesses @@ -1476,7 +1476,7 @@ void CWallet::UpdateSaplingNullifierNoteMapWithTx(CWalletTx& wtx) { uint64_t position = nd.witnesses.front().position(); auto extfvk = mapSaplingFullViewingKeys.at(nd.ivk); OutputDescription output = wtx.vShieldedOutput[op.n]; - auto optPlaintext = SaplingNotePlaintext::decrypt(output.encCiphertext, nd.ivk, output.ephemeralKey, output.cm); + auto optPlaintext = SaplingNotePlaintext::decrypt(output.encCiphertext, nd.ivk, output.ephemeralKey, output.cmu); if (!optPlaintext) { // An item in mapSaplingNoteData must have already been successfully decrypted, // otherwise the item would not exist in the first place. @@ -1882,7 +1882,7 @@ std::pair CWallet::FindMySap const OutputDescription output = tx.vShieldedOutput[i]; for (auto it = mapSaplingFullViewingKeys.begin(); it != mapSaplingFullViewingKeys.end(); ++it) { SaplingIncomingViewingKey ivk = it->first; - auto result = SaplingNotePlaintext::decrypt(output.encCiphertext, ivk, output.ephemeralKey, output.cm); + auto result = SaplingNotePlaintext::decrypt(output.encCiphertext, ivk, output.ephemeralKey, output.cmu); if (!result) { continue; } @@ -2295,7 +2295,7 @@ boost::optional(maybe_pt)); auto notePt = maybe_pt.get(); @@ -2318,7 +2318,7 @@ boost::optionalesk, outPt->pk_d, - output.cm); + output.cmu); assert(static_cast(maybe_pt)); auto notePt = maybe_pt.get(); @@ -4956,7 +4956,7 @@ void CWallet::GetFilteredNotes( wtx.vShieldedOutput[op.n].encCiphertext, nd.ivk, wtx.vShieldedOutput[op.n].ephemeralKey, - wtx.vShieldedOutput[op.n].cm); + wtx.vShieldedOutput[op.n].cmu); assert(static_cast(maybe_pt)); auto notePt = maybe_pt.get(); diff --git a/src/zcbenchmarks.cpp b/src/zcbenchmarks.cpp index 88f077f7b..9e62d8e90 100644 --- a/src/zcbenchmarks.cpp +++ b/src/zcbenchmarks.cpp @@ -735,7 +735,7 @@ double benchmark_verify_sapling_output() bool result = librustzcash_sapling_check_output( ctx, output.cv.begin(), - output.cm.begin(), + output.cmu.begin(), output.ephemeralKey.begin(), output.zkproof.begin() ); From 8ebe538eaa67dcbf1299dc6cb7f8fb9945bc4272 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Wed, 26 Feb 2020 18:33:49 -0300 Subject: [PATCH 3/3] change maybe_cm to maybe_cmu --- src/zcbenchmarks.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/zcbenchmarks.cpp b/src/zcbenchmarks.cpp index 9e62d8e90..5db123594 100644 --- a/src/zcbenchmarks.cpp +++ b/src/zcbenchmarks.cpp @@ -596,12 +596,12 @@ double benchmark_create_sapling_spend() auto address = sk.default_address(); SaplingNote note(address, GetRand(MAX_MONEY)); SaplingMerkleTree tree; - auto maybe_cm = note.cmu(); - tree.append(maybe_cm.get()); + auto maybe_cmu = note.cmu(); + tree.append(maybe_cmu.get()); auto anchor = tree.root(); auto witness = tree.witness(); auto maybe_nf = note.nullifier(expsk.full_viewing_key(), witness.position()); - if (!(maybe_cm && maybe_nf)) { + if (!(maybe_cmu && maybe_nf)) { throw JSONRPCError(RPC_INTERNAL_ERROR, "Could not create note commitment and nullifier"); }