Skip to content

Commit

Permalink
Move-only: ATMP zerocoin check moved to its own legacy file.
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Jul 6, 2020
1 parent 5e81e5d commit 01aca7c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
34 changes: 34 additions & 0 deletions src/legacy/validation_zerocoin_legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,44 @@
// file COPYING or https://www.opensource.org/licenses/mit-license.php.
#include "legacy/validation_zerocoin_legacy.h"

#include "consensus/zerocoin_verify.h"
#include "libzerocoin/CoinSpend.h"
#include "wallet/wallet.h"
#include "zpivchain.h"

bool AcceptToMemoryPoolZerocoin(const CTransaction& tx, CAmount& nValueIn, int chainHeight, CValidationState& state, const Consensus::Params& consensus)
{
nValueIn = tx.GetZerocoinSpent();

//Check that txid is not already in the chain
int nHeightTx = 0;
if (IsTransactionInChain(tx.GetHash(), nHeightTx))
return state.Invalid(error("%s : zPIV spend tx %s already in block %d", __func__, tx.GetHash().GetHex(), nHeightTx),
REJECT_DUPLICATE, "bad-txns-inputs-spent");

//Check for double spending of serial #'s
for (const CTxIn& txIn : tx.vin) {
// Only allow for public zc spends inputs
if (!txIn.IsZerocoinPublicSpend())
return state.Invalid(false, REJECT_INVALID, "bad-zc-spend-notpublic");

libzerocoin::ZerocoinParams* params = consensus.Zerocoin_Params(false);
PublicCoinSpend publicSpend(params);
if (!ZPIVModule::ParseZerocoinPublicSpend(txIn, tx, state, publicSpend)){
return false;
}
if (!ContextualCheckZerocoinSpend(tx, &publicSpend, chainHeight, UINT256_ZERO))
return state.Invalid(false, REJECT_INVALID, "bad-zc-spend-contextcheck");

// Check that the version matches the one enforced with SPORK_18
if (!CheckPublicCoinSpendVersion(publicSpend.getVersion())) {
return state.Invalid(false, REJECT_INVALID, "bad-zc-spend-version");
}
}

return true;
}

bool DisconnectZerocoinTx(const CTransaction& tx, CAmount& nValueIn, CZerocoinDB* zerocoinDB)
{
/** UNDO ZEROCOIN DATABASING
Expand Down
1 change: 1 addition & 0 deletions src/legacy/validation_zerocoin_legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "primitives/transaction.h"
#include "txdb.h" // for the zerocoinDB implementation.

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

Expand Down
29 changes: 2 additions & 27 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,33 +907,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa

CAmount nValueIn = 0;
if (hasZcSpendInputs) {
nValueIn = tx.GetZerocoinSpent();

//Check that txid is not already in the chain
int nHeightTx = 0;
if (IsTransactionInChain(tx.GetHash(), nHeightTx))
return state.Invalid(error("%s : zPIV spend tx %s already in block %d", __func__, tx.GetHash().GetHex(), nHeightTx),
REJECT_DUPLICATE, "bad-txns-inputs-spent");

//Check for double spending of serial #'s
for (const CTxIn& txIn : tx.vin) {
// Only allow for public zc spends inputs
if (!txIn.IsZerocoinPublicSpend())
return state.Invalid(false, REJECT_INVALID, "bad-zc-spend-notpublic");

libzerocoin::ZerocoinParams* params = consensus.Zerocoin_Params(false);
PublicCoinSpend publicSpend(params);
if (!ZPIVModule::ParseZerocoinPublicSpend(txIn, tx, state, publicSpend)){
return false;
}
if (!ContextualCheckZerocoinSpend(tx, &publicSpend, chainHeight, UINT256_ZERO))
return state.Invalid(false, REJECT_INVALID, "bad-zc-spend-contextcheck");

// Check that the version matches the one enforced with SPORK_18
if (!CheckPublicCoinSpendVersion(publicSpend.getVersion())) {
return state.Invalid(false, REJECT_INVALID, "bad-zc-spend-version");
}

if (!AcceptToMemoryPoolZerocoin(tx, nValueIn, chainHeight, state, consensus)) {
return false;
}
} else {
LOCK(pool.cs);
Expand Down

0 comments on commit 01aca7c

Please sign in to comment.