Skip to content

Commit 22bfc12

Browse files
furszyFuzzbawls
authored andcommitted
Move-only: ATMP zerocoin check moved to its own legacy file.
Github-Pull: #1733 Rebased-From: 01aca7c
1 parent 24d9ac4 commit 22bfc12

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

src/legacy/validation_zerocoin_legacy.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,44 @@
33
// file COPYING or https://www.opensource.org/licenses/mit-license.php.
44
#include "legacy/validation_zerocoin_legacy.h"
55

6+
#include "consensus/zerocoin_verify.h"
67
#include "libzerocoin/CoinSpend.h"
78
#include "wallet/wallet.h"
89
#include "zpivchain.h"
910

11+
bool AcceptToMemoryPoolZerocoin(const CTransaction& tx, CAmount& nValueIn, int chainHeight, CValidationState& state, const Consensus::Params& consensus)
12+
{
13+
nValueIn = tx.GetZerocoinSpent();
14+
15+
//Check that txid is not already in the chain
16+
int nHeightTx = 0;
17+
if (IsTransactionInChain(tx.GetHash(), nHeightTx))
18+
return state.Invalid(error("%s : zPIV spend tx %s already in block %d", __func__, tx.GetHash().GetHex(), nHeightTx),
19+
REJECT_DUPLICATE, "bad-txns-inputs-spent");
20+
21+
//Check for double spending of serial #'s
22+
for (const CTxIn& txIn : tx.vin) {
23+
// Only allow for public zc spends inputs
24+
if (!txIn.IsZerocoinPublicSpend())
25+
return state.Invalid(false, REJECT_INVALID, "bad-zc-spend-notpublic");
26+
27+
libzerocoin::ZerocoinParams* params = consensus.Zerocoin_Params(false);
28+
PublicCoinSpend publicSpend(params);
29+
if (!ZPIVModule::ParseZerocoinPublicSpend(txIn, tx, state, publicSpend)){
30+
return false;
31+
}
32+
if (!ContextualCheckZerocoinSpend(tx, &publicSpend, chainHeight, UINT256_ZERO))
33+
return state.Invalid(false, REJECT_INVALID, "bad-zc-spend-contextcheck");
34+
35+
// Check that the version matches the one enforced with SPORK_18
36+
if (!CheckPublicCoinSpendVersion(publicSpend.getVersion())) {
37+
return state.Invalid(false, REJECT_INVALID, "bad-zc-spend-version");
38+
}
39+
}
40+
41+
return true;
42+
}
43+
1044
bool DisconnectZerocoinTx(const CTransaction& tx, CAmount& nValueIn, CZerocoinDB* zerocoinDB)
1145
{
1246
/** UNDO ZEROCOIN DATABASING

src/legacy/validation_zerocoin_legacy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "primitives/transaction.h"
1010
#include "txdb.h" // for the zerocoinDB implementation.
1111

12+
bool AcceptToMemoryPoolZerocoin(const CTransaction& tx, CAmount& nValueIn, int chainHeight, CValidationState& state, const Consensus::Params& consensus);
1213
bool DisconnectZerocoinTx(const CTransaction& tx, CAmount& nValueIn, CZerocoinDB* zerocoinDB);
1314
void DataBaseAccChecksum(CBlockIndex* pindex, bool fWrite);
1415

src/main.cpp

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -907,33 +907,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa
907907

908908
CAmount nValueIn = 0;
909909
if (hasZcSpendInputs) {
910-
nValueIn = tx.GetZerocoinSpent();
911-
912-
//Check that txid is not already in the chain
913-
int nHeightTx = 0;
914-
if (IsTransactionInChain(tx.GetHash(), nHeightTx))
915-
return state.Invalid(error("%s : zPIV spend tx %s already in block %d", __func__, tx.GetHash().GetHex(), nHeightTx),
916-
REJECT_DUPLICATE, "bad-txns-inputs-spent");
917-
918-
//Check for double spending of serial #'s
919-
for (const CTxIn& txIn : tx.vin) {
920-
// Only allow for public zc spends inputs
921-
if (!txIn.IsZerocoinPublicSpend())
922-
return state.Invalid(false, REJECT_INVALID, "bad-zc-spend-notpublic");
923-
924-
libzerocoin::ZerocoinParams* params = consensus.Zerocoin_Params(false);
925-
PublicCoinSpend publicSpend(params);
926-
if (!ZPIVModule::ParseZerocoinPublicSpend(txIn, tx, state, publicSpend)){
927-
return false;
928-
}
929-
if (!ContextualCheckZerocoinSpend(tx, &publicSpend, chainHeight, UINT256_ZERO))
930-
return state.Invalid(false, REJECT_INVALID, "bad-zc-spend-contextcheck");
931-
932-
// Check that the version matches the one enforced with SPORK_18
933-
if (!CheckPublicCoinSpendVersion(publicSpend.getVersion())) {
934-
return state.Invalid(false, REJECT_INVALID, "bad-zc-spend-version");
935-
}
936-
910+
if (!AcceptToMemoryPoolZerocoin(tx, nValueIn, chainHeight, state, consensus)) {
911+
return false;
937912
}
938913
} else {
939914
LOCK(pool.cs);

0 commit comments

Comments
 (0)