Skip to content

Commit f9d585a

Browse files
committed
More zerocoin unused functions and classes cleanup.
1 parent 029ce7b commit f9d585a

File tree

4 files changed

+2
-624
lines changed

4 files changed

+2
-624
lines changed

src/zpiv/zerocoin.cpp

Lines changed: 1 addition & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -2,115 +2,13 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include <streams.h>
65
#include "zerocoin.h"
6+
#include "streams.h"
77
#include "hash.h"
8-
#include "util.h"
9-
#include "utilstrencodings.h"
10-
11-
bool CMintMeta::operator <(const CMintMeta& a) const
12-
{
13-
return this->hashPubcoin < a.hashPubcoin;
14-
}
15-
16-
uint256 GetSerialHash(const CBigNum& bnSerial)
17-
{
18-
CDataStream ss(SER_GETHASH, 0);
19-
ss << bnSerial;
20-
return Hash(ss.begin(), ss.end());
21-
}
228

239
uint256 GetPubCoinHash(const CBigNum& bnValue)
2410
{
2511
CDataStream ss(SER_GETHASH, 0);
2612
ss << bnValue;
2713
return Hash(ss.begin(), ss.end());
2814
}
29-
30-
bool CZerocoinMint::GetKeyPair(CKey &key) const
31-
{
32-
if (version < STAKABLE_VERSION)
33-
return error("%s: version is %d", __func__, version);
34-
35-
if (privkey.empty())
36-
return error("%s: empty privkey %s", __func__, privkey.data());
37-
38-
return key.SetPrivKey(privkey, true);
39-
}
40-
41-
std::string CZerocoinMint::ToString() const
42-
{
43-
std::string str = strprintf("\n ZerocoinMint:\n version=%d \ntxfrom=%s \nheight=%d \n randomness: %s \n serial %s \n privkey %s\n",
44-
version, txid.GetHex(), nHeight, randomness.GetHex(), serialNumber.GetHex(), HexStr(privkey));
45-
return str;
46-
}
47-
48-
void CZerocoinSpendReceipt::AddSpend(const CZerocoinSpend& spend)
49-
{
50-
vSpends.emplace_back(spend);
51-
}
52-
53-
std::vector<CZerocoinSpend> CZerocoinSpendReceipt::GetSpends()
54-
{
55-
return vSpends;
56-
}
57-
58-
void CZerocoinSpendReceipt::SetStatus(std::string strStatus, int nStatus, int nNeededSpends)
59-
{
60-
strStatusMessage = strStatus;
61-
this->nStatus = nStatus;
62-
this->nNeededSpends = nNeededSpends;
63-
}
64-
65-
std::string CZerocoinSpendReceipt::GetStatusMessage()
66-
{
67-
return strStatusMessage;
68-
}
69-
70-
int CZerocoinSpendReceipt::GetStatus()
71-
{
72-
return nStatus;
73-
}
74-
75-
int CZerocoinSpendReceipt::GetNeededSpends()
76-
{
77-
return nNeededSpends;
78-
}
79-
80-
81-
int GetWrapppedSerialInflation(libzerocoin::CoinDenomination denom){
82-
if(Params().NetworkIDString() == CBaseChainParams::MAIN) {
83-
switch (denom) {
84-
case libzerocoin::CoinDenomination::ZQ_ONE:
85-
return 7;
86-
case libzerocoin::CoinDenomination::ZQ_FIVE:
87-
return 6;
88-
case libzerocoin::CoinDenomination::ZQ_TEN:
89-
return 36;
90-
case libzerocoin::CoinDenomination::ZQ_FIFTY:
91-
return 22;
92-
case libzerocoin::CoinDenomination::ZQ_ONE_HUNDRED:
93-
return 244;
94-
case libzerocoin::CoinDenomination::ZQ_FIVE_HUNDRED:
95-
return 22;
96-
case libzerocoin::CoinDenomination::ZQ_ONE_THOUSAND:
97-
return 42;
98-
case libzerocoin::CoinDenomination::ZQ_FIVE_THOUSAND:
99-
return 98;
100-
default:
101-
throw std::runtime_error("GetWrapSerialInflation :: Invalid denom");
102-
}
103-
}else{
104-
// Testnet/Regtest is ok.
105-
return 0;
106-
}
107-
}
108-
109-
int64_t GetWrapppedSerialInflationAmount(){
110-
int64_t amount = 0;
111-
for (auto& denom : libzerocoin::zerocoinDenomList){
112-
amount += GetWrapppedSerialInflation(denom) * libzerocoin::ZerocoinDenominationToAmount(denom);
113-
}
114-
return amount;
115-
}
116-

src/zpiv/zerocoin.h

Lines changed: 1 addition & 254 deletions
Original file line numberDiff line numberDiff line change
@@ -5,262 +5,9 @@
55
#ifndef PIVX_ZEROCOIN_H
66
#define PIVX_ZEROCOIN_H
77

8-
#include <amount.h>
9-
#include <limits.h>
10-
#include <chainparams.h>
8+
#include "uint256.h"
119
#include "libzerocoin/bignum.h"
12-
#include "libzerocoin/Denominations.h"
13-
#include "key.h"
14-
#include "serialize.h"
1510

16-
//struct that is safe to store essential mint data, without holding any information that allows for actual spending (serial, randomness, private key)
17-
struct CMintMeta
18-
{
19-
int nHeight;
20-
uint256 hashSerial;
21-
uint256 hashPubcoin;
22-
uint256 hashStake; //requires different hashing method than hashSerial above
23-
uint8_t nVersion;
24-
libzerocoin::CoinDenomination denom;
25-
uint256 txid;
26-
bool isUsed;
27-
bool isArchived;
28-
bool isDeterministic;
29-
bool isSeedCorrect;
30-
31-
bool operator <(const CMintMeta& a) const;
32-
};
33-
34-
uint256 GetSerialHash(const CBigNum& bnSerial);
3511
uint256 GetPubCoinHash(const CBigNum& bnValue);
3612

37-
class CZerocoinMint
38-
{
39-
private:
40-
libzerocoin::CoinDenomination denomination;
41-
int nHeight;
42-
CBigNum value;
43-
CBigNum randomness;
44-
CBigNum serialNumber;
45-
uint256 txid;
46-
int outputIndex = -1;
47-
CPrivKey privkey;
48-
uint8_t version;
49-
bool isUsed;
50-
51-
public:
52-
static const int STAKABLE_VERSION = 2;
53-
static const int CURRENT_VERSION = 2;
54-
55-
CZerocoinMint()
56-
{
57-
SetNull();
58-
}
59-
60-
CZerocoinMint(libzerocoin::CoinDenomination denom, const CBigNum& value, const CBigNum& randomness, const CBigNum& serialNumber, bool isUsed, const uint8_t& nVersion, CPrivKey* privkey = nullptr)
61-
{
62-
SetNull();
63-
this->denomination = denom;
64-
this->value = value;
65-
this->randomness = randomness;
66-
this->serialNumber = serialNumber;
67-
this->isUsed = isUsed;
68-
this->version = nVersion;
69-
if (nVersion >= 2 && privkey)
70-
this->privkey = *privkey;
71-
}
72-
73-
void SetNull()
74-
{
75-
isUsed = false;
76-
randomness = 0;
77-
value = 0;
78-
denomination = libzerocoin::ZQ_ERROR;
79-
nHeight = 0;
80-
txid.SetNull();
81-
version = 1;
82-
privkey.clear();
83-
}
84-
85-
uint256 GetHash() const;
86-
87-
CBigNum GetValue() const { return value; }
88-
void SetValue(CBigNum value){ this->value = value; }
89-
libzerocoin::CoinDenomination GetDenomination() const { return denomination; }
90-
int64_t GetDenominationAsAmount() const { return denomination * COIN; }
91-
void SetDenomination(libzerocoin::CoinDenomination denom){ this->denomination = denom; }
92-
int GetHeight() const { return nHeight; }
93-
void SetHeight(int nHeight){ this->nHeight = nHeight; }
94-
bool IsUsed() const { return this->isUsed; }
95-
void SetUsed(bool isUsed){ this->isUsed = isUsed; }
96-
CBigNum GetRandomness() const{ return randomness; }
97-
void SetRandomness(CBigNum rand){ this->randomness = rand; }
98-
CBigNum GetSerialNumber() const { return serialNumber; }
99-
void SetSerialNumber(CBigNum serial){ this->serialNumber = serial; }
100-
uint256 GetTxHash() const { return this->txid; }
101-
void SetTxHash(uint256 txid) { this->txid = txid; }
102-
uint8_t GetVersion() const { return this->version; }
103-
void SetVersion(const uint8_t nVersion) { this->version = nVersion; }
104-
CPrivKey GetPrivKey() const { return this->privkey; }
105-
void SetPrivKey(const CPrivKey& privkey) { this->privkey = privkey; }
106-
bool GetKeyPair(CKey& key) const;
107-
108-
int GetOutputIndex() { return this->outputIndex; }
109-
void SetOutputIndex(int index) { this->outputIndex = index; }
110-
111-
inline bool operator <(const CZerocoinMint& a) const { return GetHeight() < a.GetHeight(); }
112-
113-
CZerocoinMint(const CZerocoinMint& other) {
114-
denomination = other.GetDenomination();
115-
nHeight = other.GetHeight();
116-
value = other.GetValue();
117-
randomness = other.GetRandomness();
118-
serialNumber = other.GetSerialNumber();
119-
txid = other.GetTxHash();
120-
isUsed = other.IsUsed();
121-
version = other.GetVersion();
122-
privkey = other.privkey;
123-
}
124-
125-
std::string ToString() const;
126-
127-
bool operator == (const CZerocoinMint& other) const
128-
{
129-
return this->GetValue() == other.GetValue();
130-
}
131-
132-
// Copy another CZerocoinMint
133-
inline CZerocoinMint& operator=(const CZerocoinMint& other) {
134-
denomination = other.GetDenomination();
135-
nHeight = other.GetHeight();
136-
value = other.GetValue();
137-
randomness = other.GetRandomness();
138-
serialNumber = other.GetSerialNumber();
139-
txid = other.GetTxHash();
140-
isUsed = other.IsUsed();
141-
version = other.GetVersion();
142-
privkey = other.GetPrivKey();
143-
return *this;
144-
}
145-
146-
// why 6 below (SPOCK)
147-
inline bool checkUnused(int denom, int Height) const {
148-
if (IsUsed() == false && GetDenomination() == denomination && GetRandomness() != 0 && GetSerialNumber() != 0 && GetHeight() != -1 && GetHeight() != INT_MAX && GetHeight() >= 1 && (GetHeight() + 6 <= Height)) {
149-
return true;
150-
} else {
151-
return false;
152-
}
153-
}
154-
155-
ADD_SERIALIZE_METHODS;
156-
157-
template <typename Stream, typename Operation>
158-
inline void SerializationOp(Stream& s, Operation ser_action) {
159-
READWRITE(isUsed);
160-
READWRITE(randomness);
161-
READWRITE(serialNumber);
162-
READWRITE(value);
163-
READWRITE(denomination);
164-
READWRITE(nHeight);
165-
READWRITE(txid);
166-
167-
bool fVersionedMint = true;
168-
try {
169-
READWRITE(version);
170-
} catch (...) {
171-
fVersionedMint = false;
172-
}
173-
174-
if (version > CURRENT_VERSION) {
175-
version = 1;
176-
fVersionedMint = false;
177-
}
178-
179-
if (fVersionedMint)
180-
READWRITE(privkey);
181-
};
182-
};
183-
184-
class CZerocoinSpend
185-
{
186-
private:
187-
CBigNum coinSerial;
188-
uint256 hashTx;
189-
CBigNum pubCoin;
190-
libzerocoin::CoinDenomination denomination;
191-
unsigned int nAccumulatorChecksum;
192-
int nMintCount; //memory only - the amount of mints that belong to the accumulator this is spent from
193-
194-
public:
195-
CZerocoinSpend()
196-
{
197-
SetNull();
198-
}
199-
200-
CZerocoinSpend(CBigNum coinSerial, uint256 hashTx, CBigNum pubCoin, libzerocoin::CoinDenomination denomination, unsigned int nAccumulatorChecksum)
201-
{
202-
this->coinSerial = coinSerial;
203-
this->hashTx = hashTx;
204-
this->pubCoin = pubCoin;
205-
this->denomination = denomination;
206-
this->nAccumulatorChecksum = nAccumulatorChecksum;
207-
}
208-
209-
void SetNull()
210-
{
211-
coinSerial = 0;
212-
hashTx.SetNull();
213-
pubCoin = 0;
214-
denomination = libzerocoin::ZQ_ERROR;
215-
}
216-
217-
CBigNum GetSerial() const { return coinSerial; }
218-
uint256 GetTxHash() const { return hashTx; }
219-
void SetTxHash(uint256 hash) { this->hashTx = hash; }
220-
CBigNum GetPubCoin() const { return pubCoin; }
221-
libzerocoin::CoinDenomination GetDenomination() const { return denomination; }
222-
unsigned int GetAccumulatorChecksum() const { return this->nAccumulatorChecksum; }
223-
uint256 GetHash() const;
224-
void SetMintCount(int nMintsAdded) { this->nMintCount = nMintsAdded; }
225-
int GetMintCount() const { return nMintCount; }
226-
227-
ADD_SERIALIZE_METHODS;
228-
229-
template <typename Stream, typename Operation>
230-
inline void SerializationOp(Stream& s, Operation ser_action) {
231-
READWRITE(coinSerial);
232-
READWRITE(hashTx);
233-
READWRITE(pubCoin);
234-
READWRITE(denomination);
235-
READWRITE(nAccumulatorChecksum);
236-
};
237-
};
238-
239-
class CZerocoinSpendReceipt
240-
{
241-
private:
242-
std::string strStatusMessage;
243-
int nStatus;
244-
int nNeededSpends;
245-
std::vector<CZerocoinSpend> vSpends;
246-
247-
public:
248-
void AddSpend(const CZerocoinSpend& spend);
249-
std::vector<CZerocoinSpend> GetSpends();
250-
void SetStatus(std::string strStatus, int nStatus, int nNeededSpends = 0);
251-
std::string GetStatusMessage();
252-
int GetStatus();
253-
int GetNeededSpends();
254-
};
255-
256-
/**
257-
* Wrapped serials attack inflation, only for mainnet.
258-
* FUTURE: Move this to another file..
259-
* @param denom
260-
* @return
261-
*/
262-
int GetWrapppedSerialInflation(libzerocoin::CoinDenomination denom);
263-
264-
int64_t GetWrapppedSerialInflationAmount();
265-
26613
#endif //PIVX_ZEROCOIN_H

0 commit comments

Comments
 (0)