Skip to content

Commit 71c47f8

Browse files
presstabFuzzbawls
authored andcommitted
Fix spending for v1 zPIV created before block 1050020.
The transition to v2 zPIV and reset of the accumulators caused blocks 1050000 - 1050010 to be accumulated twice. This was causing many v1 zPIV to not create valid witnesses. This problem is fixed by double accumulating blocks 1050000-1050010 when creating the witness. Github-Pull: #603 Rebased-From: abee3d9
1 parent bd153af commit 71c47f8

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/accumulators.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ bool GetAccumulatorValue(int& nHeight, const libzerocoin::CoinDenomination denom
402402
//Start at the first zerocoin
403403
libzerocoin::Accumulator accumulator(Params().Zerocoin_Params(false), denom);
404404
bnAccValue = accumulator.getValue();
405-
nHeight = Params().Zerocoin_Block_V2_Start() + 10;
405+
nHeight = Params().Zerocoin_StartHeight() + 10;
406406
return true;
407407
}
408408

@@ -437,6 +437,10 @@ bool GenerateAccumulatorWitness(const PublicCoin &coin, Accumulator& accumulator
437437
if (!GetTransaction(txid, txMinted, hashBlock))
438438
return error("%s failed to read tx", __func__);
439439

440+
int nHeightTest;
441+
if (!IsTransactionInChain(txid, nHeightTest))
442+
return error("%s: mint tx %s is not in chain", __func__, txid.GetHex());
443+
440444
int nHeightMintAdded = mapBlockIndex[hashBlock]->nHeight;
441445

442446
//get the checkpoint added at the next multiple of 10
@@ -467,6 +471,8 @@ bool GenerateAccumulatorWitness(const PublicCoin &coin, Accumulator& accumulator
467471
nMintsAdded = 0;
468472
RandomizeSecurityLevel(nSecurityLevel); //make security level not always the same and predictable
469473
libzerocoin::Accumulator witnessAccumulator = accumulator;
474+
475+
bool fDoubleCounted = false;
470476
while (pindex) {
471477
if (pindex->nHeight != nAccStartHeight && pindex->pprev->nAccumulatorCheckpoint != pindex->nAccumulatorCheckpoint)
472478
++nCheckpointsAdded;
@@ -488,8 +494,17 @@ bool GenerateAccumulatorWitness(const PublicCoin &coin, Accumulator& accumulator
488494
}
489495

490496
nMintsAdded += AddBlockMintsToAccumulator(coin, nHeightMintAdded, pindex, &witnessAccumulator, true);
497+
498+
// 10 blocks were accumulated twice when zPIV v2 was activated
499+
if (pindex->nHeight == 1050010 && !fDoubleCounted) {
500+
pindex = chainActive[1050000];
501+
fDoubleCounted = true;
502+
continue;
503+
}
504+
491505
pindex = chainActive.Next(pindex);
492506
}
507+
493508
witness.resetValue(witnessAccumulator, coin);
494509
if (!witness.VerifyWitness(accumulator, coin))
495510
return error("%s: failed to verify witness", __func__);

0 commit comments

Comments
 (0)