Skip to content

Commit 3c74d6d

Browse files
committed
[zPIV] new protocol enforcement height added. Height not final, just randomly selected and tested on regtest.
1 parent f930016 commit 3c74d6d

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

src/chainparams.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ class CMainParams : public CChainParams
163163
nEnforceNewSporkKey = 1525158000; //!> Sporks signed after (GMT): Tuesday, May 1, 2018 7:00:00 AM GMT must use the new spork key
164164
nRejectOldSporkKey = 1527811200; //!> Fully reject old spork key after (GMT): Friday, June 1, 2018 12:00:00 AM
165165

166+
// Public coin spend enforcement
167+
nPublicZCSpends = 2000000;
168+
166169
// Fake Serial Attack
167170
nFakeSerialBlockheightEnd = 1686229;
168171
nSupplyBeforeFakeSerial = 4131563 * COIN; // zerocoin supply at block nFakeSerialBlockheightEnd
@@ -293,6 +296,9 @@ class CTestNetParams : public CMainParams
293296
nEnforceNewSporkKey = 1521604800; //!> Sporks signed after Wednesday, March 21, 2018 4:00:00 AM GMT must use the new spork key
294297
nRejectOldSporkKey = 1522454400; //!> Reject old spork key after Saturday, March 31, 2018 12:00:00 AM GMT
295298

299+
// Public coin spend enforcement
300+
nPublicZCSpends = 1086574;
301+
296302
// Fake Serial Attack
297303
nFakeSerialBlockheightEnd = -1;
298304
nSupplyBeforeFakeSerial = 0;
@@ -384,6 +390,9 @@ class CRegTestParams : public CTestNetParams
384390
nBlockFirstFraudulent = 999999999; //First block that bad serials emerged
385391
nBlockLastGoodCheckpoint = 999999999; //Last valid accumulator checkpoint
386392

393+
// Public coin spend enforcement
394+
nPublicZCSpends = 350;
395+
387396
// Fake Serial Attack
388397
nFakeSerialBlockheightEnd = -1;
389398

src/chainparams.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ class CChainParams
135135
int Zerocoin_Block_Double_Accumulated() const { return nBlockDoubleAccumulated; }
136136
CAmount InvalidAmountFiltered() const { return nInvalidAmountFiltered; };
137137

138+
int Zerocoin_Block_Public_Spend_Enabled() const { return nPublicZCSpends; }
139+
138140
protected:
139141
CChainParams() {}
140142

@@ -200,6 +202,7 @@ class CChainParams
200202
int nBlockEnforceInvalidUTXO;
201203
int nBlockZerocoinV2;
202204
int nBlockDoubleAccumulated;
205+
int nPublicZCSpends;
203206

204207
// fake serial attack
205208
int nFakeSerialBlockheightEnd = 0;

src/main.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,21 @@ bool isBlockBetweenFakeSerialAttackRange(int nHeight)
988988
return nHeight <= Params().Zerocoin_Block_EndFakeSerial();
989989
}
990990

991+
bool CheckPublicCoinSpendEnforced(int blockHeight, bool isPrivZerocoinSpend, bool isPublicSpend) {
992+
if (blockHeight >= Params().Zerocoin_Block_Public_Spend_Enabled()) {
993+
// reject old coin spend
994+
if (isPrivZerocoinSpend) {
995+
return error("%s: failed to add block with older zc spend version", __func__);
996+
}
997+
998+
} else {
999+
if (isPublicSpend) {
1000+
return error("%s: failed to add block, public spend enforcement not activated", __func__);
1001+
}
1002+
}
1003+
return true;
1004+
}
1005+
9911006
bool ContextualCheckZerocoinSpend(const CTransaction& tx, const CoinSpend* spend, CBlockIndex* pindex, const uint256& hashBlock)
9921007
{
9931008
if(!ContextualCheckZerocoinSpendNoSerialCheck(tx, spend, pindex, hashBlock)){
@@ -3209,9 +3224,14 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
32093224
set<CBigNum> setSerials;
32103225
for (const CTxIn& txIn : tx.vin) {
32113226
bool isPublicSpend = txIn.scriptSig.IsZerocoinPublicSpend();
3212-
if (!txIn.IsZerocoinSpend() && !isPublicSpend)
3227+
bool isPrivZerocoinSpend = txIn.IsZerocoinSpend();
3228+
if (!isPrivZerocoinSpend && !isPublicSpend)
32133229
continue;
32143230

3231+
// Check enforcement
3232+
if (!CheckPublicCoinSpendEnforced(pindex->nHeight, isPrivZerocoinSpend, isPublicSpend)){
3233+
return false;
3234+
}
32153235

32163236
if (isPublicSpend) {
32173237
libzerocoin::ZerocoinParams* params = Params().Zerocoin_Params(false);
@@ -4766,7 +4786,14 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
47664786
for (const CTxIn& in: tx.vin) {
47674787
if(nHeight >= Params().Zerocoin_StartHeight()) {
47684788
bool isPublicSpend = in.scriptSig.IsZerocoinPublicSpend();
4769-
if (in.IsZerocoinSpend() || isPublicSpend) {
4789+
bool isPrivZerocoinSpend = in.IsZerocoinSpend();
4790+
if (isPrivZerocoinSpend || isPublicSpend) {
4791+
4792+
// Check enforcement
4793+
if (!CheckPublicCoinSpendEnforced(pindex->nHeight, isPrivZerocoinSpend, isPublicSpend)){
4794+
return false;
4795+
}
4796+
47704797
libzerocoin::CoinSpend spend;
47714798
if (isPublicSpend) {
47724799
libzerocoin::ZerocoinParams* params = Params().Zerocoin_Params(false);

src/main.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ bool ReindexAccumulators(list<uint256>& listMissingCheckpoints, string& strError
373373
// Fake Serial attack Range
374374
bool isBlockBetweenFakeSerialAttackRange(int nHeight);
375375

376+
// Public coin spend
377+
bool CheckPublicCoinSpendEnforced(int blockHeight, bool isPrivZerocoinSpend, bool isPublicSpend);
378+
376379
/**
377380
* Check if transaction will be final in the next block to be created.
378381
*

src/wallet/wallet.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4903,6 +4903,13 @@ bool CWallet::MintsToInputVectorPublicSpend(std::map<CBigNum, CZerocoinMint>& ma
49034903

49044904
bool CWallet::CreateZerocoinSpendTransaction(CAmount nValue, CWalletTx& wtxNew, CReserveKey& reserveKey, CZerocoinSpendReceipt& receipt, vector<CZerocoinMint>& vSelectedMints, vector<CDeterministicMint>& vNewMints, bool fMintChange, bool fMinimizeChange, CBitcoinAddress* address)
49054905
{
4906+
4907+
// Check enforcement
4908+
if (chainActive.Tip()->nHeight < Params().Zerocoin_Block_Public_Spend_Enabled()){
4909+
receipt.SetStatus(_("New protocol enforcement not activated"), ZPIV_SPEND_ERROR);
4910+
return false;
4911+
}
4912+
49064913
// Check available funds
49074914
int nStatus = ZPIV_TRX_FUNDS_PROBLEMS;
49084915
if (nValue > GetZerocoinBalance(true)) {

0 commit comments

Comments
 (0)