postrs

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClassUnspecified = 0
	ClassCPU         = DeviceClass((C.DeviceClass)(C.CPU))
	ClassGPU         = DeviceClass((C.DeviceClass)(C.GPU))
)
View Source
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
)
View Source
const (
	// LabelLength is the length of the label in bytes.
	LabelLength = 16
)

Variables

View Source
var (
	ErrInvalidProviderID = errors.New("invalid provider ID")

	ErrInvalidLabelsRange = errors.New("invalid labels range")
	ErrOpenCL             = errors.New("OpenCL error")
	ErrInvalidArgument    = errors.New("invalid argument")
	ErrFetchProviders     = errors.New("failed to fetch providers")
	ErrUnknown            = errors.New("unknown error")
)
View Source
var ErrScryptClosed = errors.New("scrypt has been closed")

ErrScryptClosed is returned when calling a method on an already closed Scrypt instance.

Functions

func CPUProviderID

func CPUProviderID() uint

func GenerateProof

func GenerateProof(dataDir string, challenge []byte, logger *zap.Logger, nonces uint, threads uint, K1, K2 uint32, powDifficulty [32]byte, powFlags PowFlags) (*shared.Proof, error)

func InitResultToError

func InitResultToError(retVal uint32) error

InitResultToError converts the return value of the C.initialize() function to a Go 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 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 uint) 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         uint
	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

func OpenCLProviders() ([]Provider, error)

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.

func (*Scrypt) Close added in v0.6.2

func (s *Scrypt) Close() error

Close closes the Scrypt instance.

func (*Scrypt) Positions added in v0.6.2

func (s *Scrypt) Positions(start, end uint64) (ScryptPositionsResult, error)

Positions computes the scrypt output for the given options.

type ScryptParams added in v0.7.0

type ScryptParams = C.ScryptParams

func TranslateScryptParams added in v0.7.0

func TranslateScryptParams(n, r, p uint) ScryptParams

Translate scrypt parameters expressed as N,R,P to Nfactor, Rfactor and Pfactor that are understood by scrypt-jane. Relation: N = 1 << (nfactor + 1) r = 1 << rfactor p = 1 << pfactor

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 ScryptPowParams added in v0.7.0

type ScryptPowParams struct {
	Scrypt     ScryptParams
	Difficulty uint64
}

type Verifier added in v0.7.0

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

func NewVerifier added in v0.7.0

func NewVerifier(powFlags PowFlags) (*Verifier, error)

Create a new verifier. The verifier must be closed after use with Close().

func (*Verifier) Close added in v0.7.0

func (v *Verifier) Close() error

func (*Verifier) VerifyProof added in v0.7.0

func (v *Verifier) VerifyProof(
	proof *shared.Proof,
	metadata *shared.ProofMetadata,
	logger *zap.Logger,
	k1, k2, k3 uint32,
	scryptPow ScryptPowParams,
	powDifficulty [32]byte,
	scryptParams ScryptParams,
) error

Jump to

Keyboard shortcuts

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