Skip to content

Commit 2e86345

Browse files
committed
Only require 2 mints be added to the accumulator before spending.
1 parent fd3b6aa commit 2e86345

File tree

8 files changed

+32
-25
lines changed

8 files changed

+32
-25
lines changed

src/accumulators.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,10 @@ bool GenerateAccumulatorWitness(const PublicCoin &coin, Accumulator& accumulator
237237
//Get the accumulator that is right before the cluster of blocks containing our mint was added to the accumulator
238238
CBigNum bnAccValue = 0;
239239
if (GetAccumulatorValueFromDB(nCheckpointBeforeMint, coin.getDenomination(), bnAccValue)) {
240-
accumulator.setValue(bnAccValue);
241-
witness.resetValue(accumulator, coin);
240+
if (bnAccValue > 0) {
241+
accumulator.setValue(bnAccValue);
242+
witness.resetValue(accumulator, coin);
243+
}
242244
}
243245

244246
//security level: this is an important prevention of tracing the coins via timing. Security level represents how many checkpoints
@@ -282,13 +284,13 @@ bool GenerateAccumulatorWitness(const PublicCoin &coin, Accumulator& accumulator
282284
//grab mints from this block
283285
CBlock block;
284286
if(!ReadBlockFromDisk(block, pindex)) {
285-
LogPrint("zero","%s: failed to read block from disk while adding pubcoins to witness\n", __func__);
287+
LogPrintf("%s: failed to read block from disk while adding pubcoins to witness\n", __func__);
286288
return false;
287289
}
288290

289291
std::vector<CBigNum> vValues;
290292
if(!BlockToMintValueVector(block, coin.getDenomination(), vValues)) {
291-
LogPrint("zero","%s: failed to get zerocoin mintlist from block %n\n", __func__, pindex->nHeight);
293+
LogPrintf("%s: failed to get zerocoin mintlist from block %n\n", __func__, pindex->nHeight);
292294
return false;
293295
}
294296

@@ -305,8 +307,8 @@ bool GenerateAccumulatorWitness(const PublicCoin &coin, Accumulator& accumulator
305307
pindex = chainActive[pindex->nHeight + 1];
306308
}
307309

308-
if (nMintsAdded < 3) {
309-
strError = _("Less than 3 mints added, unable to create spend");
310+
if (nMintsAdded < Params().Zerocoin_RequiredAccumulation()) {
311+
strError = _(strprintf("Less than %d mints added, unable to create spend", Params().Zerocoin_RequiredAccumulation()).c_str());
310312
LogPrintf("%s : %s\n", __func__, strError);
311313
return false;
312314
}

src/chainparams.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ class CMainParams : public CChainParams
205205
nMaxZerocoinSpendsPerTransaction = 7; // Assume about 20kb each
206206
nMinZerocoinMintFee = 1 * CENT; //high fee required for zerocoin mints
207207
nMintRequiredConfirmations = 20; //the maximum amount of confirmations until accumulated in 19
208+
nRequiredAccumulation = 2;
208209
nDefaultSecurityLevel = 100; //full security level for accumulators
209210
nZerocoinHeaderVersion = 4; //Block headers must be this version once zerocoin is active
210211
nBudget_Fee_Confirmations = 6; // Number of confirmations for the finalization fee
@@ -244,6 +245,7 @@ class CTestNetParams : public CMainParams
244245
nMasternodeCountDrift = 4;
245246
nModifierUpdateBlock = 51197; //approx Mon, 17 Apr 2017 04:00:00 GMT
246247
nMaxMoneyOut = 43199500 * COIN;
248+
nZerocoinStartHeight = 201576;
247249

248250
//! Modify the testnet genesis block so the timestamp is valid for a later start.
249251
genesis.nTime = 1454124731;

src/chainparams.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class CChainParams
105105
int Zerocoin_MaxSpendsPerTransaction() const { return nMaxZerocoinSpendsPerTransaction; }
106106
CAmount Zerocoin_MintFee() const { return nMinZerocoinMintFee; }
107107
int Zerocoin_MintRequiredConfirmations() const { return nMintRequiredConfirmations; }
108+
int Zerocoin_RequiredAccumulation() const { return nRequiredAccumulation; }
108109
int Zerocoin_DefaultSpendSecurity() const { return nDefaultSecurityLevel; }
109110
int Zerocoin_HeaderVersion() const { return nZerocoinHeaderVersion; }
110111

@@ -160,6 +161,7 @@ class CChainParams
160161
int nMaxZerocoinSpendsPerTransaction;
161162
CAmount nMinZerocoinMintFee;
162163
int nMintRequiredConfirmations;
164+
int nRequiredAccumulation;
163165
int nDefaultSecurityLevel;
164166
int nZerocoinHeaderVersion;
165167
int64_t nBudget_Fee_Confirmations;

src/qt/forms/privacydialog.ui

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@
581581
<property name="toolTip">
582582
<string>Available (mature and spendable) zPIV for spending
583583

584-
zPIV are mature when they have more than 20 confirmations AND more than 3 mints of the same denomination after them were minted</string>
584+
zPIV are mature when they have more than 20 confirmations AND more than 2 mints of the same denomination after them were minted</string>
585585
</property>
586586
<property name="text">
587587
<string>0 zPIV</string>
@@ -1048,7 +1048,7 @@ zPIV are mature when they have more than 20 confirmations AND more than 3 mints
10481048
</property>
10491049
<property name="toolTip">
10501050
<string>Unconfirmed: less than 20 confirmations
1051-
Immature: confirmed, but less than 3 mints of the same denomination after it was minted</string>
1051+
Immature: confirmed, but less than 2 mints of the same denomination after it was minted</string>
10521052
</property>
10531053
<property name="text">
10541054
<string>0 x</string>
@@ -1101,7 +1101,7 @@ Immature: confirmed, but less than 3 mints of the same denomination after it was
11011101
</property>
11021102
<property name="toolTip">
11031103
<string>Unconfirmed: less than 20 confirmations
1104-
Immature: confirmed, but less than 3 mints of the same denomination after it was minted</string>
1104+
Immature: confirmed, but less than 2 mints of the same denomination after it was minted</string>
11051105
</property>
11061106
<property name="text">
11071107
<string>0 x</string>
@@ -1154,7 +1154,7 @@ Immature: confirmed, but less than 3 mints of the same denomination after it was
11541154
</property>
11551155
<property name="toolTip">
11561156
<string>Unconfirmed: less than 20 confirmations
1157-
Immature: confirmed, but less than 3 mints of the same denomination after it was minted</string>
1157+
Immature: confirmed, but less than 2 mints of the same denomination after it was minted</string>
11581158
</property>
11591159
<property name="text">
11601160
<string>0 x</string>
@@ -1207,7 +1207,7 @@ Immature: confirmed, but less than 3 mints of the same denomination after it was
12071207
</property>
12081208
<property name="toolTip">
12091209
<string>Unconfirmed: less than 20 confirmations
1210-
Immature: confirmed, but less than 3 mints of the same denomination after it was minted</string>
1210+
Immature: confirmed, but less than 2 mints of the same denomination after it was minted</string>
12111211
</property>
12121212
<property name="text">
12131213
<string>0 x</string>
@@ -1260,7 +1260,7 @@ Immature: confirmed, but less than 3 mints of the same denomination after it was
12601260
</property>
12611261
<property name="toolTip">
12621262
<string>Unconfirmed: less than 20 confirmations
1263-
Immature: confirmed, but less than 3 mints of the same denomination after it was minted</string>
1263+
Immature: confirmed, but less than 2 mints of the same denomination after it was minted</string>
12641264
</property>
12651265
<property name="text">
12661266
<string>0 x</string>
@@ -1313,7 +1313,7 @@ Immature: confirmed, but less than 3 mints of the same denomination after it was
13131313
</property>
13141314
<property name="toolTip">
13151315
<string>Unconfirmed: less than 20 confirmations
1316-
Immature: confirmed, but less than 3 mints of the same denomination after it was minted</string>
1316+
Immature: confirmed, but less than 2 mints of the same denomination after it was minted</string>
13171317
</property>
13181318
<property name="text">
13191319
<string>0 x</string>
@@ -1366,7 +1366,7 @@ Immature: confirmed, but less than 3 mints of the same denomination after it was
13661366
</property>
13671367
<property name="toolTip">
13681368
<string>Unconfirmed: less than 20 confirmations
1369-
Immature: confirmed, but less than 3 mints of the same denomination after it was minted</string>
1369+
Immature: confirmed, but less than 2 mints of the same denomination after it was minted</string>
13701370
</property>
13711371
<property name="text">
13721372
<string>0 x</string>
@@ -1419,7 +1419,7 @@ Immature: confirmed, but less than 3 mints of the same denomination after it was
14191419
</property>
14201420
<property name="toolTip">
14211421
<string>Unconfirmed: less than 20 confirmations
1422-
Immature: confirmed, but less than 3 mints of the same denomination after it was minted</string>
1422+
Immature: confirmed, but less than 2 mints of the same denomination after it was minted</string>
14231423
</property>
14241424
<property name="text">
14251425
<string>0 x</string>

src/qt/privacydialog.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -555,21 +555,21 @@ void PrivacyDialog::setBalance(const CAmount& balance, const CAmount& unconfirme
555555
// All denominations
556556
mapDenomBalances.at(mint.GetDenomination())++;
557557

558-
if (!mint.GetHeight() || mint.GetHeight() > chainActive.Height() - Params().Zerocoin_MintRequiredConfirmations()) {
558+
if (!mint.GetHeight() || chainActive.Height() - mint.GetHeight() <= Params().Zerocoin_MintRequiredConfirmations()) {
559559
// All unconfirmed denominations
560560
mapUnconfirmed.at(mint.GetDenomination())++;
561561
}
562562
else {
563563
// After a denomination is confirmed it might still be immature because < 3 of the same denomination were minted after it
564-
CBlockIndex *pindex = chainActive[mint.GetHeight()];
564+
CBlockIndex *pindex = chainActive[mint.GetHeight() + 1];
565565
int nMintsAdded = 0;
566-
while(pindex->nHeight < chainActive.Height() - 30) { // 30 just to make sure that its at least 2 checkpoints from the top block
566+
while (pindex->nHeight < chainActive.Height() - 30) { // 30 just to make sure that its at least 2 checkpoints from the top block
567567
nMintsAdded += count(pindex->vMintDenominationsInBlock.begin(), pindex->vMintDenominationsInBlock.end(), mint.GetDenomination());
568-
if(nMintsAdded >= 3)
568+
if (nMintsAdded >= Params().Zerocoin_RequiredAccumulation())
569569
break;
570570
pindex = chainActive[pindex->nHeight + 1];
571571
}
572-
if(nMintsAdded < 3){
572+
if (nMintsAdded < Params().Zerocoin_RequiredAccumulation()){
573573
// Immature denominations
574574
mapImmature.at(mint.GetDenomination())++;
575575
}

src/qt/zpivcontroldialog.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ void ZPivControlDialog::updateList()
9595
CBlockIndex *pindex = chainActive[mint.GetHeight() + 1];
9696
while(pindex->nHeight < chainActive.Height() - 30) { // 30 just to make sure that its at least 2 checkpoints from the top block
9797
nMintsAdded += count(pindex->vMintDenominationsInBlock.begin(), pindex->vMintDenominationsInBlock.end(), mint.GetDenomination());
98-
if(nMintsAdded >= 3)
98+
if(nMintsAdded >= Params().Zerocoin_RequiredAccumulation())
9999
break;
100100
pindex = chainActive[pindex->nHeight + 1];
101101
}
102102
}
103103

104104
// disable selecting this mint if it is not spendable - also display a reason why
105-
bool fSpendable = nMintsAdded >= 3 && nConfirmations >= Params().Zerocoin_MintRequiredConfirmations();
105+
bool fSpendable = nMintsAdded >= Params().Zerocoin_RequiredAccumulation() && nConfirmations >= Params().Zerocoin_MintRequiredConfirmations();
106106
if(!fSpendable) {
107107
itemMint->setDisabled(true);
108108
itemMint->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked);
@@ -117,7 +117,7 @@ void ZPivControlDialog::updateList()
117117
if(nConfirmations < Params().Zerocoin_MintRequiredConfirmations())
118118
strReason = strprintf("Needs %d more confirmations", Params().Zerocoin_MintRequiredConfirmations() - nConfirmations);
119119
else
120-
strReason = strprintf("Needs %d more mints added to network", 3 - nMintsAdded);
120+
strReason = strprintf("Needs %d more mints added to network", Params().Zerocoin_RequiredAccumulation() - nMintsAdded);
121121

122122
itemMint->setText(COLUMN_ISSPENDABLE, QString::fromStdString(strReason));
123123
} else {

src/wallet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4037,6 +4037,7 @@ bool CWallet::MintToTxIn(CZerocoinMint zerocoinSelected, int nSecurityLevel, con
40374037
int nMintsAdded = 0;
40384038
if (!GenerateAccumulatorWitness(pubCoinSelected, accumulator, witness, nSecurityLevel, nMintsAdded, strFailReason)) {
40394039
receipt.SetStatus("Try to spend with a higher security level to include more coins", ZPIV_FAILED_ACCUMULATOR_INITIALIZATION);
4040+
LogPrintf("%s : %s \n", __func__, receipt.GetStatusMessage());
40404041
return false;
40414042
}
40424043

src/walletdb.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,12 +1166,12 @@ std::list<CZerocoinMint> CWalletDB::ListMintedCoins(bool fUnusedOnly, bool fMatu
11661166
int nMintsAdded = 0;
11671167
while(pindex->nHeight < chainActive.Height() - 30) { // 30 just to make sure that its at least 2 checkpoints from the top block
11681168
nMintsAdded += count(pindex->vMintDenominationsInBlock.begin(), pindex->vMintDenominationsInBlock.end(), mint.GetDenomination());
1169-
if(nMintsAdded >= 3)
1169+
if(nMintsAdded >= Params().Zerocoin_RequiredAccumulation())
11701170
break;
11711171
pindex = chainActive[pindex->nHeight + 1];
11721172
}
11731173

1174-
if(nMintsAdded < 3)
1174+
if(nMintsAdded < Params().Zerocoin_RequiredAccumulation())
11751175
continue;
11761176
}
11771177
}

0 commit comments

Comments
 (0)