diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 94e365022c6c9..8e337eff4296f 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -239,6 +239,7 @@ class CMainParams : public CChainParams "8441436038339044149526344321901146575444541784240209246165157233507787077498171257724679629263863563732899121548" "31438167899885040445364023527381951378636564391212010397122822120720357"; nMaxZerocoinSpendsPerTransaction = 7; // Assume about 20kb each + nMaxZerocoinPublicSpendsPerTransaction = 637; // Assume about 220 bytes each input nMinZerocoinMintFee = 1 * CENT; //high fee required for zerocoin mints nMintRequiredConfirmations = 20; //the maximum amount of confirmations until accumulated in 19 nRequiredAccumulation = 1; diff --git a/src/chainparams.h b/src/chainparams.h index 0eba67a86b67d..87011e34cc277 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -109,6 +109,7 @@ class CChainParams std::string Zerocoin_Modulus() const { return zerocoinModulus; } libzerocoin::ZerocoinParams* Zerocoin_Params(bool useModulusV1) const; int Zerocoin_MaxSpendsPerTransaction() const { return nMaxZerocoinSpendsPerTransaction; } + int Zerocoin_MaxPublicSpendsPerTransaction() const { return nMaxZerocoinPublicSpendsPerTransaction; } CAmount Zerocoin_MintFee() const { return nMinZerocoinMintFee; } int Zerocoin_MintRequiredConfirmations() const { return nMintRequiredConfirmations; } int Zerocoin_RequiredAccumulation() const { return nRequiredAccumulation; } @@ -183,6 +184,7 @@ class CChainParams int64_t nStartMasternodePayments; std::string zerocoinModulus; int nMaxZerocoinSpendsPerTransaction; + int nMaxZerocoinPublicSpendsPerTransaction; CAmount nMinZerocoinMintFee; CAmount nInvalidAmountFiltered; int nMintRequiredConfirmations; diff --git a/src/main.cpp b/src/main.cpp index 0349986218044..69f50ca0841d0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1213,7 +1213,7 @@ bool CheckTransaction(const CTransaction& tx, bool fZerocoinActive, bool fReject //duplicate zcspend serials are checked in CheckZerocoinSpend() if (!txin.IsZerocoinSpend()) { vInOutPoints.insert(txin.prevout); - } else { + } else if (!txin.IsZerocoinPublicSpend()) { nZCSpendCount++; } } @@ -1242,8 +1242,18 @@ bool CheckTransaction(const CTransaction& tx, bool fZerocoinActive, bool fReject return state.DoS(100, error("CheckTransaction() : coinbase script size=%d", tx.vin[0].scriptSig.size()), REJECT_INVALID, "bad-cb-length"); } else if (fZerocoinActive && tx.HasZerocoinSpendInputs()) { - if(tx.vin.size() < 1 || static_cast(tx.vin.size()) > Params().Zerocoin_MaxSpendsPerTransaction()) - return state.DoS(10, error("CheckTransaction() : Zerocoin Spend has more than allowed txin's"), REJECT_INVALID, "bad-zerocoinspend"); + if (tx.vin.size() < 1) + return state.DoS(10, error("CheckTransaction() : Zerocoin Spend has less than allowed txin's"), REJECT_INVALID, "bad-zerocoinspend"); + if (tx.HasZerocoinPublicSpendInputs()) { + // tx has public zerocoin spend inputs + if(static_cast(tx.vin.size()) > Params().Zerocoin_MaxPublicSpendsPerTransaction()) + return state.DoS(10, error("CheckTransaction() : Zerocoin Spend has more than allowed txin's"), REJECT_INVALID, "bad-zerocoinspend"); + } else { + // tx has regular zerocoin spend inputs + if(static_cast(tx.vin.size()) > Params().Zerocoin_MaxSpendsPerTransaction()) + return state.DoS(10, error("CheckTransaction() : Zerocoin Spend has more than allowed txin's"), REJECT_INVALID, "bad-zerocoinspend"); + } + } else { for (const CTxIn& txin : tx.vin) if (txin.prevout.IsNull() && (fZerocoinActive && !txin.IsZerocoinSpend())) diff --git a/src/qt/privacydialog.cpp b/src/qt/privacydialog.cpp index 5510b3cc89610..566f349017bf3 100644 --- a/src/qt/privacydialog.cpp +++ b/src/qt/privacydialog.cpp @@ -439,17 +439,17 @@ void PrivacyDialog::sendzPIV() // Display errors during spend if (!fSuccess) { int nNeededSpends = receipt.GetNeededSpends(); // Number of spends we would need for this transaction - const int nMaxSpends = Params().Zerocoin_MaxSpendsPerTransaction(); // Maximum possible spends for one zPIV transaction + /*const int nMaxSpends = Params().Zerocoin_MaxSpendsPerTransaction(); // Maximum possible spends for one zPIV transaction if (nNeededSpends > nMaxSpends) { QString strStatusMessage = tr("Too much inputs (") + QString::number(nNeededSpends, 10) + tr(") needed.\nMaximum allowed: ") + QString::number(nMaxSpends, 10); strStatusMessage += tr("\nEither mint higher denominations (so fewer inputs are needed) or reduce the amount to spend."); QMessageBox::warning(this, tr("Spend Zerocoin"), strStatusMessage.toStdString().c_str(), QMessageBox::Ok, QMessageBox::Ok); ui->TEMintStatus->setPlainText(tr("Spend Zerocoin failed with status = ") +QString::number(receipt.GetStatus(), 10) + "\n" + "Message: " + QString::fromStdString(strStatusMessage.toStdString())); } - else { + else {*/ QMessageBox::warning(this, tr("Spend Zerocoin"), receipt.GetStatusMessage().c_str(), QMessageBox::Ok, QMessageBox::Ok); ui->TEMintStatus->setPlainText(tr("Spend Zerocoin failed with status = ") +QString::number(receipt.GetStatus(), 10) + "\n" + "Message: " + QString::fromStdString(receipt.GetStatusMessage())); - } + //} ui->zPIVpayAmount->setFocus(); ui->TEMintStatus->repaint(); ui->TEMintStatus->verticalScrollBar()->setValue(ui->TEMintStatus->verticalScrollBar()->maximum()); // Automatically scroll to end of text diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index e9ad8a3597e99..8b575d7a04ca9 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4924,7 +4924,7 @@ bool CWallet::CreateZerocoinSpendTransaction(CAmount nValue, CWalletTx& wtxNew, CAmount nValueSelected = 0; int nCoinsReturned = 0; // Number of coins returned in change from function below (for debug) int nNeededSpends = 0; // Number of spends which would be needed if selection failed - const int nMaxSpends = Params().Zerocoin_MaxSpendsPerTransaction(); // Maximum possible spends for one zPIV transaction + const int nMaxSpends = Params().Zerocoin_MaxPublicSpendsPerTransaction(); // Maximum possible spends for one zPIV public spend transaction vector vMintsToFetch; if (vSelectedMints.empty()) { // All of the zPIV used in the public coin spend are mature by default (everything is public now.. no need to wait for any accumulation) @@ -5017,11 +5017,13 @@ bool CWallet::CreateZerocoinSpendTransaction(CAmount nValue, CWalletTx& wtxNew, return false; } - if ((static_cast(vSelectedMints.size()) > Params().Zerocoin_MaxSpendsPerTransaction())) { + + if (static_cast(vSelectedMints.size()) > nMaxSpends) { receipt.SetStatus(_("Failed to find coin set amongst held coins with less than maxNumber of Spends"), nStatus); return false; } + // Create change if needed nStatus = ZPIV_TRX_CHANGE;