diff --git a/qa/pull-tester/rpc-tests.py b/qa/pull-tester/rpc-tests.py index dd5a541074..3b9174e6a7 100755 --- a/qa/pull-tester/rpc-tests.py +++ b/qa/pull-tester/rpc-tests.py @@ -110,7 +110,7 @@ 'lelantus_spend_gettransaction.py', 'elysium_create_denomination.py', 'elysium_property_creation_fee.py', -# 'elysium_sendmint.py', + 'elysium_sendmint.py', 'elysium_sendmint_wallet_encryption.py', 'elysium_sendspend.py', 'elysium_sendspend_wallet_encryption.py', diff --git a/src/batchproof_container.cpp b/src/batchproof_container.cpp index d82e4638ea..9b89c69b25 100644 --- a/src/batchproof_container.cpp +++ b/src/batchproof_container.cpp @@ -213,7 +213,7 @@ void BatchProofContainer::batch_sigma() { try { if (!sigmaVerifier.batch_verify(anonymity_set, serials, fPadding, setSizes, proofs)) return false; - } catch (const std::exception &) { + } catch (...) { return false; } return true; @@ -316,7 +316,7 @@ void BatchProofContainer::batch_lelantus() { try { if (!sigmaVerifier.batchverify(anonymity_set, challenges, serials, setSizes, proofs)) return false; - } catch (const std::exception &) { + } catch (...) { return false; } return true; @@ -431,7 +431,7 @@ void BatchProofContainer::batch_spark() { bool passed; try { passed = spark::SpendTransaction::verify(params, sparkTransactions, cover_sets); - } catch (const std::exception &) { + } catch (...) { passed = false; } diff --git a/src/bip47/account.cpp b/src/bip47/account.cpp index adb0c7fac6..09ef4ce7b2 100644 --- a/src/bip47/account.cpp +++ b/src/bip47/account.cpp @@ -254,7 +254,7 @@ bool CAccountReceiver::acceptMaskedPayload(std::vector const & ma std::unique_ptr jsplit; try { jsplit = lelantus::ParseLelantusJoinSplit(tx); - }catch (const std::exception &) { + }catch (...) { return false; } if (!jsplit) diff --git a/src/bip47/bip47utils.cpp b/src/bip47/bip47utils.cpp index 8dacc6359b..6b2e482e0d 100644 --- a/src/bip47/bip47utils.cpp +++ b/src/bip47/bip47utils.cpp @@ -170,7 +170,7 @@ GroupElement GeFromPubkey(CPubKey const & pubKey) serializedGe.push_back(0x0); try { result.deserialize(&serializedGe[0]); - } catch (const std::exception &) { + } catch (...) { result = GroupElement(); } return result; diff --git a/src/chainparams.cpp b/src/chainparams.cpp index d14b4a9d3e..348e077684 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -425,7 +425,7 @@ class CMainParams : public CChainParams { GroupElement coin; try { coin.deserialize(ParseHex(str).data()); - } catch (const std::exception &) { + } catch (...) { continue; } consensus.lelantusBlacklist.insert(coin); @@ -435,7 +435,7 @@ class CMainParams : public CChainParams { GroupElement coin; try { coin.deserialize(ParseHex(str).data()); - } catch (const std::exception &) { + } catch (...) { continue; } consensus.sigmaBlacklist.insert(coin); @@ -728,7 +728,7 @@ class CTestNetParams : public CChainParams { GroupElement coin; try { coin.deserialize(ParseHex(str).data()); - } catch (const std::exception &) { + } catch (...) { continue; } consensus.lelantusBlacklist.insert(coin); diff --git a/src/elysium/elysium.cpp b/src/elysium/elysium.cpp index 4d8091f491..0f30f1c643 100644 --- a/src/elysium/elysium.cpp +++ b/src/elysium/elysium.cpp @@ -2329,7 +2329,7 @@ int elysium::WalletTxBuilder( case InputMode::SIGMA: try { if (!pwalletMain->CommitSigmaTransaction(wtxNew, sigmaSelected, sigmaChanges)) return MP_ERR_COMMIT_TX; - } catch (const std::exception &) { + } catch (...) { return MP_ERR_COMMIT_TX; } break; diff --git a/src/elysium/rpctx.cpp b/src/elysium/rpctx.cpp index eb30d4a504..723bdb3661 100644 --- a/src/elysium/rpctx.cpp +++ b/src/elysium/rpctx.cpp @@ -1689,7 +1689,7 @@ UniValue elysium_sendmint(const JSONRPCRequest& request) if (result != 0) { throw JSONRPCError(result, error_str(result)); } - } catch (const std::exception &) { + } catch (...) { for (auto& id : ids) { wallet->DeleteUnconfirmedSigmaMint(id); } diff --git a/src/elysium/wallet.cpp b/src/elysium/wallet.cpp index f8686dfcbe..f1771ea0fe 100644 --- a/src/elysium/wallet.cpp +++ b/src/elysium/wallet.cpp @@ -197,7 +197,7 @@ SigmaPrivateKey Wallet::GetKey(const SigmaMint &mint) // Try all mint wallets try { return mintWalletV1.GeneratePrivateKey(mint.seedId); - } catch (const std::exception &) { + } catch (...) { return mintWalletV0.GeneratePrivateKey(mint.seedId); } } diff --git a/src/hdmint/tracker.cpp b/src/hdmint/tracker.cpp index 677e88c817..c394e721d5 100644 --- a/src/hdmint/tracker.cpp +++ b/src/hdmint/tracker.cpp @@ -546,7 +546,7 @@ bool CHDMintTracker::IsMempoolSpendOurs(const std::set& setMempool, con uint32_t pubcoinId; try { std::tie(spend, pubcoinId) = sigma::ParseSigmaSpend(txin); - } catch (const std::exception &) { + } catch (...) { return false; } @@ -560,7 +560,7 @@ bool CHDMintTracker::IsMempoolSpendOurs(const std::set& setMempool, con std::unique_ptr joinsplit; try { joinsplit = lelantus::ParseLelantusJoinSplit(tx); - } catch (const std::exception &) { + } catch (...) { return false; } diff --git a/src/hdmint/wallet.cpp b/src/hdmint/wallet.cpp index 98444fd720..235995427c 100644 --- a/src/hdmint/wallet.cpp +++ b/src/hdmint/wallet.cpp @@ -1183,7 +1183,7 @@ bool CHDMintWallet::TxOutToPublicCoin(const CTxOut& txout, sigma::PublicCoin& pu secp_primitives::GroupElement publicSigma; try { publicSigma.deserialize(&coin_serialised[0]); - } catch (const std::exception &) { + } catch (...) { return state.DoS(100, error("TxOutToPublicCoin : deserialize failed")); } diff --git a/src/lelantus.cpp b/src/lelantus.cpp index 7b6df0a744..57a0f29687 100644 --- a/src/lelantus.cpp +++ b/src/lelantus.cpp @@ -402,7 +402,7 @@ bool CheckLelantusJoinSplitTransaction( REJECT_MALFORMED, "CheckLelantusJoinSplitTransaction: invalid joinsplit transaction"); } - catch (const std::exception &) { + catch (...) { return state.DoS(100, false, REJECT_MALFORMED, @@ -444,13 +444,8 @@ bool CheckLelantusJoinSplitTransaction( for (const CTxOut &txout : tx.vout) { if (!txout.scriptPubKey.empty() && txout.scriptPubKey.IsLelantusJMint()) { - try { - if (!CheckLelantusJMintTransaction(txout, state, hashTx, fStatefulSigmaCheck, Cout, lelantusTxInfo)) - return false; - } - catch (const std::exception &x) { - return state.Error(x.what()); - } + if (!CheckLelantusJMintTransaction(txout, state, hashTx, fStatefulSigmaCheck, Cout, lelantusTxInfo)) + return false; } else if(txout.scriptPubKey.IsLelantusMint()) { return false; //putting regular mints at JoinSplit transactions is not allowed } else { @@ -772,13 +767,8 @@ bool CheckLelantusTransaction( if (allowLelantus && !isVerifyDB) { for (const CTxOut &txout : tx.vout) { if (!txout.scriptPubKey.empty() && txout.scriptPubKey.IsLelantusMint()) { - try { - if (!CheckLelantusMintTransaction(txout, state, hashTx, fStatefulSigmaCheck, lelantusTxInfo)) - return false; - } - catch (const std::exception &x) { - return state.Error(x.what()); - } + if (!CheckLelantusMintTransaction(txout, state, hashTx, fStatefulSigmaCheck, lelantusTxInfo)) + return false; } } } @@ -799,15 +789,10 @@ bool CheckLelantusTransaction( } if (!isVerifyDB) { - try { - if (!CheckLelantusJoinSplitTransaction( - tx, state, hashTx, isVerifyDB, nHeight, realHeight, - isCheckWallet, fStatefulSigmaCheck, sigmaTxInfo, lelantusTxInfo)) { - return false; - } - } - catch (const std::exception &x) { - return state.Error(x.what()); + if (!CheckLelantusJoinSplitTransaction( + tx, state, hashTx, isVerifyDB, nHeight, realHeight, + isCheckWallet, fStatefulSigmaCheck, sigmaTxInfo, lelantusTxInfo)) { + return false; } } } @@ -830,7 +815,7 @@ void RemoveLelantusJoinSplitReferencingBlock(CTxMemPool& pool, CBlockIndex* bloc try { joinsplit = ParseLelantusJoinSplit(tx); } - catch (const std::exception &) { + catch (...) { txn_to_remove.push_back(tx); break; } @@ -869,7 +854,7 @@ std::vector GetLelantusJoinSplitSerialNumbers(const CTransaction &tx, co try { return ParseLelantusJoinSplit(tx)->getCoinSerialNumbers(); } - catch (const std::exception &) { + catch (...) { return std::vector(); } } @@ -881,7 +866,7 @@ std::vector GetLelantusJoinSplitIds(const CTransaction &tx, const CTxI try { return ParseLelantusJoinSplit(tx)->getCoinGroupIds(); } - catch (const std::exception &) { + catch (...) { return std::vector(); } } @@ -1021,7 +1006,7 @@ bool GetOutPointFromBlock(COutPoint& outPoint, const GroupElement &pubCoinValue, try { ParseLelantusMintScript(txout.scriptPubKey, txPubCoinValue); } - catch (const std::exception &) { + catch (...) { continue; } if(pubCoinValue==txPubCoinValue){ @@ -1146,11 +1131,13 @@ void CLelantusState::Containers::RemoveMint(lelantus::PublicCoin const & pubCoin } void CLelantusState::Containers::AddSpend(Scalar const & serial, int coinGroupId) { - if (mintMetaInfo.count(coinGroupId) > 0) { - usedCoinSerials[serial] = coinGroupId; - spendMetaInfo[coinGroupId] += 1; - CheckSurgeCondition(); + if (!mintMetaInfo.count(coinGroupId)) { + throw std::invalid_argument("group id doesn't exist"); } + + usedCoinSerials[serial] = coinGroupId; + spendMetaInfo[coinGroupId] += 1; + CheckSurgeCondition(); } void CLelantusState::Containers::RemoveSpend(Scalar const & serial) { diff --git a/src/liblelantus/lelantus_prover.cpp b/src/liblelantus/lelantus_prover.cpp index 3154b51ea6..96d908b676 100644 --- a/src/liblelantus/lelantus_prover.cpp +++ b/src/liblelantus/lelantus_prover.cpp @@ -155,7 +155,7 @@ void LelantusProver::generate_sigma_proofs( parallelTasks.emplace_back(threadPool.PostTask([&]() { try { prover.sigma_commit(commits, index, rA_i, rB_i, rC_i, rD_i, a_i, Tk_i, Pk_i, Yk_i, sigma_i, proof); - } catch (const std::exception &) { + } catch (...) { return false; } return true; diff --git a/src/libspark/coin.cpp b/src/libspark/coin.cpp index 27ca2f56e0..785cc1de90 100644 --- a/src/libspark/coin.cpp +++ b/src/libspark/coin.cpp @@ -127,7 +127,7 @@ IdentifiedCoinData Coin::identify(const IncomingViewKey& incoming_view_key) { // Decrypt recipient data CDataStream stream = AEAD::decrypt_and_verify(this->K*incoming_view_key.get_s1(), "Mint coin data", this->r_); stream >> r; - } catch (const std::exception &) { + } catch (...) { throw std::runtime_error("Unable to identify coin"); } @@ -142,7 +142,7 @@ IdentifiedCoinData Coin::identify(const IncomingViewKey& incoming_view_key) { // Decrypt recipient data CDataStream stream = AEAD::decrypt_and_verify(this->K*incoming_view_key.get_s1(), "Spend coin data", this->r_); stream >> r; - } catch (const std::exception &) { + } catch (...) { throw std::runtime_error("Unable to identify coin"); } diff --git a/src/libspark/hash.cpp b/src/libspark/hash.cpp index 2c6d71317d..c37d29a1ea 100644 --- a/src/libspark/hash.cpp +++ b/src/libspark/hash.cpp @@ -83,7 +83,7 @@ Scalar Hash::finalize_scalar() { EVP_MD_CTX_free(state_finalize); return candidate; - } catch (const std::exception &) { + } catch (...) { counter++; } } @@ -144,7 +144,7 @@ GroupElement Hash::finalize_group() { EVP_MD_CTX_free(state_finalize); return candidate; - } catch (const std::exception &) { + } catch (...) { counter++; } } diff --git a/src/libspark/transcript.cpp b/src/libspark/transcript.cpp index 5cd67c63c0..8cada15b2e 100644 --- a/src/libspark/transcript.cpp +++ b/src/libspark/transcript.cpp @@ -139,7 +139,7 @@ Scalar Transcript::challenge(const std::string label) { EVP_MD_CTX_free(state_finalize); return candidate; - } catch (const std::exception &) { + } catch (...) { counter++; } } diff --git a/src/libspark/util.cpp b/src/libspark/util.cpp index 4547251320..cb3bed31fe 100644 --- a/src/libspark/util.cpp +++ b/src/libspark/util.cpp @@ -125,7 +125,7 @@ GroupElement SparkUtils::hash_generator(const std::string label) { EVP_MD_CTX_free(state_finalize); return candidate; - } catch (const std::exception &) { + } catch (...) { counter++; } } diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index 379d54dca6..c1bd864d17 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -267,7 +267,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco try { nTxFee = lelantus::ParseLelantusJoinSplit(*wtx.tx)->getFee(); } - catch (const std::exception &) { + catch (...) { //do nothing } } diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 5360253cdc..ff6bb99e27 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -65,7 +65,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet * if (isAllJoinSplitFromMe && wtx.tx->vin.size() > 0) { try { nTxFee = lelantus::ParseLelantusJoinSplit(*wtx.tx)->getFee(); - } catch (const std::exception &) { + } catch (...) { // do nothing } } diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index c2fe430098..38606f55ed 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -127,7 +127,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) try { jsplit = lelantus::ParseLelantusJoinSplit(tx); } - catch (const std::exception &) { + catch (...) { continue; } in.push_back(Pair("nFees", ValueFromAmount(jsplit->getFee()))); @@ -143,7 +143,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) try { sparkSpend = std::make_unique(spark::ParseSparkSpend(tx)); } - catch (const std::exception &) { + catch (...) { continue; } in.push_back(Pair("nFees", ValueFromAmount(sparkSpend->getFee()))); diff --git a/src/sigma.cpp b/src/sigma.cpp index 23236241e6..ae32d83b3a 100644 --- a/src/sigma.cpp +++ b/src/sigma.cpp @@ -457,13 +457,8 @@ bool CheckSigmaTransaction( if (allowSigma) { for (const CTxOut &txout : tx.vout) { if (!txout.scriptPubKey.empty() && txout.scriptPubKey.IsSigmaMint()) { - try { - if (!CheckSigmaMintTransaction(txout, state, hashTx, fStatefulSigmaCheck, sigmaTxInfo)) - return false; - } - catch (const std::exception &x) { - return state.Error(x.what()); - } + if (!CheckSigmaMintTransaction(txout, state, hashTx, fStatefulSigmaCheck, sigmaTxInfo)) + return false; } } } @@ -513,15 +508,10 @@ bool CheckSigmaTransaction( // Check vOut // Only one loop, we checked on the format before entering this case if (!isVerifyDB) { - try { - if (!CheckSigmaSpendTransaction( - tx, denominations, state, hashTx, isVerifyDB, nHeight, realHeight, - isCheckWallet, fStatefulSigmaCheck, sigmaTxInfo)) { - return false; - } - } - catch (const std::exception &x) { - return state.Error(x.what()); + if (!CheckSigmaSpendTransaction( + tx, denominations, state, hashTx, isVerifyDB, nHeight, realHeight, + isCheckWallet, fStatefulSigmaCheck, sigmaTxInfo)) { + return false; } } } @@ -675,7 +665,7 @@ bool GetOutPointFromBlock(COutPoint& outPoint, const GroupElement &pubCoinValue, txout.scriptPubKey.end()); try { txPubCoinValue.deserialize(&coin_serialised[0]); - } catch (const std::exception &) { + } catch (...) { return false; } if(pubCoinValue==txPubCoinValue){ diff --git a/src/spark/sparkwallet.cpp b/src/spark/sparkwallet.cpp index 36c1c7cdbe..01c632c813 100644 --- a/src/spark/sparkwallet.cpp +++ b/src/spark/sparkwallet.cpp @@ -260,7 +260,7 @@ bool CSparkWallet::isAddressMine(const std::string& encodedAddr) { spark::Address address(params); try { address.decode(encodedAddr); - } catch (const std::exception &) { + } catch (...) { return false; } @@ -273,7 +273,7 @@ bool CSparkWallet::isAddressMine(const std::string& encodedAddr) { try { d = viewKey.get_diversifier(address.get_d()); - } catch (const std::exception &) { + } catch (...) { return false; } @@ -437,7 +437,7 @@ bool CSparkWallet::getMintAmount(spark::Coin coin, CAmount& amount) { spark::IdentifiedCoinData identifiedCoinData; try { identifiedCoinData = coin.identify(this->viewKey); - } catch (const std::exception &) { + } catch (...) { return false; } amount = identifiedCoinData.v; @@ -501,7 +501,7 @@ void CSparkWallet::UpdateSpendStateFromBlock(const CBlock& block) { uint256 lTagHash = primitives::GetLTagHash(txLTag); UpdateSpendState(txLTag, lTagHash, txHash); } - } catch (const std::exception &) { + } catch (...) { } } } @@ -511,7 +511,7 @@ void CSparkWallet::UpdateSpendStateFromBlock(const CBlock& block) { bool CSparkWallet::isMine(spark::Coin coin) const { try { spark::IdentifiedCoinData identifiedCoinData = coin.identify(this->viewKey); - } catch (const std::exception &) { + } catch (...) { return false; } diff --git a/src/spark/state.cpp b/src/spark/state.cpp index c5e65cb7a9..3a301804bc 100644 --- a/src/spark/state.cpp +++ b/src/spark/state.cpp @@ -129,7 +129,7 @@ void ParseSparkMintTransaction(const std::vector& scripts, MintTransact } try { mintTransaction.setMintTransaction(serializedCoins); - } catch (const std::exception &) { + } catch (...) { throw std::invalid_argument("Unable to deserialize Spark mint transaction"); } } @@ -152,7 +152,7 @@ void ParseSparkMintCoin(const CScript& script, spark::Coin& txCoin) try { stream >> txCoin; - } catch (const std::exception &) { + } catch (...) { throw std::invalid_argument("Unable to deserialize Spark mint"); } } @@ -184,7 +184,7 @@ std::vector GetSparkUsedTags(const CTransaction &tx) spark::SpendTransaction spendTransaction(params); try { spendTransaction = ParseSparkSpend(tx); - } catch (const std::exception &) { + } catch (...) { return std::vector(); } @@ -205,7 +205,7 @@ std::vector GetSparkMintCoins(const CTransaction &tx) ParseSparkMintCoin(script, coin); coin.setSerialContext(serial_context); result.push_back(coin); - } catch (const std::exception &) { + } catch (...) { //Continue } } @@ -332,7 +332,7 @@ void RemoveSpendReferencingBlock(CTxMemPool& pool, CBlockIndex* blockIndex) { try { sparkSpend = std::make_unique(ParseSparkSpend(tx)); } - catch (const std::exception &) { + catch (...) { txn_to_remove.push_back(tx); break; } @@ -470,7 +470,7 @@ bool CheckSparkSMintTransaction( spark::Coin coin(Params::get_default()); ParseSparkMintCoin(script, coin); out_coins.push_back(coin); - } catch (const std::exception &) { + } catch (...) { return state.DoS(100, false, REJECT_INVALID, @@ -529,7 +529,7 @@ bool CheckSparkSpendTransaction( REJECT_MALFORMED, "CheckSparkSpendTransaction: invalid spend transaction"); } - catch (const std::exception &) { + catch (...) { return state.DoS(100, false, REJECT_MALFORMED, @@ -653,7 +653,7 @@ bool CheckSparkSpendTransaction( } else { try { passVerify = spark::SpendTransaction::verify(*spend, cover_sets); - } catch (const std::exception &) { + } catch (...) { passVerify = false; } } @@ -730,14 +730,9 @@ bool CheckSparkTransaction( } } if (!txOuts.empty()) { - try { - if (!CheckSparkMintTransaction(txOuts, state, hashTx, fStatefulSigmaCheck, sparkTxInfo)) { - LogPrintf("CheckSparkTransaction::Mint verification failed.\n"); - return false; - } - } - catch (const std::exception &x) { - return state.Error(x.what()); + if (!CheckSparkMintTransaction(txOuts, state, hashTx, fStatefulSigmaCheck, sparkTxInfo)) { + LogPrintf("CheckSparkTransaction::Mint verification failed.\n"); + return false; } } else { return state.DoS(100, false, @@ -755,15 +750,10 @@ bool CheckSparkTransaction( } if (!isVerifyDB) { - try { - if (!CheckSparkSpendTransaction( - tx, state, hashTx, isVerifyDB, nHeight, - isCheckWallet, fStatefulSigmaCheck, sparkTxInfo)) { - return false; - } - } - catch (const std::exception &x) { - return state.Error(x.what()); + if (!CheckSparkSpendTransaction( + tx, state, hashTx, isVerifyDB, nHeight, + isCheckWallet, fStatefulSigmaCheck, sparkTxInfo)) { + return false; } } } @@ -820,7 +810,7 @@ bool GetOutPointFromBlock(COutPoint& outPoint, const spark::Coin& coin, const CB try { ParseSparkMintCoin(txout.scriptPubKey, txCoin); } - catch (const std::exception &) { + catch (...) { continue; } if (coin == txCoin) { @@ -840,7 +830,7 @@ std::vector getSerialContext(const CTransaction &tx) { try { spark::SpendTransaction spend = ParseSparkSpend(tx); serialContextStream << spend.getUsedLTags(); - } catch (const std::exception &) { + } catch (...) { return std::vector(); } } else { diff --git a/src/test/lelantus_state_tests.cpp b/src/test/lelantus_state_tests.cpp index a48dc54c0e..a493271952 100644 --- a/src/test/lelantus_state_tests.cpp +++ b/src/test/lelantus_state_tests.cpp @@ -187,6 +187,9 @@ BOOST_AUTO_TEST_CASE(serial_adding) BOOST_CHECK(!lelantusState->IsUsedCoinSerial(serial2)); BOOST_CHECK(!lelantusState->IsUsedCoinSerialHash(receivedSerial, serialHash2)); + + // add serials to group that doesn't exist, should fail + BOOST_CHECK_THROW(lelantusState->AddSpend(Scalar(1), 100), std::invalid_argument); } BOOST_AUTO_TEST_CASE(mempool) diff --git a/src/validation.cpp b/src/validation.cpp index 7e9e3901c3..aad1ea69f1 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -862,7 +862,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C catch (CBadTxIn&) { return state.Invalid(false, REJECT_CONFLICT, "txn-invalid-lelantus-joinsplit"); } - catch (const std::exception &) { + catch (...) { return state.Invalid(false, REJECT_CONFLICT, "failed to deserialize joinsplit"); } @@ -905,7 +905,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C try { sparkUsedLTags = spark::GetSparkUsedTags(tx); } - catch (const std::exception &) { + catch (...) { return state.Invalid(false, REJECT_CONFLICT, "failed to deserialize spark spend"); } @@ -953,7 +953,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C try { sparkMintCoins = spark::GetSparkMintCoins(tx); } - catch (const std::exception &) { + catch (...) { return state.Invalid(false, REJECT_CONFLICT, "failed to deserialize spark mint"); } @@ -1149,7 +1149,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C catch (CBadTxIn&) { return state.DoS(0, false, REJECT_INVALID, "unable to parse joinsplit"); } - catch (const std::exception &) { + catch (...) { return state.DoS(0, false, REJECT_INVALID, "failed to deserialize joinsplit"); } } else { @@ -1159,7 +1159,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C catch (CBadTxIn&) { return state.DoS(0, false, REJECT_INVALID, "unable to parse joinsplit"); } - catch (const std::exception &) { + catch (...) { return state.DoS(0, false, REJECT_INVALID, "failed to deserialize joinsplit"); } } @@ -1593,14 +1593,7 @@ bool AcceptToMemoryPoolWithTime(CTxMemPool& pool, CValidationState &state, const { LogPrintf("AcceptToMemoryPool(), transaction: %s\n", tx->GetHash().ToString()); std::vector coins_to_uncache; - bool res = false; - try { - res = AcceptToMemoryPoolWorker(pool, state, tx, fLimitFree, pfMissingInputs, nAcceptTime, plTxnReplaced, fOverrideMempoolLimit, nAbsurdFee, coins_to_uncache, isCheckWalletTransaction, markFiroSpendTransactionSerial); - } - catch (const std::exception &x) { - state.Error(x.what()); - res = false; - } + bool res = AcceptToMemoryPoolWorker(pool, state, tx, fLimitFree, pfMissingInputs, nAcceptTime, plTxnReplaced, fOverrideMempoolLimit, nAbsurdFee, coins_to_uncache, isCheckWalletTransaction, markFiroSpendTransactionSerial); if (!res) { BOOST_FOREACH(const COutPoint& hashTx, coins_to_uncache) pcoinsTip->Uncache(hashTx); @@ -2092,7 +2085,7 @@ bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoins catch (CBadTxIn&) { return state.DoS(0, false, REJECT_INVALID, "unable to parse joinsplit"); } - catch (const std::exception &) { + catch (...) { return state.DoS(0, false, REJECT_INVALID, "failed to deserialize joinsplit"); } } @@ -2529,7 +2522,7 @@ static DisconnectResult DisconnectBlock(const CBlock& block, CValidationState& s try { nFees += lelantus::ParseLelantusJoinSplit(tx)->getFee(); } - catch (const std::exception &) { + catch (...) { // do nothing } } @@ -2537,7 +2530,7 @@ static DisconnectResult DisconnectBlock(const CBlock& block, CValidationState& s try { nFees = spark::ParseSparkSpend(tx).getFee(); } - catch (const std::exception &) { + catch (...) { // do nothing } } @@ -2927,7 +2920,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin catch (CBadTxIn&) { return state.DoS(0, false, REJECT_INVALID, "unable to parse joinsplit"); } - catch (const std::exception &) { + catch (...) { return state.DoS(0, false, REJECT_INVALID, "failed to deserialize joinsplit"); } } @@ -2939,7 +2932,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin catch (CBadTxIn&) { return state.DoS(0, false, REJECT_INVALID, "unable to parse spark spend"); } - catch (const std::exception &) { + catch (...) { return state.DoS(0, false, REJECT_INVALID, "failed to deserialize spark spend"); } } @@ -3495,7 +3488,7 @@ bool static DisconnectTip(CValidationState& state, const CChainParams& chainpara try { joinsplit = lelantus::ParseLelantusJoinSplit(*tx); } - catch (const std::exception &) { + catch (...) { continue; } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d2c74a34ae..97947e3b7f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2082,14 +2082,14 @@ UniValue gettransaction(const JSONRPCRequest& request) try { nFee = (0 - lelantus::ParseLelantusJoinSplit(*wtx.tx)->getFee()); } - catch (const std::exception &) { + catch (...) { // do nothing } } else if (wtx.tx->IsSparkSpend()) { try { nFee = (0 - spark::ParseSparkSpend(*wtx.tx).getFee()); } - catch (const std::exception &) { + catch (...) { // do nothing } } @@ -3440,7 +3440,7 @@ UniValue getsparkaddressbalance(const JSONRPCRequest& request) { unsigned char coinNetwork; try { coinNetwork = address.decode(strAddress); - } catch (const std::exception &) { + } catch (...) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Spark address: ")+strAddress); } @@ -3562,7 +3562,7 @@ UniValue mintspark(const JSONRPCRequest& request) unsigned char coinNetwork; try { coinNetwork = address.decode(name_); - } catch (const std::exception &) { + } catch (...) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Spark address: ")+name_); } @@ -3697,7 +3697,7 @@ UniValue spendspark(const JSONRPCRequest& request) isSparkAddress = true; if (coinNetwork != network) throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid address, wrong network type: ")+name_); - } catch (const std::exception &) { + } catch (...) { isSparkAddress = false; } @@ -3771,7 +3771,7 @@ UniValue spendspark(const JSONRPCRequest& request) CWalletTx wtx; try { wtx = pwallet->SpendAndStoreSpark(recipients, privateRecipients, fee); - } catch (const std::exception &) { + } catch (...) { throw JSONRPCError(RPC_WALLET_ERROR, "Spark spend creation failed."); } @@ -3803,7 +3803,7 @@ UniValue lelantustospark(const JSONRPCRequest& request) { bool passed = false; try { passed = pwallet->LelantusToSpark(strFailReason); - } catch (const std::exception &) { + } catch (...) { throw JSONRPCError(RPC_WALLET_ERROR, "Lelantus to Spark failed!"); } if (!passed || strFailReason != "") @@ -4754,7 +4754,7 @@ UniValue listlelantusjoinsplits(const JSONRPCRequest& request) { std::unique_ptr joinsplit; try { joinsplit = lelantus::ParseLelantusJoinSplit(*pwtx->tx); - } catch (const std::exception &) { + } catch (...) { continue; } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index d21d140ee5..a86adce8bb 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1491,7 +1491,7 @@ bool CWallet::AbandonTransaction(const uint256& hashTx) try { joinsplit = lelantus::ParseLelantusJoinSplit(*wtx.tx); } - catch (const std::exception &) { + catch (...) { continue; } @@ -1517,7 +1517,7 @@ bool CWallet::AbandonTransaction(const uint256& hashTx) spark::SpendTransaction spend = spark::ParseSparkSpend(*wtx.tx); lTags = spend.getUsedLTags(); } - catch (const std::exception &) { + catch (...) { continue; } @@ -1672,7 +1672,7 @@ isminetype CWallet::IsMine(const CTxIn &txin, const CTransaction& tx) const try { joinsplit = lelantus::ParseLelantusJoinSplit(tx); } - catch (const std::exception &) { + catch (...) { return ISMINE_NO; } @@ -1687,7 +1687,7 @@ isminetype CWallet::IsMine(const CTxIn &txin, const CTransaction& tx) const spark::SpendTransaction spend = spark::ParseSparkSpend(tx); lTags = spend.getUsedLTags(); } - catch (const std::exception &) { + catch (...) { return ISMINE_NO; } if (!sparkWallet) @@ -1745,7 +1745,7 @@ CAmount CWallet::GetDebit(const CTxIn &txin, const CTransaction& tx, const ismin try { joinsplit = lelantus::ParseLelantusJoinSplit(tx); } - catch (const std::exception &) { + catch (...) { goto end; } @@ -1767,7 +1767,7 @@ CAmount CWallet::GetDebit(const CTxIn &txin, const CTransaction& tx, const ismin spark::SpendTransaction spend = spark::ParseSparkSpend(tx); lTags = spend.getUsedLTags(); } - catch (const std::exception &) { + catch (...) { goto end; } if (!sparkWallet) @@ -1929,7 +1929,7 @@ CAmount CWallet::GetChange(const uint256& tx, const CTxOut &txout) const try { spark::ParseSparkMintCoin(txout.scriptPubKey, coin); coin.setSerialContext(serial_context); - } catch (const std::exception &) { + } catch (...) { return 0; } return sparkWallet->getMyCoinV(coin); @@ -2289,14 +2289,14 @@ void CWalletTx::GetAmounts(std::list& listReceived, try { nFee = lelantus::ParseLelantusJoinSplit(*tx)->getFee(); } - catch (const std::exception &) { + catch (...) { // do nothing } } else if (tx->IsSparkSpend()) { try { nFee = spark::ParseSparkSpend(*tx).getFee(); } - catch (const std::exception &) { + catch (...) { // do nothing } } else { @@ -2745,7 +2745,7 @@ bool CWalletTx::IsChange(uint32_t out) const { try { spark::ParseSparkMintCoin(tx->vout[out].scriptPubKey, coin); coin.setSerialContext(serial_context); - } catch (const std::exception &) { + } catch (...) { return false; } return pwallet->sparkWallet->getMyCoinIsChange(coin); @@ -5627,7 +5627,7 @@ bool CWallet::CommitSigmaTransaction(CWalletTx& wtxNew, std::vector CValidationState state; CReserveKey reserveKey(this); CommitTransaction(wtxNew, reserveKey, g_connman.get(), state); - } catch (const std::exception &) { + } catch (...) { auto error = _( "Error: The transaction was rejected! This might happen if some of " "the coins in your wallet were already spent, such as if you used " @@ -5776,7 +5776,7 @@ CWalletTx CWallet::SpendAndStoreSpark( CValidationState state; CReserveKey reserveKey(this); CommitTransaction(result, reserveKey, g_connman.get(), state); - } catch (const std::exception &) { + } catch (...) { auto error = _( "Error: The transaction was rejected! This might happen if some of " "the coins in your wallet were already spent, such as if you used " @@ -5937,7 +5937,7 @@ bool CWallet::CommitLelantusTransaction(CWalletTx& wtxNew, std::vector