Documentation ¶
Index ¶
- Constants
- Variables
- func ChiaPlotSize(k int) uint64
- func DefaultPlotSize(bl int) uint64
- func EnforceMASSIP0002(height uint64) bool
- func GetChiaPlotID(proof Proof) ([32]byte, error)
- func GetChiaPoolPublicKey(proof Proof) (*chiapos.G1Element, error)
- func GetQuality(Q1 *big.Float, hashVal pocutil.Hash) *big.Int
- func HashValChia(chiaQuality []byte, slot, height uint64) pocutil.Hash
- func IsValidProofType(pt ProofType) bool
- func MustGetChiaPoolPublicKey(proof Proof) *chiapos.G1Element
- func PlotSize(proofType ProofType, bl int) uint64
- func Q1FactorChia(k uint8) *big.Float
- func Q1FactorDefault(bitLength int) *big.Float
- func VerifyProof(proof Proof, pubKeyHash pocutil.Hash, challenge pocutil.Hash, filter bool) error
- type ChiaProof
- func (proof *ChiaProof) BitLength() int
- func (proof *ChiaProof) Decode(data []byte) error
- func (proof *ChiaProof) Encode() []byte
- func (proof *ChiaProof) Pos() *chiapos.ProofOfSpace
- func (proof *ChiaProof) Quality(slot, height uint64) *big.Int
- func (proof *ChiaProof) Type() ProofType
- func (proof *ChiaProof) VerifiedQuality(useless, challenge pocutil.Hash, filter bool, slot, height uint64) (*big.Int, error)
- func (proof *ChiaProof) Verify(useless, challenge pocutil.Hash, filter bool) error
- type DefaultProof
- func (proof *DefaultProof) BitLength() int
- func (proof *DefaultProof) Decode(data []byte) error
- func (proof *DefaultProof) Encode() []byte
- func (proof *DefaultProof) GetHashVal(slot uint64, height uint64) pocutil.Hash
- func (proof *DefaultProof) GetQualityByIterative(slot, height uint64) *big.Int
- func (proof *DefaultProof) Quality(slot, height uint64) *big.Int
- func (proof *DefaultProof) Type() ProofType
- func (proof *DefaultProof) VerifiedQuality(pubKeyHash pocutil.Hash, challenge pocutil.Hash, filter bool, ...) (*big.Int, error)
- func (proof *DefaultProof) Verify(pubKeyHash pocutil.Hash, challenge pocutil.Hash, filter bool) error
- type EmptyProof
- func (proof *EmptyProof) BitLength() int
- func (proof *EmptyProof) Decode([]byte) error
- func (proof *EmptyProof) Encode() []byte
- func (proof *EmptyProof) Quality(slot, height uint64) *big.Int
- func (proof *EmptyProof) Type() ProofType
- func (proof *EmptyProof) VerifiedQuality(plotSeed pocutil.Hash, challenge pocutil.Hash, filter bool, ...) (*big.Int, error)
- func (proof *EmptyProof) Verify(plotSeed pocutil.Hash, challenge pocutil.Hash, filter bool) error
- type Proof
- type ProofType
Constants ¶
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 ¶
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 DefaultPlotSize ¶
func EnforceMASSIP0002 ¶
func GetChiaPlotID ¶
func GetQuality ¶
GetQuality produces the relative quality with factor Q1
func HashValChia ¶
HashValChia returns SHA256(t//s, chia_quality, height).
func IsValidProofType ¶
func Q1FactorChia ¶
func Q1FactorDefault ¶
Types ¶
type ChiaProof ¶
type ChiaProof struct {
// contains filtered or unexported fields
}
func GetChiaProof ¶
func MustGetChiaProof ¶
func NewChiaProof ¶
func NewChiaProof(pos *chiapos.ProofOfSpace) *ChiaProof
func (*ChiaProof) Decode ¶
decodeChia decodes proof from N + 1 bytes slice: | Chia PoS | ProofTypeChia | | N bytes | 1 byte |
func (*ChiaProof) Encode ¶
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) VerifiedQuality ¶
func (*ChiaProof) Verify ¶
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 ¶
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) Type ¶
func (proof *EmptyProof) Type() ProofType
func (*EmptyProof) VerifiedQuality ¶
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
func (ProofType) EnsureBitLength ¶
EnsureBitLength returns whether it is a valid bitLength.
Source Files ¶
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. |