github.com/mit-dci/lit@v0.0.0-20221102210550-8c3d3b49f2ce/btcutil/txscript/error.go (about)

     1  // Copyright (c) 2013-2015 The btcsuite developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  package txscript
     6  
     7  import (
     8  	"errors"
     9  	"fmt"
    10  )
    11  
    12  var (
    13  	// ErrStackShortScript is returned if the script has an opcode that is
    14  	// too long for the length of the script.
    15  	ErrStackShortScript = errors.New("execute past end of script")
    16  
    17  	// ErrStackLongScript is returned if the script has an opcode that is
    18  	// too long for the length of the script.
    19  	ErrStackLongScript = errors.New("script is longer than maximum allowed")
    20  
    21  	// ErrStackUnderflow is returned if an opcode requires more items on the
    22  	// stack than is present.f
    23  	ErrStackUnderflow = errors.New("stack underflow")
    24  
    25  	// ErrStackInvalidArgs is returned if the argument for an opcode is out
    26  	// of acceptable range.
    27  	ErrStackInvalidArgs = errors.New("invalid argument")
    28  
    29  	// ErrStackOpDisabled is returned when a disabled opcode is encountered
    30  	// in the script.
    31  	ErrStackOpDisabled = errors.New("disabled opcode")
    32  
    33  	// ErrStackVerifyFailed is returned when one of the OP_VERIFY or
    34  	// OP_*VERIFY instructions is executed and the conditions fails.
    35  	ErrStackVerifyFailed = errors.New("verify failed")
    36  
    37  	// ErrStackNumberTooBig is returned when the argument for an opcode that
    38  	// should be an offset is obviously far too large.
    39  	ErrStackNumberTooBig = errors.New("number too big")
    40  
    41  	// ErrStackInvalidOpcode is returned when an opcode marked as invalid or
    42  	// a completely undefined opcode is encountered.
    43  	ErrStackInvalidOpcode = errors.New("invalid opcode")
    44  
    45  	// ErrStackReservedOpcode is returned when an opcode marked as reserved
    46  	// is encountered.
    47  	ErrStackReservedOpcode = errors.New("reserved opcode")
    48  
    49  	// ErrStackEarlyReturn is returned when OP_RETURN is executed in the
    50  	// script.
    51  	ErrStackEarlyReturn = errors.New("script returned early")
    52  
    53  	// ErrStackNoIf is returned if an OP_ELSE or OP_ENDIF is encountered
    54  	// without first having an OP_IF or OP_NOTIF in the script.
    55  	ErrStackNoIf = errors.New("OP_ELSE or OP_ENDIF with no matching OP_IF")
    56  
    57  	// ErrStackMissingEndif is returned if the end of a script is reached
    58  	// without and OP_ENDIF to correspond to a conditional expression.
    59  	ErrStackMissingEndif = fmt.Errorf("execute fail, in conditional execution")
    60  
    61  	// ErrStackTooManyPubKeys is returned if an OP_CHECKMULTISIG is
    62  	// encountered with more than MaxPubKeysPerMultiSig pubkeys present.
    63  	ErrStackTooManyPubKeys = errors.New("invalid pubkey count in OP_CHECKMULTISIG")
    64  
    65  	// ErrStackTooManyOperations is returned if a script has more than
    66  	// MaxOpsPerScript opcodes that do not push data.
    67  	ErrStackTooManyOperations = errors.New("too many operations in script")
    68  
    69  	// ErrStackElementTooBig is returned if the size of an element to be
    70  	// pushed to the stack is over MaxScriptElementSize.
    71  	ErrStackElementTooBig = errors.New("element in script too large")
    72  
    73  	// ErrStackUnknownAddress is returned when ScriptToAddrHash does not
    74  	// recognize the pattern of the script and thus can not find the address
    75  	// for payment.
    76  	ErrStackUnknownAddress = errors.New("non-recognised address")
    77  
    78  	// ErrStackScriptFailed is returned when at the end of a script the
    79  	// boolean on top of the stack is false signifying that the script has
    80  	// failed.
    81  	ErrStackScriptFailed = errors.New("execute fail, fail on stack")
    82  
    83  	// ErrStackScriptUnfinished is returned when CheckErrorCondition is
    84  	// called on a script that has not finished executing.
    85  	ErrStackScriptUnfinished = errors.New("error check when script unfinished")
    86  
    87  	// ErrStackEmptyStack is returned when the stack is empty at the end of
    88  	// execution. Normal operation requires that a boolean is on top of the
    89  	// stack when the scripts have finished executing.
    90  	ErrStackEmptyStack = errors.New("stack empty at end of execution")
    91  
    92  	// ErrStackP2SHNonPushOnly is returned when a Pay-to-Script-Hash
    93  	// transaction is encountered and the ScriptSig does operations other
    94  	// than push data (in violation of bip16).
    95  	ErrStackP2SHNonPushOnly = errors.New("pay to script hash with non " +
    96  		"pushonly input")
    97  
    98  	// ErrStackInvalidParseType is an internal error returned from
    99  	// ScriptToAddrHash ony if the internal data tables are wrong.
   100  	ErrStackInvalidParseType = errors.New("internal error: invalid parsetype found")
   101  
   102  	// ErrStackInvalidAddrOffset is an internal error returned from
   103  	// ScriptToAddrHash ony if the internal data tables are wrong.
   104  	ErrStackInvalidAddrOffset = errors.New("internal error: invalid offset found")
   105  
   106  	// ErrStackInvalidIndex is returned when an out-of-bounds index was
   107  	// passed to a function.
   108  	ErrStackInvalidIndex = errors.New("invalid script index")
   109  
   110  	// ErrStackNonPushOnly is returned when ScriptInfo is called with a
   111  	// pkScript that peforms operations other that pushing data to the stack.
   112  	ErrStackNonPushOnly = errors.New("SigScript is non pushonly")
   113  
   114  	// ErrStackOverflow is returned when stack and altstack combined depth
   115  	// is over the limit.
   116  	ErrStackOverflow = errors.New("stack overflow")
   117  
   118  	// ErrStackInvalidLowSSignature is returned when the ScriptVerifyLowS
   119  	// flag is set and the script contains any signatures whose S values
   120  	// are higher than the half order.
   121  	ErrStackInvalidLowSSignature = errors.New("invalid low s signature")
   122  
   123  	// ErrStackInvalidPubKey is returned when the ScriptVerifyScriptEncoding
   124  	// flag is set and the script contains invalid pubkeys.
   125  	ErrStackInvalidPubKey = errors.New("invalid strict pubkey")
   126  
   127  	// ErrStackCleanStack is returned when the ScriptVerifyCleanStack flag
   128  	// is set and after evalution the stack does not contain only one element,
   129  	// which also must be true if interpreted as a boolean.
   130  	ErrStackCleanStack = errors.New("stack is not clean")
   131  
   132  	// ErrStackMinimalData is returned when the ScriptVerifyMinimalData flag
   133  	// is set and the script contains push operations that do not use
   134  	// the minimal opcode required.
   135  	ErrStackMinimalData = errors.New("non-minimally encoded script number")
   136  
   137  	// ErrWitnessProgramEmpty is returned if ScriptVerifyWitness is set and
   138  	// the witness stack itself is empty.
   139  	ErrWitnessProgramEmpty = errors.New("witness program empty passed " +
   140  		"empty witness")
   141  
   142  	// ErrWitnessScriptMismatch is returned if ScriptVerifyWitness is set
   143  	// and the witness itself for a p2wkh witness program isn't *exactly* 2
   144  	// items.
   145  	ErrWitnessScriptMismatch = errors.New("witness program hash mismatch")
   146  
   147  	// ErrWitnessProgramWrongLength is returned if ScriptVerifyWitness is
   148  	// set and the length of the witness program violates the length as
   149  	// dictated by the current witness version.
   150  	ErrWitnessProgramWrongLength = errors.New("witness program has wrong" +
   151  		" length")
   152  
   153  	// ErrWitnessMalleated is returned if ScriptVerifyWitness is set and a
   154  	// native p2wsh program is encountered which has a non-empty sigScript.
   155  	ErrWitnessMalleated = errors.New("witness requires empty sigScript")
   156  
   157  	// ErrWitnessMalleatedP2SH is returned if ScriptVerifyWitness if set
   158  	// and the validation logic for nested p2sh encounters a sigScript
   159  	// which isn't *exactyl* a datapush of the witness program.
   160  	ErrWitnessMalleatedP2SH = errors.New("nested witness requires single " +
   161  		"data-push sigScript")
   162  
   163  	// ErrWitnessUnexpected is returned if ScriptVerifyWitness is set and a
   164  	// transaction includes witness data but doesn't spend an which is a
   165  	// witness program (nested or native).
   166  	ErrWitnessUnexpected = errors.New("unexpected witness")
   167  )
   168  
   169  var (
   170  	// ErrInvalidFlags is returned when the passed flags to NewScript
   171  	// contain an invalid combination.
   172  	ErrInvalidFlags = errors.New("invalid flags combination")
   173  
   174  	// ErrInvalidIndex is returned when the passed input index for the
   175  	// provided transaction is out of range.
   176  	ErrInvalidIndex = errors.New("invalid input index")
   177  
   178  	// ErrUnsupportedAddress is returned when a concrete type that
   179  	// implements a btcutil.Address is not a supported type.
   180  	ErrUnsupportedAddress = errors.New("unsupported address type")
   181  
   182  	// ErrBadNumRequired is returned from MultiSigScript when nrequired is
   183  	// larger than the number of provided public keys.
   184  	ErrBadNumRequired = errors.New("more signatures required than keys present")
   185  )