From 89bbd48eaecac1c123b49aee0e8185c7bfb276c6 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 24 Jan 2020 12:30:58 -0500 Subject: [PATCH] More libsnark removal changes to various internals --- src/primitives/transaction.cpp | 58 +------------------ src/primitives/transaction.h | 7 ++- src/utiltest.cpp | 5 +- .../asyncrpcoperation_mergetoaddress.cpp | 4 +- src/wallet/asyncrpcoperation_sendmany.cpp | 1 - .../asyncrpcoperation_shieldcoinbase.cpp | 1 - src/wallet/rpcwallet.cpp | 8 +-- 7 files changed, 13 insertions(+), 71 deletions(-) diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index ea24f9d23..2cde04f2c 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -27,7 +27,6 @@ #include "librustzcash.h" JSDescription::JSDescription( - bool makeGrothProof, ZCJoinSplit& params, const uint256& joinSplitPubKey, const uint256& anchor, @@ -42,7 +41,6 @@ JSDescription::JSDescription( std::array notes; proof = params.prove( - makeGrothProof, inputs, outputs, notes, @@ -62,7 +60,6 @@ JSDescription::JSDescription( } JSDescription JSDescription::Randomized( - bool makeGrothProof, ZCJoinSplit& params, const uint256& joinSplitPubKey, const uint256& anchor, @@ -87,71 +84,18 @@ JSDescription JSDescription::Randomized( MappedShuffle(outputs.begin(), outputMap.begin(), ZC_NUM_JS_OUTPUTS, gen); return JSDescription( - makeGrothProof, params, joinSplitPubKey, anchor, inputs, outputs, vpub_old, vpub_new, computeProof, esk // payment disclosure ); } -class SproutProofVerifier : public boost::static_visitor -{ - ZCJoinSplit& params; - libzcash::ProofVerifier& verifier; - const uint256& joinSplitPubKey; - const JSDescription& jsdesc; - -public: - SproutProofVerifier( - ZCJoinSplit& params, - libzcash::ProofVerifier& verifier, - const uint256& joinSplitPubKey, - const JSDescription& jsdesc - ) : params(params), jsdesc(jsdesc), verifier(verifier), joinSplitPubKey(joinSplitPubKey) {} - - bool operator()(const libzcash::PHGRProof& proof) const - { - return params.verify( - proof, - verifier, - joinSplitPubKey, - jsdesc.randomSeed, - jsdesc.macs, - jsdesc.nullifiers, - jsdesc.commitments, - jsdesc.vpub_old, - jsdesc.vpub_new, - jsdesc.anchor - ); - } - - bool operator()(const libzcash::GrothProof& proof) const - { - uint256 h_sig = params.h_sig(jsdesc.randomSeed, jsdesc.nullifiers, joinSplitPubKey); - - return librustzcash_sprout_verify( - proof.begin(), - jsdesc.anchor.begin(), - h_sig.begin(), - jsdesc.macs[0].begin(), - jsdesc.macs[1].begin(), - jsdesc.nullifiers[0].begin(), - jsdesc.nullifiers[1].begin(), - jsdesc.commitments[0].begin(), - jsdesc.commitments[1].begin(), - jsdesc.vpub_old, - jsdesc.vpub_new - ); - } -}; - bool JSDescription::Verify( ZCJoinSplit& params, libzcash::ProofVerifier& verifier, const uint256& joinSplitPubKey ) const { - auto pv = SproutProofVerifier(params, verifier, joinSplitPubKey, *this); - return boost::apply_visitor(pv, proof); + return false; } uint256 JSDescription::h_sig(ZCJoinSplit& params, const uint256& joinSplitPubKey) const diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 2bc7b48c6..2ece7b255 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -48,6 +48,11 @@ extern uint32_t ASSETCHAINS_MAGIC; extern std::string ASSETCHAINS_SELFIMPORT; +#define JOINSPLIT_SIZE GetSerializeSize(JSDescription(), SER_NETWORK, PROTOCOL_VERSION) +#define OUTPUTDESCRIPTION_SIZE GetSerializeSize(OutputDescription(), SER_NETWORK, PROTOCOL_VERSION) +#define SPENDDESCRIPTION_SIZE GetSerializeSize(SpendDescription(), SER_NETWORK, PROTOCOL_VERSION) + + // Overwinter transaction version static const int32_t OVERWINTER_TX_VERSION = 3; static_assert(OVERWINTER_TX_VERSION >= OVERWINTER_MIN_TX_VERSION, @@ -252,7 +257,6 @@ public: JSDescription(): vpub_old(0), vpub_new(0) { } JSDescription( - bool makeGrothProof, ZCJoinSplit& params, const uint256& joinSplitPubKey, const uint256& rt, @@ -265,7 +269,6 @@ public: ); static JSDescription Randomized( - bool makeGrothProof, ZCJoinSplit& params, const uint256& joinSplitPubKey, const uint256& rt, diff --git a/src/utiltest.cpp b/src/utiltest.cpp index 898f2c4c9..ead7fe6a0 100644 --- a/src/utiltest.cpp +++ b/src/utiltest.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2016 The Zcash developers +// Copyright (c) 2019-2020 The Hush developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -43,7 +44,7 @@ CWalletTx GetValidReceive(ZCJoinSplit& params, // Prepare JoinSplits uint256 rt; - JSDescription jsdesc {false, params, mtx.joinSplitPubKey, rt, + JSDescription jsdesc {params, mtx.joinSplitPubKey, rt, inputs, outputs, 2*value, 0, false}; mtx.vjoinsplit.push_back(jsdesc); @@ -132,7 +133,7 @@ CWalletTx GetValidSpend(ZCJoinSplit& params, // Prepare JoinSplits uint256 rt = tree.root(); - JSDescription jsdesc {false, params, mtx.joinSplitPubKey, rt, + JSDescription jsdesc {params, mtx.joinSplitPubKey, rt, inputs, outputs, 0, value, false}; mtx.vjoinsplit.push_back(jsdesc); diff --git a/src/wallet/asyncrpcoperation_mergetoaddress.cpp b/src/wallet/asyncrpcoperation_mergetoaddress.cpp index afac9c6eb..2e77195f3 100644 --- a/src/wallet/asyncrpcoperation_mergetoaddress.cpp +++ b/src/wallet/asyncrpcoperation_mergetoaddress.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2017 The Zcash developers +// Copyright (c) 2019-2020 The Hush developers // Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. +// file COPYING or https://www.opensource.org/licenses/mit-license.php . /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * @@ -927,7 +928,6 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit( uint256 esk; // payment disclosure - secret JSDescription jsdesc = JSDescription::Randomized( - mtx.fOverwintered && (mtx.nVersion >= SAPLING_TX_VERSION), *pzcashParams, joinSplitPubKey_, anchor, diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index 82a7c9212..db7f7bd66 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -1258,7 +1258,6 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit( uint256 esk; // payment disclosure - secret JSDescription jsdesc = JSDescription::Randomized( - mtx.fOverwintered && (mtx.nVersion >= SAPLING_TX_VERSION), *pzcashParams, joinSplitPubKey_, anchor, diff --git a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp index 6db4eb6c0..55feb2cbf 100644 --- a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp +++ b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp @@ -455,7 +455,6 @@ UniValue AsyncRPCOperation_shieldcoinbase::perform_joinsplit(ShieldCoinbaseJSInf uint256 esk; // payment disclosure - secret JSDescription jsdesc = JSDescription::Randomized( - mtx.fOverwintered && (mtx.nVersion >= SAPLING_TX_VERSION), *pzcashParams, joinSplitPubKey_, anchor, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 866e01d58..88cfbe504 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3245,8 +3245,7 @@ UniValue zc_sample_joinsplit(const UniValue& params, bool fHelp, const CPubKey& uint256 joinSplitPubKey; uint256 anchor = SproutMerkleTree().root(); - JSDescription samplejoinsplit(true, - *pzcashParams, + JSDescription samplejoinsplit(*pzcashParams, joinSplitPubKey, anchor, {JSInput(), JSInput()}, @@ -3306,8 +3305,6 @@ UniValue zc_benchmark(const UniValue& params, bool fHelp, const CPubKey& mypk) for (int i = 0; i < samplecount; i++) { if (benchmarktype == "sleep") { sample_times.push_back(benchmark_sleep()); - } else if (benchmarktype == "parameterloading") { - sample_times.push_back(benchmark_parameter_loading()); } else if (benchmarktype == "createjoinsplit") { if (params.size() < 3) { sample_times.push_back(benchmark_create_joinsplit()); @@ -3605,8 +3602,7 @@ UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp, const CPubKey& myp mtx.nVersion = 2; mtx.joinSplitPubKey = joinSplitPubKey; - JSDescription jsdesc(false, - *pzcashParams, + JSDescription jsdesc(*pzcashParams, joinSplitPubKey, anchor, {vjsin[0], vjsin[1]},