Skip to main content

kaspa_txscript_errors/
lib.rs

1use kaspa_hashes::Hash;
2use thiserror::Error;
3
4#[derive(Error, PartialEq, Eq, Debug, Clone)]
5pub enum TxScriptError {
6    #[error("invalid opcode length: {0:02x?}")]
7    MalformedPushSize(Vec<u8>),
8    #[error("opcode requires {0} bytes, but script only has {1} remaining")]
9    MalformedPush(usize, usize),
10    #[error("transaction input {0} is out of bounds, should be non-negative below {1}")]
11    InvalidInputIndex(i32, usize),
12    #[error("transaction input {0} is either out of bounds or has no associated covenant outputs")]
13    InvalidCovInputIndex(i32),
14    #[error("combined stack size {0} > max allowed {1}")]
15    StackSizeExceeded(usize, usize),
16    #[error("attempt to execute invalid opcode {0}")]
17    InvalidOpcode(String),
18    #[error("attempt to execute reserved opcode {0}")]
19    OpcodeReserved(String),
20    #[error("attempt to execute disabled opcode {0}")]
21    OpcodeDisabled(String),
22    #[error("attempt to read from empty stack")]
23    EmptyStack,
24    #[error("stack contains {0} unexpected items")]
25    CleanStack(usize),
26    // We return error if stack entry is false
27    #[error("false stack entry at end of script execution")]
28    EvalFalse,
29    #[error("script returned early")]
30    EarlyReturn,
31    #[error("script ran, but verification failed")]
32    VerifyError,
33    #[error("encountered invalid state while running script: {0}")]
34    InvalidState(String),
35    #[error("pubkey invalid: {0}")]
36    InvalidPubkey(secp256k1::Error),
37    #[error("signature invalid: {0}")]
38    InvalidSignature(secp256k1::Error),
39    #[error("invalid signature in sig cache")]
40    SigcacheSignatureInvalid,
41    #[error("exceeded max operation limit of {0}")]
42    TooManyOperations(i32),
43    #[error("Engine is not running on a transaction input")]
44    NotATransactionInput,
45    #[error("element size {0} exceeds max allowed size {1}")]
46    ElementTooBig(usize, usize),
47    #[error("push encoding is not minimal: {0}")]
48    NotMinimalData(String),
49    #[error("opcode not supported on current source: {0}")]
50    InvalidSource(String),
51    #[error("Unsatisfied lock time: {0}")]
52    UnsatisfiedLockTime(String),
53    #[error("Number too big: {0}")]
54    NumberTooBig(String),
55    #[error("not all signatures empty on failed checkmultisig")]
56    NullFail,
57    #[error("invalid signature count: {0}")]
58    InvalidSignatureCount(String),
59    #[error("invalid pubkey count: {0}")]
60    InvalidPubKeyCount(String),
61    #[error("invalid hash type {0:#04x}")]
62    InvalidSigHashType(u8),
63    #[error("unsupported public key type")]
64    PubKeyFormat,
65    #[error("no scripts to run")]
66    NoScripts,
67    #[error("signature script is not push only")]
68    SignatureScriptNotPushOnly,
69    #[error("end of script reached in conditional execution")]
70    ErrUnbalancedConditional,
71    #[error("opcode requires at least {0} but stack has only {1}")]
72    InvalidStackOperation(usize, usize),
73    #[error("script of size {0} exceeded maximum allowed size of {1}")]
74    ScriptSize(usize, usize),
75    #[error("transaction output {0} is out of bounds, should be non-negative below {1}")]
76    InvalidOutputIndex(i32, usize),
77    #[error(transparent)]
78    Serialization(#[from] SerializationError),
79    #[error("script units exceeded the amount committed in the input: used={used}, limit={limit}")]
80    ExceededCommittedScriptUnits { used: u64, limit: u64 },
81    #[error("ZK Integrity: {0}")]
82    ZkIntegrity(String),
83    #[error("substring [{0}:{1}] is out of bounds for string of length {2}")]
84    OutOfBoundsSubstring(usize, usize, usize),
85    #[error("{0} cannot be used as an array index")]
86    InvalidIndex(i32),
87    #[error("{start}..{end} is not a valid range, {end} must be greater than {start}")]
88    InvalidRange { start: usize, end: usize },
89
90    #[error("blockhash must be exactly 32 bytes long, got {0} bytes instead")]
91    InvalidLengthOfBlockHash(usize),
92    #[error("block {0} not selected")]
93    BlockNotSelected(String),
94    #[error("block {0} already pruned")]
95    BlockAlreadyPruned(String),
96    #[error("block {0} is too deep")]
97    BlockIsTooDeep(String),
98    #[error("covenants error: {0}")]
99    CovenantsError(#[from] CovenantsError),
100}
101
102#[derive(Error, PartialEq, Eq, Debug, Clone, Copy)]
103pub enum SerializationError {
104    #[error("Number exceeds {1} bytes: {0}")]
105    NumberTooLong(i64, usize),
106    #[error("Ark serialization error")]
107    ArkSerialization,
108}
109
110#[derive(Error, Debug, Clone, PartialEq, Eq)]
111pub enum CovenantsError {
112    #[error("input #{0} and outputs with covenant id {1} do not correspond to the expected genesis hashing")]
113    WrongGenesisCovenantId(usize, Hash),
114    #[error("output #{0} covenant authorizing input index {1} is out of bounds")]
115    AuthInputOutOfBounds(usize, u16),
116    #[error("covenant id {0} input {1} is out of bounds")]
117    InvalidCovInIndex(Hash, usize),
118    #[error("covenant id {0} output {1} is out of bounds")]
119    InvalidCovOutIndex(Hash, usize),
120    #[error("{0} is not a valid covenant output index for input {1} with {2} authorized outputs")]
121    InvalidAuthCovOutIndex(usize, usize, usize),
122}