Skip to content

Commit 7736d6c

Browse files
committed
[Refactor] Consensus: zerocoin-related fields
- zerocoinModulus - nMaxZerocoinSpendsPerTransaction - nMaxZerocoinPublicSpendsPerTransaction - nMinZerocoinMintFee - nMintRequiredConfirmations - nRequiredAccumulation (removed) - nDefaultSecurityLevel (removed) - nZerocoinHeaderVersion (removed) - nZerocoinRequiredStakeDepth - nZerocoinStartTime
1 parent 0b63af4 commit 7736d6c

20 files changed

+141
-139
lines changed

src/chainparams.cpp

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -134,24 +134,6 @@ static const Checkpoints::CCheckpointData dataRegtest = {
134134
0,
135135
100};
136136

137-
libzerocoin::ZerocoinParams* CChainParams::Zerocoin_Params(bool useModulusV1) const
138-
{
139-
assert(this);
140-
static CBigNum bnHexModulus = 0;
141-
if (!bnHexModulus)
142-
bnHexModulus.SetHex(zerocoinModulus);
143-
static libzerocoin::ZerocoinParams ZCParamsHex = libzerocoin::ZerocoinParams(bnHexModulus);
144-
static CBigNum bnDecModulus = 0;
145-
if (!bnDecModulus)
146-
bnDecModulus.SetDec(zerocoinModulus);
147-
static libzerocoin::ZerocoinParams ZCParamsDec = libzerocoin::ZerocoinParams(bnDecModulus);
148-
149-
if (useModulusV1)
150-
return &ZCParamsHex;
151-
152-
return &ZCParamsDec;
153-
}
154-
155137
class CMainParams : public CChainParams
156138
{
157139
public:
@@ -180,7 +162,7 @@ class CMainParams : public CChainParams
180162
consensus.nTargetSpacing = 1 * 60;
181163
consensus.nTimeSlotLength = 15;
182164

183-
// height based activations
165+
// height-based activations
184166
consensus.height_last_PoW = 259200;
185167
consensus.height_last_ZC_AccumCheckpoint = 1686240;
186168
consensus.height_last_ZC_WrappedSerials = 1686229;
@@ -198,6 +180,18 @@ class CMainParams : public CChainParams
198180
consensus.height_ZC_RecalcAccumulators = 908000;
199181

200182
// Zerocoin-related params
183+
consensus.ZC_Modulus = "25195908475657893494027183240048398571429282126204032027777137836043662020707595556264018525880784"
184+
"4069182906412495150821892985591491761845028084891200728449926873928072877767359714183472702618963750149718246911"
185+
"6507761337985909570009733045974880842840179742910064245869181719511874612151517265463228221686998754918242243363"
186+
"7259085141865462043576798423387184774447920739934236584823824281198163815010674810451660377306056201619676256133"
187+
"8441436038339044149526344321901146575444541784240209246165157233507787077498171257724679629263863563732899121548"
188+
"31438167899885040445364023527381951378636564391212010397122822120720357";
189+
consensus.ZC_MaxPublicSpendsPerTx = 637; // Assume about 220 bytes each input
190+
consensus.ZC_MaxSpendsPerTx = 7; // Assume about 20kb each input
191+
consensus.ZC_MinMintConfirmations = 20;
192+
consensus.ZC_MinMintFee = 1 * CENT;
193+
consensus.ZC_MinStakeDepth = 200;
194+
consensus.ZC_TimeStart = 1508214600; // October 17, 2017 4:30:00 AM
201195
consensus.ZC_WrappedSerialsSupply = 4131563 * COIN; // zerocoin supply at height_last_ZC_WrappedSerials
202196

203197
/**
@@ -223,7 +217,6 @@ class CMainParams : public CChainParams
223217
/** Height or Time Based Activations **/
224218
nPivxBadBlockTime = 1471401614; // Skip nBit validation of Block 259201 per PR #915
225219
nPivxBadBlocknBits = 0x1c056dac; // Skip nBit validation of Block 259201 per PR #915
226-
nZerocoinStartTime = 1508214600; // October 17, 2017 4:30:00 AM
227220
nInvalidAmountFiltered = 268200*COIN; //Amount of invalid coins filtered through exchanges, that should be considered valid
228221
nEnforceNewSporkKey = 1566860400; //!> Sporks signed after Monday, August 26, 2019 11:00:00 PM GMT must use the new spork key
229222
nRejectOldSporkKey = 1569538800; //!> Fully reject old spork key after Thursday, September 26, 2019 11:00:00 PM GMT
@@ -258,22 +251,6 @@ class CMainParams : public CChainParams
258251
strObfuscationPoolDummyAddress = "D87q2gC9j6nNrnzCsg4aY6bHMLsT9nUhEw";
259252
nStartMasternodePayments = 1403728576; //Wed, 25 Jun 2014 20:36:16 GMT
260253

261-
/** Zerocoin */
262-
zerocoinModulus = "25195908475657893494027183240048398571429282126204032027777137836043662020707595556264018525880784"
263-
"4069182906412495150821892985591491761845028084891200728449926873928072877767359714183472702618963750149718246911"
264-
"6507761337985909570009733045974880842840179742910064245869181719511874612151517265463228221686998754918242243363"
265-
"7259085141865462043576798423387184774447920739934236584823824281198163815010674810451660377306056201619676256133"
266-
"8441436038339044149526344321901146575444541784240209246165157233507787077498171257724679629263863563732899121548"
267-
"31438167899885040445364023527381951378636564391212010397122822120720357";
268-
nMaxZerocoinSpendsPerTransaction = 7; // Assume about 20kb each
269-
nMaxZerocoinPublicSpendsPerTransaction = 637; // Assume about 220 bytes each input
270-
nMinZerocoinMintFee = 1 * CENT; //high fee required for zerocoin mints
271-
nMintRequiredConfirmations = 20; //the maximum amount of confirmations until accumulated in 19
272-
nRequiredAccumulation = 1;
273-
nDefaultSecurityLevel = 100; //full security level for accumulators
274-
nZerocoinHeaderVersion = 4; //Block headers must be this version once zerocoin is active
275-
nZerocoinRequiredStakeDepth = 200; //The required confirmations for a zpiv to be stakable
276-
277254
nBudget_Fee_Confirmations = 6; // Number of confirmations for the finalization fee
278255
nProposalEstablishmentTime = 60 * 60 * 24; // Proposals must be at least a day old to make it into a budget
279256
}
@@ -335,6 +312,18 @@ class CTestNetParams : public CMainParams
335312
consensus.height_ZC_RecalcAccumulators = 999999999;
336313

337314
// Zerocoin-related params
315+
consensus.ZC_Modulus = "25195908475657893494027183240048398571429282126204032027777137836043662020707595556264018525880784"
316+
"4069182906412495150821892985591491761845028084891200728449926873928072877767359714183472702618963750149718246911"
317+
"6507761337985909570009733045974880842840179742910064245869181719511874612151517265463228221686998754918242243363"
318+
"7259085141865462043576798423387184774447920739934236584823824281198163815010674810451660377306056201619676256133"
319+
"8441436038339044149526344321901146575444541784240209246165157233507787077498171257724679629263863563732899121548"
320+
"31438167899885040445364023527381951378636564391212010397122822120720357";
321+
consensus.ZC_MaxPublicSpendsPerTx = 637; // Assume about 220 bytes each input
322+
consensus.ZC_MaxSpendsPerTx = 7; // Assume about 20kb each input
323+
consensus.ZC_MinMintConfirmations = 20;
324+
consensus.ZC_MinMintFee = 1 * CENT;
325+
consensus.ZC_MinStakeDepth = 200;
326+
consensus.ZC_TimeStart = 1501776000;
338327
consensus.ZC_WrappedSerialsSupply = 0; // WrappedSerials only on main net
339328

340329
/**
@@ -357,7 +346,6 @@ class CTestNetParams : public CMainParams
357346
nPivxBadBlockTime = 1489001494; // Skip nBit validation of Block 259201 per PR #915
358347
nPivxBadBlocknBits = 0x1e0a20bd; // Skip nBit validation of Block 201 per PR #915
359348
nMasternodeCountDrift = 4;
360-
nZerocoinStartTime = 1501776000;
361349
nInvalidAmountFiltered = 0; //Amount of invalid coins filtered through exchanges, that should be considered valid
362350
nEnforceNewSporkKey = 1566860400; //!> Sporks signed after Monday, August 26, 2019 11:00:00 PM GMT must use the new spork key
363351
nRejectOldSporkKey = 1569538800; //!> Reject old spork key after Thursday, September 26, 2019 11:00:00 PM GMT
@@ -437,7 +425,7 @@ class CRegTestParams : public CTestNetParams
437425

438426
// height based activations
439427
consensus.height_last_PoW = 250;
440-
consensus.height_last_ZC_AccumCheckpoint = 301; // no checkpoints on regtest
428+
consensus.height_last_ZC_AccumCheckpoint = 310; // no checkpoints on regtest
441429
consensus.height_last_ZC_WrappedSerials = -1;
442430
consensus.height_start_BIP65 = 851019; // Not defined for regtest. Inherit TestNet value.
443431
consensus.height_start_InvalidUTXOsCheck = 999999999;
@@ -453,7 +441,19 @@ class CRegTestParams : public CTestNetParams
453441
consensus.height_ZC_RecalcAccumulators = 999999999;
454442

455443
// Zerocoin-related params
456-
consensus.ZC_WrappedSerialsSupply = 0; // WrappedSerials only on main net
444+
consensus.ZC_Modulus = "25195908475657893494027183240048398571429282126204032027777137836043662020707595556264018525880784"
445+
"4069182906412495150821892985591491761845028084891200728449926873928072877767359714183472702618963750149718246911"
446+
"6507761337985909570009733045974880842840179742910064245869181719511874612151517265463228221686998754918242243363"
447+
"7259085141865462043576798423387184774447920739934236584823824281198163815010674810451660377306056201619676256133"
448+
"8441436038339044149526344321901146575444541784240209246165157233507787077498171257724679629263863563732899121548"
449+
"31438167899885040445364023527381951378636564391212010397122822120720357";
450+
consensus.ZC_MaxPublicSpendsPerTx = 637; // Assume about 220 bytes each input
451+
consensus.ZC_MaxSpendsPerTx = 7; // Assume about 20kb each input
452+
consensus.ZC_MinMintConfirmations = 10;
453+
consensus.ZC_MinMintFee = 1 * CENT;
454+
consensus.ZC_MinStakeDepth = 10;
455+
consensus.ZC_TimeStart = 0; // not implemented on regtest
456+
consensus.ZC_WrappedSerialsSupply = 0;
457457

458458

459459
/**
@@ -473,10 +473,6 @@ class CRegTestParams : public CTestNetParams
473473
nToCheckBlockUpgradeMajority = 1000;
474474
nMinerThreads = 1;
475475
nMasternodeCountDrift = 4;
476-
nZerocoinStartTime = 1501776000;
477-
478-
nMintRequiredConfirmations = 10;
479-
nZerocoinRequiredStakeDepth = nMintRequiredConfirmations;
480476

481477
vFixedSeeds.clear(); //! Testnet mode doesn't have any fixed seeds.
482478
vSeeds.clear(); //! Testnet mode doesn't have any DNS seeds.

src/chainparams.h

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "protocol.h"
1616
#include "uint256.h"
1717

18-
#include "libzerocoin/Params.h"
1918
#include <vector>
2019

2120
typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
@@ -106,21 +105,9 @@ class CChainParams
106105
CBaseChainParams::Network NetworkID() const { return networkID; }
107106
bool IsRegTestNet() const { return NetworkID() == CBaseChainParams::REGTEST; }
108107

109-
/** Zerocoin **/
110-
libzerocoin::ZerocoinParams* Zerocoin_Params(bool useModulusV1) const;
111-
int Zerocoin_MaxSpendsPerTransaction() const { return nMaxZerocoinSpendsPerTransaction; }
112-
int Zerocoin_MaxPublicSpendsPerTransaction() const { return nMaxZerocoinPublicSpendsPerTransaction; }
113-
CAmount Zerocoin_MintFee() const { return nMinZerocoinMintFee; }
114-
int Zerocoin_MintRequiredConfirmations() const { return nMintRequiredConfirmations; }
115-
int Zerocoin_RequiredAccumulation() const { return nRequiredAccumulation; }
116-
int Zerocoin_DefaultSpendSecurity() const { return nDefaultSecurityLevel; }
117-
int Zerocoin_HeaderVersion() const { return nZerocoinHeaderVersion; }
118-
int Zerocoin_RequiredStakeDepth() const { return nZerocoinRequiredStakeDepth; }
119-
120108
/** Height or Time Based Activations **/
121109
int PivxBadBlockTime() const { return nPivxBadBlockTime; }
122110
int PivxBadBlocknBits() const { return nPivxBadBlocknBits; }
123-
int Zerocoin_StartTime() const { return nZerocoinStartTime; }
124111

125112
CAmount InvalidAmountFiltered() const { return nInvalidAmountFiltered; };
126113

@@ -145,7 +132,6 @@ class CChainParams
145132
int nMasternodeCountDrift;
146133
int nMaturity;
147134

148-
int nModifierUpdateBlock;
149135
int nMinerThreads;
150136
std::vector<CDNSSeedData> vSeeds;
151137
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
@@ -164,18 +150,9 @@ class CChainParams
164150
int64_t nRejectOldSporkKey;
165151
std::string strObfuscationPoolDummyAddress;
166152
int64_t nStartMasternodePayments;
167-
std::string zerocoinModulus;
168-
int nMaxZerocoinSpendsPerTransaction;
169-
int nMaxZerocoinPublicSpendsPerTransaction;
170-
CAmount nMinZerocoinMintFee;
153+
171154
CAmount nInvalidAmountFiltered;
172-
int nMintRequiredConfirmations;
173-
int nRequiredAccumulation;
174-
int nDefaultSecurityLevel;
175-
int nZerocoinHeaderVersion;
176155
int64_t nBudget_Fee_Confirmations;
177-
int nZerocoinStartTime;
178-
int nZerocoinRequiredStakeDepth;
179156
int64_t nProposalEstablishmentTime;
180157

181158
CAmount nMinColdStakingAmount;

src/consensus/params.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define BITCOIN_CONSENSUS_PARAMS_H
88

99
#include "amount.h"
10+
#include "libzerocoin/Params.h"
1011
#include "uint256.h"
1112
#include <map>
1213
#include <string>
@@ -33,7 +34,7 @@ struct Params {
3334
int64_t nTargetSpacing;
3435
int nTimeSlotLength;
3536

36-
// Height-based activations
37+
// height-based activations
3738
int height_last_PoW;
3839
int height_last_ZC_AccumCheckpoint;
3940
int height_last_ZC_WrappedSerials;
@@ -50,8 +51,6 @@ struct Params {
5051
int height_start_ZC_SerialsV2;
5152
int height_ZC_RecalcAccumulators;
5253

53-
// Zerocoin-related params
54-
CAmount ZC_WrappedSerialsSupply;
5554

5655
int64_t TargetTimespan(const bool fV2 = true) const { return fV2 ? nTargetTimespanV2 : nTargetTimespan; }
5756
uint256 ProofOfStakeLimit(const bool fV2) const { return fV2 ? posLimitV2 : posLimitV1; }
@@ -85,6 +84,30 @@ struct Params {
8584
// with stake modifier V2+, we require the utxo to be nStakeMinDepth deep in the chain
8685
return (contextHeight - utxoFromBlockHeight >= nStakeMinDepth);
8786
}
87+
88+
89+
/*
90+
* (Legacy) Zerocoin consensus params
91+
*/
92+
std::string ZC_Modulus; // parsed in Zerocoin_Params (either as hex or dec string)
93+
int ZC_MaxPublicSpendsPerTx;
94+
int ZC_MaxSpendsPerTx;
95+
int ZC_MinMintConfirmations;
96+
CAmount ZC_MinMintFee;
97+
int ZC_MinStakeDepth;
98+
int ZC_TimeStart;
99+
CAmount ZC_WrappedSerialsSupply;
100+
101+
libzerocoin::ZerocoinParams* Zerocoin_Params(bool useModulusV1) const
102+
{
103+
static CBigNum bnHexModulus = 0;
104+
if (!bnHexModulus) bnHexModulus.SetHex(ZC_Modulus);
105+
static libzerocoin::ZerocoinParams ZCParamsHex = libzerocoin::ZerocoinParams(bnHexModulus);
106+
static CBigNum bnDecModulus = 0;
107+
if (!bnDecModulus) bnDecModulus.SetDec(ZC_Modulus);
108+
static libzerocoin::ZerocoinParams ZCParamsDec = libzerocoin::ZerocoinParams(bnDecModulus);
109+
return (useModulusV1 ? &ZCParamsHex : &ZCParamsDec);
110+
}
88111
};
89112
} // namespace Consensus
90113

src/consensus/tx_verify.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ bool CheckTransaction(const CTransaction& tx, bool fZerocoinActive, bool fReject
117117
}
118118

119119
if (fZerocoinActive) {
120-
if (nZCSpendCount > Params().Zerocoin_MaxSpendsPerTransaction())
120+
if (nZCSpendCount > consensus.ZC_MaxSpendsPerTx)
121121
return state.DoS(100, error("CheckTransaction() : there are more zerocoin spends than are allowed in one transaction"));
122122

123123
//require that a zerocoinspend only has inputs that are zerocoins
@@ -144,11 +144,11 @@ bool CheckTransaction(const CTransaction& tx, bool fZerocoinActive, bool fReject
144144
return state.DoS(10, error("CheckTransaction() : Zerocoin Spend has less than allowed txin's"), REJECT_INVALID, "bad-zerocoinspend");
145145
if (tx.HasZerocoinPublicSpendInputs()) {
146146
// tx has public zerocoin spend inputs
147-
if(static_cast<int>(tx.vin.size()) > Params().Zerocoin_MaxPublicSpendsPerTransaction())
147+
if(static_cast<int>(tx.vin.size()) > consensus.ZC_MaxPublicSpendsPerTx)
148148
return state.DoS(10, error("CheckTransaction() : Zerocoin Spend has more than allowed txin's"), REJECT_INVALID, "bad-zerocoinspend");
149149
} else {
150150
// tx has regular zerocoin spend inputs
151-
if(static_cast<int>(tx.vin.size()) > Params().Zerocoin_MaxSpendsPerTransaction())
151+
if(static_cast<int>(tx.vin.size()) > consensus.ZC_MaxSpendsPerTx)
152152
return state.DoS(10, error("CheckTransaction() : Zerocoin Spend has more than allowed txin's"), REJECT_INVALID, "bad-zerocoinspend");
153153
}
154154

src/consensus/zerocoin_verify.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ bool CheckZerocoinSpend(const CTransaction& tx, bool fVerifySignature, CValidati
3737
uint256 hashTxOut = txTemp.GetHash();
3838

3939
bool fValidated = false;
40+
const Consensus::Params& consensus = Params().GetConsensus();
4041
std::set<CBigNum> serials;
4142
CAmount nTotalRedeemed = 0;
4243
for (const CTxIn& txin : tx.vin) {
@@ -52,7 +53,7 @@ bool CheckZerocoinSpend(const CTransaction& tx, bool fVerifySignature, CValidati
5253
if(!GetOutput(txin.prevout.hash, txin.prevout.n, state, prevOut)){
5354
return state.DoS(100, error("CheckZerocoinSpend(): public zerocoin spend prev output not found, prevTx %s, index %d", txin.prevout.hash.GetHex(), txin.prevout.n));
5455
}
55-
libzerocoin::ZerocoinParams* params = Params().Zerocoin_Params(false);
56+
libzerocoin::ZerocoinParams* params = consensus.Zerocoin_Params(false);
5657
PublicCoinSpend publicSpend(params);
5758
if (!ZPIVModule::parseCoinSpend(txin, tx, prevOut, publicSpend)){
5859
return state.DoS(100, error("CheckZerocoinSpend(): public zerocoin spend parse failed"));
@@ -75,7 +76,7 @@ bool CheckZerocoinSpend(const CTransaction& tx, bool fVerifySignature, CValidati
7576
return state.DoS(100, error("Zerocoinspend does not use the same txout that was used in the SoK"));
7677

7778
if (isPublicSpend) {
78-
libzerocoin::ZerocoinParams* params = Params().Zerocoin_Params(false);
79+
libzerocoin::ZerocoinParams* params = consensus.Zerocoin_Params(false);
7980
PublicCoinSpend ret(params);
8081
if (!ZPIVModule::validateInput(txin, prevOut, tx, ret)){
8182
return state.DoS(100, error("CheckZerocoinSpend(): public zerocoin spend did not verify"));
@@ -173,7 +174,7 @@ bool ContextualCheckZerocoinSpendNoSerialCheck(const CTransaction& tx, const lib
173174
bool fUseV1Params = spend->getCoinVersion() < libzerocoin::PrivateCoin::PUBKEY_VERSION;
174175

175176
//Reject serial's that are not in the acceptable value range
176-
if (!spend->HasValidSerial(Params().Zerocoin_Params(fUseV1Params))) {
177+
if (!spend->HasValidSerial(Params().GetConsensus().Zerocoin_Params(fUseV1Params))) {
177178
// Up until this block our chain was not checking serials correctly..
178179
if (!isBlockBetweenFakeSerialAttackRange(nHeight))
179180
return error("%s : zPIV spend with serial %s from tx %s is not in valid range\n", __func__,

src/kernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ bool initStakeInput(const CBlock& block, std::unique_ptr<CStakeInput>& stake, in
145145
CLegacyZPivStake* zPIV = dynamic_cast<CLegacyZPivStake*>(stake.get());
146146
if (!zPIV) return error("%s : dynamic_cast of stake ptr failed", __func__);
147147
// The checkpoint needs to be from 200 blocks ago
148-
const int cpHeight = nPreviousBlockHeight - Params().Zerocoin_RequiredStakeDepth();
148+
const int cpHeight = nPreviousBlockHeight - consensus.ZC_MinStakeDepth;
149149
const libzerocoin::CoinDenomination denom = libzerocoin::AmountToZerocoinDenomination(zPIV->GetValue());
150150
if (ParseAccChecksum(chainActive[cpHeight]->nAccumulatorCheckpoint, denom) != zPIV->GetChecksum())
151151
return error("%s : accum. checksum at height %d is wrong.", __func__, (nPreviousBlockHeight+1));

0 commit comments

Comments
 (0)