From c25df3bc91ca8268371cd880f110baec8588a123 Mon Sep 17 00:00:00 2001 From: furszy Date: Tue, 1 Jun 2021 23:43:19 -0300 Subject: [PATCH 1/3] [Cleanup] Remove unused CLegacyBlockIndex --- src/chain.h | 92 ---------------------------------------------------- src/txdb.cpp | 5 --- src/txdb.h | 1 - 3 files changed, 98 deletions(-) diff --git a/src/chain.h b/src/chain.h index fd16e8e5f68c..8a3e8ef6de38 100644 --- a/src/chain.h +++ b/src/chain.h @@ -402,98 +402,6 @@ class CDiskBlockIndex : public CBlockIndex } }; -/** Legacy block index - used to retrieve old serializations */ - -class CLegacyBlockIndex : public CBlockIndex -{ -public: - std::map mapZerocoinSupply{}; - int64_t nMint = 0; - uint256 hashNext{}; - uint256 hashPrev{}; - uint64_t nStakeModifier = 0; - uint256 nStakeModifierV2{}; - COutPoint prevoutStake{}; - unsigned int nStakeTime = 0; - std::vector vMintDenominationsInBlock; - int64_t nMoneySupply = 0; - - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action) - { - int nSerVersion = s.GetVersion(); - if (!(s.GetType() & SER_GETHASH)) - READWRITE(VARINT(nSerVersion, VarIntMode::NONNEGATIVE_SIGNED)); - - if (nSerVersion >= DBI_SER_VERSION_NO_ZC) { - // no extra serialized field - return; - } - - if (!ser_action.ForRead()) { - // legacy block index shouldn't be used to write - return; - } - - READWRITE(VARINT(nHeight, VarIntMode::NONNEGATIVE_SIGNED)); - READWRITE(VARINT(nStatus)); - READWRITE(VARINT(nTx)); - if (nStatus & (BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO)) - READWRITE(VARINT(nFile, VarIntMode::NONNEGATIVE_SIGNED)); - if (nStatus & BLOCK_HAVE_DATA) - READWRITE(VARINT(nDataPos)); - if (nStatus & BLOCK_HAVE_UNDO) - READWRITE(VARINT(nUndoPos)); - - if (nSerVersion > DBI_OLD_SER_VERSION) { - // Serialization with CLIENT_VERSION = 4009901 - READWRITE(nMoneySupply); - READWRITE(nFlags); - READWRITE(this->nVersion); - READWRITE(vStakeModifier); - READWRITE(hashPrev); - READWRITE(hashMerkleRoot); - READWRITE(nTime); - READWRITE(nBits); - READWRITE(nNonce); - if(this->nVersion > 3) { - READWRITE(mapZerocoinSupply); - if(this->nVersion < 7) READWRITE(nAccumulatorCheckpoint); - } - - } else { - // Serialization with CLIENT_VERSION = 4009900- - READWRITE(nMint); - READWRITE(nMoneySupply); - READWRITE(nFlags); - if (!Params().GetConsensus().NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_4)) { - READWRITE(nStakeModifier); - } else { - READWRITE(nStakeModifierV2); - } - if (IsProofOfStake()) { - READWRITE(prevoutStake); - READWRITE(nStakeTime); - } - READWRITE(this->nVersion); - READWRITE(hashPrev); - READWRITE(hashNext); - READWRITE(hashMerkleRoot); - READWRITE(nTime); - READWRITE(nBits); - READWRITE(nNonce); - if(this->nVersion > 3) { - READWRITE(nAccumulatorCheckpoint); - READWRITE(mapZerocoinSupply); - READWRITE(vMintDenominationsInBlock); - } - } - } -}; - /** An in-memory indexed chain of blocks. */ class CChain { diff --git a/src/txdb.cpp b/src/txdb.cpp index 42c45ffcc3dd..335ed6adbdeb 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -352,11 +352,6 @@ bool CBlockTreeDB::LoadBlockIndexGuts(std::function insertBlockIndex); - bool ReadLegacyBlockIndex(const uint256& blockHash, CLegacyBlockIndex& biRet); }; /** Zerocoin database (zerocoin/) */ From c268786b3e5af10d539bff6a34475f07549e5dfe Mon Sep 17 00:00:00 2001 From: furszy Date: Tue, 1 Jun 2021 23:47:13 -0300 Subject: [PATCH 2/3] [Cleanup] txdb: remove old zerocoin unused ReadCoinSpend, WipeCoins, WriteZCSupply and ReadZCSupply --- src/rpc/misc.cpp | 3 --- src/txdb.cpp | 53 +----------------------------------------------- src/txdb.h | 5 ----- 3 files changed, 1 insertion(+), 60 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index be05569e0625..0e498e62a62e 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -226,9 +226,6 @@ UniValue mnsync(const JSONRPCRequest& request) #ifdef ENABLE_WALLET class DescribeAddressVisitor : public boost::static_visitor { -private: - isminetype mine; - public: CWallet * const pwallet; diff --git a/src/txdb.cpp b/src/txdb.cpp index 335ed6adbdeb..5b894ce5b59a 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -382,11 +382,6 @@ bool CZerocoinDB::ReadCoinSpend(const CBigNum& bnSerial, uint256& txHash) return Read(std::make_pair('s', hash), txHash); } -bool CZerocoinDB::ReadCoinSpend(const uint256& hashSerial, uint256 &txHash) -{ - return Read(std::make_pair('s', hashSerial), txHash); -} - bool CZerocoinDB::EraseCoinSpend(const CBigNum& bnSerial) { CDataStream ss(SER_GETHASH, 0); @@ -396,55 +391,9 @@ bool CZerocoinDB::EraseCoinSpend(const CBigNum& bnSerial) return Erase(std::make_pair('s', hash)); } -bool CZerocoinDB::WipeCoins(std::string strType) -{ - if (strType != "spends" && strType != "mints") - return error("%s: did not recognize type %s", __func__, strType); - - std::unique_ptr pcursor(NewIterator()); - - char type = (strType == "spends" ? 's' : 'm'); - pcursor->Seek(std::make_pair(type, UINT256_ZERO)); - // Load mapBlockIndex - std::set setDelete; - while (pcursor->Valid()) { - boost::this_thread::interruption_point(); - std::pair key; - if (pcursor->GetKey(key) && key.first == type) { - uint256 hash; - if (pcursor->GetValue(hash)) { - setDelete.insert(hash); - pcursor->Next(); - } else { - return error("%s : failed to read value", __func__); - } - } else { - break; - } - } - - for (auto& hash : setDelete) { - if (!Erase(std::make_pair(type, hash))) - LogPrintf("%s: error failed to delete %s\n", __func__, hash.GetHex()); - } - - return true; -} - - // Legacy Zerocoin Database static const char LZC_ACCUMCS = 'A'; -static const char LZC_MAPSUPPLY = 'M'; - -bool CZerocoinDB::WriteZCSupply(const std::map& mapZCS) -{ - return Write(LZC_MAPSUPPLY, mapZCS); -} - -bool CZerocoinDB::ReadZCSupply(std::map& mapZCS) const -{ - return Read(LZC_MAPSUPPLY, mapZCS); -} +//static const char LZC_MAPSUPPLY = 'M'; // TODO: add removal for LZC_MAPSUPPLY key-value if is found in db bool CZerocoinDB::WriteAccChecksum(const uint32_t& nChecksum, const libzerocoin::CoinDenomination denom, const int nHeight) { diff --git a/src/txdb.h b/src/txdb.h index f81cab9c5495..459c0f2f23fe 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -158,13 +158,8 @@ class CZerocoinDB : public CDBWrapper /** Write zPIV spends to the zerocoinDB in a batch */ bool WriteCoinSpendBatch(const std::vector >& spendInfo); bool ReadCoinSpend(const CBigNum& bnSerial, uint256& txHash); - bool ReadCoinSpend(const uint256& hashSerial, uint256 &txHash); bool EraseCoinSpend(const CBigNum& bnSerial); - bool WipeCoins(std::string strType); - /** Map supply [denom] --> supply */ - bool WriteZCSupply(const std::map& mapZCS); - bool ReadZCSupply(std::map& mapZCS) const; /** Accumulators (only for zPoS IBD): [checksum, denom] --> block height **/ bool WriteAccChecksum(const uint32_t& nChecksum, const libzerocoin::CoinDenomination denom, const int nHeight); bool ReadAccChecksum(const uint32_t& nChecksum, const libzerocoin::CoinDenomination denom, int& nHeightRet); From 749f17ff84929e0a85753592b4577534c771f283 Mon Sep 17 00:00:00 2001 From: furszy Date: Tue, 1 Jun 2021 23:51:56 -0300 Subject: [PATCH 3/3] [Cleanup] sapling: remove unneeded proof.h/cpp files. --- CMakeLists.txt | 1 - src/Makefile.am | 2 - src/sapling/proof.cpp | 13 -- src/sapling/proof.h | 246 ------------------------------ src/sapling/sapling_transaction.h | 1 - 5 files changed, 263 deletions(-) delete mode 100644 src/sapling/proof.cpp delete mode 100644 src/sapling/proof.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ccff3d1251e..daa629cf7582 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -451,7 +451,6 @@ set(SAPLING_SOURCES ./src/sapling/incrementalmerkletree.cpp ./src/sapling/transaction_builder.cpp ./src/sapling/saplingscriptpubkeyman.cpp - ./src/sapling/proof.cpp ./src/sapling/sapling_operation.cpp ) diff --git a/src/Makefile.am b/src/Makefile.am index ad88a3e7e537..7f2d2b1a2ab0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -137,7 +137,6 @@ LIBSAPLING_H = \ sapling/zip32.h \ sapling/saplingscriptpubkeyman.h \ sapling/incrementalmerkletree.h \ - sapling/proof.h \ sapling/sapling_transaction.h \ sapling/transaction_builder.h \ sapling/sapling_operation.h @@ -577,7 +576,6 @@ libsapling_a_SOURCES = \ sapling/crypter_sapling.cpp \ sapling/saplingscriptpubkeyman.cpp \ sapling/incrementalmerkletree.cpp \ - sapling/proof.cpp \ sapling/transaction_builder.cpp \ sapling/sapling_operation.cpp diff --git a/src/sapling/proof.cpp b/src/sapling/proof.cpp deleted file mode 100644 index 04db5a947722..000000000000 --- a/src/sapling/proof.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "sapling/proof.h" - -namespace libzcash { - -ProofVerifier ProofVerifier::Strict() { - return ProofVerifier(true); -} - -ProofVerifier ProofVerifier::Disabled() { - return ProofVerifier(false); -} - -} diff --git a/src/sapling/proof.h b/src/sapling/proof.h deleted file mode 100644 index 87a274f166bd..000000000000 --- a/src/sapling/proof.h +++ /dev/null @@ -1,246 +0,0 @@ -// Copyright (c) 2016-2020 The ZCash developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef ZC_PROOF_H_ -#define ZC_PROOF_H_ - -#include "serialize.h" -#include "uint256.h" - -namespace libzcash { - -const unsigned char G1_PREFIX_MASK = 0x02; -const unsigned char G2_PREFIX_MASK = 0x0a; - -// Element in the base field -class Fq { -private: - base_blob<256> data; -public: - Fq() : data() { } - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - READWRITE(data); - } - - friend bool operator==(const Fq& a, const Fq& b) - { - return ( - a.data == b.data - ); - } - - friend bool operator!=(const Fq& a, const Fq& b) - { - return !(a == b); - } -}; - -// Element in the extension field -class Fq2 { -private: - base_blob<512> data; -public: - Fq2() : data() { } - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - READWRITE(data); - } - - friend bool operator==(const Fq2& a, const Fq2& b) - { - return ( - a.data == b.data - ); - } - - friend bool operator!=(const Fq2& a, const Fq2& b) - { - return !(a == b); - } -}; - -// Compressed point in G1 -class CompressedG1 { -private: - bool y_lsb; - Fq x; - -public: - CompressedG1() : y_lsb(false), x() { } - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - unsigned char leadingByte = G1_PREFIX_MASK; - - if (y_lsb) { - leadingByte |= 1; - } - - READWRITE(leadingByte); - - if ((leadingByte & (~1)) != G1_PREFIX_MASK) { - throw std::ios_base::failure("lead byte of G1 point not recognized"); - } - - y_lsb = leadingByte & 1; - - READWRITE(x); - } - - friend bool operator==(const CompressedG1& a, const CompressedG1& b) - { - return ( - a.y_lsb == b.y_lsb && - a.x == b.x - ); - } - - friend bool operator!=(const CompressedG1& a, const CompressedG1& b) - { - return !(a == b); - } -}; - -// Compressed point in G2 -class CompressedG2 { -private: - bool y_gt; - Fq2 x; - -public: - CompressedG2() : y_gt(false), x() { } - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - unsigned char leadingByte = G2_PREFIX_MASK; - - if (y_gt) { - leadingByte |= 1; - } - - READWRITE(leadingByte); - - if ((leadingByte & (~1)) != G2_PREFIX_MASK) { - throw std::ios_base::failure("lead byte of G2 point not recognized"); - } - - y_gt = leadingByte & 1; - - READWRITE(x); - } - - friend bool operator==(const CompressedG2& a, const CompressedG2& b) - { - return ( - a.y_gt == b.y_gt && - a.x == b.x - ); - } - - friend bool operator!=(const CompressedG2& a, const CompressedG2& b) - { - return !(a == b); - } -}; - -// Compressed zkSNARK proof -class PHGRProof { -private: - CompressedG1 g_A; - CompressedG1 g_A_prime; - CompressedG2 g_B; - CompressedG1 g_B_prime; - CompressedG1 g_C; - CompressedG1 g_C_prime; - CompressedG1 g_K; - CompressedG1 g_H; - -public: - PHGRProof() : g_A(), g_A_prime(), g_B(), g_B_prime(), g_C(), g_C_prime(), g_K(), g_H() { } - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - READWRITE(g_A); - READWRITE(g_A_prime); - READWRITE(g_B); - READWRITE(g_B_prime); - READWRITE(g_C); - READWRITE(g_C_prime); - READWRITE(g_K); - READWRITE(g_H); - } - - friend bool operator==(const PHGRProof& a, const PHGRProof& b) - { - return ( - a.g_A == b.g_A && - a.g_A_prime == b.g_A_prime && - a.g_B == b.g_B && - a.g_B_prime == b.g_B_prime && - a.g_C == b.g_C && - a.g_C_prime == b.g_C_prime && - a.g_K == b.g_K && - a.g_H == b.g_H - ); - } - - friend bool operator!=(const PHGRProof& a, const PHGRProof& b) - { - return !(a == b); - } -}; - -void initialize_curve_params(); - -class ProofVerifier { -private: - bool perform_verification; - - ProofVerifier(bool perform_verification) : perform_verification(perform_verification) { } - -public: - // ProofVerifier should never be copied - ProofVerifier(const ProofVerifier&) = delete; - ProofVerifier& operator=(const ProofVerifier&) = delete; - ProofVerifier(ProofVerifier&&); - ProofVerifier& operator=(ProofVerifier&&); - - // Creates a verification context that strictly verifies - // all proofs using libsnark's API. - static ProofVerifier Strict(); - - // Creates a verification context that performs no - // verification, used when avoiding duplicate effort - // such as during reindexing. - static ProofVerifier Disabled(); - - template - bool check( - const VerificationKey& vk, - const ProcessedVerificationKey& pvk, - const PrimaryInput& pi, - const Proof& p - ); -}; - -} - -#endif // ZC_PROOF_H_ diff --git a/src/sapling/sapling_transaction.h b/src/sapling/sapling_transaction.h index a0d316165824..a12b7a57f017 100644 --- a/src/sapling/sapling_transaction.h +++ b/src/sapling/sapling_transaction.h @@ -13,7 +13,6 @@ #include "sapling/noteencryption.h" #include "sapling/sapling.h" -#include "sapling/proof.h" #include