Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deal with runaway exceptions #1345

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/batchproof_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void BatchProofContainer::batch_sigma() {
try {
if (!sigmaVerifier.batch_verify(anonymity_set, serials, fPadding, setSizes, proofs))
return false;
} catch (...) {
} catch (const std::exception &) {
return false;
}
return true;
Expand Down Expand Up @@ -311,7 +311,7 @@ void BatchProofContainer::batch_lelantus() {
try {
if (!sigmaVerifier.batchverify(anonymity_set, challenges, serials, setSizes, proofs))
return false;
} catch (...) {
} catch (const std::exception &) {
return false;
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/bip47/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ bool CAccountReceiver::acceptMaskedPayload(std::vector<unsigned char> const & ma
std::unique_ptr<lelantus::JoinSplit> jsplit;
try {
jsplit = lelantus::ParseLelantusJoinSplit(tx);
}catch (...) {
}catch (const std::exception &) {
return false;
}
if (!jsplit)
Expand Down
2 changes: 1 addition & 1 deletion src/bip47/bip47utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ GroupElement GeFromPubkey(CPubKey const & pubKey)
serializedGe.push_back(0x0);
try {
result.deserialize(&serializedGe[0]);
} catch (...) {
} catch (const std::exception &) {
result = GroupElement();
}
return result;
Expand Down
6 changes: 3 additions & 3 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ class CMainParams : public CChainParams {
GroupElement coin;
try {
coin.deserialize(ParseHex(str).data());
} catch (...) {
} catch (const std::exception &) {
continue;
}
consensus.lelantusBlacklist.insert(coin);
Expand All @@ -430,7 +430,7 @@ class CMainParams : public CChainParams {
GroupElement coin;
try {
coin.deserialize(ParseHex(str).data());
} catch (...) {
} catch (const std::exception &) {
continue;
}
consensus.sigmaBlacklist.insert(coin);
Expand Down Expand Up @@ -717,7 +717,7 @@ class CTestNetParams : public CChainParams {
GroupElement coin;
try {
coin.deserialize(ParseHex(str).data());
} catch (...) {
} catch (const std::exception &) {
continue;
}
consensus.lelantusBlacklist.insert(coin);
Expand Down
2 changes: 1 addition & 1 deletion src/elysium/elysium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2329,7 +2329,7 @@ int elysium::WalletTxBuilder(
case InputMode::SIGMA:
try {
if (!pwalletMain->CommitSigmaTransaction(wtxNew, sigmaSelected, sigmaChanges)) return MP_ERR_COMMIT_TX;
} catch (...) {
} catch (const std::exception &) {
return MP_ERR_COMMIT_TX;
}
break;
Expand Down
2 changes: 1 addition & 1 deletion src/elysium/rpctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,7 @@ UniValue elysium_sendmint(const JSONRPCRequest& request)
if (result != 0) {
throw JSONRPCError(result, error_str(result));
}
} catch (...) {
} catch (const std::exception &) {
for (auto& id : ids) {
wallet->DeleteUnconfirmedSigmaMint(id);
}
Expand Down
2 changes: 1 addition & 1 deletion src/elysium/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ SigmaPrivateKey Wallet::GetKey(const SigmaMint &mint)
// Try all mint wallets
try {
return mintWalletV1.GeneratePrivateKey(mint.seedId);
} catch (...) {
} catch (const std::exception &) {
return mintWalletV0.GeneratePrivateKey(mint.seedId);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/hdmint/tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ bool CHDMintTracker::IsMempoolSpendOurs(const std::set<uint256>& setMempool, con
uint32_t pubcoinId;
try {
std::tie(spend, pubcoinId) = sigma::ParseSigmaSpend(txin);
} catch (...) {
} catch (const std::exception &) {
return false;
}

Expand All @@ -560,7 +560,7 @@ bool CHDMintTracker::IsMempoolSpendOurs(const std::set<uint256>& setMempool, con
std::unique_ptr<lelantus::JoinSplit> joinsplit;
try {
joinsplit = lelantus::ParseLelantusJoinSplit(tx);
} catch (...) {
} catch (const std::exception &) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hdmint/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ bool CHDMintWallet::TxOutToPublicCoin(const CTxOut& txout, sigma::PublicCoin& pu
secp_primitives::GroupElement publicSigma;
try {
publicSigma.deserialize(&coin_serialised[0]);
} catch (...) {
} catch (const std::exception &) {
return state.DoS(100, error("TxOutToPublicCoin : deserialize failed"));
}

Expand Down
71 changes: 46 additions & 25 deletions src/lelantus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ bool CheckLelantusJoinSplitTransaction(
REJECT_MALFORMED,
"CheckLelantusJoinSplitTransaction: invalid joinsplit transaction");
}
catch (...) {
catch (const std::exception &) {
return state.DoS(100,
false,
REJECT_MALFORMED,
Expand Down Expand Up @@ -433,8 +433,13 @@ bool CheckLelantusJoinSplitTransaction(

for (const CTxOut &txout : tx.vout) {
if (!txout.scriptPubKey.empty() && txout.scriptPubKey.IsLelantusJMint()) {
if (!CheckLelantusJMintTransaction(txout, state, hashTx, fStatefulSigmaCheck, Cout, lelantusTxInfo))
return false;
try {
if (!CheckLelantusJMintTransaction(txout, state, hashTx, fStatefulSigmaCheck, Cout, lelantusTxInfo))
return false;
}
catch (const std::exception &x) {
return state.Error(x.what());
}
} else if(txout.scriptPubKey.IsLelantusMint()) {
return false; //putting regular mints at JoinSplit transactions is not allowed
} else {
Expand Down Expand Up @@ -537,6 +542,13 @@ bool CheckLelantusJoinSplitTransaction(
anonymity_sets[idAndHash.first] = anonymity_set;
}

const std::vector<uint32_t>& ids = joinsplit->getCoinGroupIds();
for (const auto& id: ids) {
if (!anonymity_sets.count(id))
return state.DoS(100,
error("CheckLelantusJoinSplitTransaction: No anonymity set found."));
}

BatchProofContainer* batchProofContainer = BatchProofContainer::get_instance();
bool useBatching = batchProofContainer->fCollectProofs && !isVerifyDB && !isCheckWallet && lelantusTxInfo && !lelantusTxInfo->fInfoIsComplete;

Expand Down Expand Up @@ -740,8 +752,13 @@ bool CheckLelantusTransaction(
if (allowLelantus && !isVerifyDB) {
for (const CTxOut &txout : tx.vout) {
if (!txout.scriptPubKey.empty() && txout.scriptPubKey.IsLelantusMint()) {
if (!CheckLelantusMintTransaction(txout, state, hashTx, fStatefulSigmaCheck, lelantusTxInfo))
return false;
try {
if (!CheckLelantusMintTransaction(txout, state, hashTx, fStatefulSigmaCheck, lelantusTxInfo))
return false;
}
catch (const std::exception &x) {
return state.Error(x.what());
}
}
}
}
Expand All @@ -762,10 +779,15 @@ bool CheckLelantusTransaction(
}

if (!isVerifyDB) {
if (!CheckLelantusJoinSplitTransaction(
tx, state, hashTx, isVerifyDB, nHeight, realHeight,
isCheckWallet, fStatefulSigmaCheck, sigmaTxInfo, lelantusTxInfo)) {
return false;
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());
}
}
}
Expand All @@ -788,7 +810,7 @@ void RemoveLelantusJoinSplitReferencingBlock(CTxMemPool& pool, CBlockIndex* bloc
try {
joinsplit = ParseLelantusJoinSplit(tx);
}
catch (...) {
catch (const std::exception &) {
txn_to_remove.push_back(tx);
break;
}
Expand Down Expand Up @@ -827,7 +849,7 @@ std::vector<Scalar> GetLelantusJoinSplitSerialNumbers(const CTransaction &tx, co
try {
return ParseLelantusJoinSplit(tx)->getCoinSerialNumbers();
}
catch (...) {
catch (const std::exception &) {
return std::vector<Scalar>();
}
}
Expand All @@ -839,7 +861,7 @@ std::vector<uint32_t> GetLelantusJoinSplitIds(const CTransaction &tx, const CTxI
try {
return ParseLelantusJoinSplit(tx)->getCoinGroupIds();
}
catch (...) {
catch (const std::exception &) {
return std::vector<uint32_t>();
}
}
Expand Down Expand Up @@ -899,15 +921,17 @@ bool ConnectBlockLelantus(
)) {
return false;
}
}

if (!fJustCheck) {
if (!fJustCheck) {
BOOST_FOREACH(auto& serial, pblock->lelantusTxInfo->spentSerials) {
pindexNew->lelantusSpentSerials.insert(serial);
lelantusState.AddSpend(serial.first, serial.second);
}
}

if (fJustCheck)
else {
return true;
}

const auto& params = ::Params().GetConsensus();
CHash256 hash;
Expand Down Expand Up @@ -979,7 +1003,7 @@ bool GetOutPointFromBlock(COutPoint& outPoint, const GroupElement &pubCoinValue,
try {
ParseLelantusMintScript(txout.scriptPubKey, txPubCoinValue);
}
catch (...) {
catch (const std::exception &) {
continue;
}
if(pubCoinValue==txPubCoinValue){
Expand Down Expand Up @@ -1098,13 +1122,11 @@ void CLelantusState::Containers::RemoveMint(lelantus::PublicCoin const & pubCoin
}

void CLelantusState::Containers::AddSpend(Scalar const & serial, int coinGroupId) {
if (!mintMetaInfo.count(coinGroupId)) {
throw std::invalid_argument("group id doesn't exist");
if (mintMetaInfo.count(coinGroupId) > 0) {
usedCoinSerials[serial] = coinGroupId;
spendMetaInfo[coinGroupId] += 1;
CheckSurgeCondition();
}

usedCoinSerials[serial] = coinGroupId;
spendMetaInfo[coinGroupId] += 1;
CheckSurgeCondition();
}

void CLelantusState::Containers::RemoveSpend(Scalar const & serial) {
Expand Down Expand Up @@ -1294,9 +1316,8 @@ void CLelantusState::RemoveBlock(CBlockIndex *index) {
// roll back coin group updates
for (auto &coins : index->lelantusMintedPubCoins)
{
if (coinGroups.count(coins.first) == 0) {
throw std::invalid_argument("Group Id does not exist");
}
if (coinGroups.count(coins.first) == 0)
continue;

LelantusCoinGroupInfo& coinGroup = coinGroups[coins.first];
auto nMintsToForget = coins.second.size();
Expand Down
2 changes: 1 addition & 1 deletion src/liblelantus/lelantus_prover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (...) {
} catch (const std::exception &) {
return false;
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/transactiondesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
try {
nTxFee = lelantus::ParseLelantusJoinSplit(*wtx.tx)->getFee();
}
catch (...) {
catch (const std::exception &) {
//do nothing
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
if (isAllJoinSplitFromMe && wtx.tx->vin.size() > 0) {
try {
nTxFee = lelantus::ParseLelantusJoinSplit(*wtx.tx)->getFee();
} catch (...) {
} catch (const std::exception &) {
// do nothing
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
try {
jsplit = lelantus::ParseLelantusJoinSplit(tx);
}
catch (...) {
catch (const std::exception &) {
continue;
}
in.push_back(Pair("nFees", ValueFromAmount(jsplit->getFee())));
Expand Down
32 changes: 22 additions & 10 deletions src/sigma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,13 @@ bool CheckSigmaTransaction(
if (allowSigma) {
for (const CTxOut &txout : tx.vout) {
if (!txout.scriptPubKey.empty() && txout.scriptPubKey.IsSigmaMint()) {
if (!CheckSigmaMintTransaction(txout, state, hashTx, fStatefulSigmaCheck, sigmaTxInfo))
return false;
try {
if (!CheckSigmaMintTransaction(txout, state, hashTx, fStatefulSigmaCheck, sigmaTxInfo))
return false;
}
catch (const std::exception &x) {
return state.Error(x.what());
}
}
}
}
Expand Down Expand Up @@ -506,10 +511,15 @@ bool CheckSigmaTransaction(
// Check vOut
// Only one loop, we checked on the format before entering this case
if (!isVerifyDB) {
if (!CheckSigmaSpendTransaction(
tx, denominations, state, hashTx, isVerifyDB, nHeight, realHeight,
isCheckWallet, fStatefulSigmaCheck, sigmaTxInfo)) {
return false;
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());
}
}
}
Expand Down Expand Up @@ -631,15 +641,17 @@ bool ConnectBlockSigma(
)) {
return false;
}
}

if (!fJustCheck) {
if (!fJustCheck) {
BOOST_FOREACH(auto& serial, pblock->sigmaTxInfo->spentSerials) {
pindexNew->sigmaSpentSerials.insert(serial);
sigmaState.AddSpend(serial.first, serial.second.denomination, serial.second.coinGroupId);
}
}

if (fJustCheck)
else {
return true;
}

sigmaState.AddMintsToStateAndBlockIndex(pindexNew, pblock);
}
Expand All @@ -663,7 +675,7 @@ bool GetOutPointFromBlock(COutPoint& outPoint, const GroupElement &pubCoinValue,
txout.scriptPubKey.end());
try {
txPubCoinValue.deserialize(&coin_serialised[0]);
} catch (...) {
} catch (const std::exception &) {
return false;
}
if(pubCoinValue==txPubCoinValue){
Expand Down
3 changes: 0 additions & 3 deletions src/test/lelantus_state_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ 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)
Expand Down
Loading
Loading