Skip to content

Commit 26045d3

Browse files
committed
[Consensus] Set zc PublicSpend version v3/v4 via SPORK
define SPORK_18_ZEROCOIN_PUBLICSPEND_V4. When such spork is not active, zerocoin publicspend version must be 3. Otherwise must be 4.
1 parent 9765a77 commit 26045d3

File tree

8 files changed

+149
-77
lines changed

8 files changed

+149
-77
lines changed

src/chainparams.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,6 @@ bool CChainParams::HasStakeMinAgeOrDepth(const int contextHeight, const uint32_t
132132
return (contextHeight - utxoFromBlockHeight >= nStakeMinDepth);
133133
}
134134

135-
int CChainParams::Zerocoin_PublicSpendVersion(const int nHeight) const
136-
{
137-
if (nHeight < nPublicZCSpendsV4)
138-
return 3;
139-
return 4;
140-
}
141-
142135
class CMainParams : public CChainParams
143136
{
144137
public:
@@ -194,7 +187,6 @@ class CMainParams : public CChainParams
194187

195188
// Public coin spend enforcement
196189
nPublicZCSpends = 1880000;
197-
nPublicZCSpendsV4 = 2880000;
198190

199191
// New P2P messages signatures
200192
nBlockEnforceNewMessageSignatures = 2967000;
@@ -335,7 +327,6 @@ class CTestNetParams : public CMainParams
335327

336328
// Public coin spend enforcement
337329
nPublicZCSpends = 1106100;
338-
nPublicZCSpendsV4 = 2106100;
339330

340331
// New P2P messages signatures
341332
nBlockEnforceNewMessageSignatures = 2214000;
@@ -434,7 +425,6 @@ class CRegTestParams : public CTestNetParams
434425

435426
// Public coin spend enforcement
436427
nPublicZCSpends = 350;
437-
nPublicZCSpendsV4 = 450;
438428

439429
// New P2P messages signatures
440430
nBlockEnforceNewMessageSignatures = 1;

src/chainparams.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ class CChainParams
144144
int Zerocoin_Block_V2_Start() const { return nBlockZerocoinV2; }
145145
bool IsStakeModifierV2(const int nHeight) const { return nHeight >= nBlockStakeModifierlV2; }
146146
int NewSigsActive(const int nHeight) const { return nHeight >= nBlockEnforceNewMessageSignatures; }
147-
int Zerocoin_PublicSpendVersion(const int nHeight) const;
148147

149148
// fake serial attack
150149
int Zerocoin_Block_EndFakeSerial() const { return nFakeSerialBlockheightEnd; }
@@ -227,7 +226,6 @@ class CChainParams
227226
int nBlockZerocoinV2;
228227
int nBlockDoubleAccumulated;
229228
int nPublicZCSpends;
230-
int nPublicZCSpendsV4;
231229
int nBlockStakeModifierlV2;
232230
int nBlockEnforceNewMessageSignatures;
233231

src/main.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,8 +1009,12 @@ bool CheckPublicCoinSpendEnforced(int blockHeight, bool isPublicSpend) {
10091009
return true;
10101010
}
10111011

1012-
bool CheckPublicCoinSpendVersion(int blockHeight, int version) {
1013-
return version >= Params().Zerocoin_PublicSpendVersion(blockHeight);
1012+
int CurrentPublicCoinSpendVersion() {
1013+
return sporkManager.IsSporkActive(SPORK_18_ZEROCOIN_PUBLICSPEND_V4) ? 4 : 3;
1014+
}
1015+
1016+
bool CheckPublicCoinSpendVersion(int version) {
1017+
return version == CurrentPublicCoinSpendVersion();
10141018
}
10151019

10161020
bool ContextualCheckZerocoinSpend(const CTransaction& tx, const libzerocoin::CoinSpend* spend, CBlockIndex* pindex, const uint256& hashBlock)
@@ -1052,12 +1056,6 @@ bool ContextualCheckZerocoinSpendNoSerialCheck(const CTransaction& tx, const lib
10521056
}
10531057
}
10541058

1055-
// Check spend version
1056-
if (pindex->nHeight >= Params().Zerocoin_Block_Public_Spend_Enabled() &&
1057-
!CheckPublicCoinSpendVersion(pindex->nHeight, (int)spend->getVersion())) {
1058-
return error("%s: Invalid public spend version for tx %s", __func__, tx.GetHash().GetHex());
1059-
}
1060-
10611059
bool fUseV1Params = spend->getCoinVersion() < libzerocoin::PrivateCoin::PUBKEY_VERSION;
10621060

10631061
//Reject serial's that are not in the acceptable value range
@@ -1453,6 +1451,13 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa
14531451
if (!ContextualCheckZerocoinSpend(tx, &publicSpend, chainActive.Tip(), 0))
14541452
return state.Invalid(error("%s: ContextualCheckZerocoinSpend failed for tx %s",
14551453
__func__, tx.GetHash().GetHex()), REJECT_INVALID, "bad-txns-invalid-zpiv");
1454+
1455+
// Check that the version matches the one enforced with SPORK_18
1456+
if (!CheckPublicCoinSpendVersion(publicSpend.getVersion())) {
1457+
return state.Invalid(error("%s : Public Zerocoin spend version %d not accepted. must be version %d.",
1458+
__func__, publicSpend.getVersion(), CurrentPublicCoinSpendVersion()), REJECT_INVALID, "bad-txns-invalid-zpiv");
1459+
}
1460+
14561461
} else {
14571462
libzerocoin::CoinSpend spend = TxInToZerocoinSpend(txIn);
14581463
if (!ContextualCheckZerocoinSpend(tx, &spend, chainActive.Tip(), 0))
@@ -4571,6 +4576,11 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
45714576
return false;
45724577
}
45734578
spend = publicSpend;
4579+
// check that the version matches the one enforced with SPORK_18 (don't ban if it fails)
4580+
if (!IsInitialBlockDownload() && !CheckPublicCoinSpendVersion(spend.getVersion())) {
4581+
return state.DoS(0, error("%s : Public Zerocoin spend version %d not accepted. must be version %d.",
4582+
__func__, spend.getVersion(), CurrentPublicCoinSpendVersion()), REJECT_INVALID, "bad-zcspend-version");
4583+
}
45744584
} else {
45754585
spend = TxInToZerocoinSpend(txIn);
45764586
}

src/main.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ bool isBlockBetweenFakeSerialAttackRange(int nHeight);
375375

376376
// Public coin spend
377377
bool CheckPublicCoinSpendEnforced(int blockHeight, bool isPublicSpend);
378-
bool CheckPublicCoinSpendVersion(int blockHeight, int version);
378+
int CurrentPublicCoinSpendVersion();
379+
bool CheckPublicCoinSpendVersion(int version);
379380

380381
/**
381382
* Check if transaction will be final in the next block to be created.

src/spork.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ std::vector<CSporkDef> sporkDefs = {
2525
MAKE_SPORK_DEF(SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2, 4070908800ULL), // OFF
2626
MAKE_SPORK_DEF(SPORK_16_ZEROCOIN_MAINTENANCE_MODE, 4070908800ULL), // OFF
2727
MAKE_SPORK_DEF(SPORK_17_COLDSTAKING_ENFORCEMENT, 4070908800ULL), // OFF
28+
MAKE_SPORK_DEF(SPORK_18_ZEROCOIN_PUBLICSPEND_V4, 4070908800ULL), // OFF
2829
};
2930

3031
CSporkManager sporkManager;

src/sporkid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ enum SporkId : int32_t {
2323
SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2 = 10014,
2424
SPORK_16_ZEROCOIN_MAINTENANCE_MODE = 10015,
2525
SPORK_17_COLDSTAKING_ENFORCEMENT = 10017,
26+
SPORK_18_ZEROCOIN_PUBLICSPEND_V4 = 10018,
2627

2728
SPORK_INVALID = -1
2829
};

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4367,7 +4367,7 @@ bool CWallet::MintsToInputVectorPublicSpend(std::map<CBigNum, CZerocoinMint>& ma
43674367
if (!nHeight)
43684368
return error("%s: Unable to get chain tip height", __func__);
43694369

4370-
int spendVersion = Params().Zerocoin_PublicSpendVersion(nHeight);
4370+
int spendVersion = CurrentPublicCoinSpendVersion();
43714371

43724372
int nLockAttempts = 0;
43734373
while (nLockAttempts < 100) {

0 commit comments

Comments
 (0)