PIVX Core  5.6.99
P2P Digital Currency
Classes | Enumerations | Functions | Variables
libzerocoin Namespace Reference

Classes

class  InvalidSerialException
 
class  PublicCoin
 A Public coin is the part of a coin that is published to the network and what is handled by other clients. More...
 
class  CoinRandomnessSchnorrSignature
 A Schnorr Signature on the hash of metadata attesting that the signer knows the randomness v necessary to open a public coin C (which is a pedersen commitment g^S h^v mod p) with given serial number S. More...
 
class  AccumulatorProofOfKnowledge
 
class  SerialNumberSignatureOfKnowledge
 
class  CommitmentProofOfKnowledge
 
class  CoinSpend
 The complete proof needed to spend a zerocoin. More...
 
class  Commitment
 A commitment, complete with contents and opening randomness. More...
 
class  IntegerGroupParams
 
class  AccumulatorAndProofParams
 
class  ZerocoinParams
 

Enumerations

enum  CoinDenomination {
  ZQ_ERROR = 0 , ZQ_ONE = 1 , ZQ_FIVE = 5 , ZQ_TEN = 10 ,
  ZQ_FIFTY = 50 , ZQ_ONE_HUNDRED = 100 , ZQ_FIVE_HUNDRED = 500 , ZQ_ONE_THOUSAND = 1000 ,
  ZQ_FIVE_THOUSAND = 5000
}
 
enum  SpendType : uint8_t { SPEND , STAKE , MN_COLLATERAL , SIGN_MESSAGE }
 

Functions

int ExtractVersionFromSerial (const CBigNum &bnSerial)
 
CBigNum GetAdjustedSerial (const CBigNum &bnSerial)
 
bool IsValidSerial (const ZerocoinParams *params, const CBigNum &bnSerial)
 
bool IsValidCommitmentToCoinRange (const ZerocoinParams *params, const CBigNum &bnCommitment)
 
CBigNum ExtractSerialFromPubKey (const CPubKey pubkey)
 
CoinDenomination IntToZerocoinDenomination (int64_t amount)
 
int64_t ZerocoinDenominationToInt (const CoinDenomination &denomination)
 
CoinDenomination AmountToZerocoinDenomination (CAmount amount)
 
CoinDenomination AmountToClosestDenomination (CAmount nAmount, CAmount &nRemaining)
 
CAmount ZerocoinDenominationToAmount (const CoinDenomination &denomination)
 
CoinDenomination get_denomination (std::string denomAmount)
 
int64_t get_amount (std::string denomAmount)
 
void CalculateParams (ZerocoinParams &params, const CBigNum &N, const std::string &aux, uint32_t securityLevel)
 Fill in a set of Zerocoin parameters from a modulus "N". More...
 
uint256 calculateGeneratorSeed (const uint256 &seed, const uint256 &pSeed, const uint256 &qSeed, const std::string &label, uint32_t index, uint32_t count)
 Format a seed string by hashing several values. More...
 
uint256 calculateSeed (const CBigNum &modulus, const std::string &auxString, uint32_t securityLevel, const std::string &groupName)
 Format a seed string by hashing several values. More...
 
uint256 calculateHash (const uint256 &input)
 
void calculateGroupParamLengths (uint32_t maxPLen, uint32_t securityLevel, uint32_t *pLen, uint32_t *qLen)
 Calculate field/group parameter sizes based on a security level. More...
 
IntegerGroupParams deriveIntegerGroupParams (const uint256 &seed, uint32_t pLen, uint32_t qLen)
 Deterministically compute a set of group parameters using NIST procedures. More...
 
IntegerGroupParams deriveIntegerGroupFromOrder (const CBigNum &groupOrder)
 Deterministically compute a set of group parameters with a specified order. More...
 
void calculateGroupModulusAndOrder (const uint256 &seed, uint32_t pLen, uint32_t qLen, CBigNum *resultModulus, CBigNum *resultGroupOrder, uint256 *resultPseed, uint256 *resultQseed)
 Deterministically compute a group description using NIST procedures. More...
 
CBigNum calculateGroupGenerator (const uint256 &seed, const uint256 &pSeed, const uint256 &qSeed, const CBigNum &modulus, const CBigNum &groupOrder, uint32_t index)
 Deterministically compute a generator for a given group. More...
 
CBigNum generateRandomPrime (uint32_t primeBitLen, const arith_uint256 &in_seed, arith_uint256 *out_seed, uint32_t *prime_gen_counter)
 Deterministically compute a random prime number. More...
 
CBigNum generateIntegerFromSeed (uint32_t numBits, const arith_uint256 &seed, uint32_t *numIterations)
 
bool primalityTestByTrialDivision (uint32_t candidate)
 Determines whether a uint32_t is a prime through trial division. More...
 

Variables

const std::vector< CoinDenominationzerocoinDenomList = {ZQ_ONE, ZQ_FIVE, ZQ_TEN, ZQ_FIFTY, ZQ_ONE_HUNDRED, ZQ_FIVE_HUNDRED, ZQ_ONE_THOUSAND, ZQ_FIVE_THOUSAND}
 
const std::vector< int > maxCoinsAtDenom = {4, 1, 4, 1, 4, 1, 4, 4}
 

Enumeration Type Documentation

◆ CoinDenomination

Enumerator
ZQ_ERROR 
ZQ_ONE 
ZQ_FIVE 
ZQ_TEN 
ZQ_FIFTY 
ZQ_ONE_HUNDRED 
ZQ_FIVE_HUNDRED 
ZQ_ONE_THOUSAND 
ZQ_FIVE_THOUSAND 

Definition at line 14 of file Denominations.h.

◆ SpendType

enum libzerocoin::SpendType : uint8_t
Enumerator
SPEND 
STAKE 
MN_COLLATERAL 
SIGN_MESSAGE 

Definition at line 11 of file SpendType.h.

Function Documentation

◆ AmountToClosestDenomination()

CoinDenomination libzerocoin::AmountToClosestDenomination ( CAmount  nAmount,
CAmount nRemaining 
)

Definition at line 64 of file Denominations.cpp.

◆ AmountToZerocoinDenomination()

CoinDenomination libzerocoin::AmountToZerocoinDenomination ( CAmount  amount)

Definition at line 51 of file Denominations.cpp.

◆ calculateGeneratorSeed()

uint256 libzerocoin::calculateGeneratorSeed ( const uint256 seed,
const uint256 pSeed,
const uint256 qSeed,
const std::string &  label,
uint32_t  index,
uint32_t  count 
)

Format a seed string by hashing several values.

Parameters
NA CBigNum
auxAn auxiliary string
securityLevelThe security level in bits
groupNameA group description string
Exceptions
std::runtime_errorif the process fails

Returns the hash of the value.

Definition at line 126 of file ParamGeneration.cpp.

◆ calculateGroupGenerator()

CBigNum libzerocoin::calculateGroupGenerator ( const uint256 seed,
const uint256 pSeed,
const uint256 qSeed,
const CBigNum modulus,
const CBigNum groupOrder,
uint32_t  index 
)

Deterministically compute a generator for a given group.

Parameters
seedA first seed for the process.
pSeedA second seed for the process.
qSeedA third seed for the process.
modulusProposed prime modulus for the field.
groupOrderProposed order of the group.
indexIndex value, selects which generator you're building.
Returns
The resulting generator.
Exceptions
Astd::runtime_error if error.

Generates a random group generator deterministically as a function of (seed,pSeed,qSeed) Uses the algorithm described in FIPS 186-3 Appendix A.2.3.

Definition at line 451 of file ParamGeneration.cpp.

Here is the caller graph for this function:

◆ calculateGroupModulusAndOrder()

void libzerocoin::calculateGroupModulusAndOrder ( const uint256 seed,
uint32_t  pLen,
uint32_t  qLen,
CBigNum resultModulus,
CBigNum resultGroupOrder,
uint256 resultPseed,
uint256 resultQseed 
)

Deterministically compute a group description using NIST procedures.

Parameters
seedA byte string seeding the process.
pLenThe desired length of the modulus "p" in bits
qLenThe desired length of the order "q" in bits
resultModulusA value "p" describing a finite field "F_p"
resultGroupOrderA value "q" describing the order of a subgroup
resultDomainParameterSeedA resulting seed for use in later calculations.

Calculates the description of a group G of prime order "q" embedded within a field "F_p". The input to this routine is in arbitrary seed. It uses the algorithms described in FIPS 186-3 Appendix A.1.2 to calculate primes "p" and "q".

Todo:
: The use of 256-bit seeds limits us to 256-bit group orders. We should probably change this.
Todo:
: we don't have a ceiling function
Todo:
: implement a ceil function

Definition at line 350 of file ParamGeneration.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculateGroupParamLengths()

void libzerocoin::calculateGroupParamLengths ( uint32_t  maxPLen,
uint32_t  securityLevel,
uint32_t *  pLen,
uint32_t *  qLen 
)

Calculate field/group parameter sizes based on a security level.

Parameters
maxPLenMaximum size of the field (modulus "p") in bits.
securityLevelRequired security level in bits (at least 80)
pLenResult: length of "p" in bits
qLenResult: length of "q" in bits
Exceptions
std::runtime_errorif the process fails

Calculates the appropriate sizes of "p" and "q" for a prime-order subgroup of order "q" embedded within a field "F_p". The sizes are based on a 'securityLevel' provided in symmetric-equivalent bits. Our choices slightly exceed the specs in FIPS 186-3:

securityLevel = 80: pLen = 1024, qLen = 256 securityLevel = 112: pLen = 2048, qLen = 256 securityLevel = 128: qLen = 3072, qLen = 320

If the length of "p" exceeds the length provided in "maxPLen", or if "securityLevel < 80" this routine throws an exception.

Definition at line 205 of file ParamGeneration.cpp.

Here is the caller graph for this function:

◆ calculateHash()

uint256 libzerocoin::calculateHash ( const uint256 input)

Definition at line 175 of file ParamGeneration.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CalculateParams()

void libzerocoin::CalculateParams ( ZerocoinParams params,
const CBigNum N,
const std::string &  aux,
uint32_t  securityLevel 
)

Fill in a set of Zerocoin parameters from a modulus "N".

Parameters
NA trusted RSA modulus
auxAn optional auxiliary string used in derivation
securityLevelA security level
Exceptions
std::runtime_errorif the process fails

Fills in a ZC_Params data structure deterministically from a trustworthy RSA modulus "N", which is provided as a CBigNum.

Note: this routine makes the fundamental assumption that "N" encodes a valid RSA-style modulus of the form "e1*e2" for some unknown safe primes "e1" and "e2". These factors must not be known to any party, or the security of Zerocoin is compromised. The integer "N" must be a MINIMUM of 1023 in length, and 3072 bits is strongly recommended.

Definition at line 41 of file ParamGeneration.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculateSeed()

uint256 libzerocoin::calculateSeed ( const CBigNum modulus,
const std::string &  auxString,
uint32_t  securityLevel,
const std::string &  groupName 
)

Format a seed string by hashing several values.

Parameters
NA CBigNum
auxAn auxiliary string
securityLevelThe security level in bits
groupNameA group description string
Exceptions
std::runtime_errorif the process fails

Returns the hash of the value.

Definition at line 157 of file ParamGeneration.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deriveIntegerGroupFromOrder()

IntegerGroupParams libzerocoin::deriveIntegerGroupFromOrder ( const CBigNum groupOrder)

Deterministically compute a set of group parameters with a specified order.

Parameters
groupOrderThe order of the group
Returns
An IntegerGroupParams object

Given "q" calculates the description of a group G of prime order "q" embedded within a field "F_p".

Todo:
: This is a probabilistic routine and thus not the right choice

Definition at line 287 of file ParamGeneration.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deriveIntegerGroupParams()

IntegerGroupParams libzerocoin::deriveIntegerGroupParams ( const uint256 seed,
uint32_t  pLen,
uint32_t  qLen 
)

Deterministically compute a set of group parameters using NIST procedures.

Parameters
seedStrA byte string seeding the process.
pLenThe desired length of the modulus "p" in bits
qLenThe desired length of the order "q" in bits
Returns
An IntegerGroupParams object

Calculates the description of a group G of prime order "q" embedded within a field "F_p". The input to this routine is in arbitrary seed. It uses the algorithms described in FIPS 186-3 Appendix A.1.2 to calculate primes "p" and "q". It uses the procedure in Appendix A.2.3 to derive two generators "g", "h".

Definition at line 242 of file ParamGeneration.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExtractSerialFromPubKey()

CBigNum libzerocoin::ExtractSerialFromPubKey ( const CPubKey  pubkey)

Definition at line 108 of file Coin.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExtractVersionFromSerial()

int libzerocoin::ExtractVersionFromSerial ( const CBigNum bnSerial)

Definition at line 61 of file Coin.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generateIntegerFromSeed()

CBigNum libzerocoin::generateIntegerFromSeed ( uint32_t  numBits,
const arith_uint256 seed,
uint32_t *  numIterations 
)

Definition at line 610 of file ParamGeneration.cpp.

Here is the caller graph for this function:

◆ generateRandomPrime()

CBigNum libzerocoin::generateRandomPrime ( uint32_t  primeBitLen,
const arith_uint256 in_seed,
arith_uint256 out_seed,
uint32_t *  prime_gen_counter 
)

Deterministically compute a random prime number.

Parameters
primeBitLenDesired bit length of the prime.
in_seedInput seed for the process.
out_seedResult: output seed from the process.
prime_gen_counterResult: number of iterations required.
Returns
The resulting prime number.
Exceptions
Astd::runtime_error if error.

Generates a random prime number of primeBitLen bits from a given input seed. Uses the Shawe-Taylor algorithm as described in FIPS 186-3 Appendix C.6. This is a recursive function.

Todo:
no Ceiling call

Definition at line 494 of file ParamGeneration.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_amount()

int64_t libzerocoin::get_amount ( std::string  denomAmount)

Definition at line 105 of file Denominations.cpp.

Here is the call graph for this function:

◆ get_denomination()

CoinDenomination libzerocoin::get_denomination ( std::string  denomAmount)

Definition at line 99 of file Denominations.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAdjustedSerial()

CBigNum libzerocoin::GetAdjustedSerial ( const CBigNum bnSerial)

Definition at line 78 of file Coin.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IntToZerocoinDenomination()

CoinDenomination libzerocoin::IntToZerocoinDenomination ( int64_t  amount)

Definition at line 12 of file Denominations.cpp.

Here is the caller graph for this function:

◆ IsValidCommitmentToCoinRange()

bool libzerocoin::IsValidCommitmentToCoinRange ( const ZerocoinParams params,
const CBigNum bnCommitment 
)

Definition at line 102 of file Coin.cpp.

◆ IsValidSerial()

bool libzerocoin::IsValidSerial ( const ZerocoinParams params,
const CBigNum bnSerial 
)

Definition at line 87 of file Coin.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ primalityTestByTrialDivision()

bool libzerocoin::primalityTestByTrialDivision ( uint32_t  candidate)

Determines whether a uint32_t is a prime through trial division.

Parameters
candidateCandidate to test.
Returns
true if the value is prime, false otherwise

Performs trial division to determine whether a uint32_t is prime.

Todo:
: HACK HACK WRONG WRONG

Definition at line 639 of file ParamGeneration.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ZerocoinDenominationToAmount()

int64_t libzerocoin::ZerocoinDenominationToAmount ( const CoinDenomination denomination)

Definition at line 92 of file Denominations.cpp.

Here is the caller graph for this function:

◆ ZerocoinDenominationToInt()

int64_t libzerocoin::ZerocoinDenominationToInt ( const CoinDenomination denomination)

Definition at line 32 of file Denominations.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ maxCoinsAtDenom

const std::vector<int> libzerocoin::maxCoinsAtDenom = {4, 1, 4, 1, 4, 1, 4, 4}

Definition at line 30 of file Denominations.h.

◆ zerocoinDenomList

const std::vector<CoinDenomination> libzerocoin::zerocoinDenomList = {ZQ_ONE, ZQ_FIVE, ZQ_TEN, ZQ_FIFTY, ZQ_ONE_HUNDRED, ZQ_FIVE_HUNDRED, ZQ_ONE_THOUSAND, ZQ_FIVE_THOUSAND}

Definition at line 27 of file Denominations.h.