Skip to content

Commit

Permalink
Fix spending for v1 zPIV created before block 1050020.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
presstab committed May 9, 2018
1 parent 2b76f31 commit abee3d9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/accumulators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ bool GetAccumulatorValue(int& nHeight, const libzerocoin::CoinDenomination denom
//Start at the first zerocoin
libzerocoin::Accumulator accumulator(Params().Zerocoin_Params(false), denom);
bnAccValue = accumulator.getValue();
nHeight = Params().Zerocoin_Block_V2_Start() + 10;
nHeight = Params().Zerocoin_StartHeight() + 10;
return true;
}

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

int nHeightTest;
if (!IsTransactionInChain(txid, nHeightTest))
return error("%s: mint tx %s is not in chain", __func__, txid.GetHex());

int nHeightMintAdded = mapBlockIndex[hashBlock]->nHeight;

//get the checkpoint added at the next multiple of 10
Expand Down Expand Up @@ -467,6 +471,8 @@ bool GenerateAccumulatorWitness(const PublicCoin &coin, Accumulator& accumulator
nMintsAdded = 0;
RandomizeSecurityLevel(nSecurityLevel); //make security level not always the same and predictable
libzerocoin::Accumulator witnessAccumulator = accumulator;

bool fDoubleCounted = false;
while (pindex) {
if (pindex->nHeight != nAccStartHeight && pindex->pprev->nAccumulatorCheckpoint != pindex->nAccumulatorCheckpoint)
++nCheckpointsAdded;
Expand All @@ -488,8 +494,17 @@ bool GenerateAccumulatorWitness(const PublicCoin &coin, Accumulator& accumulator
}

nMintsAdded += AddBlockMintsToAccumulator(coin, nHeightMintAdded, pindex, &witnessAccumulator, true);

// 10 blocks were accumulated twice when zPIV v2 was activated
if (pindex->nHeight == 1050010 && !fDoubleCounted) {
pindex = chainActive[1050000];
fDoubleCounted = true;
continue;
}

pindex = chainActive.Next(pindex);
}

witness.resetValue(witnessAccumulator, coin);
if (!witness.VerifyWitness(accumulator, coin))
return error("%s: failed to verify witness", __func__);
Expand Down

0 comments on commit abee3d9

Please sign in to comment.