Skip to content

Commit b943f2c

Browse files
committed
[Refactoring] Remove zerocoin disabling check in ATMP and CheckBlock
as we already checking it via ContextualCheckBlock --> ContextualCheckTransaction --> ContextualCheckZerocoinTx
1 parent f91e4df commit b943f2c

File tree

5 files changed

+18
-34
lines changed

5 files changed

+18
-34
lines changed

src/consensus/tx_verify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ bool ContextualCheckTransaction(const CTransactionRef& tx, CValidationState& sta
134134
}
135135

136136
// Dispatch to ZerocoinTx validator
137-
if (!ContextualCheckZerocoinTx(tx, state, chainparams.GetConsensus(), nHeight)) {
137+
if (!ContextualCheckZerocoinTx(tx, state, chainparams.GetConsensus(), nHeight, isMined)) {
138138
return false; // Failure reason has been set in validation state object
139139
}
140140

src/consensus/zerocoin_verify.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ bool CheckPublicCoinSpendEnforced(int blockHeight, bool isPublicSpend)
127127
return true;
128128
}
129129

130-
bool ContextualCheckZerocoinTx(const CTransactionRef& tx, CValidationState& state, const Consensus::Params& consensus, int nHeight)
130+
bool ContextualCheckZerocoinTx(const CTransactionRef& tx, CValidationState& state, const Consensus::Params& consensus, int nHeight, bool isMined)
131131
{
132132
// zerocoin enforced via block time. First block with a zc mint is 863735
133133
const bool fZerocoinEnforced = (nHeight >= consensus.ZC_HeightStart);
134134
const bool fPublicSpendEnforced = consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_ZC_PUBLIC);
135-
const bool fRejectMintsAndPrivateSpends = !fZerocoinEnforced || fPublicSpendEnforced;
136-
const bool fRejectPublicSpends = !fPublicSpendEnforced || consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V5_0);
135+
const bool fRejectMintsAndPrivateSpends = !isMined || !fZerocoinEnforced || fPublicSpendEnforced;
136+
const bool fRejectPublicSpends = !isMined || !fPublicSpendEnforced || consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V5_0);
137137

138138
const bool hasPrivateSpendInputs = !tx->vin.empty() && tx->vin[0].IsZerocoinSpend();
139139
const bool hasPublicSpendInputs = !tx->vin.empty() && tx->vin[0].IsZerocoinPublicSpend();

src/consensus/zerocoin_verify.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
bool isBlockBetweenFakeSerialAttackRange(int nHeight);
1414
// Public coin spend
1515
bool CheckPublicCoinSpendEnforced(int blockHeight, bool isPublicSpend);
16-
bool ContextualCheckZerocoinTx(const CTransactionRef& tx, CValidationState& state, const Consensus::Params& consensus, int nHeight);
16+
bool ContextualCheckZerocoinTx(const CTransactionRef& tx, CValidationState& state, const Consensus::Params& consensus, int nHeight, bool isMined);
1717
bool ContextualCheckZerocoinSpend(const CTransaction& tx, const libzerocoin::CoinSpend* spend, int nHeight);
1818
bool ContextualCheckZerocoinSpendNoSerialCheck(const CTransaction& tx, const libzerocoin::CoinSpend* spend, int nHeight);
1919

src/test/validation_tests.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,25 @@ BOOST_FIXTURE_TEST_CASE(test_simple_shielded_invalid, TestingSetup)
9494
}
9595
}
9696

97-
void CheckBlockZcRejection(std::shared_ptr<CBlock>& pblock, int nHeight, CMutableTransaction& mtx)
97+
void CheckBlockZcRejection(std::shared_ptr<CBlock>& pblock, int nHeight, CMutableTransaction& mtx, const std::string& expected_msg)
9898
{
9999
pblock->vtx.emplace_back(MakeTransactionRef(mtx));
100100
BOOST_CHECK(SolveBlock(pblock, nHeight));
101101
BlockStateCatcher stateCatcher(pblock->GetHash());
102102
stateCatcher.registerEvent();
103103
BOOST_CHECK(!ProcessNewBlock(pblock, nullptr));
104104
BOOST_CHECK(stateCatcher.found && !stateCatcher.state.IsValid());
105-
BOOST_CHECK_EQUAL(stateCatcher.state.GetRejectReason(), "bad-blk-with-zc");
105+
BOOST_CHECK_EQUAL(stateCatcher.state.GetRejectReason(), expected_msg);
106106
}
107107

108-
void CheckMempoolZcRejection(CMutableTransaction& mtx)
108+
void CheckMempoolZcRejection(CMutableTransaction& mtx, const std::string& expected_msg)
109109
{
110110
LOCK(cs_main);
111111
CValidationState state;
112112
BOOST_CHECK(!AcceptToMemoryPool(
113113
mempool, state, MakeTransactionRef(mtx), true, nullptr, false, true));
114114
BOOST_CHECK(!state.IsValid());
115-
BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-tx-with-zc");
115+
BOOST_CHECK_EQUAL(state.GetRejectReason(), expected_msg);
116116
}
117117

118118
/*
@@ -121,6 +121,7 @@ void CheckMempoolZcRejection(CMutableTransaction& mtx)
121121
BOOST_FIXTURE_TEST_CASE(zerocoin_rejection_tests, WalletRegTestingSetup)
122122
{
123123
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_V5_0, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
124+
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_ZC_PUBLIC, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
124125
const CChainParams& chainparams = Params();
125126

126127
std::unique_ptr<CBlockTemplate> pblocktemplate;
@@ -140,21 +141,21 @@ BOOST_FIXTURE_TEST_CASE(zerocoin_rejection_tests, WalletRegTestingSetup)
140141
CBigNum::randBignum(chainparams.GetConsensus().Zerocoin_Params(false)->coinCommitmentGroup.groupOrder).getvch();
141142
mtx.vout[0].nValue = 1 * COIN;
142143
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>(pblocktemplate->block);
143-
CheckBlockZcRejection(pblock, 1, mtx);
144-
CheckMempoolZcRejection(mtx);
144+
CheckBlockZcRejection(pblock, 1, mtx, "bad-txns-zc-mint");
145+
CheckMempoolZcRejection(mtx, "bad-txns-zc-mint");
145146

146147
// Zerocoin spends rejection test
147148
mtx.vout[0].scriptPubKey = scriptPubKey;
148149
mtx.vin[0].scriptSig = CScript() << OP_ZEROCOINSPEND;
149150
pblock = std::make_shared<CBlock>(pblocktemplate->block);
150-
CheckBlockZcRejection(pblock, 1, mtx);
151-
CheckMempoolZcRejection(mtx);
151+
CheckBlockZcRejection(pblock, 1, mtx, "bad-txns-zc-private-spend");
152+
CheckMempoolZcRejection(mtx, "bad-txns-zc-private-spend");
152153

153154
// Zerocoin public spends rejection test
154155
mtx.vin[0].scriptSig = CScript() << OP_ZEROCOINPUBLICSPEND;
155156
pblock = std::make_shared<CBlock>(pblocktemplate->block);
156-
CheckBlockZcRejection(pblock, 1, mtx);
157-
CheckMempoolZcRejection(mtx);
157+
CheckBlockZcRejection(pblock, 1, mtx, "bad-txns-zc-public-spend");
158+
CheckMempoolZcRejection(mtx, "bad-txns-zc-public-spend");
158159
}
159160

160161
BOOST_AUTO_TEST_SUITE_END()

src/validation.cpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,6 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState &state, const C
410410
const Consensus::Params& consensus = params.GetConsensus();
411411
int chainHeight = chainActive.Height();
412412

413-
// Zerocoin txes are not longer accepted in the mempool.
414-
if (tx.ContainsZerocoins()) {
415-
return state.DoS(100, error("%s : v5 upgrade enforced, zerocoin disabled", __func__),
416-
REJECT_INVALID, "bad-tx-with-zc");
417-
}
418-
419413
// Check transaction
420414
bool fColdStakingActive = !sporkManager.IsSporkActive(SPORK_19_COLDSTAKING_MAINTENANCE);
421415
if (!CheckTransaction(tx, state, fColdStakingActive))
@@ -1549,7 +1543,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
15491543
return state.DoS(100, error("%s : shielded transactions are currently in maintenance mode", __func__));
15501544
}
15511545

1552-
// When v5 is enforced CheckBlock rejects zerocoin transactions.
1546+
// When v5 is enforced ContextualCheckTransaction rejects zerocoin transactions.
15531547
// Therefore no need to call HasZerocoinSpendInputs after the enforcement.
15541548
if (!isV5UpgradeEnforced && tx.HasZerocoinSpendInputs()) {
15551549
auto opCoinSpendValues = ParseAndValidateZerocoinSpends(consensus, tx, pindex->nHeight, state);
@@ -2740,9 +2734,6 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
27402734
// Cold Staking enforcement (true during sync - reject P2CS outputs when false)
27412735
bool fColdStakingActive = true;
27422736

2743-
// Zerocoin activation
2744-
bool fZerocoinActive = block.GetBlockTime() > Params().GetConsensus().ZC_TimeStart;
2745-
27462737
// masternode payments / budgets
27472738
CBlockIndex* pindexPrev = chainActive.Tip();
27482739
int nHeight = 0;
@@ -2779,7 +2770,6 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
27792770
}
27802771

27812772
// Check transactions
2782-
bool fSaplingActive = Params().GetConsensus().NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V5_0);
27832773
std::vector<CBigNum> vBlockSerials;
27842774
for (const auto& txIn : block.vtx) {
27852775
const CTransaction& tx = *txIn;
@@ -2793,20 +2783,13 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
27932783
// pass the state returned by the function above
27942784
return false;
27952785
}
2796-
2797-
// No need to check for zerocoin anymore after sapling, they are networkely disabled
2798-
// and checkpoints are preventing the chain for any massive reorganization.
2799-
if (fSaplingActive && tx.ContainsZerocoins()) {
2800-
return state.DoS(100, error("%s : v5 upgrade enforced, zerocoin disabled", __func__),
2801-
REJECT_INVALID, "bad-blk-with-zc");
2802-
}
28032786
}
28042787

28052788
unsigned int nSigOps = 0;
28062789
for (const auto& tx : block.vtx) {
28072790
nSigOps += GetLegacySigOpCount(*tx);
28082791
}
2809-
unsigned int nMaxBlockSigOps = fZerocoinActive ? MAX_BLOCK_SIGOPS_CURRENT : MAX_BLOCK_SIGOPS_LEGACY;
2792+
unsigned int nMaxBlockSigOps = block.GetBlockTime() > Params().GetConsensus().ZC_TimeStart ? MAX_BLOCK_SIGOPS_CURRENT : MAX_BLOCK_SIGOPS_LEGACY;
28102793
if (nSigOps > nMaxBlockSigOps)
28112794
return state.DoS(100, error("%s : out-of-bounds SigOpCount", __func__),
28122795
REJECT_INVALID, "bad-blk-sigops", true);

0 commit comments

Comments
 (0)