@@ -988,6 +988,21 @@ bool isBlockBetweenFakeSerialAttackRange(int nHeight)
988988 return nHeight <= Params ().Zerocoin_Block_EndFakeSerial ();
989989}
990990
991+ bool CheckPublicCoinSpendEnforced (int blockHeight, bool isPrivZerocoinSpend, bool isPublicSpend) {
992+ if (blockHeight >= Params ().Zerocoin_Block_Public_Spend_Enabled ()) {
993+ // reject old coin spend
994+ if (isPrivZerocoinSpend) {
995+ return error (" %s: failed to add block with older zc spend version" , __func__);
996+ }
997+
998+ } else {
999+ if (isPublicSpend) {
1000+ return error (" %s: failed to add block, public spend enforcement not activated" , __func__);
1001+ }
1002+ }
1003+ return true ;
1004+ }
1005+
9911006bool ContextualCheckZerocoinSpend (const CTransaction& tx, const CoinSpend* spend, CBlockIndex* pindex, const uint256& hashBlock)
9921007{
9931008 if (!ContextualCheckZerocoinSpendNoSerialCheck (tx, spend, pindex, hashBlock)){
@@ -3209,9 +3224,14 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
32093224 set<CBigNum> setSerials;
32103225 for (const CTxIn& txIn : tx.vin ) {
32113226 bool isPublicSpend = txIn.scriptSig .IsZerocoinPublicSpend ();
3212- if (!txIn.IsZerocoinSpend () && !isPublicSpend)
3227+ bool isPrivZerocoinSpend = txIn.IsZerocoinSpend ();
3228+ if (!isPrivZerocoinSpend && !isPublicSpend)
32133229 continue ;
32143230
3231+ // Check enforcement
3232+ if (!CheckPublicCoinSpendEnforced (pindex->nHeight , isPrivZerocoinSpend, isPublicSpend)){
3233+ return false ;
3234+ }
32153235
32163236 if (isPublicSpend) {
32173237 libzerocoin::ZerocoinParams* params = Params ().Zerocoin_Params (false );
@@ -4766,7 +4786,14 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
47664786 for (const CTxIn& in: tx.vin ) {
47674787 if (nHeight >= Params ().Zerocoin_StartHeight ()) {
47684788 bool isPublicSpend = in.scriptSig .IsZerocoinPublicSpend ();
4769- if (in.IsZerocoinSpend () || isPublicSpend) {
4789+ bool isPrivZerocoinSpend = in.IsZerocoinSpend ();
4790+ if (isPrivZerocoinSpend || isPublicSpend) {
4791+
4792+ // Check enforcement
4793+ if (!CheckPublicCoinSpendEnforced (pindex->nHeight , isPrivZerocoinSpend, isPublicSpend)){
4794+ return false ;
4795+ }
4796+
47704797 libzerocoin::CoinSpend spend;
47714798 if (isPublicSpend) {
47724799 libzerocoin::ZerocoinParams* params = Params ().Zerocoin_Params (false );
0 commit comments