From 5db5e42ec325d45f40a5f91fd8e454a9714ad0ba Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 24 Aug 2016 15:49:38 +1200 Subject: [PATCH] Add optional bool to disable computation of proof in JSDescription constructor --- src/primitives/transaction.cpp | 10 +++++++--- src/primitives/transaction.h | 3 ++- src/zcash/JoinSplit.cpp | 9 +++++++-- src/zcash/JoinSplit.hpp | 3 ++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 854a0be66..5c1f94758 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -15,11 +15,14 @@ JSDescription::JSDescription(ZCJoinSplit& params, const boost::array& inputs, const boost::array& outputs, CAmount vpub_old, - CAmount vpub_new) : vpub_old(vpub_old), vpub_new(vpub_new), anchor(anchor) + CAmount vpub_new, + bool computeProof) : vpub_old(vpub_old), vpub_new(vpub_new), anchor(anchor) { boost::array notes; - params.loadProvingKey(); + if (computeProof) { + params.loadProvingKey(); + } proof = params.prove( inputs, outputs, @@ -33,7 +36,8 @@ JSDescription::JSDescription(ZCJoinSplit& params, commitments, vpub_old, vpub_new, - anchor + anchor, + computeProof ); } diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index c88b26d17..44375fc63 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -74,7 +74,8 @@ public: const boost::array& inputs, const boost::array& outputs, CAmount vpub_old, - CAmount vpub_new + CAmount vpub_new, + bool computeProof = true // Set to false in some tests ); // Verifies that the JoinSplit proof is correct. diff --git a/src/zcash/JoinSplit.cpp b/src/zcash/JoinSplit.cpp index b103581b3..71c1ae0ad 100644 --- a/src/zcash/JoinSplit.cpp +++ b/src/zcash/JoinSplit.cpp @@ -173,9 +173,10 @@ public: boost::array& out_commitments, uint64_t vpub_old, uint64_t vpub_new, - const uint256& rt + const uint256& rt, + bool computeProof ) { - if (!pk) { + if (computeProof && !pk) { throw std::runtime_error("JoinSplit proving key not loaded"); } @@ -231,6 +232,10 @@ public: out_macs[i] = PRF_pk(inputs[i].key, i, h_sig); } + if (!computeProof) { + return ZCProof(); + } + protoboard pb; { joinsplit_gadget g(pb); diff --git a/src/zcash/JoinSplit.hpp b/src/zcash/JoinSplit.hpp index e9e89c62d..1b655728d 100644 --- a/src/zcash/JoinSplit.hpp +++ b/src/zcash/JoinSplit.hpp @@ -73,7 +73,8 @@ public: boost::array& out_commitments, uint64_t vpub_old, uint64_t vpub_new, - const uint256& rt + const uint256& rt, + bool computeProof = true ) = 0; virtual bool verify(