Skip to content

Commit

Permalink
[zPIV] use new limit Zerocoin_MaxPublicSpendsPerTransaction for max n…
Browse files Browse the repository at this point in the history
…um of inputs
  • Loading branch information
random-zebra authored and furszy committed May 23, 2019
1 parent e0decb1 commit a8ce671
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -183,6 +184,7 @@ class CChainParams
int64_t nStartMasternodePayments;
std::string zerocoinModulus;
int nMaxZerocoinSpendsPerTransaction;
int nMaxZerocoinPublicSpendsPerTransaction;
CAmount nMinZerocoinMintFee;
CAmount nInvalidAmountFiltered;
int nMintRequiredConfirmations;
Expand Down
16 changes: 13 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
}
Expand Down Expand Up @@ -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<int>(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<int>(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<int>(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()))
Expand Down
6 changes: 3 additions & 3 deletions src/qt/privacydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CMintMeta> 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)
Expand Down Expand Up @@ -5017,11 +5017,13 @@ bool CWallet::CreateZerocoinSpendTransaction(CAmount nValue, CWalletTx& wtxNew,
return false;
}

if ((static_cast<int>(vSelectedMints.size()) > Params().Zerocoin_MaxSpendsPerTransaction())) {

if (static_cast<int>(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;

Expand Down

0 comments on commit a8ce671

Please sign in to comment.