PIVX Core  5.6.99
P2P Digital Currency
validation_zerocoin_legacy.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020-2021 The PIVX Core developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or https://www.opensource.org/licenses/mit-license.php.
5 
7 #include "wallet/wallet.h"
8 #include "zpiv/zpivmodule.h"
9 
11 {
16  if (tx.ContainsZerocoins()) {
18  if (tx.HasZerocoinSpendInputs()) {
19  //erase all zerocoinspends in this transaction
20  for (const CTxIn &txin : tx.vin) {
21  bool isPublicSpend = txin.IsZerocoinPublicSpend();
22  if (txin.scriptSig.IsZerocoinSpend() || isPublicSpend) {
23  CBigNum serial;
24  if (isPublicSpend) {
25  PublicCoinSpend publicSpend(params);
26  CValidationState state;
27  if (!ZPIVModule::ParseZerocoinPublicSpend(txin, tx, state, publicSpend)) {
28  return error("Failed to parse public spend");
29  }
30  serial = publicSpend.getCoinSerialNumber();
31  } else {
33  serial = spend.getCoinSerialNumber();
34  }
35 
36  if (!zerocoinDB->EraseCoinSpend(serial))
37  return error("failed to erase spent zerocoin in block");
38  }
39 
40  }
41  }
42  }
43  return true;
44 }
45 
46 // Legacy Zerocoin DB: used for performance during IBD
47 // (between Zerocoin_Block_V2_Start and Zerocoin_Block_Last_Checkpoint)
48 void CacheAccChecksum(const CBlockIndex* pindex, bool fWrite)
49 {
50  const Consensus::Params& consensus = Params().GetConsensus();
51  if (!pindex || accumulatorCache == nullptr ||
53  pindex->nHeight > consensus.height_last_ZC_AccumCheckpoint ||
55  return;
56 
59  // add/remove changed checksums to/from cache
60  for (int i = (int)libzerocoin::zerocoinDenomList.size()-1; i >= 0; i--) {
61  const uint32_t nChecksum = accCurr.Get32();
62  if (nChecksum != accPrev.Get32()) {
63  fWrite ?
64  accumulatorCache->Set(nChecksum, libzerocoin::zerocoinDenomList[i], pindex->nHeight) :
66  }
67  accCurr >>= 32;
68  accPrev >>= 32;
69  }
70 }
CoinSpend class for the Zerocoin library.
arith_uint256 UintToArith256(const uint256 &a)
const CChainParams & Params()
Return the currently selected parameters.
C++ wrapper for BIGNUM.
Definition: bignum.h:35
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:139
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: chain.h:145
uint256 nAccumulatorCheckpoint
Definition: chain.h:199
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:151
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:72
bool IsZerocoinSpend() const
Definition: script.cpp:275
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:244
bool HasZerocoinSpendInputs() const
std::vector< CTxIn > vin
Definition: transaction.h:270
bool ContainsZerocoins() const
Definition: transaction.h:371
An input of a transaction.
Definition: transaction.h:94
bool IsZerocoinPublicSpend() const
Definition: transaction.cpp:48
CScript scriptSig
Definition: transaction.h:97
Capture information about block/transaction validation.
Definition: validation.h:24
256-bit unsigned big integer.
uint32_t Get32(int n=0) const
The complete proof needed to spend a zerocoin.
Definition: CoinSpend.h:79
const CBigNum & getCoinSerialNumber() const
Definition: CoinSpend.h:86
@ UPGRADE_ZC_V2
Definition: params.h:31
libzerocoin::CoinSpend TxInToZerocoinSpend(const CTxIn &txin)
Definition: zpivmodule.cpp:191
bool ParseZerocoinPublicSpend(const CTxIn &txIn, const CTransaction &tx, CValidationState &state, PublicCoinSpend &publicSpend)
Definition: zpivmodule.cpp:212
const std::vector< CoinDenomination > zerocoinDenomList
Definition: Denominations.h:27
Parameters that influence chain consensus.
Definition: params.h:171
libzerocoin::ZerocoinParams * Zerocoin_Params(bool useModulusV1) const
Definition: params.h:260
int height_last_ZC_AccumCheckpoint
Definition: params.h:205
bool NetworkUpgradeActive(int nHeight, Consensus::UpgradeIndex idx) const
Returns true if the given network upgrade is active as of the given block height.
Definition: params.cpp:12
bool error(const char *fmt, const Args &... args)
Definition: system.h:77
std::unique_ptr< CZerocoinDB > zerocoinDB
Global variable that points to the zerocoin database (protected by cs_main)
Definition: validation.cpp:208
std::unique_ptr< AccumulatorCache > accumulatorCache
In-memory cache for the zerocoin accumulators.
Definition: validation.cpp:210
void CacheAccChecksum(const CBlockIndex *pindex, bool fWrite)
bool DisconnectZerocoinTx(const CTransaction &tx)