[zk] Replace pzcashParams pointer with unique_ptr

This commit is contained in:
Jon Layton 2018-07-14 16:31:39 -05:00
parent 88bc234adf
commit 3bf7e8586f
6 changed files with 19 additions and 22 deletions

View File

@ -32,7 +32,7 @@ bool CheckTransactionJoinsplits(const CTransaction& tx, CValidationState &state)
// Ensure that zk-SNARKs verify
auto verifier = libzcash::ProofVerifier::Strict();
for(const JSDescription &joinsplit : tx.vjoinsplit) {
if (!joinsplit.Verify(*pzcashParams, verifier, tx.joinSplitPubKey)) {
if (!joinsplit.Verify(pzcashParams.get(), verifier, tx.joinSplitPubKey)) {
return state.DoS(100, error("CheckTransaction(): joinsplit does not verify"),
REJECT_INVALID, "bad-txns-joinsplit-verification-failed");
}

View File

@ -74,6 +74,8 @@ static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false;
std::unique_ptr<CConnman> g_connman;
std::unique_ptr<PeerLogicValidation> peerLogic;
std::unique_ptr<ZCJoinSplit> pzcashParams;
#if !(ENABLE_WALLET)
class DummyWalletInit : public WalletInitInterface {
public:
@ -92,8 +94,6 @@ public:
const WalletInitInterface& g_wallet_init_interface = DummyWalletInit();
#endif
ZCJoinSplit* pzcashParams = nullptr;
#if ENABLE_ZMQ
static CZMQNotificationInterface* pzmqNotificationInterface = nullptr;
#endif
@ -294,9 +294,6 @@ void Shutdown()
g_wallet_init_interface.Close();
globalVerifyHandle.reset();
delete pzcashParams;
pzcashParams = nullptr;
ECC_Stop();
LogPrintf("%s: done\n", __func__);
}
@ -728,7 +725,7 @@ static void ZC_LoadParams()
LogPrintf("Loading verifying key from %s\n", vk_path.string().c_str());
gettimeofday(&tv_start, 0);
pzcashParams = ZCJoinSplit::Prepared(vk_path.string(), pk_path.string());
pzcashParams = std::unique_ptr<ZCJoinSplit>(ZCJoinSplit::Prepared(vk_path.string(), pk_path.string()));
gettimeofday(&tv_end, 0);
elapsed = float(tv_end.tv_sec-tv_start.tv_sec) + (tv_end.tv_usec-tv_start.tv_usec)/float(1000000);

View File

@ -23,7 +23,7 @@ namespace boost
class thread_group;
} // namespace boost
extern ZCJoinSplit* pzcashParams;
extern std::unique_ptr<ZCJoinSplit> pzcashParams;
void StartShutdown();
bool ShutdownRequested();

View File

@ -454,7 +454,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
// Decrypt the change note's ciphertext to retrieve some data we need
ZCNoteDecryption decryptor(changeKey.receiving_key());
auto hSig = prevJoinSplit.h_sig(*pzcashParams, tx_.joinSplitPubKey);
auto hSig = prevJoinSplit.h_sig(pzcashParams.get(), tx_.joinSplitPubKey);
try {
NotePlaintext plaintext = NotePlaintext::decrypt(
decryptor,
@ -770,7 +770,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(
uint256 esk; // payment disclosure - secret
JSDescription jsdesc = JSDescription::Randomized(
*pzcashParams,
pzcashParams.get(),
joinSplitPubKey_,
anchor,
inputs,
@ -783,7 +783,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(
&esk); // parameter expects pointer to esk, so pass in address
{
auto verifier = libzcash::ProofVerifier::Strict();
if (!(jsdesc.Verify(*pzcashParams, verifier, joinSplitPubKey_))) {
if (!(jsdesc.Verify(pzcashParams.get(), verifier, joinSplitPubKey_))) {
throw std::runtime_error("error verifying joinsplit");
}
}
@ -822,7 +822,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(
ss2 << ((unsigned char)0x00);
ss2 << jsdesc.ephemeralKey;
ss2 << jsdesc.ciphertexts[0];
ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey_);
ss2 << jsdesc.h_sig(pzcashParams.get(), joinSplitPubKey_);
encryptedNote1 = HexStr(ss2.begin(), ss2.end());
}
@ -831,7 +831,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(
ss2 << ((unsigned char)0x01);
ss2 << jsdesc.ephemeralKey;
ss2 << jsdesc.ciphertexts[1];
ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey_);
ss2 << jsdesc.h_sig(pzcashParams.get(), joinSplitPubKey_);
encryptedNote2 = HexStr(ss2.begin(), ss2.end());
}

View File

@ -568,7 +568,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
// Decrypt the change note's ciphertext to retrieve some data we need
ZCNoteDecryption decryptor(spendingkey_.receiving_key());
auto hSig = prevJoinSplit.h_sig(*pzcashParams, tx_.joinSplitPubKey);
auto hSig = prevJoinSplit.h_sig(pzcashParams.get(), tx_.joinSplitPubKey);
try {
NotePlaintext plaintext = NotePlaintext::decrypt(
decryptor,
@ -982,7 +982,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(
uint256 esk; // payment disclosure - secret
JSDescription jsdesc = JSDescription::Randomized(
*pzcashParams,
pzcashParams.get(),
joinSplitPubKey_,
anchor,
inputs,
@ -995,7 +995,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(
&esk); // parameter expects pointer to esk, so pass in address
{
auto verifier = libzcash::ProofVerifier::Strict();
if (!(jsdesc.Verify(*pzcashParams, verifier, joinSplitPubKey_))) {
if (!(jsdesc.Verify(pzcashParams.get(), verifier, joinSplitPubKey_))) {
throw std::runtime_error("error verifying joinsplit");
}
}
@ -1038,7 +1038,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(
ss2 << ((unsigned char) 0x00);
ss2 << jsdesc.ephemeralKey;
ss2 << jsdesc.ciphertexts[0];
ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey_);
ss2 << jsdesc.h_sig(pzcashParams.get(), joinSplitPubKey_);
encryptedNote1 = HexStr(ss2.begin(), ss2.end());
}
@ -1047,7 +1047,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(
ss2 << ((unsigned char) 0x01);
ss2 << jsdesc.ephemeralKey;
ss2 << jsdesc.ciphertexts[1];
ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey_);
ss2 << jsdesc.h_sig(pzcashParams.get(), joinSplitPubKey_);
encryptedNote2 = HexStr(ss2.begin(), ss2.end());
}

View File

@ -354,7 +354,7 @@ UniValue AsyncRPCOperation_shieldcoinbase::perform_joinsplit(ShieldCoinbaseJSInf
uint256 esk; // payment disclosure - secret
JSDescription jsdesc = JSDescription::Randomized(
*pzcashParams,
pzcashParams.get(),
joinSplitPubKey_,
anchor,
inputs,
@ -367,7 +367,7 @@ UniValue AsyncRPCOperation_shieldcoinbase::perform_joinsplit(ShieldCoinbaseJSInf
&esk); // parameter expects pointer to esk, so pass in address
{
auto verifier = libzcash::ProofVerifier::Strict();
if (!(jsdesc.Verify(*pzcashParams, verifier, joinSplitPubKey_))) {
if (!(jsdesc.Verify(pzcashParams.get(), verifier, joinSplitPubKey_))) {
throw std::runtime_error("error verifying joinsplit");
}
}
@ -410,7 +410,7 @@ UniValue AsyncRPCOperation_shieldcoinbase::perform_joinsplit(ShieldCoinbaseJSInf
ss2 << ((unsigned char) 0x00);
ss2 << jsdesc.ephemeralKey;
ss2 << jsdesc.ciphertexts[0];
ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey_);
ss2 << jsdesc.h_sig(pzcashParams.get(), joinSplitPubKey_);
encryptedNote1 = HexStr(ss2.begin(), ss2.end());
}
@ -419,7 +419,7 @@ UniValue AsyncRPCOperation_shieldcoinbase::perform_joinsplit(ShieldCoinbaseJSInf
ss2 << ((unsigned char) 0x01);
ss2 << jsdesc.ephemeralKey;
ss2 << jsdesc.ciphertexts[1];
ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey_);
ss2 << jsdesc.h_sig(pzcashParams.get(), joinSplitPubKey_);
encryptedNote2 = HexStr(ss2.begin(), ss2.end());
}