zerocoin

package
v0.0.0-...-73b33d2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2019 License: ISC Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

ZerocoinDenominations are the valid denominations of Zerocoin

Functions

func BigToHash

func BigToHash(in *big.Int) (*chainhash.Hash, error)

BigToHash converts a big int to a chainhash

func BigToLittleBytes

func BigToLittleBytes(in *big.Int) []byte

BigToLittleBytes converts a big int to a little endian bytes

func DenominationToAmount

func DenominationToAmount(d Denomination) int64

DenominationToAmount gets the denomination of an amount

func DeserializeBigNum

func DeserializeBigNum(b []byte) (*big.Int, error)

DeserializeBigNum deserializes a big integer similar to OpenSSL with a big endian 32-bit length followed by a big endian representation of the number.

func GetChecksum

func GetChecksum(b *big.Int) uint32

GetChecksum calculates the checksum of a zerocoin accumulator value.

func HashToBig

func HashToBig(hash *chainhash.Hash) *big.Int

HashToBig converts a chainhash.Hash into a big.Int that can be used to perform math comparisons.

func SerializeBigNum

func SerializeBigNum(b *big.Int) []byte

SerializeBigNum serializes a big integer like openssl would

Types

type Accumulator

type Accumulator struct {
	// contains filtered or unexported fields
}

Accumulator represents an RSA-based accumulator.

func NewAccumulator

func NewAccumulator(params *AccumulatorAndProofParams, d Denomination) (*Accumulator, error)

NewAccumulator initializes a new empty accumulator with given parameters and denomination.

func NewAccumulatorWithValue

func NewAccumulatorWithValue(params *AccumulatorAndProofParams, d Denomination, value *big.Int) (*Accumulator, error)

NewAccumulatorWithValue initializes an accumulator with given zerocoin params, denomination, and with a preset value.

func (Accumulator) Accumulate

func (a Accumulator) Accumulate(coin *PublicCoin) error

Accumulate a given coin if it is valid and the denomination matches.

func (Accumulator) Increment

func (a Accumulator) Increment(value *big.Int)

Increment adds a value to the accumulator

type AccumulatorAndProofParams

type AccumulatorAndProofParams struct {
	Initialized                   bool
	AccumulatorModulus            *big.Int
	AccumulatorBase               *big.Int
	MinCoinValue                  *big.Int
	MaxCoinValue                  *big.Int
	AccumulatorPoKCommitmentGroup *IntegerGroupParams
	AccumulatorQRNCommitmentGroup *IntegerGroupParams

	// KPrime is the bit length of the challenges used in the accumulator
	// proof-of-knowledge.
	KPrime uint32

	// KDPrime is the statistical zero-knowledgeness of the accumulator
	// proof.
	KDPrime uint32
}

AccumulatorAndProofParams are the parameters used for Zerocoin on the network.

func NewAccumulatorAndProofParams

func NewAccumulatorAndProofParams() *AccumulatorAndProofParams

NewAccumulatorAndProofParams returns a new uninitialized version of accumulator and proof parameters.

type AccumulatorMap

type AccumulatorMap struct {
	// contains filtered or unexported fields
}

AccumulatorMap each denomination of accumulator.

func NewAccumulatorMap

func NewAccumulatorMap(params *Params) (*AccumulatorMap, error)

NewAccumulatorMap creates a new map of

func (*AccumulatorMap) Accumulate

func (a *AccumulatorMap) Accumulate(p PublicCoin) error

Accumulate adds a zerocoin to the accumulator of its denomination

func (*AccumulatorMap) GetCheckpoint

func (a *AccumulatorMap) GetCheckpoint() *big.Int

GetCheckpoint gets the checksum of all of the accumulators contained in the map.

func (*AccumulatorMap) Read

func (a *AccumulatorMap) Read(d Denomination) *big.Int

Read reads the accumulator value for a certain denomination

func (*AccumulatorMap) Reset

func (a *AccumulatorMap) Reset() error

Reset resets the accumulators to their default values.

func (*AccumulatorMap) SetValue

func (a *AccumulatorMap) SetValue(d Denomination, i *big.Int)

SetValue sets the value of one of the accumulators

func (*AccumulatorMap) SetZerocoinParams

func (a *AccumulatorMap) SetZerocoinParams(params *Params)

SetZerocoinParams sets new parameters and resets the accumulator

type AccumulatorWitness

type AccumulatorWitness struct {
	// contains filtered or unexported fields
}

AccumulatorWitness is a witness that a public coin is in the accumulation of a set of coins.

func (AccumulatorWitness) AddElement

func (a AccumulatorWitness) AddElement(coin PublicCoin)

AddElement adds a public coin to the accumulator.

func (AccumulatorWitness) ResetValue

func (a AccumulatorWitness) ResetValue(checkpoint *Accumulator, coin PublicCoin)

ResetValue resets the value of the accumulator witness to a given checkpoint and public coin.

func (AccumulatorWitness) VerifyWitness

func (a AccumulatorWitness) VerifyWitness(acc *Accumulator, p *PublicCoin) (bool, error)

VerifyWitness verifies that a witness matches the accumulator.

type Denomination

type Denomination int64

Denomination represents a Zerocoin denomination

const (
	// DenomError is the default error zerocoin denomination
	DenomError Denomination = 0

	// DenomOne represents a zerocoin with denomination 1
	DenomOne Denomination = 1

	// DenomFive represents a zerocoin with denomination 5
	DenomFive Denomination = 5

	// DenomTen represents a zerocoin with denomination 10
	DenomTen Denomination = 10

	// DenomFifty represents a zerocoin with denomination 50
	DenomFifty Denomination = 50

	// DenomOneHundred represents a zerocoin with denomination 100
	DenomOneHundred Denomination = 100

	// DenomFiveHundred represents a zerocoin with denomination 500
	DenomFiveHundred Denomination = 500

	// DenomOneThousand represents a zerocoin with denomination 1000
	DenomOneThousand Denomination = 1000

	// DenomFiveThousand represents a zerocoin with denomination 5000
	DenomFiveThousand Denomination = 5000
)

func AmountToZerocoinDenomination

func AmountToZerocoinDenomination(amount int64) Denomination

AmountToZerocoinDenomination converts an amount to a zerocoin denomination

type IntegerGroupParams

type IntegerGroupParams struct {
	// G is the generator for the group
	G *big.Int

	// H is another generator for the group
	H *big.Int

	Modulus     *big.Int
	GroupOrder  *big.Int
	Initialized bool
}

IntegerGroupParams is a cryptographic integer group. Note log_G(H) and log_H(G) must be unknown.

func NewIntegerGroupParams

func NewIntegerGroupParams() *IntegerGroupParams

NewIntegerGroupParams returns a new uninitialized version of integer group params.

type Params

type Params struct {
	Initialized       bool
	AccumulatorParams *AccumulatorAndProofParams

	// CoinCommitmentGroup is the quadratic residue group from which
	// we form a coin as a commitment to a serial number.
	CoinCommitmentGroup *IntegerGroupParams

	// One of two groups used to form a commitment to a coin. This
	// is used in the serial number proof. The order must equal the
	// modulus of CoinCommitmentGroup.
	SerialNumberSoKCommitmentGroup *IntegerGroupParams

	// Number of iterations used in the serial number proof.
	ZKPIterations uint32

	// Amount of the hash function we use for proofs.
	ZKPHashLength uint32
}

Params are parameters for Zerocoin with a trusted modulus N.

func NewZerocoinParams

func NewZerocoinParams(N *big.Int, securityLevel uint32) (*Params, error)

NewZerocoinParams returns a new set of Zerocoin params given a certain modulus.

type PublicCoin

type PublicCoin struct {
	// contains filtered or unexported fields
}

PublicCoin is the part of the coin that is published to the network and contains the value of the commitment to a serial number and the denomination of the coin.

func NewPublicCoin

func NewPublicCoin(p *Params) (*PublicCoin, error)

NewPublicCoin initializes a new public coin without a denomination.

func NewPublicCoinFromValue

func NewPublicCoinFromValue(p *Params, coin *big.Int, d Denomination) (*PublicCoin, error)

NewPublicCoinFromValue initializes a new public coin from an existing value and denomination.

func (*PublicCoin) Denomination

func (p *PublicCoin) Denomination() Denomination

Denomination gets the denomination of the pubcoin

func (PublicCoin) Equal

func (p PublicCoin) Equal(pub2 PublicCoin) bool

Equal returns two if the two public coins are equal.

func (*PublicCoin) Params

func (p *PublicCoin) Params() *Params

Params gets the parameters used by the pubcoin

func (PublicCoin) Validate

func (p PublicCoin) Validate() bool

Validate checks the validity of a public coin.

func (*PublicCoin) Value

func (p *PublicCoin) Value() *big.Int

Value gets the value of the pubcoin

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL