Navigation Menu

Skip to content

Commit

Permalink
Merge #603: Fix spending for v1 zPIV created before block 1050020.
Browse files Browse the repository at this point in the history
ccf6c77 Remove log spam and ensure proper zpiv version is used. (presstab)
8a6d425 Add getaccumulatorvalues RPC. (presstab)
abee3d9 Fix spending for v1 zPIV created before block 1050020. (presstab)

Tree-SHA512: cae09864f053c6a49ca696f4de6b3d8cbced37dc4d19ca8409b0bcc87a73520a31b3927f3b0522cc2c13d969062c55d4c2e8eab1c4fd138f44fdcdf2abd52413
  • Loading branch information
Mrs-X committed May 10, 2018
2 parents 2174335 + ccf6c77 commit 779d8d5
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 9 deletions.
17 changes: 16 additions & 1 deletion src/accumulators.cpp
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
2 changes: 1 addition & 1 deletion src/main.cpp
Expand Up @@ -1068,7 +1068,7 @@ bool TxOutToPublicCoin(const CTxOut txout, PublicCoin& pubCoin, CValidationState
publicZerocoin.setvch(vchZeroMint);

CoinDenomination denomination = AmountToZerocoinDenomination(txout.nValue);
LogPrint("zero", "%s ZCPRINT denomination %d pubcoin %s\n", __func__, denomination, publicZerocoin.GetHex());
//LogPrint("zero", "%s ZCPRINT denomination %d pubcoin %s\n", __func__, denomination, publicZerocoin.GetHex());
if (denomination == ZQ_ERROR)
return state.DoS(100, error("TxOutToPublicCoin : txout.nValue is not correct"));

Expand Down
35 changes: 34 additions & 1 deletion src/rpcblockchain.cpp
Expand Up @@ -15,6 +15,7 @@
#include "util.h"
#include "utilmoneystr.h"
#include "accumulatormap.h"
#include "accumulators.h"

#include <stdint.h>
#include <univalue.h>
Expand Down Expand Up @@ -929,6 +930,38 @@ UniValue findserial(const UniValue& params, bool fHelp)
UniValue ret(UniValue::VOBJ);
ret.push_back(Pair("success", fSuccess));
ret.push_back(Pair("txid", txid.GetHex()));

return ret;
}

UniValue getaccumulatorvalues(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"getaccumulatorvalues \"height\"\n"
"\nReturns the accumulator values associated with a block height\n"

"\nArguments:\n"
"1. height (numeric, required) the height of the checkpoint.\n"

"\nExamples:\n" +
HelpExampleCli("getaccumulatorvalues", "\"height\"") + HelpExampleRpc("getaccumulatorvalues", "\"height\""));

int nHeight = params[0].get_int();

CBlockIndex* pindex = chainActive[nHeight];
if (!pindex)
throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid block height");

UniValue ret(UniValue::VARR);
for (libzerocoin::CoinDenomination denom : libzerocoin::zerocoinDenomList) {
CBigNum bnValue;
if(!GetAccumulatorValueFromDB(pindex->nAccumulatorCheckpoint, denom, bnValue))
throw JSONRPCError(RPC_DATABASE_ERROR, "failed to find value in database");

UniValue obj(UniValue::VOBJ);
obj.push_back(Pair(std::to_string(denom), bnValue.GetHex()));
ret.push_back(obj);
}

return ret;
}
1 change: 1 addition & 0 deletions src/rpcclient.cpp
Expand Up @@ -140,6 +140,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{"searchdzpiv", 0},
{"searchdzpiv", 1},
{"searchdzpiv", 2},
{"getaccumulatorvalues", 0},
{"getfeeinfo", 0}
};

Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.cpp
Expand Up @@ -298,6 +298,7 @@ static const CRPCCommand vRPCCommands[] =

/* Block chain and UTXO */
{"blockchain", "findserial", &findserial, true, false, false},
{"blockchain", "getaccumulatorvalues", &getaccumulatorvalues, true, false, false},
{"blockchain", "getblockchaininfo", &getblockchaininfo, true, false, false},
{"blockchain", "getbestblockhash", &getbestblockhash, true, false, false},
{"blockchain", "getblockcount", &getblockcount, true, false, false},
Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.h
Expand Up @@ -291,6 +291,7 @@ extern UniValue verifychain(const UniValue& params, bool fHelp);
extern UniValue getchaintips(const UniValue& params, bool fHelp);
extern UniValue invalidateblock(const UniValue& params, bool fHelp);
extern UniValue reconsiderblock(const UniValue& params, bool fHelp);
extern UniValue getaccumulatorvalues(const UniValue& params, bool fHelp);

extern UniValue getpoolinfo(const UniValue& params, bool fHelp); // in rpcmasternode.cpp
extern UniValue masternode(const UniValue& params, bool fHelp);
Expand Down
4 changes: 2 additions & 2 deletions src/wallet.cpp
Expand Up @@ -4563,9 +4563,9 @@ bool CWallet::MintToTxIn(CZerocoinMint zerocoinSelected, int nSecurityLevel, con
{
// Default error status if not changed below
receipt.SetStatus(_("Transaction Mint Started"), ZPIV_TXMINT_GENERAL);
libzerocoin::ZerocoinParams* paramsAccumulator = Params().Zerocoin_Params(chainActive.Height() < Params().Zerocoin_Block_V2_Start());
libzerocoin::ZerocoinParams* paramsAccumulator = Params().Zerocoin_Params(false);

bool isV1Coin = zerocoinSelected.GetVersion() < libzerocoin::PrivateCoin::PUBKEY_VERSION;
bool isV1Coin = libzerocoin::ExtractVersionFromSerial(zerocoinSelected.GetSerialNumber()) < libzerocoin::PrivateCoin::PUBKEY_VERSION;
libzerocoin::ZerocoinParams* paramsCoin = Params().Zerocoin_Params(isV1Coin);
//LogPrintf("%s: *** using v1 coin params=%b, using v1 acc params=%b\n", __func__, isV1Coin, chainActive.Height() < Params().Zerocoin_Block_V2_Start());

Expand Down
4 changes: 0 additions & 4 deletions src/zpivtracker.cpp
Expand Up @@ -149,10 +149,6 @@ CAmount CzPIVTracker::GetBalance(bool fConfirmedOnly, bool fUnconfirmedOnly) con
myZerocoinSupply.at(meta.denom)++;
}
}
for (auto& denom : libzerocoin::zerocoinDenomList) {
LogPrint("zero","%s My coins for denomination %d pubcoin %s\n", __func__,denom, myZerocoinSupply.at(denom));
}
LogPrint("zero","Total value of coins %d\n",nTotal);

if (nTotal < 0 ) nTotal = 0; // Sanity never hurts

Expand Down

0 comments on commit 779d8d5

Please sign in to comment.