Skip to content

Commit 334b760

Browse files
committed
[zPIV][Cleanup] remove ContextualCheckZerocoinMint
Outright reject mints from mempool. Only verify that they are no longer accepted after Zerocoin_Block_Public_Spend_Enabled
1 parent 39116fb commit 334b760

File tree

1 file changed

+18
-70
lines changed

1 file changed

+18
-70
lines changed

src/main.cpp

Lines changed: 18 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -900,26 +900,6 @@ bool CheckZerocoinMint(const uint256& txHash, const CTxOut& txout, CValidationSt
900900
return true;
901901
}
902902

903-
bool ContextualCheckZerocoinMint(const CTransaction& tx, const libzerocoin::PublicCoin& coin, const CBlockIndex* pindex)
904-
{
905-
if (pindex->nHeight >= Params().Zerocoin_Block_Public_Spend_Enabled()) {
906-
// Zerocoin MINTs have been disabled
907-
return error("%s: Mints disabled at height %d - unable to add pubcoin %s", __func__,
908-
pindex->nHeight, coin.getValue().GetHex().substr(0, 10));
909-
}
910-
if (pindex->nHeight >= Params().Zerocoin_Block_V2_Start() && Params().NetworkID() != CBaseChainParams::TESTNET) {
911-
//See if this coin has already been added to the blockchain
912-
uint256 txid;
913-
int nHeight;
914-
if (zerocoinDB->ReadCoinMint(coin.getValue(), txid) && IsTransactionInChain(txid, nHeight))
915-
return error("%s: pubcoin %s was already accumulated in tx %s", __func__,
916-
coin.getValue().GetHex().substr(0, 10),
917-
txid.GetHex());
918-
}
919-
920-
return true;
921-
}
922-
923903
bool isBlockBetweenFakeSerialAttackRange(int nHeight)
924904
{
925905
if (Params().NetworkID() != CBaseChainParams::MAIN)
@@ -1283,19 +1263,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa
12831263
}
12841264
}
12851265

1286-
// Check that zPIV mints (if included) are not already known
1287-
for (auto& out : tx.vout) {
1288-
if (!out.IsZerocoinMint())
1289-
continue;
1290-
1291-
libzerocoin::PublicCoin coin(Params().Zerocoin_Params(false));
1292-
if (!TxOutToPublicCoin(out, coin, state))
1293-
return state.Invalid(error("%s: failed final check of zerocoinmint for tx %s",
1294-
__func__, tx.GetHash().GetHex()));
1295-
1296-
if (!ContextualCheckZerocoinMint(tx, coin, chainActive.Tip()))
1297-
return state.Invalid(error("%s: zerocoin mint failed contextual check", __func__));
1298-
}
1266+
// Reject legacy zPIV mints
1267+
if (!Params().IsRegTestNet() && tx.HasZerocoinMintOutputs())
1268+
return state.Invalid(error("%s : tried to include zPIV mint output in tx %s",
1269+
__func__, tx.GetHash().GetHex()), REJECT_INVALID, "bad-txns-invalid-outputs");
12991270

13001271
// are the actual inputs available?
13011272
if (!view.HaveInputs(tx))
@@ -1349,10 +1320,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa
13491320
__func__, hash.ToString(), nFees, txMinFee), REJECT_INSUFFICIENTFEE, "insufficient fee");
13501321

13511322
// Require that free transactions have sufficient priority to be mined in the next block.
1352-
if (tx.HasZerocoinMintOutputs()) {
1353-
if(nFees < Params().Zerocoin_MintFee() * tx.GetZerocoinMintCount())
1354-
return state.DoS(0, false, REJECT_INSUFFICIENTFEE, "insufficient fee for zerocoinmint");
1355-
} else if (!hasZcSpendInputs && GetBoolArg("-relaypriority", true) && nFees < ::minRelayTxFee.GetFee(nSize) && !AllowFree(view.GetPriority(tx, chainActive.Height() + 1))) {
1323+
if (!hasZcSpendInputs && GetBoolArg("-relaypriority", true) && nFees < ::minRelayTxFee.GetFee(nSize) && !AllowFree(view.GetPriority(tx, chainActive.Height() + 1))) {
13561324
return state.DoS(0, false, REJECT_INSUFFICIENTFEE, "insufficient priority");
13571325
}
13581326

@@ -3027,6 +2995,19 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
30272995
return state.DoS(100, error("ConnectBlock() : zerocoin transactions are currently in maintenance mode"));
30282996
}
30292997

2998+
if (tx.HasZerocoinMintOutputs()) {
2999+
if (pindex->nHeight >= Params().Zerocoin_Block_Public_Spend_Enabled())
3000+
return state.DoS(100, error("%s: Mints no longer accepted at height %d", __func__, pindex->nHeight));
3001+
// parse minted coins
3002+
for (auto& out : tx.vout) {
3003+
if (!out.IsZerocoinMint()) continue;
3004+
libzerocoin::PublicCoin coin(Params().Zerocoin_Params(false));
3005+
if (!TxOutToPublicCoin(out, coin, state))
3006+
return state.DoS(100, error("%s: failed final check of zerocoinmint for tx %s", __func__, tx.GetHash().GetHex()));
3007+
vMints.emplace_back(std::make_pair(coin, tx.GetHash()));
3008+
}
3009+
}
3010+
30303011
if (tx.HasZerocoinSpendInputs()) {
30313012
int nHeightTx = 0;
30323013
uint256 txid = tx.GetHash();
@@ -3073,22 +3054,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
30733054
}
30743055
}
30753056

3076-
// Check that zPIV mints are not already known
3077-
if (tx.HasZerocoinMintOutputs()) {
3078-
for (auto& out : tx.vout) {
3079-
if (!out.IsZerocoinMint())
3080-
continue;
3081-
3082-
libzerocoin::PublicCoin coin(Params().Zerocoin_Params(false));
3083-
if (!TxOutToPublicCoin(out, coin, state))
3084-
return state.DoS(100, error("%s: failed final check of zerocoinmint for tx %s", __func__, tx.GetHash().GetHex()));
3085-
3086-
if (!ContextualCheckZerocoinMint(tx, coin, pindex))
3087-
return state.DoS(100, error("%s: zerocoin mint failed contextual check", __func__));
3088-
3089-
vMints.emplace_back(std::make_pair(coin, tx.GetHash()));
3090-
}
3091-
}
30923057
} else if (!tx.IsCoinBase()) {
30933058
if (!view.HaveInputs(tx))
30943059
return state.DoS(100, error("ConnectBlock() : inputs missing/spent"),
@@ -3102,23 +3067,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
31023067
}
31033068
}
31043069

3105-
// Check that zPIV mints are not already known
3106-
if (tx.HasZerocoinMintOutputs()) {
3107-
for (auto& out : tx.vout) {
3108-
if (!out.IsZerocoinMint())
3109-
continue;
3110-
3111-
libzerocoin::PublicCoin coin(Params().Zerocoin_Params(false));
3112-
if (!TxOutToPublicCoin(out, coin, state))
3113-
return state.DoS(100, error("%s: failed final check of zerocoinmint for tx %s", __func__, tx.GetHash().GetHex()));
3114-
3115-
if (!ContextualCheckZerocoinMint(tx, coin, pindex))
3116-
return state.DoS(100, error("%s: zerocoin mint failed contextual check", __func__));
3117-
3118-
vMints.emplace_back(std::make_pair(coin, tx.GetHash()));
3119-
}
3120-
}
3121-
31223070
// Add in sigops done by pay-to-script-hash inputs;
31233071
// this is to prevent a "rogue miner" from creating
31243072
// an incredibly-expensive-to-validate block.

0 commit comments

Comments
 (0)