Skip to content

Commit a8ce671

Browse files
random-zebrafurszy
authored andcommitted
[zPIV] use new limit Zerocoin_MaxPublicSpendsPerTransaction for max num of inputs
1 parent e0decb1 commit a8ce671

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

src/chainparams.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class CMainParams : public CChainParams
239239
"8441436038339044149526344321901146575444541784240209246165157233507787077498171257724679629263863563732899121548"
240240
"31438167899885040445364023527381951378636564391212010397122822120720357";
241241
nMaxZerocoinSpendsPerTransaction = 7; // Assume about 20kb each
242+
nMaxZerocoinPublicSpendsPerTransaction = 637; // Assume about 220 bytes each input
242243
nMinZerocoinMintFee = 1 * CENT; //high fee required for zerocoin mints
243244
nMintRequiredConfirmations = 20; //the maximum amount of confirmations until accumulated in 19
244245
nRequiredAccumulation = 1;

src/chainparams.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class CChainParams
109109
std::string Zerocoin_Modulus() const { return zerocoinModulus; }
110110
libzerocoin::ZerocoinParams* Zerocoin_Params(bool useModulusV1) const;
111111
int Zerocoin_MaxSpendsPerTransaction() const { return nMaxZerocoinSpendsPerTransaction; }
112+
int Zerocoin_MaxPublicSpendsPerTransaction() const { return nMaxZerocoinPublicSpendsPerTransaction; }
112113
CAmount Zerocoin_MintFee() const { return nMinZerocoinMintFee; }
113114
int Zerocoin_MintRequiredConfirmations() const { return nMintRequiredConfirmations; }
114115
int Zerocoin_RequiredAccumulation() const { return nRequiredAccumulation; }
@@ -183,6 +184,7 @@ class CChainParams
183184
int64_t nStartMasternodePayments;
184185
std::string zerocoinModulus;
185186
int nMaxZerocoinSpendsPerTransaction;
187+
int nMaxZerocoinPublicSpendsPerTransaction;
186188
CAmount nMinZerocoinMintFee;
187189
CAmount nInvalidAmountFiltered;
188190
int nMintRequiredConfirmations;

src/main.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ bool CheckTransaction(const CTransaction& tx, bool fZerocoinActive, bool fReject
12131213
//duplicate zcspend serials are checked in CheckZerocoinSpend()
12141214
if (!txin.IsZerocoinSpend()) {
12151215
vInOutPoints.insert(txin.prevout);
1216-
} else {
1216+
} else if (!txin.IsZerocoinPublicSpend()) {
12171217
nZCSpendCount++;
12181218
}
12191219
}
@@ -1242,8 +1242,18 @@ bool CheckTransaction(const CTransaction& tx, bool fZerocoinActive, bool fReject
12421242
return state.DoS(100, error("CheckTransaction() : coinbase script size=%d", tx.vin[0].scriptSig.size()),
12431243
REJECT_INVALID, "bad-cb-length");
12441244
} else if (fZerocoinActive && tx.HasZerocoinSpendInputs()) {
1245-
if(tx.vin.size() < 1 || static_cast<int>(tx.vin.size()) > Params().Zerocoin_MaxSpendsPerTransaction())
1246-
return state.DoS(10, error("CheckTransaction() : Zerocoin Spend has more than allowed txin's"), REJECT_INVALID, "bad-zerocoinspend");
1245+
if (tx.vin.size() < 1)
1246+
return state.DoS(10, error("CheckTransaction() : Zerocoin Spend has less than allowed txin's"), REJECT_INVALID, "bad-zerocoinspend");
1247+
if (tx.HasZerocoinPublicSpendInputs()) {
1248+
// tx has public zerocoin spend inputs
1249+
if(static_cast<int>(tx.vin.size()) > Params().Zerocoin_MaxPublicSpendsPerTransaction())
1250+
return state.DoS(10, error("CheckTransaction() : Zerocoin Spend has more than allowed txin's"), REJECT_INVALID, "bad-zerocoinspend");
1251+
} else {
1252+
// tx has regular zerocoin spend inputs
1253+
if(static_cast<int>(tx.vin.size()) > Params().Zerocoin_MaxSpendsPerTransaction())
1254+
return state.DoS(10, error("CheckTransaction() : Zerocoin Spend has more than allowed txin's"), REJECT_INVALID, "bad-zerocoinspend");
1255+
}
1256+
12471257
} else {
12481258
for (const CTxIn& txin : tx.vin)
12491259
if (txin.prevout.IsNull() && (fZerocoinActive && !txin.IsZerocoinSpend()))

src/qt/privacydialog.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,17 +439,17 @@ void PrivacyDialog::sendzPIV()
439439
// Display errors during spend
440440
if (!fSuccess) {
441441
int nNeededSpends = receipt.GetNeededSpends(); // Number of spends we would need for this transaction
442-
const int nMaxSpends = Params().Zerocoin_MaxSpendsPerTransaction(); // Maximum possible spends for one zPIV transaction
442+
/*const int nMaxSpends = Params().Zerocoin_MaxSpendsPerTransaction(); // Maximum possible spends for one zPIV transaction
443443
if (nNeededSpends > nMaxSpends) {
444444
QString strStatusMessage = tr("Too much inputs (") + QString::number(nNeededSpends, 10) + tr(") needed.\nMaximum allowed: ") + QString::number(nMaxSpends, 10);
445445
strStatusMessage += tr("\nEither mint higher denominations (so fewer inputs are needed) or reduce the amount to spend.");
446446
QMessageBox::warning(this, tr("Spend Zerocoin"), strStatusMessage.toStdString().c_str(), QMessageBox::Ok, QMessageBox::Ok);
447447
ui->TEMintStatus->setPlainText(tr("Spend Zerocoin failed with status = ") +QString::number(receipt.GetStatus(), 10) + "\n" + "Message: " + QString::fromStdString(strStatusMessage.toStdString()));
448448
}
449-
else {
449+
else {*/
450450
QMessageBox::warning(this, tr("Spend Zerocoin"), receipt.GetStatusMessage().c_str(), QMessageBox::Ok, QMessageBox::Ok);
451451
ui->TEMintStatus->setPlainText(tr("Spend Zerocoin failed with status = ") +QString::number(receipt.GetStatus(), 10) + "\n" + "Message: " + QString::fromStdString(receipt.GetStatusMessage()));
452-
}
452+
//}
453453
ui->zPIVpayAmount->setFocus();
454454
ui->TEMintStatus->repaint();
455455
ui->TEMintStatus->verticalScrollBar()->setValue(ui->TEMintStatus->verticalScrollBar()->maximum()); // Automatically scroll to end of text

src/wallet/wallet.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4924,7 +4924,7 @@ bool CWallet::CreateZerocoinSpendTransaction(CAmount nValue, CWalletTx& wtxNew,
49244924
CAmount nValueSelected = 0;
49254925
int nCoinsReturned = 0; // Number of coins returned in change from function below (for debug)
49264926
int nNeededSpends = 0; // Number of spends which would be needed if selection failed
4927-
const int nMaxSpends = Params().Zerocoin_MaxSpendsPerTransaction(); // Maximum possible spends for one zPIV transaction
4927+
const int nMaxSpends = Params().Zerocoin_MaxPublicSpendsPerTransaction(); // Maximum possible spends for one zPIV public spend transaction
49284928
vector<CMintMeta> vMintsToFetch;
49294929
if (vSelectedMints.empty()) {
49304930
// 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,
50175017
return false;
50185018
}
50195019

5020-
if ((static_cast<int>(vSelectedMints.size()) > Params().Zerocoin_MaxSpendsPerTransaction())) {
5020+
5021+
if (static_cast<int>(vSelectedMints.size()) > nMaxSpends) {
50215022
receipt.SetStatus(_("Failed to find coin set amongst held coins with less than maxNumber of Spends"), nStatus);
50225023
return false;
50235024
}
50245025

5026+
50255027
// Create change if needed
50265028
nStatus = ZPIV_TRX_CHANGE;
50275029

0 commit comments

Comments
 (0)