Skip to content

Commit

Permalink
Enable creating zerocoin v1 spend transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
cevap committed Dec 6, 2018
1 parent 48bbf5d commit 0438624
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/accumulators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ bool GetAccumulatorValue(int& nHeight, const libzerocoin::CoinDenomination denom
return true;
}

bool GenerateAccumulatorWitness(const PublicCoin &coin, Accumulator& accumulator, AccumulatorWitness& witness, int nSecurityLevel, int& nMintsAdded, string& strError, CBlockIndex* pindexCheckpoint)
bool GenerateAccumulatorWitness(const PublicCoin &coin, Accumulator& accumulator, AccumulatorWitness& witness, int nSecurityLevel, int& nMintsAdded, string& strError, bool isV1Coin, CBlockIndex* pindexCheckpoint)
{
LogPrint("zero", "%s: generating\n", __func__);
int nLockAttempts = 0;
Expand Down Expand Up @@ -487,13 +487,19 @@ bool GenerateAccumulatorWitness(const PublicCoin &coin, Accumulator& accumulator

bnAccValue = 0;
uint256 nCheckpointSpend = chainActive[pindex->nHeight + 10]->nAccumulatorCheckpoint;
if (!GetAccumulatorValueFromDB(nCheckpointSpend, coin.getDenomination(), bnAccValue) || bnAccValue == 0)
return error("%s : failed to find checksum in database for accumulator", __func__);
if (!isV1Coin){
if (!GetAccumulatorValueFromDB(nCheckpointSpend, coin.getDenomination(), bnAccValue) || bnAccValue == 0)
return error("%s : failed to find checksum in database for accumulator", __func__);

accumulator.setValue(bnAccValue);
accumulator.setValue(bnAccValue);
}
break;
}

if (isV1Coin){
AddBlockMintsToAccumulator(coin, nHeightMintAdded, pindex, &accumulator, false);
}

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

pindex = chainActive.Next(pindex);
Expand Down Expand Up @@ -581,7 +587,7 @@ bool CalculateAccumulatorCheckpointWithoutDB(int nHeight, uint256& nCheckpoint,
return false;

//make sure this block is eligible for accumulation
if (pindex->nHeight < Params().Zerocoin_StartHeight()) {
if (pindex->nHeight < Params().Zerocoin_StartHeight()) {
pindex = chainActive[pindex->nHeight + 1];
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/accumulators.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class CBlockIndex;

std::map<libzerocoin::CoinDenomination, int> GetMintMaturityHeight();
bool GenerateAccumulatorWitness(const libzerocoin::PublicCoin &coin, libzerocoin::Accumulator& accumulator, libzerocoin::AccumulatorWitness& witness, int nSecurityLevel, int& nMintsAdded, std::string& strError, CBlockIndex* pindexCheckpoint = nullptr);
bool GenerateAccumulatorWitness(const libzerocoin::PublicCoin &coin, libzerocoin::Accumulator& accumulator, libzerocoin::AccumulatorWitness& witness, int nSecurityLevel, int& nMintsAdded, std::string& strError, bool isV1Coin, CBlockIndex* pindexCheckpoint = nullptr);
bool GetAccumulatorValueFromDB(uint256 nCheckpoint, libzerocoin::CoinDenomination denom, CBigNum& bnAccValue);
bool GetAccumulatorValueFromChecksum(uint32_t nChecksum, bool fMemoryOnly, CBigNum& bnAccValue);
void AddAccumulatorChecksum(const uint32_t nChecksum, const CBigNum &bnValue, bool fMemoryOnly);
Expand Down
8 changes: 7 additions & 1 deletion src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4762,7 +4762,7 @@ bool CWallet::MintToTxIn(CZerocoinMint zerocoinSelected, int nSecurityLevel, con
libzerocoin::AccumulatorWitness witness(paramsAccumulator, accumulator, pubCoinSelected);
string strFailReason = "";
int nMintsAdded = 0;
if (!GenerateAccumulatorWitness(pubCoinSelected, accumulator, witness, nSecurityLevel, nMintsAdded, strFailReason, pindexCheckpoint)) {
if (!GenerateAccumulatorWitness(pubCoinSelected, accumulator, witness, nSecurityLevel, nMintsAdded, strFailReason, isV1Coin, pindexCheckpoint)) {
receipt.SetStatus(_("Try to spend with a higher security level to include more coins"), XION_FAILED_ACCUMULATOR_INITIALIZATION);
return error("%s : %s", __func__, receipt.GetStatusMessage());
}
Expand All @@ -4789,7 +4789,13 @@ bool CWallet::MintToTxIn(CZerocoinMint zerocoinSelected, int nSecurityLevel, con
uint32_t nChecksum = GetChecksum(accumulator.getValue());
CBigNum bnValue;
if (!GetAccumulatorValueFromChecksum(nChecksum, false, bnValue) || bnValue == 0)
{
if (isV1Coin){
LogPrintf("%s: spending v1 coin\n", __func__);
} else {
return error("%s: could not find checksum used for spend\n", __func__);
}
}

try {
libzerocoin::CoinSpend spend(paramsCoin, paramsAccumulator, privateCoin, accumulator, nChecksum, witness, hashTxOut,
Expand Down

0 comments on commit 0438624

Please sign in to comment.