Skip to main content

bsv_script/
opcodes.rs

1//! Bitcoin script opcode definitions.
2//!
3//! All standard opcodes from OP_0 (0x00) through OP_INVALIDOPCODE (0xff).
4//! Includes opcode-to-string and string-to-opcode mappings for ASM output,
5//! plus utility functions for classifying opcodes.
6
7// === Push value ===
8
9/// Push an empty byte array (false/zero) onto the stack.
10pub const OP_0: u8 = 0x00;
11/// Push an empty byte array (false/zero) onto the stack. Alias for `OP_0`.
12pub const OP_FALSE: u8 = 0x00;
13
14// Direct data push opcodes: OP_DATA_1 through OP_DATA_75 push 1-75 bytes.
15
16/// Push the next 1 byte onto the stack.
17pub const OP_DATA_1: u8 = 0x01;
18/// Push the next 2 bytes onto the stack.
19pub const OP_DATA_2: u8 = 0x02;
20/// Push the next 3 bytes onto the stack.
21pub const OP_DATA_3: u8 = 0x03;
22/// Push the next 4 bytes onto the stack.
23pub const OP_DATA_4: u8 = 0x04;
24/// Push the next 5 bytes onto the stack.
25pub const OP_DATA_5: u8 = 0x05;
26/// Push the next 6 bytes onto the stack.
27pub const OP_DATA_6: u8 = 0x06;
28/// Push the next 7 bytes onto the stack.
29pub const OP_DATA_7: u8 = 0x07;
30/// Push the next 8 bytes onto the stack.
31pub const OP_DATA_8: u8 = 0x08;
32/// Push the next 9 bytes onto the stack.
33pub const OP_DATA_9: u8 = 0x09;
34/// Push the next 10 bytes onto the stack.
35pub const OP_DATA_10: u8 = 0x0a;
36/// Push the next 11 bytes onto the stack.
37pub const OP_DATA_11: u8 = 0x0b;
38/// Push the next 12 bytes onto the stack.
39pub const OP_DATA_12: u8 = 0x0c;
40/// Push the next 13 bytes onto the stack.
41pub const OP_DATA_13: u8 = 0x0d;
42/// Push the next 14 bytes onto the stack.
43pub const OP_DATA_14: u8 = 0x0e;
44/// Push the next 15 bytes onto the stack.
45pub const OP_DATA_15: u8 = 0x0f;
46/// Push the next 16 bytes onto the stack.
47pub const OP_DATA_16: u8 = 0x10;
48/// Push the next 17 bytes onto the stack.
49pub const OP_DATA_17: u8 = 0x11;
50/// Push the next 18 bytes onto the stack.
51pub const OP_DATA_18: u8 = 0x12;
52/// Push the next 19 bytes onto the stack.
53pub const OP_DATA_19: u8 = 0x13;
54/// Push the next 20 bytes onto the stack.
55pub const OP_DATA_20: u8 = 0x14;
56/// Push the next 21 bytes onto the stack.
57pub const OP_DATA_21: u8 = 0x15;
58/// Push the next 22 bytes onto the stack.
59pub const OP_DATA_22: u8 = 0x16;
60/// Push the next 23 bytes onto the stack.
61pub const OP_DATA_23: u8 = 0x17;
62/// Push the next 24 bytes onto the stack.
63pub const OP_DATA_24: u8 = 0x18;
64/// Push the next 25 bytes onto the stack.
65pub const OP_DATA_25: u8 = 0x19;
66/// Push the next 26 bytes onto the stack.
67pub const OP_DATA_26: u8 = 0x1a;
68/// Push the next 27 bytes onto the stack.
69pub const OP_DATA_27: u8 = 0x1b;
70/// Push the next 28 bytes onto the stack.
71pub const OP_DATA_28: u8 = 0x1c;
72/// Push the next 29 bytes onto the stack.
73pub const OP_DATA_29: u8 = 0x1d;
74/// Push the next 30 bytes onto the stack.
75pub const OP_DATA_30: u8 = 0x1e;
76/// Push the next 31 bytes onto the stack.
77pub const OP_DATA_31: u8 = 0x1f;
78/// Push the next 32 bytes onto the stack.
79pub const OP_DATA_32: u8 = 0x20;
80/// Push the next 33 bytes onto the stack.
81pub const OP_DATA_33: u8 = 0x21;
82/// Push the next 34 bytes onto the stack.
83pub const OP_DATA_34: u8 = 0x22;
84/// Push the next 35 bytes onto the stack.
85pub const OP_DATA_35: u8 = 0x23;
86/// Push the next 36 bytes onto the stack.
87pub const OP_DATA_36: u8 = 0x24;
88/// Push the next 37 bytes onto the stack.
89pub const OP_DATA_37: u8 = 0x25;
90/// Push the next 38 bytes onto the stack.
91pub const OP_DATA_38: u8 = 0x26;
92/// Push the next 39 bytes onto the stack.
93pub const OP_DATA_39: u8 = 0x27;
94/// Push the next 40 bytes onto the stack.
95pub const OP_DATA_40: u8 = 0x28;
96/// Push the next 41 bytes onto the stack.
97pub const OP_DATA_41: u8 = 0x29;
98/// Push the next 42 bytes onto the stack.
99pub const OP_DATA_42: u8 = 0x2a;
100/// Push the next 43 bytes onto the stack.
101pub const OP_DATA_43: u8 = 0x2b;
102/// Push the next 44 bytes onto the stack.
103pub const OP_DATA_44: u8 = 0x2c;
104/// Push the next 45 bytes onto the stack.
105pub const OP_DATA_45: u8 = 0x2d;
106/// Push the next 46 bytes onto the stack.
107pub const OP_DATA_46: u8 = 0x2e;
108/// Push the next 47 bytes onto the stack.
109pub const OP_DATA_47: u8 = 0x2f;
110/// Push the next 48 bytes onto the stack.
111pub const OP_DATA_48: u8 = 0x30;
112/// Push the next 49 bytes onto the stack.
113pub const OP_DATA_49: u8 = 0x31;
114/// Push the next 50 bytes onto the stack.
115pub const OP_DATA_50: u8 = 0x32;
116/// Push the next 51 bytes onto the stack.
117pub const OP_DATA_51: u8 = 0x33;
118/// Push the next 52 bytes onto the stack.
119pub const OP_DATA_52: u8 = 0x34;
120/// Push the next 53 bytes onto the stack.
121pub const OP_DATA_53: u8 = 0x35;
122/// Push the next 54 bytes onto the stack.
123pub const OP_DATA_54: u8 = 0x36;
124/// Push the next 55 bytes onto the stack.
125pub const OP_DATA_55: u8 = 0x37;
126/// Push the next 56 bytes onto the stack.
127pub const OP_DATA_56: u8 = 0x38;
128/// Push the next 57 bytes onto the stack.
129pub const OP_DATA_57: u8 = 0x39;
130/// Push the next 58 bytes onto the stack.
131pub const OP_DATA_58: u8 = 0x3a;
132/// Push the next 59 bytes onto the stack.
133pub const OP_DATA_59: u8 = 0x3b;
134/// Push the next 60 bytes onto the stack.
135pub const OP_DATA_60: u8 = 0x3c;
136/// Push the next 61 bytes onto the stack.
137pub const OP_DATA_61: u8 = 0x3d;
138/// Push the next 62 bytes onto the stack.
139pub const OP_DATA_62: u8 = 0x3e;
140/// Push the next 63 bytes onto the stack.
141pub const OP_DATA_63: u8 = 0x3f;
142/// Push the next 64 bytes onto the stack.
143pub const OP_DATA_64: u8 = 0x40;
144/// Push the next 65 bytes onto the stack.
145pub const OP_DATA_65: u8 = 0x41;
146/// Push the next 66 bytes onto the stack.
147pub const OP_DATA_66: u8 = 0x42;
148/// Push the next 67 bytes onto the stack.
149pub const OP_DATA_67: u8 = 0x43;
150/// Push the next 68 bytes onto the stack.
151pub const OP_DATA_68: u8 = 0x44;
152/// Push the next 69 bytes onto the stack.
153pub const OP_DATA_69: u8 = 0x45;
154/// Push the next 70 bytes onto the stack.
155pub const OP_DATA_70: u8 = 0x46;
156/// Push the next 71 bytes onto the stack.
157pub const OP_DATA_71: u8 = 0x47;
158/// Push the next 72 bytes onto the stack.
159pub const OP_DATA_72: u8 = 0x48;
160/// Push the next 73 bytes onto the stack.
161pub const OP_DATA_73: u8 = 0x49;
162/// Push the next 74 bytes onto the stack.
163pub const OP_DATA_74: u8 = 0x4a;
164/// Push the next 75 bytes onto the stack.
165pub const OP_DATA_75: u8 = 0x4b;
166
167// Extended push data opcodes.
168
169/// Read the next 1 byte as a length N, then push the next N bytes onto the stack.
170pub const OP_PUSHDATA1: u8 = 0x4c;
171/// Read the next 2 bytes as a little-endian length N, then push the next N bytes onto the stack.
172pub const OP_PUSHDATA2: u8 = 0x4d;
173/// Read the next 4 bytes as a little-endian length N, then push the next N bytes onto the stack.
174pub const OP_PUSHDATA4: u8 = 0x4e;
175
176/// Push the number -1 onto the stack.
177pub const OP_1NEGATE: u8 = 0x4f;
178/// Reserved opcode. Transaction is invalid if executed.
179pub const OP_RESERVED: u8 = 0x50;
180/// Base value for small integer opcodes (OP_1 through OP_16 = OP_BASE + N).
181pub const OP_BASE: u8 = 0x50;
182/// Push the number 1 onto the stack.
183pub const OP_1: u8 = 0x51;
184/// Push the number 1 onto the stack. Alias for `OP_1`.
185pub const OP_TRUE: u8 = 0x51;
186/// Push the number 2 onto the stack.
187pub const OP_2: u8 = 0x52;
188/// Push the number 3 onto the stack.
189pub const OP_3: u8 = 0x53;
190/// Push the number 4 onto the stack.
191pub const OP_4: u8 = 0x54;
192/// Push the number 5 onto the stack.
193pub const OP_5: u8 = 0x55;
194/// Push the number 6 onto the stack.
195pub const OP_6: u8 = 0x56;
196/// Push the number 7 onto the stack.
197pub const OP_7: u8 = 0x57;
198/// Push the number 8 onto the stack.
199pub const OP_8: u8 = 0x58;
200/// Push the number 9 onto the stack.
201pub const OP_9: u8 = 0x59;
202/// Push the number 10 onto the stack.
203pub const OP_10: u8 = 0x5a;
204/// Push the number 11 onto the stack.
205pub const OP_11: u8 = 0x5b;
206/// Push the number 12 onto the stack.
207pub const OP_12: u8 = 0x5c;
208/// Push the number 13 onto the stack.
209pub const OP_13: u8 = 0x5d;
210/// Push the number 14 onto the stack.
211pub const OP_14: u8 = 0x5e;
212/// Push the number 15 onto the stack.
213pub const OP_15: u8 = 0x5f;
214/// Push the number 16 onto the stack.
215pub const OP_16: u8 = 0x60;
216
217// === Flow control ===
218
219/// Do nothing.
220pub const OP_NOP: u8 = 0x61;
221/// Reserved opcode. Transaction is invalid if executed.
222pub const OP_VER: u8 = 0x62;
223/// Execute the following statements if the top stack value is true (non-zero).
224pub const OP_IF: u8 = 0x63;
225/// Execute the following statements if the top stack value is false (zero).
226pub const OP_NOTIF: u8 = 0x64;
227/// Reserved opcode. Transaction is invalid even if not executed.
228pub const OP_VERIF: u8 = 0x65;
229/// Reserved opcode. Transaction is invalid even if not executed.
230pub const OP_VERNOTIF: u8 = 0x66;
231/// Execute the following statements if the preceding OP_IF/OP_NOTIF was not executed.
232pub const OP_ELSE: u8 = 0x67;
233/// End an if/else block.
234pub const OP_ENDIF: u8 = 0x68;
235/// Mark the transaction as invalid if the top stack value is false.
236pub const OP_VERIFY: u8 = 0x69;
237/// Mark the transaction output as unspendable (provably prunable).
238pub const OP_RETURN: u8 = 0x6a;
239
240// === Stack ===
241
242/// Move the top stack item to the alt stack.
243pub const OP_TOALTSTACK: u8 = 0x6b;
244/// Move the top item from the alt stack to the main stack.
245pub const OP_FROMALTSTACK: u8 = 0x6c;
246/// Remove the top two stack items.
247pub const OP_2DROP: u8 = 0x6d;
248/// Duplicate the top two stack items.
249pub const OP_2DUP: u8 = 0x6e;
250/// Duplicate the top three stack items.
251pub const OP_3DUP: u8 = 0x6f;
252/// Copy the pair of items two spaces back to the front of the stack.
253pub const OP_2OVER: u8 = 0x70;
254/// Move the fifth and sixth items to the top of the stack.
255pub const OP_2ROT: u8 = 0x71;
256/// Swap the top two pairs of items on the stack.
257pub const OP_2SWAP: u8 = 0x72;
258/// Duplicate the top stack item if it is non-zero.
259pub const OP_IFDUP: u8 = 0x73;
260/// Push the number of items on the stack onto the stack.
261pub const OP_DEPTH: u8 = 0x74;
262/// Remove the top stack item.
263pub const OP_DROP: u8 = 0x75;
264/// Duplicate the top stack item.
265pub const OP_DUP: u8 = 0x76;
266/// Remove the second-to-top stack item.
267pub const OP_NIP: u8 = 0x77;
268/// Copy the second-to-top stack item to the top.
269pub const OP_OVER: u8 = 0x78;
270/// Copy the item N positions back in the stack to the top.
271pub const OP_PICK: u8 = 0x79;
272/// Move the item N positions back in the stack to the top.
273pub const OP_ROLL: u8 = 0x7a;
274/// Rotate the top three items on the stack (third item moves to top).
275pub const OP_ROT: u8 = 0x7b;
276/// Swap the top two stack items.
277pub const OP_SWAP: u8 = 0x7c;
278/// Copy the top stack item and insert it below the second-to-top item.
279pub const OP_TUCK: u8 = 0x7d;
280
281// === Splice ===
282
283/// Concatenate the top two stack items.
284pub const OP_CAT: u8 = 0x7e;
285/// Split the second-to-top item at position given by the top item.
286pub const OP_SPLIT: u8 = 0x7f;
287/// Convert the top numeric value to a byte array of the specified length.
288pub const OP_NUM2BIN: u8 = 0x80;
289/// Convert a byte array to a numeric value.
290pub const OP_BIN2NUM: u8 = 0x81;
291/// Push the byte length of the top stack item (without popping it).
292pub const OP_SIZE: u8 = 0x82;
293
294// === Bitwise logic ===
295
296/// Flip all bits of the top stack item.
297pub const OP_INVERT: u8 = 0x83;
298/// Bitwise AND of the top two stack items.
299pub const OP_AND: u8 = 0x84;
300/// Bitwise OR of the top two stack items.
301pub const OP_OR: u8 = 0x85;
302/// Bitwise XOR of the top two stack items.
303pub const OP_XOR: u8 = 0x86;
304/// Push 1 if the top two stack items are exactly equal, 0 otherwise.
305pub const OP_EQUAL: u8 = 0x87;
306/// Same as OP_EQUAL, then OP_VERIFY. Marks transaction invalid if not equal.
307pub const OP_EQUALVERIFY: u8 = 0x88;
308/// Reserved opcode. Transaction is invalid if executed.
309pub const OP_RESERVED1: u8 = 0x89;
310/// Reserved opcode. Transaction is invalid if executed.
311pub const OP_RESERVED2: u8 = 0x8a;
312
313// === Arithmetic ===
314
315/// Add 1 to the top stack item.
316pub const OP_1ADD: u8 = 0x8b;
317/// Subtract 1 from the top stack item.
318pub const OP_1SUB: u8 = 0x8c;
319/// Multiply the top stack item by 2 (disabled).
320pub const OP_2MUL: u8 = 0x8d;
321/// Divide the top stack item by 2 (disabled).
322pub const OP_2DIV: u8 = 0x8e;
323/// Negate the top stack item (flip its sign).
324pub const OP_NEGATE: u8 = 0x8f;
325/// Replace the top stack item with its absolute value.
326pub const OP_ABS: u8 = 0x90;
327/// Push 1 if the top item is 0, push 0 otherwise.
328pub const OP_NOT: u8 = 0x91;
329/// Push 0 if the top item is 0, push 1 otherwise.
330pub const OP_0NOTEQUAL: u8 = 0x92;
331/// Pop two items, push their sum.
332pub const OP_ADD: u8 = 0x93;
333/// Pop two items, push the second minus the top.
334pub const OP_SUB: u8 = 0x94;
335/// Pop two items, push their product.
336pub const OP_MUL: u8 = 0x95;
337/// Pop two items, push the integer quotient of the second divided by the top.
338pub const OP_DIV: u8 = 0x96;
339/// Pop two items, push the remainder of the second divided by the top.
340pub const OP_MOD: u8 = 0x97;
341/// Left-shift the second item by the number of bits given by the top item.
342pub const OP_LSHIFT: u8 = 0x98;
343/// Right-shift the second item by the number of bits given by the top item.
344pub const OP_RSHIFT: u8 = 0x99;
345/// Push 1 if both top two items are non-zero, 0 otherwise.
346pub const OP_BOOLAND: u8 = 0x9a;
347/// Push 1 if either of the top two items is non-zero, 0 otherwise.
348pub const OP_BOOLOR: u8 = 0x9b;
349/// Push 1 if the top two items are numerically equal, 0 otherwise.
350pub const OP_NUMEQUAL: u8 = 0x9c;
351/// Same as OP_NUMEQUAL, then OP_VERIFY. Marks transaction invalid if not equal.
352pub const OP_NUMEQUALVERIFY: u8 = 0x9d;
353/// Push 1 if the top two items are not numerically equal, 0 otherwise.
354pub const OP_NUMNOTEQUAL: u8 = 0x9e;
355/// Push 1 if the second item is less than the top item, 0 otherwise.
356pub const OP_LESSTHAN: u8 = 0x9f;
357/// Push 1 if the second item is greater than the top item, 0 otherwise.
358pub const OP_GREATERTHAN: u8 = 0xa0;
359/// Push 1 if the second item is less than or equal to the top item, 0 otherwise.
360pub const OP_LESSTHANOREQUAL: u8 = 0xa1;
361/// Push 1 if the second item is greater than or equal to the top item, 0 otherwise.
362pub const OP_GREATERTHANOREQUAL: u8 = 0xa2;
363/// Push the smaller of the top two stack items.
364pub const OP_MIN: u8 = 0xa3;
365/// Push the larger of the top two stack items.
366pub const OP_MAX: u8 = 0xa4;
367/// Push 1 if the third item is within the range [second, top), 0 otherwise.
368pub const OP_WITHIN: u8 = 0xa5;
369
370// === Crypto ===
371
372/// Hash the top item with RIPEMD-160.
373pub const OP_RIPEMD160: u8 = 0xa6;
374/// Hash the top item with SHA-1.
375pub const OP_SHA1: u8 = 0xa7;
376/// Hash the top item with SHA-256.
377pub const OP_SHA256: u8 = 0xa8;
378/// Hash the top item with SHA-256 then RIPEMD-160 (Bitcoin address hash).
379pub const OP_HASH160: u8 = 0xa9;
380/// Hash the top item with double SHA-256 (Bitcoin transaction hash).
381pub const OP_HASH256: u8 = 0xaa;
382/// Mark the beginning of signature-checked code.
383pub const OP_CODESEPARATOR: u8 = 0xab;
384/// Pop a public key and signature, push 1 if the signature is valid, 0 otherwise.
385pub const OP_CHECKSIG: u8 = 0xac;
386/// Same as OP_CHECKSIG, then OP_VERIFY. Marks transaction invalid if signature check fails.
387pub const OP_CHECKSIGVERIFY: u8 = 0xad;
388/// Pop N public keys and M signatures, push 1 if all signatures are valid, 0 otherwise.
389pub const OP_CHECKMULTISIG: u8 = 0xae;
390/// Same as OP_CHECKMULTISIG, then OP_VERIFY. Marks transaction invalid if check fails.
391pub const OP_CHECKMULTISIGVERIFY: u8 = 0xaf;
392
393// === Locktime ===
394
395/// No operation (reserved for future soft-fork upgrades).
396pub const OP_NOP1: u8 = 0xb0;
397/// No operation (reserved for future soft-fork upgrades). Alias for OP_CHECKLOCKTIMEVERIFY in BTC.
398pub const OP_NOP2: u8 = 0xb1;
399/// Verify that the transaction locktime is at least the given value (BTC only, NOP in BSV).
400pub const OP_CHECKLOCKTIMEVERIFY: u8 = 0xb1;
401/// No operation (reserved for future soft-fork upgrades). Alias for OP_CHECKSEQUENCEVERIFY in BTC.
402pub const OP_NOP3: u8 = 0xb2;
403/// Verify that the input sequence number is at least the given value (BTC only, NOP in BSV).
404pub const OP_CHECKSEQUENCEVERIFY: u8 = 0xb2;
405/// No operation (reserved for future soft-fork upgrades).
406pub const OP_NOP4: u8 = 0xb3;
407/// No operation (reserved for future soft-fork upgrades).
408pub const OP_NOP5: u8 = 0xb4;
409/// No operation (reserved for future soft-fork upgrades).
410pub const OP_NOP6: u8 = 0xb5;
411/// No operation (reserved for future soft-fork upgrades).
412pub const OP_NOP7: u8 = 0xb6;
413/// No operation (reserved for future soft-fork upgrades).
414pub const OP_NOP8: u8 = 0xb7;
415/// No operation (reserved for future soft-fork upgrades).
416pub const OP_NOP9: u8 = 0xb8;
417/// No operation (reserved for future soft-fork upgrades).
418pub const OP_NOP10: u8 = 0xb9;
419
420// === Unknown / internal ===
421
422/// Unknown opcode 186 (0xba). Undefined behavior.
423pub const OP_UNKNOWN186: u8 = 0xba;
424/// Unknown opcode 187 (0xbb). Undefined behavior.
425pub const OP_UNKNOWN187: u8 = 0xbb;
426/// Unknown opcode 188 (0xbc). Undefined behavior.
427pub const OP_UNKNOWN188: u8 = 0xbc;
428/// Unknown opcode 189 (0xbd). Undefined behavior.
429pub const OP_UNKNOWN189: u8 = 0xbd;
430/// Unknown opcode 190 (0xbe). Undefined behavior.
431pub const OP_UNKNOWN190: u8 = 0xbe;
432/// Unknown opcode 191 (0xbf). Undefined behavior.
433pub const OP_UNKNOWN191: u8 = 0xbf;
434/// Unknown opcode 192 (0xc0). Undefined behavior.
435pub const OP_UNKNOWN192: u8 = 0xc0;
436/// Unknown opcode 193 (0xc1). Undefined behavior.
437pub const OP_UNKNOWN193: u8 = 0xc1;
438/// Unknown opcode 194 (0xc2). Undefined behavior.
439pub const OP_UNKNOWN194: u8 = 0xc2;
440/// Unknown opcode 195 (0xc3). Undefined behavior.
441pub const OP_UNKNOWN195: u8 = 0xc3;
442/// Unknown opcode 196 (0xc4). Undefined behavior.
443pub const OP_UNKNOWN196: u8 = 0xc4;
444/// Unknown opcode 197 (0xc5). Undefined behavior.
445pub const OP_UNKNOWN197: u8 = 0xc5;
446/// Unknown opcode 198 (0xc6). Undefined behavior.
447pub const OP_UNKNOWN198: u8 = 0xc6;
448/// Unknown opcode 199 (0xc7). Undefined behavior.
449pub const OP_UNKNOWN199: u8 = 0xc7;
450/// Unknown opcode 200 (0xc8). Undefined behavior.
451pub const OP_UNKNOWN200: u8 = 0xc8;
452/// Unknown opcode 201 (0xc9). Undefined behavior.
453pub const OP_UNKNOWN201: u8 = 0xc9;
454/// Unknown opcode 202 (0xca). Undefined behavior.
455pub const OP_UNKNOWN202: u8 = 0xca;
456/// Unknown opcode 203 (0xcb). Undefined behavior.
457pub const OP_UNKNOWN203: u8 = 0xcb;
458/// Unknown opcode 204 (0xcc). Undefined behavior.
459pub const OP_UNKNOWN204: u8 = 0xcc;
460/// Unknown opcode 205 (0xcd). Undefined behavior.
461pub const OP_UNKNOWN205: u8 = 0xcd;
462/// Unknown opcode 206 (0xce). Undefined behavior.
463pub const OP_UNKNOWN206: u8 = 0xce;
464/// Unknown opcode 207 (0xcf). Undefined behavior.
465pub const OP_UNKNOWN207: u8 = 0xcf;
466/// Unknown opcode 208 (0xd0). Undefined behavior.
467pub const OP_UNKNOWN208: u8 = 0xd0;
468/// Unknown opcode 209 (0xd1). Undefined behavior.
469pub const OP_UNKNOWN209: u8 = 0xd1;
470/// Unknown opcode 210 (0xd2). Undefined behavior.
471pub const OP_UNKNOWN210: u8 = 0xd2;
472/// Unknown opcode 211 (0xd3). Undefined behavior.
473pub const OP_UNKNOWN211: u8 = 0xd3;
474/// Unknown opcode 212 (0xd4). Undefined behavior.
475pub const OP_UNKNOWN212: u8 = 0xd4;
476/// Unknown opcode 213 (0xd5). Undefined behavior.
477pub const OP_UNKNOWN213: u8 = 0xd5;
478/// Unknown opcode 214 (0xd6). Undefined behavior.
479pub const OP_UNKNOWN214: u8 = 0xd6;
480/// Unknown opcode 215 (0xd7). Undefined behavior.
481pub const OP_UNKNOWN215: u8 = 0xd7;
482/// Unknown opcode 216 (0xd8). Undefined behavior.
483pub const OP_UNKNOWN216: u8 = 0xd8;
484/// Unknown opcode 217 (0xd9). Undefined behavior.
485pub const OP_UNKNOWN217: u8 = 0xd9;
486/// Unknown opcode 218 (0xda). Undefined behavior.
487pub const OP_UNKNOWN218: u8 = 0xda;
488/// Unknown opcode 219 (0xdb). Undefined behavior.
489pub const OP_UNKNOWN219: u8 = 0xdb;
490/// Unknown opcode 220 (0xdc). Undefined behavior.
491pub const OP_UNKNOWN220: u8 = 0xdc;
492/// Unknown opcode 221 (0xdd). Undefined behavior.
493pub const OP_UNKNOWN221: u8 = 0xdd;
494/// Unknown opcode 222 (0xde). Undefined behavior.
495pub const OP_UNKNOWN222: u8 = 0xde;
496/// Unknown opcode 223 (0xdf). Undefined behavior.
497pub const OP_UNKNOWN223: u8 = 0xdf;
498/// Unknown opcode 224 (0xe0). Undefined behavior.
499pub const OP_UNKNOWN224: u8 = 0xe0;
500/// Unknown opcode 225 (0xe1). Undefined behavior.
501pub const OP_UNKNOWN225: u8 = 0xe1;
502/// Unknown opcode 226 (0xe2). Undefined behavior.
503pub const OP_UNKNOWN226: u8 = 0xe2;
504/// Unknown opcode 227 (0xe3). Undefined behavior.
505pub const OP_UNKNOWN227: u8 = 0xe3;
506/// Unknown opcode 228 (0xe4). Undefined behavior.
507pub const OP_UNKNOWN228: u8 = 0xe4;
508/// Unknown opcode 229 (0xe5). Undefined behavior.
509pub const OP_UNKNOWN229: u8 = 0xe5;
510/// Unknown opcode 230 (0xe6). Undefined behavior.
511pub const OP_UNKNOWN230: u8 = 0xe6;
512/// Unknown opcode 231 (0xe7). Undefined behavior.
513pub const OP_UNKNOWN231: u8 = 0xe7;
514/// Unknown opcode 232 (0xe8). Undefined behavior.
515pub const OP_UNKNOWN232: u8 = 0xe8;
516/// Unknown opcode 233 (0xe9). Undefined behavior.
517pub const OP_UNKNOWN233: u8 = 0xe9;
518/// Unknown opcode 234 (0xea). Undefined behavior.
519pub const OP_UNKNOWN234: u8 = 0xea;
520/// Unknown opcode 235 (0xeb). Undefined behavior.
521pub const OP_UNKNOWN235: u8 = 0xeb;
522/// Unknown opcode 236 (0xec). Undefined behavior.
523pub const OP_UNKNOWN236: u8 = 0xec;
524/// Unknown opcode 237 (0xed). Undefined behavior.
525pub const OP_UNKNOWN237: u8 = 0xed;
526/// Unknown opcode 238 (0xee). Undefined behavior.
527pub const OP_UNKNOWN238: u8 = 0xee;
528/// Unknown opcode 239 (0xef). Undefined behavior.
529pub const OP_UNKNOWN239: u8 = 0xef;
530/// Unknown opcode 240 (0xf0). Undefined behavior.
531pub const OP_UNKNOWN240: u8 = 0xf0;
532/// Unknown opcode 241 (0xf1). Undefined behavior.
533pub const OP_UNKNOWN241: u8 = 0xf1;
534/// Unknown opcode 242 (0xf2). Undefined behavior.
535pub const OP_UNKNOWN242: u8 = 0xf2;
536/// Unknown opcode 243 (0xf3). Undefined behavior.
537pub const OP_UNKNOWN243: u8 = 0xf3;
538/// Unknown opcode 244 (0xf4). Undefined behavior.
539pub const OP_UNKNOWN244: u8 = 0xf4;
540/// Unknown opcode 245 (0xf5). Undefined behavior.
541pub const OP_UNKNOWN245: u8 = 0xf5;
542/// Unknown opcode 246 (0xf6). Undefined behavior.
543pub const OP_UNKNOWN246: u8 = 0xf6;
544/// Unknown opcode 247 (0xf7). Undefined behavior.
545pub const OP_UNKNOWN247: u8 = 0xf7;
546/// Unknown opcode 248 (0xf8). Undefined behavior.
547pub const OP_UNKNOWN248: u8 = 0xf8;
548/// Unknown opcode 249 (0xf9). Undefined behavior.
549pub const OP_UNKNOWN249: u8 = 0xf9;
550/// Internal pseudo-opcode representing a small integer (used in template matching).
551pub const OP_SMALLINTEGER: u8 = 0xfa;
552/// Internal pseudo-opcode representing multiple public keys (used in template matching).
553pub const OP_PUBKEYS: u8 = 0xfb;
554/// Unknown opcode 252 (0xfc). Undefined behavior.
555pub const OP_UNKNOWN252: u8 = 0xfc;
556/// Internal pseudo-opcode representing a public key hash (used in template matching).
557pub const OP_PUBKEYHASH: u8 = 0xfd;
558/// Internal pseudo-opcode representing a public key (used in template matching).
559pub const OP_PUBKEY: u8 = 0xfe;
560/// Invalid opcode that always causes script failure.
561pub const OP_INVALIDOPCODE: u8 = 0xff;
562
563/// Convert an opcode byte value to its string representation for ASM output.
564///
565/// Returns the canonical OP_xxx name for known opcodes, or "OP_UNKNOWNxxx"
566/// for unrecognized values.
567///
568/// # Arguments
569/// * `op` - The opcode byte value.
570///
571/// # Returns
572/// A static string slice with the opcode name.
573pub fn opcode_to_string(op: u8) -> &'static str {
574    match op {
575        0x00 => "OP_FALSE",
576        0x01 => "OP_DATA_1",
577        0x02 => "OP_DATA_2",
578        0x03 => "OP_DATA_3",
579        0x04 => "OP_DATA_4",
580        0x05 => "OP_DATA_5",
581        0x06 => "OP_DATA_6",
582        0x07 => "OP_DATA_7",
583        0x08 => "OP_DATA_8",
584        0x09 => "OP_DATA_9",
585        0x0a => "OP_DATA_10",
586        0x0b => "OP_DATA_11",
587        0x0c => "OP_DATA_12",
588        0x0d => "OP_DATA_13",
589        0x0e => "OP_DATA_14",
590        0x0f => "OP_DATA_15",
591        0x10 => "OP_DATA_16",
592        0x11 => "OP_DATA_17",
593        0x12 => "OP_DATA_18",
594        0x13 => "OP_DATA_19",
595        0x14 => "OP_DATA_20",
596        0x15 => "OP_DATA_21",
597        0x16 => "OP_DATA_22",
598        0x17 => "OP_DATA_23",
599        0x18 => "OP_DATA_24",
600        0x19 => "OP_DATA_25",
601        0x1a => "OP_DATA_26",
602        0x1b => "OP_DATA_27",
603        0x1c => "OP_DATA_28",
604        0x1d => "OP_DATA_29",
605        0x1e => "OP_DATA_30",
606        0x1f => "OP_DATA_31",
607        0x20 => "OP_DATA_32",
608        0x21 => "OP_DATA_33",
609        0x22 => "OP_DATA_34",
610        0x23 => "OP_DATA_35",
611        0x24 => "OP_DATA_36",
612        0x25 => "OP_DATA_37",
613        0x26 => "OP_DATA_38",
614        0x27 => "OP_DATA_39",
615        0x28 => "OP_DATA_40",
616        0x29 => "OP_DATA_41",
617        0x2a => "OP_DATA_42",
618        0x2b => "OP_DATA_43",
619        0x2c => "OP_DATA_44",
620        0x2d => "OP_DATA_45",
621        0x2e => "OP_DATA_46",
622        0x2f => "OP_DATA_47",
623        0x30 => "OP_DATA_48",
624        0x31 => "OP_DATA_49",
625        0x32 => "OP_DATA_50",
626        0x33 => "OP_DATA_51",
627        0x34 => "OP_DATA_52",
628        0x35 => "OP_DATA_53",
629        0x36 => "OP_DATA_54",
630        0x37 => "OP_DATA_55",
631        0x38 => "OP_DATA_56",
632        0x39 => "OP_DATA_57",
633        0x3a => "OP_DATA_58",
634        0x3b => "OP_DATA_59",
635        0x3c => "OP_DATA_60",
636        0x3d => "OP_DATA_61",
637        0x3e => "OP_DATA_62",
638        0x3f => "OP_DATA_63",
639        0x40 => "OP_DATA_64",
640        0x41 => "OP_DATA_65",
641        0x42 => "OP_DATA_66",
642        0x43 => "OP_DATA_67",
643        0x44 => "OP_DATA_68",
644        0x45 => "OP_DATA_69",
645        0x46 => "OP_DATA_70",
646        0x47 => "OP_DATA_71",
647        0x48 => "OP_DATA_72",
648        0x49 => "OP_DATA_73",
649        0x4a => "OP_DATA_74",
650        0x4b => "OP_DATA_75",
651        0x4c => "OP_PUSHDATA1",
652        0x4d => "OP_PUSHDATA2",
653        0x4e => "OP_PUSHDATA4",
654        0x4f => "OP_1NEGATE",
655        0x50 => "OP_BASE",
656        0x51 => "OP_TRUE",
657        0x52 => "OP_2",
658        0x53 => "OP_3",
659        0x54 => "OP_4",
660        0x55 => "OP_5",
661        0x56 => "OP_6",
662        0x57 => "OP_7",
663        0x58 => "OP_8",
664        0x59 => "OP_9",
665        0x5a => "OP_10",
666        0x5b => "OP_11",
667        0x5c => "OP_12",
668        0x5d => "OP_13",
669        0x5e => "OP_14",
670        0x5f => "OP_15",
671        0x60 => "OP_16",
672        0x61 => "OP_NOP",
673        0x62 => "OP_VER",
674        0x63 => "OP_IF",
675        0x64 => "OP_NOTIF",
676        0x65 => "OP_VERIF",
677        0x66 => "OP_VERNOTIF",
678        0x67 => "OP_ELSE",
679        0x68 => "OP_ENDIF",
680        0x69 => "OP_VERIFY",
681        0x6a => "OP_RETURN",
682        0x6b => "OP_TOALTSTACK",
683        0x6c => "OP_FROMALTSTACK",
684        0x6d => "OP_2DROP",
685        0x6e => "OP_2DUP",
686        0x6f => "OP_3DUP",
687        0x70 => "OP_2OVER",
688        0x71 => "OP_2ROT",
689        0x72 => "OP_2SWAP",
690        0x73 => "OP_IFDUP",
691        0x74 => "OP_DEPTH",
692        0x75 => "OP_DROP",
693        0x76 => "OP_DUP",
694        0x77 => "OP_NIP",
695        0x78 => "OP_OVER",
696        0x79 => "OP_PICK",
697        0x7a => "OP_ROLL",
698        0x7b => "OP_ROT",
699        0x7c => "OP_SWAP",
700        0x7d => "OP_TUCK",
701        0x7e => "OP_CAT",
702        0x7f => "OP_SPLIT",
703        0x80 => "OP_NUM2BIN",
704        0x81 => "OP_BIN2NUM",
705        0x82 => "OP_SIZE",
706        0x83 => "OP_INVERT",
707        0x84 => "OP_AND",
708        0x85 => "OP_OR",
709        0x86 => "OP_XOR",
710        0x87 => "OP_EQUAL",
711        0x88 => "OP_EQUALVERIFY",
712        0x89 => "OP_RESERVED1",
713        0x8a => "OP_RESERVED2",
714        0x8b => "OP_1ADD",
715        0x8c => "OP_1SUB",
716        0x8d => "OP_2MUL",
717        0x8e => "OP_2DIV",
718        0x8f => "OP_NEGATE",
719        0x90 => "OP_ABS",
720        0x91 => "OP_NOT",
721        0x92 => "OP_0NOTEQUAL",
722        0x93 => "OP_ADD",
723        0x94 => "OP_SUB",
724        0x95 => "OP_MUL",
725        0x96 => "OP_DIV",
726        0x97 => "OP_MOD",
727        0x98 => "OP_LSHIFT",
728        0x99 => "OP_RSHIFT",
729        0x9a => "OP_BOOLAND",
730        0x9b => "OP_BOOLOR",
731        0x9c => "OP_NUMEQUAL",
732        0x9d => "OP_NUMEQUALVERIFY",
733        0x9e => "OP_NUMNOTEQUAL",
734        0x9f => "OP_LESSTHAN",
735        0xa0 => "OP_GREATERTHAN",
736        0xa1 => "OP_LESSTHANOREQUAL",
737        0xa2 => "OP_GREATERTHANOREQUAL",
738        0xa3 => "OP_MIN",
739        0xa4 => "OP_MAX",
740        0xa5 => "OP_WITHIN",
741        0xa6 => "OP_RIPEMD160",
742        0xa7 => "OP_SHA1",
743        0xa8 => "OP_SHA256",
744        0xa9 => "OP_HASH160",
745        0xaa => "OP_HASH256",
746        0xab => "OP_CODESEPARATOR",
747        0xac => "OP_CHECKSIG",
748        0xad => "OP_CHECKSIGVERIFY",
749        0xae => "OP_CHECKMULTISIG",
750        0xaf => "OP_CHECKMULTISIGVERIFY",
751        0xb0 => "OP_NOP1",
752        0xb1 => "OP_NOP2",
753        0xb2 => "OP_NOP3",
754        0xb3 => "OP_NOP4",
755        0xb4 => "OP_NOP5",
756        0xb5 => "OP_NOP6",
757        0xb6 => "OP_NOP7",
758        0xb7 => "OP_NOP8",
759        0xb8 => "OP_NOP9",
760        0xb9 => "OP_NOP10",
761        0xba => "OP_UNKNOWN186",
762        0xbb => "OP_UNKNOWN187",
763        0xbc => "OP_UNKNOWN188",
764        0xbd => "OP_UNKNOWN189",
765        0xbe => "OP_UNKNOWN190",
766        0xbf => "OP_UNKNOWN191",
767        0xc0 => "OP_UNKNOWN192",
768        0xc1 => "OP_UNKNOWN193",
769        0xc2 => "OP_UNKNOWN194",
770        0xc3 => "OP_UNKNOWN195",
771        0xc4 => "OP_UNKNOWN196",
772        0xc5 => "OP_UNKNOWN197",
773        0xc6 => "OP_UNKNOWN198",
774        0xc7 => "OP_UNKNOWN199",
775        0xc8 => "OP_UNKNOWN200",
776        0xc9 => "OP_UNKNOWN201",
777        0xca => "OP_UNKNOWN202",
778        0xcb => "OP_UNKNOWN203",
779        0xcc => "OP_UNKNOWN204",
780        0xcd => "OP_UNKNOWN205",
781        0xce => "OP_UNKNOWN206",
782        0xcf => "OP_UNKNOWN207",
783        0xd0 => "OP_UNKNOWN208",
784        0xd1 => "OP_UNKNOWN209",
785        0xd2 => "OP_UNKNOWN210",
786        0xd3 => "OP_UNKNOWN211",
787        0xd4 => "OP_UNKNOWN212",
788        0xd5 => "OP_UNKNOWN213",
789        0xd6 => "OP_UNKNOWN214",
790        0xd7 => "OP_UNKNOWN215",
791        0xd8 => "OP_UNKNOWN216",
792        0xd9 => "OP_UNKNOWN217",
793        0xda => "OP_UNKNOWN218",
794        0xdb => "OP_UNKNOWN219",
795        0xdc => "OP_UNKNOWN220",
796        0xdd => "OP_UNKNOWN221",
797        0xde => "OP_UNKNOWN222",
798        0xdf => "OP_UNKNOWN223",
799        0xe0 => "OP_UNKNOWN224",
800        0xe1 => "OP_UNKNOWN225",
801        0xe2 => "OP_UNKNOWN226",
802        0xe3 => "OP_UNKNOWN227",
803        0xe4 => "OP_UNKNOWN228",
804        0xe5 => "OP_UNKNOWN229",
805        0xe6 => "OP_UNKNOWN230",
806        0xe7 => "OP_UNKNOWN231",
807        0xe8 => "OP_UNKNOWN232",
808        0xe9 => "OP_UNKNOWN233",
809        0xea => "OP_UNKNOWN234",
810        0xeb => "OP_UNKNOWN235",
811        0xec => "OP_UNKNOWN236",
812        0xed => "OP_UNKNOWN237",
813        0xee => "OP_UNKNOWN238",
814        0xef => "OP_UNKNOWN239",
815        0xf0 => "OP_UNKNOWN240",
816        0xf1 => "OP_UNKNOWN241",
817        0xf2 => "OP_UNKNOWN242",
818        0xf3 => "OP_UNKNOWN243",
819        0xf4 => "OP_UNKNOWN244",
820        0xf5 => "OP_UNKNOWN245",
821        0xf6 => "OP_UNKNOWN246",
822        0xf7 => "OP_UNKNOWN247",
823        0xf8 => "OP_UNKNOWN248",
824        0xf9 => "OP_UNKNOWN249",
825        0xfa => "OP_SMALLINTEGER",
826        0xfb => "OP_PUBKEYS",
827        0xfc => "OP_UNKNOWN252",
828        0xfd => "OP_PUBKEYHASH",
829        0xfe => "OP_PUBKEY",
830        0xff => "OP_INVALIDOPCODE",
831    }
832}
833
834/// Convert an opcode name string to its byte value.
835///
836/// Supports all canonical names including aliases (e.g. OP_0, OP_ZERO, OP_FALSE
837/// all map to 0x00).
838///
839/// # Arguments
840/// * `name` - The opcode name (e.g. "OP_DUP", "OP_CHECKSIG").
841///
842/// # Returns
843/// `Some(byte)` if the name is recognized, `None` otherwise.
844pub fn string_to_opcode(name: &str) -> Option<u8> {
845    match name {
846        "OP_0" | "OP_ZERO" | "OP_FALSE" => Some(OP_0),
847        "OP_DATA_1" => Some(0x01),
848        "OP_DATA_2" => Some(0x02),
849        "OP_DATA_3" => Some(0x03),
850        "OP_DATA_4" => Some(0x04),
851        "OP_DATA_5" => Some(0x05),
852        "OP_DATA_6" => Some(0x06),
853        "OP_DATA_7" => Some(0x07),
854        "OP_DATA_8" => Some(0x08),
855        "OP_DATA_9" => Some(0x09),
856        "OP_DATA_10" => Some(0x0a),
857        "OP_DATA_11" => Some(0x0b),
858        "OP_DATA_12" => Some(0x0c),
859        "OP_DATA_13" => Some(0x0d),
860        "OP_DATA_14" => Some(0x0e),
861        "OP_DATA_15" => Some(0x0f),
862        "OP_DATA_16" => Some(0x10),
863        "OP_DATA_17" => Some(0x11),
864        "OP_DATA_18" => Some(0x12),
865        "OP_DATA_19" => Some(0x13),
866        "OP_DATA_20" => Some(0x14),
867        "OP_DATA_21" => Some(0x15),
868        "OP_DATA_22" => Some(0x16),
869        "OP_DATA_23" => Some(0x17),
870        "OP_DATA_24" => Some(0x18),
871        "OP_DATA_25" => Some(0x19),
872        "OP_DATA_26" => Some(0x1a),
873        "OP_DATA_27" => Some(0x1b),
874        "OP_DATA_28" => Some(0x1c),
875        "OP_DATA_29" => Some(0x1d),
876        "OP_DATA_30" => Some(0x1e),
877        "OP_DATA_31" => Some(0x1f),
878        "OP_DATA_32" => Some(0x20),
879        "OP_DATA_33" => Some(0x21),
880        "OP_DATA_34" => Some(0x22),
881        "OP_DATA_35" => Some(0x23),
882        "OP_DATA_36" => Some(0x24),
883        "OP_DATA_37" => Some(0x25),
884        "OP_DATA_38" => Some(0x26),
885        "OP_DATA_39" => Some(0x27),
886        "OP_DATA_40" => Some(0x28),
887        "OP_DATA_41" => Some(0x29),
888        "OP_DATA_42" => Some(0x2a),
889        "OP_DATA_43" => Some(0x2b),
890        "OP_DATA_44" => Some(0x2c),
891        "OP_DATA_45" => Some(0x2d),
892        "OP_DATA_46" => Some(0x2e),
893        "OP_DATA_47" => Some(0x2f),
894        "OP_DATA_48" => Some(0x30),
895        "OP_DATA_49" => Some(0x31),
896        "OP_DATA_50" => Some(0x32),
897        "OP_DATA_51" => Some(0x33),
898        "OP_DATA_52" => Some(0x34),
899        "OP_DATA_53" => Some(0x35),
900        "OP_DATA_54" => Some(0x36),
901        "OP_DATA_55" => Some(0x37),
902        "OP_DATA_56" => Some(0x38),
903        "OP_DATA_57" => Some(0x39),
904        "OP_DATA_58" => Some(0x3a),
905        "OP_DATA_59" => Some(0x3b),
906        "OP_DATA_60" => Some(0x3c),
907        "OP_DATA_61" => Some(0x3d),
908        "OP_DATA_62" => Some(0x3e),
909        "OP_DATA_63" => Some(0x3f),
910        "OP_DATA_64" => Some(0x40),
911        "OP_DATA_65" => Some(0x41),
912        "OP_DATA_66" => Some(0x42),
913        "OP_DATA_67" => Some(0x43),
914        "OP_DATA_68" => Some(0x44),
915        "OP_DATA_69" => Some(0x45),
916        "OP_DATA_70" => Some(0x46),
917        "OP_DATA_71" => Some(0x47),
918        "OP_DATA_72" => Some(0x48),
919        "OP_DATA_73" => Some(0x49),
920        "OP_DATA_74" => Some(0x4a),
921        "OP_DATA_75" => Some(0x4b),
922        "OP_PUSHDATA1" => Some(OP_PUSHDATA1),
923        "OP_PUSHDATA2" => Some(OP_PUSHDATA2),
924        "OP_PUSHDATA4" => Some(OP_PUSHDATA4),
925        "OP_1NEGATE" => Some(OP_1NEGATE),
926        "OP_RESERVED" | "OP_BASE" => Some(OP_RESERVED),
927        "OP_1" | "OP_ONE" | "OP_TRUE" => Some(OP_1),
928        "OP_2" => Some(OP_2),
929        "OP_3" => Some(OP_3),
930        "OP_4" => Some(OP_4),
931        "OP_5" => Some(OP_5),
932        "OP_6" => Some(OP_6),
933        "OP_7" => Some(OP_7),
934        "OP_8" => Some(OP_8),
935        "OP_9" => Some(OP_9),
936        "OP_10" => Some(OP_10),
937        "OP_11" => Some(OP_11),
938        "OP_12" => Some(OP_12),
939        "OP_13" => Some(OP_13),
940        "OP_14" => Some(OP_14),
941        "OP_15" => Some(OP_15),
942        "OP_16" => Some(OP_16),
943        "OP_NOP" => Some(OP_NOP),
944        "OP_VER" => Some(OP_VER),
945        "OP_IF" => Some(OP_IF),
946        "OP_NOTIF" => Some(OP_NOTIF),
947        "OP_VERIF" => Some(OP_VERIF),
948        "OP_VERNOTIF" => Some(OP_VERNOTIF),
949        "OP_ELSE" => Some(OP_ELSE),
950        "OP_ENDIF" => Some(OP_ENDIF),
951        "OP_VERIFY" => Some(OP_VERIFY),
952        "OP_RETURN" => Some(OP_RETURN),
953        "OP_TOALTSTACK" => Some(OP_TOALTSTACK),
954        "OP_FROMALTSTACK" => Some(OP_FROMALTSTACK),
955        "OP_2DROP" => Some(OP_2DROP),
956        "OP_2DUP" => Some(OP_2DUP),
957        "OP_3DUP" => Some(OP_3DUP),
958        "OP_2OVER" => Some(OP_2OVER),
959        "OP_2ROT" => Some(OP_2ROT),
960        "OP_2SWAP" => Some(OP_2SWAP),
961        "OP_IFDUP" => Some(OP_IFDUP),
962        "OP_DEPTH" => Some(OP_DEPTH),
963        "OP_DROP" => Some(OP_DROP),
964        "OP_DUP" => Some(OP_DUP),
965        "OP_NIP" => Some(OP_NIP),
966        "OP_OVER" => Some(OP_OVER),
967        "OP_PICK" => Some(OP_PICK),
968        "OP_ROLL" => Some(OP_ROLL),
969        "OP_ROT" => Some(OP_ROT),
970        "OP_SWAP" => Some(OP_SWAP),
971        "OP_TUCK" => Some(OP_TUCK),
972        "OP_CAT" => Some(OP_CAT),
973        "OP_SPLIT" => Some(OP_SPLIT),
974        "OP_NUM2BIN" | "OP_LEFT" => Some(OP_NUM2BIN),
975        "OP_BIN2NUM" | "OP_RIGHT" => Some(OP_BIN2NUM),
976        "OP_SIZE" => Some(OP_SIZE),
977        "OP_INVERT" => Some(OP_INVERT),
978        "OP_AND" => Some(OP_AND),
979        "OP_OR" => Some(OP_OR),
980        "OP_XOR" => Some(OP_XOR),
981        "OP_EQUAL" => Some(OP_EQUAL),
982        "OP_EQUALVERIFY" => Some(OP_EQUALVERIFY),
983        "OP_RESERVED1" => Some(OP_RESERVED1),
984        "OP_RESERVED2" => Some(OP_RESERVED2),
985        "OP_1ADD" => Some(OP_1ADD),
986        "OP_1SUB" => Some(OP_1SUB),
987        "OP_2MUL" => Some(OP_2MUL),
988        "OP_2DIV" => Some(OP_2DIV),
989        "OP_NEGATE" => Some(OP_NEGATE),
990        "OP_ABS" => Some(OP_ABS),
991        "OP_NOT" => Some(OP_NOT),
992        "OP_0NOTEQUAL" => Some(OP_0NOTEQUAL),
993        "OP_ADD" => Some(OP_ADD),
994        "OP_SUB" => Some(OP_SUB),
995        "OP_MUL" => Some(OP_MUL),
996        "OP_DIV" => Some(OP_DIV),
997        "OP_MOD" => Some(OP_MOD),
998        "OP_LSHIFT" => Some(OP_LSHIFT),
999        "OP_RSHIFT" => Some(OP_RSHIFT),
1000        "OP_BOOLAND" => Some(OP_BOOLAND),
1001        "OP_BOOLOR" => Some(OP_BOOLOR),
1002        "OP_NUMEQUAL" => Some(OP_NUMEQUAL),
1003        "OP_NUMEQUALVERIFY" => Some(OP_NUMEQUALVERIFY),
1004        "OP_NUMNOTEQUAL" => Some(OP_NUMNOTEQUAL),
1005        "OP_LESSTHAN" => Some(OP_LESSTHAN),
1006        "OP_GREATERTHAN" => Some(OP_GREATERTHAN),
1007        "OP_LESSTHANOREQUAL" => Some(OP_LESSTHANOREQUAL),
1008        "OP_GREATERTHANOREQUAL" => Some(OP_GREATERTHANOREQUAL),
1009        "OP_MIN" => Some(OP_MIN),
1010        "OP_MAX" => Some(OP_MAX),
1011        "OP_WITHIN" => Some(OP_WITHIN),
1012        "OP_RIPEMD160" => Some(OP_RIPEMD160),
1013        "OP_SHA1" => Some(OP_SHA1),
1014        "OP_SHA256" => Some(OP_SHA256),
1015        "OP_HASH160" => Some(OP_HASH160),
1016        "OP_HASH256" => Some(OP_HASH256),
1017        "OP_CODESEPARATOR" => Some(OP_CODESEPARATOR),
1018        "OP_CHECKSIG" => Some(OP_CHECKSIG),
1019        "OP_CHECKSIGVERIFY" => Some(OP_CHECKSIGVERIFY),
1020        "OP_CHECKMULTISIG" => Some(OP_CHECKMULTISIG),
1021        "OP_CHECKMULTISIGVERIFY" => Some(OP_CHECKMULTISIGVERIFY),
1022        "OP_NOP1" => Some(OP_NOP1),
1023        "OP_NOP2" => Some(OP_NOP2),
1024        "OP_NOP3" => Some(OP_NOP3),
1025        "OP_NOP4" => Some(OP_NOP4),
1026        "OP_NOP5" => Some(OP_NOP5),
1027        "OP_NOP6" => Some(OP_NOP6),
1028        "OP_NOP7" => Some(OP_NOP7),
1029        "OP_NOP8" => Some(OP_NOP8),
1030        "OP_NOP9" => Some(OP_NOP9),
1031        "OP_NOP10" => Some(OP_NOP10),
1032        "OP_UNKNOWN186" => Some(OP_UNKNOWN186),
1033        "OP_UNKNOWN187" => Some(OP_UNKNOWN187),
1034        "OP_UNKNOWN188" => Some(OP_UNKNOWN188),
1035        "OP_UNKNOWN189" => Some(OP_UNKNOWN189),
1036        "OP_UNKNOWN190" => Some(OP_UNKNOWN190),
1037        "OP_UNKNOWN191" => Some(OP_UNKNOWN191),
1038        "OP_UNKNOWN192" => Some(OP_UNKNOWN192),
1039        "OP_UNKNOWN193" => Some(OP_UNKNOWN193),
1040        "OP_UNKNOWN194" => Some(OP_UNKNOWN194),
1041        "OP_UNKNOWN195" => Some(OP_UNKNOWN195),
1042        "OP_UNKNOWN196" => Some(OP_UNKNOWN196),
1043        "OP_UNKNOWN197" => Some(OP_UNKNOWN197),
1044        "OP_UNKNOWN198" => Some(OP_UNKNOWN198),
1045        "OP_UNKNOWN199" => Some(OP_UNKNOWN199),
1046        "OP_UNKNOWN200" => Some(OP_UNKNOWN200),
1047        "OP_UNKNOWN201" => Some(OP_UNKNOWN201),
1048        "OP_UNKNOWN202" => Some(OP_UNKNOWN202),
1049        "OP_UNKNOWN203" => Some(OP_UNKNOWN203),
1050        "OP_UNKNOWN204" => Some(OP_UNKNOWN204),
1051        "OP_UNKNOWN205" => Some(OP_UNKNOWN205),
1052        "OP_UNKNOWN206" => Some(OP_UNKNOWN206),
1053        "OP_UNKNOWN207" => Some(OP_UNKNOWN207),
1054        "OP_UNKNOWN208" => Some(OP_UNKNOWN208),
1055        "OP_UNKNOWN209" => Some(OP_UNKNOWN209),
1056        "OP_UNKNOWN210" => Some(OP_UNKNOWN210),
1057        "OP_UNKNOWN211" => Some(OP_UNKNOWN211),
1058        "OP_UNKNOWN212" => Some(OP_UNKNOWN212),
1059        "OP_UNKNOWN213" => Some(OP_UNKNOWN213),
1060        "OP_UNKNOWN214" => Some(OP_UNKNOWN214),
1061        "OP_UNKNOWN215" => Some(OP_UNKNOWN215),
1062        "OP_UNKNOWN216" => Some(OP_UNKNOWN216),
1063        "OP_UNKNOWN217" => Some(OP_UNKNOWN217),
1064        "OP_UNKNOWN218" => Some(OP_UNKNOWN218),
1065        "OP_UNKNOWN219" => Some(OP_UNKNOWN219),
1066        "OP_UNKNOWN220" => Some(OP_UNKNOWN220),
1067        "OP_UNKNOWN221" => Some(OP_UNKNOWN221),
1068        "OP_UNKNOWN222" => Some(OP_UNKNOWN222),
1069        "OP_UNKNOWN223" => Some(OP_UNKNOWN223),
1070        "OP_UNKNOWN224" => Some(OP_UNKNOWN224),
1071        "OP_UNKNOWN225" => Some(OP_UNKNOWN225),
1072        "OP_UNKNOWN226" => Some(OP_UNKNOWN226),
1073        "OP_UNKNOWN227" => Some(OP_UNKNOWN227),
1074        "OP_UNKNOWN228" => Some(OP_UNKNOWN228),
1075        "OP_UNKNOWN229" => Some(OP_UNKNOWN229),
1076        "OP_UNKNOWN230" => Some(OP_UNKNOWN230),
1077        "OP_UNKNOWN231" => Some(OP_UNKNOWN231),
1078        "OP_UNKNOWN232" => Some(OP_UNKNOWN232),
1079        "OP_UNKNOWN233" => Some(OP_UNKNOWN233),
1080        "OP_UNKNOWN234" => Some(OP_UNKNOWN234),
1081        "OP_UNKNOWN235" => Some(OP_UNKNOWN235),
1082        "OP_UNKNOWN236" => Some(OP_UNKNOWN236),
1083        "OP_UNKNOWN237" => Some(OP_UNKNOWN237),
1084        "OP_UNKNOWN238" => Some(OP_UNKNOWN238),
1085        "OP_UNKNOWN239" => Some(OP_UNKNOWN239),
1086        "OP_UNKNOWN240" => Some(OP_UNKNOWN240),
1087        "OP_UNKNOWN241" => Some(OP_UNKNOWN241),
1088        "OP_UNKNOWN242" => Some(OP_UNKNOWN242),
1089        "OP_UNKNOWN243" => Some(OP_UNKNOWN243),
1090        "OP_UNKNOWN244" => Some(OP_UNKNOWN244),
1091        "OP_UNKNOWN245" => Some(OP_UNKNOWN245),
1092        "OP_UNKNOWN246" => Some(OP_UNKNOWN246),
1093        "OP_UNKNOWN247" => Some(OP_UNKNOWN247),
1094        "OP_UNKNOWN248" => Some(OP_UNKNOWN248),
1095        "OP_UNKNOWN249" => Some(OP_UNKNOWN249),
1096        "OP_SMALLINTEGER" => Some(OP_SMALLINTEGER),
1097        "OP_PUBKEYS" => Some(OP_PUBKEYS),
1098        "OP_UNKNOWN252" => Some(OP_UNKNOWN252),
1099        "OP_PUBKEYHASH" => Some(OP_PUBKEYHASH),
1100        "OP_PUBKEY" => Some(OP_PUBKEY),
1101        "OP_INVALIDOPCODE" => Some(OP_INVALIDOPCODE),
1102        _ => None,
1103    }
1104}
1105
1106/// Check if an opcode represents a small integer (OP_0 or OP_1..OP_16).
1107///
1108/// # Arguments
1109/// * `op` - The opcode byte value.
1110///
1111/// # Returns
1112/// `true` if the opcode pushes a small integer (0-16) onto the stack.
1113pub fn is_small_int_op(op: u8) -> bool {
1114    op == OP_0 || (op >= OP_1 && op <= OP_16)
1115}
1116
1117/// Check if an opcode is a push data opcode (OP_DATA_1..OP_PUSHDATA4).
1118///
1119/// # Arguments
1120/// * `op` - The opcode byte value.
1121///
1122/// # Returns
1123/// `true` if the opcode pushes data onto the stack.
1124pub fn is_push_data(op: u8) -> bool {
1125    op >= OP_DATA_1 && op <= OP_PUSHDATA4
1126}