diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index 106b7bfac73b..58ed547e112c 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -275,8 +275,8 @@ bool CActiveMasternode::CreateBroadcast(std::string strService, std::string strK bool CActiveMasternode::CreateBroadcast(CTxIn vin, CService service, CKey keyCollateralAddress, CPubKey pubKeyCollateralAddress, CKey keyMasternode, CPubKey pubKeyMasternode, std::string& errorMessage, CMasternodeBroadcast &mnb) { - // wait for reindex and/or import to finish - if (fImporting || fReindex) return false; + // wait for reindex and/or import to finish + if (fImporting || fReindex) return false; CMasternodePing mnp(vin); if (!mnp.Sign(keyMasternode, pubKeyMasternode)) { @@ -343,8 +343,8 @@ bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secr bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secretKey, std::string strTxHash, std::string strOutputIndex) { - // wait for reindex and/or import to finish - if (fImporting || fReindex) return false; + // wait for reindex and/or import to finish + if (fImporting || fReindex) return false; // Find possible candidates TRY_LOCK(pwalletMain->cs_wallet, fWallet); @@ -395,8 +395,8 @@ bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secr // Extract Masternode vin information from output bool CActiveMasternode::GetVinFromOutput(COutput out, CTxIn& vin, CPubKey& pubkey, CKey& secretKey) { - // wait for reindex and/or import to finish - if (fImporting || fReindex) return false; + // wait for reindex and/or import to finish + if (fImporting || fReindex) return false; CScript pubScript; diff --git a/src/chainparams.cpp b/src/chainparams.cpp index eff148760d95..b336fbfb4692 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -224,7 +224,7 @@ class CMainParams : public CChainParams base58Prefixes[SECRET_KEY] = std::vector(1, 212); base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x02)(0x2D)(0x25)(0x33).convert_to_container >(); base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x02)(0x21)(0x31)(0x2B).convert_to_container >(); - // BIP44 coin type is from https://github.com/satoshilabs/slips/blob/master/slip-0044.md + // BIP44 coin type is from https://github.com/satoshilabs/slips/blob/master/slip-0044.md base58Prefixes[EXT_COIN_TYPE] = boost::assign::list_of(0x80)(0x00)(0x00)(0x77).convert_to_container >(); convertSeed6(vFixedSeeds, pnSeed6_main, ARRAYLEN(pnSeed6_main)); diff --git a/src/init.cpp b/src/init.cpp index 83f4ecdad3ac..30c9d92e0c37 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1116,7 +1116,7 @@ bool AppInit2() try { boost::filesystem::copy_file(sourceFile, backupFile); LogPrintf("Creating backup of %s -> %s\n", sourceFile, backupFile); - } catch (boost::filesystem::filesystem_error& error) { + } catch (const boost::filesystem::filesystem_error& error) { LogPrintf("Failed to create backup %s\n", error.what()); } #else @@ -1152,7 +1152,7 @@ bool AppInit2() try { boost::filesystem::remove(file.second); LogPrintf("Old backup deleted: %s\n", file.second); - } catch (boost::filesystem::filesystem_error& error) { + } catch (const boost::filesystem::filesystem_error& error) { LogPrintf("Failed to delete backup %s\n", error.what()); } } @@ -1190,7 +1190,7 @@ bool AppInit2() boost::filesystem::remove_all(zerocoinDir); LogPrintf("-resync: folder deleted: %s\n", zerocoinDir.string().c_str()); } - } catch (boost::filesystem::filesystem_error& error) { + } catch (const boost::filesystem::filesystem_error& error) { LogPrintf("Failed to delete blockchain folders %s\n", error.what()); } } @@ -1205,7 +1205,7 @@ bool AppInit2() try { boost::filesystem::rename(pathDatabase, pathDatabaseBak); LogPrintf("Moved old %s to %s. Retrying.\n", pathDatabase.string(), pathDatabaseBak.string()); - } catch (boost::filesystem::filesystem_error& error) { + } catch (const boost::filesystem::filesystem_error& error) { // failure is ok (well, not really, but it's not worse than what we started with) } @@ -1569,7 +1569,7 @@ bool AppInit2() break; } } - } catch (std::exception& e) { + } catch (const std::exception& e) { if (fDebug) LogPrintf("%s\n", e.what()); strLoadError = _("Error opening block database"); fVerifyingBlocks = false; diff --git a/src/libzerocoin/AccumulatorProofOfKnowledge.cpp b/src/libzerocoin/AccumulatorProofOfKnowledge.cpp index 4dcb139449f6..657ba8a019ba 100644 --- a/src/libzerocoin/AccumulatorProofOfKnowledge.cpp +++ b/src/libzerocoin/AccumulatorProofOfKnowledge.cpp @@ -21,16 +21,16 @@ AccumulatorProofOfKnowledge::AccumulatorProofOfKnowledge(const AccumulatorAndPro AccumulatorProofOfKnowledge::AccumulatorProofOfKnowledge(const AccumulatorAndProofParams* p, const Commitment& commitmentToCoin, const AccumulatorWitness& witness): params(p) { - CBigNum sg = params->accumulatorPoKCommitmentGroup.g; - CBigNum sh = params->accumulatorPoKCommitmentGroup.h; + CBigNum sg = params->accumulatorPoKCommitmentGroup.g; + CBigNum sh = params->accumulatorPoKCommitmentGroup.h; - CBigNum g_n = params->accumulatorQRNCommitmentGroup.g; - CBigNum h_n = params->accumulatorQRNCommitmentGroup.h; + CBigNum g_n = params->accumulatorQRNCommitmentGroup.g; + CBigNum h_n = params->accumulatorQRNCommitmentGroup.h; - CBigNum e = commitmentToCoin.getContents(); - CBigNum r = commitmentToCoin.getRandomness(); + CBigNum e = commitmentToCoin.getContents(); + CBigNum r = commitmentToCoin.getRandomness(); - CBigNum aM_4 = params->accumulatorModulus/CBigNum((long)4); + CBigNum aM_4 = params->accumulatorModulus/CBigNum((long)4); CBigNum aR = CBigNum(2).pow(params->k_prime + params->k_dprime); CBigNum aR_t_aM_4 = aM_4 * aR; @@ -38,105 +38,105 @@ AccumulatorProofOfKnowledge::AccumulatorProofOfKnowledge(const AccumulatorAndPro CBigNum r_2 = CBigNum::randBignum(aM_4); CBigNum r_3 = CBigNum::randBignum(aM_4); - this->C_e = g_n.pow_mod(e, params->accumulatorModulus) * h_n.pow_mod(r_1, params->accumulatorModulus); - this->C_u = witness.getValue() * h_n.pow_mod(r_2, params->accumulatorModulus); - this->C_r = g_n.pow_mod(r_2, params->accumulatorModulus) * h_n.pow_mod(r_3, params->accumulatorModulus); + this->C_e = g_n.pow_mod(e, params->accumulatorModulus) * h_n.pow_mod(r_1, params->accumulatorModulus); + this->C_u = witness.getValue() * h_n.pow_mod(r_2, params->accumulatorModulus); + this->C_r = g_n.pow_mod(r_2, params->accumulatorModulus) * h_n.pow_mod(r_3, params->accumulatorModulus); CBigNum r_alpha = CBigNum::randBignum(params->maxCoinValue * aR); - if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { - r_alpha = 0-r_alpha; - } + if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { + r_alpha = 0-r_alpha; + } - CBigNum r_gamma = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus); - CBigNum r_phi = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus); - CBigNum r_psi = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus); - CBigNum r_sigma = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus); - CBigNum r_xi = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus); + CBigNum r_gamma = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus); + CBigNum r_phi = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus); + CBigNum r_psi = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus); + CBigNum r_sigma = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus); + CBigNum r_xi = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus); CBigNum r_epsilon = CBigNum::randBignum(aR_t_aM_4); - if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { - r_epsilon = 0-r_epsilon; - } + if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { + r_epsilon = 0-r_epsilon; + } CBigNum r_eta = CBigNum::randBignum(aR_t_aM_4); - if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { - r_eta = 0-r_eta; - } + if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { + r_eta = 0-r_eta; + } CBigNum r_zeta = CBigNum::randBignum(aR_t_aM_4); - if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { - r_zeta = 0-r_zeta; - } + if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { + r_zeta = 0-r_zeta; + } CBigNum r_beta = CBigNum::randBignum(aR_t_aM_4 * params->accumulatorPoKCommitmentGroup.modulus); - if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { - r_beta = 0-r_beta; - } + if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { + r_beta = 0-r_beta; + } CBigNum r_delta = CBigNum::randBignum(aR_t_aM_4 * params->accumulatorPoKCommitmentGroup.modulus); - if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { - r_delta = 0-r_delta; - } - - this->st_1 = (sg.pow_mod(r_alpha, params->accumulatorPoKCommitmentGroup.modulus) * sh.pow_mod(r_phi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; - this->st_2 = (((commitmentToCoin.getCommitmentValue() * sg.inverse(params->accumulatorPoKCommitmentGroup.modulus)).pow_mod(r_gamma, params->accumulatorPoKCommitmentGroup.modulus)) * sh.pow_mod(r_psi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; - this->st_3 = ((sg * commitmentToCoin.getCommitmentValue()).pow_mod(r_sigma, params->accumulatorPoKCommitmentGroup.modulus) * sh.pow_mod(r_xi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; - - this->t_1 = (h_n.pow_mod(r_zeta, params->accumulatorModulus) * g_n.pow_mod(r_epsilon, params->accumulatorModulus)) % params->accumulatorModulus; - this->t_2 = (h_n.pow_mod(r_eta, params->accumulatorModulus) * g_n.pow_mod(r_alpha, params->accumulatorModulus)) % params->accumulatorModulus; - this->t_3 = (C_u.pow_mod(r_alpha, params->accumulatorModulus) * ((h_n.inverse(params->accumulatorModulus)).pow_mod(r_beta, params->accumulatorModulus))) % params->accumulatorModulus; - this->t_4 = (C_r.pow_mod(r_alpha, params->accumulatorModulus) * ((h_n.inverse(params->accumulatorModulus)).pow_mod(r_delta, params->accumulatorModulus)) * ((g_n.inverse(params->accumulatorModulus)).pow_mod(r_beta, params->accumulatorModulus))) % params->accumulatorModulus; - - CHashWriter hasher(0,0); - hasher << *params << sg << sh << g_n << h_n << commitmentToCoin.getCommitmentValue() << C_e << C_u << C_r << st_1 << st_2 << st_3 << t_1 << t_2 << t_3 << t_4; - - //According to the proof, this hash should be of length k_prime bits. It is currently greater than that, which should not be a problem, but we should check this. - CBigNum c = CBigNum(hasher.GetHash()); - - this->s_alpha = r_alpha - c*e; - this->s_beta = r_beta - c*r_2*e; - this->s_zeta = r_zeta - c*r_3; - this->s_sigma = r_sigma - c*((e+1).inverse(params->accumulatorPoKCommitmentGroup.groupOrder)); - this->s_eta = r_eta - c*r_1; - this->s_epsilon = r_epsilon - c*r_2; - this->s_delta = r_delta - c*r_3*e; - this->s_xi = r_xi + c*r*((e+1).inverse(params->accumulatorPoKCommitmentGroup.groupOrder)); - this->s_phi = (r_phi - c*r) % params->accumulatorPoKCommitmentGroup.groupOrder; - this->s_gamma = r_gamma - c*((e-1).inverse(params->accumulatorPoKCommitmentGroup.groupOrder)); - this->s_psi = r_psi + c*r*((e-1).inverse(params->accumulatorPoKCommitmentGroup.groupOrder)); + if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { + r_delta = 0-r_delta; + } + + this->st_1 = (sg.pow_mod(r_alpha, params->accumulatorPoKCommitmentGroup.modulus) * sh.pow_mod(r_phi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; + this->st_2 = (((commitmentToCoin.getCommitmentValue() * sg.inverse(params->accumulatorPoKCommitmentGroup.modulus)).pow_mod(r_gamma, params->accumulatorPoKCommitmentGroup.modulus)) * sh.pow_mod(r_psi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; + this->st_3 = ((sg * commitmentToCoin.getCommitmentValue()).pow_mod(r_sigma, params->accumulatorPoKCommitmentGroup.modulus) * sh.pow_mod(r_xi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; + + this->t_1 = (h_n.pow_mod(r_zeta, params->accumulatorModulus) * g_n.pow_mod(r_epsilon, params->accumulatorModulus)) % params->accumulatorModulus; + this->t_2 = (h_n.pow_mod(r_eta, params->accumulatorModulus) * g_n.pow_mod(r_alpha, params->accumulatorModulus)) % params->accumulatorModulus; + this->t_3 = (C_u.pow_mod(r_alpha, params->accumulatorModulus) * ((h_n.inverse(params->accumulatorModulus)).pow_mod(r_beta, params->accumulatorModulus))) % params->accumulatorModulus; + this->t_4 = (C_r.pow_mod(r_alpha, params->accumulatorModulus) * ((h_n.inverse(params->accumulatorModulus)).pow_mod(r_delta, params->accumulatorModulus)) * ((g_n.inverse(params->accumulatorModulus)).pow_mod(r_beta, params->accumulatorModulus))) % params->accumulatorModulus; + + CHashWriter hasher(0,0); + hasher << *params << sg << sh << g_n << h_n << commitmentToCoin.getCommitmentValue() << C_e << C_u << C_r << st_1 << st_2 << st_3 << t_1 << t_2 << t_3 << t_4; + + //According to the proof, this hash should be of length k_prime bits. It is currently greater than that, which should not be a problem, but we should check this. + CBigNum c = CBigNum(hasher.GetHash()); + + this->s_alpha = r_alpha - c*e; + this->s_beta = r_beta - c*r_2*e; + this->s_zeta = r_zeta - c*r_3; + this->s_sigma = r_sigma - c*((e+1).inverse(params->accumulatorPoKCommitmentGroup.groupOrder)); + this->s_eta = r_eta - c*r_1; + this->s_epsilon = r_epsilon - c*r_2; + this->s_delta = r_delta - c*r_3*e; + this->s_xi = r_xi + c*r*((e+1).inverse(params->accumulatorPoKCommitmentGroup.groupOrder)); + this->s_phi = (r_phi - c*r) % params->accumulatorPoKCommitmentGroup.groupOrder; + this->s_gamma = r_gamma - c*((e-1).inverse(params->accumulatorPoKCommitmentGroup.groupOrder)); + this->s_psi = r_psi + c*r*((e-1).inverse(params->accumulatorPoKCommitmentGroup.groupOrder)); } /** Verifies that a commitment c is accumulated in accumulator a */ bool AccumulatorProofOfKnowledge:: Verify(const Accumulator& a, const CBigNum& valueOfCommitmentToCoin) const { - CBigNum sg = params->accumulatorPoKCommitmentGroup.g; - CBigNum sh = params->accumulatorPoKCommitmentGroup.h; + CBigNum sg = params->accumulatorPoKCommitmentGroup.g; + CBigNum sh = params->accumulatorPoKCommitmentGroup.h; - CBigNum g_n = params->accumulatorQRNCommitmentGroup.g; - CBigNum h_n = params->accumulatorQRNCommitmentGroup.h; + CBigNum g_n = params->accumulatorQRNCommitmentGroup.g; + CBigNum h_n = params->accumulatorQRNCommitmentGroup.h; - //According to the proof, this hash should be of length k_prime bits. It is currently greater than that, which should not be a problem, but we should check this. - CHashWriter hasher(0,0); - hasher << *params << sg << sh << g_n << h_n << valueOfCommitmentToCoin << C_e << C_u << C_r << st_1 << st_2 << st_3 << t_1 << t_2 << t_3 << t_4; + //According to the proof, this hash should be of length k_prime bits. It is currently greater than that, which should not be a problem, but we should check this. + CHashWriter hasher(0,0); + hasher << *params << sg << sh << g_n << h_n << valueOfCommitmentToCoin << C_e << C_u << C_r << st_1 << st_2 << st_3 << t_1 << t_2 << t_3 << t_4; - CBigNum c = CBigNum(hasher.GetHash()); //this hash should be of length k_prime bits + CBigNum c = CBigNum(hasher.GetHash()); //this hash should be of length k_prime bits - CBigNum st_1_prime = (valueOfCommitmentToCoin.pow_mod(c, params->accumulatorPoKCommitmentGroup.modulus) * sg.pow_mod(s_alpha, params->accumulatorPoKCommitmentGroup.modulus) * sh.pow_mod(s_phi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; - CBigNum st_2_prime = (sg.pow_mod(c, params->accumulatorPoKCommitmentGroup.modulus) * ((valueOfCommitmentToCoin * sg.inverse(params->accumulatorPoKCommitmentGroup.modulus)).pow_mod(s_gamma, params->accumulatorPoKCommitmentGroup.modulus)) * sh.pow_mod(s_psi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; - CBigNum st_3_prime = (sg.pow_mod(c, params->accumulatorPoKCommitmentGroup.modulus) * (sg * valueOfCommitmentToCoin).pow_mod(s_sigma, params->accumulatorPoKCommitmentGroup.modulus) * sh.pow_mod(s_xi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; + CBigNum st_1_prime = (valueOfCommitmentToCoin.pow_mod(c, params->accumulatorPoKCommitmentGroup.modulus) * sg.pow_mod(s_alpha, params->accumulatorPoKCommitmentGroup.modulus) * sh.pow_mod(s_phi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; + CBigNum st_2_prime = (sg.pow_mod(c, params->accumulatorPoKCommitmentGroup.modulus) * ((valueOfCommitmentToCoin * sg.inverse(params->accumulatorPoKCommitmentGroup.modulus)).pow_mod(s_gamma, params->accumulatorPoKCommitmentGroup.modulus)) * sh.pow_mod(s_psi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; + CBigNum st_3_prime = (sg.pow_mod(c, params->accumulatorPoKCommitmentGroup.modulus) * (sg * valueOfCommitmentToCoin).pow_mod(s_sigma, params->accumulatorPoKCommitmentGroup.modulus) * sh.pow_mod(s_xi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; - CBigNum t_1_prime = (C_r.pow_mod(c, params->accumulatorModulus) * h_n.pow_mod(s_zeta, params->accumulatorModulus) * g_n.pow_mod(s_epsilon, params->accumulatorModulus)) % params->accumulatorModulus; - CBigNum t_2_prime = (C_e.pow_mod(c, params->accumulatorModulus) * h_n.pow_mod(s_eta, params->accumulatorModulus) * g_n.pow_mod(s_alpha, params->accumulatorModulus)) % params->accumulatorModulus; - CBigNum t_3_prime = ((a.getValue()).pow_mod(c, params->accumulatorModulus) * C_u.pow_mod(s_alpha, params->accumulatorModulus) * ((h_n.inverse(params->accumulatorModulus)).pow_mod(s_beta, params->accumulatorModulus))) % params->accumulatorModulus; - CBigNum t_4_prime = (C_r.pow_mod(s_alpha, params->accumulatorModulus) * ((h_n.inverse(params->accumulatorModulus)).pow_mod(s_delta, params->accumulatorModulus)) * ((g_n.inverse(params->accumulatorModulus)).pow_mod(s_beta, params->accumulatorModulus))) % params->accumulatorModulus; + CBigNum t_1_prime = (C_r.pow_mod(c, params->accumulatorModulus) * h_n.pow_mod(s_zeta, params->accumulatorModulus) * g_n.pow_mod(s_epsilon, params->accumulatorModulus)) % params->accumulatorModulus; + CBigNum t_2_prime = (C_e.pow_mod(c, params->accumulatorModulus) * h_n.pow_mod(s_eta, params->accumulatorModulus) * g_n.pow_mod(s_alpha, params->accumulatorModulus)) % params->accumulatorModulus; + CBigNum t_3_prime = ((a.getValue()).pow_mod(c, params->accumulatorModulus) * C_u.pow_mod(s_alpha, params->accumulatorModulus) * ((h_n.inverse(params->accumulatorModulus)).pow_mod(s_beta, params->accumulatorModulus))) % params->accumulatorModulus; + CBigNum t_4_prime = (C_r.pow_mod(s_alpha, params->accumulatorModulus) * ((h_n.inverse(params->accumulatorModulus)).pow_mod(s_delta, params->accumulatorModulus)) * ((g_n.inverse(params->accumulatorModulus)).pow_mod(s_beta, params->accumulatorModulus))) % params->accumulatorModulus; - bool result_st1 = (st_1 == st_1_prime); - bool result_st2 = (st_2 == st_2_prime); - bool result_st3 = (st_3 == st_3_prime); + bool result_st1 = (st_1 == st_1_prime); + bool result_st2 = (st_2 == st_2_prime); + bool result_st3 = (st_3 == st_3_prime); - bool result_t1 = (t_1 == t_1_prime); - bool result_t2 = (t_2 == t_2_prime); - bool result_t3 = (t_3 == t_3_prime); - bool result_t4 = (t_4 == t_4_prime); + bool result_t1 = (t_1 == t_1_prime); + bool result_t2 = (t_2 == t_2_prime); + bool result_t3 = (t_3 == t_3_prime); + bool result_t4 = (t_4 == t_4_prime); - bool result_range = ((s_alpha >= -(params->maxCoinValue * CBigNum(2).pow(params->k_prime + params->k_dprime + 1))) && (s_alpha <= (params->maxCoinValue * CBigNum(2).pow(params->k_prime + params->k_dprime + 1)))); + bool result_range = ((s_alpha >= -(params->maxCoinValue * CBigNum(2).pow(params->k_prime + params->k_dprime + 1))) && (s_alpha <= (params->maxCoinValue * CBigNum(2).pow(params->k_prime + params->k_dprime + 1)))); return result_st1 && result_st2 && result_st3 && result_t1 && result_t2 && result_t3 && result_t4 && result_range; } diff --git a/src/libzerocoin/Coin.cpp b/src/libzerocoin/Coin.cpp index 73ff70e3d2df..583187696201 100644 --- a/src/libzerocoin/Coin.cpp +++ b/src/libzerocoin/Coin.cpp @@ -21,29 +21,29 @@ namespace libzerocoin { //PublicCoin class PublicCoin::PublicCoin(const ZerocoinParams* p): - params(p) { - if (this->params->initialized == false) { - throw std::runtime_error("Params are not initialized"); - } + params(p) { + if (this->params->initialized == false) { + throw std::runtime_error("Params are not initialized"); + } // Assume this will get set by another method later denomination = ZQ_ERROR; }; PublicCoin::PublicCoin(const ZerocoinParams* p, const CBigNum& coin, const CoinDenomination d): - params(p), value(coin) { - if (this->params->initialized == false) { - throw std::runtime_error("Params are not initialized"); - } - - denomination = d; - for(const CoinDenomination denom : zerocoinDenomList) { - if(denom == d) - denomination = d; - } + params(p), value(coin) { + if (this->params->initialized == false) { + throw std::runtime_error("Params are not initialized"); + } + + denomination = d; + for(const CoinDenomination denom : zerocoinDenomList) { + if(denom == d) + denomination = d; + } if (denomination == 0) { - std::cout << "denom does not exist\n"; - throw std::runtime_error("Denomination does not exist"); - } + std::cout << "denom does not exist\n"; + throw std::runtime_error("Denomination does not exist"); + } }; bool PublicCoin::validate() const @@ -67,10 +67,10 @@ bool PublicCoin::validate() const //PrivateCoin class PrivateCoin::PrivateCoin(const ZerocoinParams* p, const CoinDenomination denomination, bool fMintNew): params(p), publicCoin(p) { - // Verify that the parameters are valid - if(this->params->initialized == false) { - throw std::runtime_error("Params are not initialized"); - } + // Verify that the parameters are valid + if(this->params->initialized == false) { + throw std::runtime_error("Params are not initialized"); + } if (fMintNew) { #ifdef ZEROCOIN_FAST_MINT @@ -145,110 +145,110 @@ bool GenerateKeyPair(const CBigNum& bnGroupOrder, const uint256& nPrivkey, CKey& const CPubKey PrivateCoin::getPubKey() const { - CKey key; - key.SetPrivKey(privkey, true); - return key.GetPubKey(); + CKey key; + key.SetPrivKey(privkey, true); + return key.GetPubKey(); } bool PrivateCoin::sign(const uint256& hash, std::vector& vchSig) const { - CKey key; - key.SetPrivKey(privkey, true); - return key.Sign(hash, vchSig); + CKey key; + key.SetPrivKey(privkey, true); + return key.Sign(hash, vchSig); } void PrivateCoin::mintCoin(const CoinDenomination denomination) { - // Repeat this process up to MAX_COINMINT_ATTEMPTS times until - // we obtain a prime number - for(uint32_t attempt = 0; attempt < MAX_COINMINT_ATTEMPTS; attempt++) { - - // Generate a random serial number in the range 0...{q-1} where - // "q" is the order of the commitment group. - // And where the serial also doubles as a public key - CKey key; - CBigNum s; + // Repeat this process up to MAX_COINMINT_ATTEMPTS times until + // we obtain a prime number + for(uint32_t attempt = 0; attempt < MAX_COINMINT_ATTEMPTS; attempt++) { + + // Generate a random serial number in the range 0...{q-1} where + // "q" is the order of the commitment group. + // And where the serial also doubles as a public key + CKey key; + CBigNum s; bool isValid = false; while (!isValid) { isValid = GenerateKeyPair(this->params->coinCommitmentGroup.groupOrder, uint256(0), key, s); } - // Generate a Pedersen commitment to the serial number "s" - Commitment coin(¶ms->coinCommitmentGroup, s); - - // Now verify that the commitment is a prime number - // in the appropriate range. If not, we'll throw this coin - // away and generate a new one. - if (coin.getCommitmentValue().isPrime(ZEROCOIN_MINT_PRIME_PARAM) && - coin.getCommitmentValue() >= params->accumulatorParams.minCoinValue && - coin.getCommitmentValue() <= params->accumulatorParams.maxCoinValue) { - // Found a valid coin. Store it. - this->serialNumber = s; - this->randomness = coin.getRandomness(); - this->publicCoin = PublicCoin(params,coin.getCommitmentValue(), denomination); - this->privkey = key.GetPrivKey(); - this->version = 2; - - // Success! We're done. - return; - } - } - - // We only get here if we did not find a coin within - // MAX_COINMINT_ATTEMPTS. Throw an exception. - throw std::runtime_error("Unable to mint a new Zerocoin (too many attempts)"); + // Generate a Pedersen commitment to the serial number "s" + Commitment coin(¶ms->coinCommitmentGroup, s); + + // Now verify that the commitment is a prime number + // in the appropriate range. If not, we'll throw this coin + // away and generate a new one. + if (coin.getCommitmentValue().isPrime(ZEROCOIN_MINT_PRIME_PARAM) && + coin.getCommitmentValue() >= params->accumulatorParams.minCoinValue && + coin.getCommitmentValue() <= params->accumulatorParams.maxCoinValue) { + // Found a valid coin. Store it. + this->serialNumber = s; + this->randomness = coin.getRandomness(); + this->publicCoin = PublicCoin(params,coin.getCommitmentValue(), denomination); + this->privkey = key.GetPrivKey(); + this->version = 2; + + // Success! We're done. + return; + } + } + + // We only get here if we did not find a coin within + // MAX_COINMINT_ATTEMPTS. Throw an exception. + throw std::runtime_error("Unable to mint a new Zerocoin (too many attempts)"); } void PrivateCoin::mintCoinFast(const CoinDenomination denomination) { - // Generate a random serial number in the range 0...{q-1} where - // "q" is the order of the commitment group. - // And where the serial also doubles as a public key - CKey key; - CBigNum s; + // Generate a random serial number in the range 0...{q-1} where + // "q" is the order of the commitment group. + // And where the serial also doubles as a public key + CKey key; + CBigNum s; bool isValid = false; while (!isValid) { isValid = GenerateKeyPair(this->params->coinCommitmentGroup.groupOrder, uint256(0), key, s); } - // Generate a random number "r" in the range 0...{q-1} - CBigNum r = CBigNum::randBignum(this->params->coinCommitmentGroup.groupOrder); - - // Manually compute a Pedersen commitment to the serial number "s" under randomness "r" - // C = g^s * h^r mod p - CBigNum commitmentValue = this->params->coinCommitmentGroup.g.pow_mod(s, this->params->coinCommitmentGroup.modulus).mul_mod(this->params->coinCommitmentGroup.h.pow_mod(r, this->params->coinCommitmentGroup.modulus), this->params->coinCommitmentGroup.modulus); - - // Repeat this process up to MAX_COINMINT_ATTEMPTS times until - // we obtain a prime number - for (uint32_t attempt = 0; attempt < MAX_COINMINT_ATTEMPTS; attempt++) { - // First verify that the commitment is a prime number - // in the appropriate range. If not, we'll throw this coin - // away and generate a new one. - if (commitmentValue.isPrime(ZEROCOIN_MINT_PRIME_PARAM) && - commitmentValue >= params->accumulatorParams.minCoinValue && - commitmentValue <= params->accumulatorParams.maxCoinValue) { - // Found a valid coin. Store it. - this->serialNumber = s; - this->randomness = r; - this->publicCoin = PublicCoin(params, commitmentValue, denomination); - this->privkey = key.GetPrivKey(); - this->version = 2; - - // Success! We're done. - return; - } - - // Generate a new random "r_delta" in 0...{q-1} - CBigNum r_delta = CBigNum::randBignum(this->params->coinCommitmentGroup.groupOrder); - - // The commitment was not prime. Increment "r" and recalculate "C": - // r = r + r_delta mod q - // C = C * h mod p - r = (r + r_delta) % this->params->coinCommitmentGroup.groupOrder; - commitmentValue = commitmentValue.mul_mod(this->params->coinCommitmentGroup.h.pow_mod(r_delta, this->params->coinCommitmentGroup.modulus), this->params->coinCommitmentGroup.modulus); - } - - // We only get here if we did not find a coin within - // MAX_COINMINT_ATTEMPTS. Throw an exception. - throw std::runtime_error("Unable to mint a new Zerocoin (too many attempts)"); + // Generate a random number "r" in the range 0...{q-1} + CBigNum r = CBigNum::randBignum(this->params->coinCommitmentGroup.groupOrder); + + // Manually compute a Pedersen commitment to the serial number "s" under randomness "r" + // C = g^s * h^r mod p + CBigNum commitmentValue = this->params->coinCommitmentGroup.g.pow_mod(s, this->params->coinCommitmentGroup.modulus).mul_mod(this->params->coinCommitmentGroup.h.pow_mod(r, this->params->coinCommitmentGroup.modulus), this->params->coinCommitmentGroup.modulus); + + // Repeat this process up to MAX_COINMINT_ATTEMPTS times until + // we obtain a prime number + for (uint32_t attempt = 0; attempt < MAX_COINMINT_ATTEMPTS; attempt++) { + // First verify that the commitment is a prime number + // in the appropriate range. If not, we'll throw this coin + // away and generate a new one. + if (commitmentValue.isPrime(ZEROCOIN_MINT_PRIME_PARAM) && + commitmentValue >= params->accumulatorParams.minCoinValue && + commitmentValue <= params->accumulatorParams.maxCoinValue) { + // Found a valid coin. Store it. + this->serialNumber = s; + this->randomness = r; + this->publicCoin = PublicCoin(params, commitmentValue, denomination); + this->privkey = key.GetPrivKey(); + this->version = 2; + + // Success! We're done. + return; + } + + // Generate a new random "r_delta" in 0...{q-1} + CBigNum r_delta = CBigNum::randBignum(this->params->coinCommitmentGroup.groupOrder); + + // The commitment was not prime. Increment "r" and recalculate "C": + // r = r + r_delta mod q + // C = C * h mod p + r = (r + r_delta) % this->params->coinCommitmentGroup.groupOrder; + commitmentValue = commitmentValue.mul_mod(this->params->coinCommitmentGroup.h.pow_mod(r_delta, this->params->coinCommitmentGroup.modulus), this->params->coinCommitmentGroup.modulus); + } + + // We only get here if we did not find a coin within + // MAX_COINMINT_ATTEMPTS. Throw an exception. + throw std::runtime_error("Unable to mint a new Zerocoin (too many attempts)"); } int ExtractVersionFromSerial(const CBigNum& bnSerial) @@ -258,13 +258,13 @@ int ExtractVersionFromSerial(const CBigNum& bnSerial) uint256 nMark = bnSerial.getuint256() >> (256 - PrivateCoin::V2_BITSHIFT); if (nMark == 0xf) return PrivateCoin::PUBKEY_VERSION; - } catch (std::range_error &e) { + } catch (const std::range_error& e) { //std::cout << "ExtractVersionFromSerial(): " << e.what() << std::endl; // Only serial version 2 appeared with this range error.. return 2; } - return 1; + return 1; } //Remove the first four bits for V2 serials diff --git a/src/libzerocoin/CoinSpend.cpp b/src/libzerocoin/CoinSpend.cpp index f1b17625f1d3..57608507f7f9 100644 --- a/src/libzerocoin/CoinSpend.cpp +++ b/src/libzerocoin/CoinSpend.cpp @@ -143,7 +143,7 @@ bool CoinSpend::HasValidSignature() const //cout << "CoinSpend::HasValidSignature() hashedpubkey is not equal to the serial!\n"; return false; } - } catch(std::range_error &e) { + } catch (const std::range_error& e) { //std::cout << "HasValidSignature() error: " << e.what() << std::endl; throw InvalidSerialException("Serial longer than 256 bits"); } diff --git a/src/libzerocoin/Commitment.cpp b/src/libzerocoin/Commitment.cpp index 6b8f1212d553..c931141dc67d 100644 --- a/src/libzerocoin/Commitment.cpp +++ b/src/libzerocoin/Commitment.cpp @@ -19,9 +19,9 @@ namespace libzerocoin { //Commitment class Commitment::Commitment(const IntegerGroupParams* p, const CBigNum& value): params(p), contents(value) { - this->randomness = CBigNum::randBignum(params->groupOrder); - this->commitmentValue = (params->g.pow_mod(this->contents, params->modulus).mul_mod( - params->h.pow_mod(this->randomness, params->modulus), params->modulus)); + this->randomness = CBigNum::randBignum(params->groupOrder); + this->commitmentValue = (params->g.pow_mod(this->contents, params->modulus).mul_mod( + params->h.pow_mod(this->randomness, params->modulus), params->modulus)); } Commitment::Commitment(const IntegerGroupParams* p, const CBigNum& bnSerial, const CBigNum& bnRandomness): params(p), contents(bnSerial) { @@ -31,15 +31,15 @@ Commitment::Commitment(const IntegerGroupParams* p, const CBigNum& bnSerial, con } const CBigNum& Commitment::getCommitmentValue() const { - return this->commitmentValue; + return this->commitmentValue; } const CBigNum& Commitment::getRandomness() const { - return this->randomness; + return this->randomness; } const CBigNum& Commitment::getContents() const { - return this->contents; + return this->contents; } //CommitmentProofOfKnowledge class @@ -48,127 +48,127 @@ CommitmentProofOfKnowledge::CommitmentProofOfKnowledge(const IntegerGroupParams* // TODO: get parameters from the commitment group CommitmentProofOfKnowledge::CommitmentProofOfKnowledge(const IntegerGroupParams* aParams, const IntegerGroupParams* bParams, const Commitment& a, const Commitment& b): - ap(aParams),bp(bParams) + ap(aParams),bp(bParams) { - CBigNum r1, r2, r3; - - // First: make sure that the two commitments have the - // same contents. - if (a.getContents() != b.getContents()) { - throw std::runtime_error("Both commitments must contain the same value"); - } - - // Select three random values "r1, r2, r3" in the range 0 to (2^l)-1 where l is: - // length of challenge value + max(modulus 1, modulus 2, order 1, order 2) + margin. - // We set "margin" to be a relatively generous security parameter. - // - // We choose these large values to ensure statistical zero knowledge. - uint32_t randomSize = COMMITMENT_EQUALITY_CHALLENGE_SIZE + COMMITMENT_EQUALITY_SECMARGIN + - std::max(std::max(this->ap->modulus.bitSize(), this->bp->modulus.bitSize()), - std::max(this->ap->groupOrder.bitSize(), this->bp->groupOrder.bitSize())); - CBigNum maxRange = (CBigNum(2).pow(randomSize) - CBigNum(1)); - - r1 = CBigNum::randBignum(maxRange); - r2 = CBigNum::randBignum(maxRange); - r3 = CBigNum::randBignum(maxRange); - - // Generate two random, ephemeral commitments "T1, T2" - // of the form: - // T1 = g1^r1 * h1^r2 mod p1 - // T2 = g2^r1 * h2^r3 mod p2 - // - // Where (g1, h1, p1) are from "aParams" and (g2, h2, p2) are from "bParams". - CBigNum T1 = this->ap->g.pow_mod(r1, this->ap->modulus).mul_mod((this->ap->h.pow_mod(r2, this->ap->modulus)), this->ap->modulus); - CBigNum T2 = this->bp->g.pow_mod(r1, this->bp->modulus).mul_mod((this->bp->h.pow_mod(r3, this->bp->modulus)), this->bp->modulus); - - // Now hash commitment "A" with commitment "B" as well as the - // parameters and the two ephemeral commitments "T1, T2" we just generated - this->challenge = calculateChallenge(a.getCommitmentValue(), b.getCommitmentValue(), T1, T2); - - // Let "m" be the contents of the commitments "A, B". We have: - // A = g1^m * h1^x mod p1 - // B = g2^m * h2^y mod p2 - // T1 = g1^r1 * h1^r2 mod p1 - // T2 = g2^r1 * h2^r3 mod p2 - // - // Now compute: - // S1 = r1 + (m * challenge) -- note, not modular arithmetic - // S2 = r2 + (x * challenge) -- note, not modular arithmetic - // S3 = r3 + (y * challenge) -- note, not modular arithmetic - this->S1 = r1 + (a.getContents() * this->challenge); - this->S2 = r2 + (a.getRandomness() * this->challenge); - this->S3 = r3 + (b.getRandomness() * this->challenge); - - // We're done. The proof is S1, S2, S3 and "challenge", all of which - // are stored in member variables. + CBigNum r1, r2, r3; + + // First: make sure that the two commitments have the + // same contents. + if (a.getContents() != b.getContents()) { + throw std::runtime_error("Both commitments must contain the same value"); + } + + // Select three random values "r1, r2, r3" in the range 0 to (2^l)-1 where l is: + // length of challenge value + max(modulus 1, modulus 2, order 1, order 2) + margin. + // We set "margin" to be a relatively generous security parameter. + // + // We choose these large values to ensure statistical zero knowledge. + uint32_t randomSize = COMMITMENT_EQUALITY_CHALLENGE_SIZE + COMMITMENT_EQUALITY_SECMARGIN + + std::max(std::max(this->ap->modulus.bitSize(), this->bp->modulus.bitSize()), + std::max(this->ap->groupOrder.bitSize(), this->bp->groupOrder.bitSize())); + CBigNum maxRange = (CBigNum(2).pow(randomSize) - CBigNum(1)); + + r1 = CBigNum::randBignum(maxRange); + r2 = CBigNum::randBignum(maxRange); + r3 = CBigNum::randBignum(maxRange); + + // Generate two random, ephemeral commitments "T1, T2" + // of the form: + // T1 = g1^r1 * h1^r2 mod p1 + // T2 = g2^r1 * h2^r3 mod p2 + // + // Where (g1, h1, p1) are from "aParams" and (g2, h2, p2) are from "bParams". + CBigNum T1 = this->ap->g.pow_mod(r1, this->ap->modulus).mul_mod((this->ap->h.pow_mod(r2, this->ap->modulus)), this->ap->modulus); + CBigNum T2 = this->bp->g.pow_mod(r1, this->bp->modulus).mul_mod((this->bp->h.pow_mod(r3, this->bp->modulus)), this->bp->modulus); + + // Now hash commitment "A" with commitment "B" as well as the + // parameters and the two ephemeral commitments "T1, T2" we just generated + this->challenge = calculateChallenge(a.getCommitmentValue(), b.getCommitmentValue(), T1, T2); + + // Let "m" be the contents of the commitments "A, B". We have: + // A = g1^m * h1^x mod p1 + // B = g2^m * h2^y mod p2 + // T1 = g1^r1 * h1^r2 mod p1 + // T2 = g2^r1 * h2^r3 mod p2 + // + // Now compute: + // S1 = r1 + (m * challenge) -- note, not modular arithmetic + // S2 = r2 + (x * challenge) -- note, not modular arithmetic + // S3 = r3 + (y * challenge) -- note, not modular arithmetic + this->S1 = r1 + (a.getContents() * this->challenge); + this->S2 = r2 + (a.getRandomness() * this->challenge); + this->S3 = r3 + (b.getRandomness() * this->challenge); + + // We're done. The proof is S1, S2, S3 and "challenge", all of which + // are stored in member variables. } bool CommitmentProofOfKnowledge::Verify(const CBigNum& A, const CBigNum& B) const { - // Compute the maximum range of S1, S2, S3 and verify that the given values are - // in a correct range. This might be an unnecessary check. - uint32_t maxSize = 64 * (COMMITMENT_EQUALITY_CHALLENGE_SIZE + COMMITMENT_EQUALITY_SECMARGIN + - std::max(std::max(this->ap->modulus.bitSize(), this->bp->modulus.bitSize()), - std::max(this->ap->groupOrder.bitSize(), this->bp->groupOrder.bitSize()))); - - if ((uint32_t)this->S1.bitSize() > maxSize || - (uint32_t)this->S2.bitSize() > maxSize || - (uint32_t)this->S3.bitSize() > maxSize || - this->S1 < CBigNum(0) || - this->S2 < CBigNum(0) || - this->S3 < CBigNum(0) || - this->challenge < CBigNum(0) || - this->challenge > (CBigNum(2).pow(COMMITMENT_EQUALITY_CHALLENGE_SIZE) - CBigNum(1))) { - // Invalid inputs. Reject. - return false; - } - - // Compute T1 = g1^S1 * h1^S2 * inverse(A^{challenge}) mod p1 - CBigNum T1 = A.pow_mod(this->challenge, ap->modulus).inverse(ap->modulus).mul_mod( - (ap->g.pow_mod(S1, ap->modulus).mul_mod(ap->h.pow_mod(S2, ap->modulus), ap->modulus)), - ap->modulus); - - // Compute T2 = g2^S1 * h2^S3 * inverse(B^{challenge}) mod p2 - CBigNum T2 = B.pow_mod(this->challenge, bp->modulus).inverse(bp->modulus).mul_mod( - (bp->g.pow_mod(S1, bp->modulus).mul_mod(bp->h.pow_mod(S3, bp->modulus), bp->modulus)), - bp->modulus); - - // Hash T1 and T2 along with all of the public parameters - CBigNum computedChallenge = calculateChallenge(A, B, T1, T2); - - // Return success if the computed challenge matches the incoming challenge - return computedChallenge == this->challenge; + // Compute the maximum range of S1, S2, S3 and verify that the given values are + // in a correct range. This might be an unnecessary check. + uint32_t maxSize = 64 * (COMMITMENT_EQUALITY_CHALLENGE_SIZE + COMMITMENT_EQUALITY_SECMARGIN + + std::max(std::max(this->ap->modulus.bitSize(), this->bp->modulus.bitSize()), + std::max(this->ap->groupOrder.bitSize(), this->bp->groupOrder.bitSize()))); + + if ((uint32_t)this->S1.bitSize() > maxSize || + (uint32_t)this->S2.bitSize() > maxSize || + (uint32_t)this->S3.bitSize() > maxSize || + this->S1 < CBigNum(0) || + this->S2 < CBigNum(0) || + this->S3 < CBigNum(0) || + this->challenge < CBigNum(0) || + this->challenge > (CBigNum(2).pow(COMMITMENT_EQUALITY_CHALLENGE_SIZE) - CBigNum(1))) { + // Invalid inputs. Reject. + return false; + } + + // Compute T1 = g1^S1 * h1^S2 * inverse(A^{challenge}) mod p1 + CBigNum T1 = A.pow_mod(this->challenge, ap->modulus).inverse(ap->modulus).mul_mod( + (ap->g.pow_mod(S1, ap->modulus).mul_mod(ap->h.pow_mod(S2, ap->modulus), ap->modulus)), + ap->modulus); + + // Compute T2 = g2^S1 * h2^S3 * inverse(B^{challenge}) mod p2 + CBigNum T2 = B.pow_mod(this->challenge, bp->modulus).inverse(bp->modulus).mul_mod( + (bp->g.pow_mod(S1, bp->modulus).mul_mod(bp->h.pow_mod(S3, bp->modulus), bp->modulus)), + bp->modulus); + + // Hash T1 and T2 along with all of the public parameters + CBigNum computedChallenge = calculateChallenge(A, B, T1, T2); + + // Return success if the computed challenge matches the incoming challenge + return computedChallenge == this->challenge; } const CBigNum CommitmentProofOfKnowledge::calculateChallenge(const CBigNum& a, const CBigNum& b, const CBigNum &commitOne, const CBigNum &commitTwo) const { - CHashWriter hasher(0,0); - - // Hash together the following elements: - // * A string identifying the proof - // * Commitment A - // * Commitment B - // * Ephemeral commitment T1 - // * Ephemeral commitment T2 - // * A serialized instance of the commitment A parameters - // * A serialized instance of the commitment B parameters - - hasher << std::string(ZEROCOIN_COMMITMENT_EQUALITY_PROOF); - hasher << commitOne; - hasher << std::string("||"); - hasher << commitTwo; - hasher << std::string("||"); - hasher << a; - hasher << std::string("||"); - hasher << b; - hasher << std::string("||"); - hasher << *(this->ap); - hasher << std::string("||"); - hasher << *(this->bp); - - // Convert the SHA256 result into a Bignum - // Note that if we ever change the size of the hash function we will have - // to update COMMITMENT_EQUALITY_CHALLENGE_SIZE appropriately! - return CBigNum(hasher.GetHash()); + CHashWriter hasher(0,0); + + // Hash together the following elements: + // * A string identifying the proof + // * Commitment A + // * Commitment B + // * Ephemeral commitment T1 + // * Ephemeral commitment T2 + // * A serialized instance of the commitment A parameters + // * A serialized instance of the commitment B parameters + + hasher << std::string(ZEROCOIN_COMMITMENT_EQUALITY_PROOF); + hasher << commitOne; + hasher << std::string("||"); + hasher << commitTwo; + hasher << std::string("||"); + hasher << a; + hasher << std::string("||"); + hasher << b; + hasher << std::string("||"); + hasher << *(this->ap); + hasher << std::string("||"); + hasher << *(this->bp); + + // Convert the SHA256 result into a Bignum + // Note that if we ever change the size of the hash function we will have + // to update COMMITMENT_EQUALITY_CHALLENGE_SIZE appropriately! + return CBigNum(hasher.GetHash()); } } /* namespace libzerocoin */ diff --git a/src/libzerocoin/Denominations.cpp b/src/libzerocoin/Denominations.cpp index 7cf5aa1eff98..92fb86b46384 100644 --- a/src/libzerocoin/Denominations.cpp +++ b/src/libzerocoin/Denominations.cpp @@ -13,10 +13,10 @@ CoinDenomination IntToZerocoinDenomination(int64_t amount) { CoinDenomination denomination; switch (amount) { - case 1: denomination = CoinDenomination::ZQ_ONE; break; - case 5: denomination = CoinDenomination::ZQ_FIVE; break; - case 10: denomination = CoinDenomination::ZQ_TEN; break; - case 50: denomination = CoinDenomination::ZQ_FIFTY; break; + case 1: denomination = CoinDenomination::ZQ_ONE; break; + case 5: denomination = CoinDenomination::ZQ_FIVE; break; + case 10: denomination = CoinDenomination::ZQ_TEN; break; + case 50: denomination = CoinDenomination::ZQ_FIFTY; break; case 100: denomination = CoinDenomination::ZQ_ONE_HUNDRED; break; case 500: denomination = CoinDenomination::ZQ_FIVE_HUNDRED; break; case 1000: denomination = CoinDenomination::ZQ_ONE_THOUSAND; break; diff --git a/src/libzerocoin/Params.cpp b/src/libzerocoin/Params.cpp index dfe4b6db8875..02360114797c 100644 --- a/src/libzerocoin/Params.cpp +++ b/src/libzerocoin/Params.cpp @@ -17,32 +17,32 @@ namespace libzerocoin { ZerocoinParams::ZerocoinParams(CBigNum N, uint32_t securityLevel) { - this->zkp_hash_len = securityLevel; - this->zkp_iterations = securityLevel; + this->zkp_hash_len = securityLevel; + this->zkp_iterations = securityLevel; - this->accumulatorParams.k_prime = ACCPROOF_KPRIME; - this->accumulatorParams.k_dprime = ACCPROOF_KDPRIME; + this->accumulatorParams.k_prime = ACCPROOF_KPRIME; + this->accumulatorParams.k_dprime = ACCPROOF_KDPRIME; - // Generate the parameters - CalculateParams(*this, N, ZEROCOIN_PROTOCOL_VERSION, securityLevel); + // Generate the parameters + CalculateParams(*this, N, ZEROCOIN_PROTOCOL_VERSION, securityLevel); - this->accumulatorParams.initialized = true; - this->initialized = true; + this->accumulatorParams.initialized = true; + this->initialized = true; } AccumulatorAndProofParams::AccumulatorAndProofParams() { - this->initialized = false; + this->initialized = false; } IntegerGroupParams::IntegerGroupParams() { - this->initialized = false; + this->initialized = false; } CBigNum IntegerGroupParams::randomElement() const { - // The generator of the group raised - // to a random number less than the order of the group - // provides us with a uniformly distributed random number. - return this->g.pow_mod(CBigNum::randBignum(this->groupOrder),this->modulus); + // The generator of the group raised + // to a random number less than the order of the group + // provides us with a uniformly distributed random number. + return this->g.pow_mod(CBigNum::randBignum(this->groupOrder),this->modulus); } } /* namespace libzerocoin */ diff --git a/src/libzerocoin/SerialNumberSignatureOfKnowledge.cpp b/src/libzerocoin/SerialNumberSignatureOfKnowledge.cpp index c99c965561b0..e5abc7f481b1 100644 --- a/src/libzerocoin/SerialNumberSignatureOfKnowledge.cpp +++ b/src/libzerocoin/SerialNumberSignatureOfKnowledge.cpp @@ -170,7 +170,7 @@ bool SerialNumberSignatureOfKnowledge::Verify(const CBigNum& coinSerialNumber, c hasher << tprime[i]; } return hasher.GetHash() == hash; - }catch (std::range_error e){ + } catch (const std::range_error& e) { return error("SoK Verify() :: sprime invalid range."); } } diff --git a/src/libzerocoin/paramgen.cpp b/src/libzerocoin/paramgen.cpp index 09989fc08328..cc39db0eb80a 100644 --- a/src/libzerocoin/paramgen.cpp +++ b/src/libzerocoin/paramgen.cpp @@ -25,103 +25,103 @@ void PrintWarning() { - cout << "Zerocoin parameter generation utility" << endl; - cout << "-------------------------------------" << endl << endl; - cout << "This utility generates an l-bit modulus N as the product of" << endl; - cout << "two safe primes p, q. The values p and q are not stored." << endl; - cout << "Call this program with no arguments to see usage options." << endl; - cout << endl; - cout << "SECURITY WARNING: ZEROCOIN PARAMETERS MUST BE GENERATED BY" << endl; - cout << "A TRUSTED PARTY WHO DOES NOT STORE THE FACTORS. WHILE WE MAKE" << endl; - cout << "A BEST EFFORT TO DESTROY THIS INFORMATION WE DO NOT TAKE" << endl; - cout << "SPECIAL PRECAUTIONS TO ENSURE THAT THEY ARE DESTROYED." << endl; - cout << endl; - cout << "USE THIS UTILITY AT YOUR OWN RISK" << endl << endl; + cout << "Zerocoin parameter generation utility" << endl; + cout << "-------------------------------------" << endl << endl; + cout << "This utility generates an l-bit modulus N as the product of" << endl; + cout << "two safe primes p, q. The values p and q are not stored." << endl; + cout << "Call this program with no arguments to see usage options." << endl; + cout << endl; + cout << "SECURITY WARNING: ZEROCOIN PARAMETERS MUST BE GENERATED BY" << endl; + cout << "A TRUSTED PARTY WHO DOES NOT STORE THE FACTORS. WHILE WE MAKE" << endl; + cout << "A BEST EFFORT TO DESTROY THIS INFORMATION WE DO NOT TAKE" << endl; + cout << "SPECIAL PRECAUTIONS TO ENSURE THAT THEY ARE DESTROYED." << endl; + cout << endl; + cout << "USE THIS UTILITY AT YOUR OWN RISK" << endl << endl; } void usage() { - printf("Usage:\n"); - printf(" -b \n"); - printf(" -o \n"); + printf("Usage:\n"); + printf(" -b \n"); + printf(" -o \n"); - exit (8); + exit (8); } int main(int argc, char **argv) { - static CBigNum resultModulus(0); - uint32_t numBits = DEFAULT_MODULUS_SIZE; - ofstream outfile; - char* outfileName; - bool writeToFile = false; - - while ((argc > 1) && (argv[1][0] == '-')) - { - switch (argv[1][1]) - { - case 'b': - numBits = atoi(argv[2]); - ++argv; - --argc; - break; - - case 'o': - outfileName = argv[2]; - writeToFile = true; - break; - - case 'h': - usage(); - break; - - default: - printf("Wrong Argument: %s\n", argv[1]); - usage(); - break; - } - - ++argv; - --argc; - } - - if (numBits < MIN_MODULUS_SIZE) { - cout << "Modulus is below minimum length (" << MIN_MODULUS_SIZE << ") bits" << endl; - return(0); - } - - PrintWarning(); - - cout << "Modulus size set to " << numBits << " bits." << endl; - cout << "Generating parameters. This may take a few minutes..." << endl; - - // Generate two safe primes "p" and "q" - CBigNum *p, *q; - p = new CBigNum(0); - q = new CBigNum(0); - *p = CBigNum::generatePrime(numBits / 2, true); - *q = CBigNum::generatePrime(numBits / 2, true); - - // Multiply to compute N - resultModulus = (*p) * (*q); - - // Wipe out the factors - delete p; - delete q; - - // Convert to a hexidecimal string - std::string resultHex = resultModulus.ToString(16); - - cout << endl << "N = " << endl << resultHex << endl; - - if (writeToFile) { - try { - outfile.open (outfileName); - outfile << resultHex; - outfile.close(); - cout << endl << "Result has been written to file '" << outfileName << "'." << endl; - } catch (std::runtime_error &e) { - cout << "Unable to write to file:" << e.what() << endl; - } - } + static CBigNum resultModulus(0); + uint32_t numBits = DEFAULT_MODULUS_SIZE; + ofstream outfile; + char* outfileName; + bool writeToFile = false; + + while ((argc > 1) && (argv[1][0] == '-')) + { + switch (argv[1][1]) + { + case 'b': + numBits = atoi(argv[2]); + ++argv; + --argc; + break; + + case 'o': + outfileName = argv[2]; + writeToFile = true; + break; + + case 'h': + usage(); + break; + + default: + printf("Wrong Argument: %s\n", argv[1]); + usage(); + break; + } + + ++argv; + --argc; + } + + if (numBits < MIN_MODULUS_SIZE) { + cout << "Modulus is below minimum length (" << MIN_MODULUS_SIZE << ") bits" << endl; + return(0); + } + + PrintWarning(); + + cout << "Modulus size set to " << numBits << " bits." << endl; + cout << "Generating parameters. This may take a few minutes..." << endl; + + // Generate two safe primes "p" and "q" + CBigNum *p, *q; + p = new CBigNum(0); + q = new CBigNum(0); + *p = CBigNum::generatePrime(numBits / 2, true); + *q = CBigNum::generatePrime(numBits / 2, true); + + // Multiply to compute N + resultModulus = (*p) * (*q); + + // Wipe out the factors + delete p; + delete q; + + // Convert to a hexidecimal string + std::string resultHex = resultModulus.ToString(16); + + cout << endl << "N = " << endl << resultHex << endl; + + if (writeToFile) { + try { + outfile.open (outfileName); + outfile << resultHex; + outfile.close(); + cout << endl << "Result has been written to file '" << outfileName << "'." << endl; + } catch (const std::runtime_error& e) { + cout << "Unable to write to file:" << e.what() << endl; + } + } } diff --git a/src/lightzpivthread.cpp b/src/lightzpivthread.cpp index 63088431e2f5..d06a2dbb0c81 100644 --- a/src/lightzpivthread.cpp +++ b/src/lightzpivthread.cpp @@ -59,7 +59,7 @@ void CLightWorker::ThreadLightZPIVSimplified() { heightStop ); - } catch (NotEnoughMintsException e) { + } catch (const NotEnoughMintsException& e) { LogPrintStr(std::string("ThreadLightZPIVSimplified: ") + e.message + "\n"); rejectWork(genWit, blockHeight, NOT_ENOUGH_MINTS); continue; @@ -92,7 +92,7 @@ void CLightWorker::ThreadLightZPIVSimplified() { rejectWork(genWit, blockHeight, NON_DETERMINED); } } - } catch (std::exception& e) { + } catch (const std::exception& e) { //std::cout << "exception in light loop, closing it. " << e.what() << std::endl; PrintExceptionContinue(&e, "lightzpivthread"); break; diff --git a/src/main.cpp b/src/main.cpp index 3368c75bdba1..eb3c3060bf02 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1029,7 +1029,7 @@ bool ContextualCheckZerocoinSpendNoSerialCheck(const CTransaction& tx, const lib try { if (!spend->HasValidSignature()) return error("%s: V2 zPIV spend does not have a valid signature\n", __func__); - } catch (libzerocoin::InvalidSerialException &e) { + } catch (const libzerocoin::InvalidSerialException& e) { // Check if we are in the range of the attack if(!isBlockBetweenFakeSerialAttackRange(pindex->nHeight)) return error("%s: Invalid serial detected, txid %s, in block %d\n", __func__, tx.GetHash().GetHex(), pindex->nHeight); @@ -1867,7 +1867,7 @@ bool GetTransaction(const uint256& hash, CTransaction& txOut, uint256& hashBlock file >> header; fseek(file.Get(), postx.nTxOffset, SEEK_CUR); file >> txOut; - } catch (std::exception& e) { + } catch (const std::exception& e) { return error("%s : Deserialize or I/O error - %s", __func__, e.what()); } hashBlock = header.GetHash(); @@ -1948,7 +1948,7 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos) // Read block try { filein >> block; - } catch (std::exception& e) { + } catch (const std::exception& e) { return error("%s : Deserialize or I/O error - %s", __func__, e.what()); } @@ -4983,7 +4983,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, return state.Abort("Failed to write block"); if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) return error("AcceptBlock() : ReceivedBlockTransactions failed"); - } catch (std::runtime_error& e) { + } catch (const std::runtime_error& e) { return state.Abort(std::string("System error: ") + e.what()); } @@ -5508,7 +5508,7 @@ bool InitBlockIndex() return error("LoadBlockIndex() : genesis block cannot be activated"); // Force a chainstate write so that when we VerifyDB in a moment, it doesnt check stale data return FlushStateToDisk(state, FLUSH_STATE_ALWAYS); - } catch (std::runtime_error& e) { + } catch (const std::runtime_error& e) { return error("LoadBlockIndex() : failed to initialize block database: %s", e.what()); } } @@ -5605,11 +5605,11 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos* dbp) mapBlocksUnknownParent.erase(it); } } - } catch (std::exception& e) { + } catch (const std::exception& e) { LogPrintf("%s : Deserialize or I/O error - %s", __func__, e.what()); } } - } catch (std::runtime_error& e) { + } catch (const std::runtime_error& e) { AbortNode(std::string("System error: ") + e.what()); } if (nLoaded > 0) @@ -6016,7 +6016,7 @@ void static ProcessGetData(CNode* pfrom) } pfrom->PushMessage("pubcoins", ss); pushed = true; - } catch (std::exception &e) { + } catch (const std::exception &e) { PrintExceptionContinue(&e, "ProcessMessages()"); } } @@ -6789,7 +6789,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR ss << height; pfrom->PushMessage("accvalueresponse", ss); } - } catch (std::exception &e) { + } catch (const std::exception& e) { // TODO: Response with an error? PrintExceptionContinue(&e, "ProcessMessages()"); } @@ -6816,7 +6816,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR ss << gen.getRequestNum(); pfrom->PushMessage("pubcoins", ss); } - } catch (std::exception &e) { + } catch (const std::exception& e) { // TODO: Response with an error? PrintExceptionContinue(&e, "ProcessMessages()"); } @@ -7036,7 +7036,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR ss << ": hash " << hash.ToString(); } LogPrint("net", "Reject %s\n", SanitizeString(ss.str())); - } catch (std::ios_base::failure& e) { + } catch (const std::ios_base::failure& e) { // Avoid feedback loops by preventing reject messages from triggering a new reject message. LogPrint("net", "Unparseable reject message received\n"); } @@ -7149,7 +7149,7 @@ bool ProcessMessages(CNode* pfrom) try { fRet = ProcessMessage(pfrom, strCommand, vRecv, msg.nTime); boost::this_thread::interruption_point(); - } catch (std::ios_base::failure& e) { + } catch (const std::ios_base::failure& e) { pfrom->PushMessage("reject", strCommand, REJECT_MALFORMED, std::string("error parsing message")); if (strstr(e.what(), "end of data")) { // Allow exceptions from under-length message on vRecv @@ -7160,9 +7160,9 @@ bool ProcessMessages(CNode* pfrom) } else { PrintExceptionContinue(&e, "ProcessMessages()"); } - } catch (boost::thread_interrupted) { + } catch (const boost::thread_interrupted&) { throw; - } catch (std::exception& e) { + } catch (const std::exception& e) { PrintExceptionContinue(&e, "ProcessMessages()"); } catch (...) { PrintExceptionContinue(NULL, "ProcessMessages()"); @@ -7448,7 +7448,7 @@ bool CBlockUndo::ReadFromDisk(const CDiskBlockPos& pos, const uint256& hashBlock try { filein >> *this; filein >> hashChecksum; - } catch (std::exception& e) { + } catch (const std::exception& e) { return error("%s : Deserialize or I/O error - %s", __func__, e.what()); } diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index 1525f7c26dcd..809e6fa3c5e6 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -297,7 +297,7 @@ bool CBudgetDB::Write(const CBudgetManager& objToSave) // Write and commit header, data try { fileout << ssObj; - } catch (std::exception& e) { + } catch (const std::exception& e) { return error("%s : Serialize or I/O error - %s", __func__, e.what()); } fileout.fclose(); @@ -334,7 +334,7 @@ CBudgetDB::ReadResult CBudgetDB::Read(CBudgetManager& objToLoad, bool fDryRun) try { filein.read((char*)&vchData[0], dataSize); filein >> hashIn; - } catch (std::exception& e) { + } catch (const std::exception& e) { error("%s : Deserialize or I/O error - %s", __func__, e.what()); return HashReadError; } @@ -374,7 +374,7 @@ CBudgetDB::ReadResult CBudgetDB::Read(CBudgetManager& objToLoad, bool fDryRun) // de-serialize data into CBudgetManager object ssObj >> objToLoad; - } catch (std::exception& e) { + } catch (const std::exception& e) { objToLoad.Clear(); error("%s : Deserialize or I/O error - %s", __func__, e.what()); return IncorrectFormat; diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 226ffe882da5..393bf746f932 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -54,7 +54,7 @@ bool CMasternodePaymentDB::Write(const CMasternodePayments& objToSave) // Write and commit header, data try { fileout << ssObj; - } catch (std::exception& e) { + } catch (const std::exception& e) { return error("%s : Serialize or I/O error - %s", __func__, e.what()); } fileout.fclose(); @@ -89,7 +89,7 @@ CMasternodePaymentDB::ReadResult CMasternodePaymentDB::Read(CMasternodePayments& try { filein.read((char*)&vchData[0], dataSize); filein >> hashIn; - } catch (std::exception& e) { + } catch (const std::exception& e) { error("%s : Deserialize or I/O error - %s", __func__, e.what()); return HashReadError; } @@ -128,7 +128,7 @@ CMasternodePaymentDB::ReadResult CMasternodePaymentDB::Read(CMasternodePayments& // de-serialize data into CMasternodePayments object ssObj >> objToLoad; - } catch (std::exception& e) { + } catch (const std::exception& e) { objToLoad.Clear(); error("%s : Deserialize or I/O error - %s", __func__, e.what()); return IncorrectFormat; @@ -326,7 +326,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe txNew.vout[i].nValue = masternodePayment; //subtract mn payment from the stake reward - if (!txNew.vout[1].IsZerocoinMint()) + if (!txNew.vout[1].IsZerocoinMint()) { if (i == 2) { // Majority of cases; do it quick and move on txNew.vout[i - 1].nValue -= masternodePayment; @@ -341,6 +341,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe // in case it's not an even division, take the last bit of dust from the last one txNew.vout[outputs].nValue -= mnPaymentRemainder; } + } } else { txNew.vout.resize(2); txNew.vout[1].scriptPubKey = payee; diff --git a/src/masternode.cpp b/src/masternode.cpp index 594aafa57cfd..452af6e076d4 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -208,8 +208,8 @@ void CMasternode::Check(bool forceCheck) } if(lastPing.sigTime - sigTime < MASTERNODE_MIN_MNP_SECONDS){ - activeState = MASTERNODE_PRE_ENABLED; - return; + activeState = MASTERNODE_PRE_ENABLED; + return; } if (!unitTest) { @@ -538,11 +538,11 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) if (pmn == NULL) return true; // this broadcast is older or equal than the one that we already have - it's bad and should never happen - // unless someone is doing something fishy - // (mapSeenMasternodeBroadcast in CMasternodeMan::ProcessMessage should filter legit duplicates) - if(pmn->sigTime >= sigTime) { - return error("CMasternodeBroadcast::CheckAndUpdate - Bad sigTime %d for Masternode %20s %105s (existing broadcast is at %d)", - sigTime, addr.ToString(), vin.ToString(), pmn->sigTime); + // unless someone is doing something fishy + // (mapSeenMasternodeBroadcast in CMasternodeMan::ProcessMessage should filter legit duplicates) + if(pmn->sigTime >= sigTime) { + return error("CMasternodeBroadcast::CheckAndUpdate - Bad sigTime %d for Masternode %20s %105s (existing broadcast is at %d)", + sigTime, addr.ToString(), vin.ToString(), pmn->sigTime); } // masternode is not enabled yet/already, nothing to update @@ -663,10 +663,10 @@ bool CMasternodeBroadcast::Sign(CKey& keyCollateralAddress) std::string strMessage = GetStrMessage(); if (!obfuScationSigner.SignMessage(strMessage, errorMessage, sig, keyCollateralAddress)) - return error("CMasternodeBroadcast::Sign() - Error: %s", errorMessage); + return error("CMasternodeBroadcast::Sign() - Error: %s", errorMessage); if (!obfuScationSigner.VerifyMessage(pubKeyCollateralAddress, sig, strMessage, errorMessage)) - return error("CMasternodeBroadcast::Sign() - Error: %s", errorMessage); + return error("CMasternodeBroadcast::Sign() - Error: %s", errorMessage); return true; } @@ -733,13 +733,13 @@ bool CMasternodePing::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode) bool CMasternodePing::VerifySignature(CPubKey& pubKeyMasternode, int &nDos) { std::string strMessage = vin.ToString() + blockHash.ToString() + std::to_string(sigTime); - std::string errorMessage = ""; + std::string errorMessage = ""; - if(!obfuScationSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, errorMessage)){ - nDos = 33; - return error("CMasternodePing::VerifySignature - Got bad Masternode ping signature %s Error: %s", vin.ToString(), errorMessage); - } - return true; + if(!obfuScationSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, errorMessage)){ + nDos = 33; + return error("CMasternodePing::VerifySignature - Got bad Masternode ping signature %s Error: %s", vin.ToString(), errorMessage); + } + return true; } bool CMasternodePing::CheckAndUpdate(int& nDos, bool fRequireEnabled, bool fCheckSigTimeOnly) @@ -757,9 +757,9 @@ bool CMasternodePing::CheckAndUpdate(int& nDos, bool fRequireEnabled, bool fChec } if(fCheckSigTimeOnly) { - CMasternode* pmn = mnodeman.Find(vin); - if(pmn) return VerifySignature(pmn->pubKeyMasternode, nDos); - return true; + CMasternode* pmn = mnodeman.Find(vin); + if(pmn) return VerifySignature(pmn->pubKeyMasternode, nDos); + return true; } LogPrint("masternode", "CMasternodePing::CheckAndUpdate - New Ping - %s - %s - %lli\n", GetHash().ToString(), blockHash.ToString(), sigTime); @@ -773,7 +773,7 @@ bool CMasternodePing::CheckAndUpdate(int& nDos, bool fRequireEnabled, bool fChec // update only if there is no known ping for this masternode or // last ping was more then MASTERNODE_MIN_MNP_SECONDS-60 ago comparing to this one if (!pmn->IsPingedWithin(MASTERNODE_MIN_MNP_SECONDS - 60, sigTime)) { - if (!VerifySignature(pmn->pubKeyMasternode, nDos)) + if (!VerifySignature(pmn->pubKeyMasternode, nDos)) return false; BlockMap::iterator mi = mapBlockIndex.find(blockHash); diff --git a/src/masternodeconfig.cpp b/src/masternodeconfig.cpp index 7c25d9a9f013..34511a299c8e 100644 --- a/src/masternodeconfig.cpp +++ b/src/masternodeconfig.cpp @@ -110,7 +110,7 @@ bool CMasternodeConfig::CMasternodeEntry::castOutputIndex(int &n) { try { n = std::stoi(outputIndex); - } catch (const std::exception e) { + } catch (const std::exception& e) { LogPrintf("%s: %s on getOutputIndex\n", __func__, e.what()); return false; } diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 70734a197784..04f6ad3a8bc0 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -72,7 +72,7 @@ bool CMasternodeDB::Write(const CMasternodeMan& mnodemanToSave) // Write and commit header, data try { fileout << ssMasternodes; - } catch (std::exception& e) { + } catch (const std::exception& e) { return error("%s : Serialize or I/O error - %s", __func__, e.what()); } // FileCommit(fileout); @@ -109,7 +109,7 @@ CMasternodeDB::ReadResult CMasternodeDB::Read(CMasternodeMan& mnodemanToLoad, bo try { filein.read((char*)&vchData[0], dataSize); filein >> hashIn; - } catch (std::exception& e) { + } catch (const std::exception& e) { error("%s : Deserialize or I/O error - %s", __func__, e.what()); return HashReadError; } @@ -147,7 +147,7 @@ CMasternodeDB::ReadResult CMasternodeDB::Read(CMasternodeMan& mnodemanToLoad, bo } // de-serialize data into CMasternodeMan object ssMasternodes >> mnodemanToLoad; - } catch (std::exception& e) { + } catch (const std::exception& e) { mnodemanToLoad.Clear(); error("%s : Deserialize or I/O error - %s", __func__, e.what()); return IncorrectFormat; diff --git a/src/miner.cpp b/src/miner.cpp index 5b0533a110a2..540bafece6d4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -845,7 +845,7 @@ void static ThreadBitcoinMiner(void* parg) try { BitcoinMiner(pwallet, false); boost::this_thread::interruption_point(); - } catch (std::exception& e) { + } catch (const std::exception& e) { LogPrintf("PIVXMiner exception"); } catch (...) { LogPrintf("PIVXMiner exception"); @@ -890,7 +890,7 @@ void ThreadStakeMinter() try { BitcoinMiner(pwallet, true); boost::this_thread::interruption_point(); - } catch (std::exception& e) { + } catch (const std::exception& e) { LogPrintf("ThreadStakeMinter() exception \n"); } catch (...) { LogPrintf("ThreadStakeMinter() error \n"); diff --git a/src/net.cpp b/src/net.cpp index 0250a1aca8c6..1b158abfe8d8 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1178,7 +1178,7 @@ void ThreadMapPort() MilliSleep(20 * 60 * 1000); // Refresh every 20 minutes } - } catch (boost::thread_interrupted) { + } catch (const boost::thread_interrupted&) { r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", 0); LogPrintf("UPNP_DeletePortMapping() returned : %d\n", r); freeUPNPDevlist(devlist); @@ -1963,7 +1963,7 @@ bool CAddrDB::Write(const CAddrMan& addr) // Write and commit header, data try { fileout << ssPeers; - } catch (std::exception& e) { + } catch (const std::exception& e) { return error("%s : Serialize or I/O error - %s", __func__, e.what()); } FileCommit(fileout.Get()); @@ -1994,7 +1994,7 @@ bool CAddrDB::Read(CAddrMan& addr) try { filein.read((char*)&vchData[0], dataSize); filein >> hashIn; - } catch (std::exception& e) { + } catch (const std::exception& e) { return error("%s : Deserialize or I/O error - %s", __func__, e.what()); } filein.fclose(); @@ -2017,7 +2017,7 @@ bool CAddrDB::Read(CAddrMan& addr) // de-serialize address data into one CAddrMan object ssPeers >> addr; - } catch (std::exception& e) { + } catch (const std::exception& e) { return error("%s : Deserialize or I/O error - %s", __func__, e.what()); } @@ -2152,7 +2152,7 @@ void CNode::EndMessage() UNLOCK_FUNCTION(cs_vSend) Fuzz(GetArg("-fuzzmessagestest", 10)); if (ssSend.size() == 0) { - LEAVE_CRITICAL_SECTION(cs_vSend); + LEAVE_CRITICAL_SECTION(cs_vSend); return; } diff --git a/src/pivx-cli.cpp b/src/pivx-cli.cpp index 2c32a3684d92..b896cf090d74 100644 --- a/src/pivx-cli.cpp +++ b/src/pivx-cli.cpp @@ -90,7 +90,7 @@ static bool AppInitRPC(int argc, char* argv[]) } try { ReadConfigFile(mapArgs, mapMultiArgs); - } catch (std::exception& e) { + } catch (const std::exception& e) { fprintf(stderr, "Error reading configuration file: %s\n", e.what()); return false; } @@ -273,9 +273,9 @@ int CommandLineRPC(int argc, char* argv[]) throw; } } while (fWait); - } catch (boost::thread_interrupted) { + } catch (const boost::thread_interrupted&) { throw; - } catch (std::exception& e) { + } catch (const std::exception& e) { strPrint = std::string("error: ") + e.what(); nRet = EXIT_FAILURE; } catch (...) { @@ -300,7 +300,7 @@ int main(int argc, char* argv[]) try { if (!AppInitRPC(argc, argv)) return EXIT_FAILURE; - } catch (std::exception& e) { + } catch (const std::exception& e) { PrintExceptionContinue(&e, "AppInitRPC()"); return EXIT_FAILURE; } catch (...) { @@ -311,7 +311,7 @@ int main(int argc, char* argv[]) int ret = EXIT_FAILURE; try { ret = CommandLineRPC(argc, argv); - } catch (std::exception& e) { + } catch (const std::exception& e) { PrintExceptionContinue(&e, "CommandLineRPC()"); } catch (...) { PrintExceptionContinue(NULL, "CommandLineRPC()"); diff --git a/src/pivx-tx.cpp b/src/pivx-tx.cpp index 1595541e0d94..821c16e52574 100644 --- a/src/pivx-tx.cpp +++ b/src/pivx-tx.cpp @@ -597,9 +597,9 @@ static int CommandLineRawTx(int argc, char* argv[]) OutputTx(tx); } - catch (boost::thread_interrupted) { + catch (const boost::thread_interrupted&) { throw; - } catch (std::exception& e) { + } catch (const std::exception& e) { strPrint = std::string("error: ") + e.what(); nRet = EXIT_FAILURE; } catch (...) { @@ -620,7 +620,7 @@ int main(int argc, char* argv[]) try { if (!AppInitRawTx(argc, argv)) return EXIT_FAILURE; - } catch (std::exception& e) { + } catch (const std::exception& e) { PrintExceptionContinue(&e, "AppInitRawTx()"); return EXIT_FAILURE; } catch (...) { @@ -631,7 +631,7 @@ int main(int argc, char* argv[]) int ret = EXIT_FAILURE; try { ret = CommandLineRawTx(argc, argv); - } catch (std::exception& e) { + } catch (const std::exception& e) { PrintExceptionContinue(&e, "CommandLineRawTx()"); } catch (...) { PrintExceptionContinue(NULL, "CommandLineRawTx()"); diff --git a/src/pivxd.cpp b/src/pivxd.cpp index ec7b4d454fb9..9e4d1e8cfeda 100644 --- a/src/pivxd.cpp +++ b/src/pivxd.cpp @@ -89,7 +89,7 @@ bool AppInit(int argc, char* argv[]) } try { ReadConfigFile(mapArgs, mapMultiArgs); - } catch (std::exception& e) { + } catch (const std::exception& e) { fprintf(stderr, "Error reading configuration file: %s\n", e.what()); return false; } @@ -141,7 +141,7 @@ bool AppInit(int argc, char* argv[]) SoftSetBoolArg("-server", true); fRet = AppInit2(); - } catch (std::exception& e) { + } catch (const std::exception& e) { PrintExceptionContinue(&e, "AppInit()"); } catch (...) { PrintExceptionContinue(NULL, "AppInit()"); diff --git a/src/protocol.cpp b/src/protocol.cpp index 3b81a519887b..d52b679d956c 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -142,7 +142,7 @@ bool CInv::IsKnownType() const } bool CInv::IsMasterNodeType() const{ - return (type >= 6); + return (type >= 6); } const char* CInv::GetCommand() const diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp index 312c9319ece5..131a4a5f85b8 100644 --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -95,7 +95,7 @@ void FreespaceChecker::check() replyMessage = tr("Path already exists, and is not a directory."); } } - } catch (fs::filesystem_error& e) { + } catch (const fs::filesystem_error& e) { /* Parent directory does not exist or is not accessible */ replyStatus = ST_ERROR; replyMessage = tr("Cannot create data directory here."); @@ -198,7 +198,7 @@ bool Intro::pickDataDirectory() try { TryCreateDirectory(GUIUtil::qstringToBoostPath(dataDir)); break; - } catch (fs::filesystem_error& e) { + } catch (const fs::filesystem_error& e) { QMessageBox::critical(0, tr("PIVX Core"), tr("Error: Specified data directory \"%1\" cannot be created.").arg(dataDir)); // fall through, back to choosing screen diff --git a/src/qt/paymentrequestplus.cpp b/src/qt/paymentrequestplus.cpp index 86f3c86fa6b9..020f158caa86 100644 --- a/src/qt/paymentrequestplus.cpp +++ b/src/qt/paymentrequestplus.cpp @@ -177,7 +177,7 @@ bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) c throw SSLVerifyError("Bad certificate, missing common name."); } // TODO: detect EV certificates and set merchant = business name instead of unfriendly NID_commonName ? - } catch (SSLVerifyError& err) { + } catch (const SSLVerifyError& err) { fResult = false; qWarning() << "PaymentRequestPlus::getMerchant : SSL error: " << err.what(); } diff --git a/src/qt/pivx.cpp b/src/qt/pivx.cpp index 3be19b6834ed..2ef63c7f50b1 100644 --- a/src/qt/pivx.cpp +++ b/src/qt/pivx.cpp @@ -172,7 +172,7 @@ public slots: bool execute_restart; /// Pass fatal exception message to UI thread - void handleRunawayException(std::exception* e); + void handleRunawayException(const std::exception* e); }; /** Main PIVX application object */ @@ -244,7 +244,7 @@ BitcoinCore::BitcoinCore() : QObject() { } -void BitcoinCore::handleRunawayException(std::exception* e) +void BitcoinCore::handleRunawayException(const std::exception* e) { PrintExceptionContinue(e, "Runaway exception"); emit runawayException(QString::fromStdString(strMiscWarning)); @@ -258,7 +258,7 @@ void BitcoinCore::initialize() qDebug() << __func__ << ": Running AppInit2 in thread"; int rv = AppInit2(); emit initializeResult(rv); - } catch (std::exception& e) { + } catch (const std::exception& e) { handleRunawayException(&e); } catch (...) { handleRunawayException(NULL); @@ -279,7 +279,7 @@ void BitcoinCore::restart(QStringList args) QProcess::startDetached(QApplication::applicationFilePath(), args); qDebug() << __func__ << ": Restart initiated..."; QApplication::quit(); - } catch (std::exception& e) { + } catch (const std::exception& e) { handleRunawayException(&e); } catch (...) { handleRunawayException(NULL); @@ -295,7 +295,7 @@ void BitcoinCore::shutdown() Shutdown(); qDebug() << __func__ << ": Shutdown finished"; emit shutdownResult(1); - } catch (std::exception& e) { + } catch (const std::exception& e) { handleRunawayException(&e); } catch (...) { handleRunawayException(NULL); @@ -585,7 +585,7 @@ int main(int argc, char* argv[]) } try { ReadConfigFile(mapArgs, mapMultiArgs); - } catch (std::exception& e) { + } catch (const std::exception& e) { QMessageBox::critical(0, QObject::tr("PIVX Core"), QObject::tr("Error: Cannot parse configuration file: %1. Only use key=value syntax.").arg(e.what())); return 0; @@ -685,7 +685,7 @@ int main(int argc, char* argv[]) app.exec(); app.requestShutdown(); app.exec(); - } catch (std::exception& e) { + } catch (const std::exception& e) { PrintExceptionContinue(&e, "Runaway exception"); app.handleRunawayException(QString::fromStdString(strMiscWarning)); } catch (...) { diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 23425c2fd389..a08124a1957c 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -237,17 +237,17 @@ void RPCExecutor::request(const QString& command) strPrint = result.write(2); emit reply(RPCConsole::CMD_REPLY, QString::fromStdString(strPrint)); - } catch (UniValue& objError) { + } catch (const UniValue& objError) { try // Nice formatting for standard-format error { int code = find_value(objError, "code").get_int(); std::string message = find_value(objError, "message").get_str(); emit reply(RPCConsole::CMD_ERROR, QString::fromStdString(message) + " (code " + QString::number(code) + ")"); - } catch (std::runtime_error&) // raised when converting to invalid type, i.e. missing code or message + } catch (const std::runtime_error&) // raised when converting to invalid type, i.e. missing code or message { // Show raw JSON object emit reply(RPCConsole::CMD_ERROR, QString::fromStdString(objError.write())); } - } catch (std::exception& e) { + } catch (const std::exception& e) { emit reply(RPCConsole::CMD_ERROR, QString("Error: ") + QString::fromStdString(e.what())); } } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 9c8f942e4bc4..31d14ef5955e 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -769,7 +769,7 @@ UniValue gettxout(const UniValue& params, bool fHelp) " \"reqSigs\" : n, (numeric) Number of required signatures\n" " \"type\" : \"pubkeyhash\", (string) The type, eg pubkeyhash\n" " \"addresses\" : [ (array of string) array of pivx addresses\n" - " \"pivxaddress\" (string) pivx address\n" + " \"pivxaddress\" (string) pivx address\n" " ,...\n" " ]\n" " },\n" @@ -1206,7 +1206,7 @@ UniValue findserial(const UniValue& params, bool fHelp) CBigNum bnSerial = 0; bnSerial.SetHex(strSerial); if (!bnSerial) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid serial"); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid serial"); uint256 txid = 0; bool fSuccess = zerocoinDB->ReadCoinSpend(bnSerial, txid); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index e2010dc02923..6ce63fc53a50 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -215,7 +215,7 @@ std::string CRPCTable::help(std::string strCommand) const rpcfn_type pfn = pcmd->actor; if (setDone.insert(pfn).second) (*pfn)(params, true); - } catch (std::exception& e) { + } catch (const std::exception& e) { // Help text is returned in an exception std::string strHelp = std::string(e.what()); if (strCommand == "") { @@ -581,7 +581,7 @@ static UniValue JSONRPCExecOne(const UniValue& req) rpc_result = JSONRPCReplyObj(result, NullUniValue, jreq.id); } catch (const UniValue& objError) { rpc_result = JSONRPCReplyObj(NullUniValue, objError, jreq.id); - } catch (std::exception& e) { + } catch (const std::exception& e) { rpc_result = JSONRPCReplyObj(NullUniValue, JSONRPCError(RPC_PARSE_ERROR, e.what()), jreq.id); } @@ -610,7 +610,7 @@ UniValue CRPCTable::execute(const std::string &strMethod, const UniValue ¶ms try { // Execute return pcmd->actor(params, false); - } catch (std::exception& e) { + } catch (const std::exception& e) { throw JSONRPCError(RPC_MISC_ERROR, e.what()); } diff --git a/src/test/alert_tests.cpp b/src/test/alert_tests.cpp index c7dd4d3594e3..b74c759ece4f 100644 --- a/src/test/alert_tests.cpp +++ b/src/test/alert_tests.cpp @@ -93,7 +93,7 @@ struct ReadAlerts : public TestingSetup alerts.push_back(alert); } } - catch (std::exception) { } + catch (const std::exception&) { } } ~ReadAlerts() { } diff --git a/src/test/benchmark_zerocoin.cpp b/src/test/benchmark_zerocoin.cpp index f1ddb743f297..6e389c24d8c9 100644 --- a/src/test/benchmark_zerocoin.cpp +++ b/src/test/benchmark_zerocoin.cpp @@ -168,7 +168,7 @@ Testb_CalcParamSizes() if (pLen < 3072 || qLen < 320) { result = false; } - } catch (exception &e) { + } catch (const exception &e) { result = false; } #endif @@ -186,7 +186,7 @@ Testb_GenerateGroupParams() try { group = libzerocoin::deriveIntegerGroupParams(libzerocoin::calculateSeed(gGetTestModulus(), "test", ZEROCOIN_DEFAULT_SECURITYLEVEL, "TEST GROUP"), pLen, qLen); - } catch (std::runtime_error e) { + } catch (const std::runtime_error& e) { std::cout << "Caught exception " << e.what() << std::endl; return false; } @@ -220,7 +220,7 @@ Testb_ParamGen() timer.stop(); std::cout << "\tPARAMGEN ELAPSED TIME: " << timer.duration() << " ms\t" << timer.duration()*0.001 << " s" << std::endl; - } catch (std::runtime_error e) { + } catch (const std::runtime_error& e) { std::cout << e.what() << std::endl; result = false; } @@ -271,7 +271,7 @@ Testb_Accumulator() return false; } - } catch (std::runtime_error e) { + } catch (const std::runtime_error& e) { std::cout << e.what() << std::endl; return false; } @@ -289,7 +289,7 @@ Testb_MintCoin() ggCoins[i] = new libzerocoin::PrivateCoin(gg_Params, libzerocoin::CoinDenomination::ZQ_ONE); } timer.stop(); - } catch (std::exception &e) { + } catch (const std::exception& e) { return false; } @@ -360,7 +360,7 @@ Testb_MintAndSpend() std::cout << "\tSPEND VERIFY ELAPSED TIME: " << timer.duration() << " ms\t" << timer.duration()*0.001 << " s" << std::endl; return ret; - } catch (std::runtime_error &e) { + } catch (const std::runtime_error& e) { std::cout << e.what() << std::endl; return false; } diff --git a/src/test/libzerocoin_tests.cpp b/src/test/libzerocoin_tests.cpp index a0452c0654c8..d52a62649c0c 100644 --- a/src/test/libzerocoin_tests.cpp +++ b/src/test/libzerocoin_tests.cpp @@ -140,7 +140,7 @@ Test_CalcParamSizes() if (pLen < 3072 || qLen < 320) { result = false; } - } catch (exception &e) { + } catch (const exception& e) { result = false; } #endif @@ -158,7 +158,7 @@ Test_GenerateGroupParams() try { group = libzerocoin::deriveIntegerGroupParams(libzerocoin::calculateSeed(GetTestModulus(), "test", ZEROCOIN_DEFAULT_SECURITYLEVEL, "TEST GROUP"), pLen, qLen); - } catch (std::runtime_error e) { + } catch (const std::runtime_error& e) { std::cout << "Caught exception " << e.what() << std::endl; return false; } @@ -188,7 +188,7 @@ Test_ParamGen() try { // Instantiating testParams runs the parameter generation code libzerocoin::ZerocoinParams testParams(GetTestModulus(),ZEROCOIN_DEFAULT_SECURITYLEVEL); - } catch (std::runtime_error e) { + } catch (const std::runtime_error& e) { std::cout << e.what() << std::endl; result = false; } @@ -251,7 +251,7 @@ Test_Accumulator() return false; } - } catch (std::runtime_error e) { + } catch (const std::runtime_error& e) { return false; } @@ -307,7 +307,7 @@ Test_EqualityPoK() return false; } - } catch (std::runtime_error &e) { + } catch (const std::runtime_error& e) { return false; } } @@ -333,7 +333,7 @@ Test_MintCoin() gCoinSize /= TESTS_COINS_TO_ACCUMULATE; - } catch (std::exception &e) { + } catch (const std::exception& e) { return false; } @@ -379,7 +379,7 @@ bool Test_InvalidCoin() return false; } - } catch (std::runtime_error &e) { + } catch (const std::runtime_error& e) { std::cout << "Caught exception: " << e.what() << std::endl; return false; } @@ -435,7 +435,7 @@ Test_MintAndSpend() gSerialNumberSize = ceil((double)serialNumber.bitSize() / 8.0); return ret; - } catch (std::runtime_error &e) { + } catch (const std::runtime_error& e) { std::cout << e.what() << std::endl; return false; } diff --git a/src/test/rpc_wallet_tests.cpp b/src/test/rpc_wallet_tests.cpp index 6c23d320b52a..b1d951f319c5 100644 --- a/src/test/rpc_wallet_tests.cpp +++ b/src/test/rpc_wallet_tests.cpp @@ -87,7 +87,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet) CBitcoinAddress setaccountDemoAddress = CBitcoinAddress(CTxDestination(setaccountDemoPubkey.GetID())); /********************************* - * setaccount + * setaccount *********************************/ BOOST_CHECK_NO_THROW(CallRPC("setaccount " + setaccountDemoAddress.ToString() + " nullaccount")); /* D8w12Vu3WVhn543dgrUUf9uYu6HLwnPm5R is not owned by the test wallet. */ @@ -97,7 +97,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet) BOOST_CHECK_THROW(CallRPC("setaccount D8w12Vu3WVhn543dgrUUf9uYu6HLwnPm5 nullaccount"), std::runtime_error); /********************************* - * listunspent + * listunspent *********************************/ BOOST_CHECK_NO_THROW(CallRPC("listunspent")); BOOST_CHECK_THROW(CallRPC("listunspent string"), std::runtime_error); @@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet) BOOST_CHECK(r.get_array().empty()); /********************************* - * listreceivedbyaddress + * listreceivedbyaddress *********************************/ BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaddress")); BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaddress 0")); @@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet) BOOST_CHECK_THROW(CallRPC("listreceivedbyaddress 0 true extra"), std::runtime_error); /********************************* - * listreceivedbyaccount + * listreceivedbyaccount *********************************/ BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaccount")); BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaccount 0")); @@ -128,18 +128,18 @@ BOOST_AUTO_TEST_CASE(rpc_wallet) BOOST_CHECK_THROW(CallRPC("listreceivedbyaccount 0 true extra"), std::runtime_error); /********************************* - * getrawchangeaddress + * getrawchangeaddress *********************************/ BOOST_CHECK_NO_THROW(CallRPC("getrawchangeaddress")); /********************************* - * getnewaddress + * getnewaddress *********************************/ BOOST_CHECK_NO_THROW(CallRPC("getnewaddress")); BOOST_CHECK_NO_THROW(CallRPC("getnewaddress getnewaddress_demoaccount")); /********************************* - * getaccountaddress + * getaccountaddress *********************************/ BOOST_CHECK_NO_THROW(CallRPC("getaccountaddress \"\"")); BOOST_CHECK_NO_THROW(CallRPC("getaccountaddress accountThatDoesntExists")); // Should generate a new account @@ -147,13 +147,13 @@ BOOST_AUTO_TEST_CASE(rpc_wallet) BOOST_CHECK(CBitcoinAddress(retValue.get_str()).Get() == demoAddress.Get()); /********************************* - * getaccount + * getaccount *********************************/ BOOST_CHECK_THROW(CallRPC("getaccount"), std::runtime_error); BOOST_CHECK_NO_THROW(CallRPC("getaccount " + demoAddress.ToString())); /********************************* - * signmessage + verifymessage + * signmessage + verifymessage *********************************/ BOOST_CHECK_NO_THROW(retValue = CallRPC("signmessage " + demoAddress.ToString() + " mymessage")); BOOST_CHECK_THROW(CallRPC("signmessage"), std::runtime_error); @@ -173,7 +173,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet) BOOST_CHECK(CallRPC("verifymessage " + demoAddress.ToString() + " " + retValue.get_str() + " mymessage").get_bool() == true); /********************************* - * getaddressesbyaccount + * getaddressesbyaccount *********************************/ BOOST_CHECK_THROW(CallRPC("getaddressesbyaccount"), std::runtime_error); BOOST_CHECK_NO_THROW(retValue = CallRPC("getaddressesbyaccount " + strAccount)); diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index fad229023944..e12b01cded7b 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -107,8 +107,8 @@ BOOST_AUTO_TEST_CASE(tx_valid) std::map mapprevOutScriptPubKeys; UniValue inputs = test[0].get_array(); bool fValid = true; - for (unsigned int inpIdx = 0; inpIdx < inputs.size(); inpIdx++) { - const UniValue& input = inputs[inpIdx]; + for (unsigned int inpIdx = 0; inpIdx < inputs.size(); inpIdx++) { + const UniValue& input = inputs[inpIdx]; if (!input.isArray()) { fValid = false; @@ -182,8 +182,8 @@ BOOST_AUTO_TEST_CASE(tx_invalid) std::map mapprevOutScriptPubKeys; UniValue inputs = test[0].get_array(); bool fValid = true; - for (unsigned int inpIdx = 0; inpIdx < inputs.size(); inpIdx++) { - const UniValue& input = inputs[inpIdx]; + for (unsigned int inpIdx = 0; inpIdx < inputs.size(); inpIdx++) { + const UniValue& input = inputs[inpIdx]; if (!input.isArray()) { fValid = false; diff --git a/src/test/tutorial_zerocoin.cpp b/src/test/tutorial_zerocoin.cpp index ace7bd60c6ec..9f87ab0459d0 100644 --- a/src/test/tutorial_zerocoin.cpp +++ b/src/test/tutorial_zerocoin.cpp @@ -265,7 +265,7 @@ ZerocoinTutorial() // We're done return true; - } catch (std::runtime_error &e) { + } catch (const std::runtime_error& e) { std::cout << e.what() << std::endl; return false; } diff --git a/src/txdb.cpp b/src/txdb.cpp index 00d2eb0ad912..f5e25b80eb59 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -149,7 +149,7 @@ bool CCoinsViewDB::GetStats(CCoinsStats& stats) const ss << VARINT(0); } pcursor->Next(); - } catch (std::exception& e) { + } catch (const std::exception& e) { return error("%s : Deserialize or I/O error - %s", __func__, e.what()); } } @@ -283,7 +283,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts() } else { break; // if shutdown requested or finished loading block index } - } catch (std::exception& e) { + } catch (const std::exception& e) { return error("%s : Deserialize or I/O error - %s", __func__, e.what()); } } @@ -396,7 +396,7 @@ bool CZerocoinDB::WipeCoins(std::string strType) } else { break; // if shutdown requested or finished loading block index } - } catch (std::exception& e) { + } catch (const std::exception& e) { return error("%s : Deserialize or I/O error - %s", __func__, e.what()); } } diff --git a/src/util.cpp b/src/util.cpp index 365ffd09469e..0a3791e686b6 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -378,7 +378,7 @@ std::string HelpMessageOpt(const std::string &option, const std::string &message std::string("\n\n"); } -static std::string FormatException(std::exception* pex, const char* pszThread) +static std::string FormatException(const std::exception* pex, const char* pszThread) { #ifdef WIN32 char pszModule[MAX_PATH] = ""; @@ -394,7 +394,7 @@ static std::string FormatException(std::exception* pex, const char* pszThread) "UNKNOWN EXCEPTION \n%s in %s \n", pszModule, pszThread); } -void PrintExceptionContinue(std::exception* pex, const char* pszThread) +void PrintExceptionContinue(const std::exception* pex, const char* pszThread) { std::string message = FormatException(pex, pszThread); LogPrintf("\n\n************************\n%s\n", message); @@ -553,7 +553,7 @@ bool TryCreateDirectory(const boost::filesystem::path& p) { try { return boost::filesystem::create_directory(p); - } catch (boost::filesystem::filesystem_error) { + } catch (const boost::filesystem::filesystem_error&) { if (!boost::filesystem::exists(p) || !boost::filesystem::is_directory(p)) throw; } diff --git a/src/util.h b/src/util.h index 0f8f1b297998..d0280a3d5a77 100644 --- a/src/util.h +++ b/src/util.h @@ -123,7 +123,7 @@ static inline bool error(const char* format) double double_safe_addition(double fValue, double fIncrement); double double_safe_multiplication(double fValue, double fmultiplicator); -void PrintExceptionContinue(std::exception* pex, const char* pszThread); +void PrintExceptionContinue(const std::exception* pex, const char* pszThread); void ParseParameters(int argc, const char* const argv[]); void FileCommit(FILE* fileout); bool TruncateFile(FILE* file, unsigned int length); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 20a913ddeeff..a616e6f846c3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3622,7 +3622,7 @@ void static SearchThread(CzPIVWallet* zwallet, int nCountStart, int nCountEnd) zwallet->AddToMintPool(std::make_pair(hashPubcoin, i), true); walletDB.WriteMintPoolPair(hashSeed, hashPubcoin, i); } - } catch (std::exception& e) { + } catch (const std::exception& e) { LogPrintf("SearchThread() exception"); } catch (...) { LogPrintf("SearchThread() exception"); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c77e07c2cf1b..f2e7e7559674 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4023,7 +4023,7 @@ bool CWallet::MintsToInputVector(std::map& mapMintsSelec int64_t nTime5 = GetTimeMicros(); LogPrint("bench", " - CoinSpend verified in %.2fms\n", 0.001 * (nTime5 - nTime4)); - } catch (const std::exception &) { + } catch (const std::exception&) { receipt.SetStatus(_("CoinSpend: Accumulator witness does not verify"), ZPIV_INVALID_WITNESS); return error("%s : %s", __func__, receipt.GetStatusMessage()); } @@ -4822,7 +4822,7 @@ void ThreadPrecomputeSpends() try { pwallet->PrecomputeSpends(); boost::this_thread::interruption_point(); - } catch (std::exception& e) { + } catch (const std::exception& e) { LogPrintf("ThreadPrecomputeSpends() exception: %s \n", e.what()); } catch (...) { LogPrintf("ThreadPrecomputeSpends() error \n"); diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 9677757365e6..ce8996f0971a 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -103,7 +103,7 @@ void CWalletDB::LoadAutoConvertKeys(std::set& setAddresses) std::string strType; try { ssKey >> strType; - } catch(...) { + } catch (...) { break; } if (strType != "automint") @@ -777,7 +777,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) LogPrintf("%s\n", strErr); } pcursor->close(); - } catch (boost::thread_interrupted) { + } catch (const boost::thread_interrupted&) { throw; } catch (...) { result = DB_CORRUPT; @@ -870,7 +870,7 @@ DBErrors CWalletDB::FindWalletTx(CWallet* pwallet, std::vector& vTxHash } } pcursor->close(); - } catch (boost::thread_interrupted) { + } catch (const boost::thread_interrupted&) { throw; } catch (...) { result = DB_CORRUPT; @@ -977,7 +977,7 @@ bool BackupWallet(const CWallet& wallet, const boost::filesystem::path& strDest, } try { boost::filesystem::create_directories(pathCustom); - } catch(const boost::filesystem::filesystem_error& e) { + } catch (const boost::filesystem::filesystem_error& e) { NotifyBacked(wallet, false, strprintf("%s\n", e.what())); pathCustom = ""; } @@ -1047,7 +1047,7 @@ bool BackupWallet(const CWallet& wallet, const boost::filesystem::path& strDest, boost::filesystem::remove(entry->second); LogPrintf("Old backup deleted: %s\n", (*entry).second); } - } catch (boost::filesystem::filesystem_error& error) { + } catch (const boost::filesystem::filesystem_error& error) { std::string strMessage = strprintf("Failed to delete backup %s\n", error.what()); LogPrint(nullptr, strMessage.data()); NotifyBacked(wallet, false, strMessage); diff --git a/src/zpiv/accumulators.cpp b/src/zpiv/accumulators.cpp index ca071fd63e82..14ade298642a 100644 --- a/src/zpiv/accumulators.cpp +++ b/src/zpiv/accumulators.cpp @@ -591,11 +591,11 @@ bool GenerateAccumulatorWitness(CoinWitnessData* coinWitness, AccumulatorMap& ma return true; // TODO: I know that could merge all of this exception but maybe it's not really good.. think if we should have a different treatment for each one - } catch (searchMintHeightException e) { + } catch (const searchMintHeightException& e) { return error("%s: searchMintHeightException: %s", __func__, e.message); - } catch (ChecksumInDbNotFoundException e) { + } catch (const ChecksumInDbNotFoundException& e) { return error("%s: ChecksumInDbNotFoundException: %s", __func__, e.message); - } catch (GetPubcoinException e) { + } catch (const GetPubcoinException& e) { return error("%s: GetPubcoinException: %s", __func__, e.message); } } @@ -789,9 +789,9 @@ bool CalculateAccumulatorWitnessFor( return true; - } catch (ChecksumInDbNotFoundException e) { + } catch (const ChecksumInDbNotFoundException& e) { return error("%s: ChecksumInDbNotFoundException: %s", __func__, e.message); - } catch (GetPubcoinException e) { + } catch (const GetPubcoinException& e) { return error("%s: GetPubcoinException: %s", __func__, e.message); } } @@ -876,11 +876,11 @@ bool GenerateAccumulatorWitness( return true; // TODO: I know that could merge all of this exception but maybe it's not really good.. think if we should have a different treatment for each one - } catch (searchMintHeightException e) { + } catch (const searchMintHeightException& e) { return error("%s: searchMintHeightException: %s", __func__, e.message); - } catch (ChecksumInDbNotFoundException e) { + } catch (const ChecksumInDbNotFoundException& e) { return error("%s: ChecksumInDbNotFoundException: %s", __func__, e.message); - } catch (GetPubcoinException e) { + } catch (const GetPubcoinException& e) { return error("%s: GetPubcoinException: %s", __func__, e.message); } }