Browse Source

Bucket -> note.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
pull/145/head
Daira Hopwood 8 years ago
committed by Sean Bowe
parent
commit
4bc00dc141
  1. 6
      src/main.cpp
  2. 10
      src/primitives/transaction.h
  3. 36
      src/wallet/rpcwallet.cpp
  4. 14
      src/wallet/wallet.cpp
  5. 2
      src/wallet/wallet.h

6
src/main.cpp

@ -2158,10 +2158,10 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
UpdateCoins(tx, state, view, i == 0 ? undoDummy : blockundo.vtxundo.back(), pindex->nHeight);
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) {
BOOST_FOREACH(const uint256 &bucket_commitment, joinsplit.commitments) {
// Insert the bucket commitments into our temporary tree.
BOOST_FOREACH(const uint256 &note_commitment, joinsplit.commitments) {
// Insert the note commitments into our temporary tree.
tree.append(bucket_commitment);
tree.append(note_commitment);
}
}

10
src/primitives/transaction.h

@ -25,22 +25,22 @@ public:
CAmount vpub_old;
CAmount vpub_new;
// JoinSplits are always anchored to a root in the bucket
// JoinSplits are always anchored to a root in the note
// commitment tree at some point in the blockchain
// history or in the history of the current
// transaction.
uint256 anchor;
// Nullifiers are used to prevent double-spends. They
// are derived from the secrets placed in the bucket
// are derived from the secrets placed in the note
// and the secret spend-authority key known by the
// spender.
boost::array<uint256, ZC_NUM_JS_INPUTS> nullifiers;
// Bucket commitments are introduced into the commitment
// Note commitments are introduced into the commitment
// tree, blinding the public about the values and
// destinations involved in the JoinSplit. The presence of a
// commitment in the bucket commitment tree is required
// destinations involved in the JoinSplit. The presence of
// a commitment in the note commitment tree is required
// to spend it.
boost::array<uint256, ZC_NUM_JS_OUTPUTS> commitments;

36
src/wallet/rpcwallet.cpp

@ -2448,14 +2448,14 @@ Value zc_raw_receive(const json_spirit::Array& params, bool fHelp)
if (fHelp || params.size() != 2) {
throw runtime_error(
"zcrawreceive zcsecretkey encryptedbucket\n"
"zcrawreceive zcsecretkey encryptednote\n"
"\n"
"Decrypts encryptedbucket and checks if the coin commitments\n"
"Decrypts encryptednote and checks if the coin commitments\n"
"are in the blockchain as indicated by the \"exists\" result.\n"
"\n"
"Output: {\n"
" \"amount\": value,\n"
" \"bucket\": cleartextbucket,\n"
" \"note\": noteplaintext,\n"
" \"exists\": exists\n"
"}\n"
);
@ -2474,7 +2474,7 @@ Value zc_raw_receive(const json_spirit::Array& params, bool fHelp)
uint256 h_sig;
{
CDataStream ssData(ParseHexV(params[1], "encrypted_bucket"), SER_NETWORK, PROTOCOL_VERSION);
CDataStream ssData(ParseHexV(params[1], "encrypted_note"), SER_NETWORK, PROTOCOL_VERSION);
try {
ssData >> nonce;
ssData >> epk;
@ -2482,7 +2482,7 @@ Value zc_raw_receive(const json_spirit::Array& params, bool fHelp)
ssData >> h_sig;
} catch(const std::exception &) {
throw runtime_error(
"encrypted_bucket could not be decoded"
"encrypted_note could not be decoded"
);
}
}
@ -2503,7 +2503,7 @@ Value zc_raw_receive(const json_spirit::Array& params, bool fHelp)
std::vector<boost::optional<ZCIncrementalWitness>> witnesses;
uint256 anchor;
uint256 commitment = decrypted_note.cm();
pwalletMain->WitnessBucketCommitment(
pwalletMain->WitnessNoteCommitment(
{commitment},
witnesses,
anchor
@ -2514,7 +2514,7 @@ Value zc_raw_receive(const json_spirit::Array& params, bool fHelp)
Object result;
result.push_back(Pair("amount", ValueFromAmount(decrypted_note.value)));
result.push_back(Pair("bucket", HexStr(ss.begin(), ss.end())));
result.push_back(Pair("note", HexStr(ss.begin(), ss.end())));
result.push_back(Pair("exists", (bool) witnesses[0]));
return result;
}
@ -2530,7 +2530,7 @@ Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp)
if (fHelp || params.size() != 5) {
throw runtime_error(
"zcrawjoinsplit rawtx inputs outputs vpub_old vpub_new\n"
" inputs: a JSON object mapping {bucket: zcsecretkey, ...}\n"
" inputs: a JSON object mapping {note: zcsecretkey, ...}\n"
" outputs: a JSON object mapping {zcaddr: value, ...}\n"
"\n"
"Splices a joinsplit into rawtx. Inputs are unilaterally confidential.\n"
@ -2544,8 +2544,8 @@ Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp)
"payments in-band on the blockchain.)\n"
"\n"
"Output: {\n"
" \"encryptedbucket1\": enc1,\n"
" \"encryptedbucket2\": enc2,\n"
" \"encryptednote1\": enc1,\n"
" \"encryptednote2\": enc2,\n"
" \"rawtxn\": rawtxout\n"
"}\n"
);
@ -2585,7 +2585,7 @@ Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp)
NotePlaintext npt;
{
CDataStream ssData(ParseHexV(s.name_, "bucket"), SER_NETWORK, PROTOCOL_VERSION);
CDataStream ssData(ParseHexV(s.name_, "note"), SER_NETWORK, PROTOCOL_VERSION);
ssData >> npt;
}
@ -2597,7 +2597,7 @@ Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp)
uint256 anchor;
std::vector<boost::optional<ZCIncrementalWitness>> witnesses;
pwalletMain->WitnessBucketCommitment(commitments, witnesses, anchor);
pwalletMain->WitnessNoteCommitment(commitments, witnesses, anchor);
assert(witnesses.size() == notes.size());
assert(notes.size() == keys.size());
@ -2683,8 +2683,8 @@ Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp)
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << rawTx;
std::string encryptedBucket1;
std::string encryptedBucket2;
std::string encryptedNote1;
std::string encryptedNote2;
{
CDataStream ss2(SER_NETWORK, PROTOCOL_VERSION);
ss2 << ((unsigned char) 0x00);
@ -2692,7 +2692,7 @@ Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp)
ss2 << jsdescription.ciphertexts[0];
ss2 << jsdescription.h_sig(*pzcashParams, joinSplitPubKey);
encryptedBucket1 = HexStr(ss2.begin(), ss2.end());
encryptedNote1 = HexStr(ss2.begin(), ss2.end());
}
{
CDataStream ss2(SER_NETWORK, PROTOCOL_VERSION);
@ -2701,12 +2701,12 @@ Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp)
ss2 << jsdescription.ciphertexts[1];
ss2 << jsdescription.h_sig(*pzcashParams, joinSplitPubKey);
encryptedBucket2 = HexStr(ss2.begin(), ss2.end());
encryptedNote2 = HexStr(ss2.begin(), ss2.end());
}
Object result;
result.push_back(Pair("encryptedbucket1", encryptedBucket1));
result.push_back(Pair("encryptedbucket2", encryptedBucket2));
result.push_back(Pair("encryptednote1", encryptedNote1));
result.push_back(Pair("encryptednote2", encryptedNote2));
result.push_back(Pair("rawtxn", HexStr(ss.begin(), ss.end())));
return result;
}

14
src/wallet/wallet.cpp

@ -1051,9 +1051,9 @@ bool CWalletTx::WriteToDisk(CWalletDB *pwalletdb)
return pwalletdb->WriteTx(GetHash(), *this);
}
void CWallet::WitnessBucketCommitment(std::vector<uint256> commitments,
std::vector<boost::optional<ZCIncrementalWitness>>& witnesses,
uint256 &final_anchor)
void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
std::vector<boost::optional<ZCIncrementalWitness>>& witnesses,
uint256 &final_anchor)
{
witnesses.resize(commitments.size());
CBlockIndex* pindex = chainActive.Genesis();
@ -1067,19 +1067,19 @@ void CWallet::WitnessBucketCommitment(std::vector<uint256> commitments,
{
BOOST_FOREACH(const JSDescription& pour, tx.vjoinsplit)
{
BOOST_FOREACH(const uint256 &bucket_commitment, pour.commitments)
BOOST_FOREACH(const uint256 &note_commitment, pour.commitments)
{
tree.append(bucket_commitment);
tree.append(note_commitment);
BOOST_FOREACH(boost::optional<ZCIncrementalWitness>& wit, witnesses) {
if (wit) {
wit->append(bucket_commitment);
wit->append(note_commitment);
}
}
size_t i = 0;
BOOST_FOREACH(uint256& commitment, commitments) {
if (bucket_commitment == commitment) {
if (note_commitment == commitment) {
witnesses.at(i) = tree.witness();
}
i++;

2
src/wallet/wallet.h

@ -616,7 +616,7 @@ public:
void SyncTransaction(const CTransaction& tx, const CBlock* pblock);
bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate);
void EraseFromWallet(const uint256 &hash);
void WitnessBucketCommitment(
void WitnessNoteCommitment(
std::vector<uint256> commitments,
std::vector<boost::optional<ZCIncrementalWitness>>& witnesses,
uint256 &final_anchor);

Loading…
Cancel
Save