LCOV - code coverage report
Current view: top level - src/legacy - validation_zerocoin_legacy.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 9 35 25.7 %
Date: 2025-02-23 09:33:43 Functions: 2 2 100.0 %

          Line data    Source code
       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.
       4             : #include "legacy/validation_zerocoin_legacy.h"
       5             : 
       6             : #include "libzerocoin/CoinSpend.h"
       7             : #include "wallet/wallet.h"
       8             : #include "zpiv/zpivmodule.h"
       9             : 
      10      111345 : bool DisconnectZerocoinTx(const CTransaction& tx)
      11             : {
      12             :     /** UNDO ZEROCOIN DATABASING
      13             :          * note we only undo zerocoin databasing in the following statement, value to and from PIVX
      14             :          * addresses should still be handled by the typical bitcoin based undo code
      15             :          * */
      16      111345 :     if (tx.ContainsZerocoins()) {
      17           0 :         libzerocoin::ZerocoinParams *params = Params().GetConsensus().Zerocoin_Params(false);
      18           0 :         if (tx.HasZerocoinSpendInputs()) {
      19             :             //erase all zerocoinspends in this transaction
      20           0 :             for (const CTxIn &txin : tx.vin) {
      21           0 :                 bool isPublicSpend = txin.IsZerocoinPublicSpend();
      22           0 :                 if (txin.scriptSig.IsZerocoinSpend() || isPublicSpend) {
      23           0 :                     CBigNum serial;
      24           0 :                     if (isPublicSpend) {
      25           0 :                         PublicCoinSpend publicSpend(params);
      26           0 :                         CValidationState state;
      27           0 :                         if (!ZPIVModule::ParseZerocoinPublicSpend(txin, tx, state, publicSpend)) {
      28           0 :                             return error("Failed to parse public spend");
      29             :                         }
      30           0 :                         serial = publicSpend.getCoinSerialNumber();
      31             :                     } else {
      32           0 :                         libzerocoin::CoinSpend spend = ZPIVModule::TxInToZerocoinSpend(txin);
      33           0 :                         serial = spend.getCoinSerialNumber();
      34             :                     }
      35             : 
      36           0 :                     if (!zerocoinDB->EraseCoinSpend(serial))
      37           0 :                         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         248 : void CacheAccChecksum(const CBlockIndex* pindex, bool fWrite)
      49             : {
      50         248 :     const Consensus::Params& consensus = Params().GetConsensus();
      51         476 :     if (!pindex || accumulatorCache == nullptr ||
      52         228 :         !consensus.NetworkUpgradeActive(pindex->nHeight, Consensus::UPGRADE_ZC_V2) ||
      53         476 :         pindex->nHeight > consensus.height_last_ZC_AccumCheckpoint ||
      54         228 :         pindex->nAccumulatorCheckpoint == pindex->pprev->nAccumulatorCheckpoint)
      55         248 :         return;
      56             : 
      57           0 :     arith_uint256 accCurr = UintToArith256(pindex->nAccumulatorCheckpoint);
      58           0 :     arith_uint256 accPrev = UintToArith256(pindex->pprev->nAccumulatorCheckpoint);
      59             :     // add/remove changed checksums to/from cache
      60           0 :     for (int i = (int)libzerocoin::zerocoinDenomList.size()-1; i >= 0; i--) {
      61           0 :         const uint32_t nChecksum = accCurr.Get32();
      62           0 :         if (nChecksum != accPrev.Get32()) {
      63           0 :             fWrite ?
      64           0 :             accumulatorCache->Set(nChecksum, libzerocoin::zerocoinDenomList[i], pindex->nHeight) :
      65           0 :             accumulatorCache->Erase(nChecksum, libzerocoin::zerocoinDenomList[i]);
      66             :         }
      67           0 :         accCurr >>= 32;
      68           0 :         accPrev >>= 32;
      69             :     }
      70             : }

Generated by: LCOV version 1.14