From 216a3174affd4ba1ae7817af258d29ff722c7335 Mon Sep 17 00:00:00 2001 From: furszy Date: Mon, 20 May 2019 10:49:21 +0200 Subject: [PATCH] [zPIV] testnet publicSpend enforcement height set. [zPIV] v1 serials validation was not checked against the publicSpend height. --- src/chainparams.cpp | 2 +- src/main.cpp | 21 ++++++++++++--------- src/main.h | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 8e337eff4296f..39b9feff37fc5 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -298,7 +298,7 @@ class CTestNetParams : public CMainParams nRejectOldSporkKey = 1522454400; //!> Reject old spork key after Saturday, March 31, 2018 12:00:00 AM GMT // Public coin spend enforcement - nPublicZCSpends = 1086574; + nPublicZCSpends = 1818300; // Fake Serial Attack nFakeSerialBlockheightEnd = -1; diff --git a/src/main.cpp b/src/main.cpp index 0f0256238b2b8..3494cdfdd86ee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -988,10 +988,10 @@ bool isBlockBetweenFakeSerialAttackRange(int nHeight) return nHeight <= Params().Zerocoin_Block_EndFakeSerial(); } -bool CheckPublicCoinSpendEnforced(int blockHeight, bool isPrivZerocoinSpend, bool isPublicSpend) { +bool CheckPublicCoinSpendEnforced(int blockHeight, bool isPublicSpend) { if (blockHeight >= Params().Zerocoin_Block_Public_Spend_Enabled()) { // reject old coin spend - if (isPrivZerocoinSpend) { + if (!isPublicSpend) { return error("%s: failed to add block with older zc spend version", __func__); } @@ -1042,11 +1042,14 @@ bool ContextualCheckZerocoinSpendNoSerialCheck(const CTransaction& tx, const Coi } } - //Reject V1 old serials. - if (spend->getVersion() < libzerocoin::PrivateCoin::PUBKEY_VERSION) { - return error("%s : zPIV v1 serial spend not spendable\n", __func__, - spend->getCoinSerialNumber().GetHex(), tx.GetHash().GetHex()); + if (pindex->nHeight >= Params().Zerocoin_Block_Public_Spend_Enabled()) { + //Reject V1 old serials. + if (spend->getVersion() < libzerocoin::PrivateCoin::PUBKEY_VERSION) { + return error("%s : zPIV v1 serial spend not spendable, serial %s, tx %s\n", __func__, + spend->getCoinSerialNumber().GetHex(), tx.GetHash().GetHex()); + } } + //Reject serial's that are not in the acceptable value range if (!spend->HasValidSerial(Params().Zerocoin_Params(false))) { // Up until this block our chain was not checking serials correctly.. @@ -1416,7 +1419,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa } // Check enforcement - if (!CheckPublicCoinSpendEnforced(chainActive.Height(), isPrivZerocoinSpend, isPublicSpend)){ + if (!CheckPublicCoinSpendEnforced(chainActive.Height(), isPublicSpend)){ return state.Invalid(error("%s: AcceptToMemoryPool failed for tx %s", __func__, tx.GetHash().GetHex()), REJECT_INVALID, "bad-txns-invalid-zpiv"); } @@ -3250,7 +3253,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin continue; // Check enforcement - if (!CheckPublicCoinSpendEnforced(pindex->nHeight, isPrivZerocoinSpend, isPublicSpend)){ + if (!CheckPublicCoinSpendEnforced(pindex->nHeight, isPublicSpend)){ return false; } @@ -4811,7 +4814,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, if (isPrivZerocoinSpend || isPublicSpend) { // Check enforcement - if (!CheckPublicCoinSpendEnforced(pindex->nHeight, isPrivZerocoinSpend, isPublicSpend)){ + if (!CheckPublicCoinSpendEnforced(pindex->nHeight, isPublicSpend)){ return false; } diff --git a/src/main.h b/src/main.h index 4a0f540f383f9..8322998647aa4 100644 --- a/src/main.h +++ b/src/main.h @@ -374,7 +374,7 @@ bool ReindexAccumulators(list& listMissingCheckpoints, string& strError bool isBlockBetweenFakeSerialAttackRange(int nHeight); // Public coin spend -bool CheckPublicCoinSpendEnforced(int blockHeight, bool isPrivZerocoinSpend, bool isPublicSpend); +bool CheckPublicCoinSpendEnforced(int blockHeight, bool isPublicSpend); /** * Check if transaction will be final in the next block to be created.