#include "utiltest.h"
#include "consensus/upgrades.h"
+#include "transaction_builder.h"
#include <array>
CWalletTx wtx {NULL, tx};
return wtx;
}
+
+CWalletTx GetValidSaplingTx(const Consensus::Params& consensusParams,
+ const libzcash::SaplingExtendedSpendingKey &sk,
+ CAmount value) {
+ auto expsk = sk.expsk;
+ auto fvk = expsk.full_viewing_key();
+ auto pk = sk.DefaultAddress();
+
+ // Generate dummy Sapling note
+ libzcash::SaplingNote note(pk, value);
+ auto cm = note.cm().get();
+ SaplingMerkleTree tree;
+ tree.append(cm);
+ auto anchor = tree.root();
+ auto witness = tree.witness();
+
+ auto builder = TransactionBuilder(consensusParams, 1);
+ builder.SetFee(0);
+ assert(builder.AddSaplingSpend(expsk, note, anchor, witness));
+ builder.AddSaplingOutput(fvk.ovk, pk, value, {});
+
+ CTransaction tx = builder.Build().get();
+ CWalletTx wtx {NULL, tx};
+ return wtx;
+}
#include "zcash/JoinSplit.hpp"
#include "zcash/Note.hpp"
#include "zcash/NoteEncryption.hpp"
+#include "zcash/zip32.h"
+// Sprout
CWalletTx GetValidSproutReceive(ZCJoinSplit& params,
const libzcash::SproutSpendingKey& sk,
CAmount value,
const libzcash::SproutSpendingKey& sk,
const libzcash::SproutNote& note,
CAmount value);
+
+// Sapling
+CWalletTx GetValidSaplingTx(const Consensus::Params& consensusParams,
+ const libzcash::SaplingExtendedSpendingKey &sk,
+ CAmount value);
sample_times.push_back(benchmark_large_tx(nInputs));
} else if (benchmarktype == "trydecryptnotes") {
int nAddrs = params[2].get_int();
- sample_times.push_back(benchmark_try_decrypt_notes(nAddrs));
+ sample_times.push_back(benchmark_try_decrypt_sprout_notes(nAddrs));
+ } else if (benchmarktype == "trydecryptsaplingnotes") {
+ int nAddrs = params[2].get_int();
+ sample_times.push_back(benchmark_try_decrypt_sapling_notes(nAddrs));
} else if (benchmarktype == "incnotewitnesses") {
int nTxs = params[2].get_int();
sample_times.push_back(benchmark_increment_note_witnesses(nTxs));
return timer_stop(tv_start);
}
-double benchmark_try_decrypt_notes(size_t nAddrs)
+double benchmark_try_decrypt_sprout_notes(size_t nAddrs)
{
CWallet wallet;
for (int i = 0; i < nAddrs; i++) {
return timer_stop(tv_start);
}
+double benchmark_try_decrypt_sapling_notes(size_t nAddrs)
+{
+ // Set params
+ SelectParams(CBaseChainParams::REGTEST);
+ UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
+ UpdateNetworkUpgradeParameters(Consensus::UPGRADE_SAPLING, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
+ auto consensusParams = Params().GetConsensus();
+
+ std::vector<unsigned char, secure_allocator<unsigned char>> rawSeed(32);
+ HDSeed seed(rawSeed);
+ auto masterKey = libzcash::SaplingExtendedSpendingKey::Master(seed);
+
+ CWallet wallet;
+ wallet.AddSaplingSpendingKey(masterKey, masterKey.DefaultAddress());
+
+ int i;
+ for (i = 0; i < nAddrs; i++) {
+ auto sk = masterKey.Derive(i);
+ wallet.AddSaplingSpendingKey(sk, sk.DefaultAddress());
+ }
+
+ auto sk = masterKey.Derive(i);
+ auto tx = GetValidSaplingTx(consensusParams, sk, 10);
+
+ struct timeval tv_start;
+ timer_start(tv_start);
+ auto saplingNoteDataAndAddressesToAdd = wallet.FindMySaplingNotes(tx);
+ double tv_stop = timer_stop(tv_start);
+
+ // Revert to default
+ UpdateNetworkUpgradeParameters(Consensus::UPGRADE_SAPLING, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT);
+ UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT);
+
+ return tv_stop;
+}
+
double benchmark_increment_note_witnesses(size_t nTxs)
{
CWallet wallet;
extern double benchmark_verify_joinsplit(const JSDescription &joinsplit);
extern double benchmark_verify_equihash();
extern double benchmark_large_tx(size_t nInputs);
-extern double benchmark_try_decrypt_notes(size_t nAddrs);
+extern double benchmark_try_decrypt_sprout_notes(size_t nAddrs);
+extern double benchmark_try_decrypt_sapling_notes(size_t nAddrs);
extern double benchmark_increment_note_witnesses(size_t nTxs);
extern double benchmark_connectblock_slow();
extern double benchmark_sendtoaddress(CAmount amount);