Refactoring: SproutNote member variable value moved to BaseNote.

All notes have a value, so the member variable has been moved to the
base class, and direct member access has been replaced with a getter.
This commit is contained in:
Simon 2018-04-25 13:32:13 -07:00
parent b230fe6836
commit 5d99e3e92f
11 changed files with 24 additions and 21 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<unsigned char, ZC_MEMO_SIZE> memo) : memo(memo)
{
value = note.value;
value = note.value();
rho = note.rho;
r = note.r;
}

View File

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

View File

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

View File

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