Skip to content

Commit d518369

Browse files
presstabFuzzbawls
authored andcommitted
Require v1 zPIV to use security level 100.
1 parent 2809f0e commit d518369

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

src/accumulators.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -390,17 +390,14 @@ bool GetAccumulatorValue(int& nHeight, const libzerocoin::CoinDenomination denom
390390
if (nHeight > chainActive.Height())
391391
return error("%s: height %d is more than active chain height", __func__, nHeight);
392392

393-
//Use old db if proto not update yet
393+
//Every situation except for about 20 blocks should use this method
394394
uint256 nCheckpointBeforeMint = chainActive[nHeight]->nAccumulatorCheckpoint;
395-
if (chainActive.Height() < Params().Zerocoin_Block_V2_Start())
395+
if (nHeight > Params().Zerocoin_Block_V2_Start() + 20)
396396
return GetAccumulatorValueFromDB(nCheckpointBeforeMint, denom, bnAccValue);
397397

398398
int nHeightCheckpoint = 0;
399399
AccumulatorCheckpoints::Checkpoint checkpoint = AccumulatorCheckpoints::GetClosestCheckpoint(nHeight, nHeightCheckpoint);
400-
if (nHeightCheckpoint < 0)
401-
return error("%s: failed to load hard-checkpoint for block %s", __func__, nHeight);
402-
403-
if (nHeight < nHeightCheckpoint) {
400+
if (nHeightCheckpoint < 0) {
404401
//Start at the first zerocoin
405402
libzerocoin::Accumulator accumulator(Params().Zerocoin_Params(false), denom);
406403
bnAccValue = accumulator.getValue();
@@ -447,16 +444,6 @@ bool GenerateAccumulatorWitness(const PublicCoin &coin, Accumulator& accumulator
447444
//the height to start accumulating coins to add to witness
448445
int nAccStartHeight = nHeightMintAdded - (nHeightMintAdded % 10);
449446

450-
//If the checkpoint is from the recalculated checkpoint period, then adjust it
451-
int nHeight_LastGoodCheckpoint = Params().Zerocoin_Block_LastGoodCheckpoint();
452-
int nHeight_Recalculate = Params().Zerocoin_Block_RecalculateAccumulators();
453-
CBlockIndex* pindex = chainActive[nHeightMintAdded];
454-
if (pindex->nHeight < nHeight_Recalculate - 10 && pindex->nHeight > nHeight_LastGoodCheckpoint) {
455-
//The checkpoint before the mint will be the last good checkpoint
456-
nHeightCheckpoint = nHeight_LastGoodCheckpoint;
457-
nAccStartHeight = nHeight_LastGoodCheckpoint - 10;
458-
}
459-
460447
//Get the accumulator that is right before the cluster of blocks containing our mint was added to the accumulator
461448
CBigNum bnAccValue = 0;
462449
if (GetAccumulatorValue(nHeightCheckpoint, coin.getDenomination(), bnAccValue)) {
@@ -465,7 +452,7 @@ bool GenerateAccumulatorWitness(const PublicCoin &coin, Accumulator& accumulator
465452
}
466453

467454
//add the pubcoins from the blockchain up to the next checksum starting from the block
468-
pindex = chainActive[nHeightCheckpoint - 10];
455+
CBlockIndex* pindex = chainActive[nHeightCheckpoint - 10];
469456
int nChainHeight = chainActive.Height();
470457
int nHeightStop = nChainHeight % 10;
471458
nHeightStop = nChainHeight - nHeightStop - 20; // at least two checkpoints deep

src/qt/privacydialog.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,15 @@ void PrivacyDialog::sendzPIV()
417417
vMintsToFetch = ZPivControlDialog::GetSelectedMints();
418418

419419
for (auto& meta : vMintsToFetch) {
420+
if (meta.nVersion < libzerocoin::PrivateCoin::PUBKEY_VERSION) {
421+
//version 1 coins have to use full security level to successfully spend.
422+
if (nSecurityLevel < 100) {
423+
QMessageBox::warning(this, tr("Spend Zerocoin"), tr("Version 1 zPIV require a security level of 100 to successfully spend."), QMessageBox::Ok, QMessageBox::Ok);
424+
ui->TEMintStatus->setPlainText(tr("Failed to spend zPIV"));
425+
ui->TEMintStatus->repaint();
426+
return;
427+
}
428+
}
420429
CZerocoinMint mint;
421430
if (!pwalletMain->GetMint(meta.hashSerial, mint)) {
422431
ui->TEMintStatus->setPlainText(tr("Failed to fetch mint associated with serial hash"));

src/wallet.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4737,6 +4737,15 @@ bool CWallet::CreateZerocoinSpendTransaction(CAmount nValue, int nSecurityLevel,
47374737
return false;
47384738
}
47394739

4740+
for (const auto& mint : vSelectedMints) {
4741+
if (mint.GetVersion() < libzerocoin::PrivateCoin::PUBKEY_VERSION) {
4742+
if (nSecurityLevel < 100) {
4743+
receipt.SetStatus(_("Version 1 zPIV require a security level of 100 to successfully spend."), nStatus);
4744+
return false;
4745+
}
4746+
}
4747+
}
4748+
47404749
if ((static_cast<int>(vSelectedMints.size()) > Params().Zerocoin_MaxSpendsPerTransaction())) {
47414750
receipt.SetStatus(_("Failed to find coin set amongst held coins with less than maxNumber of Spends"), nStatus);
47424751
return false;

0 commit comments

Comments
 (0)