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:
parent
b230fe6836
commit
5d99e3e92f
|
@ -101,7 +101,7 @@ void test_full_api(ZCJoinSplit* js)
|
||||||
|
|
||||||
auto decrypted_note = note_pt.note(recipient_addr);
|
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
|
// Insert the commitments from the last tx into the tree
|
||||||
tree.append(commitments[0]);
|
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.a_pk == note.a_pk);
|
||||||
ASSERT_TRUE(decrypted_note.rho == note.rho);
|
ASSERT_TRUE(decrypted_note.rho == note.rho);
|
||||||
ASSERT_TRUE(decrypted_note.r == note.r);
|
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);
|
ASSERT_TRUE(decrypted.memo == note_pt.memo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,14 +98,14 @@ CWalletTx GetValidSpend(ZCJoinSplit& params,
|
||||||
libzcash::JSInput dummyin;
|
libzcash::JSInput dummyin;
|
||||||
|
|
||||||
{
|
{
|
||||||
if (note.value > value) {
|
if (note.value() > value) {
|
||||||
libzcash::SpendingKey dummykey = libzcash::SpendingKey::random();
|
libzcash::SpendingKey dummykey = libzcash::SpendingKey::random();
|
||||||
libzcash::PaymentAddress dummyaddr = dummykey.address();
|
libzcash::PaymentAddress dummyaddr = dummykey.address();
|
||||||
dummyout = libzcash::JSOutput(dummyaddr, note.value - value);
|
dummyout = libzcash::JSOutput(dummyaddr, note.value() - value);
|
||||||
} else if (note.value < value) {
|
} else if (note.value() < value) {
|
||||||
libzcash::SpendingKey dummykey = libzcash::SpendingKey::random();
|
libzcash::SpendingKey dummykey = libzcash::SpendingKey::random();
|
||||||
libzcash::PaymentAddress dummyaddr = dummykey.address();
|
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());
|
tree.append(dummynote.cm());
|
||||||
dummyin = libzcash::JSInput(tree.witness(), dummynote, dummykey);
|
dummyin = libzcash::JSInput(tree.witness(), dummynote, dummykey);
|
||||||
}
|
}
|
||||||
|
|
|
@ -753,7 +753,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(
|
||||||
getId(),
|
getId(),
|
||||||
tx_.vjoinsplit.size(),
|
tx_.vjoinsplit.size(),
|
||||||
FormatMoney(info.vpub_old), FormatMoney(info.vpub_new),
|
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));
|
FormatMoney(info.vjsout[0].value), FormatMoney(info.vjsout[1].value));
|
||||||
|
|
||||||
// Generate the proof, this can take over a minute.
|
// Generate the proof, this can take over a minute.
|
||||||
|
|
|
@ -968,7 +968,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(
|
||||||
getId(),
|
getId(),
|
||||||
tx_.vjoinsplit.size(),
|
tx_.vjoinsplit.size(),
|
||||||
FormatMoney(info.vpub_old), FormatMoney(info.vpub_new),
|
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)
|
FormatMoney(info.vjsout[0].value), FormatMoney(info.vjsout[1].value)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -341,7 +341,7 @@ UniValue AsyncRPCOperation_shieldcoinbase::perform_joinsplit(ShieldCoinbaseJSInf
|
||||||
getId(),
|
getId(),
|
||||||
tx_.vjoinsplit.size(),
|
tx_.vjoinsplit.size(),
|
||||||
FormatMoney(info.vpub_old), FormatMoney(info.vpub_new),
|
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)
|
FormatMoney(info.vjsout[0].value), FormatMoney(info.vjsout[1].value)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -2833,7 +2833,7 @@ UniValue zc_raw_receive(const UniValue& params, bool fHelp)
|
||||||
ss << npt;
|
ss << npt;
|
||||||
|
|
||||||
UniValue result(UniValue::VOBJ);
|
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("note", HexStr(ss.begin(), ss.end())));
|
||||||
result.push_back(Pair("exists", (bool) witnesses[0]));
|
result.push_back(Pair("exists", (bool) witnesses[0]));
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -168,7 +168,7 @@ public:
|
||||||
// Sanity checks of input
|
// Sanity checks of input
|
||||||
{
|
{
|
||||||
// If note has nonzero value
|
// 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.
|
// The witness root must equal the input root.
|
||||||
if (inputs[i].witness.root() != rt) {
|
if (inputs[i].witness.root() != rt) {
|
||||||
throw std::invalid_argument("joinsplit not anchored to the correct root");
|
throw std::invalid_argument("joinsplit not anchored to the correct root");
|
||||||
|
@ -186,11 +186,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Balance must be sensical
|
// 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");
|
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) {
|
if (lhs_value > MAX_MONEY) {
|
||||||
throw std::invalid_argument("nonsensical left hand size of joinsplit balance");
|
throw std::invalid_argument("nonsensical left hand size of joinsplit balance");
|
||||||
|
|
|
@ -13,7 +13,6 @@ SproutNote::SproutNote() {
|
||||||
a_pk = random_uint256();
|
a_pk = random_uint256();
|
||||||
rho = random_uint256();
|
rho = random_uint256();
|
||||||
r = random_uint256();
|
r = random_uint256();
|
||||||
value = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 SproutNote::cm() const {
|
uint256 SproutNote::cm() const {
|
||||||
|
@ -23,7 +22,7 @@ uint256 SproutNote::cm() const {
|
||||||
hasher.Write(&discriminant, 1);
|
hasher.Write(&discriminant, 1);
|
||||||
hasher.Write(a_pk.begin(), 32);
|
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(&value_vec[0], value_vec.size());
|
||||||
hasher.Write(rho.begin(), 32);
|
hasher.Write(rho.begin(), 32);
|
||||||
|
@ -43,7 +42,7 @@ NotePlaintext::NotePlaintext(
|
||||||
const SproutNote& note,
|
const SproutNote& note,
|
||||||
boost::array<unsigned char, ZC_MEMO_SIZE> memo) : memo(memo)
|
boost::array<unsigned char, ZC_MEMO_SIZE> memo) : memo(memo)
|
||||||
{
|
{
|
||||||
value = note.value;
|
value = note.value();
|
||||||
rho = note.rho;
|
rho = note.rho;
|
||||||
r = note.r;
|
r = note.r;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,19 +9,23 @@
|
||||||
namespace libzcash {
|
namespace libzcash {
|
||||||
|
|
||||||
class BaseNote {
|
class BaseNote {
|
||||||
|
protected:
|
||||||
|
uint64_t value_ = 0;
|
||||||
public:
|
public:
|
||||||
|
BaseNote() {}
|
||||||
|
BaseNote(uint64_t value) : value_(value) {};
|
||||||
virtual uint256 cm() const {};
|
virtual uint256 cm() const {};
|
||||||
|
inline uint64_t value() const { return value_; };
|
||||||
};
|
};
|
||||||
|
|
||||||
class SproutNote : public BaseNote {
|
class SproutNote : public BaseNote {
|
||||||
public:
|
public:
|
||||||
uint256 a_pk;
|
uint256 a_pk;
|
||||||
uint64_t value;
|
|
||||||
uint256 rho;
|
uint256 rho;
|
||||||
uint256 r;
|
uint256 r;
|
||||||
|
|
||||||
SproutNote(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();
|
SproutNote();
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,7 @@ public:
|
||||||
// Witness total_uint64 bits
|
// Witness total_uint64 bits
|
||||||
uint64_t left_side_acc = vpub_old;
|
uint64_t left_side_acc = vpub_old;
|
||||||
for (size_t i = 0; i < NumInputs; i++) {
|
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(
|
zk_total_uint64.fill_with_bits(
|
||||||
|
|
|
@ -23,7 +23,7 @@ public:
|
||||||
|
|
||||||
void generate_r1cs_witness(const SproutNote& note) {
|
void generate_r1cs_witness(const SproutNote& note) {
|
||||||
r->bits.fill_with_bits(this->pb, uint256_to_bool_vector(note.r));
|
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
|
// 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 merkle tree authentication path
|
||||||
witness_input->generate_r1cs_witness(path);
|
witness_input->generate_r1cs_witness(path);
|
||||||
|
|
Loading…
Reference in New Issue