@@ -1009,8 +1009,12 @@ bool CheckPublicCoinSpendEnforced(int blockHeight, bool isPublicSpend) {
10091009 return true ;
10101010}
10111011
1012- bool CheckPublicCoinSpendVersion (int blockHeight, int version) {
1013- return version >= Params ().Zerocoin_PublicSpendVersion (blockHeight);
1012+ int CurrentPublicCoinSpendVersion () {
1013+ return sporkManager.IsSporkActive (SPORK_18_ZEROCOIN_PUBLICSPEND_V4) ? 4 : 3 ;
1014+ }
1015+
1016+ bool CheckPublicCoinSpendVersion (int version) {
1017+ return version == CurrentPublicCoinSpendVersion ();
10141018}
10151019
10161020bool ContextualCheckZerocoinSpend (const CTransaction& tx, const libzerocoin::CoinSpend* spend, CBlockIndex* pindex, const uint256& hashBlock)
@@ -1052,12 +1056,6 @@ bool ContextualCheckZerocoinSpendNoSerialCheck(const CTransaction& tx, const lib
10521056 }
10531057 }
10541058
1055- // Check spend version
1056- if (pindex->nHeight >= Params ().Zerocoin_Block_Public_Spend_Enabled () &&
1057- !CheckPublicCoinSpendVersion (pindex->nHeight , (int )spend->getVersion ())) {
1058- return error (" %s: Invalid public spend version for tx %s" , __func__, tx.GetHash ().GetHex ());
1059- }
1060-
10611059 bool fUseV1Params = spend->getCoinVersion () < libzerocoin::PrivateCoin::PUBKEY_VERSION;
10621060
10631061 // Reject serial's that are not in the acceptable value range
@@ -1453,6 +1451,13 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa
14531451 if (!ContextualCheckZerocoinSpend (tx, &publicSpend, chainActive.Tip (), 0 ))
14541452 return state.Invalid (error (" %s: ContextualCheckZerocoinSpend failed for tx %s" ,
14551453 __func__, tx.GetHash ().GetHex ()), REJECT_INVALID, " bad-txns-invalid-zpiv" );
1454+
1455+ // Check that the version matches the one enforced with SPORK_18
1456+ if (!CheckPublicCoinSpendVersion (publicSpend.getVersion ())) {
1457+ return state.Invalid (error (" %s : Public Zerocoin spend version %d not accepted. must be version %d." ,
1458+ __func__, publicSpend.getVersion (), CurrentPublicCoinSpendVersion ()), REJECT_INVALID, " bad-txns-invalid-zpiv" );
1459+ }
1460+
14561461 } else {
14571462 libzerocoin::CoinSpend spend = TxInToZerocoinSpend (txIn);
14581463 if (!ContextualCheckZerocoinSpend (tx, &spend, chainActive.Tip (), 0 ))
@@ -4571,6 +4576,11 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
45714576 return false ;
45724577 }
45734578 spend = publicSpend;
4579+ // check that the version matches the one enforced with SPORK_18 (don't ban if it fails)
4580+ if (!IsInitialBlockDownload () && !CheckPublicCoinSpendVersion (spend.getVersion ())) {
4581+ return state.DoS (0 , error (" %s : Public Zerocoin spend version %d not accepted. must be version %d." ,
4582+ __func__, spend.getVersion (), CurrentPublicCoinSpendVersion ()), REJECT_INVALID, " bad-zcspend-version" );
4583+ }
45744584 } else {
45754585 spend = TxInToZerocoinSpend (txIn);
45764586 }
0 commit comments