From abee3d97893cd3bc549256b24308f6df1ce91f3e Mon Sep 17 00:00:00 2001 From: presstab Date: Wed, 9 May 2018 15:45:25 -0600 Subject: [PATCH] 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. --- src/accumulators.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/accumulators.cpp b/src/accumulators.cpp index 66c662cb60c7a..1323b6a5c8b25 100644 --- a/src/accumulators.cpp +++ b/src/accumulators.cpp @@ -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; } @@ -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 @@ -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; @@ -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__);