From 0fbab55b1b85224f6267b81d74c395acbf35e663 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 17 Nov 2016 19:09:45 +1300 Subject: [PATCH 1/5] Add benchmark for attempting decryption of notes --- qa/zcash/performance-measurements.sh | 11 ++++++++++- src/wallet/rpcwallet.cpp | 5 ++++- src/zcbenchmarks.cpp | 20 ++++++++++++++++++++ src/zcbenchmarks.h | 1 + 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/qa/zcash/performance-measurements.sh b/qa/zcash/performance-measurements.sh index 2e99ab2d6..84d3e4cf3 100755 --- a/qa/zcash/performance-measurements.sh +++ b/qa/zcash/performance-measurements.sh @@ -56,7 +56,7 @@ function zcashd_valgrind_stop { case "$1" in *) case "$2" in - verifyjoinsplit) + verifyjoinsplit|trydecryptnotes) zcashd_start RAWJOINSPLIT=$(zcash_rpc zcsamplejoinsplit) zcashd_stop @@ -88,6 +88,9 @@ case "$1" in validatelargetx) zcash_rpc zcbenchmark validatelargetx 5 ;; + trydecryptnotes) + zcash_rpc zcbenchmark trydecryptnotes 1000 "\"$RAWJOINSPLIT\"" + ;; *) zcashd_stop echo "Bad arguments." @@ -116,6 +119,9 @@ case "$1" in verifyequihash) zcash_rpc zcbenchmark verifyequihash 1 ;; + trydecryptnotes) + zcash_rpc zcbenchmark trydecryptnotes 1 "\"$RAWJOINSPLIT\"" + ;; *) zcashd_massif_stop echo "Bad arguments." @@ -145,6 +151,9 @@ case "$1" in verifyequihash) zcash_rpc zcbenchmark verifyequihash 1 ;; + trydecryptnotes) + zcash_rpc zcbenchmark trydecryptnotes 1 "\"$RAWJOINSPLIT\"" + ;; *) zcashd_valgrind_stop echo "Bad arguments." diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index b10a08efe..d33c35781 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2454,7 +2454,8 @@ Value zc_benchmark(const json_spirit::Array& params, bool fHelp) JSDescription samplejoinsplit; - if (benchmarktype == "verifyjoinsplit") { + if (benchmarktype == "verifyjoinsplit" || + benchmarktype == "trydecryptnotes") { CDataStream ss(ParseHexV(params[2].get_str(), "js"), SER_NETWORK, PROTOCOL_VERSION); ss >> samplejoinsplit; } @@ -2480,6 +2481,8 @@ Value zc_benchmark(const json_spirit::Array& params, bool fHelp) sample_times.push_back(benchmark_verify_equihash()); } else if (benchmarktype == "validatelargetx") { sample_times.push_back(benchmark_large_tx()); + } else if (benchmarktype == "trydecryptnotes") { + sample_times.push_back(benchmark_try_decrypt_notes(samplejoinsplit)); } else { throw JSONRPCError(RPC_TYPE_ERROR, "Invalid benchmarktype"); } diff --git a/src/zcbenchmarks.cpp b/src/zcbenchmarks.cpp index 1d60fdde7..6374141b8 100644 --- a/src/zcbenchmarks.cpp +++ b/src/zcbenchmarks.cpp @@ -223,3 +223,23 @@ double benchmark_large_tx() return timer_stop(tv_start); } +double benchmark_try_decrypt_notes(const JSDescription &joinsplit) +{ + const size_t NUM_ADDRS = 10; + + CWallet wallet; + for (int i = 0; i < NUM_ADDRS; i++) { + auto sk = libzcash::SpendingKey::random(); + wallet.AddSpendingKey(sk); + } + + CMutableTransaction mtx; + mtx.vjoinsplit.push_back(joinsplit); + CTransaction tx(mtx); + + struct timeval tv_start; + timer_start(tv_start); + auto nd = wallet.FindMyNotes(tx); + return timer_stop(tv_start); +} + diff --git a/src/zcbenchmarks.h b/src/zcbenchmarks.h index b81d4a707..9a99783ad 100644 --- a/src/zcbenchmarks.h +++ b/src/zcbenchmarks.h @@ -12,5 +12,6 @@ extern std::vector benchmark_solve_equihash_threaded(int nThreads); extern double benchmark_verify_joinsplit(const JSDescription &joinsplit); extern double benchmark_verify_equihash(); extern double benchmark_large_tx(); +extern double benchmark_try_decrypt_notes(const JSDescription &joinsplit); #endif From 0bb3d40f908bf277d5eaed27e424e9eee86c239c Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 17 Nov 2016 22:26:46 +1300 Subject: [PATCH 2/5] Add benchmark for incrementing note witnesses --- qa/zcash/performance-measurements.sh | 9 ++ src/Makefile.am | 2 + src/Makefile.gtest.include | 5 +- src/utiltest.cpp | 144 +++++++++++++++++++++++++++ src/utiltest.h | 18 ++++ src/wallet/gtest/test_wallet.cpp | 128 +----------------------- src/wallet/rpcwallet.cpp | 3 + src/zcbenchmarks.cpp | 43 ++++++++ src/zcbenchmarks.h | 1 + 9 files changed, 228 insertions(+), 125 deletions(-) create mode 100644 src/utiltest.cpp create mode 100644 src/utiltest.h diff --git a/qa/zcash/performance-measurements.sh b/qa/zcash/performance-measurements.sh index 84d3e4cf3..b65974078 100755 --- a/qa/zcash/performance-measurements.sh +++ b/qa/zcash/performance-measurements.sh @@ -91,6 +91,9 @@ case "$1" in trydecryptnotes) zcash_rpc zcbenchmark trydecryptnotes 1000 "\"$RAWJOINSPLIT\"" ;; + incnotewitnesses) + zcash_rpc zcbenchmark incnotewitnesses 100 "${@:3}" + ;; *) zcashd_stop echo "Bad arguments." @@ -122,6 +125,9 @@ case "$1" in trydecryptnotes) zcash_rpc zcbenchmark trydecryptnotes 1 "\"$RAWJOINSPLIT\"" ;; + incnotewitnesses) + zcash_rpc zcbenchmark incnotewitnesses 1 "${@:3}" + ;; *) zcashd_massif_stop echo "Bad arguments." @@ -154,6 +160,9 @@ case "$1" in trydecryptnotes) zcash_rpc zcbenchmark trydecryptnotes 1 "\"$RAWJOINSPLIT\"" ;; + incnotewitnesses) + zcash_rpc zcbenchmark incnotewitnesses 1 "${@:3}" + ;; *) zcashd_valgrind_stop echo "Bad arguments." diff --git a/src/Makefile.am b/src/Makefile.am index 8ded268cf..e37510ae4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -232,6 +232,8 @@ libbitcoin_server_a_SOURCES = \ # when wallet enabled libbitcoin_wallet_a_CPPFLAGS = $(BITCOIN_INCLUDES) libbitcoin_wallet_a_SOURCES = \ + utiltest.cpp \ + utiltest.h \ zcbenchmarks.cpp \ zcbenchmarks.h \ wallet/asyncrpcoperation_sendmany.cpp \ diff --git a/src/Makefile.gtest.include b/src/Makefile.gtest.include index 3941192b5..728d0a7f3 100644 --- a/src/Makefile.gtest.include +++ b/src/Makefile.gtest.include @@ -27,8 +27,11 @@ zcash_gtest_SOURCES = \ gtest/test_txid.cpp \ gtest/test_libzcash_utils.cpp \ gtest/test_proofs.cpp \ - gtest/test_checkblock.cpp \ + gtest/test_checkblock.cpp +if ENABLE_WALLET +zcash_gtest_SOURCES += \ wallet/gtest/test_wallet.cpp +endif zcash_gtest_CPPFLAGS = -DMULTICORE -fopenmp -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DSTATIC diff --git a/src/utiltest.cpp b/src/utiltest.cpp new file mode 100644 index 000000000..3ebbcf128 --- /dev/null +++ b/src/utiltest.cpp @@ -0,0 +1,144 @@ +// Copyright (c) 2016 The Zcash developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "utiltest.h" + +CWalletTx GetValidReceive(ZCJoinSplit& params, + const libzcash::SpendingKey& sk, CAmount value, + bool randomInputs) { + CMutableTransaction mtx; + mtx.nVersion = 2; // Enable JoinSplits + mtx.vin.resize(2); + if (randomInputs) { + mtx.vin[0].prevout.hash = GetRandHash(); + mtx.vin[1].prevout.hash = GetRandHash(); + } else { + mtx.vin[0].prevout.hash = uint256S("0000000000000000000000000000000000000000000000000000000000000001"); + mtx.vin[1].prevout.hash = uint256S("0000000000000000000000000000000000000000000000000000000000000002"); + } + mtx.vin[0].prevout.n = 0; + mtx.vin[1].prevout.n = 0; + + // Generate an ephemeral keypair. + uint256 joinSplitPubKey; + unsigned char joinSplitPrivKey[crypto_sign_SECRETKEYBYTES]; + crypto_sign_keypair(joinSplitPubKey.begin(), joinSplitPrivKey); + mtx.joinSplitPubKey = joinSplitPubKey; + + boost::array inputs = { + libzcash::JSInput(), // dummy input + libzcash::JSInput() // dummy input + }; + + boost::array outputs = { + libzcash::JSOutput(sk.address(), value), + libzcash::JSOutput(sk.address(), value) + }; + + boost::array output_notes; + + // Prepare JoinSplits + uint256 rt; + JSDescription jsdesc {params, mtx.joinSplitPubKey, rt, + inputs, outputs, 2*value, 0, false}; + mtx.vjoinsplit.push_back(jsdesc); + + // Empty output script. + CScript scriptCode; + CTransaction signTx(mtx); + uint256 dataToBeSigned = SignatureHash(scriptCode, signTx, NOT_AN_INPUT, SIGHASH_ALL); + + // Add the signature + assert(crypto_sign_detached(&mtx.joinSplitSig[0], NULL, + dataToBeSigned.begin(), 32, + joinSplitPrivKey + ) == 0); + + CTransaction tx {mtx}; + CWalletTx wtx {NULL, tx}; + return wtx; +} + +libzcash::Note GetNote(ZCJoinSplit& params, + const libzcash::SpendingKey& sk, + const CTransaction& tx, size_t js, size_t n) { + ZCNoteDecryption decryptor {sk.viewing_key()}; + auto hSig = tx.vjoinsplit[js].h_sig(params, tx.joinSplitPubKey); + auto note_pt = libzcash::NotePlaintext::decrypt( + decryptor, + tx.vjoinsplit[js].ciphertexts[n], + tx.vjoinsplit[js].ephemeralKey, + hSig, + (unsigned char) n); + return note_pt.note(sk.address()); +} + +CWalletTx GetValidSpend(ZCJoinSplit& params, + const libzcash::SpendingKey& sk, + const libzcash::Note& note, CAmount value) { + CMutableTransaction mtx; + mtx.vout.resize(2); + mtx.vout[0].nValue = value; + mtx.vout[1].nValue = 0; + + // Generate an ephemeral keypair. + uint256 joinSplitPubKey; + unsigned char joinSplitPrivKey[crypto_sign_SECRETKEYBYTES]; + crypto_sign_keypair(joinSplitPubKey.begin(), joinSplitPrivKey); + mtx.joinSplitPubKey = joinSplitPubKey; + + // Fake tree for the unused witness + ZCIncrementalMerkleTree tree; + + libzcash::JSOutput dummyout; + libzcash::JSInput dummyin; + + { + 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) { + libzcash::SpendingKey dummykey = libzcash::SpendingKey::random(); + libzcash::PaymentAddress dummyaddr = dummykey.address(); + libzcash::Note dummynote(dummyaddr.a_pk, (value - note.value), uint256(), uint256()); + tree.append(dummynote.cm()); + dummyin = libzcash::JSInput(tree.witness(), dummynote, dummykey); + } + } + + tree.append(note.cm()); + + boost::array inputs = { + libzcash::JSInput(tree.witness(), note, sk), + dummyin + }; + + boost::array outputs = { + dummyout, // dummy output + libzcash::JSOutput() // dummy output + }; + + boost::array output_notes; + + // Prepare JoinSplits + uint256 rt = tree.root(); + JSDescription jsdesc {params, mtx.joinSplitPubKey, rt, + inputs, outputs, 0, value, false}; + mtx.vjoinsplit.push_back(jsdesc); + + // Empty output script. + CScript scriptCode; + CTransaction signTx(mtx); + uint256 dataToBeSigned = SignatureHash(scriptCode, signTx, NOT_AN_INPUT, SIGHASH_ALL); + + // Add the signature + assert(crypto_sign_detached(&mtx.joinSplitSig[0], NULL, + dataToBeSigned.begin(), 32, + joinSplitPrivKey + ) == 0); + CTransaction tx {mtx}; + CWalletTx wtx {NULL, tx}; + return wtx; +} diff --git a/src/utiltest.h b/src/utiltest.h new file mode 100644 index 000000000..8cfa60d06 --- /dev/null +++ b/src/utiltest.h @@ -0,0 +1,18 @@ +// Copyright (c) 2016 The Zcash developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "wallet/wallet.h" +#include "zcash/JoinSplit.hpp" +#include "zcash/Note.hpp" +#include "zcash/NoteEncryption.hpp" + +CWalletTx GetValidReceive(ZCJoinSplit& params, + const libzcash::SpendingKey& sk, CAmount value, + bool randomInputs); +libzcash::Note GetNote(ZCJoinSplit& params, + const libzcash::SpendingKey& sk, + const CTransaction& tx, size_t js, size_t n); +CWalletTx GetValidSpend(ZCJoinSplit& params, + const libzcash::SpendingKey& sk, + const libzcash::Note& note, CAmount value); diff --git a/src/wallet/gtest/test_wallet.cpp b/src/wallet/gtest/test_wallet.cpp index d30944954..9fdec6bd3 100644 --- a/src/wallet/gtest/test_wallet.cpp +++ b/src/wallet/gtest/test_wallet.cpp @@ -6,6 +6,7 @@ #include "chainparams.h" #include "main.h" #include "random.h" +#include "utiltest.h" #include "wallet/wallet.h" #include "zcash/JoinSplit.hpp" #include "zcash/Note.hpp" @@ -65,138 +66,17 @@ public: }; CWalletTx GetValidReceive(const libzcash::SpendingKey& sk, CAmount value, bool randomInputs) { - CMutableTransaction mtx; - mtx.nVersion = 2; // Enable JoinSplits - mtx.vin.resize(2); - if (randomInputs) { - mtx.vin[0].prevout.hash = GetRandHash(); - mtx.vin[1].prevout.hash = GetRandHash(); - } else { - mtx.vin[0].prevout.hash = uint256S("0000000000000000000000000000000000000000000000000000000000000001"); - mtx.vin[1].prevout.hash = uint256S("0000000000000000000000000000000000000000000000000000000000000002"); - } - mtx.vin[0].prevout.n = 0; - mtx.vin[1].prevout.n = 0; - - // Generate an ephemeral keypair. - uint256 joinSplitPubKey; - unsigned char joinSplitPrivKey[crypto_sign_SECRETKEYBYTES]; - crypto_sign_keypair(joinSplitPubKey.begin(), joinSplitPrivKey); - mtx.joinSplitPubKey = joinSplitPubKey; - - boost::array inputs = { - libzcash::JSInput(), // dummy input - libzcash::JSInput() // dummy input - }; - - boost::array outputs = { - libzcash::JSOutput(sk.address(), value), - libzcash::JSOutput(sk.address(), value) - }; - - boost::array output_notes; - - // Prepare JoinSplits - uint256 rt; - JSDescription jsdesc {*params, mtx.joinSplitPubKey, rt, - inputs, outputs, 2*value, 0, false}; - mtx.vjoinsplit.push_back(jsdesc); - - // Empty output script. - CScript scriptCode; - CTransaction signTx(mtx); - uint256 dataToBeSigned = SignatureHash(scriptCode, signTx, NOT_AN_INPUT, SIGHASH_ALL); - - // Add the signature - assert(crypto_sign_detached(&mtx.joinSplitSig[0], NULL, - dataToBeSigned.begin(), 32, - joinSplitPrivKey - ) == 0); - - CTransaction tx {mtx}; - CWalletTx wtx {NULL, tx}; - return wtx; + return GetValidReceive(*params, sk, value, randomInputs); } libzcash::Note GetNote(const libzcash::SpendingKey& sk, const CTransaction& tx, size_t js, size_t n) { - ZCNoteDecryption decryptor {sk.viewing_key()}; - auto hSig = tx.vjoinsplit[js].h_sig(*params, tx.joinSplitPubKey); - auto note_pt = libzcash::NotePlaintext::decrypt( - decryptor, - tx.vjoinsplit[js].ciphertexts[n], - tx.vjoinsplit[js].ephemeralKey, - hSig, - (unsigned char) n); - return note_pt.note(sk.address()); + return GetNote(*params, sk, tx, js, n); } CWalletTx GetValidSpend(const libzcash::SpendingKey& sk, const libzcash::Note& note, CAmount value) { - CMutableTransaction mtx; - mtx.vout.resize(2); - mtx.vout[0].nValue = value; - mtx.vout[1].nValue = 0; - - // Generate an ephemeral keypair. - uint256 joinSplitPubKey; - unsigned char joinSplitPrivKey[crypto_sign_SECRETKEYBYTES]; - crypto_sign_keypair(joinSplitPubKey.begin(), joinSplitPrivKey); - mtx.joinSplitPubKey = joinSplitPubKey; - - // Fake tree for the unused witness - ZCIncrementalMerkleTree tree; - - libzcash::JSOutput dummyout; - libzcash::JSInput dummyin; - - { - 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) { - libzcash::SpendingKey dummykey = libzcash::SpendingKey::random(); - libzcash::PaymentAddress dummyaddr = dummykey.address(); - libzcash::Note dummynote(dummyaddr.a_pk, (value - note.value), uint256(), uint256()); - tree.append(dummynote.cm()); - dummyin = libzcash::JSInput(tree.witness(), dummynote, dummykey); - } - } - - tree.append(note.cm()); - - boost::array inputs = { - libzcash::JSInput(tree.witness(), note, sk), - dummyin - }; - - boost::array outputs = { - dummyout, // dummy output - libzcash::JSOutput() // dummy output - }; - - boost::array output_notes; - - // Prepare JoinSplits - uint256 rt = tree.root(); - JSDescription jsdesc {*params, mtx.joinSplitPubKey, rt, - inputs, outputs, 0, value, false}; - mtx.vjoinsplit.push_back(jsdesc); - - // Empty output script. - CScript scriptCode; - CTransaction signTx(mtx); - uint256 dataToBeSigned = SignatureHash(scriptCode, signTx, NOT_AN_INPUT, SIGHASH_ALL); - - // Add the signature - assert(crypto_sign_detached(&mtx.joinSplitSig[0], NULL, - dataToBeSigned.begin(), 32, - joinSplitPrivKey - ) == 0); - CTransaction tx {mtx}; - CWalletTx wtx {NULL, tx}; - return wtx; + return GetValidSpend(*params, sk, note, value); } TEST(wallet_tests, setup_datadir_location_run_as_first_test) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d33c35781..6c1ce2d11 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2483,6 +2483,9 @@ Value zc_benchmark(const json_spirit::Array& params, bool fHelp) sample_times.push_back(benchmark_large_tx()); } else if (benchmarktype == "trydecryptnotes") { sample_times.push_back(benchmark_try_decrypt_notes(samplejoinsplit)); + } else if (benchmarktype == "incnotewitnesses") { + int nTxs = params[2].get_int(); + sample_times.push_back(benchmark_increment_note_witnesses(nTxs)); } else { throw JSONRPCError(RPC_TYPE_ERROR, "Invalid benchmarktype"); } diff --git a/src/zcbenchmarks.cpp b/src/zcbenchmarks.cpp index 6374141b8..61afb535d 100644 --- a/src/zcbenchmarks.cpp +++ b/src/zcbenchmarks.cpp @@ -17,6 +17,7 @@ #include "script/sign.h" #include "sodium.h" #include "streams.h" +#include "utiltest.h" #include "wallet/wallet.h" #include "zcbenchmarks.h" @@ -243,3 +244,45 @@ double benchmark_try_decrypt_notes(const JSDescription &joinsplit) return timer_stop(tv_start); } +double benchmark_increment_note_witnesses(size_t nTxs) +{ + CWallet wallet; + ZCIncrementalMerkleTree tree; + + auto sk = libzcash::SpendingKey::random(); + wallet.AddSpendingKey(sk); + + // First block + CBlock block1; + for (int i = 0; i < nTxs; i++) { + auto wtx = GetValidReceive(*pzcashParams, sk, 10, true); + auto note = GetNote(*pzcashParams, sk, wtx, 0, 1); + auto nullifier = note.nullifier(sk); + + mapNoteData_t noteData; + JSOutPoint jsoutpt {wtx.GetHash(), 0, 1}; + CNoteData nd {sk.address(), nullifier}; + noteData[jsoutpt] = nd; + + wtx.SetNoteData(noteData); + wallet.AddToWallet(wtx, true, NULL); + block1.vtx.push_back(wtx); + } + CBlockIndex index1(block1); + index1.nHeight = 1; + + // Increment to get transactions witnessed + wallet.ChainTip(&index1, &block1, tree, true); + + // Second block + CBlock block2; + block2.hashPrevBlock = block1.GetHash(); + CBlockIndex index2(block2); + index2.nHeight = 2; + + struct timeval tv_start; + timer_start(tv_start); + wallet.ChainTip(&index2, &block2, tree, true); + return timer_stop(tv_start); +} + diff --git a/src/zcbenchmarks.h b/src/zcbenchmarks.h index 9a99783ad..a1575e500 100644 --- a/src/zcbenchmarks.h +++ b/src/zcbenchmarks.h @@ -13,5 +13,6 @@ extern double benchmark_verify_joinsplit(const JSDescription &joinsplit); extern double benchmark_verify_equihash(); extern double benchmark_large_tx(); extern double benchmark_try_decrypt_notes(const JSDescription &joinsplit); +extern double benchmark_increment_note_witnesses(size_t nTxs); #endif From a513ea90d426ef449a0a8fd16aee22dfeeb21b97 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 7 Dec 2016 17:36:48 +1300 Subject: [PATCH 3/5] Fix indentation --- src/utiltest.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utiltest.cpp b/src/utiltest.cpp index 3ebbcf128..5cebc1a5d 100644 --- a/src/utiltest.cpp +++ b/src/utiltest.cpp @@ -51,9 +51,9 @@ CWalletTx GetValidReceive(ZCJoinSplit& params, // Add the signature assert(crypto_sign_detached(&mtx.joinSplitSig[0], NULL, - dataToBeSigned.begin(), 32, - joinSplitPrivKey - ) == 0); + dataToBeSigned.begin(), 32, + joinSplitPrivKey + ) == 0); CTransaction tx {mtx}; CWalletTx wtx {NULL, tx}; @@ -135,9 +135,9 @@ CWalletTx GetValidSpend(ZCJoinSplit& params, // Add the signature assert(crypto_sign_detached(&mtx.joinSplitSig[0], NULL, - dataToBeSigned.begin(), 32, - joinSplitPrivKey - ) == 0); + dataToBeSigned.begin(), 32, + joinSplitPrivKey + ) == 0); CTransaction tx {mtx}; CWalletTx wtx {NULL, tx}; return wtx; From 88b7f3c28bb6ca4f21b4d51f5ec23184b14b9373 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 9 Dec 2016 16:55:01 +1300 Subject: [PATCH 4/5] Generate JS for trydecryptnotes, make number of addresses a variable --- qa/zcash/performance-measurements.sh | 8 ++++---- src/wallet/rpcwallet.cpp | 6 +++--- src/zcbenchmarks.cpp | 11 ++++------- src/zcbenchmarks.h | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/qa/zcash/performance-measurements.sh b/qa/zcash/performance-measurements.sh index b65974078..851adef09 100755 --- a/qa/zcash/performance-measurements.sh +++ b/qa/zcash/performance-measurements.sh @@ -56,7 +56,7 @@ function zcashd_valgrind_stop { case "$1" in *) case "$2" in - verifyjoinsplit|trydecryptnotes) + verifyjoinsplit) zcashd_start RAWJOINSPLIT=$(zcash_rpc zcsamplejoinsplit) zcashd_stop @@ -89,7 +89,7 @@ case "$1" in zcash_rpc zcbenchmark validatelargetx 5 ;; trydecryptnotes) - zcash_rpc zcbenchmark trydecryptnotes 1000 "\"$RAWJOINSPLIT\"" + zcash_rpc zcbenchmark trydecryptnotes 1000 "${@:3}" ;; incnotewitnesses) zcash_rpc zcbenchmark incnotewitnesses 100 "${@:3}" @@ -123,7 +123,7 @@ case "$1" in zcash_rpc zcbenchmark verifyequihash 1 ;; trydecryptnotes) - zcash_rpc zcbenchmark trydecryptnotes 1 "\"$RAWJOINSPLIT\"" + zcash_rpc zcbenchmark trydecryptnotes 1 "${@:3}" ;; incnotewitnesses) zcash_rpc zcbenchmark incnotewitnesses 1 "${@:3}" @@ -158,7 +158,7 @@ case "$1" in zcash_rpc zcbenchmark verifyequihash 1 ;; trydecryptnotes) - zcash_rpc zcbenchmark trydecryptnotes 1 "\"$RAWJOINSPLIT\"" + zcash_rpc zcbenchmark trydecryptnotes 1 "${@:3}" ;; incnotewitnesses) zcash_rpc zcbenchmark incnotewitnesses 1 "${@:3}" diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6c1ce2d11..abd8a362e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2454,8 +2454,7 @@ Value zc_benchmark(const json_spirit::Array& params, bool fHelp) JSDescription samplejoinsplit; - if (benchmarktype == "verifyjoinsplit" || - benchmarktype == "trydecryptnotes") { + if (benchmarktype == "verifyjoinsplit") { CDataStream ss(ParseHexV(params[2].get_str(), "js"), SER_NETWORK, PROTOCOL_VERSION); ss >> samplejoinsplit; } @@ -2482,7 +2481,8 @@ Value zc_benchmark(const json_spirit::Array& params, bool fHelp) } else if (benchmarktype == "validatelargetx") { sample_times.push_back(benchmark_large_tx()); } else if (benchmarktype == "trydecryptnotes") { - sample_times.push_back(benchmark_try_decrypt_notes(samplejoinsplit)); + int nAddrs = params[2].get_int(); + sample_times.push_back(benchmark_try_decrypt_notes(nAddrs)); } else if (benchmarktype == "incnotewitnesses") { int nTxs = params[2].get_int(); sample_times.push_back(benchmark_increment_note_witnesses(nTxs)); diff --git a/src/zcbenchmarks.cpp b/src/zcbenchmarks.cpp index 61afb535d..8f324850b 100644 --- a/src/zcbenchmarks.cpp +++ b/src/zcbenchmarks.cpp @@ -224,19 +224,16 @@ double benchmark_large_tx() return timer_stop(tv_start); } -double benchmark_try_decrypt_notes(const JSDescription &joinsplit) +double benchmark_try_decrypt_notes(size_t nAddrs) { - const size_t NUM_ADDRS = 10; - CWallet wallet; - for (int i = 0; i < NUM_ADDRS; i++) { + for (int i = 0; i < nAddrs; i++) { auto sk = libzcash::SpendingKey::random(); wallet.AddSpendingKey(sk); } - CMutableTransaction mtx; - mtx.vjoinsplit.push_back(joinsplit); - CTransaction tx(mtx); + auto sk = libzcash::SpendingKey::random(); + auto tx = GetValidReceive(*pzcashParams, sk, 10, true); struct timeval tv_start; timer_start(tv_start); diff --git a/src/zcbenchmarks.h b/src/zcbenchmarks.h index a1575e500..318921002 100644 --- a/src/zcbenchmarks.h +++ b/src/zcbenchmarks.h @@ -12,7 +12,7 @@ extern std::vector benchmark_solve_equihash_threaded(int nThreads); extern double benchmark_verify_joinsplit(const JSDescription &joinsplit); extern double benchmark_verify_equihash(); extern double benchmark_large_tx(); -extern double benchmark_try_decrypt_notes(const JSDescription &joinsplit); +extern double benchmark_try_decrypt_notes(size_t nAddrs); extern double benchmark_increment_note_witnesses(size_t nTxs); #endif From 9755eb8292ee51148f4ebbbc7bfcfdb67bac5248 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 9 Dec 2016 16:55:55 +1300 Subject: [PATCH 5/5] Add JS to second block to ensure witnesses are incremented --- src/zcbenchmarks.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/zcbenchmarks.cpp b/src/zcbenchmarks.cpp index 8f324850b..decc33f35 100644 --- a/src/zcbenchmarks.cpp +++ b/src/zcbenchmarks.cpp @@ -274,6 +274,20 @@ double benchmark_increment_note_witnesses(size_t nTxs) // Second block CBlock block2; block2.hashPrevBlock = block1.GetHash(); + { + auto wtx = GetValidReceive(*pzcashParams, sk, 10, true); + auto note = GetNote(*pzcashParams, sk, wtx, 0, 1); + auto nullifier = note.nullifier(sk); + + mapNoteData_t noteData; + JSOutPoint jsoutpt {wtx.GetHash(), 0, 1}; + CNoteData nd {sk.address(), nullifier}; + noteData[jsoutpt] = nd; + + wtx.SetNoteData(noteData); + wallet.AddToWallet(wtx, true, NULL); + block2.vtx.push_back(wtx); + } CBlockIndex index2(block2); index2.nHeight = 2;