vm

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidScriptVersion represents an error case where an asset input
	// commits to an invalid script version.
	ErrInvalidScriptVersion = tapscript.ErrInvalidScriptVersion

	// ErrInputMismatch represents an error case where an asset's set of
	// inputs mismatch the set provided to the virtual machine.
	ErrInputMismatch = tapscript.ErrInputMismatch

	// ErrNoInputs represents an error case where an asset undergoing a
	// state transition does not have any or a specific input required.
	ErrNoInputs = tapscript.ErrNoInputs
)

Wrap select errors related to virtual TX handling to provide more context to callers.

Functions

func ValidateWitnesses added in v0.4.0

func ValidateWitnesses(newAsset *asset.Asset,
	splitAssets []*commitment.SplitAsset,
	prevAssets commitment.InputSet) error

ValidateWitnesses is a helper method that checks the witnesses provided over an asset transfer. This method may be used for transfers that are not yet complete, in order to check if the existing signatures are valid.

Types

type Engine

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

Engine is a virtual machine capable of executing and verifying Taproot asset state transitions.

func New

func New(newAsset *asset.Asset, splitAssets []*commitment.SplitAsset,
	prevAssets commitment.InputSet, opts ...NewEngineOpt) (*Engine, error)

New returns a new virtual machine capable of executing and verifying Taproot Asset state transitions.

func (*Engine) Execute

func (vm *Engine) Execute() error

Execute attempts to execute an asset's state transition to determine whether it was valid or not represented by the error returned.

type Error

type Error struct {
	Kind  ErrorKind
	Inner error
}

Error represents an error returned by the Taproot Asset VM.

func (Error) Error

func (e Error) Error() string

Error returns a human-readable version of the error. This implements the main error interface.

func (Error) String

func (e Error) String() string

String is the same as Error, but intended to be used for string formatting.

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap implements the extended error interface, with the ability to expose a wrapped error to the caller.

type ErrorKind

type ErrorKind uint8

ErrorKind uniquely identifies the kind of Error returned by the Taproot Asset VM.

const (
	// ErrNoSplitCommitment represents an error case where a split
	// commitment root is not present when required.
	ErrNoSplitCommitment ErrorKind = iota

	// ErrIDMismatch represents an error case where an asset, or asset
	// split, do not match the asset genesis of their inputs.
	ErrIDMismatch

	// ErrTypeMismatch represents an error case where an asset, or asset
	// split, do not match the asset type of their inputs.
	ErrTypeMismatch

	// ErrScriptKeyMismatch represents an error case where an the script key
	// of an asset input does not match the one of the input provided to the
	// virtual machine.
	ErrScriptKeyMismatch

	// ErrAmountMismatch represents an error case where an asset, along with
	// its splits, do not match the total asset amount of their inputs.
	ErrAmountMismatch

	// ErrInvalidSigHashFlag represents an error case where an asset witness
	// contains signatures created with any sighash flag other than
	// SIGHASH_DEFAULT.
	ErrInvalidSigHashFlag

	// ErrInvalidGenesisStateTransition represents an error case where an
	// asset has a valid genesis witness but the virtual machine was
	// provided asset inputs.
	ErrInvalidGenesisStateTransition

	// ErrInvalidTransferWitness represents an error case where an asset
	// input has a malformed or invalid transfer witness as deemed by the
	// virtual machine.
	ErrInvalidTransferWitness

	// ErrInvalidSplitAssetType represents an error case where an asset
	// split type does not match the root asset.
	ErrInvalidSplitAssetType

	// ErrInvalidSplitCommitmentWitness represents an error case where an
	// asset input has a malformed split commitment witness.
	ErrInvalidSplitCommitmentWitness

	// ErrInvalidSplitCommitmentProof represents an error case where an
	// asset split has an invalid split commitment proof.
	ErrInvalidSplitCommitmentProof

	// ErrInvalidRootAsset represents an error case where the root asset
	// of an asset split has zero value but a spendable script key.
	ErrInvalidRootAsset

	// ErrUnfinalizedAsset represents an error case where the asset has not
	// been finalized. A virtual TX may only contain finalized assets.
	ErrUnfinalizedAsset
)

func (ErrorKind) String

func (k ErrorKind) String() string

type ErrorTestCase added in v0.3.0

type ErrorTestCase struct {
	Asset       *asset.TestAsset        `json:"asset"`
	SplitSet    commitment.TestSplitSet `json:"split_set"`
	InputSet    commitment.TestInputSet `json:"input_set"`
	BlockHeight uint32                  `json:"block_height"`
	Error       string                  `json:"error"`
	Comment     string                  `json:"comment"`
}

type NewEngineOpt added in v0.4.0

type NewEngineOpt func(*newEngineOptions)

NewEngineOpt is used to modify how a new engine is to be created.

func WithBlockHeight added in v0.4.0

func WithBlockHeight(blockHeight uint32) NewEngineOpt

WithBlockHeight can be used to create an engine that validates time locks against the given block height instead of the current best known block.

func WithChainLookup added in v0.4.0

func WithChainLookup(chainLookup asset.ChainLookup) NewEngineOpt

WithChainLookup can be used to create an engine that is capable of validating time locks.

func WithSkipTimeLockValidation added in v0.4.0

func WithSkipTimeLockValidation() NewEngineOpt

WithSkipTimeLockValidation can be used to create an engine that skips validating time locks.

type TestVectors added in v0.3.0

type TestVectors struct {
	ValidTestCases []*ValidTestCase `json:"valid_test_cases"`
	ErrorTestCases []*ErrorTestCase `json:"error_test_cases"`
}

type ValidTestCase added in v0.3.0

type ValidTestCase struct {
	Asset       *asset.TestAsset        `json:"asset"`
	SplitSet    commitment.TestSplitSet `json:"split_set"`
	InputSet    commitment.TestInputSet `json:"input_set"`
	BlockHeight uint32                  `json:"block_height"`
	Comment     string                  `json:"comment"`
}

Jump to

Keyboard shortcuts

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