1use crate::constants::{MAX_OPS_PER_SCRIPT, MAX_SCRIPT_ELEMENT_SIZE, MAX_STACK_SIZE};
2use crate::interpreter::{CheckMultiSigError, CheckSigError};
3use crate::num::NumError;
4use crate::signature_checker::SignatureError;
5use crate::stack::StackError;
6
7#[derive(Debug, Eq, PartialEq, thiserror::Error)]
9pub enum Error {
10 #[error("script terminated with a false stack element")]
16 EvalFalse,
17 #[error("Return early if OP_RETURN is executed in the script.")]
18 OpReturn,
19
20 #[error("Exceeds max script size")]
22 ScriptSize,
23 #[error(
24 "Size of the element pushed to the stack exceeds MAX_SCRIPT_ELEMENT_SIZE ({MAX_SCRIPT_ELEMENT_SIZE})"
25 )]
26 PushSize,
27 #[error("Exceeds max operations ({MAX_OPS_PER_SCRIPT}) per script")]
28 OpCount,
29 #[error("Exceeds stack limit ({MAX_STACK_SIZE})")]
31 StackSize,
32 #[error("sig count")]
33 SigCount,
34 #[error("pubkey count")]
35 PubkeyCount,
36
37 #[error("OP_VERIFY failed at opcode: {0:?}")]
39 Verify(bitcoin::opcodes::Opcode),
40
41 #[error("bad opcode")]
43 BadOpcode,
44 #[error("attempt to execute disabled opcode {0}")]
46 DisabledOpcode(bitcoin::opcodes::Opcode),
47 #[error(transparent)]
48 Stack(#[from] StackError),
49 #[error("unbalanced conditional")]
54 UnbalancedConditional,
55
56 #[error("Locktime is negative")]
59 NegativeLocktime,
60 #[error("Required lock time has not been reached.")]
63 UnsatisfiedLocktime,
64
65 #[error("sig hash type")]
67 SigHashType,
68 #[error("Native witness program cannot also have a signature script")]
69 WitnessMalleated,
70 #[error("witness unexpected")]
71 WitnessUnexpected,
72 #[error("witness malleated p2sh")]
73 WitnessMalleatedP2SH,
74 #[error("clean stack")]
78 CleanStack,
79 #[error("minimal if")]
83 Minimalif,
84 #[error("signature push only")]
85 SigPushOnly,
86 #[error("witness program witness empty")]
87 WitnessProgramWitnessEmpty,
88 #[error("witness program mismatch")]
89 WitnessProgramMismatch,
90 #[error("witness program wrong length")]
91 WitnessProgramWrongLength,
92
93 #[error("NOP opcode encountered when DISCOURAGE_UPGRADABLE_NOPS flag is set")]
95 DiscourageUpgradableNops,
96 #[error("discourage upgradable witness program")]
97 DiscourageUpgradableWitnessProgram,
98 #[error("discourage upgradable taproot program")]
99 DiscourageUpgradableTaprootProgram,
100 #[error("discourage upgradable taproot version")]
101 DiscourageUpgradableTaprootVersion,
102 #[error("OP_SUCCESS encountered when ScriptVerifyDiscourageOpSuccess is active.")]
106 DiscourageOpSuccess,
107 #[error("discourage upgrable pubkey type")]
111 DiscourageUpgradablePubkeyType,
112
113 #[error("schnorr sig size")]
115 SchnorrSigSize,
116 #[error("schnorr sig hash type")]
117 SchnorrSigHashType,
118 #[error("schnorr sig")]
119 SchnorrSig,
120 #[error("Taproot control block has a bad length")]
121 TaprootWrongControlSize,
122 #[error("taproot validation weight")]
123 TaprootValidationWeight,
124 #[error("taproot checkmultisig")]
125 TaprootCheckmultisig,
126 #[error("taproot minimalif")]
130 TaprootMinimalif,
131
132 #[error("OP_CODESEPARATOR is used in a non-segwit script.")]
135 OpCodeSeparator,
136 #[error("sig findanddelete")]
137 SigFindAndDelete,
138
139 #[error("error count")]
140 ErrorCount,
141
142 #[error("No script execution")]
144 NoScriptExecution,
145 #[error("Invalid alt stack operation")]
146 InvalidAltStackOperation,
147 #[error("{0} is unknown")]
148 UnknownOpcode(bitcoin::opcodes::Opcode),
149 #[error("Failed to read instruction: {0:?}")]
150 ReadInstruction(bitcoin::script::Error),
151
152 #[error(transparent)]
153 CheckSig(#[from] CheckSigError),
154 #[error(transparent)]
155 CheckMultiSig(#[from] CheckMultiSigError),
156 #[error(transparent)]
157 Num(#[from] NumError),
158 #[error(transparent)]
159 Signature(#[from] SignatureError),
160
161 #[error("schnorr signature error: {0:?}")]
162 SchnorrSignature(bitcoin::taproot::SigFromSliceError),
163 #[error("taproot error: {0:?}")]
164 Taproot(bitcoin::taproot::TaprootError),
165 #[error("secp256k1 error: {0:?}")]
166 Secp256k1(bitcoin::secp256k1::Error),
167}