Auto merge of #4380 - oxarbitrage:issue3446, r=ebfull

Change cm to cmu in sapling

Part of https://github.com/zcash/zcash/issues/3446

For each of the 2 commits, suggested change was made, then fixed build errors until compile. Finally ran bitcoin and gtests, both of them passing.
This commit is contained in:
Homu 2020-02-27 20:46:05 +00:00
commit 95e446bf69
16 changed files with 39 additions and 39 deletions

View File

@ -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());
}

View File

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

View File

@ -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);

View File

@ -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));

View File

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

View File

@ -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 <typename Stream, typename Operation>
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 &&

View File

@ -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())));

View File

@ -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());

View File

@ -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,8 +302,8 @@ TransactionBuilderResult TransactionBuilder::Build()
// Create Sapling OutputDescriptions
for (auto output : outputs) {
auto cm = output.note.cm();
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);
}

View File

@ -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 };

View File

@ -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();
@ -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<bool>(maybe_pt), true);
auto maybe_note = maybe_pt.get().note(ivk);
ASSERT_EQ(static_cast<bool>(maybe_note), true);
@ -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();
@ -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<bool>(maybe_pt), true);
auto maybe_note = maybe_pt.get().note(ivk);
ASSERT_EQ(static_cast<bool>(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<bool>(maybe_pt), true);
auto maybe_note = maybe_pt.get().note(ivk);
ASSERT_EQ(static_cast<bool>(maybe_note), true);

View File

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

View File

@ -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<mapSaplingNoteData_t, SaplingIncomingViewingKeyMap> 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<std::pair<
output.encCiphertext,
nd.ivk,
output.ephemeralKey,
output.cm);
output.cmu);
assert(static_cast<bool>(maybe_pt));
auto notePt = maybe_pt.get();
@ -2318,7 +2318,7 @@ boost::optional<std::pair<
output.outCiphertext,
ovk,
output.cv,
output.cm,
output.cmu,
output.ephemeralKey);
if (!outPt) {
continue;
@ -2329,7 +2329,7 @@ boost::optional<std::pair<
output.ephemeralKey,
outPt->esk,
outPt->pk_d,
output.cm);
output.cmu);
assert(static_cast<bool>(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<bool>(maybe_pt));
auto notePt = maybe_pt.get();

View File

@ -48,7 +48,7 @@ SaplingNote::SaplingNote(const SaplingPaymentAddress& address, const uint64_t va
}
// Call librustzcash to compute the commitment
boost::optional<uint256> SaplingNote::cm() const {
boost::optional<uint256> SaplingNote::cmu() const {
uint256 result;
if (!librustzcash_sapling_compute_cm(
d.data(),

View File

@ -56,7 +56,7 @@ public:
virtual ~SaplingNote() {};
boost::optional<uint256> cm() const;
boost::optional<uint256> cmu() const;
boost::optional<uint256> nullifier(const SaplingFullViewingKey &vk, const uint64_t position) const;
};

View File

@ -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.cm();
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");
}
@ -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()
);