poc

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PoCSlot represents the unit Slot of PoC
	PoCSlot = 3

	// KiB represents KiByte
	KiB = 1024

	// MiB represents MiByte
	MiB = 1024 * KiB

	// MinValidDefaultBitLength represents smallest default proof BitLength
	MinValidDefaultBitLength = 24

	// MaxValidDefaultBitLength represents biggest default BitLength
	MaxValidDefaultBitLength = 40

	// MinValidDefaultBitLength represents smallest default proof BitLength
	MinValidChiaBitLength = chiapos.MinPlotSize

	// MaxValidDefaultBitLength represents biggest default BitLength
	MaxValidChiaBitLength = chiapos.MaxPlotSize

	// QualityConstantMASSIP0002 multiplies the original quality to fix proof filter
	QualityConstantMASSIP0002 = 512

	// QualityConstantMASSValidity represents the fix between mass and chia proof
	QualityConstantMASSValidity = 0.329
)

Variables

View Source
var (
	// ErrProofDecodeDataSize indicates that the data length of serialized proof is invalid.
	ErrProofDecodeDataSize = errors.New("invalid data length on decode proof")

	// ErrProofInvalidBitLength indicates that the BitLength of Proof is invalid.
	ErrProofInvalidBitLength = errors.New("invalid bitLength")

	// ErrProofInvalidFlipValue indicates that x and x_prime is not matched.
	ErrProofInvalidFlipValue = errors.New("invalid flip value")

	// ErrProofInvalidChallenge indicates that challenge is not matched with proof.
	ErrProofInvalidChallenge = errors.New("invalid challenge")

	// ErrProofNilChia indicates that chia pos is nil
	ErrProofNilChia = errors.New("nil chia pos")

	// ErrProofChiaNoQuality indicates that chia pos has no quality
	ErrProofChiaNoQuality = errors.New("empty chia pos quality")

	// ErrProofFilter indicates that proof not passing proof filter
	ErrProofFilter = errors.New("not passing proof filter")

	// ErrProofType indicates that proof type is mismatched
	ErrProofType = errors.New("proof type mismatched")

	// ErrProofNilItf indicates that proof interface is nil
	ErrProofNilItf = errors.New("proof")
)

Functions

func ChiaPlotSize

func ChiaPlotSize(k int) uint64

func DefaultPlotSize

func DefaultPlotSize(bl int) uint64

func EnforceMASSIP0002

func EnforceMASSIP0002(height uint64) bool

func GetChiaPlotID

func GetChiaPlotID(proof Proof) ([32]byte, error)

func GetChiaPoolPublicKey

func GetChiaPoolPublicKey(proof Proof) (*chiapos.G1Element, error)

func GetQuality

func GetQuality(Q1 *big.Float, hashVal pocutil.Hash) *big.Int

GetQuality produces the relative quality with factor Q1

func HashValChia

func HashValChia(chiaQuality []byte, slot, height uint64) pocutil.Hash

HashValChia returns SHA256(t//s, chia_quality, height).

func IsValidProofType

func IsValidProofType(pt ProofType) bool

func MustGetChiaPoolPublicKey

func MustGetChiaPoolPublicKey(proof Proof) *chiapos.G1Element

func PlotSize

func PlotSize(proofType ProofType, bl int) uint64

func Q1FactorChia

func Q1FactorChia(k uint8) *big.Float

func Q1FactorDefault

func Q1FactorDefault(bitLength int) *big.Float

func VerifyProof

func VerifyProof(proof Proof, pubKeyHash pocutil.Hash, challenge pocutil.Hash, filter bool) error

VerifyProof verifies proof.

Types

type ChiaProof

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

func GetChiaProof

func GetChiaProof(proof Proof) (*ChiaProof, error)

func MustGetChiaProof

func MustGetChiaProof(proof Proof) *ChiaProof

func NewChiaProof

func NewChiaProof(pos *chiapos.ProofOfSpace) *ChiaProof

func (*ChiaProof) BitLength

func (proof *ChiaProof) BitLength() int

func (*ChiaProof) Decode

func (proof *ChiaProof) Decode(data []byte) error

decodeChia decodes proof from N + 1 bytes slice: | Chia PoS | ProofTypeChia | | N bytes | 1 byte |

func (*ChiaProof) Encode

func (proof *ChiaProof) Encode() []byte

Encode encodes proof to N + 1 bytes: | Chia PoS | ProofTypeChia | | N bytes | 1 byte |

func (*ChiaProof) Pos

func (proof *ChiaProof) Pos() *chiapos.ProofOfSpace

func (*ChiaProof) Quality

func (proof *ChiaProof) Quality(slot, height uint64) *big.Int

func (*ChiaProof) Type

func (proof *ChiaProof) Type() ProofType

func (*ChiaProof) VerifiedQuality

func (proof *ChiaProof) VerifiedQuality(useless, challenge pocutil.Hash, filter bool, slot, height uint64) (*big.Int, error)

func (*ChiaProof) Verify

func (proof *ChiaProof) Verify(useless, challenge pocutil.Hash, filter bool) error

verifyProofChia verifies proof: (1) make sure BitLength is Valid. Should be integer even number in [24, 40]. (2) perform function P on x and x_prime, the corresponding result

y and y_prime should be a bit-flip pair.

(3) perform function F on x and x_prime, the result z should

be equal to the bit-length-cut challenge.

It returns nil when proof is verified.

type DefaultProof

type DefaultProof struct {
	X      []byte
	XPrime []byte
	BL     int
}

Proof represents a single PoC Proof.

func GetDefaultProof

func GetDefaultProof(proof Proof) (*DefaultProof, error)

func MustGetDefaultProof

func MustGetDefaultProof(proof Proof) *DefaultProof

func NewDefaultProof

func NewDefaultProof(x, xp []byte, bl int) *DefaultProof

func (*DefaultProof) BitLength

func (proof *DefaultProof) BitLength() int

func (*DefaultProof) Decode

func (proof *DefaultProof) Decode(data []byte) error

Decode decodes proof from a 17-byte slice: | X | XPrime | BitLength | | 8 bytes | 8 bytes | 1 byte | X & XPrime is encoded in little endian

func (*DefaultProof) Encode

func (proof *DefaultProof) Encode() []byte

Encode encodes proof to 17 bytes: | X | XPrime | BitLength | | 8 bytes | 8 bytes | 1 byte | X & XPrime is encoded in little endian

func (*DefaultProof) GetHashVal

func (proof *DefaultProof) GetHashVal(slot uint64, height uint64) pocutil.Hash

GetHashVal returns SHA256(t//s,x,x',height).

func (*DefaultProof) GetQualityByIterative

func (proof *DefaultProof) GetQualityByIterative(slot, height uint64) *big.Int

func (*DefaultProof) Quality

func (proof *DefaultProof) Quality(slot, height uint64) *big.Int

Quality produces the relative quality of a proof.

Here we define: (1) H: (a hash value) as an (32-byte-big-endian-encoded) integer ranges in 0 ~ 2^256 - 1. (2) SIZE: the volume of record of certain BitLength, which equals to 2^BitLength.

The standard quality is : quality = (H / 2^256) ^ [1 / (SIZE * BitLength)], which means the more space you have, the bigger prob you get to generate a higher quality.

In MASS we use an equivalent quality formula : Quality = (SIZE * BitLength) / [256 - log2(H)], which means the more space you have, the bigger prob you get to generate a higher Quality.

A proof is considered as valid when Quality >= target.

func (*DefaultProof) Type

func (proof *DefaultProof) Type() ProofType

Type returns the type of proof

func (*DefaultProof) VerifiedQuality

func (proof *DefaultProof) VerifiedQuality(pubKeyHash pocutil.Hash, challenge pocutil.Hash, filter bool, slot, height uint64) (*big.Int, error)

VerifiedQuality verifies the proof and then calculates its quality.

func (*DefaultProof) Verify

func (proof *DefaultProof) Verify(pubKeyHash pocutil.Hash, challenge pocutil.Hash, filter bool) error

verifyProofMASS verifies proof: (1) make sure BitLength is Valid. Should be integer even number in [24, 40]. (2) perform function P on x and x_prime, the corresponding result

y and y_prime should be a bit-flip pair.

(3) perform function F on x and x_prime, the result z should

be equal to the bit-length-cut challenge.

It returns nil when proof is verified.

type EmptyProof

type EmptyProof struct{}

func NewEmptyProof

func NewEmptyProof() *EmptyProof

func (*EmptyProof) BitLength

func (proof *EmptyProof) BitLength() int

func (*EmptyProof) Decode

func (proof *EmptyProof) Decode([]byte) error

func (*EmptyProof) Encode

func (proof *EmptyProof) Encode() []byte

func (*EmptyProof) Quality

func (proof *EmptyProof) Quality(slot, height uint64) *big.Int

func (*EmptyProof) Type

func (proof *EmptyProof) Type() ProofType

func (*EmptyProof) VerifiedQuality

func (proof *EmptyProof) VerifiedQuality(plotSeed pocutil.Hash, challenge pocutil.Hash, filter bool, slot, height uint64) (*big.Int, error)

func (*EmptyProof) Verify

func (proof *EmptyProof) Verify(plotSeed pocutil.Hash, challenge pocutil.Hash, filter bool) error

type Proof

type Proof interface {
	Type() ProofType
	BitLength() int
	Encode() []byte
	Decode([]byte) error
	Quality(slot, height uint64) *big.Int
	Verify(seed pocutil.Hash, challenge pocutil.Hash, filter bool) error
	VerifiedQuality(seed pocutil.Hash, challenge pocutil.Hash, filter bool, slot, height uint64) (*big.Int, error)
}

type ProofType

type ProofType uint8
const (
	ProofTypeDefault ProofType = 0
	ProofTypeChia    ProofType = 1
	ProofTypeEmpty   ProofType = math.MaxUint8
)

func (ProofType) EnsureBitLength

func (pt ProofType) EnsureBitLength(bl int) bool

EnsureBitLength returns whether it is a valid bitLength.

func (ProofType) PlotSize

func (pt ProofType) PlotSize(bl int) uint64

Directories

Path Synopsis
crypto
Package crypto collects common cryptographic constants.
Package crypto collects common cryptographic constants.
crypto/hash
Package hash provides interfaces for hash functions.
Package hash provides interfaces for hash functions.
crypto/sha256
Package sha256 implements the SHA224 and SHA256 hash algorithms as defined in FIPS 180-4.
Package sha256 implements the SHA224 and SHA256 hash algorithms as defined in FIPS 180-4.

Jump to

Keyboard shortcuts

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