diff --git a/src/gtest/test_joinsplit.cpp b/src/gtest/test_joinsplit.cpp index a9814e4ab..d238e4b94 100644 --- a/src/gtest/test_joinsplit.cpp +++ b/src/gtest/test_joinsplit.cpp @@ -101,7 +101,7 @@ void test_full_api(ZCJoinSplit* js) auto decrypted_note = note_pt.note(recipient_addr); - ASSERT_TRUE(decrypted_note.value == 10); + ASSERT_TRUE(decrypted_note.value() == 10); // Insert the commitments from the last tx into the tree tree.append(commitments[0]); @@ -543,7 +543,7 @@ TEST(joinsplit, note_plaintexts) ASSERT_TRUE(decrypted_note.a_pk == note.a_pk); ASSERT_TRUE(decrypted_note.rho == note.rho); ASSERT_TRUE(decrypted_note.r == note.r); - ASSERT_TRUE(decrypted_note.value == note.value); + ASSERT_TRUE(decrypted_note.value() == note.value()); ASSERT_TRUE(decrypted.memo == note_pt.memo); } diff --git a/src/utiltest.cpp b/src/utiltest.cpp index 8245adf8e..60af4f7dd 100644 --- a/src/utiltest.cpp +++ b/src/utiltest.cpp @@ -98,14 +98,14 @@ CWalletTx GetValidSpend(ZCJoinSplit& params, libzcash::JSInput dummyin; { - if (note.value > value) { + if (note.value() > value) { libzcash::SpendingKey dummykey = libzcash::SpendingKey::random(); libzcash::PaymentAddress dummyaddr = dummykey.address(); - dummyout = libzcash::JSOutput(dummyaddr, note.value - value); - } else if (note.value < value) { + dummyout = libzcash::JSOutput(dummyaddr, note.value() - value); + } else if (note.value() < value) { libzcash::SpendingKey dummykey = libzcash::SpendingKey::random(); libzcash::PaymentAddress dummyaddr = dummykey.address(); - libzcash::SproutNote dummynote(dummyaddr.a_pk, (value - note.value), uint256(), uint256()); + libzcash::SproutNote dummynote(dummyaddr.a_pk, (value - note.value()), uint256(), uint256()); tree.append(dummynote.cm()); dummyin = libzcash::JSInput(tree.witness(), dummynote, dummykey); } diff --git a/src/wallet/asyncrpcoperation_mergetoaddress.cpp b/src/wallet/asyncrpcoperation_mergetoaddress.cpp index 6e6d3c7d0..b2d9eb4ab 100644 --- a/src/wallet/asyncrpcoperation_mergetoaddress.cpp +++ b/src/wallet/asyncrpcoperation_mergetoaddress.cpp @@ -753,7 +753,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit( getId(), tx_.vjoinsplit.size(), FormatMoney(info.vpub_old), FormatMoney(info.vpub_new), - FormatMoney(info.vjsin[0].note.value), FormatMoney(info.vjsin[1].note.value), + FormatMoney(info.vjsin[0].note.value()), FormatMoney(info.vjsin[1].note.value()), FormatMoney(info.vjsout[0].value), FormatMoney(info.vjsout[1].value)); // Generate the proof, this can take over a minute. diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index de6da102f..42805b5e6 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -968,7 +968,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit( getId(), tx_.vjoinsplit.size(), FormatMoney(info.vpub_old), FormatMoney(info.vpub_new), - FormatMoney(info.vjsin[0].note.value), FormatMoney(info.vjsin[1].note.value), + FormatMoney(info.vjsin[0].note.value()), FormatMoney(info.vjsin[1].note.value()), FormatMoney(info.vjsout[0].value), FormatMoney(info.vjsout[1].value) ); diff --git a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp index b7ace4dd5..dcadc6a78 100644 --- a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp +++ b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp @@ -341,7 +341,7 @@ UniValue AsyncRPCOperation_shieldcoinbase::perform_joinsplit(ShieldCoinbaseJSInf getId(), tx_.vjoinsplit.size(), FormatMoney(info.vpub_old), FormatMoney(info.vpub_new), - FormatMoney(info.vjsin[0].note.value), FormatMoney(info.vjsin[1].note.value), + FormatMoney(info.vjsin[0].note.value()), FormatMoney(info.vjsin[1].note.value()), FormatMoney(info.vjsout[0].value), FormatMoney(info.vjsout[1].value) ); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3b237a7ce..0463c07e5 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2833,7 +2833,7 @@ UniValue zc_raw_receive(const UniValue& params, bool fHelp) ss << npt; UniValue result(UniValue::VOBJ); - result.push_back(Pair("amount", ValueFromAmount(decrypted_note.value))); + result.push_back(Pair("amount", ValueFromAmount(decrypted_note.value()))); result.push_back(Pair("note", HexStr(ss.begin(), ss.end()))); result.push_back(Pair("exists", (bool) witnesses[0])); return result; diff --git a/src/zcash/JoinSplit.cpp b/src/zcash/JoinSplit.cpp index 2d7ed1153..5751d1c6d 100644 --- a/src/zcash/JoinSplit.cpp +++ b/src/zcash/JoinSplit.cpp @@ -168,7 +168,7 @@ public: // Sanity checks of input { // If note has nonzero value - if (inputs[i].note.value != 0) { + if (inputs[i].note.value() != 0) { // The witness root must equal the input root. if (inputs[i].witness.root() != rt) { throw std::invalid_argument("joinsplit not anchored to the correct root"); @@ -186,11 +186,11 @@ public: } // Balance must be sensical - if (inputs[i].note.value > MAX_MONEY) { + if (inputs[i].note.value() > MAX_MONEY) { throw std::invalid_argument("nonsensical input note value"); } - lhs_value += inputs[i].note.value; + lhs_value += inputs[i].note.value(); if (lhs_value > MAX_MONEY) { throw std::invalid_argument("nonsensical left hand size of joinsplit balance"); diff --git a/src/zcash/Note.cpp b/src/zcash/Note.cpp index c16a225ff..5b1ccf51d 100644 --- a/src/zcash/Note.cpp +++ b/src/zcash/Note.cpp @@ -13,7 +13,6 @@ SproutNote::SproutNote() { a_pk = random_uint256(); rho = random_uint256(); r = random_uint256(); - value = 0; } uint256 SproutNote::cm() const { @@ -23,7 +22,7 @@ uint256 SproutNote::cm() const { hasher.Write(&discriminant, 1); hasher.Write(a_pk.begin(), 32); - auto value_vec = convertIntToVectorLE(value); + auto value_vec = convertIntToVectorLE(value_); hasher.Write(&value_vec[0], value_vec.size()); hasher.Write(rho.begin(), 32); @@ -43,7 +42,7 @@ NotePlaintext::NotePlaintext( const SproutNote& note, boost::array memo) : memo(memo) { - value = note.value; + value = note.value(); rho = note.rho; r = note.r; } diff --git a/src/zcash/Note.hpp b/src/zcash/Note.hpp index 623fdbb6c..f4cd4e0f6 100644 --- a/src/zcash/Note.hpp +++ b/src/zcash/Note.hpp @@ -9,19 +9,23 @@ namespace libzcash { class BaseNote { +protected: + uint64_t value_ = 0; public: + BaseNote() {} + BaseNote(uint64_t value) : value_(value) {}; virtual uint256 cm() const {}; + inline uint64_t value() const { return value_; }; }; class SproutNote : public BaseNote { public: uint256 a_pk; - uint64_t value; uint256 rho; uint256 r; SproutNote(uint256 a_pk, uint64_t value, uint256 rho, uint256 r) - : a_pk(a_pk), value(value), rho(rho), r(r) {} + : BaseNote(value), a_pk(a_pk), rho(rho), r(r) {} SproutNote(); diff --git a/src/zcash/circuit/gadget.tcc b/src/zcash/circuit/gadget.tcc index d13c05962..6d057459f 100644 --- a/src/zcash/circuit/gadget.tcc +++ b/src/zcash/circuit/gadget.tcc @@ -222,7 +222,7 @@ public: // Witness total_uint64 bits uint64_t left_side_acc = vpub_old; for (size_t i = 0; i < NumInputs; i++) { - left_side_acc += inputs[i].note.value; + left_side_acc += inputs[i].note.value(); } zk_total_uint64.fill_with_bits( diff --git a/src/zcash/circuit/note.tcc b/src/zcash/circuit/note.tcc index 69526ec71..d1534ec4b 100644 --- a/src/zcash/circuit/note.tcc +++ b/src/zcash/circuit/note.tcc @@ -23,7 +23,7 @@ public: void generate_r1cs_witness(const SproutNote& note) { r->bits.fill_with_bits(this->pb, uint256_to_bool_vector(note.r)); - value.fill_with_bits(this->pb, uint64_to_bool_vector(note.value)); + value.fill_with_bits(this->pb, uint64_to_bool_vector(note.value())); } }; @@ -158,7 +158,7 @@ public: ); // Set enforce flag for nonzero input value - this->pb.val(value_enforce) = (note.value != 0) ? FieldT::one() : FieldT::zero(); + this->pb.val(value_enforce) = (note.value() != 0) ? FieldT::one() : FieldT::zero(); // Witness merkle tree authentication path witness_input->generate_r1cs_witness(path);