Documentation ¶
Index ¶
- Constants
- Variables
- func CPUProviderID() uint32
- func GenerateProof(dataDir string, challenge []byte, logger *zap.Logger, ...) (*shared.Proof, error)
- func InitResultToError(retVal uint32) error
- func VerifyPos(dataDir string, scryptParams ScryptParams, o ...VerifyPosOptionsFunc) error
- func Version() string
- type Config
- type DeviceClass
- type ErrInvalidIndex
- type OptionFunc
- type PowFlags
- type Provider
- type Scrypt
- type ScryptParams
- type ScryptPositionsResult
- type Scrypter
- type Verifier
- type VerifyOptionFunc
- type VerifyPosOptions
- type VerifyPosOptionsFunc
Constants ¶
const ( ClassUnspecified = 0 ClassCPU = DeviceClass((C.DeviceClass)(C.DeviceClass_CPU)) ClassGPU = DeviceClass((C.DeviceClass)(C.DeviceClass_GPU)) )
const ( // Use the full dataset. AKA "Fast mode". PowFastMode = C.RandomXFlag_FLAG_FULL_MEM // Allocate memory in large pages. PowLargePages = C.RandomXFlag_FLAG_LARGE_PAGES // Use JIT compilation support. PowJIT = C.RandomXFlag_FLAG_JIT // When combined with FLAG_JIT, the JIT pages are never writable and executable at the same time. PowSecure = C.RandomXFlag_FLAG_SECURE // Use hardware accelerated AES. PowHardAES = C.RandomXFlag_FLAG_HARD_AES // Optimize Argon2 for CPUs with the SSSE3 instruction set. PowArgon2SSSE3 = C.RandomXFlag_FLAG_ARGON2_SSSE3 // Optimize Argon2 for CPUs with the SSSE3 instruction set. PowArgon2AVX2 = C.RandomXFlag_FLAG_ARGON2_AVX2 // Optimize Argon2 for CPUs without the AVX2 or SSSE3 instruction sets. PowArgon2 = C.RandomXFlag_FLAG_ARGON2 )
const ( // regexp matching supported versions of post-rs library SUPPORTED_VERSION = `0\.7\.(\d+)` // 0.7.* // Set this env variable to "true" or "1" to disable version check. DISABLE_CKECK_ENV = "LIBPOST_DISABLE_VERSION_CHECK" )
const (
// LabelLength is the length of the label in bytes.
LabelLength = 16
)
Variables ¶
var ( ErrInvalidProviderID = errors.New("invalid provider ID") ErrInvalidLabelsRange = errors.New("invalid labels range") ErrInitializationFailed = errors.New("initialization failed") ErrInvalidArgument = errors.New("invalid argument") ErrFetchProviders = errors.New("failed to fetch providers") ErrUnknown = errors.New("unknown error") )
var ErrInvalidPos = errors.New("invalid POS")
var ErrScryptClosed = errors.New("scrypt has been closed")
ErrScryptClosed is returned when calling a method on an already closed Scrypt instance.
var ErrVerifierClosed = errors.New("verifier has been closed")
ErrVerifierClosed is returned when calling a method on an already closed Scrypt instance.
Functions ¶
func CPUProviderID ¶
func CPUProviderID() uint32
func GenerateProof ¶
func InitResultToError ¶
InitResultToError converts the return value of the C.initialize() function to a Go error.
func VerifyPos ¶ added in v0.8.9
func VerifyPos(dataDir string, scryptParams ScryptParams, o ...VerifyPosOptionsFunc) error
Types ¶
type DeviceClass ¶
type DeviceClass int
DeviceClass is an enum for the type of device (CPU or GPU).
func (DeviceClass) String ¶
func (c DeviceClass) String() string
type ErrInvalidIndex ¶ added in v0.11.0
type ErrInvalidIndex struct {
Index int
}
func (ErrInvalidIndex) Error ¶ added in v0.11.0
func (e ErrInvalidIndex) Error() string
type OptionFunc ¶
type OptionFunc func(*option) error
OptionFunc is a function that sets an option for a Scrypt instance.
func WithCommitment ¶
func WithCommitment(commitment []byte) OptionFunc
WithCommitment sets the commitment to use for the scrypt computation.
func WithLogger ¶ added in v0.6.3
func WithLogger(logger *zap.Logger) OptionFunc
WithLogger sets the logger to use.
func WithProviderID ¶
func WithProviderID(id uint32) OptionFunc
WithProviderID sets the ID of the openCL provider to use.
func WithScryptN ¶
func WithScryptN(n uint) OptionFunc
WithScryptN sets the N parameter for the scrypt computation.
func WithVRFDifficulty ¶
func WithVRFDifficulty(difficulty []byte) OptionFunc
WithVRFDifficulty sets the difficulty for the VRF nonce computation.
type PowFlags ¶ added in v0.7.0
type PowFlags = C.RandomXFlag
func GetRecommendedPowFlags ¶ added in v0.7.0
func GetRecommendedPowFlags() PowFlags
Get the recommended PoW flags.
Does not include: * FLAG_LARGE_PAGES * FLAG_FULL_MEM * FLAG_SECURE
The above flags need to be set manually, if required.
type Provider ¶
type Provider struct { ID uint32 Model string DeviceType DeviceClass }
Provider is a struct that contains information about an OpenCL provider. libpostrs returns a list of these structs when calling cGetProviders(). Each Provider is an OpenCL platform + Device combination.
func OpenCLProviders ¶
type Scrypt ¶ added in v0.6.2
type Scrypt struct {
// contains filtered or unexported fields
}
Scrypt is a scrypt computation instance. It communicates with post-rs to perform the scrypt computation on the GPU or CPU.
func NewScrypt ¶ added in v0.6.2
func NewScrypt(opts ...OptionFunc) (*Scrypt, error)
NewScrypt creates a new Scrypt instance.
type ScryptParams ¶ added in v0.7.0
type ScryptParams = C.ScryptParams
func NewScryptParams ¶ added in v0.10.2
func NewScryptParams(n, r, p uint) ScryptParams
type ScryptPositionsResult ¶
type ScryptPositionsResult struct { Output []byte // The output of the scrypt computation. IdxSolution *uint64 // The index of a solution to the proof of work (if checked for). }
ScryptPositionsResult is the result of a ScryptPositions call.
type Scrypter ¶ added in v0.8.3
type Scrypter interface { io.Closer Positions(start, end uint64) (ScryptPositionsResult, error) }
type Verifier ¶ added in v0.7.0
type Verifier struct {
// contains filtered or unexported fields
}
func NewVerifier ¶ added in v0.7.0
Create a new verifier. The verifier must be closed after use with Close().
func (*Verifier) VerifyProof ¶ added in v0.7.0
func (v *Verifier) VerifyProof( proof *shared.Proof, metadata *shared.ProofMetadata, logger *zap.Logger, cfg Config, scryptParams ScryptParams, opts ...VerifyOptionFunc, ) error
type VerifyOptionFunc ¶ added in v0.11.0
type VerifyOptionFunc func(*verifyOptions)
func VerifyAll ¶ added in v0.11.0
func VerifyAll() VerifyOptionFunc
Verify all indices in the proof.
func VerifyOne ¶ added in v0.11.0
func VerifyOne(ord int) VerifyOptionFunc
Verify only the selected index. The `ord` is the ordinal number of the index in the proof to verify.
func VerifySubset ¶ added in v0.11.0
func VerifySubset(k3 uint, seed []byte) VerifyOptionFunc
Verify a subset of randomly selected K3 indices. The `seed` is used to randomize the selection of indices.
type VerifyPosOptions ¶ added in v0.8.9
type VerifyPosOptions struct {
// contains filtered or unexported fields
}
type VerifyPosOptionsFunc ¶ added in v0.8.9
type VerifyPosOptionsFunc func(*VerifyPosOptions) error
func FromFile ¶ added in v0.8.9
func FromFile(fromFile uint32) VerifyPosOptionsFunc
func ToFile ¶ added in v0.8.9
func ToFile(toFile uint32) VerifyPosOptionsFunc
func VerifyPosWithLogger ¶ added in v0.8.9
func VerifyPosWithLogger(logger *zap.Logger) VerifyPosOptionsFunc
func WithFraction ¶ added in v0.8.9
func WithFraction(fraction float64) VerifyPosOptionsFunc