From 741f43c8cae126a4604625c03c2450dcdb31c779 Mon Sep 17 00:00:00 2001 From: furszy Date: Tue, 10 Mar 2020 23:06:01 -0300 Subject: [PATCH 1/5] Replace direct use of 0 with SetNull and IsNull. Replace x=0 with .SetNull(), x==0 with IsNull(), x!=0 with !IsNull(). Replace uses of uint256(0) with UINT256_ZERO. --- src/chain.cpp | 2 +- src/chain.h | 4 ++-- src/chainparams.cpp | 20 ++++++++++---------- src/coins.cpp | 6 +++--- src/coins.h | 2 +- src/core_write.cpp | 2 +- src/libzerocoin/Coin.cpp | 6 +++--- src/libzerocoin/bignum_gmp.cpp | 2 +- src/main.cpp | 28 ++++++++++++++-------------- src/masternode-budget.cpp | 4 ++-- src/masternode.cpp | 4 ++-- src/masternodeman.cpp | 6 +++--- src/merkleblock.cpp | 18 +++++++++--------- src/net.cpp | 2 +- src/pivx-tx.cpp | 4 ++-- src/pow.cpp | 6 +++--- src/primitives/transaction.cpp | 2 +- src/protocol.cpp | 2 +- src/rpc/blockchain.cpp | 2 +- src/rpc/rawtransaction.cpp | 4 ++-- src/stakeinput.cpp | 2 +- src/test/pmt_tests.cpp | 4 ++-- src/test/script_P2SH_tests.cpp | 2 +- src/test/sigopcount_tests.cpp | 2 +- src/test/uint256_tests.cpp | 2 +- src/txdb.cpp | 8 ++++---- src/uint256.h | 13 +++++++++++-- src/uint512.h | 2 +- src/wallet/rpcwallet.cpp | 8 ++++---- src/wallet/wallet.cpp | 2 +- src/wallet/wallet.h | 2 +- src/wallet/wallet_zerocoin.cpp | 4 ++-- src/wallet/walletdb.cpp | 10 +++++----- 33 files changed, 98 insertions(+), 89 deletions(-) diff --git a/src/chain.cpp b/src/chain.cpp index 28b0169e4918..7c8cd42a4dca 100644 --- a/src/chain.cpp +++ b/src/chain.cpp @@ -214,7 +214,7 @@ uint64_t CBlockIndex::GetStakeModifierV1() const uint256 CBlockIndex::GetStakeModifierV2() const { if (vStakeModifier.empty() || !Params().GetConsensus().IsStakeModifierV2(nHeight)) - return uint256(0); + return UINT256_ZERO; uint256 nStakeModifier; std::memcpy(nStakeModifier.begin(), vStakeModifier.data(), vStakeModifier.size()); return nStakeModifier; diff --git a/src/chain.h b/src/chain.h index af56d96fbad1..856b684a10d7 100644 --- a/src/chain.h +++ b/src/chain.h @@ -297,12 +297,12 @@ class CDiskBlockIndex : public CBlockIndex CDiskBlockIndex() { - hashPrev = uint256(); + hashPrev = UINT256_ZERO; } explicit CDiskBlockIndex(const CBlockIndex* pindex) : CBlockIndex(*pindex) { - hashPrev = (pprev ? pprev->GetBlockHash() : uint256(0)); + hashPrev = (pprev ? pprev->GetBlockHash() : UINT256_ZERO); } ADD_SERIALIZE_METHODS; diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 5d784af5e495..1722bd6e3290 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -31,7 +31,7 @@ static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesi CBlock genesis; genesis.vtx.push_back(txNew); - genesis.hashPrevBlock = 0; + genesis.hashPrevBlock.SetNull(); genesis.nVersion = nVersion; genesis.nTime = nTime; genesis.nBits = nBits; @@ -148,9 +148,9 @@ class CMainParams : public CChainParams assert(genesis.hashMerkleRoot == uint256("0x1b2ef6e2f28be914103a277377ae7729dcd125dfeb8bf97bd5964ba72b6dc39b")); consensus.fPowAllowMinDifficultyBlocks = false; - consensus.powLimit = ~uint256(0) >> 20; // PIVX starting difficulty is 1 / 2^12 - consensus.posLimitV1 = ~uint256(0) >> 24; - consensus.posLimitV2 = ~uint256(0) >> 20; + consensus.powLimit = ~UINT256_ZERO >> 20; // PIVX starting difficulty is 1 / 2^12 + consensus.posLimitV1 = ~UINT256_ZERO >> 24; + consensus.posLimitV2 = ~UINT256_ZERO >> 20; consensus.nBudgetCycleBlocks = 43200; // approx. 1 every 30 days consensus.nBudgetFeeConfirmations = 6; // Number of confirmations for the finalization fee consensus.nCoinbaseMaturity = 100; @@ -269,9 +269,9 @@ class CTestNetParams : public CMainParams assert(genesis.hashMerkleRoot == uint256("0x1b2ef6e2f28be914103a277377ae7729dcd125dfeb8bf97bd5964ba72b6dc39b")); consensus.fPowAllowMinDifficultyBlocks = true; - consensus.powLimit = ~uint256(0) >> 20; // PIVX starting difficulty is 1 / 2^12 - consensus.posLimitV1 = ~uint256(0) >> 24; - consensus.posLimitV2 = ~uint256(0) >> 20; + consensus.powLimit = ~UINT256_ZERO >> 20; // PIVX starting difficulty is 1 / 2^12 + consensus.posLimitV1 = ~UINT256_ZERO >> 24; + consensus.posLimitV2 = ~UINT256_ZERO >> 20; consensus.nBudgetCycleBlocks = 144; // approx 10 cycles per day consensus.nBudgetFeeConfirmations = 3; // (only 8-blocks window for finalization on testnet) consensus.nCoinbaseMaturity = 15; @@ -393,9 +393,9 @@ class CRegTestParams : public CTestNetParams assert(genesis.hashMerkleRoot == uint256("0x1b2ef6e2f28be914103a277377ae7729dcd125dfeb8bf97bd5964ba72b6dc39b")); consensus.fPowAllowMinDifficultyBlocks = true; - consensus.powLimit = ~uint256(0) >> 20; // PIVX starting difficulty is 1 / 2^12 - consensus.posLimitV1 = ~uint256(0) >> 24; - consensus.posLimitV2 = ~uint256(0) >> 20; + consensus.powLimit = ~UINT256_ZERO >> 20; // PIVX starting difficulty is 1 / 2^12 + consensus.posLimitV1 = ~UINT256_ZERO >> 24; + consensus.posLimitV2 = ~UINT256_ZERO >> 20; consensus.nBudgetCycleBlocks = 144; // approx 10 cycles per day consensus.nBudgetFeeConfirmations = 3; // (only 8-blocks window for finalization on regtest) consensus.nCoinbaseMaturity = 100; diff --git a/src/coins.cpp b/src/coins.cpp index 4b44b4856283..3763b0ad766f 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -61,7 +61,7 @@ bool CCoins::Spend(int nPos) bool CCoinsView::GetCoins(const uint256& txid, CCoins& coins) const { return false; } bool CCoinsView::HaveCoins(const uint256& txid) const { return false; } -uint256 CCoinsView::GetBestBlock() const { return uint256(0); } +uint256 CCoinsView::GetBestBlock() const { return UINT256_ZERO; } bool CCoinsView::BatchWrite(CCoinsMap& mapCoins, const uint256& hashBlock) { return false; } bool CCoinsView::GetStats(CCoinsStats& stats) const { return false; } @@ -76,7 +76,7 @@ bool CCoinsViewBacked::GetStats(CCoinsStats& stats) const { return base->GetStat CCoinsKeyHasher::CCoinsKeyHasher() : salt(GetRandHash()) {} -CCoinsViewCache::CCoinsViewCache(CCoinsView* baseIn) : CCoinsViewBacked(baseIn), hasModifier(false), hashBlock(0) {} +CCoinsViewCache::CCoinsViewCache(CCoinsView* baseIn) : CCoinsViewBacked(baseIn), hasModifier(false) {} CCoinsViewCache::~CCoinsViewCache() { @@ -152,7 +152,7 @@ bool CCoinsViewCache::HaveCoins(const uint256& txid) const uint256 CCoinsViewCache::GetBestBlock() const { - if (hashBlock == uint256(0)) + if (hashBlock.IsNull()) hashBlock = base->GetBestBlock(); return hashBlock; } diff --git a/src/coins.h b/src/coins.h index ef16cc8b5204..f02b1eda4337 100644 --- a/src/coins.h +++ b/src/coins.h @@ -328,7 +328,7 @@ struct CCoinsStats { uint256 hashSerialized; CAmount nTotalAmount; - CCoinsStats() : nHeight(0), hashBlock(0), nTransactions(0), nTransactionOutputs(0), nSerializedSize(0), hashSerialized(0), nTotalAmount(0) {} + CCoinsStats() : nHeight(0), nTransactions(0), nTransactionOutputs(0), nSerializedSize(0), nTotalAmount(0) {} }; diff --git a/src/core_write.cpp b/src/core_write.cpp index 30fc44fad6c5..6cc9c96e94d6 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -133,7 +133,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry) } entry.pushKV("vout", vout); - if (hashBlock != 0) + if (!hashBlock.IsNull()) entry.pushKV("blockhash", hashBlock.GetHex()); entry.pushKV("hex", EncodeHexTx(tx)); // the hex-encoded transaction. used the name "hex" to be consistent with the verbose output of "getrawtransaction". diff --git a/src/libzerocoin/Coin.cpp b/src/libzerocoin/Coin.cpp index 98ed2364e9d7..5bf240572728 100644 --- a/src/libzerocoin/Coin.cpp +++ b/src/libzerocoin/Coin.cpp @@ -162,7 +162,7 @@ void PrivateCoin::mintCoin(const CoinDenomination denomination) { CBigNum s; bool isValid = false; while (!isValid) { - isValid = GenerateKeyPair(this->params->coinCommitmentGroup.groupOrder, uint256(0), key, s); + isValid = GenerateKeyPair(this->params->coinCommitmentGroup.groupOrder, UINT256_ZERO, key, s); } // Generate a Pedersen commitment to the serial number "s" @@ -200,7 +200,7 @@ void PrivateCoin::mintCoinFast(const CoinDenomination denomination) { CBigNum s; bool isValid = false; while (!isValid) { - isValid = GenerateKeyPair(this->params->coinCommitmentGroup.groupOrder, uint256(0), key, s); + isValid = GenerateKeyPair(this->params->coinCommitmentGroup.groupOrder, UINT256_ZERO, key, s); } // Generate a random number "r" in the range 0...{q-1} CBigNum r = CBigNum::randBignum(this->params->coinCommitmentGroup.groupOrder); @@ -264,7 +264,7 @@ int ExtractVersionFromSerial(const CBigNum& bnSerial) CBigNum GetAdjustedSerial(const CBigNum& bnSerial) { uint256 serial = bnSerial.getuint256(); - serial &= ~uint256(0) >> PrivateCoin::V2_BITSHIFT; + serial &= ~UINT256_ZERO >> PrivateCoin::V2_BITSHIFT; CBigNum bnSerialAdjusted; bnSerialAdjusted.setuint256(serial); return bnSerialAdjusted; diff --git a/src/libzerocoin/bignum_gmp.cpp b/src/libzerocoin/bignum_gmp.cpp index a7f1453258be..0df4a4f6ba18 100644 --- a/src/libzerocoin/bignum_gmp.cpp +++ b/src/libzerocoin/bignum_gmp.cpp @@ -133,7 +133,7 @@ uint256 CBigNum::getuint256() const if(bitSize() > 256) { throw std::range_error("cannot convert to uint256, bignum longer than 256 bits"); } - uint256 n = uint256(0); + uint256 n = UINT256_ZERO; mpz_export((unsigned char*)&n, NULL, -1, 1, 0, 0, bn); return n; } diff --git a/src/main.cpp b/src/main.cpp index 1be0e666a9dc..71113d79233f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -336,7 +336,7 @@ struct CNodeState { nMisbehavior = 0; fShouldBan = false; pindexBestKnownBlock = NULL; - hashLastUnknownBlock = uint256(0); + hashLastUnknownBlock.SetNull(); pindexLastCommonBlock = NULL; fSyncStarted = false; nStallingSince = 0; @@ -443,12 +443,12 @@ void ProcessBlockAvailability(NodeId nodeid) CNodeState* state = State(nodeid); assert(state != NULL); - if (state->hashLastUnknownBlock != 0) { + if (!state->hashLastUnknownBlock.IsNull()) { BlockMap::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock); if (itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) { if (state->pindexBestKnownBlock == NULL || itOld->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) state->pindexBestKnownBlock = itOld->second; - state->hashLastUnknownBlock = uint256(0); + state->hashLastUnknownBlock.SetNull(); } } } @@ -2472,7 +2472,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return false; // verify that the view's current state corresponds to the previous block - uint256 hashPrevBlock = pindex->pprev == NULL ? uint256(0) : pindex->pprev->GetBlockHash(); + uint256 hashPrevBlock = pindex->pprev == NULL ? UINT256_ZERO : pindex->pprev->GetBlockHash(); if (hashPrevBlock != view.GetBestBlock()) LogPrintf("%s: hashPrev=%s view=%s\n", __func__, hashPrevBlock.GetHex(), view.GetBestBlock().GetHex()); assert(hashPrevBlock == view.GetBestBlock()); @@ -3951,7 +3951,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta bool IsBlockHashInChain(const uint256& hashBlock) { - if (hashBlock == 0 || !mapBlockIndex.count(hashBlock)) + if (hashBlock.IsNull() || !mapBlockIndex.count(hashBlock)) return false; return chainActive.Contains(mapBlockIndex[hashBlock]); @@ -4405,7 +4405,7 @@ bool ProcessNewBlock(CValidationState& state, CNode* pfrom, CBlock* pblock, CDis //if we get this far, check if the prev block is our prev block, if not then request sync and return false BlockMap::iterator mi = mapBlockIndex.find(pblock->hashPrevBlock); if (mi == mapBlockIndex.end()) { - pfrom->PushMessage("getblocks", chainActive.GetLocator(), uint256(0)); + pfrom->PushMessage("getblocks", chainActive.GetLocator(), UINT256_ZERO); return false; } } @@ -4554,7 +4554,7 @@ boost::filesystem::path GetBlockPosFilename(const CDiskBlockPos& pos, const char CBlockIndex* InsertBlockIndex(uint256 hash) { - if (hash == 0) + if (hash.IsNull()) return NULL; // Return existing @@ -5284,7 +5284,7 @@ void static ProcessGetData(CNode* pfrom) std::vector vInv; vInv.push_back(CInv(MSG_BLOCK, chainActive.Tip()->GetBlockHash())); pfrom->PushMessage("inv", vInv); - pfrom->hashContinue = 0; + pfrom->hashContinue.SetNull(); } } } else if (inv.IsKnownType()) { @@ -5635,7 +5635,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR // Use deterministic randomness to send to the same nodes for 24 hours // at a time so the setAddrKnowns of the chosen nodes prevent repeats static uint256 hashSalt; - if (hashSalt == 0) + if (hashSalt.IsNull()) hashSalt = GetRandHash(); uint64_t hashAddr = addr.GetHash(); uint256 hashRand = hashSalt ^ (hashAddr << 32) ^ ((GetTime() + hashAddr) / (24 * 60 * 60)); @@ -5751,7 +5751,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR if (pindex) pindex = chainActive.Next(pindex); int nLimit = 500; - LogPrint("net", "getblocks %d to %s limit %d from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop == uint256(0) ? "end" : hashStop.ToString(), nLimit, pfrom->id); + LogPrint("net", "getblocks %d to %s limit %d from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.IsNull() ? "end" : hashStop.ToString(), nLimit, pfrom->id); for (; pindex; pindex = chainActive.Next(pindex)) { if (pindex->GetBlockHash() == hashStop) { LogPrint("net", " getblocks stopping at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString()); @@ -6017,7 +6017,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR // TODO: optimize: if pindexLast is an ancestor of chainActive.Tip or pindexBestHeader, continue // from there instead. LogPrintf("more getheaders (%d) to end to peer=%d (startheight:%d)\n", pindexLast->nHeight, pfrom->id, pfrom->nStartingHeight); - pfrom->PushMessage("getheaders", chainActive.GetLocator(pindexLast), uint256(0)); + pfrom->PushMessage("getheaders", chainActive.GetLocator(pindexLast), UINT256_ZERO); } CheckBlockIndex(); @@ -6533,8 +6533,8 @@ bool SendMessages(CNode* pto, bool fSendTrickle) nSyncStarted++; //CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; //LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->id, pto->nStartingHeight); - //pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256(0)); - pto->PushMessage("getblocks", chainActive.GetLocator(chainActive.Tip()), uint256(0)); + //pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), UINT256_ZERO); + pto->PushMessage("getblocks", chainActive.GetLocator(chainActive.Tip()), UINT256_ZERO); } } @@ -6562,7 +6562,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (inv.type == MSG_TX && !fSendTrickle) { // 1/4 of tx invs blast to all immediately static uint256 hashSalt; - if (hashSalt == 0) + if (hashSalt.IsNull()) hashSalt = GetRandHash(); uint256 hashRand = inv.hash ^ hashSalt; hashRand = Hash(BEGIN(hashRand), END(hashRand)); diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index d01c17f588fc..901bf72e05bd 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -84,7 +84,7 @@ bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, s */ int conf = GetIXConfirmations(nTxCollateralHash); - if (nBlockHash != uint256(0)) { + if (nBlockHash != UINT256_ZERO) { BlockMap::iterator mi = mapBlockIndex.find(nBlockHash); if (mi != mapBlockIndex.end() && (*mi).second) { CBlockIndex* pindex = (*mi).second; @@ -230,7 +230,7 @@ void CBudgetManager::SubmitFinalBudget() return; } - if (nBlockHash != uint256(0)) { + if (nBlockHash != UINT256_ZERO) { BlockMap::iterator mi = mapBlockIndex.find(nBlockHash); if (mi != mapBlockIndex.end() && (*mi).second) { CBlockIndex* pindex = (*mi).second; diff --git a/src/masternode.cpp b/src/masternode.cpp index 24411404911a..db9ffa8ca462 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -160,7 +160,7 @@ uint256 CMasternode::CalculateScore(int mod, int64_t nBlockHeight) { if (chainActive.Tip() == NULL) return 0; - uint256 hash = 0; + uint256 hash; uint256 aux = vin.prevout.hash + vin.prevout.n; if (!GetBlockHash(hash, nBlockHeight)) { @@ -647,7 +647,7 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDoS) // verify that sig time is legit in past // should be at least not earlier than block when 1000 PIV tx got MASTERNODE_MIN_CONFIRMATIONS - uint256 hashBlock = 0; + uint256 hashBlock = UINT256_ZERO; CTransaction tx2; GetTransaction(vin.prevout.hash, tx2, hashBlock, true); BlockMap::iterator mi = mapBlockIndex.find(hashBlock); diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 1027819e9cc3..e2999f0ce51f 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -598,7 +598,7 @@ int CMasternodeMan::GetMasternodeRank(const CTxIn& vin, int64_t nBlockHeight, in int64_t nMasternode_Age = 0; //make sure we know about this block - uint256 hash = 0; + uint256 hash; if (!GetBlockHash(hash, nBlockHeight)) return -1; // scan for winner @@ -644,7 +644,7 @@ std::vector > CMasternodeMan::GetMasternodeRanks(int std::vector > vecMasternodeRanks; //make sure we know about this block - uint256 hash = 0; + uint256 hash; if (!GetBlockHash(hash, nBlockHeight)) return vecMasternodeRanks; // scan for winner @@ -1006,7 +1006,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData // verify that sig time is legit in past // should be at least not earlier than block when 1000 PIVX tx got MASTERNODE_MIN_CONFIRMATIONS - uint256 hashBlock = 0; + uint256 hashBlock = UINT256_ZERO; CTransaction tx2; GetTransaction(vin.prevout.hash, tx2, hashBlock, true); BlockMap::iterator mi = mapBlockIndex.find(hashBlock); diff --git a/src/merkleblock.cpp b/src/merkleblock.cpp index 3beb658fde1b..889718f96f68 100644 --- a/src/merkleblock.cpp +++ b/src/merkleblock.cpp @@ -77,7 +77,7 @@ uint256 CPartialMerkleTree::TraverseAndExtract(int height, unsigned int pos, uns if (nBitsUsed >= vBits.size()) { // overflowed the bits array - failure fBad = true; - return 0; + return UINT256_ZERO; } bool fParentOfMatch = vBits[nBitsUsed++]; if (height == 0 || !fParentOfMatch) { @@ -85,7 +85,7 @@ uint256 CPartialMerkleTree::TraverseAndExtract(int height, unsigned int pos, uns if (nHashUsed >= vHash.size()) { // overflowed the hash array - failure fBad = true; - return 0; + return UINT256_ZERO; } const uint256& hash = vHash[nHashUsed++]; if (height == 0 && fParentOfMatch) // in case of height 0, we have a matched txid @@ -125,16 +125,16 @@ uint256 CPartialMerkleTree::ExtractMatches(std::vector& vMatch) vMatch.clear(); // An empty set will not work if (nTransactions == 0) - return 0; + return UINT256_ZERO; // check for excessively high numbers of transactions if (nTransactions > MAX_BLOCK_SIZE_CURRENT / 60) // 60 is the lower bound for the size of a serialized CTransaction - return 0; + return UINT256_ZERO; // there can never be more hashes provided than one for every txid if (vHash.size() > nTransactions) - return 0; + return UINT256_ZERO; // there must be at least one bit per node in the partial tree, and at least one node per hash if (vBits.size() < vHash.size()) - return 0; + return UINT256_ZERO; // calculate height of tree int nHeight = 0; while (CalcTreeWidth(nHeight) > 1) @@ -144,12 +144,12 @@ uint256 CPartialMerkleTree::ExtractMatches(std::vector& vMatch) uint256 hashMerkleRoot = TraverseAndExtract(nHeight, 0, nBitsUsed, nHashUsed, vMatch); // verify that no problems occured during the tree traversal if (fBad) - return 0; + return UINT256_ZERO; // verify that all bits were consumed (except for the padding caused by serializing it as a byte sequence) if ((nBitsUsed + 7) / 8 != (vBits.size() + 7) / 8) - return 0; + return UINT256_ZERO; // verify that all hashes were consumed if (nHashUsed != vHash.size()) - return 0; + return UINT256_ZERO; return hashMerkleRoot; } diff --git a/src/net.cpp b/src/net.cpp index a1d17e41370b..10477365db0e 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2101,7 +2101,7 @@ CNode::CNode(SOCKET hSocketIn, CAddress addrIn, std::string addrNameIn, bool fIn nRefCount = 0; nSendSize = 0; nSendOffset = 0; - hashContinue = 0; + hashContinue = UINT256_ZERO; nStartingHeight = -1; fGetAddr = false; fRelayTxes = false; diff --git a/src/pivx-tx.cpp b/src/pivx-tx.cpp index 821c16e52574..feb02187483d 100644 --- a/src/pivx-tx.cpp +++ b/src/pivx-tx.cpp @@ -311,7 +311,7 @@ static bool findSighashFlags(int& flags, const std::string& flagStr) uint256 ParseHashUO(std::map& o, std::string strKey) { if (!o.count(strKey)) - return 0; + return UINT256_ZERO; return ParseHashUV(o[strKey], strKey); } @@ -496,7 +496,7 @@ static void MutateTx(CMutableTransaction& tx, const std::string& command, const static void OutputTxJSON(const CTransaction& tx) { UniValue entry(UniValue::VOBJ); - TxToUniv(tx, 0, entry); + TxToUniv(tx, UINT256_ZERO, entry); std::string jsonOutput = entry.write(4); fprintf(stdout, "%s\n", jsonOutput.c_str()); diff --git a/src/pow.cpp b/src/pow.cpp index b087ae903ec1..2b9f0c7b0b47 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -129,7 +129,7 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits) bnTarget.SetCompact(nBits, &fNegative, &fOverflow); // Check range - if (fNegative || bnTarget == 0 || fOverflow || bnTarget > Params().GetConsensus().powLimit) + if (fNegative || bnTarget.IsNull() || fOverflow || bnTarget > Params().GetConsensus().powLimit) return error("CheckProofOfWork() : nBits below minimum work"); // Check proof of work matches claimed amount @@ -145,8 +145,8 @@ uint256 GetBlockProof(const CBlockIndex& block) bool fNegative; bool fOverflow; bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); - if (fNegative || fOverflow || bnTarget == 0) - return 0; + if (fNegative || fOverflow || bnTarget.IsNull()) + return UINT256_ZERO; // We need to compute 2**256 / (bnTarget+1), but we can't represent 2**256 // as it's too large for a uint256. However, as 2**256 is at least as large // as bnTarget+1, it is equal to ((2**256 - bnTarget - 1) / (bnTarget+1)) + 1, diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 04ccb8a579c8..5a1331f1b786 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -140,7 +140,7 @@ void CTransaction::UpdateHash() const *const_cast(&hash) = SerializeHash(*this); } -CTransaction::CTransaction() : hash(), nVersion(CTransaction::CURRENT_VERSION), vin(), vout(), nLockTime(0) { } +CTransaction::CTransaction() : nVersion(CTransaction::CURRENT_VERSION), vin(), vout(), nLockTime(0) { } CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime) { UpdateHash(); diff --git a/src/protocol.cpp b/src/protocol.cpp index df9b0921f231..381554e17cc0 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -105,7 +105,7 @@ void CAddress::Init() CInv::CInv() { type = 0; - hash = 0; + hash.SetNull(); } CInv::CInv(int typeIn, const uint256& hashIn) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 04f96b82e25e..73c4e509221f 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -114,7 +114,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx for (const CTransaction& tx : block.vtx) { if (txDetails) { UniValue objTx(UniValue::VOBJ); - TxToJSON(tx, uint256(0), objTx); + TxToJSON(tx, UINT256_ZERO, objTx); txs.push_back(objTx); } else txs.push_back(tx.GetHash().GetHex()); diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 560f327291da..0adee682f1a3 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -484,7 +484,7 @@ UniValue decoderawtransaction(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); UniValue result(UniValue::VOBJ); - TxToJSON(tx, 0, result); + TxToJSON(tx, UINT256_ZERO, result); return result; } @@ -900,7 +900,7 @@ UniValue getspentzerocoinamount(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter for transaction input"); CTransaction tx; - uint256 hashBlock = 0; + uint256 hashBlock = UINT256_ZERO; if (!GetTransaction(txHash, tx, hashBlock, true)) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction"); diff --git a/src/stakeinput.cpp b/src/stakeinput.cpp index 08f108532053..4dd71eae30d5 100644 --- a/src/stakeinput.cpp +++ b/src/stakeinput.cpp @@ -98,7 +98,7 @@ CBlockIndex* CPivStake::GetIndexFrom() { if (pindexFrom) return pindexFrom; - uint256 hashBlock = 0; + uint256 hashBlock = UINT256_ZERO; CTransaction tx; if (GetTransaction(txFrom.GetHash(), tx, hashBlock, true)) { // If the index is in the chain, then set it as the "index from" diff --git a/src/test/pmt_tests.cpp b/src/test/pmt_tests.cpp index 620748643f13..289da80c44d6 100644 --- a/src/test/pmt_tests.cpp +++ b/src/test/pmt_tests.cpp @@ -47,7 +47,7 @@ BOOST_AUTO_TEST_CASE(pmt_test1) // calculate actual merkle root and height uint256 merkleRoot1 = BlockMerkleRoot(block); - std::vector vTxid(nTx, 0); + std::vector vTxid(nTx, UINT256_ZERO); for (unsigned int j=0; j pcursor(NewIterator()); CDataStream ssKeySet(SER_DISK, CLIENT_VERSION); - ssKeySet << std::make_pair('b', uint256(0)); + ssKeySet << std::make_pair('b', UINT256_ZERO); pcursor->Seek(ssKeySet.str()); // Load mapBlockIndex @@ -354,7 +354,7 @@ bool CZerocoinDB::WipeCoins(std::string strType) char type = (strType == "spends" ? 's' : 'm'); CDataStream ssKeySet(SER_DISK, CLIENT_VERSION); - ssKeySet << std::make_pair(type, uint256(0)); + ssKeySet << std::make_pair(type, UINT256_ZERO); pcursor->Seek(ssKeySet.str()); // Load mapBlockIndex std::set setDelete; diff --git a/src/uint256.h b/src/uint256.h index 80a9314e16c5..da8fadec6c15 100644 --- a/src/uint256.h +++ b/src/uint256.h @@ -311,6 +311,12 @@ class base_uint s.read((char*)pn, sizeof(pn)); } + // Temporary for migration to opaque uint160/256 + uint64_t GetCheapHash() const + { + return GetLow64(); + } + friend class uint160; friend class uint256; friend class uint512; @@ -364,7 +370,7 @@ class uint256 : public base_uint<256> /* uint256 from const char *. * This is a separate function because the constructor uint256(const char*) can result - * in dangerously catching uint256(0). + * in dangerously catching UINT256_ZERO. */ inline uint256 uint256S(const char* str) { @@ -374,7 +380,7 @@ inline uint256 uint256S(const char* str) } /* uint256 from std::string. * This is a separate function because the constructor uint256(const std::string &str) can result - * in dangerously catching uint256(0) via std::string(const char*). + * in dangerously catching UINT256_ZERO via std::string(const char*). */ inline uint256 uint256S(const std::string& str) { @@ -410,4 +416,7 @@ inline uint512 uint512S(const std::string& str) return rv; } +/** constant uint256 instances */ +const uint256 UINT256_ZERO = uint256(); + #endif // PIVX_UINT256_H diff --git a/src/uint512.h b/src/uint512.h index 79ca24440bba..ec3c42d7de31 100644 --- a/src/uint512.h +++ b/src/uint512.h @@ -33,7 +33,7 @@ class uint512 : public base_blob<512> /* uint256 from const char *. * This is a separate function because the constructor uint256(const char*) can result - * in dangerously catching uint256(0). + * in dangerously catching UINT256_ZERO. */ inline uint512 uint512S(const char* str) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 23dcfa2dc632..5f17fc4d7b48 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2085,7 +2085,7 @@ UniValue listsinceblock(const UniValue& params, bool fHelp) isminefilter filter = ISMINE_SPENDABLE_ALL | ISMINE_COLD; if (params.size() > 0) { - uint256 blockId = 0; + uint256 blockId; blockId.SetHex(params[0].get_str()); BlockMap::iterator it = mapBlockIndex.find(blockId); @@ -2116,7 +2116,7 @@ UniValue listsinceblock(const UniValue& params, bool fHelp) } CBlockIndex* pblockLast = chainActive[chainActive.Height() + 1 - target_confirms]; - uint256 lastblock = pblockLast ? pblockLast->GetBlockHash() : 0; + uint256 lastblock = pblockLast ? pblockLast->GetBlockHash() : UINT256_ZERO; UniValue ret(UniValue::VOBJ); ret.push_back(Pair("transactions", transactions)); @@ -3722,14 +3722,14 @@ UniValue resetspentzerocoin(const UniValue& params, bool fHelp) for (CZerocoinSpend spend : listSpends) { CTransaction tx; - uint256 hashBlock = 0; + uint256 hashBlock = UINT256_ZERO; if (!GetTransaction(spend.GetTxHash(), tx, hashBlock)) { listUnconfirmedSpends.push_back(spend); continue; } //no confirmations - if (hashBlock == 0) + if (hashBlock.IsNull()) listUnconfirmedSpends.push_back(spend); } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8e63c60cfa6f..e1590700efb7 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3334,7 +3334,7 @@ void CWallet::GetKeyBirthTimes(std::map& mapKeyBirth) const unsigned int CWallet::ComputeTimeSmart(const CWalletTx& wtx) const { unsigned int nTimeSmart = wtx.nTimeReceived; - if (wtx.hashBlock != 0) { + if (!wtx.hashBlock.IsNull()) { if (mapBlockIndex.count(wtx.hashBlock)) { int64_t latestNow = wtx.nTimeReceived; int64_t latestEntry = 0; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index f073d433a1bb..ff29d2bc41d6 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -630,7 +630,7 @@ class CMerkleTx : public CTransaction void Init() { - hashBlock = 0; + hashBlock = UINT256_ZERO; nIndex = -1; } diff --git a/src/wallet/wallet_zerocoin.cpp b/src/wallet/wallet_zerocoin.cpp index f3c9f151934b..f347e9fd7cd5 100644 --- a/src/wallet/wallet_zerocoin.cpp +++ b/src/wallet/wallet_zerocoin.cpp @@ -723,14 +723,14 @@ std::string CWallet::ResetSpentZerocoin() for (CZerocoinSpend spend : listSpends) { CTransaction tx; - uint256 hashBlock = 0; + uint256 hashBlock = UINT256_ZERO; if (!GetTransaction(spend.GetTxHash(), tx, hashBlock)) { listUnconfirmedSpends.push_back(spend); continue; } //no confirmations - if (hashBlock == 0) + if (hashBlock.IsNull()) listUnconfirmedSpends.push_back(spend); } diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 9fa348f05f08..59d2c5328674 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -498,7 +498,7 @@ bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, CW } CKey key; CPrivKey pkey; - uint256 hash = 0; + uint256 hash; if (strType == "key") { wss.nKeys++; @@ -521,7 +521,7 @@ bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, CW bool fSkipCheck = false; - if (hash != 0) { + if (!hash.IsNull()) { // hash pubkey/privkey to accelerate wallet load std::vector vchKey; vchKey.reserve(vchPubKey.size() + pkey.size()); @@ -1334,7 +1334,7 @@ std::map > > CWalletDB::MapMin // Read next record CDataStream ssKey(SER_DISK, CLIENT_VERSION); if (fFlags == DB_SET_RANGE) - ssKey << std::make_pair(std::string("mintpool"), uint256(0)); + ssKey << std::make_pair(std::string("mintpool"), UINT256_ZERO); CDataStream ssValue(SER_DISK, CLIENT_VERSION); int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags); fFlags = DB_NEXT; @@ -1390,7 +1390,7 @@ std::list CWalletDB::ListDeterministicMints() // Read next record CDataStream ssKey(SER_DISK, CLIENT_VERSION); if (fFlags == DB_SET_RANGE) - ssKey << make_pair(std::string("dzpiv"), uint256(0)); + ssKey << make_pair(std::string("dzpiv"), UINT256_ZERO); CDataStream ssValue(SER_DISK, CLIENT_VERSION); int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags); fFlags = DB_NEXT; @@ -1435,7 +1435,7 @@ std::list CWalletDB::ListMintedCoins() // Read next record CDataStream ssKey(SER_DISK, CLIENT_VERSION); if (fFlags == DB_SET_RANGE) - ssKey << make_pair(std::string("zerocoin"), uint256(0)); + ssKey << make_pair(std::string("zerocoin"), UINT256_ZERO); CDataStream ssValue(SER_DISK, CLIENT_VERSION); int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags); fFlags = DB_NEXT; From d96eab9d719cf93f9fadf067ed02b5683059d764 Mon Sep 17 00:00:00 2001 From: furszy Date: Tue, 10 Mar 2020 23:18:22 -0300 Subject: [PATCH 2/5] Replace GetLow64 with GetCheapHash --- src/addrman.cpp | 10 +++++----- src/main.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/addrman.cpp b/src/addrman.cpp index 7dcb894c3ab7..0bd9e9fef533 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -13,22 +13,22 @@ int CAddrInfo::GetTriedBucket(const uint256& nKey) const { - uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetKey()).GetHash().GetLow64(); - uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup() << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP)).GetHash().GetLow64(); + uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetKey()).GetHash().GetCheapHash(); + uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup() << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP)).GetHash().GetCheapHash(); return hash2 % ADDRMAN_TRIED_BUCKET_COUNT; } int CAddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src) const { std::vector vchSourceGroupKey = src.GetGroup(); - uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup() << vchSourceGroupKey).GetHash().GetLow64(); - uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << vchSourceGroupKey << (hash1 % ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP)).GetHash().GetLow64(); + uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup() << vchSourceGroupKey).GetHash().GetCheapHash(); + uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << vchSourceGroupKey << (hash1 % ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP)).GetHash().GetCheapHash(); return hash2 % ADDRMAN_NEW_BUCKET_COUNT; } int CAddrInfo::GetBucketPosition(const uint256& nKey, bool fNew, int nBucket) const { - uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << (fNew ? 'N' : 'K') << nBucket << GetKey()).GetHash().GetLow64(); + uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << (fNew ? 'N' : 'K') << nBucket << GetKey()).GetHash().GetCheapHash(); return hash1 % ADDRMAN_BUCKET_SIZE; } diff --git a/src/main.h b/src/main.h index eac7fb70a1fd..d825b005dc5b 100644 --- a/src/main.h +++ b/src/main.h @@ -117,7 +117,7 @@ static const unsigned int DEFAULT_BLOCK_SPAM_FILTER_MAX_SIZE = 100; static const unsigned int DEFAULT_BLOCK_SPAM_FILTER_MAX_AVG = 10; struct BlockHasher { - size_t operator()(const uint256& hash) const { return hash.GetLow64(); } + size_t operator()(const uint256& hash) const { return hash.GetCheapHash(); } }; extern CScript COINBASE_FLAGS; From 14319cff21659e629648f5e062f27e07a96811bf Mon Sep 17 00:00:00 2001 From: furszy Date: Tue, 10 Mar 2020 23:24:57 -0300 Subject: [PATCH 3/5] [Backport] Replace uint256(1) with static constant. SignatureHash and its test function SignatureHashOld return uint256(1) as a special error signaling value. Return a local static constant with the same value instead. --- src/script/interpreter.cpp | 4 ++-- src/test/sighash_tests.cpp | 4 ++-- src/uint256.h | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index d904c591bcff..219538b439f3 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -1091,14 +1091,14 @@ uint256 SignatureHash(const CScript& scriptCode, const CTransaction& txTo, unsig { if (nIn >= txTo.vin.size()) { // nIn out of range - return 1; + return UINT256_ONE; } // Check for invalid use of SIGHASH_SINGLE if ((nHashType & 0x1f) == SIGHASH_SINGLE) { if (nIn >= txTo.vout.size()) { // nOut out of range - return 1; + return UINT256_ONE; } } diff --git a/src/test/sighash_tests.cpp b/src/test/sighash_tests.cpp index ff3f39eb7f38..28f15ad7b47e 100644 --- a/src/test/sighash_tests.cpp +++ b/src/test/sighash_tests.cpp @@ -28,7 +28,7 @@ uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, un if (nIn >= txTo.vin.size()) { printf("ERROR: SignatureHash() : nIn=%d out of range\n", nIn); - return 1; + return UINT256_ONE; } CMutableTransaction txTmp(txTo); @@ -59,7 +59,7 @@ uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, un if (nOut >= txTmp.vout.size()) { printf("ERROR: SignatureHash() : nOut=%d out of range\n", nOut); - return 1; + return UINT256_ONE; } txTmp.vout.resize(nOut+1); for (unsigned int i = 0; i < nOut; i++) diff --git a/src/uint256.h b/src/uint256.h index da8fadec6c15..4bf0f22491a6 100644 --- a/src/uint256.h +++ b/src/uint256.h @@ -418,5 +418,6 @@ inline uint512 uint512S(const std::string& str) /** constant uint256 instances */ const uint256 UINT256_ZERO = uint256(); +const uint256 UINT256_ONE = uint256("0000000000000000000000000000000000000000000000000000000000000001"); #endif // PIVX_UINT256_H From b0163f6a38f26e16a46f43b53a5cc97af826a78e Mon Sep 17 00:00:00 2001 From: furszy Date: Tue, 10 Mar 2020 23:36:32 -0300 Subject: [PATCH 4/5] x=0 moved to x=UINT256_ZERO More x=0 moved to x=UINT256_ZERO and SetNull(). --- src/chain.h | 2 +- src/coins.cpp | 2 +- src/init.cpp | 2 +- src/invalid.cpp | 2 +- src/kernel.cpp | 6 +++--- src/libzerocoin/Coin.cpp | 2 +- src/main.cpp | 8 ++++---- src/masternode-budget.cpp | 26 +++++++++++++------------- src/masternode-budget.h | 2 +- src/masternode-payments.cpp | 2 +- src/masternode-sync.cpp | 4 ++-- src/masternode.cpp | 6 +++--- src/masternodeman.cpp | 2 +- src/primitives/transaction.cpp | 2 +- src/qt/pivx/sendconfirmdialog.h | 2 +- src/rpc/blockchain.cpp | 2 +- src/rpc/budget.cpp | 2 +- src/rpc/masternode.cpp | 2 +- src/stakeinput.h | 4 ++-- src/test/uint256_tests.cpp | 2 +- src/txdb.cpp | 2 +- src/wallet/wallet.cpp | 2 +- src/wallet/wallet.h | 2 +- src/wallet/wallet_zerocoin.cpp | 2 +- src/wallet/walletdb.cpp | 2 +- src/zpiv/deterministicmint.cpp | 10 +++++----- src/zpiv/zerocoin.h | 4 ++-- src/zpiv/zpivmodule.h | 2 +- src/zpiv/zpivtracker.cpp | 4 ++-- src/zpiv/zpivwallet.cpp | 10 +++++----- src/zpiv/zpos.h | 2 +- src/zpivchain.cpp | 10 +++++----- 32 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/chain.h b/src/chain.h index 856b684a10d7..f2a00f3432d3 100644 --- a/src/chain.h +++ b/src/chain.h @@ -351,7 +351,7 @@ class CDiskBlockIndex : public CBlockIndex READWRITE(nStakeModifier); this->SetStakeModifier(nStakeModifier, this->GeneratedStakeModifier()); } else { - uint256 nStakeModifierV2 = 0; + uint256 nStakeModifierV2; READWRITE(nStakeModifierV2); this->SetStakeModifier(nStakeModifierV2); } diff --git a/src/coins.cpp b/src/coins.cpp index 3763b0ad766f..699d143de85f 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -54,7 +54,7 @@ bool CCoins::Spend(const COutPoint& out, CTxInUndo& undo) bool CCoins::Spend(int nPos) { CTxInUndo undo; - COutPoint out(0, nPos); + COutPoint out(UINT256_ZERO, nPos); return Spend(out, undo); } diff --git a/src/init.cpp b/src/init.cpp index f2a66007106e..d20b66bee12a 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1750,7 +1750,7 @@ bool AppInit2() } fVerifyingBlocks = false; - if (zwalletMain->GetMasterSeed() != 0) { + if (!zwalletMain->GetMasterSeed().IsNull()) { //Inititalize zPIVWallet uiInterface.InitMessage(_("Syncing zPIV wallet...")); diff --git a/src/invalid.cpp b/src/invalid.cpp index 0a9ea8613643..36268ac8fa56 100644 --- a/src/invalid.cpp +++ b/src/invalid.cpp @@ -38,7 +38,7 @@ namespace invalid_out return false; uint256 txid = uint256(vTxid.get_str()); - if (txid == 0) + if (txid.IsNull()) return false; const UniValue &vN = find_value(o, "n"); diff --git a/src/kernel.cpp b/src/kernel.cpp index 63b041d336ce..733202fb4d9c 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -272,7 +272,7 @@ static bool SelectBlockFromCandidates( bool fModifierV2 = false; bool fFirstRun = true; bool fSelected = false; - uint256 hashBest = 0; + uint256 hashBest; *pindexSelected = (const CBlockIndex*)0; for (const PAIRTYPE(int64_t, uint256) & item : vSortedByTimestamp) { if (!mapBlockIndex.count(item.second)) @@ -296,7 +296,7 @@ static bool SelectBlockFromCandidates( if(fModifierV2) hashProof = pindex->GetBlockHash(); else - hashProof = pindex->IsProofOfStake() ? 0 : pindex->GetBlockHash(); + hashProof = pindex->IsProofOfStake() ? UINT256_ZERO : pindex->GetBlockHash(); CDataStream ss(SER_GETHASH, 0); ss << hashProof << nStakeModifierPrev; @@ -335,7 +335,7 @@ bool GetOldStakeModifier(CStakeInput* stake, uint64_t& nStakeModifier) const int nHeightStop = std::min(chainActive.Height(), Params().GetConsensus().height_last_ZC_AccumCheckpoint-1); while (pindexFrom && pindexFrom->nHeight + 1 <= nHeightStop) { if (pindexFrom->GetBlockTime() - nTimeBlockFrom > 60 * 60) { - nStakeModifier = pindexFrom->nAccumulatorCheckpoint.Get64(); + nStakeModifier = pindexFrom->nAccumulatorCheckpoint.GetCheapHash(); return true; } pindexFrom = chainActive.Next(pindexFrom); diff --git a/src/libzerocoin/Coin.cpp b/src/libzerocoin/Coin.cpp index 5bf240572728..db71cc815a3e 100644 --- a/src/libzerocoin/Coin.cpp +++ b/src/libzerocoin/Coin.cpp @@ -109,7 +109,7 @@ bool GenerateKeyPair(const CBigNum& bnGroupOrder, const uint256& nPrivkey, CKey& // Generate a new key pair, which also has a 256-bit pubkey hash that qualifies as a serial # // This builds off of Tim Ruffing's work on libzerocoin, but has a different implementation CKey keyPair; - if (nPrivkey == 0) + if (nPrivkey.IsNull()) keyPair.MakeNewKey(true); else keyPair.Set(nPrivkey.begin(), nPrivkey.end(), true); diff --git a/src/main.cpp b/src/main.cpp index 71113d79233f..88253dce6784 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1056,7 +1056,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa if (!ZPIVModule::ParseZerocoinPublicSpend(txIn, tx, state, publicSpend)){ return false; } - if (!ContextualCheckZerocoinSpend(tx, &publicSpend, chainHeight, 0)) + if (!ContextualCheckZerocoinSpend(tx, &publicSpend, chainHeight, UINT256_ZERO)) return state.Invalid(error("%s: ContextualCheckZerocoinSpend failed for tx %s", __func__, tx.GetHash().GetHex()), REJECT_INVALID, "bad-txns-invalid-zpiv"); @@ -4093,7 +4093,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, bool isPoS = block.IsProofOfStake(); if (isPoS) { - uint256 hashProofOfStake = 0; + uint256 hashProofOfStake; std::unique_ptr stake; if (!CheckProofOfStake(block, hashProofOfStake, stake, pindexPrev->nHeight)) return state.DoS(100, error("%s: proof of stake check failed", __func__)); @@ -4267,7 +4267,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, return state.DoS(100, error("%s: serial double spent on main chain", __func__)); } - if (!ContextualCheckZerocoinSpendNoSerialCheck(stakeTxIn, &spend, pindex->nHeight, 0)) + if (!ContextualCheckZerocoinSpendNoSerialCheck(stakeTxIn, &spend, pindex->nHeight, UINT256_ZERO)) return state.DoS(100,error("%s: forked chain ContextualCheckZerocoinSpend failed for tx %s", __func__, stakeTxIn.GetHash().GetHex()), REJECT_INVALID, "bad-txns-invalid-zpiv"); @@ -4298,7 +4298,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, if(!isBlockFromFork) for (const CTxIn& zPivInput : zPIVInputs) { libzerocoin::CoinSpend spend = TxInToZerocoinSpend(zPivInput); - if (!ContextualCheckZerocoinSpend(stakeTxIn, &spend, pindex->nHeight, 0)) + if (!ContextualCheckZerocoinSpend(stakeTxIn, &spend, pindex->nHeight, UINT256_ZERO)) return state.DoS(100,error("%s: main chain ContextualCheckZerocoinSpend failed for tx %s", __func__, stakeTxIn.GetHash().GetHex()), REJECT_INVALID, "bad-txns-invalid-zpiv"); } diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index 901bf72e05bd..c2f6110d10ac 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -84,7 +84,7 @@ bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, s */ int conf = GetIXConfirmations(nTxCollateralHash); - if (nBlockHash != UINT256_ZERO) { + if (!nBlockHash.IsNull()) { BlockMap::iterator mi = mapBlockIndex.find(nBlockHash); if (mi != mapBlockIndex.end() && (*mi).second) { CBlockIndex* pindex = (*mi).second; @@ -192,7 +192,7 @@ void CBudgetManager::SubmitFinalBudget() return; } - CFinalizedBudgetBroadcast tempBudget(strBudgetName, nBlockStart, vecTxBudgetPayments, 0); + CFinalizedBudgetBroadcast tempBudget(strBudgetName, nBlockStart, vecTxBudgetPayments, UINT256_ZERO); if (mapSeenFinalizedBudgets.count(tempBudget.GetHash())) { LogPrint("mnbudget","CBudgetManager::SubmitFinalBudget - Budget already exists - %s\n", tempBudget.GetHash().ToString()); nSubmittedHeight = nCurrentHeight; @@ -230,7 +230,7 @@ void CBudgetManager::SubmitFinalBudget() return; } - if (nBlockHash != UINT256_ZERO) { + if (!nBlockHash.IsNull()) { BlockMap::iterator mi = mapBlockIndex.find(nBlockHash); if (mi != mapBlockIndex.end() && (*mi).second) { CBlockIndex* pindex = (*mi).second; @@ -977,7 +977,7 @@ void CBudgetManager::NewBlock() LOCK(cs_vNodes); for (CNode* pnode : vNodes) if (pnode->nVersion >= ActiveProtocol()) - Sync(pnode, 0, true); + Sync(pnode, UINT256_ZERO, true); MarkSynced(); } @@ -1077,7 +1077,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData vRecv >> nProp; if (Params().NetworkID() == CBaseChainParams::MAIN) { - if (nProp == 0) { + if (nProp.IsNull()) { if (pfrom->HasFulfilledRequest("mnvs")) { LogPrint("mnbudget","mnvs - peer already asked me for the list\n"); Misbehaving(pfrom->GetId(), 20); @@ -1342,7 +1342,7 @@ void CBudgetManager::Sync(CNode* pfrom, uint256 nProp, bool fPartial) std::map::iterator it1 = mapSeenMasternodeBudgetProposals.begin(); while (it1 != mapSeenMasternodeBudgetProposals.end()) { CBudgetProposal* pbudgetProposal = FindProposal((*it1).first); - if (pbudgetProposal && pbudgetProposal->fValid && (nProp == 0 || (*it1).first == nProp)) { + if (pbudgetProposal && pbudgetProposal->fValid && (nProp.IsNull() || (*it1).first == nProp)) { pfrom->PushInventory(CInv(MSG_BUDGET_PROPOSAL, (*it1).second.GetHash())); nInvCount++; @@ -1370,7 +1370,7 @@ void CBudgetManager::Sync(CNode* pfrom, uint256 nProp, bool fPartial) std::map::iterator it3 = mapSeenFinalizedBudgets.begin(); while (it3 != mapSeenFinalizedBudgets.end()) { CFinalizedBudget* pfinalizedBudget = FindFinalizedBudget((*it3).first); - if (pfinalizedBudget && pfinalizedBudget->fValid && (nProp == 0 || (*it3).first == nProp)) { + if (pfinalizedBudget && pfinalizedBudget->fValid && (nProp.IsNull() || (*it3).first == nProp)) { pfrom->PushInventory(CInv(MSG_BUDGET_FINALIZED, (*it3).second.GetHash())); nInvCount++; @@ -1766,7 +1766,7 @@ CBudgetVote::CBudgetVote() : fValid(true), fSynced(false), vin(), - nProposalHash(0), + nProposalHash(), nVote(VOTE_ABSTAIN), nTime(0) { } @@ -1811,7 +1811,7 @@ CFinalizedBudget::CFinalizedBudget() : nBlockStart(0), vecBudgetPayments(), mapVotes(), - nFeeTXHash(0), + nFeeTXHash(), nTime(0) { } @@ -2072,7 +2072,7 @@ bool CFinalizedBudget::IsValid(std::string& strError, bool fCheckCollateral) strError = "Budget " + strBudgetName + " (" + strProposals + ") Invalid BlockStart == 0"; return false; } - if (nFeeTXHash == 0) { + if (nFeeTXHash.IsNull()) { strError = "Budget " + strBudgetName + " (" + strProposals + ") Invalid FeeTx == 0"; return false; } @@ -2172,7 +2172,7 @@ TrxValidationStatus CFinalizedBudget::IsTransactionValid(const CTransaction& txN paid = IsPaidAlready(vecBudgetPayments[nCurrentBudgetPayment].nProposalHash, nBlockHeight); if(paid) { LogPrint("mnbudget","CFinalizedBudget::IsTransactionValid - Double Budget Payment of %d for proposal %d detected. Paying a masternode instead.\n", - vecBudgetPayments[nCurrentBudgetPayment].nAmount, vecBudgetPayments[nCurrentBudgetPayment].nProposalHash.Get32()); + vecBudgetPayments[nCurrentBudgetPayment].nAmount, vecBudgetPayments[nCurrentBudgetPayment].nProposalHash.GetHex()); // No matter what we've found before, stop all checks here. In future releases there might be more than one budget payment // per block, so even if the first one was not paid yet this one disables all budget payments for this block. transactionStatus = TrxValidationStatus::DoublePayment; @@ -2181,7 +2181,7 @@ TrxValidationStatus CFinalizedBudget::IsTransactionValid(const CTransaction& txN else { transactionStatus = TrxValidationStatus::Valid; LogPrint("mnbudget","CFinalizedBudget::IsTransactionValid - Found valid Budget Payment of %d for proposal %d\n", - vecBudgetPayments[nCurrentBudgetPayment].nAmount, vecBudgetPayments[nCurrentBudgetPayment].nProposalHash.Get32()); + vecBudgetPayments[nCurrentBudgetPayment].nAmount, vecBudgetPayments[nCurrentBudgetPayment].nProposalHash.GetHex()); } } } @@ -2262,7 +2262,7 @@ CFinalizedBudgetVote::CFinalizedBudgetVote() : fValid(true), fSynced(false), vin(), - nBudgetHash(0), + nBudgetHash(), nTime(0) { } diff --git a/src/masternode-budget.h b/src/masternode-budget.h index fe878212c05b..7873a56e19c1 100644 --- a/src/masternode-budget.h +++ b/src/masternode-budget.h @@ -289,7 +289,7 @@ class CTxBudgetPayment { payee = CScript(); nAmount = 0; - nProposalHash = 0; + nProposalHash = UINT256_ZERO; } ADD_SERIALIZE_METHODS; diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index f6081e2a543a..1394526b41ce 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -549,7 +549,7 @@ bool CMasternodePayments::IsScheduled(CMasternode& mn, int nNotBlockHeight) bool CMasternodePayments::AddWinningMasternode(CMasternodePaymentWinner& winnerIn) { - uint256 blockHash = 0; + uint256 blockHash; if (!GetBlockHash(blockHash, winnerIn.nBlockHeight - 100)) { return false; } diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp index e18dfa444c92..22810559b83d 100644 --- a/src/masternode-sync.cpp +++ b/src/masternode-sync.cpp @@ -296,7 +296,7 @@ void CMasternodeSync::Process() } else if (RequestedMasternodeAttempt < 6) { int nMnCount = mnodeman.CountEnabled(); pnode->PushMessage("mnget", nMnCount); //sync payees - uint256 n = 0; + uint256 n; pnode->PushMessage("mnvs", n); //sync masternode votes } else { RequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED; @@ -413,7 +413,7 @@ void CMasternodeSync::Process() if (RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 3) return; - uint256 n = 0; + uint256 n; pnode->PushMessage("mnvs", n); //sync masternode votes RequestedMasternodeAttempt++; diff --git a/src/masternode.cpp b/src/masternode.cpp index db9ffa8ca462..776e8a29d4a0 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -158,14 +158,14 @@ bool CMasternode::UpdateFromNewBroadcast(CMasternodeBroadcast& mnb) // uint256 CMasternode::CalculateScore(int mod, int64_t nBlockHeight) { - if (chainActive.Tip() == NULL) return 0; + if (chainActive.Tip() == NULL) return UINT256_ZERO; uint256 hash; uint256 aux = vin.prevout.hash + vin.prevout.n; if (!GetBlockHash(hash, nBlockHeight)) { LogPrint("masternode","CalculateScore ERROR - nHeight %d - Returned 0\n", nBlockHeight); - return 0; + return UINT256_ZERO; } CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); @@ -694,7 +694,7 @@ uint256 CMasternodeBroadcast::GetHash() const CMasternodePing::CMasternodePing() : CSignedMessage(), vin(), - blockHash(0), + blockHash(), sigTime(GetAdjustedTime()) { } diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index e2999f0ce51f..418baf556d26 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -519,7 +519,7 @@ CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight // -- (chance per block * chances before IsScheduled will fire) int nTenthNetwork = CountEnabled() / 10; int nCountTenth = 0; - uint256 nHigh = 0; + uint256 nHigh; for (PAIRTYPE(int64_t, CTxIn) & s : vecMasternodeLastPaid) { CMasternode* pmn = Find(s.second); if (!pmn) break; diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 5a1331f1b786..e98ab709cbeb 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -48,7 +48,7 @@ CTxIn::CTxIn(uint256 hashPrevTx, uint32_t nOut, CScript scriptSigIn, uint32_t nS bool CTxIn::IsZerocoinSpend() const { - return prevout.hash == 0 && scriptSig.IsZerocoinSpend(); + return prevout.hash.IsNull() && scriptSig.IsZerocoinSpend(); } bool CTxIn::IsZerocoinPublicSpend() const diff --git a/src/qt/pivx/sendconfirmdialog.h b/src/qt/pivx/sendconfirmdialog.h index c2d45611faad..9e1a00a5bd6d 100644 --- a/src/qt/pivx/sendconfirmdialog.h +++ b/src/qt/pivx/sendconfirmdialog.h @@ -49,7 +49,7 @@ public Q_SLOTS: WalletModel *model = nullptr; WalletModel::SendCoinsReturn sendStatus; WalletModelTransaction *tx = nullptr; - uint256 txHash = 0; + uint256 txHash; bool inputsLoaded = false; bool outputsLoaded = false; diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 73c4e509221f..d6c7974bf28a 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1115,7 +1115,7 @@ UniValue findserial(const UniValue& params, bool fHelp) if (!bnSerial) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid serial"); - uint256 txid = 0; + uint256 txid; bool fSuccess = zerocoinDB->ReadCoinSpend(bnSerial, txid); UniValue ret(UniValue::VOBJ); diff --git a/src/rpc/budget.cpp b/src/rpc/budget.cpp index 3b721d1ccd41..14fabe05704f 100644 --- a/src/rpc/budget.cpp +++ b/src/rpc/budget.cpp @@ -134,7 +134,7 @@ UniValue preparebudget(const UniValue& params, bool fHelp) CScript scriptPubKey = GetScriptForDestination(address.Get()); // create transaction 15 minutes into the future, to allow for confirmation time - CBudgetProposalBroadcast budgetProposalBroadcast(strProposalName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, 0); + CBudgetProposalBroadcast budgetProposalBroadcast(strProposalName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, UINT256_ZERO); std::string strError = ""; if (!budgetProposalBroadcast.IsValid(strError, false)) diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index af1523faec19..4b8d85683742 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -728,7 +728,7 @@ UniValue getmasternodescores (const UniValue& params, bool fHelp) std::vector vMasternodes = mnodeman.GetFullMasternodeVector(); for (int nHeight = chainActive.Tip()->nHeight - nLast; nHeight < chainActive.Tip()->nHeight + 20; nHeight++) { - uint256 nHigh = 0; + uint256 nHigh; CMasternode* pBestMasternode = NULL; for (CMasternode& mn : vMasternodes) { uint256 n = mn.CalculateScore(1, nHeight - 100); diff --git a/src/stakeinput.h b/src/stakeinput.h index cfcb5287f81a..6d9a9f07c6c8 100644 --- a/src/stakeinput.h +++ b/src/stakeinput.h @@ -21,7 +21,7 @@ class CStakeInput public: virtual ~CStakeInput(){}; virtual CBlockIndex* GetIndexFrom() = 0; - virtual bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = 0) = 0; + virtual bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = UINT256_ZERO) = 0; virtual bool GetTxFrom(CTransaction& tx) const = 0; virtual CAmount GetValue() const = 0; virtual bool CreateTxOuts(CWallet* pwallet, std::vector& vout, CAmount nTotal) = 0; @@ -45,7 +45,7 @@ class CPivStake : public CStakeInput bool GetTxFrom(CTransaction& tx) const override; CAmount GetValue() const override; CDataStream GetUniqueness() const override; - bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = 0) override; + bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = UINT256_ZERO) override; bool CreateTxOuts(CWallet* pwallet, std::vector& vout, CAmount nTotal) override; bool IsZPIV() const override { return false; } }; diff --git a/src/test/uint256_tests.cpp b/src/test/uint256_tests.cpp index 4314b3dc6be8..040a76814fe0 100644 --- a/src/test/uint256_tests.cpp +++ b/src/test/uint256_tests.cpp @@ -142,7 +142,7 @@ BOOST_AUTO_TEST_CASE( basics ) // constructors, equality, inequality // uint64_t constructor BOOST_CHECK( (R1L & uint256("0xffffffffffffffff")) == uint256(R1LLow64)); - BOOST_CHECK(ZeroL == UINT256_ZERO); + BOOST_CHECK(ZeroL.IsNull()); BOOST_CHECK(OneL == uint256(1)); BOOST_CHECK(uint256("0xffffffffffffffff") = uint256(0xffffffffffffffffULL)); BOOST_CHECK( (R1S & uint160("0xffffffffffffffff")) == uint160(R1LLow64)); diff --git a/src/txdb.cpp b/src/txdb.cpp index 6296fbddadf2..e507b602663e 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -64,7 +64,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap& mapCoins, const uint256& hashBlock) CCoinsMap::iterator itOld = it++; mapCoins.erase(itOld); } - if (hashBlock != UINT256_ZERO) + if (!hashBlock.IsNull()) BatchWriteHashBestChain(batch, hashBlock); LogPrint("coindb", "Committing %u changed transactions (out of %u) to coin database...\n", (unsigned int)changed, (unsigned int)count); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index e1590700efb7..48a42494b1d0 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2542,7 +2542,7 @@ bool CWallet::CreateCoinStake( } nCredit = 0; - uint256 hashProofOfStake = 0; + uint256 hashProofOfStake; nAttempts++; fKernelFound = Stake(pindexPrev, stakeInput.get(), nBits, nTxNewTime, hashProofOfStake); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index ff29d2bc41d6..9e1f36339c87 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -151,7 +151,7 @@ class CStakerStatus { const CBlockIndex* GetLastTip() const { return tipLastStakeAttempt; } uint256 GetLastHash() const { - return (tipLastStakeAttempt == nullptr ? 0 : tipLastStakeAttempt->GetBlockHash()); + return (tipLastStakeAttempt == nullptr ? UINT256_ZERO : tipLastStakeAttempt->GetBlockHash()); } int64_t GetLastTime() const { return timeLastStakeAttempt; } void SetLastTip(const CBlockIndex* lastTip) { tipLastStakeAttempt = lastTip; } diff --git a/src/wallet/wallet_zerocoin.cpp b/src/wallet/wallet_zerocoin.cpp index f347e9fd7cd5..a5f4da6e48b8 100644 --- a/src/wallet/wallet_zerocoin.cpp +++ b/src/wallet/wallet_zerocoin.cpp @@ -361,7 +361,7 @@ bool CWallet::MintsToInputVectorPublicSpend(std::map& ma return false; } vin.emplace_back(in); - receipt.AddSpend(CZerocoinSpend(mint.GetSerialNumber(), 0, mint.GetValue(), mint.GetDenomination(), 0)); + receipt.AddSpend(CZerocoinSpend(mint.GetSerialNumber(), UINT256_ZERO, mint.GetValue(), mint.GetDenomination(), 0)); } receipt.SetStatus(_("Spend Valid"), ZPIV_SPEND_OKAY); // Everything okay diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 59d2c5328674..b3fb1c0ec6f0 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -1283,7 +1283,7 @@ bool CWalletDB::EraseZPIVSeed() if(!WriteZPIVSeed(hash, ToByteVector(base_uint<256>(0) << 256))) { return error("Failed to write empty seed to wallet"); } - if(!WriteCurrentSeedHash(0)) { + if(!WriteCurrentSeedHash(UINT256_ZERO)) { return error("Failed to write empty seedHash"); } diff --git a/src/zpiv/deterministicmint.cpp b/src/zpiv/deterministicmint.cpp index b444355f8830..5664bfee199e 100644 --- a/src/zpiv/deterministicmint.cpp +++ b/src/zpiv/deterministicmint.cpp @@ -27,11 +27,11 @@ void CDeterministicMint::SetNull() { nVersion = libzerocoin::PrivateCoin::CURRENT_VERSION; nCount = 0; - hashSeed = 0; - hashSerial = 0; - hashStake = 0; - hashPubcoin = 0; - txid = 0; + hashSeed.SetNull(); + hashSerial.SetNull(); + hashStake.SetNull(); + hashPubcoin.SetNull(); + txid.SetNull(); nHeight = 0; denom = libzerocoin::CoinDenomination::ZQ_ERROR; isUsed = false; diff --git a/src/zpiv/zerocoin.h b/src/zpiv/zerocoin.h index 8fd4620a8b94..f5a6da6251f1 100644 --- a/src/zpiv/zerocoin.h +++ b/src/zpiv/zerocoin.h @@ -77,7 +77,7 @@ class CZerocoinMint value = 0; denomination = libzerocoin::ZQ_ERROR; nHeight = 0; - txid = 0; + txid.SetNull(); version = 1; privkey.clear(); } @@ -209,7 +209,7 @@ class CZerocoinSpend void SetNull() { coinSerial = 0; - hashTx = 0; + hashTx.SetNull(); pubCoin = 0; denomination = libzerocoin::ZQ_ERROR; } diff --git a/src/zpiv/zpivmodule.h b/src/zpiv/zpivmodule.h index 4a313ec7a0ba..bf99b4609724 100644 --- a/src/zpiv/zpivmodule.h +++ b/src/zpiv/zpivmodule.h @@ -47,7 +47,7 @@ class PublicCoinSpend : public libzerocoin::CoinSpend { CBigNum randomness; libzerocoin::CoinRandomnessSchnorrSignature schnorrSig; // prev out values - uint256 txHash = 0; + uint256 txHash; unsigned int outputIndex = -1; libzerocoin::PublicCoin pubCoin; diff --git a/src/zpiv/zpivtracker.cpp b/src/zpiv/zpivtracker.cpp index 8cdec3f56deb..86c6124ad28e 100644 --- a/src/zpiv/zpivtracker.cpp +++ b/src/zpiv/zpivtracker.cpp @@ -354,7 +354,7 @@ void CzPIVTracker::RemovePending(const uint256& txid) } } - if (hashSerial > 0) + if (!hashSerial.IsNull()) mapPendingSpends.erase(hashSerial); } @@ -389,7 +389,7 @@ bool CzPIVTracker::UpdateStatusInternal(const std::set& setMempool, CMi uint256 hashBlock; // Txid will be marked 0 if there is no knowledge of the final tx hash yet - if (mint.txid == 0) { + if (mint.txid.IsNull()) { if (!isMintInChain) { LogPrintf("%s : Failed to find mint in zerocoinDB %s\n", __func__, mint.hashPubcoin.GetHex().substr(0, 6)); mint.isArchived = true; diff --git a/src/zpiv/zpivwallet.cpp b/src/zpiv/zpivwallet.cpp index eb23696ef33d..e736f56bce9a 100644 --- a/src/zpiv/zpivwallet.cpp +++ b/src/zpiv/zpivwallet.cpp @@ -41,7 +41,7 @@ CzPIVWallet::CzPIVWallet(std::string strWalletFile) //Don't try to do anything if the wallet is locked. if (pwalletMain->IsLocked() || (!fRegtest && fFirstRun)) { - seedMaster = 0; + seedMaster.SetNull(); nCountLastUsed = 0; this->mintPool = CMintPool(); return; @@ -75,7 +75,7 @@ bool CzPIVWallet::SetMasterSeed(const uint256& seedMaster, bool fResetCount) if (pwalletMain->IsLocked()) return false; - if (seedMaster != 0 && !pwalletMain->AddDeterministicSeed(seedMaster)) { + if (!seedMaster.IsNull() && !pwalletMain->AddDeterministicSeed(seedMaster)) { return error("%s: failed to set master seed.", __func__); } @@ -95,7 +95,7 @@ bool CzPIVWallet::SetMasterSeed(const uint256& seedMaster, bool fResetCount) void CzPIVWallet::Lock() { - seedMaster = 0; + seedMaster.SetNull(); } void CzPIVWallet::AddToMintPool(const std::pair& pMint, bool fVerbose) @@ -108,7 +108,7 @@ void CzPIVWallet::GenerateMintPool(uint32_t nCountStart, uint32_t nCountEnd) { //Is locked - if (seedMaster == 0) + if (seedMaster.IsNull()) return; uint32_t n = nCountLastUsed + 1; @@ -377,7 +377,7 @@ void CzPIVWallet::SeedToZPIV(const uint512& seedZerocoin, CBigNum& bnValue, CBig params->coinCommitmentGroup.modulus); CBigNum random; - uint256 attempts256 = 0; + uint256 attempts256; // Iterate on Randomness until a valid commitmentValue is found while (true) { // Now verify that the commitment is a prime number diff --git a/src/zpiv/zpos.h b/src/zpiv/zpos.h index ded6a53a2e42..dc57c273ce36 100644 --- a/src/zpiv/zpos.h +++ b/src/zpiv/zpos.h @@ -24,7 +24,7 @@ class CLegacyZPivStake : public CStakeInput CBlockIndex* GetIndexFrom() override; CAmount GetValue() const override; CDataStream GetUniqueness() const override; - bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = 0) override { return false; /* creation disabled */} + bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = UINT256_ZERO) override { return false; /* creation disabled */} bool CreateTxOuts(CWallet* pwallet, std::vector& vout, CAmount nTotal) override { return false; /* creation disabled */} bool GetTxFrom(CTransaction& tx) const override { return false; /* not available */ } }; diff --git a/src/zpivchain.cpp b/src/zpivchain.cpp index c717afc6b1bc..dcb91f67e0fb 100644 --- a/src/zpivchain.cpp +++ b/src/zpivchain.cpp @@ -153,7 +153,7 @@ void FindMints(std::vector vMintsToFind, std::vector& vMin } //see if this mint is spent - uint256 hashTxSpend = 0; + uint256 hashTxSpend; bool fSpent = zerocoinDB->ReadCoinSpend(meta.hashSerial, hashTxSpend); //if marked as spent, check that it actually made it into the chain @@ -212,19 +212,19 @@ int GetZerocoinStartHeight() bool GetZerocoinMint(const CBigNum& bnPubcoin, uint256& txHash) { - txHash = 0; + txHash = UINT256_ZERO; return zerocoinDB->ReadCoinMint(bnPubcoin, txHash); } bool IsPubcoinInBlockchain(const uint256& hashPubcoin, uint256& txid) { - txid = 0; + txid.SetNull(); return zerocoinDB->ReadCoinMint(hashPubcoin, txid); } bool IsSerialInBlockchain(const CBigNum& bnSerial, int& nHeightTx) { - uint256 txHash = 0; + uint256 txHash; // if not in zerocoinDB then its not in the blockchain if (!zerocoinDB->ReadCoinSpend(bnSerial, txHash)) return false; @@ -240,7 +240,7 @@ bool IsSerialInBlockchain(const uint256& hashSerial, int& nHeightTx, uint256& tx bool IsSerialInBlockchain(const uint256& hashSerial, int& nHeightTx, uint256& txidSpend, CTransaction& tx) { - txidSpend = 0; + txidSpend.SetNull(); // if not in zerocoinDB then its not in the blockchain if (!zerocoinDB->ReadCoinSpend(hashSerial, txidSpend)) return false; From 400f6f4159a5590c97ae80e65244d3f177147cc2 Mon Sep 17 00:00:00 2001 From: furszy Date: Sat, 14 Mar 2020 16:26:52 -0300 Subject: [PATCH 5/5] Moving uint256(str) to proper uint256S(str). --> uint256 string parse. --- src/activemasternode.cpp | 2 +- src/bip38.cpp | 16 ++++----- src/chain.cpp | 2 +- src/chainparams.cpp | 64 +++++++++++++++++----------------- src/crypter.cpp | 6 ++-- src/invalid.cpp | 2 +- src/qt/proposalframe.cpp | 2 +- src/rpc/blockchain.cpp | 10 +++--- src/rpc/budget.cpp | 6 ++-- src/rpc/masternode.cpp | 4 +-- src/rpc/rawtransaction.cpp | 2 +- src/test/Checkpoints_tests.cpp | 4 +-- src/wallet/rpcwallet.cpp | 12 +++---- 13 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index d0b6e1b2ead4..c7d7659b7794 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -368,7 +368,7 @@ bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secr // Find the vin if (!strTxHash.empty()) { // Let's find it - uint256 txHash(strTxHash); + uint256 txHash(uint256S(strTxHash)); int outputIndex; try { outputIndex = std::stoi(strOutputIndex.c_str()); diff --git a/src/bip38.cpp b/src/bip38.cpp index 44ac1c441870..d10bf6f1ec38 100644 --- a/src/bip38.cpp +++ b/src/bip38.cpp @@ -34,7 +34,7 @@ void DecryptAES(uint256 encryptedIn, uint256 decryptionKey, uint256& output) void ComputePreFactor(std::string strPassphrase, std::string strSalt, uint256& prefactor) { //passfactor is the scrypt hash of passphrase and ownersalt (NOTE this needs to handle alt cases too in the future) - uint64_t s = uint256(ReverseEndianString(strSalt)).Get64(); + uint64_t s = uint256S(ReverseEndianString(strSalt)).GetCheapHash(); scrypt_hash(strPassphrase.c_str(), strPassphrase.size(), BEGIN(s), strSalt.size() / 2, BEGIN(prefactor), 16384, 8, 8, 32); } @@ -82,7 +82,7 @@ void ComputeSeedBPass(CPubKey passpoint, std::string strAddressHash, std::string { // Derive decryption key for seedb using scrypt with passpoint, addresshash, and ownerentropy std::string salt = ReverseEndianString(strAddressHash + strOwnerSalt); - uint256 s2(salt); + uint256 s2(uint256S(salt)); scrypt_hash(BEGIN(passpoint), HexStr(passpoint).size() / 2, BEGIN(s2), salt.size() / 2, BEGIN(seedBPass), 1024, 1, 1, 64); } @@ -107,7 +107,7 @@ std::string BIP38_Encrypt(std::string strAddress, std::string strPassphrase, uin std::string strAddressHash = AddressToBip38Hash(strAddress); uint512 hashed; - uint64_t salt = uint256(ReverseEndianString(strAddressHash)).Get64(); + uint64_t salt = uint256S(ReverseEndianString(strAddressHash)).GetCheapHash(); scrypt_hash(strPassphrase.c_str(), strPassphrase.size(), BEGIN(salt), strAddressHash.size() / 2, BEGIN(hashed), 16384, 8, 8, 64); uint256 derivedHalf1(hashed.ToString().substr(64, 64)); @@ -178,11 +178,11 @@ bool BIP38_Decrypt(std::string strPassphrase, std::string strEncryptedKey, uint2 if (type == uint256(0x42)) { uint512 hashed; encryptedPart1 = uint256(ReverseEndianString(strKey.substr(14, 32))); - uint64_t salt = uint256(ReverseEndianString(strAddressHash)).Get64(); + uint64_t salt = uint256S(ReverseEndianString(strAddressHash)).GetCheapHash(); scrypt_hash(strPassphrase.c_str(), strPassphrase.size(), BEGIN(salt), strAddressHash.size() / 2, BEGIN(hashed), 16384, 8, 8, 64); - uint256 derivedHalf1(hashed.ToString().substr(64, 64)); - uint256 derivedHalf2(hashed.ToString().substr(0, 64)); + uint256 derivedHalf1(uint256S(hashed.ToString().substr(64, 64))); + uint256 derivedHalf2(uint256S(hashed.ToString().substr(0, 64))); uint256 decryptedPart1; DecryptAES(encryptedPart1, derivedHalf2, decryptedPart1); @@ -224,8 +224,8 @@ bool BIP38_Decrypt(std::string strPassphrase, std::string strEncryptedKey, uint2 ComputeSeedBPass(passpoint, strAddressHash, ownersalt, seedBPass); //get derived halfs, being mindful for endian switch - uint256 derivedHalf1(seedBPass.ToString().substr(64, 64)); - uint256 derivedHalf2(seedBPass.ToString().substr(0, 64)); + uint256 derivedHalf1(uint256S(seedBPass.ToString().substr(64, 64))); + uint256 derivedHalf2(uint256S(seedBPass.ToString().substr(0, 64))); /** Decrypt encryptedpart2 using AES256Decrypt to yield the last 8 bytes of seedb and the last 8 bytes of encryptedpart1. **/ uint256 decryptedPart2; diff --git a/src/chain.cpp b/src/chain.cpp index 7c8cd42a4dca..d1dc1c8274a1 100644 --- a/src/chain.cpp +++ b/src/chain.cpp @@ -166,7 +166,7 @@ int64_t CBlockIndex::GetMedianTimePast() const unsigned int CBlockIndex::GetStakeEntropyBit() const { - unsigned int nEntropyBit = ((GetBlockHash().Get64()) & 1); + unsigned int nEntropyBit = ((GetBlockHash().GetCheapHash()) & 1); if (GetBoolArg("-printstakemodifier", false)) LogPrintf("GetStakeEntropyBit: nHeight=%u hashBlock=%s nEntropyBit=%u\n", nHeight, GetBlockHash().ToString().c_str(), nEntropyBit); diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 1722bd6e3290..14fe27e60d39 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -85,26 +85,26 @@ static void convertSeed6(std::vector& vSeedsOut, const SeedSpec6* data // + Contains no strange transactions static Checkpoints::MapCheckpoints mapCheckpoints = boost::assign::map_list_of - (259201, uint256("1c9121bf9329a6234bfd1ea2d91515f19cd96990725265253f4b164283ade5dd")) - (424998, uint256("f31e381eedb0ed3ed65fcc98cc71f36012bee32e8efd017c4f9fb0620fd35f6b")) - (616764, uint256("29dd0bd1c59484f290896687b4ffb6a49afa5c498caf61967c69a541f8191557")) //first block to use modifierV2 - (623933, uint256("c7aafa648a0f1450157dc93bd4d7448913a85b7448f803b4ab970d91fc2a7da7")) - (791150, uint256("8e76f462e4e82d1bd21cb72e1ce1567d4ddda2390f26074ffd1f5d9c270e5e50")) - (795000, uint256("4423cceeb9fd574137a18733416275a70fdf95283cc79ad976ca399aa424a443")) - (863787, uint256("5b2482eca24caf2a46bb22e0545db7b7037282733faa3a42ec20542509999a64")) - (863795, uint256("2ad866818c4866e0d555181daccc628056216c0db431f88a825e84ed4f469067")) - (863805, uint256("a755bd9a22b63c70d3db474f4b2b61a1f86c835b290a081bb3ec1ba2103eb4cb")) - (867733, uint256("03b26296bf693de5782c76843d2fb649cb66d4b05550c6a79c047ff7e1c3ae15")) - (879650, uint256("227e1d2b738b6cd83c46d1d64617934ec899d77cee34336a56e61b71acd10bb2")) - (895400, uint256("7796a0274a608fac12d400198174e50beda992c1d522e52e5b95b884bc1beac6"))//block that serial# range is enforced - (895991, uint256("d53013ed7ea5c325b9696c95e07667d6858f8ff7ee13fecfa90827bf3c9ae316"))//network split here - (908000, uint256("202708f8c289b676fceb832a079ff6b308a28608339acbf7584de533619d014d")) - (1142400, uint256("98aff9d605bf123247f98b1e3a02567eb5799d208d78ec30fb89737b1c1f79c5")) - (1679090, uint256("f747ce055ba1b12e1f2e842bd480bc647210799359cb2e553ab292065e3419d6")) //!< First block with a "wrapped" serial spend - (1686229, uint256("bb42bf1e886a7c23474634c90893dd3d68a6ccbfea4ac92a98da5cad0c6a6cb7")) //!< Last block in the "wrapped" serial attack range - (1778954, uint256("0d3241268264a2908d6babf00d9cd1ffb83d93d7bb4e428820127fe227c2029c")) //!< Network split here - (1788528, uint256("ea9243ff8fc079fdd7a04f11fac415de4d98e1bb0dc38db6f79f8f8bbfdbe496")) //!< Network split here - (2153200, uint256("14e477e597d24549cac5e59d97d32155e6ec2861c1003b42d0566f9bf39b65d5")); //!< First v7 block + (259201, uint256S("1c9121bf9329a6234bfd1ea2d91515f19cd96990725265253f4b164283ade5dd")) + (424998, uint256S("f31e381eedb0ed3ed65fcc98cc71f36012bee32e8efd017c4f9fb0620fd35f6b")) + (616764, uint256S("29dd0bd1c59484f290896687b4ffb6a49afa5c498caf61967c69a541f8191557")) //first block to use modifierV2 + (623933, uint256S("c7aafa648a0f1450157dc93bd4d7448913a85b7448f803b4ab970d91fc2a7da7")) + (791150, uint256S("8e76f462e4e82d1bd21cb72e1ce1567d4ddda2390f26074ffd1f5d9c270e5e50")) + (795000, uint256S("4423cceeb9fd574137a18733416275a70fdf95283cc79ad976ca399aa424a443")) + (863787, uint256S("5b2482eca24caf2a46bb22e0545db7b7037282733faa3a42ec20542509999a64")) + (863795, uint256S("2ad866818c4866e0d555181daccc628056216c0db431f88a825e84ed4f469067")) + (863805, uint256S("a755bd9a22b63c70d3db474f4b2b61a1f86c835b290a081bb3ec1ba2103eb4cb")) + (867733, uint256S("03b26296bf693de5782c76843d2fb649cb66d4b05550c6a79c047ff7e1c3ae15")) + (879650, uint256S("227e1d2b738b6cd83c46d1d64617934ec899d77cee34336a56e61b71acd10bb2")) + (895400, uint256S("7796a0274a608fac12d400198174e50beda992c1d522e52e5b95b884bc1beac6"))//block that serial# range is enforced + (895991, uint256S("d53013ed7ea5c325b9696c95e07667d6858f8ff7ee13fecfa90827bf3c9ae316"))//network split here + (908000, uint256S("202708f8c289b676fceb832a079ff6b308a28608339acbf7584de533619d014d")) + (1142400, uint256S("98aff9d605bf123247f98b1e3a02567eb5799d208d78ec30fb89737b1c1f79c5")) + (1679090, uint256S("f747ce055ba1b12e1f2e842bd480bc647210799359cb2e553ab292065e3419d6")) //!< First block with a "wrapped" serial spend + (1686229, uint256S("bb42bf1e886a7c23474634c90893dd3d68a6ccbfea4ac92a98da5cad0c6a6cb7")) //!< Last block in the "wrapped" serial attack range + (1778954, uint256S("0d3241268264a2908d6babf00d9cd1ffb83d93d7bb4e428820127fe227c2029c")) //!< Network split here + (1788528, uint256S("ea9243ff8fc079fdd7a04f11fac415de4d98e1bb0dc38db6f79f8f8bbfdbe496")) //!< Network split here + (2153200, uint256S("14e477e597d24549cac5e59d97d32155e6ec2861c1003b42d0566f9bf39b65d5")); //!< First v7 block static const Checkpoints::CCheckpointData data = { &mapCheckpoints, 1578332625, // * UNIX timestamp of last checkpoint block @@ -115,11 +115,11 @@ static const Checkpoints::CCheckpointData data = { static Checkpoints::MapCheckpoints mapCheckpointsTestnet = boost::assign::map_list_of - (0, uint256("0x001")) - (1016800, uint256("6ae7d52092fd918c8ac8d9b1334400387d3057997e6e927a88e57186dc395231")) - (1106100, uint256("c54b3e7e8b710e4075da1806adf2d508ae722627d5bcc43f594cf64d5eef8b30")) //!< zc public spend activation height - (1112700, uint256("2ad8d507dbe3d3841b9f8a29c3878d570228e9361c3e057362d7915777bbc849")) - (1347000, uint256("30c173ffc09a13f288bf6e828216107037ce5b79536b1cebd750a014f4939882")); //!< First v7 block + (0, uint256S("0x001")) + (1016800, uint256S("6ae7d52092fd918c8ac8d9b1334400387d3057997e6e927a88e57186dc395231")) + (1106100, uint256S("c54b3e7e8b710e4075da1806adf2d508ae722627d5bcc43f594cf64d5eef8b30")) //!< zc public spend activation height + (1112700, uint256S("2ad8d507dbe3d3841b9f8a29c3878d570228e9361c3e057362d7915777bbc849")) + (1347000, uint256S("30c173ffc09a13f288bf6e828216107037ce5b79536b1cebd750a014f4939882")); //!< First v7 block static const Checkpoints::CCheckpointData dataTestnet = { &mapCheckpointsTestnet, 1575145155, @@ -127,7 +127,7 @@ static const Checkpoints::CCheckpointData dataTestnet = { 250}; static Checkpoints::MapCheckpoints mapCheckpointsRegtest = - boost::assign::map_list_of(0, uint256("0x001")); + boost::assign::map_list_of(0, uint256S("0x001")); static const Checkpoints::CCheckpointData dataRegtest = { &mapCheckpointsRegtest, 1454124731, @@ -144,8 +144,8 @@ class CMainParams : public CChainParams genesis = CreateGenesisBlock(1454124731, 2402015, 0x1e0ffff0, 1, 250 * COIN); consensus.hashGenesisBlock = genesis.GetHash(); - assert(consensus.hashGenesisBlock == uint256("0x0000041e482b9b9691d98eefb48473405c0b8ec31b76df3797c74a78680ef818")); - assert(genesis.hashMerkleRoot == uint256("0x1b2ef6e2f28be914103a277377ae7729dcd125dfeb8bf97bd5964ba72b6dc39b")); + assert(consensus.hashGenesisBlock == uint256S("0x0000041e482b9b9691d98eefb48473405c0b8ec31b76df3797c74a78680ef818")); + assert(genesis.hashMerkleRoot == uint256S("0x1b2ef6e2f28be914103a277377ae7729dcd125dfeb8bf97bd5964ba72b6dc39b")); consensus.fPowAllowMinDifficultyBlocks = false; consensus.powLimit = ~UINT256_ZERO >> 20; // PIVX starting difficulty is 1 / 2^12 @@ -265,8 +265,8 @@ class CTestNetParams : public CMainParams genesis = CreateGenesisBlock(1454124731, 2402015, 0x1e0ffff0, 1, 250 * COIN); consensus.hashGenesisBlock = genesis.GetHash(); - assert(consensus.hashGenesisBlock == uint256("0x0000041e482b9b9691d98eefb48473405c0b8ec31b76df3797c74a78680ef818")); - assert(genesis.hashMerkleRoot == uint256("0x1b2ef6e2f28be914103a277377ae7729dcd125dfeb8bf97bd5964ba72b6dc39b")); + assert(consensus.hashGenesisBlock == uint256S("0x0000041e482b9b9691d98eefb48473405c0b8ec31b76df3797c74a78680ef818")); + assert(genesis.hashMerkleRoot == uint256S("0x1b2ef6e2f28be914103a277377ae7729dcd125dfeb8bf97bd5964ba72b6dc39b")); consensus.fPowAllowMinDifficultyBlocks = true; consensus.powLimit = ~UINT256_ZERO >> 20; // PIVX starting difficulty is 1 / 2^12 @@ -389,8 +389,8 @@ class CRegTestParams : public CTestNetParams genesis = CreateGenesisBlock(1454124731, 2402015, 0x1e0ffff0, 1, 250 * COIN); consensus.hashGenesisBlock = genesis.GetHash(); - assert(consensus.hashGenesisBlock == uint256("0x0000041e482b9b9691d98eefb48473405c0b8ec31b76df3797c74a78680ef818")); - assert(genesis.hashMerkleRoot == uint256("0x1b2ef6e2f28be914103a277377ae7729dcd125dfeb8bf97bd5964ba72b6dc39b")); + assert(consensus.hashGenesisBlock == uint256S("0x0000041e482b9b9691d98eefb48473405c0b8ec31b76df3797c74a78680ef818")); + assert(genesis.hashMerkleRoot == uint256S("0x1b2ef6e2f28be914103a277377ae7729dcd125dfeb8bf97bd5964ba72b6dc39b")); consensus.fPowAllowMinDifficultyBlocks = true; consensus.powLimit = ~UINT256_ZERO >> 20; // PIVX starting difficulty is 1 / 2^12 diff --git a/src/crypter.cpp b/src/crypter.cpp index 74666e78ee42..d65a4cea06fc 100644 --- a/src/crypter.cpp +++ b/src/crypter.cpp @@ -408,7 +408,7 @@ bool CCryptoKeyStore::GetDeterministicSeed(const uint256& hashSeed, uint256& see std::vector vchCryptedSeed; //read encrypted seed if (db.ReadZPIVSeed(hashSeed, vchCryptedSeed)) { - uint256 seedRetrieved = uint256(ReverseEndianString(HexStr(vchCryptedSeed))); + uint256 seedRetrieved = uint256S(ReverseEndianString(HexStr(vchCryptedSeed))); //this checks if the hash of the seed we just read matches the hash given, meaning it is not encrypted //the use case for this is when not crypted, seed is set, then password set, the seed not yet crypted in memory if(hashSeed == Hash(seedRetrieved.begin(), seedRetrieved.end())) { @@ -419,7 +419,7 @@ bool CCryptoKeyStore::GetDeterministicSeed(const uint256& hashSeed, uint256& see CKeyingMaterial kmSeed; //attempt decrypt if (DecryptSecret(vMasterKey, vchCryptedSeed, hashSeed, kmSeed)) { - seedOut = uint256(ReverseEndianString(HexStr(kmSeed))); + seedOut = uint256S(ReverseEndianString(HexStr(kmSeed))); return true; } strErr = "decrypt seed"; @@ -429,7 +429,7 @@ bool CCryptoKeyStore::GetDeterministicSeed(const uint256& hashSeed, uint256& see std::vector vchSeed; // wallet not crypted if (db.ReadZPIVSeed(hashSeed, vchSeed)) { - seedOut = uint256(ReverseEndianString(HexStr(vchSeed))); + seedOut = uint256S(ReverseEndianString(HexStr(vchSeed))); return true; } strErr = "read seed from wallet"; diff --git a/src/invalid.cpp b/src/invalid.cpp index 36268ac8fa56..08b33ea98687 100644 --- a/src/invalid.cpp +++ b/src/invalid.cpp @@ -37,7 +37,7 @@ namespace invalid_out if (!vTxid.isStr()) return false; - uint256 txid = uint256(vTxid.get_str()); + uint256 txid = uint256S(vTxid.get_str()); if (txid.IsNull()) return false; diff --git a/src/qt/proposalframe.cpp b/src/qt/proposalframe.cpp index d69783cf2234..9f7e462ad881 100644 --- a/src/qt/proposalframe.cpp +++ b/src/qt/proposalframe.cpp @@ -265,7 +265,7 @@ void ProposalFrame::voteButton_clicked(int nVote) void ProposalFrame::SendVote(std::string strHash, int nVote) { - uint256 hash = uint256(strHash); + uint256 hash = uint256S(strHash); int failed = 0, success = 0; std::string mnresult; for (CMasternodeConfig::CMasternodeEntry mne : masternodeConfig.getEntries()) { diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index d6c7974bf28a..67ea8bdab8d1 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -534,7 +534,7 @@ UniValue getblock(const UniValue& params, bool fHelp) LOCK(cs_main); std::string strHash = params[0].get_str(); - uint256 hash(strHash); + uint256 hash(uint256S(strHash)); bool fVerbose = true; if (params.size() > 1) @@ -590,7 +590,7 @@ UniValue getblockheader(const UniValue& params, bool fHelp) HelpExampleRpc("getblockheader", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"")); std::string strHash = params[0].get_str(); - uint256 hash(strHash); + uint256 hash(uint256S(strHash)); bool fVerbose = true; if (params.size() > 1) @@ -695,7 +695,7 @@ UniValue gettxout(const UniValue& params, bool fHelp) UniValue ret(UniValue::VOBJ); std::string strHash = params[0].get_str(); - uint256 hash(strHash); + uint256 hash(uint256S(strHash)); int n = params[1].get_int(); bool fMempool = true; if (params.size() > 2) @@ -1029,7 +1029,7 @@ UniValue invalidateblock(const UniValue& params, bool fHelp) HelpExampleCli("invalidateblock", "\"blockhash\"") + HelpExampleRpc("invalidateblock", "\"blockhash\"")); std::string strHash = params[0].get_str(); - uint256 hash(strHash); + uint256 hash(uint256S(strHash)); CValidationState state; { @@ -1067,7 +1067,7 @@ UniValue reconsiderblock(const UniValue& params, bool fHelp) HelpExampleCli("reconsiderblock", "\"blockhash\"") + HelpExampleRpc("reconsiderblock", "\"blockhash\"")); std::string strHash = params[0].get_str(); - uint256 hash(strHash); + uint256 hash(uint256S(strHash)); CValidationState state; { diff --git a/src/rpc/budget.cpp b/src/rpc/budget.cpp index 14fabe05704f..14497b67ce00 100644 --- a/src/rpc/budget.cpp +++ b/src/rpc/budget.cpp @@ -778,7 +778,7 @@ UniValue mnfinalbudget(const UniValue& params, bool fHelp) throw std::runtime_error("Correct usage is 'mnfinalbudget vote-many BUDGET_HASH'"); std::string strHash = params[1].get_str(); - uint256 hash(strHash); + uint256 hash(uint256S(strHash)); int success = 0; int failed = 0; @@ -849,7 +849,7 @@ UniValue mnfinalbudget(const UniValue& params, bool fHelp) throw std::runtime_error("Correct usage is 'mnfinalbudget vote BUDGET_HASH'"); std::string strHash = params[1].get_str(); - uint256 hash(strHash); + uint256 hash(uint256S(strHash)); CPubKey pubKeyMasternode; CKey keyMasternode; @@ -906,7 +906,7 @@ UniValue mnfinalbudget(const UniValue& params, bool fHelp) throw std::runtime_error("Correct usage is 'mnbudget getvotes budget-hash'"); std::string strHash = params[1].get_str(); - uint256 hash(strHash); + uint256 hash(uint256S(strHash)); UniValue obj(UniValue::VOBJ); diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 4b8d85683742..e425985078cc 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -259,7 +259,7 @@ bool StartMasternodeEntry(UniValue& statusObjRet, CMasternodeBroadcast& mnbRet, return false; } - CTxIn vin = CTxIn(uint256(mne.getTxHash()), uint32_t(nIndex)); + CTxIn vin = CTxIn(uint256S(mne.getTxHash()), uint32_t(nIndex)); CMasternode* pmn = mnodeman.Find(vin); if (pmn != NULL) { if (strCommand == "missing") return false; @@ -533,7 +533,7 @@ UniValue listmasternodeconf (const UniValue& params, bool fHelp) int nIndex; if(!mne.castOutputIndex(nIndex)) continue; - CTxIn vin = CTxIn(uint256(mne.getTxHash()), uint32_t(nIndex)); + CTxIn vin = CTxIn(uint256S(mne.getTxHash()), uint32_t(nIndex)); CMasternode* pmn = mnodeman.Find(vin); std::string strStatus = pmn ? pmn->Status() : "MISSING"; diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 0adee682f1a3..a44ee2cdf51c 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -958,7 +958,7 @@ UniValue createrawzerocoinspend(const UniValue& params, bool fHelp) EnsureWalletIsUnlocked(); LOCK2(cs_main, pwalletMain->cs_wallet); - uint256 hashSerial(serial_hash); + uint256 hashSerial(uint256S(serial_hash)); CZerocoinMint input_mint; if (!pwalletMain->GetMint(hashSerial, input_mint)) { std::string strErr = "Failed to fetch mint associated with serial hash " + serial_hash; diff --git a/src/test/Checkpoints_tests.cpp b/src/test/Checkpoints_tests.cpp index 44930a96be41..3cc7df2aa95e 100644 --- a/src/test/Checkpoints_tests.cpp +++ b/src/test/Checkpoints_tests.cpp @@ -19,8 +19,8 @@ BOOST_FIXTURE_TEST_SUITE(Checkpoints_tests, BasicTestingSetup) BOOST_AUTO_TEST_CASE(sanity) { - uint256 p259201 = uint256("0x1c9121bf9329a6234bfd1ea2d91515f19cd96990725265253f4b164283ade5dd"); - uint256 p623933 = uint256("0xc7aafa648a0f1450157dc93bd4d7448913a85b7448f803b4ab970d91fc2a7da7"); + uint256 p259201 = uint256S("0x1c9121bf9329a6234bfd1ea2d91515f19cd96990725265253f4b164283ade5dd"); + uint256 p623933 = uint256S("0xc7aafa648a0f1450157dc93bd4d7448913a85b7448f803b4ab970d91fc2a7da7"); BOOST_CHECK(Checkpoints::CheckBlock(259201, p259201)); BOOST_CHECK(Checkpoints::CheckBlock(623933, p623933)); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5f17fc4d7b48..4246a24d9199 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -767,7 +767,7 @@ UniValue rawdelegatestake(const UniValue& params, bool fHelp) CreateColdStakeDelegation(params, wtx, reservekey); UniValue result(UniValue::VOBJ); - TxToUniv(wtx, 0, result); + TxToUniv(wtx, UINT256_ZERO, result); return result; } @@ -2585,7 +2585,7 @@ UniValue lockunspent(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive"); } - const COutPoint outpt(uint256(txid), nOutput); + const COutPoint outpt(uint256S(txid), nOutput); const auto it = pwalletMain->mapWallet.find(outpt.hash); if (it == pwalletMain->mapWallet.end()) { @@ -3220,7 +3220,7 @@ UniValue listmintedzerocoins(const UniValue& params, bool fHelp) objMint.push_back(Pair("mint height", m.nHeight)); // Mint Height int nConfirmations = (m.nHeight && nBestHeight > m.nHeight) ? nBestHeight - m.nHeight : 0; objMint.push_back(Pair("confirmations", nConfirmations)); // Confirmations - if (m.hashStake == 0) { + if (m.hashStake.IsNull()) { CZerocoinMint mint; if (pwalletMain->GetMint(m.hashSerial, mint)) { uint256 hashStake = mint.GetSerialNumber().getuint256(); @@ -3408,7 +3408,7 @@ UniValue mintzerocoin(const UniValue& params, bool fHelp) if (nOutput < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive"); - COutPoint outpt(uint256(txid), nOutput); + COutPoint outpt(uint256S(txid), nOutput); vOutpts.push_back(outpt); } strError = pwalletMain->MintZerocoinFromOutPoint(nAmount, wtx, vDMints, vOutpts); @@ -3547,7 +3547,7 @@ UniValue spendzerocoinmints(const UniValue& params, bool fHelp) std::string serialHashStr = arrMints[i].get_str(); if (!IsHex(serialHashStr)) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected hex serial hash"); - vSerialHashes.push_back(uint256(serialHashStr)); + vSerialHashes.push_back(uint256S(serialHashStr)); } // fetch mints and update nAmount @@ -3940,7 +3940,7 @@ UniValue importzerocoins(const UniValue& params, bool fHelp) bnSerial.SetHex(find_value(o, "s").get_str()); CBigNum bnRandom = 0; bnRandom.SetHex(find_value(o, "r").get_str()); - uint256 txid(find_value(o, "t").get_str()); + uint256 txid(uint256S(find_value(o, "t").get_str())); int nHeight = find_value(o, "h").get_int(); if (nHeight < 0)