postrs

package
v0.12.6 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClassUnspecified = 0
	ClassCPU         = DeviceClass((C.DeviceClass)(C.DeviceClass_CPU))
	ClassGPU         = DeviceClass((C.DeviceClass)(C.DeviceClass_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 (
	// 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"
)
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")
	ErrInitializationFailed = errors.New("initialization failed")
	ErrInvalidArgument      = errors.New("invalid argument")
	ErrFetchProviders       = errors.New("failed to fetch providers")
	ErrUnknown              = errors.New("unknown error")
)
View Source
var ErrInvalidPos = errors.New("invalid POS")
View Source
var ErrScryptClosed = errors.New("scrypt has been closed")

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

View Source
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 GenerateProof(
	dataDir string,
	challenge []byte,
	logger *zap.Logger,
	nonces, threads, K1, K2 uint,
	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.

func VerifyPos added in v0.8.9

func VerifyPos(dataDir string, scryptParams ScryptParams, o ...VerifyPosOptionsFunc) error

func Version added in v0.10.3

func Version() string

Types

type Config added in v0.10.2

type Config struct {
	MinNumUnits   uint32
	MaxNumUnits   uint32
	LabelsPerUnit uint64

	K1 uint // K1 specifies the difficulty for a label to be a candidate for a proof.
	K2 uint // K2 is the number of labels below the required difficulty required for a proof.

	PowDifficulty [32]byte
}

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

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 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

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,
	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

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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