Skip to content

Commit

Permalink
[zPIV] testnet publicSpend enforcement height set.
Browse files Browse the repository at this point in the history
[zPIV] v1 serials validation was not checked against the publicSpend height.
  • Loading branch information
furszy committed Jun 4, 2019
1 parent 0393227 commit 216a317
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class CTestNetParams : public CMainParams
nRejectOldSporkKey = 1522454400; //!> Reject old spork key after Saturday, March 31, 2018 12:00:00 AM GMT

// Public coin spend enforcement
nPublicZCSpends = 1086574;
nPublicZCSpends = 1818300;

// Fake Serial Attack
nFakeSerialBlockheightEnd = -1;
Expand Down
21 changes: 12 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,10 +988,10 @@ bool isBlockBetweenFakeSerialAttackRange(int nHeight)
return nHeight <= Params().Zerocoin_Block_EndFakeSerial();
}

bool CheckPublicCoinSpendEnforced(int blockHeight, bool isPrivZerocoinSpend, bool isPublicSpend) {
bool CheckPublicCoinSpendEnforced(int blockHeight, bool isPublicSpend) {
if (blockHeight >= Params().Zerocoin_Block_Public_Spend_Enabled()) {
// reject old coin spend
if (isPrivZerocoinSpend) {
if (!isPublicSpend) {
return error("%s: failed to add block with older zc spend version", __func__);
}

Expand Down Expand Up @@ -1042,11 +1042,14 @@ bool ContextualCheckZerocoinSpendNoSerialCheck(const CTransaction& tx, const Coi
}
}

//Reject V1 old serials.
if (spend->getVersion() < libzerocoin::PrivateCoin::PUBKEY_VERSION) {
return error("%s : zPIV v1 serial spend not spendable\n", __func__,
spend->getCoinSerialNumber().GetHex(), tx.GetHash().GetHex());
if (pindex->nHeight >= Params().Zerocoin_Block_Public_Spend_Enabled()) {
//Reject V1 old serials.
if (spend->getVersion() < libzerocoin::PrivateCoin::PUBKEY_VERSION) {
return error("%s : zPIV v1 serial spend not spendable, serial %s, tx %s\n", __func__,
spend->getCoinSerialNumber().GetHex(), tx.GetHash().GetHex());
}
}

//Reject serial's that are not in the acceptable value range
if (!spend->HasValidSerial(Params().Zerocoin_Params(false))) {
// Up until this block our chain was not checking serials correctly..
Expand Down Expand Up @@ -1416,7 +1419,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa
}

// Check enforcement
if (!CheckPublicCoinSpendEnforced(chainActive.Height(), isPrivZerocoinSpend, isPublicSpend)){
if (!CheckPublicCoinSpendEnforced(chainActive.Height(), isPublicSpend)){
return state.Invalid(error("%s: AcceptToMemoryPool failed for tx %s", __func__,
tx.GetHash().GetHex()), REJECT_INVALID, "bad-txns-invalid-zpiv");
}
Expand Down Expand Up @@ -3250,7 +3253,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
continue;

// Check enforcement
if (!CheckPublicCoinSpendEnforced(pindex->nHeight, isPrivZerocoinSpend, isPublicSpend)){
if (!CheckPublicCoinSpendEnforced(pindex->nHeight, isPublicSpend)){
return false;
}

Expand Down Expand Up @@ -4811,7 +4814,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
if (isPrivZerocoinSpend || isPublicSpend) {

// Check enforcement
if (!CheckPublicCoinSpendEnforced(pindex->nHeight, isPrivZerocoinSpend, isPublicSpend)){
if (!CheckPublicCoinSpendEnforced(pindex->nHeight, isPublicSpend)){
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ bool ReindexAccumulators(list<uint256>& listMissingCheckpoints, string& strError
bool isBlockBetweenFakeSerialAttackRange(int nHeight);

// Public coin spend
bool CheckPublicCoinSpendEnforced(int blockHeight, bool isPrivZerocoinSpend, bool isPublicSpend);
bool CheckPublicCoinSpendEnforced(int blockHeight, bool isPublicSpend);

/**
* Check if transaction will be final in the next block to be created.
Expand Down

0 comments on commit 216a317

Please sign in to comment.